Migrate "ms/controllerblueprints" from ccsdk/apps
[ccsdk/cds.git] / ms / controllerblueprints / modules / service / src / main / kotlin / org / onap / ccsdk / apps / controllerblueprints / service / enhancer / BluePrintEnhancerServiceImpl.kt
1 /*\r
2  * Copyright © 2017-2018 AT&T Intellectual Property.\r
3  * Modifications Copyright © 2018 IBM.\r
4  *\r
5  * Licensed under the Apache License, Version 2.0 (the "License");\r
6  * you may not use this file except in compliance with the License.\r
7  * You may obtain a copy of the License at\r
8  *\r
9  *     http://www.apache.org/licenses/LICENSE-2.0\r
10  *\r
11  * Unless required by applicable law or agreed to in writing, software\r
12  * distributed under the License is distributed on an "AS IS" BASIS,\r
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14  * See the License for the specific language governing permissions and\r
15  * limitations under the License.\r
16  */\r
17 \r
18 package org.onap.ccsdk.apps.controllerblueprints.service.enhancer\r
19 \r
20 import com.att.eelf.configuration.EELFLogger\r
21 import com.att.eelf.configuration.EELFManager\r
22 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException\r
23 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhancerService\r
24 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService\r
25 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext\r
26 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils\r
27 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils\r
28 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils\r
29 import org.springframework.stereotype.Service\r
30 import java.util.*\r
31 \r
32 @Service\r
33 open class BluePrintEnhancerServiceImpl(private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService,\r
34                                         private val resourceDefinitionEnhancerService: ResourceDefinitionEnhancerService) : BluePrintEnhancerService {\r
35 \r
36     private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintEnhancerServiceImpl::class.toString())\r
37 \r
38     override suspend fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext {\r
39 \r
40         // Copy the Blueprint Content to Target Location\r
41         BluePrintFileUtils.copyBluePrint(basePath, enrichedBasePath)\r
42 \r
43         // Enhance the Blueprint\r
44         return enhance(enrichedBasePath)\r
45     }\r
46 \r
47     @Throws(BluePrintException::class)\r
48     override suspend fun enhance(basePath: String): BluePrintContext {\r
49 \r
50         log.info("Enhancing blueprint($basePath)")\r
51         val blueprintRuntimeService = BluePrintMetadataUtils\r
52                 .getBaseEnhancementBluePrintRuntime(UUID.randomUUID().toString(), basePath)\r
53 \r
54         try {\r
55 \r
56             bluePrintTypeEnhancerService.enhanceServiceTemplate(blueprintRuntimeService, "service_template",\r
57                     blueprintRuntimeService.bluePrintContext().serviceTemplate)\r
58 \r
59             log.info("##### Enhancing blueprint Resource Definitions")\r
60             val resourceDefinitions = resourceDefinitionEnhancerService.enhance(bluePrintTypeEnhancerService,\r
61                     blueprintRuntimeService)\r
62 \r
63             // Write the Enhanced Blueprint Definitions\r
64             BluePrintFileUtils.writeEnhancedBluePrint(blueprintRuntimeService.bluePrintContext())\r
65 \r
66             // Write the Enhanced Blueprint Resource Definitions\r
67             ResourceDictionaryUtils.writeResourceDefinitionTypes(basePath, resourceDefinitions)\r
68 \r
69             if (blueprintRuntimeService.getBluePrintError().errors.isNotEmpty()) {\r
70                 throw BluePrintException(blueprintRuntimeService.getBluePrintError().errors.toString())\r
71             }\r
72 \r
73         } catch (e: Exception) {\r
74             throw e\r
75         }\r
76         return blueprintRuntimeService.bluePrintContext()\r
77     }\r
78 \r
79 }\r
80 \r