Search in sources :

Example 46 with VertexRef

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

the class FRLayoutTest method runFRLayout.

private TopoFRLayout<VertexRef, EdgeRef> runFRLayout(Graph g, Layout graphLayout, List<Vertex> vertices) {
    TopoFRLayout<VertexRef, EdgeRef> layout = new TopoFRLayout<>(createJungGraph(g));
    Dimension size = selectLayoutSize(m_graphContainer);
    // layout.setRepulsionMultiplier(3/8.0);
    // layout.setAttractionMultiplier(3/8.0);
    layout.setInitializer(initializer(graphLayout, size));
    layout.setSize(size);
    while (!layout.done()) {
        layout.step();
    }
    LOG.info("/******** FRLayout Run **********/");
    for (Vertex v : vertices) {
        graphLayout.setLocation(v, new Point(layout.getX(v) - size.getWidth() / 2.0, layout.getY(v) - size.getHeight() / 2.0));
        LOG.info("layout.getX(): " + layout.getX(v) + " layout.getY(): " + layout.getY(v));
    }
    LOG.info("/******** End FRLayout Run **********/");
    return layout;
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) Dimension(java.awt.Dimension) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 47 with VertexRef

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

the class PingOperation method execute.

@Override
public void execute(final List<VertexRef> targets, final OperationContext operationContext) {
    final VertexRef target = targets.get(0);
    final Vertex vertex = getVertexItem(operationContext, target);
    final Optional<OnmsNode> node = getNodeIfAvailable(vertex);
    final List<String> locations = monitoringLocationDao.findAll().stream().map(OnmsMonitoringLocation::getLocationName).collect(Collectors.toList());
    final String defaultLocation = node.isPresent() ? node.get().getLocation().getLocationName() : MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID;
    final List<InetAddress> ipAddresses = node.isPresent() ? Lists.newArrayList(node.get().getIpInterfaces()).stream().map(OnmsIpInterface::getIpAddress).collect(Collectors.toList()) : Lists.newArrayList(InetAddressUtils.addr(vertex.getIpAddress()));
    final InetAddress defaultIp = getDefaultIp(vertex, node);
    final String caption = String.format("Ping - %s (%s)", vertex.getLabel(), vertex.getIpAddress());
    new PingWindow(pingClient, locations, ipAddresses, defaultLocation, defaultIp, caption).open();
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) PingWindow(org.opennms.features.topology.netutils.internal.ping.PingWindow) VertexRef(org.opennms.features.topology.api.topo.VertexRef) InetAddress(java.net.InetAddress)

Example 48 with VertexRef

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

the class PathOutageProvider method getDefaults.

@Override
public Defaults getDefaults() {
    // semantic zoom level 0 and the node with the worst state; or for the first node (if all nodes have state NORMAL)
    return new Defaults().withSemanticZoomLevel(0).withPreferredLayout("Hierarchy Layout").withCriteria(() -> {
        Map<VertexRef, Status> resultMap = statusProvider.getStatusForVertices(this, Lists.newArrayList(this.getVertices()), new Criteria[0]);
        Optional<Map.Entry<VertexRef, Status>> max = resultMap.entrySet().stream().max(Comparator.comparing(e -> OnmsSeverity.get(e.getValue().computeStatus())));
        if (max.isPresent()) {
            return Lists.newArrayList(new VertexHopGraphProvider.DefaultVertexHopCriteria(max.get().getKey()));
        } else if (this.getVertexTotalCount() > 0) {
            return Lists.newArrayList(new VertexHopGraphProvider.DefaultVertexHopCriteria(this.getVertices().get(0)));
        } else {
            return Lists.newArrayList();
        }
    });
}
Also used : Status(org.opennms.features.topology.api.topo.Status) NodeDao(org.opennms.netmgt.dao.api.NodeDao) Collection(java.util.Collection) AbstractTopologyProvider(org.opennms.features.topology.api.topo.AbstractTopologyProvider) DirectedSparseGraph(edu.uci.ics.jung.graph.DirectedSparseGraph) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) Collectors(java.util.stream.Collectors) VertexHopGraphProvider(org.opennms.features.topology.api.support.VertexHopGraphProvider) ArrayList(java.util.ArrayList) List(java.util.List) Lists(com.google.common.collect.Lists) Map(java.util.Map) Criteria(org.opennms.features.topology.api.topo.Criteria) Defaults(org.opennms.features.topology.api.topo.Defaults) EdgeType(edu.uci.ics.jung.graph.util.EdgeType) Optional(java.util.Optional) SelectionChangedListener(org.opennms.features.topology.api.browsers.SelectionChangedListener) AbstractEdge(org.opennms.features.topology.api.topo.AbstractEdge) Status(org.opennms.features.topology.api.topo.Status) Comparator(java.util.Comparator) VertexRef(org.opennms.features.topology.api.topo.VertexRef) ContentType(org.opennms.features.topology.api.browsers.ContentType) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) Defaults(org.opennms.features.topology.api.topo.Defaults) VertexHopGraphProvider(org.opennms.features.topology.api.support.VertexHopGraphProvider) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 49 with VertexRef

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

the class PathOutageStatusProviderIT method verify.

@Test
public /**
 * This method tests if the {@link PathOutageStatusProvider} retrieves alarm data correctly
 */
void verify() throws UnknownHostException {
    this.pathOutageStatusProvider = new PathOutageStatusProvider(this.genericPersistenceAccessor);
    this.pathOutageProvider = new PathOutageProvider(this.nodeDao, this.pathOutageStatusProvider);
    this.pathOutageProvider.refresh();
    // Very basic test - check that PathOutageStatusProvider finds a Status for each vertex
    // and that all these statuses are at the moment NORMAL
    Map<VertexRef, Status> stats = this.calculateStatuses();
    for (VertexRef vertex : stats.keySet()) {
        Assert.assertNotNull(stats.get(vertex));
        Assert.assertEquals(OnmsSeverity.NORMAL.getLabel().toLowerCase(), stats.get(vertex).computeStatus().toLowerCase());
    }
    // Also check that the PathOutageProvider calculates the default focus strategy correctly
    // the list of criteria should always contain exactly 1 vertex (with the worst status)
    List<Criteria> criteria = this.pathOutageProvider.getDefaults().getCriteria();
    Assert.assertNotNull(criteria);
    Assert.assertEquals(1, criteria.size());
    // Adding a single path outage with MINOR severity.
    // PathOutageStatusProvider should be able to find this outage + all other nodes should have a state NORMAL
    this.outageDao.save(createOutage(EventConstants.NODE_DOWN_EVENT_UEI, address_1, this.nodeDao.get(1), OnmsSeverity.MINOR));
    stats = this.calculateStatuses();
    for (VertexRef vertex : stats.keySet()) {
        Assert.assertNotNull(stats.get(vertex));
        if (vertex.getId().equalsIgnoreCase("1")) {
            Assert.assertEquals(OnmsSeverity.MINOR.getLabel().toLowerCase(), stats.get(vertex).computeStatus().toLowerCase());
        } else {
            Assert.assertEquals(OnmsSeverity.NORMAL.getLabel().toLowerCase(), stats.get(vertex).computeStatus().toLowerCase());
        }
    }
    // List of criteria should contain exactly 1 vertex (with the worst status, meaning that its id should be 1)
    criteria = this.pathOutageProvider.getDefaults().getCriteria();
    Assert.assertNotNull(criteria);
    Assert.assertEquals(1, criteria.size());
    VertexHopGraphProvider.DefaultVertexHopCriteria criterion = (VertexHopGraphProvider.DefaultVertexHopCriteria) criteria.get(0);
    Assert.assertEquals("1", criterion.getId());
    // Adding a MAJOR path outage to the same node.
    // PathOutageStatusProvider should display the alarm with a MAJOR severity level
    this.outageDao.save(createOutage(EventConstants.NODE_DOWN_EVENT_UEI, address_1, this.nodeDao.get(1), OnmsSeverity.MAJOR));
    stats = this.calculateStatuses();
    for (VertexRef vertex : stats.keySet()) {
        Assert.assertNotNull(stats.get(vertex));
        if (vertex.getId().equalsIgnoreCase("1")) {
            Assert.assertEquals(OnmsSeverity.MAJOR.getLabel().toLowerCase(), stats.get(vertex).computeStatus().toLowerCase());
            break;
        }
    }
    // List of criteria should contain exactly 1 vertex (with the worst status, meaning that its id should still be 1)
    criteria = this.pathOutageProvider.getDefaults().getCriteria();
    Assert.assertNotNull(criteria);
    Assert.assertEquals(1, criteria.size());
    criterion = (VertexHopGraphProvider.DefaultVertexHopCriteria) criteria.get(0);
    Assert.assertEquals("1", criterion.getId());
    // Adding several more path outages of different types
    // PathOutageStatusProvider should display them all, plus the one from the previous test
    this.outageDao.save(createOutage(EventConstants.NODE_LOST_SERVICE_EVENT_UEI, address_2, this.nodeDao.get(2), OnmsSeverity.MINOR));
    this.outageDao.save(createOutage(EventConstants.INTERFACE_DOWN_EVENT_UEI, address_3, this.nodeDao.get(3), OnmsSeverity.MINOR));
    this.outageDao.save(createOutage(EventConstants.PATH_OUTAGE_EVENT_UEI, address_4, this.nodeDao.get(4), OnmsSeverity.MAJOR));
    stats = this.calculateStatuses();
    for (VertexRef vertex : stats.keySet()) {
        Assert.assertNotNull(stats.get(vertex));
        if (vertex.getId().equalsIgnoreCase("1")) {
            Assert.assertEquals(OnmsSeverity.MAJOR.getLabel().toLowerCase(), stats.get(vertex).computeStatus().toLowerCase());
        } else if (vertex.getId().equalsIgnoreCase("2")) {
            Assert.assertEquals(OnmsSeverity.MINOR.getLabel().toLowerCase(), stats.get(vertex).computeStatus().toLowerCase());
        } else if (vertex.getId().equalsIgnoreCase("3")) {
            Assert.assertEquals(OnmsSeverity.MINOR.getLabel().toLowerCase(), stats.get(vertex).computeStatus().toLowerCase());
        } else if (vertex.getId().equalsIgnoreCase("4")) {
            Assert.assertEquals(OnmsSeverity.MAJOR.getLabel().toLowerCase(), stats.get(vertex).computeStatus().toLowerCase());
        }
    }
    // List of criteria should contain exactly 1 vertex (with the worst status, meaning that its id should be either 1 or 4)
    criteria = this.pathOutageProvider.getDefaults().getCriteria();
    Assert.assertNotNull(criteria);
    Assert.assertEquals(1, criteria.size());
    criterion = (VertexHopGraphProvider.DefaultVertexHopCriteria) criteria.get(0);
    Assert.assertTrue(criterion.getId().equalsIgnoreCase("1") || criterion.getId().equalsIgnoreCase("4"));
}
Also used : Status(org.opennms.features.topology.api.topo.Status) VertexHopGraphProvider(org.opennms.features.topology.api.support.VertexHopGraphProvider) Criteria(org.opennms.features.topology.api.topo.Criteria) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Test(org.junit.Test)

Example 50 with VertexRef

use of org.opennms.features.topology.api.topo.VertexRef 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 : AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) 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) 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)

Aggregations

VertexRef (org.opennms.features.topology.api.topo.VertexRef)105 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)33 Vertex (org.opennms.features.topology.api.topo.Vertex)31 Point (org.opennms.features.topology.api.Point)23 Criteria (org.opennms.features.topology.api.topo.Criteria)22 Edge (org.opennms.features.topology.api.topo.Edge)22 Test (org.junit.Test)21 List (java.util.List)20 ArrayList (java.util.ArrayList)19 Collectors (java.util.stream.Collectors)18 EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)18 Map (java.util.Map)17 Status (org.opennms.features.topology.api.topo.Status)15 Collection (java.util.Collection)13 HashSet (java.util.HashSet)13 SparseGraph (edu.uci.ics.jung.graph.SparseGraph)12 HashMap (java.util.HashMap)12 Layout (org.opennms.features.topology.api.Layout)12 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)12 Lists (com.google.common.collect.Lists)11