summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap
diff options
context:
space:
mode:
authorBrinda Santh <brindasanth@in.ibm.com>2019-08-14 19:10:04 -0400
committerBrinda Santh Muthuramalingam <brindasanth@in.ibm.com>2019-08-16 14:28:50 +0000
commit048aad79ece5b709e65155e2d0c8675b7c2c84a2 (patch)
treebd771d1c5113bd17f2cb812443f691f7d5ad6166 /ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap
parentd58654ce65f36b9d6ddc3f38c751da26d029ea41 (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/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap')
-rw-r--r--ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/ImperativeWorkflowExecutionService.kt143
-rw-r--r--ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt6
2 files changed, 146 insertions, 3 deletions
diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/ImperativeWorkflowExecutionService.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/ImperativeWorkflowExecutionService.kt
new file mode 100644
index 000000000..e7e5fe68a
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/ImperativeWorkflowExecutionService.kt
@@ -0,0 +1,143 @@
+/*
+ * Copyright © 2019 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.cds.blueprintsprocessor.services.workflow
+
+import kotlinx.coroutines.CompletableDeferred
+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.asGraph
+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.interfaces.BluePrintWorkflowExecutionService
+import org.onap.ccsdk.cds.controllerblueprints.core.logger
+import org.onap.ccsdk.cds.controllerblueprints.core.service.*
+import org.springframework.beans.factory.config.ConfigurableBeanFactory
+import org.springframework.context.annotation.Scope
+import org.springframework.stereotype.Service
+
+@Service("imperativeWorkflowExecutionService")
+class ImperativeWorkflowExecutionService(
+ private val bluePrintWorkFlowService: BluePrintWorkFlowService<ExecutionServiceInput, ExecutionServiceOutput>)
+ : BluePrintWorkflowExecutionService<ExecutionServiceInput, ExecutionServiceOutput> {
+
+ override suspend fun executeBluePrintWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>,
+ executionServiceInput: ExecutionServiceInput,
+ properties: MutableMap<String, Any>): ExecutionServiceOutput {
+
+ val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
+
+ val workflowName = executionServiceInput.actionIdentifiers.actionName
+
+ val graph = bluePrintContext.workflowByName(workflowName).asGraph()
+
+ val deferredOutput = CompletableDeferred<ExecutionServiceOutput>()
+ bluePrintWorkFlowService.executeWorkflow(graph, bluePrintRuntimeService, executionServiceInput, deferredOutput)
+ return deferredOutput.await()
+ }
+}
+
+@Service
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+open class ImperativeBluePrintWorkflowService(private val nodeTemplateExecutionService: NodeTemplateExecutionService)
+ : AbstractBluePrintWorkFlowService<ExecutionServiceInput, ExecutionServiceOutput>() {
+ val log = logger(ImperativeBluePrintWorkflowService::class)
+
+ lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*>
+ lateinit var executionServiceInput: ExecutionServiceInput
+ lateinit var deferredExecutionServiceOutput: CompletableDeferred<ExecutionServiceOutput>
+
+ override suspend fun executeWorkflow(graph: Graph, bluePrintRuntimeService: BluePrintRuntimeService<*>,
+ input: ExecutionServiceInput,
+ output: CompletableDeferred<ExecutionServiceOutput>) {
+ this.graph = graph
+ this.bluePrintRuntimeService = bluePrintRuntimeService
+ this.executionServiceInput = input
+ this.deferredExecutionServiceOutput = output
+ this.workflowId = bluePrintRuntimeService.id()
+ val startMessage = WorkflowExecuteMessage(input, output)
+ workflowActor.send(startMessage)
+ }
+
+ override suspend fun initializeWorkflow(input: ExecutionServiceInput): EdgeLabel {
+ return EdgeLabel.SUCCESS
+ }
+
+ override suspend fun prepareWorkflowOutput(): ExecutionServiceOutput {
+ return ExecutionServiceOutput().apply {
+ commonHeader = executionServiceInput.commonHeader
+ actionIdentifiers = executionServiceInput.actionIdentifiers
+ }
+ }
+
+ override suspend fun prepareNodeExecutionMessage(node: Graph.Node)
+ : NodeExecuteMessage<ExecutionServiceInput, ExecutionServiceOutput> {
+ val deferredOutput = CompletableDeferred<ExecutionServiceOutput>()
+ return NodeExecuteMessage(node, executionServiceInput, deferredOutput)
+ }
+
+ override suspend fun prepareNodeSkipMessage(node: Graph.Node)
+ : NodeSkipMessage<ExecutionServiceInput, ExecutionServiceOutput> {
+ val deferredOutput = CompletableDeferred<ExecutionServiceOutput>()
+ return NodeSkipMessage(node, executionServiceInput, deferredOutput)
+ }
+
+ override suspend fun executeNode(node: Graph.Node, nodeInput: ExecutionServiceInput,
+ deferredNodeOutput: CompletableDeferred<ExecutionServiceOutput>,
+ deferredNodeStatus: CompletableDeferred<EdgeLabel>) {
+ try {
+ val nodeTemplateName = node.id
+ /** execute node template */
+ val executionServiceOutput = nodeTemplateExecutionService
+ .executeNodeTemplate(bluePrintRuntimeService, nodeTemplateName, nodeInput)
+ val edgeStatus = when (executionServiceOutput.status.message) {
+ BluePrintConstants.STATUS_FAILURE -> EdgeLabel.FAILURE
+ else -> EdgeLabel.SUCCESS
+ }
+ /** set deferred output and status */
+ deferredNodeOutput.complete(executionServiceOutput)
+ deferredNodeStatus.complete(edgeStatus)
+ } catch (e: Exception) {
+ log.error("failed in executeNode($node)", e)
+ deferredNodeOutput.completeExceptionally(e)
+ deferredNodeStatus.complete(EdgeLabel.FAILURE)
+ }
+ }
+
+ override suspend fun skipNode(node: Graph.Node, nodeInput: ExecutionServiceInput,
+ deferredNodeOutput: CompletableDeferred<ExecutionServiceOutput>,
+ deferredNodeStatus: CompletableDeferred<EdgeLabel>) {
+ val executionServiceOutput = ExecutionServiceOutput().apply {
+ commonHeader = nodeInput.commonHeader
+ actionIdentifiers = nodeInput.actionIdentifiers
+ }
+ deferredNodeOutput.complete(executionServiceOutput)
+ deferredNodeStatus.complete(EdgeLabel.SUCCESS)
+ }
+
+ override suspend fun cancelNode(node: Graph.Node, nodeInput: ExecutionServiceInput,
+ deferredNodeOutput: CompletableDeferred<ExecutionServiceOutput>,
+ deferredNodeStatus: CompletableDeferred<EdgeLabel>) {
+ TODO("not implemented")
+ }
+
+ override suspend fun restartNode(node: Graph.Node, nodeInput: ExecutionServiceInput,
+ deferredNodeOutput: CompletableDeferred<ExecutionServiceOutput>,
+ deferredNodeStatus: CompletableDeferred<EdgeLabel>) {
+ TODO("not implemented")
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt
index af7846340..89732e300 100644
--- a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt
+++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt
@@ -23,13 +23,13 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.cds.controllerblueprints.core.putJsonElement
+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.context.ApplicationContext
import org.springframework.stereotype.Service
@Service
-open class NodeTemplateExecutionService(private val applicationContext: ApplicationContext) {
+open class NodeTemplateExecutionService {
private val log = LoggerFactory.getLogger(NodeTemplateExecutionService::class.java)!!
@@ -48,7 +48,7 @@ open class NodeTemplateExecutionService(private val applicationContext: Applicat
"interface($interfaceName) operation($operationName)")
// Get the Component Instance
- val plugin = applicationContext.getBean(componentName, AbstractComponentFunction::class.java)
+ val plugin = BluePrintDependencyService.instance<AbstractComponentFunction>(componentName)
// Set the Blueprint Service
plugin.bluePrintRuntimeService = bluePrintRuntimeService
plugin.stepName = nodeTemplateName