Merge "workflow action should read config for max retries"
authorSteve Smokowski <ss835w@att.com>
Thu, 14 Feb 2019 16:32:24 +0000 (16:32 +0000)
committerGerrit Code Review <gerrit@onap.org>
Thu, 14 Feb 2019 16:32:24 +0000 (16:32 +0000)
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java
bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java

index 78a84b1..f6c9597 100644 (file)
@@ -41,6 +41,7 @@ import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
 import org.springframework.stereotype.Component;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
@@ -54,6 +55,7 @@ public class WorkflowActionBBTasks {
        private static final String G_ALACARTE = "aLaCarte";
        private static final String G_ACTION = "requestAction";
        private static final String RETRY_COUNT = "retryCount";
+       protected String maxRetries = "mso.rainyDay.maxRetries";
        private static final Logger logger = LoggerFactory.getLogger(WorkflowActionBBTasks.class);
 
        @Autowired
@@ -62,6 +64,8 @@ public class WorkflowActionBBTasks {
        private WorkflowAction workflowAction;
        @Autowired
        private WorkflowActionBBFailure workflowActionBBFailure;
+       @Autowired
+       private Environment environment;
        
        public void selectBB(DelegateExecution execution) {
                List<ExecuteBuildingBlock> flowsToExecute = (List<ExecuteBuildingBlock>) execution
@@ -215,17 +219,24 @@ public class WorkflowActionBBTasks {
                String requestId = (String) execution.getVariable(G_REQUEST_ID);
                String retryDuration = (String) execution.getVariable("RetryDuration");
                int retryCount = (int) execution.getVariable(RETRY_COUNT);
+               int envMaxRetries;
+               try{
+                       envMaxRetries = Integer.parseInt(this.environment.getProperty(maxRetries));     
+               } catch (Exception ex) {
+                       logger.error("Could not read maxRetries from config file. Setting max to 5 retries");
+                       envMaxRetries = 5;
+               }
                int nextCount = retryCount +1;
                if (handlingCode.equals("Retry")){
                        workflowActionBBFailure.updateRequestErrorStatusMessage(execution);
                        try{
                                InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
-                               request.setRetryStatusMessage("Retry " + nextCount + "/5 will be started in " + retryDuration);
+                               request.setRetryStatusMessage("Retry " + nextCount + "/" + envMaxRetries + " will be started in " + retryDuration);
                                requestDbclient.updateInfraActiveRequests(request); 
                        } catch(Exception ex){
                                logger.warn("Failed to update Request Db Infra Active Requests with Retry Status",ex);
                        }
-                       if(retryCount<5){
+                       if(retryCount<envMaxRetries){
                                int currSequence = (int) execution.getVariable("gCurrentSequence");
                                execution.setVariable("gCurrentSequence", currSequence-1);
                                execution.setVariable(RETRY_COUNT, nextCount);
index f3b094f..2fc6297 100644 (file)
@@ -31,6 +31,7 @@ import static org.mockito.Mockito.when;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.camunda.bpm.engine.delegate.BpmnError;
 import org.camunda.bpm.engine.delegate.DelegateExecution;
 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
 import org.junit.Before;
@@ -46,6 +47,7 @@ import org.onap.so.bpmn.core.WorkflowException;
 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.core.env.Environment;
 
 public class WorkflowActionBBTasksTest extends BaseTaskTest {
 
@@ -64,6 +66,9 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest {
        
        private DelegateExecution execution;
        
+       @Mock
+       protected Environment environment;
+       
        @Rule
        public ExpectedException thrown = ExpectedException.none();
        
@@ -287,6 +292,7 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest {
                String reqId = "reqId123";
                execution.setVariable("mso-request-id", reqId);
                doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
+               doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
                execution.setVariable("handlingCode","Retry");
                execution.setVariable("retryCount", 1);
                execution.setVariable("gCurrentSequence",1);
@@ -296,6 +302,25 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest {
                assertEquals(0,execution.getVariable("gCurrentSequence"));
        }
        
+       @Test
+       public void checkRetryStatusTestExceededMaxRetries(){
+               String reqId = "reqId123";
+               execution.setVariable("mso-request-id", reqId);
+               doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
+               doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
+               execution.setVariable("handlingCode","Retry");
+               execution.setVariable("retryCount", 6);
+               execution.setVariable("gCurrentSequence",1);
+               InfraActiveRequests req = new InfraActiveRequests();
+               doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
+               try{
+                       workflowActionBBTasks.checkRetryStatus(execution);
+               } catch (BpmnError e) {
+                       WorkflowException exception = (WorkflowException) execution.getVariable("WorkflowException");
+                       assertEquals("Exceeded maximum retries. Ending flow with status Abort",exception.getErrorMessage());
+               }
+       }
+       
        @Test
        public void checkRetryStatusNoRetryTest(){
                String reqId = "reqId123";