blob: 805db469c87a8c2cf4a449dce026e90a7e5ba967 [file] [log] [blame]
Hyunsun Moon699f46b2015-12-04 11:35:25 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Hyunsun Moon699f46b2015-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 */
16package org.onosproject.cordvtn.rest;
17
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080018import org.onosproject.cordvtn.CordVtnService;
19import org.onosproject.cordvtn.CordServiceId;
Hyunsun Moon699f46b2015-12-04 11:35:25 -080020import org.onosproject.rest.AbstractWebResource;
21
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080022import javax.ws.rs.DELETE;
23import javax.ws.rs.POST;
Hyunsun Moon699f46b2015-12-04 11:35:25 -080024import javax.ws.rs.Path;
Hyunsun Moonbfc47d12015-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 Moon699f46b2015-12-04 11:35:25 -080029
30/**
31 * Manages service dependency.
32 */
33@Path("service-dependency")
34public class ServiceDependencyWebResource extends AbstractWebResource {
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080035
36 private final CordVtnService service = get(CordVtnService.class);
Hyunsun Moon640f183e2016-02-10 17:02:37 -080037 private static final String BIDIRECTION = "b";
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080038
39 /**
Hyunsun Moon640f183e2016-02-10 17:02:37 -080040 * Creates service dependencies with unidirectional access between the services.
Hyunsun Moonbfc47d12015-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 Moonbfc47d12015-12-07 14:06:28 -080049 public Response createServiceDependency(@PathParam("tenantServiceId") String tServiceId,
50 @PathParam("providerServiceId") String pServiceId) {
Hyunsun Moon640f183e2016-02-10 17:02:37 -080051 service.createServiceDependency(CordServiceId.of(tServiceId),
52 CordServiceId.of(pServiceId),
53 false);
54 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) {
71 service.createServiceDependency(CordServiceId.of(tServiceId),
72 CordServiceId.of(pServiceId),
73 direction.equals(BIDIRECTION));
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080074 return Response.status(Response.Status.OK).build();
75 }
76
77 /**
78 * Removes service dependencies.
79 *
Hyunsun Moonc71231d2015-12-16 20:53:23 -080080 * @param tServiceId tenant service id
81 * @param pServiceId provider service id
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080082 * @return 200 OK, or 400 Bad Request
83 */
84 @DELETE
Hyunsun Moonc71231d2015-12-16 20:53:23 -080085 @Path("{tenantServiceId}/{providerServiceId}")
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080086 @Produces(MediaType.APPLICATION_JSON)
Hyunsun Moonc71231d2015-12-16 20:53:23 -080087 public Response removeServiceDependency(@PathParam("tenantServiceId") String tServiceId,
88 @PathParam("providerServiceId") String pServiceId) {
89 service.removeServiceDependency(CordServiceId.of(tServiceId), CordServiceId.of(pServiceId));
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080090 return Response.status(Response.Status.OK).build();
91 }
Hyunsun Moon699f46b2015-12-04 11:35:25 -080092}