diff options
author | Brinda Santh <brindasanth@in.ibm.com> | 2019-08-14 19:10:04 -0400 |
---|---|---|
committer | Brinda Santh Muthuramalingam <brindasanth@in.ibm.com> | 2019-08-16 14:28:50 +0000 |
commit | 048aad79ece5b709e65155e2d0c8675b7c2c84a2 (patch) | |
tree | bd771d1c5113bd17f2cb812443f691f7d5ad6166 /ms/controllerblueprints/modules/blueprint-core/src/main | |
parent | d58654ce65f36b9d6ddc3f38c751da26d029ea41 (diff) |
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 <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/controllerblueprints/modules/blueprint-core/src/main')
3 files changed, 27 insertions, 19 deletions
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<In, Out> { - /** 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<Out>) suspend fun initializeWorkflow(input: In): EdgeLabel @@ -89,8 +89,9 @@ enum class EdgeAction(val id: String) { } /** Abstract workflow service implementation */ -abstract class AbstractBluePrintWorkFlowService<In, Out>(private val graph: Graph) - : CoroutineScope, BluePrintWorkFlowService<In, Out> { +abstract class AbstractBluePrintWorkFlowService<In, Out> : CoroutineScope, BluePrintWorkFlowService<In, Out> { + + lateinit var graph: Graph private val log = logger(AbstractBluePrintWorkFlowService::class) @@ -101,8 +102,6 @@ abstract class AbstractBluePrintWorkFlowService<In, Out>(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<In, Out>(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<In, Out>(private val graph: Grap } } - - override suspend fun executeWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, input: In, output: CompletableDeferred<Out>) { + override suspend fun executeWorkflow(graph: Graph, bluePrintRuntimeService: BluePrintRuntimeService<*>, + input: In, output: CompletableDeferred<Out>) { 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<MutableMap<String, JsonNode>> { - + fun getBluePrintRuntime(id: String, blueprintBasePath: String) + : BluePrintRuntimeService<MutableMap<String, JsonNode>> { val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath) + return getBluePrintRuntime(id, bluePrintContext) + } + fun getBluePrintRuntime(id: String, bluePrintContext: BluePrintContext) + : BluePrintRuntimeService<MutableMap<String, JsonNode>> { + 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 } |