aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2022-02-10 13:34:40 -0600
committerjhh <jorge.hernandez-herrero@att.com>2022-02-10 13:34:40 -0600
commit1bab60c2a752ad50844465d6db1f28b8a8d776ff (patch)
tree0719fc7d89c0c2d1aad5e8432a19b5bc271fa150
parentbeb5cb32f7d1ccb08735ea3d5f77a8b2223857e4 (diff)
remove unused state-management related modules
Issue-ID: POLICY-3922 Signed-off-by: jhh <jorge.hernandez-herrero@att.com> Change-Id: Ie8164a482cce4598c621b58af612ab3a45d848ae
-rw-r--r--api-active-standby-management/pom.xml44
-rw-r--r--api-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeatureApi.java54
-rw-r--r--api-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeatureApiConstants.java37
-rw-r--r--api-state-management/pom.xml54
-rw-r--r--api-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeatureApi.java173
-rw-r--r--api-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeatureApiConstants.java69
-rw-r--r--feature-active-standby-management/pom.xml148
-rw-r--r--feature-active-standby-management/src/assembly/assemble_zip.xml76
-rw-r--r--feature-active-standby-management/src/main/feature/config/feature-active-standby-management.properties40
-rw-r--r--feature-active-standby-management/src/main/feature/db/activestandbymanagement/sql/18020-activestandbymanagement.upgrade.sql34
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeature.java227
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyProperties.java76
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdp.java50
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpEntity.java79
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpImpl.java58
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpObject.java83
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsConnector.java64
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java973
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/Factory.java40
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/JpaDroolsPdpsConnector.java565
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/PmStandbyStateChangeNotifier.java310
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ThreadRunningChecker.java27
-rw-r--r--feature-active-standby-management/src/main/resources/META-INF/persistence.xml35
-rw-r--r--feature-active-standby-management/src/main/resources/META-INF/services/org.onap.policy.drools.activestandby.ActiveStandbyFeatureApi1
-rw-r--r--feature-active-standby-management/src/main/resources/META-INF/services/org.onap.policy.drools.core.PolicySessionFeatureApi1
-rw-r--r--feature-active-standby-management/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyEngineFeatureApi1
-rw-r--r--feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/ActiveStandbyPropertiesTest.java53
-rw-r--r--feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/AllSeemsWellTest.java379
-rw-r--r--feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/DroolsPdpObjectTest.java169
-rw-r--r--feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/FactoryTest.java65
-rw-r--r--feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/PmStandbyStateChangeNotifierTest.java284
-rw-r--r--feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/StandbyStateManagementTest.java1378
-rw-r--r--feature-active-standby-management/src/test/resources/META-INF/persistence.xml48
-rw-r--r--feature-active-standby-management/src/test/resources/asw/feature-active-standby-management.properties40
-rw-r--r--feature-active-standby-management/src/test/resources/asw/feature-state-management.properties82
-rw-r--r--feature-active-standby-management/src/test/resources/feature-active-standby-management.properties39
-rw-r--r--feature-active-standby-management/src/test/resources/feature-state-management.properties83
-rw-r--r--feature-active-standby-management/src/test/resources/logback-test.xml49
-rw-r--r--feature-state-management/.gitignore1
-rw-r--r--feature-state-management/pom.xml127
-rw-r--r--feature-state-management/src/assembly/assemble_zip.xml76
-rw-r--r--feature-state-management/src/main/feature/config/feature-state-management.properties90
-rw-r--r--feature-state-management/src/main/feature/db/statemanagement/sql/18020-statemanagement.upgrade.sql74
-rw-r--r--feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java228
-rw-r--r--feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPdpIntegrityMonitor.java413
-rw-r--r--feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/IntegrityMonitorRestManager.java110
-rw-r--r--feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java559
-rw-r--r--feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeature.java256
-rw-r--r--feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementProperties.java93
-rw-r--r--feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementPropertiesException.java42
-rw-r--r--feature-state-management/src/main/resources/META-INF/services/org.onap.policy.drools.core.PolicySessionFeatureApi1
-rw-r--r--feature-state-management/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyEngineFeatureApi1
-rw-r--r--feature-state-management/src/main/resources/META-INF/services/org.onap.policy.drools.statemanagement.StateManagementFeatureApi1
-rw-r--r--feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/Audit.java42
-rw-r--r--feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java257
-rw-r--r--feature-state-management/src/test/resources/META-INF/persistence.xml50
-rw-r--r--feature-state-management/src/test/resources/feature-state-management.properties87
-rw-r--r--feature-state-management/src/test/resources/logback-test.xml50
-rw-r--r--packages/install/pom.xml14
-rw-r--r--pom.xml6
60 files changed, 2 insertions, 8564 deletions
diff --git a/api-active-standby-management/pom.xml b/api-active-standby-management/pom.xml
deleted file mode 100644
index 8afd7ef2..00000000
--- a/api-active-standby-management/pom.xml
+++ /dev/null
@@ -1,44 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- ECOMP Policy Engine - Drools PDP
- ================================================================================
- 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.
- 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.
- See the License for the specific language governing permissions and
- limitations under the License.
- ============LICENSE_END=========================================================
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>drools-pdp</artifactId>
- <version>1.10.1-SNAPSHOT</version>
- </parent>
-
- <artifactId>api-active-standby-management</artifactId>
-
- <name>api-active-standby-management</name>
- <description>API for Active Standby Management feature</description>
-
- <dependencies>
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>policy-management</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
- </dependencies>
-</project>
diff --git a/api-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeatureApi.java b/api-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeatureApi.java
deleted file mode 100644
index 751ca28f..00000000
--- a/api-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeatureApi.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * api-active-standby-management
- * ================================================================================
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.activestandby;
-
-import org.onap.policy.common.utils.services.OrderedService;
-
-/**
- * This interface provides a way to invoke optional features at various points in the code. At
- * appropriate points in the application, the code iterates through this list, invoking these
- * optional methods.
- */
-public interface ActiveStandbyFeatureApi extends OrderedService {
-
- /**
- * Returns the resourceName (PDP ID) for the Drools-PDP that is
- * currently designated as active.
- *
- * @return String (resourceName)
- */
- String getPdpdNowActive();
-
- /**
- * Returns the resourceName (PDP ID) for the Drools-PDP that is
- * previously designated as active.
- *
- * @return String (resourceName)
- */
- String getPdpdLastActive();
-
- /**
- * Returns the resourceName associated with this instance of the feature.
- *
- * @return String (resourceName)
- */
- String getResourceName();
-}
diff --git a/api-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeatureApiConstants.java b/api-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeatureApiConstants.java
deleted file mode 100644
index 9047739c..00000000
--- a/api-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeatureApiConstants.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * api-active-standby-management
- * ================================================================================
- * 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.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.activestandby;
-
-import lombok.AccessLevel;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import org.onap.policy.common.utils.services.OrderedServiceImpl;
-
-@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);
-}
diff --git a/api-state-management/pom.xml b/api-state-management/pom.xml
deleted file mode 100644
index 419208dd..00000000
--- a/api-state-management/pom.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- ONAP Policy Engine - Drools PDP
- ================================================================================
- 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.
- 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.
- See the License for the specific language governing permissions and
- limitations under the License.
- ============LICENSE_END=========================================================
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>drools-pdp</artifactId>
- <version>1.10.1-SNAPSHOT</version>
- </parent>
-
- <artifactId>api-state-management</artifactId>
-
- <name>api-state-management</name>
- <description>Separately loadable module for state management APIe</description>
-
- <dependencies>
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>policy-core</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.onap.policy.common</groupId>
- <artifactId>integrity-monitor</artifactId>
- <version>${policy.common.version}</version>
- </dependency>
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- <scope>provided</scope>
- </dependency>
- </dependencies>
-</project>
diff --git a/api-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeatureApi.java b/api-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeatureApi.java
deleted file mode 100644
index c4ba8622..00000000
--- a/api-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeatureApi.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * policy-core
- * ================================================================================
- * Copyright (C) 2017-2020 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.statemanagement;
-
-import javax.validation.constraints.NotNull;
-import org.onap.policy.common.capabilities.Lockable;
-import org.onap.policy.common.im.AllSeemsWellException;
-import org.onap.policy.common.im.IntegrityMonitorException;
-import org.onap.policy.common.im.StateChangeNotifier;
-import org.onap.policy.common.im.StateManagementException;
-import org.onap.policy.common.utils.services.OrderedService;
-
-/**
- * This interface provides a way to invoke optional features at various points in the code. At
- * appropriate points in the application, the code iterates through this list, invoking these
- * optional methods. Most of the methods here are notification only -- these tend to return a 'void'
- * value. In other cases, such as 'activatePolicySession', may
- */
-public interface StateManagementFeatureApi extends OrderedService, Lockable {
-
- /**
- * ALL SEEMS/NOT WELL This interface is used to support the concept of All Seems/Not Well. It
- * provides a way for client code to indicate to the DroolsPDPIntegrityMonitor that an event has
- * occurred which is disabling (or enabling) for the Drools PDP. The call is actually
- * implemented in the common modules IntegrityMonitor where it will cause the testTransaction to
- * fail if any module has set the value ALLNOTWELL, stopping the forward progress counter and
- * eventually causing the operational state to become disabled.
- *
- * <p>ALLSEEMSWELL is passed to the method when the client is healthy ALLNOTWELL is passed to the
- * method when the client is disabled
- *
- * @param key - This should be a unique identifier for the entity making the call (e.g., class
- * name)
- * @param asw - This is the indicator of health. See constants: ALLSEEMSWELL or ALLNOTWELL
- * @param msg - A message is required. It should indicate why all is not well or a message
- * indicating that a component has been restored to health (perhaps indicating the
- * problem that has resolved).
- * @throws AllSeemsWellException exception
- */
- void allSeemsWell(@NotNull String key, @NotNull Boolean asw, @NotNull String msg)
- throws AllSeemsWellException;
-
- /**
- * This method is called to add an Observer to receive notifications of state changes.
- *
- * @param stateChangeObserver observer
- */
- void addObserver(StateChangeNotifier stateChangeObserver);
-
- /**
- * Returns the X.731 Administrative State for this resource.
- *
- * @return String (locked, unlocked)
- */
- String getAdminState();
-
- /**
- * Returns the X.731 Operational State for this resource.
- *
- * @return String (enabled, disabled)
- */
- String getOpState();
-
- /**
- * Returns the X.731 Availability Status for this resource.
- *
- * @return String (failed; dependency; dependency,failed)
- */
- String getAvailStatus();
-
- /**
- * Returns the X.731 Standby Status for this resource.
- *
- * @return String (providingservice, hotstandby or coldstandby)
- */
- String getStandbyStatus();
-
- /**
- * Returns the X.731 Standby Status for the named resource
- *
- * @param resourceName the resource name
- * @return String (providingservice, hotstandby or coldstandby)
- */
- String getStandbyStatus(String resourceName);
-
- /**
- * This method moves the X.731 Operational State for the named resource into a value of disabled
- * and the Availability Status to a value of failed. As a consequence the Standby Status value
- * will take a value of coldstandby.
- *
- * @param resourceName resource name
- * @throws StateManagementException exception
- */
- void disableFailed(String resourceName) throws StateManagementException;
-
- /**
- * This method moves the X.731 Operational State for this resource into a value of disabled and
- * the Availability Status to a value of failed. As a consequence the Standby Status value will
- * take a value of coldstandby.
- *
- * @throws StateManagementException exception
- */
- void disableFailed() throws StateManagementException;
-
- /**
- * This method moves the X.731 Standby Status for this resource from hotstandby to
- * providingservice. If the current value is coldstandby, no change is made. If the current
- * value is null, it will move to providingservice assuming the Operational State is enabled and
- * Administrative State is unlocked.
- *
- * @throws IntegrityMonitorException exception
- */
- void promote() throws IntegrityMonitorException;
-
- /**
- * This method moves the X.731 Standby Status for this resource from providingservice to
- * hotstandby. If the current value is null, it will move to hotstandby assuming the Operational
- * State is enabled and Administrative State is unlocked. Else, it will move to coldstandby
- *
- * @throws StateManagementException exception
- */
- void demote() throws StateManagementException;
-
- /**
- * Returns the resourceName associated with this instance of the
- * StateManagementFeature.
- *
- * @return String (resourceName)
- */
- String getResourceName();
-
- /**
- * This Lockable method will lock the StateManagement object Admin state.
- *
- * @return true if successful, false otherwise
- */
- @Override
- boolean lock();
-
- /**
- * This Lockable method will unlock the StateManagement object Admin state.
- *
- * @return true if successfull, false otherwise
- */
- @Override
- boolean unlock();
-
- /**
- * This Lockable method indicates the Admin state StateManagement object.
- *
- * @return true if locked, false otherwise
- */
- @Override
- boolean isLocked();
-}
diff --git a/api-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeatureApiConstants.java b/api-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeatureApiConstants.java
deleted file mode 100644
index 04e6011e..00000000
--- a/api-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeatureApiConstants.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * policy-core
- * ================================================================================
- * 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.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-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;
-
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class StateManagementFeatureApiConstants {
-
- public static final String LOCKED = StateManagement.LOCKED;
- public static final String UNLOCKED = StateManagement.UNLOCKED;
- public static final String ENABLED = StateManagement.ENABLED;
- public static final String DISABLED = StateManagement.DISABLED;
- public static final String ENABLE_NOT_FAILED = StateManagement.ENABLE_NOT_FAILED_ACTION;
- public static final String DISABLE_FAILED = StateManagement.DISABLE_FAILED_ACTION;
- public static final String FAILED = StateManagement.FAILED;
- public static final String DEPENDENCY = StateManagement.DEPENDENCY;
- public static final String DEPENDENCY_FAILED = StateManagement.DEPENDENCY_FAILED;
- public static final String DISABLE_DEPENDENCY = StateManagement.DISABLE_DEPENDENCY_ACTION;
- public static final String ENABLE_NO_DEPENDENCY = StateManagement.ENABLE_NO_DEPENDENCY_ACTION;
- public static final String NULL_VALUE = StateManagement.NULL_VALUE;
- public static final String DO_LOCK = StateManagement.LOCK_ACTION;
- public static final String DO_UNLOCK = StateManagement.UNLOCK_ACTION;
- public static final String DO_PROMOTE = StateManagement.PROMOTE_ACTION;
- public static final String DO_DEMOTE = StateManagement.DEMOTE_ACTION;
- public static final String HOT_STANDBY = StateManagement.HOT_STANDBY;
- public static final String COLD_STANDBY = StateManagement.COLD_STANDBY;
- public static final String PROVIDING_SERVICE = StateManagement.PROVIDING_SERVICE;
-
- public static final String ADMIN_STATE = StateManagement.ADMIN_STATE;
- public static final String OPERATION_STATE = StateManagement.OPERATION_STATE;
- public static final String AVAILABLE_STATUS = StateManagement.AVAILABLE_STATUS;
- public static final String STANDBY_STATUS = StateManagement.STANDBY_STATUS;
-
- public static final Boolean ALLSEEMSWELL_STATE = Boolean.TRUE;
- public static final Boolean ALLNOTWELL_STATE = Boolean.FALSE;
-
- public static final int SEQ_NUM = 0;
-
- /**
- * 'FeatureAPI.impl.getList()' returns an ordered list of objects implementing the 'FeatureAPI'
- * interface.
- */
- @Getter
- private static final OrderedServiceImpl<StateManagementFeatureApi> impl =
- new OrderedServiceImpl<>(StateManagementFeatureApi.class);
-}
diff --git a/feature-active-standby-management/pom.xml b/feature-active-standby-management/pom.xml
deleted file mode 100644
index 9eb4ad75..00000000
--- a/feature-active-standby-management/pom.xml
+++ /dev/null
@@ -1,148 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- feature-active-standby-management
- ================================================================================
- 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.
- 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.
- See the License for the specific language governing permissions and
- limitations under the License.
- ============LICENSE_END=========================================================
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>drools-pdp</artifactId>
- <version>1.10.1-SNAPSHOT</version>
- </parent>
-
- <artifactId>feature-active-standby-management</artifactId>
-
- <name>feature-active-standby-management</name>
- <description>Separately loadable module for managing active-standby behavior</description>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <executions>
- <execution>
- <id>zipfile</id>
- <goals>
- <goal>single</goal>
- </goals>
- <phase>package</phase>
- <configuration>
- <attach>true</attach>
- <finalName>${project.artifactId}-${project.version}</finalName>
- <descriptors>
- <descriptor>src/assembly/assemble_zip.xml</descriptor>
- </descriptors>
- <appendAssemblyId>false</appendAssemblyId>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <execution>
- <id>copy-dependencies</id>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- <phase>prepare-package</phase>
- <configuration>
- <transitive>false</transitive>
- <outputDirectory>${project.build.directory}/assembly/lib</outputDirectory>
- <overWriteReleases>false</overWriteReleases>
- <overWriteSnapshots>true</overWriteSnapshots>
- <overWriteIfNewer>true</overWriteIfNewer>
- <useRepositoryLayout>false</useRepositoryLayout>
- <addParentPoms>false</addParentPoms>
- <copyPom>false</copyPom>
- <includeScope>runtime</includeScope>
- <excludeTransitive>true</excludeTransitive>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>policy-core</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>policy-management</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.eclipse.persistence</groupId>
- <artifactId>eclipselink</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>api-active-standby-management</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>api-state-management</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>feature-state-management</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.onap.policy.common</groupId>
- <artifactId>utils-test</artifactId>
- <version>${policy.common.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.assertj</groupId>
- <artifactId>assertj-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito2</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
-</project>
diff --git a/feature-active-standby-management/src/assembly/assemble_zip.xml b/feature-active-standby-management/src/assembly/assemble_zip.xml
deleted file mode 100644
index 97b82ac2..00000000
--- a/feature-active-standby-management/src/assembly/assemble_zip.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- feature-active-standby- management
- ================================================================================
- Copyright (C) 2017 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.
- See the License for the specific language governing permissions and
- limitations under the License.
- ============LICENSE_END=========================================================
- -->
-
-<!-- Defines how we build the .zip file which is our distribution. -->
-
-<assembly
- xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
- <id>feature-active-standby-management</id>
- <formats>
- <format>zip</format>
- </formats>
-
- <!-- we want "system" and related files right at the root level as this
- file is suppose to be unzip on top of a karaf distro. -->
- <includeBaseDirectory>false</includeBaseDirectory>
-
- <fileSets>
- <fileSet>
- <directory>target</directory>
- <outputDirectory>lib/feature</outputDirectory>
- <includes>
- <include>feature-active-standby-management-${project.version}.jar</include>
- </includes>
- </fileSet>
- <fileSet>
- <directory>target/assembly/lib</directory>
- <outputDirectory>lib/dependencies</outputDirectory>
- <includes>
- <include>*.jar</include>
- </includes>
- </fileSet>
- <fileSet>
- <directory>src/main/feature/config</directory>
- <outputDirectory>config</outputDirectory>
- <fileMode>0644</fileMode>
- <excludes/>
- </fileSet>
- <fileSet>
- <directory>src/main/feature/bin</directory>
- <outputDirectory>bin</outputDirectory>
- <fileMode>0744</fileMode>
- <excludes/>
- </fileSet>
- <fileSet>
- <directory>src/main/feature/db</directory>
- <outputDirectory>db</outputDirectory>
- <fileMode>0744</fileMode>
- <excludes/>
- </fileSet>
- <fileSet>
- <directory>src/main/feature/install</directory>
- <outputDirectory>install</outputDirectory>
- <fileMode>0744</fileMode>
- <excludes/>
- </fileSet>
- </fileSets>
-</assembly>
diff --git a/feature-active-standby-management/src/main/feature/config/feature-active-standby-management.properties b/feature-active-standby-management/src/main/feature/config/feature-active-standby-management.properties
deleted file mode 100644
index f5fe1c70..00000000
--- a/feature-active-standby-management/src/main/feature/config/feature-active-standby-management.properties
+++ /dev/null
@@ -1,40 +0,0 @@
-###
-# ============LICENSE_START=======================================================
-# feature-active-standby-management
-# ================================================================================
-# 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.
-# 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.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-# ============LICENSE_END=========================================================
-###
-
-# DB properties
-eclipselink.target-database=MySQL
-javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver
-javax.persistence.jdbc.url=jdbc:mariadb://${envd:SQL_HOST}:${envd:SQL_PORT:3306}/activestandbymanagement
-javax.persistence.jdbc.user=${envd:SQL_USER}
-javax.persistence.jdbc.password=${envd:SQL_PASSWORD}
-
-# Must be unique across the system
-resource.name=pdp1
-# Name of the site in which this node is hosted
-site_name=site1
-
-# Needed by DroolsPdpsElectionHandler
-pdp.checkInterval=2500
-pdp.updateInterval=2500
-#pdp.timeout=3000
-# Need long timeout, because testTransaction is only run every 10 seconds.
-pdp.timeout=15000
-#how long do we wait for the pdp table to populate on initial startup
-pdp.initialWait=20000
diff --git a/feature-active-standby-management/src/main/feature/db/activestandbymanagement/sql/18020-activestandbymanagement.upgrade.sql b/feature-active-standby-management/src/main/feature/db/activestandbymanagement/sql/18020-activestandbymanagement.upgrade.sql
deleted file mode 100644
index 4b3375ad..00000000
--- a/feature-active-standby-management/src/main/feature/db/activestandbymanagement/sql/18020-activestandbymanagement.upgrade.sql
+++ /dev/null
@@ -1,34 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * feature-active-standby-management
- * ================================================================================
- * Copyright (C) 2017 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-set foreign_key_checks=0;
-
-CREATE TABLE if not exists activestandbymanagement.DROOLSPDPENTITY
-(
-pdpId VARCHAR(255) NOT NULL,
-designated TINYINT(1) default 0 NOT NULL,
-priority INTEGER NOT NULL,
-site VARCHAR(50),
-updatedDate TIMESTAMP NOT NULL,
-designatedDate TIMESTAMP NOT NULL,
-PRIMARY KEY (pdpId)
-);
-
-set foreign_key_checks=1; \ No newline at end of file
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeature.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeature.java
deleted file mode 100644
index e3125a5f..00000000
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeature.java
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * feature-active-standby-management
- * ================================================================================
- * 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.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.activestandby;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import javax.persistence.Persistence;
-import org.eclipse.persistence.config.PersistenceUnitProperties;
-import org.onap.policy.common.im.MonitorTime;
-import org.onap.policy.drools.core.PolicySessionFeatureApi;
-import org.onap.policy.drools.features.PolicyEngineFeatureApi;
-import org.onap.policy.drools.statemanagement.StateManagementFeatureApi;
-import org.onap.policy.drools.statemanagement.StateManagementFeatureApiConstants;
-import org.onap.policy.drools.system.PolicyEngine;
-import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.drools.utils.PropertyUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * If this feature is supported, there is a single instance of it.
- * It adds persistence to Drools sessions, but it is also intertwined with
- * active/standby state management and IntegrityMonitor. For now, they are
- * all treated as a single feature, but it would be nice to separate them.
- *
- * <p>The bulk of the code here was once in other classes, such as
- * 'PolicyContainer' and 'Main'. It was moved here as part of making this
- * a separate optional feature.
- */
-public class ActiveStandbyFeature implements ActiveStandbyFeatureApi,
- PolicySessionFeatureApi, PolicyEngineFeatureApi {
- // get an instance of logger
- private static final Logger logger =
- LoggerFactory.getLogger(ActiveStandbyFeature.class);
-
- private static DroolsPdp myPdp;
- private static Object myPdpSync = new Object();
- private static DroolsPdpsElectionHandler electionHandler;
-
- private StateManagementFeatureApi stateManagementFeature;
-
- public static final int SEQ_NUM = 1;
-
-
- /*========================*/
- /* 'FeatureAPI' interface */
- /*========================*/
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public int getSequenceNumber() {
- return SEQ_NUM;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void globalInit(String[] args, String configDir) {
- // This must come first since it initializes myPdp
- initializePersistence(configDir);
-
- for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- if (feature.getResourceName().equals(myPdp.getPdpId())) {
- logger.debug("ActiveStandbyFeature.globalInit: Found StateManagementFeature"
- + " with resourceName: {}", myPdp.getPdpId());
- stateManagementFeature = feature;
- break;
- }
- }
- if (stateManagementFeature == null) {
- logger.debug("ActiveStandbyFeature failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: {}", myPdp.getPdpId());
- logger.error("ActiveStandbyFeature failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: {}", myPdp.getPdpId());
- //
- // Cannot add observer since stateManagementFeature is null
- //
- return;
- }
-
-
-
- //Create an instance of the Observer
- var pmNotifier = new PmStandbyStateChangeNotifier();
-
- //Register the PMStandbyStateChangeNotifier Observer
- stateManagementFeature.addObserver(pmNotifier);
- logger.debug("ActiveStandbyFeature.globalInit() exit");
- }
-
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public boolean afterStart(PolicyEngine engine) {
- // ASSERTION: engine == PolicyEngine.manager
- PolicyEngineConstants.getManager().lock();
- return false;
- }
-
- /**
- * Read in the persistence properties, determine whether persistence is
- * enabled or disabled, and initialize persistence if enabled.
- */
- private static void initializePersistence(String configDir) {
- //Get the Active Standby properties
- try {
- var activeStandbyProperties =
- PropertyUtil.getProperties(configDir + "/feature-active-standby-management.properties");
- ActiveStandbyProperties.initProperties(activeStandbyProperties);
- logger.info("initializePersistence: ActiveStandbyProperties success");
- } catch (IOException e) {
- logger.error("ActiveStandbyFeature: initializePersistence ActiveStandbyProperties", e);
- }
-
- var conn = getDroolsPdpsConnector("activeStandbyPU");
- String resourceName = ActiveStandbyProperties.getProperty(ActiveStandbyProperties.NODE_NAME);
- if (resourceName == null) {
- throw new NullPointerException();
- }
-
- /*
- * In a JUnit test environment, one or more PDPs may already have been
- * inserted in the DB, so we need to check for this.
- */
- DroolsPdp existingPdp = conn.getPdp(resourceName);
- if (existingPdp != null) {
- logger.info("Found existing PDP record, pdpId={} isDesignated={}, updatedDate={}",
- existingPdp.getPdpId(), existingPdp.isDesignated(), existingPdp.getUpdatedDate());
- myPdp = existingPdp;
- }
-
- synchronized (myPdpSync) {
- if (myPdp == null) {
-
- myPdp = new DroolsPdpImpl(resourceName, false, 4, MonitorTime.getInstance().getDate());
- }
- String siteName = ActiveStandbyProperties.getProperty(ActiveStandbyProperties.SITE_NAME);
- if (siteName == null) {
- siteName = "";
- } else {
- siteName = siteName.trim();
- }
- myPdp.setSite(siteName);
- if (electionHandler == null) {
- electionHandler = new DroolsPdpsElectionHandler(conn, myPdp);
- }
- }
- logger.info("\n\nThis controller is a standby, waiting to be chosen as primary...\n\n");
- }
-
-
- /**
- * Moved code to instantiate a JpaDroolsPdpsConnector object from main() to
- * this method, so it can also be accessed from StandbyStateChangeNotifier
- * class.
- *
- * @param pu string
- * @return connector object
- */
- public static DroolsPdpsConnector getDroolsPdpsConnector(String pu) {
-
- Map<String, Object> propMap = new HashMap<>();
- propMap.put(PersistenceUnitProperties.JDBC_DRIVER,
- ActiveStandbyProperties.getProperty(ActiveStandbyProperties.DB_DRIVER));
- propMap.put(PersistenceUnitProperties.JDBC_URL,
- ActiveStandbyProperties.getProperty(ActiveStandbyProperties.DB_URL));
- propMap.put(PersistenceUnitProperties.JDBC_USER,
- ActiveStandbyProperties.getProperty(ActiveStandbyProperties.DB_USER));
- propMap.put(PersistenceUnitProperties.JDBC_PASSWORD,
- ActiveStandbyProperties.getProperty(ActiveStandbyProperties.DB_PWD));
- propMap.put(PersistenceUnitProperties.TARGET_DATABASE,
- ActiveStandbyProperties.getProperty(ActiveStandbyProperties.DB_TYPE));
-
- var emf = Persistence.createEntityManagerFactory(pu, propMap);
- return new JpaDroolsPdpsConnector(emf);
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public String getPdpdNowActive() {
- return electionHandler.getPdpdNowActive();
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public String getPdpdLastActive() {
- return electionHandler.getPdpdLastActive();
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public String getResourceName() {
- return myPdp.getPdpId();
- }
-}
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
deleted file mode 100644
index 30c8171e..00000000
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyProperties.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * feature-active-standby-management
- * ================================================================================
- * 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.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-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;
-
-@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 PDP_CHECK_INVERVAL = "pdp.checkInterval";
- public static final String PDP_UPDATE_INTERVAL = "pdp.updateInterval";
- public static final String PDP_TIMEOUT = "pdp.timeout";
- public static final String PDP_INITIAL_WAIT_PERIOD = "pdp.initialWait";
-
- public static final String NODE_NAME = "resource.name";
- public static final String SITE_NAME = "site_name";
-
- /*
- * feature-active-standby-management.properties parameter key values
- */
- public static final String DB_DRIVER = PersistenceUnitProperties.JDBC_DRIVER;
- public static final String DB_URL = PersistenceUnitProperties.JDBC_URL;
- public static final String DB_USER = PersistenceUnitProperties.JDBC_USER;
- public static final String DB_PWD = PersistenceUnitProperties.JDBC_PASSWORD;
- public static final String DB_TYPE = PersistenceUnitProperties.TARGET_DATABASE;
-
- @Getter
- private static Properties properties = null;
-
- /**
- * Initialize the parameter values from the droolsPersitence.properties file values.
- *
- * <p>This is designed so that the Properties object is obtained from properties
- * file and then is passed to this method to initialize the value of the parameters.
- * This allows the flexibility of JUnit tests using getProperties(filename) to get the
- * properties while runtime methods can use getPropertiesFromClassPath(filename).
- *
- * @param prop properties
- */
- public static void initProperties(Properties prop) {
- logger.info("ActiveStandbyProperties.initProperties(Properties): entry");
- logger.info("\n\nActiveStandbyProperties.initProperties: Properties = \n{}\n\n", prop);
-
- properties = prop;
- }
-
- public static String getProperty(String key) {
- return properties.getProperty(key);
- }
-}
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
deleted file mode 100644
index 12c75929..00000000
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdp.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * feature-active-standby-management
- * ================================================================================
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.activestandby;
-
-import java.util.Date;
-
-public interface DroolsPdp {
-
- String getPdpId();
-
- boolean isDesignated();
-
- int getPriority();
-
- Date getUpdatedDate();
-
- void setDesignated(boolean isDesignated);
-
- void setUpdatedDate(Date updatedDate);
-
- int comparePriority(DroolsPdp other);
-
- int comparePriority(DroolsPdp other, String previousSite);
-
- String getSite();
-
- void setSite(String site);
-
- Date getDesignatedDate();
-
- void setDesignatedDate(Date designatedDate);
-}
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
deleted file mode 100644
index 526200fc..00000000
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpEntity.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * feature-active-standby-management
- * ================================================================================
- * 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.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.activestandby;
-
-import java.io.Serializable;
-import java.util.Date;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.NamedQuery;
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
-import org.onap.policy.common.im.MonitorTime;
-
-@Entity
-//@Table(name="DroolsPdpEntity")
-
-@NamedQuery(name = "DroolsPdpEntity.findAll", query = "SELECT e FROM DroolsPdpEntity e ")
-@NamedQuery(name = "DroolsPdpEntity.deleteAll", query = "DELETE FROM DroolsPdpEntity WHERE 1=1")
-@Getter
-@Setter
-@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = true)
-public class DroolsPdpEntity extends DroolsPdpObject implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- @Id
- @Column(name = "pdpId", nullable = false)
- private String pdpId = "-1";
-
- @Column(name = "designated", nullable = false)
- private boolean designated = false;
-
- @Column(name = "priority", nullable = false)
- private int priority = 0;
-
- @Temporal(TemporalType.TIMESTAMP)
- @Column(name = "updatedDate", nullable = false)
- private Date updatedDate;
-
- @Temporal(TemporalType.TIMESTAMP)
- @Column(name = "designatedDate", nullable = false)
- private Date designatedDate;
-
- @Column(name = "site", nullable = true, length = 50)
- private String site;
-
- /**
- * Constructor.
- */
- public DroolsPdpEntity() {
- updatedDate = MonitorTime.getInstance().getDate();
- //When this is translated to a TimeStamp in MySQL, it assumes the date is relative
- //to the local timezone. So, a value of Date(0) is actually Dec 31 18:00:00 CST 1969
- //which is an invalid value for the MySql TimeStamp
- designatedDate = new Date(864000000);
- }
-}
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
deleted file mode 100644
index dac35ea3..00000000
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpImpl.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * feature-active-standby-management
- * ================================================================================
- * 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.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.activestandby;
-
-import java.util.Date;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
-
-@Getter
-@Setter
-@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = true)
-public class DroolsPdpImpl extends DroolsPdpObject {
-
- private boolean designated;
- private int priority;
- private Date updatedDate;
- private Date designatedDate;
- private String pdpId;
- private String site;
-
- /**
- * Contructor.
- *
- * @param pdpId ID for the PDP
- * @param designated is designated
- * @param priority priority
- * @param updatedDate date updated
- */
- public DroolsPdpImpl(String pdpId, boolean designated, int priority, Date updatedDate) {
- this.pdpId = pdpId;
- this.designated = designated;
- this.priority = priority;
- this.updatedDate = updatedDate;
- //When this is translated to a TimeStamp in MySQL, it assumes the date is relative
- //to the local timezone. So, a value of Date(0) is actually Dec 31 18:00:00 CST 1969
- //which is an invalid value for the MySql TimeStamp
- this.designatedDate = new Date(864000000);
- }
-}
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpObject.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpObject.java
deleted file mode 100644
index c8971130..00000000
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpObject.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * feature-active-standby-management
- * ================================================================================
- * 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.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.activestandby;
-
-
-public abstract class DroolsPdpObject implements DroolsPdp {
-
- @Override
- public boolean equals(Object other) {
- if (other instanceof DroolsPdp) {
- return this.getPdpId().equals(((DroolsPdp) other).getPdpId());
- } else {
- return false;
- }
- }
-
- @Override
- public int hashCode() {
- final var prime = 31;
- var result = 1;
- result = prime * result + (this.getPdpId() == null ? 0 : this.getPdpId().hashCode());
- return result;
- }
-
- private int nullSafeCompare(String one, String two) {
- if (one != null) {
- if (two != null) {
- return one.compareTo(two);
-
- } else {
- return 1;
- }
-
- } else if (two != null) {
- return -1;
-
- } else {
- return 0;
- }
- }
-
- @Override
- public int comparePriority(DroolsPdp other) {
- return commonCompare(other);
- }
-
- @Override
- public int comparePriority(DroolsPdp other, String previousSite) {
- if (previousSite == null || previousSite.isEmpty()) {
- return comparePriority(other);
- }
- return commonCompare(other);
- }
-
- private int commonCompare(DroolsPdp other) {
- if (nullSafeCompare(this.getSite(), other.getSite()) == 0) {
- if (this.getPriority() != other.getPriority()) {
- return this.getPriority() - other.getPriority();
- }
- return this.getPdpId().compareTo(other.getPdpId());
- } else {
- return nullSafeCompare(this.getSite(), other.getSite());
- }
- }
-}
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
deleted file mode 100644
index 6e06272c..00000000
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsConnector.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * feature-active-standby-management
- * ================================================================================
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.activestandby;
-
-import java.util.Collection;
-
-public interface DroolsPdpsConnector {
-
-
- //return a list of PDPs, NOT including this PDP
- Collection<DroolsPdp> getDroolsPdps();
-
- void update(DroolsPdp pdp);
-
- //determines if the DroolsPdp parameter is considered "current" or expired
- //(has it been too long since the Pdp sent an update)
- boolean isPdpCurrent(DroolsPdp pdp);
-
- // Updates DESIGNATED boolean in PDP record.
- void setDesignated(DroolsPdp pdp, boolean designated);
-
- // Marks droolspdpentity.DESIGNATED=false, so another PDP-D will go active.
- void standDownPdp(String pdpId);
-
- // This is used in a JUnit test environment to manually
- // insert a PDP
- void insertPdp(DroolsPdp pdp);
-
- // This is used in a JUnit test environment to manually
- // delete a PDP
- void deletePdp(String pdpId);
-
- // This is used in a JUnit test environment to manually
- // clear the droolspdpentity table.
- void deleteAllPdps();
-
- // This is used in a JUnit test environment to manually
- // get a PDP
- DroolsPdpEntity getPdp(String pdpId);
-
- // Used by DroolsPdpsElectionHandler to determine if the currently designated
- // PDP has failed.
- 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
deleted file mode 100644
index ff4b21df..00000000
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java
+++ /dev/null
@@ -1,973 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * feature-active-standby-management
- * ================================================================================
- * 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.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.activestandby;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
-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;
-import org.onap.policy.drools.statemanagement.StateManagementFeatureApi;
-import org.onap.policy.drools.statemanagement.StateManagementFeatureApiConstants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
- private static final String RUN_PRIMARY_MSG = "DesignatedWaiter.run mostRecentPrimary = {}";
-
- // get an instance of logger
- private static final Logger logger = LoggerFactory.getLogger(DroolsPdpsElectionHandler.class);
-
- /*
- * Must be static, so it can be referenced by JpaDroolsPdpsConnector,
- * without requiring a reference to the election handler instantiation.
- */
- 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 int pdpUpdateInterval;
-
- private volatile boolean isDesignated;
-
- @Getter
- private String pdpdNowActive;
- @Getter
- private String pdpdLastActive;
-
- /*
- * Start allSeemsWell with a value of null so that, on the first run
- * of the checkWaitTimer it will set the value in IntegrityMonitor
- * regardless of whether it needs to be set to true or false.
- */
- private Boolean allSeemsWell = null;
-
- private StateManagementFeatureApi stateManagementFeature;
-
- private final CurrentTime currentTime = MonitorTime.getInstance();
-
- /**
- * Constructor.
- *
- * @param pdps connectors
- * @param myPdp pdp
- */
- public DroolsPdpsElectionHandler(DroolsPdpsConnector pdps, DroolsPdp myPdp) {
- if (pdps == null) {
- logger.error("DroolsPdpsElectinHandler(): pdpsConnector==null");
- throw new IllegalArgumentException("DroolsPdpsElectinHandler(): pdpsConnector==null");
- }
- if (myPdp == null) {
- logger.error("DroolsPdpsElectinHandler(): droolsPdp==null");
- throw new IllegalArgumentException("DroolsPdpsElectinHandler(): DroolsPdp==null");
- }
-
- pdpdNowActive = null;
- pdpdLastActive = null;
- this.pdpsConnector = pdps;
- setMyPdp(myPdp);
- this.isDesignated = false;
-
- // The interval between checks of the DesignationWaiter to be sure it is running.
- var 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);
- }
- pdpUpdateInterval = 2000;
- try {
- pdpUpdateInterval = Integer.parseInt(ActiveStandbyProperties.getProperty(
- ActiveStandbyProperties.PDP_UPDATE_INTERVAL));
- } catch (Exception e) {
- logger.error("Could not get pdpUpdateInterval property. Using default {} ", pdpUpdateInterval, e);
- }
-
- var now = currentTime.getDate();
-
- // Retrieve the ms since the epoch
- final long nowMs = now.getTime();
-
- // Create the timer which will update the updateDate in DroolsPdpEntity table.
- // This is the heartbeat
- var 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
- // drools droolsPdpEntity table.
- updateWorker.scheduleAtFixedRate(new TimerUpdateClass(), 100, pdpCheckInterval);
-
- // Create the timer which will run the election algorithm
- var 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();
- var designationWaiter = new DesignationWaiter();
- waitTimer.scheduleAtFixedRate(designationWaiter, startMs, pdpUpdateInterval);
- waitTimerLastRunDate = new Date(nowMs + startMs);
-
- //Get the StateManagementFeature instance
-
- for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- if (feature.getResourceName().equals(myPdp.getPdpId())) {
- logger.debug("DroolsPdpsElectionHandler: Found StateManagementFeature"
- + " with resourceName: {}", myPdp.getPdpId());
- stateManagementFeature = feature;
- break;
- }
- }
- if (stateManagementFeature == null) {
- logger.error("DroolsPdpsElectionHandler failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: {}", myPdp.getPdpId());
- }
- }
-
- private static void setMyPdp(DroolsPdp myPdp) {
- DroolsPdpsElectionHandler.myPdp = myPdp;
- }
-
- /**
- * When the JpaDroolsPdpsConnector.standDown() method is invoked, it needs
- * access to myPdp, so it can keep its designation status in sync with the
- * DB.
- *
- * @param designated is designated value
- */
- public static void setMyPdpDesignated(boolean designated) {
- logger.debug("setMyPdpDesignated: designated= {}", designated);
- myPdp.setDesignated(designated);
- }
-
- private class DesignationWaiter extends TimerTask {
- // get an instance of logger
- private final Logger logger = LoggerFactory.getLogger(DesignationWaiter.class);
-
- @Override
- public void run() {
- try {
- logger.debug("DesignatedWaiter.run: Entering");
-
- //This is for testing the checkWaitTimer
- if (unitTesting && stalled) {
- logger.debug("DesignatedWaiter.run: isUnitTesting = {} isStalled = {}",
- unitTesting, stalled);
- return;
- }
-
- synchronized (designationWaiterLock) {
-
- logger.debug("DesignatedWaiter.run: Entering synchronized block");
-
- //It is possible that multiple PDPs are designated lead. So, we will make a list of all designated
- //PDPs and then decide which one really should be designated at the end.
- List<DroolsPdp> listOfDesignated = new ArrayList<>();
-
- Collection<DroolsPdp> pdps = pdpsConnector.getDroolsPdps();
-
- logger.debug("DesignatedWaiter.run: pdps.size= {}", pdps.size());
-
- //This is only true if all designated PDPs have failed
- allPdpsFailed(pdps, listOfDesignated);
-
- /*
- * We have checked the four combinations of isDesignated and isCurrent. Where appropriate,
- * we added the PDPs to the potential list of designated pdps
- *
- * We need to give priority to pdps on the same site that is currently being used
- * First, however, we must sanitize the list of designated to make sure their are
- * only designated members or non-designated members. There should not be both in
- * the list. Because there are real time delays, it is possible that both types could
- * be on the list.
- */
-
- listOfDesignated = santizeDesignatedList(listOfDesignated);
-
- /*
- * We need to figure out the last pdp that was the primary so we can get the last site
- * name and the last session numbers. We need to create a "dummy" droolspdp since
- * it will be used in later comparisons and cannot be null.
- */
-
- DroolsPdp mostRecentPrimary = computeMostRecentPrimary(pdps, listOfDesignated);
-
- if (mostRecentPrimary != null) {
- pdpdLastActive = mostRecentPrimary.getPdpId();
- }
-
-
- /*
- * It is possible to get here with more than one pdp designated and providing service. This normally
- * occurs when there is a race condition with multiple nodes coming up at the same time. If that is
- * the case we must determine which one is the one that should be designated and which one should
- * be demoted.
- *
- * It is possible to have 0, 1, 2 or more but not all, or all designated.
- * If we have one designated and current, we chose it and are done
- * If we have 2 or more, but not all, we must determine which one is in the same site as
- * the previously designated pdp.
- */
- DroolsPdp designatedPdp = computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
-
- if (designatedPdp == null) {
- logger.warn("WARNING: DesignatedWaiter.run: No viable PDP found to be Designated. "
- + "designatedPdp still null.");
- designateNoPdp();
- return;
- }
-
- pdpdNowActive = designatedPdp.getPdpId();
-
- if (pdpdNowActive.equals(myPdp.getPdpId())) {
- logger.debug("DesignatedWaiter.run: designatedPdp is PDP={}", myPdp.getPdpId());
- designateMyPdp();
- return;
- }
-
- isDesignated = false;
-
- } // end synchronized
- logger.debug("DesignatedWaiter.run: myPdp: {}; Returning, isDesignated= {}",
- isDesignated, myPdp.getPdpId());
-
- var tmpDate = currentTime.getDate();
- logger.debug("DesignatedWaiter.run (end of run) waitTimerLastRunDate = {}", tmpDate);
-
- waitTimerLastRunDate = tmpDate;
- myPdp.setUpdatedDate(waitTimerLastRunDate);
- pdpsConnector.update(myPdp);
-
- } catch (Exception e) {
- logger.error("DesignatedWaiter.run caught an unexpected exception: ", e);
- }
- } // end run
-
- private void allPdpsFailed(Collection<DroolsPdp> pdps, List<DroolsPdp> listOfDesignated) {
- boolean designatedPdpHasFailed = pdpsConnector.hasDesignatedPdpFailed(pdps);
- logger.debug("DesignatedWaiter.run: designatedPdpHasFailed= {}", designatedPdpHasFailed);
- for (DroolsPdp pdp : pdps) {
- logger.debug("DesignatedWaiter.run: evaluating pdp ID: {}", pdp.getPdpId());
-
- /*
- * Note: side effect of isPdpCurrent is that any stale but
- * designated PDPs will be marked as un-designated.
- */
- boolean isCurrent = pdpsConnector.isPdpCurrent(pdp);
-
- /*
- * We can't use stateManagement.getStandbyStatus() here, because
- * we need the standbyStatus, not for this PDP, but for the PDP
- * being processed by this loop iteration.
- */
- String standbyStatus = stateManagementFeature.getStandbyStatus(pdp.getPdpId());
- if (standbyStatus == null) {
- // Treat this case as a cold standby -- if we
- // abort here, no sessions will be created in a
- // single-node test environment.
- standbyStatus = StateManagement.COLD_STANDBY;
- }
- logger.debug("DesignatedWaiter.run: PDP= {}, isCurrent= {}", pdp.getPdpId(), isCurrent);
-
- adjustPdp(pdp, isCurrent, designatedPdpHasFailed, standbyStatus, listOfDesignated);
-
-
- } // end pdps loop
- }
-
- private void adjustPdp(DroolsPdp pdp, boolean isCurrent, boolean designatedPdpHasFailed, String standbyStatus,
- List<DroolsPdp> listOfDesignated) {
- /*
- * There are 4 combinations of isDesignated and isCurrent. We will examine each one in-turn
- * and evaluate the each pdp in the list of pdps against each combination.
- */
- if (pdp.isDesignated()) {
- /*
- * This is the first combination of isDesignated and isCurrent
- */
- if (isCurrent) {
- pdpDesignatedCurrent(pdp, standbyStatus, listOfDesignated);
-
- /*
- * The second combination of isDesignated and isCurrent
- *
- * PDP is designated but not current; it has failed.
- * So we stand it down (it doesn't matter what
- * its standbyStatus is). None of these go on the list.
- */
- } else {
- logger.debug("INFO: DesignatedWaiter.run: PDP= {} is currently "
- + "designated but is not current; "
- + "it has failed. Standing down. standbyStatus= {}",
- pdp.getPdpId(), standbyStatus);
- pdpDesignatedNotCurrent(pdp);
- }
-
- } else {
- // NOT designated
-
-
- /*
- * The third combination of isDesignated and isCurrent
- * /*
- * If a PDP is not currently designated but is providing service
- * (erroneous, but recoverable) or hot standby
- * we can add it to the list of possible designated if all the designated have failed
- */
- if (isCurrent) {
- pdpNotDesignatedCurrent(pdp, designatedPdpHasFailed, standbyStatus,
- listOfDesignated);
-
- /*
- * The fourth combination of isDesignated and isCurrent
- *
- * We are not going to put any of these on the list since it appears they have failed.
- *
- */
- } else {
- logger.debug("INFO: DesignatedWaiter.run: PDP= {} "
- + "designated= {}, current= {}, "
- + "designatedPdpHasFailed= {}, "
- + "standbyStatus= {}", pdp.getPdpId(),
- pdp.isDesignated(), false, designatedPdpHasFailed, standbyStatus);
- pdpNotDesignatedNotCurrent(pdp, standbyStatus);
- }
- }
- }
-
- private void pdpDesignatedCurrent(DroolsPdp pdp, String standbyStatus, List<DroolsPdp> listOfDesignated) {
- //It is current, but it could have a standbystatus=coldstandby / hotstandby
- //If so, we need to stand it down and demote it
- if (!standbyStatus.equals(StateManagement.PROVIDING_SERVICE)) {
- if (pdp.getPdpId().equals(myPdp.getPdpId())) {
- logger.debug("\n\nDesignatedWaiter.run: myPdp {} is current and designated, "
- + "butstandbystatus is not providingservice. "
- + " Executing stateManagement.demote()" + "\n\n", myPdp.getPdpId());
- // So, we must demote it
- try {
- demoteMyPdp(pdp, standbyStatus);
- } catch (Exception e) {
- logger.error("DesignatedWaiter.run: myPdp: {} "
- + "Caught Exception attempting to demote myPdp,"
- + "message= {}", myPdp.getPdpId(), e);
- }
- } else {
- // Don't demote a remote PDP that is current. It should catch itself
- logger.debug("\n\nDesignatedWaiter.run: myPdp {} is current and designated, "
- + "but standbystatus is not providingservice. "
- + " Cannot execute stateManagement.demote() "
- + "since it it is not myPdp\n\n",
- myPdp.getPdpId());
- }
-
- } else {
- // If we get here, it is ok to be on the list
- logger.debug("DesignatedWaiter.run: PDP= {} is designated, "
- + "current and {} Noting PDP as "
- + "designated, standbyStatus= {}",
- pdp.getPdpId(), standbyStatus, standbyStatus);
- listOfDesignated.add(pdp);
- }
- }
-
- private void demoteMyPdp(DroolsPdp pdp, String standbyStatus) throws Exception {
- /*
- * Keep the order like this. StateManagement is last since it triggers
- * controller shutdown. This will change isDesignated and it can enter another
- * if-combination below
- */
- pdpsConnector.standDownPdp(pdp.getPdpId());
- myPdp.setDesignated(false);
- isDesignated = false;
- if (!(standbyStatus.equals(StateManagement.HOT_STANDBY)
- || standbyStatus.equals(StateManagement.COLD_STANDBY))) {
- /*
- * Only demote it if it appears it has not already been demoted. Don't worry
- * about synching with the topic endpoint states. That is done by the
- * refreshStateAudit
- */
- stateManagementFeature.demote();
- }
- }
-
- private void pdpDesignatedNotCurrent(DroolsPdp pdp) {
- /*
- * Changes designated to 0 but it is still potentially providing service.
- * Will affect isDesignated, so, it can enter an if-combination below
- */
- pdpsConnector.standDownPdp(pdp.getPdpId());
-
- //need to change standbystatus to coldstandby
- if (pdp.getPdpId().equals(myPdp.getPdpId())) {
- logger.debug("\n\nDesignatedWaiter.run: myPdp {} is not Current. "
- + " Executing stateManagement.disableFailed()\n\n", myPdp.getPdpId());
- // We found that myPdp is designated but not current
- // So, we must cause it to disableFail
- try {
- myPdp.setDesignated(false);
- pdpsConnector.setDesignated(myPdp, false);
- isDesignated = false;
- stateManagementFeature.disableFailed();
- } catch (Exception e) {
- logger.error("DesignatedWaiter.run: myPdp: {} Caught Exception "
- + "attempting to disableFail myPdp {}, message= {}",
- myPdp.getPdpId(), myPdp.getPdpId(), e);
- }
- } else { //it is a remote PDP that is failed
- logger.debug("\n\nDesignatedWaiter.run: PDP {} is not Current. "
- + " Executing stateManagement.disableFailed(otherResourceName)\n\n",
- pdp.getPdpId());
- // We found a PDP is designated but not current
- // We already called standdown(pdp) which will change designated to false
- // Now we need to disableFail it to get its states in synch. The standbyStatus
- // should equal coldstandby
- try {
- stateManagementFeature.disableFailed(pdp.getPdpId());
- } catch (Exception e) {
- logger.error("DesignatedWaiter.run: for PDP {} Caught Exception attempting to "
- + "disableFail({}), message= {}",
- pdp.getPdpId(), pdp.getPdpId(), e);
- }
-
- }
- }
-
- private void pdpNotDesignatedCurrent(DroolsPdp pdp, boolean designatedPdpHasFailed, String standbyStatus,
- List<DroolsPdp> listOfDesignated) {
- if (!(StateManagement.HOT_STANDBY.equals(standbyStatus)
- || StateManagement.COLD_STANDBY.equals(standbyStatus))) {
- logger.debug("\n\nDesignatedWaiter.run: PDP {}"
- + " is NOT designated but IS current and"
- + " has a standbystatus= {}", pdp.getPdpId(), standbyStatus);
- // Since it is current, we assume it can adjust its own state.
- // We will demote if it is myPdp
- if (pdp.getPdpId().equals(myPdp.getPdpId())) {
- //demote it
- logger.debug("DesignatedWaiter.run: PDP {} going to "
- + "setDesignated = false and calling stateManagement.demote",
- pdp.getPdpId());
- try {
- //Keep the order like this.
- //StateManagement is last since it triggers controller shutdown
- pdpsConnector.setDesignated(myPdp, false);
- myPdp.setDesignated(false);
- isDesignated = false;
- //This is definitely not a redundant call.
- //It is attempting to correct a problem
- stateManagementFeature.demote();
- //recheck the standbystatus
- standbyStatus = stateManagementFeature.getStandbyStatus(pdp.getPdpId());
- } catch (Exception e) {
- logger.error("DesignatedWaiter.run: myPdp: {} Caught Exception "
- + "attempting to demote myPdp {}, message = {}", myPdp.getPdpId(),
- myPdp.getPdpId(), e);
- }
-
- }
- }
- if (StateManagement.HOT_STANDBY.equals(standbyStatus) && designatedPdpHasFailed) {
- //add it to the list
- logger.debug("INFO: DesignatedWaiter.run: PDP= {}"
- + " is not designated but is {} and designated PDP "
- + "has failed. standbyStatus= {}", pdp.getPdpId(),
- standbyStatus, standbyStatus);
- listOfDesignated.add(pdp);
- }
- }
-
- private void pdpNotDesignatedNotCurrent(DroolsPdp pdp, String standbyStatus) {
- if (StateManagement.COLD_STANDBY.equals(standbyStatus)) {
- return;
- }
-
- //stand it down
- //disableFail it
- pdpsConnector.standDownPdp(pdp.getPdpId());
- if (pdp.getPdpId().equals(myPdp.getPdpId())) {
- /*
- * I don't actually know how this condition could
- * happen, but if it did, we would want to declare it
- * failed.
- */
- logger.debug("\n\nDesignatedWaiter.run: myPdp {} is !current and !designated, "
- + " Executing stateManagement.disableFailed()\n\n",
- myPdp.getPdpId());
- // So, we must disableFail it
- try {
- //Keep the order like this.
- //StateManagement is last since it triggers controller shutdown
- pdpsConnector.setDesignated(myPdp, false);
- myPdp.setDesignated(false);
- isDesignated = false;
- stateManagementFeature.disableFailed();
- } catch (Exception e) {
- logger.error("DesignatedWaiter.run: myPdp: {} Caught Exception attempting to "
- + "disableFail myPdp {}, message= {}",
- myPdp.getPdpId(), myPdp.getPdpId(), e);
- }
- } else { //it is remote
- logger.debug("\n\nDesignatedWaiter.run: myPdp {} is !current and !designated, "
- + " Executing stateManagement.disableFailed({})\n\n",
- myPdp.getPdpId(), pdp.getPdpId());
- // We already called standdown(pdp) which will change designated to false
- // Now we need to disableFail it to get its states in sync.
- // StandbyStatus = coldstandby
- try {
- stateManagementFeature.disableFailed(pdp.getPdpId());
- } catch (Exception e) {
- logger.error("DesignatedWaiter.run: for PDP {}"
- + " Caught Exception attempting to disableFail({})"
- + ", message=", pdp.getPdpId(), pdp.getPdpId(), e);
- }
- }
- }
-
- private void designateNoPdp() {
- // Just to be sure the parameters are correctly set
- myPdp.setDesignated(false);
- pdpsConnector.setDesignated(myPdp, false);
- isDesignated = false;
-
- waitTimerLastRunDate = currentTime.getDate();
- logger.debug("DesignatedWaiter.run (designatedPdp == null) waitTimerLastRunDate = {}",
- waitTimerLastRunDate);
- myPdp.setUpdatedDate(waitTimerLastRunDate);
- pdpsConnector.update(myPdp);
- }
-
- private void designateMyPdp() {
- /*
- * update function expects myPdp.isDesignated to be true.
- */
- try {
- //Keep the order like this. StateManagement is last since it triggers controller init
- myPdp.setDesignated(true);
- myPdp.setDesignatedDate(currentTime.getDate());
- pdpsConnector.setDesignated(myPdp, true);
- isDesignated = true;
- String standbyStatus = stateManagementFeature.getStandbyStatus();
- if (!standbyStatus.equals(StateManagement.PROVIDING_SERVICE)) {
- /*
- * Only call promote if it is not already in the right state. Don't worry about
- * synching the lower level topic endpoint states. That is done by the
- * refreshStateAudit.
- */
- stateManagementFeature.promote();
- }
- } catch (Exception e) {
- logger.error("ERROR: DesignatedWaiter.run: Caught Exception attempting to promote PDP={}"
- + ", message=", myPdp.getPdpId(), e);
- myPdp.setDesignated(false);
- pdpsConnector.setDesignated(myPdp, false);
- isDesignated = false;
- //If you can't promote it, demote it
- try {
- String standbyStatus = stateManagementFeature.getStandbyStatus();
- if (!(standbyStatus.equals(StateManagement.HOT_STANDBY)
- || standbyStatus.equals(StateManagement.COLD_STANDBY))) {
- /*
- * Only call demote if it is not already in the right state. Don't worry about
- * synching the lower level topic endpoint states. That is done by the
- * refreshStateAudit.
- */
- stateManagementFeature.demote();
- }
- } catch (Exception e1) {
- logger.error("ERROR: DesignatedWaiter.run: Caught StandbyStatusException "
- + "attempting to promote then demote PDP={}, message=",
- myPdp.getPdpId(), e1);
- }
-
- }
- waitTimerLastRunDate = currentTime.getDate();
- logger.debug("DesignatedWaiter.run (designatedPdp.getPdpId().equals(myPdp.getPdpId())) "
- + "waitTimerLastRunDate = {}", waitTimerLastRunDate);
- myPdp.setUpdatedDate(waitTimerLastRunDate);
- pdpsConnector.update(myPdp);
- }
- }
-
- /**
- * Sanitize designated list.
- *
- * @param listOfDesignated list of designated pdps
- * @return list of drools pdps
- */
- public List<DroolsPdp> santizeDesignatedList(List<DroolsPdp> listOfDesignated) {
-
- var containsDesignated = false;
- var containsHotStandby = false;
- List<DroolsPdp> listForRemoval = new ArrayList<>();
- for (DroolsPdp pdp : listOfDesignated) {
- logger.debug("DesignatedWaiter.run sanitizing: pdp = {}"
- + " isDesignated = {}", pdp.getPdpId(), pdp.isDesignated());
- if (pdp.isDesignated()) {
- containsDesignated = true;
- } else {
- containsHotStandby = true;
- listForRemoval.add(pdp);
- }
- }
- if (containsDesignated && containsHotStandby) {
- //remove the hot standby from the list
- listOfDesignated.removeAll(listForRemoval);
- }
- return listOfDesignated;
- }
-
- /**
- * Compute most recent primary.
- *
- * @param pdps collection of pdps
- * @param listOfDesignated list of designated pdps
- * @return drools pdp object
- */
- public DroolsPdp computeMostRecentPrimary(Collection<DroolsPdp> pdps, List<DroolsPdp> listOfDesignated) {
- boolean containsDesignated = listOfDesignated.stream().anyMatch(DroolsPdp::isDesignated);
-
- DroolsPdp mostRecentPrimary = new DroolsPdpImpl(null, true, 1, new Date(0));
- mostRecentPrimary.setSite(null);
- logger.debug("DesignatedWaiter.run listOfDesignated.size() = {}", listOfDesignated.size());
-
- if (listOfDesignated.size() <= 1) {
- logger.debug("DesignatedWainter.run: listOfDesignated.size <=1");
- //Only one or none is designated or hot standby. Choose the latest designated date
- mostRecentPrimary = getLatestDesignated(pdps, mostRecentPrimary);
-
- } else if (listOfDesignated.size() == pdps.size()) {
- logger.debug("DesignatedWainter.run: listOfDesignated.size = pdps.size() which is {}", pdps.size());
- //They are all designated or all hot standby.
- mostRecentPrimary = getBestDesignated(pdps, containsDesignated);
-
- } else {
- logger.debug("DesignatedWainter.run: Some but not all are designated or hot standby. ");
- logger.debug("DesignatedWainter.run: containsDesignated = {}", containsDesignated);
- //Some but not all are designated or hot standby.
- if (containsDesignated) {
- /*
- * The list only contains designated. This is a problem. It is most likely a race
- * condition that resulted in two thinking they should be designated. Choose the
- * site with the latest designated date for the pdp not included on the designated list.
- * This should be the site that had the last designation before this race condition
- * occurred.
- */
- mostRecentPrimary = getLatestUndesignated(pdps, mostRecentPrimary, listOfDesignated);
-
- } else {
- //The list only contains hot standby. Choose the site of the latest designated date
- mostRecentPrimary = getLatestDesignated(pdps, mostRecentPrimary);
- }
- }
- return mostRecentPrimary;
- }
-
- private DroolsPdp getBestDesignated(Collection<DroolsPdp> pdps, boolean containsDesignated) {
- DroolsPdp mostRecentPrimary;
- mostRecentPrimary = null;
- for (DroolsPdp pdp : pdps) {
- if (mostRecentPrimary == null) {
- mostRecentPrimary = pdp;
- continue;
- }
- if (containsDesignated) { //Choose the site of the first designated date
- if (pdp.getDesignatedDate().compareTo(mostRecentPrimary.getDesignatedDate()) < 0) {
- mostRecentPrimary = pdp;
- logger.debug(RUN_PRIMARY_MSG, mostRecentPrimary.getPdpId());
- }
- } else { //Choose the site with the latest designated date
- if (pdp.getDesignatedDate().compareTo(mostRecentPrimary.getDesignatedDate()) > 0) {
- mostRecentPrimary = pdp;
- logger.debug(RUN_PRIMARY_MSG, mostRecentPrimary.getPdpId());
- }
- }
- }
- return mostRecentPrimary;
- }
-
- private DroolsPdp getLatestUndesignated(Collection<DroolsPdp> pdps, DroolsPdp mostRecentPrimary,
- List<DroolsPdp> listOfDesignated) {
- for (DroolsPdp pdp : pdps) {
- if (listOfDesignated.contains(pdp)) {
- continue; //Don't consider this entry
- }
- if (pdp.getDesignatedDate().compareTo(mostRecentPrimary.getDesignatedDate()) > 0) {
- mostRecentPrimary = pdp;
- logger.debug(RUN_PRIMARY_MSG, mostRecentPrimary.getPdpId());
- }
- }
- return mostRecentPrimary;
- }
-
- private DroolsPdp getLatestDesignated(Collection<DroolsPdp> pdps, DroolsPdp mostRecentPrimary) {
- for (DroolsPdp pdp : pdps) {
- logger.debug("DesignatedWaiter.run pdp = {}"
- + " pdp.getDesignatedDate() = {}",
- pdp.getPdpId(), pdp.getDesignatedDate());
- if (pdp.getDesignatedDate().compareTo(mostRecentPrimary.getDesignatedDate()) > 0) {
- mostRecentPrimary = pdp;
- logger.debug(RUN_PRIMARY_MSG, mostRecentPrimary.getPdpId());
- }
- }
- return mostRecentPrimary;
- }
-
- /**
- * Compue designated pdp.
- *
- * @param listOfDesignated list of designated pdps
- * @param mostRecentPrimary most recent primary pdpd
- * @return drools pdp object
- */
- public DroolsPdp computeDesignatedPdp(List<DroolsPdp> listOfDesignated, DroolsPdp mostRecentPrimary) {
- if (listOfDesignated.isEmpty()) {
- logger.debug("\nDesignatedWaiter.run: myPdp: {} listOfDesignated is: EMPTY.", myPdp.getPdpId());
- return null;
- }
-
- if (listOfDesignated.size() == 1) {
- logger.debug("\nDesignatedWaiter.run: myPdp: {} listOfDesignated "
- + "has ONE entry. PDP ID: {}", myPdp.getPdpId(), listOfDesignated.get(0).getPdpId());
- return listOfDesignated.get(0);
- }
-
- logger.debug("DesignatedWaiter.run: myPdp: {} listOfDesignated.size(): {}", myPdp.getPdpId(),
- listOfDesignated.size());
- var data = new DesignatedData();
- for (DroolsPdp pdp : listOfDesignated) {
- DroolsPdp rejectedPdp;
-
- // We need to determine if another PDP is the lowest priority
- 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 && 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(),
- myPdp.getPdpId());
- // We found that myPdp is on the listOfDesignated and it is not the lowest priority
- // So, we must demote it
- demoteMyPdp();
- }
- }
-
- DroolsPdp lowestPriorityPdp = data.getLowestPriority();
-
- //now we have a valid value for lowestPriorityPdp
- logger.debug("\n\nDesignatedWaiter.run: myPdp: {} listOfDesignated "
- + "found the LOWEST priority pdp ID: {} "
- + " It is now the designatedPpd from the perspective of myPdp ID: {} \n\n",
- myPdp.getPdpId(), lowestPriorityPdp.getPdpId(), myPdp);
- return lowestPriorityPdp;
-
- }
-
- private class DesignatedData {
- private DroolsPdp lowestPrioritySameSite = null;
- private DroolsPdp lowestPriorityDifferentSite = null;
-
- private DroolsPdp compareSameSite(DroolsPdp pdp) {
- if (lowestPrioritySameSite == null) {
- if (lowestPriorityDifferentSite != null) {
- //we need to reject lowestPriorityDifferentSite
- DroolsPdp rejectedPdp = lowestPriorityDifferentSite;
- lowestPriorityDifferentSite = pdp;
- return rejectedPdp;
- }
- lowestPrioritySameSite = pdp;
- return null;
- } else {
- if (pdp.getPdpId().equals((lowestPrioritySameSite.getPdpId()))) {
- return null; //nothing to compare
- }
- if (pdp.comparePriority(lowestPrioritySameSite) < 0) {
- logger.debug("\nDesignatedWaiter.run: myPdp {} listOfDesignated pdp ID: {}"
- + " has lower priority than pdp ID: {}", myPdp.getPdpId(), pdp.getPdpId(),
- lowestPrioritySameSite.getPdpId());
- //we need to reject lowestPrioritySameSite
- DroolsPdp rejectedPdp = lowestPrioritySameSite;
- lowestPrioritySameSite = pdp;
- return rejectedPdp;
- } else {
- //we need to reject pdp and keep lowestPrioritySameSite
- logger.debug("\nDesignatedWaiter.run: myPdp {} listOfDesignated pdp ID: {} "
- + " has higher priority than pdp ID: {}", myPdp.getPdpId(), pdp.getPdpId(),
- lowestPrioritySameSite.getPdpId());
- return pdp;
- }
- }
- }
-
- private DroolsPdp compareDifferentSite(DroolsPdp pdp) {
- if (lowestPrioritySameSite != null) {
- //if we already have a candidate for same site, we don't want to bother with different sites
- return pdp;
- } else {
- if (lowestPriorityDifferentSite == null) {
- lowestPriorityDifferentSite = pdp;
- return null;
- }
- if (pdp.getPdpId().equals((lowestPriorityDifferentSite.getPdpId()))) {
- return null; //nothing to compare
- }
- if (pdp.comparePriority(lowestPriorityDifferentSite) < 0) {
- logger.debug("\nDesignatedWaiter.run: myPdp {} listOfDesignated pdp ID: {}"
- + " has lower priority than pdp ID: {}", myPdp.getPdpId(), pdp.getPdpId(),
- lowestPriorityDifferentSite.getPdpId());
- //we need to reject lowestPriorityDifferentSite
- DroolsPdp rejectedPdp = lowestPriorityDifferentSite;
- lowestPriorityDifferentSite = pdp;
- return rejectedPdp;
- } else {
- //we need to reject pdp and keep lowestPriorityDifferentSite
- logger.debug("\nDesignatedWaiter.run: myPdp {} listOfDesignated pdp ID: {}"
- + " has higher priority than pdp ID: {}", myPdp.getPdpId(), pdp.getPdpId(),
- lowestPriorityDifferentSite.getPdpId());
- return pdp;
- }
- }
- }
-
- private DroolsPdp getLowestPriority() {
- return (lowestPrioritySameSite != null ? lowestPrioritySameSite : lowestPriorityDifferentSite);
- }
- }
-
- private void demoteMyPdp() {
- try {
- //Keep the order like this. StateManagement is last since it triggers controller shutdown
- myPdp.setDesignated(false);
- pdpsConnector.setDesignated(myPdp, false);
- isDesignated = false;
- String standbyStatus = stateManagementFeature.getStandbyStatus();
- if (!(standbyStatus.equals(StateManagement.HOT_STANDBY)
- || standbyStatus.equals(StateManagement.COLD_STANDBY))) {
- /*
- * Only call demote if it is not already in the right state. Don't worry about
- * synching the lower level topic endpoint states. That is done by the
- * refreshStateAudit.
- */
- stateManagementFeature.demote();
- }
- } catch (Exception e) {
- myPdp.setDesignated(false);
- pdpsConnector.setDesignated(myPdp, false);
- isDesignated = false;
- logger.error("DesignatedWaiter.run: myPdp: {} Caught Exception attempting to "
- + "demote myPdp {} myPdp.getPdpId(), message= {}", myPdp.getPdpId(),
- e);
- }
- }
-
- private class TimerUpdateClass extends TimerTask {
-
- @Override
- public void run() {
- try {
- logger.debug("TimerUpdateClass.run: entry");
- checkWaitTimer();
- } catch (Exception e) {
- logger.error("TimerUpdateClass.run caught an unexpected exception: ", e);
- }
- logger.debug("TimerUpdateClass.run.exit");
- }
- }
-
- @Override
- public void checkThreadStatus() {
- checkWaitTimer();
- }
-
- private void checkWaitTimer() {
- synchronized (checkWaitTimerLock) {
- try {
- logger.debug("checkWaitTimer: entry");
- var now = currentTime.getDate();
- long nowMs = now.getTime();
- long waitTimerMs = waitTimerLastRunDate.getTime();
-
- //give it 10 times leeway
- if ((nowMs - waitTimerMs) > 10 * pdpUpdateInterval) {
- if (allSeemsWell == null || allSeemsWell) {
- allSeemsWell = false;
- logger.debug("checkWaitTimer: calling allSeemsWell with ALLNOTWELL param");
- stateManagementFeature.allSeemsWell(this.getClass().getName(),
- StateManagementFeatureApiConstants.ALLNOTWELL_STATE,
- "DesignationWaiter/ElectionHandler has STALLED");
- }
- logger.error("checkWaitTimer: nowMs - waitTimerMs = {}"
- + ", exceeds 10* pdpUpdateInterval = {}"
- + " DesignationWaiter is STALLED!", (nowMs - waitTimerMs), (10 * pdpUpdateInterval));
- } else if (allSeemsWell == null || !allSeemsWell) {
- allSeemsWell = true;
- stateManagementFeature.allSeemsWell(this.getClass().getName(),
- StateManagementFeatureApiConstants.ALLSEEMSWELL_STATE,
- "DesignationWaiter/ElectionHandler has RESUMED");
- logger.info("DesignationWaiter/ElectionHandler has RESUMED");
- }
- logger.debug("checkWaitTimer: exit");
- } catch (Exception e) {
- logger.error("checkWaitTimer: caught unexpected exception: ", e);
- }
- }
- }
-
- private long getDWaiterStartMs() {
- var now = currentTime.getDate();
-
- // Retrieve the ms since the epoch
- long nowMs = now.getTime();
-
- // Time since the end of the last pdpUpdateInterval multiple
- long nowModMs = nowMs % pdpUpdateInterval;
-
- // Time to the start of the next pdpUpdateInterval multiple
- long startMs = 2 * pdpUpdateInterval - nowModMs;
-
- // Give the start time a minimum of a 5 second cushion
- if (startMs < 5000) {
- // Start at the beginning of following interval
- startMs = pdpUpdateInterval + startMs;
- }
- return startMs;
- }
-}
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/Factory.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/Factory.java
deleted file mode 100644
index fae70074..00000000
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/Factory.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.activestandby;
-
-import java.util.Timer;
-import lombok.AccessLevel;
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * Factory for creating various objects.
- */
-public class Factory {
-
- @Getter
- @Setter(AccessLevel.PROTECTED)
- private static Factory instance = new Factory();
-
- public Timer makeTimer() {
- return new Timer();
- }
-}
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
deleted file mode 100644
index 39386d5e..00000000
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/JpaDroolsPdpsConnector.java
+++ /dev/null
@@ -1,565 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * feature-active-standby-management
- * ================================================================================
- * 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.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.activestandby;
-
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.FlushModeType;
-import javax.persistence.LockModeType;
-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 static final String PDP_ID_PARAM = "pdpId";
-
- // get an instance of logger
- private static final Logger logger = LoggerFactory.getLogger(JpaDroolsPdpsConnector.class);
- private EntityManagerFactory emf;
-
- private final CurrentTime currentTime = MonitorTime.getInstance();
-
- @Override
- public Collection<DroolsPdp> getDroolsPdps() {
- //return a list of all the DroolsPdps in the database
- var em = emf.createEntityManager();
- try {
- em.getTransaction().begin();
- var droolsPdpsListQuery = em.createQuery("SELECT p FROM DroolsPdpEntity p", DroolsPdp.class);
- List<DroolsPdp> droolsPdpsList = droolsPdpsListQuery.setLockMode(LockModeType.NONE)
- .setFlushMode(FlushModeType.COMMIT).getResultList();
- LinkedList<DroolsPdp> droolsPdpsReturnList = new LinkedList<>();
- for (DroolsPdp droolsPdp : droolsPdpsList) {
- //Make sure it is not a cached version
- em.refresh(droolsPdp);
- droolsPdpsReturnList.add(droolsPdp);
- if (logger.isDebugEnabled()) {
- logger.debug("getDroolsPdps: PDP= {}"
- + ", isDesignated= {}"
- + ", updatedDate= {}"
- + ", priority= {}", droolsPdp.getPdpId(), droolsPdp.isDesignated(),
- droolsPdp.getUpdatedDate(), droolsPdp.getPriority());
- }
- }
- try {
- em.getTransaction().commit();
- } catch (Exception e) {
- logger.error("Cannot commit getDroolsPdps() transaction", e);
- }
- return droolsPdpsReturnList;
- } finally {
- cleanup(em, "getDroolsPdps");
- }
- }
-
- 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;
- }
-
- @Override
- public void update(DroolsPdp pdp) {
-
- logger.debug("update: Entering, pdpId={}", pdp.getPdpId());
-
- //this is to update our own pdp in the database
- var em = emf.createEntityManager();
- try {
- em.getTransaction().begin();
- var droolsPdpsListQuery = em.createQuery(SELECT_PDP_BY_ID, DroolsPdpEntity.class);
- droolsPdpsListQuery.setParameter(PDP_ID_PARAM, pdp.getPdpId());
- List<DroolsPdpEntity> droolsPdpsList = droolsPdpsListQuery.setLockMode(LockModeType.NONE)
- .setFlushMode(FlushModeType.COMMIT).getResultList();
- DroolsPdpEntity droolsPdpEntity;
- if (droolsPdpsList.size() == 1) {
- droolsPdpEntity = droolsPdpsList.get(0);
- em.refresh(droolsPdpEntity); //Make sure we have current values
- var currentDate = currentTime.getDate();
- long difference = currentDate.getTime() - droolsPdpEntity.getUpdatedDate().getTime();
- //just set some kind of default here
- long pdpTimeout = 15000;
- try {
- pdpTimeout = Long.parseLong(
- ActiveStandbyProperties.getProperty(ActiveStandbyProperties.PDP_TIMEOUT));
- } catch (Exception e) {
- logger.error("Could not get PDP timeout property, using default.", e);
- }
- boolean isCurrent = difference < pdpTimeout;
- logger.debug("update: PDP= {}, isCurrent={}"
- + " difference= {}"
- + ", pdpTimeout= {}, designated= {}",
- pdp.getPdpId(), isCurrent, difference, pdpTimeout, droolsPdpEntity.isDesignated());
- } else {
- logger.debug("update: For PDP={}"
- + ", instantiating new DroolsPdpEntity", pdp.getPdpId());
- droolsPdpEntity = new DroolsPdpEntity();
- em.persist(droolsPdpEntity);
- droolsPdpEntity.setPdpId(pdp.getPdpId());
- }
- if (droolsPdpEntity.getPriority() != pdp.getPriority()) {
- droolsPdpEntity.setPriority(pdp.getPriority());
- }
- if (!droolsPdpEntity.getUpdatedDate().equals(pdp.getUpdatedDate())) {
- droolsPdpEntity.setUpdatedDate(pdp.getUpdatedDate());
- }
- if (!nullSafeEquals(droolsPdpEntity.getSite(), pdp.getSite())) {
- droolsPdpEntity.setSite(pdp.getSite());
- }
-
- if (droolsPdpEntity.isDesignated() != pdp.isDesignated()) {
- logger.debug("update: pdpId={}"
- + ", pdp.isDesignated={}"
- + ", droolsPdpEntity.pdpId= {}"
- + ", droolsPdpEntity.isDesignated={}",
- pdp.getPdpId(), pdp.isDesignated(),
- droolsPdpEntity.getPdpId(), droolsPdpEntity.isDesignated());
- droolsPdpEntity.setDesignated(pdp.isDesignated());
- //The isDesignated value is not the same and the new one == true
- if (pdp.isDesignated()) {
- droolsPdpEntity.setDesignatedDate(currentTime.getDate());
- }
- }
- em.getTransaction().commit();
- } finally {
- cleanup(em, "update");
- }
-
- logger.debug("update: Exiting");
-
- }
-
- /*
- * Note: A side effect of this boolean method is that if the PDP is designated but not current, the
- * droolspdpentity.DESIGNATED column will be set to false (the PDP will be un-designated, i.e. marked as
- * being in standby mode)
- */
- @Override
- public boolean isPdpCurrent(DroolsPdp pdp) {
-
- boolean isCurrent = isCurrent(pdp);
-
- var em = emf.createEntityManager();
- try {
- if (!isCurrent && pdp.isDesignated()) {
- em.getTransaction().begin();
- var droolsPdpsListQuery = em.createQuery(SELECT_PDP_BY_ID, DroolsPdpEntity.class);
- droolsPdpsListQuery.setParameter(PDP_ID_PARAM, pdp.getPdpId());
- List<DroolsPdpEntity> droolsPdpsList = droolsPdpsListQuery.setLockMode(LockModeType.NONE)
- .setFlushMode(FlushModeType.COMMIT).getResultList();
- if (droolsPdpsList.size() == 1) {
- logger.debug("isPdpCurrent: PDP={} designated but not current; setting designated to false",
- pdp.getPdpId());
- var droolsPdpEntity = droolsPdpsList.get(0);
- droolsPdpEntity.setDesignated(false);
- em.getTransaction().commit();
- } else {
- logger.warn("isPdpCurrent: PDP={} is designated but not current; "
- + "however it does not have a DB entry, so cannot set DESIGNATED to false!",
- pdp.getPdpId());
- }
- } else {
- logger.debug("isPdpCurrent: For PDP= {}, "
- + "designated={}, isCurrent={}", pdp.getPdpId(), pdp.isDesignated(), isCurrent);
- }
- } catch (Exception e) {
- logger.error("Could not update expired record marked as designated in the database", e);
- } finally {
- cleanup(em, "isPdpCurrent");
- }
- return isCurrent;
-
- }
-
- @Override
- public void setDesignated(DroolsPdp pdp, boolean designated) {
-
- logger.debug("setDesignated: Entering, pdpId={}"
- + ", designated={}", pdp.getPdpId(), designated);
-
- EntityManager em = null;
- try {
- em = emf.createEntityManager();
- em.getTransaction().begin();
- var droolsPdpsListQuery = em
- .createQuery(SELECT_PDP_BY_ID, DroolsPdpEntity.class);
- droolsPdpsListQuery.setParameter(PDP_ID_PARAM, pdp.getPdpId());
- List<DroolsPdpEntity> droolsPdpsList = droolsPdpsListQuery.setLockMode(
- LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
- if (droolsPdpsList.size() == 1) {
- var droolsPdpEntity = droolsPdpsList.get(0);
-
- logger.debug("setDesignated: PDP={}"
- + " found, designated= {}"
- + ", setting to {}", pdp.getPdpId(), droolsPdpEntity.isDesignated(),
- designated);
- setPdpDesignation(em, droolsPdpEntity, designated);
- em.getTransaction().commit();
- } else {
- logger.error("setDesignated: PDP={}"
- + " not in DB; cannot update designation", pdp.getPdpId());
- }
- } catch (Exception e) {
- logger.error("setDesignated: Caught Exception", e);
- } finally {
- cleanup(em, "setDesignated");
- }
-
- logger.debug("setDesignated: Exiting");
-
- }
-
- private void setPdpDesignation(EntityManager em, DroolsPdpEntity droolsPdpEntity, boolean designated) {
- droolsPdpEntity.setDesignated(designated);
- if (designated) {
- em.refresh(droolsPdpEntity); //make sure we get the DB value
- if (!droolsPdpEntity.isDesignated()) {
- droolsPdpEntity.setDesignatedDate(currentTime.getDate());
- }
-
- }
- }
-
-
- @Override
- public void standDownPdp(String pdpId) {
- logger.debug("standDownPdp: Entering, pdpId={}", pdpId);
-
- EntityManager em = null;
- try {
- /*
- * Start transaction.
- */
- em = emf.createEntityManager();
- em.getTransaction().begin();
-
- /*
- * Get droolspdpentity record for this PDP and mark DESIGNATED as
- * false.
- */
- var droolsPdpsListQuery = em
- .createQuery(SELECT_PDP_BY_ID, DroolsPdpEntity.class);
- droolsPdpsListQuery.setParameter(PDP_ID_PARAM, pdpId);
- List<DroolsPdpEntity> droolsPdpsList = droolsPdpsListQuery.setLockMode(
- LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
- if (droolsPdpsList.size() == 1) {
- var droolsPdpEntity = droolsPdpsList.get(0);
- droolsPdpEntity.setDesignated(false);
- em.persist(droolsPdpEntity);
- logger.debug("standDownPdp: PDP={} persisted as non-designated.", pdpId);
- } else {
- logger.error("standDownPdp: Missing record in droolspdpentity for pdpId={}"
- + "; cannot stand down PDP", pdpId);
- }
-
- /*
- * End transaction.
- */
- em.getTransaction().commit();
- cleanup(em, "standDownPdp");
- em = null;
-
- // Keep the election handler in sync with the DB
- DroolsPdpsElectionHandler.setMyPdpDesignated(false);
-
- } catch (Exception e) {
- logger.error("standDownPdp: Unexpected Exception attempting to mark "
- + "DESIGNATED as false for droolspdpentity, pdpId={}"
- + ". Cannot stand down PDP; message={}", pdpId, e.getMessage(), e);
- } finally {
- cleanup(em, "standDownPdp");
- }
- logger.debug("standDownPdp: Exiting");
-
- }
-
- /*
- * Determines whether or not a designated PDP has failed.
- *
- * Note: The update method, which is run periodically by the
- * TimerUpdateClass, will un-designate a PDP that is stale.
- */
- @Override
- public boolean hasDesignatedPdpFailed(Collection<DroolsPdp> pdps) {
-
- logger.debug("hasDesignatedPdpFailed: Entering, pdps.size()={}", pdps.size());
-
- var failed = true;
- var foundDesignatedPdp = false;
-
- for (DroolsPdp pdp : pdps) {
-
- /*
- * Normally, the update method will un-designate any stale PDP, but
- * we check here to see if the PDP has gone stale since the update
- * method was run.
- *
- * Even if we determine that the designated PDP is current, we keep
- * going (we don't break), so we can get visibility into the other
- * PDPs, when in DEBUG mode.
- */
- if (pdp.isDesignated() && isCurrent(pdp)) {
- logger.debug("hasDesignatedPdpFailed: Designated PDP={} is current", pdp.getPdpId());
- failed = false;
- foundDesignatedPdp = true;
- } else if (pdp.isDesignated() && !isCurrent(pdp)) {
- logger.error("hasDesignatedPdpFailed: Designated PDP={} has failed", pdp.getPdpId());
- foundDesignatedPdp = true;
- } else {
- logger.debug("hasDesignatedPdpFailed: PDP={} is not designated", pdp.getPdpId());
- }
- }
-
- logger.debug("hasDesignatedPdpFailed: Exiting and returning, foundDesignatedPdp={}",
- foundDesignatedPdp);
- return failed;
- }
-
-
- private boolean isCurrent(DroolsPdp pdp) {
-
- logger.debug("isCurrent: Entering, pdpId={}", pdp.getPdpId());
-
- var current = false;
-
- // Return if the current PDP is considered "current" based on whatever
- // time box that may be.
- // If the the PDP is not current, we should mark it as not primary in
- // the database
- var currentDate = currentTime.getDate();
- long difference = currentDate.getTime()
- - pdp.getUpdatedDate().getTime();
- // just set some kind of default here
- long pdpTimeout = 15000;
- try {
- pdpTimeout = Long.parseLong(ActiveStandbyProperties
- .getProperty(ActiveStandbyProperties.PDP_TIMEOUT));
- logger.debug("isCurrent: pdp.timeout={}", pdpTimeout);
- } catch (Exception e) {
- logger.error("isCurrent: Could not get PDP timeout property, using default.", e);
- }
- current = difference < pdpTimeout;
-
- logger.debug("isCurrent: Exiting, difference={}, pdpTimeout={}"
- + "; returning current={}", difference, pdpTimeout, current);
-
- return current;
- }
-
-
- /*
- * Currently this method is only used in a JUnit test environment. Gets a
- * PDP record from droolspdpentity table.
- */
- @Override
- public DroolsPdpEntity getPdp(String pdpId) {
-
- logger.debug("getPdp: Entering and getting PDP with pdpId={}", pdpId);
-
- DroolsPdpEntity droolsPdpEntity = null;
-
- EntityManager em = null;
- try {
- em = emf.createEntityManager();
- em.getTransaction().begin();
- var droolsPdpsListQuery = em
- .createQuery(SELECT_PDP_BY_ID);
- droolsPdpsListQuery.setParameter(PDP_ID_PARAM, pdpId);
- List<?> droolsPdpsList = droolsPdpsListQuery.setLockMode(
- LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
- if (droolsPdpsList.size() == 1
- && droolsPdpsList.get(0) instanceof DroolsPdpEntity) {
- droolsPdpEntity = (DroolsPdpEntity) droolsPdpsList.get(0);
- logger.debug("getPdp: PDP={}"
- + " found, isDesignated={},"
- + " updatedDate={}, "
- + "priority={}", pdpId,
- droolsPdpEntity.isDesignated(), droolsPdpEntity.getUpdatedDate(),
- droolsPdpEntity.getPriority());
-
- // Make sure the droolsPdpEntity is not a cached version
- em.refresh(droolsPdpEntity);
-
- em.getTransaction().commit();
- } else {
- logger.error("getPdp: PDP={} not found!?", pdpId);
- }
- } catch (Exception e) {
- logger.error("getPdp: Caught Exception attempting to get PDP", e);
- } finally {
- cleanup(em, "getPdp");
- }
-
- logger.debug("getPdp: Returning droolsPdpEntity={}", droolsPdpEntity);
- return droolsPdpEntity;
-
- }
-
- /*
- * Normally this method should only be used in a JUnit test environment.
- * Manually inserts a PDP record in droolspdpentity table.
- */
- @Override
- public void insertPdp(DroolsPdp pdp) {
- logger.debug("insertPdp: Entering and manually inserting PDP");
-
- /*
- * Start transaction
- */
- var em = emf.createEntityManager();
- try {
- em.getTransaction().begin();
-
- /*
- * Insert record.
- */
- var droolsPdpEntity = new DroolsPdpEntity();
- em.persist(droolsPdpEntity);
- droolsPdpEntity.setPdpId(pdp.getPdpId());
- droolsPdpEntity.setDesignated(pdp.isDesignated());
- droolsPdpEntity.setPriority(pdp.getPriority());
- droolsPdpEntity.setUpdatedDate(pdp.getUpdatedDate());
- droolsPdpEntity.setSite(pdp.getSite());
-
- /*
- * End transaction.
- */
- em.getTransaction().commit();
- } finally {
- cleanup(em, "insertPdp");
- }
- logger.debug("insertPdp: Exiting");
-
- }
-
- /*
- * Normally this method should only be used in a JUnit test environment.
- * Manually deletes all PDP records in droolspdpentity table.
- */
- @Override
- public void deleteAllPdps() {
-
- logger.debug("deleteAllPdps: Entering");
-
- /*
- * Start transaction
- */
- var em = emf.createEntityManager();
- try {
- em.getTransaction().begin();
-
- var droolsPdpsListQuery = em
- .createQuery("SELECT p FROM DroolsPdpEntity p");
- @SuppressWarnings("unchecked")
- List<DroolsPdp> droolsPdpsList = droolsPdpsListQuery.setLockMode(
- LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
- logger.debug("deleteAllPdps: Deleting {} PDPs", droolsPdpsList.size());
- for (DroolsPdp droolsPdp : droolsPdpsList) {
- String pdpId = droolsPdp.getPdpId();
- deletePdp(pdpId);
- }
-
- /*
- * End transaction.
- */
- em.getTransaction().commit();
- } finally {
- cleanup(em, "deleteAllPdps");
- }
- logger.debug("deleteAllPdps: Exiting");
-
- }
-
- /*
- * Normally this method should only be used in a JUnit test environment.
- * Manually deletes a PDP record in droolspdpentity table.
- */
- @Override
- public void deletePdp(String pdpId) {
- logger.debug("deletePdp: Entering and manually deleting pdpId={}", pdpId);
-
- /*
- * Start transaction
- */
- var em = emf.createEntityManager();
- try {
- em.getTransaction().begin();
-
- /*
- * Delete record.
- */
- var droolsPdpEntity = em.find(DroolsPdpEntity.class, pdpId);
- if (droolsPdpEntity != null) {
- logger.debug("deletePdp: Removing PDP");
- em.remove(droolsPdpEntity);
- } else {
- logger.debug("deletePdp: PDP with ID={} not currently in DB", pdpId);
- }
-
- /*
- * End transaction.
- */
- em.getTransaction().commit();
- } finally {
- cleanup(em, "deletePdp");
- }
- logger.debug("deletePdp: Exiting");
-
- }
-
- /*
- * Close the specified EntityManager, rolling back any pending transaction
- *
- * @param em the EntityManager to close ('null' is OK)
- * @param method the invoking Java method (used for log messages)
- */
- private static void cleanup(EntityManager em, String method) {
- if (em != null && em.isOpen()) {
- if (em.getTransaction().isActive()) {
- // there is an active EntityTransaction -- roll it back
- try {
- em.getTransaction().rollback();
- } catch (Exception e) {
- logger.error("{}: Caught Exception attempting to rollback EntityTransaction", method, e);
- }
- }
-
- // now, close the EntityManager
- try {
- em.close();
- } catch (Exception e) {
- logger.error("{}: Caught Exception attempting to close EntityManager", method, e);
- }
- }
- }
-}
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
deleted file mode 100644
index 1756246b..00000000
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/PmStandbyStateChangeNotifier.java
+++ /dev/null
@@ -1,310 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * feature-active-standby-management
- * ================================================================================
- * 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.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-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;
-import org.onap.policy.common.utils.time.CurrentTime;
-import org.onap.policy.drools.system.PolicyEngine;
-import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/*
- * Some background:
- *
- * Originally, there was a "StandbyStateChangeNotifier" that belonged to policy-core, and this class's
- * handleStateChange() method used to take care of invoking conn.standDownPdp().
- *
- * But testing revealed that when a state change to hot standby
- * occurred from a demote() operation, first the PMStandbyStateChangeNotifier.handleStateChange() method
- * would be invoked and then the StandbyStateChangeNotifier.handleStateChange() method would be invoked,
- * and this ordering was creating the following problem:
- *
- * When PMStandbyStateChangeNotifier.handleStateChange() was invoked it would take a long time to finish,
- * because it would result in SingleThreadedUebTopicSource.stop() being invoked, which can potentially do a
- * 5 second sleep for each controller being stopped.
- *
- * Meanwhile, as these controller stoppages and their associated sleeps were occurring, the election handler
- * would discover the demoted PDP in hotstandby (but still designated!) and promote it, resulting in the
- * standbyStatus going from hotstandby to providingservice. So then, by the time that
- * PMStandbyStateChangeNotifier.handleStateChange() finished its work and
- * StandbyStateChangeNotifier.handleStateChange() started executing, the standbyStatus was no longer hotstandby
- * (as effected by the demote), but providingservice (as reset by the election handling logic) and
- * conn.standDownPdp() would not get called!
- *
- * To fix this bug, we consolidated StandbyStateChangeNotifier and PMStandbyStateChangeNotifier,
- * with the standDownPdp() always
- * being invoked prior to the TopicEndpoint.manager.lock(). In this way, when the election handling logic is invoked
- * during the controller stoppages, the PDP is in hotstandby and the standdown occurs.
- *
- */
-public class PmStandbyStateChangeNotifier extends StateChangeNotifier {
- // get an instance of logger
- private static final Logger logger = LoggerFactory.getLogger(PmStandbyStateChangeNotifier.class);
- private Timer delayActivateTimer;
- private boolean isWaitingForActivation;
- 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 static final String NONE = "none";
- public static final String UNSUPPORTED = "unsupported";
- public static final String HOTSTANDBY_OR_COLDSTANDBY = "hotstandby_or_coldstandby";
-
- /**
- * Constructor.
- *
- */
- public PmStandbyStateChangeNotifier() {
- var 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
- waitInterval = 2 * pdpUpdateInterval + 2000L;
- isNowActivating = false;
- previousStandbyStatus = PmStandbyStateChangeNotifier.NONE;
- }
-
- @Override
- public void handleStateChange() {
- /*
- * A note on synchronization: This method is not synchronized because the caller,
- * stateManagememt, has synchronize all of its methods. Only one stateManagement operation
- * can occur at a time. Thus, only one handleStateChange() call will ever be made at a time.
- */
- logger.debug("handleStateChange: Entering, message={}, standbyStatus={}", super.getMessage(),
- super.getStateManagement().getStandbyStatus());
- String standbyStatus = super.getStateManagement().getStandbyStatus();
- String pdpId = ActiveStandbyProperties.getProperty(ActiveStandbyProperties.NODE_NAME);
-
- logger.debug("handleStateChange: previousStandbyStatus = {}; standbyStatus = {}",
- previousStandbyStatus, standbyStatus);
-
- if (standbyStatus == null || standbyStatus.equals(StateManagement.NULL_VALUE)) {
- logger.debug("handleStateChange: standbyStatus is null; standing down PDP={}", pdpId);
- standDownPdpNull(pdpId);
-
- } else if (standbyStatus.equals(StateManagement.HOT_STANDBY)
- || standbyStatus.equals(StateManagement.COLD_STANDBY)) {
- logger.debug("handleStateChange: standbyStatus={}; standing down PDP={}", standbyStatus, pdpId);
- standDownPdp(pdpId, standbyStatus);
-
- } else if (standbyStatus.equals(StateManagement.PROVIDING_SERVICE)) {
- logger.debug("handleStateChange: standbyStatus= {} scheduling activation of PDP={}", standbyStatus,
- pdpId);
- schedulePdpActivation(pdpId, standbyStatus);
-
- } else {
- logger.error("handleStateChange: Unsupported standbyStatus={}; standing down PDP={}", standbyStatus, pdpId);
- standDownPdpUnsupported(pdpId, standbyStatus);
- }
-
- logger.debug("handleStateChange: Exiting");
- }
-
- private void standDownPdpNull(String pdpId) {
- if (previousStandbyStatus.equals(StateManagement.NULL_VALUE)) {
- // We were just here and did this successfully
- logger.debug("handleStateChange: "
- + "Is returning because standbyStatus is null and was previously 'null'; PDP={}",
- pdpId);
- return;
- }
-
- isWaitingForActivation = false;
- try {
- logger.debug("handleStateChange: null: cancelling delayActivationTimer.");
- cancelTimer();
- // Only want to lock the endpoints, not the controllers.
- getPolicyEngineManager().deactivate();
- // The operation was fully successful, but you cannot assign it a real null value
- // because later we might try to execute previousStandbyStatus.equals() and get
- // a null pointer exception.
- previousStandbyStatus = StateManagement.NULL_VALUE;
- } catch (Exception e) {
- logger.warn("handleStateChange: standbyStatus == null caught exception: ", e);
- }
- }
-
- private void standDownPdp(String pdpId, String standbyStatus) {
- if (previousStandbyStatus.equals(PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY)) {
- // We were just here and did this successfully
- logger.debug("handleStateChange: Is returning because standbyStatus is {}"
- + " and was previously {}; PDP= {}", standbyStatus, previousStandbyStatus, pdpId);
- return;
- }
-
- isWaitingForActivation = false;
- try {
- logger.debug("handleStateChange: HOT_STNDBY || COLD_STANDBY: cancelling delayActivationTimer.");
- cancelTimer();
- // Only want to lock the endpoints, not the controllers.
- getPolicyEngineManager().deactivate();
- // The operation was fully successful
- previousStandbyStatus = PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY;
- } catch (Exception e) {
- logger.warn("handleStateChange: standbyStatus = {} caught exception: {}", standbyStatus, e.getMessage(),
- e);
- }
- }
-
- private void schedulePdpActivation(String pdpId, String standbyStatus) {
- if (previousStandbyStatus.equals(StateManagement.PROVIDING_SERVICE)) {
- // We were just here and did this successfully
- logger.debug("handleStateChange: Is returning because standbyStatus is {}"
- + "and was previously {}; PDP={}", standbyStatus, previousStandbyStatus, pdpId);
- return;
- }
-
- try {
- // UnLock all the endpoints
- logger.debug("handleStateChange: standbyStatus={}; controllers must be unlocked.", standbyStatus);
- /*
- * Only endpoints should be unlocked. Controllers have not been locked. Because,
- * sometimes, it is possible for more than one PDP-D to become active (race
- * conditions) we need to delay the activation of the topic endpoint interfaces to
- * give the election algorithm time to resolve the conflict.
- */
- logger.debug("handleStateChange: PROVIDING_SERVICE isWaitingForActivation= {}",
- isWaitingForActivation);
-
- // Delay activation for 2*pdpUpdateInterval+2000 ms in case of an election handler
- // conflict.
- // You could have multiple election handlers thinking they can take over.
-
- // First let's check that the timer has not died
- checkTimerStatus();
-
- if (!isWaitingForActivation) {
- // Just in case there is an old timer hanging around
- logger.debug("handleStateChange: PROVIDING_SERVICE cancelling delayActivationTimer.");
- cancelTimer();
- delayActivateTimer = timerFactory.makeTimer();
- // delay the activate so the DesignatedWaiter can run twice
- delayActivateTimer.schedule(new DelayActivateClass(), waitInterval);
- isWaitingForActivation = true;
- startTimeWaitingForActivationMs = currentTime.getMillis();
- logger.debug("handleStateChange: PROVIDING_SERVICE scheduling delayActivationTimer in {} ms",
- waitInterval);
- } else {
- logger.debug("handleStateChange: PROVIDING_SERVICE delayActivationTimer is "
- + "waiting for activation.");
- }
-
- } catch (Exception e) {
- logger.warn("handleStateChange: PROVIDING_SERVICE standbyStatus == providingservice caught exception: ",
- e);
- }
- }
-
- private void checkTimerStatus() {
- if (isWaitingForActivation) {
- logger.debug("handleStateChange: PROVIDING_SERVICE isWaitingForActivation = {}",
- isWaitingForActivation);
- long now = currentTime.getMillis();
- long waitTimeMs = now - startTimeWaitingForActivationMs;
- if (waitTimeMs > 3 * waitInterval) {
- logger.debug("handleStateChange: PROVIDING_SERVICE looks like the activation wait timer "
- + "may be hung, waitTimeMs = {} and allowable waitInterval = {}"
- + " Checking whether it is currently in activation. isNowActivating = {}",
- waitTimeMs, waitInterval, isNowActivating);
- // Now check that it is not currently executing an activation
- if (!isNowActivating) {
- logger.debug("handleStateChange: PROVIDING_SERVICE looks like the activation "
- + "wait timer died");
- // This will assure the timer is cancelled and rescheduled.
- isWaitingForActivation = false;
- }
- }
- }
- }
-
- private void standDownPdpUnsupported(String pdpId, String standbyStatus) {
- if (previousStandbyStatus.equals(PmStandbyStateChangeNotifier.UNSUPPORTED)) {
- // We were just here and did this successfully
- logger.debug("handleStateChange: Is returning because standbyStatus is "
- + "UNSUPPORTED and was previously {}; PDP={}", previousStandbyStatus, pdpId);
- return;
- }
-
- // Only want to lock the endpoints, not the controllers.
- isWaitingForActivation = false;
- try {
- logger.debug("handleStateChange: unsupported standbystatus: cancelling delayActivationTimer.");
- cancelTimer();
- getPolicyEngineManager().deactivate();
- // We know the standbystatus is unsupported
- previousStandbyStatus = PmStandbyStateChangeNotifier.UNSUPPORTED;
- } catch (Exception e) {
- logger.warn("handleStateChange: Unsupported standbyStatus = {} " + "caught exception: {} ",
- standbyStatus, e.getMessage(), e);
- }
- }
-
- private void cancelTimer() {
- if (delayActivateTimer != null) {
- delayActivateTimer.cancel();
- }
- }
-
- private class DelayActivateClass extends TimerTask {
-
- private Object delayActivateLock = new Object();
-
-
- @Override
- public void run() {
- isNowActivating = true;
- try {
- logger.debug("DelayActivateClass.run: entry");
- synchronized (delayActivateLock) {
- getPolicyEngineManager().activate();
- // The state change fully succeeded
- previousStandbyStatus = StateManagement.PROVIDING_SERVICE;
- // We want to set this to false here because the activate call can take a while
- isWaitingForActivation = false;
- isNowActivating = false;
- }
- logger.debug("DelayActivateClass.run.exit");
- } catch (Exception e) {
- isWaitingForActivation = false;
- isNowActivating = false;
- logger.warn("DelayActivateClass.run: caught an unexpected exception "
- + "calling PolicyEngineConstants.getManager().activate: ", e);
- }
- }
- }
-
- // these may be overridden by junit tests
-
- protected PolicyEngine getPolicyEngineManager() {
- return PolicyEngineConstants.getManager();
- }
-}
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
deleted file mode 100644
index d359b5a6..00000000
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ThreadRunningChecker.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * feature-active-standby-management
- * ================================================================================
- * Copyright (C) 2017-2018 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.activestandby;
-
-@FunctionalInterface
-public interface ThreadRunningChecker {
- void checkThreadStatus();
-
-}
diff --git a/feature-active-standby-management/src/main/resources/META-INF/persistence.xml b/feature-active-standby-management/src/main/resources/META-INF/persistence.xml
deleted file mode 100644
index 36f65ad8..00000000
--- a/feature-active-standby-management/src/main/resources/META-INF/persistence.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ============LICENSE_START=======================================================
- feature-active-standby-management
- ================================================================================
- Copyright (C) 2017-2018 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.
- See the License for the specific language governing permissions and
- limitations under the License.
- ============LICENSE_END=========================================================
- -->
-
-<persistence version="2.1"
- xmlns="http://xmlns.jcp.org/xml/ns/persistence"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
- <persistence-unit name="activeStandbyPU"
- transaction-type="RESOURCE_LOCAL">
- <!-- This is for database access by non-drools methods -->
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
- <class>org.onap.policy.drools.activestandby.DroolsPdpEntity</class>
- <properties>
- <!-- Properties are passed in -->
- </properties>
- </persistence-unit>
-</persistence>
diff --git a/feature-active-standby-management/src/main/resources/META-INF/services/org.onap.policy.drools.activestandby.ActiveStandbyFeatureApi b/feature-active-standby-management/src/main/resources/META-INF/services/org.onap.policy.drools.activestandby.ActiveStandbyFeatureApi
deleted file mode 100644
index 5296f8b7..00000000
--- a/feature-active-standby-management/src/main/resources/META-INF/services/org.onap.policy.drools.activestandby.ActiveStandbyFeatureApi
+++ /dev/null
@@ -1 +0,0 @@
-org.onap.policy.drools.activestandby.ActiveStandbyFeature
diff --git a/feature-active-standby-management/src/main/resources/META-INF/services/org.onap.policy.drools.core.PolicySessionFeatureApi b/feature-active-standby-management/src/main/resources/META-INF/services/org.onap.policy.drools.core.PolicySessionFeatureApi
deleted file mode 100644
index 5296f8b7..00000000
--- a/feature-active-standby-management/src/main/resources/META-INF/services/org.onap.policy.drools.core.PolicySessionFeatureApi
+++ /dev/null
@@ -1 +0,0 @@
-org.onap.policy.drools.activestandby.ActiveStandbyFeature
diff --git a/feature-active-standby-management/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyEngineFeatureApi b/feature-active-standby-management/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyEngineFeatureApi
deleted file mode 100644
index 5296f8b7..00000000
--- a/feature-active-standby-management/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyEngineFeatureApi
+++ /dev/null
@@ -1 +0,0 @@
-org.onap.policy.drools.activestandby.ActiveStandbyFeature
diff --git a/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/ActiveStandbyPropertiesTest.java b/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/ActiveStandbyPropertiesTest.java
deleted file mode 100644
index 058aa5e8..00000000
--- a/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/ActiveStandbyPropertiesTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.activestandby;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-
-import java.util.Properties;
-import org.junit.Before;
-import org.junit.Test;
-
-public class ActiveStandbyPropertiesTest {
-
- private Properties props;
-
- /**
- * Initializes objects.
- */
- @Before
- public void setUp() {
- props = new Properties();
- props.setProperty("abc", "hello");
- props.setProperty("def", "world");
- }
-
- @Test
- public void testInitProperties_testGetProperty_testGetProperties() {
- ActiveStandbyProperties.initProperties(props);
-
- assertSame(props, ActiveStandbyProperties.getProperties());
-
- assertEquals("hello", ActiveStandbyProperties.getProperty("abc"));
- assertEquals("world", ActiveStandbyProperties.getProperty("def"));
- }
-}
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
deleted file mode 100644
index 311f2954..00000000
--- a/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/AllSeemsWellTest.java
+++ /dev/null
@@ -1,379 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * feature-active-standby-management
- * ================================================================================
- * 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.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.activestandby;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.Date;
-import java.util.Properties;
-import java.util.concurrent.Callable;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.EntityTransaction;
-import javax.persistence.Persistence;
-import org.apache.commons.lang3.time.DateUtils;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.common.im.IntegrityMonitor;
-import org.onap.policy.common.im.IntegrityMonitorException;
-import org.onap.policy.common.im.MonitorTime;
-import org.onap.policy.common.im.StateManagement;
-import org.onap.policy.common.utils.time.CurrentTime;
-import org.onap.policy.common.utils.time.PseudoTimer;
-import org.onap.policy.common.utils.time.TestTimeMulti;
-import org.onap.policy.drools.core.PolicySessionFeatureApi;
-import org.onap.policy.drools.statemanagement.StateManagementFeatureApi;
-import org.onap.policy.drools.statemanagement.StateManagementFeatureApiConstants;
-import org.powermock.reflect.Whitebox;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/*
- * Testing the allSeemsWell interface to verify that it correctly affects the
- * operational state.
- */
-
-public class AllSeemsWellTest {
- private static final Logger logger = LoggerFactory.getLogger(AllSeemsWellTest.class);
-
- private static final String MONITOR_FIELD_NAME = "instance";
- private static final String HANDLER_INSTANCE_FIELD = "electionHandler";
-
- /*
- * Currently, the DroolsPdpsElectionHandler.DesignationWaiter is invoked every 1 seconds, starting
- * at the start of the next multiple of pdpUpdateInterval, but with a minimum of 5 sec cushion
- * to ensure that we wait for the DesignationWaiter to do its job, before
- * checking the results. Add a few seconds for safety
- */
-
- private static final int SLEEP_TIME_SEC = 10;
-
- /*
- * DroolsPdpsElectionHandler runs every 1 seconds, so it takes 10 seconds for the
- * checkWaitTimer() method to time out and call allSeemsWell which then requires
- * the forward progress counter to go stale which should add an additional 5 sec.
- */
-
- private static final int STALLED_ELECTION_HANDLER_SLEEP_TIME_SEC = 15;
-
- /*
- * As soon as the election hander successfully runs, it will resume the forward progress.
- * If the election handler runs ever 1 sec and test transaction is run every 1 sec and
- * then fpc is written every 1 sec and then the fpc is checked every 2 sec, that could
- * take a total of 5 sec to recognize the resumption of progress. So, add 1 for safety.
- */
- private static final int RESUMED_ELECTION_HANDLER_SLEEP_TIME_SEC = 6;
-
- private static EntityManagerFactory emfx;
- private static EntityManagerFactory emfd;
- private static EntityManager emx;
- private static EntityManager emd;
- private static EntityTransaction et;
-
- private static final String CONFIG_DIR = "src/test/resources/asw";
-
- private static CurrentTime saveTime;
- private static Factory saveFactory;
-
- private TestTimeMulti testTime;
-
- /*
- * See the IntegrityMonitor.getJmxUrl() method for the rationale behind this jmx related processing.
- */
-
- /**
- * Setup the class.
- *
- * @throws Exception exception
- */
- @BeforeClass
- public static void setUpClass() throws Exception {
-
- String userDir = System.getProperty("user.dir");
- logger.debug("setUpClass: userDir={}", userDir);
- System.setProperty("com.sun.management.jmxremote.port", "9980");
- System.setProperty("com.sun.management.jmxremote.authenticate", "false");
-
- DroolsPdpsElectionHandler.setUnitTesting(true);
-
- saveTime = Whitebox.getInternalState(MonitorTime.class, MONITOR_FIELD_NAME);
- saveFactory = Factory.getInstance();
-
- resetInstanceObjects();
-
- //Create the data access for xacml db
- Properties stateManagementProperties = loadStateManagementProperties();
-
- emfx = Persistence.createEntityManagerFactory("junitXacmlPU", stateManagementProperties);
-
- // Create an entity manager to use the DB
- emx = emfx.createEntityManager();
-
- //Create the data access for drools db
- Properties activeStandbyProperties = loadActiveStandbyProperties();
-
- emfd = Persistence.createEntityManagerFactory("junitDroolsPU", activeStandbyProperties);
-
- // Create an entity manager to use the DB
- emd = emfd.createEntityManager();
- }
-
- /**
- * Restores the system state.
- *
- * @throws IntegrityMonitorException if the integrity monitor cannot be shut down
- */
- @AfterClass
- public static void tearDownClass() throws IntegrityMonitorException {
- resetInstanceObjects();
-
- Whitebox.setInternalState(MonitorTime.class, MONITOR_FIELD_NAME, saveTime);
- Factory.setInstance(saveFactory);
-
- DroolsPdpsElectionHandler.setUnitTesting(false);
-
- emd.close();
- emfd.close();
-
- emx.close();
- emfx.close();
- }
-
- /**
- * Setup.
- *
- * @throws Exception exception
- */
- @Before
- public void setUp() throws Exception {
- resetInstanceObjects();
-
- // set test time
- testTime = new TestTimeMulti();
- Whitebox.setInternalState(MonitorTime.class, MONITOR_FIELD_NAME, testTime);
-
- Factory factory = mock(Factory.class);
- when(factory.makeTimer()).thenAnswer(ans -> new PseudoTimer(testTime));
- Factory.setInstance(factory);
- }
-
- private static void resetInstanceObjects() throws IntegrityMonitorException {
- IntegrityMonitor.setUnitTesting(true);
- IntegrityMonitor.deleteInstance();
- IntegrityMonitor.setUnitTesting(false);
-
- Whitebox.setInternalState(ActiveStandbyFeature.class, HANDLER_INSTANCE_FIELD, (Object) null);
-
- }
-
- /**
- * Clean the xacml database.
- */
- public void cleanXacmlDb() {
- et = emx.getTransaction();
-
- et.begin();
- // Make sure we leave the DB clean
- emx.createQuery("DELETE FROM StateManagementEntity").executeUpdate();
- emx.createQuery("DELETE FROM ResourceRegistrationEntity").executeUpdate();
- emx.createQuery("DELETE FROM ForwardProgressEntity").executeUpdate();
- emx.flush();
- et.commit();
- }
-
- /**
- * Clean the drools database.
- */
- public void cleanDroolsDb() {
- et = emd.getTransaction();
-
- et.begin();
- // Make sure we leave the DB clean
- emd.createQuery("DELETE FROM DroolsPdpEntity").executeUpdate();
- emd.flush();
- et.commit();
- }
-
-
- // Tests hot standby when there is only one PDP.
-
- //@Ignore
- @Test
- public void testAllSeemsWell() throws Exception {
-
- logger.debug("\n\ntestAllSeemsWell: Entering\n\n");
- cleanXacmlDb();
- cleanDroolsDb();
-
- Properties stateManagementProperties = loadStateManagementProperties();
-
- logger.debug("testAllSeemsWell: Creating emfXacml");
- final EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
- "junitXacmlPU", stateManagementProperties);
-
- Properties activeStandbyProperties = loadActiveStandbyProperties();
- final String thisPdpId = activeStandbyProperties
- .getProperty(ActiveStandbyProperties.NODE_NAME);
-
- logger.debug("testAllSeemsWell: Creating emfDrools");
- EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
- "junitDroolsPU", activeStandbyProperties);
-
- DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools);
-
- logger.debug("testAllSeemsWell: Cleaning up tables");
- conn.deleteAllPdps();
-
- /*
- * Insert this PDP as not designated. Initial standby state will be
- * either null or cold standby. Demoting should transit state to
- * hot standby.
- */
-
- logger.debug("testAllSeemsWell: Inserting PDP={} as not designated", thisPdpId);
- Date yesterday = DateUtils.addDays(testTime.getDate(), -1);
- DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, false, 4, yesterday);
- conn.insertPdp(pdp);
- DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
- logger.debug("testAllSeemsWell: After insertion, PDP={} has DESIGNATED={}",
- thisPdpId, droolsPdpEntity.isDesignated());
- assertFalse(droolsPdpEntity.isDesignated());
-
- logger.debug("testAllSeemsWell: Instantiating stateManagement object");
- StateManagement sm = new StateManagement(emfXacml, "dummy");
- sm.deleteAllStateManagementEntities();
-
-
- // Now we want to create a StateManagementFeature and initialize it. It will be
- // discovered by the ActiveStandbyFeature when the election handler initializes.
-
- StateManagementFeatureApi stateManagementFeatureApi = null;
- for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
- stateManagementFeatureApi = feature;
- logger.debug("testAllSeemsWell stateManagementFeature.getResourceName(): {}",
- stateManagementFeatureApi.getResourceName());
- break;
- }
- assertNotNull(stateManagementFeatureApi);
-
- final StateManagementFeatureApi smf = stateManagementFeatureApi;
-
- // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
- // that has been created.
- ActiveStandbyFeatureApi activeStandbyFeature = null;
- for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
- activeStandbyFeature = feature;
- logger.debug("testAllSeemsWell activeStandbyFeature.getResourceName(): {}",
- activeStandbyFeature.getResourceName());
- break;
- }
- assertNotNull(activeStandbyFeature);
-
-
- logger.debug("testAllSeemsWell: Demoting PDP={}", thisPdpId);
- // demoting should cause state to transit to hotstandby
- smf.demote();
-
-
- logger.debug("testAllSeemsWell: Sleeping {} s, to allow JpaDroolsPdpsConnector "
- + "time to check droolspdpentity table", SLEEP_TIME_SEC);
- waitForCondition(() -> conn.getPdp(thisPdpId).isDesignated(), SLEEP_TIME_SEC);
-
- // Verify that this formerly un-designated PDP in HOT_STANDBY is now designated and providing service.
-
- droolsPdpEntity = conn.getPdp(thisPdpId);
- logger.debug("testAllSeemsWell: After sm.demote() invoked, DESIGNATED= {} "
- + "for PDP= {}", droolsPdpEntity.isDesignated(), thisPdpId);
- assertTrue(droolsPdpEntity.isDesignated());
- String standbyStatus = smf.getStandbyStatus(thisPdpId);
- logger.debug("testAllSeemsWell: After demotion, PDP= {} "
- + "has standbyStatus= {}", thisPdpId, standbyStatus);
- assertTrue(standbyStatus != null && standbyStatus.equals(StateManagement.PROVIDING_SERVICE));
-
- //Now we want to stall the election handler and see the if AllSeemsWell will make the
- //standbystatus = coldstandby
-
- 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 "
- + "increment forward progress and for the lack of forward progress to be recognized.",
- STALLED_ELECTION_HANDLER_SLEEP_TIME_SEC);
-
-
- //It takes 10x the update interval (1 sec) before the watcher will declare the election handler dead
- //and that just stops forward progress counter. So, the fp monitor must then run to determine
- // if the fpc has stalled. That will take about another 5 sec.
- waitForCondition(() -> smf.getStandbyStatus().equals(StateManagement.COLD_STANDBY),
- STALLED_ELECTION_HANDLER_SLEEP_TIME_SEC);
-
- logger.debug("testAllSeemsWell: After isStalled=true, PDP= {} "
- + "has standbyStatus= {}", thisPdpId, smf.getStandbyStatus(thisPdpId));
- assertEquals(StateManagement.COLD_STANDBY, smf.getStandbyStatus());
-
- //Now lets resume the election handler
- DroolsPdpsElectionHandler.setStalled(false);
-
- waitForCondition(() -> smf.getStandbyStatus().equals(StateManagement.PROVIDING_SERVICE),
- RESUMED_ELECTION_HANDLER_SLEEP_TIME_SEC);
-
- logger.debug("testAllSeemsWell: After isStalled=false, PDP= {} "
- + "has standbyStatus= {}", thisPdpId, smf.getStandbyStatus(thisPdpId));
-
- assertEquals(StateManagement.PROVIDING_SERVICE, smf.getStandbyStatus());
-
- //resumedElectionHandlerSleepTime = 5000;
- logger.debug("\n\ntestAllSeemsWell: Exiting\n\n");
-
- }
-
- private static Properties loadStateManagementProperties() throws IOException {
- try (FileInputStream input = new FileInputStream(CONFIG_DIR + "/feature-state-management.properties")) {
- Properties props = new Properties();
- props.load(input);
- return props;
- }
- }
-
- private static Properties loadActiveStandbyProperties() throws IOException {
- try (FileInputStream input =
- new FileInputStream(CONFIG_DIR + "/feature-active-standby-management.properties")) {
- Properties props = new Properties();
- props.load(input);
- return props;
- }
- }
-
- private void waitForCondition(Callable<Boolean> testCondition, int timeoutInSeconds) throws InterruptedException {
- testTime.waitUntil(testCondition);
- }
-}
diff --git a/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/DroolsPdpObjectTest.java b/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/DroolsPdpObjectTest.java
deleted file mode 100644
index 78902ec7..00000000
--- a/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/DroolsPdpObjectTest.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.activestandby;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-
-import java.util.Date;
-import lombok.Getter;
-import lombok.Setter;
-import org.junit.Before;
-import org.junit.Test;
-
-public class DroolsPdpObjectTest {
- private static final String PDP_ID = "my-id";
- private static final String PDP_ID2 = "my-id2";
- private static final String SITE = "my-site";
- private static final String SITE2 = "my-site2";
- private static final int PRIORITY = 11;
- private static final int PRIORITY2 = 12;
-
- private MyPdp pdp;
-
- @Before
- public void setUp() {
- pdp = makePdp(PDP_ID, SITE, PRIORITY);
- }
-
- @Test
- public void testEqualsObject() {
- // self
- assertEquals(pdp, pdp);
-
- // same id
- MyPdp pdp2 = new MyPdp();
- pdp2.setPdpId(PDP_ID);
- assertEquals(pdp, pdp2);
-
- // different id
- pdp2.setPdpId(PDP_ID2);
- assertNotEquals(pdp, pdp2);
-
- // different type of object
- assertNotEquals(pdp, "");
- }
-
- @Test
- public void testHashCode() {
- int hc = pdp.hashCode();
-
- // same data should yield same hash code
- assertEquals(hc, pdp.hashCode());
- assertEquals(hc, makePdp(PDP_ID, SITE, PRIORITY).hashCode());
-
- // different data should yield different hash code
- assertNotEquals(hc, makePdp(PDP_ID2, SITE, PRIORITY).hashCode());
-
- // these fields have no impact on hash code
- assertEquals(hc, makePdp(PDP_ID, SITE, PRIORITY2).hashCode());
- assertEquals(hc, makePdp(PDP_ID, SITE2, PRIORITY).hashCode());
-
- // should not throw an exception
- new MyPdp().hashCode();
- }
-
- @Test
- public void testNullSafeCompare() {
- // self, when null
- pdp.setSite(null);
- assertEquals(0, pdp.comparePriority(pdp));
-
- // both null
- MyPdp pdp2 = makePdp(PDP_ID, null, PRIORITY);
- assertEquals(0, pdp.comparePriority(pdp2));
-
- // left null
- pdp2 = makePdp(PDP_ID, SITE, PRIORITY);
- assertEquals(-1, pdp.comparePriority(pdp2));
-
- // right null - note: args are reversed
- pdp2 = makePdp(PDP_ID, SITE, PRIORITY);
- assertEquals(1, pdp2.comparePriority(pdp));
- }
-
- @Test
- public void testComparePriorityDroolsPdp() {
- // self
- assertEquals(0, pdp.comparePriority(pdp));
-
- // same
- MyPdp pdp2 = makePdp(PDP_ID, SITE, PRIORITY);
- assertEquals(0, pdp.comparePriority(pdp2));
-
- // different site
- pdp2 = makePdp(PDP_ID, SITE2, PRIORITY);
- assertEquals(SITE.compareTo(SITE2), pdp.comparePriority(pdp2));
-
- // different priority
- pdp2 = makePdp(PDP_ID, SITE, PRIORITY2);
- assertEquals(PRIORITY - PRIORITY2, pdp.comparePriority(pdp2));
-
- // different id
- pdp2 = makePdp(PDP_ID2, SITE, PRIORITY);
- assertEquals(PDP_ID.compareTo(PDP_ID2), pdp.comparePriority(pdp2));
- }
-
- @Test
- public void testComparePriorityDroolsPdpString() {
- final int result = 1000;
-
- // override other comparison method so we know if it's called
- MyPdp pdp2 = new MyPdp() {
- @Override
- public int comparePriority(DroolsPdp other) {
- return result;
- }
- };
-
- pdp2.setPdpId(PDP_ID);
- pdp2.setSite(SITE2);
- pdp2.setPriority(PRIORITY);
-
- // should use overridden comparison method
- assertEquals(result, pdp2.comparePriority(pdp, null));
- assertEquals(result, pdp2.comparePriority(pdp, ""));
-
- // should use normal comparison method
- assertEquals(SITE2.compareTo(SITE), pdp2.comparePriority(pdp, SITE));
- }
-
- private MyPdp makePdp(String id, String site, int priority) {
- MyPdp pdp2 = new MyPdp();
-
- pdp2.setSite(site);
- pdp2.setPdpId(id);
- pdp2.setPriority(priority);
-
- return pdp2;
- }
-
- @Getter
- @Setter
- private class MyPdp extends DroolsPdpObject {
- private String pdpId;
- private boolean designated;
- private int priority;
- private Date updatedDate;
- private String site;
- private Date designatedDate;
- }
-}
diff --git a/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/FactoryTest.java b/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/FactoryTest.java
deleted file mode 100644
index 8a166954..00000000
--- a/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/FactoryTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.activestandby;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class FactoryTest {
- private static Factory saveFactory;
-
- private Factory factory;
-
- @BeforeClass
- public static void setUpBeforeClass() {
- saveFactory = Factory.getInstance();
- assertNotNull(saveFactory);
- }
-
- @AfterClass
- public static void tearDownAfterClass() {
- Factory.setInstance(saveFactory);
- }
-
- @Before
- public void setUp() {
- factory = new Factory();
- }
-
- @Test
- public void testMakeTimer() {
- assertNotNull(factory.makeTimer());
- }
-
- @Test
- public void testGetInstance_testSetInstance() {
- Factory.setInstance(factory);
- assertSame(factory, Factory.getInstance());
-
- // repeat - should be the same
- assertSame(factory, Factory.getInstance());
- }
-}
diff --git a/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/PmStandbyStateChangeNotifierTest.java b/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/PmStandbyStateChangeNotifierTest.java
deleted file mode 100644
index a6dba1a6..00000000
--- a/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/PmStandbyStateChangeNotifierTest.java
+++ /dev/null
@@ -1,284 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * 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.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.activestandby;
-
-import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.Properties;
-import java.util.Timer;
-import java.util.TimerTask;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.policy.common.im.StateManagement;
-import org.onap.policy.drools.system.PolicyEngine;
-
-@RunWith(MockitoJUnitRunner.class)
-public class PmStandbyStateChangeNotifierTest {
- private static final String UNSUPPORTED_STATUS = "unsupported status";
- private static final String PDP_ID = "my-pdp";
- private static final long UPDATE_INTERVAL = 100;
- private static final long WAIT_INTERVAL = 2 * UPDATE_INTERVAL + 2000;
-
- private static Factory saveFactory;
-
- @Mock
- private Factory factory;
-
- @Mock
- private PolicyEngine engmgr;
-
- @Mock
- private Timer timer;
-
- @Mock
- private StateManagement mgmt;
-
- private PmStandbyStateChangeNotifier notifier;
-
- /**
- * Initializes the properties.
- */
- @BeforeClass
- public static void setUpBeforeClass() {
- Properties props = new Properties();
- props.setProperty(ActiveStandbyProperties.NODE_NAME, PDP_ID);
- props.setProperty(ActiveStandbyProperties.PDP_UPDATE_INTERVAL, String.valueOf(UPDATE_INTERVAL));
-
- ActiveStandbyProperties.initProperties(props);
-
- saveFactory = Factory.getInstance();
- }
-
- @AfterClass
- public static void tearDownAfterClass() {
- Factory.setInstance(saveFactory);
- }
-
- /**
- * Initializes objects, including the notifier.
- */
- @Before
- public void setUp() {
- Factory.setInstance(factory);
- when(factory.makeTimer()).thenReturn(timer);
-
- notifier = new MyNotifier();
- }
-
- @Test
- public void testHandleStateChange_Null() {
- notifier.update(mgmt, null);
- verify(engmgr).deactivate();
- assertEquals(StateManagement.NULL_VALUE, notifier.getPreviousStandbyStatus());
-
- // repeat - nothing else should be done
- when(mgmt.getStandbyStatus()).thenReturn(StateManagement.NULL_VALUE);
- notifier.update(mgmt, null);
- verify(engmgr, times(1)).deactivate();
- assertEquals(StateManagement.NULL_VALUE, notifier.getPreviousStandbyStatus());
- }
-
- @Test
- public void testHandleStateChange_Null_Ex() {
- doThrow(new MyException()).when(engmgr).deactivate();
-
- // should not throw an exception
- notifier.update(mgmt, null);
- assertEquals(PmStandbyStateChangeNotifier.NONE, notifier.getPreviousStandbyStatus());
- }
-
- @Test
- public void testHandleStateChange_HotOrCold() {
- when(mgmt.getStandbyStatus()).thenReturn(StateManagement.HOT_STANDBY);
- notifier.update(mgmt, null);
- verify(engmgr).deactivate();
- assertEquals(PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY, notifier.getPreviousStandbyStatus());
-
- // repeat - nothing else should be done
- when(mgmt.getStandbyStatus()).thenReturn(StateManagement.COLD_STANDBY);
- notifier.update(mgmt, null);
- verify(engmgr, times(1)).deactivate();
- assertEquals(PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY, notifier.getPreviousStandbyStatus());
- }
-
- @Test
- public void testHandleStateChange_HotOrCold_Ex() {
- doThrow(new MyException()).when(engmgr).deactivate();
-
- // should not throw an exception
- when(mgmt.getStandbyStatus()).thenReturn(StateManagement.HOT_STANDBY);
- notifier.update(mgmt, null);
- assertEquals(PmStandbyStateChangeNotifier.NONE, notifier.getPreviousStandbyStatus());
- }
-
- @Test
- public void testHandleStateChange_ProvidingService() {
- when(mgmt.getStandbyStatus()).thenReturn(StateManagement.PROVIDING_SERVICE);
- notifier.update(mgmt, null);
- verify(engmgr, never()).activate();
- assertEquals(PmStandbyStateChangeNotifier.NONE, notifier.getPreviousStandbyStatus());
-
- ArgumentCaptor<TimerTask> captor = ArgumentCaptor.forClass(TimerTask.class);
- verify(timer).schedule(captor.capture(), eq(WAIT_INTERVAL));
-
- // execute the timer task
- captor.getValue().run();
-
- verify(engmgr).activate();
- assertEquals(StateManagement.PROVIDING_SERVICE, notifier.getPreviousStandbyStatus());
-
- // repeat - nothing else should be done
- notifier.update(mgmt, null);
- verify(engmgr, never()).deactivate();
- verify(engmgr, times(1)).activate();
- verify(timer, times(1)).schedule(captor.capture(), eq(WAIT_INTERVAL));
- assertEquals(StateManagement.PROVIDING_SERVICE, notifier.getPreviousStandbyStatus());
- }
-
- @Test
- public void testHandleStateChange_ProvidingService_BeforeActivation() {
- when(mgmt.getStandbyStatus()).thenReturn(StateManagement.PROVIDING_SERVICE);
- notifier.update(mgmt, null);
-
- // repeat - nothing else should be done
- notifier.update(mgmt, null);
- verify(engmgr, never()).deactivate();
- verify(engmgr, never()).activate();
-
- verify(timer, times(1)).schedule(any(), eq(WAIT_INTERVAL));
- assertEquals(PmStandbyStateChangeNotifier.NONE, notifier.getPreviousStandbyStatus());
- }
-
- @Test
- public void testHandleStateChange_ProvidingService_Ex() {
- when(factory.makeTimer()).thenThrow(new MyException());
-
- when(mgmt.getStandbyStatus()).thenReturn(StateManagement.PROVIDING_SERVICE);
- notifier.update(mgmt, null);
-
- assertEquals(PmStandbyStateChangeNotifier.NONE, notifier.getPreviousStandbyStatus());
- }
-
- @Test
- public void testHandleStateChange_Unsupported() {
- when(mgmt.getStandbyStatus()).thenReturn(UNSUPPORTED_STATUS);
- notifier.update(mgmt, null);
-
- verify(engmgr).deactivate();
- assertEquals(PmStandbyStateChangeNotifier.UNSUPPORTED, notifier.getPreviousStandbyStatus());
-
- // repeat - nothing else should be done
- notifier.update(mgmt, null);
- verify(engmgr, times(1)).deactivate();
- assertEquals(PmStandbyStateChangeNotifier.UNSUPPORTED, notifier.getPreviousStandbyStatus());
- }
-
- @Test
- public void testHandleStateChange_Unsupported_Ex() {
- doThrow(new MyException()).when(engmgr).deactivate();
-
- // should not throw an exception
- when(mgmt.getStandbyStatus()).thenReturn(UNSUPPORTED_STATUS);
- notifier.update(mgmt, null);
- assertEquals(PmStandbyStateChangeNotifier.NONE, notifier.getPreviousStandbyStatus());
- }
-
- @Test
- public void testCancelTimer() {
- when(mgmt.getStandbyStatus()).thenReturn(StateManagement.PROVIDING_SERVICE);
- notifier.update(mgmt, null);
-
- when(mgmt.getStandbyStatus()).thenReturn(null);
- notifier.update(mgmt, null);
-
- verify(timer).cancel();
- }
-
- @Test
- public void testDelayActivateClass() {
- when(mgmt.getStandbyStatus()).thenReturn(StateManagement.PROVIDING_SERVICE);
- notifier.update(mgmt, null);
- verify(engmgr, never()).activate();
- assertEquals(PmStandbyStateChangeNotifier.NONE, notifier.getPreviousStandbyStatus());
-
- ArgumentCaptor<TimerTask> captor = ArgumentCaptor.forClass(TimerTask.class);
- verify(timer).schedule(captor.capture(), eq(WAIT_INTERVAL));
-
- // execute the timer task
- captor.getValue().run();
-
- verify(engmgr).activate();
- assertEquals(StateManagement.PROVIDING_SERVICE, notifier.getPreviousStandbyStatus());
- }
-
- @Test
- public void testDelayActivateClass_Ex() {
- when(mgmt.getStandbyStatus()).thenReturn(StateManagement.PROVIDING_SERVICE);
- notifier.update(mgmt, null);
- verify(engmgr, never()).activate();
- assertEquals(PmStandbyStateChangeNotifier.NONE, notifier.getPreviousStandbyStatus());
-
- ArgumentCaptor<TimerTask> captor = ArgumentCaptor.forClass(TimerTask.class);
- verify(timer).schedule(captor.capture(), eq(WAIT_INTERVAL));
-
- doThrow(new MyException()).when(engmgr).activate();
-
- // execute the timer task
- captor.getValue().run();
-
- assertEquals(PmStandbyStateChangeNotifier.NONE, notifier.getPreviousStandbyStatus());
- }
-
- @Test
- public void testGetPolicyEngineManager() {
- // use real object with real method - no exception expected
- assertThatCode(() -> new PmStandbyStateChangeNotifier().getPolicyEngineManager()).doesNotThrowAnyException();
- }
-
- private class MyNotifier extends PmStandbyStateChangeNotifier {
- @Override
- protected PolicyEngine getPolicyEngineManager() {
- return engmgr;
- }
- }
-
- private static class MyException extends RuntimeException {
- private static final long serialVersionUID = 1L;
-
- public MyException() {
- super("expected exception");
- }
- }
-}
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
deleted file mode 100644
index 52f8b27a..00000000
--- a/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/StandbyStateManagementTest.java
+++ /dev/null
@@ -1,1378 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * feature-active-standby-management
- * ================================================================================
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.activestandby;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Properties;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.EntityTransaction;
-import javax.persistence.Persistence;
-import org.apache.commons.lang3.time.DateUtils;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.common.im.AdministrativeStateException;
-import org.onap.policy.common.im.IntegrityMonitor;
-import org.onap.policy.common.im.IntegrityMonitorException;
-import org.onap.policy.common.im.MonitorTime;
-import org.onap.policy.common.im.StandbyStatusException;
-import org.onap.policy.common.im.StateManagement;
-import org.onap.policy.common.utils.time.CurrentTime;
-import org.onap.policy.common.utils.time.PseudoTimer;
-import org.onap.policy.common.utils.time.TestTimeMulti;
-import org.onap.policy.drools.core.PolicySessionFeatureApi;
-import org.onap.policy.drools.statemanagement.StateManagementFeatureApi;
-import org.onap.policy.drools.statemanagement.StateManagementFeatureApiConstants;
-import org.powermock.reflect.Whitebox;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/*
- * All JUnits are designed to run in the local development environment
- * where they have write privileges and can execute time-sensitive
- * tasks.
- */
-
-public class StandbyStateManagementTest {
- private static final Logger logger = LoggerFactory.getLogger(StandbyStateManagementTest.class);
-
- private static final String MONITOR_FIELD_NAME = "instance";
- private static final String HANDLER_INSTANCE_FIELD = "electionHandler";
-
- /*
- * Currently, the DroolsPdpsElectionHandler.DesignationWaiter is invoked every 1 seconds, starting
- * at the start of the next multiple of pdpUpdateInterval, but with a minimum of 5 sec cushion
- * to ensure that we wait for the DesignationWaiter to do its job, before
- * checking the results. Add a few seconds for safety
- */
-
- private static final long SLEEP_TIME = 10000;
-
- /*
- * DroolsPdpsElectionHandler runs every 1 seconds, so a 6 second sleep should be
- * plenty to ensure it has time to re-promote this PDP.
- */
-
- private static final long ELECTION_WAIT_SLEEP_TIME = 6000;
-
- /*
- * Sleep a few seconds after each test to allow interrupt (shutdown) recovery.
- */
-
- private static final long INTERRUPT_RECOVERY_TIME = 5000;
-
- private static EntityManagerFactory emfx;
- private static EntityManagerFactory emfd;
- private static EntityManager emx;
- private static EntityManager emd;
- private static EntityTransaction et;
-
- private static final String CONFIG_DIR = "src/test/resources";
-
- private static CurrentTime saveTime;
- private static Factory saveFactory;
-
- private TestTimeMulti testTime;
-
- /*
- * This cannot be shared by tests, as each integrity monitor may manipulate it by
- * adding its own property values.
- */
- private Properties activeStandbyProperties;
-
- /*
- * See the IntegrityMonitor.getJmxUrl() method for the rationale behind this jmx related processing.
- */
-
- /**
- * Setup the class.
- *
- * @throws Exception exception
- */
- @BeforeClass
- public static void setUpClass() throws Exception {
-
- String userDir = System.getProperty("user.dir");
- logger.debug("setUpClass: userDir={}", userDir);
- System.setProperty("com.sun.management.jmxremote.port", "9980");
- System.setProperty("com.sun.management.jmxremote.authenticate", "false");
-
- saveTime = Whitebox.getInternalState(MonitorTime.class, MONITOR_FIELD_NAME);
- saveFactory = Factory.getInstance();
-
- resetInstanceObjects();
-
- //Create the data access for xacml db
- Properties smProps = loadStateManagementProperties();
-
- emfx = Persistence.createEntityManagerFactory("junitXacmlPU", smProps);
-
- // Create an entity manager to use the DB
- emx = emfx.createEntityManager();
-
- //Create the data access for drools db
- Properties asbProps = loadActiveStandbyProperties();
-
- emfd = Persistence.createEntityManagerFactory("junitDroolsPU", asbProps);
-
- // Create an entity manager to use the DB
- emd = emfd.createEntityManager();
- }
-
- /**
- * Restores the system state.
- *
- * @throws IntegrityMonitorException if the integrity monitor cannot be shut down
- */
- @AfterClass
- public static void tearDownClass() throws IntegrityMonitorException {
- resetInstanceObjects();
-
- Whitebox.setInternalState(MonitorTime.class, MONITOR_FIELD_NAME, saveTime);
- Factory.setInstance(saveFactory);
-
- emd.close();
- emfd.close();
-
- emx.close();
- emfx.close();
- }
-
- /**
- * Setup.
- *
- * @throws Exception exception
- */
- @Before
- public void setUp() throws Exception {
- resetInstanceObjects();
- cleanXacmlDb();
- cleanDroolsDb();
-
- /*
- * set test time
- *
- * All threads use the test time object for sleeping. As a result, we don't have
- * to wait more than an instant for them to complete their work, thus we'll use
- * a very small REAL wait time in the constructor.
- */
- testTime = new TestTimeMulti(5);
- Whitebox.setInternalState(MonitorTime.class, MONITOR_FIELD_NAME, testTime);
-
- Factory factory = mock(Factory.class);
- when(factory.makeTimer()).thenAnswer(ans -> new PseudoTimer(testTime));
- Factory.setInstance(factory);
-
- activeStandbyProperties = loadActiveStandbyProperties();
- }
-
- private static void resetInstanceObjects() throws IntegrityMonitorException {
- IntegrityMonitor.setUnitTesting(true);
- IntegrityMonitor.deleteInstance();
- IntegrityMonitor.setUnitTesting(false);
-
- Whitebox.setInternalState(ActiveStandbyFeature.class, HANDLER_INSTANCE_FIELD, (Object) null);
-
- }
-
- /**
- * Clean up the xacml database.
- *
- */
- public void cleanXacmlDb() {
- et = emx.getTransaction();
-
- et.begin();
- // Make sure we leave the DB clean
- emx.createQuery("DELETE FROM StateManagementEntity").executeUpdate();
- emx.createQuery("DELETE FROM ResourceRegistrationEntity").executeUpdate();
- emx.createQuery("DELETE FROM ForwardProgressEntity").executeUpdate();
- emx.flush();
- et.commit();
- }
-
- /**
- * Clean up the drools db.
- */
- public void cleanDroolsDb() {
- et = emd.getTransaction();
-
- et.begin();
- // Make sure we leave the DB clean
- emd.createQuery("DELETE FROM DroolsPdpEntity").executeUpdate();
- emd.flush();
- et.commit();
- }
-
- /**
- * Test the standby state change notifier.
- *
- * @throws Exception exception
- */
- @Test
- public void testPmStandbyStateChangeNotifier() throws Exception {
- logger.debug("\n\ntestPmStandbyStateChangeNotifier: Entering\n\n");
-
- logger.debug("testPmStandbyStateChangeNotifier: Reading activeStandbyProperties");
-
- String resourceName = "testPMS";
- activeStandbyProperties.setProperty("resource.name", resourceName);
- ActiveStandbyProperties.initProperties(activeStandbyProperties);
-
- logger.debug("testPmStandbyStateChangeNotifier: Getting StateManagement instance");
-
- StateManagement sm = new StateManagement(emfx, resourceName);
-
- //Create an instance of the Observer
- PmStandbyStateChangeNotifier pmNotifier = new PmStandbyStateChangeNotifier();
-
- //Register the PmStandbyStateChangeNotifier Observer
- sm.addObserver(pmNotifier);
-
- //At this point the standbystatus = 'null'
- sm.lock();
- assertEquals(StateManagement.NULL_VALUE, pmNotifier.getPreviousStandbyStatus());
-
- sm.unlock();
- assertEquals(StateManagement.NULL_VALUE, pmNotifier.getPreviousStandbyStatus());
-
- //Adding standbystatus=hotstandby
- sm.demote();
- System.out.println(pmNotifier.getPreviousStandbyStatus());
- assertEquals(PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY,
- pmNotifier.getPreviousStandbyStatus());
-
- //Now making standbystatus=coldstandby
- sm.lock();
- assertEquals(PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY,
- pmNotifier.getPreviousStandbyStatus());
-
- //standbystatus = hotstandby
- sm.unlock();
- assertEquals(PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY,
- pmNotifier.getPreviousStandbyStatus());
-
- //standbystatus = providingservice
- sm.promote();
- //The previousStandbyStatus is not updated until after the delay activation expires
- assertEquals(PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY,
- pmNotifier.getPreviousStandbyStatus());
-
- //Sleep long enough for the delayActivationTimer to run
- sleep(5000);
- assertEquals(StateManagement.PROVIDING_SERVICE, pmNotifier.getPreviousStandbyStatus());
-
- //standbystatus = providingservice
- sm.promote();
- assertEquals(StateManagement.PROVIDING_SERVICE, pmNotifier.getPreviousStandbyStatus());
-
- //standbystatus = coldstandby
- sm.lock();
- assertEquals(PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY,
- pmNotifier.getPreviousStandbyStatus());
-
- //standbystatus = hotstandby
- sm.unlock();
- assertEquals(PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY,
- pmNotifier.getPreviousStandbyStatus());
-
- //standbystatus = hotstandby
- sm.demote();
- assertEquals(PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY,
- pmNotifier.getPreviousStandbyStatus());
- }
-
- /**
- * Test sanitize designated list.
- *
- * @throws Exception exception
- */
- @Test
- public void testSanitizeDesignatedList() throws Exception {
-
- logger.debug("\n\ntestSanitizeDesignatedList: Entering\n\n");
-
- // Get a DroolsPdpsConnector
-
- final DroolsPdpsConnector droolsPdpsConnector = new JpaDroolsPdpsConnector(emfd);
-
- // Create 4 pdpd all not designated
-
- DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, testTime.getDate());
- DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, testTime.getDate());
- DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, testTime.getDate());
- DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, testTime.getDate());
-
- List<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
- listOfDesignated.add(pdp1);
- listOfDesignated.add(pdp2);
- listOfDesignated.add(pdp3);
- listOfDesignated.add(pdp4);
-
- // Now we want to create a StateManagementFeature and initialize it. It will be
- // discovered by the ActiveStandbyFeature when the election handler initializes.
-
- StateManagementFeatureApi stateManagementFeature = null;
- for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
- stateManagementFeature = feature;
- logger.debug("testColdStandby stateManagementFeature.getResourceName(): {}",
- stateManagementFeature.getResourceName());
- break;
- }
- assertNotNull(stateManagementFeature);
-
-
- DroolsPdpsElectionHandler droolsPdpsElectionHandler = new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1);
-
- listOfDesignated = droolsPdpsElectionHandler.santizeDesignatedList(listOfDesignated);
-
- logger.debug("\n\ntestSanitizeDesignatedList: listOfDesignated.size = {}\n\n", listOfDesignated.size());
-
- assertEquals(4, listOfDesignated.size());
-
- // Now make 2 designated
-
- pdp1.setDesignated(true);
- pdp2.setDesignated(true);
-
- listOfDesignated = droolsPdpsElectionHandler.santizeDesignatedList(listOfDesignated);
-
- logger.debug("\n\ntestSanitizeDesignatedList: listOfDesignated.size after 2 designated = {}\n\n",
- listOfDesignated.size());
-
- assertEquals(2, listOfDesignated.size());
- assertTrue(listOfDesignated.contains(pdp1));
- assertTrue(listOfDesignated.contains(pdp2));
-
-
- // Now all are designated. But, we have to add back the previously non-designated nodes
-
- pdp3.setDesignated(true);
- pdp4.setDesignated(true);
- listOfDesignated.add(pdp3);
- listOfDesignated.add(pdp4);
-
- listOfDesignated = droolsPdpsElectionHandler.santizeDesignatedList(listOfDesignated);
-
- logger.debug("\n\ntestSanitizeDesignatedList: listOfDesignated.size after all designated = {}\n\n",
- listOfDesignated.size());
-
- assertEquals(4, listOfDesignated.size());
-
- }
-
- /**
- * Test Compute most recent primary.
- *
- * @throws Exception exception
- */
- @Test
- public void testComputeMostRecentPrimary() throws Exception {
-
- logger.debug("\n\ntestComputeMostRecentPrimary: Entering\n\n");
-
- final DroolsPdpsConnector droolsPdpsConnector = new JpaDroolsPdpsConnector(emfd);
-
-
- // Create 4 pdpd all not designated
-
-
- long designatedDateMs = testTime.getMillis();
- DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, testTime.getDate());
- pdp1.setDesignatedDate(new Date(designatedDateMs - 2));
-
- DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, testTime.getDate());
- //oldest
- pdp2.setDesignatedDate(new Date(designatedDateMs - 3));
-
- DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, testTime.getDate());
- pdp3.setDesignatedDate(new Date(designatedDateMs - 1));
-
- DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, testTime.getDate());
- //most recent
- pdp4.setDesignatedDate(new Date(designatedDateMs));
-
- ArrayList<DroolsPdp> listOfAllPdps = new ArrayList<DroolsPdp>();
- listOfAllPdps.add(pdp1);
- listOfAllPdps.add(pdp2);
- listOfAllPdps.add(pdp3);
- listOfAllPdps.add(pdp4);
-
-
- ArrayList<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
- listOfDesignated.add(pdp1);
- listOfDesignated.add(pdp2);
- listOfDesignated.add(pdp3);
- listOfDesignated.add(pdp4);
-
- // Because the way we sanitize the listOfDesignated, it will always contain all hot standby
- // or all designated members.
-
- // Now we want to create a StateManagementFeature and initialize it. It will be
- // discovered by the ActiveStandbyFeature when the election handler initializes.
-
- StateManagementFeatureApi stateManagementFeature = null;
- for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
- stateManagementFeature = feature;
- logger.debug("testComputeMostRecentPrimary stateManagementFeature.getResourceName(): {}",
- stateManagementFeature.getResourceName());
- break;
- }
- assertNotNull(stateManagementFeature);
-
- DroolsPdpsElectionHandler droolsPdpsElectionHandler = new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1);
-
- DroolsPdp mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(
- listOfAllPdps, listOfDesignated);
-
- logger.debug("\n\ntestComputeMostRecentPrimary: mostRecentPrimary.getPdpId() = {}\n\n",
- mostRecentPrimary.getPdpId());
-
-
- // If all of the pdps are included in the listOfDesignated and none are designated, it will choose
- // the one which has the most recent designated date.
-
-
- assertEquals("pdp4", mostRecentPrimary.getPdpId());
-
-
- // Now let's designate all of those on the listOfDesignated. It will choose the first one designated
-
-
- pdp1.setDesignated(true);
- pdp2.setDesignated(true);
- pdp3.setDesignated(true);
- pdp4.setDesignated(true);
-
- mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
-
- logger.debug("\n\ntestComputeMostRecentPrimary: All designated all on list, "
- + "mostRecentPrimary.getPdpId() = {}\n\n",
- mostRecentPrimary.getPdpId());
-
-
- // If all of the pdps are included in the listOfDesignated and all are designated, it will choose
- // the one which was designated first
-
-
- assertEquals("pdp2", mostRecentPrimary.getPdpId());
-
-
- // Now we will designate only 2 and put just them in the listOfDesignated. The algorithm will now
- // look for the most recently designated pdp which is not currently designated.
-
-
- pdp3.setDesignated(false);
- pdp4.setDesignated(false);
-
- listOfDesignated.remove(pdp3);
- listOfDesignated.remove(pdp4);
-
- mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
-
- logger.debug("\n\ntestComputeMostRecentPrimary: mostRecentPrimary.getPdpId() = {}\n\n",
- mostRecentPrimary.getPdpId());
-
- assertEquals("pdp4", mostRecentPrimary.getPdpId());
-
-
-
- // Now we will have none designated and put two of them in the listOfDesignated. The algorithm will now
- // look for the most recently designated pdp regardless of whether it is currently marked as designated.
-
-
- pdp1.setDesignated(false);
- pdp2.setDesignated(false);
-
- mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
-
- logger.debug("\n\ntestComputeMostRecentPrimary: 2 on list mostRecentPrimary.getPdpId() = {}\n\n",
- mostRecentPrimary.getPdpId());
-
- assertEquals("pdp4", mostRecentPrimary.getPdpId());
-
-
- // If we have only one pdp on in the listOfDesignated,
- // the most recently designated pdp will be chosen, regardless
- // of its designation status
-
-
- listOfDesignated.remove(pdp1);
-
- mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
-
- logger.debug("\n\ntestComputeMostRecentPrimary: 1 on list mostRecentPrimary.getPdpId() = {}\n\n",
- mostRecentPrimary.getPdpId());
-
- assertEquals("pdp4", mostRecentPrimary.getPdpId());
-
-
- // Finally, if none are on the listOfDesignated, it will again choose the most recently designated pdp.
-
-
- listOfDesignated.remove(pdp2);
-
- mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
-
- logger.debug("\n\ntestComputeMostRecentPrimary: 0 on list mostRecentPrimary.getPdpId() = {}\n\n",
- mostRecentPrimary.getPdpId());
-
- assertEquals("pdp4", mostRecentPrimary.getPdpId());
-
- }
-
- /**
- * Test compute designated PDP.
- *
- * @throws Exception exception
- */
- @Test
- public void testComputeDesignatedPdp() throws Exception {
-
- logger.debug("\n\ntestComputeDesignatedPdp: Entering\n\n");
-
- final DroolsPdpsConnector droolsPdpsConnector = new JpaDroolsPdpsConnector(emfd);
-
-
- // Create 4 pdpd all not designated. Two on site1. Two on site2
-
-
- long designatedDateMs = testTime.getMillis();
- DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, testTime.getDate());
- pdp1.setDesignatedDate(new Date(designatedDateMs - 2));
- pdp1.setSite("site1");
-
- DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, testTime.getDate());
- pdp2.setDesignatedDate(new Date(designatedDateMs - 3));
- pdp2.setSite("site1");
-
- //oldest
- DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, testTime.getDate());
- pdp3.setDesignatedDate(new Date(designatedDateMs - 4));
- pdp3.setSite("site2");
-
- DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, testTime.getDate());
- //most recent
- pdp4.setDesignatedDate(new Date(designatedDateMs));
- pdp4.setSite("site2");
-
- ArrayList<DroolsPdp> listOfAllPdps = new ArrayList<DroolsPdp>();
- listOfAllPdps.add(pdp1);
- listOfAllPdps.add(pdp2);
- listOfAllPdps.add(pdp3);
- listOfAllPdps.add(pdp4);
-
-
- ArrayList<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
-
-
- // We will first test an empty listOfDesignated. As we know from the previous JUnit,
- // the pdp with the most designated date will be chosen for mostRecentPrimary
-
- // Now we want to create a StateManagementFeature and initialize it. It will be
- // discovered by the ActiveStandbyFeature when the election handler initializes.
-
- StateManagementFeatureApi stateManagementFeature = null;
- for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
- stateManagementFeature = feature;
- logger.debug("testComputeDesignatedPdp stateManagementFeature.getResourceName(): {}",
- stateManagementFeature.getResourceName());
- break;
- }
- assertNotNull(stateManagementFeature);
-
-
- DroolsPdpsElectionHandler droolsPdpsElectionHandler = new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1);
-
- DroolsPdp mostRecentPrimary = pdp4;
-
- DroolsPdp designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
-
-
- // The designatedPdp should be null
-
- assertNull(designatedPdp);
-
-
- // Now let's try having only one pdp in listOfDesignated, but not in the same site as the most recent primary
-
- listOfDesignated.add(pdp2);
-
- designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
-
-
- // Now the designatedPdp should be the one and only selection in the listOfDesignated
-
-
- assertEquals(designatedPdp.getPdpId(), pdp2.getPdpId());
-
-
- // Now let's put 2 pdps in the listOfDesignated, neither in the same site as the mostRecentPrimary
-
-
- listOfDesignated.add(pdp1);
-
- designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
-
-
- // The designatedPdp should now be the one with the lowest lexiographic score - pdp1
-
-
- assertEquals(designatedPdp.getPdpId(), pdp1.getPdpId());
-
-
- // Finally, we will have 2 pdps in the listOfDesignated, one in the same site with the mostRecentPrimary
-
-
- listOfDesignated.remove(pdp1);
- listOfDesignated.add(pdp3);
-
- designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
-
-
- // The designatedPdp should now be the one on the same site as the mostRecentPrimary
-
-
- assertEquals(designatedPdp.getPdpId(), pdp3.getPdpId());
- }
-
- /**
- * Test cold standby.
- *
- * @throws Exception exception
- */
- @Test
- public void testColdStandby() throws Exception {
-
- logger.debug("\n\ntestColdStandby: Entering\n\n");
-
- final String thisPdpId = activeStandbyProperties.getProperty(ActiveStandbyProperties.NODE_NAME);
-
- DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfd);
-
- logger.debug("testColdStandby: Inserting PDP={} as designated", thisPdpId);
- DroolsPdp pdp = new DroolsPdpImpl(thisPdpId, true, 4, testTime.getDate());
- conn.insertPdp(pdp);
- DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
- logger.debug("testColdStandby: After insertion, DESIGNATED= {} "
- + "for PDP= {}", droolsPdpEntity.isDesignated(), thisPdpId);
- assertTrue(droolsPdpEntity.isDesignated());
-
- /*
- * When the Standby Status changes (from providingservice) to hotstandby
- * or coldstandby,the Active/Standby selection algorithm must stand down
- * if thePDP-D is currently the lead/active node and allow another PDP-D
- * to take over.
- *
- * It must also call lock on all engines in the engine management.
- */
-
-
- /*
- * Yes, this is kludgy, but we have a chicken and egg problem here: we
- * need a StateManagement object to invoke the
- * deleteAllStateManagementEntities method.
- */
- logger.debug("testColdStandby: Instantiating stateManagement object");
-
- StateManagement sm = new StateManagement(emfx, "dummy");
- sm.deleteAllStateManagementEntities();
-
- // Now we want to create a StateManagementFeature and initialize it. It will be
- // discovered by the ActiveStandbyFeature when the election handler initializes.
-
- StateManagementFeatureApi smf = null;
- for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
- smf = feature;
- logger.debug("testColdStandby stateManagementFeature.getResourceName(): {}", smf.getResourceName());
- break;
- }
- assertNotNull(smf);
-
- // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
- // that has been created.
- ActiveStandbyFeatureApi activeStandbyFeature = null;
- for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
- activeStandbyFeature = feature;
- logger.debug("testColdStandby activeStandbyFeature.getResourceName(): {}",
- activeStandbyFeature.getResourceName());
- break;
- }
- assertNotNull(activeStandbyFeature);
-
- // Artificially putting a PDP into service is really a two step process, 1)
- // inserting it as designated and 2) promoting it so that its standbyStatus
- // is providing service.
-
- logger.debug("testColdStandby: Runner started; Sleeping "
- + INTERRUPT_RECOVERY_TIME + "ms before promoting PDP= {}",
- thisPdpId);
- sleep(INTERRUPT_RECOVERY_TIME);
-
- logger.debug("testColdStandby: Promoting PDP={}", thisPdpId);
- smf.promote();
-
- String standbyStatus = sm.getStandbyStatus(thisPdpId);
- logger.debug("testColdStandby: Before locking, PDP= {} has standbyStatus= {}",
- thisPdpId, standbyStatus);
-
- logger.debug("testColdStandby: Locking smf");
- smf.lock();
-
- sleep(INTERRUPT_RECOVERY_TIME);
-
- // Verify that the PDP is no longer designated.
-
- droolsPdpEntity = conn.getPdp(thisPdpId);
- logger.debug("testColdStandby: After lock sm.lock() invoked, "
- + "DESIGNATED= {} for PDP={}", droolsPdpEntity.isDesignated(), thisPdpId);
- assertFalse(droolsPdpEntity.isDesignated());
-
- logger.debug("\n\ntestColdStandby: Exiting\n\n");
- }
-
- // Tests hot standby when there is only one PDP.
-
- /**
- * Test hot standby 1.
- *
- * @throws Exception exception
- */
- @Test
- public void testHotStandby1() throws Exception {
-
- logger.debug("\n\ntestHotStandby1: Entering\n\n");
-
- final String thisPdpId = activeStandbyProperties
- .getProperty(ActiveStandbyProperties.NODE_NAME);
-
- DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfd);
-
- /*
- * Insert this PDP as not designated. Initial standby state will be
- * either null or cold standby. Demoting should transit state to
- * hot standby.
- */
-
- logger.debug("testHotStandby1: Inserting PDP={} as not designated", thisPdpId);
- Date yesterday = DateUtils.addDays(testTime.getDate(), -1);
- DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, false, 4, yesterday);
- conn.insertPdp(pdp);
- DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
- logger.debug("testHotStandby1: After insertion, PDP={} has DESIGNATED={}",
- thisPdpId, droolsPdpEntity.isDesignated());
- assertFalse(droolsPdpEntity.isDesignated());
-
- logger.debug("testHotStandby1: Instantiating stateManagement object");
- StateManagement sm = new StateManagement(emfx, "dummy");
- sm.deleteAllStateManagementEntities();
-
-
- // Now we want to create a StateManagementFeature and initialize it. It will be
- // discovered by the ActiveStandbyFeature when the election handler initializes.
-
- StateManagementFeatureApi smf = null;
- for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
- smf = feature;
- logger.debug("testHotStandby1 stateManagementFeature.getResourceName(): {}", smf.getResourceName());
- break;
- }
- assertNotNull(smf);
-
- // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
- // that has been created.
- ActiveStandbyFeatureApi activeStandbyFeature = null;
- for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
- activeStandbyFeature = feature;
- logger.debug("testHotStandby1 activeStandbyFeature.getResourceName(): {}",
- activeStandbyFeature.getResourceName());
- break;
- }
- assertNotNull(activeStandbyFeature);
-
-
- logger.debug("testHotStandby1: Demoting PDP={}", thisPdpId);
- // demoting should cause state to transit to hotstandby
- smf.demote();
-
-
- logger.debug("testHotStandby1: Sleeping {} ms, to allow JpaDroolsPdpsConnector "
- + "time to check droolspdpentity table", SLEEP_TIME);
- sleep(SLEEP_TIME);
-
-
- // Verify that this formerly un-designated PDP in HOT_STANDBY is now designated and providing service.
-
- droolsPdpEntity = conn.getPdp(thisPdpId);
- logger.debug("testHotStandby1: After sm.demote() invoked, DESIGNATED= {} "
- + "for PDP= {}", droolsPdpEntity.isDesignated(), thisPdpId);
- assertTrue(droolsPdpEntity.isDesignated());
- String standbyStatus = smf.getStandbyStatus(thisPdpId);
- logger.debug("testHotStandby1: After demotion, PDP= {} "
- + "has standbyStatus= {}", thisPdpId, standbyStatus);
- assertTrue(standbyStatus != null && standbyStatus.equals(StateManagement.PROVIDING_SERVICE));
-
- logger.debug("testHotStandby1: Stopping policyManagementRunner");
-
- logger.debug("\n\ntestHotStandby1: Exiting\n\n");
- }
-
- /*
- * Tests hot standby when two PDPs are involved.
- */
-
- /**
- * Test hot standby 2.
- *
- * @throws Exception exception
- */
- @Test
- public void testHotStandby2() throws Exception {
-
- logger.info("\n\ntestHotStandby2: Entering\n\n");
-
- final String thisPdpId = activeStandbyProperties
- .getProperty(ActiveStandbyProperties.NODE_NAME);
-
- DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfd);
-
-
- // Insert a PDP that's designated but not current.
-
- String activePdpId = "pdp2";
- logger.info("testHotStandby2: Inserting PDP={} as stale, designated PDP", activePdpId);
- Date yesterday = DateUtils.addDays(testTime.getDate(), -1);
- DroolsPdp pdp = new DroolsPdpImpl(activePdpId, true, 4, yesterday);
- conn.insertPdp(pdp);
- DroolsPdpEntity droolsPdpEntity = conn.getPdp(activePdpId);
- logger.info("testHotStandby2: After insertion, PDP= {}, which is "
- + "not current, has DESIGNATED= {}", activePdpId, droolsPdpEntity.isDesignated());
- assertTrue(droolsPdpEntity.isDesignated());
-
- /*
- * Promote the designated PDP.
- *
- * We have a chicken and egg problem here: we need a StateManagement
- * object to invoke the deleteAllStateManagementEntities method.
- */
-
-
- logger.info("testHotStandby2: Promoting PDP={}", activePdpId);
- StateManagement sm = new StateManagement(emfx, "dummy");
- sm.deleteAllStateManagementEntities();
-
-
- sm = new StateManagement(emfx, activePdpId); //pdp2
-
- // Artificially putting a PDP into service is really a two step process, 1)
- // inserting it as designated and 2) promoting it so that its standbyStatus
- // is providing service.
-
- /*
- * Insert this PDP as not designated. Initial standby state will be
- * either null or cold standby. Demoting should transit state to
- * hot standby.
- */
-
-
- logger.info("testHotStandby2: Inserting PDP= {} as not designated", thisPdpId);
- pdp = new DroolsPdpImpl(thisPdpId, false, 4, yesterday);
- conn.insertPdp(pdp);
- droolsPdpEntity = conn.getPdp(thisPdpId);
- logger.info("testHotStandby2: After insertion, PDP={} "
- + "has DESIGNATED= {}", thisPdpId, droolsPdpEntity.isDesignated());
- assertFalse(droolsPdpEntity.isDesignated());
-
-
- // Now we want to create a StateManagementFeature and initialize it. It will be
- // discovered by the ActiveStandbyFeature when the election handler initializes.
-
- StateManagementFeatureApi sm2 = null;
- for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
- sm2 = feature;
- logger.debug("testHotStandby2 stateManagementFeature.getResourceName(): {}", sm2.getResourceName());
- break;
- }
- assertNotNull(sm2);
-
- // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
- // that has been created.
- ActiveStandbyFeatureApi activeStandbyFeature = null;
- for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
- activeStandbyFeature = feature;
- logger.debug("testHotStandby2 activeStandbyFeature.getResourceName(): {}",
- activeStandbyFeature.getResourceName());
- break;
- }
- assertNotNull(activeStandbyFeature);
-
- logger.info("testHotStandby2: Runner started; Sleeping {} "
- + "ms before promoting/demoting", INTERRUPT_RECOVERY_TIME);
- sleep(INTERRUPT_RECOVERY_TIME);
-
- logger.info("testHotStandby2: Runner started; promoting PDP={}", activePdpId);
- //At this point, the newly created pdp will have set the state to disabled/failed/cold standby
- //because it is stale. So, it cannot be promoted. We need to call sm.enableNotFailed() so we
- //can promote it and demote the other pdp - else the other pdp will just spring back to providingservice
- sm.enableNotFailed(); //pdp2
- sm.promote();
- String standbyStatus = sm.getStandbyStatus(activePdpId);
- logger.info("testHotStandby2: After promoting, PDP= {} has standbyStatus= {}", activePdpId, standbyStatus);
-
- // demoting PDP should ensure that state transits to hotstandby
- logger.info("testHotStandby2: Runner started; demoting PDP= {}", thisPdpId);
- sm2.demote(); //pdp1
- standbyStatus = sm.getStandbyStatus(thisPdpId);
- logger.info("testHotStandby2: After demoting, PDP={} has standbyStatus= {}", thisPdpId, standbyStatus);
-
- logger.info("testHotStandby2: Sleeping {} ms, to allow JpaDroolsPdpsConnector "
- + "time to check droolspdpentity table", SLEEP_TIME);
- sleep(SLEEP_TIME);
-
- /*
- * Verify that this PDP, demoted to HOT_STANDBY, is now
- * re-designated and providing service.
- */
-
- droolsPdpEntity = conn.getPdp(thisPdpId);
- logger.info("testHotStandby2: After demoting PDP={}"
- + ", DESIGNATED= {}"
- + " for PDP= {}", activePdpId, droolsPdpEntity.isDesignated(), thisPdpId);
- assertTrue(droolsPdpEntity.isDesignated());
- standbyStatus = sm2.getStandbyStatus(thisPdpId);
- logger.info("testHotStandby2: After demoting PDP={}"
- + ", PDP={} has standbyStatus= {}",
- activePdpId, thisPdpId, standbyStatus);
- assertTrue(standbyStatus != null
- && standbyStatus.equals(StateManagement.PROVIDING_SERVICE));
-
- logger.info("testHotStandby2: Stopping policyManagementRunner");
-
- logger.info("\n\ntestHotStandby2: Exiting\n\n");
- }
-
- /*
- * 1) Inserts and designates this PDP, then verifies that startTransaction
- * is successful.
- *
- * 2) Demotes PDP, and verifies that because there is only one PDP, it will
- * be immediately re-promoted, thus allowing startTransaction to be
- * successful.
- *
- * 3) Locks PDP and verifies that startTransaction results in
- * AdministrativeStateException.
- *
- * 4) Unlocks PDP and verifies that startTransaction results in
- * StandbyStatusException.
- *
- * 5) Promotes PDP and verifies that startTransaction is once again
- * successful.
- */
-
- /**
- * Test locking.
- *
- * @throws Exception exception
- */
- @Test
- public void testLocking1() throws Exception {
- logger.debug("testLocking1: Entry");
-
- final String thisPdpId = activeStandbyProperties
- .getProperty(ActiveStandbyProperties.NODE_NAME);
-
- DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfd);
-
- /*
- * Insert this PDP as designated. Initial standby state will be
- * either null or cold standby.
- */
-
- logger.debug("testLocking1: Inserting PDP= {} as designated", thisPdpId);
- DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, true, 4, testTime.getDate());
- conn.insertPdp(pdp);
- DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
- logger.debug("testLocking1: After insertion, PDP= {} has DESIGNATED= {}",
- thisPdpId, droolsPdpEntity.isDesignated());
- assertTrue(droolsPdpEntity.isDesignated());
-
- logger.debug("testLocking1: Instantiating stateManagement object");
- StateManagement smDummy = new StateManagement(emfx, "dummy");
- smDummy.deleteAllStateManagementEntities();
-
- // Now we want to create a StateManagementFeature and initialize it. It will be
- // discovered by the ActiveStandbyFeature when the election handler initializes.
-
- StateManagementFeatureApi sm = null;
- for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
- sm = feature;
- logger.debug("testLocking1 stateManagementFeature.getResourceName(): {}", sm.getResourceName());
- break;
- }
- assertNotNull(sm);
-
- // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
- // that has been created.
- ActiveStandbyFeatureApi activeStandbyFeature = null;
- for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
- activeStandbyFeature = feature;
- logger.debug("testLocking1 activeStandbyFeature.getResourceName(): {}",
- activeStandbyFeature.getResourceName());
- break;
- }
- assertNotNull(activeStandbyFeature);
-
- logger.debug("testLocking1: Runner started; Sleeping "
- + INTERRUPT_RECOVERY_TIME + "ms before promoting PDP={}",
- thisPdpId);
- sleep(INTERRUPT_RECOVERY_TIME);
-
- logger.debug("testLocking1: Promoting PDP={}", thisPdpId);
- sm.promote();
-
- logger.debug("testLocking1: Sleeping {} ms, to allow time for "
- + "policy-management.Main class to come up, designated= {}",
- SLEEP_TIME, conn.getPdp(thisPdpId).isDesignated());
- sleep(SLEEP_TIME);
-
- logger.debug("testLocking1: Waking up and invoking startTransaction on active PDP={}"
- + ", designated= {}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
-
-
- IntegrityMonitor droolsPdpIntegrityMonitor = IntegrityMonitor.getInstance();
- try {
- droolsPdpIntegrityMonitor.startTransaction();
- droolsPdpIntegrityMonitor.endTransaction();
- logger.debug("testLocking1: As expected, transaction successful");
- } catch (AdministrativeStateException e) {
- logger.error("testLocking1: Unexpectedly caught AdministrativeStateException, ", e);
- assertTrue(false);
- } catch (StandbyStatusException e) {
- logger.error("testLocking1: Unexpectedly caught StandbyStatusException, ", e);
- assertTrue(false);
- } catch (Exception e) {
- logger.error("testLocking1: Unexpectedly caught Exception, ", e);
- assertTrue(false);
- }
-
- // demoting should cause state to transit to hotstandby, followed by re-promotion,
- // since there is only one PDP.
- logger.debug("testLocking1: demoting PDP={}", thisPdpId);
- sm.demote();
-
- logger.debug("testLocking1: sleeping" + ELECTION_WAIT_SLEEP_TIME
- + " to allow election handler to re-promote PDP={}", thisPdpId);
- sleep(ELECTION_WAIT_SLEEP_TIME);
-
- logger.debug("testLocking1: Invoking startTransaction on re-promoted PDP={}"
- + ", designated={}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
- try {
- droolsPdpIntegrityMonitor.startTransaction();
- droolsPdpIntegrityMonitor.endTransaction();
- logger.debug("testLocking1: As expected, transaction successful");
- } catch (AdministrativeStateException e) {
- logger.error("testLocking1: Unexpectedly caught AdministrativeStateException, ", e);
- assertTrue(false);
- } catch (StandbyStatusException e) {
- logger.error("testLocking1: Unexpectedly caught StandbyStatusException, ", e);
- assertTrue(false);
- } catch (Exception e) {
- logger.error("testLocking1: Unexpectedly caught Exception, ", e);
- assertTrue(false);
- }
-
- // locking should cause state to transit to cold standby
- logger.debug("testLocking1: locking PDP={}", thisPdpId);
- sm.lock();
-
- // Just to avoid any race conditions, sleep a little after locking
- logger.debug("testLocking1: Sleeping a few millis after locking, to avoid race condition");
- sleep(100);
-
- logger.debug("testLocking1: Invoking startTransaction on locked PDP= {}"
- + ", designated= {}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
- try {
- droolsPdpIntegrityMonitor.startTransaction();
- logger.error("testLocking1: startTransaction unexpectedly successful");
- assertTrue(false);
- } catch (AdministrativeStateException e) {
- logger.debug("testLocking1: As expected, caught AdministrativeStateException, ", e);
- } catch (StandbyStatusException e) {
- logger.error("testLocking1: Unexpectedly caught StandbyStatusException, ", e);
- assertTrue(false);
- } catch (Exception e) {
- logger.error("testLocking1: Unexpectedly caught Exception, ", e);
- assertTrue(false);
- } finally {
- droolsPdpIntegrityMonitor.endTransaction();
- }
-
- // unlocking should cause state to transit to hot standby and then providing service
- logger.debug("testLocking1: unlocking PDP={}", thisPdpId);
- sm.unlock();
-
- // Just to avoid any race conditions, sleep a little after locking
- logger.debug("testLocking1: Sleeping a few millis after unlocking, to avoid race condition");
- sleep(ELECTION_WAIT_SLEEP_TIME);
-
- logger.debug("testLocking1: Invoking startTransaction on unlocked PDP="
- + thisPdpId
- + ", designated="
- + conn.getPdp(thisPdpId).isDesignated());
- try {
- droolsPdpIntegrityMonitor.startTransaction();
- logger.error("testLocking1: startTransaction successful as expected");
- } catch (AdministrativeStateException e) {
- logger.error("testLocking1: Unexpectedly caught AdministrativeStateException, ", e);
- assertTrue(false);
- } catch (StandbyStatusException e) {
- logger.debug("testLocking1: Unexpectedly caught StandbyStatusException, ", e);
- assertTrue(false);
- } catch (Exception e) {
- logger.error("testLocking1: Unexpectedly caught Exception, ", e);
- assertTrue(false);
- } finally {
- droolsPdpIntegrityMonitor.endTransaction();
- }
-
- // demoting should cause state to transit to hot standby
- logger.debug("testLocking1: demoting PDP={}", thisPdpId);
- sm.demote();
-
- logger.debug("testLocking1: Invoking startTransaction on demoted PDP={}"
- + ", designated={}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
- try {
- droolsPdpIntegrityMonitor.startTransaction();
- droolsPdpIntegrityMonitor.endTransaction();
- logger.debug("testLocking1: Unexpectedly, transaction successful");
- assertTrue(false);
- } catch (AdministrativeStateException e) {
- logger.error("testLocking1: Unexpectedly caught AdministrativeStateException, ", e);
- assertTrue(false);
- } catch (StandbyStatusException e) {
- logger.error("testLocking1: As expected caught StandbyStatusException, ", e);
- } catch (Exception e) {
- logger.error("testLocking1: Unexpectedly caught Exception, ", e);
- assertTrue(false);
- }
-
- logger.debug("\n\ntestLocking1: Exiting\n\n");
- }
-
-
- /*
- * 1) Inserts and designates this PDP, then verifies that startTransaction
- * is successful.
- *
- * 2) Inserts another PDP in hotstandby.
- *
- * 3) Demotes this PDP, and verifies 1) that other PDP is not promoted (because one
- * PDP cannot promote another PDP) and 2) that this PDP is re-promoted.
- */
-
- /**
- * Test locking 2.
- *
- * @throws Exception exception
- */
- @Test
- public void testLocking2() throws Exception {
-
- logger.debug("\n\ntestLocking2: Entering\n\n");
-
- final String thisPdpId = activeStandbyProperties
- .getProperty(ActiveStandbyProperties.NODE_NAME);
-
- DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfd);
-
- /*
- * Insert this PDP as designated. Initial standby state will be
- * either null or cold standby. Demoting should transit state to
- * hot standby.
- */
-
- logger.debug("testLocking2: Inserting PDP= {} as designated", thisPdpId);
- DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, true, 3, testTime.getDate());
- conn.insertPdp(pdp);
- DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
- logger.debug("testLocking2: After insertion, PDP= {} has DESIGNATED= {}",
- thisPdpId, droolsPdpEntity.isDesignated());
- assertTrue(droolsPdpEntity.isDesignated());
-
- logger.debug("testLocking2: Instantiating stateManagement object and promoting PDP={}", thisPdpId);
- StateManagement smDummy = new StateManagement(emfx, "dummy");
- smDummy.deleteAllStateManagementEntities();
-
- // Now we want to create a StateManagementFeature and initialize it. It will be
- // discovered by the ActiveStandbyFeature when the election handler initializes.
-
- StateManagementFeatureApi sm = null;
- for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
- sm = feature;
- logger.debug("testLocking2 stateManagementFeature.getResourceName(): {}", sm.getResourceName());
- break;
- }
- assertNotNull(sm);
-
- // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
- // that has been created.
- ActiveStandbyFeatureApi activeStandbyFeature = null;
- for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
- activeStandbyFeature = feature;
- logger.debug("testLocking2 activeStandbyFeature.getResourceName(): {}",
- activeStandbyFeature.getResourceName());
- break;
- }
- assertNotNull(activeStandbyFeature);
-
- /*
- * Insert another PDP as not designated. Initial standby state will be
- * either null or cold standby. Demoting should transit state to
- * hot standby.
- */
-
- String standbyPdpId = "pdp2";
- logger.debug("testLocking2: Inserting PDP= {} as not designated", standbyPdpId);
- Date yesterday = DateUtils.addDays(testTime.getDate(), -1);
- pdp = new DroolsPdpImpl(standbyPdpId, false, 4, yesterday);
- conn.insertPdp(pdp);
- droolsPdpEntity = conn.getPdp(standbyPdpId);
- logger.debug("testLocking2: After insertion, PDP={} has DESIGNATED= {}",
- standbyPdpId, droolsPdpEntity.isDesignated());
- assertFalse(droolsPdpEntity.isDesignated());
-
- logger.debug("testLocking2: Demoting PDP= {}", standbyPdpId);
- final StateManagement sm2 = new StateManagement(emfx, standbyPdpId);
-
- logger.debug("testLocking2: Runner started; Sleeping {} ms "
- + "before promoting/demoting", INTERRUPT_RECOVERY_TIME);
- sleep(INTERRUPT_RECOVERY_TIME);
-
- logger.debug("testLocking2: Promoting PDP= {}", thisPdpId);
- sm.promote();
-
- // demoting PDP should ensure that state transits to hotstandby
- logger.debug("testLocking2: Demoting PDP={}", standbyPdpId);
- sm2.demote();
-
- logger.debug("testLocking2: Sleeping {} ms, to allow time for to come up", SLEEP_TIME);
- sleep(SLEEP_TIME);
-
- logger.debug("testLocking2: Waking up and invoking startTransaction on active PDP={}"
- + ", designated= {}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
-
- IntegrityMonitor droolsPdpIntegrityMonitor = IntegrityMonitor.getInstance();
-
- try {
- droolsPdpIntegrityMonitor.startTransaction();
- droolsPdpIntegrityMonitor.endTransaction();
- logger.debug("testLocking2: As expected, transaction successful");
- } catch (AdministrativeStateException e) {
- logger.error("testLocking2: Unexpectedly caught AdministrativeStateException, ", e);
- assertTrue(false);
- } catch (StandbyStatusException e) {
- logger.error("testLocking2: Unexpectedly caught StandbyStatusException, ", e);
- assertTrue(false);
- } catch (Exception e) {
- logger.error("testLocking2: Unexpectedly caught Exception, ", e);
- assertTrue(false);
- }
-
- // demoting should cause state to transit to hotstandby followed by re-promotion.
- logger.debug("testLocking2: demoting PDP={}", thisPdpId);
- sm.demote();
-
- logger.debug("testLocking2: sleeping {}"
- + " to allow election handler to re-promote PDP={}", ELECTION_WAIT_SLEEP_TIME, thisPdpId);
- sleep(ELECTION_WAIT_SLEEP_TIME);
-
- logger.debug("testLocking2: Waking up and invoking startTransaction "
- + "on re-promoted PDP= {}, designated= {}",
- thisPdpId, conn.getPdp(thisPdpId).isDesignated());
- try {
- droolsPdpIntegrityMonitor.startTransaction();
- droolsPdpIntegrityMonitor.endTransaction();
- logger.debug("testLocking2: As expected, transaction successful");
- } catch (AdministrativeStateException e) {
- logger.error("testLocking2: Unexpectedly caught AdministrativeStateException, ", e);
- assertTrue(false);
- } catch (StandbyStatusException e) {
- logger.error("testLocking2: Unexpectedly caught StandbyStatusException, ", e);
- assertTrue(false);
- } catch (Exception e) {
- logger.error("testLocking2: Unexpectedly caught Exception, ", e);
- assertTrue(false);
- }
-
- logger.debug("testLocking2: Verifying designated status for PDP= {}", standbyPdpId);
- assertFalse(conn.getPdp(standbyPdpId).isDesignated());
-
- logger.debug("\n\ntestLocking2: Exiting\n\n");
- }
-
- private static Properties loadStateManagementProperties() throws IOException {
- try (FileInputStream input = new FileInputStream(CONFIG_DIR + "/feature-state-management.properties")) {
- Properties props = new Properties();
- props.load(input);
- return props;
- }
- }
-
- private static Properties loadActiveStandbyProperties() throws IOException {
- try (FileInputStream input =
- new FileInputStream(CONFIG_DIR + "/feature-active-standby-management.properties")) {
- Properties props = new Properties();
- props.load(input);
- return props;
- }
- }
-
- private void sleep(long sleepms) throws InterruptedException {
- testTime.waitFor(sleepms);
- }
-}
diff --git a/feature-active-standby-management/src/test/resources/META-INF/persistence.xml b/feature-active-standby-management/src/test/resources/META-INF/persistence.xml
deleted file mode 100644
index ecbf22b7..00000000
--- a/feature-active-standby-management/src/test/resources/META-INF/persistence.xml
+++ /dev/null
@@ -1,48 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ============LICENSE_START=======================================================
- feature-active-standby-management
- ================================================================================
- Copyright (C) 2017-2018 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.
- See the License for the specific language governing permissions and
- limitations under the License.
- ============LICENSE_END=========================================================
- -->
-
-<persistence version="2.1"
- xmlns="http://xmlns.jcp.org/xml/ns/persistence"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
- <persistence-unit name="junitDroolsPU"
- transaction-type="RESOURCE_LOCAL">
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
- <class>org.onap.policy.drools.activestandby.DroolsPdpEntity</class>
- <properties>
- <property
- name="javax.persistence.schema-generation.database.action"
- value="drop-and-create" />
- </properties>
- </persistence-unit>
- <persistence-unit name="junitXacmlPU"
- transaction-type="RESOURCE_LOCAL">
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
- <class>org.onap.policy.common.im.jpa.StateManagementEntity</class>
- <class>org.onap.policy.common.im.jpa.ForwardProgressEntity</class>
- <class>org.onap.policy.common.im.jpa.ResourceRegistrationEntity</class>
- <properties>
- <property
- name="javax.persistence.schema-generation.database.action"
- value="drop-and-create" />
- </properties>
- </persistence-unit>
-</persistence>
diff --git a/feature-active-standby-management/src/test/resources/asw/feature-active-standby-management.properties b/feature-active-standby-management/src/test/resources/asw/feature-active-standby-management.properties
deleted file mode 100644
index 23a1f6db..00000000
--- a/feature-active-standby-management/src/test/resources/asw/feature-active-standby-management.properties
+++ /dev/null
@@ -1,40 +0,0 @@
-###
-# ============LICENSE_START=======================================================
-# feature-active-standby-management
-# ================================================================================
-# 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.
-# 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.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-# ============LICENSE_END=========================================================
-###
-
-# DB properties
-eclipselink.target-database=Auto
-javax.persistence.jdbc.driver = org.h2.Driver
-javax.persistence.jdbc.url = jdbc:h2:mem:asw_activestandbymanagement
-javax.persistence.jdbc.user = sa
-javax.persistence.jdbc.password =
-
-# Must be unique across the system
-resource.name=pdp1
-# Name of the site in which this node is hosted
-site_name=pdp_1
-
-# Needed by DroolsPdpsElectionHandler
-pdp.checkInterval=1500
-pdp.updateInterval=1000
-
-# Need long timeout, because testTransaction is only run every 1 seconds.
-pdp.timeout=3000
-#how long do we wait for the pdp table to populate on initial startup
-pdp.initialWait=1000
diff --git a/feature-active-standby-management/src/test/resources/asw/feature-state-management.properties b/feature-active-standby-management/src/test/resources/asw/feature-state-management.properties
deleted file mode 100644
index e03ebd2b..00000000
--- a/feature-active-standby-management/src/test/resources/asw/feature-state-management.properties
+++ /dev/null
@@ -1,82 +0,0 @@
-###
-# ============LICENSE_START=======================================================
-# feature-active-standby-management
-# ================================================================================
-# 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.
-# 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.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-# ============LICENSE_END=========================================================
-###
-
-# DB properties
-eclipselink.target-database=Auto
-javax.persistence.jdbc.driver = org.h2.Driver
-javax.persistence.jdbc.url = jdbc:h2:mem:asw_statemanagement
-javax.persistence.jdbc.user = sa
-javax.persistence.jdbc.password =
-
-# DroolsPDPIntegrityMonitor Properties
-
-http.server.services=TEST
-http.server.services.TEST.host=0.0.0.0
-http.server.services.TEST.port=9982
-#These properties will default to the following if no other values are provided:
-# http.server.services.TEST.restClasses=org.onap.policy.drools.statemanagement.IntegrityMonitorRestManager
-# http.server.services.TEST.managed=false
-# http.server.services.TEST.swagger=true
-
-#IntegrityMonitor Properties
-
-# Must be unique across the system
-resource.name=pdp1
-# Name of the site in which this node is hosted
-site_name = pdp_1
-# How often in sec the forward progress monitor checks for forward progress
-fp_monitor_interval = 2
-# Failed counter threshold before failover
-failed_counter_threshold = 1
-# Interval between test transactions when no traffic seconds
-test_trans_interval = 1
-# Interval between writes of the FPC to the DB seconds
-write_fpc_interval = 1
-# Node type Note: Make sure you don't leave any trailing spaces, or you'll get an 'invalid node type' error!
-node_type = pdp_drools
-# Dependency groups are groups of resources upon which a node operational state is dependent upon.
-# Each group is a comma-separated list of resource names and groups are separated by a semicolon. For example:
-# dependency_groups=site_1.astra_1,site_1.astra_2;site_1.brms_1,site_1.brms_2;site_1.logparser_1;site_1.pypdp_1
-dependency_groups=
-# When set to true, dependent health checks are performed by using JMX to invoke test() on the dependent.
-# The default false is to use state checks for health.
-test_via_jmx=true
-# This is the max number of seconds beyond which a non incrementing FPC is considered a failure
-max_fpc_update_interval=5
-# Run the state audit every 60 seconds (60000 ms). The state audit finds stale DB entries in the
-# forwardprogressentity table and marks the node as disabled/failed in the statemanagemententity
-# table. NOTE! It will only run on nodes that have a standbystatus = providingservice.
-# A value of <= 0 will turn off the state audit.
-state_audit_interval_ms= -1
-# The refresh state audit is run every (default) 10 minutes (600000 ms) to clean up any state corruption in the
-# DB statemanagemententity table. It only refreshes the DB state entry for the local node. That is, it does not
-# refresh the state of any other nodes. A value <= 0 will turn the audit off. Any other value will override
-# the default of 600000 ms.
-refresh_state_audit_interval_ms=-1
-
-
-# Repository audit properties
-# Flag to control the execution of the subsystemTest for the Nexus Maven repository
-repository.audit.is.active=false
-repository.audit.ignore.errors=true
-
-# DB Audit Properties
-# Flag to control the execution of the subsystemTest for the Database
-db.audit.is.active=false
diff --git a/feature-active-standby-management/src/test/resources/feature-active-standby-management.properties b/feature-active-standby-management/src/test/resources/feature-active-standby-management.properties
deleted file mode 100644
index 5a1f9607..00000000
--- a/feature-active-standby-management/src/test/resources/feature-active-standby-management.properties
+++ /dev/null
@@ -1,39 +0,0 @@
-###
-# ============LICENSE_START=======================================================
-# feature-active-standby-management
-# ================================================================================
-# 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.
-# 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.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-# ============LICENSE_END=========================================================
-###
-
-# DB properties
-eclipselink.target-database=Auto
-javax.persistence.jdbc.driver = org.h2.Driver
-javax.persistence.jdbc.url = jdbc:h2:mem:activestandbymanagement
-javax.persistence.jdbc.user = sa
-javax.persistence.jdbc.password =
-
-# Must be unique across the system
-resource.name=pdp1
-# Name of the site in which this node is hosted
-site_name=pdp_1
-
-# Needed by DroolsPdpsElectionHandler
-pdp.checkInterval=1500
-pdp.updateInterval=1000
-# Need long timeout, because testTransaction is only run every 10 seconds.
-pdp.timeout=3000
-#how long do we wait for the pdp table to populate on initial startup
-pdp.initialWait=1000
diff --git a/feature-active-standby-management/src/test/resources/feature-state-management.properties b/feature-active-standby-management/src/test/resources/feature-state-management.properties
deleted file mode 100644
index 6e4f61f3..00000000
--- a/feature-active-standby-management/src/test/resources/feature-state-management.properties
+++ /dev/null
@@ -1,83 +0,0 @@
-###
-# ============LICENSE_START=======================================================
-# feature-active-standby-management
-# ================================================================================
-# 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.
-# 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.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-# ============LICENSE_END=========================================================
-###
-
-# DB properties
-eclipselink.target-database=Auto
-javax.persistence.jdbc.driver = org.h2.Driver
-javax.persistence.jdbc.url = jdbc:h2:mem:statemanagement
-javax.persistence.jdbc.user = sa
-javax.persistence.jdbc.password =
-
-# DroolsPDPIntegrityMonitor Properties
-#Test interface host and port defaults may be overwritten here
-http.server.services.TEST.host=0.0.0.0
-http.server.services.TEST.port=9981
-#These properties will default to the following if no other values are provided:
-# http.server.services.TEST.restClasses=org.onap.policy.drools.statemanagement.IntegrityMonitorRestManager
-# http.server.services.TEST.managed=false
-# http.server.services.TEST.swagger=true
-
-#IntegrityMonitor Properties
-
-# Must be unique across the system
-resource.name=pdp1
-# Name of the site in which this node is hosted
-site_name = pdp_1
-# Forward Progress Monitor update interval seconds
-fp_monitor_interval = 2
-# Failed counter threshold before failover
-failed_counter_threshold = 1
-# Interval between test transactions when no traffic seconds
-test_trans_interval = 1
-# Interval between writes of the FPC to the DB seconds
-write_fpc_interval = 1
-# Node type Note: Make sure you don't leave any trailing spaces, or you'll get an 'invalid node type' error!
-node_type = pdp_drools
-# Dependency groups are groups of resources upon which a node operational state is dependent upon.
-# Each group is a comma-separated list of resource names and groups are separated by a semicolon. For example:
-# dependency_groups=site_1.astra_1,site_1.astra_2;site_1.brms_1,site_1.brms_2;site_1.logparser_1;site_1.pypdp_1
-dependency_groups=
-# When set to true, dependent health checks are performed by using JMX to invoke test() on the dependent.
-# The default false is to use state checks for health.
-test_via_jmx=true
-# This is the max number of seconds beyond which a non incrementing FPC is considered a failure
-max_fpc_update_interval=5
-# Run the state audit every 60 seconds (60000 ms). The state audit finds stale DB entries in the
-# forwardprogressentity table and marks the node as disabled/failed in the statemanagemententity
-# table. NOTE! It will only run on nodes that have a standbystatus = providingservice.
-# A value of <= 0 will turn off the state audit.
-state_audit_interval_ms=-1
-# The refresh state audit is run every (default) 10 minutes (600000 ms) to clean up any state corruption in the
-# DB statemanagemententity table. It only refreshes the DB state entry for the local node. That is, it does not
-# refresh the state of any other nodes. A value <= 0 will turn the audit off. Any other value will override
-# the default of 600000 ms.
-refresh_state_audit_interval_ms=-1
-
-
-# Repository audit properties
-# Flag to control the execution of the subsystemTest for the Nexus Maven repository
-repository.audit.is.active=false
-repository.audit.ignore.errors=true
-repository.audit.interval_sec=86400
-repository.audit.failure.threshold=3
-
-# DB Audit Properties
-# Flag to control the execution of the subsystemTest for the Database
-db.audit.is.active=false
diff --git a/feature-active-standby-management/src/test/resources/logback-test.xml b/feature-active-standby-management/src/test/resources/logback-test.xml
deleted file mode 100644
index 583b9667..00000000
--- a/feature-active-standby-management/src/test/resources/logback-test.xml
+++ /dev/null
@@ -1,49 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- feature-state-management
- ================================================================================
- Copyright (C) 2017-2018 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.
- See the License for the specific language governing permissions and
- limitations under the License.
- ============LICENSE_END=========================================================
- -->
-
-<!-- Controls the output of logs for JUnit tests -->
-
-<configuration>
-
- <appender name="STDOUT"
- class="ch.qos.logback.core.ConsoleAppender">
- <encoder
- class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
- <Pattern>
- %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M\(%line\) - %msg%n
- </Pattern>
- </encoder>
- </appender>
- <appender name="FILE"
- class="ch.qos.logback.core.FileAppender">
- <file>logs/debug.log</file>
- <encoder>
- <Pattern>
- %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M\(%line\) - %msg%n
- </Pattern>
- </encoder>
- </appender>
-
- <root level="debug">
- <appender-ref ref="STDOUT" />
- <appender-ref ref="FILE" />
- </root>
-
-</configuration>
diff --git a/feature-state-management/.gitignore b/feature-state-management/.gitignore
deleted file mode 100644
index b83d2226..00000000
--- a/feature-state-management/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/target/
diff --git a/feature-state-management/pom.xml b/feature-state-management/pom.xml
deleted file mode 100644
index a3cf9188..00000000
--- a/feature-state-management/pom.xml
+++ /dev/null
@@ -1,127 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- feature-state-management
- ================================================================================
- 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.
- 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.
- See the License for the specific language governing permissions and
- limitations under the License.
- ============LICENSE_END=========================================================
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>drools-pdp</artifactId>
- <version>1.10.1-SNAPSHOT</version>
- </parent>
-
- <artifactId>feature-state-management</artifactId>
-
- <name>feature-state-management</name>
- <description>Separately loadable module for State Management</description>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <executions>
- <execution>
- <id>zipfile</id>
- <goals>
- <goal>single</goal>
- </goals>
- <phase>package</phase>
- <configuration>
- <attach>true</attach>
- <finalName>${project.artifactId}-${project.version}</finalName>
- <descriptors>
- <descriptor>src/assembly/assemble_zip.xml</descriptor>
- </descriptors>
- <appendAssemblyId>false</appendAssemblyId>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <execution>
- <id>copy-dependencies</id>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- <phase>prepare-package</phase>
- <configuration>
- <transitive>false</transitive>
- <outputDirectory>${project.build.directory}/assembly/lib</outputDirectory>
- <overWriteReleases>false</overWriteReleases>
- <overWriteSnapshots>true</overWriteSnapshots>
- <overWriteIfNewer>true</overWriteIfNewer>
- <useRepositoryLayout>false</useRepositoryLayout>
- <addParentPoms>false</addParentPoms>
- <copyPom>false</copyPom>
- <includeScope>runtime</includeScope>
- <excludeTransitive>true</excludeTransitive>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>policy-core</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>policy-management</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>api-state-management</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.eclipse.persistence</groupId>
- <artifactId>eclipselink</artifactId>
- <scope>provided</scope>
- </dependency>
- <!-- Need to pull in to assembly -->
- <dependency>
- <groupId>org.onap.policy.common</groupId>
- <artifactId>integrity-monitor</artifactId>
- <version>${policy.common.version}</version>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
diff --git a/feature-state-management/src/assembly/assemble_zip.xml b/feature-state-management/src/assembly/assemble_zip.xml
deleted file mode 100644
index f398829d..00000000
--- a/feature-state-management/src/assembly/assemble_zip.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- feature-state-management
- ================================================================================
- Copyright (C) 2017 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.
- See the License for the specific language governing permissions and
- limitations under the License.
- ============LICENSE_END=========================================================
- -->
-
-<!-- Defines how we build the .zip file which is our distribution. -->
-
-<assembly
- xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
- <id>feature-state-management</id>
- <formats>
- <format>zip</format>
- </formats>
-
- <!-- we want "system" and related files right at the root level as this
- file is suppose to be unzip on top of a karaf distro. -->
- <includeBaseDirectory>false</includeBaseDirectory>
-
- <fileSets>
- <fileSet>
- <directory>target</directory>
- <outputDirectory>lib/feature</outputDirectory>
- <includes>
- <include>feature-state-management-${project.version}.jar</include>
- </includes>
- </fileSet>
- <fileSet>
- <directory>target/assembly/lib</directory>
- <outputDirectory>lib/dependencies</outputDirectory>
- <includes>
- <include>*.jar</include>
- </includes>
- </fileSet>
- <fileSet>
- <directory>src/main/feature/config</directory>
- <outputDirectory>config</outputDirectory>
- <fileMode>0644</fileMode>
- <excludes/>
- </fileSet>
- <fileSet>
- <directory>src/main/feature/bin</directory>
- <outputDirectory>bin</outputDirectory>
- <fileMode>0744</fileMode>
- <excludes/>
- </fileSet>
- <fileSet>
- <directory>src/main/feature/db</directory>
- <outputDirectory>db</outputDirectory>
- <fileMode>0744</fileMode>
- <excludes/>
- </fileSet>
- <fileSet>
- <directory>src/main/feature/install</directory>
- <outputDirectory>install</outputDirectory>
- <fileMode>0744</fileMode>
- <excludes/>
- </fileSet>
- </fileSets>
-</assembly>
diff --git a/feature-state-management/src/main/feature/config/feature-state-management.properties b/feature-state-management/src/main/feature/config/feature-state-management.properties
deleted file mode 100644
index da1b5486..00000000
--- a/feature-state-management/src/main/feature/config/feature-state-management.properties
+++ /dev/null
@@ -1,90 +0,0 @@
-###
-# ============LICENSE_START=======================================================
-# feature-state-management
-# ================================================================================
-# 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.
-# 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.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-# ============LICENSE_END=========================================================
-###
-
-# DB properties
-eclipselink.target-database=MySQL
-javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver
-javax.persistence.jdbc.url=jdbc:mariadb://${envd:SQL_HOST}:${envd:SQL_PORT:3306}/statemanagement
-javax.persistence.jdbc.user=${envd:SQL_USER}
-javax.persistence.jdbc.password=${envd:SQL_PASSWORD}
-
-# DroolsPDPIntegrityMonitor Properties
-# Test interface host and port defaults may be overwritten here
-http.server.services.TEST.host=0.0.0.0
-http.server.services.TEST.port=9981
-http.server.services.TEST.serialization.provider=org.onap.policy.common.gson.JacksonHandler,org.onap.policy.common.endpoints.http.server.YamlJacksonHandler
-#These properties will default to the following if no other values are provided:
-# http.server.services.TEST.restClasses=org.onap.policy.drools.statemanagement.IntegrityMonitorRestManager
-# http.server.services.TEST.managed=false
-# http.server.services.TEST.swagger=true
-
-#IntegrityMonitor Properties
-
-# Must be unique across the system
-resource.name=pdp1
-# Name of the site in which this node is hosted
-site_name=site1
-# Forward Progress Monitor update interval seconds
-fp_monitor_interval=30
-# Failed counter threshold before failover
-failed_counter_threshold=3
-# Interval between test transactions when no traffic seconds
-test_trans_interval=10
-# Interval between writes of the FPC to the DB seconds
-write_fpc_interval=5
-# Node type Note: Make sure you don't leave any trailing spaces, or you'll get an 'invalid node type' error!
-node_type=pdp_drools
-# Dependency groups are groups of resources upon which a node operational state is dependent upon.
-# Each group is a comma-separated list of resource names and groups are separated by a semicolon. For example:
-# dependency_groups=site_1.astra_1,site_1.astra_2;site_1.brms_1,site_1.brms_2;site_1.logparser_1;site_1.pypdp_1
-dependency_groups=
-# When set to true, dependent health checks are performed by using JMX to invoke test() on the dependent.
-# The default false is to use state checks for health.
-test_via_jmx=true
-# This is the max number of seconds beyond which a non incrementing FPC is considered a failure
-max_fpc_update_interval=120
-# Run the state audit every 60 seconds (60000 ms). The state audit finds stale DB entries in the
-# forwardprogressentity table and marks the node as disabled/failed in the statemanagemententity
-# table. NOTE! It will only run on nodes that have a standbystatus = providingservice.
-# A value of <= 0 will turn off the state audit.
-state_audit_interval_ms=60000
-# The refresh state audit is run every (default) 10 minutes (600000 ms) to clean up any state corruption in the
-# DB statemanagemententity table. It only refreshes the DB state entry for the local node. That is, it does not
-# refresh the state of any other nodes. A value <= 0 will turn the audit off. Any other value will override
-# the default of 600000 ms.
-refresh_state_audit_interval_ms=600000
-
-
-# Repository audit properties
-
-# Assume it's the releaseRepository that needs to be audited,
-# because that's the one BRMGW will publish to.
-repository.audit.id=${env:RELEASE_REPOSITORY_ID}
-repository.audit.url=${env:RELEASE_REPOSITORY_URL}
-repository.audit.username=${env:REPOSITORY_USERNAME}
-repository.audit.password=${env:REPOSITORY_PASSWORD}
-# Flag to control the execution of the subsystemTest for the Nexus Maven repository
-repository.audit.is.active=false
-repository.audit.ignore.errors=true
-
-# DB Audit Properties
-
-# Flag to control the execution of the subsystemTest for the Database
-db.audit.is.active=false
diff --git a/feature-state-management/src/main/feature/db/statemanagement/sql/18020-statemanagement.upgrade.sql b/feature-state-management/src/main/feature/db/statemanagement/sql/18020-statemanagement.upgrade.sql
deleted file mode 100644
index f73f992b..00000000
--- a/feature-state-management/src/main/feature/db/statemanagement/sql/18020-statemanagement.upgrade.sql
+++ /dev/null
@@ -1,74 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * feature-state-management
- * ================================================================================
- * Copyright (C) 2017 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-set foreign_key_checks=0;
-
-CREATE TABLE if not exists statemanagement.StateManagementEntity
-(
- id int not null auto_increment,
- resourceName varchar(100) not null,
- adminState varchar(20) not null,
- opstate varchar(20) not null,
- availStatus varchar(20),
- standbyStatus varchar(20),
- created_date timestamp not null default current_timestamp,
- modifiedDate timestamp not null,
- primary key(id),
- unique key resource(resourceName)
-);
-
-CREATE TABLE if not exists statemanagement.ResourceRegistrationEntity
-(
- resourceRegistrationId bigint not null auto_increment,
- resourceName varchar(100) not null,
- resourceURL varchar(255) not null,
- site varchar(50),
- nodetype varchar(50),
- created_date timestamp not null default current_timestamp,
- last_updated timestamp not null,
- primary key (resourceRegistrationId),
- unique key resource (resourceName),
- unique key id_resource_url (resourceURL)
-);
-
-CREATE TABLE if not exists statemanagement.ForwardProgressEntity
-(
- forwardProgressId bigint not null auto_increment,
- resourceName varchar(100) not null,
- fpc_count bigint not null,
- created_date timestamp not null default current_timestamp,
- last_updated timestamp not null,
- primary key (forwardProgressId),
- unique key resource_key (resourceName)
-);
-
-CREATE TABLE if not exists statemanagement.sequence
-(
-SEQ_NAME VARCHAR(50) NOT NULL,
-SEQ_COUNT DECIMAL(38,0),
-PRIMARY KEY (SEQ_NAME)
-);
-
--- Will only insert a record if none exists:
-INSERT INTO statemanagement.SEQUENCE (SEQ_NAME,SEQ_COUNT)
-SELECT * FROM (SELECT 'SEQ_GEN',1) AS tmp
-WHERE NOT EXISTS(select SEQ_NAME from statemanagement.SEQUENCE where SEQ_NAME = 'SEQ_GEN') LIMIT 1;
-
-set foreign_key_checks=1; \ No newline at end of file
diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java
deleted file mode 100644
index de378933..00000000
--- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * feature-state-management
- * ================================================================================
- * 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.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.statemanagement;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Properties;
-import java.util.UUID;
-import lombok.Getter;
-import lombok.Setter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/** This class audits the database.
- */
-public class DbAudit extends DroolsPdpIntegrityMonitor.AuditBase {
- // get an instance of logger
- private static Logger logger = LoggerFactory.getLogger(DbAudit.class);
- // single global instance of this audit object
- private static final DbAudit instance = new DbAudit();
-
- // This indicates if 'CREATE TABLE IF NOT EXISTS Audit ...' should be
- // invoked -- doing this avoids the need to create the table in advance.
- private static boolean createTableNeeded = true;
-
- @Getter
- @Setter
- private static boolean junit = false;
-
- /** Constructor - set the name to 'Database'. */
- private DbAudit() {
- super("Database");
- }
-
- private static synchronized void setCreateTableNeeded(boolean isNeeded) {
- DbAudit.createTableNeeded = isNeeded;
- }
-
- /**
- * Get the instance.
- *
- * @return the single 'DbAudit' instance. */
- public static DroolsPdpIntegrityMonitor.AuditBase getInstance() {
- return instance;
- }
-
- /**
- * Invoke the audit.
- *
- * @param properties properties to be passed to the audit
- */
- @Override
- public void invoke(Properties properties) {
- logger.debug("Running 'DbAudit.invoke'");
- boolean doCreate = createTableNeeded && !isJunit();
-
- if (!isActive()) {
- logger.info("DbAudit.invoke: exiting because isActive = false");
- return;
- }
-
- // fetch DB properties from properties file -- they are already known
- // to exist, because they were verified by the 'IntegrityMonitor'
- // constructor
- String url = properties.getProperty(StateManagementProperties.DB_URL);
- String user = properties.getProperty(StateManagementProperties.DB_USER);
- String password = properties.getProperty(StateManagementProperties.DB_PWD);
-
- // operation phase currently running -- used to construct an error
- // message, if needed
- String phase = null;
-
- // create connection to DB
- phase = "creating connection";
- logger.debug("DbAudit: Creating connection to {}", url);
- try (var connection = DriverManager.getConnection(url, user, password)) {
-
- // create audit table, if needed
- if (doCreate) {
- phase = "create table";
- createTable(connection);
- }
-
- // insert an entry into the table
- phase = "insert entry";
- var key = UUID.randomUUID().toString();
- insertEntry(connection, key);
-
- phase = "fetch entry";
- findEntry(connection, key);
-
- phase = "delete entry";
- deleteEntry(connection, key);
- } catch (Exception e) {
- String message = "DbAudit: Exception during audit, phase = " + phase;
- logger.error(message, e);
- setResponse(message);
- }
- }
-
- /**
- * Determines if the DbAudit is active, based on properties. Defaults to {@code true}, if not
- * found in the properties.
- *
- * @return {@code true} if DbAudit is active, {@code false} otherwise
- */
- private boolean isActive() {
- String dbAuditIsActive = StateManagementProperties.getProperty("db.audit.is.active");
- logger.debug("DbAudit.invoke: dbAuditIsActive = {}", dbAuditIsActive);
-
- if (dbAuditIsActive != null) {
- try {
- return Boolean.parseBoolean(dbAuditIsActive.trim());
- } catch (NumberFormatException e) {
- logger.warn(
- "DbAudit.invoke: Ignoring invalid property: db.audit.is.active = {}", dbAuditIsActive);
- }
- }
-
- return true;
- }
-
- /**
- * Creates the table.
- *
- * @param connection connection
- * @throws SQLException exception
- */
- private void createTable(Connection connection) throws SQLException {
- logger.info("DbAudit: Creating 'Audit' table, if needed");
- try (PreparedStatement statement =
- connection.prepareStatement(
- "CREATE TABLE IF NOT EXISTS Audit (\n"
- + " name varchar(64) DEFAULT NULL,\n"
- + " UNIQUE KEY name (name)\n"
- + ") DEFAULT CHARSET=latin1;")) {
- statement.execute();
- DbAudit.setCreateTableNeeded(false);
- }
- }
-
- /**
- * Inserts an entry.
- *
- * @param connection connection
- * @param key key
- * @throws SQLException exception
- */
- private void insertEntry(Connection connection, String key) throws SQLException {
- try (PreparedStatement statement =
- connection.prepareStatement("INSERT INTO Audit (name) VALUES (?)")) {
- statement.setString(1, key);
- statement.executeUpdate();
- }
- }
-
- /**
- * Finds an entry.
- *
- * @param connection connection
- * @param key key
- * @throws SQLException exception
- */
- private void findEntry(Connection connection, String key) throws SQLException {
- try (PreparedStatement statement =
- connection.prepareStatement("SELECT name FROM Audit WHERE name = ?")) {
- statement.setString(1, key);
- getEntry(statement, key);
- }
- }
-
- /**
- * Executes the query to determine if the entry exists. Sets the response if it fails.
- *
- * @param statement statement
- * @param key key
- * @throws SQLException exception
- */
- private void getEntry(PreparedStatement statement, String key) throws SQLException {
- try (ResultSet rs = statement.executeQuery()) {
- if (rs.first()) {
- // found entry
- if (logger.isDebugEnabled()) {
- logger.debug("DbAudit: Found key {}", rs.getString(1));
- }
- } else {
- logger.error("DbAudit: can't find newly-created entry with key {}", key);
- setResponse("Can't find newly-created entry");
- }
- }
- }
-
- /**
- * Deletes an entry.
- *
- * @param connection connection
- * @param key key
- * @throws SQLException exception
- */
- private void deleteEntry(Connection connection, String key) throws SQLException {
- try (PreparedStatement statement =
- connection.prepareStatement("DELETE FROM Audit WHERE name = ?")) {
- statement.setString(1, key);
- statement.executeUpdate();
- }
- }
-}
diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPdpIntegrityMonitor.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPdpIntegrityMonitor.java
deleted file mode 100644
index da94302f..00000000
--- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPdpIntegrityMonitor.java
+++ /dev/null
@@ -1,413 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * 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.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.statemanagement;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Properties;
-import lombok.Getter;
-import lombok.Setter;
-import org.onap.policy.common.capabilities.Startable;
-import org.onap.policy.common.endpoints.http.server.HttpServletServer;
-import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
-import org.onap.policy.common.im.IntegrityMonitor;
-import org.onap.policy.common.im.IntegrityMonitorException;
-import org.onap.policy.drools.utils.PropertyUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class extends 'IntegrityMonitor' for use in the 'Drools PDP' virtual machine. The included
- * audits are 'Database' and 'Repository'.
- */
-public class DroolsPdpIntegrityMonitor extends IntegrityMonitor {
-
- private static final String INVALID_PROPERTY_VALUE = "init: property {} does not have the expected value of {}";
-
- // get an instance of logger
- private static final Logger logger = LoggerFactory.getLogger(DroolsPdpIntegrityMonitor.class);
-
- // static global instance
- private static DroolsPdpIntegrityMonitor im = null;
-
- // list of audits to run
- private static final AuditBase[] audits = new AuditBase[] {DbAudit.getInstance(), RepositoryAudit.getInstance()};
-
- private static Properties subsystemTestProperties = null;
-
- private static final String PROPERTIES_NAME = "feature-state-management.properties";
-
- /**
- * Constructor - pass arguments to superclass, but remember properties.
- *
- * @param resourceName unique name of this Integrity Monitor
- * @param consolidatedProperties properties used locally, as well as by 'IntegrityMonitor'
- * @throws IntegrityMonitorException (passed from superclass)
- */
- private DroolsPdpIntegrityMonitor(String resourceName, Properties consolidatedProperties)
- throws IntegrityMonitorException {
- super(resourceName, consolidatedProperties);
- }
-
- private static void missingProperty(String prop) throws IntegrityMonitorException {
- String msg = "init: missing IntegrityMonitor property: ".concat(prop);
- logger.error(msg);
- throw new IntegrityMonitorException(msg);
- }
-
- private static void logPropertyValue(String prop, String val) {
- logger.info("\n\n init: property: {} = {}\n", prop, val);
- }
-
- /**
- * Static initialization -- create Drools Integrity Monitor, and an HTTP server to handle REST
- * 'test' requests.
- *
- * @throws IntegrityMonitorException exception
- */
- public static DroolsPdpIntegrityMonitor init(String configDir) throws IntegrityMonitorException {
-
- logger.info("init: Entering and invoking PropertyUtil.getProperties() on '{}'", configDir);
-
- // read in properties
- var stateManagementProperties = getProperties(configDir);
-
- // fetch and verify definitions of some properties, adding defaults where
- // appropriate
- // (the 'IntegrityMonitor' constructor does some additional verification)
-
- checkPropError(stateManagementProperties, StateManagementProperties.TEST_HOST);
- checkPropError(stateManagementProperties, StateManagementProperties.TEST_PORT);
-
- addDefaultPropError(stateManagementProperties, StateManagementProperties.TEST_SERVICES,
- StateManagementProperties.TEST_SERVICES_DEFAULT);
-
- addDefaultPropError(stateManagementProperties, StateManagementProperties.TEST_REST_CLASSES,
- StateManagementProperties.TEST_REST_CLASSES_DEFAULT);
-
- addDefaultPropWarn(stateManagementProperties, StateManagementProperties.TEST_MANAGED,
- StateManagementProperties.TEST_MANAGED_DEFAULT);
-
- addDefaultPropWarn(stateManagementProperties, StateManagementProperties.TEST_SWAGGER,
- StateManagementProperties.TEST_SWAGGER_DEFAULT);
-
- checkPropError(stateManagementProperties, StateManagementProperties.RESOURCE_NAME);
- checkPropError(stateManagementProperties, StateManagementProperties.FP_MONITOR_INTERVAL);
- checkPropError(stateManagementProperties, StateManagementProperties.FAILED_COUNTER_THRESHOLD);
- checkPropError(stateManagementProperties, StateManagementProperties.TEST_TRANS_INTERVAL);
- checkPropError(stateManagementProperties, StateManagementProperties.WRITE_FPC_INTERVAL);
- checkPropError(stateManagementProperties, StateManagementProperties.SITE_NAME);
- checkPropError(stateManagementProperties, StateManagementProperties.NODE_TYPE);
- checkPropError(stateManagementProperties, StateManagementProperties.DEPENDENCY_GROUPS);
- checkPropError(stateManagementProperties, StateManagementProperties.DB_TYPE);
- checkPropError(stateManagementProperties, StateManagementProperties.DB_DRIVER);
- checkPropError(stateManagementProperties, StateManagementProperties.DB_URL);
- checkPropError(stateManagementProperties, StateManagementProperties.DB_USER);
- checkPropError(stateManagementProperties, StateManagementProperties.DB_PWD);
-
- final String testHost = stateManagementProperties.getProperty(StateManagementProperties.TEST_HOST);
- final String testPort = stateManagementProperties.getProperty(StateManagementProperties.TEST_PORT);
- final String resourceName = stateManagementProperties.getProperty(StateManagementProperties.RESOURCE_NAME);
-
- subsystemTestProperties = stateManagementProperties;
-
- // Now that we've validated the properties, create Drools Integrity Monitor
- // with these properties.
- im = makeMonitor(resourceName, stateManagementProperties);
- logger.info("init: New DroolsPDPIntegrityMonitor instantiated, resourceName = {}", resourceName);
-
- // create http server
- makeRestServer(testHost, testPort, stateManagementProperties);
- logger.info("init: Exiting and returning DroolsPDPIntegrityMonitor");
-
- return im;
- }
-
- /**
- * Makes an Integrity Monitor.
- *
- * @param resourceName unique name of this Integrity Monitor
- * @param properties properties used to configure the Integrity Monitor
- * @return monitor object
- * @throws IntegrityMonitorException exception
- */
- private static DroolsPdpIntegrityMonitor makeMonitor(String resourceName, Properties properties)
- throws IntegrityMonitorException {
-
- try {
- return new DroolsPdpIntegrityMonitor(resourceName, properties);
-
- } catch (Exception e) {
- throw new IntegrityMonitorException(e);
- }
- }
-
- /**
- * Makes a rest server for the Integrity Monitor.
- *
- * @param testHost host name
- * @param testPort port
- * @param properties properties used to configure the rest server
- * @throws IntegrityMonitorException exception
- */
- private static void makeRestServer(String testHost, String testPort, Properties properties)
- throws IntegrityMonitorException {
-
- try {
- logger.info("init: Starting HTTP server, addr= {}:{}", testHost, testPort);
-
- new IntegrityMonitorRestServer(properties);
-
- } catch (Exception e) {
- logger.error("init: Caught Exception attempting to start server on testPort={}", testPort);
- throw new IntegrityMonitorException(e);
- }
- }
-
- /**
- * Gets the properties from the property file.
- *
- * @param configDir directory containing the property file
- * @return the properties
- * @throws IntegrityMonitorException exception
- */
- private static Properties getProperties(String configDir) throws IntegrityMonitorException {
- try {
- return PropertyUtil.getProperties(configDir + "/" + PROPERTIES_NAME);
-
- } catch (IOException e) {
- throw new IntegrityMonitorException(e);
- }
- }
-
- /**
- * Checks that a property is defined.
- *
- * @param props set of properties
- * @param name name of the property to check
- * @throws IntegrityMonitorException exception
- */
- private static void checkPropError(Properties props, String name) throws IntegrityMonitorException {
- String val = props.getProperty(name);
- if (val == null) {
- missingProperty(name);
- }
-
- logPropertyValue(name, val);
- }
-
- /**
- * Checks a property's value to verify that it matches the expected value. If the property is
- * not defined, then it is added to the property set, with the expected value. Logs an error if
- * the property is defined, but does not have the expected value.
- *
- * @param props set of properties
- * @param name name of the property to check
- * @param expected expected/default value
- */
- private static void addDefaultPropError(Properties props, String name, String expected) {
- String val = props.getProperty(name);
- if (val == null) {
- props.setProperty(name, expected);
-
- } else if (!val.equals(expected)) {
- logger.error(INVALID_PROPERTY_VALUE, name, expected);
- }
-
- logPropertyValue(name, val);
- }
-
- /**
- * Checks a property's value to verify that it matches the expected value. If the property is
- * not defined, then it is added to the property set, with the expected value. Logs a warning if
- * the property is defined, but does not have the expected value.
- *
- * @param props set of properties
- * @param name name of the property to check
- * @param dflt expected/default value
- */
- private static void addDefaultPropWarn(Properties props, String name, String dflt) {
- String val = props.getProperty(name);
- if (val == null) {
- props.setProperty(name, dflt);
-
- } else if (!val.equals(dflt)) {
- logger.warn(INVALID_PROPERTY_VALUE, name, dflt);
- }
-
- logPropertyValue(name, val);
- }
-
- /**
- * Run tests (audits) unique to Drools PDP VM (Database + Repository).
- */
- @Override
- public void subsystemTest() throws IntegrityMonitorException {
- logger.info("DroolsPDPIntegrityMonitor.subsystemTest called");
-
- // clear all responses (non-null values indicate an error)
- for (AuditBase audit : audits) {
- audit.setResponse(null);
- }
-
- // invoke all of the audits
- for (AuditBase audit : audits) {
- try {
- // invoke the audit (responses are stored within the audit object)
- audit.invoke(subsystemTestProperties);
- } catch (Exception e) {
- logger.error("{} audit error", audit.getName(), e);
- if (audit.getResponse() == null) {
- // if there is no current response, use the exception message
- audit.setResponse(e.getMessage());
- }
- }
- }
-
- // will contain list of subsystems where the audit failed
- var responseMsg = "";
-
- // Loop through all of the audits, and see which ones have failed.
- // NOTE: response information is stored within the audit objects
- // themselves -- only one can run at a time.
- for (AuditBase audit : audits) {
- String response = audit.getResponse();
- if (response != null) {
- // the audit has failed -- add subsystem and
- // and 'responseValue' with the new information
- responseMsg = responseMsg.concat("\n" + audit.getName() + ": " + response);
- }
- }
-
- if (!responseMsg.isEmpty()) {
- throw new IntegrityMonitorException(responseMsg);
- }
- }
-
- /* ============================================================ */
-
- /**
- * This is the base class for audits invoked in 'subsystemTest'.
- */
- @Getter
- public abstract static class AuditBase {
- // name of the audit
- protected String name;
-
- // non-null indicates the error response
- @Setter
- protected String response;
-
- /**
- * Constructor - initialize the name, and clear the initial response.
- *
- * @param name name of the audit
- */
- protected AuditBase(String name) {
- this.name = name;
- this.response = null;
- }
-
- /**
- * Abstract method to invoke the audit.
- *
- * @param persistenceProperties Used for DB access
- * @throws IntegrityMonitorException passed in by the audit
- */
- abstract void invoke(Properties persistenceProperties) throws IntegrityMonitorException;
- }
-
- public static class IntegrityMonitorRestServer implements Startable {
- protected HttpServletServer server = null;
- protected final Properties integrityMonitorRestServerProperties;
-
- public IntegrityMonitorRestServer(Properties props) {
- this.integrityMonitorRestServerProperties = props;
- this.start();
- }
-
- @Override
- public boolean start() {
- try {
- List<HttpServletServer> servers = HttpServletServerFactoryInstance.getServerFactory()
- .build(integrityMonitorRestServerProperties);
-
- if (!servers.isEmpty()) {
- server = servers.get(0);
-
- waitServerStart();
- }
- } catch (Exception e) {
- logger.error("Exception building servers", e);
- return false;
- }
-
- return true;
- }
-
- private void waitServerStart() {
- try {
- server.waitedStart(5);
- } catch (Exception e) {
- logger.error("Exception waiting for servers to start: ", e);
- Thread.currentThread().interrupt();
- }
- }
-
- @Override
- public boolean stop() {
- try {
- server.stop();
- } catch (Exception e) {
- logger.error("Exception during stop", e);
- }
-
- return true;
- }
-
- @Override
- public void shutdown() {
- this.stop();
- }
-
- @Override
- public synchronized boolean isAlive() {
- return this.integrityMonitorRestServerProperties != null;
- }
- }
-
- /**
- * Returns the instance.
- *
- * @return DroolsPDPIntegrityMonitor object
- * @throws IntegrityMonitorException exception
- */
- public static DroolsPdpIntegrityMonitor getInstance() throws IntegrityMonitorException {
- logger.debug("getInstance() called");
- if (im == null) {
- String msg = "No DroolsPDPIntegrityMonitor instance exists."
- + " Please use the method DroolsPDPIntegrityMonitor init(String configDir)";
- throw new IntegrityMonitorException(msg);
- } else {
- return im;
- }
- }
-}
diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/IntegrityMonitorRestManager.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/IntegrityMonitorRestManager.java
deleted file mode 100644
index 8dd735e6..00000000
--- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/IntegrityMonitorRestManager.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * feature-state-management
- * ================================================================================
- * Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021 Nordix Foundation.
- * ================================================================================
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.statemanagement;
-
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiResponse;
-import io.swagger.annotations.ApiResponses;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.core.Response;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-@Api(value = "test")
-@Path("/")
-public class IntegrityMonitorRestManager {
- private static Logger logger = LoggerFactory.getLogger(IntegrityMonitorRestManager.class);
- private DroolsPdpIntegrityMonitor im;
-
- /**
- * Test interface for Integrity Monitor.
- *
- * @return Exception message if exception, otherwise empty
- */
- @ApiOperation(
- value = "Test endpoint for integrity monitor",
- notes = "The TEST command is used to request data from a subcomponent "
- + "instance that can be used to determine its operational state. "
- + "A 200/success response status code should be returned if the "
- + "subcomponent instance is functioning properly and able to respond to requests.",
- response = String.class)
- @ApiResponses(value = {
- @ApiResponse(
- code = 200,
- message = "Integrity monitor sanity check passed"),
- @ApiResponse(
- code = 500,
- message = "Integrity monitor sanity check encountered an exception. "
- + "This can indicate operational state disabled or administrative state locked")
- })
- @GET
- @Path("test")
- public Response test() {
- logger.debug("integrity monitor /test accessed");
- // The responses are stored within the audit objects, so we need to
- // invoke the audits and get responses before we handle another
- // request.
- synchronized (IntegrityMonitorRestManager.class) {
- // will include messages associated with subsystem failures
- var body = new StringBuilder();
-
- // 200=SUCCESS, 500=failure
- var responseValue = 200;
-
- if (im == null) {
- try {
- im = DroolsPdpIntegrityMonitor.getInstance();
- } catch (Exception e) {
- logger.error("IntegrityMonitorRestManager: test() interface caught an exception", e);
- body.append("\nException: " + e + "\n");
- responseValue = 500;
- }
- }
-
- if (im != null) {
- try {
- // call 'IntegrityMonitor.evaluateSanity()'
- im.evaluateSanity();
- } catch (Exception e) {
- // this exception isn't coming from one of the audits,
- // because those are caught in 'subsystemTest()'
- logger.error("DroolsPDPIntegrityMonitor.evaluateSanity()", e);
-
- // include exception in HTTP response
- body.append("\nException: " + e + "\n");
- responseValue = 500;
- }
- }
-
- // send response, including the contents of 'body'
- // (which is empty if everything is successful)
- if (responseValue == 200) {
- return Response.status(Response.Status.OK).build();
- } else {
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(body.toString()).build();
- }
- }
- }
-}
diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java
deleted file mode 100644
index ecc4acc6..00000000
--- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java
+++ /dev/null
@@ -1,559 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * feature-state-management
- * ================================================================================
- * 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.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.statemanagement;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.nio.file.Path;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Properties;
-import java.util.Set;
-import java.util.TreeSet;
-import java.util.concurrent.TimeUnit;
-import java.util.regex.Pattern;
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-import org.apache.commons.io.FileUtils;
-import org.onap.policy.common.im.IntegrityMonitorException;
-import org.onap.policy.common.utils.resources.DirectoryUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class audits the Maven repository.
- */
-public class RepositoryAudit extends DroolsPdpIntegrityMonitor.AuditBase {
- // timeout in 60 seconds
- private static final long DEFAULT_TIMEOUT = 60;
-
- // get an instance of logger
- private static final Logger logger = LoggerFactory.getLogger(RepositoryAudit.class);
-
- // single global instance of this audit object
- @Getter
- private static RepositoryAudit instance = new RepositoryAudit();
-
- // Regex pattern used to find additional repos in the form "repository(number).id.url"
- private static final Pattern repoPattern = Pattern.compile("(repository([1-9][0-9]*))[.]audit[.]id");
-
- /**
- * Constructor - set the name to 'Repository'.
- */
- private RepositoryAudit() {
- super("Repository");
- }
-
- /**
- * First, get the names of each property from StateManagementProperties. For each property name, check if it is of
- * the form "repository(number).audit.id" If so, we extract the number and determine if there exists another
- * property in the form "repository(number).audit.url" with the same "number". Only the
- * 'repository(number).audit.id' and 'repository(number).audit.url" properties need to be specified. If both 'id'
- * and 'url' properties are found, we add it to our set. InvokeData.getProperty(String, boolean) will determine the
- * other 4 properties: '*.username', '*.password', '*.is.active', and '*.ignore.errors', or use default values.
- *
- * @return set of Integers representing a repository to support
- */
- private static TreeSet<Integer> countAdditionalNexusRepos() {
- TreeSet<Integer> returnIndices = new TreeSet<>();
- var properties = StateManagementProperties.getProperties();
- Set<String> propertyNames = properties.stringPropertyNames();
-
- for (String currName : propertyNames) {
- var matcher = repoPattern.matcher(currName);
-
- if (matcher.matches()) {
- var currRepoNum = Integer.parseInt(matcher.group(2));
- if (propertyNames.contains(matcher.group(1) + ".audit.url")) {
- returnIndices.add(currRepoNum);
- }
- }
- }
- return returnIndices;
- }
-
- /**
- * Invoke the audit.
- *
- * @param properties properties to be passed to the audit
- */
- @Override
- public void invoke(Properties properties) throws IntegrityMonitorException {
- logger.debug("Running 'RepositoryAudit.invoke'");
-
- var data = new InvokeData();
-
- logger.debug("RepositoryAudit.invoke: repoAuditIsActive = {}" + ", repoAuditIgnoreErrors = {}",
- data.repoAuditIsActive, data.repoAuditIgnoreErrors);
-
- data.initIsActive();
-
- if (!data.isActive) {
- logger.info("RepositoryAudit.invoke: exiting because isActive = {}", data.isActive);
- return;
- }
-
- try {
- // Run audit for first nexus repository
- logger.debug("Running read-only audit on first nexus repository: repository");
- runAudit(data);
-
- // set of indices for supported nexus repos (ex: repository2 -> 2)
- // TreeSet is used to maintain order so repos can be audited in numerical
- // order
- TreeSet<Integer> repoIndices = countAdditionalNexusRepos();
- logger.debug("Additional nexus repositories: {}", repoIndices);
-
- // Run audit for remaining 'numNexusRepos' repositories
- for (int index : repoIndices) {
- logger.debug("Running read-only audit on nexus repository = repository{}", index);
-
- data = new InvokeData(index);
- data.initIsActive();
-
- if (data.isActive) {
- runAudit(data);
- }
- }
-
- } catch (IOException e) {
- throw new IntegrityMonitorException(e);
-
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- throw new IntegrityMonitorException(e);
- }
- }
-
- private void runAudit(InvokeData data) throws IOException, InterruptedException {
- data.initIgnoreErrors();
- data.initTimeout();
-
- /*
- * 1) create temporary directory
- */
- data.dir = DirectoryUtils.createTempDirectory("auditRepo");
-
- // nested 'pom.xml' file and 'repo' directory
- final Path pom = data.dir.resolve("pom.xml");
- final Path repo = data.dir.resolve("repo");
-
- /*
- * 2) Create test file, and upload to repository (only if repository information is specified)
- */
- if (data.upload) {
- data.uploadTestFile();
- }
-
- /*
- * 3) create 'pom.xml' file in temporary directory
- */
- data.createPomFile(repo, pom);
-
- /*
- * 4) Invoke external 'mvn' process to do the downloads
- */
-
- // output file = ${dir}/out (this supports step '4a')
- var output = data.dir.resolve("out").toFile();
-
- // invoke process, and wait for response
- int rval = data.runMaven(output);
-
- /*
- * 4a) Check attempted and successful downloads from output file Note: at present, this step just generates log
- * messages, but doesn't do any verification.
- */
- if (rval == 0 && output != null) {
- generateDownloadLogs(output);
- }
-
- /*
- * 5) Check the contents of the directory to make sure the downloads were successful
- */
- data.verifyDownloads(repo);
-
- /*
- * 6) Use 'curl' to delete the uploaded test file (only if repository information is specified)
- */
- if (data.upload) {
- data.deleteUploadedTestFile();
- }
-
- /*
- * 7) Remove the temporary directory
- */
- FileUtils.forceDelete(data.dir.toFile());
- }
-
-
- /**
- * Set the response string to the specified value. Overrides 'setResponse(String value)' from
- * DroolsPdpIntegrityMonitor This method prevents setting a response string that indicates whether the caller should
- * receive an error list from the audit. By NOT setting the response string to a value, this indicates that there
- * are no errors.
- *
- * @param value the new value of the response string (null = no errors)
- */
- @Override
- public void setResponse(String value) {
- // Do nothing, prevent the caller from receiving a list of errors.
- }
-
- private class InvokeData {
- private boolean isActive = true;
-
- // ignore errors by default
- private boolean ignoreErrors = true;
-
- private final String repoAuditIsActive;
- private final String repoAuditIgnoreErrors;
-
- private final String repositoryId;
- private final String repositoryUrl;
- private final String repositoryUsername;
- private final String repositoryPassword;
- private final boolean upload;
-
- // used to incrementally construct response as problems occur
- // (empty = no problems)
- private final StringBuilder response = new StringBuilder();
-
- private long timeoutInSeconds = DEFAULT_TIMEOUT;
-
- private Path dir;
-
- private String groupId = null;
- private String artifactId = null;
- private String version = null;
-
- // artifacts to be downloaded
- private final List<Artifact> artifacts = new LinkedList<>();
-
- // 0 = base repository, 2-n = additional repositories
- private final int index;
-
- public InvokeData() {
- this(0);
- }
-
- public InvokeData(int index) {
- this.index = index;
- repoAuditIsActive = getProperty("audit.is.active", true);
- repoAuditIgnoreErrors = getProperty("audit.ignore.errors", true);
-
- // Fetch repository information from 'IntegrityMonitorProperties'
- repositoryId = getProperty("audit.id", false);
- repositoryUrl = getProperty("audit.url", false);
- repositoryUsername = getProperty("audit.username", true);
- repositoryPassword = getProperty("audit.password", true);
-
- logger.debug("Nexus Repository Information retrieved from 'IntegrityMonitorProperties':");
- logger.debug("repositoryId: {}", repositoryId);
- logger.debug("repositoryUrl: {}", repositoryUrl);
-
- // Setting upload to be false so that files can no longer be created/deleted
- upload = false;
- }
-
- private String getProperty(String property, boolean useDefault) {
- String fullProperty = (index == 0 ? "repository." + property : "repository" + index + "." + property);
- String rval = StateManagementProperties.getProperty(fullProperty);
- if (rval == null && index != 0 && useDefault) {
- rval = StateManagementProperties.getProperty("repository." + property);
- }
- return rval;
- }
-
- public void initIsActive() {
- if (repoAuditIsActive != null) {
- try {
- isActive = Boolean.parseBoolean(repoAuditIsActive.trim());
- } catch (NumberFormatException e) {
- logger.warn("RepositoryAudit.invoke: Ignoring invalid property: repository.audit.is.active = {}",
- repoAuditIsActive);
- }
- }
- if (repositoryId == null || repositoryUrl == null) {
- isActive = false;
- }
- }
-
- public void initIgnoreErrors() {
- if (repoAuditIgnoreErrors != null) {
- try {
- ignoreErrors = Boolean.parseBoolean(repoAuditIgnoreErrors.trim());
- } catch (NumberFormatException e) {
- ignoreErrors = true;
- logger.warn(
- "RepositoryAudit.invoke: Ignoring invalid property: repository.audit.ignore.errors = {}",
- repoAuditIgnoreErrors);
- }
- } else {
- ignoreErrors = true;
- }
- }
-
- public void initTimeout() {
- var timeoutString = getProperty("audit.timeout", true);
- if (timeoutString != null && !timeoutString.isEmpty()) {
- try {
- timeoutInSeconds = Long.valueOf(timeoutString);
- } catch (NumberFormatException e) {
- logger.error("RepositoryAudit: Invalid 'repository.audit.timeout' value: '{}'", timeoutString, e);
- if (!ignoreErrors) {
- response.append("Invalid 'repository.audit.timeout' value: '").append(timeoutString)
- .append("'\n");
- setResponse(response.toString());
- }
- }
- }
- }
-
- private void uploadTestFile() throws IOException, InterruptedException {
- groupId = "org.onap.policy.audit";
- artifactId = "repository-audit";
- version = "0." + System.currentTimeMillis();
-
- if (repositoryUrl.toLowerCase().contains("snapshot")) {
- // use SNAPSHOT version
- version += "-SNAPSHOT";
- }
-
- // create text file to write
- try (var fos = new FileOutputStream(dir.resolve("repository-audit.txt").toFile())) {
- fos.write(version.getBytes());
- }
-
- // try to install file in repository
- if (runProcess(timeoutInSeconds, dir.toFile(), null, "mvn", "deploy:deploy-file",
- "-DrepositoryId=" + repositoryId, "-Durl=" + repositoryUrl, "-Dfile=repository-audit.txt",
- "-DgroupId=" + groupId, "-DartifactId=" + artifactId, "-Dversion=" + version, "-Dpackaging=txt",
- "-DgeneratePom=false") != 0) {
- logger.error("RepositoryAudit: 'mvn deploy:deploy-file' failed");
- if (!ignoreErrors) {
- response.append("'mvn deploy:deploy-file' failed\n");
- setResponse(response.toString());
- }
- } else {
- logger.info("RepositoryAudit: 'mvn deploy:deploy-file succeeded");
-
- // we also want to include this new artifact in the download
- // test (steps 3 and 4)
- artifacts.add(new Artifact(groupId, artifactId, version, "txt"));
- }
- }
-
- private void createPomFile(final Path repo, final Path pom) throws IOException {
-
- artifacts.add(new Artifact("org.apache.maven/maven-embedder/3.2.2"));
-
- var sb = new StringBuilder();
- sb.append(
- "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
- + " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">\n"
- + "\n" + " <modelVersion>4.0.0</modelVersion>\n" + " <groupId>empty</groupId>\n"
- + " <artifactId>empty</artifactId>\n" + " <version>1.0-SNAPSHOT</version>\n"
- + " <packaging>pom</packaging>\n" + "\n" + " <build>\n" + " <plugins>\n"
- + " <plugin>\n" + " <groupId>org.apache.maven.plugins</groupId>\n"
- + " <artifactId>maven-dependency-plugin</artifactId>\n"
- + " <version>2.10</version>\n" + " <executions>\n"
- + " <execution>\n" + " <id>copy</id>\n" + " <goals>\n"
- + " <goal>copy</goal>\n" + " </goals>\n"
- + " <configuration>\n" + " <localRepositoryDirectory>")
- .append(repo).append("</localRepositoryDirectory>\n").append(" <artifactItems>\n");
-
- for (Artifact artifact : artifacts) {
- // each artifact results in an 'artifactItem' element
- sb.append(" <artifactItem>\n" + " <groupId>").append(artifact.groupId)
- .append("</groupId>\n" + " <artifactId>").append(artifact.artifactId)
- .append("</artifactId>\n" + " <version>").append(artifact.version)
- .append("</version>\n" + " <type>").append(artifact.type)
- .append("</type>\n" + " </artifactItem>\n");
- }
- sb.append(" </artifactItems>\n" + " </configuration>\n"
- + " </execution>\n" + " </executions>\n" + " </plugin>\n"
- + " </plugins>\n" + " </build>\n" + "</project>\n");
-
- try (var fos = new FileOutputStream(pom.toFile())) {
- fos.write(sb.toString().getBytes());
- }
- }
-
- private int runMaven(File output) throws IOException, InterruptedException {
- int rval = runProcess(timeoutInSeconds, dir.toFile(), output, "mvn", "compile");
- logger.info("RepositoryAudit: 'mvn' return value = {}", rval);
- if (rval != 0) {
- logger.error("RepositoryAudit: 'mvn compile' invocation failed");
- if (!ignoreErrors) {
- response.append("'mvn compile' invocation failed\n");
- setResponse(response.toString());
- }
- }
- return rval;
- }
-
- private void verifyDownloads(final Path repo) {
- for (Artifact artifact : artifacts) {
- if (repo.resolve(artifact.groupId.replace('.', '/')).resolve(artifact.artifactId)
- .resolve(artifact.version)
- .resolve(artifact.artifactId + "-" + artifact.version + "." + artifact.type).toFile()
- .exists()) {
- // artifact exists, as expected
- logger.info("RepositoryAudit: {} : exists", artifact);
- } else {
- // Audit ERROR: artifact download failed for some reason
- logger.error("RepositoryAudit: {}: does not exist", artifact);
- if (!ignoreErrors) {
- response.append("Failed to download artifact: ").append(artifact).append('\n');
- setResponse(response.toString());
- }
- }
- }
- }
-
- private void deleteUploadedTestFile() throws IOException, InterruptedException {
- if (runProcess(timeoutInSeconds, dir.toFile(), null, "curl", "--request", "DELETE", "--user",
- repositoryUsername + ":" + repositoryPassword,
- repositoryUrl + "/" + groupId.replace('.', '/') + "/" + artifactId + "/" + version) != 0) {
- logger.error("RepositoryAudit: delete of uploaded artifact failed");
- if (!ignoreErrors) {
- response.append("delete of uploaded artifact failed\n");
- setResponse(response.toString());
- }
- } else {
- logger.info("RepositoryAudit: delete of uploaded artifact succeeded");
- artifacts.add(new Artifact(groupId, artifactId, version, "txt"));
- }
- }
- }
-
- private void generateDownloadLogs(File output) throws IOException {
- // place output in 'fileContents' (replacing the Return characters
- // with Newline)
- var outputData = new byte[(int) output.length()];
- String fileContents;
- try (var fis = new FileInputStream(output)) {
- //
- // Ideally this should be in a loop or even better use
- // Java 8 nio functionality.
- //
- int bytesRead = fis.read(outputData);
- logger.info("fileContents read {} bytes", bytesRead);
- fileContents = new String(outputData).replace('\r', '\n');
- }
-
- // generate log messages from 'Downloading' and 'Downloaded'
- // messages within the 'mvn' output
- var index = 0;
- while ((index = fileContents.indexOf("\nDown", index)) > 0) {
- index += 5;
- if (fileContents.regionMatches(index, "loading: ", 0, 9)) {
- index += 9;
- int endIndex = fileContents.indexOf('\n', index);
- if (logger.isInfoEnabled()) {
- logger.info("RepositoryAudit: Attempted download: '{}'", fileContents.substring(index, endIndex));
- }
- index = endIndex;
- } else if (fileContents.regionMatches(index, "loaded: ", 0, 8)) {
- index += 8;
- int endIndex = fileContents.indexOf(' ', index);
- if (logger.isInfoEnabled()) {
- logger.info("RepositoryAudit: Successful download: '{}'", fileContents.substring(index, endIndex));
- }
- index = endIndex;
- }
- }
- }
-
- /**
- * Run a process, and wait for the response.
- *
- * @param timeoutInSeconds the number of seconds to wait for the process to terminate
- * @param directory the execution directory of the process (null = current directory)
- * @param stdout the file to contain the standard output (null = discard standard output)
- * @param command command and arguments
- * @return the return value of the process
- * @throws IOException InterruptedException
- */
- static int runProcess(long timeoutInSeconds, File directory, File stdout, String... command)
- throws IOException, InterruptedException {
- var pb = new ProcessBuilder(command);
- if (directory != null) {
- pb.directory(directory);
- }
- if (stdout != null) {
- pb.redirectOutput(stdout);
- }
-
- var process = pb.start();
- if (process.waitFor(timeoutInSeconds, TimeUnit.SECONDS)) {
- // process terminated before the timeout
- return process.exitValue();
- }
-
- // process timed out -- kill it, and return -1
- process.destroyForcibly();
- return -1;
- }
-
- /* ============================================================ */
-
- /**
- * An instance of this class exists for each artifact that we are trying to download.
- */
- @AllArgsConstructor
- static class Artifact {
- String groupId;
- String artifactId;
- String version;
- String type;
-
- /**
- * Constructor - populate an 'Artifact' instance.
- *
- * @param artifact a string of the form: {@code"<groupId>/<artifactId>/<version>[/<type>]"}
- * @throws IllegalArgumentException if 'artifact' has the incorrect format
- */
- Artifact(String artifact) {
- String[] segments = artifact.split("/");
- if (segments.length != 4 && segments.length != 3) {
- throw new IllegalArgumentException("groupId/artifactId/version/type");
- }
- groupId = segments[0];
- artifactId = segments[1];
- version = segments[2];
- type = segments.length == 4 ? segments[3] : "jar";
- }
-
- /**
- * Returns string representation.
- *
- * @return the artifact id in the form: {@code"<groupId>/<artifactId>/<version>/<type>"}
- */
- @Override
- public String toString() {
- return groupId + "/" + artifactId + "/" + version + "/" + type;
- }
- }
-}
diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeature.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeature.java
deleted file mode 100644
index 8f5e4e3c..00000000
--- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeature.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * feature-state-management
- * ================================================================================
- * 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.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.statemanagement;
-
-import java.io.IOException;
-import org.onap.policy.common.im.AllSeemsWellException;
-import org.onap.policy.common.im.IntegrityMonitorException;
-import org.onap.policy.common.im.StateChangeNotifier;
-import org.onap.policy.common.im.StateManagement;
-import org.onap.policy.common.im.StateManagementException;
-import org.onap.policy.drools.core.PolicySessionFeatureApi;
-import org.onap.policy.drools.features.PolicyEngineFeatureApi;
-import org.onap.policy.drools.utils.PropertyUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * If this feature is supported, there is a single instance of it.
- * It adds persistence to Drools sessions, but it is also intertwined with
- * active/standby state management and IntegrityMonitor. For now, they are
- * all treated as a single feature, but it would be nice to separate them.
- *
- * <p>The bulk of the code here was once in other classes, such as
- * 'PolicyContainer' and 'Main'. It was moved here as part of making this
- * a separate optional feature.
- */
-
-public class StateManagementFeature implements StateManagementFeatureApi,
- PolicySessionFeatureApi, PolicyEngineFeatureApi {
- // get an instance of logger
- private static final Logger logger =
- LoggerFactory.getLogger(StateManagementFeature.class);
-
- private DroolsPdpIntegrityMonitor droolsPdpIntegrityMonitor = null;
- private StateManagement stateManagement = null;
-
- public StateManagementFeature() {
- logger.debug("StateManagementFeature() constructor");
- }
-
- @Override
- public void globalInit(String[] args, String configDir) {
- // Initialization code associated with 'PolicyContainer'
- logger.debug("StateManagementFeature.globalInit({}) entry", configDir);
-
- try {
- droolsPdpIntegrityMonitor = DroolsPdpIntegrityMonitor.init(configDir);
- } catch (Exception e) {
- logger.debug("DroolsPDPIntegrityMonitor initialization exception: ", e);
- logger.error("DroolsPDPIntegrityMonitor.init()", e);
- }
-
- initializeProperties(configDir);
-
- //At this point the DroolsPDPIntegrityMonitor instance must exist. Let's check it.
- try {
- droolsPdpIntegrityMonitor = DroolsPdpIntegrityMonitor.getInstance();
- stateManagement = droolsPdpIntegrityMonitor.getStateManager();
-
- if (stateManagement == null) {
- logger.debug("StateManagementFeature.globalInit(): stateManagement is NULL!");
- } else {
- logger.debug("StateManagementFeature.globalInit(): "
- + "stateManagement.getAdminState(): {}", stateManagement.getAdminState());
- }
- } catch (Exception e1) {
- logger.debug("StateManagementFeature.globalInit(): DroolsPDPIntegrityMonitor"
- + " initialization failed with exception:", e1);
- logger.error("DroolsPDPIntegrityMonitor.init(): StateManagementFeature startup failed "
- + "to get DroolsPDPIntegrityMonitor instance:", e1);
- }
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void addObserver(StateChangeNotifier stateChangeObserver) {
- logger.debug("StateManagementFeature.addObserver() entry\n"
- + "StateManagementFeature.addObserver(): "
- + "stateManagement.getAdminState(): {}", stateManagement.getAdminState());
-
- stateManagement.addObserver(stateChangeObserver);
-
- logger.debug("StateManagementFeature.addObserver() exit");
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public String getAdminState() {
- return stateManagement.getAdminState();
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public String getOpState() {
- return stateManagement.getOpState();
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public String getAvailStatus() {
- return stateManagement.getAvailStatus();
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public String getStandbyStatus() {
- return stateManagement.getStandbyStatus();
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public String getStandbyStatus(String resourceName) {
- return stateManagement.getStandbyStatus(resourceName);
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void disableFailed(String resourceName) throws StateManagementException {
- stateManagement.disableFailed(resourceName);
-
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void disableFailed() throws StateManagementException {
- stateManagement.disableFailed();
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void promote() throws IntegrityMonitorException {
- stateManagement.promote();
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void demote() throws StateManagementException {
- stateManagement.demote();
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public String getResourceName() {
- return StateManagementProperties.getProperty(StateManagementProperties.NODE_NAME);
- }
-
- /**
- * {@inheritDoc}.
- *
- * @return true if locked or false if failed
- */
- @Override
- public boolean lock() {
- try {
- stateManagement.lock();
- } catch (Exception e) {
- logger.error("StateManagementFeature.lock() failed with exception", e);
- return false;
- }
- return true;
- }
-
- /**
- * {@inheritDoc}.
- *
- * @throws Exception exception
- */
- @Override
- public boolean unlock() {
- try {
- stateManagement.unlock();
- } catch (Exception e) {
- logger.error("StateManagementFeature.unlock() failed with exception", e);
- return false;
- }
- return true;
- }
-
- /**
- * {@inheritDoc}.
- *
- * @throws Exception exception
- */
- @Override
- public boolean isLocked() {
- return StateManagement.LOCKED.equals(stateManagement.getAdminState());
- }
-
- @Override
- public int getSequenceNumber() {
- return StateManagementFeatureApiConstants.SEQ_NUM;
- }
-
- /**
- * Read in the properties and initialize the StateManagementProperties.
- */
- private static void initializeProperties(String configDir) {
- //Get the state management properties
- try {
- var props = PropertyUtil.getProperties(configDir + "/feature-state-management.properties");
- StateManagementProperties.initProperties(props);
- logger.info("initializeProperties: resourceName= {}",
- StateManagementProperties.getProperty(StateManagementProperties.NODE_NAME));
- } catch (IOException e1) {
- logger.error("initializeProperties", e1);
- }
- }
-
- @Override
- public void allSeemsWell(String key, Boolean asw, String msg)
- throws AllSeemsWellException {
-
- droolsPdpIntegrityMonitor.allSeemsWell(key, asw, msg);
-
- }
-}
diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementProperties.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementProperties.java
deleted file mode 100644
index 1582ace0..00000000
--- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementProperties.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * feature-state-management
- * ================================================================================
- * Copyright (C) 2017-2018, 2020-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.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.statemanagement;
-
-import java.util.Properties;
-import lombok.AccessLevel;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import org.eclipse.persistence.config.PersistenceUnitProperties;
-import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class StateManagementProperties {
- // get an instance of logger
- private static final Logger logger = LoggerFactory.getLogger(StateManagementProperties.class);
-
- public static final String NODE_NAME = "resource.name";
- public static final String NODE_TYPE = "node_type";
- public static final String SITE_NAME = "site_name";
-
- public static final String DB_DRIVER = PersistenceUnitProperties.JDBC_DRIVER;
- public static final String DB_URL = PersistenceUnitProperties.JDBC_URL;
- public static final String DB_USER = PersistenceUnitProperties.JDBC_USER;
- public static final String DB_PWD = PersistenceUnitProperties.JDBC_PASSWORD;
- public static final String DB_TYPE = PersistenceUnitProperties.TARGET_DATABASE;
-
- public static final String TEST_SERVICES = PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES;
- public static final String TEST_SERVICES_DEFAULT = "TEST";
- public static final String TEST_HOST =
- TEST_SERVICES + "." + TEST_SERVICES_DEFAULT + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX;
- public static final String TEST_PORT =
- TEST_SERVICES + "." + TEST_SERVICES_DEFAULT + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX;
- public static final String TEST_REST_CLASSES =
- TEST_SERVICES + "." + TEST_SERVICES_DEFAULT + PolicyEndPointProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX;
- public static final String TEST_REST_CLASSES_DEFAULT = IntegrityMonitorRestManager.class.getName();
- public static final String TEST_MANAGED =
- TEST_SERVICES + "." + TEST_SERVICES_DEFAULT + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX;
- public static final String TEST_MANAGED_DEFAULT = "false";
- public static final String TEST_SWAGGER =
- TEST_SERVICES + "." + TEST_SERVICES_DEFAULT + PolicyEndPointProperties.PROPERTY_HTTP_SWAGGER_SUFFIX;
- public static final String TEST_SWAGGER_DEFAULT = "true";
- public static final String RESOURCE_NAME = "resource.name";
- public static final String FP_MONITOR_INTERVAL = "fp_monitor_interval";
- public static final String FAILED_COUNTER_THRESHOLD = "failed_counter_threshold";
- public static final String TEST_TRANS_INTERVAL = "test_trans_interval";
- public static final String WRITE_FPC_INTERVAL = "write_fpc_interval";
- public static final String DEPENDENCY_GROUPS = "dependency_groups";
-
- @Getter
- private static Properties properties = null;
-
- /**
- * Initialize the parameter values from the feature-state-management.properties file values.
- *
- * <p>This is designed so that the Properties object is obtained from the
- * feature-state-management.properties file and then is passed to this method to initialize the
- * value of the parameters. This allows the flexibility of JUnit tests using
- * getProperties(filename) to get the properties while runtime methods can use
- * getPropertiesFromClassPath(filename).
- *
- * @param prop properties
- */
- public static void initProperties(Properties prop) {
- logger.info("StateManagementProperties.initProperties(Properties): entry");
- logger.info("\n\nStateManagementProperties.initProperties: Properties = \n{}\n\n", prop);
-
- properties = prop;
- }
-
- public static String getProperty(String key) {
- return properties.getProperty(key);
- }
-}
diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementPropertiesException.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementPropertiesException.java
deleted file mode 100644
index a88bcf25..00000000
--- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementPropertiesException.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Feature-State-Management
- * ================================================================================
- * Copyright (C) 2017-2018 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.statemanagement;
-
-public class StateManagementPropertiesException extends Exception {
- private static final long serialVersionUID = 1L;
-
- public StateManagementPropertiesException() {
- super();
- }
-
- public StateManagementPropertiesException(String message) {
- super(message);
- }
-
- public StateManagementPropertiesException(Throwable cause) {
- super(cause);
- }
-
- public StateManagementPropertiesException(String message, Throwable cause) {
- super(message, cause);
- }
-
-}
diff --git a/feature-state-management/src/main/resources/META-INF/services/org.onap.policy.drools.core.PolicySessionFeatureApi b/feature-state-management/src/main/resources/META-INF/services/org.onap.policy.drools.core.PolicySessionFeatureApi
deleted file mode 100644
index 9ffef571..00000000
--- a/feature-state-management/src/main/resources/META-INF/services/org.onap.policy.drools.core.PolicySessionFeatureApi
+++ /dev/null
@@ -1 +0,0 @@
-org.onap.policy.drools.statemanagement.StateManagementFeature \ No newline at end of file
diff --git a/feature-state-management/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyEngineFeatureApi b/feature-state-management/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyEngineFeatureApi
deleted file mode 100644
index 74d0b995..00000000
--- a/feature-state-management/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyEngineFeatureApi
+++ /dev/null
@@ -1 +0,0 @@
-org.onap.policy.drools.statemanagement.StateManagementFeature
diff --git a/feature-state-management/src/main/resources/META-INF/services/org.onap.policy.drools.statemanagement.StateManagementFeatureApi b/feature-state-management/src/main/resources/META-INF/services/org.onap.policy.drools.statemanagement.StateManagementFeatureApi
deleted file mode 100644
index 74d0b995..00000000
--- a/feature-state-management/src/main/resources/META-INF/services/org.onap.policy.drools.statemanagement.StateManagementFeatureApi
+++ /dev/null
@@ -1 +0,0 @@
-org.onap.policy.drools.statemanagement.StateManagementFeature
diff --git a/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/Audit.java b/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/Audit.java
deleted file mode 100644
index 37d9d7b8..00000000
--- a/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/Audit.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Integrity Monitor
- * ================================================================================
- * Copyright (C) 2017-2018 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.statemanagement.test;
-
-import java.io.Serializable;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Table;
-
-@Entity
-@Table(name = "Audit")
-
-public class Audit implements Serializable {
- private static final long serialVersionUID = 1L;
-
- @Id
- @Column(name = "name", length = 64, unique = true)
- private String name;
-
- public Audit() {
- //default constructor
- }
-}
diff --git a/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java b/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java
deleted file mode 100644
index 578b6222..00000000
--- a/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * policy-persistence
- * ================================================================================
- * 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.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.statemanagement.test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.util.Properties;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.EntityTransaction;
-import javax.persistence.Persistence;
-import javax.ws.rs.core.Response;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.common.im.IntegrityMonitorException;
-import org.onap.policy.common.im.StateManagement;
-import org.onap.policy.drools.core.PolicySessionFeatureApi;
-import org.onap.policy.drools.statemanagement.DbAudit;
-import org.onap.policy.drools.statemanagement.IntegrityMonitorRestManager;
-import org.onap.policy.drools.statemanagement.RepositoryAudit;
-import org.onap.policy.drools.statemanagement.StateManagementFeatureApi;
-import org.onap.policy.drools.statemanagement.StateManagementFeatureApiConstants;
-import org.onap.policy.drools.statemanagement.StateManagementProperties;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class StateManagementTest {
-
- // get an instance of logger
- private static Logger logger = LoggerFactory.getLogger(StateManagementTest.class);
-
- private static EntityManagerFactory emf;
- private static EntityManager em;
-
- StateManagementFeatureApi stateManagementFeature;
-
- /**
- * Setup the class.
- * All you need to do here is create an instance of StateManagementFeature class. Then,
- * check it initial state and the state after diableFailed() and promote()
- *
- * @throws Exception exception
- */
- @BeforeClass
- public static void setUpClass() throws Exception {
-
- logger.info("setUpClass: Entering");
-
- String userDir = System.getProperty("user.dir");
- logger.debug("setUpClass: userDir=" + userDir);
- System.setProperty("com.sun.management.jmxremote.port", "9980");
- System.setProperty("com.sun.management.jmxremote.authenticate", "false");
-
- initializeDb();
-
- logger.info("setUpClass: Exiting");
- }
-
- @AfterClass
- public static void tearDownClass() throws Exception {
- em.close();
- emf.close();
- }
-
- @Before
- public void setUp() throws Exception {
-
- }
-
- @After
- public void tearDown() throws Exception {
-
- }
-
- /*
- * Verifies that StateManagementFeature starts and runs successfully.
- */
-
- //@Ignore
- @Test
- public void testStateManagementOperation() throws Exception {
-
- logger.debug("\n\ntestStateManagementOperation: Entering\n\n");
-
- logger.debug("testStateManagementOperation: Reading StateManagementProperties");
-
- String configDir = "src/test/resources";
-
- DbAudit.setJunit(true);
-
- Properties fsmProperties = new Properties();
- fsmProperties.load(new FileInputStream(new File(
- configDir + "/feature-state-management.properties")));
- String thisPdpId = fsmProperties
- .getProperty(StateManagementProperties.NODE_NAME);
-
- StateManagementFeatureApi stateManagementFeature = null;
- for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, configDir);
- stateManagementFeature = feature;
- logger.debug("testStateManagementOperation stateManagementFeature.getResourceName(): "
- + stateManagementFeature.getResourceName());
- break;
- }
- if (stateManagementFeature == null) {
- String msg = "testStateManagementOperation failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: " + thisPdpId;
- logger.error(msg);
- logger.debug(msg);
- }
-
- String admin = stateManagementFeature.getAdminState();
- String oper = stateManagementFeature.getOpState();
- String avail = stateManagementFeature.getAvailStatus();
- String standby = stateManagementFeature.getStandbyStatus();
-
- logger.debug("admin = {}", admin);
- logger.debug("oper = {}", oper);
- logger.debug("avail = {}", avail);
- logger.debug("standby = {}", standby);
-
- assertEquals("Admin state not unlocked after initialization", StateManagement.UNLOCKED, admin);
- assertEquals("Operational state not enabled after initialization", StateManagement.ENABLED, oper);
-
- try {
- stateManagementFeature.disableFailed();
- } catch (Exception e) {
- logger.error(e.getMessage());
- assertTrue(e.getMessage(), false);
- }
-
- admin = stateManagementFeature.getAdminState();
- oper = stateManagementFeature.getOpState();
- avail = stateManagementFeature.getAvailStatus();
- standby = stateManagementFeature.getStandbyStatus();
-
- logger.debug("after disableFailed()");
- logger.debug("admin = {}", admin);
- logger.debug("oper = {}", oper);
- logger.debug("avail = {}", avail);
- logger.debug("standby = {}", standby);
-
- assertEquals("Operational state not disabled after disableFailed()", StateManagement.DISABLED, oper);
- assertEquals("Availability status not failed after disableFailed()", StateManagement.FAILED, avail);
-
-
- try {
- stateManagementFeature.promote();
- } catch (Exception e) {
- logger.debug(e.getMessage());
- }
-
- admin = stateManagementFeature.getAdminState();
- oper = stateManagementFeature.getOpState();
- avail = stateManagementFeature.getAvailStatus();
- standby = stateManagementFeature.getStandbyStatus();
-
- logger.debug("after promote()");
- logger.debug("admin = {}", admin);
- logger.debug("oper = {}", oper);
- logger.debug("avail = {}", avail);
- logger.debug("standby = {}", standby);
-
- assertEquals("Standby status not coldstandby after promote()", StateManagement.COLD_STANDBY, standby);
-
- /* *************Repository Audit Test. ************* */
- logger.debug("\n\ntestStateManagementOperation: Repository Audit\n\n");
- try {
- StateManagementProperties.initProperties(fsmProperties);
- RepositoryAudit repositoryAudit = (RepositoryAudit) RepositoryAudit.getInstance();
- repositoryAudit.invoke(fsmProperties);
-
- //Should not throw an IOException in Linux Foundation env
-
- } catch (IntegrityMonitorException e) {
- //Note: this catch is here because in a local environment mvn will not run in
- //in the temp directory
- logger.debug("testSubsytemTest RepositoryAudit IOException", e);
- }
-
- /* ****************Db Audit Test. ************** */
- logger.debug("\n\ntestStateManagementOperation: DB Audit\n\n");
-
- DbAudit dbAudit = (DbAudit) DbAudit.getInstance();
- dbAudit.invoke(fsmProperties);
-
- /* ************IntegrityMonitorRestManager Test. ************ */
- logger.debug("\n\ntestStateManagementOperation: IntegrityMonitorRestManager\n\n");
- IntegrityMonitorRestManager integrityMonitorRestManager = new IntegrityMonitorRestManager();
-
- Response response = integrityMonitorRestManager.test();
- logger.debug("\n\nIntegrityMonitorRestManager response: " + response.toString());
-
- assertTrue(response.toString().contains("status=500"));
-
- //All done
- logger.debug("\n\ntestStateManagementOperation: Exiting\n\n");
- }
-
- /**
- * This method initializes and cleans the DB so that PDP-D will be able to
- * store fresh records in the DB.
- */
- public static void initializeDb() {
-
- logger.debug("initializeDb: Entering");
-
- Properties cleanProperties = new Properties();
- cleanProperties.put(StateManagementProperties.DB_DRIVER, "org.h2.Driver");
- cleanProperties.put(StateManagementProperties.DB_URL, "jdbc:h2:mem:statemanagement");
- cleanProperties.put(StateManagementProperties.DB_USER, "sa");
- cleanProperties.put(StateManagementProperties.DB_PWD, "");
-
- emf = Persistence.createEntityManagerFactory("junitPU", cleanProperties);
-
- em = emf.createEntityManager();
- // Start a transaction
- EntityTransaction et = em.getTransaction();
-
- et.begin();
-
- // Clean up the DB
- em.createQuery("Delete from StateManagementEntity").executeUpdate();
- em.createQuery("Delete from ForwardProgressEntity").executeUpdate();
- em.createQuery("Delete from ResourceRegistrationEntity").executeUpdate();
-
- // commit transaction
- et.commit();
-
- logger.debug("initializeDb: Exiting");
- }
-}
diff --git a/feature-state-management/src/test/resources/META-INF/persistence.xml b/feature-state-management/src/test/resources/META-INF/persistence.xml
deleted file mode 100644
index c96d8b64..00000000
--- a/feature-state-management/src/test/resources/META-INF/persistence.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ============LICENSE_START=======================================================
- feature-state-management
- ================================================================================
- Copyright (C) 2017-2018, 2020 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.
- See the License for the specific language governing permissions and
- limitations under the License.
- ============LICENSE_END=========================================================
- -->
-
-<persistence version="2.1"
- xmlns="http://xmlns.jcp.org/xml/ns/persistence"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
-
- <persistence-unit name="junitPU"
- transaction-type="RESOURCE_LOCAL">
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
- <class>org.onap.policy.common.im.jpa.StateManagementEntity</class>
- <class>org.onap.policy.common.im.jpa.ForwardProgressEntity</class>
- <class>org.onap.policy.common.im.jpa.ResourceRegistrationEntity</class>
- <class>org.onap.policy.drools.statemanagement.test.Audit</class>
- <properties>
- <property
- name="javax.persistence.schema-generation.database.action"
- value="drop-and-create" />
- <property
- name="javax.persistence.schema-generation.scripts.action"
- value="drop-and-create" />
- <property
- name="javax.persistence.schema-generation.scripts.create-target"
- value="target/classes/META-INF/generatedCreateStateManagement.ddl" />
- <property
- name="javax.persistence.schema-generation.scripts.drop-target"
- value="target/classes/META-INF/generatedDropStateManagement.ddl" />
- </properties>
- </persistence-unit>
-
-</persistence>
diff --git a/feature-state-management/src/test/resources/feature-state-management.properties b/feature-state-management/src/test/resources/feature-state-management.properties
deleted file mode 100644
index ef7b805a..00000000
--- a/feature-state-management/src/test/resources/feature-state-management.properties
+++ /dev/null
@@ -1,87 +0,0 @@
-###
-# ============LICENSE_START=======================================================
-# feature-state-management
-# ================================================================================
-# Copyright (C) 2017, 2020-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.
-# 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.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-# ============LICENSE_END=========================================================
-###
-
-# DB properties
-eclipselink.target-database=Auto
-javax.persistence.jdbc.driver = org.h2.Driver
-javax.persistence.jdbc.url = jdbc:h2:mem:statemanagement
-javax.persistence.jdbc.user = sa
-javax.persistence.jdbc.password =
-
-# DroolsPDPIntegrityMonitor Properties
-#Test interface host and port defaults may be overwritten here
-http.server.services.TEST.host=0.0.0.0
-http.server.services.TEST.port=9981
-#These properties will default to the following if no other values are provided:
-# http.server.services.TEST.restClasses=org.onap.policy.drools.statemanagement.IntegrityMonitorRestManager
-# http.server.services.TEST.managed=false
-# http.server.services.TEST.swagger=true
-
-#IntegrityMonitor Properties
-
-# Must be unique across the system
-resource.name=pdp1
-# Name of the site in which this node is hosted
-site_name = pdp_1
-# Forward Progress Monitor update interval seconds
-fp_monitor_interval = 30
-# Failed counter threshold before failover
-failed_counter_threshold = 3
-# Interval between test transactions when no traffic seconds
-test_trans_interval = 10
-# Interval between writes of the FPC to the DB seconds
-write_fpc_interval = 5
-# Node type Note: Make sure you don't leave any trailing spaces, or you'll get an 'invalid node type' error!
-node_type = pdp_drools
-# Dependency groups are groups of resources upon which a node operational state is dependent upon.
-# Each group is a comma-separated list of resource names and groups are separated by a semicolon. For example:
-# dependency_groups=site_1.astra_1,site_1.astra_2;site_1.brms_1,site_1.brms_2;site_1.logparser_1;site_1.pypdp_1
-dependency_groups=
-# When set to true, dependent health checks are performed by using JMX to invoke test() on the dependent.
-# The default false is to use state checks for health.
-test_via_jmx=true
-# This is the max number of seconds beyond which a non incrementing FPC is considered a failure
-max_fpc_update_interval=120
-# Run the state audit every 60 seconds (60000 ms). The state audit finds stale DB entries in the
-# forwardprogressentity table and marks the node as disabled/failed in the statemanagemententity
-# table. NOTE! It will only run on nodes that have a standbystatus = providingservice.
-# A value of <= 0 will turn off the state audit.
-state_audit_interval_ms=-1000
-# The refresh state audit is run every (default) 10 minutes (600000 ms) to clean up any state corruption in the
-# DB statemanagemententity table. It only refreshes the DB state entry for the local node. That is, it does not
-# refresh the state of any other nodes. A value <= 0 will turn the audit off. Any other value will override
-# the default of 600000 ms.
-refresh_state_audit_interval_ms=-1000
-
-
-# Repository audit properties
-# Flag to control the execution of the subsystemTest for the Nexus Maven repository
-repository.audit.is.active=true
-repository.audit.ignore.errors=true
-# Timeout in seconds
-repository.audit.timeout=5
-repository.audit.id=statemanagement
-repository.audit.url=jdbc:h2:mem:statemanagement
-repository.audit.username=sa
-repository.audit.password=
-
-# DB Audit Properties
-# Flag to control the execution of the subsystemTest for the Database
-db.audit.is.active=true
diff --git a/feature-state-management/src/test/resources/logback-test.xml b/feature-state-management/src/test/resources/logback-test.xml
deleted file mode 100644
index 99cdaf9a..00000000
--- a/feature-state-management/src/test/resources/logback-test.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- feature-state-management
- ================================================================================
- Copyright (C) 2017-2018 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.
- See the License for the specific language governing permissions and
- limitations under the License.
- ============LICENSE_END=========================================================
- -->
-
-<!-- Controls the output of logs for JUnit tests -->
-
-<configuration>
-
- <appender name="STDOUT"
- class="ch.qos.logback.core.ConsoleAppender">
- <encoder
- class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
- <Pattern>
- %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M\(%line\) - %msg%n
- </Pattern>
- </encoder>
- </appender>
- <appender name="FILE"
- class="ch.qos.logback.core.FileAppender">
- <file>logs/debug.log</file>
- <encoder>
- <Pattern>
- %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M\(%line\) - %msg%n
- </Pattern>
- </encoder>
- </appender>
-
- <root level="debug">
- <appender-ref ref="STDOUT" />
- <appender-ref ref="FILE" />
- </root>
-
-</configuration>
-
diff --git a/packages/install/pom.xml b/packages/install/pom.xml
index 3a883ed5..5c531c21 100644
--- a/packages/install/pom.xml
+++ b/packages/install/pom.xml
@@ -2,7 +2,7 @@
============LICENSE_START=======================================================
Policy Packages
================================================================================
- Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ Copyright (C) 2017, 2022 AT&T Intellectual Property. All rights reserved.
Modifications Copyright (C) 2020 Bell Canada.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
@@ -99,18 +99,6 @@
</dependency>
<dependency>
<groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>feature-state-management</artifactId>
- <version>${project.version}</version>
- <type>zip</type>
- </dependency>
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>feature-active-standby-management</artifactId>
- <version>${project.version}</version>
- <type>zip</type>
- </dependency>
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
<artifactId>feature-distributed-locking</artifactId>
<version>${project.version}</version>
<type>zip</type>
diff --git a/pom.xml b/pom.xml
index dfaac165..e9ec9cb7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
============LICENSE_START=======================================================
ONAP Policy Engine - Drools PDP
================================================================================
- Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
+ Copyright (C) 2017-2022 AT&T Intellectual Property. All rights reserved.
Modifications Copyright (C) 2020 Nordix Foundation.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
@@ -65,10 +65,6 @@
<module>feature-pooling-dmaap</module>
<module>feature-session-persistence</module>
<module>feature-test-transaction</module>
- <module>api-state-management</module>
- <module>feature-state-management</module>
- <module>api-active-standby-management</module>
- <module>feature-active-standby-management</module>
<module>feature-distributed-locking</module>
<module>feature-controller-logging</module>
<module>feature-mdc-filters</module>