From 7a04ac414b690983d863e96b487e314780572c48 Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Mon, 23 Sep 2019 16:11:17 -0400 Subject: Refactoring ResourceAssignmentUtils Refactoring ResourceAssignmentUtils parseResponseNodeForPrimitiveTypes API to remove cyclic value assignments Issue-ID: CCSDK-1748 Signed-off-by: Singal, Kapil (ks220y) Change-Id: I27b5a7d3ed2df38cf4e3e44686aec094ebdb5f25 Refactoring ResourceAssignmentUtils Changing isNull condition to isNullOrEmpty to make sure Empty value doesn't get assigned to resource Issue-ID: CCSDK-1748 Signed-off-by: Singal, Kapil (ks220y) Change-Id: I0744537c7ddec80f20ffd7e6545b947439f63743 Resource Resolution Refactoring Refactoring some logging statements and adding new loggers Issue-ID: CCSDK-1748 Signed-off-by: Singal, Kapil (ks220y) Change-Id: I5676659eea01056a7d29206f13473a4361516755 --- .../executor/ComponentRemoteAnsibleExecutor.kt | 8 +- .../resolution/ResourceResolutionService.kt | 2 +- .../DatabaseResourceAssignmentProcessor.kt | 9 +- .../processor/ResourceAssignmentProcessor.kt | 4 +- .../processor/RestResourceResolutionProcessor.kt | 5 +- .../resolution/utils/ResourceAssignmentUtils.kt | 88 +++--- .../mock/MockRestResourceResolutionProcessor.kt | 3 +- .../utils/ResourceAssignmentUtilsTest.kt | 4 +- .../execution/AbstractComponentFunction.kt | 20 ++ .../scripts/AbstractComponentFunctionTest.kt | 7 +- .../controllerblueprints/core/CustomFunctions.kt | 15 +- .../core/service/BluePrintRuntimeService.kt | 348 +++++++++++---------- .../core/CustomFunctionsTest.kt | 26 ++ .../core/service/BluePrintRuntimeServiceTest.kt | 3 +- .../resource/dict/ResourceDefinition.kt | 19 +- .../dict/utils/BulkResourceSequencingUtils.kt | 4 +- 16 files changed, 316 insertions(+), 249 deletions(-) diff --git a/ms/blueprintsprocessor/functions/ansible-awx-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/ansible/executor/ComponentRemoteAnsibleExecutor.kt b/ms/blueprintsprocessor/functions/ansible-awx-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/ansible/executor/ComponentRemoteAnsibleExecutor.kt index 25bb3c938..3a655ded7 100644 --- a/ms/blueprintsprocessor/functions/ansible-awx-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/ansible/executor/ComponentRemoteAnsibleExecutor.kt +++ b/ms/blueprintsprocessor/functions/ansible-awx-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/ansible/executor/ComponentRemoteAnsibleExecutor.kt @@ -296,20 +296,20 @@ open class ComponentRemoteAnsibleExecutor(private val blueprintRestLibPropertySe val skipTagsProp = getOptionalOperationInput(INPUT_SKIP_TAGS) val askLimitOnLaunch = jtLaunchReqs.at("/ask_limit_on_launch").asBoolean() - if (askLimitOnLaunch && limitProp.isNotNull()) { + if (askLimitOnLaunch && !limitProp.isNullOrMissing()) { payload.set(INPUT_LIMIT_TO_HOST, limitProp) } val askTagsOnLaunch = jtLaunchReqs.at("/ask_tags_on_launch").asBoolean() - if (askTagsOnLaunch && tagsProp.isNotNull()) { + if (askTagsOnLaunch && !tagsProp.isNullOrMissing()) { payload.set(INPUT_TAGS, tagsProp) } - if (askTagsOnLaunch && skipTagsProp.isNotNull()) { + if (askTagsOnLaunch && !skipTagsProp.isNullOrMissing()) { payload.set("skip_tags", skipTagsProp) } } val askInventoryOnLaunch = jtLaunchReqs.at("/ask_inventory_on_launch").asBoolean() - if (askInventoryOnLaunch && inventoryProp.isNotNull()) { + if (askInventoryOnLaunch && !inventoryProp.isNullOrMissing()) { var inventoryKeyId = if (inventoryProp is TextNode) { resolveInventoryIdByName(awxClient, inventoryProp.textValue())?.asJsonPrimitive() } else { 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 51170a9b2..8651e2620 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 @@ -230,7 +230,7 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica blueprintRuntimeService, artifactPrefix, resourceAssignment) - log.info("Resource resolution saved into database successfully : ($resourceAssignment)") + log.info("Resource resolution saved into database successfully : (${resourceAssignment.name})") } // Set errors from RA diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt index 8d21e9a70..0f5d91415 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt @@ -91,7 +91,8 @@ open class DatabaseResourceAssignmentProcessor( "failed to get input-key-mappings for $dName under $dSource properties" } - logger.info("$dSource dictionary information : ($sql), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})") + logger.info("DatabaseResource ($dSource) dictionary information: " + + "Query:($sql), input-key-mapping:($inputKeyMapping), output-key-mapping:(${sourceProperties.outputKeyMapping})") val jdbcTemplate = blueprintDBLibService(sourceProperties) val rows = jdbcTemplate.query(sql, populateNamedParameter(inputKeyMapping)) @@ -135,7 +136,9 @@ open class DatabaseResourceAssignmentProcessor( logger.trace("Reference dictionary key (${it.key}) resulted in value ($expressionValue)") namedParameters[it.key] = expressionValue } - logger.info("Parameter information : ($namedParameters)") + if (namedParameters.isNotEmpty()) { + logger.info("Parameter information : ($namedParameters)") + } return namedParameters } @@ -152,7 +155,7 @@ open class DatabaseResourceAssignmentProcessor( val outputKeyMapping = checkNotNull(sourceProperties.outputKeyMapping) { "failed to get output-key-mappings for $dName under $dSource properties" } - logger.info("Response processing type($type)") + logger.info("Response processing type ($type)") val responseNode = checkNotNull(JacksonUtils.getJsonNode(rows)) { "Failed to get database query result into Json node." diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt index af89bcef6..e513170a8 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt @@ -51,7 +51,9 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode, - templateArtifactName: String): ResourceAssignmentRuntimeService { + fun transformToRARuntimeService( + blueprintRuntimeService: BluePrintRuntimeService<*>, + templateArtifactName: String + ): ResourceAssignmentRuntimeService { val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService( blueprintRuntimeService.id(), @@ -210,8 +210,10 @@ class ResourceAssignmentUtils { } @Throws(BluePrintProcessorException::class) - fun getPropertyType(raRuntimeService: ResourceAssignmentRuntimeService, dataTypeName: String, - propertyName: String): String { + fun getPropertyType( + raRuntimeService: ResourceAssignmentRuntimeService, dataTypeName: String, + propertyName: String + ): String { lateinit var type: String try { val dataTypeProps = @@ -228,8 +230,10 @@ class ResourceAssignmentUtils { } @Throws(BluePrintProcessorException::class) - fun parseResponseNode(responseNode: JsonNode, resourceAssignment: ResourceAssignment, - raRuntimeService: ResourceAssignmentRuntimeService, outputKeyMapping: MutableMap): JsonNode { + fun parseResponseNode( + responseNode: JsonNode, resourceAssignment: ResourceAssignment, + raRuntimeService: ResourceAssignmentRuntimeService, outputKeyMapping: MutableMap + ): JsonNode { val metadata = resourceAssignment.property!!.metadata try { if ((resourceAssignment.property?.type).isNullOrEmpty()) { @@ -238,9 +242,10 @@ class ResourceAssignmentUtils { val type = resourceAssignment.property!!.type val valueToPrint = getValueToLog(metadata, responseNode) - logger.info("For template key (${resourceAssignment.name}) setting value as ($valueToPrint)") + logger.info("For template key (${resourceAssignment.name}) trying to get value from responseNode ($valueToPrint)") return when (type) { in BluePrintTypes.validPrimitiveTypes() -> { + // Primitive Types parseResponseNodeForPrimitiveTypes(responseNode, outputKeyMapping) } in BluePrintTypes.validCollectionTypes() -> { @@ -258,46 +263,37 @@ class ResourceAssignmentUtils { } } - //TODO: Need to Refactor - private fun parseResponseNodeForPrimitiveTypes(responseNode: JsonNode, - outputKeyMapping: MutableMap): JsonNode { - var result: JsonNode? = responseNode - - if (responseNode.isComplexType()) { - val key = outputKeyMapping.keys.firstOrNull() - var returnNode: JsonNode? - if (responseNode is ArrayNode) { - val arrayNode = responseNode.toList() - val firstElement = if (key.isNullOrEmpty()) { - arrayNode.first() - } else { - arrayNode.firstOrNull { element -> - element.isComplexType() && element.has(outputKeyMapping[key]) - } - } - returnNode = firstElement - } else { - returnNode = responseNode - } + private fun parseResponseNodeForPrimitiveTypes( + responseNode: JsonNode, + outputKeyMapping: MutableMap + ): JsonNode { + // Return responseNode if is not a Complex Type + if (!responseNode.isComplexType()) { + return responseNode + } - if (returnNode.isNull() || (returnNode!!.isComplexType() && !returnNode.has(outputKeyMapping[key]))) { - if (key.isNullOrEmpty()) { - throw BluePrintProcessorException("Fail to find mapping in the responseNode.") - } else { - throw BluePrintProcessorException("Fail to find response with output key mapping ($key) in result.") - } - } - result = if (returnNode.isComplexType()) { - returnNode[outputKeyMapping[key]] + val outputKey = outputKeyMapping.keys.firstOrNull() + var returnNode = if (responseNode is ArrayNode) { + val arrayNode = responseNode.toList() + if (outputKey.isNullOrEmpty()) { + arrayNode.first() } else { - responseNode + arrayNode.firstOrNull { element -> + element.isComplexType() && element.has(outputKeyMapping[outputKey]) + } } } else { - if (outputKeyMapping.isNotEmpty()) { - throw BluePrintProcessorException("Fail to find key-value in response node to map output-key-mapping.") - } + responseNode + } + + if (returnNode.isNullOrMissing() || returnNode!!.isComplexType() && !returnNode.has(outputKeyMapping[outputKey])) { + throw BluePrintProcessorException("Fail to find output key mapping ($outputKey) in the responseNode.") + } + return if (returnNode.isComplexType()) { + returnNode[outputKeyMapping[outputKey]] + } else { + returnNode } - return result!! } private fun parseResponseNodeForCollection( @@ -568,7 +564,7 @@ class ResourceAssignmentUtils { fun getValueToLog(metadata: MutableMap?, value: Any): Any { return if (checkIfLogIsProtected(metadata)) { - "*************" + "******REDACTED******" } else { value } diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockRestResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockRestResourceResolutionProcessor.kt index 203b7ea30..e5b559826 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockRestResourceResolutionProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockRestResourceResolutionProcessor.kt @@ -77,7 +77,8 @@ class MockRestResourceResolutionProcessor(private val blueprintRestLibPropertySe resolveFromInputKeyMapping(checkNotNull(sourceProperties.urlPath), resolvedInputKeyMapping) val verb = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.verb), resolvedInputKeyMapping) - logger.info("$dSource dictionary information : ($urlPath), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})") + logger.info("MockRestResource ($dSource) dictionary information: " + + "URL:($urlPath), input-key-mapping:($inputKeyMapping), output-key-mapping:(${sourceProperties.outputKeyMapping})") // Get the Rest Client Service val restClientService = blueprintWebClientService(executionRequest) diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt index 728e1165a..d7a696848 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt @@ -131,7 +131,7 @@ class ResourceAssignmentUtilsTest { //then the assignment should produce a valid result val expected = "{\n" + " \"pnf-id\" : \"valid_value\"\n" + "}" - assertEquals(expected, outcome, "unexpected outcome generated") + assertEquals(expected, outcome.replace("\r\n","\n"), "unexpected outcome generated") } @Test @@ -147,7 +147,7 @@ class ResourceAssignmentUtilsTest { //then the assignment should produce a valid result val expected = "{\n" + " \"pnf-id\" : \"\${pnf-id}\"\n" + "}" - assertEquals(expected, outcome, "unexpected outcome generated") + assertEquals(expected, outcome.replace("\r\n","\n"), "unexpected outcome generated") } diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt index 8759338b7..5163a93ac 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt @@ -154,6 +154,26 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode-request/data" + */ + fun requestPayloadActionProperty(expression: String?): JsonNode? { + val requestExpression = if (expression.isNullOrBlank()) { + "$operationName-request" + } else { + "$operationName-request.$expression" + } + return executionServiceInput.payload.jsonPathParse(".$requestExpression") + } + fun artifactContent(artifactName: String): String { return bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactName) } diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt index 07be8c809..24696b456 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt @@ -70,9 +70,6 @@ class AbstractComponentFunctionTest { every { blueprintContext.rootPath } returns normalizedPathName("target") } - /** - * Tests the abstract component functionality. - */ @Test fun testAbstractComponent() { runBlocking { @@ -95,9 +92,6 @@ class AbstractComponentFunctionTest { } } - /** - * Tests the abstract script component functionality. - */ @Test fun testAbstractScriptComponent() { runBlocking { @@ -190,5 +184,6 @@ class AbstractComponentFunctionTest { val componentScriptExecutor = BluePrintTypes.nodeTypeComponentScriptExecutor() assertNotNull(componentScriptExecutor.interfaces, "failed to get interface operations") } + } 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 b74b7e4cf..1aaf9d8a4 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 @@ -175,7 +175,7 @@ fun ArrayNode.asListOfString(): List { fun JsonNode.asType(clazzType: Class): T { return JacksonUtils.readValue(this, clazzType) - ?: throw BluePrintException("couldn't convert JsonNode of type $clazzType") + ?: throw BluePrintException("couldn't convert JsonNode of type $clazzType") } fun JsonNode.asListOfString(): List { @@ -183,20 +183,17 @@ fun JsonNode.asListOfString(): List { return this.asListOfString() } -fun JsonNode.returnNullIfMissing(): JsonNode? { - return if (this is NullNode || this is MissingNode) { +fun T?.returnNullIfMissing(): JsonNode? { + return if (this == null || this is NullNode || this is MissingNode) { null - } else this + } + else this } -fun T?.isNull(): Boolean { +fun T?.isNullOrMissing(): Boolean { return this == null || this is NullNode || this is MissingNode } -fun T?.isNotNull(): Boolean { - return !(this == null || this is NullNode || this is MissingNode) -} - /** * Convert Json to map of json node, the root fields will be map keys */ 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 ba210df10..f7b512153 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 @@ -62,9 +62,11 @@ interface BluePrintRuntimeService { fun loadEnvironments(type: String, fileName: String) - fun resolveNodeTemplatePropertyAssignments(nodeTemplateName: String, - propertyDefinitions: MutableMap, - propertyAssignments: MutableMap): MutableMap + fun resolveNodeTemplatePropertyAssignments( + nodeTemplateName: String, + propertyDefinitions: MutableMap, + propertyAssignments: MutableMap + ): MutableMap fun resolvePropertyDefinitions(name: String, propertyDefinitions: MutableMap) : MutableMap @@ -77,11 +79,15 @@ interface BluePrintRuntimeService { fun resolveNodeTemplateCapabilityProperties(nodeTemplateName: String, capabilityName: String): MutableMap - fun resolveNodeTemplateInterfaceOperationInputs(nodeTemplateName: String, interfaceName: String, - operationName: String): MutableMap + fun resolveNodeTemplateInterfaceOperationInputs( + nodeTemplateName: String, interfaceName: String, + operationName: String + ): MutableMap - fun resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName: String, interfaceName: String, - operationName: String): MutableMap + fun resolveNodeTemplateInterfaceOperationOutputs( + nodeTemplateName: String, interfaceName: String, + operationName: String + ): MutableMap fun resolveNodeTemplateArtifact(nodeTemplateName: String, artifactName: String): String @@ -89,28 +95,38 @@ interface BluePrintRuntimeService { fun resolveDSLExpression(dslPropertyName: String): JsonNode - fun setInputValue(propertyName: String, propertyDefinition: PropertyDefinition, value: JsonNode) + fun setInputValue(propertyName: String, value: JsonNode) - fun setWorkflowInputValue(workflowName: String, propertyName: String, propertyDefinition: PropertyDefinition, - value: JsonNode) + fun setWorkflowInputValue( + workflowName: String, propertyName: String, propertyDefinition: PropertyDefinition, + value: JsonNode + ) fun setNodeTemplatePropertyValue(nodeTemplateName: String, propertyName: String, value: JsonNode) fun setNodeTemplateAttributeValue(nodeTemplateName: String, attributeName: String, value: JsonNode) - fun setNodeTemplateOperationPropertyValue(nodeTemplateName: String, interfaceName: String, - operationName: String, propertyName: String, value: JsonNode) + fun setNodeTemplateOperationPropertyValue( + nodeTemplateName: String, interfaceName: String, + operationName: String, propertyName: String, value: JsonNode + ) - fun setNodeTemplateOperationInputValue(nodeTemplateName: String, interfaceName: String, - operationName: String, propertyName: String, value: JsonNode) + fun setNodeTemplateOperationInputValue( + nodeTemplateName: String, interfaceName: String, + operationName: String, propertyName: String, value: JsonNode + ) - fun setNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, - operationName: String, propertyName: String, value: JsonNode) + fun setNodeTemplateOperationOutputValue( + nodeTemplateName: String, interfaceName: String, + operationName: String, propertyName: String, value: JsonNode + ) fun getInputValue(propertyName: String): JsonNode - fun getNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, - operationName: String, propertyName: String): JsonNode + fun getNodeTemplateOperationOutputValue( + nodeTemplateName: String, interfaceName: String, + operationName: String, propertyName: String + ): JsonNode fun getNodeTemplatePropertyValue(nodeTemplateName: String, propertyName: String): JsonNode? @@ -130,8 +146,8 @@ interface BluePrintRuntimeService { * * @author Brinda Santh */ -open class DefaultBluePrintRuntimeService(private var id: String, private var bluePrintContext: BluePrintContext) - : BluePrintRuntimeService> { +open class DefaultBluePrintRuntimeService(private var id: String, private var bluePrintContext: BluePrintContext) : + BluePrintRuntimeService> { @Transient private val log = LoggerFactory.getLogger(BluePrintRuntimeService::class.toString()) @@ -145,7 +161,7 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl * Load Blueprint Environments Properties */ val absoluteEnvFilePath = bluePrintContext.rootPath.plus(File.separator) - .plus(BluePrintConstants.TOSCA_ENVIRONMENTS_DIR) + .plus(BluePrintConstants.TOSCA_ENVIRONMENTS_DIR) loadEnvironments(BluePrintConstants.PROPERTY_BPP, absoluteEnvFilePath) } @@ -220,9 +236,11 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl /** * Resolve any property assignments for the node */ - override fun resolveNodeTemplatePropertyAssignments(nodeTemplateName: String, - propertyDefinitions: MutableMap, - propertyAssignments: MutableMap) + override fun resolveNodeTemplatePropertyAssignments( + nodeTemplateName: String, + propertyDefinitions: MutableMap, + propertyAssignments: MutableMap + ) : MutableMap { val propertyAssignmentValue: MutableMap = hashMapOf() @@ -235,8 +253,8 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl if (propertyAssignment != null) { // Resolve the Expressing val propertyAssignmentExpression = PropertyAssignmentService(this) - resolvedValue = propertyAssignmentExpression.resolveAssignmentExpression(nodeTemplateName, - nodeTypePropertyName, propertyAssignment) + resolvedValue = propertyAssignmentExpression.resolveAssignmentExpression( + nodeTemplateName, nodeTypePropertyName, propertyAssignment) } // Set default value if null @@ -258,8 +276,8 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl val propertyAssignmentExpression = PropertyAssignmentService(this) val expression = propertyDefinition.value ?: propertyDefinition.defaultValue if (expression != null) { - propertyAssignmentValue[propertyName] = propertyAssignmentExpression.resolveAssignmentExpression(name, - propertyName, expression) + propertyAssignmentValue[propertyName] = + propertyAssignmentExpression.resolveAssignmentExpression(name, propertyName, expression) } } return propertyAssignmentValue @@ -267,13 +285,12 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl override fun resolvePropertyAssignments(name: String, propertyAssignments: MutableMap) : MutableMap { - val propertyAssignmentValue: MutableMap = hashMapOf() - propertyAssignments.forEach { propertyName, propertyExpression -> + propertyAssignments.forEach { (propertyName, propertyExpression) -> val propertyAssignmentExpression = PropertyAssignmentService(this) - propertyAssignmentValue[propertyName] = propertyAssignmentExpression.resolveAssignmentExpression(name, - propertyName, propertyExpression) + propertyAssignmentValue[propertyName] = + propertyAssignmentExpression.resolveAssignmentExpression(name, propertyName, propertyExpression) } return propertyAssignmentValue } @@ -286,84 +303,86 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl val propertyAssignments: MutableMap = nodeTemplate.properties!! // Get the Node Type Definitions - val nodeTypePropertieDefinitions: MutableMap = bluePrintContext - .nodeTypeChainedProperties(nodeTemplate.type)!! + val nodeTypePropertiesDefinitions: MutableMap = bluePrintContext + .nodeTypeChainedProperties(nodeTemplate.type)!! /** * Resolve the NodeTemplate Property Assignment Values. */ - return resolveNodeTemplatePropertyAssignments(nodeTemplateName, nodeTypePropertieDefinitions, - propertyAssignments) + return resolveNodeTemplatePropertyAssignments(nodeTemplateName, nodeTypePropertiesDefinitions, propertyAssignments) } override fun resolveNodeTemplateCapabilityProperties(nodeTemplateName: String, capabilityName: String): MutableMap { - log.info("resolveNodeTemplateCapabilityProperties for node template($nodeTemplateName) capability " + - "($capabilityName)") + log.info("resolveNodeTemplateCapabilityProperties for node template($nodeTemplateName) capability($capabilityName)") val nodeTemplate: NodeTemplate = bluePrintContext.nodeTemplateByName(nodeTemplateName) val propertyAssignments = nodeTemplate.capabilities?.get(capabilityName)?.properties ?: hashMapOf() val propertyDefinitions = bluePrintContext.nodeTemplateNodeType(nodeTemplateName) - .capabilities?.get(capabilityName)?.properties ?: hashMapOf() + .capabilities?.get(capabilityName)?.properties ?: hashMapOf() /** * Resolve the Capability Property Assignment Values. */ - return resolveNodeTemplatePropertyAssignments(nodeTemplateName, propertyDefinitions, - propertyAssignments) + return resolveNodeTemplatePropertyAssignments(nodeTemplateName, propertyDefinitions, propertyAssignments) } - override fun resolveNodeTemplateInterfaceOperationInputs(nodeTemplateName: String, - interfaceName: String, - operationName: String): MutableMap { - log.info("resolveNodeTemplateInterfaceOperationInputs for node template ($nodeTemplateName),interface name " + - "($interfaceName), operationName($operationName)") + override fun resolveNodeTemplateInterfaceOperationInputs( + nodeTemplateName: String, + interfaceName: String, + operationName: String + ): MutableMap { + log.info("resolveNodeTemplateInterfaceOperationInputs for node template ($nodeTemplateName), " + + "interface name($interfaceName), operationName($operationName)") val propertyAssignments: MutableMap = - bluePrintContext.nodeTemplateInterfaceOperationInputs(nodeTemplateName, interfaceName, operationName) - ?: hashMapOf() + bluePrintContext.nodeTemplateInterfaceOperationInputs(nodeTemplateName, interfaceName, operationName) + ?: hashMapOf() val nodeTypeName = bluePrintContext.nodeTemplateByName(nodeTemplateName).type val nodeTypeInterfaceOperationInputs: MutableMap = - bluePrintContext.nodeTypeInterfaceOperationInputs(nodeTypeName, interfaceName, operationName) - ?: hashMapOf() + bluePrintContext.nodeTypeInterfaceOperationInputs(nodeTypeName, interfaceName, operationName) + ?: hashMapOf() log.info("input definition for node template ($nodeTemplateName), values ($propertyAssignments)") /** * Resolve the Property Input Assignment Values. */ - return resolveNodeTemplatePropertyAssignments(nodeTemplateName, nodeTypeInterfaceOperationInputs, - propertyAssignments) + return resolveNodeTemplatePropertyAssignments(nodeTemplateName, nodeTypeInterfaceOperationInputs, propertyAssignments) } - override fun resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName: String, - interfaceName: String, - operationName: String): MutableMap { - log.info("resolveNodeTemplateInterfaceOperationOutputs for node template ($nodeTemplateName),interface name " + - "($interfaceName), operationName($operationName)") + override fun resolveNodeTemplateInterfaceOperationOutputs( + nodeTemplateName: String, + interfaceName: String, + operationName: String + ): MutableMap { + log.info( + "resolveNodeTemplateInterfaceOperationOutputs for node template ($nodeTemplateName),interface name " + + "($interfaceName), operationName($operationName)" + ) val propertyAssignments: MutableMap = - bluePrintContext.nodeTemplateInterfaceOperationOutputs(nodeTemplateName, interfaceName, operationName) - ?: hashMapOf() + bluePrintContext.nodeTemplateInterfaceOperationOutputs(nodeTemplateName, interfaceName, operationName) + ?: hashMapOf() val nodeTypeName = bluePrintContext.nodeTemplateByName(nodeTemplateName).type val nodeTypeInterfaceOperationOutputs: MutableMap = - bluePrintContext.nodeTypeInterfaceOperationOutputs(nodeTypeName, interfaceName, operationName) - ?: hashMapOf() + bluePrintContext.nodeTypeInterfaceOperationOutputs(nodeTypeName, interfaceName, operationName) + ?: hashMapOf() /** * Resolve the Property Output Assignment Values. */ - val propertyAssignmentValue = resolveNodeTemplatePropertyAssignments(nodeTemplateName, - nodeTypeInterfaceOperationOutputs, propertyAssignments) + val propertyAssignmentValue = + resolveNodeTemplatePropertyAssignments(nodeTemplateName,nodeTypeInterfaceOperationOutputs, propertyAssignments) // Store operation output values into context - propertyAssignmentValue.forEach { key, value -> + propertyAssignmentValue.forEach { (key, value) -> setNodeTemplateOperationOutputValue(nodeTemplateName, interfaceName, operationName, key, value) } return propertyAssignmentValue @@ -371,19 +390,20 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl override fun resolveNodeTemplateArtifact(nodeTemplateName: String, artifactName: String): String { val artifactDefinition: ArtifactDefinition = - resolveNodeTemplateArtifactDefinition(nodeTemplateName, artifactName) + resolveNodeTemplateArtifactDefinition(nodeTemplateName, artifactName) val propertyAssignmentExpression = PropertyAssignmentService(this) return propertyAssignmentExpression.artifactContent(artifactDefinition) } - override fun resolveNodeTemplateArtifactDefinition(nodeTemplateName: String, - artifactName: String): ArtifactDefinition { + override fun resolveNodeTemplateArtifactDefinition( + nodeTemplateName: String, + artifactName: String + ): ArtifactDefinition { val nodeTemplate = bluePrintContext.nodeTemplateByName(nodeTemplateName) return nodeTemplate.artifacts?.get(artifactName) - ?: throw BluePrintProcessorException("failed to get artifact definition($artifactName) from the node " + - "template") - + ?: throw BluePrintProcessorException( + "failed to get artifact definition($artifactName) from the node template") } /** @@ -393,14 +413,14 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl override fun resolveDSLExpression(dslPropertyName: String): JsonNode { val propertyAssignments = bluePrintContext.dslPropertiesByName(dslPropertyName) return if (BluePrintExpressionService.checkContainsExpression(propertyAssignments) - && propertyAssignments is ObjectNode) { + && propertyAssignments is ObjectNode) { val rootKeyMap = propertyAssignments.rootFieldsToMap() val propertyAssignmentValue: MutableMap = hashMapOf() - rootKeyMap.forEach { propertyName, propertyValue -> + rootKeyMap.forEach { (propertyName, propertyValue) -> val propertyAssignmentExpression = PropertyAssignmentService(this) propertyAssignmentValue[propertyName] = propertyAssignmentExpression - .resolveAssignmentExpression("DSL", propertyName, propertyValue) + .resolveAssignmentExpression("DSL", propertyName, propertyValue) } propertyAssignmentValue.asJsonNode() } else { @@ -408,120 +428,127 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl } } - override fun setInputValue(propertyName: String, propertyDefinition: PropertyDefinition, value: JsonNode) { - val path = StringBuilder(BluePrintConstants.PATH_INPUTS) - .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + override fun setInputValue(propertyName: String, value: JsonNode) { + val path = """${BluePrintConstants.PATH_INPUTS}${BluePrintConstants.PATH_DIVIDER}${propertyName}""" log.trace("setting input path ({}), values ({})", path, value) put(path, value) } - override fun setWorkflowInputValue(workflowName: String, propertyName: String, - propertyDefinition: PropertyDefinition, value: JsonNode) { + override fun setWorkflowInputValue( + workflowName: String, propertyName: String, + propertyDefinition: PropertyDefinition, value: JsonNode + ) { val path: String = StringBuilder(BluePrintConstants.PATH_NODE_WORKFLOWS) - .append(BluePrintConstants.PATH_DIVIDER).append(workflowName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INPUTS) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) - .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + .append(BluePrintConstants.PATH_DIVIDER).append(workflowName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() put(path, value) } override fun setNodeTemplatePropertyValue(nodeTemplateName: String, propertyName: String, value: JsonNode) { - val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES) - .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) - .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() put(path, value) } override fun setNodeTemplateAttributeValue(nodeTemplateName: String, attributeName: String, value: JsonNode) { - val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES) - .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_ATTRIBUTES) - .append(BluePrintConstants.PATH_DIVIDER).append(attributeName).toString() + .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_ATTRIBUTES) + .append(BluePrintConstants.PATH_DIVIDER).append(attributeName).toString() put(path, value) } - override fun setNodeTemplateOperationPropertyValue(nodeTemplateName: String, interfaceName: String, - operationName: String, propertyName: String, - value: JsonNode) { + override fun setNodeTemplateOperationPropertyValue( + nodeTemplateName: String, interfaceName: String, + operationName: String, propertyName: String, + value: JsonNode + ) { val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES) - .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES) - .append(BluePrintConstants.PATH_DIVIDER).append(interfaceName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS) - .append(BluePrintConstants.PATH_DIVIDER).append(operationName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) - .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES) + .append(BluePrintConstants.PATH_DIVIDER).append(interfaceName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS) + .append(BluePrintConstants.PATH_DIVIDER).append(operationName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() log.trace("setting operation property path ({}), values ({})", path, value) put(path, value) } - override fun setNodeTemplateOperationInputValue(nodeTemplateName: String, interfaceName: String, - operationName: String, propertyName: String, - value: JsonNode) { + override fun setNodeTemplateOperationInputValue( + nodeTemplateName: String, interfaceName: String, + operationName: String, propertyName: String, + value: JsonNode + ) { val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES) - .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES) - .append(BluePrintConstants.PATH_DIVIDER).append(interfaceName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS) - .append(BluePrintConstants.PATH_DIVIDER).append(operationName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INPUTS) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) - .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES) + .append(BluePrintConstants.PATH_DIVIDER).append(interfaceName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS) + .append(BluePrintConstants.PATH_DIVIDER).append(operationName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() put(path, value) } - override fun setNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, - operationName: String, propertyName: String, - value: JsonNode) { + override fun setNodeTemplateOperationOutputValue( + nodeTemplateName: String, interfaceName: String, + operationName: String, propertyName: String, + value: JsonNode + ) { val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES) - .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES) - .append(BluePrintConstants.PATH_DIVIDER).append(interfaceName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS) - .append(BluePrintConstants.PATH_DIVIDER).append(operationName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OUTPUTS) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) - .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES) + .append(BluePrintConstants.PATH_DIVIDER).append(interfaceName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS) + .append(BluePrintConstants.PATH_DIVIDER).append(operationName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OUTPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() put(path, value) } override fun getInputValue(propertyName: String): JsonNode { val path = StringBuilder(BluePrintConstants.PATH_INPUTS) - .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() return getJsonNode(path) } - override fun getNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, - operationName: String, propertyName: String): JsonNode { + override fun getNodeTemplateOperationOutputValue( + nodeTemplateName: String, interfaceName: String, + operationName: String, propertyName: String + ): JsonNode { val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES) - .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES) - .append(BluePrintConstants.PATH_DIVIDER).append(interfaceName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS) - .append(BluePrintConstants.PATH_DIVIDER).append(operationName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OUTPUTS) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) - .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES) + .append(BluePrintConstants.PATH_DIVIDER).append(interfaceName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS) + .append(BluePrintConstants.PATH_DIVIDER).append(operationName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OUTPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() return getJsonNode(path) } override fun getNodeTemplatePropertyValue(nodeTemplateName: String, propertyName: String): JsonNode { val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES) - .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) - .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() return getJsonNode(path) } override fun getNodeTemplateAttributeValue(nodeTemplateName: String, attributeName: String): JsonNode { val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES) - .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_ATTRIBUTES) - .append(BluePrintConstants.PATH_DIVIDER).append(attributeName).toString() + .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_ATTRIBUTES) + .append(BluePrintConstants.PATH_DIVIDER).append(attributeName).toString() return getJsonNode(path) } @@ -529,38 +556,37 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl log.info("assignInputs from input JSON ({})", jsonNode.toString()) bluePrintContext.inputs()?.forEach { propertyName, property -> val valueNode: JsonNode = jsonNode.at(BluePrintConstants.PATH_DIVIDER + propertyName) - ?: NullNode.getInstance() - setInputValue(propertyName, property, valueNode) + ?: property.defaultValue + ?: NullNode.getInstance() + setInputValue(propertyName, valueNode) } } override fun assignWorkflowInputs(workflowName: String, jsonNode: JsonNode) { - log.info("assign workflow {} input value ({})", workflowName, jsonNode.toString()) - + log.info("For workflow ($workflowName) driving input data from (${jsonNode})") val dynamicInputPropertiesName = "$workflowName-properties" - bluePrintContext.workflowByName(workflowName).inputs?.forEach { propertyName, property -> + bluePrintContext.workflowByName(workflowName).inputs?. + forEach { propertyName, property -> if (propertyName != dynamicInputPropertiesName) { - val valueNode: JsonNode = jsonNode - .at(BluePrintConstants.PATH_DIVIDER + propertyName).returnNullIfMissing() + val valueNode: JsonNode = + jsonNode.at(BluePrintConstants.PATH_DIVIDER + propertyName).returnNullIfMissing() ?: property.defaultValue ?: NullNode.getInstance() - setInputValue(propertyName, property, valueNode) + log.trace("Setting input data - attribute:($propertyName) value:($valueNode)") + setInputValue(propertyName, valueNode) } } // Load Dynamic data Types - val workflowDynamicInputs: JsonNode? = jsonNode.get(dynamicInputPropertiesName) - - workflowDynamicInputs?.let { - bluePrintContext.dataTypeByName("dt-$dynamicInputPropertiesName") - ?.properties?.forEach { propertyName, property -> + jsonNode.get(dynamicInputPropertiesName)?.let { + bluePrintContext.dataTypeByName("dt-$dynamicInputPropertiesName")?.properties?. + forEach { propertyName, property -> val valueNode: JsonNode = - workflowDynamicInputs - .at(BluePrintConstants.PATH_DIVIDER + propertyName).returnNullIfMissing() - ?: property.defaultValue - ?: NullNode.getInstance() - setInputValue(propertyName, property, valueNode) - + it.at(BluePrintConstants.PATH_DIVIDER + propertyName).returnNullIfMissing() + ?: property.defaultValue + ?: NullNode.getInstance() + log.trace("Setting input data - attribute:($propertyName) value:($valueNode)") + setInputValue(propertyName, valueNode) } } } @@ -575,9 +601,9 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl val jsonNode: ObjectNode = jacksonObjectMapper().createObjectNode() val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES) - .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_ATTRIBUTES) - .append(BluePrintConstants.PATH_DIVIDER).toString() + .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_ATTRIBUTES) + .append(BluePrintConstants.PATH_DIVIDER).toString() store.keys.filter { it.startsWith(path) }.map { diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctionsTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctionsTest.kt index 487b1d15b..76be647f1 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctionsTest.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctionsTest.kt @@ -129,6 +129,32 @@ class CustomFunctionsTest { assertNull(missingValue) } + @Test + fun testIsNullOrMissing() { + assertTrue(NullNode.instance.isNullOrMissing()) + assertTrue(MissingNode.getInstance().isNullOrMissing()) + + assertFalse(TextNode("").isNullOrMissing()) + assertFalse("".asJsonType().isNullOrMissing()) + assertFalse("hello".asJsonType().isNullOrMissing()) + assertFalse("{\"key\": \"value\"}".asJsonType().isNullOrMissing()) + assertFalse(TextNode("hello").isNullOrMissing()) + } + + @Test + fun testIsComplexType() { + assertFalse(NullNode.instance.isComplexType()) + assertFalse(MissingNode.getInstance().isComplexType()) + + assertFalse(TextNode("").isComplexType()) + assertFalse("".asJsonType().isComplexType()) + assertFalse("hello".asJsonType().isComplexType()) + assertFalse(TextNode("hello").isComplexType()) + + assertTrue("{\"key\": \"value\"}".asJsonType().isComplexType()) + assertTrue("[{\"key\": \"value\"},{\"key\": \"value\"}]".asJsonType().isComplexType()) + } + @Test(expected = BluePrintException::class) fun testRootFieldsToMap() { 1.asJsonType().rootFieldsToMap() diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt index 9103af3fa..bef1c4570 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt @@ -146,8 +146,7 @@ class BluePrintRuntimeServiceTest { val bluePrintRuntimeService = getBluePrintRuntimeService() - bluePrintRuntimeService.setInputValue("rest-user-name", PropertyDefinition(), "sample-username" - .asJsonPrimitive()) + bluePrintRuntimeService.setInputValue("rest-user-name", "sample-username".asJsonPrimitive()) val resolvedJsonNode: JsonNode = bluePrintRuntimeService.resolveDSLExpression("dynamic-rest-source") assertNotNull(resolvedJsonNode, "Failed to populate dsl property values") diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt index c222de9e5..f1e0d2c86 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt @@ -84,15 +84,16 @@ open class ResourceAssignment { var updatedBy: String? = null override fun toString(): String { - return StringBuilder() - .append("[") - .append("name=", name) - .append(", status=", status) - .append(", property=", property?.value ?: "") - .append(", dictionaryName=", dictionaryName) - .append(", dictionarySource=", dictionarySource) - .append("]") - .toString() + return """ + [ + name = $name + status = $status + required = ${property?.required} + dependencies = $dependencies + dictionaryName = $dictionaryName + dictionarySource = $dictionarySource + ] + """.trimIndent() } } diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt index 60fe6a705..cd887bf54 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt @@ -35,7 +35,7 @@ object BulkResourceSequencingUtils { fun process(resourceAssignments: MutableList): List> { val resourceAssignmentMap: MutableMap = hashMapOf() val sequenceBatchResourceAssignment = ArrayList>() - log.info("Assignments ({})", resourceAssignments) + log.trace("Assignments ({})", resourceAssignments) // Prepare Map resourceAssignments.forEach { resourceAssignment -> log.trace("Processing Key ({})", resourceAssignment.name) @@ -64,7 +64,7 @@ object BulkResourceSequencingUtils { } val sequencedResourceAssignments: MutableList = topologySorting.topSort()!! as MutableList - log.info("Sorted Sequenced Assignments ({})", sequencedResourceAssignments) + log.trace("Sorted Sequenced Assignments ({})", sequencedResourceAssignments) var batchResourceAssignment: MutableList? = null var batchAssignmentName: MutableList? = null -- cgit 1.2.3-korg