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