use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class BreadcrumbCriteria method handleClick.
public void handleClick(Breadcrumb breadcrumb, GraphContainer graphContainer) {
final GraphProvider targetGraphProvider = graphContainer.getTopologyServiceClient().getGraphProviderBy(breadcrumb.getTargetNamespace());
if (isLeaf(breadcrumb)) {
if (breadcrumb.getSourceVertices().isEmpty()) {
final List<VertexRef> defaultFocus = targetGraphProvider.getDefaults().getCriteria().stream().filter(c -> c instanceof VertexHopGraphProvider.VertexHopCriteria).map(c -> ((VertexHopGraphProvider.VertexHopCriteria) c).getVertices()).flatMap(Set::stream).collect(Collectors.toList());
handleClick(graphContainer, targetGraphProvider, defaultFocus, breadcrumb);
} else {
List<VertexRef> oppositeVertices = breadcrumb.getSourceVertices().stream().flatMap(sourceVertex -> getOppositeVertices(graphContainer, breadcrumb.getTargetNamespace(), sourceVertex).stream()).collect(Collectors.toList());
handleClick(graphContainer, targetGraphProvider, oppositeVertices, breadcrumb);
}
} else {
Breadcrumb next = getNext(breadcrumb);
handleClick(graphContainer, targetGraphProvider, next.getSourceVertices(), breadcrumb);
}
}
use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class VertexHopGraphProviderTest method testCollapseEdges.
@Test
public void testCollapseEdges() {
CollapsibleCriteria collapseMe = new CollapsibleCriteria() {
@Override
public void setCollapsed(boolean collapsed) {
}
@Override
public boolean isCollapsed() {
return true;
}
@Override
public Set<VertexRef> getVertices() {
Set<VertexRef> retval = new HashSet<>();
retval.add(new DefaultVertexRef("nodes", "g2"));
return retval;
}
@Override
public String getNamespace() {
return "nodes";
}
@Override
public String getLabel() {
return "Test Criteria";
}
@Override
public String getId() {
return "Test Criteria";
}
@Override
public Vertex getCollapsedRepresentation() {
return new AbstractVertex("category", "c");
}
};
Set<Edge> edges = VertexHopGraphProvider.collapseEdges(new HashSet<Edge>(m_provider.getEdges()), new CollapsibleCriteria[] { collapseMe });
for (Edge edge : edges) {
assertEquals("nodes", edge.getNamespace());
/*
Here's the original list of edges
.edge("e1", "g0", "g1").eLabel("edge1").eStyleName("edge")
.edge("e2", "g0", "g2").eLabel("edge2").eStyleName("edge")
.edge("e3", "g1", "v1").eLabel("edge3").eStyleName("edge")
.edge("e4", "g1", "v2").eLabel("edge4").eStyleName("edge")
.edge("e5", "g2", "v3").eLabel("edge5").eStyleName("edge")
.edge("e6", "g2", "v4").eLabel("edge6").eStyleName("edge")
*/
if (edge.getId().equals("e1")) {
assertEquals("nodes", edge.getSource().getVertex().getNamespace());
assertEquals("g0", edge.getSource().getVertex().getId());
assertEquals("nodes", edge.getTarget().getVertex().getNamespace());
assertEquals("g1", edge.getTarget().getVertex().getId());
} else if (edge.getId().equals("collapsedTarget-e2")) {
assertEquals("nodes", edge.getSource().getVertex().getNamespace());
assertEquals("g0", edge.getSource().getVertex().getId());
assertEquals("category", edge.getTarget().getVertex().getNamespace());
assertEquals("c", edge.getTarget().getVertex().getId());
} else if (edge.getId().equals("e3")) {
assertEquals("nodes", edge.getSource().getVertex().getNamespace());
assertEquals("g1", edge.getSource().getVertex().getId());
assertEquals("nodes", edge.getTarget().getVertex().getNamespace());
assertEquals("v1", edge.getTarget().getVertex().getId());
} else if (edge.getId().equals("e4")) {
assertEquals("nodes", edge.getSource().getVertex().getNamespace());
assertEquals("g1", edge.getSource().getVertex().getId());
assertEquals("nodes", edge.getTarget().getVertex().getNamespace());
assertEquals("v2", edge.getTarget().getVertex().getId());
} else if (edge.getId().equals("collapsedSource-e5")) {
assertEquals("category", edge.getSource().getVertex().getNamespace());
assertEquals("c", edge.getSource().getVertex().getId());
assertEquals("nodes", edge.getTarget().getVertex().getNamespace());
assertEquals("v3", edge.getTarget().getVertex().getId());
} else if (edge.getId().equals("collapsedSource-e6")) {
assertEquals("category", edge.getSource().getVertex().getNamespace());
assertEquals("c", edge.getSource().getVertex().getId());
assertEquals("nodes", edge.getTarget().getVertex().getNamespace());
assertEquals("v4", edge.getTarget().getVertex().getId());
} else {
fail("Unexpected edge found: " + edge.toString());
}
}
}
use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class AlarmSearchProvider method getVertexRefsBy.
// FIXME so that the focus button works.???
@Override
public Set<VertexRef> getVertexRefsBy(SearchResult searchResult, GraphContainer container) {
LOG.debug("SearchProvider.getVertexRefsBy: called with search result: '{}'", searchResult);
Criteria criterion = findCriterion(searchResult, container);
Set<VertexRef> vertices = ((AlarmHopCriteria) criterion).getVertices();
LOG.debug("SearchProvider.getVertexRefsBy: found '{}' vertices.", vertices.size());
return vertices;
}
use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class TopologyComponent method computeBoundsForSelected.
private void computeBoundsForSelected(SelectionContext selectionContext) {
if (selectionContext.getSelectedVertexRefs().size() > 0) {
Collection<? extends Vertex> visible = m_graphContainer.getGraph().getDisplayVertices();
Collection<VertexRef> selected = selectionContext.getSelectedVertexRefs();
Collection<VertexRef> vRefs = new ArrayList<>();
for (VertexRef vRef : selected) {
if (visible.contains(vRef)) {
vRefs.add(vRef);
}
}
getViewManager().setBoundingBox(m_graphContainer.getGraph().getLayout().computeBoundingBox(vRefs));
} else {
getViewManager().setBoundingBox(m_graphContainer.getGraph().getLayout().getBounds());
}
}
use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class PathOutageStatusProvider method getStatusForVertices.
@Override
public Map<VertexRef, Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
final List<Integer> nodeIds = vertices.stream().filter(v -> v.getNamespace().equals(getNamespace())).map(v -> (PathOutageVertex) v).map(v -> v.getNodeID()).collect(Collectors.toList());
if (nodeIds.isEmpty()) {
return new HashMap<>();
}
// Preparing database request
final StringBuilder hql = new StringBuilder();
hql.append("SELECT node.id, max(event.eventSeverity) ");
hql.append("FROM OnmsOutage as outage ");
hql.append("LEFT JOIN outage.monitoredService as ifservice ");
hql.append("LEFT JOIN ifservice.ipInterface as ipinterface ");
hql.append("LEFT JOIN ipinterface.node as node ");
hql.append("LEFT JOIN outage.serviceLostEvent as event ");
hql.append("WHERE node.id in (:nodeIds) ");
hql.append("AND outage.serviceRegainedEvent is null ");
hql.append("GROUP BY node.id");
final List<String> paramNames = Lists.newArrayList("nodeIds");
final List<Object> paramValues = new ArrayList();
paramValues.add(Lists.newArrayList(nodeIds));
final List<Object[]> retvals = this.persistenceAccessor.findUsingNamedParameters(hql.toString(), paramNames.toArray(new String[paramNames.size()]), paramValues.toArray());
// Generating alarms map
final Map<Integer, OnmsSeverity> mappedAlarms = new HashedMap();
for (int i = 0; i < retvals.size(); i++) {
final Integer nodeId = (Integer) retvals.get(i)[0];
final Integer severity = Optional.ofNullable((Integer) retvals.get(i)[1]).orElse(OnmsSeverity.NORMAL.ordinal());
mappedAlarms.put(nodeId, OnmsSeverity.get(severity));
}
final Map<VertexRef, Status> status = vertices.stream().map(v -> (PathOutageVertex) v).collect(Collectors.toMap(v -> v, v -> {
if (!mappedAlarms.containsKey(v.getNodeID())) {
return new DefaultStatus(OnmsSeverity.NORMAL.getLabel(), 0);
} else {
return new DefaultStatus(mappedAlarms.get(v.getNodeID()).getLabel(), 0);
}
}));
return status;
}
Aggregations