use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class ManualLayoutAlgorithmTest method verifyLayoutCoordinatesHavePriority.
/*
* If persisted layout is defined, verify that it has priority.
*/
@Test
public void verifyLayoutCoordinatesHavePriority() {
final GraphProvider graphProvider = new SimpleGraphBuilder("dummy").vertex("vertex1").vX(1).vY(1).get();
final ManualTest test = new ManualTest(graphProvider);
final LayoutEntity persistedLayout = new LayoutEntity();
int x = 5;
int y = 5;
for (VertexRef eachVertex : graphProvider.getVertices()) {
VertexPositionEntity vertexPositionEntity = new VertexPositionEntity();
vertexPositionEntity.setVertexRef(LayoutManager.toVertexRefEntity(eachVertex));
vertexPositionEntity.setPosition(new PointEntity(x++, y++));
persistedLayout.addVertexPosition(vertexPositionEntity);
}
Mockito.when(test.layoutManager.loadLayout(test.graph)).thenReturn(persistedLayout);
new ManualLayoutAlgorithm(test.layoutManager).updateLayout(test.graph);
Assert.assertEquals(ImmutableMap.builder().put(new DefaultVertexRef("dummy", "vertex1"), new Point(5, 5)).build(), test.layout.getLocations());
}
use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class OSGiVerticesUpdateManagerTest method createContextWithVertRefIds.
private SelectionContext createContextWithVertRefIds(int... vertIds) {
SelectionContext context = new DefaultSelectionManager(createGraph());
List<VertexRef> vertices = createVertexRefsWithIds(vertIds);
context.setSelectedVertexRefs(vertices);
return context;
}
use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class D3TopoLayoutAlgorithm method updateLayout.
@Override
public void updateLayout(Graph graph) {
final Layout graphLayout = graph.getLayout();
SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>();
Collection<Vertex> vertices = graph.getDisplayVertices();
for (Vertex v : vertices) {
jungGraph.addVertex(v);
}
Collection<Edge> edges = graph.getDisplayEdges();
for (Edge e : edges) {
jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
}
D3TopoLayout<VertexRef, EdgeRef> layout = new D3TopoLayout<VertexRef, EdgeRef>(jungGraph);
// Initialize the vertex positions to the last known positions from the layout
Dimension size = selectLayoutSize(graph);
layout.setInitializer(initializer(graphLayout, (int) size.getWidth() / 2, (int) size.getHeight() / 2));
// Resize the graph to accommodate the number of vertices
layout.setSize(size);
while (!layout.done()) {
layout.step();
}
// Store the new positions in the layout
for (Vertex v : vertices) {
graphLayout.setLocation(v, new Point(layout.getX(v) - (size.getWidth() / 2), layout.getY(v) - (size.getHeight() / 2)));
}
}
use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class ApplicationStatusProvider method getStatusForVertices.
@Override
public Map<VertexRef, Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
Map<VertexRef, Status> returnMap = new HashMap<>();
Map<ApplicationStatusEntity.Key, Status> statusMap = new HashMap<>();
List<ApplicationStatusEntity> result = applicationDao.getAlarmStatus();
for (ApplicationStatusEntity eachRow : result) {
DefaultStatus status = createStatus(eachRow.getSeverity(), eachRow.getCount());
statusMap.put(eachRow.getKey(), status);
}
// status for all known node ids
Collection<VertexRef> vertexRefsForNamespace = getVertexRefsForNamespace(vertices);
Collection<VertexRef> vertexRefsRoot = getRootElements(vertexRefsForNamespace);
Collection<VertexRef> vertexRefs = new ArrayList<>(vertexRefsForNamespace);
vertexRefs.removeAll(vertexRefsRoot);
// calculate status for children
for (VertexRef eachVertex : vertexRefs) {
ApplicationVertex applicationVertex = (ApplicationVertex) eachVertex;
Status alarmStatus = statusMap.get(createKey(applicationVertex));
if (alarmStatus == null) {
alarmStatus = createStatus(OnmsSeverity.NORMAL, 0);
}
returnMap.put(eachVertex, alarmStatus);
}
// calculate status for root
for (VertexRef eachRoot : vertexRefsRoot) {
ApplicationVertex eachRootApplication = (ApplicationVertex) eachRoot;
OnmsSeverity maxSeverity = OnmsSeverity.NORMAL;
int count = 0;
for (VertexRef eachChild : eachRootApplication.getChildren()) {
ApplicationVertex eachChildApplication = (ApplicationVertex) eachChild;
ApplicationStatusEntity.Key childKey = createKey(eachChildApplication);
Status childStatus = statusMap.get(childKey);
if (childStatus != null && maxSeverity.isLessThan(createSeverity(childStatus.computeStatus()))) {
maxSeverity = createSeverity(childStatus.computeStatus());
count = Integer.parseInt(childStatus.getStatusProperties().get("statusCount"));
}
}
returnMap.put(eachRoot, createStatus(maxSeverity, count));
}
return returnMap;
}
use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class ResourceGraphsOperation 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.intValue();
break;
}
}
}
final Node node = new Node(nodeID, null, label);
final String url;
if (node.getNodeID() >= 0) {
url = getResourceGraphNodeURL() + "[" + node.getNodeID() + "]";
} else {
url = getResourceGraphListURL();
}
final URL fullUrl = new URL(getFullUrl(url));
operationContext.getMainWindow().addWindow(new ResourceGraphsWindow(node, fullUrl));
} catch (final Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
throw new RuntimeException("Failed to create resource graph window.", e);
}
}
}
Aggregations