aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/inbounds
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2019-07-08 15:14:18 +0000
committerGerrit Code Review <gerrit@onap.org>2019-07-08 15:14:18 +0000
commit61672376481804b037a92d77042bac84eca0adf8 (patch)
treed598aaa055a81e8d6c658b2b116fd2814ae9118c /ms/blueprintsprocessor/modules/inbounds
parent64561f49e029e567c94e89141c8657a33112c06e (diff)
parent5f0a5dde67bc0e7c99bd8f9e9b7c447e69ce62fa (diff)
Merge "Enforce resolutionKey or resourceId/resourceType"
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds')
-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
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resolutionresults/api/ResourceControllerTest.kt20
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateControllerTest.kt9
6 files changed, 78 insertions, 46 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)
}
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 daab7b3bb..9ed97df1a 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
@@ -16,44 +16,28 @@
package org.onap.ccsdk.cds.blueprintsprocessor.resolutionresults.api
-import com.fasterxml.jackson.core.type.TypeReference
-import com.fasterxml.jackson.module.kotlin.readValue
import kotlinx.coroutines.runBlocking
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
-import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration
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.asJsonPrimitive
import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
-import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
-import org.python.jline.console.internal.ConsoleRunner.property
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.security.SecurityProperties
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
import org.springframework.context.annotation.ComponentScan
-import org.springframework.http.HttpHeaders
-import org.springframework.http.HttpStatus
-import org.springframework.http.MediaType
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.TestPropertySource
import org.springframework.test.context.junit4.SpringRunner
import org.springframework.test.web.reactive.server.WebTestClient
-import org.springframework.web.reactive.function.BodyInserters
-import java.util.function.Consumer
-import kotlin.test.BeforeTest
-import org.h2.value.DataType.readValue
-import java.util.*
-import org.h2.value.DataType.readValue
-import org.python.bouncycastle.asn1.x500.style.RFC4519Style.l
-import org.h2.value.DataType.readValue
import org.onap.ccsdk.cds.blueprintsprocessor.resource.api.ErrorMessage
import org.onap.ccsdk.cds.blueprintsprocessor.resource.api.ResourceController
-import java.lang.reflect.Array
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
@RunWith(SpringRunner::class)
@@ -233,7 +217,7 @@ class ResourceControllerTest {
resourceAssignment.dictionaryName = "dd$prefix"
resourceAssignment.dictionarySource = "source$prefix"
resourceAssignment.version = 2
- resourceAssignment.status = "SUCCESS"
+ resourceAssignment.status = BluePrintConstants.STATUS_SUCCESS
resourceAssignment.property = property
return resourceAssignment
}
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 649f6b5fe..c3a718e11 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
@@ -17,11 +17,9 @@
package org.onap.ccsdk.cds.blueprintsprocessor.resource.api
import kotlinx.coroutines.runBlocking
-import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration
-import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.TemplateResolutionService
import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService
import org.slf4j.LoggerFactory
@@ -29,18 +27,13 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.security.SecurityProperties
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
import org.springframework.context.annotation.ComponentScan
-import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.TestPropertySource
import org.springframework.test.context.junit4.SpringRunner
import org.springframework.test.web.reactive.server.WebTestClient
import org.springframework.web.reactive.function.BodyInserters
-import java.io.File
-import java.nio.file.Paths
import kotlin.test.AfterTest
-import kotlin.test.BeforeTest
-import kotlin.test.assertTrue
@RunWith(SpringRunner::class)
@WebFluxTest
@@ -137,7 +130,7 @@ class TemplateControllerTest {
webTestClient
.get()
.uri("/api/v1/template?bpName=$blueprintName&bpVersion=$blueprintVersion" +
- "&artifactName=$templatePrefix&resolutionKey=bob")
+ "&artifactName=$templatePrefix&resolutionKey=notFound")
.exchange()
.expectStatus().isNotFound
}