f6659e7dbe2d8a68034f01917aec2f4d877046ce
[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 BluePrintPolicyTypeEnhancer : BluePrintEnhancer<PolicyType>
39
40 interface BluePrintPropertyDefinitionEnhancer : BluePrintEnhancer<PropertyDefinition>
41
42 interface BluePrintAttributeDefinitionEnhancer : BluePrintEnhancer<AttributeDefinition>
43
44
45 interface BluePrintEnhancerService {
46
47     @Throws(BluePrintException::class)
48     fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext
49
50     @Throws(BluePrintException::class)
51     fun enhance(basePath: String): BluePrintContext
52 }
53
54 interface BluePrintTypeEnhancerService {
55
56     fun getServiceTemplateEnhancers(): List<BluePrintServiceTemplateEnhancer>
57
58     fun getTopologyTemplateEnhancers(): List<BluePrintTopologyTemplateEnhancer>
59
60     fun getWorkflowEnhancers(): List<BluePrintWorkflowEnhancer>
61
62     fun getNodeTemplateEnhancers(): List<BluePrintNodeTemplateEnhancer>
63
64     fun getNodeTypeEnhancers(): List<BluePrintNodeTypeEnhancer>
65
66     fun getPolicyTypeEnhancers(): List<BluePrintPolicyTypeEnhancer>
67
68     fun getPropertyDefinitionEnhancers(): List<BluePrintPropertyDefinitionEnhancer>
69
70     fun getAttributeDefinitionEnhancers(): List<BluePrintAttributeDefinitionEnhancer>
71
72     fun enhanceServiceTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, serviceTemplate: ServiceTemplate) {
73         val enhancers = getServiceTemplateEnhancers()
74         doEnhancement(bluePrintRuntimeService, name, serviceTemplate, enhancers)
75     }
76
77     fun enhanceTopologyTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, topologyTemplate: TopologyTemplate) {
78         val enhancers = getTopologyTemplateEnhancers()
79         doEnhancement(bluePrintRuntimeService, name, topologyTemplate, enhancers)
80     }
81
82     fun enhanceWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, workflow: Workflow) {
83         val enhancers = getWorkflowEnhancers()
84         doEnhancement(bluePrintRuntimeService, name, workflow, enhancers)
85     }
86
87     fun enhanceNodeTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) {
88         val enhancers = getNodeTemplateEnhancers()
89         doEnhancement(bluePrintRuntimeService, name, nodeTemplate, enhancers)
90     }
91
92     fun enhanceNodeType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) {
93         val enhancers = getNodeTypeEnhancers()
94         doEnhancement(bluePrintRuntimeService, name, nodeType, enhancers)
95     }
96
97     fun enhancePolicyType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, policyType: PolicyType) {
98         val enhancers = getPolicyTypeEnhancers()
99         doEnhancement(bluePrintRuntimeService, name, policyType, enhancers)
100     }
101
102     fun enhancePropertyDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, properties: MutableMap<String, PropertyDefinition>) {
103         properties.forEach { propertyName, propertyDefinition ->
104             enhancePropertyDefinition(bluePrintRuntimeService, propertyName, propertyDefinition)
105         }
106     }
107
108     fun enhancePropertyDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) {
109         val enhancers = getPropertyDefinitionEnhancers()
110         doEnhancement(bluePrintRuntimeService, name, propertyDefinition, enhancers)
111     }
112
113     fun enhanceAttributeDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, attributes: MutableMap<String, AttributeDefinition>) {
114         attributes.forEach { attributeName, attributeDefinition ->
115             enhanceAttributeDefinition(bluePrintRuntimeService, attributeName, attributeDefinition)
116         }
117     }
118
119     fun enhanceAttributeDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, attributeDefinition: AttributeDefinition) {
120         val enhancers = getAttributeDefinitionEnhancers()
121         doEnhancement(bluePrintRuntimeService, name, attributeDefinition, enhancers)
122     }
123
124     @Suppress("UNCHECKED_CAST")
125     private fun <T> doEnhancement(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, definition: Any, enhancers: List<BluePrintEnhancer<T>>) {
126         if (enhancers.isNotEmpty()) {
127             enhancers.forEach {
128                 it.enhance(bluePrintRuntimeService, name, definition as T)
129             }
130         }
131     }
132 }