summaryrefslogtreecommitdiffstats
path: root/controlloop/common
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/common')
-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);
+ }
}
});
}