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