@Override public Iterator<Row<T>> iterator() { return getRows().iterator(); }
@Override public Results<Sample> select(Context context, Resource resource, Optional<Timestamp> start, Optional<Timestamp> end) { Timer.Context timer = m_sampleSelectTimer.time(); validateSelect(start, end); Timestamp upper = end.isPresent() ? end.get() : Timestamp.now(); Timestamp lower = start.isPresent() ? start.get() : upper.minus(Duration.seconds(86400)); LOG.debug("Querying database for resource {}, from {} to {}", resource, lower, upper); Results<Sample> samples = new Results<>(); DriverAdapter driverAdapter = new DriverAdapter(cassandraSelect(context, resource, lower, upper)); for (Row<Sample> row : driverAdapter) { samples.addRow(row); } LOG.debug("{} results returned from database", driverAdapter.getResultCount()); m_samplesSelected.mark(driverAdapter.getResultCount()); try { return samples; } finally { timer.stop(); } }
public void addElement(T sample) { Row<T> row = m_rows.get(sample.getTimestamp()); if (row == null) { row = new Row<>(sample.getTimestamp(), sample.getResource()); addRow(row); } row.addElement(sample); }
public Results<Measurement> process(Iterator<Row<Sample>> samples) { checkNotNull(samples, "samples argument"); // Build chain of iterators to process results as a stream Rate rate = new Rate(samples, m_resultDescriptor.getSourceNames()); PrimaryData primaryData = new PrimaryData(m_resource, m_start.minus(m_resolution), m_end, m_resultDescriptor, rate); Aggregation aggregation = new Aggregation(m_resource, m_start, m_end, m_resultDescriptor, m_resolution, primaryData); Compute compute = new Compute(m_resultDescriptor, aggregation); Export exports = new Export(m_resultDescriptor.getExports(), compute); Results<Measurement> measurements = new Results<>(); for (Row<Measurement> row : exports) { measurements.addRow(row); } return measurements; }
@Override public String toString() { return String.format("%s[%s]", getClass().getSimpleName(), getRows()); }
query.getResolution()); int numRows = results.getRows().size(); LOG.debug("Select returned {} rows.", numRows); meter.mark(numRows);
@Override public Collection<Row<Measurement>> call() throws Exception { ResultDescriptor resultDescriptor = new ResultDescriptor(lag.getInterval()); for (Source source : listOfSources) { // Use the datasource as the metric name if set, otherwise use the name of the attribute final String metricName = source.getDataSource() != null ? source.getDataSource() : source.getAttribute(); final String name = source.getLabel(); final AggregationFunction fn = toAggregationFunction(source.getAggregation()); resultDescriptor.datasource(name, metricName, lag.getHeartbeat(), fn); resultDescriptor.export(name); } LOG.debug("Querying Newts for resource id {} with result descriptor: {}", newtsResourceId, resultDescriptor); Results<Measurement> results = m_sampleRepository.select(m_context, new Resource(newtsResourceId), start, end, resultDescriptor, Optional.of(Duration.millis(lag.getStep())), limitConcurrentAggregationsCallback); Collection<Row<Measurement>> rows = results.getRows(); LOG.debug("Found {} rows.", rows.size()); return rows; } };
@Override public Collection<Row<Measurement>> call() throws Exception { ResultDescriptor resultDescriptor = new ResultDescriptor(lag.getInterval()); for (Source source : listOfSources) { // Use the datasource as the metric name if set, otherwise use the name of the attribute final String metricName = source.getDataSource() != null ? source.getDataSource() : source.getAttribute(); final String name = source.getLabel(); final AggregationFunction fn = toAggregationFunction(source.getAggregation()); resultDescriptor.datasource(name, metricName, lag.getHeartbeat(), fn); resultDescriptor.export(name); } LOG.debug("Querying Newts for resource id {} with result descriptor: {}", newtsResourceId, resultDescriptor); Results<Measurement> results = m_sampleRepository.select(m_context, new Resource(newtsResourceId), start, end, resultDescriptor, Optional.of(Duration.millis(lag.getStep())), limitConcurrentAggregationsCallback); Collection<Row<Measurement>> rows = results.getRows(); LOG.debug("Found {} rows.", rows.size()); return rows; } };