summaryrefslogtreecommitdiffstats
path: root/feature-state-management/src/test
diff options
context:
space:
mode:
authorMagnusen, Drew (dm741q) <dm741q@att.com>2017-09-07 08:55:17 -0500
committerKevin McKiou <km097d@att.com>2017-09-14 18:45:36 +0000
commit18253e5bfbccc53baaa58e485704e9cb87855ac4 (patch)
tree7c91bf25f65ed1d6f43e719fc1899149994e679a /feature-state-management/src/test
parent8dd90c302c4c2406dba22a420d30a668969d889c (diff)
Addition of State Management Feature
Patch 1:This commit adds the feature to provide node state management. There are also a couple of very minor cleanup items in feature-session-persistence which came up during review and testing. Patch 2: Cleaned up some logging statements and exceptions per comments by Pam Dragosh. Patch 3: Clean up per comments from Jorge Hernandez. Patch4: Added a default to ignoreErrors in RepositoryAudit. Patch 5: Rebase. Patch 6: Removed api-state-management/.gitignore Issue-ID: POLICY-155 Change-Id: I4fbfa33314d488ff46764931ca965f802b6a26d5 Signed-off-by: Kevin McKiou <km097d@att.com>
Diffstat (limited to 'feature-state-management/src/test')
-rw-r--r--feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java245
-rw-r--r--feature-state-management/src/test/resources/META-INF/persistence.xml39
-rw-r--r--feature-state-management/src/test/resources/feature-state-management.properties74
-rw-r--r--feature-state-management/src/test/resources/logback-test.xml47
4 files changed, 405 insertions, 0 deletions
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
new file mode 100644
index 00000000..e458dcea
--- /dev/null
+++ b/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java
@@ -0,0 +1,245 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-persistence
+ * ================================================================================
+ * 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=========================================================
+ */
+
+package org.onap.policy.drools.statemanagement.test;
+
+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 org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.onap.policy.common.im.StateManagement;
+import org.onap.policy.drools.core.PolicySessionFeatureAPI;
+import org.onap.policy.drools.statemanagement.StateManagementFeatureAPI;
+import org.onap.policy.drools.statemanagement.StateManagementProperties;
+
+public class StateManagementTest {
+
+ // get an instance of logger
+ private static Logger logger = LoggerFactory.getLogger(StateManagementTest.class);
+
+ /*
+ * Sleep 5 seconds after each test to allow interrupt (shutdown) recovery.
+ */
+
+ private long interruptRecoveryTime = 1000;
+
+ StateManagementFeatureAPI stateManagementFeature;
+
+ /*
+ * 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()
+ */
+
+ @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 {
+
+ }
+
+ @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";
+
+ 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 : StateManagementFeatureAPI.impl.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);
+ }
+
+ Thread.sleep(interruptRecoveryTime);
+
+ String admin = stateManagementFeature.getAdminState();
+ String oper = stateManagementFeature.getOpState();
+ String avail = stateManagementFeature.getAvailStatus();
+ String standby = stateManagementFeature.getStandbyStatus();
+
+ logger.debug("admin = {}", admin);
+ System.out.println("admin = " + admin);
+ logger.debug("oper = {}", oper);
+ System.out.println("oper = " + oper);
+ logger.debug("avail = {}", avail);
+ System.out.println("avail = " + avail);
+ logger.debug("standby = {}", standby);
+ System.out.println("standby = " + standby);
+
+ assertTrue("Admin state not unlocked after initialization", admin.equals(StateManagement.UNLOCKED));
+ assertTrue("Operational state not enabled after initialization", oper.equals(StateManagement.ENABLED));
+
+ try{
+ stateManagementFeature.disableFailed();
+ }catch(Exception e){
+ logger.error(e.getMessage());
+ System.out.println(e.getMessage());
+ assertTrue(e.getMessage(), false);
+ }
+
+ Thread.sleep(interruptRecoveryTime);
+
+ admin = stateManagementFeature.getAdminState();
+ oper = stateManagementFeature.getOpState();
+ avail = stateManagementFeature.getAvailStatus();
+ standby = stateManagementFeature.getStandbyStatus();
+
+ logger.debug("after disableFailed()");
+ System.out.println("after disableFailed()");
+ logger.debug("admin = {}", admin);
+ System.out.println("admin = " + admin);
+ logger.debug("oper = {}", oper);
+ System.out.println("oper = " + oper);
+ logger.debug("avail = {}", avail);
+ System.out.println("avail = " + avail);
+ logger.debug("standby = {}", standby);
+ System.out.println("standby = " + standby);
+
+ assertTrue("Operational state not disabled after disableFailed()", oper.equals(StateManagement.DISABLED));
+ assertTrue("Availability status not failed after disableFailed()", avail.equals(StateManagement.FAILED));
+
+
+ try{
+ stateManagementFeature.promote();
+ }catch(Exception e){
+ logger.debug(e.getMessage());
+ System.out.println(e.getMessage());
+ }
+
+ Thread.sleep(interruptRecoveryTime);
+
+ admin = stateManagementFeature.getAdminState();
+ oper = stateManagementFeature.getOpState();
+ avail = stateManagementFeature.getAvailStatus();
+ standby = stateManagementFeature.getStandbyStatus();
+
+ logger.debug("after promote()");
+ System.out.println("after promote()");
+ logger.debug("admin = {}", admin);
+ System.out.println("admin = " + admin);
+ logger.debug("oper = {}", oper);
+ System.out.println("oper = " + oper);
+ logger.debug("avail = {}", avail);
+ System.out.println("avail = " + avail);
+ logger.debug("standby = {}", standby);
+ System.out.println("standby = " + standby);
+
+ assertTrue("Standby status not coldstandby after promote()", standby.equals(StateManagement.COLD_STANDBY));
+
+ 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:file:./sql/statemanagement");
+ cleanProperties.put(StateManagementProperties.DB_USER, "sa");
+ cleanProperties.put(StateManagementProperties.DB_PWD, "");
+
+ EntityManagerFactory emf = Persistence.createEntityManagerFactory("junitPU", cleanProperties);
+
+ EntityManager 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();
+ em.close();
+
+ 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
new file mode 100644
index 00000000..d26ab443
--- /dev/null
+++ b/feature-state-management/src/test/resources/META-INF/persistence.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============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=========================================================
+ -->
+
+<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>
+ <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="./sql/generatedCreateStateManagement.ddl"/>
+ <property name="javax.persistence.schema-generation.scripts.drop-target" value="./sql/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
new file mode 100644
index 00000000..7b4a697e
--- /dev/null
+++ b/feature-state-management/src/test/resources/feature-state-management.properties
@@ -0,0 +1,74 @@
+###
+# ============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=========================================================
+###
+
+# DB properties
+javax.persistence.jdbc.driver = org.h2.Driver
+javax.persistence.jdbc.url = jdbc:h2:file:./sql/statemanagement
+javax.persistence.jdbc.user = sa
+javax.persistence.jdbc.password =
+
+# DroolsPDPIntegrityMonitor Properties
+hostPort = 0.0.0.0:57692
+
+#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=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
+# 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/test/resources/logback-test.xml b/feature-state-management/src/test/resources/logback-test.xml
new file mode 100644
index 00000000..58cabf98
--- /dev/null
+++ b/feature-state-management/src/test/resources/logback-test.xml
@@ -0,0 +1,47 @@
+<!--
+ ============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=========================================================
+ -->
+
+<!-- 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>
+