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.ServiceTemplate
28 import org.onap.ccsdk.cds.controllerblueprints.core.data.TopologyTemplate
29 import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow
30 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
31 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
33 interface BluePrintEnhancer<T> {
34 fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: T)
37 interface BluePrintServiceTemplateEnhancer : BluePrintEnhancer<ServiceTemplate>
39 interface BluePrintTopologyTemplateEnhancer : BluePrintEnhancer<TopologyTemplate>
41 interface BluePrintWorkflowEnhancer : BluePrintEnhancer<Workflow>
43 interface BluePrintNodeTemplateEnhancer : BluePrintEnhancer<NodeTemplate>
45 interface BluePrintNodeTypeEnhancer : BluePrintEnhancer<NodeType>
47 interface BluePrintArtifactDefinitionEnhancer : BluePrintEnhancer<ArtifactDefinition>
49 interface BluePrintPolicyTypeEnhancer : BluePrintEnhancer<PolicyType>
51 interface BluePrintPropertyDefinitionEnhancer : BluePrintEnhancer<PropertyDefinition>
53 interface BluePrintAttributeDefinitionEnhancer : BluePrintEnhancer<AttributeDefinition>
55 interface BluePrintEnhancerService {
57 @Throws(BluePrintException::class)
58 suspend fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext
60 @Throws(BluePrintException::class)
61 suspend fun enhance(basePath: String): BluePrintContext
64 interface BluePrintTypeEnhancerService {
66 fun getServiceTemplateEnhancers(): List<BluePrintServiceTemplateEnhancer>
68 fun getTopologyTemplateEnhancers(): List<BluePrintTopologyTemplateEnhancer>
70 fun getWorkflowEnhancers(): List<BluePrintWorkflowEnhancer>
72 fun getNodeTemplateEnhancers(): List<BluePrintNodeTemplateEnhancer>
74 fun getNodeTypeEnhancers(): List<BluePrintNodeTypeEnhancer>
76 fun getArtifactDefinitionEnhancers(): List<BluePrintArtifactDefinitionEnhancer>
78 fun getPolicyTypeEnhancers(): List<BluePrintPolicyTypeEnhancer>
80 fun getPropertyDefinitionEnhancers(): List<BluePrintPropertyDefinitionEnhancer>
82 fun getAttributeDefinitionEnhancers(): List<BluePrintAttributeDefinitionEnhancer>
84 fun enhanceServiceTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, serviceTemplate: ServiceTemplate) {
85 val enhancers = getServiceTemplateEnhancers()
86 doEnhancement(bluePrintRuntimeService, name, serviceTemplate, enhancers)
89 fun enhanceTopologyTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, topologyTemplate: TopologyTemplate) {
90 val enhancers = getTopologyTemplateEnhancers()
91 doEnhancement(bluePrintRuntimeService, name, topologyTemplate, enhancers)
94 fun enhanceWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, workflow: Workflow) {
95 val enhancers = getWorkflowEnhancers()
96 doEnhancement(bluePrintRuntimeService, name, workflow, enhancers)
99 fun enhanceNodeTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) {
100 val enhancers = getNodeTemplateEnhancers()
101 doEnhancement(bluePrintRuntimeService, name, nodeTemplate, enhancers)
104 fun enhanceNodeType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) {
105 val enhancers = getNodeTypeEnhancers()
106 doEnhancement(bluePrintRuntimeService, name, nodeType, enhancers)
109 fun enhanceArtifactDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, artifactDefinition: ArtifactDefinition) {
110 val enhancers = getArtifactDefinitionEnhancers()
111 doEnhancement(bluePrintRuntimeService, name, artifactDefinition, enhancers)
114 fun enhancePolicyType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, policyType: PolicyType) {
115 val enhancers = getPolicyTypeEnhancers()
116 doEnhancement(bluePrintRuntimeService, name, policyType, enhancers)
119 fun enhancePropertyDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, properties: MutableMap<String, PropertyDefinition>) {
120 properties.forEach { propertyName, propertyDefinition ->
121 enhancePropertyDefinition(bluePrintRuntimeService, propertyName, propertyDefinition)
125 fun enhancePropertyDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) {
126 val enhancers = getPropertyDefinitionEnhancers()
127 doEnhancement(bluePrintRuntimeService, name, propertyDefinition, enhancers)
130 fun enhanceAttributeDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, attributes: MutableMap<String, AttributeDefinition>) {
131 attributes.forEach { attributeName, attributeDefinition ->
132 enhanceAttributeDefinition(bluePrintRuntimeService, attributeName, attributeDefinition)
136 fun enhanceAttributeDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, attributeDefinition: AttributeDefinition) {
137 val enhancers = getAttributeDefinitionEnhancers()
138 doEnhancement(bluePrintRuntimeService, name, attributeDefinition, enhancers)
141 @Suppress("UNCHECKED_CAST")
142 private fun <T> doEnhancement(
143 bluePrintRuntimeService: BluePrintRuntimeService<*>,
146 enhancers: List<BluePrintEnhancer<T>>
148 if (enhancers.isNotEmpty()) {
150 it.enhance(bluePrintRuntimeService, name, definition as T)