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.service.enhancer
19 import com.att.eelf.configuration.EELFLogger
20 import com.att.eelf.configuration.EELFManager
21 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError
22 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
23 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
24 import org.onap.ccsdk.apps.controllerblueprints.core.data.InterfaceDefinition
25 import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType
26 import org.onap.ccsdk.apps.controllerblueprints.core.data.OperationDefinition
27 import org.onap.ccsdk.apps.controllerblueprints.core.format
28 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintNodeTypeEnhancer
29 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService
30 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
31 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService
32 import org.springframework.beans.factory.config.ConfigurableBeanFactory
33 import org.springframework.context.annotation.Scope
34 import org.springframework.stereotype.Service
37 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
38 open class BluePrintNodeTypeEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService,
39 private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) : BluePrintNodeTypeEnhancer {
41 private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintNodeTypeEnhancerImpl::class.toString())
43 lateinit var bluePrintContext: BluePrintContext
44 lateinit var error: BluePrintError
46 override fun enhance(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, nodeType: NodeType) {
47 this.bluePrintContext = bluePrintContext
50 val derivedFrom = nodeType.derivedFrom
52 if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) {
53 val derivedFromNodeType = populateNodeType(name)
55 enhance(bluePrintContext, error, derivedFrom, derivedFromNodeType)
58 // NodeType Property Definitions
59 enrichNodeTypeProperties(name, nodeType)
61 //NodeType Requirement
62 enrichNodeTypeRequirements(name, nodeType)
65 enrichNodeTypeCapabilityProperties(name, nodeType)
68 enrichNodeTypeInterfaces(name, nodeType)
72 open fun enrichNodeTypeProperties(nodeTypeName: String, nodeType: NodeType) {
73 nodeType.properties?.let {
74 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintContext, error, nodeType.properties!!)
78 open fun enrichNodeTypeRequirements(nodeTypeName: String, nodeType: NodeType) {
80 nodeType.requirements?.forEach { _, requirementDefinition ->
81 // Populate Requirement Node
82 requirementDefinition.node?.let { requirementNodeTypeName ->
83 // Get Requirement NodeType from Repo and Update Service Template
84 val requirementNodeType = populateNodeType(requirementNodeTypeName)
86 enhance(bluePrintContext, error, requirementNodeTypeName, requirementNodeType)
91 open fun enrichNodeTypeCapabilityProperties(nodeTypeName: String, nodeType: NodeType) {
92 nodeType.capabilities?.forEach { _, capabilityDefinition ->
93 capabilityDefinition.properties?.let { properties ->
94 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintContext, error, properties)
99 open fun enrichNodeTypeInterfaces(nodeTypeName: String, nodeType: NodeType) {
100 nodeType.interfaces?.forEach { interfaceName, interfaceObj ->
101 // Populate Node type Interface Operation
102 log.debug("Enriching NodeType({}) Interface({})", nodeTypeName, interfaceName)
103 populateNodeTypeInterfaceOperation(nodeTypeName, interfaceName, interfaceObj)
108 open fun populateNodeTypeInterfaceOperation(nodeTypeName: String, interfaceName: String, interfaceObj: InterfaceDefinition) {
110 interfaceObj.operations?.forEach { operationName, operation ->
111 enrichNodeTypeInterfaceOperationInputs(nodeTypeName, operationName, operation)
112 enrichNodeTypeInterfaceOperationOputputs(nodeTypeName, operationName, operation)
116 open fun enrichNodeTypeInterfaceOperationInputs(nodeTypeName: String, operationName: String, operation: OperationDefinition) {
117 operation.inputs?.let { inputs ->
118 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintContext, error, inputs)
122 open fun enrichNodeTypeInterfaceOperationOputputs(nodeTypeName: String, operationName: String, operation: OperationDefinition) {
123 operation.outputs?.let { inputs ->
124 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintContext, error, inputs)
128 open fun populateNodeType(nodeTypeName: String): NodeType {
130 val nodeType = bluePrintContext.serviceTemplate.nodeTypes?.get(nodeTypeName)
131 ?: bluePrintRepoService.getNodeType(nodeTypeName)
132 ?: throw BluePrintException(format("Couldn't get NodeType({}) from repo.", nodeTypeName))
133 bluePrintContext.serviceTemplate.nodeTypes?.put(nodeTypeName, nodeType)