Blueprint Processor Python Script Components
[ccsdk/cds.git] / components / core / src / main / kotlin / org / onap / ccsdk / apps / controllerblueprints / core / interfaces / BlueprintValidator.kt
1 package org.onap.ccsdk.apps.controllerblueprints.core.interfaces
2
3 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
4 import org.onap.ccsdk.apps.controllerblueprints.core.data.*
5 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
6
7
8 interface BluePrintValidator<T> {
9
10     fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: T)
11
12 }
13
14
15 interface BluePrintServiceTemplateValidator : BluePrintValidator<ServiceTemplate>
16
17 interface BluePrintTopologyTemplateValidator : BluePrintValidator<TopologyTemplate>
18
19 interface BluePrintArtifactTypeValidator : BluePrintValidator<ArtifactType>
20
21 interface BluePrintDataTypeValidator : BluePrintValidator<DataType>
22
23 interface BluePrintNodeTypeValidator : BluePrintValidator<NodeType>
24
25 interface BluePrintNodeTemplateValidator : BluePrintValidator<NodeTemplate>
26
27 interface BluePrintWorkflowValidator : BluePrintValidator<Workflow>
28
29 interface BluePrintPropertyDefinitionValidator : BluePrintValidator<PropertyDefinition>
30
31 interface BluePrintAttributeDefinitionValidator : BluePrintValidator<AttributeDefinition>
32
33 /**
34  * Blueprint Validation Interface.
35  */
36 interface BluePrintValidatorService {
37
38     @Throws(BluePrintException::class)
39     fun validateBluePrints(basePath: String): Boolean
40
41     @Throws(BluePrintException::class)
42     fun validateBluePrints(bluePrintRuntimeService: BluePrintRuntimeService<*>): Boolean
43 }
44
45
46 interface BluePrintTypeValidatorService {
47
48     fun getServiceTemplateValidators(): List<BluePrintServiceTemplateValidator>
49
50     fun getDataTypeValidators(): List<BluePrintDataTypeValidator>
51
52     fun getArtifactTypeValidators(): List<BluePrintArtifactTypeValidator>
53
54     fun getNodeTypeValidators(): List<BluePrintNodeTypeValidator>
55
56     fun getTopologyTemplateValidators(): List<BluePrintTopologyTemplateValidator>
57
58     fun getNodeTemplateValidators(): List<BluePrintNodeTemplateValidator>
59
60     fun getWorkflowValidators(): List<BluePrintWorkflowValidator>
61
62     fun getPropertyDefinitionValidators(): List<BluePrintPropertyDefinitionValidator>
63
64     fun getAttributeDefinitionValidators(): List<BluePrintAttributeDefinitionValidator>
65
66     fun validateServiceTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, serviceTemplate: ServiceTemplate) {
67         val validators = getServiceTemplateValidators()
68         doValidation(bluePrintRuntimeService, name, serviceTemplate, validators)
69     }
70
71     fun validateArtifactType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, artifactType: ArtifactType) {
72         val validators = getArtifactTypeValidators()
73         doValidation(bluePrintRuntimeService, name, artifactType, validators)
74     }
75
76     fun validateDataType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, dataType: DataType) {
77         val validators = getDataTypeValidators()
78         doValidation(bluePrintRuntimeService, name, dataType, validators)
79     }
80
81     fun validateNodeType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) {
82         val validators = getNodeTypeValidators()
83         doValidation(bluePrintRuntimeService, name, nodeType, validators)
84     }
85
86     fun validateTopologyTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, topologyTemplate: TopologyTemplate) {
87         val validators = getTopologyTemplateValidators()
88         doValidation(bluePrintRuntimeService, name, topologyTemplate, validators)
89     }
90
91     fun validateNodeTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) {
92         val validators = getNodeTemplateValidators()
93         doValidation(bluePrintRuntimeService, name, nodeTemplate, validators)
94     }
95
96     fun validateWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, workflow: Workflow) {
97         val validators = getWorkflowValidators()
98         doValidation(bluePrintRuntimeService, name, workflow, validators)
99     }
100
101     fun validatePropertyDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, properties: MutableMap<String, PropertyDefinition>) {
102         properties.forEach { propertyName, propertyDefinition ->
103             validatePropertyDefinition(bluePrintRuntimeService, propertyName, propertyDefinition)
104         }
105     }
106
107     fun validatePropertyDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) {
108         val validators = getPropertyDefinitionValidators()
109         doValidation(bluePrintRuntimeService, name, propertyDefinition, validators)
110     }
111
112     fun validateAttributeDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, attributes: MutableMap<String, AttributeDefinition>) {
113         attributes.forEach { attributeName, attributeDefinition ->
114             validateAttributeDefinition(bluePrintRuntimeService, attributeName, attributeDefinition)
115         }
116     }
117
118     fun validateAttributeDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, attributeDefinition: AttributeDefinition) {
119         val validators = getAttributeDefinitionValidators()
120         doValidation(bluePrintRuntimeService, name, attributeDefinition, validators)
121     }
122
123     @Suppress("UNCHECKED_CAST")
124     private fun <T> doValidation(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, definition: Any, validators: List<BluePrintValidator<T>>) {
125         validators.forEach {
126             it.validate(bluePrintRuntimeService, name, definition as T)
127         }
128     }
129 }
130
131
132