Search in sources :

Example 26 with OnmsAttribute

use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.

the class TopNAttributeStatisticVisitorTest method testVisitGetResultsSameValue.

public void testVisitGetResultsSameValue() throws Exception {
    BottomNAttributeStatisticVisitor visitor = new TopNAttributeStatisticVisitor();
    visitor.setCount(20);
    visitor.afterPropertiesSet();
    Map<OnmsAttribute, Double> attributes = new HashMap<OnmsAttribute, Double>();
    for (int i = 0; i < 5; i++) {
        attributes.put(new MockAttribute("foo"), 0.0);
    }
    OnmsResource resource = new OnmsResource("1", "Node One", new MockResourceType(), attributes.keySet(), ResourcePath.get("foo"));
    resource.getAttributes();
    for (Entry<OnmsAttribute, Double> entry : attributes.entrySet()) {
        visitor.visit(entry.getKey(), entry.getValue());
    }
    SortedSet<AttributeStatistic> top = visitor.getResults();
    assertNotNull("topN list should not be null", top);
    assertEquals("topN list size", 5, top.size());
    int i = 0;
    for (AttributeStatistic stat : top) {
        assertEquals("topN[" + i + "] value", 0.0, stat.getStatistic());
        i++;
    }
}
Also used : HashMap(java.util.HashMap) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) AttributeStatistic(org.opennms.netmgt.model.AttributeStatistic) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 27 with OnmsAttribute

use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.

the class TopNAttributeStatisticVisitorTest method testVisitGetResultsDifferentValues.

public void testVisitGetResultsDifferentValues() throws Exception {
    BottomNAttributeStatisticVisitor visitor = new TopNAttributeStatisticVisitor();
    visitor.setCount(20);
    visitor.afterPropertiesSet();
    Map<OnmsAttribute, Double> attributes = new HashMap<OnmsAttribute, Double>();
    for (int i = 0; i < 5; i++) {
        attributes.put(new MockAttribute("foo"), 0.0 + i);
    }
    OnmsResource resource = new OnmsResource("1", "Node One", new MockResourceType(), attributes.keySet(), ResourcePath.get("foo"));
    resource.getAttributes();
    for (Entry<OnmsAttribute, Double> entry : attributes.entrySet()) {
        visitor.visit(entry.getKey(), entry.getValue());
    }
    SortedSet<AttributeStatistic> top = visitor.getResults();
    assertNotNull("topN list should not be null", top);
    assertEquals("topN list size", 5, top.size());
    int i = 0;
    for (AttributeStatistic stat : top) {
        assertEquals("topN[" + i + "] value", 4.0 - i, stat.getStatistic());
        i++;
    }
}
Also used : HashMap(java.util.HashMap) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) AttributeStatistic(org.opennms.netmgt.model.AttributeStatistic) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 28 with OnmsAttribute

use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.

the class TopNAttributeStatisticVisitorTest method testVisitGetResults.

public void testVisitGetResults() throws Exception {
    BottomNAttributeStatisticVisitor visitor = new TopNAttributeStatisticVisitor();
    visitor.setCount(20);
    visitor.afterPropertiesSet();
    Map<OnmsAttribute, Double> attributes = new HashMap<OnmsAttribute, Double>();
    attributes.put(new MockAttribute("foo"), 0.0);
    OnmsResource resource = new OnmsResource("1", "Node One", new MockResourceType(), attributes.keySet(), ResourcePath.get("foo"));
    resource.getAttributes();
    for (Entry<OnmsAttribute, Double> entry : attributes.entrySet()) {
        visitor.visit(entry.getKey(), entry.getValue());
    }
    SortedSet<AttributeStatistic> top = visitor.getResults();
    assertNotNull("topN list should not be null", top);
    assertEquals("topN list size", 1, top.size());
    int i = 0;
    for (AttributeStatistic stat : top) {
        assertEquals("topN[" + i + "] value", 0.0, stat.getStatistic());
    }
}
Also used : HashMap(java.util.HashMap) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) AttributeStatistic(org.opennms.netmgt.model.AttributeStatistic) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 29 with OnmsAttribute

use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.

the class InterfaceSnmpResourceType method getResourceByParentPathAndInterface.

private OnmsResource getResourceByParentPathAndInterface(ResourcePath parent, String intf, String label, Long ifSpeed, String ifSpeedFriendly) throws DataAccessException {
    final ResourcePath path = ResourcePath.get(parent, intf);
    final AttributeLoader loader = new AttributeLoader(m_resourceStorageDao, path, ifSpeed, ifSpeedFriendly);
    final Set<OnmsAttribute> set = new LazySet<OnmsAttribute>(loader);
    return new OnmsResource(intf, label, this, set, path);
}
Also used : LazySet(org.opennms.core.utils.LazySet) ResourcePath(org.opennms.netmgt.model.ResourcePath) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute)

Example 30 with OnmsAttribute

use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.

the class AttributeMatchingResourceVisitorTest method testVisitWithoutMatch.

public void testVisitWithoutMatch() throws Exception {
    AttributeMatchingResourceVisitor resourceVisitor = new AttributeMatchingResourceVisitor();
    resourceVisitor.setAttributeVisitor(m_attributeVisitor);
    resourceVisitor.setAttributeMatch("ifInOctets");
    resourceVisitor.afterPropertiesSet();
    MockResourceType resourceType = new MockResourceType();
    resourceType.setName("something other than interfaceSnmp");
    OnmsResource resource = new OnmsResource("1", "Node One", resourceType, new HashSet<OnmsAttribute>(0), ResourcePath.get("foo"));
    m_mocks.replayAll();
    resourceVisitor.visit(resource);
    m_mocks.verifyAll();
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Aggregations

OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)45 OnmsResource (org.opennms.netmgt.model.OnmsResource)40 MockResourceType (org.opennms.netmgt.mock.MockResourceType)30 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)21 HashSet (java.util.HashSet)13 ResourcePath (org.opennms.netmgt.model.ResourcePath)13 Test (org.junit.Test)7 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)7 Source (org.opennms.netmgt.measurements.model.Source)7 ExternalValueAttribute (org.opennms.netmgt.model.ExternalValueAttribute)7 LazySet (org.opennms.core.utils.LazySet)6 HashMap (java.util.HashMap)5 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)5 AttributeStatistic (org.opennms.netmgt.model.AttributeStatistic)4 ResourceId (org.opennms.netmgt.model.ResourceId)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 OnmsResourceType (org.opennms.netmgt.model.OnmsResourceType)3 StringPropertyAttribute (org.opennms.netmgt.model.StringPropertyAttribute)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2