use of org.opennms.netmgt.jasper.measurement.MeasurementDataSource 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);
}
}
use of org.opennms.netmgt.jasper.measurement.MeasurementDataSource in project opennms by OpenNMS.
the class RemoteMeasurementDataSourceWrapper method createDataSource.
@Override
public JRRewindableDataSource createDataSource(String query) throws JRException {
try {
QueryRequest queryRequest = unmarshal(query);
// enforce relaxed mode
queryRequest.setRelaxed(true);
query = marshal(queryRequest);
Result result = connector.execute(useSsl, url, username, password, query);
// therefore do not allow redirection at all.
if (result.wasRedirection()) {
throw new IOException("Request was redirected. This is not supported.");
}
// if there is no data
if (404 == result.getResponseCode()) {
LOG.warn("Got a 404 (Not Found) response. This might be due to a wrong url or the resource does not exist. Requested URL was: '{}'", url);
return new EmptyJRDataSource();
}
// OK
if (result.wasSuccessful() && result.getInputStream() != null) {
return new MeasurementDataSource(result.getInputStream());
}
// Error
ByteArrayOutputStream errorMessageStream = new ByteArrayOutputStream();
if (result.getErrorStream() != null) {
ByteStreams.copy(result.getErrorStream(), errorMessageStream);
}
throw new JRException("Invalid request. Response was : " + result.getResponseCode() + " (" + result.getResponseMessage() + ")\n" + errorMessageStream.toString());
} catch (IOException ioException) {
throw new JRException(ioException);
}
}
use of org.opennms.netmgt.jasper.measurement.MeasurementDataSource in project opennms by OpenNMS.
the class LocalMeasurementDataSourceWrapperTest method verifyContainsResultEvenIfResourceOrAttributeDoNotExist.
// See NMS-8337
@Test
public void verifyContainsResultEvenIfResourceOrAttributeDoNotExist() throws JRException {
SpringHelper springHelper = MeasurementsHelper.getSpringHelper();
MeasurementDataSource dataSource = (MeasurementDataSource) new LocalMeasurementDataSourceWrapper(springHelper.getMeasurementFetchStrategy(), springHelper.getExpressionEngine(), springHelper.getFilterEngine()).createDataSource(getQuery());
Assert.assertEquals(2, dataSource.getRowCount());
double[] data = new double[] { 13, 17 };
while (dataSource.next()) {
Assert.assertEquals(data[dataSource.getCurrentRow()], dataSource.getFieldValue("ifInErrors", dataSource.getCurrentRow()));
Assert.assertEquals(Double.NaN, dataSource.getFieldValue("ifOutDiscards", dataSource.getCurrentRow()));
Assert.assertEquals(Double.NaN, dataSource.getFieldValue("ifOutErrors", dataSource.getCurrentRow()));
}
}
Aggregations