From: <sc...@hy...> - 2009-12-07 02:33:02
|
Author: scottmf Date: 2009-12-06 18:32:49 -0800 (Sun, 06 Dec 2009) New Revision: 14035 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=14035 Modified: trunk/src/org/hyperic/hq/measurement/server/session/ReportProcessorEJBImpl.java Log: [HHQ-3588] added timings. fixed potential for NPEs when resource is in async delete mode. Modified: trunk/src/org/hyperic/hq/measurement/server/session/ReportProcessorEJBImpl.java =================================================================== --- trunk/src/org/hyperic/hq/measurement/server/session/ReportProcessorEJBImpl.java 2009-12-07 02:30:30 UTC (rev 14034) +++ trunk/src/org/hyperic/hq/measurement/server/session/ReportProcessorEJBImpl.java 2009-12-07 02:32:49 UTC (rev 14035) @@ -35,8 +35,12 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.hyperic.hq.appdef.Agent; +import org.hyperic.hq.appdef.server.session.Platform; import org.hyperic.hq.appdef.server.session.PlatformManagerEJBImpl; +import org.hyperic.hq.appdef.server.session.Server; import org.hyperic.hq.appdef.server.session.ServerManagerEJBImpl; +import org.hyperic.hq.appdef.server.session.Service; import org.hyperic.hq.appdef.server.session.ServiceManagerEJBImpl; import org.hyperic.hq.appdef.shared.AppdefEntityID; import org.hyperic.hq.appdef.shared.PlatformNotFoundException; @@ -57,6 +61,7 @@ import org.hyperic.hq.measurement.shared.SRNManagerLocal; import org.hyperic.hq.product.MetricValue; import org.hyperic.util.StringUtil; +import org.hyperic.util.timer.StopWatch; /** * @ejb:bean name="ReportProcessor" @@ -80,6 +85,7 @@ MetricValue[] vals) { final boolean debug = _log.isDebugEnabled(); + final StopWatch watch = new StopWatch(); for (int i=0; i<vals.length; i++) { final long now = @@ -94,27 +100,33 @@ } else { points.add(pt); } + if (debug) watch.markTimeBegin("getTemplate"); if (debug && m.getTemplate().isAvailability()) { _log.debug("availability -> " + pt); } + if (debug) watch.markTimeEnd("getTemplate"); } catch(NumberFormatException e) { _log.warn("Unable to insert: " + e.getMessage() + ", metric id=" + m); } } + if (debug) _log.debug(watch); } - private boolean isPriority(long timestamp, long metricTimestamp) { + private final boolean isPriority(long timestamp, long metricTimestamp) { if (metricTimestamp >= (timestamp-PRIORITY_OFFSET)) { return true; } return false; } - private void addData(List points, List priorityPts, Measurement m, - MetricValue[] dpts) - { + private final void addData(List points, List priorityPts, Measurement m, + MetricValue[] dpts) { + final boolean debug = _log.isDebugEnabled(); + StopWatch watch = new StopWatch(); + if (debug) watch.markTimeBegin("getInterval"); long interval = m.getInterval(); + if (debug) watch.markTimeEnd("getInterval"); // Safeguard against an anomaly if (interval <= 0) { @@ -126,18 +138,25 @@ // values for that cycle. MetricValue[] passThroughs = new MetricValue[dpts.length]; - for (int i = 0; i < dpts.length; i++) - { + for (int i = 0; i < dpts.length; i++) { // Save data point to DB. + if (debug) watch.markTimeBegin("getTimestamp"); long retrieval = dpts[i].getTimestamp(); + if (debug) watch.markTimeEnd("getTimestamp"); + if (debug) watch.markTimeBegin("roundDownTime"); long adjust = TimingVoodoo.roundDownTime(retrieval, interval); + if (debug) watch.markTimeEnd("roundDownTime"); // Create new Measurement data point with the adjusted time - MetricValue modified = new MetricValue(dpts[i].getValue(), - adjust); + if (debug) watch.markTimeBegin("new MetricValue"); + MetricValue modified = new MetricValue(dpts[i].getValue(), adjust); + if (debug) watch.markTimeEnd("new MetricValue"); passThroughs[i] = modified; } + if (debug) watch.markTimeBegin("addPoint"); addPoint(points, priorityPts, m, passThroughs); + if (debug) watch.markTimeEnd("addPoint"); + if (debug) _log.debug(watch); } /** @@ -159,9 +178,12 @@ final MeasurementManagerLocal mMan = MeasurementManagerEJBImpl.getOne(); final boolean debug = _log.isDebugEnabled(); + final StopWatch watch = new StopWatch(); for (int i = 0; i < dsnLists.length; i++) { Integer dmId = new Integer(dsnLists[i].getClientId()); + if (debug) watch.markTimeBegin("getMeasurement"); Measurement m = mMan.getMeasurement(dmId); + if (debug) watch.markTimeEnd("getMeasurement"); // Can't do much if we can't look up the derived measurement // If the measurement is enabled, we just throw away their data @@ -173,7 +195,9 @@ continue; } // Need to check if resource was asynchronously deleted (type == null) + if (debug) watch.markTimeBegin("getResource"); final Resource res = m.getResource(); + if (debug) watch.markTimeEnd("getResource"); if (res == null || res.isInAsyncDeleteState()) { if (debug) { _log.debug("dropping metricId=" + m.getId() + @@ -181,16 +205,20 @@ } continue; } + if (debug) watch.markTimeBegin("resMatchesAgent"); if (!resourceMatchesAgent(res, agentToken)) { _log.warn("measurement (id=" + m.getId() + ") was sent to the " + "HQ server from agent (agentToken=" + agentToken + ")" + " but resource (id=" + res.getId() + ") is not associated " + " with that agent. Dropping measurement."); + if (debug) watch.markTimeEnd("resMatchesAgent"); continue; } + if (debug) watch.markTimeEnd("resMatchesAgent"); final boolean isAvail = m.getTemplate().isAvailability(); final ValueList[] valLists = dsnLists[i].getDsns(); + if (debug) watch.markTimeBegin("addData"); for (int j = 0; j < valLists.length; j++) { final MetricValue[] vals = valLists[j].getValues(); if (isAvail) { @@ -199,25 +227,35 @@ addData(dataPoints, null, m, vals); } } + if (debug) watch.markTimeEnd("addData"); } + if (debug) _log.debug(watch); DataInserter d = MeasurementStartupListener.getDataInserter(); + if (debug) watch.markTimeBegin("sendMetricDataToDB"); sendMetricDataToDB(d, dataPoints, false); + if (debug) watch.markTimeEnd("sendMetricDataToDB"); DataInserter a = MeasurementStartupListener.getAvailDataInserter(); + if (debug) watch.markTimeBegin("sendAvailDataToDB"); sendMetricDataToDB(a, availPoints, false); sendMetricDataToDB(a, priorityAvailPts, true); + if (debug) watch.markTimeEnd("sendAvailDataToDB"); // Check the SRNs to make sure the agent is up-to-date SRNManagerLocal srnManager = getSRNManager(); + if (debug) watch.markTimeBegin("reportAgentSRNs"); Collection nonEntities = srnManager.reportAgentSRNs(report.getSRNList()); + if (debug) watch.markTimeEnd("reportAgentSRNs"); if (report.getAgentToken() != null && nonEntities.size() > 0) { // Better tell the agent to stop reporting non-existent entities AppdefEntityID[] entIds = (AppdefEntityID[]) nonEntities.toArray(new AppdefEntityID[nonEntities.size()]); try { + if (debug) watch.markTimeBegin("unschedule"); MeasurementProcessorEJBImpl.getOne().unschedule( report.getAgentToken(), entIds); + if (debug) watch.markTimeEnd("unschedule"); } catch (MeasurementUnscheduleException e) { _log.error("Cannot unschedule entities: " + StringUtil.arrayToString(entIds)); @@ -229,21 +267,72 @@ * checks if the agentToken matches resource's agentToken */ private boolean resourceMatchesAgent(Resource resource, String agentToken) { + if (resource == null || resource.isInAsyncDeleteState()) { + return false; + } final Integer resType = resource.getResourceType().getId(); final Integer aeid = resource.getInstanceId(); try { if (resType.equals(AuthzConstants.authzPlatform)) { - String token = PlatformManagerEJBImpl.getOne().findPlatformById( - aeid).getAgent().getAgentToken(); - return token.equals(agentToken); + Platform p = + PlatformManagerEJBImpl.getOne().findPlatformById(aeid); + Resource r = p.getResource(); + if (r == null || r.isInAsyncDeleteState()) { + return false; + } + Agent a = p.getAgent(); + if (a == null) { + return false; + } + return a.getAgentToken().equals(agentToken); } else if (resType.equals(AuthzConstants.authzServer)) { - String token = ServerManagerEJBImpl.getOne().findServerById( - aeid).getPlatform().getAgent().getAgentToken(); - return token.equals(agentToken); + Server server = + ServerManagerEJBImpl.getOne().findServerById(aeid); + Resource r = server.getResource(); + if (r == null || r.isInAsyncDeleteState()) { + return false; + } + Platform p = server.getPlatform(); + if (p == null) { + return false; + } + r = p.getResource(); + if (r == null || r.isInAsyncDeleteState()) { + return false; + } + Agent a = p.getAgent(); + if (a == null) { + return false; + } + return a.getAgentToken().equals(agentToken); } else if (resType.equals(AuthzConstants.authzService)) { - String token = ServiceManagerEJBImpl.getOne().findServiceById( - aeid).getServer().getPlatform().getAgent().getAgentToken(); - return token.equals(agentToken); + Service service = + ServiceManagerEJBImpl.getOne().findServiceById(aeid); + Resource r = service.getResource(); + if (r == null || r.isInAsyncDeleteState()) { + return false; + } + Server server = service.getServer(); + if (server == null) { + return false; + } + r = server.getResource(); + if (r == null || r.isInAsyncDeleteState()) { + return false; + } + Platform p = server.getPlatform(); + if (p == null) { + return false; + } + r = p.getResource(); + if (r == null || r.isInAsyncDeleteState()) { + return false; + } + Agent a = p.getAgent(); + if (a == null) { + return false; + } + return a.getAgentToken().equals(agentToken); } } catch (PlatformNotFoundException e) { _log.warn("Platform not found Id=" + aeid); |