535021b34bd3d768851a6990a6a06c6d3287130e
[ccsdk/cds.git] /
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.RelationshipTemplate
28 import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType
29 import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate
30 import org.onap.ccsdk.cds.controllerblueprints.core.data.TopologyTemplate
31 import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow
32 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
33 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
34
35 interface BluePrintEnhancer<T> {
36     fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: T)
37 }
38
39 interface BluePrintServiceTemplateEnhancer : BluePrintEnhancer<ServiceTemplate>
40
41 interface BluePrintTopologyTemplateEnhancer : BluePrintEnhancer<TopologyTemplate>
42
43 interface BluePrintWorkflowEnhancer : BluePrintEnhancer<Workflow>
44
45 interface BluePrintNodeTemplateEnhancer : BluePrintEnhancer<NodeTemplate>
46
47 interface BluePrintNodeTypeEnhancer : BluePrintEnhancer<NodeType>
48
49 interface BluePrintRelationshipTemplateEnhancer : BluePrintEnhancer<RelationshipTemplate>
50
51 interface BluePrintRelationshipTypeEnhancer : BluePrintEnhancer<RelationshipType>
52
53 interface BluePrintArtifactDefinitionEnhancer : BluePrintEnhancer<ArtifactDefinition>
54
55 interface BluePrintPolicyTypeEnhancer : BluePrintEnhancer<PolicyType>
56
57 interface BluePrintPropertyDefinitionEnhancer : BluePrintEnhancer<PropertyDefinition>
58
59 interface BluePrintAttributeDefinitionEnhancer : BluePrintEnhancer<AttributeDefinition>
60
61 interface BluePrintEnhancerService {
62
63     @Throws(BluePrintException::class)
64     suspend fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext
65
66     @Throws(BluePrintException::class)
67     suspend fun enhance(basePath: String): BluePrintContext
68 }
69
70 interface BluePrintTypeEnhancerService {
71
72     fun getServiceTemplateEnhancers(): List<BluePrintServiceTemplateEnhancer>
73
74     fun getTopologyTemplateEnhancers(): List<BluePrintTopologyTemplateEnhancer>
75
76     fun getWorkflowEnhancers(): List<BluePrintWorkflowEnhancer>
77
78     fun getNodeTemplateEnhancers(): List<BluePrintNodeTemplateEnhancer>
79
80     fun getNodeTypeEnhancers(): List<BluePrintNodeTypeEnhancer>
81
82     fun getRelationshipTemplateEnhancers(): List<BluePrintRelationshipTemplateEnhancer>
83
84     fun getRelationshipTypeEnhancers(): List<BluePrintRelationshipTypeEnhancer>
85
86     fun getArtifactDefinitionEnhancers(): List<BluePrintArtifactDefinitionEnhancer>
87
88     fun getPolicyTypeEnhancers(): List<BluePrintPolicyTypeEnhancer>
89
90     fun getPropertyDefinitionEnhancers(): List<BluePrintPropertyDefinitionEnhancer>
91
92     fun getAttributeDefinitionEnhancers(): List<BluePrintAttributeDefinitionEnhancer>
93
94     fun enhanceServiceTemplate(
95         bluePrintRuntimeService: BluePrintRuntimeService<*>,
96         name: String,
97         serviceTemplate: ServiceTemplate
98     ) {
99         val enhancers = getServiceTemplateEnhancers()
100         doEnhancement(bluePrintRuntimeService, name, serviceTemplate, enhancers)
101     }
102
103     fun enhanceTopologyTemplate(
104         bluePrintRuntimeService: BluePrintRuntimeService<*>,
105         name: String,
106         topologyTemplate: TopologyTemplate
107     ) {
108         val enhancers = getTopologyTemplateEnhancers()
109         doEnhancement(bluePrintRuntimeService, name, topologyTemplate, enhancers)
110     }
111
112     fun enhanceWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, workflow: Workflow) {
113         val enhancers = getWorkflowEnhancers()
114         doEnhancement(bluePrintRuntimeService, name, workflow, enhancers)
115     }
116
117     fun enhanceNodeTemplate(
118         bluePrintRuntimeService: BluePrintRuntimeService<*>,
119         name: String,
120         nodeTemplate: NodeTemplate
121     ) {
122         val enhancers = getNodeTemplateEnhancers()
123         doEnhancement(bluePrintRuntimeService, name, nodeTemplate, enhancers)
124     }
125
126     fun enhanceNodeType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) {
127         val enhancers = getNodeTypeEnhancers()
128         doEnhancement(bluePrintRuntimeService, name, nodeType, enhancers)
129     }
130
131     fun enhanceRelationshipTemplate(
132         bluePrintRuntimeService: BluePrintRuntimeService<*>,
133         name: String,
134         relationshipTemplate: RelationshipTemplate
135     ) {
136         val enhancers = getRelationshipTemplateEnhancers()
137         doEnhancement(bluePrintRuntimeService, name, relationshipTemplate, enhancers)
138     }
139
140     fun enhanceRelationshipType(
141         bluePrintRuntimeService: BluePrintRuntimeService<*>,
142         name: String,
143         relationshipType: RelationshipType
144     ) {
145         val enhancers = getRelationshipTypeEnhancers()
146         doEnhancement(bluePrintRuntimeService, name, relationshipType, enhancers)
147     }
148
149     fun enhanceArtifactDefinition(
150         bluePrintRuntimeService: BluePrintRuntimeService<*>,
151         name: String,
152         artifactDefinition: ArtifactDefinition
153     ) {
154         val enhancers = getArtifactDefinitionEnhancers()
155         doEnhancement(bluePrintRuntimeService, name, artifactDefinition, enhancers)
156     }
157
158     fun enhancePolicyType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, policyType: PolicyType) {
159         val enhancers = getPolicyTypeEnhancers()
160         doEnhancement(bluePrintRuntimeService, name, policyType, enhancers)
161     }
162
163     fun enhancePropertyDefinitions(
164         bluePrintRuntimeService: BluePrintRuntimeService<*>,
165         properties: MutableMap<String, PropertyDefinition>
166     ) {
167         properties.forEach { propertyName, propertyDefinition ->
168             enhancePropertyDefinition(bluePrintRuntimeService, propertyName, propertyDefinition)
169         }
170     }
171
172     fun enhancePropertyDefinition(
173         bluePrintRuntimeService: BluePrintRuntimeService<*>,
174         name: String,
175         propertyDefinition: PropertyDefinition
176     ) {
177         val enhancers = getPropertyDefinitionEnhancers()
178         doEnhancement(bluePrintRuntimeService, name, propertyDefinition, enhancers)
179     }
180
181     fun enhanceAttributeDefinitions(
182         bluePrintRuntimeService: BluePrintRuntimeService<*>,
183         attributes: MutableMap<String, AttributeDefinition>
184     ) {
185         attributes.forEach { attributeName, attributeDefinition ->
186             enhanceAttributeDefinition(bluePrintRuntimeService, attributeName, attributeDefinition)
187         }
188     }
189
190     fun enhanceAttributeDefinition(
191         bluePrintRuntimeService: BluePrintRuntimeService<*>,
192         name: String,
193         attributeDefinition: AttributeDefinition
194     ) {
195         val enhancers = getAttributeDefinitionEnhancers()
196         doEnhancement(bluePrintRuntimeService, name, attributeDefinition, enhancers)
197     }
198
199     @Suppress("UNCHECKED_CAST")
200     private fun <T> doEnhancement(
201         bluePrintRuntimeService: BluePrintRuntimeService<*>,
202         name: String,
203         definition: Any,
204         enhancers: List<BluePrintEnhancer<T>>
205     ) {
206         if (enhancers.isNotEmpty()) {
207             enhancers.forEach {
208                 it.enhance(bluePrintRuntimeService, name, definition as T)
209             }
210         }
211     }
212 }