aboutsummaryrefslogtreecommitdiffstats
path: root/feature-active-standby-management
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-08-05 16:24:50 -0400
committerJim Hahn <jrh3@att.com>2021-08-06 09:01:33 -0400
commit7accd0e89516254d88634d6e978ec3ea03790cd1 (patch)
tree77f8f2f97138cbeeebbae7f6321f5742248d1b96 /feature-active-standby-management
parentf9eaa709e739a1596fafe0d840c354087f7ed5ff (diff)
Use lombok in drools-pdp #4
Updated thru feature-eelf. Issue-ID: POLICY-3397 Change-Id: Iad12f5f921374775fb5436cb7d13746256cd6d81 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'feature-active-standby-management')
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyProperties.java15
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpEntity.java12
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpImpl.java12
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java56
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/JpaDroolsPdpsConnector.java11
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/PmStandbyStateChangeNotifier.java8
-rw-r--r--feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/AllSeemsWellTest.java10
7 files changed, 38 insertions, 86 deletions
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyProperties.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyProperties.java
index ebe57567..30c8171e 100644
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyProperties.java
+++ b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyProperties.java
@@ -21,11 +21,15 @@
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;
- }
}
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpEntity.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpEntity.java
index 29f66e90..cf610d9d 100644
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpEntity.java
+++ b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpEntity.java
@@ -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);
- }
}
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpImpl.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpImpl.java
index 41d58602..f86b1a59 100644
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpImpl.java
+++ b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpImpl.java
@@ -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);
- }
}
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java
index 4d40fd5e..8e6b5ef9 100644
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java
+++ b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java
@@ -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;
- }
}
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/JpaDroolsPdpsConnector.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/JpaDroolsPdpsConnector.java
index 14ae52a0..471ef49b 100644
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/JpaDroolsPdpsConnector.java
+++ b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/JpaDroolsPdpsConnector.java
@@ -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
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/PmStandbyStateChangeNotifier.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/PmStandbyStateChangeNotifier.java
index f350bb0a..776b70ee 100644
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/PmStandbyStateChangeNotifier.java
+++ b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/PmStandbyStateChangeNotifier.java
@@ -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() {
diff --git a/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/AllSeemsWellTest.java b/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/AllSeemsWellTest.java
index 0ce12dfc..311f2954 100644
--- a/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/AllSeemsWellTest.java
+++ b/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/AllSeemsWellTest.java
@@ -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);