Fixing scaleOut workflow looping issue 14/72014/1
authorPrema Bhatt <pb6115@att.com>
Tue, 6 Nov 2018 21:10:30 +0000 (13:10 -0800)
committerPrema Bhatt <pb6115@att.com>
Tue, 6 Nov 2018 21:10:30 +0000 (13:10 -0800)
Updated both GenericVnfHealthCheck and ConfigurationScaleOut BB with
appropriate Exception catch block and added Exception unit test.

Issue-ID: SO-1182
Change-Id: Ia29741a4a7d8e1bb759ace4fd888864141d224d6
Signed-off-by: Prema Bhatt <pb6115@att.com>
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigurationScaleOut.java
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheck.java
bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigurationScaleOutTest.java
bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheckTest.java

index 58dd5a1..615b727 100644 (file)
@@ -37,6 +37,7 @@ import org.onap.so.client.appc.ApplicationControllerAction;
 import org.onap.so.client.exception.ExceptionBuilder;
 import org.onap.so.db.catalog.beans.ControllerSelectionReference;
 import org.onap.so.db.catalog.client.CatalogDbClient;
+import org.onap.so.logger.MessageEnum;
 import org.onap.so.logger.MsoLogger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -124,6 +125,9 @@ public class ConfigurationScaleOut {
        }
        
        public void callAppcClient(BuildingBlockExecution execution) {
+               msoLogger.trace("Start runAppcCommand ");
+               String appcCode = "1002";
+               String appcMessage = "";
                try{
                        Action commandAction = Action.valueOf(execution.getVariable(ACTION));
                        String msoRequestId = execution.getVariable(MSO_REQUEST_ID);
@@ -137,10 +141,22 @@ public class ConfigurationScaleOut {
                        HashMap<String, String> payloadInfo = new HashMap<>();
                        payloadInfo.put(VNF_NAME, execution.getVariable(VNF_NAME));
                        payloadInfo.put(VFMODULE_ID,execution.getVariable(VFMODULE_ID));
+                       msoLogger.debug("Running APP-C action: " + commandAction.toString());
+                       msoLogger.debug("VNFID: " + vnfId);     
                        //PayloadInfo contains extra information that adds on to payload before making request to appc
                        appCClient.runAppCCommand(commandAction, msoRequestId, vnfId, payloadString, payloadInfo, controllerType);
-               }catch(Exception ex){
-                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
+                       appcCode = appCClient.getErrorCode();
+                       appcMessage = appCClient.getErrorMessage();
+               
+               } catch (Exception e) {
+                       msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "Caught exception in runAppcCommand in ConfigurationScaleOut", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "APPC Error", e);
+                       appcMessage = e.getMessage();
+               }
+               msoLogger.error("Error Message: " + appcMessage);
+               msoLogger.error("ERROR CODE: " + appcCode);
+               msoLogger.trace("End of runAppCommand ");
+               if (appcCode != null && !appcCode.equals("0")) {
+                       exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage);
                }
        }
 }
index 61162f4..2dae820 100644 (file)
@@ -32,6 +32,7 @@ import org.onap.so.client.appc.ApplicationControllerAction;
 import org.onap.so.client.exception.ExceptionBuilder;
 import org.onap.so.db.catalog.client.CatalogDbClient;
 import org.onap.so.db.catalog.beans.ControllerSelectionReference;
+import org.onap.so.logger.MessageEnum;
 import org.onap.so.logger.MsoLogger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -78,7 +79,9 @@ public class GenericVnfHealthCheck {
        }
        
        public void callAppcClient(BuildingBlockExecution execution) {
-               
+               msoLogger.trace("Start runAppcCommand ");
+               String appcCode = "1002";
+               String appcMessage = "";
                try {
                        Action action = null;
                        action = Action.valueOf(execution.getVariable("action"));
@@ -95,11 +98,23 @@ public class GenericVnfHealthCheck {
                        payloadInfo.put("vfModuleId",execution.getVariable("vfModuleId"));
                        payloadInfo.put("oamIpAddress",execution.getVariable("oamIpAddress"));
                        payloadInfo.put("vnfHostIpAddress",execution.getVariable("vnfHostIpAddress"));
+                       
+                       msoLogger.debug("Running APP-C action: " + action.toString());
+                       msoLogger.debug("VNFID: " + vnfId);     
                        //PayloadInfo contains extra information that adds on to payload before making request to appc
                        appCClient.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType);
+                       appcCode = appCClient.getErrorCode();
+                       appcMessage = appCClient.getErrorMessage();
                
-                       } catch (Exception ex) {
-                               exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
-                       }
+               } catch (Exception e) {
+                       msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "Caught exception in runAppcCommand in GenericVnfHealthCheck", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "APPC Error", e);
+                       appcMessage = e.getMessage();
+               }
+               msoLogger.error("Error Message: " + appcMessage);
+               msoLogger.error("ERROR CODE: " + appcCode);
+               msoLogger.trace("End of runAppCommand ");
+               if (appcCode != null && !appcCode.equals("0")) {
+                       exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage);
+               }
        }
 }
index 8577de2..85915bd 100644 (file)
@@ -22,6 +22,7 @@ package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
 import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
@@ -34,6 +35,7 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.UUID;
 
+import org.camunda.bpm.engine.delegate.BpmnError;
 import org.junit.Before;
 import org.junit.Test;
 import org.onap.appc.client.lcm.model.Action;
@@ -146,4 +148,29 @@ public class ConfigurationScaleOutTest extends BaseTaskTest {
                assertEquals(expectedPayload, execution.getVariable("payload"));
        }
 
+       @Test
+       public void callAppcClientExceptionTest() throws Exception {
+               expectedException.expect(BpmnError.class);
+               Action action = Action.ConfigScaleOut;
+               String vnfId = genericVnf.getVnfId();
+               String controllerType = "testType";
+               String payload = "{\"request-parameters\":{\"vnf-host-ip-address\":\"10.222.22.2\","
+                               + "\"vf-module-id\":\"testVfModuleId1\"},\"configuration-parameters\""
+                               + ":{\"vnf-id\":\"66dac89b-2a5b-4cb9-b22e-a7e4488fb3db\",\"availability-zone\":\"AZ-MN02\"}}";
+               HashMap<String, String> payloadInfo = new HashMap<String, String>();
+               payloadInfo.put("vnfName", "testVnfName");
+               payloadInfo.put("vfModuleId", "testVfModuleId");
+       
+               execution.setVariable("action", Action.ConfigScaleOut.toString());
+               execution.setVariable("msoRequestId", msoRequestId);
+               execution.setVariable("controllerType", controllerType);
+               execution.setVariable("vnfId", "testVnfId1");
+               execution.setVariable("vnfName", "testVnfName");
+               execution.setVariable("vfModuleId", "testVfModuleId");
+               execution.setVariable("payload", payload);
+               
+               doThrow(Exception.class).when(appCClient).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
+               configurationScaleOut.callAppcClient(execution);
+               verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
+       }
 }
index 9f0bb91..e5e092a 100644 (file)
@@ -22,6 +22,7 @@ package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
 import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
@@ -29,6 +30,7 @@ import java.util.HashMap;
 import java.util.Optional;
 import java.util.UUID;
 
+import org.camunda.bpm.engine.delegate.BpmnError;
 import org.junit.Before;
 import org.junit.Test;
 import org.onap.appc.client.lcm.model.Action;
@@ -97,6 +99,35 @@ public class GenericVnfHealthCheckTest extends BaseTaskTest {
                
                doNothing().when(appCClient).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
                
+               genericVnfHealthCheck.callAppcClient(execution);
+               verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
+       }
+       
+       @Test
+       public void callAppcClientExceptionTest() throws Exception {
+               expectedException.expect(BpmnError.class);
+               Action action = Action.HealthCheck;
+               String vnfId = genericVnf.getVnfId();
+               String payload = "{\"testName\":\"testValue\",}";
+               String controllerType = "testType";
+               HashMap<String, String> payloadInfo = new HashMap<String, String>();
+               payloadInfo.put("vnfName", "testVnfName");
+               payloadInfo.put("vfModuleId", "testVfModuleId");
+               payloadInfo.put("oamIpAddress", "testOamIpAddress");
+               payloadInfo.put("vnfHostIpAddress", "testOamIpAddress");
+               execution.setVariable("action", Action.HealthCheck.toString());
+               execution.setVariable("msoRequestId", msoRequestId);
+               execution.setVariable("controllerType", controllerType);
+               execution.setVariable("vnfId", "testVnfId1");
+               execution.setVariable("vnfName", "testVnfName");
+               execution.setVariable("vfModuleId", "testVfModuleId");
+               execution.setVariable("oamIpAddress", "testOamIpAddress");
+               execution.setVariable("vnfHostIpAddress", "testOamIpAddress");
+               execution.setVariable("payload", payload);
+               
+               doThrow(Exception.class).when(appCClient).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
+               
+               
                genericVnfHealthCheck.callAppcClient(execution);
                verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
        }