From 4db25ff7b585c21f14e1acb306aec752bd362610 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Thu, 23 Aug 2018 08:48:58 -0400 Subject: write update status of BBs progress added in the missing bpmn file change add implementation to update status of BBs progress Change-Id: If913b4e4da2a548e7b5660be947721cb17c60d3f Issue-ID: SO-890 Signed-off-by: Benjamin, Max (mb388a) --- .../subprocess/BuildingBlock/WorkflowActionBB.bpmn | 101 ++++++++++++--------- .../workflow/tasks/WorkflowActionBBTasks.java | 39 ++++++++ .../test/java/org/onap/so/bpmn/BaseTaskTest.java | 4 + .../workflow/tasks/WorkflowActionBBTasksTest.java | 27 ++++++ 4 files changed, 128 insertions(+), 43 deletions(-) diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WorkflowActionBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WorkflowActionBB.bpmn index 6544387775..13dad149cd 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WorkflowActionBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WorkflowActionBB.bpmn @@ -1,5 +1,5 @@ - + SequenceFlow_15s0okp @@ -18,10 +18,10 @@ - SequenceFlow_0mqrkxv + SequenceFlow_0mew9im SequenceFlow_07h9d4y - + SequenceFlow_1atzsgn SequenceFlow_1wb59ic @@ -185,14 +185,19 @@ + + SequenceFlow_0mqrkxv + SequenceFlow_0mew9im + + - + - + @@ -202,24 +207,24 @@ - - + + - + - - + + - + - + @@ -243,10 +248,10 @@ - + - + @@ -288,26 +293,26 @@ - + - + - - + + - + - + - - + + - + @@ -337,12 +342,12 @@ - - - - + + + + - + @@ -356,34 +361,34 @@ - - + + - + - + - + - - - + + + - + - - + + - + @@ -435,11 +440,11 @@ - - + + - + @@ -545,6 +550,16 @@ + + + + + + + + + + diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java index ee6af61d0f..101a355c2f 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java @@ -81,6 +81,45 @@ public class WorkflowActionBBTasks { execution.setVariable(G_CURRENT_SEQUENCE, currentSequence); } } + + public void updateFlowStatistics(DelegateExecution execution) { + int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE); + if(currentSequence > 1) { + InfraActiveRequests request = this.getUpdatedRequest(execution, currentSequence); + requestDbclient.updateInfraActiveRequests(request); + } + } + + protected InfraActiveRequests getUpdatedRequest(DelegateExecution execution, int currentSequence) { + List flowsToExecute = (List) execution + .getVariable("flowsToExecute"); + String requestId = (String) execution.getVariable(G_REQUEST_ID); + InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId); + ExecuteBuildingBlock completedBB = flowsToExecute.get(currentSequence - 2); + ExecuteBuildingBlock nextBB = flowsToExecute.get(currentSequence - 1); + int completedBBs = currentSequence - 1; + int totalBBs = flowsToExecute.size(); + int remainingBBs = totalBBs - completedBBs; + String statusMessage = this.getStatusMessage(completedBB.getBuildingBlock().getBpmnFlowName(), + nextBB.getBuildingBlock().getBpmnFlowName(), completedBBs, remainingBBs); + Long percentProgress = this.getPercentProgress(completedBBs, totalBBs); + request.setStatusMessage(statusMessage); + request.setProgress(percentProgress); + request.setLastModifiedBy("CamundaBPMN"); + return request; + } + + protected Long getPercentProgress(int completedBBs, int totalBBs) { + double ratio = (completedBBs / (totalBBs * 1.0)); + int percentProgress = (int) (ratio * 95); + return new Long(percentProgress + 5); + } + + protected String getStatusMessage(String completedBB, String nextBB, int completedBBs, int remainingBBs) { + return "Execution of " + completedBB + " has completed successfully, next invoking " + nextBB + + " (Execution Path progress: BBs completed = " + completedBBs + "; BBs remaining = " + remainingBBs + + ")."; + } public void sendSyncAck(DelegateExecution execution) { final String requestId = (String) execution.getVariable(G_REQUEST_ID); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java index 501e64f4d4..87852e9922 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java @@ -27,6 +27,7 @@ import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignNetworkBBUtils; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; import org.onap.so.client.adapter.network.mapper.NetworkAdapterObjectMapper; +import org.onap.so.client.db.request.RequestsDbClient; import org.onap.so.client.orchestration.AAICollectionResources; import org.onap.so.client.orchestration.AAIInstanceGroupResources; import org.onap.so.client.orchestration.AAINetworkResources; @@ -108,6 +109,9 @@ public abstract class BaseTaskTest extends TestDataSetup { @MockBean protected CatalogDbClient catalogDbClient; + @MockBean + protected RequestsDbClient requestsDbClient; + @Mock protected BBInputSetupUtils bbSetupUtils; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java index d856b5e184..27173b7502 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java @@ -37,6 +37,7 @@ import org.junit.rules.ExpectedException; import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.db.request.beans.InfraActiveRequests; import org.springframework.beans.factory.annotation.Autowired; public class WorkflowActionBBTasksTest extends BaseTaskTest { @@ -79,6 +80,32 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { assertEquals(true,success); } + @Test + public void getUpdatedRequestTest() throws Exception{ + List flowsToExecute = new ArrayList(); + ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock(); + BuildingBlock bb1 = new BuildingBlock(); + bb1.setBpmnFlowName("CreateNetworkBB"); + flowsToExecute.add(ebb1); + ebb1.setBuildingBlock(bb1); + ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock(); + BuildingBlock bb2 = new BuildingBlock(); + bb2.setBpmnFlowName("ActivateNetworkBB"); + flowsToExecute.add(ebb2); + ebb2.setBuildingBlock(bb2); + String requestId = "requestId"; + execution.setVariable("mso-request-id", requestId); + execution.setVariable("flowsToExecute", flowsToExecute); + int currentSequence = 2; + String expectedStatusMessage = "Execution of CreateNetworkBB has completed successfully, next invoking ActivateNetworkBB (Execution Path progress: BBs completed = 1; BBs remaining = 1)."; + Long expectedLong = new Long(52); + InfraActiveRequests mockedRequest = new InfraActiveRequests(); + when(requestsDbClient.getInfraActiveRequestbyRequestId(requestId)).thenReturn(mockedRequest); + InfraActiveRequests actual = workflowActionBBTasks.getUpdatedRequest(execution, currentSequence); + assertEquals(expectedStatusMessage, actual.getStatusMessage()); + assertEquals(expectedLong, actual.getProgress()); + } + @Test public void select2BBTest() throws Exception{ String gAction = "Delete-Network-Collection"; -- cgit 1.2.3-korg