Search in sources :

Example 11 with FetchResults

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);
}
Also used : FetchResults(org.opennms.netmgt.measurements.api.FetchResults) Source(org.opennms.netmgt.measurements.model.Source) Test(org.junit.Test)

Example 12 with FetchResults

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());
}
Also used : FetchResults(org.opennms.netmgt.measurements.api.FetchResults) Source(org.opennms.netmgt.measurements.model.Source) Test(org.junit.Test)

Example 13 with FetchResults

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");
}
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)

Example 14 with FetchResults

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();
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) FetchResults(org.opennms.netmgt.measurements.api.FetchResults) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) Source(org.opennms.netmgt.measurements.model.Source) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 15 with FetchResults

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();
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) FetchResults(org.opennms.netmgt.measurements.api.FetchResults) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) Source(org.opennms.netmgt.measurements.model.Source) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Aggregations

FetchResults (org.opennms.netmgt.measurements.api.FetchResults)19 Source (org.opennms.netmgt.measurements.model.Source)18 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)7 Test (org.junit.Test)6 OnmsResource (org.opennms.netmgt.model.OnmsResource)6 Map (java.util.Map)5 OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)5 MockResourceType (org.opennms.netmgt.mock.MockResourceType)4 RrdException (org.jrobin.core.RrdException)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Optional (com.google.common.base.Optional)1 Strings (com.google.common.base.Strings)1 Throwables (com.google.common.base.Throwables)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1