2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.onap.ccsdk.apps.controllerblueprints.service.enhancer
\r
19 import com.att.eelf.configuration.EELFLogger
\r
20 import com.att.eelf.configuration.EELFManager
\r
21 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
\r
22 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
\r
23 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService
\r
24 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
\r
25 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
\r
26 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition
\r
27 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants
\r
28 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory
\r
29 import org.onap.ccsdk.apps.controllerblueprints.service.ResourceDefinitionRepoService
\r
30 import org.springframework.beans.factory.config.ConfigurableBeanFactory
\r
31 import org.springframework.context.annotation.Scope
\r
32 import org.springframework.stereotype.Service
\r
35 * ResourceAssignmentEnhancerService.
\r
37 * @author Brinda Santh
\r
39 interface ResourceAssignmentEnhancerService {
\r
41 @Throws(BluePrintException::class)
\r
42 fun enhanceBluePrint(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService,
\r
43 bluePrintRuntimeService: BluePrintRuntimeService<*>,
\r
44 resourceAssignments: List<ResourceAssignment>)
\r
48 * ResourceAssignmentEnhancerDefaultService.
\r
50 * @author Brinda Santh
\r
53 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
\r
54 open class ResourceAssignmentEnhancerServiceImpl(private val resourceDefinitionRepoService: ResourceDefinitionRepoService)
\r
55 : ResourceAssignmentEnhancerService {
\r
56 private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentEnhancerServiceImpl::class.java)
\r
59 * Get the defined source instance from the ResourceAssignment,
\r
60 * then get the NodeType of the Sources assigned
\r
62 override fun enhanceBluePrint(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService,
\r
63 bluePrintRuntimeService: BluePrintRuntimeService<*>,
\r
64 resourceAssignments: List<ResourceAssignment>) {
\r
66 val uniqueSourceNodeTypeNames = hashSetOf<String>()
\r
68 // Iterate the Resource Assignment and
\r
69 resourceAssignments.map { resourceAssignment ->
\r
70 val dictionaryName = resourceAssignment.dictionaryName!!
\r
71 val dictionarySource = resourceAssignment.dictionarySource!!
\r
72 log.debug("Enriching assignment name(${resourceAssignment.name}), dictionary name($dictionaryName), source($dictionarySource)")
\r
73 val sourceNodeTypeName = ResourceSourceMappingFactory.getRegisterSourceMapping(dictionarySource)
\r
75 // Add Unique Node Types
\r
76 uniqueSourceNodeTypeNames.add(sourceNodeTypeName)
\r
78 // TODO("Candidate for Optimisation")
\r
79 if (checkResourceDefinitionNeeded(resourceAssignment)) {
\r
81 bluePrintTypeEnhancerService.enhancePropertyDefinition(bluePrintRuntimeService, resourceAssignment.name,
\r
82 resourceAssignment.property!!);
\r
84 // Get the Resource Definition from Repo
\r
85 val resourceDefinition: ResourceDefinition = getResourceDefinition(dictionaryName)
\r
87 val sourceNodeTemplate = resourceDefinition.sources.get(dictionarySource)
\r
88 ?: throw BluePrintException("failed to get assigned dictionarySource($dictionarySource) from resourceDefinition($dictionaryName)")
\r
90 // Enrich as NodeTemplate
\r
91 bluePrintTypeEnhancerService.enhanceNodeTemplate(bluePrintRuntimeService, dictionarySource, sourceNodeTemplate)
\r
94 // Enrich the ResourceSource NodeTypes
\r
95 uniqueSourceNodeTypeNames.map { nodeTypeName ->
\r
96 val nodeType = resourceDefinitionRepoService.getNodeType(nodeTypeName)
\r
97 bluePrintTypeEnhancerService.enhanceNodeType(bluePrintRuntimeService, nodeTypeName, nodeType)
\r
102 private fun checkResourceDefinitionNeeded(resourceAssignment: ResourceAssignment): Boolean {
\r
103 return !((resourceAssignment.dictionarySource.equals(ResourceDictionaryConstants.SOURCE_INPUT)
\r
104 || resourceAssignment.dictionarySource.equals(ResourceDictionaryConstants.SOURCE_DEFAULT))
\r
105 && BluePrintTypes.validPrimitiveOrCollectionPrimitive(resourceAssignment.property!!))
\r
108 private fun getResourceDefinition(name: String): ResourceDefinition {
\r
109 return resourceDefinitionRepoService.getResourceDefinition(name)
\r