X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=appc-adapters%2Fappc-ansible-adapter%2Fappc-ansible-adapter-bundle%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fappc%2Fadapter%2Fansible%2Fimpl%2FAnsibleAdapterImpl.java;h=4c59b4e181df233c4b79e463310a11f31ee9a033;hb=70d72d23f7ec9d221c8f44d9e66c177d71f79551;hp=576a576c445050ea5db969f7dbcf13fc695ded3e;hpb=933a4b3ba8190fad9cf3a97d3a72b8ac00eaa69e;p=appc.git 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 576a576c4..4c59b4e18 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 @@ -520,6 +520,8 @@ public class AnsibleAdapterImpl implements AnsibleAdapter { String message = StringUtils.EMPTY; String results = StringUtils.EMPTY; String output = StringUtils.EMPTY; + String configData = StringUtils.EMPTY; + String finalResponse = StringUtils.EMPTY; try { // Try to retrieve the test results (modify the URL for that) AnsibleResult testResult = queryServer(reqUri, params.get("User"), @@ -535,10 +537,19 @@ public class AnsibleAdapterImpl implements AnsibleAdapter { message = testResult.getStatusMessage(); results = testResult.getResults(); output = testResult.getOutput(); - ctx.setAttribute(OUTPUT_ATTRIBUTE_NAME, output); + configData = testResult.getconfigData(); + if ((StringUtils.isBlank(output) ) ||(output.trim().equalsIgnoreCase("{}"))) { + finalResponse = results; + } else { + finalResponse = output; + } + logger.info("configData from ansible's response = " + configData); + ctx.setAttribute("device-running-config", configData); } logger.info("Request response = " + message); } catch (APPCException e) { + ctx.setAttribute(RESULTS_ATTRIBUTE_NAME, results); + ctx.setAttribute(OUTPUT_ATTRIBUTE_NAME, finalResponse); doFailure(ctx, AnsibleResultCodes.UNKNOWN_EXCEPTION.getValue(), "Exception encountered retrieving result : " + e.getMessage()); return; @@ -554,16 +565,16 @@ public class AnsibleAdapterImpl implements AnsibleAdapter { logger.info(String.format("Ansible Request %s finished with Result %s, Message = %s", params.get("Id"), OUTCOME_FAILURE, message)); ctx.setAttribute(RESULTS_ATTRIBUTE_NAME, results); - ctx.setAttribute(OUTPUT_ATTRIBUTE_NAME, output); + ctx.setAttribute(OUTPUT_ATTRIBUTE_NAME, finalResponse); doFailure(ctx, code, message); return; } // In case of 200,400,FINISHED return 400 - ctx.setAttribute(RESULT_CODE_ATTRIBUTE_NAME, "400"); + ctx.setAttribute(RESULT_CODE_ATTRIBUTE_NAME, Integer.toString(400)); ctx.setAttribute(MESSAGE_ATTRIBUTE_NAME, message); ctx.setAttribute(RESULTS_ATTRIBUTE_NAME, results); - ctx.setAttribute(OUTPUT_ATTRIBUTE_NAME, output); + ctx.setAttribute(OUTPUT_ATTRIBUTE_NAME, finalResponse); ctx.setStatus(OUTCOME_SUCCESS); }