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.blueprintsprocessor.designer.api.enhancer
19 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.service.ResourceDefinitionRepoService
20 import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintException
21 import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintTypes
22 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintTypeEnhancerService
23 import org.onap.ccsdk.cds.controllerblueprints.core.logger
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.springframework.beans.factory.config.ConfigurableBeanFactory
30 import org.springframework.context.annotation.Scope
31 import org.springframework.stereotype.Service
34 * ResourceAssignmentEnhancerService.
36 * @author Brinda Santh
38 interface ResourceAssignmentEnhancerService {
40 @Throws(BlueprintException::class)
42 bluePrintTypeEnhancerService: BlueprintTypeEnhancerService,
43 bluePrintRuntimeService: BlueprintRuntimeService<*>,
44 resourceAssignments: List<ResourceAssignment>
49 * ResourceAssignmentEnhancerDefaultService.
51 * @author Brinda Santh
54 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
55 open class ResourceAssignmentEnhancerServiceImpl(private val resourceDefinitionRepoService: ResourceDefinitionRepoService) :
56 ResourceAssignmentEnhancerService {
58 private val log = logger(ResourceAssignmentEnhancerServiceImpl::class)
61 * Get the defined source instance from the ResourceAssignment,
62 * then get the NodeType of the Sources assigned
64 override fun enhanceBlueprint(
65 bluePrintTypeEnhancerService: BlueprintTypeEnhancerService,
66 bluePrintRuntimeService: BlueprintRuntimeService<*>,
67 resourceAssignments: List<ResourceAssignment>
70 val uniqueSourceNodeTypeNames = hashSetOf<String>()
72 // Iterate the Resource Assignment and
73 resourceAssignments.map { resourceAssignment ->
74 val dictionaryName = resourceAssignment.dictionaryName!!
75 val dictionarySource = resourceAssignment.dictionarySource!!
76 log.debug("Enriching assignment name(${resourceAssignment.name}), dictionary name($dictionaryName), source($dictionarySource)")
77 val sourceNodeTypeName = ResourceSourceMappingFactory.getRegisterSourceMapping(dictionarySource)
79 // Add Unique Node Types
80 uniqueSourceNodeTypeNames.add(sourceNodeTypeName)
82 // TODO("Candidate for Optimisation")
83 if (checkResourceDefinitionNeeded(resourceAssignment)) {
85 bluePrintTypeEnhancerService.enhancePropertyDefinition(
86 bluePrintRuntimeService, resourceAssignment.name,
87 resourceAssignment.property!!
90 // Get the Resource Definition from Repo
91 val resourceDefinition: ResourceDefinition = getResourceDefinition(dictionaryName)
93 val sourceNodeTemplate = resourceDefinition.sources[dictionarySource]
94 ?: throw BlueprintException("failed to get assigned dictionarySource($dictionarySource) from resourceDefinition($dictionaryName)")
96 // Enrich as NodeTemplate
97 bluePrintTypeEnhancerService.enhanceNodeTemplate(bluePrintRuntimeService, dictionarySource, sourceNodeTemplate)
100 // Enrich the ResourceSource NodeTypes
101 uniqueSourceNodeTypeNames.map { nodeTypeName ->
102 val nodeType = resourceDefinitionRepoService.getNodeType(nodeTypeName)
103 bluePrintTypeEnhancerService.enhanceNodeType(bluePrintRuntimeService, nodeTypeName, nodeType)
107 private fun checkResourceDefinitionNeeded(resourceAssignment: ResourceAssignment): Boolean {
110 resourceAssignment.dictionarySource.equals(ResourceDictionaryConstants.SOURCE_INPUT) ||
111 resourceAssignment.dictionarySource.equals(ResourceDictionaryConstants.SOURCE_DEFAULT)
113 BlueprintTypes.validPrimitiveOrCollectionPrimitive(resourceAssignment.property!!)
117 private fun getResourceDefinition(name: String): ResourceDefinition {
118 return resourceDefinitionRepoService.getResourceDefinition(name)