use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class RealUltimateLayoutAlgorithm method updateLayout.
@Override
public void updateLayout(Graph graph) {
final Layout graphLayout = graph.getLayout();
SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>();
Collection<? extends Vertex> vertices = graph.getDisplayVertices();
for (Vertex v : vertices) {
jungGraph.addVertex(v);
}
Collection<? extends Edge> edges = graph.getDisplayEdges();
for (Edge e : edges) {
jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
}
Dimension size = selectLayoutSize(graph);
Dimension paddedSize = new Dimension((int) (size.getWidth() * .75), (int) (size.getHeight() * .75));
doISOMLayout(graphLayout, jungGraph, size);
doSpringLayout(graphLayout, jungGraph, size, SPRING_LAYOUT_REPULSION);
doFRLayout(graphLayout, jungGraph, paddedSize, (int) (size.getWidth() / 8.0), (int) (size.getHeight() / 8.0));
doSpringLayout(graphLayout, jungGraph, size, SPRING_LAYOUT_REPULSION);
}
use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class HierarchyLayoutAlgorithm method convert.
private edu.uci.ics.jung.graph.DirectedGraph<VertexRef, Edge> convert(final Graph g) {
if (!isFullyLevelAware(g)) {
throw new IllegalStateException("The graph is not LevelAware. Cannot apply Hierarchy Layout. Aborting");
}
// We need to sort the elements. For this purpose we use the DirectedOrderedSparseMultigraph
final edu.uci.ics.jung.graph.DirectedGraph<VertexRef, Edge> jungGraph = new DirectedOrderedSparseMultigraph<>();
final Collection<Vertex> displayVertices = g.getDisplayVertices();
// Sort by level
final List<Vertex> sortedVertices = displayVertices.stream().filter(v -> v instanceof LevelAware).sorted(new Comparator<Vertex>() {
@Override
public int compare(Vertex o1, Vertex o2) {
return Integer.compare(((LevelAware) o1).getLevel(), ((LevelAware) o2).getLevel());
}
}).collect(Collectors.toList());
// Build the graph
for (VertexRef v : sortedVertices) {
jungGraph.addVertex(v);
}
// The order of edges does not matter
for (Edge e : g.getDisplayEdges()) {
jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
}
return jungGraph;
}
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;
}
use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class GraphMLSearchProvider method onFocusSearchResult.
@Override
public void onFocusSearchResult(SearchResult searchResult, OperationContext operationContext) {
final GraphContainer graphContainer = operationContext.getGraphContainer();
final DefaultVertexRef vertexRef = new DefaultVertexRef(searchResult.getNamespace(), searchResult.getId(), searchResult.getLabel());
if (graphContainer.getTopologyServiceClient().getVertex(vertexRef) == null) {
// The vertex to add to focus is not in the current layer
// Find the GraphProvider it belongs to
Optional<GraphProvider> first = graphContainer.getTopologyServiceClient().getGraphProviders().stream().filter(eachProvider -> eachProvider.getNamespace().equals(searchResult.getNamespace())).findFirst();
// If there is a graph provider (which should) select it
if (first.isPresent() && first.get().getVertex(vertexRef) != null) {
graphContainer.selectTopologyProvider(first.get());
graphContainer.clearCriteria();
}
}
super.onFocusSearchResult(searchResult, operationContext);
}
use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class GraphMLVertexStatusProvider method getStatusForVertices.
@Override
public Map<VertexRef, Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
// All vertices for the current vertexProvider
final List<GraphMLVertex> graphMLVertices = vertices.stream().filter(eachVertex -> contributesTo(eachVertex.getNamespace()) && eachVertex instanceof GraphMLVertex).map(eachVertex -> (GraphMLVertex) eachVertex).collect(Collectors.toList());
// All vertices associated with a node id
final Map<Integer, VertexRef> nodeIdMap = graphMLVertices.stream().filter(eachVertex -> eachVertex.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 (GraphMLVertex eachVertex : graphMLVertices) {
AlarmSummary alarmSummary = nodeIdToAlarmSummaryMap.get(eachVertex.getNodeID());
DefaultStatus status = alarmSummary == null ? new VertexStatus(OnmsSeverity.NORMAL) : new VertexStatus(alarmSummary.getMaxSeverity(), alarmSummary.getAlarmCount());
resultMap.put(eachVertex, status);
}
return resultMap;
}
Aggregations