From 048aad79ece5b709e65155e2d0c8675b7c2c84a2 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Wed, 14 Aug 2019 19:10:04 -0400 Subject: Add Imperative workflow execution service. Workflow implementation based on multiple steps in blueprint model. Change-Id: I21eaf5d08621ae6eac2fa0a5db2aca0291928d52 Issue-ID: CCSDK-1619 Signed-off-by: Brinda Santh --- .../core/GraphExtensionFunctions.kt | 7 ++++++ .../core/service/BluePrintWorkflowService.kt | 25 +++++++++------------- .../core/utils/BluePrintMetadataUtils.kt | 14 ++++++++---- 3 files changed, 27 insertions(+), 19 deletions(-) (limited to 'ms/controllerblueprints/modules/blueprint-core/src/main') diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/GraphExtensionFunctions.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/GraphExtensionFunctions.kt index 235c48b66..793bdc455 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/GraphExtensionFunctions.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/GraphExtensionFunctions.kt @@ -18,10 +18,17 @@ package org.onap.ccsdk.cds.controllerblueprints.core import org.onap.ccsdk.cds.controllerblueprints.core.data.EdgeLabel import org.onap.ccsdk.cds.controllerblueprints.core.data.Graph +import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow +import org.onap.ccsdk.cds.controllerblueprints.core.utils.WorkflowGraphUtils import java.util.regex.Pattern private val graphTokenSeparators = Pattern.compile("[->/]") +/** Convert Blueprint workflow to graph data structure */ +fun Workflow.asGraph(): Graph { + return WorkflowGraphUtils.workFlowToGraph(this) +} + fun String.toGraph(): Graph { if (!startsWith('[') || !endsWith(']')) { throw IllegalArgumentException("Expected string starting '[' and ending with ']' but it was '$") diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintWorkflowService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintWorkflowService.kt index 019f31805..91c2bcbbb 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintWorkflowService.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintWorkflowService.kt @@ -29,9 +29,9 @@ import kotlin.coroutines.CoroutineContext interface BluePrintWorkFlowService { - /** Executes imperative workflow for the bluePrintRuntimeService [bluePrintRuntimeService] and workflow - * input [input], response will be retrieve from output [output]*/ - suspend fun executeWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, + /** Executes imperative workflow graph [graph] for the bluePrintRuntimeService [bluePrintRuntimeService] + * and workflow input [input], response will be retrieve from output [output]*/ + suspend fun executeWorkflow(graph: Graph, bluePrintRuntimeService: BluePrintRuntimeService<*>, input: In, output: CompletableDeferred) suspend fun initializeWorkflow(input: In): EdgeLabel @@ -89,8 +89,9 @@ enum class EdgeAction(val id: String) { } /** Abstract workflow service implementation */ -abstract class AbstractBluePrintWorkFlowService(private val graph: Graph) - : CoroutineScope, BluePrintWorkFlowService { +abstract class AbstractBluePrintWorkFlowService : CoroutineScope, BluePrintWorkFlowService { + + lateinit var graph: Graph private val log = logger(AbstractBluePrintWorkFlowService::class) @@ -101,8 +102,6 @@ abstract class AbstractBluePrintWorkFlowService(private val graph: Grap final override val coroutineContext: CoroutineContext get() = job + CoroutineName("Wf") - val root = graph.startNodes() - fun cancel() { log.info("Received workflow($workflowId) cancel request") job.cancel() @@ -121,7 +120,7 @@ abstract class AbstractBluePrintWorkFlowService(private val graph: Grap // Prepare Workflow and Populate the Initial store initializeWorkflow(workflowExecuteMessage.input) - val startNode = root.first() + val startNode = graph.startNodes().first() // Prepare first node message and Send NodeExecuteMessage // Start node doesn't wait for any nodes, so we can pass Execute message directly val nodeExecuteMessage = prepareNodeExecutionMessage(startNode) @@ -325,16 +324,12 @@ abstract class AbstractBluePrintWorkFlowService(private val graph: Grap } } - - override suspend fun executeWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, input: In, output: CompletableDeferred) { + override suspend fun executeWorkflow(graph: Graph, bluePrintRuntimeService: BluePrintRuntimeService<*>, + input: In, output: CompletableDeferred) { log.info("Executing Graph : $graph") + this.graph = graph this.workflowId = bluePrintRuntimeService.id() - validateWorkflow() val startMessage = WorkflowExecuteMessage(input, output) workflowActor.send(startMessage) } - - open fun validateWorkflow() { - //check(!graph.findCycles().isNotEmpty()) { "Graph is cyclic, Cycle is not supported" } - } } \ No newline at end of file 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 669ab3fef..55424ada8 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 @@ -61,7 +61,7 @@ class BluePrintMetadataUtils { // Verify if the environment directory exists if (envDir.exists() && envDir.isDirectory) { //Find all available environment files - envDir.listFiles() + envDir.listFiles()!! .filter { it.name.endsWith(".properties") } .forEach { val istream = it.inputStream() @@ -96,14 +96,20 @@ class BluePrintMetadataUtils { return toscaMetaData } - fun getBluePrintRuntime(id: String, blueprintBasePath: String): BluePrintRuntimeService> { - + fun getBluePrintRuntime(id: String, blueprintBasePath: String) + : BluePrintRuntimeService> { val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath) + return getBluePrintRuntime(id, bluePrintContext) + } + fun getBluePrintRuntime(id: String, bluePrintContext: BluePrintContext) + : BluePrintRuntimeService> { + checkNotEmpty(bluePrintContext.rootPath) { "blueprint context root path is missing." } + checkNotEmpty(bluePrintContext.entryDefinition) { "blueprint context entry definition is missing." } + val blueprintBasePath = bluePrintContext.rootPath val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext) bluePrintRuntimeService.put(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH, blueprintBasePath.asJsonPrimitive()) bluePrintRuntimeService.put(BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID, id.asJsonPrimitive()) - return bluePrintRuntimeService } -- cgit 1.2.3-korg