From 50fb805cd04593426f6c8e23a40f51398099e183 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Mon, 25 Feb 2019 16:03:16 -0500 Subject: Get DSL Property in Resource Resolution Change-Id: I768c2515bc4b0eaa829213ac4d045628ca960adb Issue-ID: CCSDK-1106 Signed-off-by: Muthuramalingam, Brinda Santh --- .../resolution/ResourceResolutionConstants.kt | 2 +- .../resolution/ResourceResolutionService.kt | 58 ++++++- .../resolution/ResourceSourceProperties.kt | 11 +- .../CapabilityResourceAssignmentProcessor.kt | 181 --------------------- .../CapabilityResourceResolutionProcessor.kt | 178 ++++++++++++++++++++ .../DefaultResourceAssignmentProcessor.kt | 66 -------- .../DefaultResourceResolutionProcessor.kt | 69 ++++++++ .../processor/InputResourceAssignmentProcessor.kt | 62 ------- .../processor/InputResourceResolutionProcessor.kt | 65 ++++++++ .../PrimaryDataResourceAssignmentProcessor.kt | 164 ------------------- .../PrimaryDataResourceResolutionProcessor.kt | 167 +++++++++++++++++++ .../processor/ResourceAssignmentProcessor.kt | 10 +- .../processor/RestResourceResolutionProcessor.kt | 176 ++++++++++++++++++++ .../SimpleRestResourceAssignmentProcessor.kt | 162 ------------------ .../resolution/ResourceResolutionComponentTest.kt | 6 +- .../resolution/ResourceResolutionServiceTest.kt | 9 +- .../CapabilityResourceAssignmentProcessorTest.kt | 120 -------------- .../CapabilityResourceResolutionProcessorTest.kt | 120 ++++++++++++++ .../capability/jython-resource-definitions.json | 4 +- .../service/BluePrintRestLibPropertyService.kt | 33 +++- 20 files changed, 879 insertions(+), 784 deletions(-) delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt create mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceAssignmentProcessor.kt create mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceAssignmentProcessor.kt create mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/PrimaryDataResourceAssignmentProcessor.kt create mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/PrimaryDataResourceResolutionProcessor.kt create mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/SimpleRestResourceAssignmentProcessor.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessorTest.kt create mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt (limited to 'ms/blueprintsprocessor') 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 5765609b..ca92e96d 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 @@ -20,7 +20,7 @@ class ResourceResolutionConstants { companion object { const val SERVICE_RESOURCE_RESOLUTION = "resource-resolution-service" - const val PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR = "resource-assignment-processor-" + const val PREFIX_RESOURCE_RESOLUTION_PROCESSOR = "rr-processor-" const val INPUT_ARTIFACT_PREFIX_NAMES = "artifact-prefix-names" const val OUTPUT_ASSIGNMENT_PARAMS = "assignment-params" const val FILE_NAME_RESOURCE_DEFINITION_TYPES = "resources_definition_types.json" 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 24401ccf..48415efa 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 @@ -21,6 +21,7 @@ import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.pro import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow 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.utils.JacksonUtils @@ -59,8 +60,8 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica 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) } + .filter { it.startsWith(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) } + .map { it.substringAfter(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) } } override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, @@ -123,6 +124,11 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica return resolvedContent } + /** + * Iterate the Batch, get the Resource Assignment, dictionary Name, Look for the Resource definition for the + * name, then get the type of the Resource Definition, Get the instance for the Resource Type and process the + * request. + */ override fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>, resourceDictionaries: MutableMap, resourceAssignments: MutableList, @@ -133,12 +139,17 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica bulkSequenced.map { batchResourceAssignments -> batchResourceAssignments.filter { it.name != "*" && it.name != "start" } - .map { resourceAssignment -> + .forEach { resourceAssignment -> + val dictionaryName = resourceAssignment.dictionaryName val dictionarySource = resourceAssignment.dictionarySource - val processorInstanceName = ResourceResolutionConstants.PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR.plus(dictionarySource) - - val resourceAssignmentProcessor = applicationContext.getBean(processorInstanceName) as? ResourceAssignmentProcessor - ?: throw BluePrintProcessorException("failed to get resource processor for instance name($processorInstanceName) " + + /** + * Get the Processor name + */ + val processorName = processorName(dictionaryName!!, dictionarySource!!, + resourceDictionaries) + + val resourceAssignmentProcessor = applicationContext.getBean(processorName) as? ResourceAssignmentProcessor + ?: throw BluePrintProcessorException("failed to get resource processor for name($processorName) " + "for resource assignment(${resourceAssignment.name})") try { // Set BluePrint Runtime Service @@ -155,4 +166,37 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica } } + + /** + * If the Source instance is "input", then it is not mandatory to have source Resource Definition, So it can + * derive the default input processor. + */ + private fun processorName(dictionaryName: String, dictionarySource: String, + resourceDictionaries: MutableMap): String { + var processorName: String? = null + when (dictionarySource) { + "input" -> { + processorName = "${ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-input" + } + "default" -> { + processorName = "${ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-default" + } + else -> { + val resourceDefinition = resourceDictionaries[dictionaryName] + ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dictionaryName") + + val resourceSource = resourceDefinition.sources[dictionarySource] + ?: throw BluePrintProcessorException("couldn't get resource definition $dictionaryName source($dictionarySource)") + + processorName = ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR + .plus(resourceSource.type) + } + } + checkNotEmptyOrThrow(processorName, + "couldn't get processor name for resource dictionary definition($dictionaryName) source" + + "($dictionarySource)") + + return processorName + + } } diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt index 0f1267cb..1c357446 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt @@ -36,6 +36,8 @@ open class DefaultResourceSource : ResourceSourceProperties() { open class DatabaseResourceSource : ResourceSourceProperties() { lateinit var type: String + @get:JsonProperty("endpoint-selector") + var endpointSelector: String? = null lateinit var query: String @get:JsonProperty("input-key-mapping") var inputKeyMapping: MutableMap? = null @@ -47,6 +49,8 @@ open class DatabaseResourceSource : ResourceSourceProperties() { open class RestResourceSource : ResourceSourceProperties() { lateinit var type: String + @get:JsonProperty("endpoint-selector") + var endpointSelector: String? = null @get:JsonProperty("url-path") lateinit var urlPath: String lateinit var path: String @@ -61,9 +65,10 @@ open class RestResourceSource : ResourceSourceProperties() { } open class CapabilityResourceSource : ResourceSourceProperties() { - lateinit var type: String - @get:JsonProperty("instance-name") - lateinit var instanceName: String + @get:JsonProperty("script-type") + lateinit var scriptType: String + @get:JsonProperty("script-class-reference") + lateinit var scriptClassReference: String @get:JsonProperty("instance-dependencies") var instanceDependencies: List? = null @get:JsonProperty("key-dependencies") 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 deleted file mode 100644 index 489645fd..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Modifications Copyright © 2019 IBM, Bell Canada. - * - * 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.processor - -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 -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintScriptsService -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.slf4j.LoggerFactory -import org.springframework.context.ApplicationContext -import org.springframework.stereotype.Service -import java.io.File - -@Service("resource-assignment-processor-capability") -open class CapabilityResourceAssignmentProcessor(private var applicationContext: ApplicationContext, - private val bluePrintScriptsService: BluePrintScriptsService, - private val bluePrintJythonService: BlueprintJythonService) : - ResourceAssignmentProcessor() { - - companion object { - const val CAPABILITY_TYPE_KOTLIN_COMPONENT = "KOTLIN-COMPONENT" - const val CAPABILITY_TYPE_JAVA_COMPONENT = "JAVA-COMPONENT" - const val CAPABILITY_TYPE_JYTHON_COMPONENT = "JYTHON-COMPONENT" - } - - override fun getName(): String { - return "resource-assignment-processor-capability" - } - - override fun process(resourceAssignment: ResourceAssignment) { - - val resourceDefinition = resourceDictionaries[resourceAssignment.dictionaryName] - ?: throw BluePrintProcessorException("couldn't get resource definition for ${resourceAssignment.dictionaryName}") - - val resourceSource = resourceDefinition.sources[resourceAssignment.dictionarySource] - ?: throw BluePrintProcessorException("couldn't get resource definition " + - "${resourceAssignment.dictionaryName} source(${resourceAssignment.dictionarySource})") - - val resourceSourceProps = checkNotNull(resourceSource.properties) { "failed to get $resourceSource properties" } - /** - * Get the Capability Resource Source Info from Property Definitions. - */ - val capabilityResourceSourceProperty = JacksonUtils - .getInstanceFromMap(resourceSourceProps, CapabilityResourceSource::class.java) - - val instanceType = capabilityResourceSourceProperty.type - val instanceName = capabilityResourceSourceProperty.instanceName - - var componentResourceAssignmentProcessor: ResourceAssignmentProcessor? = null - - when (instanceType) { - CAPABILITY_TYPE_KOTLIN_COMPONENT -> { - componentResourceAssignmentProcessor = getKotlinResourceAssignmentProcessorInstance(instanceName, - capabilityResourceSourceProperty.instanceDependencies) - } - CAPABILITY_TYPE_JAVA_COMPONENT -> { - // Initialize Capability Resource Assignment Processor - componentResourceAssignmentProcessor = applicationContext.getBean(instanceName, ResourceAssignmentProcessor::class.java) - } - CAPABILITY_TYPE_JYTHON_COMPONENT -> { - val content = getJythonContent(instanceName) - componentResourceAssignmentProcessor = getJythonResourceAssignmentProcessorInstance(instanceName, - content, capabilityResourceSourceProperty.instanceDependencies) - } - } - - checkNotNull(componentResourceAssignmentProcessor) { "failed to get capability resource assignment processor($instanceName)" } - - // Assign Current Blueprint runtime and ResourceDictionaries - componentResourceAssignmentProcessor.raRuntimeService = raRuntimeService - componentResourceAssignmentProcessor.resourceDictionaries = resourceDictionaries - - // Invoke componentResourceAssignmentProcessor - componentResourceAssignmentProcessor.apply(resourceAssignment) - } - - override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { - - TODO("To Implement") - } - - private fun getKotlinResourceAssignmentProcessorInstance(scriptClassName: String, - instanceNames: List? = null): ResourceAssignmentProcessor { - var scriptPropertyInstances: MutableMap? = null - - if (instanceNames != null && instanceNames.isNotEmpty()) { - scriptPropertyInstances = hashMapOf() - instanceNames.forEach { - scriptPropertyInstances[it] = applicationContext.getBean(it) - ?: throw BluePrintProcessorException("couldn't get the dependency instance($it)") - } - } - - return getKotlinResourceAssignmentProcessorInstance(scriptClassName, scriptPropertyInstances) - - } - - fun getKotlinResourceAssignmentProcessorInstance(scriptClassName: String, - scriptPropertyInstances: MutableMap? = null): - ResourceAssignmentProcessor { - - val resourceAssignmentProcessor = bluePrintScriptsService - .scriptInstance(raRuntimeService.bluePrintContext(), - scriptClassName, false) - - // Add additional Instance - if (scriptPropertyInstances != null) { - resourceAssignmentProcessor.scriptPropertyInstances = scriptPropertyInstances - } - - return resourceAssignmentProcessor - } - - private fun getJythonContent(instanceName: String): String { - val absolutePath = raRuntimeService.bluePrintContext().rootPath - .plus(File.separator) - .plus(BluePrintConstants.TOSCA_SCRIPTS_JYTHON_DIR) - .plus(File.separator) - .plus("$instanceName.py") - - return JacksonUtils.getContent(absolutePath) - - } - - /** - * getJythonResourceAssignmentProcessorInstance Purpose: prepare the jython - * executor component as a resource assignment processor - * - * @param pythonClassName String - * @param content String - * @param dependencyInstances List - * @return resourceAssignmentProcessor ResourceAssignmentProcessor - */ - private fun getJythonResourceAssignmentProcessorInstance(pythonClassName: String, content: String, - dependencyInstances: List?): - ResourceAssignmentProcessor { - val jythonContextInstance: MutableMap = hashMapOf() - jythonContextInstance["log"] = LoggerFactory.getLogger(pythonClassName) - jythonContextInstance["raRuntimeService"] = raRuntimeService - dependencyInstances?.forEach { instanceName -> - jythonContextInstance[instanceName] = applicationContext.getBean(instanceName) - } - - return getJythonResourceAssignmentProcessorInstance(pythonClassName, content, jythonContextInstance) - } - - fun getJythonResourceAssignmentProcessorInstance(pythonClassName: String, content: String, - dependencyInstances: MutableMap): - ResourceAssignmentProcessor { - - val resourceAssignmentProcessor = bluePrintJythonService - .jythonInstance(raRuntimeService.bluePrintContext(), pythonClassName, - content, dependencyInstances) - - // Add additional Instance - if (dependencyInstances != null) { - resourceAssignmentProcessor.scriptPropertyInstances = dependencyInstances - } - - return resourceAssignmentProcessor - } -} \ 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/processor/CapabilityResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt new file mode 100644 index 00000000..c6b7d77e --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt @@ -0,0 +1,178 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Modifications Copyright © 2019 IBM, Bell Canada. + * + * 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.processor + +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.CapabilityResourceSource +import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.BlueprintJythonService +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintScriptsService +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.ApplicationContext +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service +import java.io.File + +@Service("rr-processor-source-capability") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +open class CapabilityResourceResolutionProcessor(private var applicationContext: ApplicationContext, + private val bluePrintScriptsService: BluePrintScriptsService, + private val bluePrintJythonService: BlueprintJythonService) : + ResourceAssignmentProcessor() { + + override fun getName(): String { + return "resource-assignment-processor-capability" + } + + override fun process(resourceAssignment: ResourceAssignment) { + + val resourceDefinition = resourceDictionaries[resourceAssignment.dictionaryName] + ?: throw BluePrintProcessorException("couldn't get resource definition for ${resourceAssignment.dictionaryName}") + + val resourceSource = resourceDefinition.sources[resourceAssignment.dictionarySource] + ?: throw BluePrintProcessorException("couldn't get resource definition " + + "${resourceAssignment.dictionaryName} source(${resourceAssignment.dictionarySource})") + + val resourceSourceProps = checkNotNull(resourceSource.properties) { "failed to get $resourceSource properties" } + /** + * Get the Capability Resource Source Info from Property Definitions. + */ + val capabilityResourceSourceProperty = JacksonUtils + .getInstanceFromMap(resourceSourceProps, CapabilityResourceSource::class.java) + + val scriptType = capabilityResourceSourceProperty.scriptType + val scriptClassReference = capabilityResourceSourceProperty.scriptClassReference + + var componentResourceAssignmentProcessor: ResourceAssignmentProcessor? = null + + when (scriptType) { + BluePrintConstants.SCRIPT_KOTLIN -> { + componentResourceAssignmentProcessor = getKotlinResourceAssignmentProcessorInstance(scriptClassReference, + capabilityResourceSourceProperty.instanceDependencies) + } + BluePrintConstants.SCRIPT_INTERNAL -> { + // Initialize Capability Resource Assignment Processor + componentResourceAssignmentProcessor = applicationContext.getBean(scriptClassReference, ResourceAssignmentProcessor::class.java) + } + BluePrintConstants.SCRIPT_JYTHON -> { + val content = getJythonContent(scriptClassReference) + componentResourceAssignmentProcessor = getJythonResourceAssignmentProcessorInstance(scriptClassReference, + content, capabilityResourceSourceProperty.instanceDependencies) + } + } + + checkNotNull(componentResourceAssignmentProcessor) { "failed to get capability resource assignment processor($scriptClassReference)" } + + // Assign Current Blueprint runtime and ResourceDictionaries + componentResourceAssignmentProcessor.raRuntimeService = raRuntimeService + componentResourceAssignmentProcessor.resourceDictionaries = resourceDictionaries + + // Invoke componentResourceAssignmentProcessor + componentResourceAssignmentProcessor.apply(resourceAssignment) + } + + override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { + + TODO("To Implement") + } + + private fun getKotlinResourceAssignmentProcessorInstance(scriptClassName: String, + instanceNames: List? = null): ResourceAssignmentProcessor { + var scriptPropertyInstances: MutableMap? = null + + if (instanceNames != null && instanceNames.isNotEmpty()) { + scriptPropertyInstances = hashMapOf() + instanceNames.forEach { + scriptPropertyInstances[it] = applicationContext.getBean(it) + ?: throw BluePrintProcessorException("couldn't get the dependency instance($it)") + } + } + + return getKotlinResourceAssignmentProcessorInstance(scriptClassName, scriptPropertyInstances) + + } + + fun getKotlinResourceAssignmentProcessorInstance(scriptClassName: String, + scriptPropertyInstances: MutableMap? = null): + ResourceAssignmentProcessor { + + val resourceAssignmentProcessor = bluePrintScriptsService + .scriptInstance(raRuntimeService.bluePrintContext(), + scriptClassName, false) + + // Add additional Instance + if (scriptPropertyInstances != null) { + resourceAssignmentProcessor.scriptPropertyInstances = scriptPropertyInstances + } + + return resourceAssignmentProcessor + } + + private fun getJythonContent(instanceName: String): String { + val absolutePath = raRuntimeService.bluePrintContext().rootPath + .plus(File.separator) + .plus(BluePrintConstants.TOSCA_SCRIPTS_JYTHON_DIR) + .plus(File.separator) + .plus("$instanceName.py") + + return JacksonUtils.getContent(absolutePath) + + } + + /** + * getJythonResourceAssignmentProcessorInstance Purpose: prepare the jython + * executor component as a resource assignment processor + * + * @param pythonClassName String + * @param content String + * @param dependencyInstances List + * @return resourceAssignmentProcessor ResourceAssignmentProcessor + */ + private fun getJythonResourceAssignmentProcessorInstance(pythonClassName: String, content: String, + dependencyInstances: List?): + ResourceAssignmentProcessor { + val jythonContextInstance: MutableMap = hashMapOf() + jythonContextInstance["log"] = LoggerFactory.getLogger(pythonClassName) + jythonContextInstance["raRuntimeService"] = raRuntimeService + dependencyInstances?.forEach { instanceName -> + jythonContextInstance[instanceName] = applicationContext.getBean(instanceName) + } + + return getJythonResourceAssignmentProcessorInstance(pythonClassName, content, jythonContextInstance) + } + + fun getJythonResourceAssignmentProcessorInstance(pythonClassName: String, content: String, + dependencyInstances: MutableMap): + ResourceAssignmentProcessor { + + val resourceAssignmentProcessor = bluePrintJythonService + .jythonInstance(raRuntimeService.bluePrintContext(), pythonClassName, + content, dependencyInstances) + + // Add additional Instance + if (dependencyInstances != null) { + resourceAssignmentProcessor.scriptPropertyInstances = dependencyInstances + } + + return resourceAssignmentProcessor + } +} \ 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/processor/DefaultResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceAssignmentProcessor.kt deleted file mode 100644 index e389f362..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceAssignmentProcessor.kt +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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.processor - -import com.fasterxml.jackson.databind.node.NullNode -import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Service - -/** - * DefaultResourceAssignmentProcessor - * - * @author Kapil Singal - */ -@Service("resource-assignment-processor-default") -open class DefaultResourceAssignmentProcessor : ResourceAssignmentProcessor() { - - private val logger = LoggerFactory.getLogger(DefaultResourceAssignmentProcessor::class.java) - - override fun getName(): String { - return "resource-assignment-processor-default" - } - - override fun process(resourceAssignment: ResourceAssignment) { - try { - // Check if It has Input - var value: Any? = raRuntimeService.getInputValue(resourceAssignment.name) - - // If value is null get it from default source - if (value == null || value is NullNode) { - logger.info("Looking for defaultValue as couldn't find value in input For template key (${resourceAssignment.name})") - value = resourceAssignment.property?.defaultValue - } - - logger.info("For template key (${resourceAssignment.name}) setting value as ($value)") - ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value) - - // Check the value has populated for mandatory case - ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment) - } catch (e: Exception) { - ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message) - throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}", e) - } - - } - - override fun recover(runtimeException: RuntimeException, resourceAssignment: 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/resolution/processor/DefaultResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt new file mode 100644 index 00000000..f23ada98 --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt @@ -0,0 +1,69 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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.processor + +import com.fasterxml.jackson.databind.node.NullNode +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service + +/** + * DefaultResourceResolutionProcessor + * + * @author Kapil Singal + */ +@Service("rr-processor-source-default") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +open class DefaultResourceResolutionProcessor : ResourceAssignmentProcessor() { + + private val logger = LoggerFactory.getLogger(DefaultResourceResolutionProcessor::class.java) + + override fun getName(): String { + return "rr-processor-source-default" + } + + override fun process(resourceAssignment: ResourceAssignment) { + try { + // Check if It has Input + var value: Any? = raRuntimeService.getInputValue(resourceAssignment.name) + + // If value is null get it from default source + if (value == null || value is NullNode) { + logger.info("Looking for defaultValue as couldn't find value in input For template key (${resourceAssignment.name})") + value = resourceAssignment.property?.defaultValue + } + + logger.info("For template key (${resourceAssignment.name}) setting value as ($value)") + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value) + + // Check the value has populated for mandatory case + ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment) + } catch (e: Exception) { + ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message) + throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}", e) + } + + } + + override fun recover(runtimeException: RuntimeException, resourceAssignment: 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/resolution/processor/InputResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceAssignmentProcessor.kt deleted file mode 100644 index 5757de2a..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceAssignmentProcessor.kt +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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.processor - -import com.fasterxml.jackson.databind.node.NullNode -import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Service - -/** - * InputResourceAssignmentProcessor - * - * @author Kapil Singal - */ -@Service("resource-assignment-processor-input") -open class InputResourceAssignmentProcessor : ResourceAssignmentProcessor() { - - private val logger = LoggerFactory.getLogger(InputResourceAssignmentProcessor::class.java) - - override fun getName(): String { - return "resource-assignment-processor-input" - } - - override fun process(resourceAssignment: ResourceAssignment) { - try { - if (checkNotEmpty(resourceAssignment.name)) { - val value = raRuntimeService.getInputValue(resourceAssignment.name) - // if value is null don't call setResourceDataValue to populate the value - if (value != null && value !is NullNode) { - logger.info("input source template key (${resourceAssignment.name}) found from input and value is ($value)") - ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value) - } - } - // Check the value has populated for mandatory case - ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment) - } catch (e: Exception) { - ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message) - throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with : (${e.message})", e) - } - } - - override fun recover(runtimeException: RuntimeException, resourceAssignment: 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/resolution/processor/InputResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt new file mode 100644 index 00000000..ed6b09fc --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt @@ -0,0 +1,65 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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.processor + +import com.fasterxml.jackson.databind.node.NullNode +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service + +/** + * InputResourceResolutionProcessor + * + * @author Kapil Singal + */ +@Service("rr-processor-source-input") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +open class InputResourceResolutionProcessor : ResourceAssignmentProcessor() { + + private val logger = LoggerFactory.getLogger(InputResourceResolutionProcessor::class.java) + + override fun getName(): String { + return "rr-processor-source-input" + } + + override fun process(resourceAssignment: ResourceAssignment) { + try { + if (checkNotEmpty(resourceAssignment.name)) { + val value = raRuntimeService.getInputValue(resourceAssignment.name) + // if value is null don't call setResourceDataValue to populate the value + if (value != null && value !is NullNode) { + logger.info("input source template key (${resourceAssignment.name}) found from input and value is ($value)") + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value) + } + } + // Check the value has populated for mandatory case + ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment) + } catch (e: Exception) { + ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message) + throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with : (${e.message})", e) + } + } + + override fun recover(runtimeException: RuntimeException, resourceAssignment: 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/resolution/processor/PrimaryDataResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/PrimaryDataResourceAssignmentProcessor.kt deleted file mode 100644 index 876c75fa..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/PrimaryDataResourceAssignmentProcessor.kt +++ /dev/null @@ -1,164 +0,0 @@ -/* - * 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.resolution.processor - -import com.fasterxml.jackson.databind.node.JsonNodeFactory -import com.fasterxml.jackson.databind.node.MissingNode -import com.fasterxml.jackson.databind.node.NullNode -import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.PrimaryDBLibGenericService -import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.DatabaseResourceSource -import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils -import org.onap.ccsdk.apps.controllerblueprints.core.* -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.ResourceDictionaryConstants -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Service -import java.util.* - -/** - * PrimaryDataResourceAssignmentProcessor - * - * @author Kapil Singal - */ -@Service("resource-assignment-processor-primary-db") -open class PrimaryDataResourceAssignmentProcessor(private val primaryDBLibGenericService: PrimaryDBLibGenericService) - : ResourceAssignmentProcessor() { - - private val logger = LoggerFactory.getLogger(PrimaryDataResourceAssignmentProcessor::class.java) - - override fun getName(): String { - return "resource-assignment-processor-primary-db" - } - - override fun process(resourceAssignment: ResourceAssignment) { - try { - validate(resourceAssignment) - - // Check if It has Input - val value = raRuntimeService.getInputValue(resourceAssignment.name) - if (value !is NullNode && value !is MissingNode) { - logger.info("primary-db source template key (${resourceAssignment.name}) found from input and value is ($value)") - ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value) - } else { - val dName = resourceAssignment.dictionaryName - val dSource = resourceAssignment.dictionarySource - val resourceDefinition = resourceDictionaries[dName] - ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dName") - val resourceSource = resourceDefinition.sources[dSource] - ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)") - val resourceSourceProperties = checkNotNull(resourceSource.properties) { "failed to get source properties for $dName " } - val sourceProperties = JacksonUtils.getInstanceFromMap(resourceSourceProperties, DatabaseResourceSource::class.java) - - val sql = checkNotNull(sourceProperties.query) { "failed to get request query for $dName under $dSource properties" } - val inputKeyMapping = checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" } - - logger.info("$dSource dictionary information : ($sql), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})") - - val rows = primaryDBLibGenericService.query(sql, populateNamedParameter(inputKeyMapping)) - if (rows.isNullOrEmpty()) { - logger.warn("Failed to get $dSource result for dictionary name ($dName) the query ($sql)") - } else { - populateResource(resourceAssignment, sourceProperties, rows) - } - } - - // Check the value has populated for mandatory case - ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment) - } catch (e: Exception) { - ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message) - throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}", e) - } - } - - @Throws(BluePrintProcessorException::class) - private fun validate(resourceAssignment: ResourceAssignment) { - checkNotEmptyOrThrow(resourceAssignment.name, "resource assignment template key is not defined") - checkNotEmptyOrThrow(resourceAssignment.dictionaryName, "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})") - checkEqualsOrThrow(ResourceDictionaryConstants.SOURCE_PRIMARY_DB, resourceAssignment.dictionarySource) { - "resource assignment source is not ${ResourceDictionaryConstants.SOURCE_PRIMARY_DB} but it is ${resourceAssignment.dictionarySource}" - } - } - - private fun populateNamedParameter(inputKeyMapping: Map): Map { - val namedParameters = HashMap() - inputKeyMapping.forEach { - val expressionValue = raRuntimeService.getDictionaryStore(it.value) - logger.trace("Reference dictionary key (${it.key}) resulted in value ($expressionValue)") - namedParameters[it.key] = expressionValue - } - logger.info("Parameter information : ({})", namedParameters) - return namedParameters - } - - @Throws(BluePrintProcessorException::class) - private fun populateResource(resourceAssignment: ResourceAssignment, sourceProperties: DatabaseResourceSource, rows: List>) { - val dName = resourceAssignment.dictionaryName - val dSource = resourceAssignment.dictionarySource - val type = nullToEmpty(resourceAssignment.property?.type) - - val outputKeyMapping = checkNotNull(sourceProperties.outputKeyMapping) { "failed to get output-key-mappings for $dName under $dSource properties" } - logger.info("Response processing type($type)") - - // Primitive Types - when(type) { - in BluePrintTypes.validPrimitiveTypes() -> { - val dbColumnValue = rows[0][outputKeyMapping[dName]] - logger.info("For template key (${resourceAssignment.name}) setting value as ($dbColumnValue)") - ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, dbColumnValue) - } - in BluePrintTypes.validCollectionTypes() -> { - val entrySchemaType = returnNotEmptyOrThrow(resourceAssignment.property?.entrySchema?.type) { "Entry schema is not defined for dictionary ($dName) info" } - var arrayNode = JsonNodeFactory.instance.arrayNode() - rows.forEach { - if (entrySchemaType in BluePrintTypes.validPrimitiveTypes()) { - val dbColumnValue = it[outputKeyMapping[dName]] - // Add Array JSON - JacksonUtils.populatePrimitiveValues(dbColumnValue!!, entrySchemaType, arrayNode) - } else { - val arrayChildNode = JsonNodeFactory.instance.objectNode() - for (mapping in outputKeyMapping.entries) { - val dbColumnValue = checkNotNull(it[mapping.key]) - val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, mapping.key) - JacksonUtils.populatePrimitiveValues(mapping.key, dbColumnValue, propertyTypeForDataType, arrayChildNode) - } - arrayNode.add(arrayChildNode) - } - } - logger.info("For template key (${resourceAssignment.name}) setting value as ($arrayNode)") - // Set the List of Complex Values - ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, arrayNode) - } - else -> { - // Complex Types - val row = rows[0] - var objectNode = JsonNodeFactory.instance.objectNode() - for (mapping in outputKeyMapping.entries) { - val dbColumnValue = checkNotNull(row[mapping.key]) - val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, type, mapping.key) - JacksonUtils.populatePrimitiveValues(mapping.key, dbColumnValue, propertyTypeForDataType, objectNode) - } - logger.info("For template key (${resourceAssignment.name}) setting value as ($objectNode)") - ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, objectNode) - } - } - } - - override fun recover(runtimeException: RuntimeException, resourceAssignment: 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/resolution/processor/PrimaryDataResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/PrimaryDataResourceResolutionProcessor.kt new file mode 100644 index 00000000..7da22b03 --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/PrimaryDataResourceResolutionProcessor.kt @@ -0,0 +1,167 @@ +/* + * 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.resolution.processor + +import com.fasterxml.jackson.databind.node.JsonNodeFactory +import com.fasterxml.jackson.databind.node.MissingNode +import com.fasterxml.jackson.databind.node.NullNode +import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.PrimaryDBLibGenericService +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.DatabaseResourceSource +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils +import org.onap.ccsdk.apps.controllerblueprints.core.* +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.ResourceDictionaryConstants +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service +import java.util.* + +/** + * PrimaryDataResourceResolutionProcessor + * + * @author Kapil Singal + */ +@Service("rr-processor-source-primary-db") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +open class PrimaryDataResourceResolutionProcessor(private val primaryDBLibGenericService: PrimaryDBLibGenericService) + : ResourceAssignmentProcessor() { + + private val logger = LoggerFactory.getLogger(PrimaryDataResourceResolutionProcessor::class.java) + + override fun getName(): String { + return "rr-processor-source-primary-db" + } + + override fun process(resourceAssignment: ResourceAssignment) { + try { + validate(resourceAssignment) + + // Check if It has Input + val value = raRuntimeService.getInputValue(resourceAssignment.name) + if (value !is NullNode && value !is MissingNode) { + logger.info("primary-db source template key (${resourceAssignment.name}) found from input and value is ($value)") + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value) + } else { + val dName = resourceAssignment.dictionaryName + val dSource = resourceAssignment.dictionarySource + val resourceDefinition = resourceDictionaries[dName] + ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dName") + val resourceSource = resourceDefinition.sources[dSource] + ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)") + val resourceSourceProperties = checkNotNull(resourceSource.properties) { "failed to get source properties for $dName " } + val sourceProperties = JacksonUtils.getInstanceFromMap(resourceSourceProperties, DatabaseResourceSource::class.java) + + val sql = checkNotNull(sourceProperties.query) { "failed to get request query for $dName under $dSource properties" } + val inputKeyMapping = checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" } + + logger.info("$dSource dictionary information : ($sql), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})") + + val rows = primaryDBLibGenericService.query(sql, populateNamedParameter(inputKeyMapping)) + if (rows.isNullOrEmpty()) { + logger.warn("Failed to get $dSource result for dictionary name ($dName) the query ($sql)") + } else { + populateResource(resourceAssignment, sourceProperties, rows) + } + } + + // Check the value has populated for mandatory case + ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment) + } catch (e: Exception) { + ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message) + throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}", e) + } + } + + @Throws(BluePrintProcessorException::class) + private fun validate(resourceAssignment: ResourceAssignment) { + checkNotEmptyOrThrow(resourceAssignment.name, "resource assignment template key is not defined") + checkNotEmptyOrThrow(resourceAssignment.dictionaryName, "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})") + checkEqualsOrThrow(ResourceDictionaryConstants.SOURCE_PRIMARY_DB, resourceAssignment.dictionarySource) { + "resource assignment source is not ${ResourceDictionaryConstants.SOURCE_PRIMARY_DB} but it is ${resourceAssignment.dictionarySource}" + } + } + + private fun populateNamedParameter(inputKeyMapping: Map): Map { + val namedParameters = HashMap() + inputKeyMapping.forEach { + val expressionValue = raRuntimeService.getDictionaryStore(it.value) + logger.trace("Reference dictionary key (${it.key}) resulted in value ($expressionValue)") + namedParameters[it.key] = expressionValue + } + logger.info("Parameter information : ({})", namedParameters) + return namedParameters + } + + @Throws(BluePrintProcessorException::class) + private fun populateResource(resourceAssignment: ResourceAssignment, sourceProperties: DatabaseResourceSource, rows: List>) { + val dName = resourceAssignment.dictionaryName + val dSource = resourceAssignment.dictionarySource + val type = nullToEmpty(resourceAssignment.property?.type) + + val outputKeyMapping = checkNotNull(sourceProperties.outputKeyMapping) { "failed to get output-key-mappings for $dName under $dSource properties" } + logger.info("Response processing type($type)") + + // Primitive Types + when(type) { + in BluePrintTypes.validPrimitiveTypes() -> { + val dbColumnValue = rows[0][outputKeyMapping[dName]] + logger.info("For template key (${resourceAssignment.name}) setting value as ($dbColumnValue)") + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, dbColumnValue) + } + in BluePrintTypes.validCollectionTypes() -> { + val entrySchemaType = returnNotEmptyOrThrow(resourceAssignment.property?.entrySchema?.type) { "Entry schema is not defined for dictionary ($dName) info" } + var arrayNode = JsonNodeFactory.instance.arrayNode() + rows.forEach { + if (entrySchemaType in BluePrintTypes.validPrimitiveTypes()) { + val dbColumnValue = it[outputKeyMapping[dName]] + // Add Array JSON + JacksonUtils.populatePrimitiveValues(dbColumnValue!!, entrySchemaType, arrayNode) + } else { + val arrayChildNode = JsonNodeFactory.instance.objectNode() + for (mapping in outputKeyMapping.entries) { + val dbColumnValue = checkNotNull(it[mapping.key]) + val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, mapping.key) + JacksonUtils.populatePrimitiveValues(mapping.key, dbColumnValue, propertyTypeForDataType, arrayChildNode) + } + arrayNode.add(arrayChildNode) + } + } + logger.info("For template key (${resourceAssignment.name}) setting value as ($arrayNode)") + // Set the List of Complex Values + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, arrayNode) + } + else -> { + // Complex Types + val row = rows[0] + var objectNode = JsonNodeFactory.instance.objectNode() + for (mapping in outputKeyMapping.entries) { + val dbColumnValue = checkNotNull(row[mapping.key]) + val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, type, mapping.key) + JacksonUtils.populatePrimitiveValues(mapping.key, dbColumnValue, propertyTypeForDataType, objectNode) + } + logger.info("For template key (${resourceAssignment.name}) setting value as ($objectNode)") + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, objectNode) + } + } + } + + override fun recover(runtimeException: RuntimeException, resourceAssignment: 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/resolution/processor/ResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt index b07155a3..9b7c70aa 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt @@ -57,9 +57,13 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode { + logger.info("For template key (${resourceAssignment.name}) setting value as ($responseNode)") + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, responseNode) + } + in BluePrintTypes.validCollectionTypes() -> { + // Array Types + entrySchemaType = returnNotEmptyOrThrow(resourceAssignment.property?.entrySchema?.type) { "Entry schema is not defined for dictionary ($dName) info" } + val arrayNode = responseNode as ArrayNode + + if (entrySchemaType !in BluePrintTypes.validPrimitiveTypes()) { + val responseArrayNode = responseNode.toList() + for (responseSingleJsonNode in responseArrayNode) { + val arrayChildNode = JsonNodeFactory.instance.objectNode() + outputKeyMapping.map { + val responseKeyValue = responseSingleJsonNode.get(it.key) + val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, it.key) + logger.info("For List Type Resource: key (${it.key}), value ($responseKeyValue), type ({$propertyTypeForDataType})") + JacksonUtils.populateJsonNodeValues(it.value, responseKeyValue, propertyTypeForDataType, arrayChildNode) + } + arrayNode.add(arrayChildNode) + } + } + logger.info("For template key (${resourceAssignment.name}) setting value as ($arrayNode)") + // Set the List of Complex Values + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, arrayNode) + } + else -> { + // Complex Types + val objectNode = responseNode as ObjectNode + outputKeyMapping.map { + val responseKeyValue = responseNode.get(it.key) + val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, it.key) + logger.info("For List Type Resource: key (${it.key}), value ($responseKeyValue), type ({$propertyTypeForDataType})") + JacksonUtils.populateJsonNodeValues(it.value, responseKeyValue, propertyTypeForDataType, objectNode) + } + + logger.info("For template key (${resourceAssignment.name}) setting value as ($objectNode)") + // Set the List of Complex Values + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, objectNode) + } + } + } + + @Throws(BluePrintProcessorException::class) + private fun validate(resourceAssignment: ResourceAssignment) { + checkNotEmptyOrThrow(resourceAssignment.name, "resource assignment template key is not defined") + checkNotEmptyOrThrow(resourceAssignment.dictionaryName, "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})") + checkEqualsOrThrow(ResourceDictionaryConstants.SOURCE_PRIMARY_CONFIG_DATA, resourceAssignment.dictionarySource) { + "resource assignment source is not ${ResourceDictionaryConstants.SOURCE_PRIMARY_CONFIG_DATA} but it is ${resourceAssignment.dictionarySource}" + } + checkNotEmptyOrThrow(resourceAssignment.dictionaryName, "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})") + } + + override fun recover(runtimeException: RuntimeException, resourceAssignment: 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/resolution/processor/SimpleRestResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/SimpleRestResourceAssignmentProcessor.kt deleted file mode 100644 index a264ba50..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/SimpleRestResourceAssignmentProcessor.kt +++ /dev/null @@ -1,162 +0,0 @@ -/* - * 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.resolution.processor - -import com.fasterxml.jackson.databind.node.ArrayNode -import com.fasterxml.jackson.databind.node.JsonNodeFactory -import com.fasterxml.jackson.databind.node.NullNode -import com.fasterxml.jackson.databind.node.ObjectNode -import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.RestResourceSource -import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils -import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService -import org.onap.ccsdk.apps.controllerblueprints.core.* -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.ResourceDictionaryConstants -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Service - -/** - * SimpleRestResourceAssignmentProcessor - * - * @author Kapil Singal - */ -@Service("resource-assignment-processor-primary-config-data") -open class SimpleRestResourceAssignmentProcessor(private val blueprintRestLibPropertyService: BluePrintRestLibPropertyService) - : ResourceAssignmentProcessor() { - - private val logger = LoggerFactory.getLogger(SimpleRestResourceAssignmentProcessor::class.java) - - override fun getName(): String { - return "resource-assignment-processor-primary-config-data" - } - - override fun process(resourceAssignment: ResourceAssignment) { - try { - validate(resourceAssignment) - - // Check if It has Input - val value = raRuntimeService.getInputValue(resourceAssignment.name) - if (value != null && value !is NullNode) { - logger.info("primary-db source template key (${resourceAssignment.name}) found from input and value is ($value)") - ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value) - } else { - val dName = resourceAssignment.dictionaryName - val dSource = resourceAssignment.dictionarySource - val resourceDefinition = resourceDictionaries[dName] - ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dName") - val resourceSource = resourceDefinition.sources[dSource] - ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)") - val resourceSourceProperties = checkNotNull(resourceSource.properties) { "failed to get source properties for $dName " } - val sourceProperties = JacksonUtils.getInstanceFromMap(resourceSourceProperties, RestResourceSource::class.java) - - val urlPath = checkNotNull(sourceProperties.urlPath) { "failed to get request urlPath for $dName under $dSource properties" } - val path = nullToEmpty(sourceProperties.path) - 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()) { - logger.warn("Failed to get $dSource result for dictionary name ($dName) using urlPath ($urlPath)") - } else { - populateResource(resourceAssignment, sourceProperties, response, path) - } - } - // Check the value has populated for mandatory case - ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment) - } catch (e: Exception) { - ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message) - throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}", e) - } - } - - @Throws(BluePrintProcessorException::class) - private fun populateResource(resourceAssignment: ResourceAssignment, sourceProperties: RestResourceSource, restResponse: String, path: String) { - val dName = resourceAssignment.dictionaryName - val dSource = resourceAssignment.dictionarySource - val type = nullToEmpty(resourceAssignment.property?.type) - lateinit var entrySchemaType: String - - val outputKeyMapping = checkNotNull(sourceProperties.outputKeyMapping) { "failed to get output-key-mappings for $dName under $dSource properties" } - logger.info("Response processing type($type)") - - val responseNode = checkNotNull(JacksonUtils.jsonNode(restResponse).at(path)) { "Failed to find path ($path) in response ($restResponse)" } - logger.info("populating value for output mapping ($outputKeyMapping), from json ($responseNode)") - - - when (type) { - in BluePrintTypes.validPrimitiveTypes() -> { - logger.info("For template key (${resourceAssignment.name}) setting value as ($responseNode)") - ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, responseNode) - } - in BluePrintTypes.validCollectionTypes() -> { - // Array Types - entrySchemaType = returnNotEmptyOrThrow(resourceAssignment.property?.entrySchema?.type) { "Entry schema is not defined for dictionary ($dName) info" } - val arrayNode = responseNode as ArrayNode - - if (entrySchemaType !in BluePrintTypes.validPrimitiveTypes()) { - val responseArrayNode = responseNode.toList() - for (responseSingleJsonNode in responseArrayNode) { - val arrayChildNode = JsonNodeFactory.instance.objectNode() - outputKeyMapping.map { - val responseKeyValue = responseSingleJsonNode.get(it.key) - val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, it.key) - logger.info("For List Type Resource: key (${it.key}), value ($responseKeyValue), type ({$propertyTypeForDataType})") - JacksonUtils.populateJsonNodeValues(it.value, responseKeyValue, propertyTypeForDataType, arrayChildNode) - } - arrayNode.add(arrayChildNode) - } - } - logger.info("For template key (${resourceAssignment.name}) setting value as ($arrayNode)") - // Set the List of Complex Values - ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, arrayNode) - } - else -> { - // Complex Types - val objectNode = responseNode as ObjectNode - outputKeyMapping.map { - val responseKeyValue = responseNode.get(it.key) - val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, it.key) - logger.info("For List Type Resource: key (${it.key}), value ($responseKeyValue), type ({$propertyTypeForDataType})") - JacksonUtils.populateJsonNodeValues(it.value, responseKeyValue, propertyTypeForDataType, objectNode) - } - - logger.info("For template key (${resourceAssignment.name}) setting value as ($objectNode)") - // Set the List of Complex Values - ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, objectNode) - } - } - } - - @Throws(BluePrintProcessorException::class) - private fun validate(resourceAssignment: ResourceAssignment) { - checkNotEmptyOrThrow(resourceAssignment.name, "resource assignment template key is not defined") - checkNotEmptyOrThrow(resourceAssignment.dictionaryName, "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})") - checkEqualsOrThrow(ResourceDictionaryConstants.SOURCE_PRIMARY_CONFIG_DATA, resourceAssignment.dictionarySource) { - "resource assignment source is not ${ResourceDictionaryConstants.SOURCE_PRIMARY_CONFIG_DATA} but it is ${resourceAssignment.dictionarySource}" - } - checkNotEmptyOrThrow(resourceAssignment.dictionaryName, "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})") - } - - override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { - } - - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt index fbecb55c..c3b10184 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt @@ -42,9 +42,9 @@ import org.springframework.test.context.junit4.SpringRunner @RunWith(SpringRunner::class) @ContextConfiguration(classes = [ResourceResolutionServiceImpl::class, - InputResourceAssignmentProcessor::class, DefaultResourceAssignmentProcessor::class, - PrimaryDataResourceAssignmentProcessor::class, SimpleRestResourceAssignmentProcessor::class, - CapabilityResourceAssignmentProcessor::class, PrimaryDBLibGenericService::class, + InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class, + PrimaryDataResourceResolutionProcessor::class, RestResourceResolutionProcessor::class, + CapabilityResourceResolutionProcessor::class, PrimaryDBLibGenericService::class, BlueprintPropertyConfiguration::class, BluePrintProperties::class, BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class]) @TestPropertySource(locations = ["classpath:application-test.properties"]) diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt index d0d3a13f..6d2d3f2d 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt @@ -47,9 +47,9 @@ import kotlin.test.assertTrue */ @RunWith(SpringRunner::class) @ContextConfiguration(classes = [ResourceResolutionServiceImpl::class, - InputResourceAssignmentProcessor::class, DefaultResourceAssignmentProcessor::class, - PrimaryDataResourceAssignmentProcessor::class, SimpleRestResourceAssignmentProcessor::class, - CapabilityResourceAssignmentProcessor::class, PrimaryDBLibGenericService::class, + InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class, + PrimaryDataResourceResolutionProcessor::class, RestResourceResolutionProcessor::class, + CapabilityResourceResolutionProcessor::class, PrimaryDBLibGenericService::class, BlueprintPropertyConfiguration::class, BluePrintProperties::class, BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class]) @TestPropertySource(locations = ["classpath:application-test.properties"]) @@ -66,7 +66,8 @@ class ResourceResolutionServiceTest { fun testRegisteredSource() { val sources = resourceResolutionService.registeredResourceSources() assertNotNull(sources, "failed to get registered sources") - assertTrue(sources.containsAll(arrayListOf("input", "default", "primary-db", "primary-config-data")), "failed to get registered sources") + assertTrue(sources.containsAll(arrayListOf("source-input", "source-default", "source-primary-db", + "source-rest")), "failed to get registered sources") } @Test diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessorTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessorTest.kt deleted file mode 100644 index 0dbd0f6e..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessorTest.kt +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Modifications Copyright © 2019 IBM, Bell Canada. - * - * 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.processor - -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.BlueprintJythonService -import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.PythonExecutorProperty -import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService -import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils -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 -import org.onap.ccsdk.apps.controllerblueprints.scripts.BluePrintScriptsServiceImpl -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner -import kotlin.test.assertNotNull - -@RunWith(SpringRunner::class) -@ContextConfiguration(classes = [CapabilityResourceAssignmentProcessor::class, BluePrintScriptsServiceImpl::class, - BlueprintJythonService::class, PythonExecutorProperty::class, MockCapabilityService::class]) -@TestPropertySource(properties = -["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints", - "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints"]) -class CapabilityResourceAssignmentProcessorTest { - - @Autowired - lateinit var capabilityResourceAssignmentProcessor: CapabilityResourceAssignmentProcessor - - @Test - fun `test kotlin capability`() { - - val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext( - "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") - - val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext) - - capabilityResourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService - capabilityResourceAssignmentProcessor.resourceDictionaries = hashMapOf() - - - val scriptPropertyInstances: MutableMap = mutableMapOf() - scriptPropertyInstances["mock-service1"] = MockCapabilityService() - scriptPropertyInstances["mock-service2"] = MockCapabilityService() - - val resourceAssignmentProcessor = capabilityResourceAssignmentProcessor - .getKotlinResourceAssignmentProcessorInstance( - "ResourceAssignmentProcessor_cba\$ScriptResourceAssignmentProcessor", scriptPropertyInstances) - - assertNotNull(resourceAssignmentProcessor, "couldn't get kotlin script resource assignment processor") - - val resourceAssignment = ResourceAssignment().apply { - name = "ra-name" - dictionaryName = "ra-dict-name" - dictionarySource = "capability" - property = PropertyDefinition().apply { - type = "string" - } - } - - val processorName = resourceAssignmentProcessor.apply(resourceAssignment) - assertNotNull(processorName, "couldn't get kotlin script resource assignment processor name") - println(processorName) - } - - @Test - fun `test jython capability`() { - - val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext( - "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_python") - - val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext) - - capabilityResourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService - - val resourceDefinition = JacksonUtils - .readValueFromClassPathFile("mapping/capability/jython-resource-definitions.json", - ResourceDefinition::class.java)!! - val resourceDefinitions: MutableMap = mutableMapOf() - resourceDefinitions[resourceDefinition.name] = resourceDefinition - capabilityResourceAssignmentProcessor.resourceDictionaries = resourceDefinitions - - val resourceAssignment = ResourceAssignment().apply { - name = "service-instance-id" - dictionaryName = "service-instance-id" - dictionarySource = "capability" - property = PropertyDefinition().apply { - type = "string" - } - } - - val processorName = capabilityResourceAssignmentProcessor.apply(resourceAssignment) - assertNotNull(processorName, "couldn't get Jython script resource assignment processor name") - - } - -} - -open class MockCapabilityService { - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt new file mode 100644 index 00000000..f779054e --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt @@ -0,0 +1,120 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Modifications Copyright © 2019 IBM, Bell Canada. + * + * 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.processor + +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService +import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.BlueprintJythonService +import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.PythonExecutorProperty +import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils +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 +import org.onap.ccsdk.apps.controllerblueprints.scripts.BluePrintScriptsServiceImpl +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.assertNotNull + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [CapabilityResourceResolutionProcessor::class, BluePrintScriptsServiceImpl::class, + BlueprintJythonService::class, PythonExecutorProperty::class, MockCapabilityService::class]) +@TestPropertySource(properties = +["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints", + "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints"]) +class CapabilityResourceResolutionProcessorTest { + + @Autowired + lateinit var capabilityResourceResolutionProcessor: CapabilityResourceResolutionProcessor + + @Test + fun `test kotlin capability`() { + + val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext( + "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + + val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext) + + capabilityResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService + capabilityResourceResolutionProcessor.resourceDictionaries = hashMapOf() + + + val scriptPropertyInstances: MutableMap = mutableMapOf() + scriptPropertyInstances["mock-service1"] = MockCapabilityService() + scriptPropertyInstances["mock-service2"] = MockCapabilityService() + + val resourceAssignmentProcessor = capabilityResourceResolutionProcessor + .getKotlinResourceAssignmentProcessorInstance( + "ResourceAssignmentProcessor_cba\$ScriptResourceAssignmentProcessor", scriptPropertyInstances) + + assertNotNull(resourceAssignmentProcessor, "couldn't get kotlin script resource assignment processor") + + val resourceAssignment = ResourceAssignment().apply { + name = "ra-name" + dictionaryName = "ra-dict-name" + dictionarySource = "capability" + property = PropertyDefinition().apply { + type = "string" + } + } + + val processorName = resourceAssignmentProcessor.apply(resourceAssignment) + assertNotNull(processorName, "couldn't get kotlin script resource assignment processor name") + println(processorName) + } + + @Test + fun `test jython capability`() { + + val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext( + "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_python") + + val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext) + + capabilityResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService + + val resourceDefinition = JacksonUtils + .readValueFromClassPathFile("mapping/capability/jython-resource-definitions.json", + ResourceDefinition::class.java)!! + val resourceDefinitions: MutableMap = mutableMapOf() + resourceDefinitions[resourceDefinition.name] = resourceDefinition + capabilityResourceResolutionProcessor.resourceDictionaries = resourceDefinitions + + val resourceAssignment = ResourceAssignment().apply { + name = "service-instance-id" + dictionaryName = "service-instance-id" + dictionarySource = "capability" + property = PropertyDefinition().apply { + type = "string" + } + } + + val processorName = capabilityResourceResolutionProcessor.apply(resourceAssignment) + assertNotNull(processorName, "couldn't get Jython script resource assignment processor name") + + } + +} + +open class MockCapabilityService { + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json index d3780e0a..fe89291c 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json @@ -10,8 +10,8 @@ "capability": { "type": "source-capability", "properties": { - "type": "JYTHON-COMPONENT", - "instance-name": "SampleRAProcessor", + "script-type": "jython", + "script-class-reference": "SampleRAProcessor", "instance-dependencies": [] } } diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt index 47577b39..705caa2e 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt @@ -17,15 +17,16 @@ package org.onap.ccsdk.apps.blueprintsprocessor.rest.service +import com.fasterxml.jackson.databind.JsonNode import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties import org.onap.ccsdk.apps.blueprintsprocessor.rest.* import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.springframework.stereotype.Service @Service(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY) open class BluePrintRestLibPropertyService(private var bluePrintProperties: BluePrintProperties) { - @Throws(BluePrintProcessorException::class) fun restClientProperties(prefix: String): RestClientProperties { val type = bluePrintProperties.propertyBeanType("$prefix.type", String::class.java) return when (type) { @@ -47,19 +48,39 @@ open class BluePrintRestLibPropertyService(private var bluePrintProperties: Blue } } - @Throws(BluePrintProcessorException::class) + fun restClientProperties(jsonNode: JsonNode): RestClientProperties { + val type = jsonNode.get("type").textValue() + return when (type) { + RestLibConstants.TYPE_BASIC_AUTH -> { + JacksonUtils.readValue(jsonNode, BasicAuthRestClientProperties::class.java)!! + } + RestLibConstants.TYPE_SSL_BASIC_AUTH -> { + JacksonUtils.readValue(jsonNode, SSLBasicAuthRestClientProperties::class.java)!! + } + RestLibConstants.TYPE_DME2_PROXY -> { + JacksonUtils.readValue(jsonNode, DME2RestClientProperties::class.java)!! + } + RestLibConstants.TYPE_POLICY_MANAGER -> { + JacksonUtils.readValue(jsonNode, PolicyManagerRestClientProperties::class.java)!! + } + else -> { + throw BluePrintProcessorException("Rest adaptor($type) is not supported") + } + } + } + + fun blueprintWebClientService(selector: String): BlueprintWebClientService { val prefix = "blueprintsprocessor.restclient.$selector" val restClientProperties = restClientProperties(prefix) return blueprintWebClientService(restClientProperties) } - - fun blueprintDynamicWebClientService(sourceType: String, selector: String): BlueprintWebClientService { - TODO() + fun blueprintWebClientService(jsonNode: JsonNode): BlueprintWebClientService { + val restClientProperties = restClientProperties(jsonNode) + return blueprintWebClientService(restClientProperties) } - @Throws(BluePrintProcessorException::class) fun blueprintWebClientService(restClientProperties: RestClientProperties): BlueprintWebClientService { when (restClientProperties) { is BasicAuthRestClientProperties -> { -- cgit 1.2.3-korg