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