From b26a869c146e58a014cc3c936f8716b90cd0b84a Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Mon, 25 Mar 2019 13:12:24 -0400 Subject: Add workflow output processing Change-Id: Ie1ff465e7fba07bc5280166275a9109fbdded379 Issue-ID: CCSDK-1175 Signed-off-by: Muthuramalingam, Brinda Santh --- .../core/api/data/BlueprintProcessorData.kt | 2 +- .../execution/AbstractComponentFunction.kt | 39 +++++++++---------- .../BluePrintWorkflowExecutionServiceImpl.kt | 13 ++++++- .../workflow/ComponentWorkflowExecutionService.kt | 4 -- .../workflow/DGWorkflowExecutionService.kt | 8 +--- .../BluePrintWorkflowExecutionServiceImplTest.kt | 21 +++++++---- .../services/workflow/BlueprintServiceLogicTest.kt | 44 +++++++++++++++------- .../workflow/DGWorkflowExecutionServiceTest.kt | 28 +++++++++----- .../core/utils/BluePrintMetadataUtils.kt | 14 +++---- .../core/utils/JacksonUtils.kt | 39 +++++++++---------- .../core/utils/BluePrintMetadataUtilsTest.kt | 21 ++++++----- 11 files changed, 132 insertions(+), 101 deletions(-) diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt index a73c6a7d1..fb6a0832a 100644 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt @@ -43,7 +43,7 @@ open class ExecutionServiceOutput { @get:ApiModelProperty(required = true) lateinit var actionIdentifiers: ActionIdentifiers @get:ApiModelProperty(required = true) - var status: Status = Status() + lateinit var status: Status @get:ApiModelProperty(required = true) lateinit var payload: ObjectNode } diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt index d6c1a7c21..35fef96fd 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt @@ -19,7 +19,6 @@ package org.onap.ccsdk.cds.blueprintsprocessor.services.execution import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.node.JsonNodeFactory import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Status @@ -30,6 +29,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.asObjectNode import org.onap.ccsdk.cds.controllerblueprints.core.getAsString import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintFunctionNode import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.slf4j.LoggerFactory /** @@ -70,10 +70,10 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode 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 readValue(content: String): T = - jacksonObjectMapper().readValue(content, T::class.java) + objectMapper.readValue(content, T::class.java) fun readValue(content: String, valueType: Class): T? { - return jacksonObjectMapper().readValue(content, valueType) + return objectMapper.readValue(content, valueType) } fun readValue(node: JsonNode, valueType: Class): 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 getMapFromFile(file: File, valueType: Class): MutableMap { - val content: String = getContent(file) - return getMapFromJson(content, valueType) + fun getMapFromFile(file: File, valueType: Class): MutableMap = runBlocking { + val content: String = file.readNBText() + getMapFromJson(content, valueType) } fun getMapFromFile(fileName: String, valueType: Class): MutableMap = 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") + } } -- cgit 1.2.3-korg