Hyunsun Moon
Committed by Gerrit Code Review

[Falcon] CORD-368 Skeleton of service dependency APIs

- Changed service ID from VNI to network ID
- Added REST APIs(POST/DELETE/PUT)
- Added interfaces to CordVtnService(create/remove)
- Renamed Service/ServiceId to more specific

Change-Id: I80322fea28a7740a2cc7723b576e7bb9ff08389e
...@@ -33,6 +33,13 @@ ...@@ -33,6 +33,13 @@
33 33
34 <properties> 34 <properties>
35 <onos.app.name>org.onosproject.cordvtn</onos.app.name> 35 <onos.app.name>org.onosproject.cordvtn</onos.app.name>
36 + <web.context>/onos/cordvtn</web.context>
37 + <api.version>1.0.0</api.version>
38 + <api.title>CORD VTN REST API</api.title>
39 + <api.description>
40 + APIs for interacting with the CORD VTN application.
41 + </api.description>
42 + <api.package>org.onosproject.cordvtn.rest</api.package>
36 <onos.app.requires> 43 <onos.app.requires>
37 org.onosproject.ovsdb, 44 org.onosproject.ovsdb,
38 org.onosproject.openstackswitching 45 org.onosproject.openstackswitching
...@@ -102,4 +109,47 @@ ...@@ -102,4 +109,47 @@
102 </dependency> 109 </dependency>
103 </dependencies> 110 </dependencies>
104 111
112 + <build>
113 + <plugins>
114 + <plugin>
115 + <groupId>org.apache.felix</groupId>
116 + <artifactId>maven-bundle-plugin</artifactId>
117 + <extensions>true</extensions>
118 + <configuration>
119 + <instructions>
120 + <_wab>src/main/webapp/</_wab>
121 + <Include-Resource>
122 + WEB-INF/classes/apidoc/swagger.json=target/swagger.json,
123 + {maven-resources}
124 + </Include-Resource>
125 + <Bundle-SymbolicName>
126 + ${project.groupId}.${project.artifactId}
127 + </Bundle-SymbolicName>
128 + <Import-Package>
129 + org.slf4j,
130 + org.osgi.framework,
131 + javax.ws.rs,
132 + javax.ws.rs.core,
133 + com.sun.jersey.api.core,
134 + com.sun.jersey.spi.container.servlet,
135 + com.sun.jersey.server.impl.container.servlet,
136 + com.fasterxml.jackson.databind,
137 + com.fasterxml.jackson.databind.node,
138 + com.fasterxml.jackson.core,
139 + org.apache.karaf.shell.commands,
140 + org.apache.karaf.shell.console,
141 + com.google.common.*,
142 + org.onlab.packet.*,
143 + org.onlab.rest.*,
144 + org.onosproject.*,
145 + org.onlab.util.*,
146 + org.jboss.netty.util.*
147 + </Import-Package>
148 + <Web-ContextPath>${web.context}</Web-ContextPath>
149 + </instructions>
150 + </configuration>
151 + </plugin>
152 + </plugins>
153 + </build>
154 +
105 </project> 155 </project>
......
...@@ -21,7 +21,7 @@ import org.onlab.packet.IpPrefix; ...@@ -21,7 +21,7 @@ import org.onlab.packet.IpPrefix;
21 21
22 import java.util.Objects; 22 import java.util.Objects;
23 23
24 -public final class Service { 24 +public final class CordService {
25 25
26 enum ServiceType { 26 enum ServiceType {
27 PRIVATE, 27 PRIVATE,
...@@ -31,8 +31,8 @@ public final class Service { ...@@ -31,8 +31,8 @@ public final class Service {
31 PUBLIC_INDIRECT 31 PUBLIC_INDIRECT
32 } 32 }
33 33
34 - private final ServiceId serviceId; 34 + private final CordServiceId id;
35 - private final String networkId; 35 + private final long segmentationId;
36 private final ServiceType serviceType; 36 private final ServiceType serviceType;
37 private final IpPrefix serviceIpRange; 37 private final IpPrefix serviceIpRange;
38 private final IpAddress serviceIp; 38 private final IpAddress serviceIp;
...@@ -40,16 +40,16 @@ public final class Service { ...@@ -40,16 +40,16 @@ public final class Service {
40 /** 40 /**
41 * Default constructor. 41 * Default constructor.
42 * 42 *
43 - * @param serviceId service id 43 + * @param id service id, which is identical to OpenStack network id
44 - * @param networkId OpenStack Neutron network id 44 + * @param segmentationId segmentation id, which is identical to VNI
45 * @param serviceType service type 45 * @param serviceType service type
46 * @param serviceIpRange service ip range 46 * @param serviceIpRange service ip range
47 * @param serviceIp service ip 47 * @param serviceIp service ip
48 */ 48 */
49 - public Service(ServiceId serviceId, String networkId, ServiceType serviceType, 49 + public CordService(CordServiceId id, long segmentationId, ServiceType serviceType,
50 IpPrefix serviceIpRange, IpAddress serviceIp) { 50 IpPrefix serviceIpRange, IpAddress serviceIp) {
51 - this.serviceId = serviceId; 51 + this.id = id;
52 - this.networkId = networkId; 52 + this.segmentationId = segmentationId;
53 this.serviceType = serviceType; 53 this.serviceType = serviceType;
54 this.serviceIpRange = serviceIpRange; 54 this.serviceIpRange = serviceIpRange;
55 this.serviceIp = serviceIp; 55 this.serviceIp = serviceIp;
...@@ -60,17 +60,17 @@ public final class Service { ...@@ -60,17 +60,17 @@ public final class Service {
60 * 60 *
61 * @return service id 61 * @return service id
62 */ 62 */
63 - public ServiceId serviceId() { 63 + public CordServiceId id() {
64 - return serviceId; 64 + return id;
65 } 65 }
66 66
67 /** 67 /**
68 - * Returns OpenStack Neutron network ID of this service. 68 + * Returns segmentation ID of this service.
69 * 69 *
70 - * @return network id 70 + * @return segmentation id
71 */ 71 */
72 - public String networkId() { 72 + public long segmentationId() {
73 - return networkId; 73 + return segmentationId;
74 } 74 }
75 75
76 /** 76 /**
...@@ -102,7 +102,7 @@ public final class Service { ...@@ -102,7 +102,7 @@ public final class Service {
102 102
103 @Override 103 @Override
104 public int hashCode() { 104 public int hashCode() {
105 - return Objects.hash(serviceId); 105 + return Objects.hash(id);
106 } 106 }
107 107
108 @Override 108 @Override
...@@ -110,18 +110,18 @@ public final class Service { ...@@ -110,18 +110,18 @@ public final class Service {
110 if (this == obj) { 110 if (this == obj) {
111 return true; 111 return true;
112 } 112 }
113 - if (!(obj instanceof Service)) { 113 + if (!(obj instanceof CordService)) {
114 return false; 114 return false;
115 } 115 }
116 - final Service other = (Service) obj; 116 + final CordService other = (CordService) obj;
117 - return Objects.equals(this.serviceId, other.serviceId); 117 + return Objects.equals(this.id, other.id);
118 } 118 }
119 119
120 @Override 120 @Override
121 public String toString() { 121 public String toString() {
122 return MoreObjects.toStringHelper(this) 122 return MoreObjects.toStringHelper(this)
123 - .add("serviceId", serviceId) 123 + .add("id", id)
124 - .add("networkId", networkId) 124 + .add("segmentationId", segmentationId)
125 .add("serviceType", serviceType) 125 .add("serviceType", serviceType)
126 .add("serviceIpRange", serviceIpRange) 126 .add("serviceIpRange", serviceIpRange)
127 .add("serviceIp", serviceIp) 127 .add("serviceIp", serviceIp)
......
...@@ -19,30 +19,33 @@ import com.google.common.base.MoreObjects; ...@@ -19,30 +19,33 @@ import com.google.common.base.MoreObjects;
19 19
20 import java.util.Objects; 20 import java.util.Objects;
21 21
22 +import static com.google.common.base.Preconditions.checkNotNull;
23 +
22 /** 24 /**
23 * Representation of service identifier. 25 * Representation of service identifier.
24 */ 26 */
25 -public final class ServiceId { 27 +public final class CordServiceId {
26 28
27 - private final long serviceId; 29 + private final String id;
28 30
29 /** 31 /**
30 * Default constructor. 32 * Default constructor.
31 * 33 *
32 - * @param serviceId service identifier 34 + * @param id service identifier
33 */ 35 */
34 - private ServiceId(long serviceId) { 36 + private CordServiceId(String id) {
35 - this.serviceId = serviceId; 37 + this.id = id;
36 } 38 }
37 39
38 /** 40 /**
39 - * Returns the ServiceId with value. 41 + * Returns the CordServiceId with value.
40 * 42 *
41 - * @param serviceId service id 43 + * @param id service id
42 - * @return ServiceId 44 + * @return CordServiceId
43 */ 45 */
44 - public static ServiceId of(long serviceId) { 46 + public static CordServiceId of(String id) {
45 - return new ServiceId(serviceId); 47 + checkNotNull(id);
48 + return new CordServiceId(id);
46 } 49 }
47 50
48 /** 51 /**
...@@ -50,13 +53,13 @@ public final class ServiceId { ...@@ -50,13 +53,13 @@ public final class ServiceId {
50 * 53 *
51 * @return service id 54 * @return service id
52 */ 55 */
53 - public long serviceId() { 56 + public String id() {
54 - return serviceId; 57 + return id;
55 } 58 }
56 59
57 @Override 60 @Override
58 public int hashCode() { 61 public int hashCode() {
59 - return Objects.hash(serviceId); 62 + return Objects.hash(id);
60 } 63 }
61 64
62 @Override 65 @Override
...@@ -64,17 +67,17 @@ public final class ServiceId { ...@@ -64,17 +67,17 @@ public final class ServiceId {
64 if (this == obj) { 67 if (this == obj) {
65 return true; 68 return true;
66 } 69 }
67 - if (!(obj instanceof ServiceId)) { 70 + if (!(obj instanceof CordServiceId)) {
68 return false; 71 return false;
69 } 72 }
70 - final ServiceId other = (ServiceId) obj; 73 + final CordServiceId other = (CordServiceId) obj;
71 - return Objects.equals(this.serviceId, other.serviceId); 74 + return Objects.equals(this.id, other.id);
72 } 75 }
73 76
74 @Override 77 @Override
75 public String toString() { 78 public String toString() {
76 return MoreObjects.toStringHelper(this) 79 return MoreObjects.toStringHelper(this)
77 - .add("serviceId", serviceId) 80 + .add("id", id)
78 .toString(); 81 .toString();
79 } 82 }
80 } 83 }
......
...@@ -277,11 +277,19 @@ public class CordVtn implements CordVtnService { ...@@ -277,11 +277,19 @@ public class CordVtn implements CordVtnService {
277 } 277 }
278 278
279 @Override 279 @Override
280 - public void createServiceDependency(ServiceId tenantServiceId, ServiceId providerServiceId) { 280 + public void createServiceDependency(CordServiceId tenantCordServiceId,
281 + CordServiceId providerCordServiceId) {
282 + CordService tenantService = getCordService(tenantCordServiceId);
283 + CordService providerService = getCordService(providerCordServiceId);
284 +
285 + // TODO populate flow rules to create service dependency
281 } 286 }
282 287
283 @Override 288 @Override
284 - public void removeServiceDependency(ServiceId tenantServiceId, ServiceId providerServiceId) { 289 + public void removeServiceDependency(CordServiceId tenantCordServiceId) {
290 + CordService tenantService = getCordService(tenantCordServiceId);
291 +
292 + //TODO uninstall flow rules to remove service dependency
285 } 293 }
286 294
287 /** 295 /**
...@@ -688,6 +696,23 @@ public class CordVtn implements CordVtnService { ...@@ -688,6 +696,23 @@ public class CordVtn implements CordVtnService {
688 } 696 }
689 697
690 /** 698 /**
699 + * Returns OpenStack network associated with a given CORD service.
700 + *
701 + * @param serviceId service id
702 + * @return cord service, or null if it fails to get network from OpenStack
703 + */
704 + private CordService getCordService(CordServiceId serviceId) {
705 + OpenstackNetwork vNet = openstackService.network(serviceId.id());
706 + if (vNet == null) {
707 + log.warn("Couldn't find OpenStack network for service {}", serviceId.id());
708 + return null;
709 + }
710 +
711 + // TODO create CordService with network/subnet information from Neutron
712 + return null;
713 + }
714 +
715 + /**
691 * Installs flow rules for a given OpenStack network. 716 * Installs flow rules for a given OpenStack network.
692 * 717 *
693 * @param vNet OpenStack network 718 * @param vNet OpenStack network
......
...@@ -67,18 +67,17 @@ public interface CordVtnService { ...@@ -67,18 +67,17 @@ public interface CordVtnService {
67 List<CordVtnNode> getNodes(); 67 List<CordVtnNode> getNodes();
68 68
69 /** 69 /**
70 - * Creates a dependency between two services. 70 + * Creates dependencies for a given tenant service.
71 * 71 *
72 - * @param tenantServiceId id of the service which has a dependency 72 + * @param tenantCordServiceId id of the service which has a dependency
73 - * @param providerServiceId id of the service which provides dependency 73 + * @param providerCordServiceId id of the service which provide dependency
74 */ 74 */
75 - void createServiceDependency(ServiceId tenantServiceId, ServiceId providerServiceId); 75 + void createServiceDependency(CordServiceId tenantCordServiceId, CordServiceId providerCordServiceId);
76 76
77 /** 77 /**
78 - * Removes a dependency between two services. 78 + * Removes all dependencies from a given tenant service.
79 * 79 *
80 - * @param tenantServiceId id of the service which has a dependency 80 + * @param tenantCordServiceId id of the service which has a dependency
81 - * @param providerServiceId id of the service which provides dependency
82 */ 81 */
83 - void removeServiceDependency(ServiceId tenantServiceId, ServiceId providerServiceId); 82 + void removeServiceDependency(CordServiceId tenantCordServiceId);
84 } 83 }
......
1 /* 1 /*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2014-2015 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -13,17 +13,19 @@ ...@@ -13,17 +13,19 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 +
16 package org.onosproject.cordvtn.rest; 17 package org.onosproject.cordvtn.rest;
17 18
18 -import org.apache.felix.scr.annotations.Component; 19 +import org.onlab.rest.AbstractWebApplication;
19 -import org.onosproject.rest.AbstractApiDocRegistrator; 20 +
20 -import org.onosproject.rest.ApiDocProvider; 21 +import java.util.Set;
21 22
22 -@Component(immediate = true) 23 +/**
23 -public class ApiDocRegistrator extends AbstractApiDocRegistrator { 24 + * CORD VTN Web application.
24 - public ApiDocRegistrator() { 25 + */
25 - super(new ApiDocProvider("/onos/cordvtn", 26 +public class CordVtnWebApplication extends AbstractWebApplication {
26 - "CORD VTN Service REST API", 27 + @Override
27 - ApiDocRegistrator.class.getClassLoader())); 28 + public Set<Class<?>> getClasses() {
29 + return getClasses(ServiceDependencyWebResource.class);
28 } 30 }
29 } 31 }
......
...@@ -15,13 +15,74 @@ ...@@ -15,13 +15,74 @@
15 */ 15 */
16 package org.onosproject.cordvtn.rest; 16 package org.onosproject.cordvtn.rest;
17 17
18 +import org.onosproject.cordvtn.CordVtnService;
19 +import org.onosproject.cordvtn.CordServiceId;
18 import org.onosproject.rest.AbstractWebResource; 20 import org.onosproject.rest.AbstractWebResource;
19 21
22 +import javax.ws.rs.Consumes;
23 +import javax.ws.rs.DELETE;
24 +import javax.ws.rs.POST;
25 +import javax.ws.rs.PUT;
20 import javax.ws.rs.Path; 26 import javax.ws.rs.Path;
27 +import javax.ws.rs.PathParam;
28 +import javax.ws.rs.Produces;
29 +import javax.ws.rs.core.MediaType;
30 +import javax.ws.rs.core.Response;
31 +import java.io.InputStream;
21 32
22 /** 33 /**
23 * Manages service dependency. 34 * Manages service dependency.
24 */ 35 */
25 @Path("service-dependency") 36 @Path("service-dependency")
26 public class ServiceDependencyWebResource extends AbstractWebResource { 37 public class ServiceDependencyWebResource extends AbstractWebResource {
38 +
39 + private final CordVtnService service = get(CordVtnService.class);
40 +
41 + /**
42 + * Creates service dependencies.
43 + *
44 + * @param tServiceId tenant service id
45 + * @param pServiceId provider service id
46 + * @return 200 OK
47 + */
48 + @POST
49 + @Path("{tenantServiceId}/{providerServiceId}")
50 + @Produces(MediaType.APPLICATION_JSON)
51 + @Consumes(MediaType.APPLICATION_JSON)
52 + public Response createServiceDependency(@PathParam("tenantServiceId") String tServiceId,
53 + @PathParam("providerServiceId") String pServiceId) {
54 + service.createServiceDependency(CordServiceId.of(tServiceId), CordServiceId.of(pServiceId));
55 + return Response.status(Response.Status.OK).build();
56 + }
57 +
58 + /**
59 + * Removes service dependencies.
60 + *
61 + * @param serviceId service id
62 + * @return 200 OK, or 400 Bad Request
63 + */
64 + @DELETE
65 + @Path("{serviceId}")
66 + @Produces(MediaType.APPLICATION_JSON)
67 + public Response removeServiceDependency(@PathParam("serviceId") String serviceId) {
68 + service.removeServiceDependency(CordServiceId.of(serviceId));
69 + return Response.status(Response.Status.OK).build();
70 + }
71 +
72 + /**
73 + * Updates service dependencies.
74 + *
75 + * @param serviceId service id
76 + * @param stream input JSON
77 + * @return 200 OK, or 400 Bad Request
78 + */
79 + @PUT
80 + @Path("{serviceId}")
81 + @Produces(MediaType.APPLICATION_JSON)
82 + @Consumes(MediaType.APPLICATION_JSON)
83 + public Response updateServiceDependency(@PathParam("serviceId") String serviceId,
84 + InputStream stream) {
85 + // TODO define input stream
86 + return Response.status(Response.Status.OK).build();
87 + }
27 } 88 }
......
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2015 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
18 + xmlns="http://java.sun.com/xml/ns/javaee"
19 + xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
20 + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
21 + id="ONOS" version="2.5">
22 + <display-name>CORD VTN REST API v1.0</display-name>
23 +
24 + <security-constraint>
25 + <web-resource-collection>
26 + <web-resource-name>Secured</web-resource-name>
27 + <url-pattern>/*</url-pattern>
28 + </web-resource-collection>
29 + <auth-constraint>
30 + <role-name>admin</role-name>
31 + </auth-constraint>
32 + </security-constraint>
33 +
34 + <security-role>
35 + <role-name>admin</role-name>
36 + </security-role>
37 +
38 + <login-config>
39 + <auth-method>BASIC</auth-method>
40 + <realm-name>karaf</realm-name>
41 + </login-config>
42 +
43 + <servlet>
44 + <servlet-name>JAX-RS Service</servlet-name>
45 + <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
46 + <init-param>
47 + <param-name>javax.ws.rs.Application</param-name>
48 + <param-value>org.onosproject.cordvtn.rest.CordVtnWebApplication</param-value>
49 + </init-param>
50 + <load-on-startup>1</load-on-startup>
51 + </servlet>
52 +
53 + <servlet-mapping>
54 + <servlet-name>JAX-RS Service</servlet-name>
55 + <url-pattern>/*</url-pattern>
56 + </servlet-mapping>
57 +</web-app>