Remove sonar blocker and critical 65/14865/1
authorPamela Dragosh <pdragosh@research.att.com>
Sun, 24 Sep 2017 12:34:24 +0000 (08:34 -0400)
committerPamela Dragosh <pdragosh@research.att.com>
Sun, 24 Sep 2017 12:35:04 +0000 (08:35 -0400)
Removed unused import
Null pointer exception
Does not evaluate to true
override hashCode
log exception
cast long
public static final

Issue-ID: POLICY-261
Change-Id: I2d90f8503fcc5ed7d13aff31143b8fb69c689e18
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeature.java
feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpObject.java
feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java
feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/PMStandbyStateChangeNotifier.java
feature-active-standby-management/src/test/java/org/onap/policy/drools/controller/test/StandbyStateManagementTest.java

index d40a9e0..d2c542f 100644 (file)
@@ -106,6 +106,10 @@ public class ActiveStandbyFeature implements ActiveStandbyFeatureAPI,
                        logger.error("ActiveStandbyFeature failed to initialize.  "
                                        + "Unable to get instance of StateManagementFeatureAPI "
                                        + "with resourceID: {}", myPdp.getPdpId());
+                       //
+                       // Cannot add observer since stateManagementFeature is null
+                       //
+                       return;
                }
 
 
@@ -172,15 +176,13 @@ public class ActiveStandbyFeature implements ActiveStandbyFeatureAPI,
 
                                myPdp = new DroolsPdpImpl(resourceName,false,4,new Date());     
                        }
-                       if(myPdp != null){
-                               String site_name = ActiveStandbyProperties.getProperty(ActiveStandbyProperties.SITE_NAME);
-                               if (site_name == null) {
-                                       site_name = "";
-                               }else{
-                                       site_name = site_name.trim();
-                               }
-                               myPdp.setSiteName(site_name);
+                       String site_name = ActiveStandbyProperties.getProperty(ActiveStandbyProperties.SITE_NAME);
+                       if (site_name == null) {
+                               site_name = "";
+                       }else{
+                               site_name = site_name.trim();
                        }
+                       myPdp.setSiteName(site_name);
                        if(electionHandler == null){
                                electionHandler = new DroolsPdpsElectionHandler(conn,myPdp);
                        }
index e434c83..8c1d9f2 100644 (file)
@@ -31,6 +31,15 @@ public abstract class DroolsPdpObject implements DroolsPdp{
                        return false;
                }
        }
+       @Override
+       public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + (this.getPdpId() == null ? 0 : this.getPdpId().hashCode());
+        result = prime * result + (this.getSiteName() == null ? 0 : this.getSiteName().hashCode());
+        result = prime * result + this.getPriority();
+               return super.hashCode();
+       }
        private int nullSafeCompare(String one, String two){
                if(one != null && two != null){
                        return one.compareTo(two);
index 6edf11f..b0f1a12 100644 (file)
@@ -256,7 +256,7 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
                                                                                logger.error
                                                                                ("DesignatedWaiter.run: myPdp: {} "
                                                                                                + "Caught Exception attempting to demote myPdp,"
-                                                                                               + "message= {}", myPdp.getPdpId(), e.getMessage());
+                                                                                               + "message= {}", myPdp.getPdpId(), e);
                                                                        }
                                                                }else{
                                                                        // Don't demote a remote PDP that is current.  It should catch itself
@@ -318,7 +318,7 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
                                                                        logger.error
                                                                        ("DesignatedWaiter.run: myPdp: {} Caught Exception "
                                                                                        + "attempting to disableFail myPdp {}, message= {}",
-                                                                                       myPdp.getPdpId(), myPdp.getPdpId(), e.getMessage());
+                                                                                       myPdp.getPdpId(), myPdp.getPdpId(), e);
                                                                }
                                                        } else { //it is a remote PDP that is failed
                                                                if(logger.isDebugEnabled()){
@@ -336,7 +336,7 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
                                                                        logger.error
                                                                        ("DesignatedWaiter.run: for PDP {}  Caught Exception attempting to "
                                                                                        + "disableFail({}), message= {}",
-                                                                                       pdp.getPdpId(), pdp.getPdpId(), e.getMessage());
+                                                                                       pdp.getPdpId(), pdp.getPdpId(), e);
                                                                }
 
                                                        }
@@ -378,7 +378,7 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
                                                                                logger.error
                                                                                ("DesignatedWaiter.run: myPdp: {} Caught Exception "
                                                                                                + "attempting to demote myPdp {}, message = {}",  myPdp.getPdpId(),
-                                                                                               myPdp.getPdpId(), e.getMessage());
+                                                                                               myPdp.getPdpId(), e);
                                                                        }
 
                                                                }
@@ -438,7 +438,7 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
                                                                                logger.error
                                                                                ("DesignatedWaiter.run: myPdp: {} Caught Exception attempting to "
                                                                                                + "disableFail myPdp {}, message= {}", 
-                                                                                                myPdp.getPdpId(), myPdp.getPdpId(), e.getMessage());
+                                                                                                myPdp.getPdpId(), myPdp.getPdpId(), e);
                                                                        }
                                                                }else{//it is remote
                                                                        if(logger.isDebugEnabled()){
@@ -455,7 +455,7 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
                                                                                logger.error
                                                                                ("DesignatedWaiter.run: for PDP {}" 
                                                                                                + " Caught Exception attempting to disableFail({})"
-                                                                                               + ", message=", pdp.getPdpId(), pdp.getPdpId(), e.getMessage());
+                                                                                               + ", message=", pdp.getPdpId(), pdp.getPdpId(), e);
                                                                        }
                                                                }
                                                        }
@@ -551,7 +551,7 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
                                                } catch (Exception e) {
                                                        logger.error
                                                        ("ERROR: DesignatedWaiter.run: Caught Exception attempting to promote PDP={}"
-                                                                       + ", message=", myPdp.getPdpId(), e.getMessage());
+                                                                       + ", message=", myPdp.getPdpId(), e);
                                                        myPdp.setDesignated(false);
                                                        pdpsConnector.setDesignated(myPdp,false);
                                                        isDesignated = false;
@@ -571,7 +571,7 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
                                                                logger.error
                                                                ("ERROR: DesignatedWaiter.run: Caught StandbyStatusException "
                                                                                + "attempting to promote then demote PDP={}, message=",
-                                                                               myPdp.getPdpId(), e1.getMessage());
+                                                                               myPdp.getPdpId(), e1);
                                                        }
 
                                                } 
@@ -850,7 +850,7 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
                                                logger.error
                                                ("DesignatedWaiter.run: myPdp: {} Caught Exception attempting to "
                                                                + "demote myPdp {} myPdp.getPdpId(), message= {}", myPdp.getPdpId(), 
-                                                               e.getMessage());
+                                                               e);
                                        }
                                }
                        } //end: for(DroolsPdp pdp : listOfDesignated)
index ce62bf8..5a6dd8f 100644 (file)
@@ -80,16 +80,16 @@ public class PMStandbyStateChangeNotifier extends StateChangeNotifier {
        private long waitInterval;
        private boolean isNowActivating;
        private String previousStandbyStatus;
-       public static String NONE = "none";
-       public static String UNSUPPORTED = "unsupported";
-       public static String HOTSTANDBY_OR_COLDSTANDBY = "hotstandby_or_coldstandby";
+       public static final String NONE = "none";
+       public static final String UNSUPPORTED = "unsupported";
+       public static final String HOTSTANDBY_OR_COLDSTANDBY = "hotstandby_or_coldstandby";
                
        public PMStandbyStateChangeNotifier(){
                pdpUpdateInterval = Integer.parseInt(ActiveStandbyProperties.getProperty(ActiveStandbyProperties.PDP_UPDATE_INTERVAL));
                isWaitingForActivation = false;
                startTimeWaitingForActivationMs = new Date().getTime();
                //delay the activate so the DesignatedWaiter can run twice - give it an extra 2 seconds
-               waitInterval = 2*pdpUpdateInterval + 2000;
+               waitInterval = 2*pdpUpdateInterval + 2000L;
                isNowActivating=false;
                previousStandbyStatus = PMStandbyStateChangeNotifier.NONE;
        }
@@ -248,7 +248,7 @@ public class PMStandbyStateChangeNotifier extends StateChangeNotifier {
                                                delayActivateTimer.cancel();
                                        }catch(Exception e){
                                                if(logger.isDebugEnabled()){
-                                                       logger.debug("handleStateChange: PROVIDING_SERVICE no delayActivationTimer existed.");
+                                                       logger.debug("handleStateChange: PROVIDING_SERVICE no delayActivationTimer existed.", e);
                                                }
                                                //If you end of here, there was no active timer
                                        }
index a4a9796..4f7469c 100644 (file)
@@ -38,10 +38,7 @@ import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.onap.policy.common.im.AdministrativeStateException;
 import org.onap.policy.common.im.IntegrityMonitor;
 import org.onap.policy.common.im.StandbyStatusException;
@@ -57,6 +54,8 @@ import org.onap.policy.drools.activestandby.JpaDroolsPdpsConnector;
 import org.onap.policy.drools.activestandby.PMStandbyStateChangeNotifier;
 import org.onap.policy.drools.core.PolicySessionFeatureAPI;
 import org.onap.policy.drools.statemanagement.StateManagementFeatureAPI;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /*
  * All JUnits are designed to run in the local development environment