summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRuslan Kashapov <ruslan.kashapov@pantheon.tech>2021-01-21 09:37:05 +0200
committerRuslan Kashapov <ruslan.kashapov@pantheon.tech>2021-01-21 17:46:11 +0200
commit708fd6615c97756eade415a6295b1fb663e4d3ef (patch)
tree215cfd5d3886f64e4b95232e5102bd4425f9bea1
parentcd9f368b1f3c5e25e17e21649e582d84a909ac79 (diff)
Enable log level management via actuator, /cps/api path to use for REST controllers only only
Issue-ID: CPS-158 Change-Id: I1f9ff4429f331ca4204d1acaf73ac896a68994d0 Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
-rw-r--r--README.md4
-rw-r--r--cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java2
-rw-r--r--cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java2
-rw-r--r--cps-rest/src/main/resources/application.yml10
-rw-r--r--cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy18
-rw-r--r--cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy6
6 files changed, 30 insertions, 12 deletions
diff --git a/README.md b/README.md
index d5f0c66f4c..8282d30cae 100644
--- a/README.md
+++ b/README.md
@@ -29,5 +29,5 @@ java -DDB_HOST=localhost -DDB_USERNAME=cps -DDB_PASSWORD=cps -jar cps-rest/targe
```
* Browse
- * [Swagger UI](http://localhost:8080/api/cps/swagger-ui/index.html)
- * [Api Documentation](http://localhost:8080/api/cps/v3/api-docs)
+ * [Swagger UI](http://localhost:8080/swagger-ui/index.html)
+ * [Api Documentation](http://localhost:8080/v3/api-docs)
diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
index 08020eca2a..1b6f56a211 100644
--- a/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
+++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
@@ -33,10 +33,12 @@ import org.onap.cps.spi.model.SchemaSet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@RestController
+@RequestMapping("${rest.api.base-path}")
public class AdminRestController implements CpsAdminApi {
@Autowired
diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java
index fcb8ddc1c1..2ecbd4f544 100644
--- a/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java
+++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java
@@ -25,10 +25,12 @@ import org.onap.cps.api.CpsAdminService;
import org.onap.cps.rest.api.CpsDataApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@RestController
+@RequestMapping("${rest.api.base-path}")
public class DataRestController implements CpsDataApi {
@Autowired
diff --git a/cps-rest/src/main/resources/application.yml b/cps-rest/src/main/resources/application.yml
index e8af0bcfb2..b50a92662b 100644
--- a/cps-rest/src/main/resources/application.yml
+++ b/cps-rest/src/main/resources/application.yml
@@ -1,7 +1,9 @@
server:
port: 8080
- servlet:
- context-path: /api/cps
+
+rest:
+ api:
+ base-path: /cps/api
spring:
main:
@@ -27,12 +29,16 @@ management:
endpoints:
web:
base-path: /manage
+ exposure:
+ include: health,info,loggers
endpoint:
health:
show-details: always
# kubernetes probes: liveness and readiness
probes:
enabled: true
+ looging:
+ enabled: true
logging:
level:
diff --git a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy
index a95d606a35..2d4fe9bb01 100644
--- a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy
+++ b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy
@@ -29,6 +29,7 @@ import org.onap.cps.spi.model.Anchor
import org.onap.cps.spi.model.SchemaSet
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
@@ -59,6 +60,9 @@ class AdminRestControllerSpec extends Specification {
@Autowired
MockMvc mvc
+ @Value('${rest.api.base-path}')
+ def basePath
+
def anchorsEndpoint = '/v1/dataspaces/my_dataspace/anchors'
def schemaSetsEndpoint = '/v1/dataspaces/test-dataspace/schema-sets'
def schemaSetEndpoint = schemaSetsEndpoint + '/my_schema_set'
@@ -130,7 +134,7 @@ class AdminRestControllerSpec extends Specification {
def performCreateDataspaceRequest(String dataspaceName) {
return mvc.perform(
- post('/v1/dataspaces').param('dataspace-name', dataspaceName)
+ post("$basePath/v1/dataspaces").param('dataspace-name', dataspaceName)
).andReturn().response
}
@@ -140,14 +144,14 @@ class AdminRestControllerSpec extends Specification {
def performCreateSchemaSetRequest(multipartFile) {
return mvc.perform(
- multipart(schemaSetsEndpoint)
+ multipart("$basePath$schemaSetsEndpoint")
.file(multipartFile)
.param('schema-set-name', 'test-schema-set')
).andReturn().response
}
- def performDeleteRequest(String uri) {
- return mvc.perform(delete(uri)).andReturn().response
+ def performDeleteRequest(String deleteEndpoint) {
+ return mvc.perform(delete("$basePath$deleteEndpoint")).andReturn().response
}
def 'Get existing schema set'() {
@@ -155,7 +159,7 @@ class AdminRestControllerSpec extends Specification {
mockCpsModuleService.getSchemaSet('test-dataspace', 'my_schema_set') >>
new SchemaSet(name: 'my_schema_set', dataspaceName: 'test-dataspace')
when: 'get schema set API is invoked'
- def response = mvc.perform(get(schemaSetEndpoint)).andReturn().response
+ def response = mvc.perform(get("$basePath$schemaSetEndpoint")).andReturn().response
then: 'the correct schema set is returned'
response.status == HttpStatus.OK.value()
response.getContentAsString().contains('my_schema_set')
@@ -167,7 +171,7 @@ class AdminRestControllerSpec extends Specification {
requestParams.add('schema-set-name', 'my_schema-set')
requestParams.add('anchor-name', 'my_anchor')
when: 'post is invoked'
- def response = mvc.perform(post(anchorsEndpoint).contentType(MediaType.APPLICATION_JSON)
+ def response = mvc.perform(post("$basePath$anchorsEndpoint").contentType(MediaType.APPLICATION_JSON)
.params(requestParams as MultiValueMap)).andReturn().response
then: 'Anchor is created successfully'
1 * mockCpsAdminService.createAnchor('my_dataspace', 'my_schema-set', 'my_anchor')
@@ -179,7 +183,7 @@ class AdminRestControllerSpec extends Specification {
given:
mockCpsAdminService.getAnchors('my_dataspace') >> anchorList
when: 'get all anchors API is invoked'
- def response = mvc.perform(get(anchorsEndpoint)).andReturn().response
+ def response = mvc.perform(get("$basePath$anchorsEndpoint")).andReturn().response
then: 'the correct anchor is returned'
response.status == HttpStatus.OK.value()
response.getContentAsString().contains('my_anchor')
diff --git a/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy
index d372d3c0b7..edc484b14a 100644
--- a/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy
+++ b/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy
@@ -33,6 +33,7 @@ import org.onap.cps.spi.exceptions.SchemaSetAlreadyDefinedException
import org.onap.cps.spi.exceptions.SchemaSetInUseException
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.test.web.servlet.MockMvc
import spock.lang.Shared
@@ -60,6 +61,9 @@ class CpsRestExceptionHandlerSpec extends Specification {
@Autowired
MockMvc mvc
+ @Value('${rest.api.base-path}')
+ def basePath
+
@Shared
def errorMessage = 'some error message'
@Shared
@@ -161,7 +165,7 @@ class CpsRestExceptionHandlerSpec extends Specification {
}
def performTestRequest() {
- return mvc.perform(get('/v1/dataspaces/dataspace-name/anchors')).andReturn().response
+ return mvc.perform(get("$basePath/v1/dataspaces/dataspace-name/anchors")).andReturn().response
}
void assertTestResponse(response, expectedStatus,