Search in sources :

Example 11 with ResultDescriptor

use of org.opennms.newts.api.query.ResultDescriptor in project newts by OpenNMS.

the class InsertSelectMeasurementsITCase method testWithDefaultResolution.

@Test
public void testWithDefaultResolution() {
    Iterator<Row<Sample>> testSamples = new SampleRowsBuilder(new Resource("localhost"), MetricType.GAUGE).row(900000000).element("mGauge", // Thu Jul  9 11:00:00 CDT 1998
    1).row(900000300).element("mGauge", 1).row(900000600).element("mGauge", 1).row(900000900).element("mGauge", 1).row(900001200).element("mGauge", 1).row(900001500).element("mGauge", 1).row(900001800).element("mGauge", 1, mapFor("a", "1")).row(900002100).element("mGauge", 3).row(900002400).element("mGauge", 3, mapFor("b", "2")).row(900002700).element("mGauge", 3).row(900003000).element("mGauge", 3).row(900003300).element("mGauge", 3).row(900003600).element("mGauge", 3).row(900003900).element("mGauge", 1).row(900004200).element("mGauge", 1).row(900004500).element("mGauge", 1).row(900004800).element("mGauge", 1).row(900005100).element("mGauge", 1, mapFor("c", "3")).row(900005400).element("mGauge", 1).row(900005700).element("mGauge", 3, mapFor("d", "4")).row(900006000).element("mGauge", 3).row(900006300).element("mGauge", 3).row(900006600).element("mGauge", 3).row(900006900).element("mGauge", 3).row(900007200).element("mGauge", // Thu Jul  9 13:00:00 CDT 1998
    3).build();
    ResultDescriptor rDescriptor = new ResultDescriptor(Duration.seconds(300)).datasource("mGauge-avg", "mGauge", Duration.seconds(600), AVERAGE).export("mGauge-avg");
    Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(900003600).element("mGauge-avg", 3).row(900004200).element("mGauge-avg", 1).row(900004800).element("mGauge-avg", 1).row(900005400).element("mGauge-avg", 1).row(900006000).element("mGauge-avg", 3).row(900006600).element("mGauge-avg", 3).row(900007200).element("mGauge-avg", 3).build();
    writeSamples(testSamples);
    Results<Measurement> results = getRepository().select(Context.DEFAULT_CONTEXT, new Resource("localhost"), Optional.of(Timestamp.fromEpochSeconds(900003600)), Optional.of(Timestamp.fromEpochSeconds(900007200)), rDescriptor, Optional.<Duration>absent());
    // Validate results
    assertRowsEqual(expected, results.iterator());
}
Also used : Measurement(org.opennms.newts.api.Measurement) MeasurementRowsBuilder(org.opennms.newts.persistence.cassandra.Utils.MeasurementRowsBuilder) Resource(org.opennms.newts.api.Resource) ResultDescriptor(org.opennms.newts.api.query.ResultDescriptor) Row(org.opennms.newts.api.Results.Row) SampleRowsBuilder(org.opennms.newts.persistence.cassandra.Utils.SampleRowsBuilder) Test(org.junit.Test)

Example 12 with ResultDescriptor

use of org.opennms.newts.api.query.ResultDescriptor in project newts by OpenNMS.

the class InsertSelectMeasurementsITCase method testWithDerive.

@Test
public void testWithDerive() {
    Iterator<Row<Sample>> testSamples = new SampleRowsBuilder(new Resource("localhost"), MetricType.DERIVE).row(900000000).element("mDerive", // Thu Jul  9 11:00:00 CDT 1998
    0).row(900000300).element("mDerive", 300).row(900000600).element("mDerive", 600).row(900000900).element("mDerive", 900).row(900001200).element("mDerive", 1200).row(900001500).element("mDerive", 1500).row(900001800).element("mDerive", 1800, mapFor("a", "1")).row(900002100).element("mDerive", 2100).row(900002400).element("mDerive", 2400, mapFor("b", "2")).row(900002700).element("mDerive", 2700).row(900003000).element("mDerive", 3000).row(900003300).element("mDerive", 3300).row(900003600).element("mDerive", 3600).row(900003900).element("mDerive", 3900).row(900004200).element("mDerive", 4200).row(900004500).element("mDerive", 4500).row(900004800).element("mDerive", 4800).row(900005100).element("mDerive", 5100, mapFor("c", "3")).row(900005400).element("mDerive", 5400).row(900005700).element("mDerive", 5700, mapFor("d", "4")).row(900006000).element("mDerive", 6000).row(900006300).element("mDerive", 6300).row(900006600).element("mDerive", 6600).row(900006900).element("mDerive", 6900).row(900007200).element("mDerive", // Thu Jul  9 13:00:00 CDT 1998
    7200).build();
    ResultDescriptor rDescriptor = new ResultDescriptor(Duration.seconds(300)).datasource("mDerive-avg", "mDerive", Duration.seconds(600), AVERAGE).export("mDerive-avg");
    Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(900003600).element("mDerive-avg", 1).row(900007200).element("mDerive-avg", 1).build();
    writeSamples(testSamples);
    Results<Measurement> results = getRepository().select(Context.DEFAULT_CONTEXT, new Resource("localhost"), Optional.of(Timestamp.fromEpochSeconds(900003600)), Optional.of(Timestamp.fromEpochSeconds(900007200)), rDescriptor, Optional.of(Duration.minutes(60)));
    // Validate results
    assertRowsEqual(expected, results.iterator());
    // Validate merged attributes
    Iterator<Row<Measurement>> rows = results.iterator();
    assertAttributes(rows.next().getElement("mDerive-avg"), mapFor("a", "1", "b", "2"));
    assertAttributes(rows.next().getElement("mDerive-avg"), mapFor("c", "3", "d", "4"));
}
Also used : Measurement(org.opennms.newts.api.Measurement) MeasurementRowsBuilder(org.opennms.newts.persistence.cassandra.Utils.MeasurementRowsBuilder) Resource(org.opennms.newts.api.Resource) ResultDescriptor(org.opennms.newts.api.query.ResultDescriptor) Row(org.opennms.newts.api.Results.Row) SampleRowsBuilder(org.opennms.newts.persistence.cassandra.Utils.SampleRowsBuilder) Test(org.junit.Test)

Example 13 with ResultDescriptor

use of org.opennms.newts.api.query.ResultDescriptor in project newts by OpenNMS.

the class InsertSelectMeasurementsITCase method test.

@Test
public void test() {
    Iterator<Row<Sample>> testSamples = new SampleRowsBuilder(new Resource("localhost"), MetricType.GAUGE).row(900000000).element("mGauge", // Thu Jul  9 11:00:00 CDT 1998
    1).row(900000300).element("mGauge", 1).row(900000600).element("mGauge", 1).row(900000900).element("mGauge", 1).row(900001200).element("mGauge", 1).row(900001500).element("mGauge", 1).row(900001800).element("mGauge", 1, mapFor("a", "1")).row(900002100).element("mGauge", 3).row(900002400).element("mGauge", 3, mapFor("b", "2")).row(900002700).element("mGauge", 3).row(900003000).element("mGauge", 3).row(900003300).element("mGauge", 3).row(900003600).element("mGauge", 3).row(900003900).element("mGauge", 1).row(900004200).element("mGauge", 1).row(900004500).element("mGauge", 1).row(900004800).element("mGauge", 1).row(900005100).element("mGauge", 1, mapFor("c", "3")).row(900005400).element("mGauge", 1).row(900005700).element("mGauge", 3, mapFor("d", "4")).row(900006000).element("mGauge", 3).row(900006300).element("mGauge", 3).row(900006600).element("mGauge", 3).row(900006900).element("mGauge", 3).row(900007200).element("mGauge", // Thu Jul  9 13:00:00 CDT 1998
    3).build();
    ResultDescriptor rDescriptor = new ResultDescriptor(Duration.seconds(300)).datasource("mGauge-avg", "mGauge", Duration.seconds(600), AVERAGE).export("mGauge-avg");
    Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(900003600).element("mGauge-avg", 2).row(900007200).element("mGauge-avg", 2).build();
    writeSamples(testSamples);
    Results<Measurement> results = getRepository().select(Context.DEFAULT_CONTEXT, new Resource("localhost"), Optional.of(Timestamp.fromEpochSeconds(900003600)), Optional.of(Timestamp.fromEpochSeconds(900007200)), rDescriptor, Optional.of(Duration.minutes(60)));
    // Validate results
    assertRowsEqual(expected, results.iterator());
    // Validate merged attributes
    Iterator<Row<Measurement>> rows = results.iterator();
    assertAttributes(rows.next().getElement("mGauge-avg"), mapFor("a", "1", "b", "2"));
    assertAttributes(rows.next().getElement("mGauge-avg"), mapFor("c", "3", "d", "4"));
}
Also used : Measurement(org.opennms.newts.api.Measurement) MeasurementRowsBuilder(org.opennms.newts.persistence.cassandra.Utils.MeasurementRowsBuilder) Resource(org.opennms.newts.api.Resource) ResultDescriptor(org.opennms.newts.api.query.ResultDescriptor) Row(org.opennms.newts.api.Results.Row) SampleRowsBuilder(org.opennms.newts.persistence.cassandra.Utils.SampleRowsBuilder) Test(org.junit.Test)

Example 14 with ResultDescriptor

use of org.opennms.newts.api.query.ResultDescriptor in project newts by OpenNMS.

the class PrimaryDataTest method testHeartbeatNaNs.

@Test
public void testHeartbeatNaNs() {
    // Test for NEWTS-70
    Iterator<Row<Sample>> testData = new SampleRowsBuilder(new Resource("localhost"), MetricType.GAUGE).row(0).element("m1", 1).row(300).element("m1", 2).row(1800).element("m1", 8).build();
    ResultDescriptor rDescriptor = new ResultDescriptor().step(Duration.seconds(300)).datasource("m1", "m1", Duration.seconds(600), null);
    // Expected results
    Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(300).element("m1", 2).row(600).element("m1", Double.NaN).row(900).element("m1", Double.NaN).row(1200).element("m1", Double.NaN).row(1500).element("m1", Double.NaN).row(1800).element("m1", Double.NaN).build();
    PrimaryData primaryData = new PrimaryData(new Resource("localhost"), Timestamp.fromEpochSeconds(300), Timestamp.fromEpochSeconds(1800), rDescriptor, testData);
    assertRowsEqual(expected, primaryData);
}
Also used : MeasurementRowsBuilder(org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder) Resource(org.opennms.newts.api.Resource) ResultDescriptor(org.opennms.newts.api.query.ResultDescriptor) Row(org.opennms.newts.api.Results.Row) SampleRowsBuilder(org.opennms.newts.aggregate.Utils.SampleRowsBuilder) Test(org.junit.Test)

Example 15 with ResultDescriptor

use of org.opennms.newts.api.query.ResultDescriptor in project newts by OpenNMS.

the class ResultProcessorTest method test.

@Test
public void test() {
    Iterator<Row<Sample>> testData = new SampleRowsBuilder(new Resource("localhost"), MetricType.GAUGE).row(900000000).element("m0", // Thu Jul  9 11:00:00 CDT 1998
    1).row(900000300).element("m0", 1).row(900000600).element("m0", 1).row(900000900).element("m0", 1).row(900001200).element("m0", 1).row(900001500).element("m0", 1).row(900001800).element("m0", 1).row(900002100).element("m0", 3).row(900002400).element("m0", 3).row(900002700).element("m0", 3).row(900003000).element("m0", 3).row(900003300).element("m0", 3).row(900003600).element("m0", 3).row(900003900).element("m0", 1).row(900004200).element("m0", 1).row(900004500).element("m0", 1).row(900004800).element("m0", 1).row(900005100).element("m0", 1).row(900005400).element("m0", 1).row(900005700).element("m0", 3).row(900006000).element("m0", 3).row(900006300).element("m0", 3).row(900006600).element("m0", 3).row(900006900).element("m0", 3).row(900007200).element("m0", // Thu Jul  9 13:00:00 CDT 1998
    3).build();
    ResultDescriptor rDescriptor = new ResultDescriptor(Duration.seconds(300)).datasource("m0-avg", "m0", Duration.seconds(600), AVERAGE).export("m0-avg");
    Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(900003600).element("m0-avg", 2.0).row(900007200).element("m0-avg", 2.0).build();
    ResultProcessor processor = new ResultProcessor(new Resource("localhost"), Timestamp.fromEpochSeconds(900003600), Timestamp.fromEpochSeconds(900007200), rDescriptor, Duration.minutes(60));
    assertRowsEqual(expected, processor.process(testData).iterator());
}
Also used : MeasurementRowsBuilder(org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder) Resource(org.opennms.newts.api.Resource) ResultDescriptor(org.opennms.newts.api.query.ResultDescriptor) Row(org.opennms.newts.api.Results.Row) SampleRowsBuilder(org.opennms.newts.aggregate.Utils.SampleRowsBuilder) Test(org.junit.Test)

Aggregations

ResultDescriptor (org.opennms.newts.api.query.ResultDescriptor)33 Resource (org.opennms.newts.api.Resource)30 Row (org.opennms.newts.api.Results.Row)29 Test (org.junit.Test)28 MeasurementRowsBuilder (org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder)20 SampleRowsBuilder (org.opennms.newts.aggregate.Utils.SampleRowsBuilder)17 Measurement (org.opennms.newts.api.Measurement)11 MeasurementRowsBuilder (org.opennms.newts.persistence.cassandra.Utils.MeasurementRowsBuilder)5 SampleRowsBuilder (org.opennms.newts.persistence.cassandra.Utils.SampleRowsBuilder)5 Timed (com.codahale.metrics.annotation.Timed)1 Path (java.nio.file.Path)1 Callable (java.util.concurrent.Callable)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Source (org.opennms.netmgt.measurements.model.Source)1 OnmsResource (org.opennms.netmgt.model.OnmsResource)1 ResourcePath (org.opennms.netmgt.model.ResourcePath)1 Context (org.opennms.newts.api.Context)1 Duration (org.opennms.newts.api.Duration)1 Results (org.opennms.newts.api.Results)1