summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java84
-rw-r--r--controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java54
2 files changed, 78 insertions, 60 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);
+ }
}
});
}
diff --git a/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java
index b0aa5832e..2ef9b3aac 100644
--- a/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java
+++ b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java
@@ -5,9 +5,9 @@
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -40,18 +40,18 @@ public final class VFCManager implements Runnable {
WorkingMemory workingMem;
private static final Logger logger = LoggerFactory.getLogger(VFCManager.class);
private static final Logger netLogger = LoggerFactory.getLogger(org.onap.policy.drools.event.comm.Topic.NETWORK_LOGGER);
-
+
public VFCManager(WorkingMemory wm, VFCRequest request) {
workingMem = wm;
vfcRequest = request;
-
+
/*
* TODO: What if these are null?
*/
String url = PolicyEngine.manager.getEnvironmentProperty("vfc.url");
String username = PolicyEngine.manager.getEnvironmentProperty("vfc.username");
String password = PolicyEngine.manager.getEnvironmentProperty("vfc.password");
-
+
setVFCParams(url, username, password);
}
@@ -66,16 +66,28 @@ public final class VFCManager implements Runnable {
public void run() {
Map<String, String> headers = new HashMap<String, String>();
- headers.put("Accept", "application/json");
+ Pair<Integer, String> httpDetails;
+
+ VFCResponse responseError = new VFCResponse();
+ responseError.responseDescriptor = new VFCResponseDescriptor();
+ responseError.responseDescriptor.status = "error";
+ headers.put("Accept", "application/json");
String vfcUrl = vfcUrlBase + "/ns/" + vfcRequest.nsInstanceId + "/heal";
- String vfcRequestJson = Serialization.gsonPretty.toJson(vfcRequest);
- netLogger.info("[OUT|{}|{}|]{}{}", "VFC", vfcUrl, System.lineSeparator(), vfcRequestJson);
-
- Pair<Integer, String> httpDetails = RESTManager.post(vfcUrl, username, password, headers,
- "application/json", vfcRequestJson);
+ try {
+ String vfcRequestJson = Serialization.gsonPretty.toJson(vfcRequest);
+ netLogger.info("[OUT|{}|{}|]{}{}", "VFC", vfcUrl, System.lineSeparator(), vfcRequestJson);
+
+ httpDetails = RESTManager.post(vfcUrl, username, password, headers,
+ "application/json", vfcRequestJson);
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ workingMem.insert(responseError);
+ return;
+ }
if (httpDetails == null) {
+ workingMem.insert(responseError);
return;
}
@@ -83,7 +95,7 @@ public final class VFCManager implements Runnable {
try {
VFCResponse response = Serialization.gsonPretty.fromJson(httpDetails.b, VFCResponse.class);
netLogger.info("[IN|{}|{}|]{}{}", "VFC", vfcUrl, System.lineSeparator(), response.toString());
-
+
String body = Serialization.gsonPretty.toJson(response);
logger.debug("Response to VFC Heal post:");
logger.debug(body);
@@ -115,16 +127,16 @@ public final class VFCManager implements Runnable {
}
Thread.sleep(20000);
}
- if ((attemptsLeft <= 0)
- && (responseGet != null)
- && (responseGet.responseDescriptor != null)
- && (responseGet.responseDescriptor.status != null)
- && (!responseGet.responseDescriptor.status.isEmpty())) {
- logger.debug("VFC timeout. Status: ({})", responseGet.responseDescriptor.status);
- workingMem.insert(responseGet);
- }
+ if ((attemptsLeft <= 0)
+ && (responseGet != null)
+ && (responseGet.responseDescriptor != null)
+ && (responseGet.responseDescriptor.status != null)
+ && (!responseGet.responseDescriptor.status.isEmpty())) {
+ logger.debug("VFC timeout. Status: ({})", responseGet.responseDescriptor.status);
+ workingMem.insert(responseGet);
+ }
} catch (JsonSyntaxException e) {
- logger.error("Failed to deserialize into VFCResponse {}",e.getLocalizedMessage(),e);
+ logger.error("Failed to deserialize into VFCResponse {}", e.getLocalizedMessage(), e);
} catch (InterruptedException e) {
logger.error("Interrupted exception: {}", e.getLocalizedMessage(), e);
Thread.currentThread().interrupt();