summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cps/README.md33
-rw-r--r--cps/cps-rest/pom.xml78
-rw-r--r--cps/cps-rest/src/main/java/org/onap/cps/rest/config/JerseyConfig.java17
-rw-r--r--cps/cps-rest/src/main/resources/application.yml2
-rw-r--r--cps/cps-service/src/main/java/org/onap/cps/api/impl/CpServiceImpl.java3
-rw-r--r--cps/pom.xml4
6 files changed, 131 insertions, 6 deletions
diff --git a/cps/README.md b/cps/README.md
index b6131a1fac..791015ef19 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 2b4cbb8940..274e57f528 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 290ad5d9ee..ac781d3370 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 5cfa974159..c9154ba1f8 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 73138ccc1b..80a685b092 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 d81ee9e08e..c70af6be8a 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>