Enhanced Exception handling. 17/73217/1
authorPrema Bhatt <pb6115@att.com>
Wed, 21 Nov 2018 06:38:33 +0000 (22:38 -0800)
committerPrema Bhatt <pb6115@att.com>
Wed, 21 Nov 2018 06:38:33 +0000 (22:38 -0800)
Issue-ID: SO-1182
Change-Id: Iae4a0072b637ddd0e64c4ec54421509e1c03ccc5
Signed-off-by: Prema Bhatt <pb6115@att.com>
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/GenericVnfHealthCheckTest.java

index 2dae820..4f2e2c9 100644 (file)
@@ -21,7 +21,10 @@ package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
 
 import java.util.HashMap;
 import java.util.Optional;
-
+import java.net.HttpURLConnection;
+import java.net.SocketTimeoutException;
+import org.apache.http.conn.ConnectTimeoutException;
+import org.camunda.bpm.engine.delegate.BpmnError;
 import org.onap.appc.client.lcm.model.Action;
 import org.onap.so.bpmn.common.BuildingBlockExecution;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
@@ -105,10 +108,22 @@ public class GenericVnfHealthCheck {
                        appCClient.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType);
                        appcCode = appCClient.getErrorCode();
                        appcMessage = appCClient.getErrorMessage();
-               
+        } catch (BpmnError ex) {
+                       msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Caught exception in GenericVnfHealthCheck", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + ex);
+            appcMessage = ex.getMessage();
+            exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage);
                } 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();
+                       if (e instanceof java.util.concurrent.TimeoutException )
+                       {
+                               appcMessage = "Request to APPC timed out. ";
+                               msoLogger.error(MessageEnum.RA_CONNECTION_EXCEPTION, "Caught timedOut exception in runAppcCommand in GenericVnfHealthCheck", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "APPC Error", e);
+                               throw e;
+                       }
+                       else {
+                               msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "Caught exception in runAppcCommand in GenericVnfHealthCheck", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "APPC Error", e);
+                               appcMessage = e.getMessage();
+                               exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage);
+                       }
                }
                msoLogger.error("Error Message: " + appcMessage);
                msoLogger.error("ERROR CODE: " + appcCode);
index e5e092a..3ef7ef4 100644 (file)
@@ -128,6 +128,35 @@ public class GenericVnfHealthCheckTest extends BaseTaskTest {
                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);
+       }
+       
+       @Test
+       public void callAppcClientTimeOutExceptionTest() throws java.util.concurrent.TimeoutException {
+               expectedException.expect(java.util.concurrent.TimeoutException.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(java.util.concurrent.TimeoutException.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);
        }