Refractor controller blueprint modules
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / blueprints / blueprint-core / src / main / kotlin / org / onap / ccsdk / cds / controllerblueprints / core / interfaces / BluePrintEnhancer.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  * Modifications Copyright © 2019 IBM.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 package org.onap.ccsdk.cds.controllerblueprints.core.interfaces
19
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.AttributeDefinition
23 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate
24 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType
25 import org.onap.ccsdk.cds.controllerblueprints.core.data.PolicyType
26 import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
27 import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate
28 import org.onap.ccsdk.cds.controllerblueprints.core.data.TopologyTemplate
29 import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow
30 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
31 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
32
33 interface BluePrintEnhancer<T> {
34     fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: T)
35 }
36
37 interface BluePrintServiceTemplateEnhancer : BluePrintEnhancer<ServiceTemplate>
38
39 interface BluePrintTopologyTemplateEnhancer : BluePrintEnhancer<TopologyTemplate>
40
41 interface BluePrintWorkflowEnhancer : BluePrintEnhancer<Workflow>
42
43 interface BluePrintNodeTemplateEnhancer : BluePrintEnhancer<NodeTemplate>
44
45 interface BluePrintNodeTypeEnhancer : BluePrintEnhancer<NodeType>
46
47 interface BluePrintArtifactDefinitionEnhancer : BluePrintEnhancer<ArtifactDefinition>
48
49 interface BluePrintPolicyTypeEnhancer : BluePrintEnhancer<PolicyType>
50
51 interface BluePrintPropertyDefinitionEnhancer : BluePrintEnhancer<PropertyDefinition>
52
53 interface BluePrintAttributeDefinitionEnhancer : BluePrintEnhancer<AttributeDefinition>
54
55 interface BluePrintEnhancerService {
56
57     @Throws(BluePrintException::class)
58     suspend fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext
59
60     @Throws(BluePrintException::class)
61     suspend fun enhance(basePath: String): BluePrintContext
62 }
63
64 interface BluePrintTypeEnhancerService {
65
66     fun getServiceTemplateEnhancers(): List<BluePrintServiceTemplateEnhancer>
67
68     fun getTopologyTemplateEnhancers(): List<BluePrintTopologyTemplateEnhancer>
69
70     fun getWorkflowEnhancers(): List<BluePrintWorkflowEnhancer>
71
72     fun getNodeTemplateEnhancers(): List<BluePrintNodeTemplateEnhancer>
73
74     fun getNodeTypeEnhancers(): List<BluePrintNodeTypeEnhancer>
75
76     fun getArtifactDefinitionEnhancers(): List<BluePrintArtifactDefinitionEnhancer>
77
78     fun getPolicyTypeEnhancers(): List<BluePrintPolicyTypeEnhancer>
79
80     fun getPropertyDefinitionEnhancers(): List<BluePrintPropertyDefinitionEnhancer>
81
82     fun getAttributeDefinitionEnhancers(): List<BluePrintAttributeDefinitionEnhancer>
83
84     fun enhanceServiceTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, serviceTemplate: ServiceTemplate) {
85         val enhancers = getServiceTemplateEnhancers()
86         doEnhancement(bluePrintRuntimeService, name, serviceTemplate, enhancers)
87     }
88
89     fun enhanceTopologyTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, topologyTemplate: TopologyTemplate) {
90         val enhancers = getTopologyTemplateEnhancers()
91         doEnhancement(bluePrintRuntimeService, name, topologyTemplate, enhancers)
92     }
93
94     fun enhanceWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, workflow: Workflow) {
95         val enhancers = getWorkflowEnhancers()
96         doEnhancement(bluePrintRuntimeService, name, workflow, enhancers)
97     }
98
99     fun enhanceNodeTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) {
100         val enhancers = getNodeTemplateEnhancers()
101         doEnhancement(bluePrintRuntimeService, name, nodeTemplate, enhancers)
102     }
103
104     fun enhanceNodeType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) {
105         val enhancers = getNodeTypeEnhancers()
106         doEnhancement(bluePrintRuntimeService, name, nodeType, enhancers)
107     }
108
109     fun enhanceArtifactDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, artifactDefinition: ArtifactDefinition) {
110         val enhancers = getArtifactDefinitionEnhancers()
111         doEnhancement(bluePrintRuntimeService, name, artifactDefinition, enhancers)
112     }
113
114     fun enhancePolicyType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, policyType: PolicyType) {
115         val enhancers = getPolicyTypeEnhancers()
116         doEnhancement(bluePrintRuntimeService, name, policyType, enhancers)
117     }
118
119     fun enhancePropertyDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, properties: MutableMap<String, PropertyDefinition>) {
120         properties.forEach { propertyName, propertyDefinition ->
121             enhancePropertyDefinition(bluePrintRuntimeService, propertyName, propertyDefinition)
122         }
123     }
124
125     fun enhancePropertyDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) {
126         val enhancers = getPropertyDefinitionEnhancers()
127         doEnhancement(bluePrintRuntimeService, name, propertyDefinition, enhancers)
128     }
129
130     fun enhanceAttributeDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, attributes: MutableMap<String, AttributeDefinition>) {
131         attributes.forEach { attributeName, attributeDefinition ->
132             enhanceAttributeDefinition(bluePrintRuntimeService, attributeName, attributeDefinition)
133         }
134     }
135
136     fun enhanceAttributeDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, attributeDefinition: AttributeDefinition) {
137         val enhancers = getAttributeDefinitionEnhancers()
138         doEnhancement(bluePrintRuntimeService, name, attributeDefinition, enhancers)
139     }
140
141     @Suppress("UNCHECKED_CAST")
142     private fun <T> doEnhancement(
143         bluePrintRuntimeService: BluePrintRuntimeService<*>,
144         name: String,
145         definition: Any,
146         enhancers: List<BluePrintEnhancer<T>>
147     ) {
148         if (enhancers.isNotEmpty()) {
149             enhancers.forEach {
150                 it.enhance(bluePrintRuntimeService, name, definition as T)
151             }
152         }
153     }
154 }