brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [20/50] brooklyn-server git commit: Add swagger as a rest endpoint
Date Wed, 30 Mar 2016 13:59:57 GMT
Add swagger as a rest endpoint


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/17044e8e
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/17044e8e
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/17044e8e

Branch: refs/heads/master
Commit: 17044e8e707c1064e114a1ed11a6bcd4dc4abb1a
Parents: 84e845c
Author: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Authored: Thu Mar 10 17:26:39 2016 +0200
Committer: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Committed: Thu Mar 17 19:19:58 2016 +0200

----------------------------------------------------------------------
 .../mgmt/osgi/OsgiVersionMoreEntityTest.java    |   2 +-
 karaf/features/src/main/feature/feature.xml     |  19 ++--
 pom.xml                                         |   4 +-
 .../brooklyn/rest/util/ScannerInjectHelper.java |  27 +++++
 .../resources/OSGI-INF/blueprint/service.xml    |   9 +-
 rest/rest-server-jersey/pom.xml                 |   3 +-
 utils/rest-swagger/pom.xml                      | 102 +++----------------
 .../rest/apidoc/RestApiResourceScanner.java     |  19 ++--
 8 files changed, 74 insertions(+), 111 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/17044e8e/core/src/test/java/org/apache/brooklyn/core/mgmt/osgi/OsgiVersionMoreEntityTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/osgi/OsgiVersionMoreEntityTest.java
b/core/src/test/java/org/apache/brooklyn/core/mgmt/osgi/OsgiVersionMoreEntityTest.java
index 118ca39..108f437 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/osgi/OsgiVersionMoreEntityTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/osgi/OsgiVersionMoreEntityTest.java
@@ -282,7 +282,7 @@ public class OsgiVersionMoreEntityTest {
             Entity me = addItemFromCatalog(c2);
             Assert.fail("Should have failed, with unresolved dependency; instead got "+me);
         } catch (Exception e) {
-            Assert.assertTrue(e.toString().toLowerCase().contains("unresolved constraint"),
"Missing expected text in error: "+e);
+            Assert.assertTrue(e.toString().toLowerCase().contains("unresolved requirements"),
"Missing expected text in error: "+e);
             Assert.assertTrue(e.toString().toLowerCase().contains("wiring.package"), "Missing
expected text in error: "+e);
             Assert.assertTrue(e.toString().toLowerCase().contains("org.apache.brooklyn.test.osgi.entities"),
"Missing expected text in error: "+e);
         }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/17044e8e/karaf/features/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/karaf/features/src/main/feature/feature.xml b/karaf/features/src/main/feature/feature.xml
index fbcbd0f..764d779 100644
--- a/karaf/features/src/main/feature/feature.xml
+++ b/karaf/features/src/main/feature/feature.xml
@@ -24,15 +24,14 @@
 
     <repository>mvn:org.apache.cxf.karaf/apache-cxf/${cxf.version}/xml/features</repository>
 
-    <!-- temporary feature until we migrate to swagger-1.5.4, which is properly bundled
-->
-    <feature name="swagger-crippled" version="${swagger.version}" description="Swagger
Annotations+Core+JAXRS+Models">
+    <feature name="swagger" version="${swagger.version}" description="Swagger Annotations+Core+JAXRS+Models">
+        <bundle dependency='true'>mvn:com.google.guava/guava/${guava-swagger.version}</bundle>
+
         <bundle>mvn:io.swagger/swagger-annotations/${swagger.version}</bundle>
-<!--        <bundle>wrap:mvn:io.swagger/swagger-core/${swagger.version}</bundle>
-        <bundle>wrap:mvn:io.swagger/swagger-jaxrs/${swagger.version}</bundle>-->
+        <bundle>wrap:mvn:io.swagger/swagger-core/${swagger.version}</bundle>
+        <bundle>wrap:mvn:io.swagger/swagger-jaxrs/${swagger.version}</bundle>
         <bundle>mvn:io.swagger/swagger-models/${swagger.version}</bundle>
 
-        <!--<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.javassist/${javassist.bundle.version}</bundle>-->
-        <!--<bundle dependency='true'>mvn:com.google.guava/guava/${guava.version}</bundle>-->
         <bundle dependency='true'>mvn:com.fasterxml.jackson.core/jackson-annotations/${fasterxml.jackson.version}</bundle>
         <bundle dependency='true'>mvn:com.fasterxml.jackson.core/jackson-core/${fasterxml.jackson.version}</bundle>
         <bundle dependency='true'>mvn:com.fasterxml.jackson.core/jackson-databind/${fasterxml.jackson.version}</bundle>
@@ -65,16 +64,10 @@
 
     <feature name="brooklyn-utils-rest-swagger" version="${project.version}" description="Brooklyn
REST Swagger Apidoc Utilities">
         <feature>brooklyn-utils-common</feature>
-        <feature version="${swagger.version}">swagger-crippled</feature>
+        <feature version="${swagger.version}">swagger</feature>
 
         <bundle>mvn:org.apache.brooklyn/brooklyn-utils-rest-swagger/${project.version}</bundle>
 
-        <!--<feature>jersey</feature>-->
-        <bundle dependency="true">mvn:com.sun.jersey/jersey-server/${jersey.version}</bundle>
-        <bundle dependency="true">mvn:com.sun.jersey/jersey-core/${jersey.version}</bundle>
-        <bundle dependency="true">mvn:com.sun.jersey/jersey-servlet/${jersey.version}</bundle>
-        <bundle dependency="true">mvn:org.apache.commons/commons-lang3/${commons-lang3.version}</bundle>
-
         <bundle dependency="true">mvn:javax.servlet/javax.servlet-api/${javax-servlet.version}</bundle>
         <bundle dependency="true">mvn:javax.ws.rs/javax.ws.rs-api/${jax-rs-api.version}</bundle>
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/17044e8e/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 3f2b1ee..9f84952 100644
--- a/pom.xml
+++ b/pom.xml
@@ -96,6 +96,7 @@
         <logback.version>1.0.7</logback.version>
         <slf4j.version>1.6.6</slf4j.version>  <!-- used for java.util.logging
jul-to-slf4j interception -->
         <guava.version>17.0</guava.version>
+        <guava-swagger.version>18.0</guava-swagger.version>
         <xstream.version>1.4.7</xstream.version>
         <!-- double-check downstream projects before changing jackson and resteasy versions
-->
         <fasterxml.jackson.version>2.4.5</fasterxml.jackson.version>
@@ -107,7 +108,8 @@
         <groovy.version>2.3.7</groovy.version> <!-- Version supported by https://github.com/groovy/groovy-eclipse/wiki/Groovy-Eclipse-2.9.1-Release-Notes
-->
         <jsr305.version>2.0.1</jsr305.version>
         <snakeyaml.version>1.11</snakeyaml.version>
-        <swagger.version>1.5.3</swagger.version>
+        <!-- Next version of swagger requires changes to how path mapping and scanner
injection are done. -->
+        <swagger.version>1.5.6</swagger.version>
         <jansi.version>1.2.1</jansi.version>
         <gson.version>2.3</gson.version>
         <ivy.version>2.2.0</ivy.version>

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/17044e8e/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/ScannerInjectHelper.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/ScannerInjectHelper.java
b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/ScannerInjectHelper.java
new file mode 100644
index 0000000..f8c224a
--- /dev/null
+++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/ScannerInjectHelper.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2015 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.brooklyn.rest.util;
+
+import org.apache.brooklyn.rest.apidoc.RestApiResourceScanner;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+
+import io.swagger.config.ScannerFactory;
+
+public class ScannerInjectHelper {
+    public void setServer(JAXRSServerFactoryBean server) {
+        ScannerFactory.setScanner(new RestApiResourceScanner(server.getResourceClasses()));
+    }
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/17044e8e/rest/rest-resources/src/main/resources/OSGI-INF/blueprint/service.xml
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/main/resources/OSGI-INF/blueprint/service.xml b/rest/rest-resources/src/main/resources/OSGI-INF/blueprint/service.xml
index c1482b7..7d3674b 100644
--- a/rest/rest-resources/src/main/resources/OSGI-INF/blueprint/service.xml
+++ b/rest/rest-resources/src/main/resources/OSGI-INF/blueprint/service.xml
@@ -49,7 +49,7 @@ limitations under the License.
         <property name="managementContext" ref="localManagementContext" />
         <property name="managementContextInternal" ref="localManagementContextInternal"
/>
     </bean>
-    <!--<bean id="apidocResourceBean" class="org.apache.brooklyn.rest.resources.ApidocResource"
/>-->
+    <bean id="apidocResourceBean" class="org.apache.brooklyn.rest.resources.ApidocResource"
/>
     <bean id="applicationResourceBean" class="org.apache.brooklyn.rest.resources.ApplicationResource">
         <property name="managementContext" ref="localManagementContext" />
         <property name="managementContextInternal" ref="localManagementContextInternal"
/>
@@ -107,7 +107,7 @@ limitations under the License.
         <jaxrs:serviceBeans>
             <ref component-id="accessResourceBean" />
             <ref component-id="activityResourceBean" />
-            <!--<ref component-id="apidocResourceBean" />-->
+            <ref component-id="apidocResourceBean" />
             <ref component-id="applicationResourceBean" />
             <ref component-id="catalogResourceBean" />
             <ref component-id="effectorResourceBean" />
@@ -127,6 +127,11 @@ limitations under the License.
             <bean class="org.apache.brooklyn.rest.util.DefaultExceptionMapper"/>
             <bean class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
             <bean class="org.apache.brooklyn.rest.util.FormMapProvider"/>
+            <bean class="io.swagger.jaxrs.listing.SwaggerSerializers" />
         </jaxrs:providers>
     </jaxrs:server>
+
+    <bean class="org.apache.brooklyn.rest.util.ScannerInjectHelper">
+      <property name="server" ref="brooklynRestApiV1" />
+    </bean>
 </blueprint>

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/17044e8e/rest/rest-server-jersey/pom.xml
----------------------------------------------------------------------
diff --git a/rest/rest-server-jersey/pom.xml b/rest/rest-server-jersey/pom.xml
index a102681..daa13e8 100644
--- a/rest/rest-server-jersey/pom.xml
+++ b/rest/rest-server-jersey/pom.xml
@@ -47,12 +47,10 @@
         <dependency>
             <groupId>com.fasterxml.jackson.core</groupId>
             <artifactId>jackson-annotations</artifactId>
-            <version>${fasterxml.jackson.version}</version>
         </dependency>
         <dependency>
             <groupId>com.fasterxml.jackson.core</groupId>
             <artifactId>jackson-databind</artifactId>
-            <version>${fasterxml.jackson.version}</version>
         </dependency>
         <dependency>
             <groupId>javax.validation</groupId>
@@ -255,6 +253,7 @@
                                 <exclude>**/HaHotCheckResourceFilter.java</exclude>
                                 <exclude>**/FormMapProvider.java</exclude>
                                 <exclude>**/ApidocResource.java</exclude>
+                                <exclude>**/ScannerInjectHelper.java</exclude>
                               </excludes>
                             </resource>
                             <resource>

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/17044e8e/utils/rest-swagger/pom.xml
----------------------------------------------------------------------
diff --git a/utils/rest-swagger/pom.xml b/utils/rest-swagger/pom.xml
index 3afa7e0..103f92e 100644
--- a/utils/rest-swagger/pom.xml
+++ b/utils/rest-swagger/pom.xml
@@ -19,7 +19,7 @@
 -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
-    <packaging>bundle</packaging>
+    <packaging>jar</packaging>
     
     <artifactId>brooklyn-utils-rest-swagger</artifactId>
     <name>Brooklyn REST Swagger Apidoc Utilities</name>
@@ -37,26 +37,13 @@
 
     <dependencies>
         <dependency>
-            <groupId>com.google.guava</groupId>
-            <artifactId>guava</artifactId>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.brooklyn</groupId>
-            <artifactId>brooklyn-utils-common</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-
-        <dependency>
             <groupId>javax.ws.rs</groupId>
             <artifactId>javax.ws.rs-api</artifactId>
         </dependency>
 
         <dependency>
-            <groupId>org.apache.brooklyn</groupId>
-            <artifactId>brooklyn-test-support</artifactId>
-            <version>${project.version}</version>
-            <scope>test</scope>
+            <groupId>javax.servlet</groupId>
+            <artifactId>javax.servlet-api</artifactId>
         </dependency>
 
         <dependency>
@@ -71,6 +58,10 @@
                     <groupId>org.apache.commons</groupId>
                     <artifactId>commons-lang3</artifactId>
                 </exclusion>
+                <exclusion>
+                  <groupId>com.google.guava</groupId>
+                  <artifactId>guava</artifactId>
+                </exclusion>
             </exclusions>
         </dependency>
         <dependency>
@@ -85,80 +76,19 @@
                     <groupId>javax.ws.rs</groupId>
                     <artifactId>jsr311-api</artifactId>
                 </exclusion>
+                <exclusion>
+                  <groupId>com.google.guava</groupId>
+                  <artifactId>guava</artifactId>
+                </exclusion>
             </exclusions>
         </dependency>
+
         <dependency>
-            <groupId>javax.servlet</groupId>
-            <artifactId>javax.servlet-api</artifactId>
+            <groupId>org.apache.brooklyn</groupId>
+            <artifactId>brooklyn-test-support</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
         </dependency>
 
     </dependencies>
-
-    <build>
-        <plugins>
-            <!--            <plugin>
-                <artifactId>maven-shade-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <phase>package</phase>
-                        <goals>
-                            <goal>shade</goal>
-                        </goals>
-                        <configuration>
-                            <artifactSet>
-                                <includes>
-                                    <include>io.swagger:swagger-core</include>
-                                    <include>io.swagger:swagger-jaxrs</include>
-                                </includes>
-                            </artifactSet>
-                            <finalName>${project.artifactId}-${project.version}-with-swagger</finalName>
-                            <outputFile>${project.build.directory}/${project.artifactId}-shaded-${project.version}.jar</outputFile>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>-->
-            <plugin>
-                <groupId>org.apache.felix</groupId>
-                <artifactId>maven-bundle-plugin</artifactId>
-                <extensions>true</extensions>
-                <configuration>
-                    <supportedProjectTypes>
-                        <supportedProjectType>jar</supportedProjectType>
-                        <supportedProjectType>bundle</supportedProjectType>
-                    </supportedProjectTypes>
-                    <excludeDependencies>brooklyn-util-common,brooklyn-logback-includes</excludeDependencies>
-                    <instructions>
-                        <!--
-                            This tells maven-bundle-plugin to include and export swagger-core
and swagger-jaxrs into this bundle,
-                            but to not include other dependencies that are properly bundled
themselves.
-                            We also need the swagger packages exported, since we're going
to use them in higher-level bundles.
-
-                            The only way I could convince maven-bundle-plugin to do all this
was to manually specify the packages
-                            in swagger-core and swagger-jaxrs versions 1.5.3
-
-                            FIXME: move to >=swagger-1.5.4 (which does not suffer from
split packages and is a proper bundle),
-                            but those depend on guava-18.0 instead of brooklyn's currently
used guava-17.x
-                        -->
-                        <Export-Package>
-                            org.apache.brooklyn.rest.*,
-                            io.swagger.config.*,
-                            io.swagger.converter.*,
-                            io.swagger.core.filter.*,
-                            io.swagger.jackson.*,
-                            io.swagger.model.*,
-                            io.swagger.util.*,
-                            io.swagger.jaxrs.*,
-                            !*
-                        </Export-Package>
-                        <Import-Package>
-                            javax.ws.rs;version="[1.1,2.0]",
-                            javax.ws.rs.core;version="[1.1,2.0]",
-                            javax.ws.rs.ext;version="[1.1,2.0]",
-                            *
-                        </Import-Package>
-                    </instructions>
-                </configuration>
-            </plugin>
-        </plugins>
-    </build>
 </project>

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/17044e8e/utils/rest-swagger/src/main/java/org/apache/brooklyn/rest/apidoc/RestApiResourceScanner.java
----------------------------------------------------------------------
diff --git a/utils/rest-swagger/src/main/java/org/apache/brooklyn/rest/apidoc/RestApiResourceScanner.java
b/utils/rest-swagger/src/main/java/org/apache/brooklyn/rest/apidoc/RestApiResourceScanner.java
index 1bb86b9..e90aea0 100644
--- a/utils/rest-swagger/src/main/java/org/apache/brooklyn/rest/apidoc/RestApiResourceScanner.java
+++ b/utils/rest-swagger/src/main/java/org/apache/brooklyn/rest/apidoc/RestApiResourceScanner.java
@@ -16,6 +16,8 @@
 package org.apache.brooklyn.rest.apidoc;
 
 
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -40,12 +42,19 @@ public class RestApiResourceScanner extends AbstractScanner implements
JaxrsScan
 
     private Set<Class<?>> apiClasses = null;
 
-    private void addAnnotatedClasses(Set<Class<?>> output, Class<?>[] classes)
{
+    public RestApiResourceScanner() {}
+
+    public RestApiResourceScanner(Collection<Class<?>> resourceClasses) {
+        this.apiClasses = new HashSet<>();
+        addAnnotatedClasses(apiClasses, resourceClasses);
+    }
+
+    private void addAnnotatedClasses(Set<Class<?>> output, Collection<Class<?>>
classes) {
         for (Class<?> clz : classes) {
             if (clz.getAnnotation(Api.class) != null) {
                 output.add(clz);
             }
-            addAnnotatedClasses(output, clz.getInterfaces());
+            addAnnotatedClasses(output, Arrays.asList(clz.getInterfaces()));
         }
     }
 
@@ -55,14 +64,12 @@ public class RestApiResourceScanner extends AbstractScanner implements
JaxrsScan
             if (app != null) {
                 Set<Class<?>> classes = app.getClasses();
                 if (classes != null) {
-                    final Class<?>[] template = {};
-                    addAnnotatedClasses(apiClasses, classes.toArray(template));
+                    addAnnotatedClasses(apiClasses, classes);
                 }
                 Set<Object> singletons = app.getSingletons();
                 if (singletons != null) {
                     for (Object o : singletons) {
-                        Class<?>[] types = {o.getClass()};
-                        addAnnotatedClasses(apiClasses, types);
+                        addAnnotatedClasses(apiClasses, Arrays.<Class<?>>asList(o.getClass()));
                     }
                 }
             }


Mime
View raw message