use of org.opennms.netmgt.measurements.api.FetchResults in project opennms by OpenNMS.
the class NewtsFetchStrategyTest method canRetrieveAttributeWhenFallbackAttributeIsSet.
@Test
public void canRetrieveAttributeWhenFallbackAttributeIsSet() throws Exception {
createMockResource("icmplocalhost", "icmp", "127.0.0.1");
replay();
Source sourceToBeFetched = new Source();
sourceToBeFetched.setResourceId("nodeSource[NODES:1505998205].responseTime[127.0.0.1]");
sourceToBeFetched.setAttribute("icmp");
sourceToBeFetched.setFallbackAttribute("willNotBeFound");
sourceToBeFetched.setAggregation("AVERAGE");
sourceToBeFetched.setLabel("icmp");
FetchResults fetchResults = m_newtsFetchStrategy.fetch(1431047069000L - (60 * 60 * 1000), 1431047069000L, 300 * 1000, 0, null, null, Lists.newArrayList(sourceToBeFetched), false);
assertEquals(1, fetchResults.getColumns().keySet().size());
assertTrue(fetchResults.getColumns().containsKey("icmplocalhost"));
assertEquals(1, fetchResults.getTimestamps().length);
}
use of org.opennms.netmgt.measurements.api.FetchResults in project opennms by OpenNMS.
the class NewtsFetchStrategyTest method testFetchWithDuplicateResources.
@Test
public void testFetchWithDuplicateResources() throws Exception {
List<Source> sources = Lists.newArrayList(createMockResource("icmp", "icmp", "127.0.0.1"), createMockResource("icmp", "icmp", "192.168.0.1"));
replay();
FetchResults fetchResults = m_newtsFetchStrategy.fetch(1431047069000L - (60 * 60 * 1000), 1431047069000L, 300 * 1000, 0, null, null, sources, false);
// It's not possible to fetch multiple resources with the same label, we should only get 1 ICMP result
assertEquals(1, fetchResults.getColumns().keySet().size());
}
use of org.opennms.netmgt.measurements.api.FetchResults 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");
}
use of org.opennms.netmgt.measurements.api.FetchResults in project opennms by OpenNMS.
the class RrdStatisticAttributeVisitorTest method testVisitWithRrdAttribute.
public void testVisitWithRrdAttribute() throws Exception {
RrdStatisticAttributeVisitor attributeVisitor = new RrdStatisticAttributeVisitor();
attributeVisitor.setFetchStrategy(m_fetchStrategy);
attributeVisitor.setConsolidationFunction("AVERAGE");
attributeVisitor.setStartTime(m_startTime);
attributeVisitor.setEndTime(m_endTime);
attributeVisitor.setStatisticVisitor(m_statisticVisitor);
attributeVisitor.afterPropertiesSet();
MockResourceType resourceType = new MockResourceType();
resourceType.setName("interfaceSnmp");
OnmsAttribute attribute = new RrdGraphAttribute("ifInOctets", "something", "something else");
attribute.setResource(new OnmsResource("1", "Node One", resourceType, Collections.singleton(attribute), ResourcePath.get("foo")));
Source source = new Source();
source.setLabel("result");
source.setResourceId(attribute.getResource().getId().toString());
source.setAttribute(attribute.getName());
source.setAggregation(attributeVisitor.getConsolidationFunction().toUpperCase());
FetchResults results = new FetchResults(new long[] { m_startTime }, Collections.singletonMap("result", new double[] { 1.0 }), m_endTime - m_startTime, Collections.emptyMap());
expect(m_fetchStrategy.fetch(m_startTime, m_endTime, 1, 0, null, null, Collections.singletonList(source), false)).andReturn(results);
m_statisticVisitor.visit(attribute, 1.0);
m_mocks.replayAll();
attributeVisitor.visit(attribute);
m_mocks.verifyAll();
}
use of org.opennms.netmgt.measurements.api.FetchResults in project opennms by OpenNMS.
the class RrdStatisticAttributeVisitorTest method testVisitWithNotANumberRrdAttribute.
public void testVisitWithNotANumberRrdAttribute() throws Exception {
RrdStatisticAttributeVisitor attributeVisitor = new RrdStatisticAttributeVisitor();
attributeVisitor.setFetchStrategy(m_fetchStrategy);
attributeVisitor.setConsolidationFunction("AVERAGE");
attributeVisitor.setStartTime(m_startTime);
attributeVisitor.setEndTime(m_endTime);
attributeVisitor.setStatisticVisitor(m_statisticVisitor);
attributeVisitor.afterPropertiesSet();
MockResourceType resourceType = new MockResourceType();
resourceType.setName("somethingOtherThanInterfaceSnmp");
OnmsAttribute attribute = new RrdGraphAttribute("ifInOctets", "something", "something else");
attribute.setResource(new OnmsResource("1", "Node One", resourceType, Collections.singleton(attribute), ResourcePath.get("foo")));
Source source = new Source();
source.setLabel("result");
source.setResourceId(attribute.getResource().getId().toString());
source.setAttribute(attribute.getName());
source.setAggregation(attributeVisitor.getConsolidationFunction().toUpperCase());
FetchResults results = new FetchResults(new long[] {}, Collections.singletonMap("result", new double[] {}), m_endTime - m_startTime, Collections.emptyMap());
expect(m_fetchStrategy.fetch(m_startTime, m_endTime, 1, 0, null, null, Collections.singletonList(source), false)).andReturn(results);
m_mocks.replayAll();
attributeVisitor.visit(attribute);
m_mocks.verifyAll();
}
Aggregations