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.apps.controllerblueprints.core.interfaces
20 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
21 import org.onap.ccsdk.apps.controllerblueprints.core.data.*
22 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
25 interface BluePrintValidator<T> {
27 fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: T)
32 interface BluePrintServiceTemplateValidator : BluePrintValidator<ServiceTemplate>
34 interface BluePrintTopologyTemplateValidator : BluePrintValidator<TopologyTemplate>
36 interface BluePrintArtifactTypeValidator : BluePrintValidator<ArtifactType>
38 interface BluePrintArtifactDefinitionValidator : BluePrintValidator<ArtifactDefinition>
40 interface BluePrintDataTypeValidator : BluePrintValidator<DataType>
42 interface BluePrintNodeTypeValidator : BluePrintValidator<NodeType>
44 interface BluePrintNodeTemplateValidator : BluePrintValidator<NodeTemplate>
46 interface BluePrintWorkflowValidator : BluePrintValidator<Workflow>
48 interface BluePrintPropertyDefinitionValidator : BluePrintValidator<PropertyDefinition>
50 interface BluePrintAttributeDefinitionValidator : BluePrintValidator<AttributeDefinition>
53 * Blueprint Validation Interface.
55 interface BluePrintValidatorService {
57 @Throws(BluePrintException::class)
58 fun validateBluePrints(basePath: String): Boolean
60 @Throws(BluePrintException::class)
61 fun validateBluePrints(bluePrintRuntimeService: BluePrintRuntimeService<*>): Boolean
65 interface BluePrintTypeValidatorService {
67 fun <T : BluePrintValidator<*>> bluePrintValidator(referenceName: String, classType: Class<T>): T?
69 fun <T : BluePrintValidator<*>> bluePrintValidators(referenceNamePrefix: String, classType: Class<T>): List<T>?
71 fun <T : BluePrintValidator<*>> bluePrintValidators(classType: Class<T>): List<T>?
73 fun getServiceTemplateValidators(): List<BluePrintServiceTemplateValidator>
75 fun getDataTypeValidators(): List<BluePrintDataTypeValidator>
77 fun getArtifactTypeValidators(): List<BluePrintArtifactTypeValidator>
79 fun getArtifactDefinitionsValidators(): List<BluePrintArtifactDefinitionValidator>
81 fun getNodeTypeValidators(): List<BluePrintNodeTypeValidator>
83 fun getTopologyTemplateValidators(): List<BluePrintTopologyTemplateValidator>
85 fun getNodeTemplateValidators(): List<BluePrintNodeTemplateValidator>
87 fun getWorkflowValidators(): List<BluePrintWorkflowValidator>
89 fun getPropertyDefinitionValidators(): List<BluePrintPropertyDefinitionValidator>
91 fun getAttributeDefinitionValidators(): List<BluePrintAttributeDefinitionValidator>
93 fun validateServiceTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, serviceTemplate: ServiceTemplate) {
94 val validators = getServiceTemplateValidators()
95 doValidation(bluePrintRuntimeService, name, serviceTemplate, validators)
98 fun validateArtifactType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, artifactType: ArtifactType) {
99 val validators = getArtifactTypeValidators()
100 doValidation(bluePrintRuntimeService, name, artifactType, validators)
103 fun validateArtifactDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String,
104 artifactDefinition: ArtifactDefinition) {
105 val validators = getArtifactDefinitionsValidators()
106 doValidation(bluePrintRuntimeService, name, artifactDefinition, validators)
109 fun validateDataType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, dataType: DataType) {
110 val validators = getDataTypeValidators()
111 doValidation(bluePrintRuntimeService, name, dataType, validators)
114 fun validateNodeType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) {
115 val validators = getNodeTypeValidators()
116 doValidation(bluePrintRuntimeService, name, nodeType, validators)
119 fun validateTopologyTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, topologyTemplate: TopologyTemplate) {
120 val validators = getTopologyTemplateValidators()
121 doValidation(bluePrintRuntimeService, name, topologyTemplate, validators)
124 fun validateNodeTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) {
125 val validators = getNodeTemplateValidators()
126 doValidation(bluePrintRuntimeService, name, nodeTemplate, validators)
129 fun validateWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, workflow: Workflow) {
130 val validators = getWorkflowValidators()
131 doValidation(bluePrintRuntimeService, name, workflow, validators)
134 fun validatePropertyDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, properties: MutableMap<String, PropertyDefinition>) {
135 properties.forEach { propertyName, propertyDefinition ->
136 validatePropertyDefinition(bluePrintRuntimeService, propertyName, propertyDefinition)
140 fun validatePropertyDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) {
141 val validators = getPropertyDefinitionValidators()
142 doValidation(bluePrintRuntimeService, name, propertyDefinition, validators)
145 fun validateAttributeDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, attributes: MutableMap<String, AttributeDefinition>) {
146 attributes.forEach { attributeName, attributeDefinition ->
147 validateAttributeDefinition(bluePrintRuntimeService, attributeName, attributeDefinition)
151 fun validateAttributeDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, attributeDefinition: AttributeDefinition) {
152 val validators = getAttributeDefinitionValidators()
153 doValidation(bluePrintRuntimeService, name, attributeDefinition, validators)
156 @Suppress("UNCHECKED_CAST")
157 private fun <T> doValidation(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, definition: Any, validators: List<BluePrintValidator<T>>) {
159 it.validate(bluePrintRuntimeService, name, definition as T)