diff options
Diffstat (limited to 'ms/blueprintsprocessor/functions/resource-resolution')
31 files changed, 0 insertions, 2245 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/pom.xml b/ms/blueprintsprocessor/functions/resource-resolution/pom.xml deleted file mode 100644 index eafdb9a0..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/pom.xml +++ /dev/null @@ -1,58 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ 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. - --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId> - <artifactId>functions</artifactId> - <version>0.4.2-SNAPSHOT</version> - </parent> - <groupId>org.onap.ccsdk.apps.blueprintsprocessor.functions</groupId> - <artifactId>resource-resolution</artifactId> - <packaging>jar</packaging> - <name>Blueprints Processor Function - Resource Resolution</name> - <description>Blueprints Processor Function - Resource Resolution</description> - - <dependencies> - <dependency> - <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId> - <artifactId>db-lib</artifactId> - </dependency> - <dependency> - <groupId>org.onap.ccsdk.apps.blueprintsprocessor.functions</groupId> - <artifactId>python-executor</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-jpa</artifactId> - </dependency> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - </dependency> - <dependency> - <groupId>org.mariadb.jdbc</groupId> - <artifactId>mariadb-java-client</artifactId> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-testing</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - -</project> 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<String, JsonNode> = 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<String, Any> = 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<String> - - fun resolveFromDatabase(bluePrintRuntimeService: BluePrintRuntimeService<*>, artifactTemplate: String, - resolutionKey: String): String - - fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - artifactNames: List<String>, properties: Map<String, Any>): MutableMap<String, String> - - fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - artifactPrefix: String, properties: Map<String, Any>): String - - fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - artifactMapping: String, artifactTemplate: String?): String - - fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>, - resourceDictionaries: MutableMap<String, ResourceDefinition>, - resourceAssignments: MutableList<ResourceAssignment>, - 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<String> { - 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<String>, - properties: Map<String, Any>): MutableMap<String, String> { - - val resolvedParams: MutableMap<String, String> = 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, Any>): 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<ResourceAssignment> = - JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment::class.java) - as? MutableList<ResourceAssignment> - ?: 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<String, ResourceDefinition> = - 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<String, ResourceDefinition>, - resourceAssignments: MutableList<ResourceAssignment>, - 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, ResourceDefinition>): 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<String> -} - -open class DefaultResourceSource : ResourceSourceProperties() { - lateinit var key: String - @get:JsonProperty("key-dependencies") - lateinit var keyDependencies: MutableList<String> -} - -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<String, String>? = null - @get:JsonProperty("output-key-mapping") - var outputKeyMapping: MutableMap<String, String>? = null - @get:JsonProperty("key-dependencies") - lateinit var keyDependencies: MutableList<String> -} - -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<String, String>? = null - @get:JsonProperty("output-key-mapping") - var outputKeyMapping: MutableMap<String, String>? = null - @get:JsonProperty("key-dependencies") - lateinit var keyDependencies: MutableList<String> -} - -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<String>? = null - @get:JsonProperty("key-dependencies") - lateinit var keyDependencies: MutableList<String> -}
\ 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<ResourceResolutionResult, String> { - - 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<String, Any>, 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<String>) - : ResourceAssignmentProcessor { - - log.info("creating resource resolution of script type($scriptType), reference name($scriptClassReference) and" + - "instanceDependencies($instanceDependencies)") - - val scriptComponent = componentFunctionScriptingService - .scriptInstance<ResourceAssignmentProcessor>(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<String, String>): Map<String, Any> { - val namedParameters = HashMap<String, Any>() - 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<Map<String, Any>>) { - 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<ResourceAssignment, Boolean> { - - private val log = LoggerFactory.getLogger(ResourceAssignmentProcessor::class.java) - - lateinit var raRuntimeService: ResourceAssignmentRuntimeService - lateinit var resourceDictionaries: MutableMap<String, ResourceDefinition> - - var scriptPropertyInstances: MutableMap<String, Any> = hashMapOf() - - /** - * This will be called from the scripts to serve instance from runtime to scripts. - */ - open fun <T> 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<String, String>): Map<String, Any> { - val resolvedInputKeyMapping = HashMap<String, Any>() - 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, Any>): 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<ResourceAssignment>): 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<String, JsonNode>) - - 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 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 deleted file mode 100644 index 91997e34..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.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. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution - -import com.fasterxml.jackson.databind.JsonNode -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties -import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfiguration -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.core.utils.PayloadUtils -import org.onap.ccsdk.apps.blueprintsprocessor.db.BluePrintDBLibConfiguration -import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.* -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode -import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration -import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.context.annotation.ComponentScan -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner - -@RunWith(SpringRunner::class) -@ContextConfiguration(classes = [ResourceResolutionServiceImpl::class, - InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class, - DatabaseResourceAssignmentProcessor::class, RestResourceResolutionProcessor::class, - CapabilityResourceResolutionProcessor::class, - BlueprintPropertyConfiguration::class, BluePrintProperties::class, - BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class]) -@TestPropertySource(locations = ["classpath:application-test.properties"]) -@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"]) -@EnableAutoConfiguration -class ResourceResolutionComponentTest { - - @Autowired - lateinit var resourceResolutionComponent: ResourceResolutionComponent - - @Test - fun testProcess() { - - val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", - "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") - - val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json", - ExecutionServiceInput::class.java)!! - - // Prepare Inputs - PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment") - - val stepMetaData: MutableMap<String, JsonNode> = hashMapOf() - stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment") - stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ResourceResolutionComponent") - stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process") - bluePrintRuntimeService.put("resource-assignment-step-inputs", stepMetaData.asJsonNode()) - - resourceResolutionComponent.bluePrintRuntimeService = bluePrintRuntimeService - resourceResolutionComponent.stepName = "resource-assignment" - resourceResolutionComponent.apply(executionServiceInput) - } -}
\ 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/ResourceResolutionServiceTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt deleted file mode 100644 index d560e8c3..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt +++ /dev/null @@ -1,91 +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.junit.Assert -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties -import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfiguration -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.core.utils.PayloadUtils -import org.onap.ccsdk.apps.blueprintsprocessor.db.BluePrintDBLibConfiguration -import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.* -import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.context.annotation.ComponentScan -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner -import kotlin.test.assertNotNull -import kotlin.test.assertTrue - -/** - * ResourceResolutionServiceTest - * - * @author Brinda Santh DATE : 8/15/2018 - */ -@RunWith(SpringRunner::class) -@ContextConfiguration(classes = [ResourceResolutionServiceImpl::class, - InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class, - DatabaseResourceAssignmentProcessor::class, RestResourceResolutionProcessor::class, - CapabilityResourceResolutionProcessor::class, - BlueprintPropertyConfiguration::class, BluePrintProperties::class, - BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class]) -@TestPropertySource(locations = ["classpath:application-test.properties"]) -@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"]) -@EnableAutoConfiguration -class ResourceResolutionServiceTest { - - private val log = LoggerFactory.getLogger(ResourceResolutionServiceTest::class.java) - - @Autowired - lateinit var resourceResolutionService: ResourceResolutionService - - @Test - fun testRegisteredSource() { - val sources = resourceResolutionService.registeredResourceSources() - assertNotNull(sources, "failed to get registered sources") - assertTrue(sources.containsAll(arrayListOf("source-input", "source-default", "source-processor-db", - "source-rest")), "failed to get registered sources : $sources") - } - - @Test - @Throws(Exception::class) - fun testResolveResource() { - - Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService) - - val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", - "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") - - val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json", - ExecutionServiceInput::class.java)!! - - // Prepare Inputs - PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment") - - resourceResolutionService.resolveResources(bluePrintRuntimeService, "resource-assignment", "baseconfig", mapOf()) - - } - -} 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 deleted file mode 100644 index 5a14a296..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt +++ /dev/null @@ -1,126 +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.Ignore -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.ComponentFunctionScriptingService -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, ComponentFunctionScriptingService::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 - - @Ignore - @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<String, Any> = mutableMapOf() - scriptPropertyInstances["mock-service1"] = MockCapabilityService() - scriptPropertyInstances["mock-service2"] = MockCapabilityService() - - val instanceDependencies: List<String> = listOf() - - val resourceAssignmentProcessor = capabilityResourceResolutionProcessor - .scriptInstance("kotlin", - "ResourceAssignmentProcessor_cba\$ScriptResourceAssignmentProcessor", instanceDependencies) - - 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<String, ResourceDefinition> = 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/application-test.properties b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties deleted file mode 100644 index 3f37d1b9..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties +++ /dev/null @@ -1,43 +0,0 @@ -# suppress inspection "UnusedProperty" for whole file -# -# 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. -# -blueprintsprocessor.db.primary.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE -blueprintsprocessor.db.primary.username=sa -blueprintsprocessor.db.primary.password= -blueprintsprocessor.db.primary.driverClassName=org.h2.Driver -blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=create-drop -blueprintsprocessor.db.primary.hibernateDDLAuto=update -blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy -blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.H2Dialect -# Controller Blueprints Core Configuration -blueprintsprocessor.blueprintDeployPath=./target/blueprints/deploy -blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive - -blueprintsprocessor.restclient.primary-config-data.type=basic-auth -blueprintsprocessor.restclient.primary-config-data.url=http://127.0.0.1:9111 -blueprintsprocessor.restclient.primary-config-data.userId=sampleuser -blueprintsprocessor.restclient.primary-config-data.token=sampletoken - -# Python executor -blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints -blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints - - -# CBA examples for tests cases -controllerblueprints.loadBlueprintsExamplesPath=./../../../../components/model-catalog/blueprint-model/test-blueprint -controllerblueprints.loadBluePrintPaths=./../../../../components/model-catalog/blueprint-model/test-blueprint
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/logback-test.xml b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/logback-test.xml deleted file mode 100644 index a816a06c..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/logback-test.xml +++ /dev/null @@ -1,35 +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.
- -->
-
-<configuration>
- <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- <!-- encoders are assigned the type
- ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
- <encoder>
- <pattern>%d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n</pattern>
- </encoder>
- </appender>
-
-
- <logger name="org.springframework" level="warn"/>
- <logger name="org.hibernate" level="info"/>
- <logger name="org.onap.ccsdk.apps.blueprintsprocessor" level="info"/>
-
- <root level="warn">
- <appender-ref ref="STDOUT"/>
- </root>
-
-</configuration>
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 deleted file mode 100644 index b565eec8..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "tags": "service-instance-id, tosca.datatypes.Root, data_type", - "name": "service-instance-id", - "property": { - "description": "To be provided", - "type": "string" - }, - "updated-by": "Singal, Kapil <ks220y@att.com>", - "sources": { - "capability": { - "type": "source-capability", - "properties": { - "script-type": "jython", - "script-class-reference": "Scripts/python/SampleRAProcessor.py", - "instance-dependencies": [] - } - } - } -}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/dt-location.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/dt-location.json deleted file mode 100644 index 52e0a796..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/dt-location.json +++ /dev/null @@ -1,15 +0,0 @@ -{
- "version": "1.0.0",
- "description": "test Data Type",
- "properties": {
- "country": {
- "required": true,
- "type": "string"
- },
- "state": {
- "required": false,
- "type": "string"
- }
- },
- "derived_from": "tosca.datatypes.Root"
-}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/primary-db-array.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/primary-db-array.json deleted file mode 100644 index 7082a434..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/primary-db-array.json +++ /dev/null @@ -1,35 +0,0 @@ -{
- "locations": {
- "name": "locations",
- "data-type": "list",
- "entry-schema": "dt-location",
- "source": {
- "primary-db": {
- "query": "SELECT db-country, db-state FROM DEVICE_PROFILE WHERE profile_name = :profile_name",
- "input-key-mapping": {
- "profile_name": "profile_name"
- },
- "output-key-mapping": {
- "db-country": "country",
- "db-state": "state"
- }
- }
- },
- "candidate-dependency": {
- "primary-db": {
- "names": [
- "profile_name"
- ]
- }
- }
- },
- "profile_name": {
- "name": "profile_name",
- "data-type": "string",
- "source": {
- "input": {
-
- }
- }
- }
-}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/primary-db-complex.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/primary-db-complex.json deleted file mode 100644 index 53e2a11c..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/primary-db-complex.json +++ /dev/null @@ -1,27 +0,0 @@ -{
- "location": {
- "name": "location",
- "data-type": "dt-location",
- "source": {
- "primary-db": {
- "query": "SELECT db-country, db-state FROM DEVICE_PROFILE WHERE profile_name = :profile_name",
- "input-key-mapping": {
- "profile_name": "profile_name"
- },
- "output-key-mapping": {
- "db-country": "country",
- "db-state": "state"
- }
- }
- }
- },
- "profile_name": {
- "name": "profile_name",
- "data-type": "string",
- "source": {
- "input": {
-
- }
- }
- }
-}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/primary-db-simple.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/primary-db-simple.json deleted file mode 100644 index fad08887..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/primary-db-simple.json +++ /dev/null @@ -1,26 +0,0 @@ -{
- "country": {
- "name": "country",
- "data-type": "string",
- "source": {
- "primary-db": {
- "query": "SELECT country FROM DEVICE_PROFILE WHERE profile_name = :profile_name",
- "input-key-mapping": {
- "profile_name": "profile_name"
- },
- "output-key-mapping": {
- "country": "country"
- }
- }
- }
- },
- "profile_name": {
- "name": "profile_name",
- "data-type": "string",
- "source": {
- "input": {
-
- }
- }
- }
-}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/resource-assignments-simple.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/resource-assignments-simple.json deleted file mode 100644 index bb392d7b..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/resource-assignments-simple.json +++ /dev/null @@ -1,22 +0,0 @@ -[
- {
- "name": "country",
- "input-param": true,
- "property": {
- "type": "string"
- },
- "dictionary-name": "country",
- "dictionary-source": "primary-db",
- "dependencies": ["state"]
- },
- {
- "name": "state",
- "input-param": true,
- "property": {
- "type": "string"
- },
- "dictionary-name": "state",
- "dictionary-source": "input",
- "dependencies": []
- }
-]
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/inputs/input.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/inputs/input.json deleted file mode 100644 index cd6fac12..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/inputs/input.json +++ /dev/null @@ -1,18 +0,0 @@ -{
- "api-ver": "2.00",
- "originator-id": "MSO",
- "request-id": "123456",
- "service-instance-id": "ibcx0001vm001",
- "service-type": "AVPN",
- "vnf-type": "vUSP - vDBE-IPX HUB",
- "vnf-id": 123456,
- "service-template-name": "VRR-baseconfiguration",
- "service-template-version": "1.0.0",
- "action-name": "resource-assignment-action",
- "group-name": "sample group name",
- "bundle-id": "sample bundle id",
- "bundle-mac": [
- "Sample bundle mac",
- "Sample bundle mac"
- ]
-}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request.json deleted file mode 100644 index 6a7b4c2a..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request.json +++ /dev/null @@ -1,32 +0,0 @@ -{
- "actionIdentifiers": {
- "actionName": "sample-action",
- "blueprintName": "sample-blurprint",
- "blueprintVersion": "1.0.0",
- "mode": "sync"
- },
- "commonHeader": {
- "flags": {
- "force": true,
- "ttl": 3600
- },
- "originatorId": "sdnc",
- "requestId": "123456-1000",
- "subRequestId": "sub-123456-1000",
- "timestamp": "2012-04-23T18:25:43.511Z"
- },
- "payload": {
- "resource-assignment-request": {
- "resource-assignment-properties": {
- "request-id": "1234",
- "profile_name": "1.0.0",
- "service-instance-id": "siid_1234",
- "vnf-id": "vnf_1234",
- "action-name": "assign-activate",
- "scope-type": "vnf-type",
- "hostname": "localhost",
- "vnf_name": "temp_vnf"
- }
- }
- }
-}
|