Search in sources :

Example 16 with QueryRequest

use of org.opennms.netmgt.measurements.model.QueryRequest in project opennms by OpenNMS.

the class MeasurementsRestServiceITCase method canRetrieveNoMeasurementsInRelaxedMode.

@Test
public void canRetrieveNoMeasurementsInRelaxedMode() throws Exception {
    // Enable relaxed mode
    QueryRequest request = new QueryRequest();
    request.setRelaxed(true);
    request.setStart(1414602000000L);
    request.setEnd(1417046400000L);
    request.setStep(1000L);
    request.setMaxRows(700);
    // Query for some attribute that doesn't exist, on an existing resource
    Source notIfInOctetsAvg = new Source();
    notIfInOctetsAvg.setResourceId("node[1].interfaceSnmp[eth0-04013f75f101]");
    notIfInOctetsAvg.setAttribute("notIfInOctets");
    notIfInOctetsAvg.setAggregation("AVERAGE");
    notIfInOctetsAvg.setLabel("notIfInOctets");
    request.setSources(Lists.newArrayList(notIfInOctetsAvg));
    // Perform the query
    try {
        m_svc.query(request);
        fail("HTTP 204 exception expected.");
    } catch (WebApplicationException ex) {
        assertEquals(204, ex.getResponse().getStatus());
    }
}
Also used : QueryRequest(org.opennms.netmgt.measurements.model.QueryRequest) WebApplicationException(javax.ws.rs.WebApplicationException) Source(org.opennms.netmgt.measurements.model.Source) Test(org.junit.Test)

Example 17 with QueryRequest

use of org.opennms.netmgt.measurements.model.QueryRequest in project opennms by OpenNMS.

the class MeasurementsRestServiceITCase method notFoundOnMissingResource.

@Test
public void notFoundOnMissingResource() {
    final QueryRequest request = buildRequest();
    request.getSources().get(0).setResourceId("node[99].interfaceSnmp[eth0-04013f75f101]");
    exception.expect(exceptionWithResponseCode(404));
    m_svc.query(request);
}
Also used : QueryRequest(org.opennms.netmgt.measurements.model.QueryRequest) Test(org.junit.Test)

Example 18 with QueryRequest

use of org.opennms.netmgt.measurements.model.QueryRequest in project opennms by OpenNMS.

the class MeasurementsRestServiceITCase method canRetrieveFallbackAttributeWhenAttributeNotFound.

@Test
public void canRetrieveFallbackAttributeWhenAttributeNotFound() {
    QueryRequest request = new QueryRequest();
    request.setStart(1414602000000L);
    request.setEnd(1417046400000L);
    request.setStep(1000L);
    request.setMaxRows(700);
    // Average
    Source ifInOctetsAvg = new Source();
    ifInOctetsAvg.setResourceId("node[1].interfaceSnmp[eth0-04013f75f101]");
    ifInOctetsAvg.setAttribute("willNotBeFound");
    ifInOctetsAvg.setFallbackAttribute("ifInOctets");
    ifInOctetsAvg.setAggregation("AVERAGE");
    ifInOctetsAvg.setLabel("ifInOctetsAvg");
    request.setSources(Lists.newArrayList(ifInOctetsAvg));
    // Perform the query
    QueryResponse response = m_svc.query(request);
    // Validate the results
    long[] timestamps = response.getTimestamps();
    final Map<String, double[]> columns = response.columnsWithLabels();
    assertEquals(3600000L, response.getStep());
    assertEquals(680, timestamps.length);
    // Verify the values at an arbitrary index
    final int idx = 8;
    assertEquals(1414630800000L, timestamps[idx]);
    assertEquals(270.66140826873385, columns.get("ifInOctetsAvg")[idx], 0.0001);
}
Also used : QueryRequest(org.opennms.netmgt.measurements.model.QueryRequest) QueryResponse(org.opennms.netmgt.measurements.model.QueryResponse) Source(org.opennms.netmgt.measurements.model.Source) Test(org.junit.Test)

Example 19 with QueryRequest

use of org.opennms.netmgt.measurements.model.QueryRequest in project opennms by OpenNMS.

the class MeasurementsRestServiceITCase method badRequestOnMissingLabel.

@Test
public void badRequestOnMissingLabel() {
    final QueryRequest request = buildRequest();
    request.getSources().get(0).setLabel(null);
    exception.expect(exceptionWithResponseCode(400));
    m_svc.query(request);
}
Also used : QueryRequest(org.opennms.netmgt.measurements.model.QueryRequest) Test(org.junit.Test)

Example 20 with QueryRequest

use of org.opennms.netmgt.measurements.model.QueryRequest in project opennms by OpenNMS.

the class MeasurementsWrapper method queryInt.

private QueryResponse queryInt(final String resource, final String attribute, final long start, final long end, final long step, final String aggregation, final boolean relaxed) throws MeasurementException {
    QueryRequest request = new QueryRequest();
    request.setRelaxed(relaxed);
    request.setStart(start);
    request.setEnd(end);
    request.setStep(step);
    Source source = new Source();
    source.setAggregation(aggregation);
    source.setTransient(false);
    source.setAttribute(attribute);
    source.setResourceId(resource);
    source.setLabel(attribute);
    request.setSources(Collections.singletonList(source));
    return measurementsService.query(request);
}
Also used : QueryRequest(org.opennms.netmgt.measurements.model.QueryRequest) Source(org.opennms.netmgt.measurements.model.Source)

Aggregations

QueryRequest (org.opennms.netmgt.measurements.model.QueryRequest)21 Test (org.junit.Test)13 Source (org.opennms.netmgt.measurements.model.Source)13 QueryResponse (org.opennms.netmgt.measurements.model.QueryResponse)7 Expression (org.opennms.netmgt.measurements.model.Expression)3 JRException (net.sf.jasperreports.engine.JRException)2 EmptyJRDataSource (org.opennms.netmgt.jasper.measurement.EmptyJRDataSource)2 MeasurementDataSource (org.opennms.netmgt.jasper.measurement.MeasurementDataSource)2 Request (com.github.tomakehurst.wiremock.http.Request)1 LoggedRequest (com.github.tomakehurst.wiremock.verification.LoggedRequest)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)1