2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2018 IBM.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org.onap.ccsdk.cds.controllerblueprints.service.enhancer
20 import com.att.eelf.configuration.EELFLogger
21 import com.att.eelf.configuration.EELFManager
22 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
23 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintEnhancerService
24 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService
25 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
26 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils
27 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
28 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils
29 import org.springframework.stereotype.Service
33 open class BluePrintEnhancerServiceImpl(private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService,
34 private val resourceDefinitionEnhancerService: ResourceDefinitionEnhancerService) : BluePrintEnhancerService {
36 private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintEnhancerServiceImpl::class.toString())
38 override suspend fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext {
40 // Copy the Blueprint Content to Target Location
41 BluePrintFileUtils.copyBluePrint(basePath, enrichedBasePath)
43 // Enhance the Blueprint
44 return enhance(enrichedBasePath)
47 @Throws(BluePrintException::class)
48 override suspend fun enhance(basePath: String): BluePrintContext {
50 log.info("Enhancing blueprint($basePath)")
51 val blueprintRuntimeService = BluePrintMetadataUtils
52 .getBaseEnhancementBluePrintRuntime(UUID.randomUUID().toString(), basePath)
56 bluePrintTypeEnhancerService.enhanceServiceTemplate(blueprintRuntimeService, "service_template",
57 blueprintRuntimeService.bluePrintContext().serviceTemplate)
59 log.info("##### Enhancing blueprint Resource Definitions")
60 val resourceDefinitions = resourceDefinitionEnhancerService.enhance(bluePrintTypeEnhancerService,
61 blueprintRuntimeService)
63 // Write the Enhanced Blueprint Definitions
64 BluePrintFileUtils.writeEnhancedBluePrint(blueprintRuntimeService.bluePrintContext())
66 // Write the Enhanced Blueprint Resource Definitions
67 ResourceDictionaryUtils.writeResourceDefinitionTypes(basePath, resourceDefinitions)
69 if (blueprintRuntimeService.getBluePrintError().errors.isNotEmpty()) {
70 throw BluePrintException(blueprintRuntimeService.getBluePrintError().errors.toString())
73 } catch (e: Exception) {
76 return blueprintRuntimeService.bluePrintContext()