summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main
diff options
context:
space:
mode:
authorAlexis de Talhouët <adetalhouet89@gmail.com>2019-06-29 00:28:40 -0400
committerAlexis de Talhouët <adetalhouet89@gmail.com>2019-07-04 15:53:42 -0400
commit5f0a5dde67bc0e7c99bd8f9e9b7c447e69ce62fa (patch)
tree0eb10b1fc86efa62c70114495b599d3701107bb1 /ms/blueprintsprocessor/modules/inbounds/resource-api/src/main
parentc48ca03872b11a54cf898c93d4a62ef220f3c55f (diff)
Enforce resolutionKey or resourceId/resourceType
There are three existing ways to perform the resolution: either we don't store the results at all, whether for resource or template either we store using the resolution key. The combination of blueprintName, blueprintVersion, artifactName and resolutionKey has to be unique. If it is re-used, it is considered as a new attempt for that specific resolution request, and process will only try to resolve resources not marked at SUCCESS in the database. either we store using the resourceId and resourceType. As previous point, the combination of blueprintName, blueprintVersion, artifactName and resolutionKey has to be unique. If it is re-used, it is considered as a new attempt for that specific resolution request, and process will only try to resolve resources not marked at SUCCESS in the database. TBD: add uni tests Issue-ID: CCSDK-1423 Change-Id: I6b7198453cf0002edfa7a0c9ea3179555211b5dc Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/resource-api/src/main')
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResolutionException.kt (renamed from ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceException.kt)2
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt7
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceExceptionHandler.kt2
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateController.kt84
4 files changed, 75 insertions, 20 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceException.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResolutionException.kt
index 19c42f2ea..62e89e260 100644
--- a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceException.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResolutionException.kt
@@ -15,6 +15,6 @@
*/
package org.onap.ccsdk.cds.blueprintsprocessor.resource.api
-class ResourceException(message: String) : RuntimeException(message) {
+class ResolutionException(message: String) : RuntimeException(message) {
var code: Int = 404
}
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 4c8fc193c..3a708a973 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
@@ -70,7 +70,7 @@ open class ResourceController(private var resourceResolutionDBService: ResourceR
: ResponseEntity<List<ResourceResolution>> = runBlocking {
if ((resolutionKey.isNotEmpty() || artifactName.isNotEmpty()) && (resourceId.isNotEmpty() || resourceType.isNotEmpty())) {
- throw ResourceException("Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.")
+ throw ResolutionException("Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.")
} else if (resolutionKey.isNotEmpty() && artifactName.isNotEmpty()) {
ResponseEntity.ok()
.body(resourceResolutionDBService.readWithResolutionKey(bpName, bpVersion, artifactName, resolutionKey))
@@ -81,7 +81,7 @@ open class ResourceController(private var resourceResolutionDBService: ResourceR
resourceId,
resourceType))
} else {
- throw ResourceException("Missing param. Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.")
+ throw ResolutionException("Missing param. Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.")
}
}
@@ -97,8 +97,7 @@ open class ResourceController(private var resourceResolutionDBService: ResourceR
@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)
+ @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,
diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceExceptionHandler.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceExceptionHandler.kt
index f01dccff7..42ff8016c 100644
--- a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceExceptionHandler.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceExceptionHandler.kt
@@ -93,7 +93,7 @@ open class ResourceExceptionHandler {
}
@ExceptionHandler
- fun ResolutionResultsServiceExceptionHandler(e: ResourceException): ResponseEntity<ErrorMessage> {
+ fun ResolutionResultsServiceExceptionHandler(e: ResolutionException): ResponseEntity<ErrorMessage> {
log.error(e.message, e)
return ResponseEntity(ErrorMessage(e.message, e.code, debugMsg), HttpStatus.resolve(e.code))
}
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 83e813079..de5843a66 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
@@ -24,6 +24,7 @@ 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.dao.EmptyResultDataAccessException
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.security.access.prepost.PreAuthorize
@@ -66,15 +67,40 @@ open class TemplateController(private val templateResolutionService: TemplateRes
@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)
+ @ApiParam(value = "Resolution Key associated with the resolution.", required = false)
@RequestParam(value = "resolutionKey") 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,
@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)
+ var result = ""
+
+ if ((resolutionKey.isNotEmpty() || artifactName.isNotEmpty()) && (resourceId.isNotEmpty() || resourceType.isNotEmpty())) {
+ throw ResolutionException("Either retrieve resolved template using artifact name and resolution-key OR using resource-id and resource-type.")
+ } else if (resolutionKey.isNotEmpty() && artifactName.isNotEmpty()) {
+ result = templateResolutionService.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
+ bpName,
+ bpVersion,
+ artifactName,
+ resolutionKey)
+ } else if (resourceType.isNotEmpty() && resourceId.isNotEmpty()) {
+ result =
+ templateResolutionService.findByResoureIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactName(
+ bpName,
+ bpVersion,
+ artifactName,
+ resourceId,
+ resourceType)
+ } else {
+ throw ResolutionException("Missing param. Either retrieve resolved template using artifact name and resolution-key OR using resource-id and resource-type.")
+ }
+
var expectedContentType = format
if (expectedContentType.indexOf('/') < 0) {
@@ -87,26 +113,56 @@ open class TemplateController(private val templateResolutionService: TemplateRes
@PostMapping("/{bpName}/{bpVersion}/{artifactName}/{resolutionKey}", produces = [MediaType.APPLICATION_JSON_VALUE])
- @ApiOperation(value = "Store a resolved template",
+ @ApiOperation(value = "Store a resolved template w/ resolution-key",
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(@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 {
+ fun postWithResolutionKey(
+ @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 =
+ templateResolutionService.write(bpName, bpVersion, artifactName, result, resolutionKey = resolutionKey)
+
+ ResponseEntity.ok().body(resultStored)
+ }
+
+ @PostMapping("/{bpName}/{bpVersion}/{artifactName}/{resourceType}/{resourceId}",
+ produces = [MediaType.APPLICATION_JSON_VALUE])
+ @ApiOperation(value = "Store a resolved template w/ resourceId and resourceType",
+ notes = "Store a template for a given CBA's action, identified by its blueprint name, blueprint version, " +
+ "artifact name, resourceId and resourceType.",
+ response = TemplateResolution::class,
+ produces = MediaType.APPLICATION_JSON_VALUE)
+ @ResponseBody
+ @PreAuthorize("hasRole('USER')")
+ fun postWithResourceIdAndResourceType(
+ @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 = "Resource Type associated with the resolution.", required = false)
+ @PathVariable(value = "resourceType", required = true) resourceType: String,
+ @ApiParam(value = "Resource Id associated with the resolution.", required = false)
+ @PathVariable(value = "resourceId", required = true) resourceId: String,
+ @ApiParam(value = "Template to store.", required = true)
+ @RequestBody result: String): ResponseEntity<TemplateResolution> = runBlocking {
val resultStored =
- templateResolutionService.write(bpName, bpVersion, resolutionKey, artifactName, result)
+ templateResolutionService.write(bpName, bpVersion, artifactName, result, resourceId = resourceId, resourceType = resourceType)
ResponseEntity.ok().body(resultStored)
}