From a09c74a9c080bb5ed8b769c30617025eeb4ca3a4 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Tue, 27 Nov 2018 10:03:04 -0500 Subject: Add Blueprint Validation Interfaces. Change-Id: Idbda09fc8be7878814e782990ab8d6e9a5d8b047 Issue-ID: CCSDK-757 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../core/BluePrintValidationError.kt | 29 +++++ .../core/interfaces/BlueprintValidator.kt | 129 +++++++++++++++++++++ .../core/service/BluePrintContext.kt | 5 + 3 files changed, 163 insertions(+) create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintValidationError.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BlueprintValidator.kt (limited to 'components') diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintValidationError.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintValidationError.kt new file mode 100644 index 000000000..3ec0691f4 --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintValidationError.kt @@ -0,0 +1,29 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core + +class BluePrintValidationError { + var errors: MutableList = arrayListOf() + + fun addError(type: String, name: String, error: String) { + this.errors.add("$type : $name : $error") + } + + fun addError(error: String) { + this.errors.add(error) + } +} \ No newline at end of file diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BlueprintValidator.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BlueprintValidator.kt new file mode 100644 index 000000000..9407cfa11 --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BlueprintValidator.kt @@ -0,0 +1,129 @@ +package org.onap.ccsdk.apps.controllerblueprints.core.interfaces + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintValidationError +import org.onap.ccsdk.apps.controllerblueprints.core.data.* +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext + + +interface BluePrintValidator { + + fun validate(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, type: T) + +} + + +interface BluePrintServiceTemplateValidator : BluePrintValidator + +interface BluePrintTopologyTemplateValidator : BluePrintValidator + +interface BluePrintArtifactTypeValidator : BluePrintValidator + +interface BluePrintDataTypeValidator : BluePrintValidator + +interface BluePrintNodeTypeValidator : BluePrintValidator + +interface BluePrintNodeTemplateValidator : BluePrintValidator + +interface BluePrintWorkflowValidator : BluePrintValidator + +interface BluePrintPropertyDefinitionValidator : BluePrintValidator + +interface BluePrintAttributeDefinitionValidator : BluePrintValidator + +/** + * Blueprint Validation Interface. + */ +interface BluePrintValidatorService { + + @Throws(BluePrintException::class) + fun validateBluePrints(bluePrintContext: BluePrintContext, properties: MutableMap) +} + + +interface BluePrintTypeValidatorService { + + fun getServiceTemplateValidators(): List + + fun getDataTypeValidators(): List + + fun getArtifactTypeValidators(): List + + fun getNodeTypeValidators(): List + + fun getTopologyTemplateValidators(): List + + fun getNodeTemplateValidators(): List + + fun getWorkflowValidators(): List + + fun getPropertyDefinitionValidators(): List + + fun getAttributeDefinitionValidators(): List + + fun validateServiceTemplate(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, serviceTemplate: ServiceTemplate) { + val validators = getServiceTemplateValidators() + doValidation(bluePrintContext, error, name, serviceTemplate, validators) + } + + fun validateArtifactType(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, artifactType: ArtifactType) { + val validators = getArtifactTypeValidators() + doValidation(bluePrintContext, error, name, artifactType, validators) + } + + fun validateDataType(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, dataType: DataType) { + val validators = getDataTypeValidators() + doValidation(bluePrintContext, error, name, dataType, validators) + } + + fun validateNodeType(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, nodeType: NodeType) { + val validators = getNodeTypeValidators() + doValidation(bluePrintContext, error, name, nodeType, validators) + } + + fun validateTopologyTemplate(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, topologyTemplate: TopologyTemplate) { + val validators = getTopologyTemplateValidators() + doValidation(bluePrintContext, error, name, topologyTemplate, validators) + } + + fun validateNodeTemplate(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, nodeTemplate: NodeTemplate) { + val validators = getNodeTemplateValidators() + doValidation(bluePrintContext, error, name, nodeTemplate, validators) + } + + fun validateWorkflow(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, workflow: Workflow) { + val validators = getWorkflowValidators() + doValidation(bluePrintContext, error, name, workflow, validators) + } + + fun validatePropertyDefinitions(bluePrintContext: BluePrintContext, error: BluePrintValidationError, properties: MutableMap) { + properties.forEach { propertyName, propertyDefinition -> + validatePropertyDefinition(bluePrintContext, error, propertyName, propertyDefinition) + } + } + + fun validatePropertyDefinition(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, propertyDefinition: PropertyDefinition) { + val validators = getPropertyDefinitionValidators() + doValidation(bluePrintContext, error, name, propertyDefinition, validators) + } + + fun validateAttributeDefinitions(bluePrintContext: BluePrintContext, error: BluePrintValidationError, attributes: MutableMap) { + attributes.forEach { attributeName, attributeDefinition -> + validateAttributeDefinition(bluePrintContext, error, attributeName, attributeDefinition) + } + } + + fun validateAttributeDefinition(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, attributeDefinition: AttributeDefinition) { + val validators = getAttributeDefinitionValidators() + doValidation(bluePrintContext, error, name, attributeDefinition, validators) + } + + private fun doValidation(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, definition: Any, validators: List>) { + validators.forEach { + it.validate(bluePrintContext, error, name, definition as T) + } + } +} + + + diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt index f73fb727d..cce6d904c 100644 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt @@ -32,6 +32,11 @@ class BluePrintContext(val serviceTemplate: ServiceTemplate) { private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + /** + * Blueprint CBA extracted file location + */ + var rootPath = "." + val imports: List? = serviceTemplate.imports val metadata: MutableMap? = serviceTemplate.metadata -- cgit 1.2.3-korg