summaryrefslogtreecommitdiffstats
path: root/ansible-adapter
diff options
context:
space:
mode:
authorEnbo Wang <wangenbo@huawei.com>2019-04-14 23:51:33 +0800
committerEnbo Wang <wangenbo@huawei.com>2019-04-15 21:47:54 +0800
commitc06bd49c6a58ef995943f8b4236f84e1cec1f79c (patch)
treed883d0bd73425ef58b7c726260fd58b9d35e4734 /ansible-adapter
parent4d8ef14921d25cd924fc7dcf388a943d313e54b7 (diff)
Add missing GetOutput method in ansible-adapter
Add missing GetOutput method in ansible-adapter for ansible-server. Change-Id: Ifc544176b86fc033f2760a6b02d18f6e29bfd88a Issue-ID: CCSDK-1225 Signed-off-by: Enbo Wang <wangenbo@huawei.com>
Diffstat (limited to 'ansible-adapter')
-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 a2d537e50..e43d3e3c3 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 79103dbbd..2361feebd 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 427149ccb..5f6342d94 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 86bed7e41..4636d2450 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 ");
+ }
+ }
}