Hyunsun Moon | 9274aaf | 2015-12-04 11:35:25 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 8e57fd5 | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Hyunsun Moon | 9274aaf | 2015-12-04 11:35:25 -0800 | [diff] [blame] | 3 | * |
| 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 | */ |
| 16 | package org.onosproject.cordvtn.rest; |
| 17 | |
Hyunsun Moon | f948020 | 2016-04-14 16:13:42 -0700 | [diff] [blame] | 18 | import org.onosproject.cordvtn.api.CordVtnService; |
| 19 | import org.onosproject.cordvtn.api.CordServiceId; |
Hyunsun Moon | 9274aaf | 2015-12-04 11:35:25 -0800 | [diff] [blame] | 20 | import org.onosproject.rest.AbstractWebResource; |
| 21 | |
Hyunsun Moon | 97eaf50 | 2015-12-07 14:06:28 -0800 | [diff] [blame] | 22 | import javax.ws.rs.DELETE; |
| 23 | import javax.ws.rs.POST; |
Hyunsun Moon | 9274aaf | 2015-12-04 11:35:25 -0800 | [diff] [blame] | 24 | import javax.ws.rs.Path; |
Hyunsun Moon | 97eaf50 | 2015-12-07 14:06:28 -0800 | [diff] [blame] | 25 | import javax.ws.rs.PathParam; |
| 26 | import javax.ws.rs.Produces; |
| 27 | import javax.ws.rs.core.MediaType; |
| 28 | import javax.ws.rs.core.Response; |
Hyunsun Moon | 9274aaf | 2015-12-04 11:35:25 -0800 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Manages service dependency. |
| 32 | */ |
| 33 | @Path("service-dependency") |
| 34 | public class ServiceDependencyWebResource extends AbstractWebResource { |
Hyunsun Moon | 97eaf50 | 2015-12-07 14:06:28 -0800 | [diff] [blame] | 35 | |
| 36 | private final CordVtnService service = get(CordVtnService.class); |
Hyunsun Moon | 5f7ed8a | 2016-02-10 17:02:37 -0800 | [diff] [blame] | 37 | private static final String BIDIRECTION = "b"; |
Hyunsun Moon | 97eaf50 | 2015-12-07 14:06:28 -0800 | [diff] [blame] | 38 | |
| 39 | /** |
Hyunsun Moon | 5f7ed8a | 2016-02-10 17:02:37 -0800 | [diff] [blame] | 40 | * Creates service dependencies with unidirectional access between the services. |
Hyunsun Moon | 97eaf50 | 2015-12-07 14:06:28 -0800 | [diff] [blame] | 41 | * |
| 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 Moon | 97eaf50 | 2015-12-07 14:06:28 -0800 | [diff] [blame] | 49 | public Response createServiceDependency(@PathParam("tenantServiceId") String tServiceId, |
| 50 | @PathParam("providerServiceId") String pServiceId) { |
Hyunsun Moon | 5f7ed8a | 2016-02-10 17:02:37 -0800 | [diff] [blame] | 51 | 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 Moon | 97eaf50 | 2015-12-07 14:06:28 -0800 | [diff] [blame] | 74 | return Response.status(Response.Status.OK).build(); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Removes service dependencies. |
| 79 | * |
Hyunsun Moon | ba29007 | 2015-12-16 20:53:23 -0800 | [diff] [blame] | 80 | * @param tServiceId tenant service id |
| 81 | * @param pServiceId provider service id |
Jian Li | 1c64601 | 2016-05-10 11:48:19 -0700 | [diff] [blame^] | 82 | * @return 204 NO CONTENT |
Hyunsun Moon | 97eaf50 | 2015-12-07 14:06:28 -0800 | [diff] [blame] | 83 | */ |
| 84 | @DELETE |
Hyunsun Moon | ba29007 | 2015-12-16 20:53:23 -0800 | [diff] [blame] | 85 | @Path("{tenantServiceId}/{providerServiceId}") |
Hyunsun Moon | ba29007 | 2015-12-16 20:53:23 -0800 | [diff] [blame] | 86 | public Response removeServiceDependency(@PathParam("tenantServiceId") String tServiceId, |
| 87 | @PathParam("providerServiceId") String pServiceId) { |
| 88 | service.removeServiceDependency(CordServiceId.of(tServiceId), CordServiceId.of(pServiceId)); |
Jian Li | 1c64601 | 2016-05-10 11:48:19 -0700 | [diff] [blame^] | 89 | return Response.noContent().build(); |
Hyunsun Moon | 97eaf50 | 2015-12-07 14:06:28 -0800 | [diff] [blame] | 90 | } |
Hyunsun Moon | 9274aaf | 2015-12-04 11:35:25 -0800 | [diff] [blame] | 91 | } |