Add a REST APIs support for IOVIsor module 09/30409/4
authoradetalhouet <adetalhouet@inocybe.com>
Mon, 30 Nov 2015 23:25:25 +0000 (18:25 -0500)
committerAlexis de Talhouët <adetalhouet@inocybe.com>
Tue, 1 Dec 2015 16:00:33 +0000 (16:00 +0000)
- provide aaa authentication
- path is: /controller/sb/iovisor/{SERVICE}

For now we have one service being: /policies
Through this one we will POST a list of policies for the
IOVisor module to GET.

To play with thee REST interface, you can use this
postman collection: https://www.getpostman.com/collections/3b1fe6ef1ec0ead72ee7

Another patch will implement the POST correctly

Change-Id: I5186df6b5d0501dca8b244bfd04e22dd54649b40
Signed-off-by: adetalhouet <adetalhouet@inocybe.com>
features/pom.xml
features/src/main/features/features.xml
renderers/iovisor/enunciate.xml [new file with mode: 0644]
renderers/iovisor/pom.xml
renderers/iovisor/src/main/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/sbrest/IovisorModuleService.java [new file with mode: 0644]
renderers/iovisor/src/main/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/sbrest/IovisorRSApplication.java [new file with mode: 0644]
renderers/iovisor/src/main/resources/WEB-INF/web.xml [new file with mode: 0644]

index 721a2d5ce2069272d40fe0cc330119d2348e5343..4f789f3c986ca5654baafe04d28b4f91f4b3c278 100755 (executable)
@@ -24,6 +24,7 @@
   </prerequisites>
 
   <properties>
+    <aaa.version>0.3.0-SNAPSHOT</aaa.version>
     <mdsal.version>2.0.0-SNAPSHOT</mdsal.version>
     <mdsal.model.version>0.8.0-SNAPSHOT</mdsal.model.version>
     <controller.mdsal.version>1.3.0-SNAPSHOT</controller.mdsal.version>
       <type>xml</type>
     </dependency>
 
+    <!-- AAA -->
+    <dependency>
+      <groupId>org.opendaylight.aaa</groupId>
+      <artifactId>features-aaa</artifactId>
+      <version>${aaa.version}</version>
+      <classifier>features</classifier>
+      <type>xml</type>
+    </dependency>
+
+    <!-- JERSEY -->
+    <dependency>
+        <groupId>com.sun.jersey</groupId>
+        <artifactId>jersey-core</artifactId>
+    </dependency>
+    <dependency>
+        <groupId>com.sun.jersey</groupId>
+        <artifactId>jersey-server</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller.thirdparty</groupId>
+      <artifactId>com.sun.jersey.jersey-servlet</artifactId>
+    </dependency>
+
     <!-- GBP -->
     <dependency>
       <groupId>commons-net</groupId>
index e7422e2187c75d48781835af75dbfdececae8a53..1e7cef5bd54d40290f8a6764ac6b3cf001d1a353 100755 (executable)
@@ -27,6 +27,8 @@
     <repository>mvn:org.opendaylight.netconf/features-restconf/{{VERSION}}/xml/features</repository>
     <!-- Repos needed by the UI -->
     <repository>mvn:org.opendaylight.dlux/features-dlux/{{VERSION}}/xml/features</repository>
+    <!-- Repos needed by IOvisor Renderer -->
+    <repository>mvn:org.opendaylight.aaa/features-aaa/${aaa.version}/xml/features</repository>
 
     <!-- The common GBP components -->
     <feature name='odl-groupbasedpolicy-base' version='${project.version}' description='OpenDaylight :: groupbasedpolicy :: Base Copmonents'>
 
         This renderer maps GBP service model to agents of the IOVisor Linux Foundation project.
     -->
-    <feature name='odl-groupbasedpolicy-iovisor' version='${project.version}' description='OpenDaylight :: groupbasedpolicy :: IOVisor Renderer'>
+    <feature name='odl-groupbasedpolicy-iovisor' version='${project.version}'
+        description='OpenDaylight :: groupbasedpolicy :: IOVisor Renderer'>
+        <feature>war</feature>
+        <feature version='${aaa.version}'>odl-aaa-authn</feature>
         <feature version="${project.version}">odl-groupbasedpolicy-base</feature>
         <bundle>mvn:org.opendaylight.groupbasedpolicy/iovisor-renderer/{{VERSION}}</bundle>
+        <bundle>mvn:com.sun.jersey/jersey-core/${jersey.version}</bundle>
+        <bundle>mvn:com.sun.jersey/jersey-server/${jersey.version}</bundle>
+        <bundle>mvn:com.sun.jersey/jersey-servlet/${jersey.version}</bundle>
         <configfile finalname="${config.configfile.directory}/15-groupbasedpolicy-iovisor.xml">mvn:org.opendaylight.groupbasedpolicy/iovisor-renderer/{{VERSION}}/xml/config</configfile>
     </feature>
 
diff --git a/renderers/iovisor/enunciate.xml b/renderers/iovisor/enunciate.xml
new file mode 100644 (file)
index 0000000..80d540a
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<enunciate label="full" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:noNamespaceSchemaLocation="http://enunciate.codehaus.org/schemas/enunciate-1.28.xsd">
+
+  <services>
+    <rest defaultRestSubcontext="/controller/sb/iovisor"/>
+  </services>
+
+  <modules>
+    <docs docsDir="rest" title="IOVisor Renderer REST API" includeExampleXml="false" includeExampleJson="true"/>
+   </modules>
+</enunciate>
index e3ecf4d411a4310d86c3c0ad7e08478678be6240..f608602dd26d7b91f01244b38ce9eb4b7adfa40a 100644 (file)
       <groupId>org.opendaylight.mdsal.model</groupId>
       <artifactId>yang-ext</artifactId>
     </dependency>
+
+    <!-- JERSEY -->
+    <dependency>
+        <groupId>com.sun.jersey</groupId>
+        <artifactId>jersey-core</artifactId>
+    </dependency>
+    <dependency>
+        <groupId>com.sun.jersey</groupId>
+        <artifactId>jersey-server</artifactId>
+    </dependency>
+    <dependency>
+        <groupId>org.opendaylight.controller.thirdparty</groupId>
+        <artifactId>com.sun.jersey.jersey-servlet</artifactId>
+    </dependency>
+
+    <!-- Eclipse persistence -->
+    <dependency>
+        <groupId>org.eclipse.persistence</groupId>
+        <artifactId>org.eclipse.persistence.moxy</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.codehaus.enunciate</groupId>
+      <artifactId>enunciate-core-annotations</artifactId>
+    </dependency>
+
     <!-- testing dependencies -->
     <dependency>
       <groupId>junit</groupId>
       <scope>test</scope>
     </dependency>
   </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Import-Package>
+              org.eclipse.jetty.servlets,
+              com.sun.jersey.spi.container.servlet,*
+              </Import-Package>
+            <Web-ContextPath>/controller/sb/iovisor</Web-ContextPath>
+          </instructions>
+          <manifestLocation>${project.basedir}/src/main/resources/META-INF</manifestLocation>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
 </project>
diff --git a/renderers/iovisor/src/main/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/sbrest/IovisorModuleService.java b/renderers/iovisor/src/main/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/sbrest/IovisorModuleService.java
new file mode 100644 (file)
index 0000000..1803b3f
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2015 Inocybe Technologies and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.renderer.iovisor.sbrest;
+
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Path("/policies")
+public class IovisorModuleService {
+
+    private static final Logger LOG = LoggerFactory.getLogger(IovisorModuleService.class);
+
+    private static final String RESOLVED_POLICY_URI = "/restconf/operational/resolved-policy:resolved-policies/resolved-policy:resolved-policy";
+
+    @POST
+    @Produces({ MediaType.APPLICATION_JSON })
+    @Consumes({ MediaType.APPLICATION_JSON })
+    public Response sendResolvedPolicies(List<String> resolvedPoliciesID) {
+        // TODO create resolvedPolicies coder/decoder
+        LOG.info("Sent resolvedPolicies to IOVisorModule {}", "MODULE_INSTANCE");
+        return Response.status(200).entity(resolvedPoliciesID).build();
+    }
+
+    @GET
+    @Produces({MediaType.TEXT_PLAIN})
+    public Response test() {
+      String result = "Our SBREST Module is up and running\n\n";
+      return Response.status(200).entity(result).build();
+    }
+}
diff --git a/renderers/iovisor/src/main/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/sbrest/IovisorRSApplication.java b/renderers/iovisor/src/main/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/sbrest/IovisorRSApplication.java
new file mode 100644 (file)
index 0000000..0aac16e
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2015 Inocybe Technologies and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.renderer.iovisor.sbrest;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+/**
+ * This class is an instance of javax.ws.rs.core.Application and is used to
+ * return the classes that will be instantiated for JAXRS processing. This is
+ * necessary because package scanning in jersey doesn't yet work in OSGi
+ * environment.
+ *
+ */
+public class IovisorRSApplication extends Application {
+
+    @Override
+    public Set<Class<?>> getClasses() {
+        Set<Class<?>> classes = new HashSet<Class<?>>();
+        classes.add(IovisorModuleService.class);
+        return classes;
+    }
+}
diff --git a/renderers/iovisor/src/main/resources/WEB-INF/web.xml b/renderers/iovisor/src/main/resources/WEB-INF/web.xml
new file mode 100644 (file)
index 0000000..67da998
--- /dev/null
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>\r
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"\r
+        version="3.0">\r
+  <servlet>\r
+    <servlet-name>JAXRSIOVisor</servlet-name>\r
+    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>\r
+    <init-param>\r
+      <param-name>javax.ws.rs.Application</param-name>\r
+      <param-value>org.opendaylight.groupbasedpolicy.renderer.iovisor.sbrest.IovisorRSApplication</param-value>\r
+    </init-param>\r
+    <!-- AAA Auth Filter -->\r
+    <init-param>\r
+      <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>\r
+      <param-value> org.opendaylight.aaa.sts.TokenAuthFilter</param-value>\r
+    </init-param>\r
+    <load-on-startup>1</load-on-startup>\r
+  </servlet>\r
+\r
+  <servlet-mapping>\r
+    <servlet-name>JAXRSIOVisor</servlet-name>\r
+    <url-pattern>/*</url-pattern>\r
+  </servlet-mapping>\r
+\r
+  <filter>\r
+    <filter-name>cross-origin-restconf</filter-name>\r
+    <filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>\r
+    <init-param>\r
+      <param-name>allowedOrigins</param-name>\r
+      <param-value>*</param-value>\r
+    </init-param>\r
+    <init-param>\r
+      <param-name>allowedMethods</param-name>\r
+      <param-value>GET,POST,OPTIONS,DELETE,PUT,HEAD</param-value>\r
+    </init-param>\r
+    <init-param>\r
+      <param-name>allowedHeaders</param-name>\r
+      <param-value>origin, content-type, accept, authorization</param-value>\r
+    </init-param>\r
+  </filter>\r
+  <filter-mapping>\r
+    <filter-name>cross-origin-restconf</filter-name>\r
+    <url-pattern>/*</url-pattern>\r
+  </filter-mapping>\r
+  <security-constraint>\r
+    <web-resource-collection>\r
+      <web-resource-name>IOVisor api</web-resource-name>\r
+      <url-pattern>/*</url-pattern>\r
+      <http-method>POST</http-method>\r
+      <http-method>GET</http-method>\r
+      <http-method>PUT</http-method>\r
+      <http-method>PATCH</http-method>\r
+      <http-method>DELETE</http-method>\r
+      <http-method>HEAD</http-method>\r
+    </web-resource-collection>\r
+  </security-constraint>\r
+</web-app>\r