summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorModaboina, Kusumakumari (km583p) <km583p@us.att.com>2018-06-19 13:43:56 -0400
committerTakamune Cho <tc012c@att.com>2018-06-19 18:24:20 +0000
commitf3fe0cea8af6f8854452a3d92b09618403a30ed6 (patch)
tree190d6054826e00668e1c5c3607c9eba3d378e422
parent07ecb52a74c75c85e69d65cf19328f7ac58f8d9a (diff)
Enhance Ansible by parsing of response messages
Issue-ID: APPC-1015 Change-Id: I19d81c1a266625c81b772fbee9996054bb5a2cbf Signed-off-by: Modaboina, Kusumakumari (km583p) <km583p@us.att.com>
-rw-r--r--appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/impl/AnsibleAdapterImpl.java14
-rw-r--r--appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/model/AnsibleMessageParser.java6
-rw-r--r--appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/model/AnsibleResult.java20
3 files changed, 35 insertions, 5 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 4ac9a7e90..36d486375 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
@@ -40,6 +40,7 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
+import org.onap.appc.encryption.EncryptionTool;
/**
* This class implements the {@link AnsibleAdapter} interface. This interface defines the behaviors
@@ -75,6 +76,7 @@ public class AnsibleAdapterImpl implements AnsibleAdapter {
private static final String RESULT_CODE_ATTRIBUTE_NAME = "org.onap.appc.adapter.ansible.result.code";
private static final String MESSAGE_ATTRIBUTE_NAME = "org.onap.appc.adapter.ansible.message";
private static final String RESULTS_ATTRIBUTE_NAME = "org.onap.appc.adapter.ansible.results";
+ private static final String OUTPUT_ATTRIBUTE_NAME = "org.onap.appc.adapter.ansible.output";
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";
@@ -224,7 +226,7 @@ public class AnsibleAdapterImpl implements AnsibleAdapter {
agentUrl = (String) jsonPayload.remove("AgentUrl");
user = (String) jsonPayload.remove("User");
- password = (String) jsonPayload.remove(PASSWORD);
+ password = EncryptionTool.getInstance().decrypt((String) jsonPayload.remove(PASSWORD));
id = jsonPayload.getString("Id");
payload = jsonPayload.toString();
logger.info("Updated Payload = " + payload);
@@ -315,20 +317,23 @@ public class AnsibleAdapterImpl implements AnsibleAdapter {
int code = -1;
String message = StringUtils.EMPTY;
String results = StringUtils.EMPTY;
+ String output = StringUtils.EMPTY;
try {
// Try to retrieve the test results (modify the URL for that)
- AnsibleResult testResult = queryServer(reqUri, params.get("User"), params.get(PASSWORD));
+ AnsibleResult testResult = queryServer(reqUri, params.get("User"), EncryptionTool.getInstance().decrypt(params.get(PASSWORD)));
code = testResult.getStatusCode();
message = testResult.getStatusMessage();
- if (code == 200) {
+ if (code == 200 || code == 400) {
logger.info("Parsing response from Server = " + message);
// Valid HTTP. process the Ansible message
testResult = messageProcessor.parseGetResponse(message);
code = testResult.getStatusCode();
message = testResult.getStatusMessage();
results = testResult.getResults();
+ output = testResult.getOutput();
+
}
logger.info("Request response = " + message);
@@ -355,6 +360,7 @@ public class AnsibleAdapterImpl implements AnsibleAdapter {
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.setStatus(OUTCOME_SUCCESS);
}
@@ -379,7 +385,7 @@ public class AnsibleAdapterImpl implements AnsibleAdapter {
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(PASSWORD));
+ AnsibleResult testResult = queryServer(reqUri, params.get("User"), EncryptionTool.getInstance().decrypt(params.get(PASSWORD)));
message = testResult.getStatusMessage();
logger.info("Request output = " + message);
ctx.setAttribute(LOG_ATTRIBUTE_NAME, message);
diff --git a/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/model/AnsibleMessageParser.java b/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/model/AnsibleMessageParser.java
index 4fc3fcf23..6aee75631 100644
--- a/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/model/AnsibleMessageParser.java
+++ b/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/model/AnsibleMessageParser.java
@@ -233,6 +233,12 @@ public class AnsibleMessageParser {
ansibleResult.setStatusCode(AnsibleResultCodes.INVALID_RESPONSE.getValue());
ansibleResult.setStatusMessage("Results not found in GET for response");
}
+ if(!postRsp.isNull("Output")) {
+ LOGGER.info("Processing results-output in response");
+ JSONObject output = postRsp.getJSONObject("Output");
+ ansibleResult.setOutput(output.toString());
+ }
+
return ansibleResult;
}
diff --git a/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/model/AnsibleResult.java b/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/model/AnsibleResult.java
index 3f09851ca..eef46826c 100644
--- a/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/model/AnsibleResult.java
+++ b/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/model/AnsibleResult.java
@@ -33,6 +33,15 @@ public class AnsibleResult {
private int statusCode;
private String statusMessage;
private String results;
+ private String output;
+
+ public String getOutput() {
+ return output;
+ }
+
+ public void setOutput(String output) {
+ this.output = output;
+ }
public AnsibleResult() {
this(-1, EMPTY_VALUE, EMPTY_VALUE);
@@ -48,6 +57,13 @@ public class AnsibleResult {
results = result;
}
+ public AnsibleResult(int code, String message, String result, String outputData) {
+ statusCode = code;
+ statusMessage = message;
+ results = result;
+ output = outputData;
+ }
+
public void setStatusCode(int code) {
this.statusCode = code;
}
@@ -60,10 +76,12 @@ public class AnsibleResult {
this.results = results;
}
- void set(int code, String message, String results) {
+ void set(int code, String message, String results, String output) {
this.statusCode = code;
this.statusMessage = message;
this.results = results;
+ this.output = output;
+
}
public int getStatusCode() {