aboutsummaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints
diff options
context:
space:
mode:
Diffstat (limited to 'ms/controllerblueprints')
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtils.kt14
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt39
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt21
3 files changed, 36 insertions, 38 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtils.kt
index 904983fcd..bc0103958 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtils.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtils.kt
@@ -1,6 +1,6 @@
/*
* Copyright © 2017-2018 AT&T Intellectual Property.
- * Modifications Copyright © 2018 IBM.
+ * Modifications Copyright © 2018-2019 IBM.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,12 +26,12 @@ import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
import org.onap.ccsdk.cds.controllerblueprints.core.data.ToscaMetaData
import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
+import org.onap.ccsdk.cds.controllerblueprints.core.readNBLines
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintImportService
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService
import java.io.File
-import java.nio.charset.Charset
import java.util.*
class BluePrintMetadataUtils {
@@ -39,13 +39,13 @@ class BluePrintMetadataUtils {
private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
- fun toscaMetaData(basePath: String): ToscaMetaData {
+ suspend fun toscaMetaData(basePath: String): ToscaMetaData {
val toscaMetaPath = basePath.plus(BluePrintConstants.PATH_DIVIDER)
.plus(BluePrintConstants.TOSCA_METADATA_ENTRY_DEFINITION_FILE)
return toscaMetaDataFromMetaFile(toscaMetaPath)
}
- fun entryDefinitionFile(basePath: String): String {
+ suspend fun entryDefinitionFile(basePath: String): String {
val toscaMetaPath = basePath.plus(BluePrintConstants.PATH_DIVIDER)
.plus(BluePrintConstants.TOSCA_METADATA_ENTRY_DEFINITION_FILE)
return toscaMetaDataFromMetaFile(toscaMetaPath).entityDefinitions
@@ -59,7 +59,7 @@ class BluePrintMetadataUtils {
fun environmentFileProperties(pathName: String): Properties {
val properties = Properties()
- val envDir = File(pathName)
+ val envDir = normalizedFile(pathName)
// Verify if the environment directory exists
if (envDir.exists() && envDir.isDirectory) {
//Find all available environment files
@@ -72,9 +72,9 @@ class BluePrintMetadataUtils {
return properties
}
- fun toscaMetaDataFromMetaFile(metaFilePath: String): ToscaMetaData {
+ private suspend fun toscaMetaDataFromMetaFile(metaFilePath: String): ToscaMetaData {
val toscaMetaData = ToscaMetaData()
- val lines = normalizedFile(metaFilePath).readLines(Charset.defaultCharset())
+ val lines = normalizedFile(metaFilePath).readNBLines()
lines.forEach { line ->
if (line.contains(":")) {
val keyValue = line.split(":")
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt
index 85ae359cd..7ac79e2f1 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt
@@ -16,15 +16,12 @@
*/
package org.onap.ccsdk.cds.controllerblueprints.core.utils
-import com.att.eelf.configuration.EELFLogger
-import com.att.eelf.configuration.EELFManager
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.databind.node.*
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.apache.commons.io.IOUtils
@@ -39,16 +36,18 @@ import java.nio.charset.Charset
*/
class JacksonUtils {
companion object {
- private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
+
+ val objectMapper = jacksonObjectMapper()
+
inline fun <reified T : Any> readValue(content: String): T =
- jacksonObjectMapper().readValue(content, T::class.java)
+ objectMapper.readValue(content, T::class.java)
fun <T> readValue(content: String, valueType: Class<T>): T? {
- return jacksonObjectMapper().readValue(content, valueType)
+ return objectMapper.readValue(content, valueType)
}
fun <T> readValue(node: JsonNode, valueType: Class<T>): T? {
- return jacksonObjectMapper().treeToValue(node, valueType)
+ return objectMapper.treeToValue(node, valueType)
}
fun removeJsonNullNode(node: JsonNode) {
@@ -64,16 +63,12 @@ class JacksonUtils {
}
- fun getContent(fileName: String): String = getContent(normalizedFile(fileName))
-
- fun getContent(file: File): String = runBlocking {
- async {
- try {
- file.readText(Charsets.UTF_8)
- } catch (e: Exception) {
- throw BluePrintException("couldn't get file (${file.absolutePath}) content : ${e.message}")
- }
- }.await()
+ fun getContent(fileName: String): String = runBlocking {
+ try {
+ normalizedFile(fileName).readNBText()
+ } catch (e: Exception) {
+ throw BluePrintException("couldn't get file ($fileName) content : ${e.message}")
+ }
}
fun getClassPathFileContent(fileName: String): String {
@@ -96,11 +91,11 @@ class JacksonUtils {
}
fun objectNodeFromObject(from: kotlin.Any): ObjectNode {
- return jacksonObjectMapper().convertValue(from, ObjectNode::class.java)
+ return objectMapper.convertValue(from, ObjectNode::class.java)
}
fun jsonNodeFromObject(from: kotlin.Any): JsonNode {
- return jacksonObjectMapper().convertValue(from, JsonNode::class.java)
+ return objectMapper.convertValue(from, JsonNode::class.java)
}
fun jsonNodeFromClassPathFile(fileName: String): JsonNode {
@@ -171,9 +166,9 @@ class JacksonUtils {
return objectMapper.readValue(content, mapType)
}
- fun <T> getMapFromFile(file: File, valueType: Class<T>): MutableMap<String, T> {
- val content: String = getContent(file)
- return getMapFromJson(content, valueType)
+ fun <T> getMapFromFile(file: File, valueType: Class<T>): MutableMap<String, T> = runBlocking {
+ val content: String = file.readNBText()
+ getMapFromJson(content, valueType)
}
fun <T> getMapFromFile(fileName: String, valueType: Class<T>): MutableMap<String, T> = getMapFromFile(File(fileName), valueType)
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt
index 7a1fb6d9e..1a6ccfa17 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt
@@ -18,6 +18,7 @@
package org.onap.ccsdk.cds.controllerblueprints.core.utils
+import kotlinx.coroutines.runBlocking
import org.junit.Test
import org.onap.ccsdk.cds.controllerblueprints.core.data.ToscaMetaData
import kotlin.test.assertEquals
@@ -29,15 +30,17 @@ class BluePrintMetadataUtilsTest {
@Test
fun testToscaMetaData() {
- val basePath: String = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
-
- val toscaMetaData: ToscaMetaData = BluePrintMetadataUtils.toscaMetaData(basePath)
- assertNotNull(toscaMetaData, "Missing Tosca Definition Object")
- assertNotNull(toscaMetaData.toscaMetaFileVersion, "Missing Tosca Metadata Version")
- assertNotNull(toscaMetaData.csarVersion, "Missing CSAR version")
- assertNotNull(toscaMetaData.createdBy, "Missing Created by")
- assertNotNull(toscaMetaData.entityDefinitions, "Missing Tosca Entity Definition")
- assertNotNull(toscaMetaData.templateTags, "Missing Template Tags")
+ runBlocking {
+ val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
+
+ val toscaMetaData: ToscaMetaData = BluePrintMetadataUtils.toscaMetaData(basePath)
+ assertNotNull(toscaMetaData, "Missing Tosca Definition Object")
+ assertNotNull(toscaMetaData.toscaMetaFileVersion, "Missing Tosca Metadata Version")
+ assertNotNull(toscaMetaData.csarVersion, "Missing CSAR version")
+ assertNotNull(toscaMetaData.createdBy, "Missing Created by")
+ assertNotNull(toscaMetaData.entityDefinitions, "Missing Tosca Entity Definition")
+ assertNotNull(toscaMetaData.templateTags, "Missing Template Tags")
+ }
}