blob: 9c587579c23c5010815f23cf2b5cb8390e9626d0 [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 Moon486ed1b2016-05-13 18:58:35 -070019import org.onosproject.xosclient.api.VtnServiceId;
Hyunsun Moon5401aaa2016-06-12 17:40:34 -070020import org.opencord.cordvtn.api.DependencyService;
Hyunsun Moon9274aaf2015-12-04 11:35:25 -080021
Hyunsun Moon97eaf502015-12-07 14:06:28 -080022import javax.ws.rs.DELETE;
23import javax.ws.rs.POST;
Hyunsun Moon9274aaf2015-12-04 11:35:25 -080024import javax.ws.rs.Path;
Hyunsun Moon97eaf502015-12-07 14:06:28 -080025import javax.ws.rs.PathParam;
26import javax.ws.rs.Produces;
27import javax.ws.rs.core.MediaType;
28import javax.ws.rs.core.Response;
Hyunsun Moon9274aaf2015-12-04 11:35:25 -080029
30/**
31 * Manages service dependency.
32 */
33@Path("service-dependency")
34public class ServiceDependencyWebResource extends AbstractWebResource {
Hyunsun Moon97eaf502015-12-07 14:06:28 -080035
Hyunsun Moon5401aaa2016-06-12 17:40:34 -070036 private final DependencyService service = get(DependencyService.class);
Hyunsun Moon5f7ed8a2016-02-10 17:02:37 -080037 private static final String BIDIRECTION = "b";
Hyunsun Moon97eaf502015-12-07 14:06:28 -080038
39 /**
Hyunsun Moon5f7ed8a2016-02-10 17:02:37 -080040 * Creates service dependencies with unidirectional access between the services.
Hyunsun Moon97eaf502015-12-07 14:06:28 -080041 *
42 * @param tServiceId tenant service id
43 * @param pServiceId provider service id
44 * @return 200 OK
45 */
46 @POST
47 @Path("{tenantServiceId}/{providerServiceId}")
48 @Produces(MediaType.APPLICATION_JSON)
Hyunsun Moon97eaf502015-12-07 14:06:28 -080049 public Response createServiceDependency(@PathParam("tenantServiceId") String tServiceId,
50 @PathParam("providerServiceId") String pServiceId) {
Hyunsun Moon5401aaa2016-06-12 17:40:34 -070051 service.createDependency(VtnServiceId.of(tServiceId),
52 VtnServiceId.of(pServiceId),
53 false);
Hyunsun Moon5f7ed8a2016-02-10 17:02:37 -080054 return Response.status(Response.Status.OK).build();
55 }
56
57 /**
58 * Creates service dependencies with an access type extension between the services.
59 *
60 * @param tServiceId tenant service id
61 * @param pServiceId provider service id
62 * @param direction b for bidirectional access, otherwise unidirectional access
63 * @return 200 OK
64 */
65 @POST
66 @Path("{tenantServiceId}/{providerServiceId}/{direction}")
67 @Produces(MediaType.APPLICATION_JSON)
68 public Response createServiceDependency(@PathParam("tenantServiceId") String tServiceId,
69 @PathParam("providerServiceId") String pServiceId,
70 @PathParam("direction") String direction) {
Hyunsun Moon5401aaa2016-06-12 17:40:34 -070071 service.createDependency(VtnServiceId.of(tServiceId),
72 VtnServiceId.of(pServiceId),
73 direction.equals(BIDIRECTION));
Hyunsun Moon97eaf502015-12-07 14:06:28 -080074 return Response.status(Response.Status.OK).build();
75 }
76
77 /**
78 * Removes service dependencies.
79 *
Hyunsun Moonba290072015-12-16 20:53:23 -080080 * @param tServiceId tenant service id
81 * @param pServiceId provider service id
Jian Li1c646012016-05-10 11:48:19 -070082 * @return 204 NO CONTENT
Hyunsun Moon97eaf502015-12-07 14:06:28 -080083 */
84 @DELETE
Hyunsun Moonba290072015-12-16 20:53:23 -080085 @Path("{tenantServiceId}/{providerServiceId}")
Hyunsun Moonba290072015-12-16 20:53:23 -080086 public Response removeServiceDependency(@PathParam("tenantServiceId") String tServiceId,
87 @PathParam("providerServiceId") String pServiceId) {
Hyunsun Moon5401aaa2016-06-12 17:40:34 -070088 service.removeDependency(VtnServiceId.of(tServiceId), VtnServiceId.of(pServiceId));
Jian Li1c646012016-05-10 11:48:19 -070089 return Response.noContent().build();
Hyunsun Moon97eaf502015-12-07 14:06:28 -080090 }
Hyunsun Moon9274aaf2015-12-04 11:35:25 -080091}