Search in sources :

Example 31 with Resource

use of org.opennms.newts.api.Resource in project newts by OpenNMS.

the class InsertSelectMeasurementsITCase method testWithAbsolute.

@Test
public void testWithAbsolute() {
    Iterator<Row<Sample>> testSamples = new SampleRowsBuilder(new Resource("localhost"), MetricType.ABSOLUTE).row(900000000).element("mAbsolute", // Thu Jul  9 11:00:00 CDT 1998
    300).row(900000300).element("mAbsolute", 300).row(900000600).element("mAbsolute", 300).row(900000900).element("mAbsolute", 300).row(900001200).element("mAbsolute", 300).row(900001500).element("mAbsolute", 300).row(900001800).element("mAbsolute", 300, mapFor("a", "1")).row(900002100).element("mAbsolute", 300).row(900002400).element("mAbsolute", 300, mapFor("b", "2")).row(900002700).element("mAbsolute", 300).row(900003000).element("mAbsolute", 300).row(900003300).element("mAbsolute", 300).row(900003600).element("mAbsolute", 300).row(900003900).element("mAbsolute", 300).row(900004200).element("mAbsolute", 300).row(900004500).element("mAbsolute", 300).row(900004800).element("mAbsolute", 300).row(900005100).element("mAbsolute", 300, mapFor("c", "3")).row(900005400).element("mAbsolute", 300).row(900005700).element("mAbsolute", 300, mapFor("d", "4")).row(900006000).element("mAbsolute", 300).row(900006300).element("mAbsolute", 300).row(900006600).element("mAbsolute", 300).row(900006900).element("mAbsolute", 300).row(900007200).element("mAbsolute", // Thu Jul  9 13:00:00 CDT 1998
    300).build();
    ResultDescriptor rDescriptor = new ResultDescriptor(Duration.seconds(300)).datasource("mAbsolute-avg", "mAbsolute", Duration.seconds(600), AVERAGE).export("mAbsolute-avg");
    Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(900003600).element("mAbsolute-avg", 1).row(900007200).element("mAbsolute-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("mAbsolute-avg"), mapFor("a", "1", "b", "2"));
    assertAttributes(rows.next().getElement("mAbsolute-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 32 with Resource

use of org.opennms.newts.api.Resource 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 33 with Resource

use of org.opennms.newts.api.Resource 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 34 with Resource

use of org.opennms.newts.api.Resource 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 35 with Resource

use of org.opennms.newts.api.Resource in project newts by OpenNMS.

the class CassandraIndexerITCase method test.

@Test
public void test() {
    Map<String, String> base = map("meat", "people", "bread", "beer");
    List<Sample> samples = Lists.newArrayList();
    samples.add(sampleFor(new Resource("aaa", Optional.of(base)), "m0"));
    samples.add(sampleFor(new Resource("aab", Optional.of(map(base, "music", "metal", "beverage", "beer"))), "m0"));
    samples.add(sampleFor(new Resource("aac:aaa", Optional.of(map(base, "music", "country"))), "m0"));
    CassandraSession session = newtsInstance.getCassandraSession();
    ResourceMetadataCache mockCache = mock(ResourceMetadataCache.class);
    when(mockCache.get(any(Context.class), any(Resource.class))).thenReturn(Optional.<ResourceMetadata>absent());
    MetricRegistry registry = new MetricRegistry();
    ContextConfigurations contextConfigurations = new ContextConfigurations();
    CassandraIndexingOptions options = new CassandraIndexingOptions.Builder().withHierarchicalIndexing(false).build();
    Indexer indexer = new CassandraIndexer(session, 86400, mockCache, registry, options, new SimpleResourceIdSplitter(), contextConfigurations);
    indexer.update(samples);
    CassandraSearcher searcher = new CassandraSearcher(session, registry, contextConfigurations);
    // Match path components
    assertThat(searcher.search(Context.DEFAULT_CONTEXT, QueryBuilder.matchAnyValue("aaa")).size(), equalTo(2));
    assertThat(searcher.search(Context.DEFAULT_CONTEXT, QueryBuilder.matchAnyValue("aac")).size(), equalTo(1));
    // Match attribute values
    assertThat(searcher.search(Context.DEFAULT_CONTEXT, QueryBuilder.matchAnyValue("people")).size(), equalTo(3));
    assertThat(searcher.search(Context.DEFAULT_CONTEXT, QueryBuilder.matchAnyValue("metal")).size(), equalTo(1));
    // Match attribute key + value pairs
    BooleanQuery query = new BooleanQuery();
    query.add(new TermQuery(new Term("beverage", "beer")), Operator.OR);
    assertThat(searcher.search(Context.DEFAULT_CONTEXT, query).size(), equalTo(1));
    // Or'd terms
    assertThat(searcher.search(Context.DEFAULT_CONTEXT, QueryBuilder.matchAnyValue("metal", "country")).size(), equalTo(2));
    assertThat(searcher.search(Context.DEFAULT_CONTEXT, QueryBuilder.matchAnyValue("beer", "wine")).size(), equalTo(3));
    // And'd terms
    assertThat(searcher.search(Context.DEFAULT_CONTEXT, QueryBuilder.matchAllValues("metal", "country")).size(), equalTo(0));
    assertThat(searcher.search(Context.DEFAULT_CONTEXT, QueryBuilder.matchAllValues("aaa", "aac")).size(), equalTo(1));
    // Groups queries
    // (beer AND metal) OR (aaa AND country)
    BooleanQuery subquery1 = new BooleanQuery();
    subquery1.add(new TermQuery(new Term("beer")), Operator.OR);
    subquery1.add(new TermQuery(new Term("metal")), Operator.AND);
    BooleanQuery subquery2 = new BooleanQuery();
    subquery2.add(new TermQuery(new Term("aaa")), Operator.OR);
    subquery2.add(new TermQuery(new Term("country")), Operator.AND);
    query = new BooleanQuery();
    query.add(subquery1, Operator.OR);
    query.add(subquery2, Operator.OR);
    assertThat(searcher.search(Context.DEFAULT_CONTEXT, query).size(), equalTo(2));
    // Attributes are retrieved
    Result r = searcher.search(Context.DEFAULT_CONTEXT, QueryBuilder.matchAnyValue("metal")).iterator().next();
    assertThat(r.getResource().getId(), is(equalTo("aab")));
    assertThat(r.getResource().getAttributes().isPresent(), is(true));
    assertThat(r.getResource().getAttributes().get(), equalTo(map(base, "music", "metal", "beverage", "beer")));
    // Metrics too
    assertThat(r.getMetrics().size(), equalTo(1));
    assertThat(r.getMetrics().iterator().next(), equalTo("m0"));
}
Also used : Context(org.opennms.newts.api.Context) BooleanQuery(org.opennms.newts.api.search.BooleanQuery) TermQuery(org.opennms.newts.api.search.TermQuery) Sample(org.opennms.newts.api.Sample) MetricRegistry(com.codahale.metrics.MetricRegistry) QueryBuilder(org.opennms.newts.api.search.QueryBuilder) Resource(org.opennms.newts.api.Resource) CassandraSession(org.opennms.newts.cassandra.CassandraSession) Term(org.opennms.newts.api.search.Term) Result(org.opennms.newts.api.search.SearchResults.Result) Indexer(org.opennms.newts.api.search.Indexer) ContextConfigurations(org.opennms.newts.cassandra.ContextConfigurations) Test(org.junit.Test)

Aggregations

Resource (org.opennms.newts.api.Resource)67 Test (org.junit.Test)50 Row (org.opennms.newts.api.Results.Row)35 ResultDescriptor (org.opennms.newts.api.query.ResultDescriptor)31 MeasurementRowsBuilder (org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder)20 SampleRowsBuilder (org.opennms.newts.aggregate.Utils.SampleRowsBuilder)20 Sample (org.opennms.newts.api.Sample)19 Measurement (org.opennms.newts.api.Measurement)14 Context (org.opennms.newts.api.Context)12 MetricRegistry (com.codahale.metrics.MetricRegistry)9 SearchResults (org.opennms.newts.api.search.SearchResults)8 Timestamp (org.opennms.newts.api.Timestamp)7 ResourcePath (org.opennms.netmgt.model.ResourcePath)6 ContextConfigurations (org.opennms.newts.cassandra.ContextConfigurations)6 Map (java.util.Map)5 Results (org.opennms.newts.api.Results)5 CassandraSession (org.opennms.newts.cassandra.CassandraSession)5 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)4 List (java.util.List)4 Result (org.opennms.newts.api.search.SearchResults.Result)4