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.cds.controllerblueprints.service.enhancer
19 import com.att.eelf.configuration.EELFLogger
20 import com.att.eelf.configuration.EELFManager
21 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
22 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
23 import org.onap.ccsdk.cds.controllerblueprints.core.data.InterfaceDefinition
24 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType
25 import org.onap.ccsdk.cds.controllerblueprints.core.data.OperationDefinition
26 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintNodeTypeEnhancer
27 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRepoService
28 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService
29 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
30 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
31 import org.onap.ccsdk.cds.controllerblueprints.service.utils.BluePrintEnhancerUtils
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 = BluePrintEnhancerUtils.populateNodeType(bluePrintContext, bluePrintRepoService, name)
57 enhance(bluePrintRuntimeService, derivedFrom, derivedFromNodeType)
60 // NodeType Attribute Definitions
61 enrichNodeTypeAttributes(name, nodeType)
63 // NodeType Property Definitions
64 enrichNodeTypeProperties(name, nodeType)
66 //NodeType Requirement
67 enrichNodeTypeRequirements(name, nodeType)
70 enrichNodeTypeCapabilityProperties(name, nodeType)
73 enrichNodeTypeInterfaces(name, nodeType)
77 open fun enrichNodeTypeAttributes(nodeTypeName: String, nodeType: NodeType) {
78 nodeType.attributes?.let {
79 bluePrintTypeEnhancerService.enhanceAttributeDefinitions(bluePrintRuntimeService, nodeType.attributes!!)
83 open fun enrichNodeTypeProperties(nodeTypeName: String, nodeType: NodeType) {
84 nodeType.properties?.let {
85 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, nodeType.properties!!)
89 open fun enrichNodeTypeRequirements(nodeTypeName: String, nodeType: NodeType) {
91 nodeType.requirements?.forEach { requirementName, requirementDefinition ->
92 // Populate Requirement Node
93 requirementDefinition.node?.let { requirementNodeTypeName ->
94 // Get Requirement NodeType from Repo and Update Service Template
95 val requirementNodeType = BluePrintEnhancerUtils.populateNodeType(bluePrintContext,
96 bluePrintRepoService, requirementNodeTypeName)
98 enhance(bluePrintRuntimeService, requirementNodeTypeName, requirementNodeType)
100 // Enhance Relationship Type
101 val relationShipTypeName = requirementDefinition.relationship
102 ?: throw BluePrintException("couldn't get relationship name for the NodeType($nodeTypeName) " +
103 "Requirement($requirementName)")
104 enrichRelationShipType(relationShipTypeName)
109 open fun enrichNodeTypeCapabilityProperties(nodeTypeName: String, nodeType: NodeType) {
110 nodeType.capabilities?.forEach { _, capabilityDefinition ->
111 capabilityDefinition.properties?.let { properties ->
112 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, properties)
117 open fun enrichNodeTypeInterfaces(nodeTypeName: String, nodeType: NodeType) {
118 nodeType.interfaces?.forEach { interfaceName, interfaceObj ->
119 // Populate Node type Interface Operation
120 log.debug("Enriching NodeType({}) Interface({})", nodeTypeName, interfaceName)
121 populateNodeTypeInterfaceOperation(nodeTypeName, interfaceName, interfaceObj)
126 open fun populateNodeTypeInterfaceOperation(nodeTypeName: String, interfaceName: String, interfaceObj: InterfaceDefinition) {
128 interfaceObj.operations?.forEach { operationName, operation ->
129 enrichNodeTypeInterfaceOperationInputs(nodeTypeName, operationName, operation)
130 enrichNodeTypeInterfaceOperationOutputs(nodeTypeName, operationName, operation)
134 open fun enrichNodeTypeInterfaceOperationInputs(nodeTypeName: String, operationName: String, operation: OperationDefinition) {
135 operation.inputs?.let { inputs ->
136 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs)
140 open fun enrichNodeTypeInterfaceOperationOutputs(nodeTypeName: String, operationName: String,
141 operation: OperationDefinition) {
142 operation.outputs?.let { inputs ->
143 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs)
148 * Get the Relationship Type from database and add to Blueprint Context
150 open fun enrichRelationShipType(relationshipName: String) {
151 BluePrintEnhancerUtils.populateRelationshipType(bluePrintContext, bluePrintRepoService, relationshipName)