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 BluePrintArtifactDefinitionEnhancer : BluePrintEnhancer<ArtifactDefinition>
40 interface BluePrintPolicyTypeEnhancer : BluePrintEnhancer<PolicyType>
42 interface BluePrintPropertyDefinitionEnhancer : BluePrintEnhancer<PropertyDefinition>
44 interface BluePrintAttributeDefinitionEnhancer : BluePrintEnhancer<AttributeDefinition>
47 interface BluePrintEnhancerService {
49 @Throws(BluePrintException::class)
50 fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext
52 @Throws(BluePrintException::class)
53 fun enhance(basePath: String): BluePrintContext
56 interface BluePrintTypeEnhancerService {
58 fun getServiceTemplateEnhancers(): List<BluePrintServiceTemplateEnhancer>
60 fun getTopologyTemplateEnhancers(): List<BluePrintTopologyTemplateEnhancer>
62 fun getWorkflowEnhancers(): List<BluePrintWorkflowEnhancer>
64 fun getNodeTemplateEnhancers(): List<BluePrintNodeTemplateEnhancer>
66 fun getNodeTypeEnhancers(): List<BluePrintNodeTypeEnhancer>
68 fun getArtifactDefinitionEnhancers(): List<BluePrintArtifactDefinitionEnhancer>
70 fun getPolicyTypeEnhancers(): List<BluePrintPolicyTypeEnhancer>
72 fun getPropertyDefinitionEnhancers(): List<BluePrintPropertyDefinitionEnhancer>
74 fun getAttributeDefinitionEnhancers(): List<BluePrintAttributeDefinitionEnhancer>
76 fun enhanceServiceTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, serviceTemplate: ServiceTemplate) {
77 val enhancers = getServiceTemplateEnhancers()
78 doEnhancement(bluePrintRuntimeService, name, serviceTemplate, enhancers)
81 fun enhanceTopologyTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, topologyTemplate: TopologyTemplate) {
82 val enhancers = getTopologyTemplateEnhancers()
83 doEnhancement(bluePrintRuntimeService, name, topologyTemplate, enhancers)
86 fun enhanceWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, workflow: Workflow) {
87 val enhancers = getWorkflowEnhancers()
88 doEnhancement(bluePrintRuntimeService, name, workflow, enhancers)
91 fun enhanceNodeTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) {
92 val enhancers = getNodeTemplateEnhancers()
93 doEnhancement(bluePrintRuntimeService, name, nodeTemplate, enhancers)
96 fun enhanceNodeType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) {
97 val enhancers = getNodeTypeEnhancers()
98 doEnhancement(bluePrintRuntimeService, name, nodeType, enhancers)
101 fun enhanceArtifactDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, artifactDefinition: ArtifactDefinition) {
102 val enhancers = getArtifactDefinitionEnhancers()
103 doEnhancement(bluePrintRuntimeService, name, artifactDefinition, enhancers)
106 fun enhancePolicyType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, policyType: PolicyType) {
107 val enhancers = getPolicyTypeEnhancers()
108 doEnhancement(bluePrintRuntimeService, name, policyType, enhancers)
111 fun enhancePropertyDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, properties: MutableMap<String, PropertyDefinition>) {
112 properties.forEach { propertyName, propertyDefinition ->
113 enhancePropertyDefinition(bluePrintRuntimeService, propertyName, propertyDefinition)
117 fun enhancePropertyDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) {
118 val enhancers = getPropertyDefinitionEnhancers()
119 doEnhancement(bluePrintRuntimeService, name, propertyDefinition, enhancers)
122 fun enhanceAttributeDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, attributes: MutableMap<String, AttributeDefinition>) {
123 attributes.forEach { attributeName, attributeDefinition ->
124 enhanceAttributeDefinition(bluePrintRuntimeService, attributeName, attributeDefinition)
128 fun enhanceAttributeDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, attributeDefinition: AttributeDefinition) {
129 val enhancers = getAttributeDefinitionEnhancers()
130 doEnhancement(bluePrintRuntimeService, name, attributeDefinition, enhancers)
133 @Suppress("UNCHECKED_CAST")
134 private fun <T> doEnhancement(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, definition: Any, enhancers: List<BluePrintEnhancer<T>>) {
135 if (enhancers.isNotEmpty()) {
137 it.enhance(bluePrintRuntimeService, name, definition as T)