aboutsummaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/blueprint-core
diff options
context:
space:
mode:
Diffstat (limited to 'ms/controllerblueprints/modules/blueprint-core')
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/GraphExtensionFunctions.kt7
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintWorkflowService.kt25
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtils.kt14
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt13
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintWorkflowServiceTest.kt24
5 files changed, 48 insertions, 35 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
}
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt
index 4c207fbe1..9103af3fa 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt
@@ -17,16 +17,17 @@
package org.onap.ccsdk.cds.controllerblueprints.core.service
-import org.slf4j.LoggerFactory
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.node.NullNode
import org.junit.Test
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
+import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintRuntimeUtils
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.slf4j.LoggerFactory
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
@@ -36,7 +37,7 @@ import kotlin.test.assertNotNull
* @author Brinda Santh
*/
class BluePrintRuntimeServiceTest {
- private val log= LoggerFactory.getLogger(this::class.toString())
+ private val log = LoggerFactory.getLogger(this::class.toString())
@Test
fun `test Resolve NodeTemplate Properties`() {
@@ -167,11 +168,15 @@ class BluePrintRuntimeServiceTest {
}
private fun getBluePrintRuntimeService(): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
- val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+ val blueprintBasePath = normalizedPathName("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
val blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
+ val checkProcessId = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID)
val checkBasePath = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH)
- assertEquals(blueprintBasePath.asJsonPrimitive(), checkBasePath, "Failed to get base path after runtime creation")
+ assertEquals("1234".asJsonPrimitive(),
+ checkProcessId, "Failed to get process id after runtime creation")
+ assertEquals(blueprintBasePath.asJsonPrimitive(),
+ checkBasePath, "Failed to get base path after runtime creation")
return blueprintRuntime
}
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintWorkflowServiceTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintWorkflowServiceTest.kt
index 7cb64922c..62cb10851 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintWorkflowServiceTest.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintWorkflowServiceTest.kt
@@ -33,11 +33,11 @@ class BluePrintWorkflowServiceTest {
runBlocking {
val graph = "[START>A/SUCCESS, A>B/SUCCESS, B>C/SUCCESS, C>D/SUCCESS, D>E/SUCCESS, E>END/SUCCESS]"
.toGraph()
- val simpleWorkflow = TestBluePrintWorkFlowService(graph)
+ val simpleWorkflow = TestBluePrintWorkFlowService()
simpleWorkflow.simulatedState = prepareSimulation(arrayListOf("A", "B", "C", "D", "E"), null)
val deferredOutput = CompletableDeferred<String>()
val input = "123456"
- simpleWorkflow.executeWorkflow(mockBluePrintRuntimeService(), input, deferredOutput)
+ simpleWorkflow.executeWorkflow(graph, mockBluePrintRuntimeService(), input, deferredOutput)
val response = deferredOutput.await()
assertNotNull(response, "failed to get response")
}
@@ -48,11 +48,11 @@ class BluePrintWorkflowServiceTest {
runBlocking {
val graph = "[START>A/SUCCESS, A>B/SUCCESS, A>C/FAILURE, B>D/SUCCESS, C>D/SUCCESS, D>END/SUCCESS]"
.toGraph()
- val simpleWorkflow = TestBluePrintWorkFlowService(graph)
+ val simpleWorkflow = TestBluePrintWorkFlowService()
simpleWorkflow.simulatedState = prepareSimulation(arrayListOf("A", "B", "C", "D", "E"), null)
val deferredOutput = CompletableDeferred<String>()
val input = "123456"
- simpleWorkflow.executeWorkflow(mockBluePrintRuntimeService(), input, deferredOutput)
+ simpleWorkflow.executeWorkflow(graph, mockBluePrintRuntimeService(), input, deferredOutput)
val response = deferredOutput.await()
assertNotNull(response, "failed to get response")
}
@@ -64,12 +64,12 @@ class BluePrintWorkflowServiceTest {
// Failure Flow
val failurePatGraph = "[START>A/SUCCESS, A>B/SUCCESS, A>C/FAILURE, B>D/SUCCESS, C>D/SUCCESS, D>END/SUCCESS]"
.toGraph()
- val failurePathWorkflow = TestBluePrintWorkFlowService(failurePatGraph)
+ val failurePathWorkflow = TestBluePrintWorkFlowService()
failurePathWorkflow.simulatedState = prepareSimulation(arrayListOf("B", "C", "D", "E"),
arrayListOf("A"))
val failurePathWorkflowDeferredOutput = CompletableDeferred<String>()
val failurePathWorkflowInput = "123456"
- failurePathWorkflow.executeWorkflow(mockBluePrintRuntimeService(), failurePathWorkflowInput, failurePathWorkflowDeferredOutput)
+ failurePathWorkflow.executeWorkflow(failurePatGraph, mockBluePrintRuntimeService(), failurePathWorkflowInput, failurePathWorkflowDeferredOutput)
val failurePathResponse = failurePathWorkflowDeferredOutput.await()
assertNotNull(failurePathResponse, "failed to get response")
}
@@ -80,11 +80,11 @@ class BluePrintWorkflowServiceTest {
runBlocking {
val graph = "[START>A/SUCCESS, A>B/SUCCESS, A>C/FAILURE, C>D/SUCCESS, D>E/SUCCESS, B>E/SUCCESS, E>END/SUCCESS]"
.toGraph()
- val simpleWorkflow = TestBluePrintWorkFlowService(graph)
+ val simpleWorkflow = TestBluePrintWorkFlowService()
simpleWorkflow.simulatedState = prepareSimulation(arrayListOf("A", "B", "C", "D", "E"), null)
val deferredOutput = CompletableDeferred<String>()
val input = "123456"
- simpleWorkflow.executeWorkflow(mockBluePrintRuntimeService(), input, deferredOutput)
+ simpleWorkflow.executeWorkflow(graph, mockBluePrintRuntimeService(), input, deferredOutput)
val response = deferredOutput.await()
assertNotNull(response, "failed to get response")
}
@@ -95,11 +95,11 @@ class BluePrintWorkflowServiceTest {
runBlocking {
val graph = "[START>A/SUCCESS, A>B/SUCCESS, A>C/SUCCESS, B>D/SUCCESS, C>D/SUCCESS, D>END/SUCCESS]"
.toGraph()
- val simpleWorkflow = TestBluePrintWorkFlowService(graph)
+ val simpleWorkflow = TestBluePrintWorkFlowService()
simpleWorkflow.simulatedState = prepareSimulation(arrayListOf("A", "B", "C", "D"), null)
val deferredOutput = CompletableDeferred<String>()
val input = "123456"
- simpleWorkflow.executeWorkflow(mockBluePrintRuntimeService(), input, deferredOutput)
+ simpleWorkflow.executeWorkflow(graph, mockBluePrintRuntimeService(), input, deferredOutput)
val response = deferredOutput.await()
assertNotNull(response, "failed to get response")
}
@@ -123,8 +123,8 @@ class BluePrintWorkflowServiceTest {
}
}
-class TestBluePrintWorkFlowService(graph: Graph)
- : AbstractBluePrintWorkFlowService<String, String>(graph) {
+class TestBluePrintWorkFlowService
+ : AbstractBluePrintWorkFlowService<String, String>() {
lateinit var simulatedState: MutableMap<String, EdgeLabel>