diff options
6 files changed, 45 insertions, 17 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt index 5958c7899..bfe9da35c 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt @@ -90,7 +90,7 @@ class ResourceResolutionDBService(private val resourceResolutionRepository: Reso artifactPrefix: String, resolutionKey: String, name: String - ): ResourceResolution = withContext(Dispatchers.IO) { + ): ResourceResolution? = withContext(Dispatchers.IO) { resourceResolutionRepository.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndName( resolutionKey, diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt index c2d630e5e..6e0ed3a4b 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt @@ -16,19 +16,25 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.Query +import org.springframework.data.repository.query.Param import org.springframework.stereotype.Repository import javax.transaction.Transactional @Repository interface ResourceResolutionRepository : JpaRepository<ResourceResolution, String> { + @Query( + value = "SELECT * FROM RESOURCE_RESOLUTION WHERE resolution_key = :key AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion AND artifact_name = :artifactName AND name = :name ORDER BY occurrence DESC, creation_date DESC LIMIT 1", + nativeQuery = true + ) fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndName( - key: String, - blueprintName: String?, - blueprintVersion: String?, - artifactName: String, - name: String - ): ResourceResolution + @Param("key")key: String, + @Param("blueprintName")blueprintName: String, + @Param("blueprintVersion")blueprintVersion: String, + @Param("artifactName")artifactName: String, + @Param("name")name: String + ): ResourceResolution? fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName( resolutionKey: String, diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBServiceTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBServiceTest.kt index fa59876a9..635ce0e38 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBServiceTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBServiceTest.kt @@ -30,6 +30,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRunt import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment import org.springframework.dao.EmptyResultDataAccessException import kotlin.test.assertEquals +import kotlin.test.assertNotEquals open class ResourceResolutionDBServiceTest { @@ -158,9 +159,11 @@ open class ResourceResolutionDBServiceTest { resourceResolutionDBService.readValue( blueprintName, blueprintVersion, artifactPrefix, resolutionKey, "bob" ) - - assertEquals(rr.name, res.name) - assertEquals(rr.value, res.value) + assertNotEquals(res, null, "resource resolution failed") + if (res != null) { + assertEquals(rr.name, res.name) + assertEquals(rr.value, res.value) + } } } diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt index 611c0855d..b1d8abd16 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt @@ -29,6 +29,7 @@ import kotlinx.coroutines.reactor.ReactorContext import kotlinx.coroutines.reactor.asCoroutineContext import kotlinx.coroutines.withContext import org.apache.http.message.BasicHeader +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_INVOCATION_ID import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_ORIGINATOR_ID @@ -107,8 +108,12 @@ class RestLoggerService { } } -/** Used in Rest controller API methods to populate MDC context to nested coroutines from reactor web filter context. */ +/** + * Used in Rest controller API methods to populate MDC context to nested coroutines from reactor web filter context. + * @param executionServiceInput (Optional) Used to override values populated in the MDC Context + */ suspend fun <T> mdcWebCoroutineScope( + executionServiceInput: ExecutionServiceInput? = null, block: suspend CoroutineScope.() -> T ) = coroutineScope { val reactorContext = this.coroutineContext[ReactorContext] @@ -118,12 +123,20 @@ suspend fun <T> mdcWebCoroutineScope( !reactorContext.context.isEmpty && reactorContext.context.hasKey(MDCContext) ) { - val mdcContext = reactorContext.context.get<MDCContext>(MDCContext) + val mdcContext = if (executionServiceInput != null) { + // MDC Context with overridden request ID + MDC.put("RequestID", executionServiceInput.commonHeader.requestId) + MDCContext(MDC.getCopyOfContextMap()) + } else { + // Default MDC Context + reactorContext.context.get(MDCContext) + } if (mdcContext != null) newCoroutineContext(this.coroutineContext + reactorContext + mdcContext) else newCoroutineContext(this.coroutineContext + reactorContext) } else this.coroutineContext + // Execute the block with new and old context withContext(newContext) { block() 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 15c27a43b..4a2a55930 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 @@ -26,6 +26,8 @@ import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.R import org.onap.ccsdk.cds.controllerblueprints.core.httpProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogCodes +import org.onap.ccsdk.cds.error.catalog.core.ErrorPayload +import org.springframework.http.HttpStatus import org.springframework.http.MediaType import org.springframework.http.ResponseEntity import org.springframework.security.access.prepost.PreAuthorize @@ -161,9 +163,14 @@ open class ResourceController(private var resourceResolutionDBService: ResourceR @ApiParam(value = "Name of the resource to retrieve", required = true) @RequestParam(value = "name", required = true) name: String ): - ResponseEntity<ResourceResolution> = runBlocking { + ResponseEntity<out Any>? = runBlocking { - ResponseEntity.ok() - .body(resourceResolutionDBService.readValue(bpName, bpVersion, artifactName, resolutionKey, name)) + var result: ResourceResolution? = resourceResolutionDBService.readValue(bpName, bpVersion, artifactName, resolutionKey, name) + if (result != null) { + ResponseEntity.ok().body(result) + } else { + var errorPayload = ErrorPayload(HttpStatus.NOT_FOUND.value(), ErrorCatalogCodes.GENERIC_FAILURE, "No records found") + ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorPayload) + } } } diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt index bb7ecc6ad..9e0a7ee71 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt @@ -91,8 +91,7 @@ open class ExecutionServiceController { suspend fun process( @ApiParam(value = "ExecutionServiceInput payload.", required = true) @RequestBody executionServiceInput: ExecutionServiceInput - ): ResponseEntity<ExecutionServiceOutput> = mdcWebCoroutineScope { - + ): ResponseEntity<ExecutionServiceOutput> = mdcWebCoroutineScope(executionServiceInput) { if (executionServiceInput.actionIdentifiers.mode == ACTION_MODE_ASYNC) { throw httpProcessorException( ErrorCatalogCodes.GENERIC_FAILURE, |