diff options
Diffstat (limited to 'components/core/src')
3 files changed, 163 insertions, 0 deletions
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 00000000..3ec0691f --- /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<String> = 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 00000000..9407cfa1 --- /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<T> { + + fun validate(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, type: T) + +} + + +interface BluePrintServiceTemplateValidator : BluePrintValidator<ServiceTemplate> + +interface BluePrintTopologyTemplateValidator : BluePrintValidator<TopologyTemplate> + +interface BluePrintArtifactTypeValidator : BluePrintValidator<ArtifactType> + +interface BluePrintDataTypeValidator : BluePrintValidator<DataType> + +interface BluePrintNodeTypeValidator : BluePrintValidator<NodeType> + +interface BluePrintNodeTemplateValidator : BluePrintValidator<NodeTemplate> + +interface BluePrintWorkflowValidator : BluePrintValidator<Workflow> + +interface BluePrintPropertyDefinitionValidator : BluePrintValidator<PropertyDefinition> + +interface BluePrintAttributeDefinitionValidator : BluePrintValidator<AttributeDefinition> + +/** + * Blueprint Validation Interface. + */ +interface BluePrintValidatorService { + + @Throws(BluePrintException::class) + fun validateBluePrints(bluePrintContext: BluePrintContext, properties: MutableMap<String, Any>) +} + + +interface BluePrintTypeValidatorService { + + fun getServiceTemplateValidators(): List<BluePrintServiceTemplateValidator> + + fun getDataTypeValidators(): List<BluePrintDataTypeValidator> + + fun getArtifactTypeValidators(): List<BluePrintArtifactTypeValidator> + + fun getNodeTypeValidators(): List<BluePrintNodeTypeValidator> + + fun getTopologyTemplateValidators(): List<BluePrintTopologyTemplateValidator> + + fun getNodeTemplateValidators(): List<BluePrintNodeTemplateValidator> + + fun getWorkflowValidators(): List<BluePrintWorkflowValidator> + + fun getPropertyDefinitionValidators(): List<BluePrintPropertyDefinitionValidator> + + fun getAttributeDefinitionValidators(): List<BluePrintAttributeDefinitionValidator> + + 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<String, PropertyDefinition>) { + 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<String, AttributeDefinition>) { + 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 <T> doValidation(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, definition: Any, validators: List<BluePrintValidator<T>>) { + 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 f73fb727..cce6d904 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<ImportDefinition>? = serviceTemplate.imports
val metadata: MutableMap<String, String>? = serviceTemplate.metadata
|