Search in sources :

Example 1 with VertexProvider

use of org.opennms.features.topology.api.topo.VertexProvider in project opennms by OpenNMS.

the class VmwareStatusProvider method getStatusForVertices.

@Override
public Map<VertexRef, Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
    final List<AbstractVertex> vmwareVertices = vertices.stream().filter(v -> v.getNamespace().equals(getNamespace())).map(v -> (AbstractVertex) v).collect(Collectors.toList());
    // All vertices associated with a node id
    final Map<Integer, VertexRef> nodeIdMap = vmwareVertices.stream().filter(v -> v.getNodeID() != null).collect(Collectors.toMap(AbstractVertex::getNodeID, Function.identity()));
    // Alarm summary for each node id
    final Map<Integer, AlarmSummary> nodeIdToAlarmSummaryMap = getAlarmSummaries(nodeIdMap.keySet());
    // Set the result
    Map<VertexRef, Status> resultMap = Maps.newHashMap();
    for (AbstractVertex eachVertex : vmwareVertices) {
        AlarmSummary alarmSummary = nodeIdToAlarmSummaryMap.get(eachVertex.getNodeID());
        if (alarmSummary != null) {
            resultMap.put(eachVertex, new DefaultStatus(alarmSummary.getMaxSeverity().getLabel(), 0));
        }
    }
    return resultMap;
}
Also used : AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) Collection(java.util.Collection) Set(java.util.Set) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) ArrayList(java.util.ArrayList) Objects(java.util.Objects) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) List(java.util.List) StatusProvider(org.opennms.features.topology.api.topo.StatusProvider) VertexProvider(org.opennms.features.topology.api.topo.VertexProvider) AlarmDao(org.opennms.netmgt.dao.api.AlarmDao) Map(java.util.Map) Criteria(org.opennms.features.topology.api.topo.Criteria) Status(org.opennms.features.topology.api.topo.Status) VertexRef(org.opennms.features.topology.api.topo.VertexRef) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) Status(org.opennms.features.topology.api.topo.Status) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 2 with VertexProvider

use of org.opennms.features.topology.api.topo.VertexProvider in project opennms by OpenNMS.

the class GraphMLVertexStatusProvider method getStatusForVertices.

@Override
public Map<VertexRef, Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
    // All vertices for the current vertexProvider
    final List<GraphMLVertex> graphMLVertices = vertices.stream().filter(eachVertex -> contributesTo(eachVertex.getNamespace()) && eachVertex instanceof GraphMLVertex).map(eachVertex -> (GraphMLVertex) eachVertex).collect(Collectors.toList());
    // All vertices associated with a node id
    final Map<Integer, VertexRef> nodeIdMap = graphMLVertices.stream().filter(eachVertex -> eachVertex.getNodeID() != null).collect(Collectors.toMap(AbstractVertex::getNodeID, Function.identity()));
    // Alarm summary for each node id
    final Map<Integer, AlarmSummary> nodeIdToAlarmSummaryMap = getAlarmSummaries(nodeIdMap.keySet());
    // Set the result
    Map<VertexRef, Status> resultMap = Maps.newHashMap();
    for (GraphMLVertex eachVertex : graphMLVertices) {
        AlarmSummary alarmSummary = nodeIdToAlarmSummaryMap.get(eachVertex.getNodeID());
        DefaultStatus status = alarmSummary == null ? new VertexStatus(OnmsSeverity.NORMAL) : new VertexStatus(alarmSummary.getMaxSeverity(), alarmSummary.getAlarmCount());
        resultMap.put(eachVertex, status);
    }
    return resultMap;
}
Also used : AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) Collection(java.util.Collection) Set(java.util.Set) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) ArrayList(java.util.ArrayList) Objects(java.util.Objects) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) List(java.util.List) StatusProvider(org.opennms.features.topology.api.topo.StatusProvider) VertexProvider(org.opennms.features.topology.api.topo.VertexProvider) AlarmSummaryWrapper(org.opennms.features.topology.plugins.topo.graphml.internal.AlarmSummaryWrapper) Map(java.util.Map) Criteria(org.opennms.features.topology.api.topo.Criteria) Status(org.opennms.features.topology.api.topo.Status) VertexRef(org.opennms.features.topology.api.topo.VertexRef) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) Status(org.opennms.features.topology.api.topo.Status) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 3 with VertexProvider

use of org.opennms.features.topology.api.topo.VertexProvider in project opennms by OpenNMS.

the class EnhancedLinkdTopologyProviderTest method testTopoProviderSetParent.

@Test
public void testTopoProviderSetParent() {
    VertexRef vertexId1 = addVertexToTopr();
    VertexRef vertexId2 = addVertexToTopr();
    final AtomicInteger eventsReceived = new AtomicInteger(0);
    m_topologyProvider.addVertexListener(new VertexListener() {

        @Override
        public void vertexSetChanged(VertexProvider provider, Collection<? extends Vertex> added, Collection<? extends Vertex> update, Collection<String> removedVertexIds) {
            eventsReceived.incrementAndGet();
        }

        @Override
        public void vertexSetChanged(VertexProvider provider) {
            eventsReceived.incrementAndGet();
        }
    });
    Vertex groupId = m_topologyProvider.addGroup("Test Group", "groupIcon.jpg");
    assertEquals(1, eventsReceived.get());
    eventsReceived.set(0);
    m_topologyProvider.setParent(vertexId1, groupId);
    m_topologyProvider.setParent(vertexId2, groupId);
    assertEquals(2, eventsReceived.get());
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) SimpleLeafVertex(org.opennms.features.topology.api.topo.SimpleLeafVertex) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VertexProvider(org.opennms.features.topology.api.topo.VertexProvider) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) VertexListener(org.opennms.features.topology.api.topo.VertexListener) Test(org.junit.Test)

Aggregations

AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)3 VertexProvider (org.opennms.features.topology.api.topo.VertexProvider)3 VertexRef (org.opennms.features.topology.api.topo.VertexRef)3 Maps (com.google.common.collect.Maps)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Set (java.util.Set)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 Criteria (org.opennms.features.topology.api.topo.Criteria)2 DefaultStatus (org.opennms.features.topology.api.topo.DefaultStatus)2 Status (org.opennms.features.topology.api.topo.Status)2 StatusProvider (org.opennms.features.topology.api.topo.StatusProvider)2 AlarmSummary (org.opennms.netmgt.model.alarm.AlarmSummary)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)1