2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2018 IBM.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.onap.ccsdk.cds.controllerblueprints.core.interfaces
20 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
21 import org.onap.ccsdk.cds.controllerblueprints.core.data.ArtifactDefinition
22 import org.onap.ccsdk.cds.controllerblueprints.core.data.ArtifactType
23 import org.onap.ccsdk.cds.controllerblueprints.core.data.AttributeDefinition
24 import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType
25 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate
26 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType
27 import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
28 import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate
29 import org.onap.ccsdk.cds.controllerblueprints.core.data.TopologyTemplate
30 import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow
31 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
33 interface BluePrintValidator<T> {
35 fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: T)
38 interface BluePrintServiceTemplateValidator : BluePrintValidator<ServiceTemplate>
40 interface BluePrintTopologyTemplateValidator : BluePrintValidator<TopologyTemplate>
42 interface BluePrintArtifactTypeValidator : BluePrintValidator<ArtifactType>
44 interface BluePrintArtifactDefinitionValidator : BluePrintValidator<ArtifactDefinition>
46 interface BluePrintDataTypeValidator : BluePrintValidator<DataType>
48 interface BluePrintNodeTypeValidator : BluePrintValidator<NodeType>
50 interface BluePrintNodeTemplateValidator : BluePrintValidator<NodeTemplate>
52 interface BluePrintWorkflowValidator : BluePrintValidator<Workflow>
54 interface BluePrintPropertyDefinitionValidator : BluePrintValidator<PropertyDefinition>
56 interface BluePrintAttributeDefinitionValidator : BluePrintValidator<AttributeDefinition>
59 * Blueprint Validation Interface.
61 interface BluePrintValidatorService {
63 @Throws(BluePrintException::class)
64 suspend fun validateBluePrints(basePath: String): Boolean
66 @Throws(BluePrintException::class)
67 suspend fun validateBluePrints(bluePrintRuntimeService: BluePrintRuntimeService<*>): Boolean
70 interface BluePrintTypeValidatorService {
72 fun <T : BluePrintValidator<*>> bluePrintValidator(referenceName: String, classType: Class<T>): T?
74 fun <T : BluePrintValidator<*>> bluePrintValidators(referenceNamePrefix: String, classType: Class<T>): List<T>?
76 fun <T : BluePrintValidator<*>> bluePrintValidators(classType: Class<T>): List<T>?
78 fun getServiceTemplateValidators(): List<BluePrintServiceTemplateValidator>
80 fun getDataTypeValidators(): List<BluePrintDataTypeValidator>
82 fun getArtifactTypeValidators(): List<BluePrintArtifactTypeValidator>
84 fun getArtifactDefinitionsValidators(): List<BluePrintArtifactDefinitionValidator>
86 fun getNodeTypeValidators(): List<BluePrintNodeTypeValidator>
88 fun getTopologyTemplateValidators(): List<BluePrintTopologyTemplateValidator>
90 fun getNodeTemplateValidators(): List<BluePrintNodeTemplateValidator>
92 fun getWorkflowValidators(): List<BluePrintWorkflowValidator>
94 fun getPropertyDefinitionValidators(): List<BluePrintPropertyDefinitionValidator>
96 fun getAttributeDefinitionValidators(): List<BluePrintAttributeDefinitionValidator>
98 fun validateServiceTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, serviceTemplate: ServiceTemplate) {
99 val validators = getServiceTemplateValidators()
100 doValidation(bluePrintRuntimeService, name, serviceTemplate, validators)
103 fun validateArtifactType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, artifactType: ArtifactType) {
104 val validators = getArtifactTypeValidators()
105 doValidation(bluePrintRuntimeService, name, artifactType, validators)
108 fun validateArtifactDefinition(
109 bluePrintRuntimeService: BluePrintRuntimeService<*>,
111 artifactDefinition: ArtifactDefinition
113 val validators = getArtifactDefinitionsValidators()
114 doValidation(bluePrintRuntimeService, name, artifactDefinition, validators)
117 fun validateDataType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, dataType: DataType) {
118 val validators = getDataTypeValidators()
119 doValidation(bluePrintRuntimeService, name, dataType, validators)
122 fun validateNodeType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) {
123 val validators = getNodeTypeValidators()
124 doValidation(bluePrintRuntimeService, name, nodeType, validators)
127 fun validateTopologyTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, topologyTemplate: TopologyTemplate) {
128 val validators = getTopologyTemplateValidators()
129 doValidation(bluePrintRuntimeService, name, topologyTemplate, validators)
132 fun validateNodeTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) {
133 val validators = getNodeTemplateValidators()
134 doValidation(bluePrintRuntimeService, name, nodeTemplate, validators)
137 fun validateWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, workflow: Workflow) {
138 val validators = getWorkflowValidators()
139 doValidation(bluePrintRuntimeService, name, workflow, validators)
142 fun validatePropertyDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, properties: MutableMap<String, PropertyDefinition>) {
143 properties.forEach { propertyName, propertyDefinition ->
144 validatePropertyDefinition(bluePrintRuntimeService, propertyName, propertyDefinition)
148 fun validatePropertyDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) {
149 val validators = getPropertyDefinitionValidators()
150 doValidation(bluePrintRuntimeService, name, propertyDefinition, validators)
153 fun validateAttributeDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, attributes: MutableMap<String, AttributeDefinition>) {
154 attributes.forEach { attributeName, attributeDefinition ->
155 validateAttributeDefinition(bluePrintRuntimeService, attributeName, attributeDefinition)
159 fun validateAttributeDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, attributeDefinition: AttributeDefinition) {
160 val validators = getAttributeDefinitionValidators()
161 doValidation(bluePrintRuntimeService, name, attributeDefinition, validators)
164 @Suppress("UNCHECKED_CAST")
165 private fun <T> doValidation(
166 bluePrintRuntimeService: BluePrintRuntimeService<*>,
169 validators: List<BluePrintValidator<T>>
172 it.validate(bluePrintRuntimeService, name, definition as T)