summaryrefslogtreecommitdiffstats
path: root/controlloop/common/model-impl/so
diff options
context:
space:
mode:
authorHockla, Ali (ah999m) <ah999m@att.com>2017-11-02 12:14:29 -0500
committerHockla, Ali (ah999m) <ah999m@att.com>2017-11-02 15:22:52 -0500
commitb6ecb09c2f98736d11c2684239063a3d43214631 (patch)
tree2f4f009140bd35b2ab6f5f54f637858fda434b86 /controlloop/common/model-impl/so
parent32d406d841dc8c6674a7392e5e925cc0a4a9028b (diff)
Added fix to catch null pointer in SOManager
Issue-ID: POLICY-408 Change-Id: I9f6681b8cbafdd9639966d862e7b1df3b729297e Signed-off-by: Hockla, Ali (ah999m) <ah999m@att.com>
Diffstat (limited to 'controlloop/common/model-impl/so')
-rw-r--r--controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java84
1 files changed, 45 insertions, 39 deletions
diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java
index fb2cc3d60..1caa045e4 100644
--- a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java
+++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java
@@ -141,45 +141,51 @@ public final class SOManager {
@Override
public void run()
{
-
- /*
- * TODO: What if these are null?
- */
- String serverRoot = PolicyEngine.manager.getEnvironmentProperty("so.url");
- String username = PolicyEngine.manager.getEnvironmentProperty("so.username");
- String password = PolicyEngine.manager.getEnvironmentProperty("so.password");
-
- String url = serverRoot + "/serviceInstances/v5/" + serviceInstanceId + "/vnfs/" + vnfInstanceId + "/vfModulesHTTPS/1.1";
-
- String auth = username + ":" + password;
-
- Map<String, String> headers = new HashMap<String, String>();
- byte[] encodedBytes = Base64.getEncoder().encode(auth.getBytes());
- headers.put("Accept", "application/json");
- headers.put("Authorization", "Basic " + new String(encodedBytes));
-
- Gson gsonPretty = new GsonBuilder().disableHtmlEscaping()
- .setPrettyPrinting()
- .create();
-
- String soJson = gsonPretty.toJson(request);
-
- SOResponse so = new SOResponse();
- netLogger.info("[OUT|{}|{}|]{}{}", "SO", url, System.lineSeparator(), soJson);
- Pair<Integer, String> httpResponse = RESTManager.post(url, "policy", "policy", headers, "application/json", soJson);
-
- if (httpResponse != null) {
- netLogger.info("[IN|{}|{}|]{}{}", url, "SO", System.lineSeparator(), httpResponse.b);
-
- Gson gson = new Gson();
- so = gson.fromJson(httpResponse.b, SOResponse.class);
- so.httpResponseCode = httpResponse.a;
- } else {
- logger.error("SO Response returned null.");
- }
-
- wm.insert(so);
- logger.info("SOResponse inserted " + gsonPretty.toJson(so));
+ try {
+ String serverRoot = PolicyEngine.manager.getEnvironmentProperty("so.url");
+ String username = PolicyEngine.manager.getEnvironmentProperty("so.username");
+ String password = PolicyEngine.manager.getEnvironmentProperty("so.password");
+
+ String url = serverRoot + "/serviceInstances/v5/" + serviceInstanceId + "/vnfs/" + vnfInstanceId + "/vfModulesHTTPS/1.1";
+
+ String auth = username + ":" + password;
+
+ Map<String, String> headers = new HashMap<String, String>();
+ byte[] encodedBytes = Base64.getEncoder().encode(auth.getBytes());
+ headers.put("Accept", "application/json");
+ headers.put("Authorization", "Basic " + new String(encodedBytes));
+
+ Gson gsonPretty = new GsonBuilder().disableHtmlEscaping()
+ .setPrettyPrinting()
+ .create();
+
+ String soJson = gsonPretty.toJson(request);
+
+ SOResponse so = new SOResponse();
+ netLogger.info("[OUT|{}|{}|]{}{}", "SO", url, System.lineSeparator(), soJson);
+ Pair<Integer, String> httpResponse = RESTManager.post(url, "policy", "policy", headers, "application/json", soJson);
+
+ if (httpResponse != null) {
+ netLogger.info("[IN|{}|{}|]{}{}", url, "SO", System.lineSeparator(), httpResponse.b);
+
+ Gson gson = new Gson();
+ so = gson.fromJson(httpResponse.b, SOResponse.class);
+ so.httpResponseCode = httpResponse.a;
+ } else {
+ logger.error("SO Response returned null.");
+ so.httpResponseCode = 999;
+ }
+
+ wm.insert(so);
+ logger.info("SOResponse inserted " + gsonPretty.toJson(so));
+ } catch (Exception e) {
+ logger.error("Error while performing asyncSORestCall: "+ e.getMessage(),e);
+
+ // create dummy SO object to trigger cleanup
+ SOResponse so = new SOResponse();
+ so.httpResponseCode = 999;
+ wm.insert(so);
+ }
}
});
}