Add directed graph reterive and execution service.
authorMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Tue, 20 Nov 2018 20:55:29 +0000 (15:55 -0500)
committerBrinda Santh Muthuramalingam <bs2796@att.com>
Fri, 30 Nov 2018 20:45:33 +0000 (20:45 +0000)
Change-Id: Ia31af4d14e38e6229166cda0f39fa090764ef1cb
Issue-ID: CCSDK-672
Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
ms/blueprintsprocessor/modules/commons/core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt
ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractComponentFunction.kt
ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintDGExecutionService.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt
ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/WorkflowServiceConfiguration.kt
ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintDGExecutionServiceTest.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt
ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/mock/MockComponentFunction.kt
ms/blueprintsprocessor/modules/services/workflow-service/src/test/resources/execution-input/default-input.json [new file with mode: 0644]

index 45f684f..adce865 100644 (file)
@@ -22,6 +22,7 @@ import com.fasterxml.jackson.databind.JsonNode
 import com.fasterxml.jackson.databind.node.ObjectNode\r
 import io.swagger.annotations.ApiModelProperty\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment\r
+import java.util.*\r
 \r
 /**\r
  * BlueprintProcessorData\r
@@ -87,7 +88,7 @@ open class ActionIdentifiers {
 open class CommonHeader {\r
     @get:ApiModelProperty(required = true, example = "2012-04-23T18:25:43.511Z")\r
     @get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")\r
-    lateinit var timestamp: String\r
+    var timestamp: Date = Date()\r
     @get:ApiModelProperty(required = true)\r
     lateinit var originatorId: String\r
     @get:ApiModelProperty(required = true)\r
index 801b660..dfdf625 100644 (file)
@@ -33,7 +33,7 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic
     private val log = LoggerFactory.getLogger(AbstractComponentFunction::class.java)\r
 \r
     var executionServiceInput: ExecutionServiceInput? = null\r
-    val executionServiceOutput = ExecutionServiceOutput()\r
+    var executionServiceOutput = ExecutionServiceOutput()\r
     var bluePrintRuntimeService: BluePrintRuntimeService<*>? = null\r
     var processId: String = ""\r
     var workflowName: String = ""\r
diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintDGExecutionService.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintDGExecutionService.kt
new file mode 100644 (file)
index 0000000..993f10e
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * 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.apps.blueprintsprocessor.services.workflow
+
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput
+import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.utils.SvcGraphUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
+import org.slf4j.LoggerFactory
+import org.springframework.stereotype.Service
+import java.io.File
+
+
+interface BlueprintDGExecutionService {
+
+    fun executeDirectedGraph(bluePrintRuntimeService: BluePrintRuntimeService<*>,
+                             executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput
+
+}
+
+@Service
+class DefaultBlueprintDGExecutionService(val blueprintSvcLogicService: BlueprintSvcLogicService) : BlueprintDGExecutionService {
+
+    private val log = LoggerFactory.getLogger(DefaultBlueprintDGExecutionService::class.java)
+
+    override fun executeDirectedGraph(bluePrintRuntimeService: BluePrintRuntimeService<*>,
+                                      executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
+
+        val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
+
+        val workflowName = executionServiceInput.actionIdentifiers.actionName
+
+        // Get the DG Node Template
+        val nodeTemplateName = bluePrintContext.workflowFirstStepNodeTemplate(workflowName)
+
+        log.info("Executing workflow($workflowName) directed graph NodeTemplate($nodeTemplateName)")
+
+        // Get the DG file info
+        val artifactDefinition = bluePrintContext.nodeTemplateArtifactForArtifactType(nodeTemplateName,
+                WorkflowServiceConstants.ARTIFACT_TYPE_DIRECTED_GRAPH)
+
+        // Populate the DG Path
+        val dgFilePath = bluePrintRuntimeService.getAsString(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH)
+                .plus(File.separator).plus(artifactDefinition.file)
+
+        log.info("Executing directed graph ($dgFilePath)")
+
+        // Create DG instance
+        val graph = SvcGraphUtils.getSvcGraphFromFile(dgFilePath)
+
+        // Execute the DG
+        return blueprintSvcLogicService.execute(graph, bluePrintRuntimeService, executionServiceInput) as ExecutionServiceOutput
+
+    }
+
+}
\ No newline at end of file
index 0600f62..ab7d738 100644 (file)
@@ -36,7 +36,7 @@ interface BlueprintSvcLogicService : SvcLogicService {
 
     fun unRegisterExecutors(name: String)
 
-    fun execute(graph: SvcLogicGraph, bluePrintRuntimeService: BluePrintRuntimeService<*>): Any
+    fun execute(graph: SvcLogicGraph, bluePrintRuntimeService: BluePrintRuntimeService<*>, input: Any): Any
 
     @Deprecated("Populate Graph Dynamically from Blueprints, No need to get from Database Store ")
     override fun getStore(): SvcLogicStore {
@@ -93,10 +93,11 @@ class DefaultBlueprintSvcLogicService : BlueprintSvcLogicService {
         }
     }
 
-    override fun execute(graph: SvcLogicGraph, bluePrintRuntimeService: BluePrintRuntimeService<*>): Any {
-        //Initialise BlueprintSvcLogic Context
+    override fun execute(graph: SvcLogicGraph, bluePrintRuntimeService: BluePrintRuntimeService<*>, input: Any): Any {
+        //Initialise BlueprintSvcLogic Context with Blueprint Runtime Service and Input Request
         val blueprintSvcLogicContext = BlueprintSvcLogicContext()
         blueprintSvcLogicContext.setBluePrintRuntimeService(bluePrintRuntimeService)
+        blueprintSvcLogicContext.setRequest(input)
         // Execute the Graph
         execute(graph, blueprintSvcLogicContext)
         // Get the Response
index b9c041e..b3186e8 100644 (file)
@@ -21,6 +21,11 @@ import org.springframework.context.annotation.Configuration
 
 @Configuration
 @ComponentScan
-open class WorkflowServiceConfiguration {
+open class WorkflowServiceConfiguration
 
+
+class WorkflowServiceConstants {
+    companion object {
+        const val ARTIFACT_TYPE_DIRECTED_GRAPH = "artifact-directed-graph"
+    }
 }
\ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintDGExecutionServiceTest.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintDGExecutionServiceTest.kt
new file mode 100644 (file)
index 0000000..46bb6f0
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * 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.apps.blueprintsprocessor.services.workflow
+
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.executor.ComponentExecuteNodeExecutor
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+import org.slf4j.LoggerFactory
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.test.context.ContextConfiguration
+import org.springframework.test.context.junit4.SpringRunner
+
+@RunWith(SpringRunner::class)
+@ContextConfiguration(classes = [WorkflowServiceConfiguration::class, ComponentExecuteNodeExecutor::class])
+class BlueprintDGExecutionServiceTest {
+
+    private val log = LoggerFactory.getLogger(BlueprintServiceLogicTest::class.java)
+
+    @Autowired
+    lateinit var blueprintDGExecutionService: BlueprintDGExecutionService
+
+
+    @Test
+    fun testExecuteDirectedGraph() {
+
+        val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
+                "./../../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration")
+
+        val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/default-input.json", ExecutionServiceInput::class.java)!!
+
+        blueprintDGExecutionService.executeDirectedGraph(bluePrintRuntimeService, executionServiceInput)
+
+    }
+
+
+}
\ No newline at end of file
index 9a59831..341b6f8 100644 (file)
 
 package org.onap.ccsdk.apps.blueprintsprocessor.services.workflow
 
-import com.fasterxml.jackson.databind.JsonNode
 import org.junit.Test
 import org.junit.runner.RunWith
-import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers
-import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader
 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
 import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.executor.ComponentExecuteNodeExecutor
 import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.utils.SvcGraphUtils
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
-import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
 import org.slf4j.LoggerFactory
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.test.context.ContextConfiguration
@@ -41,6 +37,8 @@ class BlueprintServiceLogicTest {
     val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
             "./../../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration")
 
+    val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/default-input.json", ExecutionServiceInput::class.java)!!
+
     @Autowired
     lateinit var blueprintSvcLogicService: BlueprintSvcLogicService
 
@@ -48,42 +46,15 @@ class BlueprintServiceLogicTest {
     fun testExecuteGraphWithSingleComponent() {
 
         val graph = SvcGraphUtils.getSvcGraphFromClassPathFile("service-logic/one-component.xml")
-        val svcLogicContext = BlueprintSvcLogicContext()
-        svcLogicContext.setBluePrintRuntimeService(bluePrintRuntimeService)
-        svcLogicContext.setRequest(getDefaultExecutionServiceInput())
-        blueprintSvcLogicService.execute(graph, svcLogicContext)
+        blueprintSvcLogicService.execute(graph, bluePrintRuntimeService, executionServiceInput)
 
     }
 
     @Test
     fun testExecuteGraphWithMultipleComponents() {
         val graph = SvcGraphUtils.getSvcGraphFromClassPathFile("service-logic/two-component.xml")
-        val svcLogicContext = BlueprintSvcLogicContext()
-        svcLogicContext.setBluePrintRuntimeService(bluePrintRuntimeService)
-        svcLogicContext.setRequest(getDefaultExecutionServiceInput())
-        blueprintSvcLogicService.execute(graph, svcLogicContext)
+        blueprintSvcLogicService.execute(graph, bluePrintRuntimeService, executionServiceInput)
 
     }
 
-    private fun getDefaultExecutionServiceInput(): ExecutionServiceInput {
-        val executionServiceInput = ExecutionServiceInput()
-        val commonHeader = CommonHeader()
-        commonHeader.requestId = "1234"
-        executionServiceInput.commonHeader = commonHeader
-
-        val actionIdentifiers = ActionIdentifiers()
-        actionIdentifiers.blueprintName = "baseconfiguration"
-        actionIdentifiers.blueprintVersion = "1.0.0"
-        actionIdentifiers.actionName = "activate"
-        executionServiceInput.actionIdentifiers = actionIdentifiers
-
-        val metaData: MutableMap<String, JsonNode> = hashMapOf()
-        metaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_STEP,"resource-assignment-py")
-        metaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment-py")
-        metaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ResourceAssignmentComponent")
-        metaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
-        executionServiceInput.metadata = metaData
-
-        return executionServiceInput
-    }
 }
\ No newline at end of file
index 5aa9013..747be76 100644 (file)
@@ -17,6 +17,7 @@
 package org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.mock
 
 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput
 import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
 import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.executor.ComponentExecuteNodeExecutor
 import org.slf4j.LoggerFactory
@@ -38,6 +39,8 @@ class MockComponentFunction : AbstractComponentFunction() {
 
     override fun process(executionRequest: ExecutionServiceInput) {
         log.info("Processing component..")
+
+        this.executionServiceOutput = ExecutionServiceOutput()
     }
 
     override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/resources/execution-input/default-input.json b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/resources/execution-input/default-input.json
new file mode 100644 (file)
index 0000000..20401fd
--- /dev/null
@@ -0,0 +1,20 @@
+{
+  "commonHeader" : {
+    "originatorId" : "System",
+    "requestId" : "1234",
+    "subRequestId" : "1234-12234"
+  },
+  "actionIdentifiers" : {
+    "blueprintName" : "baseconfiguration",
+    "blueprintVersion" : "1.0.0",
+    "actionName" : "activate",
+    "mode" : "sync"
+  },
+  "payload" : { },
+  "metadata" : {
+    "current-node-template" : "resource-assignment-py",
+    "current-step" : "resource-assignment-py",
+    "current-operation" : "process",
+    "current-interface" : "ResourceAssignmentComponent"
+  }
+}
\ No newline at end of file