0d08985a1932fbccfaa54c187ba67cd9432aaf1e
[ccsdk/cds.git] /
1 /*\r
2  *  Copyright © 2017-2018 AT&T Intellectual Property.\r
3  *\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
7  *\r
8  *      http://www.apache.org/licenses/LICENSE-2.0\r
9  *\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
15  */\r
16 \r
17 package org.onap.ccsdk.apps.controllerblueprints.service.enhancer\r
18 \r
19 import com.att.eelf.configuration.EELFLogger\r
20 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException\r
21 import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate\r
22 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerDefaultService\r
23 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerService\r
24 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment\r
25 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition\r
26 import com.att.eelf.configuration.EELFManager\r
27 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationDefaultService\r
28 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionRepoService\r
29 \r
30 /**\r
31  * ResourceAssignmentEnhancerService.\r
32  *\r
33  * @author Brinda Santh\r
34  */\r
35 interface ResourceAssignmentEnhancerService {\r
36 \r
37     @Throws(BluePrintException::class)\r
38     fun enhanceBluePrint(bluePrintEnhancerService: BluePrintEnhancerService,\r
39                          resourceAssignments: List<ResourceAssignment>)\r
40 \r
41     @Throws(BluePrintException::class)\r
42     fun enhanceBluePrint(resourceAssignments: List<ResourceAssignment>): ServiceTemplate\r
43 }\r
44 \r
45 /**\r
46  * ResourceAssignmentEnhancerDefaultService.\r
47  *\r
48  * @author Brinda Santh\r
49  */\r
50 open class ResourceAssignmentEnhancerDefaultService(private val resourceDefinitionRepoService: ResourceDefinitionRepoService)\r
51     : ResourceAssignmentEnhancerService {\r
52     private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationDefaultService::class.java)\r
53 \r
54     /**\r
55      * Get the defined source instance from the ResourceAssignment,\r
56      * then get the NodeType of the Sources assigned\r
57      */\r
58     override fun enhanceBluePrint(bluePrintEnhancerService: BluePrintEnhancerService,\r
59                                   resourceAssignments: List<ResourceAssignment>) {\r
60 \r
61         // Iterate the Resource Assignment and\r
62         resourceAssignments.map { resourceAssignment ->\r
63             val dictionaryName = resourceAssignment.dictionaryName!!\r
64             val dictionarySource = resourceAssignment.dictionarySource!!\r
65             log.info("Enriching Assignment name({}), dictionary name({}), source({})", resourceAssignment.name,\r
66                     dictionaryName, dictionarySource)\r
67             // Get the Resource Definition from Repo\r
68             val resourceDefinition: ResourceDefinition = getResourceDefinition(dictionaryName)\r
69 \r
70             val sourceNodeTemplate = resourceDefinition.sources.get(dictionarySource)\r
71 \r
72             // Enrich as NodeTemplate\r
73             bluePrintEnhancerService.enrichNodeTemplate(dictionarySource, sourceNodeTemplate!!)\r
74         }\r
75     }\r
76 \r
77     override fun enhanceBluePrint(resourceAssignments: List<ResourceAssignment>): ServiceTemplate {\r
78         val bluePrintEnhancerService = BluePrintEnhancerDefaultService(resourceDefinitionRepoService)\r
79         bluePrintEnhancerService.serviceTemplate = ServiceTemplate()\r
80         bluePrintEnhancerService.initialCleanUp()\r
81         enhanceBluePrint(bluePrintEnhancerService, resourceAssignments)\r
82         return bluePrintEnhancerService.serviceTemplate\r
83     }\r
84 \r
85     private fun getResourceDefinition(name: String): ResourceDefinition {\r
86         return resourceDefinitionRepoService.getResourceDefinition(name).block()!!\r
87     }\r
88 }