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.BluePrintException
22 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
23 import org.onap.ccsdk.apps.controllerblueprints.core.data.InterfaceDefinition
24 import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType
25 import org.onap.ccsdk.apps.controllerblueprints.core.data.OperationDefinition
26 import org.onap.ccsdk.apps.controllerblueprints.core.format
27 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintNodeTypeEnhancer
28 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService
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.BluePrintRuntimeService
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 bluePrintRuntimeService: BluePrintRuntimeService<*>
44 lateinit var bluePrintContext: BluePrintContext
47 override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) {
48 this.bluePrintRuntimeService = bluePrintRuntimeService
49 this.bluePrintContext = bluePrintRuntimeService.bluePrintContext()
52 val derivedFrom = nodeType.derivedFrom
54 if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) {
55 val derivedFromNodeType = populateNodeType(name)
57 enhance(bluePrintRuntimeService, derivedFrom, derivedFromNodeType)
60 // NodeType Property Definitions
61 enrichNodeTypeProperties(name, nodeType)
63 //NodeType Requirement
64 enrichNodeTypeRequirements(name, nodeType)
67 enrichNodeTypeCapabilityProperties(name, nodeType)
70 enrichNodeTypeInterfaces(name, nodeType)
74 open fun enrichNodeTypeProperties(nodeTypeName: String, nodeType: NodeType) {
75 nodeType.properties?.let {
76 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, nodeType.properties!!)
80 open fun enrichNodeTypeRequirements(nodeTypeName: String, nodeType: NodeType) {
82 nodeType.requirements?.forEach { _, requirementDefinition ->
83 // Populate Requirement Node
84 requirementDefinition.node?.let { requirementNodeTypeName ->
85 // Get Requirement NodeType from Repo and Update Service Template
86 val requirementNodeType = populateNodeType(requirementNodeTypeName)
88 enhance(bluePrintRuntimeService, requirementNodeTypeName, requirementNodeType)
93 open fun enrichNodeTypeCapabilityProperties(nodeTypeName: String, nodeType: NodeType) {
94 nodeType.capabilities?.forEach { _, capabilityDefinition ->
95 capabilityDefinition.properties?.let { properties ->
96 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, properties)
101 open fun enrichNodeTypeInterfaces(nodeTypeName: String, nodeType: NodeType) {
102 nodeType.interfaces?.forEach { interfaceName, interfaceObj ->
103 // Populate Node type Interface Operation
104 log.debug("Enriching NodeType({}) Interface({})", nodeTypeName, interfaceName)
105 populateNodeTypeInterfaceOperation(nodeTypeName, interfaceName, interfaceObj)
110 open fun populateNodeTypeInterfaceOperation(nodeTypeName: String, interfaceName: String, interfaceObj: InterfaceDefinition) {
112 interfaceObj.operations?.forEach { operationName, operation ->
113 enrichNodeTypeInterfaceOperationInputs(nodeTypeName, operationName, operation)
114 enrichNodeTypeInterfaceOperationOputputs(nodeTypeName, operationName, operation)
118 open fun enrichNodeTypeInterfaceOperationInputs(nodeTypeName: String, operationName: String, operation: OperationDefinition) {
119 operation.inputs?.let { inputs ->
120 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs)
124 open fun enrichNodeTypeInterfaceOperationOputputs(nodeTypeName: String, operationName: String, operation: OperationDefinition) {
125 operation.outputs?.let { inputs ->
126 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs)
130 open fun populateNodeType(nodeTypeName: String): NodeType {
132 val nodeType = bluePrintContext.serviceTemplate.nodeTypes?.get(nodeTypeName)
133 ?: bluePrintRepoService.getNodeType(nodeTypeName)
134 ?: throw BluePrintException(format("Couldn't get NodeType({}) from repo.", nodeTypeName))
135 bluePrintContext.serviceTemplate.nodeTypes?.put(nodeTypeName, nodeType)