return dao.findLatestRawMetric(scheduleId);
}
public Iterable<MeasurementDataNumericHighLowComposite> findDataForResource(int scheduleId, long beginTime,
long endTime, int numberOfBuckets) {
Stopwatch stopwatch = new Stopwatch().start();
try {
DateTime begin = new DateTime(beginTime);
if (dateTimeService.isInRawDataRange(begin)) {
Iterable<RawNumericMetric> metrics = dao.findRawMetrics(scheduleId, beginTime, endTime);
return createRawComposites(metrics, beginTime, endTime, numberOfBuckets);
}
List<AggregateNumericMetric> metrics = null;
if (dateTimeService.isIn1HourDataRange(begin)) {
metrics = dao.findAggregateMetrics(scheduleId, Bucket.ONE_HOUR, beginTime,
endTime);
return createComposites(metrics, beginTime, endTime, numberOfBuckets);
} else if (dateTimeService.isIn6HourDataRange(begin)) {
metrics = dao.findAggregateMetrics(scheduleId, Bucket.SIX_HOUR, beginTime, endTime);
return createComposites(metrics, beginTime, endTime, numberOfBuckets);
} else if (dateTimeService.isIn24HourDataRange(begin)) {
metrics = dao.findAggregateMetrics(scheduleId, Bucket.TWENTY_FOUR_HOUR, beginTime, endTime);
return createComposites(metrics, beginTime, endTime, numberOfBuckets);
} else {
throw new IllegalArgumentException("beginTime[" + beginTime + "] is outside the accepted range.");
}
} finally {
stopwatch.stop();
if (log.isDebugEnabled()) {
log.debug("Finished calculating resource summary aggregate in " +
stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms");
}
}
}