diff options
author | 2020-10-20 10:12:06 +0000 | |
---|---|---|
committer | 2020-10-20 10:12:06 +0000 | |
commit | a085206e0ab80d4179f766baa4d40c22f6c5283b (patch) | |
tree | 4c426f51ce52cb4655b2c9396f65843a6d33cc35 | |
parent | 4dbcd00b188506d76f7b5721191e713ded0ae726 (diff) | |
parent | 49c88d9f013f97d598a6c38f73fde2e9c9e9da5c (diff) |
Merge "Add swagger-ui" into cps_poc
-rw-r--r-- | cps/README.md | 33 | ||||
-rw-r--r-- | cps/cps-rest/pom.xml | 78 | ||||
-rw-r--r-- | cps/cps-rest/src/main/java/org/onap/cps/rest/config/JerseyConfig.java | 17 | ||||
-rw-r--r-- | cps/cps-rest/src/main/resources/application.yml | 2 | ||||
-rw-r--r-- | cps/cps-service/src/main/java/org/onap/cps/api/impl/CpServiceImpl.java | 3 | ||||
-rw-r--r-- | cps/pom.xml | 4 |
6 files changed, 131 insertions, 6 deletions
diff --git a/cps/README.md b/cps/README.md index b6131a1fa..791015ef1 100644 --- a/cps/README.md +++ b/cps/README.md @@ -1,7 +1,34 @@ # Configuration & Persistency Service -This folder contains all files for +This folder contains all files for [Configuration & Persistency Service](https://wiki.onap.org/pages/viewpage.action?pageId=81406119). -The code here is related to CPS POC, then it must be kept self contained in this cps folder to prevent any impact on -current ccsdk components and to be ready to be moved in its own repo once CPS becomes a standalone project.
\ No newline at end of file +The code here is related to CPS POC, then it must be kept self contained in this cps folder to prevent any impact on +current ccsdk components and to be ready to be moved in its own repo once CPS becomes a standalone project. + + +## Running Locally + +* Run a postgres container instance and create `cpsdb' database: + +``` +CREATE USER cps WITH PASSWORD 'cps'; +CREATE DATABASE cpsdb OWNER cps; +``` + +* Build (from cps root folder) + +```bash +mvn clean package +``` + +* Run (from cps root folder) + +```bash +java -DDB_HOST=localhost -DDB_USERNAME=cps -DDB_PASSWORD=cps -jar cps-rest/target/cps-rest-0.0.1-SNAPSHOT.jar +``` + +* Browse + * [Swagger UI](http://localhost:8080/swagger-ui/index.html) + * OpenAPI Specification in [JSON](http://localhost:8080/api/cps/openapi.json) + or [YAML](http://localhost:8080/api/cps/openapi.yaml) format diff --git a/cps/cps-rest/pom.xml b/cps/cps-rest/pom.xml index 2b4cbb894..274e57f52 100644 --- a/cps/cps-rest/pom.xml +++ b/cps/cps-rest/pom.xml @@ -29,6 +29,11 @@ </dependency>
<dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
<exclusions>
@@ -83,6 +88,79 @@ </execution>
</executions>
</plugin>
+ <plugin>
+ <!-- Download Swagger UI webjar. -->
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>${maven-dependency-plugin.version}</version>
+ <executions>
+ <execution>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>unpack</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.webjars</groupId>
+ <artifactId>swagger-ui</artifactId>
+ <version>${swagger-ui.version}</version>
+ </artifactItem>
+ </artifactItems>
+ <outputDirectory>${project.build.directory}/swagger-ui-${swagger-ui.version}</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <!-- Copy Swagger UI resources to static resources directory. -->
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>${maven-resources-plugin.version}</version>
+ <executions>
+ <execution>
+ <id>copy-resources</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.outputDirectory}/static/swagger-ui</outputDirectory>
+ <resources>
+ <resource>
+ <directory>${project.build.directory}/swagger-ui-${swagger-ui.version}/META-INF/resources/webjars/swagger-ui/${swagger-ui.version}/</directory>
+ <excludes>
+ <exclude>**/*.gz</exclude>
+ </excludes>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <!-- Replace the OpenAPI specification example URL with the local one. -->
+ <groupId>com.google.code.maven-replacer-plugin</groupId>
+ <artifactId>replacer</artifactId>
+ <version>${maven-replacer-plugin.version}</version>
+ <executions>
+ <execution>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>replace</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <file>${project.build.outputDirectory}/static/swagger-ui/index.html</file>
+ <replacements>
+ <replacement>
+ <token>https://petstore.swagger.io/v2/swagger.json</token>
+ <value>/api/cps/openapi.json</value>
+ </replacement>
+ </replacements>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
diff --git a/cps/cps-rest/src/main/java/org/onap/cps/rest/config/JerseyConfig.java b/cps/cps-rest/src/main/java/org/onap/cps/rest/config/JerseyConfig.java index 290ad5d9e..ac781d337 100644 --- a/cps/cps-rest/src/main/java/org/onap/cps/rest/config/JerseyConfig.java +++ b/cps/cps-rest/src/main/java/org/onap/cps/rest/config/JerseyConfig.java @@ -28,6 +28,9 @@ import javax.annotation.PostConstruct; import javax.ws.rs.ApplicationPath;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.servlet.ServletProperties;
+import org.onap.cps.rest.controller.ModelController;
+import org.onap.cps.rest.controller.RestController;
import org.springframework.context.annotation.Configuration;
@Configuration
@@ -43,8 +46,12 @@ public class JerseyConfig extends ResourceConfig { register(OpenApiResource.class);
register(AcceptHeaderOpenApiResource.class);
- packages("org.onap.cps.rest.controller");
+ // Register controllers
+ register(ModelController.class);
+ register(RestController.class);
+
configureSwagger();
+ configureSwaggerUI();
}
private void configureSwagger() {
@@ -54,4 +61,12 @@ public class JerseyConfig extends ResourceConfig { throw new RuntimeException(e.getMessage(), e);
}
}
+
+ private void configureSwaggerUI() {
+ // Enable Jersey filter forwarding to next filter for 404 responses.
+ // This configuration lets Jersey servlet container forwarding static swagger ui requests to spring mvc filter
+ // to be handle by spring mvc dispatcher servlet.
+ property(ServletProperties.FILTER_FORWARD_ON_404, true);
+ }
+
}
diff --git a/cps/cps-rest/src/main/resources/application.yml b/cps/cps-rest/src/main/resources/application.yml index 5cfa97415..c9154ba1f 100644 --- a/cps/cps-rest/src/main/resources/application.yml +++ b/cps/cps-rest/src/main/resources/application.yml @@ -19,6 +19,8 @@ spring: password: ${DB_PASSWORD}
driverClassName: org.postgresql.Driver
initialization-mode: always
+ jersey:
+ type: filter
logging:
level:
diff --git a/cps/cps-service/src/main/java/org/onap/cps/api/impl/CpServiceImpl.java b/cps/cps-service/src/main/java/org/onap/cps/api/impl/CpServiceImpl.java index 73138ccc1..80a685b09 100644 --- a/cps/cps-service/src/main/java/org/onap/cps/api/impl/CpServiceImpl.java +++ b/cps/cps-service/src/main/java/org/onap/cps/api/impl/CpServiceImpl.java @@ -82,8 +82,7 @@ public class CpServiceImpl implements CpService { @Override public final void storeSchemaContext(final SchemaContext schemaContext) { for (final Module module : schemaContext.getModules()) { - modelPersistencyService.storeModule(module.getName(), module.toString(), - module.getRevision().toString()); + modelPersistencyService.storeModule(module.getName(), module.toString(), module.getRevision().toString()); } } } diff --git a/cps/pom.xml b/cps/pom.xml index d81ee9e08..c70af6be8 100644 --- a/cps/pom.xml +++ b/cps/pom.xml @@ -26,6 +26,10 @@ <swagger.version>2.1.4</swagger.version>
<groovy.version>3.0.6</groovy.version>
<spock-core.version>2.0-M2-groovy-3.0</spock-core.version>
+ <maven-dependency-plugin.version>3.1.2</maven-dependency-plugin.version>
+ <maven-resources-plugin.version>3.2.0</maven-resources-plugin.version>
+ <maven-replacer-plugin.version>1.5.3</maven-replacer-plugin.version>
+ <swagger-ui.version>3.35.0</swagger-ui.version>
</properties>
<dependencyManagement>
|