use of org.opennms.features.topology.api.topo.EdgeRef in project opennms by OpenNMS.
the class ISOMLayoutAlgorithm method updateLayout.
@Override
public void updateLayout(final 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());
}
NonStupidISOMLayout layout = new NonStupidISOMLayout(jungGraph, graphLayout);
layout.setInitializer(initializer(graphLayout));
layout.setSize(selectLayoutSize(graph));
while (!layout.done()) {
layout.step();
}
for (Vertex v : vertices) {
graphLayout.setLocation(v, new Point(layout.getX(v), layout.getY(v)));
}
}
use of org.opennms.features.topology.api.topo.EdgeRef in project opennms by OpenNMS.
the class GraphMLEdgeStatusProvider method getStatusForEdges.
@Override
public Map<EdgeRef, Status> getStatusForEdges(EdgeProvider edgeProvider, Collection<EdgeRef> edges, Criteria[] criteria) {
final List<StatusScript> scripts = Lists.newArrayList();
try (final DirectoryStream<Path> stream = Files.newDirectoryStream(getScriptPath())) {
for (final Path path : stream) {
// ignore readme
if (".readme".equals(path.getFileName().toString())) {
LOG.debug("Skipping .readme");
continue;
}
final String extension = FilenameUtils.getExtension(path.toString());
final ScriptEngine scriptEngine = this.scriptEngineManager.getEngineByExtension(extension);
if (scriptEngine == null) {
LOG.warn("No script engine found for extension '{}'", extension);
continue;
}
LOG.debug("Found script: path={}, extension={}, engine={}", path, extension, scriptEngine);
try (final Stream<String> lines = Files.lines(path, Charset.defaultCharset())) {
final String source = lines.collect(Collectors.joining("\n"));
scripts.add(new StatusScript(scriptEngine, source));
}
}
} catch (final IOException e) {
LOG.error("Failed to walk template directory: {}", getScriptPath());
return Collections.emptyMap();
}
return serviceAccessor.getTransactionOperations().execute(transactionStatus -> edges.stream().filter(eachEdge -> eachEdge instanceof GraphMLEdge).map(edge -> (GraphMLEdge) edge).map(edge -> new HashMap.SimpleEntry<>(edge, computeEdgeStatus(scripts, edge))).filter(e -> e.getValue() != null).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
}
use of org.opennms.features.topology.api.topo.EdgeRef 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.EdgeRef in project opennms by OpenNMS.
the class D3LayoutTest method testD3Layout.
@Test
public void testD3Layout() throws IOException {
Graph g = m_graphContainer.getGraph();
List<Vertex> vertices = new ArrayList<>(g.getDisplayVertices());
D3TopoLayout<VertexRef, EdgeRef> layout = runD3Layout(1, g, g.getLayout(), vertices);
Vertex v1 = vertices.get(0);
Vertex v2 = vertices.get(1);
Vertex v3 = vertices.get(2);
double distance = calcDistance(layout, v1, v2);
double distance2 = calcDistance(layout, v2, v3);
double distance3 = calcDistance(layout, v1, v3);
LOG.info("distance: " + distance);
LOG.info("distance2: " + distance2);
LOG.info("distance3: " + distance3);
D3TopoLayout<VertexRef, EdgeRef> layout2 = runD3Layout(2, g, g.getLayout(), vertices);
distance = calcDistance(layout2, v1, v2);
distance2 = calcDistance(layout2, v2, v3);
distance3 = calcDistance(layout2, v1, v3);
LOG.info("distance: " + distance);
LOG.info("distance2: " + distance2);
LOG.info("distance3: " + distance3);
D3TopoLayout<VertexRef, EdgeRef> layout3 = runD3Layout(3, g, g.getLayout(), vertices);
distance = calcDistance(layout3, v1, v2);
distance2 = calcDistance(layout3, v2, v3);
distance3 = calcDistance(layout3, v1, v3);
LOG.info("distance: " + distance);
LOG.info("distance2: " + distance2);
LOG.info("distance3: " + distance3);
}
use of org.opennms.features.topology.api.topo.EdgeRef 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;
}
Aggregations