2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2019 IBM.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org.onap.ccsdk.cds.controllerblueprints.core.interfaces
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
35 interface BluePrintEnhancer<T> {
37 fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: T)
40 interface BluePrintServiceTemplateEnhancer : BluePrintEnhancer<ServiceTemplate>
42 interface BluePrintTopologyTemplateEnhancer : BluePrintEnhancer<TopologyTemplate>
44 interface BluePrintWorkflowEnhancer : BluePrintEnhancer<Workflow>
46 interface BluePrintNodeTemplateEnhancer : BluePrintEnhancer<NodeTemplate>
48 interface BluePrintNodeTypeEnhancer : BluePrintEnhancer<NodeType>
50 interface BluePrintRelationshipTemplateEnhancer : BluePrintEnhancer<RelationshipTemplate>
52 interface BluePrintRelationshipTypeEnhancer : BluePrintEnhancer<RelationshipType>
54 interface BluePrintArtifactDefinitionEnhancer : BluePrintEnhancer<ArtifactDefinition>
56 interface BluePrintPolicyTypeEnhancer : BluePrintEnhancer<PolicyType>
58 interface BluePrintPropertyDefinitionEnhancer : BluePrintEnhancer<PropertyDefinition>
60 interface BluePrintAttributeDefinitionEnhancer : BluePrintEnhancer<AttributeDefinition>
62 interface BluePrintEnhancerService {
64 @Throws(BluePrintException::class)
65 suspend fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext
67 @Throws(BluePrintException::class)
68 suspend fun enhance(basePath: String): BluePrintContext
71 interface BluePrintTypeEnhancerService {
73 fun getServiceTemplateEnhancers(): List<BluePrintServiceTemplateEnhancer>
75 fun getTopologyTemplateEnhancers(): List<BluePrintTopologyTemplateEnhancer>
77 fun getWorkflowEnhancers(): List<BluePrintWorkflowEnhancer>
79 fun getNodeTemplateEnhancers(): List<BluePrintNodeTemplateEnhancer>
81 fun getNodeTypeEnhancers(): List<BluePrintNodeTypeEnhancer>
83 fun getRelationshipTemplateEnhancers(): List<BluePrintRelationshipTemplateEnhancer>
85 fun getRelationshipTypeEnhancers(): List<BluePrintRelationshipTypeEnhancer>
87 fun getArtifactDefinitionEnhancers(): List<BluePrintArtifactDefinitionEnhancer>
89 fun getPolicyTypeEnhancers(): List<BluePrintPolicyTypeEnhancer>
91 fun getPropertyDefinitionEnhancers(): List<BluePrintPropertyDefinitionEnhancer>
93 fun getAttributeDefinitionEnhancers(): List<BluePrintAttributeDefinitionEnhancer>
95 fun enhanceServiceTemplate(
96 bluePrintRuntimeService: BluePrintRuntimeService<*>,
98 serviceTemplate: ServiceTemplate
100 val enhancers = getServiceTemplateEnhancers()
101 doEnhancement(bluePrintRuntimeService, name, serviceTemplate, enhancers)
104 fun enhanceTopologyTemplate(
105 bluePrintRuntimeService: BluePrintRuntimeService<*>,
107 topologyTemplate: TopologyTemplate
109 val enhancers = getTopologyTemplateEnhancers()
110 doEnhancement(bluePrintRuntimeService, name, topologyTemplate, enhancers)
113 fun enhanceWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, workflow: Workflow) {
114 val enhancers = getWorkflowEnhancers()
115 doEnhancement(bluePrintRuntimeService, name, workflow, enhancers)
118 fun enhanceNodeTemplate(
119 bluePrintRuntimeService: BluePrintRuntimeService<*>,
121 nodeTemplate: NodeTemplate
123 val enhancers = getNodeTemplateEnhancers()
124 doEnhancement(bluePrintRuntimeService, name, nodeTemplate, enhancers)
127 fun enhanceNodeType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) {
128 val enhancers = getNodeTypeEnhancers()
129 doEnhancement(bluePrintRuntimeService, name, nodeType, enhancers)
132 fun enhanceRelationshipTemplate(
133 bluePrintRuntimeService: BluePrintRuntimeService<*>,
135 relationshipTemplate: RelationshipTemplate
137 val enhancers = getRelationshipTemplateEnhancers()
138 doEnhancement(bluePrintRuntimeService, name, relationshipTemplate, enhancers)
141 fun enhanceRelationshipType(
142 bluePrintRuntimeService: BluePrintRuntimeService<*>,
144 relationshipType: RelationshipType
146 val enhancers = getRelationshipTypeEnhancers()
147 doEnhancement(bluePrintRuntimeService, name, relationshipType, enhancers)
150 fun enhanceArtifactDefinition(
151 bluePrintRuntimeService: BluePrintRuntimeService<*>,
153 artifactDefinition: ArtifactDefinition
155 val enhancers = getArtifactDefinitionEnhancers()
156 doEnhancement(bluePrintRuntimeService, name, artifactDefinition, enhancers)
159 fun enhancePolicyType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, policyType: PolicyType) {
160 val enhancers = getPolicyTypeEnhancers()
161 doEnhancement(bluePrintRuntimeService, name, policyType, enhancers)
164 fun enhancePropertyDefinitions(
165 bluePrintRuntimeService: BluePrintRuntimeService<*>,
166 properties: MutableMap<String, PropertyDefinition>
168 val errorMap = linkedMapOf<String, BluePrintException>()
169 properties.forEach { propertyName, propertyDefinition ->
171 enhancePropertyDefinition(bluePrintRuntimeService, propertyName, propertyDefinition)
172 } catch (e: BluePrintException) {
173 errorMap[propertyName] = e
176 if (errorMap.isNotEmpty()) {
177 val nestedErrors = errorMap.keys.map { "[ property: ${errorMap[it]?.message} ]" }.joinToString(";")
178 throw BluePrintException("Failed to enhance properties $nestedErrors")
182 fun enhancePropertyDefinition(
183 bluePrintRuntimeService: BluePrintRuntimeService<*>,
185 propertyDefinition: PropertyDefinition
187 val enhancers = getPropertyDefinitionEnhancers()
188 doEnhancement(bluePrintRuntimeService, name, propertyDefinition, enhancers)
191 fun enhanceAttributeDefinitions(
192 bluePrintRuntimeService: BluePrintRuntimeService<*>,
193 attributes: MutableMap<String, AttributeDefinition>
195 val errorMap = linkedMapOf<String, BluePrintException>()
196 attributes.forEach { attributeName, attributeDefinition ->
198 enhanceAttributeDefinition(bluePrintRuntimeService, attributeName, attributeDefinition)
199 } catch (e: BluePrintException) {
200 errorMap[attributeName] = e
203 if (errorMap.isNotEmpty()) {
204 val nestedErrors = errorMap.keys.map { "[ attribute: ${errorMap[it]?.message} ]" }.joinToString(";")
205 throw BluePrintException("Failed to enhance attributes $nestedErrors")
209 fun enhanceAttributeDefinition(
210 bluePrintRuntimeService: BluePrintRuntimeService<*>,
212 attributeDefinition: AttributeDefinition
214 val enhancers = getAttributeDefinitionEnhancers()
215 doEnhancement(bluePrintRuntimeService, name, attributeDefinition, enhancers)
218 @Suppress("UNCHECKED_CAST")
219 private fun <T> doEnhancement(
220 bluePrintRuntimeService: BluePrintRuntimeService<*>,
223 enhancers: List<BluePrintEnhancer<T>>
225 if (enhancers.isNotEmpty()) {
226 val errorMap = linkedMapOf<String, BluePrintException>()
229 it.enhance(bluePrintRuntimeService, name, definition as T)
230 } catch (e: BluePrintException) {
234 if (errorMap.isNotEmpty()) {
235 val nestedErrors = errorMap.keys.map {
236 "${errorMap[it]?.message ?: errorMap[it].toString()}"
238 throw BluePrintException("$name-->$nestedErrors")