diff options
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/resource-api/src')
4 files changed, 87 insertions, 33 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt index c50853ff2..4c8fc193c 100644 --- a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt @@ -16,10 +16,14 @@ package org.onap.ccsdk.cds.blueprintsprocessor.resource.api +import com.fasterxml.jackson.databind.JsonNode +import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation +import io.swagger.annotations.ApiParam import kotlinx.coroutines.runBlocking import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolution import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolutionDBService +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.springframework.http.MediaType import org.springframework.http.ResponseEntity import org.springframework.security.access.prepost.PreAuthorize @@ -27,27 +31,42 @@ import org.springframework.web.bind.annotation.* @RestController @RequestMapping("/api/v1/resources") +@Api(value = "/api/v1/resources", + description = "Interaction with resolved resources.") open class ResourceController(private var resourceResolutionDBService: ResourceResolutionDBService) { - @RequestMapping(path = ["/ping"], method = [RequestMethod.GET], produces = [MediaType.APPLICATION_JSON_VALUE]) + @RequestMapping(path = ["/health-check"], + method = [RequestMethod.GET], + produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody - fun ping(): String = runBlocking { - "Success" + @ApiOperation(value = "Health Check", hidden = true) + fun resourceControllerHealthCheck(): JsonNode = runBlocking { + JacksonUtils.getJsonNode("Success") } @RequestMapping(path = [""], method = [RequestMethod.GET], produces = [MediaType.APPLICATION_JSON_VALUE]) - @ApiOperation(value = "Fetch all resource values associated to a resolution key. ", - notes = "Retrieve a stored resource value using the blueprint metadata, artifact name and the resolution-key.", + @ApiOperation(value = "Get all resolved resources using the resolution key. ", + notes = "Retrieve all stored resolved resources using the blueprint name, blueprint version, " + + "artifact name and the resolution-key.", + response = ResourceResolution::class, + responseContainer = "List", produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody @PreAuthorize("hasRole('USER')") - fun getAllFromResolutionKeyOrFromResourceTypeAndId(@RequestParam(value = "bpName", required = true) bpName: String, - @RequestParam(value = "bpVersion", required = true) bpVersion: String, - @RequestParam(value = "artifactName", required = false, defaultValue = "") artifactName: String, - @RequestParam(value = "resolutionKey", required = false, defaultValue = "") resolutionKey: String, - @RequestParam(value = "resourceType", required = false, defaultValue = "") resourceType: String, - @RequestParam(value = "resourceId", required = false, defaultValue = "") resourceId: String) + fun getAllFromResolutionKeyOrFromResourceTypeAndId( + @ApiParam(value = "Name of the CBA.", required = true) + @RequestParam(value = "bpName", required = true) bpName: String, + @ApiParam(value = "Version of the CBA.", required = true) + @RequestParam(value = "bpVersion", required = true) bpVersion: String, + @ApiParam(value = "Artifact name for which to retrieve a resolved resource.", required = true) + @RequestParam(value = "artifactName", required = false, defaultValue = "") artifactName: String, + @ApiParam(value = "Resolution Key associated with the resolution.", required = false) + @RequestParam(value = "resolutionKey", required = false, defaultValue = "") resolutionKey: String, + @ApiParam(value = "Resource Type associated with the resolution.", required = false) + @RequestParam(value = "resourceType", required = false, defaultValue = "") resourceType: String, + @ApiParam(value = "Resource Id associated with the resolution.", required = false) + @RequestParam(value = "resourceId", required = false, defaultValue = "") resourceId: String) : ResponseEntity<List<ResourceResolution>> = runBlocking { if ((resolutionKey.isNotEmpty() || artifactName.isNotEmpty()) && (resourceId.isNotEmpty() || resourceType.isNotEmpty())) { @@ -55,9 +74,12 @@ open class ResourceController(private var resourceResolutionDBService: ResourceR } else if (resolutionKey.isNotEmpty() && artifactName.isNotEmpty()) { ResponseEntity.ok() .body(resourceResolutionDBService.readWithResolutionKey(bpName, bpVersion, artifactName, resolutionKey)) - } else if (resourceType.isNotEmpty() && resourceId.isNotEmpty()){ - ResponseEntity.ok() - .body(resourceResolutionDBService.readWithResourceIdAndResourceType(bpName, bpVersion, resourceId, resourceType)) + } else if (resourceType.isNotEmpty() && resourceId.isNotEmpty()) { + ResponseEntity.ok() + .body(resourceResolutionDBService.readWithResourceIdAndResourceType(bpName, + bpVersion, + resourceId, + resourceType)) } else { throw ResourceException("Missing param. Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.") } @@ -71,10 +93,16 @@ open class ResourceController(private var resourceResolutionDBService: ResourceR produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody @PreAuthorize("hasRole('USER')") - fun getOneFromResolutionKey(@RequestParam(value = "bpName", required = true) bpName: String, + fun getOneFromResolutionKey(@ApiParam(value = "Name of the CBA.", required = true) + @RequestParam(value = "bpName", required = true) bpName: String, + @ApiParam(value = "Version of the CBA.", required = true) @RequestParam(value = "bpVersion", required = true) bpVersion: String, + @ApiParam(value = "Artifact name for which to retrieve a resolved resource.", + required = true) @RequestParam(value = "artifactName", required = true) artifactName: String, + @ApiParam(value = "Resolution Key associated with the resolution.", required = true) @RequestParam(value = "resolutionKey", required = true) resolutionKey: String, + @ApiParam(value = "Name of the resource to retrieve.", required = true) @RequestParam(value = "name", required = true) name: String) : ResponseEntity<ResourceResolution> = runBlocking { diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateController.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateController.kt index d3ebd5c49..83e813079 100644 --- a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateController.kt @@ -16,10 +16,14 @@ package org.onap.ccsdk.cds.blueprintsprocessor.resource.api +import com.fasterxml.jackson.databind.JsonNode +import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation +import io.swagger.annotations.ApiParam import kotlinx.coroutines.runBlocking import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.TemplateResolution import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.TemplateResolutionService +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.springframework.http.MediaType import org.springframework.http.ResponseEntity import org.springframework.security.access.prepost.PreAuthorize @@ -33,26 +37,41 @@ import org.springframework.web.bind.annotation.* */ @RestController @RequestMapping("/api/v1/template") +@Api(value = "/api/v1/template", + description = "Interaction with resolved template.") open class TemplateController(private val templateResolutionService: TemplateResolutionService) { - @RequestMapping(path = ["/ping"], method = [RequestMethod.GET], produces = [MediaType.APPLICATION_JSON_VALUE]) + @RequestMapping(path = ["/health-check"], + method = [RequestMethod.GET], + produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody - fun ping(): String = runBlocking { - "Success" + @ApiOperation(value = "Health Check", hidden = true) + fun templateControllerHealthCheck(): JsonNode = runBlocking { + JacksonUtils.getJsonNode("Success") } - @RequestMapping(path = [""], method = [RequestMethod.GET], produces = [MediaType.TEXT_PLAIN_VALUE]) - @ApiOperation(value = "Retrieve a meshed template.", - notes = "Retrieve a meshed template for a given CBA's action, identified by its blueprint name, blueprint version, " + - "artifact name and resolution key. And extra 'format' parameter can be passed to tell what content-type" + + @RequestMapping(path = [""], + method = [RequestMethod.GET], + produces = [MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE]) + @ApiOperation(value = "Retrieve a resolved template.", + notes = "Retrieve a config template for a given CBA's action, identified by its blueprint name, blueprint version, " + + "artifact name and resolution key. An extra 'format' parameter can be passed to tell what content-type" + " to expect in return") @ResponseBody @PreAuthorize("hasRole('USER')") - fun get(@RequestParam(value = "bpName") bpName: String, - @RequestParam(value = "bpVersion") bpVersion: String, - @RequestParam(value = "artifactName") artifactName: String, - @RequestParam(value = "resolutionKey") resolutionKey: String, - @RequestParam(value = "format", required = false, defaultValue = "text/plain") format: String) + fun get( + @ApiParam(value = "Name of the CBA.", required = true) + @RequestParam(value = "bpName") bpName: String, + @ApiParam(value = "Version of the CBA.", required = true) + @RequestParam(value = "bpVersion") bpVersion: String, + @ApiParam(value = "Artifact name for which to retrieve a resolved resource.", required = true) + @RequestParam(value = "artifactName") artifactName: String, + @ApiParam(value = "Resolution Key associated with the resolution.", required = true) + @RequestParam(value = "resolutionKey") resolutionKey: String, + @ApiParam(value = "Expected format of the template being retrieved.", + defaultValue = MediaType.TEXT_PLAIN_VALUE, + required = true) + @RequestParam(value = "format", required = false, defaultValue = MediaType.TEXT_PLAIN_VALUE) format: String) : ResponseEntity<String> = runBlocking { val result = templateResolutionService.read(bpName, bpVersion, artifactName, resolutionKey) @@ -68,15 +87,22 @@ open class TemplateController(private val templateResolutionService: TemplateRes @PostMapping("/{bpName}/{bpVersion}/{artifactName}/{resolutionKey}", produces = [MediaType.APPLICATION_JSON_VALUE]) - @ApiOperation(value = "Store a meshed template", - notes = "Store a meshed template for a given CBA's action, identified by its blueprint name, blueprint version, " + - "artifact name and resolution key.") + @ApiOperation(value = "Store a resolved template", + notes = "Store a template for a given CBA's action, identified by its blueprint name, blueprint version, " + + "artifact name and resolution key.", + response = TemplateResolution::class, + produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody @PreAuthorize("hasRole('USER')") - fun post(@PathVariable(value = "bpName") bpName: String, + fun post(@ApiParam(value = "Name of the CBA.", required = true) + @PathVariable(value = "bpName") bpName: String, + @ApiParam(value = "Version of the CBA.", required = true) @PathVariable(value = "bpVersion") bpVersion: String, + @ApiParam(value = "Artifact name for which to retrieve a resolved resource.", required = true) @PathVariable(value = "artifactName") artifactName: String, + @ApiParam(value = "Resolution Key associated with the resolution.", required = true) @PathVariable(value = "resolutionKey") resolutionKey: String, + @ApiParam(value = "Template to store.", required = true) @RequestBody result: String): ResponseEntity<TemplateResolution> = runBlocking { val resultStored = diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resolutionresults/api/ResourceControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resolutionresults/api/ResourceControllerTest.kt index cde71d86c..daab7b3bb 100644 --- a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resolutionresults/api/ResourceControllerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resolutionresults/api/ResourceControllerTest.kt @@ -77,7 +77,7 @@ class ResourceControllerTest { @Test fun `ping return Success`() { runBlocking { - webTestClient.get().uri("/api/v1/resources/ping") + webTestClient.get().uri("/api/v1/resources/health-check") .exchange() .expectStatus().isOk .expectBody() diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateControllerTest.kt index d12d05804..649f6b5fe 100644 --- a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateControllerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateControllerTest.kt @@ -72,7 +72,7 @@ class TemplateControllerTest { @Test fun `ping return Success`() { runBlocking { - webTestClient.get().uri("/api/v1/template/ping") + webTestClient.get().uri("/api/v1/template/health-check") .exchange() .expectStatus().isOk .expectBody() |