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.apps.controllerblueprints.core.interfaces
20 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
21 import org.onap.ccsdk.apps.controllerblueprints.core.data.*
22 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
23 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
25 interface BluePrintEnhancer<T> {
26 fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: T)
29 interface BluePrintServiceTemplateEnhancer : BluePrintEnhancer<ServiceTemplate>
31 interface BluePrintTopologyTemplateEnhancer : BluePrintEnhancer<TopologyTemplate>
33 interface BluePrintWorkflowEnhancer : BluePrintEnhancer<Workflow>
35 interface BluePrintNodeTemplateEnhancer : BluePrintEnhancer<NodeTemplate>
37 interface BluePrintNodeTypeEnhancer : BluePrintEnhancer<NodeType>
39 interface BluePrintArtifactDefinitionEnhancer : BluePrintEnhancer<ArtifactDefinition>
41 interface BluePrintPolicyTypeEnhancer : BluePrintEnhancer<PolicyType>
43 interface BluePrintPropertyDefinitionEnhancer : BluePrintEnhancer<PropertyDefinition>
45 interface BluePrintAttributeDefinitionEnhancer : BluePrintEnhancer<AttributeDefinition>
48 interface BluePrintEnhancerService {
50 @Throws(BluePrintException::class)
51 suspend fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext
53 @Throws(BluePrintException::class)
54 suspend fun enhance(basePath: String): BluePrintContext
57 interface BluePrintTypeEnhancerService {
59 fun getServiceTemplateEnhancers(): List<BluePrintServiceTemplateEnhancer>
61 fun getTopologyTemplateEnhancers(): List<BluePrintTopologyTemplateEnhancer>
63 fun getWorkflowEnhancers(): List<BluePrintWorkflowEnhancer>
65 fun getNodeTemplateEnhancers(): List<BluePrintNodeTemplateEnhancer>
67 fun getNodeTypeEnhancers(): List<BluePrintNodeTypeEnhancer>
69 fun getArtifactDefinitionEnhancers(): List<BluePrintArtifactDefinitionEnhancer>
71 fun getPolicyTypeEnhancers(): List<BluePrintPolicyTypeEnhancer>
73 fun getPropertyDefinitionEnhancers(): List<BluePrintPropertyDefinitionEnhancer>
75 fun getAttributeDefinitionEnhancers(): List<BluePrintAttributeDefinitionEnhancer>
77 fun enhanceServiceTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, serviceTemplate: ServiceTemplate) {
78 val enhancers = getServiceTemplateEnhancers()
79 doEnhancement(bluePrintRuntimeService, name, serviceTemplate, enhancers)
82 fun enhanceTopologyTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, topologyTemplate: TopologyTemplate) {
83 val enhancers = getTopologyTemplateEnhancers()
84 doEnhancement(bluePrintRuntimeService, name, topologyTemplate, enhancers)
87 fun enhanceWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, workflow: Workflow) {
88 val enhancers = getWorkflowEnhancers()
89 doEnhancement(bluePrintRuntimeService, name, workflow, enhancers)
92 fun enhanceNodeTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) {
93 val enhancers = getNodeTemplateEnhancers()
94 doEnhancement(bluePrintRuntimeService, name, nodeTemplate, enhancers)
97 fun enhanceNodeType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) {
98 val enhancers = getNodeTypeEnhancers()
99 doEnhancement(bluePrintRuntimeService, name, nodeType, enhancers)
102 fun enhanceArtifactDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, artifactDefinition: ArtifactDefinition) {
103 val enhancers = getArtifactDefinitionEnhancers()
104 doEnhancement(bluePrintRuntimeService, name, artifactDefinition, enhancers)
107 fun enhancePolicyType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, policyType: PolicyType) {
108 val enhancers = getPolicyTypeEnhancers()
109 doEnhancement(bluePrintRuntimeService, name, policyType, enhancers)
112 fun enhancePropertyDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, properties: MutableMap<String, PropertyDefinition>) {
113 properties.forEach { propertyName, propertyDefinition ->
114 enhancePropertyDefinition(bluePrintRuntimeService, propertyName, propertyDefinition)
118 fun enhancePropertyDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) {
119 val enhancers = getPropertyDefinitionEnhancers()
120 doEnhancement(bluePrintRuntimeService, name, propertyDefinition, enhancers)
123 fun enhanceAttributeDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, attributes: MutableMap<String, AttributeDefinition>) {
124 attributes.forEach { attributeName, attributeDefinition ->
125 enhanceAttributeDefinition(bluePrintRuntimeService, attributeName, attributeDefinition)
129 fun enhanceAttributeDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, attributeDefinition: AttributeDefinition) {
130 val enhancers = getAttributeDefinitionEnhancers()
131 doEnhancement(bluePrintRuntimeService, name, attributeDefinition, enhancers)
134 @Suppress("UNCHECKED_CAST")
135 private fun <T> doEnhancement(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, definition: Any, enhancers: List<BluePrintEnhancer<T>>) {
136 if (enhancers.isNotEmpty()) {
138 it.enhance(bluePrintRuntimeService, name, definition as T)