From b86beb3f274449b7b6a50c1ed1e141d7d5704b5f Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Thu, 21 Mar 2019 15:56:38 -0400 Subject: Add workflow output resolution Change-Id: I3d5bb339fd07257e86ada85e4a30040183808848 Issue-ID: CCSDK-1175 Signed-off-by: Muthuramalingam, Brinda Santh --- .../core/FileExtensionFunctions.kt | 6 +-- .../core/data/BluePrintModel.kt | 6 ++- .../core/service/BluePrintRuntimeService.kt | 44 +++++++++++++++++++++- .../core/service/BluePrintRuntimeServiceTest.kt | 16 +++++++- 4 files changed, 65 insertions(+), 7 deletions(-) (limited to 'ms/controllerblueprints/modules/blueprint-core') diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt index 11553ba6..ff896ba9 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt @@ -65,8 +65,8 @@ fun File.deCompress(targetFile: File): File { return targetFile } -fun deleteDir(path: String) { - normalizedFile(path).deleteRecursively() +fun deleteDir(path: String, vararg more: String?) { + normalizedFile(path, *more).deleteRecursively() } fun normalizedFile(path: String, vararg more: String?): File { @@ -78,6 +78,6 @@ fun normalizedPath(path: String, vararg more: String?): Path { } fun normalizedPathName(path: String, vararg more: String?): String { - return normalizedPath(path, *more).toUri().path + return normalizedPath(path, *more).toString() } diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt index aab4e7c7..56acf612 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt @@ -1,6 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. + * Modifications Copyright © 2018-2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -163,7 +163,8 @@ class PropertyDefinition { var constraints: MutableList? = null @get:JsonProperty("entry_schema") var entrySchema: EntrySchema? = null - @get:ApiModelProperty(notes = "Property Value, It may be raw JSON or primitive data type values") + // Mainly used in Workflow Outputs + @get:ApiModelProperty(notes = "Property Value, It may be Expression or Json type values") var value: JsonNode? = null } @@ -565,6 +566,7 @@ class Workflow { var steps: MutableMap? = null var preconditions: ArrayList? = null var inputs: MutableMap? = null + var outputs: MutableMap? = null } diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt index c16d1ecc..7958adf7 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt @@ -1,6 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. + * Modifications Copyright © 2018-2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,6 +67,12 @@ interface BluePrintRuntimeService { propertyDefinitions: MutableMap, propertyAssignments: MutableMap): MutableMap + fun resolvePropertyDefinitions(name: String, propertyDefinitions: MutableMap) + : MutableMap + + fun resolvePropertyAssignments(name: String, propertyAssignments: MutableMap) + : MutableMap + fun resolveNodeTemplateProperties(nodeTemplateName: String): MutableMap fun resolveNodeTemplateCapabilityProperties(nodeTemplateName: String, capabilityName: String): MutableMap { fun assignWorkflowInputs(workflowName: String, jsonNode: JsonNode) + fun resolveWorkflowOutputs(workflowName: String): MutableMap + fun getJsonForNodeTemplateAttributeProperties(nodeTemplateName: String, keys: List): JsonNode } @@ -242,6 +250,34 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl return propertyAssignmentValue } + override fun resolvePropertyDefinitions(name: String, propertyDefinitions: MutableMap) + : MutableMap { + val propertyAssignmentValue: MutableMap = hashMapOf() + + propertyDefinitions.forEach { propertyName, propertyDefinition -> + val propertyAssignmentExpression = PropertyAssignmentService(this) + val expression = propertyDefinition.value ?: propertyDefinition.defaultValue + if (expression != null) { + propertyAssignmentValue[propertyName] = propertyAssignmentExpression.resolveAssignmentExpression(name, + propertyName, expression) + } + } + return propertyAssignmentValue + } + + override fun resolvePropertyAssignments(name: String, propertyAssignments: MutableMap) + : MutableMap { + + val propertyAssignmentValue: MutableMap = hashMapOf() + + propertyAssignments.forEach { propertyName, propertyExpression -> + val propertyAssignmentExpression = PropertyAssignmentService(this) + propertyAssignmentValue[propertyName] = propertyAssignmentExpression.resolveAssignmentExpression(name, + propertyName, propertyExpression) + } + return propertyAssignmentValue + } + override fun resolveNodeTemplateProperties(nodeTemplateName: String): MutableMap { log.info("resolveNodeTemplatePropertyValues for node template ({})", nodeTemplateName) @@ -520,6 +556,12 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl } } + override fun resolveWorkflowOutputs(workflowName: String): MutableMap { + log.info("resolveWorkflowOutputs for workflow($workflowName)") + val outputs = bluePrintContext.workflowByName(workflowName).outputs ?: mutableMapOf() + return resolvePropertyDefinitions("WORKFLOW", outputs) + } + override fun getJsonForNodeTemplateAttributeProperties(nodeTemplateName: String, keys: List): JsonNode { val jsonNode: ObjectNode = jacksonObjectMapper().createObjectNode() diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt index c0bfd0f5..dc56b520 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt @@ -1,6 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. + * Modifications Copyright © 2018-2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -153,6 +153,20 @@ class BluePrintRuntimeServiceTest { assertNotNull(resolvedJsonNode, "Failed to populate dsl property values") } + @Test + fun `test Resolve Workflow Outputs`() { + log.info("************************ resolvePropertyAssignments **********************") + val bluePrintRuntimeService = getBluePrintRuntimeService() + + val assignmentParams = "{\"ipAddress\": \"127.0.0.1\", \"hostName\": \"vnf-host\"}" + + bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params", + JacksonUtils.jsonNode(assignmentParams)) + + val resolvedJsonNode = bluePrintRuntimeService.resolveWorkflowOutputs("resource-assignment") + assertNotNull(resolvedJsonNode, "Failed to populate workflow output property values") + } + private fun getBluePrintRuntimeService(): BluePrintRuntimeService> { val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") val blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath) -- cgit 1.2.3-korg