Renaming Files having BluePrint to have Blueprint
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / services / workflow-service / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / services / workflow / NodeTemplateExecutionService.kt
index b64177a..1d179a1 100644 (file)
@@ -20,21 +20,26 @@ import com.fasterxml.jackson.databind.JsonNode
 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.StepData
+import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterService
 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants
 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
-import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
-import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
+import org.onap.ccsdk.cds.controllerblueprints.core.data.Implementation
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintDependencyService
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintRuntimeService
 import org.slf4j.LoggerFactory
 import org.springframework.stereotype.Service
 
 @Service
-open class NodeTemplateExecutionService {
+open class NodeTemplateExecutionService(private val bluePrintClusterService: BlueprintClusterService) {
 
     private val log = LoggerFactory.getLogger(NodeTemplateExecutionService::class.java)!!
 
-    suspend fun executeNodeTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
-                                    executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
+    suspend fun executeNodeTemplate(
+        bluePrintRuntimeService: BlueprintRuntimeService<*>,
+        nodeTemplateName: String,
+        executionServiceInput: ExecutionServiceInput
+    ): ExecutionServiceOutput {
         // Get the Blueprint Context
         val blueprintContext = bluePrintRuntimeService.bluePrintContext()
 
@@ -47,17 +52,20 @@ open class NodeTemplateExecutionService {
         val operationName = blueprintContext.nodeTemplateFirstInterfaceFirstOperationName(nodeTemplateName)
 
         val nodeTemplateImplementation = blueprintContext
-                .nodeTemplateOperationImplementation(nodeTemplateName, interfaceName, operationName)
+            .nodeTemplateOperationImplementation(nodeTemplateName, interfaceName, operationName)
+            ?: Implementation()
 
-        val timeout: Int = nodeTemplateImplementation?.timeout ?: 180
-
-        log.info("executing node template($nodeTemplateName) component($componentName) " +
-                "interface($interfaceName) operation($operationName) with timeout($timeout) sec.")
+        log.info(
+            "executing node template($nodeTemplateName) component($componentName) " +
+                "interface($interfaceName) operation($operationName) on host (${nodeTemplateImplementation.operationHost}) " +
+                "with timeout(${nodeTemplateImplementation.timeout}) sec."
+        )
 
         // Get the Component Instance
-        val plugin = BluePrintDependencyService.instance<AbstractComponentFunction>(componentName)
-        // Set the Blueprint Service
+        val plugin = BlueprintDependencyService.instance<AbstractComponentFunction>(componentName)
+        // Set the Blueprint Services
         plugin.bluePrintRuntimeService = bluePrintRuntimeService
+        plugin.bluePrintClusterService = bluePrintClusterService
         plugin.stepName = nodeTemplateName
 
         // Parent request shouldn't tamper, so need to clone the request and send to the actual component.
@@ -69,10 +77,9 @@ open class NodeTemplateExecutionService {
 
         // Populate Step Meta Data
         val stepInputs: MutableMap<String, JsonNode> = hashMapOf()
-        stepInputs[BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] = nodeTemplateName.asJsonPrimitive()
-        stepInputs[BluePrintConstants.PROPERTY_CURRENT_INTERFACE] = interfaceName.asJsonPrimitive()
-        stepInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] = operationName.asJsonPrimitive()
-        stepInputs[BluePrintConstants.PROPERTY_CURRENT_TIMEOUT] = timeout.asJsonPrimitive()
+        stepInputs[BlueprintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] = nodeTemplateName.asJsonPrimitive()
+        stepInputs[BlueprintConstants.PROPERTY_CURRENT_INTERFACE] = interfaceName.asJsonPrimitive()
+        stepInputs[BlueprintConstants.PROPERTY_CURRENT_OPERATION] = operationName.asJsonPrimitive()
         val stepInputData = StepData().apply {
             name = nodeTemplateName
             properties = stepInputs
@@ -82,5 +89,4 @@ open class NodeTemplateExecutionService {
         // Get the Request from the Context and Set to the Function Input and Invoke the function
         return plugin.applyNB(clonedExecutionServiceInput)
     }
-
-}
\ No newline at end of file
+}