summaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src/main/java
diff options
context:
space:
mode:
authorMagnusen, Drew (dm741q) <dm741q@att.com>2017-08-16 15:21:15 -0500
committerMagnusen, Drew (dm741q) <dm741q@att.com>2017-08-18 14:40:18 -0500
commit6d7e231986b84cf6646e46beba7e7e05699bffe6 (patch)
treee08ebda96bc5797d64dd66e667303cf55ad87491 /controlloop/common/eventmanager/src/main/java
parent5ae90a9bf72d2d6dbb163c3dbea5474b657be7e7 (diff)
Code cleanup to resolve critical sonar issues
Code cleanup mostly involed directing the output of exception messages to the correct logger stream. Issue-ID: [POLICY-115] Change-Id: I2042bac3d3b0991a2ebed33421a73f1aa300c7c1 Signed-off-by: Magnusen, Drew (dm741q) <dm741q@att.com>
Diffstat (limited to 'controlloop/common/eventmanager/src/main/java')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ControlLoopLogger.java14
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ControlLoopPublisher.java11
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java13
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java7
4 files changed, 33 insertions, 12 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ControlLoopLogger.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ControlLoopLogger.java
index 4495f2a71..bb23983ce 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ControlLoopLogger.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ControlLoopLogger.java
@@ -22,6 +22,10 @@ package org.onap.policy.controlloop;
import java.lang.reflect.Constructor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
public interface ControlLoopLogger {
public void info(String... parameters);
@@ -32,13 +36,17 @@ public interface ControlLoopLogger {
public static class Factory {
- public ControlLoopLogger buildLogger(String className) {
+ private static final Logger logger = LoggerFactory.getLogger(Factory.class);
+
+
+ public ControlLoopLogger buildLogger(String className) throws ControlLoopException {
+
try {
Constructor<?> constr = Class.forName(className).getConstructor();
return (ControlLoopLogger) constr.newInstance();
} catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException("Cannot load class " + className);
+ logger.error("buildLogger threw: ", e);
+ throw new ControlLoopException("Cannot load class " + className);
}
}
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ControlLoopPublisher.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ControlLoopPublisher.java
index 3ed6f8d58..9272e2887 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ControlLoopPublisher.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ControlLoopPublisher.java
@@ -22,19 +22,24 @@ package org.onap.policy.controlloop;
import java.lang.reflect.Constructor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public interface ControlLoopPublisher {
public void publish(Object object);
public static class Factory {
+ private static final Logger logger = LoggerFactory.getLogger(Factory.class);
- public ControlLoopPublisher buildLogger(String className) {
+
+ public ControlLoopPublisher buildLogger(String className) throws ControlLoopException {
try {
Constructor<?> constr = Class.forName(className).getConstructor();
return (ControlLoopPublisher) constr.newInstance();
} catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException("Cannot load class " + className);
+ logger.error("ControlLoopPublisher.buildLogger threw: ", e);
+ throw new ControlLoopException("Cannot load class " + className);
}
}
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
index d1d2cefd2..3feab7d7c 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
@@ -33,7 +33,6 @@ import org.onap.policy.controlloop.ControlLoopNotificationType;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.VirtualControlLoopNotification;
-
import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.policy.FinalResult;
import org.onap.policy.controlloop.policy.Policy;
@@ -43,12 +42,16 @@ import org.onap.policy.guard.LockCallback;
import org.onap.policy.guard.PolicyGuard;
import org.onap.policy.guard.PolicyGuard.LockResult;
import org.onap.policy.guard.TargetLock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ControlLoopEventManager implements LockCallback, Serializable {
/**
*
*/
+ private static final Logger logger = LoggerFactory.getLogger(ControlLoopEventManager.class);
+
private static final long serialVersionUID = -1216568161322872641L;
public final String closedLoopControlName;
public final UUID requestID;
@@ -62,11 +65,11 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
private FinalResult controlLoopTimedOut = null;
private boolean isActivated = false;
- private LinkedList<ControlLoopOperation> controlLoopHistory = new LinkedList<ControlLoopOperation>();
+ private LinkedList<ControlLoopOperation> controlLoopHistory = new LinkedList<>();
private ControlLoopOperationManager currentOperation = null;
private TargetLock targetLock = null;
- private static Collection<String> requiredAAIKeys = new ArrayList<String>();
+ private static Collection<String> requiredAAIKeys = new ArrayList<>();
static {
requiredAAIKeys.add("AICVServerSelfLink");
requiredAAIKeys.add("AICIdentity");
@@ -148,6 +151,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
//
this.isActivated = true;
} catch (ControlLoopException e) {
+ logger.error("{}: activate threw: ",this, e);
notification.notification = ControlLoopNotificationType.REJECTED;
notification.message = e.getMessage();
}
@@ -183,6 +187,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
yamlSpecification = decodedYaml;
}
} catch (UnsupportedEncodingException e) {
+ logger.error("{}: activate threw: ",this, e);
}
//
// Parse the YAML specification
@@ -203,6 +208,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
//
this.isActivated = true;
} catch (ControlLoopException e) {
+ logger.error("{}: activate threw: ",this, e);
notification.notification = ControlLoopNotificationType.REJECTED;
notification.message = e.getMessage();
}
@@ -467,6 +473,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
return NEW_EVENT_STATUS.SYNTAX_ERROR;
}
} catch (ControlLoopException e) {
+ logger.error("{}: onNewEvent threw: ",this, e);
return NEW_EVENT_STATUS.SYNTAX_ERROR;
}
}
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
index ff7b2c74d..f552cc549 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
@@ -30,15 +30,15 @@ import javax.persistence.Persistence;
import org.onap.policy.appc.Response;
import org.onap.policy.appc.ResponseCode;
-
import org.onap.policy.controlloop.ControlLoopEvent;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
-
import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.controlloop.actor.appc.APPCActorServiceProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ControlLoopOperationManager implements Serializable {
@@ -47,6 +47,7 @@ public class ControlLoopOperationManager implements Serializable {
*
*/
private static final long serialVersionUID = -3773199283624595410L;
+ private static final Logger logger = LoggerFactory.getLogger(ControlLoopOperationManager.class);
@Override
public String toString() {
@@ -449,7 +450,7 @@ public class ControlLoopOperationManager implements Serializable {
try{
em = Persistence.createEntityManagerFactory("OperationsHistoryPU").createEntityManager();//emf.createEntityManager();
}catch(Exception e){
- System.err.println("Test thread got Exception " + e.getLocalizedMessage() + " Can't write to Operations History DB.");
+ logger.error("storeOperationInDataBase threw: ", e);
return;
}