aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdapter.java3
-rw-r--r--ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/AnsibleAdapterImpl.java34
-rw-r--r--ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleMessageParser.java15
-rw-r--r--ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/impl/TestAnsibleAdapterImpl.java17
4 files changed, 69 insertions, 0 deletions
diff --git a/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdapter.java b/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdapter.java
index a2d537e5..e43d3e3c 100644
--- a/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdapter.java
+++ b/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/AnsibleAdapter.java
@@ -49,4 +49,7 @@ public interface AnsibleAdapter extends SvcLogicJavaPlugin {
/* Method to get log of a playbook execution request */
void reqExecLog(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException;
+
+ /* Method to get output of a playbook execution request */
+ void reqExecOutput(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException;
}
diff --git a/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/AnsibleAdapterImpl.java b/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/AnsibleAdapterImpl.java
index 79103dbb..2361feeb 100644
--- a/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/AnsibleAdapterImpl.java
+++ b/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/AnsibleAdapterImpl.java
@@ -76,6 +76,7 @@ public class AnsibleAdapterImpl implements AnsibleAdapter {
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";
@@ -391,6 +392,39 @@ public class AnsibleAdapterImpl implements AnsibleAdapter {
}
/**
+ * 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
*/
private AnsibleResult postExecRequest(String agentUrl, String payload, String user, String password) {
diff --git a/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleMessageParser.java b/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleMessageParser.java
index 427149cc..5f6342d9 100644
--- a/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleMessageParser.java
+++ b/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/model/AnsibleMessageParser.java
@@ -133,6 +133,21 @@ public class AnsibleMessageParser {
}
/**
+ * 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.
*/
diff --git a/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/impl/TestAnsibleAdapterImpl.java b/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/impl/TestAnsibleAdapterImpl.java
index 86bed7e4..4636d245 100644
--- a/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/impl/TestAnsibleAdapterImpl.java
+++ b/ansible-adapter/ansible-adapter-bundle/src/test/java/org/onap/ccsdk/adapter/ansible/impl/TestAnsibleAdapterImpl.java
@@ -127,4 +127,21 @@ public class TestAnsibleAdapterImpl {
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 ");
+ }
+ }
}