summaryrefslogtreecommitdiffstats
path: root/integrity-monitor
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2017-09-12 10:28:35 -0400
committerPamela Dragosh <pdragosh@research.att.com>2017-09-12 12:46:46 -0400
commit65dff31a2e34b14347f1c0311420463c367afd3d (patch)
treebbd5dba3e1f48449c43085ef373e6ca235760bbc /integrity-monitor
parent5827bc8c28d85f536ac2dff3c4e03ab83f0f8408 (diff)
Fix sonar critical associated with logging
Addressing the following sonar critical: Use a logger to log this exception Either log or rethrow this exception It does not hurt to simply do these as well as clean out lines of code that dump to Sys.out via e.printStackTrace. Issue-ID: POLICY-195 Change-Id: Ibc328094a0653b7baa04778298e4a69955105ea3 Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'integrity-monitor')
-rw-r--r--integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java32
-rw-r--r--integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java31
-rw-r--r--integrity-monitor/src/main/java/org/onap/policy/common/im/StateTransition.java4
-rw-r--r--integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/JmxAgentConnection.java9
4 files changed, 33 insertions, 43 deletions
diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java
index ce042541..fef4b897 100644
--- a/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java
+++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java
@@ -549,8 +549,8 @@ public class IntegrityMonitor {
} catch (Exception e) {
String msg = "IntegrityMonitor.stateCheck(): Failed to diableFail dependent resource = " + dep
+ "; " + e.getMessage();
- logger.debug(msg);
- logger.error(msg);
+ logger.debug(msg, e);
+ logger.error(msg, e);
}
}
}
@@ -844,6 +844,7 @@ public class IntegrityMonitor {
this.stateManager.disableDependency();
}
} catch (Exception e) {
+ logger.error(e);
if (!error_msg.isEmpty()) {
error_msg = error_msg.concat(",");
}
@@ -867,6 +868,7 @@ public class IntegrityMonitor {
this.stateManager.enableNoDependency();
} // The refreshStateAudit will catch the case where it is disabled but availStatus != failed
} catch (Exception e) {
+ logger.error(e);
if (!error_msg.isEmpty()) {
error_msg = error_msg.concat(",");
}
@@ -887,6 +889,7 @@ public class IntegrityMonitor {
this.stateManager.enableNoDependency();
}// The refreshStateAudit will catch the case where it is disabled but availStatus != failed
} catch (Exception e) {
+ logger.error(e);
if (!error_msg.isEmpty()) {
error_msg = error_msg.concat(",");
}
@@ -913,6 +916,7 @@ public class IntegrityMonitor {
error_msg = error_msg.concat(resourceName + ": " + e.getMessage());
this.stateManager.disableDependency();
} catch (Exception ex) {
+ logger.error(ex);
if (!error_msg.isEmpty()) {
error_msg = error_msg.concat(",");
}
@@ -943,7 +947,7 @@ public class IntegrityMonitor {
try {
startTransaction();
} catch (AdministrativeStateException | StandbyStatusException e) {
- // ignore
+ logger.debug(e);
}
// TODO: add test functionality if needed
@@ -1049,7 +1053,7 @@ public class IntegrityMonitor {
}
}
} catch (Exception e1) {
- // ignore
+ logger.debug(e1);
}
logger.error("writeFpc DB table commit failed with exception: " + e);
throw e;
@@ -1131,7 +1135,7 @@ public class IntegrityMonitor {
dep_groups = prop.getProperty(IntegrityMonitorProperties.DEPENDENCY_GROUPS).split(";");
logger.info("dependency groups property = " + Arrays.toString(dep_groups));
} catch (Exception e) {
- logger.warn("Ignored invalid property: " + IntegrityMonitorProperties.DEPENDENCY_GROUPS);
+ logger.warn("Ignored invalid property: " + IntegrityMonitorProperties.DEPENDENCY_GROUPS, e);
}
}
@@ -1203,7 +1207,7 @@ public class IntegrityMonitor {
try {
validateProperties(newprop);
} catch (IntegrityMonitorPropertiesException e) {
- // ignore
+ logger.debug(e);
}
}
else {
@@ -1355,9 +1359,9 @@ public class IntegrityMonitor {
}
} catch (Exception e) {
// log an error
- String msg = "IntegrityMonitor.stateAudit(): " + fpe.getResourceName() + ": StateManagementEntity DB read failed with exception: " + e;
+ String msg = "IntegrityMonitor.stateAudit(): " + fpe.getResourceName() + ": StateManagementEntity DB read failed with exception: ";
+ logger.error(msg, e);
logger.debug(msg);
- logger.error(msg);
synchronized(IMFLUSHLOCK){
if(et.isActive()){
et.rollback();
@@ -1372,7 +1376,7 @@ public class IntegrityMonitor {
} catch (Exception e) {
String msg = "IntegrityMonitor.stateAudit(): Failed to disable " + sme.getResourceName();
logger.debug(msg);
- logger.error(msg);
+ logger.error(msg, e);
}
}
}// end if(diffMs > staleMs)
@@ -1427,7 +1431,7 @@ public class IntegrityMonitor {
try {
writeFpc();
} catch (Exception e) {
- // ignore
+ logger.debug(e);
}
}
}
@@ -1477,9 +1481,6 @@ public class IntegrityMonitor {
stateManager.lock();
} catch (Exception e) {
logger.error("refreshStateAudit: caught unexpected exception from stateManager.lock(): " + e );
- System.out.println(new Date() + " refreshStateAudit: caught unexpected exception "
- + "from stateManager.lock()");
- e.printStackTrace();
}
}else{//unlocked
try {
@@ -1487,9 +1488,6 @@ public class IntegrityMonitor {
stateManager.unlock();;
} catch (Exception e) {
logger.error("refreshStateAudit: caught unexpected exception from stateManager.unlock(): " + e );
- System.out.println(new Date() + " refreshStateAudit: caught unexpected exception "
- + "from stateManager.unlock()");
- e.printStackTrace();
}
}
refreshStateAuditLastRunDate = new Date();
@@ -1528,6 +1526,8 @@ public class IntegrityMonitor {
Thread.sleep(CYCLE_INTERVAL_MILLIS);
} catch (InterruptedException e) {
// The 'sleep' call was interrupted
+ logger.debug(e);
+ Thread.currentThread().interrupt();
continue;
}
diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java
index d8e0f693..bcf910f7 100644
--- a/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java
+++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java
@@ -136,7 +136,6 @@ public class StateManagement extends Observable {
logger.debug("StateManagement: constructor end, resourceName: " + this.resourceName);
} catch(Exception ex) {
logger.error("StateManagement: constructor caught unexpected exception: " + ex);
- ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
et.rollback();
@@ -182,7 +181,6 @@ public class StateManagement extends Observable {
logger.debug("StateManagement: initializeState() operation completed, resourceName = " + this.resourceName);
} catch(Exception ex) {
logger.error("StateManagement.initializeState() caught unexpected exception: " + ex);
- ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
et.rollback();
@@ -230,7 +228,6 @@ public class StateManagement extends Observable {
logger.debug("StateManagement: lock() operation completed, resourceName = " + this.resourceName);
} catch(Exception ex) {
logger.error("StateManagement.lock() caught unexpected exception: " + ex);
- ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
et.rollback();
@@ -277,7 +274,6 @@ public class StateManagement extends Observable {
logger.debug("StateManagement: unlock() operation completed, resourceName = " + this.resourceName);
} catch(Exception ex) {
logger.error("StateManagement.unlock() caught unexpected exception: " + ex);
- ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
et.rollback();
@@ -325,7 +321,6 @@ public class StateManagement extends Observable {
logger.debug("StateManagement enableNotFailed() operation completed, resourceName = " + this.resourceName);
} catch(Exception ex) {
logger.error("StateManagement.enableNotFailed() caught unexpected exception: " + ex);
- ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
et.rollback();
@@ -371,7 +366,6 @@ public class StateManagement extends Observable {
logger.debug("StateManagement: disableFailed() operation completed, resourceName = " + this.resourceName);
} catch(Exception ex) {
logger.error("StateManagement.disableFailed() caught unexpected exception: " + ex);
- ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
et.rollback();
@@ -424,7 +418,6 @@ public class StateManagement extends Observable {
+ otherResourceName);
} catch(Exception ex) {
logger.error("StateManagement.disableFailed(otherResourceName) caught unexpected exception: " + ex);
- ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
et.rollback();
@@ -471,7 +464,6 @@ public class StateManagement extends Observable {
logger.debug("StateManagement: disableDependency() operation completed, resourceName = " + this.resourceName);
} catch(Exception ex) {
logger.error("StateManagement.disableDependency() caught unexpected exception: " + ex);
- ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
et.rollback();
@@ -519,7 +511,6 @@ public class StateManagement extends Observable {
logger.debug("StateManagement: enableNoDependency() operation completed, resourceName = " + this.resourceName);
} catch(Exception ex) {
logger.error("StateManagement.enableNoDependency() caught unexpected exception: " + ex);
- ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
et.rollback();
@@ -569,7 +560,6 @@ public class StateManagement extends Observable {
notifyObservers(STANDBY_STATUS);
}catch(Exception ex){
logger.error("StateManagement.promote() caught unexpected exception: " + ex);
- ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
et.rollback();
@@ -622,7 +612,6 @@ public class StateManagement extends Observable {
logger.debug("StateManagement: demote() operation completed, resourceName = " + this.resourceName);
} catch(Exception ex) {
logger.error("StateManagement.demote() caught unexpected exception: " + ex);
- ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
et.rollback();
@@ -677,7 +666,6 @@ public class StateManagement extends Observable {
logger.debug("StateManagement: demote(otherResourceName) operation completed, resourceName = " + otherResourceName);
} catch(Exception ex) {
logger.error("StateManagement.demote(otherResourceName) caught unexpected exception: " + ex);
- ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
et.rollback();
@@ -713,8 +701,7 @@ public String getAdminState()
this.adminState = null;
}
} catch(Exception ex) {
- ex.printStackTrace();
- logger.error("StateManagement: getAdminState exception: " + ex.toString());
+ logger.error("StateManagement: getAdminState exception: " + ex);
}
return this.adminState;
@@ -745,8 +732,7 @@ public String getOpState()
this.opState = null;
}
} catch(Exception ex) {
- ex.printStackTrace();
- logger.error("StateManagement: getOpState exception: " + ex.toString());
+ logger.error("StateManagement: getOpState exception: " + ex);
}
return this.opState;
@@ -777,8 +763,7 @@ public String getOpState()
this.availStatus = null;
}
} catch(Exception ex) {
- ex.printStackTrace();
- logger.error("StateManagement: getAvailStatus exception: " + ex.toString());
+ logger.error("StateManagement: getAvailStatus exception: ", ex);
}
return this.availStatus;
@@ -809,8 +794,7 @@ public String getOpState()
this.standbyStatus = null;
}
} catch(Exception ex) {
- ex.printStackTrace();
- logger.error("StateManagement: getStandbyStatus exception: " + ex.toString());
+ logger.error("StateManagement: getStandbyStatus exception: " + ex);
}
return this.standbyStatus;
@@ -851,8 +835,7 @@ public String getOpState()
stateManagementEntity.setStandbyStatus(NULL_VALUE); // default
}
} catch(Exception ex) {
- ex.printStackTrace();
- logger.error("findStateManagementEntity exception: " + ex.toString());
+ logger.error("findStateManagementEntity exception: " + ex);
}
return stateManagementEntity;
}
@@ -903,8 +886,7 @@ public String getOpState()
}
} catch (Exception e) {
logger.error("getStandbyStatus: Caught Exception attempting to get statemanagemententity record, message='"
- + e.getMessage() + "'");
- e.printStackTrace();
+ + e.getMessage() + "'", e);
synchronized(FLUSHLOCK){
if(et.isActive()){
et.rollback();
@@ -954,7 +936,6 @@ public String getOpState()
}
}catch(Exception ex){
logger.error("StateManagement.deleteAllStateManagementEntities() caught Exception: " + ex);
- ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
et.rollback();
diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/StateTransition.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateTransition.java
index a45a536b..03f6f4e3 100644
--- a/integrity-monitor/src/main/java/org/onap/policy/common/im/StateTransition.java
+++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateTransition.java
@@ -55,6 +55,7 @@ public class StateTransition {
setupStateTable();
} catch(Exception ex) {
+ logger.debug(ex);
throw new StateTransitionException("StateTransition Exception: " + ex.toString());
}
}
@@ -142,7 +143,7 @@ public class StateTransition {
stateElement.displayStateElement();
} catch(Exception ex) {
- logger.error("String split exception: " + ex.toString());
+ logger.error("String split exception: " + ex);
}
} else {
@@ -152,6 +153,7 @@ public class StateTransition {
throw new StateTransitionException(msg);
}
} catch (Exception ex) {
+ logger.debug(ex);
throw new StateTransitionException("Exception: " + ex.toString() + ", adminState=[" + adminState + "], opState=[" + opState + "], availStatus=[" +
availStatus + "], standbyStatus=[" + standbyStatus + "], actionName=[" + actionName + "]");
}
diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/JmxAgentConnection.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/JmxAgentConnection.java
index 9b9bc48c..091f2d57 100644
--- a/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/JmxAgentConnection.java
+++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/JmxAgentConnection.java
@@ -26,6 +26,7 @@ package org.onap.policy.common.im.jmx;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+
import javax.management.MBeanServerConnection;
import javax.management.Notification;
import javax.management.NotificationListener;
@@ -34,10 +35,16 @@ import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
+
/**
* Class to create a JMX RMI connection to the JmxAgent.
*/
public final class JmxAgentConnection {
+
+ private static final Logger logger = FlexLogger.getLogger(JmxAgentConnection.class);
+
private static final String DEFAULT_HOST = "localhost";
private static final String DEFAULT_PORT = "9996";
@@ -117,7 +124,7 @@ public final class JmxAgentConnection {
*/
public void disconnect() {
if (connector != null) {
- try { connector.close(); } catch (IOException e) { }
+ try { connector.close(); } catch (IOException e) { logger.debug(e); }
}
}
}