b7f9fc7e60eea9759f24e45bfd3eb255b58d7479
[ccsdk/cds.git] /
1 /*\r
2  * Copyright © 2017-2018 AT&T Intellectual Property.\r
3  *\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
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\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
15  */\r
16 \r
17 package org.onap.ccsdk.apps.controllerblueprints.core.utils\r
18 \r
19 \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
25 import java.io.File\r
26 import java.nio.charset.Charset\r
27 \r
28 object BluePrintMetadataUtils {\r
29     private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())\r
30 \r
31     @JvmStatic\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
35     }\r
36 \r
37     @JvmStatic\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
52                     }\r
53                 }\r
54             }\r
55 \r
56         }\r
57         return toscaMetaData\r
58     }\r
59 \r
60     /*\r
61     fun getBluePrintContext(blueprintBasePath: String): BluePrintContext {\r
62 \r
63         val metaDataFile = StringBuilder().append(blueprintBasePath).append(File.separator)\r
64                 .append(BluePrintConstants.DEFAULT_TOSCA_METADATA_ENTRY_DEFINITION_FILE).toString()\r
65 \r
66         val toscaMetaData: ToscaMetaData = BluePrintMetadataUtils.toscaMetaData(metaDataFile)\r
67 \r
68         log.info("Processing blueprint base path ({}) and entry definition file ({})", blueprintBasePath, toscaMetaData.entityDefinitions)\r
69 \r
70         return BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!!\r
71                 .readBlueprintFile(toscaMetaData.entityDefinitions!!, blueprintBasePath)\r
72     }\r
73 \r
74     fun getBluePrintRuntime(requestId: String, blueprintBasePath: String): BluePrintRuntimeService {\r
75 \r
76         val metaDataFile = StringBuilder().append(blueprintBasePath).append(File.separator)\r
77                 .append(BluePrintConstants.DEFAULT_TOSCA_METADATA_ENTRY_DEFINITION_FILE).toString()\r
78 \r
79         val toscaMetaData: ToscaMetaData = BluePrintMetadataUtils.toscaMetaData(metaDataFile)\r
80 \r
81         log.info("Processing blueprint base path ({}) and entry definition file ({})", blueprintBasePath, toscaMetaData.entityDefinitions)\r
82 \r
83         val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!!\r
84                 .readBlueprintFile(toscaMetaData.entityDefinitions!!, blueprintBasePath)\r
85 \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
89 \r
90         val bluePrintRuntimeService: BluePrintRuntimeService = BluePrintRuntimeService(bluePrintContext, context)\r
91 \r
92         return bluePrintRuntimeService\r
93     }\r
94     */\r
95 }