aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJegadeesh Babu <jegabab1@in.ibm.com>2019-02-27 19:11:51 +0530
committerTakamune Cho <takamune.cho@att.com>2019-02-28 14:40:32 +0000
commit86dd2bc3a4e2316cd20c95f7a85a68ccd2f49894 (patch)
treeea5d4eac3c7c6d48da446a6bbc5b73cfaeee6c51
parentd1a56a7bef30e17462ded7bd9e14449985a32db4 (diff)
Added null check to avoid null pointer exception
Sonar fix Issue-ID: APPC-1505 Change-Id: Iefd8a45aacb6e8de50c16c36fe9ab551401ca417 Signed-off-by: Jegadeesh Babu <jegabab1@in.ibm.com>
-rw-r--r--appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/impl/AnsibleAdapterImpl.java18
1 files changed, 11 insertions, 7 deletions
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(),