blob: c194174b3250dadef47118d80235adb7bb95ae81 [file] [log] [blame]
Hyunsun Moon9274aaf2015-12-04 11:35:25 -08001/*
Brian O'Connor8e57fd52016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Hyunsun Moon9274aaf2015-12-04 11:35:25 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
alshabibb4d31712016-06-01 18:51:03 -070016package org.opencord.cordvtn.rest;
Hyunsun Moon9274aaf2015-12-04 11:35:25 -080017
18import org.onosproject.rest.AbstractWebResource;
Hyunsun Mooneaf75e62016-09-27 16:40:23 -070019import org.opencord.cordvtn.api.Dependency.Type;
Hyunsun Moon5401aaa2016-06-12 17:40:34 -070020import org.opencord.cordvtn.api.DependencyService;
Hyunsun Mooneaf75e62016-09-27 16:40:23 -070021import org.opencord.cordvtn.api.NetworkId;
Hyunsun Moon9274aaf2015-12-04 11:35:25 -080022
Hyunsun Moon97eaf502015-12-07 14:06:28 -080023import javax.ws.rs.DELETE;
24import javax.ws.rs.POST;
Hyunsun Moon9274aaf2015-12-04 11:35:25 -080025import javax.ws.rs.Path;
Hyunsun Moon97eaf502015-12-07 14:06:28 -080026import javax.ws.rs.PathParam;
27import javax.ws.rs.Produces;
28import javax.ws.rs.core.MediaType;
29import javax.ws.rs.core.Response;
Hyunsun Mooneaf75e62016-09-27 16:40:23 -070030import java.util.Objects;
31
32import static org.opencord.cordvtn.api.Dependency.Type.BIDIRECTIONAL;
33import static org.opencord.cordvtn.api.Dependency.Type.UNIDIRECTIONAL;
Hyunsun Moon9274aaf2015-12-04 11:35:25 -080034
35/**
36 * Manages service dependency.
37 */
Hyunsun Mooneaf75e62016-09-27 16:40:23 -070038@Deprecated
Hyunsun Moon9274aaf2015-12-04 11:35:25 -080039@Path("service-dependency")
40public class ServiceDependencyWebResource extends AbstractWebResource {
Hyunsun Moon97eaf502015-12-07 14:06:28 -080041
Hyunsun Moon5401aaa2016-06-12 17:40:34 -070042 private final DependencyService service = get(DependencyService.class);
Hyunsun Moon5f7ed8a2016-02-10 17:02:37 -080043 private static final String BIDIRECTION = "b";
Hyunsun Moon97eaf502015-12-07 14:06:28 -080044
45 /**
Hyunsun Moon5f7ed8a2016-02-10 17:02:37 -080046 * Creates service dependencies with unidirectional access between the services.
Hyunsun Moon97eaf502015-12-07 14:06:28 -080047 *
48 * @param tServiceId tenant service id
49 * @param pServiceId provider service id
50 * @return 200 OK
51 */
52 @POST
53 @Path("{tenantServiceId}/{providerServiceId}")
54 @Produces(MediaType.APPLICATION_JSON)
Hyunsun Moon97eaf502015-12-07 14:06:28 -080055 public Response createServiceDependency(@PathParam("tenantServiceId") String tServiceId,
56 @PathParam("providerServiceId") String pServiceId) {
Hyunsun Mooneaf75e62016-09-27 16:40:23 -070057 service.createDependency(NetworkId.of(tServiceId),
58 NetworkId.of(pServiceId),
59 UNIDIRECTIONAL);
Hyunsun Moon5f7ed8a2016-02-10 17:02:37 -080060 return Response.status(Response.Status.OK).build();
61 }
62
63 /**
64 * Creates service dependencies with an access type extension between the services.
65 *
66 * @param tServiceId tenant service id
67 * @param pServiceId provider service id
68 * @param direction b for bidirectional access, otherwise unidirectional access
69 * @return 200 OK
70 */
71 @POST
72 @Path("{tenantServiceId}/{providerServiceId}/{direction}")
73 @Produces(MediaType.APPLICATION_JSON)
74 public Response createServiceDependency(@PathParam("tenantServiceId") String tServiceId,
75 @PathParam("providerServiceId") String pServiceId,
76 @PathParam("direction") String direction) {
Hyunsun Mooneaf75e62016-09-27 16:40:23 -070077 Type type = Objects.equals(direction, BIDIRECTION) ? BIDIRECTIONAL : UNIDIRECTIONAL;
78 service.createDependency(NetworkId.of(tServiceId),
79 NetworkId.of(pServiceId),
80 type);
Hyunsun Moon97eaf502015-12-07 14:06:28 -080081 return Response.status(Response.Status.OK).build();
82 }
83
84 /**
85 * Removes service dependencies.
86 *
Hyunsun Moonba290072015-12-16 20:53:23 -080087 * @param tServiceId tenant service id
88 * @param pServiceId provider service id
Jian Li1c646012016-05-10 11:48:19 -070089 * @return 204 NO CONTENT
Hyunsun Moon97eaf502015-12-07 14:06:28 -080090 */
91 @DELETE
Hyunsun Moonba290072015-12-16 20:53:23 -080092 @Path("{tenantServiceId}/{providerServiceId}")
Hyunsun Moonba290072015-12-16 20:53:23 -080093 public Response removeServiceDependency(@PathParam("tenantServiceId") String tServiceId,
94 @PathParam("providerServiceId") String pServiceId) {
Hyunsun Mooneaf75e62016-09-27 16:40:23 -070095 service.removeDependency(NetworkId.of(tServiceId), NetworkId.of(pServiceId));
Jian Li1c646012016-05-10 11:48:19 -070096 return Response.noContent().build();
Hyunsun Moon97eaf502015-12-07 14:06:28 -080097 }
Hyunsun Moon9274aaf2015-12-04 11:35:25 -080098}