Search in sources :

Example 6 with EdgeRef

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

the class LinkdEdgeStatusProviderTest method testGetCdpLinkStatusDown.

@Test
public void testGetCdpLinkStatusDown() {
    EasyMock.expect(m_alarmDao.findMatching(EasyMock.anyObject(org.opennms.core.criteria.Criteria.class))).andReturn(createCdpDownAlarm()).anyTimes();
    List<EdgeRef> edges = getEdgeRefs();
    for (EdgeRef ref : edges) EasyMock.expect(m_edgeProvider.getEdge(ref)).andReturn(getEdgeFromRef(ref)).anyTimes();
    EasyMock.replay(m_alarmDao, m_edgeProvider);
    Map<EdgeRef, Status> statusMap = m_statusProvider.getStatusForEdges(m_edgeProvider, edges, new Criteria[0]);
    assertEquals(8, statusMap.size());
    assertEquals(edges.get(0), new ArrayList<EdgeRef>(statusMap.keySet()).get(0));
    assertEquals(statusMap.get(edges.get(0)).computeStatus(), "up");
    assertEquals(statusMap.get(edges.get(1)).computeStatus(), "up");
    assertEquals(statusMap.get(edges.get(2)).computeStatus(), "up");
    assertEquals(statusMap.get(edges.get(3)).computeStatus(), "up");
    assertEquals(statusMap.get(edges.get(4)).computeStatus(), "up");
    assertEquals(statusMap.get(edges.get(5)).computeStatus(), "up");
    assertEquals(statusMap.get(edges.get(7)).computeStatus(), "up");
    assertEquals(statusMap.get(edges.get(6)).computeStatus(), "down");
}
Also used : Status(org.opennms.features.topology.api.topo.Status) ArrayList(java.util.ArrayList) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) Test(org.junit.Test)

Example 7 with EdgeRef

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

the class LinkdEdgeStatusProviderTest method testLinkStatusWithNoAlarms.

@Test
public void testLinkStatusWithNoAlarms() {
    EasyMock.expect(m_alarmDao.findMatching(EasyMock.anyObject(org.opennms.core.criteria.Criteria.class))).andReturn(createEmptyAlarmList()).anyTimes();
    List<EdgeRef> edges = getEdgeRefs();
    for (EdgeRef ref : edges) EasyMock.expect(m_edgeProvider.getEdge(ref)).andReturn(getEdgeFromRef(ref)).anyTimes();
    EasyMock.replay(m_alarmDao, m_edgeProvider);
    Map<EdgeRef, Status> statusMap = m_statusProvider.getStatusForEdges(m_edgeProvider, edges, new Criteria[0]);
    assertEquals(8, statusMap.size());
    assertEquals(edges.get(0), new ArrayList<EdgeRef>(statusMap.keySet()).get(0));
    for (Status status : statusMap.values()) {
        assertEquals("up", status.computeStatus());
    }
    Map<EdgeRef, Status> statusMap2 = m_statusProvider.getStatusForEdges(m_edgeProvider, edges, new Criteria[0]);
    assertEquals(8, statusMap2.size());
    for (Status status : statusMap2.values()) {
        assertEquals("up", status.computeStatus());
    }
}
Also used : Status(org.opennms.features.topology.api.topo.Status) ArrayList(java.util.ArrayList) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) Test(org.junit.Test)

Example 8 with EdgeRef

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

the class GraphMLEdgeStatusProviderIT method verify.

@Test
public void verify() throws Exception {
    final GraphMLServiceAccessor serviceAccessor = new GraphMLServiceAccessor();
    serviceAccessor.setTransactionOperations(transactionOperations);
    serviceAccessor.setNodeDao(nodeDao);
    serviceAccessor.setSnmpInterfaceDao(snmpInterfaceDao);
    serviceAccessor.setMeasurementsService(request -> new QueryResponse());
    final GraphMLGraph graph = GraphMLReader.read(getClass().getResourceAsStream("/test-graph2.xml")).getGraphs().get(0);
    final GraphMLTopologyProvider topologyProvider = new GraphMLTopologyProvider(null, graph, serviceAccessor);
    final GraphMLEdgeStatusProvider provider = new GraphMLEdgeStatusProvider(topologyProvider, new ScriptEngineManager(), serviceAccessor, Paths.get("src", "test", "opennms-home", "etc", "graphml-edge-status"));
    assertThat(provider.contributesTo("acme:regions"), is(true));
    assertThat(provider.getNamespace(), is("acme:regions"));
    // Calculating the status executes some tests defined int the according scripts as a side effect
    final EdgeRef edgeRef = topologyProvider.getEdge("acme:regions", "center_north");
    final Map<? extends EdgeRef, ? extends Status> status = provider.getStatusForEdges(topologyProvider, ImmutableList.of(edgeRef), new Criteria[0]);
    // Checking nodeID creation for vertices with only foreignSource/foreignID set
    final VertexRef vertexRef = topologyProvider.getVertex("acme:regions", "west");
    assertThat(vertexRef, is(notNullValue()));
    assertThat(vertexRef, is(instanceOf(GraphMLVertex.class)));
    assertThat(((GraphMLVertex) vertexRef).getNodeID(), is(4));
    // Testing status merging from two scripts
    assertThat(status, is(notNullValue()));
    assertThat(status, is(hasEntry(edgeRef, new GraphMLEdgeStatus().severity(OnmsSeverity.WARNING).style("stroke", "pink").style("stroke-width", "3em"))));
}
Also used : GraphMLEdgeStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLEdgeStatusProvider) QueryResponse(org.opennms.netmgt.measurements.model.QueryResponse) GraphMLServiceAccessor(org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor) GraphMLGraph(org.opennms.features.graphml.model.GraphMLGraph) ScriptEngineManager(javax.script.ScriptEngineManager) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) GraphMLEdgeStatus(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLEdgeStatus) Test(org.junit.Test)

Example 9 with EdgeRef

use of org.opennms.features.topology.api.topo.EdgeRef 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 10 with EdgeRef

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

the class NCSEdgeStatusProvider method getStatusForEdges.

@Override
public Map<EdgeRef, Status> getStatusForEdges(EdgeProvider edgeProvider, Collection<EdgeRef> edges, Criteria[] criteria) {
    List<EdgeRef> ncsEdges = new ArrayList<EdgeRef>(Collections2.filter(edges, new Predicate<EdgeRef>() {

        @Override
        public boolean apply(EdgeRef edgeRef) {
            return edgeRef.getNamespace().equals("ncs");
        }
    }));
    Set<String> alarms = getNCSImpactedAlarms();
    Map<EdgeRef, Status> statusMap = new HashMap<EdgeRef, Status>();
    for (EdgeRef edge : ncsEdges) {
        NCSEdgeProvider.NCSEdge e = (NCSEdgeProvider.NCSEdge) edge;
        e.setStatus("up");
        statusMap.put(edge, new NCSLinkStatus("up"));
        if (alarms.contains(e.getSourceElementName()) || alarms.contains(e.getTargetElementName())) {
            statusMap.put(edge, new NCSLinkStatus("down"));
            e.setStatus("down");
        }
    }
    return statusMap;
}
Also used : Status(org.opennms.features.topology.api.topo.Status) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Predicate(com.google.common.base.Predicate) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef)

Aggregations

EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)30 VertexRef (org.opennms.features.topology.api.topo.VertexRef)18 Vertex (org.opennms.features.topology.api.topo.Vertex)14 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)12 Edge (org.opennms.features.topology.api.topo.Edge)11 SparseGraph (edu.uci.ics.jung.graph.SparseGraph)10 Status (org.opennms.features.topology.api.topo.Status)10 Point (org.opennms.features.topology.api.Point)9 Dimension (java.awt.Dimension)6 Layout (org.opennms.features.topology.api.Layout)6 FRLayout (edu.uci.ics.jung.algorithms.layout.FRLayout)3 SpringLayout (edu.uci.ics.jung.algorithms.layout.SpringLayout)3 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)3 HashMap (java.util.HashMap)2 Graph (org.opennms.features.topology.api.Graph)2 Predicate (com.google.common.base.Predicate)1 Lists (com.google.common.collect.Lists)1 ISOMLayout (edu.uci.ics.jung.algorithms.layout.ISOMLayout)1 UnweightedShortestPath (edu.uci.ics.jung.algorithms.shortestpath.UnweightedShortestPath)1