Search in sources :

Example 1 with QueryResponse

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

the class LocalMeasurementDataSourceWrapper method createDataSource.

@Override
public JRRewindableDataSource createDataSource(String query) throws JRException {
    Objects.requireNonNull(query);
    QueryRequest queryRequest = unmarshal(query);
    Objects.requireNonNull(queryRequest);
    // Enforce relaxed mode
    queryRequest.setRelaxed(true);
    try {
        QueryResponse response = fetchService.query(queryRequest);
        return new MeasurementDataSource(response);
    } catch (ResourceNotFoundException rnfe) {
        LOG.warn("A attribute or resource was not found", rnfe);
        return new EmptyJRDataSource();
    } catch (Exception e) {
        LOG.error("An error occurred while fetching the measurement results", e);
        throw new JRException(e);
    }
}
Also used : QueryRequest(org.opennms.netmgt.measurements.model.QueryRequest) JRException(net.sf.jasperreports.engine.JRException) QueryResponse(org.opennms.netmgt.measurements.model.QueryResponse) MeasurementDataSource(org.opennms.netmgt.jasper.measurement.MeasurementDataSource) ResourceNotFoundException(org.opennms.netmgt.measurements.api.exceptions.ResourceNotFoundException) ResourceNotFoundException(org.opennms.netmgt.measurements.api.exceptions.ResourceNotFoundException) JRException(net.sf.jasperreports.engine.JRException) EmptyJRDataSource(org.opennms.netmgt.jasper.measurement.EmptyJRDataSource)

Example 2 with QueryResponse

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

the class MeasurementsRestServiceWithRrdIT method canRetrieveMeasurementsFromRrd.

@Test
public void canRetrieveMeasurementsFromRrd() throws Exception {
    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("ifInOctets");
    ifInOctetsAvg.setAggregation("AVERAGE");
    ifInOctetsAvg.setLabel("ifInOctetsAvg");
    // Min
    Source ifInOctetsMin = new Source();
    ifInOctetsMin.setResourceId("node[1].interfaceSnmp[eth0-04013f75f101]");
    ifInOctetsMin.setAttribute("ifInOctets");
    ifInOctetsMin.setAggregation("MIN");
    ifInOctetsMin.setLabel("ifInOctetsMin");
    // Max
    Source ifInOctetsMax = new Source();
    ifInOctetsMax.setResourceId("node[1].interfaceSnmp[eth0-04013f75f101]");
    ifInOctetsMax.setAttribute("ifInOctets");
    ifInOctetsMax.setAggregation("MAX");
    ifInOctetsMax.setLabel("ifInOctetsMax");
    request.setSources(Lists.newArrayList(ifInOctetsAvg, ifInOctetsMin, ifInOctetsMax));
    // 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);
    assertEquals(259.54086378737543, columns.get("ifInOctetsMin")[idx], 0.0001);
    assertEquals(67872.22455490529, columns.get("ifInOctetsMax")[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 3 with QueryResponse

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

the class MeasurementsRestServiceWithJrbIT method canApplyFilters.

@Test
public void canApplyFilters() {
    QueryRequest request = new QueryRequest();
    request.setStart(1414602000000L);
    request.setEnd(1418046400000L);
    request.setStep(1000L);
    request.setMaxRows(700);
    Source ifInOctets = new Source();
    ifInOctets.setResourceId("node[1].interfaceSnmp[eth0-04013f75f101]");
    ifInOctets.setAttribute("ifInOctets");
    ifInOctets.setAggregation("MAX");
    ifInOctets.setLabel("ifInOctets");
    request.setSources(Lists.newArrayList(ifInOctets));
    // Apply a chomp filter - cutting some of the first row off, and the trailing NaNs
    FilterDef chompFilter = new FilterDef("Chomp", "cutoffDate", "1414630000.0", "stripNaNs", "true");
    request.setFilters(Lists.newArrayList(chompFilter));
    LOG.debug(JaxbUtils.marshal(request));
    QueryResponse response = m_svc.query(request);
    // Verify the values for the first and last rows
    final Map<String, double[]> columns = response.columnsWithLabels();
    double[] ifInOctetsColumn = columns.get("ifInOctets");
    assertEquals(67872.22455490529, ifInOctetsColumn[0], 0.0001);
    assertEquals(1649961.9593111263, ifInOctetsColumn[ifInOctetsColumn.length - 1], 0.0001);
}
Also used : QueryRequest(org.opennms.netmgt.measurements.model.QueryRequest) FilterDef(org.opennms.netmgt.measurements.model.FilterDef) QueryResponse(org.opennms.netmgt.measurements.model.QueryResponse) Source(org.opennms.netmgt.measurements.model.Source) Test(org.junit.Test)

Example 4 with QueryResponse

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

the class MeasurementsRestServiceWithJrbIT method canRetrieveMeasurementsFromJrb.

@Test
public void canRetrieveMeasurementsFromJrb() {
    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("ifInOctets");
    ifInOctetsAvg.setAggregation("AVERAGE");
    ifInOctetsAvg.setLabel("ifInOctetsAvg");
    // Min
    Source ifInOctetsMin = new Source();
    ifInOctetsMin.setResourceId("node[1].interfaceSnmp[eth0-04013f75f101]");
    ifInOctetsMin.setAttribute("ifInOctets");
    ifInOctetsMin.setAggregation("MIN");
    ifInOctetsMin.setLabel("ifInOctetsMin");
    // Max
    Source ifInOctetsMax = new Source();
    ifInOctetsMax.setResourceId("node[1].interfaceSnmp[eth0-04013f75f101]");
    ifInOctetsMax.setAttribute("ifInOctets");
    ifInOctetsMax.setAggregation("MAX");
    ifInOctetsMax.setLabel("ifInOctetsMax");
    request.setSources(Lists.newArrayList(ifInOctetsAvg, ifInOctetsMin, ifInOctetsMax));
    // 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);
    assertEquals(259.54086378737543, columns.get("ifInOctetsMin")[idx], 0.0001);
    assertEquals(67872.22455490529, columns.get("ifInOctetsMax")[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 5 with QueryResponse

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

the class DefaultMeasurementsService method query.

@Override
public QueryResponse query(QueryRequest request) throws MeasurementException {
    validate(request);
    // Fetch the measurements
    FetchResults results;
    try {
        results = fetchStrategy.fetch(request.getStart(), request.getEnd(), request.getStep(), request.getMaxRows(), request.getHeartbeat(), request.getInterval(), request.getSources(), request.isRelaxed());
    } catch (Exception e) {
        throw new FetchException(e, "Fetch failed: {}", e.getMessage());
    }
    if (results == null) {
        throw new ResourceNotFoundException(request);
    }
    // Apply the expression to the fetch results
    expressionEngine.applyExpressions(request, results);
    // Apply the filters
    if (!request.getFilters().isEmpty()) {
        RowSortedTable<Long, String, Double> table = results.asRowSortedTable();
        filterEngine.filter(request.getFilters(), table);
        results = new FetchResults(table, results.getStep(), results.getConstants());
    }
    // Remove any transient values belonging to sources
    final Map<String, double[]> columns = results.getColumns();
    for (final Source source : request.getSources()) {
        if (source.getTransient()) {
            columns.remove(source.getLabel());
        }
    }
    // Build the response
    final QueryResponse response = new QueryResponse();
    response.setStart(request.getStart());
    response.setEnd(request.getEnd());
    response.setStep(results.getStep());
    response.setTimestamps(results.getTimestamps());
    response.setColumns(results.getColumns());
    response.setConstants(results.getConstants());
    return response;
}
Also used : QueryResponse(org.opennms.netmgt.measurements.model.QueryResponse) FetchException(org.opennms.netmgt.measurements.api.exceptions.FetchException) ResourceNotFoundException(org.opennms.netmgt.measurements.api.exceptions.ResourceNotFoundException) FetchException(org.opennms.netmgt.measurements.api.exceptions.FetchException) MeasurementException(org.opennms.netmgt.measurements.api.exceptions.MeasurementException) ValidationException(org.opennms.netmgt.measurements.api.exceptions.ValidationException) ResourceNotFoundException(org.opennms.netmgt.measurements.api.exceptions.ResourceNotFoundException) Source(org.opennms.netmgt.measurements.model.Source)

Aggregations

QueryResponse (org.opennms.netmgt.measurements.model.QueryResponse)11 Test (org.junit.Test)7 QueryRequest (org.opennms.netmgt.measurements.model.QueryRequest)7 Source (org.opennms.netmgt.measurements.model.Source)7 ResourceNotFoundException (org.opennms.netmgt.measurements.api.exceptions.ResourceNotFoundException)3 GraphMLServiceAccessor (org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor)2 FetchException (org.opennms.netmgt.measurements.api.exceptions.FetchException)2 ValidationException (org.opennms.netmgt.measurements.api.exceptions.ValidationException)2 ScriptEngineManager (javax.script.ScriptEngineManager)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 JRException (net.sf.jasperreports.engine.JRException)1 Before (org.junit.Before)1 GraphMLGraph (org.opennms.features.graphml.model.GraphMLGraph)1 EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)1 VertexRef (org.opennms.features.topology.api.topo.VertexRef)1 GraphMLEdgeStatus (org.opennms.features.topology.plugins.topo.graphml.status.GraphMLEdgeStatus)1