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 | */ |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 16 | package org.opencord.cordvtn.rest; |
Hyunsun Moon | 9274aaf | 2015-12-04 11:35:25 -0800 | [diff] [blame] | 17 | |
| 18 | import org.onosproject.rest.AbstractWebResource; |
Hyunsun Moon | eaf75e6 | 2016-09-27 16:40:23 -0700 | [diff] [blame] | 19 | import org.opencord.cordvtn.api.Dependency.Type; |
Hyunsun Moon | 5401aaa | 2016-06-12 17:40:34 -0700 | [diff] [blame] | 20 | import org.opencord.cordvtn.api.DependencyService; |
Hyunsun Moon | eaf75e6 | 2016-09-27 16:40:23 -0700 | [diff] [blame] | 21 | import org.opencord.cordvtn.api.NetworkId; |
Hyunsun Moon | 9274aaf | 2015-12-04 11:35:25 -0800 | [diff] [blame] | 22 | |
Hyunsun Moon | 97eaf50 | 2015-12-07 14:06:28 -0800 | [diff] [blame] | 23 | import javax.ws.rs.DELETE; |
| 24 | import javax.ws.rs.POST; |
Hyunsun Moon | 9274aaf | 2015-12-04 11:35:25 -0800 | [diff] [blame] | 25 | import javax.ws.rs.Path; |
Hyunsun Moon | 97eaf50 | 2015-12-07 14:06:28 -0800 | [diff] [blame] | 26 | import javax.ws.rs.PathParam; |
| 27 | import javax.ws.rs.Produces; |
| 28 | import javax.ws.rs.core.MediaType; |
| 29 | import javax.ws.rs.core.Response; |
Hyunsun Moon | eaf75e6 | 2016-09-27 16:40:23 -0700 | [diff] [blame] | 30 | import java.util.Objects; |
| 31 | |
| 32 | import static org.opencord.cordvtn.api.Dependency.Type.BIDIRECTIONAL; |
| 33 | import static org.opencord.cordvtn.api.Dependency.Type.UNIDIRECTIONAL; |
Hyunsun Moon | 9274aaf | 2015-12-04 11:35:25 -0800 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Manages service dependency. |
| 37 | */ |
Hyunsun Moon | eaf75e6 | 2016-09-27 16:40:23 -0700 | [diff] [blame] | 38 | @Deprecated |
Hyunsun Moon | 9274aaf | 2015-12-04 11:35:25 -0800 | [diff] [blame] | 39 | @Path("service-dependency") |
| 40 | public class ServiceDependencyWebResource extends AbstractWebResource { |
Hyunsun Moon | 97eaf50 | 2015-12-07 14:06:28 -0800 | [diff] [blame] | 41 | |
Hyunsun Moon | 5401aaa | 2016-06-12 17:40:34 -0700 | [diff] [blame] | 42 | private final DependencyService service = get(DependencyService.class); |
Hyunsun Moon | 5f7ed8a | 2016-02-10 17:02:37 -0800 | [diff] [blame] | 43 | private static final String BIDIRECTION = "b"; |
Hyunsun Moon | 97eaf50 | 2015-12-07 14:06:28 -0800 | [diff] [blame] | 44 | |
| 45 | /** |
Hyunsun Moon | 5f7ed8a | 2016-02-10 17:02:37 -0800 | [diff] [blame] | 46 | * Creates service dependencies with unidirectional access between the services. |
Hyunsun Moon | 97eaf50 | 2015-12-07 14:06:28 -0800 | [diff] [blame] | 47 | * |
| 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 Moon | 97eaf50 | 2015-12-07 14:06:28 -0800 | [diff] [blame] | 55 | public Response createServiceDependency(@PathParam("tenantServiceId") String tServiceId, |
| 56 | @PathParam("providerServiceId") String pServiceId) { |
Hyunsun Moon | eaf75e6 | 2016-09-27 16:40:23 -0700 | [diff] [blame] | 57 | service.createDependency(NetworkId.of(tServiceId), |
| 58 | NetworkId.of(pServiceId), |
| 59 | UNIDIRECTIONAL); |
Hyunsun Moon | 5f7ed8a | 2016-02-10 17:02:37 -0800 | [diff] [blame] | 60 | 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 Moon | eaf75e6 | 2016-09-27 16:40:23 -0700 | [diff] [blame] | 77 | Type type = Objects.equals(direction, BIDIRECTION) ? BIDIRECTIONAL : UNIDIRECTIONAL; |
| 78 | service.createDependency(NetworkId.of(tServiceId), |
| 79 | NetworkId.of(pServiceId), |
| 80 | type); |
Hyunsun Moon | 97eaf50 | 2015-12-07 14:06:28 -0800 | [diff] [blame] | 81 | return Response.status(Response.Status.OK).build(); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Removes service dependencies. |
| 86 | * |
Hyunsun Moon | ba29007 | 2015-12-16 20:53:23 -0800 | [diff] [blame] | 87 | * @param tServiceId tenant service id |
| 88 | * @param pServiceId provider service id |
Jian Li | 1c64601 | 2016-05-10 11:48:19 -0700 | [diff] [blame] | 89 | * @return 204 NO CONTENT |
Hyunsun Moon | 97eaf50 | 2015-12-07 14:06:28 -0800 | [diff] [blame] | 90 | */ |
| 91 | @DELETE |
Hyunsun Moon | ba29007 | 2015-12-16 20:53:23 -0800 | [diff] [blame] | 92 | @Path("{tenantServiceId}/{providerServiceId}") |
Hyunsun Moon | ba29007 | 2015-12-16 20:53:23 -0800 | [diff] [blame] | 93 | public Response removeServiceDependency(@PathParam("tenantServiceId") String tServiceId, |
| 94 | @PathParam("providerServiceId") String pServiceId) { |
Hyunsun Moon | eaf75e6 | 2016-09-27 16:40:23 -0700 | [diff] [blame] | 95 | service.removeDependency(NetworkId.of(tServiceId), NetworkId.of(pServiceId)); |
Jian Li | 1c64601 | 2016-05-10 11:48:19 -0700 | [diff] [blame] | 96 | return Response.noContent().build(); |
Hyunsun Moon | 97eaf50 | 2015-12-07 14:06:28 -0800 | [diff] [blame] | 97 | } |
Hyunsun Moon | 9274aaf | 2015-12-04 11:35:25 -0800 | [diff] [blame] | 98 | } |