2 * Copyright © 2017-2018 AT&T Intellectual Property.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.ccsdk.apps.controllerblueprints.core.interfaces
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
24 interface BluePrintEnhancer<T> {
25 fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: T)
28 interface BluePrintServiceTemplateEnhancer : BluePrintEnhancer<ServiceTemplate>
30 interface BluePrintTopologyTemplateEnhancer : BluePrintEnhancer<TopologyTemplate>
32 interface BluePrintWorkflowEnhancer : BluePrintEnhancer<Workflow>
34 interface BluePrintNodeTemplateEnhancer : BluePrintEnhancer<NodeTemplate>
36 interface BluePrintNodeTypeEnhancer : BluePrintEnhancer<NodeType>
38 interface BluePrintPolicyTypeEnhancer : BluePrintEnhancer<PolicyType>
40 interface BluePrintPropertyDefinitionEnhancer : BluePrintEnhancer<PropertyDefinition>
42 interface BluePrintAttributeDefinitionEnhancer : BluePrintEnhancer<AttributeDefinition>
45 interface BluePrintEnhancerService {
47 @Throws(BluePrintException::class)
48 fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext
50 @Throws(BluePrintException::class)
51 fun enhance(basePath: String): BluePrintContext
54 interface BluePrintTypeEnhancerService {
56 fun getServiceTemplateEnhancers(): List<BluePrintServiceTemplateEnhancer>
58 fun getTopologyTemplateEnhancers(): List<BluePrintTopologyTemplateEnhancer>
60 fun getWorkflowEnhancers(): List<BluePrintWorkflowEnhancer>
62 fun getNodeTemplateEnhancers(): List<BluePrintNodeTemplateEnhancer>
64 fun getNodeTypeEnhancers(): List<BluePrintNodeTypeEnhancer>
66 fun getPolicyTypeEnhancers(): List<BluePrintPolicyTypeEnhancer>
68 fun getPropertyDefinitionEnhancers(): List<BluePrintPropertyDefinitionEnhancer>
70 fun getAttributeDefinitionEnhancers(): List<BluePrintAttributeDefinitionEnhancer>
72 fun enhanceServiceTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, serviceTemplate: ServiceTemplate) {
73 val enhancers = getServiceTemplateEnhancers()
74 doEnhancement(bluePrintRuntimeService, name, serviceTemplate, enhancers)
77 fun enhanceTopologyTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, topologyTemplate: TopologyTemplate) {
78 val enhancers = getTopologyTemplateEnhancers()
79 doEnhancement(bluePrintRuntimeService, name, topologyTemplate, enhancers)
82 fun enhanceWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, workflow: Workflow) {
83 val enhancers = getWorkflowEnhancers()
84 doEnhancement(bluePrintRuntimeService, name, workflow, enhancers)
87 fun enhanceNodeTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) {
88 val enhancers = getNodeTemplateEnhancers()
89 doEnhancement(bluePrintRuntimeService, name, nodeTemplate, enhancers)
92 fun enhanceNodeType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) {
93 val enhancers = getNodeTypeEnhancers()
94 doEnhancement(bluePrintRuntimeService, name, nodeType, enhancers)
97 fun enhancePolicyType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, policyType: PolicyType) {
98 val enhancers = getPolicyTypeEnhancers()
99 doEnhancement(bluePrintRuntimeService, name, policyType, enhancers)
102 fun enhancePropertyDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, properties: MutableMap<String, PropertyDefinition>) {
103 properties.forEach { propertyName, propertyDefinition ->
104 enhancePropertyDefinition(bluePrintRuntimeService, propertyName, propertyDefinition)
108 fun enhancePropertyDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) {
109 val enhancers = getPropertyDefinitionEnhancers()
110 doEnhancement(bluePrintRuntimeService, name, propertyDefinition, enhancers)
113 fun enhanceAttributeDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, attributes: MutableMap<String, AttributeDefinition>) {
114 attributes.forEach { attributeName, attributeDefinition ->
115 enhanceAttributeDefinition(bluePrintRuntimeService, attributeName, attributeDefinition)
119 fun enhanceAttributeDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, attributeDefinition: AttributeDefinition) {
120 val enhancers = getAttributeDefinitionEnhancers()
121 doEnhancement(bluePrintRuntimeService, name, attributeDefinition, enhancers)
124 @Suppress("UNCHECKED_CAST")
125 private fun <T> doEnhancement(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, definition: Any, enhancers: List<BluePrintEnhancer<T>>) {
126 if (enhancers.isNotEmpty()) {
128 it.enhance(bluePrintRuntimeService, name, definition as T)