From 86a67360c6cd076c91954892b5c0c49b4cbc1dfa Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Wed, 5 Feb 2020 14:27:36 -0500 Subject: Refactoring Resource Resolution Service Removing Node Template dependency Issue-ID: CCSDK-2078 Signed-off-by: Singal, Kapil (ks220y) Change-Id: I24f3e003c64f3ee40eee4699366cfadfc1d7147e --- .../resolution/ResourceResolutionService.kt | 32 +++++++++++++--------- .../resolution/ResourceResolutionServiceTest.kt | 26 ++++++++++-------- 2 files changed, 33 insertions(+), 25 deletions(-) (limited to 'ms/blueprintsprocessor/functions/resource-resolution') diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt index 51e93a3c1..7272a3d63 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt @@ -152,8 +152,7 @@ open class ResourceResolutionServiceImpl( // Resource Assignment Artifact Definition Name val artifactMapping = "$artifactPrefix-mapping" - val resolvedContent: String - log.info("Resolving resource for template artifact($artifactTemplate) with resource assignment artifact($artifactMapping)") + log.info("Resolving resource with resource assignment artifact($artifactMapping)") val resourceAssignmentContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactMapping) @@ -189,14 +188,20 @@ open class ResourceResolutionServiceImpl( val resolvedParamJsonContent = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList()) - resolvedContent = blueprintTemplateService.generateContent( - bluePrintRuntimeService, nodeTemplateName, - artifactTemplate, resolvedParamJsonContent, false, - mutableMapOf( - ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE to - properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE].asJsonPrimitive() + val artifactTemplateDefinition = bluePrintRuntimeService.bluePrintContext().checkNodeTemplateArtifact(nodeTemplateName, artifactTemplate) + + val resolvedContent = if (artifactTemplateDefinition != null) { + blueprintTemplateService.generateContent( + bluePrintRuntimeService, nodeTemplateName, + artifactTemplate, resolvedParamJsonContent, false, + mutableMapOf( + ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE to + properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE].asJsonPrimitive() + ) ) - ) + } else { + resolvedParamJsonContent + } if (isToStore(properties)) { templateResolutionDBService.write(properties, resolvedContent, bluePrintRuntimeService, artifactPrefix) @@ -211,8 +216,7 @@ open class ResourceResolutionServiceImpl( resourceDefinitions: MutableMap, resolveDefinition: String, sources: List - ): - MutableMap { + ): MutableMap { // Populate Dummy Resource Assignments val resourceAssignments = createResourceAssignments(resourceDefinitions, resolveDefinition, sources) @@ -397,8 +401,10 @@ open class ResourceResolutionServiceImpl( if (resourceResolution.status == BluePrintConstants.STATUS_SUCCESS) { resourceAssignmentList.forEach { if (compareOne(resourceResolution, it)) { - log.info("Resource ({}) already resolved: value=({})", it.name, - if (hasLogProtect(it.property)) LOG_REDACTED else resourceResolution.value) + log.info( + "Resource ({}) already resolved: value=({})", it.name, + if (hasLogProtect(it.property)) LOG_REDACTED else resourceResolution.value + ) // Make sure to recreate value as per the defined type. val value = resourceResolution.value!!.asJsonType(it.property!!.type) diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt index 264b45789..2f338a3a1 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt @@ -202,20 +202,20 @@ class ResourceResolutionServiceTest { "resource-assignment" ) - resourceResolutionService.resolveResources( - resourceAssignmentRuntimeService, - "resource-assignment", - artifactPrefix, - props + assertNotNull( + resourceResolutionService.resolveResources( + resourceAssignmentRuntimeService, + "resource-assignment", + artifactPrefix, + props + ), "Couldn't Resolve Resources for artifact $artifactPrefix" ) } } @Test fun testResolveResourcesWithResourceIdAndResourceType() { - props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = "" - runBlocking { Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService) @@ -245,11 +245,13 @@ class ResourceResolutionServiceTest { "resource-assignment" ) - resourceResolutionService.resolveResources( - resourceAssignmentRuntimeService, - "resource-assignment", - artifactPrefix, - props + assertNotNull( + resourceResolutionService.resolveResources( + resourceAssignmentRuntimeService, + "resource-assignment", + artifactPrefix, + props + ), "Couldn't Resolve Resources for artifact $artifactPrefix" ) } } -- cgit 1.2.3-korg