From 1141bf4d7f7c641aecdc12c085a7410bbe713bb8 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Mon, 10 Dec 2018 17:01:38 -0500 Subject: Implement Resource Resolution Services Change-Id: Ia1cf57c9fa16cb943836e3a78d4d2c9776f0e32f Issue-ID: CCSDK-724 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../resolution/ResourceResolutionComponent.kt | 23 +++++- .../resolution/ResourceResolutionConfiguration.kt | 26 +++++++ .../resolution/ResourceResolutionConstants.kt | 3 + .../resolution/ResourceResolutionService.kt | 91 +++++++++++++++++----- .../DataBaseResourceAssignmentProcessor.kt | 1 - .../DefaultResourceAssignmentProcessor.kt | 1 - .../InputResourceAssignmentProcessor.kt | 1 - .../ResourceAssignmentProcessor.kt | 61 +++++++++++++++ .../SimpleRestResourceAssignmentProcessor.kt | 1 - 9 files changed, 182 insertions(+), 26 deletions(-) create mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConfiguration.kt create mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/ResourceAssignmentProcessor.kt (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/ResourceResolutionComponent.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt index 32696c57..e5feb257 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt @@ -18,15 +18,34 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.ApplicationContext import org.springframework.context.annotation.Scope import org.springframework.stereotype.Component @Component("component-resource-resolution") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class ResourceResolutionComponent : AbstractComponentFunction() { +open class ResourceResolutionComponent(private val resourceResolutionService: ResourceResolutionService) : AbstractComponentFunction() { + + @Autowired + private lateinit var applicationContext: ApplicationContext + override fun process(executionRequest: ExecutionServiceInput) { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + + val artifactPrefixNamesNode = getOperationInput(ResourceResolutionConstants.INPUT_ARTIFACT_PREFIX_NAMES) + + val artifactPrefixNames = JacksonUtils.getListFromJsonNode(artifactPrefixNamesNode, String::class.java) + ?: throw BluePrintProcessorException("coundn't transform ${artifactPrefixNamesNode.asText()} to string array") + + val resolvedParamContents = resourceResolutionService.resolveResources(bluePrintRuntimeService!!, nodeTemplateName, artifactPrefixNames) + + // Set Output Attributes + bluePrintRuntimeService!!.setNodeTemplateAttributeValue(nodeTemplateName, + ResourceResolutionConstants.OUTPUT_ASSIGNMENT_PARAMS, resolvedParamContents.asJsonNode()) } override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConfiguration.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConfiguration.kt new file mode 100644 index 00000000..4c24ac69 --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConfiguration.kt @@ -0,0 +1,26 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution + +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration + +@Configuration +@ComponentScan +open class ResourceResolutionConfiguration + + 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 aea3313c..3211d6e8 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 @@ -19,6 +19,9 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution class ResourceResolutionConstants { companion object { 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" + const val FILE_NAME_RESOURCE_DICTIONARY_TYPES = "resources_dictionary_types.json" } } \ No newline at end of file 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 2b76b78a..c3cf0097 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 @@ -17,16 +17,19 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ResourceResolutionInput -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ResourceResolutionOutput -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolutionprocessor.ResourceAssignmentProcessor +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.utils.JacksonUtils import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignmentProcessor +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.BulkResourceSequencingUtils +import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.context.ApplicationContext import org.springframework.stereotype.Service +import java.io.File /** * ResourceResolutionService @@ -37,33 +40,76 @@ import org.springframework.stereotype.Service @Service class ResourceResolutionService { + private val log = LoggerFactory.getLogger(ResourceResolutionService::class.java) @Autowired private lateinit var applicationContext: ApplicationContext - fun resolveResource(resourceResolutionInput: ResourceResolutionInput): ResourceResolutionOutput { - val resourceResolutionOutput = ResourceResolutionOutput() - resourceResolutionOutput.actionIdentifiers = resourceResolutionInput.actionIdentifiers - resourceResolutionOutput.commonHeader = resourceResolutionInput.commonHeader - resourceResolutionOutput.resourceAssignments = resourceResolutionInput.resourceAssignments + 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) } + } - process(resourceResolutionOutput.resourceAssignments) - val status = Status() - status.code = 200 - status.message = "Success" - resourceResolutionOutput.status = status + fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, + artifactNames: List): MutableMap { - return resourceResolutionOutput + val resolvedParams: MutableMap = hashMapOf() + artifactNames.forEach { artifactName -> + val resolvedContent = resolveResources(bluePrintRuntimeService, nodeTemplateName, artifactName) + resolvedParams[artifactName] = resolvedContent + } + return resolvedParams } - 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) } + + fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, artifactName: String): String { + + var resolvedContent = "" + // Velocity Artifact Definition Name + val templateArtifactName = "$artifactName-template" + // Resource Assignment Artifact Definition Name + val mappingArtifactName = "$artifactName-mapping" + + log.info("Resolving resource for template artifact($templateArtifactName) with resource assignment artifact($mappingArtifactName)") + + val resourceAssignmentContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, mappingArtifactName) + + val resourceAssignments: MutableList = JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment::class.java) + as? MutableList + ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions") + + // Get the Resource Dictionary Name + val dictionaryFile = bluePrintRuntimeService.bluePrintContext().rootPath.plus(File.separator) + .plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR).plus(File.separator) + .plus(ResourceResolutionConstants.FILE_NAME_RESOURCE_DICTIONARY_TYPES) + + val resourceDictionaries: MutableMap = JacksonUtils.getMapFromFile(dictionaryFile, ResourceDefinition::class.java) + ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions") + + executeProcessors(bluePrintRuntimeService, resourceDictionaries, resourceAssignments) + + // Check Template is there + val templateContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, mappingArtifactName) + + // TODO ("Generate Param JSON from Resource Assignment") + val resolvedParamJsonContent = "{}" + + if (templateContent.isNotEmpty()) { + // TODO ( "Mash Data and Content") + resolvedContent = "Mashed Content" + + } else { + resolvedContent = resolvedParamJsonContent + } + return resolvedContent } - fun process(resourceAssignments: MutableList) { + + fun executeProcessors(bluePrintRuntimeService: BluePrintRuntimeService<*>, + resourceDictionaries: MutableMap, + resourceAssignments: MutableList) { val bulkSequenced = BulkResourceSequencingUtils.process(resourceAssignments) @@ -77,6 +123,10 @@ class ResourceResolutionService { ?: throw BluePrintProcessorException("failed to get resource processor for instance name($processorInstanceName) " + "for resource assignment(${resourceAssignment.name})") try { + // Set BluePrint Runtime Service + resourceAssignmentProcessor.bluePrintRuntimeService = bluePrintRuntimeService + // Set Resource Dictionaries + resourceAssignmentProcessor.resourceDictionaries = resourceDictionaries // Invoke Apply Method resourceAssignmentProcessor.apply(resourceAssignment) } catch (e: RuntimeException) { @@ -86,4 +136,5 @@ class ResourceResolutionService { } } } + } diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/DataBaseResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/DataBaseResourceAssignmentProcessor.kt index bdb79d30..12120341 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/DataBaseResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/DataBaseResourceAssignmentProcessor.kt @@ -18,7 +18,6 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolutionprocessor import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignmentProcessor import org.springframework.stereotype.Service /** diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/DefaultResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/DefaultResourceAssignmentProcessor.kt index 5419c0f6..58c9e1d8 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/DefaultResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/DefaultResourceAssignmentProcessor.kt @@ -18,7 +18,6 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolutionprocessor import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignmentProcessor import org.springframework.stereotype.Service /** diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/InputResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/InputResourceAssignmentProcessor.kt index 2b36add0..10332484 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/InputResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/InputResourceAssignmentProcessor.kt @@ -18,7 +18,6 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolutionprocessor import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignmentProcessor import org.springframework.stereotype.Service /** diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/ResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/ResourceAssignmentProcessor.kt new file mode 100644 index 00000000..2b19c8b8 --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/ResourceAssignmentProcessor.kt @@ -0,0 +1,61 @@ +/* + * Copyright © 2018 IBM. + * Modifications Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolutionprocessor + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BlueprintFunctionNode +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition +import org.slf4j.LoggerFactory + +abstract class ResourceAssignmentProcessor : BlueprintFunctionNode { + + private val log = LoggerFactory.getLogger(ResourceAssignmentProcessor::class.java) + + var bluePrintRuntimeService: BluePrintRuntimeService<*>? = null + + var resourceDictionaries: Map = hashMapOf() + + + open fun resourceDefinition(name: String): ResourceDefinition { + return resourceDictionaries.get(name) + ?: throw BluePrintProcessorException("couldn't get resource definition($name)") + } + + override fun prepareRequest(resourceAssignment: ResourceAssignment): ResourceAssignment { + log.info("prepareRequest for ${resourceAssignment.name}, dictionary(${resourceAssignment.dictionaryName})," + + "source(${resourceAssignment.dictionarySource})") + return resourceAssignment + } + + override fun prepareResponse(): ResourceAssignment { + log.info("Preparing Response...") + return ResourceAssignment() + } + + override fun apply(executionServiceInput: ResourceAssignment): ResourceAssignment { + prepareRequest(executionServiceInput) + process(executionServiceInput) + return prepareResponse() + } + + override abstract fun process(executionRequest: ResourceAssignment) + + override abstract fun recover(runtimeException: RuntimeException, executionRequest: ResourceAssignment) +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/SimpleRestResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/SimpleRestResourceAssignmentProcessor.kt index d778c232..c6732627 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/SimpleRestResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/SimpleRestResourceAssignmentProcessor.kt @@ -18,7 +18,6 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolutionprocessor import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignmentProcessor import org.springframework.stereotype.Service /** -- cgit 1.2.3-korg