From: <cl...@hy...> - 2008-10-30 23:30:18
|
Author: clee Date: 2008-10-30 16:30:12 -0700 (Thu, 30 Oct 2008) New Revision: 11659 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=11659 Modified: trunk/src/org/hyperic/hq/events/server/session/ActionDAO.java trunk/src/org/hyperic/hq/events/server/session/AlertConditionDAO.java trunk/src/org/hyperic/hq/events/server/session/AlertDAO.java trunk/src/org/hyperic/hq/events/server/session/AlertDefinitionDAO.java trunk/src/org/hyperic/hq/events/server/session/AlertDefinitionManagerEJBImpl.java Log: Delete orphaned alert definitions correctly (from deleted resources) Modified: trunk/src/org/hyperic/hq/events/server/session/ActionDAO.java =================================================================== --- trunk/src/org/hyperic/hq/events/server/session/ActionDAO.java 2008-10-30 23:05:55 UTC (rev 11658) +++ trunk/src/org/hyperic/hq/events/server/session/ActionDAO.java 2008-10-30 23:30:12 UTC (rev 11659) @@ -55,11 +55,7 @@ private void removeActionCascade(Action action) { if (action.getParent() != null) { action.getParent().getChildrenBag().remove(action); - } - - for (Iterator it = action.getLogEntries().iterator(); it.hasNext();) { - remove(it.next()); - } + } remove(action); } @@ -75,7 +71,6 @@ if (action.getAlertDefinition() != null) { action.getAlertDefinition().getActionsBag().remove(action); } - removeActionCascade(action); } Modified: trunk/src/org/hyperic/hq/events/server/session/AlertConditionDAO.java =================================================================== --- trunk/src/org/hyperic/hq/events/server/session/AlertConditionDAO.java 2008-10-30 23:05:55 UTC (rev 11658) +++ trunk/src/org/hyperic/hq/events/server/session/AlertConditionDAO.java 2008-10-30 23:30:12 UTC (rev 11659) @@ -41,11 +41,4 @@ void save(AlertCondition cond) { super.save(cond); } - - void removeConditions(AlertDefinition def) { - for (Iterator it = def.getConditions().iterator(); it.hasNext(); ) { - remove(it.next()); - } - def.clearConditions(); - } } Modified: trunk/src/org/hyperic/hq/events/server/session/AlertDAO.java =================================================================== --- trunk/src/org/hyperic/hq/events/server/session/AlertDAO.java 2008-10-30 23:05:55 UTC (rev 11658) +++ trunk/src/org/hyperic/hq/events/server/session/AlertDAO.java 2008-10-30 23:30:12 UTC (rev 11659) @@ -221,7 +221,7 @@ } int deleteByAlertDefinition(AlertDefinition def) { - String sql = "DELETE Alert WHERE alertDefinition = :alertDef"; + String sql = "DELETE FROM Alert WHERE alertDefinition = :alertDef"; return getSession().createQuery(sql) .setParameter("alertDef", def) Modified: trunk/src/org/hyperic/hq/events/server/session/AlertDefinitionDAO.java =================================================================== --- trunk/src/org/hyperic/hq/events/server/session/AlertDefinitionDAO.java 2008-10-30 23:05:55 UTC (rev 11658) +++ trunk/src/org/hyperic/hq/events/server/session/AlertDefinitionDAO.java 2008-10-30 23:30:12 UTC (rev 11659) @@ -78,6 +78,13 @@ return createCriteria().add(Restrictions.eq("resource", r)).list(); } + public List findAllDeletedResources() { + return createCriteria() + .add(Restrictions.isNull("resource")) + .add(Restrictions.eq("deleted", Boolean.TRUE)) + .list(); + } + /** * Find the alert def for a given appdef entity and is child of the parent * alert def passed in @@ -186,8 +193,7 @@ public List findByRootResource(AuthzSubject subject, Resource r) { EdgePermCheck wherePermCheck = getPermissionManager().makePermCheckHql("rez"); - String hql = "select ad from AlertDefinition ad " + - "join ad.resource rez " + + String hql = "select ad from AlertDefinition ad join ad.resource rez " + wherePermCheck; Query q = createQuery(hql); @@ -223,52 +229,40 @@ void setAlertDefinitionValue(AlertDefinition def, AlertDefinitionValue val) { AlertConditionDAO cDAO = - DAOFactory.getDAOFactory().getAlertConditionDAO(); - ActionDAO actDAO = DAOFactory.getDAOFactory().getActionDAO(); - TriggerDAO tDAO = DAOFactory.getDAOFactory().getTriggerDAO(); + new AlertConditionDAO(DAOFactory.getDAOFactory()); + ActionDAO actDAO = new ActionDAO(DAOFactory.getDAOFactory()); + TriggerDAO tDAO = new TriggerDAO(DAOFactory.getDAOFactory()); setAlertDefinitionValueNoRels(def, val); for (Iterator i=val.getAddedTriggers().iterator(); i.hasNext(); ) { - RegisteredTriggerValue tVal = (RegisteredTriggerValue)i.next(); - RegisteredTrigger t = tDAO.findById(tVal.getId()); - - def.addTrigger(t); + RegisteredTriggerValue tVal = (RegisteredTriggerValue) i.next(); + def.addTrigger(tDAO.findById(tVal.getId())); } for (Iterator i=val.getRemovedTriggers().iterator(); i.hasNext(); ) { RegisteredTriggerValue tVal = (RegisteredTriggerValue)i.next(); - RegisteredTrigger t = tDAO.findById(tVal.getId()); - - def.removeTrigger(t); + def.removeTrigger(tDAO.findById(tVal.getId())); } for (Iterator i=val.getAddedConditions().iterator(); i.hasNext(); ) { AlertConditionValue cVal = (AlertConditionValue)i.next(); - AlertCondition c = cDAO.findById(cVal.getId()); - - def.addCondition(c); + def.addCondition(cDAO.findById(cVal.getId())); } for (Iterator i=val.getRemovedConditions().iterator(); i.hasNext(); ) { AlertConditionValue cVal = (AlertConditionValue)i.next(); - AlertCondition c = cDAO.findById(cVal.getId()); - - def.removeCondition(c); + def.removeCondition(cDAO.findById(cVal.getId())); } for (Iterator i=val.getAddedActions().iterator(); i.hasNext(); ) { ActionValue aVal = (ActionValue)i.next(); - Action a = actDAO.findById(aVal.getId()); - - def.addAction(a); + def.addAction(actDAO.findById(aVal.getId())); } for (Iterator i=val.getRemovedActions().iterator(); i.hasNext(); ) { ActionValue aVal = (ActionValue)i.next(); - Action a = actDAO.findById(aVal.getId()); - - def.removeAction(a); + def.removeAction(actDAO.findById(aVal.getId())); } } Modified: trunk/src/org/hyperic/hq/events/server/session/AlertDefinitionManagerEJBImpl.java =================================================================== --- trunk/src/org/hyperic/hq/events/server/session/AlertDefinitionManagerEJBImpl.java 2008-10-30 23:05:55 UTC (rev 11658) +++ trunk/src/org/hyperic/hq/events/server/session/AlertDefinitionManagerEJBImpl.java 2008-10-30 23:30:12 UTC (rev 11659) @@ -607,6 +607,7 @@ for (Iterator i = adefs.iterator(); i.hasNext(); ) { AlertDefinition alertdef = (AlertDefinition) i.next(); alertdef.setResource(null); + alertdef.setDeleted(true); } aDao.getSession().flush(); } @@ -618,32 +619,42 @@ public void cleanupAlertDefinitions(AppdefEntityID aeid) { StopWatch watch = new StopWatch(); - AlertDefinitionDAO aDao = getAlertDefDAO(); - Resource res = findResource(aeid); - List adefs = aDao.findAllByResource(res); - - for (Iterator i = adefs.iterator(); i.hasNext(); ) { + final AlertDefinitionDAO aDao = getAlertDefDAO(); + final AlertDAO dao = getAlertDAO(); + final ActionDAO actionDAO = getActionDAO(); + + List adefs = aDao.findAllDeletedResources(); + for (Iterator i = adefs.iterator(); i.hasNext();) { AlertDefinition alertdef = (AlertDefinition) i.next(); - AlertDAO dao = getAlertDAO(); // Delete the alerts watch.markTimeBegin("deleteByAlertDefinition"); dao.deleteByAlertDefinition(alertdef); watch.markTimeEnd("deleteByAlertDefinition"); + // Get the alerts deleted + dao.getSession().flush(); + // Remove the conditions - watch.markTimeBegin("removeConditions"); - getConditionDAO().removeConditions(alertdef); - watch.markTimeEnd("deleteByAlertDefinition"); + watch.markTimeBegin("remove conditions and triggers"); + alertdef.clearConditions(); + alertdef.getTriggersBag().clear(); + watch.markTimeEnd("remove conditions and triggers"); // Remove the actions watch.markTimeBegin("removeActions"); - getActionDAO().removeActions(alertdef); + actionDAO.removeActions(alertdef); watch.markTimeEnd("removeActions"); + watch.markTimeBegin("remove from parent"); + if (alertdef.getParent() != null) { + alertdef.getParent().getChildrenBag().remove(alertdef); + } + watch.markTimeBegin("remove from parent"); + // Actually remove the definition watch.markTimeBegin("remove"); - getAlertDefDAO().remove(alertdef); + aDao.remove(alertdef); watch.markTimeBegin("remove"); if (log.isDebugEnabled()) { |