From abdc4a1f59294b8435a4af3738b415fe348967ab Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Wed, 13 Mar 2019 10:56:28 -0400 Subject: Add node template workflow service. Change-Id: I3a9167fe58b697f8fb9c7f5fd09768950afe1ff4 Issue-ID: CCSDK-1154 Signed-off-by: Muthuramalingam, Brinda Santh --- .../BluePrintWorkflowExecutionServiceImpl.kt | 72 +++++++++++++++++++++ .../workflow/BlueprintDGExecutionService.kt | 73 ---------------------- .../services/workflow/BlueprintSvcLogicService.kt | 6 +- .../workflow/ComponentWorkflowExecutionService.kt | 49 +++++++++++++++ .../workflow/DGWorkflowExecutionService.kt | 70 +++++++++++++++++++++ .../workflow/NodeTemplateExecutionService.kt | 72 +++++++++++++++++++++ .../executor/ComponentExecuteNodeExecutor.kt | 66 ++++--------------- .../BluePrintWorkflowExecutionServiceImplTest.kt | 54 ++++++++++++++++ .../workflow/BlueprintDGExecutionServiceTest.kt | 53 ---------------- .../services/workflow/BlueprintServiceLogicTest.kt | 12 +++- .../workflow/DGWorkflowExecutionServiceTest.kt | 57 +++++++++++++++++ 11 files changed, 398 insertions(+), 186 deletions(-) create mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt delete mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintDGExecutionService.kt create mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/ComponentWorkflowExecutionService.kt create mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/DGWorkflowExecutionService.kt create mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt create mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImplTest.kt delete mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintDGExecutionServiceTest.kt create mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/DGWorkflowExecutionServiceTest.kt (limited to 'ms/blueprintsprocessor/modules/services/workflow-service/src') diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt new file mode 100644 index 000000000..73f6f497e --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt @@ -0,0 +1,72 @@ +/* + * 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.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.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Service + +@Service("bluePrintWorkflowExecutionService") +open class BluePrintWorkflowExecutionServiceImpl( + private val componentWorkflowExecutionService: ComponentWorkflowExecutionService, + private val dgWorkflowExecutionService: DGWorkflowExecutionService +) : BluePrintWorkflowExecutionService { + + private val log = LoggerFactory.getLogger(BluePrintWorkflowExecutionServiceImpl::class.java)!! + + override suspend fun executeBluePrintWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, + executionServiceInput: ExecutionServiceInput, + properties: MutableMap): ExecutionServiceOutput { + + val bluePrintContext = bluePrintRuntimeService.bluePrintContext() + + val workflowName = executionServiceInput.actionIdentifiers.actionName + + // Get the DG Node Template + val nodeTemplateName = bluePrintContext.workflowFirstStepNodeTemplate(workflowName) + + val derivedFrom = bluePrintContext.nodeTemplateNodeType(nodeTemplateName).derivedFrom + + log.info("Executing workflow($workflowName) NodeTemplate($nodeTemplateName), derived from($derivedFrom)") + + val executionServiceOutput: ExecutionServiceOutput = when { + derivedFrom.startsWith(BluePrintConstants.MODEL_TYPE_NODE_COMPONENT, true) -> { + componentWorkflowExecutionService + .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, properties) + } + derivedFrom.startsWith(BluePrintConstants.MODEL_TYPE_NODE_DG, true) -> { + dgWorkflowExecutionService + .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, properties) + } + else -> { + throw BluePrintProcessorException("couldn't execute workflow($workflowName) step mapped " + + "to node template($nodeTemplateName) derived from($derivedFrom)") + } + } + + executionServiceOutput.commonHeader = executionServiceInput.commonHeader + executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers + // TODO("Populate Response Payload and status") + return executionServiceOutput + } + +} \ No newline at end of file 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 deleted file mode 100644 index 8ba02ac8f..000000000 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintDGExecutionService.kt +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.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(private 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 = bluePrintContext.rootPath.plus(File.separator).plus(artifactDefinition.file) - - log.info("Executing directed graph ($dgFilePath)") - - // Create DG instance - val graph = SvcGraphUtils.getSvcGraphFromFile(dgFilePath) - - // Assign Workflow inputs - val input = executionServiceInput.payload.get("$workflowName-request") - bluePrintRuntimeService.assignWorkflowInputs(workflowName, input) - - // Execute the DG - return blueprintSvcLogicService.execute(graph, bluePrintRuntimeService, executionServiceInput) as ExecutionServiceOutput - - } - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt index dfa22f68e..fd7ec45b3 100644 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications 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. @@ -35,7 +36,7 @@ interface BlueprintSvcLogicService : SvcLogicServiceBase { fun unRegisterExecutors(name: String) - fun execute(graph: SvcLogicGraph, bluePrintRuntimeService: BluePrintRuntimeService<*>, input: Any): Any + suspend 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 { @@ -87,7 +88,8 @@ class DefaultBlueprintSvcLogicService : BlueprintSvcLogicService { } } - override fun execute(graph: SvcLogicGraph, bluePrintRuntimeService: BluePrintRuntimeService<*>, input: Any): Any { + override suspend 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) diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/ComponentWorkflowExecutionService.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/ComponentWorkflowExecutionService.kt new file mode 100644 index 000000000..76d0c46b5 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/ComponentWorkflowExecutionService.kt @@ -0,0 +1,49 @@ +/* + * 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.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.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService +import org.springframework.stereotype.Service + +@Service("componentWorkflowExecutionService") +open class ComponentWorkflowExecutionService(private val nodeTemplateExecutionService: NodeTemplateExecutionService) + : BluePrintWorkflowExecutionService { + + override suspend fun executeBluePrintWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, + executionServiceInput: ExecutionServiceInput, + properties: MutableMap): ExecutionServiceOutput { + + val bluePrintContext = bluePrintRuntimeService.bluePrintContext() + + val workflowName = executionServiceInput.actionIdentifiers.actionName + + // Get the DG Node Template + val nodeTemplateName = bluePrintContext.workflowFirstStepNodeTemplate(workflowName) + + // Assign Workflow inputs + val input = executionServiceInput.payload.get("$workflowName-request") + bluePrintRuntimeService.assignWorkflowInputs(workflowName, input) + + return nodeTemplateExecutionService.executeNodeTemplate(bluePrintRuntimeService, + nodeTemplateName, executionServiceInput) + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/DGWorkflowExecutionService.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/DGWorkflowExecutionService.kt new file mode 100644 index 000000000..262b1be19 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/DGWorkflowExecutionService.kt @@ -0,0 +1,70 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications 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.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.interfaces.BluePrintWorkflowExecutionService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Service +import java.io.File + + +@Service("dgWorkflowExecutionService") +open class DGWorkflowExecutionService(private val blueprintSvcLogicService: BlueprintSvcLogicService) + : BluePrintWorkflowExecutionService { + + private val log = LoggerFactory.getLogger(DGWorkflowExecutionService::class.java) + + override suspend fun executeBluePrintWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, + executionServiceInput: ExecutionServiceInput, + properties: MutableMap): 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 = bluePrintContext.rootPath.plus(File.separator).plus(artifactDefinition.file) + + log.info("Executing directed graph ($dgFilePath)") + + // Create DG instance + val graph = SvcGraphUtils.getSvcGraphFromFile(dgFilePath) + + // Assign Workflow inputs + val input = executionServiceInput.payload.get("$workflowName-request") + bluePrintRuntimeService.assignWorkflowInputs(workflowName, input) + + // Execute the DG + return blueprintSvcLogicService.execute(graph, bluePrintRuntimeService, executionServiceInput) as ExecutionServiceOutput + + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt new file mode 100644 index 000000000..6ce4753b8 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt @@ -0,0 +1,72 @@ +/* + * 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.apps.blueprintsprocessor.services.workflow + +import com.fasterxml.jackson.databind.JsonNode +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +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.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode +import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement +import org.onap.ccsdk.apps.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) { + + private val log = LoggerFactory.getLogger(NodeTemplateExecutionService::class.java)!! + + suspend fun executeNodeTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, + executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput { + // Get the Blueprint Context + val blueprintContext = bluePrintRuntimeService.bluePrintContext() + // Get the Component Name, NodeTemplate type is mapped to Component Name + val componentName = blueprintContext.nodeTemplateByName(nodeTemplateName).type + + val interfaceName = blueprintContext.nodeTemplateFirstInterfaceName(nodeTemplateName) + + val operationName = blueprintContext.nodeTemplateFirstInterfaceFirstOperationName(nodeTemplateName) + + log.info("executing node template($nodeTemplateName) component($componentName) " + + "interface($interfaceName) operation($operationName)") + + // Get the Component Instance + val plugin = applicationContext.getBean(componentName, AbstractComponentFunction::class.java) + // Set the Blueprint Service + plugin.bluePrintRuntimeService = bluePrintRuntimeService + plugin.stepName = nodeTemplateName + + // Populate Step Meta Data + val stepInputs: MutableMap = hashMapOf() + stepInputs.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, nodeTemplateName) + stepInputs.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, interfaceName) + stepInputs.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, operationName) + + plugin.bluePrintRuntimeService.put("$nodeTemplateName-step-inputs", stepInputs.asJsonNode()) + + // Get the Request from the Context and Set to the Function Input and Invoke the function + return withContext(Dispatchers.Default) { + plugin.apply(executionServiceInput) + } + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/executor/ComponentExecuteNodeExecutor.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/executor/ComponentExecuteNodeExecutor.kt index 7a59a0ab2..1e856b689 100644 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/executor/ComponentExecuteNodeExecutor.kt +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/executor/ComponentExecuteNodeExecutor.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications 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. @@ -16,16 +17,10 @@ package org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.executor -import com.fasterxml.jackson.databind.JsonNode -import kotlinx.coroutines.async -import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.runBlocking import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.BlueprintSvcLogicContext -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode -import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement +import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.NodeTemplateExecutionService import org.onap.ccsdk.sli.core.sli.SvcLogicContext import org.onap.ccsdk.sli.core.sli.SvcLogicException import org.onap.ccsdk.sli.core.sli.SvcLogicNode @@ -33,33 +28,17 @@ import org.onap.ccsdk.sli.core.sli.provider.base.ExecuteNodeExecutor import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicExpressionResolver import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicServiceBase import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.context.ApplicationContext import org.springframework.stereotype.Service @Service -open class ComponentExecuteNodeExecutor : ExecuteNodeExecutor() { +open class ComponentExecuteNodeExecutor(private val nodeTemplateExecutionService: NodeTemplateExecutionService) + : ExecuteNodeExecutor() { private val log = LoggerFactory.getLogger(ComponentExecuteNodeExecutor::class.java) - @Autowired - private lateinit var context: ApplicationContext - - fun getComponentFunction(pluginName: String): AbstractComponentFunction { - return context.getBean(pluginName, AbstractComponentFunction::class.java) - } - @Throws(SvcLogicException::class) override fun execute(svc: SvcLogicServiceBase, node: SvcLogicNode, svcLogicContext: SvcLogicContext) : SvcLogicNode = runBlocking { - coroutineScope { - val job = async { executeAsy(svc, node, svcLogicContext) } - job.await() - } - } - - - private fun executeAsy(svc: SvcLogicServiceBase, node: SvcLogicNode, svcLogicContext: SvcLogicContext): SvcLogicNode { var outValue: String @@ -67,35 +46,11 @@ open class ComponentExecuteNodeExecutor : ExecuteNodeExecutor() { val nodeTemplateName = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx) - try { - // Get the Blueprint Context - val blueprintContext = ctx.getBluePrintService().bluePrintContext() - // Get the Component Name, NodeTemplate type is mapped to Component Name - val componentName = blueprintContext.nodeTemplateByName(nodeTemplateName).type + val executionInput = ctx.getRequest() as ExecutionServiceInput - val interfaceName = blueprintContext.nodeTemplateFirstInterfaceName(nodeTemplateName) - - val operationName = blueprintContext.nodeTemplateFirstInterfaceFirstOperationName(nodeTemplateName) - - log.info("executing node template($nodeTemplateName) component($componentName) interface($interfaceName) operation($operationName)") - // Get the Component Instance - val plugin = this.getComponentFunction(componentName) - // Set the Blueprint Service - plugin.bluePrintRuntimeService = ctx.getBluePrintService() - plugin.stepName = nodeTemplateName - - val executionInput = ctx.getRequest() as ExecutionServiceInput - - // Populate Step Meta Data - val stepInputs: MutableMap = hashMapOf() - stepInputs.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, nodeTemplateName) - stepInputs.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, interfaceName) - stepInputs.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, operationName) - - plugin.bluePrintRuntimeService.put("$nodeTemplateName-step-inputs", stepInputs.asJsonNode()) - - // Get the Request from the Context and Set to the Function Input and Invoke the function - val executionOutput = plugin.apply(executionInput) + try { // Get the Request from the Context and Set to the Function Input and Invoke the function + val executionOutput = nodeTemplateExecutionService.executeNodeTemplate(ctx.getBluePrintService(), + nodeTemplateName, executionInput) ctx.setResponse(executionOutput) @@ -103,11 +58,12 @@ open class ComponentExecuteNodeExecutor : ExecuteNodeExecutor() { ctx.status = executionOutput.status.message } catch (e: Exception) { - this.log.error("Could not execute plugin($nodeTemplateName) : ", e) + log.error("Could not execute plugin($nodeTemplateName) : ", e) outValue = "failure" ctx.status = "failure" } - return this.getNextNode(node, outValue) + getNextNode(node, outValue) } + } \ 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/BluePrintWorkflowExecutionServiceImplTest.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImplTest.kt new file mode 100644 index 000000000..7ac9bc33d --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImplTest.kt @@ -0,0 +1,54 @@ +/* + * 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.apps.blueprintsprocessor.services.workflow + +import kotlinx.coroutines.runBlocking +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.core.api.data.ExecutionServiceOutput +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +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]) +class BluePrintWorkflowExecutionServiceImplTest { + + @Autowired + lateinit var bluePrintWorkflowExecutionService: BluePrintWorkflowExecutionService + + @Test + fun testBluePrintWorkflowExecutionService() { + + val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", + "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + + val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json", + ExecutionServiceInput::class.java)!! + + runBlocking { + bluePrintWorkflowExecutionService.executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, + hashMapOf()) + } + } + +} 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 deleted file mode 100644 index 5369bd323..000000000 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintDGExecutionServiceTest.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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/test-blueprint/baseconfiguration") - - val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json", ExecutionServiceInput::class.java)!! - - blueprintDGExecutionService.executeDirectedGraph(bluePrintRuntimeService, executionServiceInput) - - } - - -} \ 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/BlueprintServiceLogicTest.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt index 6184162f5..b374e7d44 100644 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications 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. @@ -16,6 +17,7 @@ package org.onap.ccsdk.apps.blueprintsprocessor.services.workflow +import kotlinx.coroutines.runBlocking import org.junit.Test import org.junit.runner.RunWith import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput @@ -41,7 +43,7 @@ class BlueprintServiceLogicTest { lateinit var applicationContext: ApplicationContext @Autowired - lateinit var blueprintDGExecutionService: BlueprintDGExecutionService + lateinit var dgWorkflowExecutionService: DGWorkflowExecutionService @Test fun testExecuteGraphWithSingleComponent() { @@ -51,8 +53,10 @@ class BlueprintServiceLogicTest { val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json", ExecutionServiceInput::class.java)!! + runBlocking { + dgWorkflowExecutionService.executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, mutableMapOf()) + } - blueprintDGExecutionService.executeDirectedGraph(bluePrintRuntimeService, executionServiceInput) } @@ -64,7 +68,9 @@ class BlueprintServiceLogicTest { val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/assign-activate-input.json", ExecutionServiceInput::class.java)!! - blueprintDGExecutionService.executeDirectedGraph(bluePrintRuntimeService, executionServiceInput) + runBlocking { + dgWorkflowExecutionService.executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, mutableMapOf()) + } } diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/DGWorkflowExecutionServiceTest.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/DGWorkflowExecutionServiceTest.kt new file mode 100644 index 000000000..2e36fb5ff --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/DGWorkflowExecutionServiceTest.kt @@ -0,0 +1,57 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications 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.apps.blueprintsprocessor.services.workflow + +import kotlinx.coroutines.runBlocking +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 DGWorkflowExecutionServiceTest { + + private val log = LoggerFactory.getLogger(BlueprintServiceLogicTest::class.java) + + @Autowired + lateinit var dgWorkflowExecutionService: DGWorkflowExecutionService + + + @Test + fun testExecuteDirectedGraph() { + + val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", + "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + + val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json", ExecutionServiceInput::class.java)!! + + runBlocking { + dgWorkflowExecutionService.executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, mutableMapOf()) + } + + } + + +} \ No newline at end of file -- cgit 1.2.3-korg