aboutsummaryrefslogtreecommitdiffstats
path: root/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java')
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java56
1 files changed, 19 insertions, 37 deletions
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;
- }
}