2 * Copyright © 2017-2018 AT&T Intellectual Property.
\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
8 * http://www.apache.org/licenses/LICENSE-2.0
\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
17 package org.onap.ccsdk.apps.controllerblueprints.core.utils
\r
20 import org.apache.commons.io.FileUtils
\r
21 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
\r
22 import org.onap.ccsdk.apps.controllerblueprints.core.data.ToscaMetaData
\r
23 import com.att.eelf.configuration.EELFLogger
\r
24 import com.att.eelf.configuration.EELFManager
\r
26 import java.nio.charset.Charset
\r
28 object BluePrintMetadataUtils {
\r
29 private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
\r
32 fun toscaMetaData(basePath: String): ToscaMetaData {
\r
33 val toscaMetaPath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus("TOSCA-Metadata/TOSCA.meta")
\r
34 return toscaMetaDataFromMetaFile(toscaMetaPath)
\r
38 fun toscaMetaDataFromMetaFile(metaFilePath: String): ToscaMetaData {
\r
39 val toscaMetaData = ToscaMetaData()
\r
40 val lines: MutableList<String> = FileUtils.readLines(File(metaFilePath), Charset.defaultCharset())
\r
41 lines.forEach { line ->
\r
42 if (line.contains(":")) {
\r
43 val keyValue = line.split(":")
\r
44 if (keyValue.size == 2) {
\r
45 val value: String = keyValue[1].trim()
\r
46 when (keyValue[0]) {
\r
47 "TOSCA-Meta-File-Version" -> toscaMetaData.toscaMetaFileVersion = value
\r
48 "CSAR-Version" -> toscaMetaData.csarVersion = value
\r
49 "Created-By" -> toscaMetaData.createdBy = value
\r
50 "Entry-Definitions" -> toscaMetaData.entityDefinitions = value
\r
51 "Template-Tags" -> toscaMetaData.templateTags = value
\r
57 return toscaMetaData
\r
61 fun getBluePrintContext(blueprintBasePath: String): BluePrintContext {
\r
63 val metaDataFile = StringBuilder().append(blueprintBasePath).append(File.separator)
\r
64 .append(BluePrintConstants.DEFAULT_TOSCA_METADATA_ENTRY_DEFINITION_FILE).toString()
\r
66 val toscaMetaData: ToscaMetaData = BluePrintMetadataUtils.toscaMetaData(metaDataFile)
\r
68 log.info("Processing blueprint base path ({}) and entry definition file ({})", blueprintBasePath, toscaMetaData.entityDefinitions)
\r
70 return BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!!
\r
71 .readBlueprintFile(toscaMetaData.entityDefinitions!!, blueprintBasePath)
\r
74 fun getBluePrintRuntime(requestId: String, blueprintBasePath: String): BluePrintRuntimeService {
\r
76 val metaDataFile = StringBuilder().append(blueprintBasePath).append(File.separator)
\r
77 .append(BluePrintConstants.DEFAULT_TOSCA_METADATA_ENTRY_DEFINITION_FILE).toString()
\r
79 val toscaMetaData: ToscaMetaData = BluePrintMetadataUtils.toscaMetaData(metaDataFile)
\r
81 log.info("Processing blueprint base path ({}) and entry definition file ({})", blueprintBasePath, toscaMetaData.entityDefinitions)
\r
83 val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!!
\r
84 .readBlueprintFile(toscaMetaData.entityDefinitions!!, blueprintBasePath)
\r
86 val context: MutableMap<String, Any> = hashMapOf()
\r
87 context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = blueprintBasePath
\r
88 context[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = requestId
\r
90 val bluePrintRuntimeService: BluePrintRuntimeService = BluePrintRuntimeService(bluePrintContext, context)
\r
92 return bluePrintRuntimeService
\r