private static final String RESULTS_ATTRIBUTE_NAME = "org.onap.appc.adapter.ansible.results";
private static final String ID_ATTRIBUTE_NAME = "org.onap.appc.adapter.ansible.Id";
private static final String LOG_ATTRIBUTE_NAME = "org.onap.appc.adapter.ansible.log";
+ private static final String OUTPUT_ATTRIBUTE_NAME = "org.onap.appc.adapter.ansible.output";
private static final String CLIENT_TYPE_PROPERTY_NAME = "org.onap.appc.adapter.ansible.clientType";
private static final String TRUSTSTORE_PROPERTY_NAME = "org.onap.appc.adapter.ansible.trustStore";
}
}
+ /**
+ * Public method to get output from playbook execution for a specific request
+ *
+ * It blocks till the Ansible Server responds or the session times out very similar to
+ * reqExecResult and output is returned in the DG context variable org.onap.appc.adapter.ansible.output
+ */
+ @Override
+ public void reqExecOutput(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
+
+ String reqUri = StringUtils.EMPTY;
+ try {
+ reqUri = messageProcessor.reqUriOutput(params);
+ logger.info("Retrieving results from " + reqUri);
+ } catch (Exception e) {
+ logger.error("Exception caught", e);
+ doFailure(ctx, AnsibleResultCodes.INVALID_PAYLOAD.getValue(), e.getMessage());
+ }
+
+ String message = StringUtils.EMPTY;
+ try {
+ // Try to retrieve the test results (modify the url for that)
+ AnsibleResult testResult = queryServer(reqUri, params.get("User"), params.get(PASSD));
+ message = testResult.getStatusMessage();
+ logger.info("Request output = " + message);
+ ctx.setAttribute(OUTPUT_ATTRIBUTE_NAME, message);
+ ctx.setStatus(OUTCOME_SUCCESS);
+ } catch (Exception e) {
+ logger.error("Exception caught", e);
+ doFailure(ctx, AnsibleResultCodes.UNKNOWN_EXCEPTION.getValue(),
+ "Exception encountered retreiving output : " + e.getMessage());
+ }
+ }
+
/**
* Method that posts the request
*/
return params.get(AGENT_URL_KEY) + "?Id=" + params.get(ID_KEY) + "&Type=GetLog";
}
+ /**
+ * Method that validates that the Map has enough information
+ * to query Ansible server for an output. If so, it returns
+ * the appropriate url, else an empty string.
+ */
+ public String reqUriOutput(Map<String, String> params) throws SvcLogicException {
+
+ final String[] mandatoryTestParams = {AGENT_URL_KEY, ID_KEY, USER_KEY, PASS_KEY};
+
+ for (String mandatoryParam : mandatoryTestParams) {
+ throwIfMissingMandatoryParam(params, mandatoryParam);
+ }
+ return params.get(AGENT_URL_KEY) + "?Id=" + params.get(ID_KEY) + "&Type=GetOutput";
+ }
+
/**
* This method parses response from the Ansible Server when we do a post
* and returns an AnsibleResult object.
fail(e.getMessage() + " Unknown exception encountered ");
}
}
+
+ @Test
+ public void reqExecOutput_shouldSetMessage() throws IllegalStateException, IllegalArgumentException {
+
+ params.put("Id", "101");
+
+ try {
+ adapter.reqExecOutput(params, svcContext);
+ String status = svcContext.getAttribute("org.onap.appc.adapter.ansible.output");
+ assertEquals(message, status);
+ } catch (SvcLogicException e) {
+ String status = svcContext.getAttribute("org.onap.appc.adapter.ansible.output");
+ fail(e.getMessage() + " Code = " + status);
+ } catch (Exception e) {
+ fail(e.getMessage() + " Unknown exception encountered ");
+ }
+ }
}