From 42a4e522ae497f6404d71748c753509fbd892d8d Mon Sep 17 00:00:00 2001 From: Prema Bhatt Date: Tue, 20 Nov 2018 22:38:33 -0800 Subject: Enhanced Exception handling. Issue-ID: SO-1182 Change-Id: Iae4a0072b637ddd0e64c4ec54421509e1c03ccc5 Signed-off-by: Prema Bhatt --- .../flowspecific/tasks/GenericVnfHealthCheck.java | 23 ++++++++++++++--- .../tasks/GenericVnfHealthCheckTest.java | 29 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) (limited to 'bpmn') diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheck.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheck.java index 2dae820e95..4f2e2c98d2 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheck.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheck.java @@ -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); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheckTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheckTest.java index e5e092aace..3ef7ef4dc5 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheckTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheckTest.java @@ -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 payloadInfo = new HashMap(); + 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); } -- cgit 1.2.3-korg