Use lombok in drools-pdp #4 61/123161/2
authorJim Hahn <jrh3@att.com>
Thu, 5 Aug 2021 20:24:50 +0000 (16:24 -0400)
committerJim Hahn <jrh3@att.com>
Fri, 6 Aug 2021 13:01:33 +0000 (09:01 -0400)
Updated thru feature-eelf.

Issue-ID: POLICY-3397
Change-Id: Iad12f5f921374775fb5436cb7d13746256cd6d81
Signed-off-by: Jim Hahn <jrh3@att.com>
api-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeatureApiConstants.java
api-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeatureApiConstants.java
feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyProperties.java
feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpEntity.java
feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpImpl.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/JpaDroolsPdpsConnector.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/activestandby/AllSeemsWellTest.java

index 48f41a6..9047739 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * api-active-standby-management
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.drools.activestandby;
 
+import lombok.AccessLevel;
 import lombok.Getter;
+import lombok.NoArgsConstructor;
 import org.onap.policy.common.utils.services.OrderedServiceImpl;
 
-public class ActiveStandbyFeatureApiConstants {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ActiveStandbyFeatureApiConstants {
     /**
      * 'FeatureAPI.impl.getList()' returns an ordered list of objects implementing the 'FeatureAPI'
      * interface.
@@ -31,8 +34,4 @@ public class ActiveStandbyFeatureApiConstants {
     @Getter
     private static final OrderedServiceImpl<ActiveStandbyFeatureApi> impl =
             new OrderedServiceImpl<>(ActiveStandbyFeatureApi.class);
-
-    private ActiveStandbyFeatureApiConstants() {
-        // do nothing
-    }
 }
index be51a50..04e6011 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * policy-core
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.drools.statemanagement;
 
+import lombok.AccessLevel;
 import lombok.Getter;
+import lombok.NoArgsConstructor;
 import org.onap.policy.common.im.StateManagement;
 import org.onap.policy.common.utils.services.OrderedServiceImpl;
 
-public class StateManagementFeatureApiConstants {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class StateManagementFeatureApiConstants {
 
     public static final String LOCKED = StateManagement.LOCKED;
     public static final String UNLOCKED = StateManagement.UNLOCKED;
@@ -63,8 +66,4 @@ public class StateManagementFeatureApiConstants {
     @Getter
     private static final OrderedServiceImpl<StateManagementFeatureApi> impl =
             new OrderedServiceImpl<>(StateManagementFeatureApi.class);
-
-    private StateManagementFeatureApiConstants() {
-        // do nothing
-    }
 }
index ebe5756..30c8171 100644 (file)
 package org.onap.policy.drools.activestandby;
 
 import java.util.Properties;
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
 import org.eclipse.persistence.config.PersistenceUnitProperties;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class ActiveStandbyProperties {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ActiveStandbyProperties {
     // get an instance of logger
     private static final Logger  logger = LoggerFactory.getLogger(ActiveStandbyProperties.class);
 
@@ -46,12 +50,9 @@ public class ActiveStandbyProperties {
     public static final String DB_PWD = PersistenceUnitProperties.JDBC_PASSWORD;
     public static final String DB_TYPE = PersistenceUnitProperties.TARGET_DATABASE;
 
+    @Getter
     private static Properties properties = null;
 
-    private ActiveStandbyProperties() {
-        // do nothing
-    }
-
     /**
      * Initialize the parameter values from the droolsPersitence.properties file values.
      *
@@ -72,8 +73,4 @@ public class ActiveStandbyProperties {
     public static String getProperty(String key) {
         return properties.getProperty(key);
     }
-
-    public static Properties getProperties() {
-        return properties;
-    }
 }
index 29f66e9..cf610d9 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * feature-active-standby-management
  * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -74,14 +74,4 @@ public class DroolsPdpEntity extends DroolsPdpObject implements Serializable {
         //which is an invalid value for the MySql TimeStamp
         designatedDate = new Date(864000000);
     }
-
-    @Override
-    public int hashCode() {
-        return super.hashCode();
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        return super.equals(obj);
-    }
 }
index 41d5860..f86b1a5 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * feature-active-standby-management
  * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -53,14 +53,4 @@ public class DroolsPdpImpl extends DroolsPdpObject {
         //which is an invalid value for the MySql TimeStamp
         this.designatedDate = new Date(864000000);
     }
-
-    @Override
-    public int hashCode() {
-        return super.hashCode();
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        return super.equals(obj);
-    }
 }
index 4d40fd5..8e6b5ef 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * feature-active-standby-management
  * ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,8 +24,11 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
 import java.util.List;
+import java.util.Objects;
 import java.util.Timer;
 import java.util.TimerTask;
+import lombok.Getter;
+import lombok.Setter;
 import org.onap.policy.common.im.MonitorTime;
 import org.onap.policy.common.im.StateManagement;
 import org.onap.policy.common.utils.time.CurrentTime;
@@ -39,9 +42,6 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
 
     // get an instance of logger
     private static final Logger  logger = LoggerFactory.getLogger(DroolsPdpsElectionHandler.class);
-    private DroolsPdpsConnector pdpsConnector;
-    private Object checkWaitTimerLock = new Object();
-    private Object designationWaiterLock = new Object();
 
     /*
      * Must be static, so it can be referenced by JpaDroolsPdpsConnector,
@@ -49,6 +49,15 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
      */
     private static DroolsPdp myPdp;
 
+    @Setter
+    private static boolean unitTesting = false;
+    @Setter
+    private static boolean stalled = false;
+
+    private DroolsPdpsConnector pdpsConnector;
+    private Object checkWaitTimerLock = new Object();
+    private Object designationWaiterLock = new Object();
+
     private Date waitTimerLastRunDate;
 
     // The interval between runs of the DesignationWaiter
@@ -56,7 +65,9 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
 
     private volatile boolean isDesignated;
 
+    @Getter
     private String pdpdNowActive;
+    @Getter
     private String pdpdLastActive;
 
     /*
@@ -70,9 +81,6 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
 
     private final CurrentTime currentTime = MonitorTime.getInstance();
 
-    private static boolean isUnitTesting = false;
-    private static boolean isStalled = false;
-
     /**
      * Constructor.
      *
@@ -156,14 +164,6 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
         DroolsPdpsElectionHandler.myPdp = myPdp;
     }
 
-    public static void setIsUnitTesting(boolean val) {
-        isUnitTesting = val;
-    }
-
-    public static void setIsStalled(boolean val) {
-        isStalled = val;
-    }
-
     /**
      * When the JpaDroolsPdpsConnector.standDown() method is invoked, it needs
      * access to myPdp, so it can keep its designation status in sync with the
@@ -186,9 +186,9 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
                 logger.debug("DesignatedWaiter.run: Entering");
 
                 //This is for testing the checkWaitTimer
-                if (isUnitTesting && isStalled) {
+                if (unitTesting && stalled) {
                     logger.debug("DesignatedWaiter.run: isUnitTesting = {} isStalled = {}",
-                                    isUnitTesting, isStalled);
+                                    unitTesting, stalled);
                     return;
                 }
 
@@ -773,14 +773,14 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
             DroolsPdp rejectedPdp;
 
             // We need to determine if another PDP is the lowest priority
-            if (nullSafeEquals(pdp.getSite(), mostRecentPrimary.getSite())) {
+            if (Objects.equals(pdp.getSite(), mostRecentPrimary.getSite())) {
                 rejectedPdp = data.compareSameSite(pdp);
             } else {
                 rejectedPdp = data.compareDifferentSite(pdp);
             }
             // If the rejectedPdp is myPdp, we need to stand it down and demote it.  Each pdp is responsible
             // for demoting itself
-            if (rejectedPdp != null && nullSafeEquals(rejectedPdp.getPdpId(), myPdp.getPdpId())) {
+            if (rejectedPdp != null && Objects.equals(rejectedPdp.getPdpId(), myPdp.getPdpId())) {
                 logger.debug("\n\nDesignatedWaiter.run: myPdp: {} listOfDesignated myPdp ID: {}"
                                 + " is NOT the lowest priority.  Executing stateManagement.demote()\n\n",
                                 myPdp.getPdpId(),
@@ -971,22 +971,4 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
         }
         return startMs;
     }
-
-    private boolean nullSafeEquals(Object one, Object two) {
-        if (one == null && two == null) {
-            return true;
-        }
-        if (one != null && two != null) {
-            return one.equals(two);
-        }
-        return false;
-    }
-
-    public String getPdpdNowActive() {
-        return pdpdNowActive;
-    }
-
-    public String getPdpdLastActive() {
-        return pdpdLastActive;
-    }
 }
index 14ae52a..471ef49 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * feature-active-standby-management
  * ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -29,11 +29,13 @@ import javax.persistence.EntityManagerFactory;
 import javax.persistence.FlushModeType;
 import javax.persistence.LockModeType;
 import javax.persistence.Query;
+import lombok.AllArgsConstructor;
 import org.onap.policy.common.im.MonitorTime;
 import org.onap.policy.common.utils.time.CurrentTime;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@AllArgsConstructor
 public class JpaDroolsPdpsConnector implements DroolsPdpsConnector {
 
     private static final String SELECT_PDP_BY_ID = "SELECT p FROM DroolsPdpEntity p WHERE p.pdpId=:pdpId";
@@ -45,13 +47,6 @@ public class JpaDroolsPdpsConnector implements DroolsPdpsConnector {
 
     private final CurrentTime currentTime = MonitorTime.getInstance();
 
-
-    //not sure if we want to use the same entity manager factory
-    //for drools session and pass it in here, or create a new one
-    public JpaDroolsPdpsConnector(EntityManagerFactory emf) {
-        this.emf = emf;
-    }
-
     @Override
     public Collection<DroolsPdp> getDroolsPdps() {
         //return a list of all the DroolsPdps in the database
index f350bb0..776b70e 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * feature-active-standby-management
  * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ package org.onap.policy.drools.activestandby;
 
 import java.util.Timer;
 import java.util.TimerTask;
+import lombok.Getter;
 import org.onap.policy.common.im.MonitorTime;
 import org.onap.policy.common.im.StateChangeNotifier;
 import org.onap.policy.common.im.StateManagement;
@@ -68,6 +69,7 @@ public class PmStandbyStateChangeNotifier extends StateChangeNotifier {
     private long startTimeWaitingForActivationMs;
     private long waitInterval;
     private boolean isNowActivating;
+    @Getter
     private String previousStandbyStatus;
     private final CurrentTime currentTime = MonitorTime.getInstance();
     private final Factory timerFactory = Factory.getInstance();
@@ -300,10 +302,6 @@ public class PmStandbyStateChangeNotifier extends StateChangeNotifier {
         }
     }
 
-    public String getPreviousStandbyStatus() {
-        return previousStandbyStatus;
-    }
-
     // these may be overridden by junit tests
 
     protected PolicyEngine getPolicyEngineManager() {
index 0ce12df..311f295 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * feature-active-standby-management
  * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -121,7 +121,7 @@ public class AllSeemsWellTest {
         System.setProperty("com.sun.management.jmxremote.port", "9980");
         System.setProperty("com.sun.management.jmxremote.authenticate", "false");
 
-        DroolsPdpsElectionHandler.setIsUnitTesting(true);
+        DroolsPdpsElectionHandler.setUnitTesting(true);
 
         saveTime = Whitebox.getInternalState(MonitorTime.class, MONITOR_FIELD_NAME);
         saveFactory = Factory.getInstance();
@@ -157,7 +157,7 @@ public class AllSeemsWellTest {
         Whitebox.setInternalState(MonitorTime.class, MONITOR_FIELD_NAME, saveTime);
         Factory.setInstance(saveFactory);
 
-        DroolsPdpsElectionHandler.setIsUnitTesting(false);
+        DroolsPdpsElectionHandler.setUnitTesting(false);
 
         emd.close();
         emfd.close();
@@ -322,7 +322,7 @@ public class AllSeemsWellTest {
         //Now we want to stall the election handler and see the if AllSeemsWell will make the
         //standbystatus = coldstandby
 
-        DroolsPdpsElectionHandler.setIsStalled(true);
+        DroolsPdpsElectionHandler.setStalled(true);
 
         logger.debug("testAllSeemsWell: Sleeping {} s, to allow checkWaitTimer to recognize "
                 + "the election handler has stalled and for the testTransaction to fail to "
@@ -341,7 +341,7 @@ public class AllSeemsWellTest {
         assertEquals(StateManagement.COLD_STANDBY, smf.getStandbyStatus());
 
         //Now lets resume the election handler
-        DroolsPdpsElectionHandler.setIsStalled(false);
+        DroolsPdpsElectionHandler.setStalled(false);
 
         waitForCondition(() -> smf.getStandbyStatus().equals(StateManagement.PROVIDING_SERVICE),
             RESUMED_ELECTION_HANDLER_SLEEP_TIME_SEC);