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.interfaces.BluePrintTypeEnhancerService
24 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
25 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
26 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
27 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDictionaryConstants
28 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory
29 import org.onap.ccsdk.cds.controllerblueprints.service.ResourceDefinitionRepoService
30 import org.springframework.beans.factory.config.ConfigurableBeanFactory
31 import org.springframework.context.annotation.Scope
32 import org.springframework.stereotype.Service
35 * ResourceAssignmentEnhancerService.
37 * @author Brinda Santh
39 interface ResourceAssignmentEnhancerService {
41 @Throws(BluePrintException::class)
42 fun enhanceBluePrint(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService,
43 bluePrintRuntimeService: BluePrintRuntimeService<*>,
44 resourceAssignments: List<ResourceAssignment>)
48 * ResourceAssignmentEnhancerDefaultService.
50 * @author Brinda Santh
53 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
54 open class ResourceAssignmentEnhancerServiceImpl(private val resourceDefinitionRepoService: ResourceDefinitionRepoService)
55 : ResourceAssignmentEnhancerService {
56 private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentEnhancerServiceImpl::class.java)
59 * Get the defined source instance from the ResourceAssignment,
60 * then get the NodeType of the Sources assigned
62 override fun enhanceBluePrint(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService,
63 bluePrintRuntimeService: BluePrintRuntimeService<*>,
64 resourceAssignments: List<ResourceAssignment>) {
66 val uniqueSourceNodeTypeNames = hashSetOf<String>()
68 // Iterate the Resource Assignment and
69 resourceAssignments.map { resourceAssignment ->
70 val dictionaryName = resourceAssignment.dictionaryName!!
71 val dictionarySource = resourceAssignment.dictionarySource!!
72 log.debug("Enriching assignment name(${resourceAssignment.name}), dictionary name($dictionaryName), source($dictionarySource)")
73 val sourceNodeTypeName = ResourceSourceMappingFactory.getRegisterSourceMapping(dictionarySource)
75 // Add Unique Node Types
76 uniqueSourceNodeTypeNames.add(sourceNodeTypeName)
78 // TODO("Candidate for Optimisation")
79 if (checkResourceDefinitionNeeded(resourceAssignment)) {
81 bluePrintTypeEnhancerService.enhancePropertyDefinition(bluePrintRuntimeService, resourceAssignment.name,
82 resourceAssignment.property!!);
84 // Get the Resource Definition from Repo
85 val resourceDefinition: ResourceDefinition = getResourceDefinition(dictionaryName)
87 val sourceNodeTemplate = resourceDefinition.sources.get(dictionarySource)
88 ?: throw BluePrintException("failed to get assigned dictionarySource($dictionarySource) from resourceDefinition($dictionaryName)")
90 // Enrich as NodeTemplate
91 bluePrintTypeEnhancerService.enhanceNodeTemplate(bluePrintRuntimeService, dictionarySource, sourceNodeTemplate)
94 // Enrich the ResourceSource NodeTypes
95 uniqueSourceNodeTypeNames.map { nodeTypeName ->
96 val nodeType = resourceDefinitionRepoService.getNodeType(nodeTypeName)
97 bluePrintTypeEnhancerService.enhanceNodeType(bluePrintRuntimeService, nodeTypeName, nodeType)
102 private fun checkResourceDefinitionNeeded(resourceAssignment: ResourceAssignment): Boolean {
103 return !((resourceAssignment.dictionarySource.equals(ResourceDictionaryConstants.SOURCE_INPUT)
104 || resourceAssignment.dictionarySource.equals(ResourceDictionaryConstants.SOURCE_DEFAULT))
105 && BluePrintTypes.validPrimitiveOrCollectionPrimitive(resourceAssignment.property!!))
108 private fun getResourceDefinition(name: String): ResourceDefinition {
109 return resourceDefinitionRepoService.getResourceDefinition(name)