From 854cabcebee6d42a241700b4dcd66878440c2849 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Mon, 18 Feb 2019 15:10:25 -0500 Subject: Add component function scripting service Change-Id: I7c5b49617823dd623566fb4be4d431012420e17c Issue-ID: CCSDK-959 Signed-off-by: Muthuramalingam, Brinda Santh --- .../resolution/ResourceResolutionConstants.kt | 2 + .../resolution/ResourceResolutionService.kt | 112 ++++++++++----------- .../CapabilityResourceAssignmentProcessor.kt | 2 +- .../SimpleRestResourceAssignmentProcessor.kt | 2 +- 4 files changed, 60 insertions(+), 58 deletions(-) (limited to 'ms/blueprintsprocessor/functions/resource-resolution/src/main') diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt index eaa8eacc..5765609b 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt @@ -18,6 +18,8 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution class ResourceResolutionConstants { companion object { + const val SERVICE_RESOURCE_RESOLUTION = "resource-resolution-service" + const val PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR = "resource-assignment-processor-" const val INPUT_ARTIFACT_PREFIX_NAMES = "artifact-prefix-names" const val OUTPUT_ASSIGNMENT_PARAMS = "assignment-params" diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt index 34985527..24401ccf 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt @@ -22,7 +22,7 @@ import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.uti import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintTemplateService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintTemplateService import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition @@ -32,39 +32,39 @@ import org.springframework.context.ApplicationContext import org.springframework.stereotype.Service import java.io.File -interface ResourceResolutionService { - - fun registeredResourceSources(): List - - fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - artifactNames: List): MutableMap - - fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - artifactPrefix: String): String - - fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - artifactMapping: String, artifactTemplate: String?): String - - fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>, - resourceDictionaries: MutableMap, - resourceAssignments: MutableList, - identifierName: String) -} - -@Service -open class ResourceResolutionServiceImpl(private var applicationContext: ApplicationContext) : - ResourceResolutionService { +interface ResourceResolutionService { + + fun registeredResourceSources(): List + + fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, + artifactNames: List): MutableMap + + fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, + artifactPrefix: String): String + + fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, + artifactMapping: String, artifactTemplate: String?): String + + fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>, + resourceDictionaries: MutableMap, + resourceAssignments: MutableList, + identifierName: String) +} + +@Service(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION) +open class ResourceResolutionServiceImpl(private var applicationContext: ApplicationContext) : + ResourceResolutionService { private val log = LoggerFactory.getLogger(ResourceResolutionService::class.java) - override fun registeredResourceSources(): List { + override fun registeredResourceSources(): List { return applicationContext.getBeanNamesForType(ResourceAssignmentProcessor::class.java) .filter { it.startsWith(ResourceResolutionConstants.PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR) } .map { it.substringAfter(ResourceResolutionConstants.PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR) } } - override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - artifactNames: List): MutableMap { + override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, + artifactNames: List): MutableMap { val resolvedParams: MutableMap = hashMapOf() artifactNames.forEach { artifactName -> @@ -74,27 +74,27 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica return resolvedParams } - override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - artifactPrefix: String): String { + override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, + artifactPrefix: String): String { // Velocity Artifact Definition Name - val artifactTemplate = "$artifactPrefix-template" + val artifactTemplate = "$artifactPrefix-template" // Resource Assignment Artifact Definition Name - val artifactMapping = "$artifactPrefix-mapping" - - return resolveResources(bluePrintRuntimeService, nodeTemplateName, artifactMapping, artifactTemplate) - } - - - override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - artifactMapping: String, artifactTemplate: String?): String { - - var resolvedContent = "" - log.info("Resolving resource for template artifact($artifactTemplate) with resource assignment artifact($artifactMapping)") - - val identifierName = artifactTemplate ?: "no-template" - - val resourceAssignmentContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactMapping) + val artifactMapping = "$artifactPrefix-mapping" + + return resolveResources(bluePrintRuntimeService, nodeTemplateName, artifactMapping, artifactTemplate) + } + + + override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, + artifactMapping: String, artifactTemplate: String?): String { + + var resolvedContent = "" + log.info("Resolving resource for template artifact($artifactTemplate) with resource assignment artifact($artifactMapping)") + + val identifierName = artifactTemplate ?: "no-template" + + val resourceAssignmentContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactMapping) val resourceAssignments: MutableList = JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment::class.java) as? MutableList @@ -108,28 +108,28 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica val resourceDictionaries: MutableMap = JacksonUtils.getMapFromFile(dictionaryFile, ResourceDefinition::class.java) ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions") - // Resolve resources - resolveResourceAssignments(bluePrintRuntimeService, resourceDictionaries, resourceAssignments, identifierName) + // Resolve resources + resolveResourceAssignments(bluePrintRuntimeService, resourceDictionaries, resourceAssignments, identifierName) - val resolvedParamJsonContent = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList()) + val resolvedParamJsonContent = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList()) - // Check Template is there - if (artifactTemplate != null) { - val templateContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactTemplate) - resolvedContent = BluePrintTemplateService.generateContent(templateContent, resolvedParamJsonContent) + // Check Template is there + if (artifactTemplate != null) { + val templateContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactTemplate) + resolvedContent = BluePrintTemplateService.generateContent(templateContent, resolvedParamJsonContent) } else { resolvedContent = resolvedParamJsonContent } return resolvedContent } - override fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>, - resourceDictionaries: MutableMap, - resourceAssignments: MutableList, - identifierName: String) { + override fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>, + resourceDictionaries: MutableMap, + resourceAssignments: MutableList, + identifierName: String) { val bulkSequenced = BulkResourceSequencingUtils.process(resourceAssignments) - val resourceAssignmentRuntimeService = ResourceAssignmentUtils.transformToRARuntimeService(blueprintRuntimeService, identifierName) + val resourceAssignmentRuntimeService = ResourceAssignmentUtils.transformToRARuntimeService(blueprintRuntimeService, identifierName) bulkSequenced.map { batchResourceAssignments -> batchResourceAssignments.filter { it.name != "*" && it.name != "start" } diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt index 162a7b49..489645fd 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt @@ -18,7 +18,7 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor -import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService +import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.BlueprintJythonService import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.CapabilityResourceSource import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/SimpleRestResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/SimpleRestResourceAssignmentProcessor.kt index f1a4dbb0..a264ba50 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/SimpleRestResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/SimpleRestResourceAssignmentProcessor.kt @@ -70,7 +70,7 @@ open class SimpleRestResourceAssignmentProcessor(private val blueprintRestLibPro val inputKeyMapping = checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" } logger.info("$dSource dictionary information : ($urlPath), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})") - + // TODO("Dynamic Rest Client Service, call (blueprintDynamicWebClientService || blueprintWebClientService") val restClientService = blueprintRestLibPropertyService.blueprintWebClientService("primary-config-data") val response = restClientService.getResource(urlPath, String::class.java) if (response.isNotBlank()) { -- cgit 1.2.3-korg