diff options
author | Dan Timoney <dtimoney@att.com> | 2019-03-18 18:29:40 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-03-18 18:29:40 +0000 |
commit | 2a1364a0df3906ec6810187d308d876eb71a501a (patch) | |
tree | 9eac52d501a5319f112729bb7b15535a907c2157 /ms/controllerblueprints/modules | |
parent | fcfc57138b81b220d729392d3241a14ead418e5a (diff) | |
parent | 06484d350655bea2da849e4d21dc9aeca10ccde9 (diff) |
Merge "Add workflow node template enrichment"
Diffstat (limited to 'ms/controllerblueprints/modules')
9 files changed, 68 insertions, 40 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt index e2211f7e4..ca86c9646 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt @@ -44,15 +44,15 @@ class BluePrintContext(val serviceTemplate: ServiceTemplate) { */ var entryDefinition = "" - val imports: List<ImportDefinition>? = serviceTemplate.imports + fun imports(): List<ImportDefinition>? = serviceTemplate.imports - val dslDefinitions = serviceTemplate.dslDefinitions + fun dslDefinitions() = serviceTemplate.dslDefinitions val metadata: MutableMap<String, String>? = serviceTemplate.metadata - val dataTypes: MutableMap<String, DataType>? = serviceTemplate.dataTypes + fun dataTypes(): MutableMap<String, DataType>? = serviceTemplate.dataTypes - val inputs: MutableMap<String, PropertyDefinition>? = serviceTemplate.topologyTemplate?.inputs + fun inputs(): MutableMap<String, PropertyDefinition>? = serviceTemplate.topologyTemplate?.inputs fun blueprintJson(pretty: Boolean = false): String = print("json", pretty) @@ -70,9 +70,9 @@ class BluePrintContext(val serviceTemplate: ServiceTemplate) { ?: throw BluePrintException("could't get template author from meta data") // Workflow - val workflows: MutableMap<String, Workflow>? = serviceTemplate.topologyTemplate?.workflows + fun workflows(): MutableMap<String, Workflow>? = serviceTemplate.topologyTemplate?.workflows - fun workflowByName(workFlowName: String): Workflow = workflows?.get(workFlowName) + fun workflowByName(workFlowName: String): Workflow = workflows()?.get(workFlowName) ?: throw BluePrintException("could't get workflow($workFlowName)") fun workflowInputs(workFlowName: String) = workflowByName(workFlowName).inputs @@ -99,27 +99,27 @@ class BluePrintContext(val serviceTemplate: ServiceTemplate) { } // DSL - fun dslPropertiesByName(name: String): JsonNode = dslDefinitions?.get(name) + fun dslPropertiesByName(name: String): JsonNode = dslDefinitions()?.get(name) ?: throw BluePrintException("could't get policy type for the dsl($name)") // Data Type - fun dataTypeByName(name: String): DataType? = dataTypes?.get(name) + fun dataTypeByName(name: String): DataType? = dataTypes()?.get(name) // Artifact Type - val artifactTypes: MutableMap<String, ArtifactType>? = serviceTemplate.artifactTypes + fun artifactTypes(): MutableMap<String, ArtifactType>? = serviceTemplate.artifactTypes // Policy Types - val policyTypes: MutableMap<String, PolicyType>? = serviceTemplate.policyTypes + fun policyTypes(): MutableMap<String, PolicyType>? = serviceTemplate.policyTypes - fun policyTypeByName(policyName: String) = policyTypes?.get(policyName) + fun policyTypeByName(policyName: String) = policyTypes()?.get(policyName) ?: throw BluePrintException("could't get policy type for the name($policyName)") fun policyTypesDerivedFrom(name: String): MutableMap<String, PolicyType>? { - return policyTypes?.filterValues { policyType -> policyType.derivedFrom == name }?.toMutableMap() + return policyTypes()?.filterValues { policyType -> policyType.derivedFrom == name }?.toMutableMap() } fun policyTypesTarget(target: String): MutableMap<String, PolicyType>? { - return policyTypes?.filterValues { it.targets.contains(target) }?.toMutableMap() + return policyTypes()?.filterValues { it.targets.contains(target) }?.toMutableMap() } fun policyTypesTargetNDerivedFrom(target: String, derivedFrom: String): MutableMap<String, PolicyType>? { @@ -129,14 +129,14 @@ class BluePrintContext(val serviceTemplate: ServiceTemplate) { } // Node Type Methods - val nodeTypes: MutableMap<String, NodeType>? = serviceTemplate.nodeTypes + fun nodeTypes(): MutableMap<String, NodeType>? = serviceTemplate.nodeTypes fun nodeTypeByName(name: String): NodeType = - nodeTypes?.get(name) + nodeTypes()?.get(name) ?: throw BluePrintException("could't get node type for the name($name)") fun nodeTypeDerivedFrom(name: String): MutableMap<String, NodeType>? { - return nodeTypes?.filterValues { nodeType -> nodeType.derivedFrom == name }?.toMutableMap() + return nodeTypes()?.filterValues { nodeType -> nodeType.derivedFrom == name }?.toMutableMap() } fun nodeTypeInterface(nodeTypeName: String, interfaceName: String): InterfaceDefinition { @@ -163,13 +163,13 @@ class BluePrintContext(val serviceTemplate: ServiceTemplate) { } // Node Template Methods - val nodeTemplates: MutableMap<String, NodeTemplate>? = serviceTemplate.topologyTemplate?.nodeTemplates + fun nodeTemplates(): MutableMap<String, NodeTemplate>? = serviceTemplate.topologyTemplate?.nodeTemplates fun nodeTemplateByName(name: String): NodeTemplate = - nodeTemplates?.get(name) ?: throw BluePrintException("could't get node template for the name($name)") + nodeTemplates()?.get(name) ?: throw BluePrintException("could't get node template for the name($name)") fun nodeTemplateForNodeType(name: String): MutableMap<String, NodeTemplate>? { - return nodeTemplates?.filterValues { nodeTemplate -> nodeTemplate.type == name }?.toMutableMap() + return nodeTemplates()?.filterValues { nodeTemplate -> nodeTemplate.type == name }?.toMutableMap() } fun nodeTemplateNodeType(nodeTemplateName: String): NodeType { 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 c58280732..c16d1ecc6 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 @@ -488,7 +488,7 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl override fun assignInputs(jsonNode: JsonNode) { log.info("assignInputs from input JSON ({})", jsonNode.toString()) - bluePrintContext.inputs?.forEach { propertyName, property -> + bluePrintContext.inputs()?.forEach { propertyName, property -> val valueNode: JsonNode = jsonNode.at(BluePrintConstants.PATH_DIVIDER + propertyName) ?: NullNode.getInstance() setInputValue(propertyName, property, valueNode) diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt index c37d8eeaa..d20fc5530 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt @@ -49,7 +49,7 @@ object BluePrintRuntimeUtils { fun assignInputs(bluePrintContext: BluePrintContext, jsonNode: JsonNode, context: MutableMap<String, JsonNode>) { log.info("assignInputs from input JSON ({})", jsonNode.toString()) - bluePrintContext.inputs?.forEach { propertyName, _ -> + bluePrintContext.inputs()?.forEach { propertyName, _ -> val valueNode: JsonNode = jsonNode.at("/".plus(propertyName)) ?: NullNode.getInstance() val path = BluePrintConstants.PATH_INPUTS.plus(BluePrintConstants.PATH_DIVIDER).plus(propertyName) diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintNodeTemplateValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintNodeTemplateValidatorImpl.kt index ded1f384c..601ba4f5c 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintNodeTemplateValidatorImpl.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintNodeTemplateValidatorImpl.kt @@ -247,6 +247,8 @@ open class BluePrintNodeTemplateValidatorImpl(private val bluePrintTypeValidator if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { isValid = JacksonUtils.checkJsonNodeValueOfPrimitiveType(propertyType, propertyAssignment) + } else if (BluePrintTypes.validComplexTypes().contains(propertyType)) { + isValid = true } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { val entrySchemaType = propertyDefinition.entrySchema?.type diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintWorkflowValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintWorkflowValidatorImpl.kt index 851a7c603..519358b10 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintWorkflowValidatorImpl.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintWorkflowValidatorImpl.kt @@ -58,9 +58,10 @@ open class BluePrintWorkflowValidatorImpl(private val bluePrintTypeValidatorServ val nodeTypeDerivedFrom = bluePrintRuntimeService.bluePrintContext().nodeTemplateNodeType(it).derivedFrom - check(nodeTypeDerivedFrom == BluePrintConstants.MODEL_TYPE_NODE_DG) { - "NodeType(${nodeTemplate.type}) derived from is '$nodeTypeDerivedFrom', Expected is " + - "'${BluePrintConstants.MODEL_TYPE_NODE_DG}'" + check(nodeTypeDerivedFrom == BluePrintConstants.MODEL_TYPE_NODE_DG + || nodeTypeDerivedFrom == BluePrintConstants.MODEL_TYPE_NODE_COMPONENT) { + "NodeType(${nodeTemplate.type}) derived from is '$nodeTypeDerivedFrom', Expected " + + "'${BluePrintConstants.MODEL_TYPE_NODE_DG}' or '${BluePrintConstants.MODEL_TYPE_NODE_COMPONENT}'" } } catch (e: Exception) { bluePrintRuntimeService.getBluePrintError() diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt b/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt index 3fc918e60..d844d1ecd 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt @@ -90,7 +90,9 @@ class BluePrintDesignTimeValidatorServiceTest { workflowValidator.validate(bluePrintRuntime, workflowName, workflow) assertEquals(1, bluePrintRuntime.getBluePrintError().errors.size) - assertEquals("Failed to validate Workflow(resource-assignment)'s step(test)'s definition : resource-assignment/steps/test : NodeType(TestNodeType) derived from is 'tosca.nodes.TEST', Expected is 'tosca.nodes.DG'", bluePrintRuntime.getBluePrintError().errors[0]) + assertEquals("Failed to validate Workflow(resource-assignment)'s step(test)'s definition : " + + "resource-assignment/steps/test : NodeType(TestNodeType) derived from is 'tosca.nodes.TEST', " + + "Expected 'tosca.nodes.DG' or 'tosca.nodes.Component'", bluePrintRuntime.getBluePrintError().errors[0]) } @Test diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt index 9fbf0916a..fc9ee5045 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt @@ -82,8 +82,27 @@ open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BlueP private fun enhanceStepTargets(name: String, workflow: Workflow) { - // Get the first Step Target NodeTemplate name( Since that is the DG Node Template) - val dgNodeTemplateName = bluePrintContext.workflowFirstStepNodeTemplate(name) + // Get the first Step Target NodeTemplate name( It may be Component or DG Node Template) + val firstNodeTemplateName = bluePrintContext.workflowFirstStepNodeTemplate(name) + + val derivedFrom = bluePrintContext.nodeTemplateNodeType(firstNodeTemplateName).derivedFrom + + when { + derivedFrom.startsWith(BluePrintConstants.MODEL_TYPE_NODE_COMPONENT, true) -> { + // DO Nothing + } + derivedFrom.startsWith(BluePrintConstants.MODEL_TYPE_NODE_DG, true) -> { + enhanceDGStepTargets(name, workflow, firstNodeTemplateName) + } + else -> { + throw BluePrintProcessorException("couldn't execute workflow($name) step mapped " + + "to node template($firstNodeTemplateName) derived from($derivedFrom)") + } + } + + } + + private fun enhanceDGStepTargets(name: String, workflow: Workflow, dgNodeTemplateName: String) { val dgNodeTemplate = bluePrintContext.nodeTemplateByName(dgNodeTemplateName) diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt index 6171687f2..816b35664 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt @@ -75,7 +75,7 @@ class ResourceDefinitionEnhancerServiceImpl(private val resourceDefinitionRepoSe // Get all the Mapping files from all node templates. private fun getAllResourceMappingFiles(blueprintContext: BluePrintContext): List<String>? { - return blueprintContext.nodeTemplates?.mapNotNull { nodeTemplateMap -> + return blueprintContext.nodeTemplates()?.mapNotNull { nodeTemplateMap -> // Return only Mapping Artifact File Names nodeTemplateMap.value.artifacts?.filter { artifactDefinitionMap -> diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt index 919d202f5..48183f4cb 100644 --- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt @@ -64,30 +64,34 @@ class BluePrintEnhancerServiceImplTest { fun testEnhancementAndValidation() { val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" - - val targetPath = Paths.get("target", "bp-enhance").toUri().path - - val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath) - Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext) - - // Validate the Generated BluePrints - val valid = bluePrintValidatorService.validateBluePrints(targetPath) - Assert.assertTrue("blueprint validation failed ", valid) + testComponentInvokeEnhancementAndValidation(basePath, "base-enhance") } @Test @Throws(Exception::class) - fun testEnhancementAndValidation2() { + fun testComponentInvokeEnhancementAndValidation() { + val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/component_invoke" + testComponentInvokeEnhancementAndValidation(basePath, "component-enhance") + } + @Test + @Throws(Exception::class) + fun testGoldenEnhancementAndValidation() { val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/golden" + testComponentInvokeEnhancementAndValidation(basePath, "golden-enhance") + } - val targetPath = Paths.get("target", "bp-enhance").toUri().path + + private fun testComponentInvokeEnhancementAndValidation(basePath: String, targetDirName: String) { + + val targetPath = Paths.get("target", targetDirName).toUri().path val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath) Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext) // Validate the Generated BluePrints val valid = bluePrintValidatorService.validateBluePrints(targetPath) - Assert.assertTrue("blueprint validation failed ", valid) + Assert.assertTrue("blueprint($basePath) validation failed ", valid) } + }
\ No newline at end of file |