Search in sources :

Example 1 with MeasurementException

use of org.opennms.netmgt.measurements.api.exceptions.MeasurementException 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

FetchException (org.opennms.netmgt.measurements.api.exceptions.FetchException)1 MeasurementException (org.opennms.netmgt.measurements.api.exceptions.MeasurementException)1 ResourceNotFoundException (org.opennms.netmgt.measurements.api.exceptions.ResourceNotFoundException)1 ValidationException (org.opennms.netmgt.measurements.api.exceptions.ValidationException)1 QueryResponse (org.opennms.netmgt.measurements.model.QueryResponse)1 Source (org.opennms.netmgt.measurements.model.Source)1