From: <sc...@hy...> - 2009-12-02 00:40:26
|
Author: scottmf Date: 2009-12-01 16:40:12 -0800 (Tue, 01 Dec 2009) New Revision: 14018 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=14018 Modified: branches/HQ_4_2_0_PATCH/src/org/hyperic/hq/bizapp/server/session/EventsBossEJBImpl.java branches/HQ_4_2_0_PATCH/src/org/hyperic/hq/events/server/session/AlertDefinitionManagerEJBImpl.java Log: [HHQ-3534] reworked code so that the entireCleanup is not called per appdefId, instead it is called once. Also batched it up to avoid potential timeout issues Modified: branches/HQ_4_2_0_PATCH/src/org/hyperic/hq/bizapp/server/session/EventsBossEJBImpl.java =================================================================== --- branches/HQ_4_2_0_PATCH/src/org/hyperic/hq/bizapp/server/session/EventsBossEJBImpl.java 2009-12-02 00:27:18 UTC (rev 14017) +++ branches/HQ_4_2_0_PATCH/src/org/hyperic/hq/bizapp/server/session/EventsBossEJBImpl.java 2009-12-02 00:40:12 UTC (rev 14018) @@ -1724,9 +1724,8 @@ _log.debug("fixPreviousAlerts: alertId = " + alertID + ", previous alerts fixed = " + fixCount + ", time = " + watch); - - return fixCount; } + return fixCount; } /** @@ -1833,16 +1832,30 @@ // are deleted. HashSet events = new HashSet(); events.add (ResourceDeletedZevent.class); - ZeventManager.getInstance().addBufferedListener(events, - new ZeventListener() { + ZeventManager inst = ZeventManager.getInstance(); + inst.addBufferedListener( + events, new ZeventListener() { public void processEvents(List events) { - AlertDefinitionManagerLocal adm = getADM(); - for (Iterator i = events.iterator(); i.hasNext();) { - ResourceZevent z = (ResourceZevent) i.next(); - if (z instanceof ResourceDeletedZevent) { - adm.cleanupAlertDefinitions(z.getAppdefEntityID()); + final StopWatch watch = new StopWatch(); + final Log log = LogFactory.getLog(this.getClass().getName()); + final boolean debug = log.isDebugEnabled(); + final AlertDefinitionManagerLocal adm = getADM(); + final List alertDefs = getADM().getAllDeletedAlertDefs(); + final int batchSize = 1000; + for (int i=0; i<alertDefs.size(); i+=batchSize) { + final int end = Math.min(i+batchSize, alertDefs.size()); + final List sublist = alertDefs.subList(i, end); + // can't pass in pojos since the session changes + final List ids = new ArrayList(sublist.size()); + for (final Iterator it=sublist.iterator(); it.hasNext(); ) { + final AlertDefinition def = (AlertDefinition) it.next(); + ids.add(def.getId()); } + if (debug) watch.markTimeBegin("cleanupAlertDefs"); + adm.cleanupAlertDefs(ids); + if (debug) watch.markTimeEnd("cleanupAlertDefs"); } + if (debug) log.debug(watch); } public String toString() { Modified: branches/HQ_4_2_0_PATCH/src/org/hyperic/hq/events/server/session/AlertDefinitionManagerEJBImpl.java =================================================================== --- branches/HQ_4_2_0_PATCH/src/org/hyperic/hq/events/server/session/AlertDefinitionManagerEJBImpl.java 2009-12-02 00:27:18 UTC (rev 14017) +++ branches/HQ_4_2_0_PATCH/src/org/hyperic/hq/events/server/session/AlertDefinitionManagerEJBImpl.java 2009-12-02 00:40:12 UTC (rev 14018) @@ -67,7 +67,6 @@ import org.hyperic.hq.events.shared.AlertDefinitionValue; import org.hyperic.hq.events.shared.RegisteredTriggerManagerLocal; import org.hyperic.hq.events.shared.RegisteredTriggerValue; -import org.hyperic.hq.measurement.MeasurementConstants; import org.hyperic.hq.measurement.server.session.Measurement; import org.hyperic.hq.measurement.server.session.MeasurementDAO; import org.hyperic.util.config.ConfigResponse; @@ -741,56 +740,59 @@ } aDao.getSession().flush(); } + + /** + * @ejb:interface-method + */ + public List getAllDeletedAlertDefs() { + return getAlertDefDAO().findAllDeletedResources(); + } - /** Clean up alert definitions and alerts for removed resources - * + /** + * @param alertDefIds {@link List} of {@link Integer} of alertDefIds * @ejb:interface-method */ - public void cleanupAlertDefinitions(AppdefEntityID aeid) { - StopWatch watch = new StopWatch(); - + public void cleanupAlertDefs(List alertDefIds) { + if (alertDefIds.size() <= 0) { + return; + } + final StopWatch watch = new StopWatch(); + final boolean debug = log.isDebugEnabled(); + final AlertDAO dao = getAlertDAO(); final AlertDefinitionDAO aDao = getAlertDefDAO(); - final AlertDAO dao = getAlertDAO(); final ActionDAO actionDAO = getActionDAO(); + for (final Iterator i = alertDefIds.iterator(); i.hasNext();) { + final Integer alertdefId = (Integer) i.next(); + final AlertDefinition alertdef = aDao.findById(alertdefId); - List adefs = aDao.findAllDeletedResources(); - for (Iterator i = adefs.iterator(); i.hasNext();) { - AlertDefinition alertdef = (AlertDefinition) i.next(); - // Delete the alerts - watch.markTimeBegin("deleteByAlertDefinition"); + if (debug) watch.markTimeBegin("deleteByAlertDefinition"); dao.deleteByAlertDefinition(alertdef); - watch.markTimeEnd("deleteByAlertDefinition"); + if (debug) watch.markTimeEnd("deleteByAlertDefinition"); - // Get the alerts deleted - dao.getSession().flush(); - // Remove the conditions - watch.markTimeBegin("remove conditions and triggers"); + if (debug) watch.markTimeBegin("remove conditions and triggers"); alertdef.clearConditions(); alertdef.getTriggersBag().clear(); - watch.markTimeEnd("remove conditions and triggers"); + if (debug) watch.markTimeEnd("remove conditions and triggers"); // Remove the actions - watch.markTimeBegin("removeActions"); + if (debug) watch.markTimeBegin("removeActions"); actionDAO.removeActions(alertdef); - watch.markTimeEnd("removeActions"); + if (debug) watch.markTimeEnd("removeActions"); - watch.markTimeBegin("remove from parent"); + if (debug) watch.markTimeBegin("remove from parent"); if (alertdef.getParent() != null) { alertdef.getParent().getChildrenBag().remove(alertdef); } - watch.markTimeBegin("remove from parent"); + if (debug) watch.markTimeEnd("remove from parent"); // Actually remove the definition - watch.markTimeBegin("remove"); + if (debug) watch.markTimeBegin("remove"); aDao.remove(alertdef); - watch.markTimeBegin("remove"); - - if (log.isDebugEnabled()) { - log.debug("deleteAlertDefinition: " + watch); - } + if (debug) watch.markTimeEnd("remove"); } + if (debug) log.debug("deleted " + alertDefIds.size() + " alertDefs: " + watch); } /** Find an alert definition and return a value object |