summaryrefslogtreecommitdiffstats
path: root/controlloop/common/model-impl/vfc/src/main
diff options
context:
space:
mode:
authorRitu Sood <ritu.sood@intel.com>2017-11-02 05:29:49 -0700
committerRitu Sood <ritu.sood@intel.com>2017-11-02 05:29:49 -0700
commit970beac6b638562b909faf1fa96114474a3fb1f3 (patch)
treeed6bc63f1829db7ed27d6a59fad503dbe51b03db /controlloop/common/model-impl/vfc/src/main
parent32d406d841dc8c6674a7392e5e925cc0a4a9028b (diff)
Add fix to catch exception
Added fix to catch exception caused by NULL url provided to Policy for VFC Change-Id: Ifb8bdf41fbb212acf13d388d041d3cb44143caeb Issue-ID: POLICY-408 Signed-off-by: Ritu Sood <ritu.sood@intel.com>
Diffstat (limited to 'controlloop/common/model-impl/vfc/src/main')
-rw-r--r--controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java54
1 files changed, 33 insertions, 21 deletions
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();