From 72d22a4339db09824d46746dacbba1e141763dc0 Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Tue, 26 Mar 2019 09:49:13 -0400 Subject: Migrate ccdsk/apps to ccsdk/cds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I020a2ccec4e691717f888e8bd2afec91a7c4e987 Issue-ID: CCSDK-1178 Signed-off-by: Alexis de Talhouët --- ...sourceAssignmentProcessorScriptConfiguration.kt | 42 ---- .../resolution/ResourceAssignmentRuntimeService.kt | 88 -------- .../resolution/ResourceResolutionComponent.kt | 62 ------ .../resolution/ResourceResolutionConfiguration.kt | 26 --- .../resolution/ResourceResolutionConstants.kt | 31 --- .../resolution/ResourceResolutionService.kt | 228 --------------------- .../resolution/ResourceSourceProperties.kt | 79 ------- .../resolution/db/ResourceResolutionRepository.kt | 25 --- .../resolution/db/ResourceResolutionResult.kt | 69 ------- .../db/ResourceResolutionResultService.kt | 64 ------ .../CapabilityResourceResolutionProcessor.kt | 104 ---------- .../DatabaseResourceAssignmentProcessor.kt | 190 ----------------- .../DefaultResourceResolutionProcessor.kt | 65 ------ .../processor/InputResourceResolutionProcessor.kt | 68 ------ .../processor/ResourceAssignmentProcessor.kt | 115 ----------- .../processor/RestResourceResolutionProcessor.kt | 204 ------------------ .../resolution/utils/ResourceAssignmentUtils.kt | 159 -------------- 17 files changed, 1619 deletions(-) delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentProcessorScriptConfiguration.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentRuntimeService.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConfiguration.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt delete mode 100755 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResult.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResultService.kt delete 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/DatabaseResourceAssignmentProcessor.kt delete 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/InputResourceResolutionProcessor.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt delete 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/utils/ResourceAssignmentUtils.kt (limited to 'ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin') diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentProcessorScriptConfiguration.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentProcessorScriptConfiguration.kt deleted file mode 100644 index ffe09e4d..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentProcessorScriptConfiguration.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution - -import org.jetbrains.kotlin.script.util.DependsOn -import org.jetbrains.kotlin.script.util.Repository -import kotlin.script.experimental.annotations.KotlinScript -import kotlin.script.experimental.api.ScriptCompilationConfiguration -import kotlin.script.experimental.api.defaultImports -import kotlin.script.experimental.jvm.dependenciesFromCurrentContext -import kotlin.script.experimental.jvm.jvm - -@KotlinScript(fileExtension = "resourceassignmentprocessor.kts", - compilationConfiguration = ResourceAssignmentProcessorScriptConfiguration::class) -abstract class ResourceAssignmentProcessorScript { - -} - -object ResourceAssignmentProcessorScriptConfiguration : ScriptCompilationConfiguration( - { - defaultImports(DependsOn::class, Repository::class) - jvm { - dependenciesFromCurrentContext( - wholeClasspath = true - ) - } - } -) \ 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/ResourceAssignmentRuntimeService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentRuntimeService.kt deleted file mode 100644 index c4ae1397..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentRuntimeService.kt +++ /dev/null @@ -1,88 +0,0 @@ -package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution - -import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService - -class ResourceAssignmentRuntimeService(private var id: String, private var bluePrintContext: BluePrintContext) - : DefaultBluePrintRuntimeService(id, bluePrintContext) { - - private lateinit var resolutionId: String - private var resourceStore: MutableMap = hashMapOf() - - fun createUniqueId(key: String) { - resolutionId = "$id-$key" - } - - fun cleanResourceStore() { - resourceStore.clear() - } - - fun putResolutionStore(key: String, value: JsonNode) { - resourceStore[key] = value - } - - fun getResolutionStore(key: String): JsonNode { - return resourceStore[key] - ?: throw BluePrintProcessorException("failed to get execution property ($key)") - } - - fun checkResolutionStore(key: String): Boolean { - return resourceStore.containsKey(key) - } - - fun getJsonNodeFromResolutionStore(key: String): JsonNode { - return getResolutionStore(key) - } - - fun getStringFromResolutionStore(key: String): String? { - return getResolutionStore(key).asText() - } - - fun getBooleanFromResolutionStore(key: String): Boolean? { - return getResolutionStore(key).asBoolean() - } - - fun getIntFromResolutionStore(key: String): Int? { - return getResolutionStore(key).asInt() - } - - fun getDoubleFromResolutionStore(key: String): Double? { - return getResolutionStore(key).asDouble() - } - - fun putDictionaryStore(key: String, value: JsonNode) { - resourceStore["dictionary-$key"] = value - } - - fun getDictionaryStore(key: String): JsonNode { - return resourceStore["dictionary-$key"] - ?: throw BluePrintProcessorException("failed to get execution property (dictionary-$key)") - } - - fun checkDictionaryStore(key: String): Boolean { - return resourceStore.containsKey("dictionary-$key") - } - - fun getJsonNodeFromDictionaryStore(key: String): JsonNode { - return getResolutionStore("dictionary-$key") - } - - fun getStringFromDictionaryStore(key: String): String? { - return getResolutionStore("dictionary-$key").asText() - } - - fun getBooleanFromDictionaryStore(key: String): Boolean? { - return getResolutionStore("dictionary-$key").asBoolean() - } - - fun getIntFromDictionaryStore(key: String): Int? { - return getResolutionStore("dictionary-$key").asInt() - } - - fun getDoubleFromDictionaryStore(key: String): Double? { - return getResolutionStore("dictionary-$key").asDouble() - } - -} diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt deleted file mode 100644 index 98d8c65d..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution - -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.springframework.beans.factory.config.ConfigurableBeanFactory -import org.springframework.context.annotation.Scope -import org.springframework.stereotype.Component - -@Component("component-resource-resolution") -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class ResourceResolutionComponent(private val resourceResolutionService: ResourceResolutionService) : - AbstractComponentFunction() { - - override fun process(executionRequest: ExecutionServiceInput) { - - val properties: MutableMap = mutableMapOf() - - try { - val key = getOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY) - val storeResult = getOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT) - properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY] = key.asText() - properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = storeResult.asBoolean() - } catch (e: BluePrintProcessorException) { - // NoOp - these property aren't mandatory, so don't fail the process if not provided. - } - - val artifactPrefixNamesNode = getOperationInput(ResourceResolutionConstants.INPUT_ARTIFACT_PREFIX_NAMES) - val artifactPrefixNames = JacksonUtils.getListFromJsonNode(artifactPrefixNamesNode, String::class.java) - - val resolvedParamContents = resourceResolutionService.resolveResources(bluePrintRuntimeService, - nodeTemplateName, - artifactPrefixNames, - properties) - - // Set Output Attributes - bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName, - ResourceResolutionConstants.OUTPUT_ASSIGNMENT_PARAMS, resolvedParamContents.asJsonNode()) - } - - override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { - bluePrintRuntimeService.getBluePrintError().addError(runtimeException.message!!) - } -} \ 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/ResourceResolutionConfiguration.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConfiguration.kt deleted file mode 100644 index 4c24ac69..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConfiguration.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution - -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration - -@Configuration -@ComponentScan -open class ResourceResolutionConfiguration - - diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt deleted file mode 100644 index b57b88b7..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 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 - -object ResourceResolutionConstants { - - const val SERVICE_RESOURCE_RESOLUTION = "resource-resolution-service" - 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" - const val RESOURCE_RESOLUTION_INPUT_KEY = "resolution-key"; - const val RESOURCE_RESOLUTION_INPUT_STORE_RESULT = "store-result"; - - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt deleted file mode 100644 index 620696f8..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt +++ /dev/null @@ -1,228 +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 - -import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.db.ResourceResolutionResultService -import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor -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 -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.BulkResourceSequencingUtils -import org.slf4j.LoggerFactory -import org.springframework.context.ApplicationContext -import org.springframework.stereotype.Service -import java.io.File - -interface ResourceResolutionService { - - fun registeredResourceSources(): List - - fun resolveFromDatabase(bluePrintRuntimeService: BluePrintRuntimeService<*>, artifactTemplate: String, - resolutionKey: String): String - - fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - artifactNames: List, properties: Map): MutableMap - - fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - artifactPrefix: String, properties: Map): String - - fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - artifactMapping: String, artifactTemplate: String?): String - - fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>, - resourceDictionaries: MutableMap, - resourceAssignments: MutableList, - identifierName: String) -} - -@Service(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION) -open class ResourceResolutionServiceImpl(private var applicationContext: ApplicationContext, - private var resolutionResultService: ResourceResolutionResultService) : - ResourceResolutionService { - - private val log = LoggerFactory.getLogger(ResourceResolutionService::class.java) - - override fun registeredResourceSources(): List { - return applicationContext.getBeanNamesForType(ResourceAssignmentProcessor::class.java) - .filter { it.startsWith(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) } - .map { it.substringAfter(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) } - } - - override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - artifactNames: List, - properties: Map): MutableMap { - - val resolvedParams: MutableMap = hashMapOf() - artifactNames.forEach { artifactName -> - val resolvedContent = resolveResources(bluePrintRuntimeService, nodeTemplateName, artifactName, properties) - resolvedParams[artifactName] = resolvedContent - } - return resolvedParams - } - - override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - artifactPrefix: String, properties: Map): String { - - // Velocity Artifact Definition Name - val artifactTemplate = "$artifactPrefix-template" - // Resource Assignment Artifact Definition Name - val artifactMapping = "$artifactPrefix-mapping" - - val result = resolveResources(bluePrintRuntimeService, nodeTemplateName, artifactMapping, artifactTemplate) - - if (properties.containsKey(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT) - && properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] as Boolean) { - resolutionResultService.write(properties, result, bluePrintRuntimeService, artifactPrefix) - } - - return result - } - - override fun resolveFromDatabase(bluePrintRuntimeService: BluePrintRuntimeService<*>, artifactTemplate: String, - resolutionKey: String): String { - return resolutionResultService.read(bluePrintRuntimeService, artifactTemplate, resolutionKey) - } - - override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - artifactMapping: String, artifactTemplate: String?): String { - - var resolvedContent = "" - log.info("Resolving resource for template artifact($artifactTemplate) with resource assignment artifact($artifactMapping)") - - val identifierName = artifactTemplate ?: "no-template" - - val resourceAssignmentContent = - bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactMapping) - - val resourceAssignments: MutableList = - JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment::class.java) - as? MutableList - ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions") - - // Get the Resource Dictionary Name - val dictionaryFile = bluePrintRuntimeService.bluePrintContext().rootPath.plus(File.separator) - .plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR).plus(File.separator) - .plus(ResourceResolutionConstants.FILE_NAME_RESOURCE_DEFINITION_TYPES) - - val resourceDictionaries: MutableMap = - JacksonUtils.getMapFromFile(dictionaryFile, ResourceDefinition::class.java) - ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions") - - // Resolve resources - resolveResourceAssignments(bluePrintRuntimeService, resourceDictionaries, resourceAssignments, identifierName) - - val resolvedParamJsonContent = - ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList()) - - // Check Template is there - if (artifactTemplate != null) { - val templateContent = - bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactTemplate) - resolvedContent = BluePrintTemplateService.generateContent(templateContent, resolvedParamJsonContent) - } else { - resolvedContent = resolvedParamJsonContent - } - - 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, - identifierName: String) { - - val bulkSequenced = BulkResourceSequencingUtils.process(resourceAssignments) - val resourceAssignmentRuntimeService = - ResourceAssignmentUtils.transformToRARuntimeService(blueprintRuntimeService, identifierName) - - bulkSequenced.map { batchResourceAssignments -> - batchResourceAssignments.filter { it.name != "*" && it.name != "start" } - .forEach { resourceAssignment -> - val dictionaryName = resourceAssignment.dictionaryName - val dictionarySource = resourceAssignment.dictionarySource - /** - * 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 - resourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService - // Set Resource Dictionaries - resourceAssignmentProcessor.resourceDictionaries = resourceDictionaries - // Invoke Apply Method - resourceAssignmentProcessor.apply(resourceAssignment) - - // Set errors from RA - blueprintRuntimeService.setBluePrintError(resourceAssignmentRuntimeService.getBluePrintError()) - } catch (e: RuntimeException) { - throw BluePrintProcessorException(e) - } - } - } - } - - - /** - * 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 deleted file mode 100644 index 25fc8c01..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt +++ /dev/null @@ -1,79 +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. - */ -@file:Suppress("unused") - -package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution - -import com.fasterxml.jackson.annotation.JsonProperty - -open class ResourceSourceProperties - -open class InputResourceSource : ResourceSourceProperties() { - lateinit var key: String - @get:JsonProperty("key-dependencies") - lateinit var keyDependencies: MutableList -} - -open class DefaultResourceSource : ResourceSourceProperties() { - lateinit var key: String - @get:JsonProperty("key-dependencies") - lateinit var keyDependencies: MutableList -} - -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 - @get:JsonProperty("output-key-mapping") - var outputKeyMapping: MutableMap? = null - @get:JsonProperty("key-dependencies") - lateinit var keyDependencies: MutableList -} - -open class RestResourceSource : ResourceSourceProperties() { - lateinit var verb: String - @get:JsonProperty("payload") - var payload: String? = null - lateinit var type: String - @get:JsonProperty("endpoint-selector") - var endpointSelector: String? = null - @get:JsonProperty("url-path") - lateinit var urlPath: String - lateinit var path: String - @get:JsonProperty("expression-type") - lateinit var expressionType: String - @get:JsonProperty("input-key-mapping") - var inputKeyMapping: MutableMap? = null - @get:JsonProperty("output-key-mapping") - var outputKeyMapping: MutableMap? = null - @get:JsonProperty("key-dependencies") - lateinit var keyDependencies: MutableList -} - -open class CapabilityResourceSource : ResourceSourceProperties() { - @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") - lateinit var keyDependencies: MutableList -} \ 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/db/ResourceResolutionRepository.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt deleted file mode 100644 index e50c578d..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2019 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.db - -import org.springframework.data.jpa.repository.JpaRepository - -interface ResourceResolutionRepository : JpaRepository { - - fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(key: String, blueprintName: String?, - blueprintVersion: String?, - artifactName: String): ResourceResolutionResult -} diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResult.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResult.kt deleted file mode 100755 index 814fba5e..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResult.kt +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright © 2019 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.db - -import com.fasterxml.jackson.annotation.JsonFormat -import org.hibernate.annotations.Proxy -import org.springframework.data.annotation.LastModifiedDate -import org.springframework.data.jpa.domain.support.AuditingEntityListener -import java.io.Serializable -import java.util.* -import javax.persistence.Column -import javax.persistence.Entity -import javax.persistence.EntityListeners -import javax.persistence.Id -import javax.persistence.Lob -import javax.persistence.Table -import javax.persistence.Temporal -import javax.persistence.TemporalType - -@EntityListeners(AuditingEntityListener::class) -@Entity -@Table(name = "RESOURCE_RESOLUTION_RESULT") -@Proxy(lazy = false) -class ResourceResolutionResult : Serializable { - - @Id - @Column(name = "resource_resolution_result_id") - var id: String? = null - - @Column(name = "resolution_key", nullable = false) - var resolutionKey: String? = null - - @Column(name = "blueprint_name", nullable = false) - var blueprintName: String? = null - - @Column(name = "blueprint_version", nullable = false) - var blueprintVersion: String? = null - - @Column(name = "artifact_name", nullable = false) - var artifactName: String? = null - - @Lob - @Column(name = "result", nullable = false) - var result: String? = null - - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - @LastModifiedDate - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "creation_date") - var createdDate = Date() - - companion object { - private const val serialVersionUID = 1L - } -} \ 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/db/ResourceResolutionResultService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResultService.kt deleted file mode 100644 index 448782a8..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResultService.kt +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2019 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.db - -import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.springframework.dao.DataIntegrityViolationException -import org.springframework.stereotype.Service -import java.util.* - -@Service -class ResourceResolutionResultService(private val resourceResolutionRepository: ResourceResolutionRepository) { - - fun write(properties: Map, result: String, bluePrintRuntimeService: BluePrintRuntimeService<*>, - artifactPrefix: String) { - - val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! - - val resourceResolutionResult = ResourceResolutionResult() - resourceResolutionResult.id = UUID.randomUUID().toString() - resourceResolutionResult.artifactName = artifactPrefix - resourceResolutionResult.blueprintVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION] - resourceResolutionResult.blueprintName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME] - resourceResolutionResult.resolutionKey = - properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY].toString() - resourceResolutionResult.result = result - - try { - resourceResolutionRepository.saveAndFlush(resourceResolutionResult) - } catch (ex: DataIntegrityViolationException) { - throw BluePrintException("Failed to store resource resolution result.", ex) - } - } - - fun read(bluePrintRuntimeService: BluePrintRuntimeService<*>, artifactPrefix: String, - resolutionKey: String): String { - - val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! - - val blueprintVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION] - val blueprintName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME] - - return resourceResolutionRepository.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName( - resolutionKey, - blueprintName, - blueprintVersion, - artifactPrefix).result!! - } -} \ 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 deleted file mode 100644 index 6469e78d..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt +++ /dev/null @@ -1,104 +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.functions.resource.resolution.CapabilityResourceSource -import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR -import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.ComponentFunctionScriptingService -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -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 - -@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-capability") -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class CapabilityResourceResolutionProcessor(private val applicationContext: ApplicationContext, - private var componentFunctionScriptingService: ComponentFunctionScriptingService) - : ResourceAssignmentProcessor() { - - private val log = LoggerFactory.getLogger(CapabilityResourceResolutionProcessor::class.java) - - var componentResourceAssignmentProcessor: ResourceAssignmentProcessor? = null - - override fun getName(): String { - return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-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 - val instanceDependencies = capabilityResourceSourceProperty.instanceDependencies ?: listOf() - - componentResourceAssignmentProcessor = scriptInstance(scriptType, scriptClassReference, 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) { - log.info("Recovering for : ${resourceAssignment.name} : ${runtimeException.toString()}") - if (componentResourceAssignmentProcessor != null) { - componentResourceAssignmentProcessor!!.recover(runtimeException, resourceAssignment) - } - } - - fun scriptInstance(scriptType: String, scriptClassReference: String, instanceDependencies: List) - : ResourceAssignmentProcessor { - - log.info("creating resource resolution of script type($scriptType), reference name($scriptClassReference) and" + - "instanceDependencies($instanceDependencies)") - - val scriptComponent = componentFunctionScriptingService - .scriptInstance(raRuntimeService.bluePrintContext(), scriptType, - scriptClassReference) - - instanceDependencies.forEach { instanceDependency -> - scriptPropertyInstances[instanceDependency] = applicationContext - .getBean(instanceDependency) - } - return scriptComponent - } -} \ 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/DatabaseResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt deleted file mode 100644 index a192989e..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt +++ /dev/null @@ -1,190 +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.BluePrintDBLibGenericService -import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.BluePrintDBLibPropertySevice -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.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR -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.* - -/** - * DatabaseResourceAssignmentProcessor - * - * @author Kapil Singal - */ -@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-processor-db") -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class DatabaseResourceAssignmentProcessor(private val bluePrintDBLibPropertySevice: BluePrintDBLibPropertySevice, private val primaryDBLibGenericService: PrimaryDBLibGenericService) - : ResourceAssignmentProcessor() { - - private val logger = LoggerFactory.getLogger(DatabaseResourceAssignmentProcessor::class.java) - - override fun getName(): String { - return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-processor-db" - } - - override fun process(resourceAssignment: ResourceAssignment) { - try { - validate(resourceAssignment) - - // Check if It has Input - try { - val value = raRuntimeService.getInputValue(resourceAssignment.name) - if (value !is NullNode && value !is MissingNode) { - logger.info("processor-db source template key (${resourceAssignment.name}) found from input and value is ($value)") - ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value) - } else { - setValueFromDB(resourceAssignment) - } - } catch (e: BluePrintProcessorException) { - setValueFromDB(resourceAssignment) - } - - // 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) - } - } - - private fun setValueFromDB(resourceAssignment: ResourceAssignment) { - 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 jdbcTemplate = blueprintDBLibService(sourceProperties) - - val rows = jdbcTemplate.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) - } - } - - private fun blueprintDBLibService(sourceProperties: DatabaseResourceSource): BluePrintDBLibGenericService { - return if (checkNotEmpty(sourceProperties.endpointSelector)) { - val dbPropertiesJson = raRuntimeService.resolveDSLExpression(sourceProperties.endpointSelector!!) - bluePrintDBLibPropertySevice.JdbcTemplate(dbPropertiesJson) - } else { - primaryDBLibGenericService - } - - } - - @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_PROCESSOR_DB, resourceAssignment.dictionarySource) { - "resource assignment source is not ${ResourceDictionaryConstants.SOURCE_PROCESSOR_DB} but it is ${resourceAssignment.dictionarySource}" - } - } - - private fun populateNamedParameter(inputKeyMapping: Map): Map { - val namedParameters = HashMap() - inputKeyMapping.forEach { - val expressionValue = raRuntimeService.getDictionaryStore(it.value).textValue() - 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" } - val 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] - val 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) { - raRuntimeService.getBluePrintError().addError(runtimeException.message!!) - } -} \ 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 deleted file mode 100644 index 0f51e4bf..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt +++ /dev/null @@ -1,65 +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.MissingNode -import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR -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("${PREFIX_RESOURCE_RESOLUTION_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 "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-default" - } - - override fun process(resourceAssignment: ResourceAssignment) { - try { - var value = getFromInput(resourceAssignment) - if (value == null || value is MissingNode) { - value = resourceAssignment.property?.defaultValue - 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) { - raRuntimeService.getBluePrintError().addError(runtimeException.message!!) - } -} \ 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 deleted file mode 100644 index 579989a6..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt +++ /dev/null @@ -1,68 +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.MissingNode -import com.fasterxml.jackson.databind.node.NullNode -import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR -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("${PREFIX_RESOURCE_RESOLUTION_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 "${PREFIX_RESOURCE_RESOLUTION_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 !is MissingNode && 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) { - raRuntimeService.getBluePrintError().addError(runtimeException.message!!) - } -} \ 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 deleted file mode 100644 index 3f0c1b4f..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt +++ /dev/null @@ -1,115 +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.JsonNode -import org.apache.commons.collections.MapUtils -import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService -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.interfaces.BlueprintFunctionNode -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintTemplateService -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition -import org.slf4j.LoggerFactory -import java.util.* - -abstract class ResourceAssignmentProcessor : BlueprintFunctionNode { - - private val log = LoggerFactory.getLogger(ResourceAssignmentProcessor::class.java) - - lateinit var raRuntimeService: ResourceAssignmentRuntimeService - lateinit var resourceDictionaries: MutableMap - - var scriptPropertyInstances: MutableMap = hashMapOf() - - /** - * This will be called from the scripts to serve instance from runtime to scripts. - */ - open fun scriptPropertyInstanceType(name: String): T { - return scriptPropertyInstances as? T - ?: throw BluePrintProcessorException("couldn't get script property instance ($name)") - } - - open fun getFromInput(resourceAssignment: ResourceAssignment): JsonNode? { - var value: JsonNode? = null - try { - value = raRuntimeService.getInputValue(resourceAssignment.name) - ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value) - } catch (e: BluePrintProcessorException) { - // NoOp - couldn't find value from input - } - return value - } - - open fun resourceDefinition(name: String): ResourceDefinition { - return resourceDictionaries[name] - ?: throw BluePrintProcessorException("couldn't get resource definition for ($name)") - } - - open fun resolveInputKeyMappingVariables(inputKeyMapping: Map): Map { - val resolvedInputKeyMapping = HashMap() - if (MapUtils.isNotEmpty(inputKeyMapping)) { - for ((key, value) in inputKeyMapping) { - val resultValue = raRuntimeService.getResolutionStore(value) - val expressionValue = JacksonUtils.getValue(resultValue) - log.trace("Reference dictionary key ({}), value ({})", key, expressionValue) - resolvedInputKeyMapping[key] = expressionValue - } - } - return resolvedInputKeyMapping - } - - open fun resolveFromInputKeyMapping(valueToResolve: String, keyMapping: Map): String { - if (valueToResolve.isEmpty() || !valueToResolve.contains("$")) { - return valueToResolve - } - return BluePrintTemplateService.generateContent(valueToResolve, additionalContext = keyMapping) - } - - override fun prepareRequest(resourceAssignment: ResourceAssignment): ResourceAssignment { - log.info("prepareRequest for ${resourceAssignment.name}, dictionary(${resourceAssignment.dictionaryName})," + - "source(${resourceAssignment.dictionarySource})") - return resourceAssignment - } - - override fun prepareResponse(): Boolean { - log.info("Preparing Response...") - return true - } - - override fun apply(resourceAssignment: ResourceAssignment): Boolean { - try { - prepareRequest(resourceAssignment) - process(resourceAssignment) - } catch (runtimeException: RuntimeException) { - recover(runtimeException, resourceAssignment) - } - return prepareResponse() - } - - fun addError(type: String, name: String, error: String) { - raRuntimeService.getBluePrintError().addError(type, name, error) - } - - fun addError(error: String) { - raRuntimeService.getBluePrintError().addError(error) - } - -} \ 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/RestResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt deleted file mode 100644 index 091220b5..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt +++ /dev/null @@ -1,204 +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.MissingNode -import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR -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.blueprintsprocessor.rest.service.BlueprintWebClientService -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes -import org.onap.ccsdk.apps.controllerblueprints.core.checkEqualsOrThrow -import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty -import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow -import org.onap.ccsdk.apps.controllerblueprints.core.nullToEmpty -import org.onap.ccsdk.apps.controllerblueprints.core.returnNotEmptyOrThrow -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 - -/** - * RestResourceResolutionProcessor - * - * @author Kapil Singal - */ -@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-rest") -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyService: BluePrintRestLibPropertyService) - : ResourceAssignmentProcessor() { - - private val logger = LoggerFactory.getLogger(RestResourceResolutionProcessor::class.java) - - override fun getName(): String { - return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-rest" - } - - override fun process(resourceAssignment: ResourceAssignment) { - try { - validate(resourceAssignment) - - // Check if It has Input - val value = getFromInput(resourceAssignment) - if (value == null || value is MissingNode) { - 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 path = nullToEmpty(sourceProperties.path) - val inputKeyMapping = - checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" } - val resolvedInputKeyMapping = resolveInputKeyMappingVariables(inputKeyMapping) - - // Resolving content Variables - val payload = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.payload), resolvedInputKeyMapping) - val urlPath = - resolveFromInputKeyMapping(checkNotNull(sourceProperties.urlPath), resolvedInputKeyMapping) - val verb = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.verb), resolvedInputKeyMapping) - - logger.info("$dSource dictionary information : ($urlPath), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})") - // Get the Rest Client Service - val restClientService = blueprintWebClientService(resourceAssignment, sourceProperties) - - val response = restClientService.exchangeResource(verb, urlPath, payload) - if (response.isBlank()) { - 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) - } - } - - private fun blueprintWebClientService(resourceAssignment: ResourceAssignment, - restResourceSource: RestResourceSource): BlueprintWebClientService { - return if (checkNotEmpty(restResourceSource.endpointSelector)) { - val restPropertiesJson = raRuntimeService.resolveDSLExpression(restResourceSource.endpointSelector!!) - blueprintRestLibPropertyService.blueprintWebClientService(restPropertiesJson) - } else { - blueprintRestLibPropertyService.blueprintWebClientService(resourceAssignment.dictionarySource!!) - } - } - - @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 - entrySchemaType = - returnNotEmptyOrThrow(resourceAssignment.property?.type) { "Entry schema is not defined for dictionary ($dName) info" } - val objectNode = JsonNodeFactory.instance.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) { - raRuntimeService.getBluePrintError().addError(runtimeException.message!!) - } - - -} \ 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/utils/ResourceAssignmentUtils.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt deleted file mode 100644 index d55ccacb..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 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.utils - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.databind.node.NullNode -import com.fasterxml.jackson.databind.node.ObjectNode -import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes -import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty -import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow -import org.onap.ccsdk.apps.controllerblueprints.core.nullToEmpty -import org.onap.ccsdk.apps.controllerblueprints.core.returnNotEmptyOrThrow -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import java.util.* - -class ResourceAssignmentUtils { - companion object { - - private val logger: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentUtils::class.toString()) - - // TODO("Modify Value type from Any to JsonNode") - @Throws(BluePrintProcessorException::class) - fun setResourceDataValue(resourceAssignment: ResourceAssignment, - raRuntimeService: ResourceAssignmentRuntimeService, value: Any?) { - - val resourceProp = checkNotNull(resourceAssignment.property) { "Failed in setting resource value for resource mapping $resourceAssignment" } - checkNotEmptyOrThrow(resourceAssignment.name, "Failed in setting resource value for resource mapping $resourceAssignment") - - if (resourceAssignment.dictionaryName.isNullOrEmpty()) { - resourceAssignment.dictionaryName = resourceAssignment.name - logger.warn("Missing dictionary key, setting with template key (${resourceAssignment.name}) as dictionary key (${resourceAssignment.dictionaryName})") - } - - try { - if (resourceProp.type.isNotEmpty()) { - val convertedValue = convertResourceValue(resourceProp.type, value) - logger.info("Setting Resource Value ($convertedValue) for Resource Name (${resourceAssignment.dictionaryName}) of type (${resourceProp.type})") - setResourceValue(resourceAssignment, raRuntimeService, convertedValue) - resourceAssignment.updatedDate = Date() - resourceAssignment.updatedBy = BluePrintConstants.USER_SYSTEM - resourceAssignment.status = BluePrintConstants.STATUS_SUCCESS - } - } catch (e: Exception) { - throw BluePrintProcessorException("Failed in setting value for template key (${resourceAssignment.name}) and " + - "dictionary key (${resourceAssignment.dictionaryName}) of type (${resourceProp.type}) with error message (${e.message})", e) - } - } - - private fun setResourceValue(resourceAssignment: ResourceAssignment, raRuntimeService: ResourceAssignmentRuntimeService, value: JsonNode) { - raRuntimeService.putResolutionStore(resourceAssignment.name, value) - raRuntimeService.putDictionaryStore(resourceAssignment.dictionaryName!!, value) - resourceAssignment.property!!.value = value - } - - private fun convertResourceValue(type: String, value: Any?): JsonNode { - - return if (value == null || value is NullNode) { - logger.info("Returning {} value from convertResourceValue", value) - NullNode.instance - } else if (BluePrintTypes.validPrimitiveTypes().contains(type) && value is String) { - JacksonUtils.convertPrimitiveResourceValue(type, value) - } else if (value is String) { - JacksonUtils.jsonNode(value) - } else { - JacksonUtils.getJsonNode(value) - } - - } - - fun setFailedResourceDataValue(resourceAssignment: ResourceAssignment, message: String?) { - if (checkNotEmpty(resourceAssignment.name)) { - resourceAssignment.updatedDate = Date() - resourceAssignment.updatedBy = BluePrintConstants.USER_SYSTEM - resourceAssignment.status = BluePrintConstants.STATUS_FAILURE - resourceAssignment.message = message - } - } - - @Throws(BluePrintProcessorException::class) - fun assertTemplateKeyValueNotNull(resourceAssignment: ResourceAssignment) { - val resourceProp = checkNotNull(resourceAssignment.property) { "Failed to populate mandatory resource resource mapping $resourceAssignment" } - if (resourceProp.required != null && resourceProp.required!! && (resourceProp.value == null || resourceProp.value !is NullNode)) { - logger.error("failed to populate mandatory resource mapping ($resourceAssignment)") - throw BluePrintProcessorException("failed to populate mandatory resource mapping ($resourceAssignment)") - } - } - - @Throws(BluePrintProcessorException::class) - fun generateResourceDataForAssignments(assignments: List): String { - val result: String - try { - val mapper = ObjectMapper() - val root: ObjectNode = mapper.createObjectNode() - - assignments.forEach { - if (checkNotEmpty(it.name) && it.property != null) { - val rName = it.name - val type = nullToEmpty(it.property?.type).toLowerCase() - val value = it.property?.value - logger.info("Generating Resource name ($rName), type ($type), value ($value)") - root.set(rName, value) - } - } - result = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root) - logger.info("Generated Resource Param Data ($result)") - } catch (e: Exception) { - throw BluePrintProcessorException("Resource Assignment is failed with $e.message", e) - } - - return result - } - - fun transformToRARuntimeService(blueprintRuntimeService: BluePrintRuntimeService<*>, templateArtifactName: String): ResourceAssignmentRuntimeService { - val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService(blueprintRuntimeService.id(), blueprintRuntimeService.bluePrintContext()) - resourceAssignmentRuntimeService.createUniqueId(templateArtifactName) - resourceAssignmentRuntimeService.setExecutionContext(blueprintRuntimeService.getExecutionContext() as MutableMap) - - return resourceAssignmentRuntimeService - } - - @Throws(BluePrintProcessorException::class) - fun getPropertyType(raRuntimeService: ResourceAssignmentRuntimeService, dataTypeName: String, propertyName: String): String { - lateinit var type: String - try { - val dataTypeProps = checkNotNull(raRuntimeService.bluePrintContext().dataTypeByName(dataTypeName)?.properties) - val propertyDefinition = checkNotNull(dataTypeProps[propertyName]) - type = returnNotEmptyOrThrow(propertyDefinition.type) { "Couldn't get data type ($dataTypeName)" } - logger.trace("Data type({})'s property ({}) is ({})", dataTypeName, propertyName, type) - } catch (e: Exception) { - logger.error("couldn't get data type($dataTypeName)'s property ($propertyName), error message $e") - throw BluePrintProcessorException("${e.message}", e) - } - return type - } - } -} \ No newline at end of file -- cgit 1.2.3-korg