From: <sc...@hy...> - 2008-12-09 05:44:31
|
Author: scottmf Date: 2008-12-08 21:44:25 -0800 (Mon, 08 Dec 2008) New Revision: 12001 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=12001 Modified: trunk/src/org/hyperic/hq/measurement/server/session/DataInserter.java trunk/src/org/hyperic/hq/measurement/server/session/ReportProcessorEJBImpl.java trunk/src/org/hyperic/hq/measurement/server/session/SynchronousAvailDataInserter.java trunk/src/org/hyperic/hq/measurement/server/session/SynchronousDataInserter.java Log: [HHQ-2695] (reviewed by clee) Changed DataInserters to accept a prioritized list. Changed ReportProcessor to use a priority when availability is within 3 mins of the current timestamp Modified: trunk/src/org/hyperic/hq/measurement/server/session/DataInserter.java =================================================================== --- trunk/src/org/hyperic/hq/measurement/server/session/DataInserter.java 2008-12-09 05:30:46 UTC (rev 12000) +++ trunk/src/org/hyperic/hq/measurement/server/session/DataInserter.java 2008-12-09 05:44:25 UTC (rev 12001) @@ -41,5 +41,17 @@ public void insertMetrics(List metricData) throws InterruptedException, DataInserterException; + /** + * Insert priority data into the DB, possibly blocking. This may or may not + * be implemented by the inherited class. + * + * @param metricData a list of {@link DataPoint}s + * @param isPriority tells the inserter to prioritize the metricData List. + * When implemented the DataInserter will give will insert the priority + * data before the low priority data. + */ + public void insertMetrics(List metricData, boolean isPriority) + throws InterruptedException, DataInserterException; + public Object getLock(); } Modified: trunk/src/org/hyperic/hq/measurement/server/session/ReportProcessorEJBImpl.java =================================================================== --- trunk/src/org/hyperic/hq/measurement/server/session/ReportProcessorEJBImpl.java 2008-12-09 05:30:46 UTC (rev 12000) +++ trunk/src/org/hyperic/hq/measurement/server/session/ReportProcessorEJBImpl.java 2008-12-09 05:44:25 UTC (rev 12001) @@ -38,6 +38,7 @@ import org.apache.commons.logging.LogFactory; import org.hyperic.hq.appdef.shared.AppdefEntityID; import org.hyperic.hq.common.SystemException; +import org.hyperic.hq.measurement.MeasurementConstants; import org.hyperic.hq.measurement.MeasurementUnscheduleException; import org.hyperic.hq.measurement.TimingVoodoo; import org.hyperic.hq.measurement.data.DSNList; @@ -70,18 +71,27 @@ MeasurementManagerEJBImpl.getOne(); private final MeasurementProcessorLocal _measurementProc = MeasurementProcessorEJBImpl.getOne(); + private final long MINUTE = MeasurementConstants.MINUTE; + private final long PRIORITY_OFFSET = MINUTE*3; - private void addPoint(List points, Measurement m, MetricValue[] vals) + private void addPoint(List points, List priorityPts, Measurement m, + MetricValue[] vals) { final boolean debug = _log.isDebugEnabled(); for (int i=0; i<vals.length; i++) { + long now = System.currentTimeMillis(); + now = TimingVoodoo.roundDownTime(now, MINUTE); try { //this is just to check if the metricvalue is valid //will throw a NumberFormatException if there is a problem new BigDecimal(vals[i].getValue()); DataPoint pt = new DataPoint(m.getId(), vals[i]); - points.add(pt); + if (priorityPts != null && isPriority(now, pt.getTimestamp())) { + priorityPts.add(pt); + } else { + points.add(pt); + } if (debug && m.getTemplate().isAvailability()) { _log.debug("availability -> " + pt); } @@ -91,9 +101,16 @@ } } } - - private void addData(List points, Measurement m, int dsnId, - MetricValue[] dpts) + + private boolean isPriority(long timestamp, long metricTimestamp) { + if (metricTimestamp >= (timestamp-PRIORITY_OFFSET)) { + return true; + } + return false; + } + + private void addData(List points, List priorityPts, Measurement m, + int dsnId, MetricValue[] dpts) { long interval = m.getInterval(); @@ -118,7 +135,7 @@ adjust); passThroughs[i] = modified; } - addPoint(points, m, passThroughs); + addPoint(points, priorityPts, m, passThroughs); } /** @@ -135,6 +152,7 @@ List dataPoints = new ArrayList(dsnLists.length); List availPoints = new ArrayList(dsnLists.length); + List priorityAvailPts = new ArrayList(dsnLists.length); for (int i = 0; i < dsnLists.length; i++) { Integer dmId = new Integer(dsnLists[i].getClientId()); @@ -156,17 +174,18 @@ MetricValue[] vals = valLists[j].getValues(); if (isAvail) { - addData(availPoints, m, dsnId, vals); + addData(availPoints, priorityAvailPts, m, dsnId, vals); } else { - addData(dataPoints, m, dsnId, vals); + addData(dataPoints, null, m, dsnId, vals); } } } DataInserter d = MeasurementStartupListener.getDataInserter(); - sendMetricDataToDB(d, dataPoints); + sendMetricDataToDB(d, dataPoints, false); DataInserter a = MeasurementStartupListener.getAvailDataInserter(); - sendMetricDataToDB(a, availPoints); + sendMetricDataToDB(a, availPoints, false); + sendMetricDataToDB(a, priorityAvailPts, true); // Check the SRNs to make sure the agent is up-to-date SRNManagerLocal srnManager = getSRNManager(); @@ -188,11 +207,15 @@ /** * Sends the actual data to the DB. */ - private void sendMetricDataToDB(DataInserter d, List dataPoints) + private void sendMetricDataToDB(DataInserter d, List dataPoints, + boolean isPriority) throws DataInserterException { + if (dataPoints.size() <= 0) { + return; + } try { - d.insertMetrics(dataPoints); + d.insertMetrics(dataPoints, isPriority); int size = dataPoints.size(); long ts = System.currentTimeMillis(); ReportStatsCollector.getInstance().getCollector().add(size, ts); Modified: trunk/src/org/hyperic/hq/measurement/server/session/SynchronousAvailDataInserter.java =================================================================== --- trunk/src/org/hyperic/hq/measurement/server/session/SynchronousAvailDataInserter.java 2008-12-09 05:30:46 UTC (rev 12000) +++ trunk/src/org/hyperic/hq/measurement/server/session/SynchronousAvailDataInserter.java 2008-12-09 05:44:25 UTC (rev 12001) @@ -49,4 +49,9 @@ return _lock; } + public void insertMetrics(List metricData, boolean isPriority) + throws InterruptedException, DataInserterException { + insertMetrics(metricData); + } + } Modified: trunk/src/org/hyperic/hq/measurement/server/session/SynchronousDataInserter.java =================================================================== --- trunk/src/org/hyperic/hq/measurement/server/session/SynchronousDataInserter.java 2008-12-09 05:30:46 UTC (rev 12000) +++ trunk/src/org/hyperic/hq/measurement/server/session/SynchronousDataInserter.java 2008-12-09 05:44:25 UTC (rev 12001) @@ -47,4 +47,9 @@ public Object getLock() { return _lock; } + + public void insertMetrics(List metricData, boolean isPriority) + throws InterruptedException, DataInserterException { + insertMetrics(metricData); + } } |