diff options
Diffstat (limited to 'integrity-monitor/src/main/java')
-rw-r--r-- | integrity-monitor/src/main/java/org/openecomp/policy/common/im/IntegrityMonitor.java | 176 | ||||
-rw-r--r-- | integrity-monitor/src/main/java/org/openecomp/policy/common/im/StateManagement.java | 169 |
2 files changed, 195 insertions, 150 deletions
diff --git a/integrity-monitor/src/main/java/org/openecomp/policy/common/im/IntegrityMonitor.java b/integrity-monitor/src/main/java/org/openecomp/policy/common/im/IntegrityMonitor.java index 6c575ab7..293bd11c 100644 --- a/integrity-monitor/src/main/java/org/openecomp/policy/common/im/IntegrityMonitor.java +++ b/integrity-monitor/src/main/java/org/openecomp/policy/common/im/IntegrityMonitor.java @@ -37,14 +37,15 @@ import javax.persistence.LockModeType; import javax.persistence.Persistence; import javax.persistence.Query; -//import org.apache.log4j.Logger; - -import org.openecomp.policy.common.im.jmx.*; import org.openecomp.policy.common.im.jpa.ForwardProgressEntity; import org.openecomp.policy.common.im.jpa.ResourceRegistrationEntity; import org.openecomp.policy.common.im.jpa.StateManagementEntity; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; import org.openecomp.policy.common.logging.flexlogger.Logger; +//import org.apache.log4j.Logger; +import org.openecomp.policy.common.im.jmx.ComponentAdmin; +import org.openecomp.policy.common.im.jmx.ComponentAdminMBean; +import org.openecomp.policy.common.im.jmx.JmxAgentConnection; /** * IntegrityMonitor @@ -309,7 +310,6 @@ public class IntegrityMonitor { em.persist(rrx); // flush to the DB synchronized(IMFLUSHLOCK){ - em.flush(); et.commit(); } @@ -442,59 +442,145 @@ public class IntegrityMonitor { } } - - private String stateCheck(String dep) { + + /* + * This method checks the forward progress counter and the state of + * a dependency. If the dependency is unavailable or failed, an + * error message is created which is checked when evaluateSanity interface + * is called. If the error message is set then the evaluateSanity + * will return an error. + */ + public String stateCheck(String dep) { logger.debug("checking state of dependent resource: " + dep); - - // get state management entry for dependent resource - StateManagementEntity stateManagementEntity = null; + String error_msg = null; - try { - // Start a transaction - EntityTransaction et = em.getTransaction(); - et.begin(); + ForwardProgressEntity forwardProgressEntity = null; + StateManagementEntity stateManagementEntity = null; + + // Start a transaction + EntityTransaction et = em.getTransaction(); + et.begin(); - // query if StateManagement entry exists for dependent resource - Query query = em.createQuery("Select p from StateManagementEntity p where p.resourceName=:resource"); + try{ + Query query = em.createQuery("Select p from ForwardProgressEntity p where p.resourceName=:resource"); query.setParameter("resource", dep); @SuppressWarnings("rawtypes") - List smList = query.setLockMode( - LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList(); - if (!smList.isEmpty()) { - // exist - stateManagementEntity = (StateManagementEntity) smList.get(0); + List fpList = query.setLockMode( + LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList(); + + if (!fpList.isEmpty()) { + // exists + forwardProgressEntity = (ForwardProgressEntity) fpList.get(0); // refresh the object from DB in case cached data was returned - em.refresh(stateManagementEntity); - logger.debug("Found entry in StateManagementEntity table for dependent Resource=" + dep); + em.refresh(forwardProgressEntity); + logger.debug("Found entry in ForwardProgressEntity table for dependent Resource=" + dep); } else { - error_msg = dep + ": resource not found in state management entity database table"; + error_msg = dep + ": resource not found in ForwardProgressEntity database table"; + logger.debug(error_msg); logger.error(error_msg); } - synchronized(IMFLUSHLOCK){ et.commit(); } - } catch (Exception e) { + } + catch(Exception ex){ // log an error - error_msg = dep + ": StateManagementEntity DB read failed with exception: " + e; + error_msg = dep + ": ForwardProgressEntity DB operation failed with exception: " + ex; + logger.debug(error_msg); logger.error(error_msg); + synchronized(IMFLUSHLOCK){ + if(et.isActive()){ + et.rollback(); + } + } + } + + if(error_msg==null){ + // Start a transaction + et = em.getTransaction(); + et.begin(); + try { + // query if StateManagement entry exists for dependent resource + Query query = em.createQuery("Select p from StateManagementEntity p where p.resourceName=:resource"); + query.setParameter("resource", dep); + + @SuppressWarnings("rawtypes") + List smList = query.setLockMode( + LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList(); + if (!smList.isEmpty()) { + // exist + stateManagementEntity = (StateManagementEntity) smList.get(0); + // refresh the object from DB in case cached data was returned + em.refresh(stateManagementEntity); + logger.debug("Found entry in StateManagementEntity table for dependent Resource=" + dep); + } else { + error_msg = dep + ": resource not found in state management entity database table"; + logger.debug(error_msg); + logger.error(error_msg); + } + + synchronized(IMFLUSHLOCK){ + et.commit(); + } + } catch (Exception e) { + // log an error + error_msg = dep + ": StateManagementEntity DB read failed with exception: " + e; + logger.debug(error_msg); + logger.error(error_msg); + synchronized(IMFLUSHLOCK){ + if(et.isActive()){ + et.rollback(); + } + } + } + } + + //verify that the ForwardProgress is current (check last_updated) + if(error_msg==null){ + Date date = new Date(); + long diffMs = date.getTime() - forwardProgressEntity.getLastUpdated().getTime(); + logger.debug("IntegrityMonitor.stateCheck(): diffMs = " + diffMs); + + //Threshold for a stale entry + long staleMs = failedCounterThreshold * monitorInterval * 1000; + logger.debug("IntegrityMonitor.stateCheck(): staleMs = " + staleMs); + + if(diffMs > staleMs){ + //ForwardProgress is stale. Disable it + try { + if(!stateManagementEntity.getOpState().equals(StateManagement.DISABLED)){ + logger.debug("IntegrityMonitor.stateCheck(): Changing OpStat = disabled for " + dep); + stateManager.disableFailed(dep); + } + } catch (Exception e) { + String msg = "IntegrityMonitor.stateCheck(): Failed to diableFail dependent resource = " + dep + + "; " + e.getMessage(); + logger.debug(msg); + logger.error(msg); + } + } } // check operation, admin and standby states of dependent resource if (error_msg == null) { if ((stateManager.getAdminState() != null) && stateManagementEntity.getAdminState().equals(StateManagement.LOCKED)) { error_msg = dep + ": resource is administratively locked"; + logger.debug(error_msg); logger.error(error_msg); } else if ((stateManager.getOpState() != null) && stateManagementEntity.getOpState().equals(StateManagement.DISABLED)) { error_msg = dep + ": resource is operationally disabled"; + logger.debug(error_msg); logger.error(error_msg); } else if ((stateManager.getStandbyStatus() != null) && stateManagementEntity.getStandbyStatus().equals(StateManagement.COLD_STANDBY)) { error_msg = dep + ": resource is cold standby"; + logger.debug(error_msg); logger.error(error_msg); } } + String returnMsg = "IntegrityMonitor.stateCheck(): returned error_msg: " + error_msg; + logger.debug(returnMsg); return error_msg; } @@ -551,6 +637,11 @@ public class IntegrityMonitor { // log an error and continue error_msg = dep + ": ForwardProgressEntity DB read failed with exception: " + e; logger.error(error_msg); + synchronized(IMFLUSHLOCK){ + if(et.isActive()){ + et.rollback(); + } + } } return error_msg; @@ -563,11 +654,10 @@ public class IntegrityMonitor { // get the JMX URL from the database String jmxUrl = null; + // Start a transaction + EntityTransaction et = em.getTransaction(); + et.begin(); try { - // Start a transaction - EntityTransaction et = em.getTransaction(); - et.begin(); - // query if ResourceRegistration entry exists for resourceName Query rquery = em.createQuery("Select r from ResourceRegistrationEntity r where r.resourceName=:rn"); rquery.setParameter("rn", dep); @@ -595,6 +685,11 @@ public class IntegrityMonitor { } catch (Exception e) { error_msg = dep + ": ResourceRegistrationEntity DB read failed with exception: " + e; logger.error(error_msg); + synchronized(IMFLUSHLOCK){ + if(et.isActive()){ + et.rollback(); + } + } } @@ -876,7 +971,6 @@ public class IntegrityMonitor { em.persist(fpx); // flush to the DB and commit synchronized(IMFLUSHLOCK){ - em.flush(); et.commit(); } } @@ -887,8 +981,10 @@ public class IntegrityMonitor { } } catch (Exception e) { try { - if (et.isActive()) { - et.rollback(); + synchronized(IMFLUSHLOCK){ + if (et.isActive()) { + et.rollback(); + } } } catch (Exception e1) { // ignore @@ -965,18 +1061,6 @@ public class IntegrityMonitor { } } - /*********************** - // followers are a comma separated list of resource names - if (prop.getProperty(IntegrityMonitorProperties.SS_FOLLOWERS) != null) { - try { - followers = prop.getProperty(IntegrityMonitorProperties.SS_FOLLOWERS).split(","); - logger.debug("followers property = " + Arrays.toString(followers)); - } catch (Exception e) { - logger.warn("Ignored invalid property: " + IntegrityMonitorProperties.SS_FOLLOWERS); - } - } - **************************/ - // dependency_groups are a semi-colon separated list of groups // each group is a comma separated list of resource names // For ex. dependency_groups = site_1.pap_1,site_1.pap_2 ; site_1.pdp_1, site_1.pdp_2 diff --git a/integrity-monitor/src/main/java/org/openecomp/policy/common/im/StateManagement.java b/integrity-monitor/src/main/java/org/openecomp/policy/common/im/StateManagement.java index 14d35e1d..fd0f3d9f 100644 --- a/integrity-monitor/src/main/java/org/openecomp/policy/common/im/StateManagement.java +++ b/integrity-monitor/src/main/java/org/openecomp/policy/common/im/StateManagement.java @@ -129,16 +129,11 @@ public class StateManagement extends Observable { logger.debug("Persist adminstrative state, resourceName = " + this.resourceName); em.persist(sm); synchronized(FLUSHLOCK){ - em.flush(); - if(et.isActive()){ - et.commit(); - } + et.commit(); } } else { synchronized(FLUSHLOCK){ - if(et.isActive()){ - et.commit(); - } + et.commit(); } } @@ -147,13 +142,13 @@ public class StateManagement extends Observable { logger.debug("StateManagement: constructor end, resourceName: " + this.resourceName); } catch(Exception ex) { + logger.error("StateManagement: constructor caught unexpected exception: " + ex); + ex.printStackTrace(); synchronized(FLUSHLOCK){ if(et.isActive()){ - et.commit(); + et.rollback(); } } - ex.printStackTrace(); - logger.error("StateManagement: constructor caught unexpected exception: " + ex); throw new Exception("StateManagement: Exception: " + ex.toString()); } } @@ -186,23 +181,20 @@ public class StateManagement extends Observable { em.persist(sm); synchronized(FLUSHLOCK){ - em.flush(); - if(et.isActive()){ - et.commit(); - } + et.commit(); } setChanged(); notifyObservers(ADMIN_STATE); logger.debug("StateManagement: initializeState() operation completed, resourceName = " + this.resourceName); } catch(Exception ex) { + logger.error("StateManagement.initializeState() caught unexpected exception: " + ex); + ex.printStackTrace(); synchronized(FLUSHLOCK){ if(et.isActive()){ - et.commit(); + et.rollback(); } } - ex.printStackTrace(); - logger.error("StateManagement.initializeState() caught unexpected exception: " + ex); throw new Exception("StateManagement.initializeState() Exception: " + ex); } } @@ -237,23 +229,20 @@ public class StateManagement extends Observable { em.persist(sm); synchronized(FLUSHLOCK){ - em.flush(); - if(et.isActive()){ - et.commit(); - } + et.commit(); } setChanged(); notifyObservers(ADMIN_STATE); logger.debug("StateManagement: lock() operation completed, resourceName = " + this.resourceName); } catch(Exception ex) { + logger.error("StateManagement.lock() caught unexpected exception: " + ex); + ex.printStackTrace(); synchronized(FLUSHLOCK){ if(et.isActive()){ - et.commit(); + et.rollback(); } } - ex.printStackTrace(); - logger.error("StateManagement.lock() caught unexpected exception: " + ex); throw new Exception("StateManagement.lock() Exception: " + ex.toString()); } } @@ -287,23 +276,20 @@ public class StateManagement extends Observable { em.persist(sm); synchronized(FLUSHLOCK){ - em.flush(); - if(et.isActive()){ - et.commit(); - } + et.commit(); } setChanged(); notifyObservers(ADMIN_STATE); logger.debug("StateManagement: unlock() operation completed, resourceName = " + this.resourceName); } catch(Exception ex) { + logger.error("StateManagement.unlock() caught unexpected exception: " + ex); + ex.printStackTrace(); synchronized(FLUSHLOCK){ if(et.isActive()){ - et.commit(); + et.rollback(); } } - ex.printStackTrace(); - logger.error("StateManagement.unlock() caught unexpected exception: " + ex); throw new Exception("StateManagement.unlock() Exception: " + ex); } } @@ -338,23 +324,20 @@ public class StateManagement extends Observable { em.persist(sm); synchronized(FLUSHLOCK){ - em.flush(); - if(et.isActive()){ - et.commit(); - } + et.commit(); } setChanged(); notifyObservers(OPERATION_STATE); logger.debug("StateManagement enableNotFailed() operation completed, resourceName = " + this.resourceName); } catch(Exception ex) { + logger.error("StateManagement.enableNotFailed() caught unexpected exception: " + ex); + ex.printStackTrace(); synchronized(FLUSHLOCK){ if(et.isActive()){ - et.commit(); + et.rollback(); } } - ex.printStackTrace(); - logger.error("StateManagement.enableNotFailed() caught unexpected exception: " + ex); throw new Exception("StateManagement.enableNotFailed() Exception: " + ex); } } @@ -387,23 +370,20 @@ public class StateManagement extends Observable { em.persist(sm); synchronized(FLUSHLOCK){ - em.flush(); - if(et.isActive()){ - et.commit(); - } + et.commit(); } setChanged(); notifyObservers(OPERATION_STATE); logger.debug("StateManagement: disableFailed() operation completed, resourceName = " + this.resourceName); } catch(Exception ex) { + logger.error("StateManagement.disableFailed() caught unexpected exception: " + ex); + ex.printStackTrace(); synchronized(FLUSHLOCK){ if(et.isActive()){ - et.commit(); + et.rollback(); } } - ex.printStackTrace(); - logger.error("StateManagement.disableFailed() caught unexpected exception: " + ex); throw new Exception("StateManagement.disableFailed() Exception: " + ex); } } @@ -442,10 +422,7 @@ public class StateManagement extends Observable { em.persist(sm); synchronized(FLUSHLOCK){ - em.flush(); - if(et.isActive()){ - et.commit(); - } + et.commit(); } setChanged(); notifyObservers(OPERATION_STATE); @@ -453,13 +430,13 @@ public class StateManagement extends Observable { logger.debug("StateManagement: disableFailed(otherResourceName) operation completed, resourceName = " + otherResourceName); } catch(Exception ex) { + logger.error("StateManagement.disableFailed(otherResourceName) caught unexpected exception: " + ex); + ex.printStackTrace(); synchronized(FLUSHLOCK){ if(et.isActive()){ - et.commit(); + et.rollback(); } } - ex.printStackTrace(); - logger.error("StateManagement.disableFailed(otherResourceName) caught unexpected exception: " + ex); throw new Exception("StateManagement.disableFailed(otherResourceName) Exception: " + ex); } } @@ -493,23 +470,20 @@ public class StateManagement extends Observable { em.persist(sm); synchronized(FLUSHLOCK){ - em.flush(); - if(et.isActive()){ - et.commit(); - } + et.commit(); } setChanged(); notifyObservers(OPERATION_STATE); logger.debug("StateManagement: disableDependency() operation completed, resourceName = " + this.resourceName); } catch(Exception ex) { + logger.error("StateManagement.disableDependency() caught unexpected exception: " + ex); + ex.printStackTrace(); synchronized(FLUSHLOCK){ if(et.isActive()){ - et.commit(); + et.rollback(); } } - ex.printStackTrace(); - logger.error("StateManagement.disableDependency() caught unexpected exception: " + ex); throw new Exception("StateManagement.disableDependency() Exception: " + ex); } } @@ -544,23 +518,20 @@ public class StateManagement extends Observable { em.persist(sm); synchronized(FLUSHLOCK){ - em.flush(); - if(et.isActive()){ - et.commit(); - } + et.commit(); } setChanged(); notifyObservers(OPERATION_STATE); logger.debug("StateManagement: enableNoDependency() operation completed, resourceName = " + this.resourceName); } catch(Exception ex) { + logger.error("StateManagement.enableNoDependency() caught unexpected exception: " + ex); + ex.printStackTrace(); synchronized(FLUSHLOCK){ if(et.isActive()){ - et.commit(); + et.rollback(); } } - ex.printStackTrace(); - logger.error("StateManagement.enableNoDependency() caught unexpected exception: " + ex); throw new Exception("StateManagement.enableNoDependency() Exception: " + ex); } } @@ -597,7 +568,6 @@ public class StateManagement extends Observable { em.persist(sm); synchronized(FLUSHLOCK){ - em.flush(); if(et.isActive()){ et.commit(); } @@ -605,13 +575,13 @@ public class StateManagement extends Observable { setChanged(); notifyObservers(STANDBY_STATUS); }catch(Exception ex){ + logger.error("StateManagement.promote() caught unexpected exception: " + ex); + ex.printStackTrace(); synchronized(FLUSHLOCK){ if(et.isActive()){ - et.commit(); + et.rollback(); } } - ex.printStackTrace(); - logger.error("StateManagement.promote() caught unexpected exception: " + ex); throw new Exception("StateManagement.promote() Exception: " + ex); } @@ -651,23 +621,20 @@ public class StateManagement extends Observable { em.persist(sm); synchronized(FLUSHLOCK){ - em.flush(); - if(et.isActive()){ - et.commit(); - } + et.commit(); } setChanged(); notifyObservers(STANDBY_STATUS); logger.debug("StateManagement: demote() operation completed, resourceName = " + this.resourceName); } catch(Exception ex) { + logger.error("StateManagement.demote() caught unexpected exception: " + ex); + ex.printStackTrace(); synchronized(FLUSHLOCK){ if(et.isActive()){ - et.commit(); + et.rollback(); } } - ex.printStackTrace(); - logger.error("StateManagement.demote() caught unexpected exception: " + ex); throw new Exception("StateManagement.demote() Exception: " + ex); } } @@ -710,22 +677,19 @@ public class StateManagement extends Observable { em.persist(sm); synchronized(FLUSHLOCK){ - em.flush(); - if(et.isActive()){ - et.commit(); - } + et.commit(); } //We don't notify observers because this is assumed to be a remote resource logger.debug("StateManagement: demote(otherResourceName) operation completed, resourceName = " + otherResourceName); } catch(Exception ex) { + logger.error("StateManagement.demote(otherResourceName) caught unexpected exception: " + ex); + ex.printStackTrace(); synchronized(FLUSHLOCK){ if(et.isActive()){ - et.commit(); + et.rollback(); } } - ex.printStackTrace(); - logger.error("StateManagement.demote(otherResourceName) caught unexpected exception: " + ex); throw new Exception("StateManagement.demote(otherResourceName) Exception: " + ex); } } @@ -914,6 +878,7 @@ public String getOpState() String standbyStatus = null; + // The transaction is required for the LockModeType EntityTransaction et = em.getTransaction(); if(!et.isActive()){ et.begin(); @@ -940,17 +905,19 @@ public String getOpState() logger.error("getStandbyStatus: resourceName =" + otherResourceName + " not found in statemanagemententity table"); } + synchronized(FLUSHLOCK){ + et.commit(); + } } catch (Exception e) { - e.printStackTrace(); logger.error("getStandbyStatus: Caught Exception attempting to get statemanagemententity record, message='" + e.getMessage() + "'"); - } - synchronized(FLUSHLOCK){ - if(et.isActive()){ - et.commit(); + e.printStackTrace(); + synchronized(FLUSHLOCK){ + if(et.isActive()){ + et.rollback(); + } } } - if (logger.isDebugEnabled()) { logger.debug("getStandbyStatus: Returning standbyStatus=" + standbyStatus); @@ -989,27 +956,21 @@ public String getOpState() + stateManagementEntity.getStandbyStatus()); em.remove(stateManagementEntity); } + synchronized(FLUSHLOCK){ + et.commit(); + } }catch(Exception ex){ + logger.error("StateManagement.deleteAllStateManagementEntities() caught Exception: " + ex); + ex.printStackTrace(); synchronized(FLUSHLOCK){ if(et.isActive()){ - et.commit(); + et.rollback(); } } - ex.printStackTrace(); - logger.error("StateManagement.deleteAllStateManagementEntities() caught Exception: " + ex); } - - /* - * End transaction. - */ - synchronized(FLUSHLOCK){ - if(et.isActive()){ - et.commit(); - } + if(logger.isDebugEnabled()){ + logger.info("deleteAllStateManagementEntities: Exiting"); } - - logger.info("deleteAllStateManagementEntities: Exiting"); - } } |