Updated thru feature-eelf.
Issue-ID: POLICY-3397
Change-Id: Iad12f5f921374775fb5436cb7d13746256cd6d81
Signed-off-by: Jim Hahn <jrh3@att.com>
* ============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.
@Getter
private static final OrderedServiceImpl<ActiveStandbyFeatureApi> impl =
new OrderedServiceImpl<>(ActiveStandbyFeatureApi.class);
-
- private ActiveStandbyFeatureApiConstants() {
- // do nothing
- }
}
* ============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;
@Getter
private static final OrderedServiceImpl<StateManagementFeatureApi> impl =
new OrderedServiceImpl<>(StateManagementFeatureApi.class);
-
- private StateManagementFeatureApiConstants() {
- // do nothing
- }
}
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);
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.
*
public static String getProperty(String key) {
return properties.getProperty(key);
}
-
- public static Properties getProperties() {
- return properties;
- }
}
* ============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.
//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);
- }
}
* ============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.
//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);
- }
}
* ============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.
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;
// 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,
*/
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
private volatile boolean isDesignated;
+ @Getter
private String pdpdNowActive;
+ @Getter
private String pdpdLastActive;
/*
private final CurrentTime currentTime = MonitorTime.getInstance();
- private static boolean isUnitTesting = false;
- private static boolean isStalled = false;
-
/**
* Constructor.
*
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
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;
}
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(),
}
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;
- }
}
* ============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.
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";
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
* ============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.
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;
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();
}
}
- public String getPreviousStandbyStatus() {
- return previousStandbyStatus;
- }
-
// these may be overridden by junit tests
protected PolicyEngine getPolicyEngineManager() {
* ============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.
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();
Whitebox.setInternalState(MonitorTime.class, MONITOR_FIELD_NAME, saveTime);
Factory.setInstance(saveFactory);
- DroolsPdpsElectionHandler.setIsUnitTesting(false);
+ DroolsPdpsElectionHandler.setUnitTesting(false);
emd.close();
emfd.close();
//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 "
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);