use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class ApplicationVertexTest method testHierarchy.
@Test
public void testHierarchy() {
ApplicationVertex vertex = createVertex("100");
vertex.addChildren(createVertex("service:1"));
vertex.addChildren(createVertex("service:2"));
Assert.assertEquals(true, vertex.isRoot());
Assert.assertEquals(false, vertex.isLeaf());
Assert.assertEquals(true, vertex.isPartOf("100"));
Assert.assertEquals(false, vertex.isPartOf("101"));
// Verify first level
for (VertexRef eachRef : vertex.getChildren()) {
Assert.assertEquals(ApplicationTopologyProvider.TOPOLOGY_NAMESPACE, eachRef.getNamespace());
ApplicationVertex child = (ApplicationVertex) eachRef;
Assert.assertEquals(false, child.isRoot());
Assert.assertEquals(true, child.isLeaf());
Assert.assertEquals(vertex, child.getRoot());
Assert.assertEquals(vertex, child.getParent());
Assert.assertEquals(true, child.isPartOf("100"));
Assert.assertEquals(false, child.isPartOf("101"));
}
}
use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class NCSSearchProvider method getVertexRefsForEdges.
public static Set<VertexRef> getVertexRefsForEdges(NCSEdgeProvider provider, Criteria criteria) {
Set<VertexRef> vertexRefs = new TreeSet<VertexRef>(new RefComparator());
List<Edge> edges = provider.getEdges(criteria);
for (Edge ncsEdge : edges) {
vertexRefs.add(ncsEdge.getSource().getVertex());
vertexRefs.add(ncsEdge.getTarget().getVertex());
}
return vertexRefs;
}
use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class EventsAlarmsOperation method execute.
@Override
public void execute(final List<VertexRef> targets, final OperationContext operationContext) {
try {
String label = "";
int nodeID = -1;
if (targets != null) {
for (final VertexRef target : targets) {
final String labelValue = getLabelValue(operationContext, target);
final Integer nodeValue = getNodeIdValue(operationContext, target);
if (nodeValue != null && nodeValue > 0) {
label = labelValue == null ? "" : labelValue;
nodeID = nodeValue;
break;
}
}
}
final Node node = new Node(nodeID, null, label);
final String eventUrl;
final String alarmUrl;
if (node.getNodeID() >= 0) {
eventUrl = getEventsURL() + "?filter=node%3D" + node.getNodeID();
alarmUrl = getAlarmsURL() + "?sortby=id&acktype=unacklimit=20&filter=node%3D" + node.getNodeID();
} else {
eventUrl = getEventsURL();
alarmUrl = getAlarmsURL();
}
final URL fullEventUrl = new URL(getFullUrl(eventUrl));
final URL fullAlarmUrl = new URL(getFullUrl(alarmUrl));
operationContext.getMainWindow().addWindow(new EventsAlarmsWindow(node, fullEventUrl, fullAlarmUrl));
} catch (final Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
throw new RuntimeException("Failed to create event/alarm window.", e);
}
}
}
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(eachLocation -> eachLocation.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(eachInterface -> eachInterface.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 VertexHopGraphProvider method getVertices.
@Override
public List<Vertex> getVertices(Criteria... criteria) {
// If we have a IgnoreHopCriteria, just return all existing vertices
for (Criteria criterium : criteria) {
try {
IgnoreHopCriteria ignoreHopCriteria = (IgnoreHopCriteria) criterium;
return m_delegate.getVertices();
} catch (ClassCastException e) {
}
}
// Otherwise consider vertices szl and focus nodes
Set<VertexRef> focusNodes = getFocusNodes(criteria);
int maxSemanticZoomLevel = getMaxSemanticZoomLevel(criteria);
// Clear the existing semantic zoom level values
m_semanticZoomLevels.clear();
int semanticZoomLevel = 0;
// If we didn't find any matching nodes among the focus nodes...
if (focusNodes.size() < 1) {
// ...then return an empty list of vertices
return Collections.emptyList();
// return allVertices;
}
Map<VertexRef, Set<VertexRef>> neighborMap = new HashMap<VertexRef, Set<VertexRef>>();
List<Edge> edges = m_delegate.getEdges(criteria);
for (Edge edge : edges) {
VertexRef src = edge.getSource().getVertex();
VertexRef tgt = edge.getTarget().getVertex();
Set<VertexRef> srcNeighbors = neighborMap.get(src);
if (srcNeighbors == null) {
srcNeighbors = new HashSet<VertexRef>();
neighborMap.put(src, srcNeighbors);
}
srcNeighbors.add(tgt);
Set<VertexRef> tgtNeighbors = neighborMap.get(tgt);
if (tgtNeighbors == null) {
tgtNeighbors = new HashSet<VertexRef>();
neighborMap.put(tgt, tgtNeighbors);
}
tgtNeighbors.add(src);
}
Set<Vertex> processed = new HashSet<Vertex>();
Set<VertexRef> neighbors = new HashSet<VertexRef>();
Set<VertexRef> workingSet = new HashSet<VertexRef>(focusNodes);
// Put a limit on the SZL in case we infinite loop for some reason
while (semanticZoomLevel <= maxSemanticZoomLevel && workingSet.size() > 0) {
neighbors.clear();
for (VertexRef vertexRef : workingSet) {
// Only consider Vertex if it is actually not filtered by the criteria (which it might)
Vertex vertex = getVertex(vertexRef, criteria);
if (vertex != null) {
if (m_semanticZoomLevels.containsKey(vertexRef)) {
throw new IllegalStateException("Calculating semantic zoom level for vertex that has already been calculated: " + vertexRef.toString());
}
m_semanticZoomLevels.put(vertexRef, semanticZoomLevel);
Set<VertexRef> refs = neighborMap.get(vertexRef);
if (refs != null) {
neighbors.addAll(refs);
}
processed.add(vertex);
}
}
neighbors.removeAll(processed);
workingSet.clear();
workingSet.addAll(neighbors);
// Increment the semantic zoom level
semanticZoomLevel++;
}
processed = collapseVertices(processed, getCollapsedCriteria(criteria));
return new ArrayList<Vertex>(processed);
}
Aggregations