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