Search in sources :

Example 21 with QueryRequest

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

the class JEXLExpressionEngineTest method performExpression.

private double[] performExpression(String expression, Map<String, Object> constants) throws ExpressionException {
    // Build a simple request with the given expression
    QueryRequest request = new QueryRequest();
    Source constant = new Source();
    constant.setLabel("x");
    request.setSources(Lists.newArrayList(constant));
    Expression exp = new Expression();
    exp.setLabel("y");
    exp.setExpression(expression);
    request.setExpressions(Lists.newArrayList(exp));
    // Build the fetch results with known values
    final int N = 100;
    long[] timestamps = new long[N];
    double[] xValues = new double[N];
    for (int i = 0; i < N; i++) {
        timestamps[i] = i * 1000;
        xValues[i] = Double.valueOf(i);
    }
    Map<String, double[]> values = Maps.newHashMap();
    values.put("x", xValues);
    FetchResults results = new FetchResults(timestamps, values, 1, constants);
    // Use the engine to evaluate the expression
    jexlExpressionEngine.applyExpressions(request, results);
    // Retrieve the results
    return results.getColumns().get("y");
}
Also used : QueryRequest(org.opennms.netmgt.measurements.model.QueryRequest) Expression(org.opennms.netmgt.measurements.model.Expression) FetchResults(org.opennms.netmgt.measurements.api.FetchResults) 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