[POLICY-105] Modifications to RefreshStateAudit 97/6197/1
authorKevin McKiou <km097d@att.com>
Mon, 24 Jul 2017 22:52:01 +0000 (17:52 -0500)
committerKevin McKiou <km097d@att.com>
Mon, 24 Jul 2017 23:13:31 +0000 (18:13 -0500)
Made the refreshStateAudit configurable and changed the default interval to 10 minutes from 1 minute.  Added a check to fpCheck to check the state of the dependent before setting the opstate to disabled.

Added a refresh to the forwardprogressentity object in stateAudit() so that we are not reading stale timestamp data.

Change-Id: I394feca083fc1fb356d11b9f6886e566c31f248a
Signed-off-by: Kevin McKiou <km097d@att.com>
integrity-monitor/src/main/java/org/openecomp/policy/common/im/IntegrityMonitor.java
integrity-monitor/src/main/java/org/openecomp/policy/common/im/IntegrityMonitorProperties.java
integrity-monitor/src/test/java/org/openecomp/policy/common/im/test/IntegrityMonitorTest.java

index a421894..57182f7 100644 (file)
@@ -133,7 +133,7 @@ public class IntegrityMonitor {
        
        private static String jmxFqdn = null;
 
-       // this is the max interval allowed without any forward progress counter updates
+       // this is the max interval seconds allowed without any forward progress counter updates
        private static int maxFpcUpdateInterval = IntegrityMonitorProperties.DEFAULT_MAX_FPC_UPDATE_INTERVAL;
        
        // Node types
@@ -153,7 +153,7 @@ public class IntegrityMonitor {
        private static String site_name;
        private static String node_type;
        private Date refreshStateAuditLastRunDate;
-       private int refreshStateAuditIntervalMs = 60000; //run it once per minute
+       private static long refreshStateAuditIntervalMs = 600000; //run it once per 10 minutes
        
        //lock objects
        private final Object evaluateSanityLock = new Object();
@@ -626,8 +626,10 @@ public class IntegrityMonitor {
                                                // create instance of StateMangement class for dependent
                                                StateManagement depStateManager = new StateManagement(emf, dep);
                                                if (depStateManager != null) {
-                                                       logger.info("Forward progress not detected for dependent resource " + dep + ". Setting dependent's state to disable failed.");
-                                                       depStateManager.disableFailed();
+                                                       if(!depStateManager.getOpState().equals(StateManagement.DISABLED)){
+                                                               logger.info("Forward progress not detected for dependent resource " + dep + ". Setting dependent's state to disable failed.");
+                                                               depStateManager.disableFailed();
+                                                       }
                                                }
                                        } catch (Exception e) {
                                                // ignore errors
@@ -1181,6 +1183,13 @@ public class IntegrityMonitor {
                        }
                }
                
+               if (prop.getProperty(IntegrityMonitorProperties.REFRESH_STATE_AUDIT_INTERVAL_MS) != null){
+                       try{
+                               refreshStateAuditIntervalMs = Long.parseLong(prop.getProperty(IntegrityMonitorProperties.REFRESH_STATE_AUDIT_INTERVAL_MS));
+                       }catch(NumberFormatException e){
+                               logger.warn("Ignored invalid property: " + IntegrityMonitorProperties.REFRESH_STATE_AUDIT_INTERVAL_MS);
+                       }
+               }
                
                return;
        }
@@ -1272,9 +1281,7 @@ public class IntegrityMonitor {
         * check their operational state.  If it is not disabled, then disable them.
         */
        public void stateAudit() {
-               
-               //TODO add stateAuditIntervalMs to the IntegrityMonitor properties here and in droolspdp
-               // monitoring interval checks
+
                if (stateAuditIntervalMs <= 0) {
                        return; // stateAudit is disabled
                }
@@ -1308,11 +1315,13 @@ public class IntegrityMonitor {
                        if(fpe.getResourceName().equals(IntegrityMonitor.resourceName)){
                                continue;
                        }
+                       //Make sure you are not getting a cached version
+                       em.refresh(fpe);
                        long diffMs = date.getTime() - fpe.getLastUpdated().getTime();
                        logger.debug("IntegrityMonitor.stateAudit(): diffMs = " + diffMs);
 
                        //Threshold for a stale entry
-                       long staleMs = failedCounterThreshold * monitorInterval * 1000;
+                       long staleMs = maxFpcUpdateInterval * 1000;
                        logger.debug("IntegrityMonitor.stateAudit(): staleMs = " + staleMs);
 
                        if(diffMs > staleMs){
@@ -1449,6 +1458,10 @@ public class IntegrityMonitor {
         * send a notification to all registered observers.
         */
        private void refreshStateAudit(){
+               if(refreshStateAuditIntervalMs <=0){
+                       // The audit is deactivated
+                       return;
+               }
                synchronized(refreshStateAuditLock){
                        logger.debug("refreshStateAudit: entry");
                        Date now = new Date();
index 9b9ae55..1a901ba 100644 (file)
@@ -37,7 +37,7 @@ public class IntegrityMonitorProperties {
        public static final int DEFAULT_FAILED_COUNTER_THRESHOLD = 3;
        public static final int DEFAULT_TEST_INTERVAL = 10; //20;
        public static final int DEFAULT_WRITE_FPC_INTERVAL = 5;
-       public static final int DEFAULT_MAX_FPC_UPDATE_INTERVAL = 60;
+       public static final int DEFAULT_MAX_FPC_UPDATE_INTERVAL = 120;
        
        public static final String FP_MONITOR_INTERVAL = "fp_monitor_interval";
        public static final String FAILED_COUNTER_THRESHOLD = "failed_counter_threshold";
@@ -52,5 +52,6 @@ public class IntegrityMonitorProperties {
        public static final String JMX_FQDN = "jmx_fqdn";
        public static final String MAX_FPC_UPDATE_INTERVAL = "max_fpc_update_interval";
        public static final String STATE_AUDIT_INTERVAL_MS = "state_audit_interval_ms";
+       public static final String REFRESH_STATE_AUDIT_INTERVAL_MS = "refresh_state_audit_interval_ms";
        
 }
index acc9ad0..d2fbac4 100644 (file)
@@ -122,10 +122,10 @@ public class IntegrityMonitorTest {
                //testSanityJmx();
                //testIM();
                //testSanityState();
-               //testRefreshStateAudit();
+               testRefreshStateAudit();
                //testStateCheck();
                //testGetAllForwardProgressEntity();
-               testStateAudit();
+               //testStateAudit();
        }
 
        /*
@@ -642,6 +642,7 @@ public class IntegrityMonitorTest {
                // parameters are passed via a properties file
                myProp.put(IntegrityMonitorProperties.DEPENDENCY_GROUPS, "");
                myProp.put(IntegrityMonitorProperties.TEST_VIA_JMX, "false");
+               myProp.put(IntegrityMonitorProperties.REFRESH_STATE_AUDIT_INTERVAL_MS, "60000");
                IntegrityMonitor.updateProperties(myProp);
                
                et = em.getTransaction();