From 7f52a96672beabb6b1f8ccfa1417307ccdbb40e8 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Fri, 7 Sep 2018 09:00:40 -0400 Subject: Controller Blueprints Microservice Add Controller Blueprint Capabily Assignment and their properies validation. Change-Id: I845fec3d307414b2caeb1d577308a17656ff194a Issue-ID: CCSDK-484 Signed-off-by: Brinda Santh --- .../core/service/BluePrintValidatorService.kt | 36 ++++++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'components') diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt index 2b11589d4..8c00e0a15 100644 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt @@ -136,7 +136,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService { //Check Derived From checkValidNodeTypesDerivedFrom(nodeTypeName, derivedFrom) - if(!BluePrintTypes.rootNodeTypes().contains(derivedFrom)){ + if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) { serviceTemplate.nodeTypes?.get(derivedFrom) ?: throw BluePrintException(format("Failed to get derivedFrom NodeType({})'s for NodeType({}) ", derivedFrom, nodeTypeName)) @@ -193,7 +193,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService { nodeTemplate.artifacts?.let { validateArtifactDefinitions(nodeTemplate.artifacts!!) } nodeTemplate.properties?.let { validatePropertyAssignments(nodeType.properties!!, nodeTemplate.properties!!) } - nodeTemplate.capabilities?.let { validateCapabilityAssignments(nodeTemplate.capabilities!!) } + nodeTemplate.capabilities?.let { validateCapabilityAssignments(nodeType, nodeTemplateName, nodeTemplate) } nodeTemplate.requirements?.let { validateRequirementAssignments(nodeType, nodeTemplateName, nodeTemplate) } nodeTemplate.interfaces?.let { validateInterfaceAssignments(nodeType, nodeTemplateName, nodeTemplate) } paths.removeAt(paths.lastIndex) @@ -291,7 +291,28 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService { } @Throws(BluePrintException::class) - open fun validateCapabilityAssignments(capabilities: MutableMap) { + open fun validateCapabilityAssignments(nodeType: NodeType, nodeTemplateName: String, nodeTemplate: NodeTemplate) { + val capabilities = nodeTemplate.capabilities + paths.add("capabilities") + capabilities?.forEach { capabilityName, capabilityAssignment -> + paths.add(capabilityName) + + val capabilityDefinition = nodeType.capabilities?.get(capabilityName) + ?: throw BluePrintException(format("Failed to get NodeTemplate({}) capability definition ({}) " + + "from NodeType({}) ", nodeTemplateName, capabilityName, nodeTemplate.type)) + + validateCapabilityAssignment(nodeTemplateName, capabilityName, capabilityDefinition, capabilityAssignment) + + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateCapabilityAssignment(nodeTemplateName: String, capabilityName: String, + capabilityDefinition: CapabilityDefinition, capabilityAssignment: CapabilityAssignment) { + + capabilityAssignment.properties?.let { validatePropertyAssignments(capabilityDefinition.properties!!, capabilityAssignment.properties!!) } } @@ -396,6 +417,15 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService { validatePropertyAssignment(propertyName, propertyDefinition, propertyAssignment) } + outputs?.forEach { propertyName, propertyAssignment -> + val propertyDefinition = operationDefinition.outputs?.get(propertyName) + ?: throw BluePrintException(format("Failed to get NodeTemplate({}) operation definition ({}) " + + "output property definition({})", nodeTemplateName, operationAssignmentName, + propertyName)) + // Check the property values with property definition + validatePropertyAssignment(propertyName, propertyDefinition, propertyAssignment) + } + } } -- cgit 1.2.3-korg