use of org.opennms.features.topology.api.topo.Edge in project opennms by OpenNMS.
the class BreadcrumbPathCalculator method getIncomingEdgeMap.
static Map<VertexRef, EdgeRef> getIncomingEdgeMap(TopologyServiceClient topologyServiceClient) {
// Convert to JUNG graph
// We build one big graph out of all graph providers in order to determine the shortest path between each vertex
// when we want to calculate the SHORTEST_PATH_TO_ROOT
final DirectedSparseGraph<VertexRef, EdgeRef> sparseGraph = new DirectedSparseGraph<>();
topologyServiceClient.getGraphProviders().forEach(eachGraph -> {
for (Vertex eachVertex : eachGraph.getVertices(new IgnoreHopCriteria())) {
sparseGraph.addVertex(eachVertex);
}
for (EdgeRef eachEdge : eachGraph.getEdges()) {
sparseGraph.addEdge(eachEdge, ((Edge) eachEdge).getSource().getVertex(), ((Edge) eachEdge).getTarget().getVertex());
}
});
// Link the layers
final IdGenerator idGenerator = new IdGenerator();
sparseGraph.getVertices().forEach(eachVertex -> {
topologyServiceClient.getOppositeVertices(eachVertex).forEach(oppositeVertex -> {
sparseGraph.addEdge(new AbstractEdge("$$outer-space$$", "" + idGenerator.nextId(), eachVertex, oppositeVertex), eachVertex, oppositeVertex);
});
});
// Create dummy root
sparseGraph.addVertex(rootVertex);
for (Vertex eachVertex : topologyServiceClient.getDefaultGraphProvider().getVertices(new IgnoreHopCriteria())) {
sparseGraph.addEdge(new AbstractEdge("$$outer-space$$", "" + idGenerator.nextId(), rootVertex, eachVertex), rootVertex, eachVertex);
}
// Build shortest path for graph
final UnweightedShortestPath<VertexRef, EdgeRef> shortestPath = new UnweightedShortestPath<>(sparseGraph);
Map<VertexRef, EdgeRef> incomingEdgeMap = shortestPath.getIncomingEdgeMap(rootVertex);
return incomingEdgeMap;
}
use of org.opennms.features.topology.api.topo.Edge in project opennms by OpenNMS.
the class D3LayoutTest method createJungGraph.
private SparseGraph<VertexRef, EdgeRef> createJungGraph(Graph g) {
SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<>();
Collection<Vertex> vertices = g.getDisplayVertices();
for (Vertex v : vertices) {
jungGraph.addVertex(v);
}
Collection<Edge> edges = g.getDisplayEdges();
for (Edge e : edges) {
jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
}
return jungGraph;
}
use of org.opennms.features.topology.api.topo.Edge in project opennms by OpenNMS.
the class FRLayoutTest method createJungGraph.
private SparseGraph<VertexRef, EdgeRef> createJungGraph(Graph g) {
SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<>();
Collection<Vertex> vertices = g.getDisplayVertices();
for (Vertex v : vertices) {
jungGraph.addVertex(v);
}
Collection<Edge> edges = g.getDisplayEdges();
for (Edge e : edges) {
jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
}
return jungGraph;
}
use of org.opennms.features.topology.api.topo.Edge in project opennms by OpenNMS.
the class TestGraph method visit.
@Override
public void visit(GraphVisitor visitor) throws Exception {
visitor.visitGraph(this);
for (Vertex v : vertices) {
visitor.visitVertex(v);
}
for (Edge e : edges) {
visitor.visitEdge(e);
}
visitor.completeGraph(this);
}
use of org.opennms.features.topology.api.topo.Edge in project opennms by OpenNMS.
the class BusinessServicesTopologyProvider method addVertex.
private void addVertex(BusinessServiceGraph graph, GraphVertex graphVertex, AbstractBusinessServiceVertex topologyVertex) {
if (topologyVertex == null) {
// Create a topology vertex for the current vertex
topologyVertex = createTopologyVertex(graphVertex);
addVertices(topologyVertex);
}
for (GraphEdge graphEdge : graph.getOutEdges(graphVertex)) {
GraphVertex childVertex = graph.getOpposite(graphVertex, graphEdge);
// Create a topology vertex for the child vertex
AbstractBusinessServiceVertex childTopologyVertex = createTopologyVertex(childVertex);
graph.getInEdges(childVertex).stream().map(GraphEdge::getFriendlyName).filter(s -> !Strings.isNullOrEmpty(s)).findFirst().ifPresent(childTopologyVertex::setLabel);
addVertices(childTopologyVertex);
// Connect the two
childTopologyVertex.setParent(topologyVertex);
Edge edge = new BusinessServiceEdge(graphEdge, topologyVertex, childTopologyVertex);
addEdges(edge);
// Recurse
addVertex(graph, childVertex, childTopologyVertex);
}
}
Aggregations