Add workflow output processing 37/83237/3
authorMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Mon, 25 Mar 2019 17:12:24 +0000 (13:12 -0400)
committerAlexis de Talhouët <adetalhouet89@gmail.com>
Mon, 25 Mar 2019 18:31:38 +0000 (14:31 -0400)
Change-Id: Ie1ff465e7fba07bc5280166275a9109fbdded379
Issue-ID: CCSDK-1175
Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt
ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt
ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt
ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/ComponentWorkflowExecutionService.kt
ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/DGWorkflowExecutionService.kt
ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImplTest.kt
ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt
ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/DGWorkflowExecutionServiceTest.kt
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtils.kt
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt
ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt

index a73c6a7..fb6a083 100644 (file)
@@ -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
 }
index d6c1a7c..35fef96 100644 (file)
@@ -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<ExecutionServic
 
         log.info("preparing request id($processId) for workflow($workflowName) step($stepName)")
 
-        val operationInputs = bluePrintRuntimeService.get("$stepName-step-inputs")
-                ?: JsonNodeFactory.instance.objectNode()
+        val stepInputs = bluePrintRuntimeService.get("$stepName-step-inputs")
+                ?: JacksonUtils.objectMapper.createObjectNode()
 
-        operationInputs.fields().forEach {
+        stepInputs.fields().forEach {
             this.operationInputs[it.key] = it.value
         }
 
@@ -98,23 +98,20 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic
         log.info("Preparing Response...")
         executionServiceOutput.commonHeader = executionServiceInput.commonHeader
         executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers
-
-        // Resolve the Output Expression
-        val stepOutputs = bluePrintRuntimeService
-                .resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName, interfaceName, operationName)
-
-        // FIXME("Not the right place to populate the response payload")
-        executionServiceOutput.payload = stepOutputs.asObjectNode()
-
-        bluePrintRuntimeService.put("$stepName-step-outputs", executionServiceOutput.payload)
-
-        // FIXME("Not the right place to populate the status")
-        // Populate Status
-        val status = Status()
-        status.eventType = EventType.EVENT_COMPONENT_EXECUTED.name
-        status.code = 200
-        status.message = BluePrintConstants.STATUS_SUCCESS
-        executionServiceOutput.status = status
+        var status: Status?
+        try {
+            // Resolve the Output Expression
+            val stepOutputs = bluePrintRuntimeService
+                    .resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName, interfaceName, operationName)
+
+            bluePrintRuntimeService.put("$stepName-step-outputs", stepOutputs.asObjectNode())
+            // Set the Default Step Status
+            status = Status()
+        } catch (e: Exception) {
+            status = Status()
+            status.message = BluePrintConstants.STATUS_FAILURE
+        }
+        executionServiceOutput.status = status!!
         return this.executionServiceOutput
     }
 
index fbd9f4c..d8aefe9 100644 (file)
@@ -20,8 +20,10 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInpu
 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.asObjectNode
 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService
 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
 import org.slf4j.LoggerFactory
 import org.springframework.stereotype.Service
 
@@ -41,6 +43,10 @@ open class BluePrintWorkflowExecutionServiceImpl(
 
         val workflowName = executionServiceInput.actionIdentifiers.actionName
 
+        // Assign Workflow inputs
+        val input = executionServiceInput.payload.get("$workflowName-request")
+        bluePrintRuntimeService.assignWorkflowInputs(workflowName, input)
+
         // Get the DG Node Template
         val nodeTemplateName = bluePrintContext.workflowFirstStepNodeTemplate(workflowName)
 
@@ -65,7 +71,12 @@ open class BluePrintWorkflowExecutionServiceImpl(
 
         executionServiceOutput.commonHeader = executionServiceInput.commonHeader
         executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers
-        // TODO("Populate Response Payload and status")
+        // Resolve Workflow Outputs
+        val workflowOutputs = bluePrintRuntimeService.resolveWorkflowOutputs(workflowName)
+
+        // Set the Response Payload
+        executionServiceOutput.payload = JacksonUtils.objectMapper.createObjectNode()
+        executionServiceOutput.payload.set("$workflowName-response", workflowOutputs.asObjectNode())
         return executionServiceOutput
     }
 
index 3b2fc33..ee6c353 100644 (file)
@@ -38,10 +38,6 @@ open class ComponentWorkflowExecutionService(private val nodeTemplateExecutionSe
         // Get the DG Node Template
         val nodeTemplateName = bluePrintContext.workflowFirstStepNodeTemplate(workflowName)
 
-        // Assign Workflow inputs
-        val input = executionServiceInput.payload.get("$workflowName-request")
-        bluePrintRuntimeService.assignWorkflowInputs(workflowName, input)
-
         return nodeTemplateExecutionService.executeNodeTemplate(bluePrintRuntimeService,
                 nodeTemplateName, executionServiceInput)
     }
index 571b6c7..80aa103 100644 (file)
@@ -21,10 +21,10 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInpu
 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput
 import org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.utils.SvcGraphUtils
 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService
+import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
 import org.slf4j.LoggerFactory
 import org.springframework.stereotype.Service
-import java.io.File
 
 
 @Service("dgWorkflowExecutionService")
@@ -51,17 +51,13 @@ open class DGWorkflowExecutionService(private val blueprintSvcLogicService: Blue
                 WorkflowServiceConstants.ARTIFACT_TYPE_DIRECTED_GRAPH)
 
         // Populate the DG Path
-        val dgFilePath = bluePrintContext.rootPath.plus(File.separator).plus(artifactDefinition.file)
+        val dgFilePath = normalizedPathName(bluePrintContext.rootPath, artifactDefinition.file)
 
         log.info("Executing directed graph ($dgFilePath)")
 
         // Create DG instance
         val graph = SvcGraphUtils.getSvcGraphFromFile(dgFilePath)
 
-        // Assign Workflow inputs
-        val input = executionServiceInput.payload.get("$workflowName-request")
-        bluePrintRuntimeService.assignWorkflowInputs(workflowName, input)
-
         // Execute the DG
         return blueprintSvcLogicService.execute(graph, bluePrintRuntimeService, executionServiceInput) as ExecutionServiceOutput
 
index 3958f0c..59be940 100644 (file)
@@ -21,12 +21,15 @@ import org.junit.Test
 import org.junit.runner.RunWith
 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.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.test.context.ContextConfiguration
 import org.springframework.test.context.junit4.SpringRunner
+import kotlin.test.assertEquals
+import kotlin.test.assertNotNull
 
 
 @RunWith(SpringRunner::class)
@@ -38,16 +41,20 @@ class BluePrintWorkflowExecutionServiceImplTest {
 
     @Test
     fun testBluePrintWorkflowExecutionService() {
+        runBlocking {
+            val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
+                    "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
 
-        val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
-                "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+            val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json",
+                    ExecutionServiceInput::class.java)!!
 
-        val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json",
-                ExecutionServiceInput::class.java)!!
 
-        runBlocking {
-            bluePrintWorkflowExecutionService.executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput,
-                    hashMapOf())
+            val executionServiceOutput = bluePrintWorkflowExecutionService
+                    .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, hashMapOf())
+
+            assertNotNull(executionServiceOutput, "failed to get response")
+            assertEquals(BluePrintConstants.STATUS_SUCCESS, executionServiceOutput.status.message,
+                    "failed to get successful response")
         }
     }
 
index ad2ee57..4352277 100644 (file)
@@ -24,21 +24,20 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInpu
 import org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.executor.ComponentExecuteNodeExecutor
 import org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.mock.PrototypeComponentFunction
 import org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.mock.SingletonComponentFunction
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
-import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
-import org.slf4j.LoggerFactory
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonReactorUtils
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.context.ApplicationContext
 import org.springframework.test.context.ContextConfiguration
 import org.springframework.test.context.junit4.SpringRunner
 import kotlin.test.assertEquals
+import kotlin.test.assertNotNull
 
 @RunWith(SpringRunner::class)
 @ContextConfiguration(classes = [WorkflowServiceConfiguration::class, ComponentExecuteNodeExecutor::class])
 class BlueprintServiceLogicTest {
 
-    private val log = LoggerFactory.getLogger(BlueprintServiceLogicTest::class.java)
-
     @Autowired
     lateinit var applicationContext: ApplicationContext
 
@@ -47,14 +46,22 @@ class BlueprintServiceLogicTest {
 
     @Test
     fun testExecuteGraphWithSingleComponent() {
+        runBlocking {
+            val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
+                    "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
 
-        val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
-                "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+            val executionServiceInput = JacksonReactorUtils
+                    .readValueFromClassPathFile("execution-input/resource-assignment-input.json", ExecutionServiceInput::class.java)!!
 
-        val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json", ExecutionServiceInput::class.java)!!
+            // Assign Workflow inputs Mock
+            val input = executionServiceInput.payload.get("resource-assignment-request")
+            bluePrintRuntimeService.assignWorkflowInputs("resource-assignment", input)
 
-        runBlocking {
-            dgWorkflowExecutionService.executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, mutableMapOf())
+            val executionServiceOutput = dgWorkflowExecutionService
+                    .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, mutableMapOf())
+            assertNotNull(executionServiceOutput, "failed to get response")
+            assertEquals(BluePrintConstants.STATUS_SUCCESS, executionServiceOutput.status.message,
+                    "failed to get successful response")
         }
 
 
@@ -62,14 +69,23 @@ class BlueprintServiceLogicTest {
 
     @Test
     fun testExecuteGraphWithMultipleComponents() {
+        runBlocking {
+            val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
+                    "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
 
-        val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
-                "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+            val executionServiceInput = JacksonReactorUtils
+                    .readValueFromClassPathFile("execution-input/assign-activate-input.json", ExecutionServiceInput::class.java)!!
 
-        val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/assign-activate-input.json", ExecutionServiceInput::class.java)!!
+            // Assign Workflow inputs Mock
+            val input = executionServiceInput.payload.get("assign-activate-request")
+            bluePrintRuntimeService.assignWorkflowInputs("assign-activate", input)
 
-        runBlocking {
-            dgWorkflowExecutionService.executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, mutableMapOf())
+
+            val executionServiceOutput = dgWorkflowExecutionService
+                    .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, mutableMapOf())
+            assertNotNull(executionServiceOutput, "failed to get response")
+            assertEquals(BluePrintConstants.STATUS_SUCCESS, executionServiceOutput.status.message,
+                    "failed to get successful response")
         }
 
     }
index 0980f84..ac2d7d6 100644 (file)
@@ -22,33 +22,43 @@ import org.junit.Test
 import org.junit.runner.RunWith
 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
 import org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.executor.ComponentExecuteNodeExecutor
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
-import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
-import org.slf4j.LoggerFactory
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonReactorUtils
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.test.context.ContextConfiguration
 import org.springframework.test.context.junit4.SpringRunner
+import kotlin.test.assertEquals
+import kotlin.test.assertNotNull
 
 @RunWith(SpringRunner::class)
 @ContextConfiguration(classes = [WorkflowServiceConfiguration::class, ComponentExecuteNodeExecutor::class])
 class DGWorkflowExecutionServiceTest {
 
-    private val log = LoggerFactory.getLogger(BlueprintServiceLogicTest::class.java)
-
     @Autowired
     lateinit var dgWorkflowExecutionService: DGWorkflowExecutionService
 
 
     @Test
     fun testExecuteDirectedGraph() {
+        runBlocking {
 
-        val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
-                "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+            val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
+                    "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
 
-        val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json", ExecutionServiceInput::class.java)!!
+            val executionServiceInput = JacksonReactorUtils
+                    .readValueFromClassPathFile("execution-input/resource-assignment-input.json", ExecutionServiceInput::class.java)!!
 
-        runBlocking {
-            dgWorkflowExecutionService.executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, mutableMapOf())
+            // Assign Workflow inputs Mock
+            val input = executionServiceInput.payload.get("resource-assignment-request")
+            bluePrintRuntimeService.assignWorkflowInputs("resource-assignment", input)
+
+            val executionServiceOutput = dgWorkflowExecutionService.executeBluePrintWorkflow(bluePrintRuntimeService,
+                    executionServiceInput, mutableMapOf())
+
+            assertNotNull(executionServiceOutput, "failed to get response")
+            assertEquals(BluePrintConstants.STATUS_SUCCESS, executionServiceOutput.status.message,
+                    "failed to get successful response")
         }
 
     }
index 904983f..bc01039 100644 (file)
@@ -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(":")
index 85ae359..7ac79e2 100644 (file)
  */
 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)
index 7a1fb6d..1a6ccfa 100644 (file)
@@ -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")
+        }
 
     }