6c7b6e08babfc5cc4efea5e58c0aad403ee2f4f7
[ccsdk/cds.git] /
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.BluePrintRepoService\r
25 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService\r
26 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext\r
27 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService\r
28 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils\r
29 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils\r
30 import org.springframework.stereotype.Service\r
31 import java.util.*\r
32 \r
33 @Service\r
34 open class BluePrintEnhancerServiceImpl(private val bluePrintRepoService: BluePrintRepoService,\r
35                                         private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService,\r
36                                         private val resourceDefinitionEnhancerService: ResourceDefinitionEnhancerService) : BluePrintEnhancerService {\r
37 \r
38     private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintEnhancerServiceImpl::class.toString())\r
39 \r
40     override fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext {\r
41 \r
42         // Copy the Blueprint Content to Target Location\r
43         BluePrintFileUtils.copyBluePrint(basePath, enrichedBasePath)\r
44 \r
45         // Enhance the Blueprint\r
46         return enhance(enrichedBasePath)\r
47     }\r
48 \r
49     @Throws(BluePrintException::class)\r
50     override fun enhance(basePath: String): BluePrintContext {\r
51 \r
52         log.info("Enhancing blueprint($basePath)")\r
53         val blueprintRuntimeService = BluePrintMetadataUtils\r
54                 .getBaseEnhancementBluePrintRuntime(UUID.randomUUID().toString(), basePath)\r
55 \r
56         try {\r
57 \r
58             bluePrintTypeEnhancerService.enhanceServiceTemplate(blueprintRuntimeService, "service_template",\r
59                     blueprintRuntimeService.bluePrintContext().serviceTemplate)\r
60 \r
61             // Write the Type File Definitions\r
62             BluePrintFileUtils.writeBluePrintTypes(blueprintRuntimeService.bluePrintContext())\r
63 \r
64             // Enhance Resource Dictionary\r
65             enhanceResourceDefinition(blueprintRuntimeService)\r
66 \r
67             if (blueprintRuntimeService.getBluePrintError().errors.isNotEmpty()) {\r
68                 throw BluePrintException(blueprintRuntimeService.getBluePrintError().errors.toString())\r
69             }\r
70 \r
71         } catch (e: Exception) {\r
72             log.error("failed in blueprint enhancement", e)\r
73         }\r
74 \r
75         return blueprintRuntimeService.bluePrintContext()\r
76     }\r
77 \r
78     private fun enhanceResourceDefinition(blueprintRuntimeService: BluePrintRuntimeService<*>) {\r
79 \r
80         resourceDefinitionEnhancerService.enhance(blueprintRuntimeService)\r
81     }\r
82 \r
83 }\r
84 \r