Search in sources :

Example 36 with Row

use of org.opennms.newts.api.Results.Row in project newts by OpenNMS.

the class PrimaryDataTest method testVeryShortSamples.

@Test
public void testVeryShortSamples() {
    // Samples occur prior to the nearest step interval boundary.
    Iterator<Row<Sample>> testData = new SampleRowsBuilder(new Resource("localhost"), MetricType.GAUGE).row(000).element("m0", 0).element("m1", 1).row(250).element("m0", 1).element("m1", 2).row(550).element("m0", 2).element("m1", 3).row(850).element("m0", 3).element("m1", 4).build();
    // Minimal result descriptor
    ResultDescriptor rDescriptor = new ResultDescriptor().step(Duration.seconds(300)).datasource("m0", "m0", Duration.seconds(600), null).datasource("m1", "m1", Duration.seconds(600), null);
    // Expected results
    Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(300).element("m0", 1.16666667).element("m1", 2.16666667).row(600).element("m0", 2.16666667).element("m1", 3.16666667).row(900).element("m0", 3.0).element("m1", 4.0).row(1200).element("m0", Double.NaN).element("m1", Double.NaN).row(1500).element("m0", Double.NaN).element("m1", Double.NaN).build();
    PrimaryData primaryData = new PrimaryData(new Resource("localhost"), Timestamp.fromEpochSeconds(300), Timestamp.fromEpochSeconds(1500), 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 37 with Row

use of org.opennms.newts.api.Results.Row in project opennms by OpenNMS.

the class NewtsFetchStrategyTest method createMockResource.

public Source createMockResource(final String label, final String attr, final String node, boolean expect) {
    OnmsResourceType type = EasyMock.createNiceMock(OnmsResourceType.class);
    final int nodeId = node.hashCode();
    final String newtsResourceId = "response:" + node + ":" + attr;
    final ResourceId resourceId = ResourceId.get("nodeSource", "NODES:" + nodeId).resolve("responseTime", node);
    OnmsResource resource = m_resources.get(resourceId);
    if (resource == null) {
        resource = new OnmsResource(attr, label, type, Sets.newHashSet(), ResourcePath.get("foo"));
        m_resources.put(resourceId, resource);
    }
    Set<OnmsAttribute> attributes = resource.getAttributes();
    attributes.add(new RrdGraphAttribute(attr, "", newtsResourceId));
    Results<Measurement> results = new Results<Measurement>();
    Resource res = new Resource(newtsResourceId);
    Row<Measurement> row = new Row<Measurement>(Timestamp.fromEpochSeconds(0), res);
    Measurement measurement = new Measurement(Timestamp.fromEpochSeconds(0), res, label, 0.0d);
    row.addElement(measurement);
    results.addRow(row);
    if (expect) {
        EasyMock.expect(m_sampleRepository.select(EasyMock.eq(m_context), EasyMock.eq(res), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(results);
    }
    final Source source = new Source();
    source.setAggregation("AVERAGE");
    source.setAttribute(attr);
    source.setLabel(label);
    source.setResourceId(resourceId.toString());
    source.setTransient(false);
    return source;
}
Also used : Measurement(org.opennms.newts.api.Measurement) OnmsResource(org.opennms.netmgt.model.OnmsResource) Resource(org.opennms.newts.api.Resource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) Source(org.opennms.netmgt.measurements.model.Source) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsResourceType(org.opennms.netmgt.model.OnmsResourceType) ResourceId(org.opennms.netmgt.model.ResourceId) FetchResults(org.opennms.netmgt.measurements.api.FetchResults) Results(org.opennms.newts.api.Results) Row(org.opennms.newts.api.Results.Row)

Aggregations

Row (org.opennms.newts.api.Results.Row)37 Resource (org.opennms.newts.api.Resource)33 Test (org.junit.Test)31 ResultDescriptor (org.opennms.newts.api.query.ResultDescriptor)30 MeasurementRowsBuilder (org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder)20 SampleRowsBuilder (org.opennms.newts.aggregate.Utils.SampleRowsBuilder)18 Measurement (org.opennms.newts.api.Measurement)14 Sample (org.opennms.newts.api.Sample)4 Timestamp (org.opennms.newts.api.Timestamp)4 MeasurementRowsBuilder (org.opennms.newts.persistence.cassandra.Utils.MeasurementRowsBuilder)4 SampleRowsBuilder (org.opennms.newts.persistence.cassandra.Utils.SampleRowsBuilder)4 NoSuchElementException (java.util.NoSuchElementException)3 Source (org.opennms.netmgt.measurements.model.Source)3 OnmsResource (org.opennms.netmgt.model.OnmsResource)3 Map (java.util.Map)2 Callable (java.util.concurrent.Callable)2 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)2 ResourceId (org.opennms.netmgt.model.ResourceId)2 Rate (org.opennms.newts.aggregate.Rate)2 Duration (org.opennms.newts.api.Duration)2