aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop
diff options
context:
space:
mode:
authorMike Babinski <mb1915@att.com>2017-08-22 04:40:23 +0000
committerMike Babinski <mb1915@att.com>2017-08-23 22:19:40 +0000
commit945627aef4645a9a696aeb2150669e43aae9f98a (patch)
treec2c7aa3bc2124def4a41e3f1710946922d2d325d /controlloop
parent1b93494ed7c4808aaf979472a9349177ff99d8d8 (diff)
Fix Sonar Blockers for Drools-Applications
Add null checks to protect against potential null exceptions. Issue-ID: POLICY-111 Change-Id: Ib079d1b48a6858332ea3eaa0e75a991f518a0f9a Signed-off-by: Mike Babinski <mb1915@att.com>
Diffstat (limited to 'controlloop')
-rw-r--r--controlloop/common/guard/src/main/java/org/onap/policy/guard/PIPEngineGetHistory.java25
-rw-r--r--controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/MSOManager.java8
-rw-r--r--controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java17
3 files changed, 24 insertions, 26 deletions
diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PIPEngineGetHistory.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PIPEngineGetHistory.java
index 57deee5f1..30f1ef820 100644
--- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PIPEngineGetHistory.java
+++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PIPEngineGetHistory.java
@@ -57,7 +57,6 @@ public class PIPEngineGetHistory extends StdConfigurableEngine{
private static final Logger logger = LoggerFactory.getLogger(PIPEngineGetHistory.class);
- //private static EntityManager em;
public static final String DEFAULT_DESCRIPTION = "PIP for retrieving Operations History from DB";
@@ -89,7 +88,7 @@ public class PIPEngineGetHistory extends StdConfigurableEngine{
try {
attributeValue = DataTypes.DT_INTEGER.createAttributeValue(value);
} catch (Exception ex) {
- this.logger.error("Failed to convert {} to an AttributeValue<Boolean>",value, ex);
+ logger.error("Failed to convert {} to an AttributeValue<Boolean>",value, ex);
}
if (attributeValue != null) {
stdPIPResponse.addAttribute(new StdMutableAttribute(category, attributeId, attributeValue, pipRequest.getIssuer()/*this.getIssuer()*/, false));
@@ -120,22 +119,20 @@ public class PIPEngineGetHistory extends StdConfigurableEngine{
@Override
public PIPResponse getAttributes(PIPRequest pipRequest, PIPFinder pipFinder) throws PIPException {
// TODO Auto-generated method stub
- System.out.println("Entering FeqLimiter PIP");
+ logger.debug("Entering FeqLimiter PIP");
/*
* First check to see if the issuer is set and then match it
*/
String string;
if ((string = pipRequest.getIssuer()) == null) {
- this.logger.debug("No issuer in the request...");
- System.out.println("FeqLimiter PIP - No issuer in the request!");
+ logger.debug("No issuer in the request...");
return StdPIPResponse.PIP_RESPONSE_EMPTY;
}
else{
//Notice, we are checking here for the base issuer prefix.
if (!string.contains(this.getIssuer())) {
- this.logger.debug("Requested issuer '" + string + "' does not match " + (this.getIssuer() == null ? "null" : "'" + this.getIssuer() + "'"));
- System.out.println("FeqLimiter PIP - Issuer "+ string +" does not match with: "+this.getIssuer());
+ logger.debug("Requested issuer '" + string + "' does not match " + (this.getIssuer() == null ? "null" : "'" + this.getIssuer() + "'"));
return StdPIPResponse.PIP_RESPONSE_EMPTY;
}
}
@@ -151,7 +148,7 @@ public class PIPEngineGetHistory extends StdConfigurableEngine{
String timeWindow = timeWindowVal + " " + timeWindowScale;
- System.out.println("Going to query DB about: "+actor + " " + operation + " " + target + " " + timeWindow);
+ logger.debug("Going to query DB about: "+actor + " " + operation + " " + target + " " + timeWindow);
int countFromDB = getCountFromDB(actor, operation, target, timeWindow);
StdMutablePIPResponse stdPIPResponse = new StdMutablePIPResponse();
@@ -186,11 +183,11 @@ public class PIPEngineGetHistory extends StdConfigurableEngine{
try {
pipResponse = pipFinder.getMatchingAttributes(pipRequest, this);
if (pipResponse.getStatus() != null && !pipResponse.getStatus().isOk()) {
- System.out.println("Error retrieving " + pipRequest.getAttributeId().stringValue() + ": " + pipResponse.getStatus().toString());
+ logger.debug("Error retrieving " + pipRequest.getAttributeId().stringValue() + ": " + pipResponse.getStatus().toString());
pipResponse = null;
}
- if (pipResponse.getAttributes().size() == 0) {
- System.out.println("No value for " + pipRequest.getAttributeId().stringValue());
+ if (pipResponse.getAttributes() != null && pipResponse.getAttributes().isEmpty()) {
+ logger.debug("No value for {}", pipRequest.getAttributeId().stringValue());
pipResponse = null;
}
} catch (PIPException ex) {
@@ -290,8 +287,6 @@ public class PIPEngineGetHistory extends StdConfigurableEngine{
private static int getCountFromDB(String actor, String operation, String target, String timeWindow){
- //long startTime = System.nanoTime();
-
EntityManager em;
try{
em = Persistence.createEntityManagerFactory("OperationsHistoryPU").createEntityManager();
@@ -321,10 +316,6 @@ public class PIPEngineGetHistory extends StdConfigurableEngine{
return -1;
}
- //System.out.println("###########************** History count: " + ret);
-
- //long estimatedTime = System.nanoTime() - startTime;
- //System.out.println("time took: " + (double)estimatedTime/1000/1000 + " mili sec.");
em.close();
diff --git a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/MSOManager.java b/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/MSOManager.java
index 81d43ef76..9f4fe5bbc 100644
--- a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/MSOManager.java
+++ b/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/MSOManager.java
@@ -87,8 +87,12 @@ public final class MSOManager {
}
Thread.sleep(20000);
}
-
- System.out.println("***** ######## VF Module Creation timeout. Status: ("+responseGet.request.requestStatus.requestState+")");
+ if (responseGet != null
+ && responseGet.request != null
+ && responseGet.request.requestStatus != null
+ && responseGet.request.requestStatus.requestState != null) {
+ logger.warn("***** ######## VF Module Creation timeout. Status: ( {})", responseGet.request.requestStatus.requestState);
+ }
return responseGet;
} catch (JsonSyntaxException e) {
logger.error("Failed to deserialize into MSOResponse: ", e);
diff --git a/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java b/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java
index 8c79d2ad3..c38c1076c 100644
--- a/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java
+++ b/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java
@@ -67,8 +67,10 @@ public final class RESTManager {
try (CloseableHttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(credentials).build()) {
HttpPost post = new HttpPost(url);
- for (String key : headers.keySet()) {
- post.addHeader(key, headers.get(key));
+ if (headers != null) {
+ for (String key : headers.keySet()) {
+ post.addHeader(key, headers.get(key));
+ }
}
post.addHeader("Content-Type", contentType);
@@ -100,16 +102,17 @@ public final class RESTManager {
try (CloseableHttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(credentials).build()) {
HttpGet get = new HttpGet(url);
- for (String key : headers.keySet()) {
- get.addHeader(key, headers.get(key));
+ if (headers != null) {
+ for (String key : headers.keySet()) {
+ get.addHeader(key, headers.get(key));
+ }
}
HttpResponse response = client.execute(get);
String returnBody = EntityUtils.toString(response.getEntity(), "UTF-8");
- System.out.println("HTTP GET Response Status Code: " + response.getStatusLine().getStatusCode());
- System.out.println("HTTP GET Response Body:");
- System.out.println(returnBody);
+ logger.debug("HTTP GET Response Status Code: " + response.getStatusLine().getStatusCode());
+ logger.debug("HTTP GET Response Body: " + returnBody);
return new Pair<Integer, String>(response.getStatusLine().getStatusCode(), returnBody);
} catch (IOException e) {