aboutsummaryrefslogtreecommitdiffstats
path: root/appc-adapters/appc-ansible-adapter
diff options
context:
space:
mode:
authorJegadeesh Babu <jegabab1@in.ibm.com>2019-03-25 22:12:52 +0530
committerPatrick Brady <patrick.brady@att.com>2019-03-27 21:19:38 +0000
commit4c8bd08a8b33ccf08c811434f65ce538a3946fb5 (patch)
treefe266172f8f75a075c2b880581291aa497225ee1 /appc-adapters/appc-ansible-adapter
parent82a563486818bf28e8a40fbda1fed7069d9e0d70 (diff)
Used constants to replace duplicated literals
Sonar Fix Issue-ID: APPC-1555 Change-Id: I3943003c7fa37aed95e138f03a3fe4b8f48b75ce Signed-off-by: Jegadeesh Babu <jegabab1@in.ibm.com>
Diffstat (limited to 'appc-adapters/appc-ansible-adapter')
-rw-r--r--appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/model/AnsibleMessageParser.java18
1 files changed, 11 insertions, 7 deletions
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 77738d7dd..0b4a6bdfe 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
@@ -6,6 +6,8 @@
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
+ * Modifications Copyright (C) 2019 IBM
+ * =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -63,6 +65,8 @@ public class AnsibleMessageParser {
private static final String TIMEOUT_OPT_KEY = "Timeout";
private static final String VERSION_OPT_KEY = "Version";
private static final String ACTION_OPT_KEY = "Action";
+ private static final String OUTPUT_OPT_KEY = "Output";
+ private static final String JSON_ERROR_MESSAGE = "JSONException: Error parsing response";
private static final Logger LOGGER = LoggerFactory.getLogger(AnsibleMessageParser.class);
@@ -171,14 +175,14 @@ public class AnsibleMessageParser {
if (StringUtils.isNotBlank(serverIP))
ansibleResult.setServerIp(serverIP);
- if (!postResponse.isNull("Output")) {
+ if (!postResponse.isNull(OUTPUT_OPT_KEY)) {
LOGGER.info("Processing results-output in post response");
- JSONObject output = postResponse.getJSONObject("Output");
+ JSONObject output = postResponse.getJSONObject(OUTPUT_OPT_KEY);
ansibleResult.setOutput(output.toString());
}
} catch (JSONException e) {
- LOGGER.error("JSONException: Error parsing response", e);
+ LOGGER.error(JSON_ERROR_MESSAGE, e);
ansibleResult = new AnsibleResult(600, "Error parsing response = " + input + ". Error = " + e.getMessage());
}
return ansibleResult;
@@ -196,7 +200,7 @@ public class AnsibleMessageParser {
JSONObject postResponse = new JSONObject(input);
ansibleResult = parseGetResponseNested(ansibleResult, postResponse);
} catch (JSONException e) {
- LOGGER.error("JSONException: Error parsing response", e);
+ LOGGER.error(JSON_ERROR_MESSAGE, e);
ansibleResult = new AnsibleResult(AnsibleResultCodes.INVALID_PAYLOAD.getValue(),
"Error parsing response = " + input + ". Error = " + e.getMessage(), "");
}
@@ -247,7 +251,7 @@ public class AnsibleMessageParser {
finalCode = AnsibleResultCodes.REQ_FAILURE.getValue();
}
} catch (JSONException e) {
- LOGGER.error("JSONException: Error parsing response", e);
+ LOGGER.error(JSON_ERROR_MESSAGE, e);
ansibleResult.setStatusCode(AnsibleResultCodes.INVALID_RESPONSE.getValue());
ansibleResult.setStatusMessage(String.format("Error processing response message = %s from host %s",
results.getString(host), host));
@@ -264,9 +268,9 @@ public class AnsibleMessageParser {
ansibleResult.setStatusCode(AnsibleResultCodes.INVALID_RESPONSE.getValue());
ansibleResult.setStatusMessage("Results not found in GET for response");
}
- if (!postRsp.isNull("Output")) {
+ if (!postRsp.isNull(OUTPUT_OPT_KEY)) {
LOGGER.info("Processing results-output in response");
- JSONObject output = postRsp.getJSONObject("Output");
+ JSONObject output = postRsp.getJSONObject(OUTPUT_OPT_KEY);
ansibleResult.setOutput(output.toString());
}