f01f126204928f47b2ae2344e4320c42d108c8b4
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.ccsdk.apps.controllerblueprints.core.interfaces
18
19 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
20 import org.onap.ccsdk.apps.controllerblueprints.core.data.*
21 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
22 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
23
24 interface BluePrintEnhancer<T> {
25     fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: T)
26 }
27
28 interface BluePrintServiceTemplateEnhancer : BluePrintEnhancer<ServiceTemplate>
29
30 interface BluePrintTopologyTemplateEnhancer : BluePrintEnhancer<TopologyTemplate>
31
32 interface BluePrintWorkflowEnhancer : BluePrintEnhancer<Workflow>
33
34 interface BluePrintNodeTemplateEnhancer : BluePrintEnhancer<NodeTemplate>
35
36 interface BluePrintNodeTypeEnhancer : BluePrintEnhancer<NodeType>
37
38 interface BluePrintArtifactDefinitionEnhancer : BluePrintEnhancer<ArtifactDefinition>
39
40 interface BluePrintPolicyTypeEnhancer : BluePrintEnhancer<PolicyType>
41
42 interface BluePrintPropertyDefinitionEnhancer : BluePrintEnhancer<PropertyDefinition>
43
44 interface BluePrintAttributeDefinitionEnhancer : BluePrintEnhancer<AttributeDefinition>
45
46
47 interface BluePrintEnhancerService {
48
49     @Throws(BluePrintException::class)
50     fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext
51
52     @Throws(BluePrintException::class)
53     fun enhance(basePath: String): BluePrintContext
54 }
55
56 interface BluePrintTypeEnhancerService {
57
58     fun getServiceTemplateEnhancers(): List<BluePrintServiceTemplateEnhancer>
59
60     fun getTopologyTemplateEnhancers(): List<BluePrintTopologyTemplateEnhancer>
61
62     fun getWorkflowEnhancers(): List<BluePrintWorkflowEnhancer>
63
64     fun getNodeTemplateEnhancers(): List<BluePrintNodeTemplateEnhancer>
65
66     fun getNodeTypeEnhancers(): List<BluePrintNodeTypeEnhancer>
67
68     fun getArtifactDefinitionEnhancers(): List<BluePrintArtifactDefinitionEnhancer>
69
70     fun getPolicyTypeEnhancers(): List<BluePrintPolicyTypeEnhancer>
71
72     fun getPropertyDefinitionEnhancers(): List<BluePrintPropertyDefinitionEnhancer>
73
74     fun getAttributeDefinitionEnhancers(): List<BluePrintAttributeDefinitionEnhancer>
75
76     fun enhanceServiceTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, serviceTemplate: ServiceTemplate) {
77         val enhancers = getServiceTemplateEnhancers()
78         doEnhancement(bluePrintRuntimeService, name, serviceTemplate, enhancers)
79     }
80
81     fun enhanceTopologyTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, topologyTemplate: TopologyTemplate) {
82         val enhancers = getTopologyTemplateEnhancers()
83         doEnhancement(bluePrintRuntimeService, name, topologyTemplate, enhancers)
84     }
85
86     fun enhanceWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, workflow: Workflow) {
87         val enhancers = getWorkflowEnhancers()
88         doEnhancement(bluePrintRuntimeService, name, workflow, enhancers)
89     }
90
91     fun enhanceNodeTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) {
92         val enhancers = getNodeTemplateEnhancers()
93         doEnhancement(bluePrintRuntimeService, name, nodeTemplate, enhancers)
94     }
95
96     fun enhanceNodeType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) {
97         val enhancers = getNodeTypeEnhancers()
98         doEnhancement(bluePrintRuntimeService, name, nodeType, enhancers)
99     }
100
101     fun enhanceArtifactDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, artifactDefinition: ArtifactDefinition) {
102         val enhancers = getArtifactDefinitionEnhancers()
103         doEnhancement(bluePrintRuntimeService, name, artifactDefinition, enhancers)
104     }
105
106     fun enhancePolicyType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, policyType: PolicyType) {
107         val enhancers = getPolicyTypeEnhancers()
108         doEnhancement(bluePrintRuntimeService, name, policyType, enhancers)
109     }
110
111     fun enhancePropertyDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, properties: MutableMap<String, PropertyDefinition>) {
112         properties.forEach { propertyName, propertyDefinition ->
113             enhancePropertyDefinition(bluePrintRuntimeService, propertyName, propertyDefinition)
114         }
115     }
116
117     fun enhancePropertyDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) {
118         val enhancers = getPropertyDefinitionEnhancers()
119         doEnhancement(bluePrintRuntimeService, name, propertyDefinition, enhancers)
120     }
121
122     fun enhanceAttributeDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, attributes: MutableMap<String, AttributeDefinition>) {
123         attributes.forEach { attributeName, attributeDefinition ->
124             enhanceAttributeDefinition(bluePrintRuntimeService, attributeName, attributeDefinition)
125         }
126     }
127
128     fun enhanceAttributeDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, attributeDefinition: AttributeDefinition) {
129         val enhancers = getAttributeDefinitionEnhancers()
130         doEnhancement(bluePrintRuntimeService, name, attributeDefinition, enhancers)
131     }
132
133     @Suppress("UNCHECKED_CAST")
134     private fun <T> doEnhancement(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, definition: Any, enhancers: List<BluePrintEnhancer<T>>) {
135         if (enhancers.isNotEmpty()) {
136             enhancers.forEach {
137                 it.enhance(bluePrintRuntimeService, name, definition as T)
138             }
139         }
140     }
141 }