From 86dd2bc3a4e2316cd20c95f7a85a68ccd2f49894 Mon Sep 17 00:00:00 2001 From: Jegadeesh Babu Date: Wed, 27 Feb 2019 19:11:51 +0530 Subject: Added null check to avoid null pointer exception Sonar fix Issue-ID: APPC-1505 Change-Id: Iefd8a45aacb6e8de50c16c36fe9ab551401ca417 Signed-off-by: Jegadeesh Babu --- .../appc/adapter/ansible/impl/AnsibleAdapterImpl.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle') diff --git a/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/impl/AnsibleAdapterImpl.java b/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/impl/AnsibleAdapterImpl.java index ace39ee9c..5ac1e8864 100644 --- a/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/impl/AnsibleAdapterImpl.java +++ b/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/impl/AnsibleAdapterImpl.java @@ -316,12 +316,13 @@ public class AnsibleAdapterImpl implements AnsibleAdapter { // post the test request logger.info("Posting ansible request = " + payload + " to url = " + agentUrl); AnsibleResult testResult = postExecRequest(agentUrl, payload, user, password,ctx); + if (testResult != null) { logger.info("Received response on ansible post request " + testResult.getStatusMessage()); // Process if HTTP was successful if (testResult.getStatusCode() == 200) { - testResult = messageProcessor.parsePostResponse(testResult.getStatusMessage()); + testResult = messageProcessor.parsePostResponse(testResult.getStatusMessage()); } else { - doFailure(ctx, testResult.getStatusCode(), + doFailure(ctx, testResult.getStatusCode(), "Error posting request. Reason = " + testResult.getStatusMessage()); } String output = StringUtils.EMPTY; @@ -331,16 +332,19 @@ public class AnsibleAdapterImpl implements AnsibleAdapter { ctx.setAttribute(OUTPUT_ATTRIBUTE_NAME, output); String serverIp = testResult.getServerIp(); if (StringUtils.isBlank(serverIp)) - ctx.setAttribute("ServerIP", serverIp); + ctx.setAttribute("ServerIP", serverIp); else - ctx.setAttribute("ServerIP", ""); + ctx.setAttribute("ServerIP", ""); // Check status of test request returned by Agent if (code == AnsibleResultCodes.PENDING.getValue()) { - logger.info(String.format("Submission of Test %s successful.", playbookName)); - // test request accepted. We are in asynchronous case + logger.info(String.format("Submission of Test %s successful.", playbookName)); + // test request accepted. We are in asynchronous case } else { - doFailure(ctx, code, "Request for execution of playbook rejected. Reason = " + message); + doFailure(ctx, code, "Request for execution of playbook rejected. Reason = " + message); } + } else { + doFailure(ctx, code, "Ansible Test result is null"); + } } catch (APPCException e) { logger.error(APPC_EXCEPTION_CAUGHT, e); doFailure(ctx, AnsibleResultCodes.UNKNOWN_EXCEPTION.getValue(), -- cgit 1.2.3-korg