From: Steve Siani Date: Tue, 16 Jul 2019 21:46:53 +0000 (-0400) Subject: Resolve Attribute and properties fails with subPropertyName X-Git-Tag: 0.5.0~57 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=cc195ac47a785965ebca290d66e11046c68718ab;p=ccsdk%2Fcds.git Resolve Attribute and properties fails with subPropertyName Issue-ID: CCSDK-1489 Signed-off-by: Steve Siani Change-Id: If27c0dd301f2c0e63cecc662cd89b1a72d1b21f1 --- diff --git a/components/scripts/python/ccsdk_netconf/common.py b/components/scripts/python/ccsdk_netconf/common.py index f161e29ff..ad2057f32 100644 --- a/components/scripts/python/ccsdk_netconf/common.py +++ b/components/scripts/python/ccsdk_netconf/common.py @@ -1,4 +1,5 @@ # Copyright (c) 2019 Bell Canada. +# Modifications Copyright © 2018 - 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. @@ -18,11 +19,11 @@ class ResolutionHelper: self.component_function = component_function def resolve_and_generate_message_from_template_prefix(self, artifact_prefix): - return self.component_function.resolveAndGenerateMessage(artifact_prefix) + return self.component_function.contentFromResolvedArtifact(artifact_prefix) def resolve_and_generate_message(self, artifact_mapping, artifact_template): return self.component_function.resolveAndGenerateMessage(artifact_mapping, artifact_template) def retrieve_resolved_template_from_database(self, key, artifact_template): - return self.component_function.resolveFromDatabase(key, artifact_template) + return self.component_function.storedContentFromResolvedArtifact(key, artifact_template) diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ScriptComponentExtensions.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ScriptComponentExtensions.kt index bac211ab2..510621b2e 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ScriptComponentExtensions.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ScriptComponentExtensions.kt @@ -1,5 +1,6 @@ /* * Copyright © 2019 IBM. + * Modifications Copyright © 2018 - 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. @@ -50,4 +51,8 @@ fun AbstractComponentFunction.netconfDeviceInfo(requirementName: String): Device private fun AbstractComponentFunction.netconfDeviceInfo(capabilityProperty: MutableMap): DeviceInfo { return JacksonUtils.getInstanceFromMap(capabilityProperty, DeviceInfo::class.java) -} \ No newline at end of file +} + +/** + * Blocking Methods called from Jython Scripts + */ \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt index 0e97267da..938affc82 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt @@ -17,6 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution +import com.fasterxml.jackson.databind.JsonNode import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll import kotlinx.coroutines.coroutineScope @@ -25,10 +26,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.R import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.TemplateResolutionService import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive -import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty +import org.onap.ccsdk.cds.controllerblueprints.core.* import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintTemplateService import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils @@ -47,7 +45,7 @@ interface ResourceResolutionService { resolutionKey: String): String suspend fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - artifactNames: List, properties: Map): MutableMap + artifactNames: List, properties: Map): MutableMap suspend fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, artifactPrefix: String, properties: Map): String @@ -85,17 +83,19 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica override suspend fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, artifactNames: List, - properties: Map): MutableMap { + properties: Map): MutableMap { val resourceAssignmentRuntimeService = ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService, artifactNames.toString()) - val resolvedParams: MutableMap = hashMapOf() + val resolvedParams: MutableMap = hashMapOf() artifactNames.forEach { artifactName -> val resolvedContent = resolveResources(resourceAssignmentRuntimeService, nodeTemplateName, artifactName, properties) - resolvedParams[artifactName] = resolvedContent + + resolvedParams[artifactName] = resolvedContent.asJsonType() + } return resolvedParams } diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt index cea18ef9b..a5b18a1f6 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt @@ -253,4 +253,8 @@ fun nullToEmpty(value: String?): String { return if (isNotEmpty(value)) value!! else "" } +inline fun T.isComplexType(): Boolean { + return this is ObjectNode || this is ArrayNode +} + diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/data/BluePrintExpressionData.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/data/BluePrintExpressionData.kt index 15b3e22fb..d3013402b 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/data/BluePrintExpressionData.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/data/BluePrintExpressionData.kt @@ -1,6 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. + * Modifications Copyright © 2018 - 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. @@ -67,7 +67,8 @@ data class OperationOutputExpression( val modelableEntityName: String = "SELF", val interfaceName: String, val operationName: String, - val propertyName: String + val propertyName: String, + var subPropertyName: String? = null ) data class DSLExpression( diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintExpressionService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintExpressionService.kt index 32cb6ac77..fbf911664 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintExpressionService.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintExpressionService.kt @@ -1,6 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. + * Modifications Copyright © 2018 - 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. @@ -170,10 +170,16 @@ object BluePrintExpressionService { throw BluePrintException(String.format("missing operation output expression, " + "it should be (, , , ) , but present {}", jsonNode)) } + + var subPropertyName: String? = null + if (arrayNode.size() == 5) + subPropertyName = arrayNode[4].asText() + return OperationOutputExpression(modelableEntityName = arrayNode[0].asText(), interfaceName = arrayNode[1].asText(), operationName = arrayNode[2].asText(), - propertyName = arrayNode[3].asText() + propertyName = arrayNode[3].asText(), + subPropertyName = subPropertyName ) } diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRuntimeService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRuntimeService.kt index e6f3f71ca..ba210df10 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRuntimeService.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRuntimeService.kt @@ -1,6 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018-2019 IBM. + * Modifications Copyright © 2018-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. @@ -213,8 +213,7 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl override fun loadEnvironments(type: String, fileName: String) { BluePrintMetadataUtils.environmentFileProperties(fileName).forEach { key, value -> - setNodeTemplateAttributeValue(type, key.toString(), value.toString() - .asJsonPrimitive()) + setNodeTemplateAttributeValue(type, key.toString(), value.asJsonType()) } } diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/PropertyAssignmentService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/PropertyAssignmentService.kt index 931d31e9d..30bd75f7d 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/PropertyAssignmentService.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/PropertyAssignmentService.kt @@ -1,6 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. + * Modifications Copyright © 2018 - 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. @@ -21,11 +21,8 @@ package org.onap.ccsdk.cds.controllerblueprints.core.service import org.slf4j.LoggerFactory import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.node.NullNode -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive +import org.onap.ccsdk.cds.controllerblueprints.core.* import org.onap.ccsdk.cds.controllerblueprints.core.data.* -import org.onap.ccsdk.cds.controllerblueprints.core.format import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.cds.controllerblueprints.core.utils.JsonParserUtils import org.onap.ccsdk.cds.controllerblueprints.core.utils.ResourceResolverUtils @@ -143,8 +140,8 @@ If Property Assignment is Expression. } if (subAttributeName != null) { - if (valueNode.isObject || valueNode.isArray) - valueNode = JsonParserUtils.parse(valueNode, subAttributeName) + if (valueNode.isComplexType()) + valueNode = JsonParserUtils.parse(valueNode.asJsonString(), subAttributeName) } return valueNode } @@ -176,8 +173,8 @@ If Property Assignment is Expression. valueNode = resolveAssignmentExpression(propertyNodeTemplateName, propertyName, nodeTemplatePropertyExpression) if (subPropertyName != null) { - if (valueNode.isObject || valueNode.isArray) - valueNode = JsonParserUtils.parse(valueNode, subPropertyName) + if (valueNode.isComplexType()) + valueNode = JsonParserUtils.parse(valueNode.asJsonString(), subPropertyName) } return valueNode } @@ -190,9 +187,17 @@ If Property Assignment is Expression. if (!operationOutputExpression.modelableEntityName.equals("SELF", true)) { outputNodeTemplateName = operationOutputExpression.modelableEntityName } - return bluePrintRuntimeService.getNodeTemplateOperationOutputValue(outputNodeTemplateName, + + var valueNode = bluePrintRuntimeService.getNodeTemplateOperationOutputValue(outputNodeTemplateName, operationOutputExpression.interfaceName, operationOutputExpression.operationName, operationOutputExpression.propertyName) + + val subPropertyName: String? = operationOutputExpression.subPropertyName + if (subPropertyName != null) { + if (valueNode.isComplexType()) + valueNode = JsonParserUtils.parse(valueNode.asJsonString(), subPropertyName) + } + return valueNode } /* diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt index 5e9fd6207..9b1b66b5b 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt @@ -296,6 +296,5 @@ class JacksonUtils { else -> getJsonNode(value) } } - } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JsonParserUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JsonParserUtils.kt index 342ff7636..e5eef5a41 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JsonParserUtils.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JsonParserUtils.kt @@ -1,5 +1,6 @@ /* * Copyright © 2018 IBM. + * Modifications Copyright © 2018 - 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. @@ -38,7 +39,7 @@ class JsonParserUtils { } fun paths(jsonNode: JsonNode, expression: String): List { - return paths(jsonNode.toString(), expression) + return paths(jsonNode, expression) } fun parse(jsonContent: String, expression: String): JsonNode { @@ -54,7 +55,8 @@ class JsonParserUtils { } fun parseNSet(jsonNode: JsonNode, expression: String, valueNode: JsonNode): JsonNode { - return parseNSet(jsonNode.toString(), expression, valueNode) + + return parseNSet(jsonNode, expression, valueNode) } } } \ No newline at end of file