diff options
Diffstat (limited to 'feature-active-standby-management/src')
7 files changed, 51 insertions, 55 deletions
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdp.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdp.java index 8fada968..12c75929 100644 --- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdp.java +++ b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdp.java @@ -24,27 +24,27 @@ import java.util.Date; public interface DroolsPdp { - public String getPdpId(); + String getPdpId(); - public boolean isDesignated(); + boolean isDesignated(); - public int getPriority(); + int getPriority(); - public Date getUpdatedDate(); + Date getUpdatedDate(); - public void setDesignated(boolean isDesignated); + void setDesignated(boolean isDesignated); - public void setUpdatedDate(Date updatedDate); + void setUpdatedDate(Date updatedDate); - public int comparePriority(DroolsPdp other); + int comparePriority(DroolsPdp other); - public int comparePriority(DroolsPdp other,String previousSite); + int comparePriority(DroolsPdp other, String previousSite); - public String getSite(); + String getSite(); - public void setSite(String site); + void setSite(String site); - public Date getDesignatedDate(); + Date getDesignatedDate(); - public void setDesignatedDate(Date designatedDate); + void setDesignatedDate(Date designatedDate); } diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsConnector.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsConnector.java index fdb87378..6e06272c 100644 --- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsConnector.java +++ b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsConnector.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * feature-active-standby-management * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 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. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -26,39 +26,39 @@ public interface DroolsPdpsConnector { //return a list of PDPs, NOT including this PDP - public Collection<DroolsPdp> getDroolsPdps(); + Collection<DroolsPdp> getDroolsPdps(); - public void update(DroolsPdp pdp); + void update(DroolsPdp pdp); - //determines if the DroolsPdp parameter is considered "current" or expired + //determines if the DroolsPdp parameter is considered "current" or expired //(has it been too long since the Pdp sent an update) - public boolean isPdpCurrent(DroolsPdp pdp); + boolean isPdpCurrent(DroolsPdp pdp); // Updates DESIGNATED boolean in PDP record. - public void setDesignated(DroolsPdp pdp, boolean designated); + void setDesignated(DroolsPdp pdp, boolean designated); // Marks droolspdpentity.DESIGNATED=false, so another PDP-D will go active. - public void standDownPdp(String pdpId); + void standDownPdp(String pdpId); // This is used in a JUnit test environment to manually // insert a PDP - public void insertPdp(DroolsPdp pdp); + void insertPdp(DroolsPdp pdp); // This is used in a JUnit test environment to manually // delete a PDP - public void deletePdp(String pdpId); + void deletePdp(String pdpId); // This is used in a JUnit test environment to manually // clear the droolspdpentity table. - public void deleteAllPdps(); + void deleteAllPdps(); // This is used in a JUnit test environment to manually // get a PDP - public DroolsPdpEntity getPdp(String pdpId); + DroolsPdpEntity getPdp(String pdpId); // Used by DroolsPdpsElectionHandler to determine if the currently designated // PDP has failed. - public boolean hasDesignatedPdpFailed(Collection<DroolsPdp> pdps); + boolean hasDesignatedPdpFailed(Collection<DroolsPdp> pdps); } 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 5308cbe6..37382e81 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 @@ -49,14 +49,8 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker { */ private static DroolsPdp myPdp; - private DesignationWaiter designationWaiter; - private Timer updateWorker; - private Timer waitTimer; private Date waitTimerLastRunDate; - // The interval between checks of the DesignationWaiter to be sure it is running. - private int pdpCheckInterval; - // The interval between runs of the DesignationWaiter private int pdpUpdateInterval; @@ -100,12 +94,14 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker { this.pdpsConnector = pdps; DroolsPdpsElectionHandler.myPdp = myPdp; this.isDesignated = false; - pdpCheckInterval = 3000; + + // The interval between checks of the DesignationWaiter to be sure it is running. + int pdpCheckInterval = 3000; try { pdpCheckInterval = Integer.parseInt(ActiveStandbyProperties.getProperty( ActiveStandbyProperties.PDP_CHECK_INVERVAL)); } catch (Exception e) { - logger.error("Could not get pdpCheckInterval property. Using default {}",pdpCheckInterval, e); + logger.error("Could not get pdpCheckInterval property. Using default {}", pdpCheckInterval, e); } pdpUpdateInterval = 2000; try { @@ -122,7 +118,7 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker { // Create the timer which will update the updateDate in DroolsPdpEntity table. // This is the heartbeat - updateWorker = Factory.getInstance().makeTimer(); + Timer updateWorker = Factory.getInstance().makeTimer(); // Schedule the TimerUpdateClass to run at 100 ms and run at pdpCheckInterval ms thereafter // NOTE: The first run of the TimerUpdateClass results in myPdp being added to the @@ -130,12 +126,12 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker { updateWorker.scheduleAtFixedRate(new TimerUpdateClass(), 100, pdpCheckInterval); // Create the timer which will run the election algorithm - waitTimer = Factory.getInstance().makeTimer(); + Timer waitTimer = Factory.getInstance().makeTimer(); // Schedule it to start in startMs ms // (so it will run after the updateWorker and run at pdpUpdateInterval ms thereafter long startMs = getDWaiterStartMs(); - designationWaiter = new DesignationWaiter(); + DesignationWaiter designationWaiter = new DesignationWaiter(); waitTimer.scheduleAtFixedRate(designationWaiter, startMs, pdpUpdateInterval); waitTimerLastRunDate = new Date(nowMs + startMs); 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 735e3a2a..f350bb0a 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 @@ -64,7 +64,6 @@ public class PmStandbyStateChangeNotifier extends StateChangeNotifier { // get an instance of logger private static final Logger logger = LoggerFactory.getLogger(PmStandbyStateChangeNotifier.class); private Timer delayActivateTimer; - private int pdpUpdateInterval; private boolean isWaitingForActivation; private long startTimeWaitingForActivationMs; private long waitInterval; @@ -81,8 +80,8 @@ public class PmStandbyStateChangeNotifier extends StateChangeNotifier { * */ public PmStandbyStateChangeNotifier() { - pdpUpdateInterval = - Integer.parseInt(ActiveStandbyProperties.getProperty(ActiveStandbyProperties.PDP_UPDATE_INTERVAL)); + int pdpUpdateInterval = + Integer.parseInt(ActiveStandbyProperties.getProperty(ActiveStandbyProperties.PDP_UPDATE_INTERVAL)); isWaitingForActivation = false; startTimeWaitingForActivationMs = currentTime.getMillis(); // delay the activate so the DesignatedWaiter can run twice - give it an extra 2 seconds diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ThreadRunningChecker.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ThreadRunningChecker.java index 373c373c..d359b5a6 100644 --- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ThreadRunningChecker.java +++ b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ThreadRunningChecker.java @@ -22,6 +22,6 @@ package org.onap.policy.drools.activestandby; @FunctionalInterface public interface ThreadRunningChecker { - public void checkThreadStatus(); + void checkThreadStatus(); } 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 cb7e4c3f..2616ac34 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 @@ -20,6 +20,7 @@ package org.onap.policy.drools.activestandby; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; @@ -262,7 +263,7 @@ public class AllSeemsWellTest { DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId); logger.debug("testAllSeemsWell: After insertion, PDP={} has DESIGNATED={}", thisPdpId, droolsPdpEntity.isDesignated()); - assertTrue(droolsPdpEntity.isDesignated() == false); + assertFalse(droolsPdpEntity.isDesignated()); logger.debug("testAllSeemsWell: Instantiating stateManagement object"); StateManagement sm = new StateManagement(emfXacml, "dummy"); @@ -311,7 +312,7 @@ public class AllSeemsWellTest { droolsPdpEntity = conn.getPdp(thisPdpId); logger.debug("testAllSeemsWell: After sm.demote() invoked, DESIGNATED= {} " + "for PDP= {}", droolsPdpEntity.isDesignated(), thisPdpId); - assertTrue(droolsPdpEntity.isDesignated() == true); + assertTrue(droolsPdpEntity.isDesignated()); String standbyStatus = smf.getStandbyStatus(thisPdpId); logger.debug("testAllSeemsWell: After demotion, PDP= {} " + "has standbyStatus= {}", thisPdpId, standbyStatus); diff --git a/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/StandbyStateManagementTest.java b/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/StandbyStateManagementTest.java index 32648eb2..f51d620f 100644 --- a/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/StandbyStateManagementTest.java +++ b/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/StandbyStateManagementTest.java @@ -20,6 +20,7 @@ package org.onap.policy.drools.activestandby; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; @@ -688,7 +689,7 @@ public class StandbyStateManagementTest { DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId); logger.debug("testColdStandby: After insertion, DESIGNATED= {} " + "for PDP= {}", droolsPdpEntity.isDesignated(), thisPdpId); - assertTrue(droolsPdpEntity.isDesignated() == true); + assertTrue(droolsPdpEntity.isDesignated()); /* * When the Standby Status changes (from providingservice) to hotstandby @@ -760,7 +761,7 @@ public class StandbyStateManagementTest { droolsPdpEntity = conn.getPdp(thisPdpId); logger.debug("testColdStandby: After lock sm.lock() invoked, " + "DESIGNATED= {} for PDP={}", droolsPdpEntity.isDesignated(), thisPdpId); - assertTrue(droolsPdpEntity.isDesignated() == false); + assertFalse(droolsPdpEntity.isDesignated()); logger.debug("\n\ntestColdStandby: Exiting\n\n"); } @@ -795,7 +796,7 @@ public class StandbyStateManagementTest { DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId); logger.debug("testHotStandby1: After insertion, PDP={} has DESIGNATED={}", thisPdpId, droolsPdpEntity.isDesignated()); - assertTrue(droolsPdpEntity.isDesignated() == false); + assertFalse(droolsPdpEntity.isDesignated()); logger.debug("testHotStandby1: Instantiating stateManagement object"); StateManagement sm = new StateManagement(emfx, "dummy"); @@ -842,7 +843,7 @@ public class StandbyStateManagementTest { droolsPdpEntity = conn.getPdp(thisPdpId); logger.debug("testHotStandby1: After sm.demote() invoked, DESIGNATED= {} " + "for PDP= {}", droolsPdpEntity.isDesignated(), thisPdpId); - assertTrue(droolsPdpEntity.isDesignated() == true); + assertTrue(droolsPdpEntity.isDesignated()); String standbyStatus = smf.getStandbyStatus(thisPdpId); logger.debug("testHotStandby1: After demotion, PDP= {} " + "has standbyStatus= {}", thisPdpId, standbyStatus); @@ -883,7 +884,7 @@ public class StandbyStateManagementTest { DroolsPdpEntity droolsPdpEntity = conn.getPdp(activePdpId); logger.info("testHotStandby2: After insertion, PDP= {}, which is " + "not current, has DESIGNATED= {}", activePdpId, droolsPdpEntity.isDesignated()); - assertTrue(droolsPdpEntity.isDesignated() == true); + assertTrue(droolsPdpEntity.isDesignated()); /* * Promote the designated PDP. @@ -917,7 +918,7 @@ public class StandbyStateManagementTest { droolsPdpEntity = conn.getPdp(thisPdpId); logger.info("testHotStandby2: After insertion, PDP={} " + "has DESIGNATED= {}", thisPdpId, droolsPdpEntity.isDesignated()); - assertTrue(droolsPdpEntity.isDesignated() == false); + assertFalse(droolsPdpEntity.isDesignated()); // Now we want to create a StateManagementFeature and initialize it. It will be @@ -976,7 +977,7 @@ public class StandbyStateManagementTest { logger.info("testHotStandby2: After demoting PDP={}" + ", DESIGNATED= {}" + " for PDP= {}", activePdpId, droolsPdpEntity.isDesignated(), thisPdpId); - assertTrue(droolsPdpEntity.isDesignated() == true); + assertTrue(droolsPdpEntity.isDesignated()); standbyStatus = sm2.getStandbyStatus(thisPdpId); logger.info("testHotStandby2: After demoting PDP={}" + ", PDP={} has standbyStatus= {}", @@ -1032,7 +1033,7 @@ public class StandbyStateManagementTest { DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId); logger.debug("testLocking1: After insertion, PDP= {} has DESIGNATED= {}", thisPdpId, droolsPdpEntity.isDesignated()); - assertTrue(droolsPdpEntity.isDesignated() == true); + assertTrue(droolsPdpEntity.isDesignated()); logger.debug("testLocking1: Instantiating stateManagement object"); StateManagement smDummy = new StateManagement(emfx, "dummy"); @@ -1237,7 +1238,7 @@ public class StandbyStateManagementTest { DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId); logger.debug("testLocking2: After insertion, PDP= {} has DESIGNATED= {}", thisPdpId, droolsPdpEntity.isDesignated()); - assertTrue(droolsPdpEntity.isDesignated() == true); + assertTrue(droolsPdpEntity.isDesignated()); logger.debug("testLocking2: Instantiating stateManagement object and promoting PDP={}", thisPdpId); StateManagement smDummy = new StateManagement(emfx, "dummy"); @@ -1281,7 +1282,7 @@ public class StandbyStateManagementTest { droolsPdpEntity = conn.getPdp(standbyPdpId); logger.debug("testLocking2: After insertion, PDP={} has DESIGNATED= {}", standbyPdpId, droolsPdpEntity.isDesignated()); - assertTrue(droolsPdpEntity.isDesignated() == false); + assertFalse(droolsPdpEntity.isDesignated()); logger.debug("testLocking2: Demoting PDP= {}", standbyPdpId); final StateManagement sm2 = new StateManagement(emfx, standbyPdpId); @@ -1347,8 +1348,7 @@ public class StandbyStateManagementTest { } logger.debug("testLocking2: Verifying designated status for PDP= {}", standbyPdpId); - boolean standbyPdpDesignated = conn.getPdp(standbyPdpId).isDesignated(); - assertTrue(standbyPdpDesignated == false); + assertFalse(conn.getPdp(standbyPdpId).isDesignated()); logger.debug("\n\ntestLocking2: Exiting\n\n"); } |