use of org.opennms.features.topology.api.topo.Edge in project opennms by OpenNMS.
the class NCSEdgeProvider method getEdges.
/**
* This factory works by using {@link NCSServiceCriteria} to construct edges based on
* connecting all of the ServiceElements that make up a Service to each other.
*
* @param criteria An {@link NCSServiceCriteria} object
*/
@Override
public List<Edge> getEdges(Criteria... criteria) {
List<Edge> retval = new ArrayList<>();
for (Criteria criterium : criteria) {
try {
NCSServiceCriteria crit = (NCSServiceCriteria) criterium;
for (Long id : crit) {
NCSComponent service = m_dao.get(id);
if (service == null) {
LoggerFactory.getLogger(this.getClass()).warn("NCSComponent not found for ID {}", id);
} else {
// Check foreignsource of the subcomponents to make sure it matches the Service's foreignsource
NCSComponent[] subs = checkForeignSource(service.getForeignSource(), service.getSubcomponents());
// Connect all of the ServiceElements to one another
for (int i = 0; i < subs.length; i++) {
for (int j = i + 1; j < subs.length; j++) {
String foreignSource = null, foreignId = null;
OnmsNode sourceNode = null, targetNode = null;
NodeIdentification ident = subs[i].getNodeIdentification();
String sourceLabel = subs[i].getName();
if (ident != null) {
foreignSource = ident.getForeignSource();
foreignId = ident.getForeignId();
sourceNode = m_nodeDao.findByForeignId(foreignSource, foreignId);
if (sourceNode == null) {
continue;
}
if (sourceLabel == null) {
sourceLabel = sourceNode.getLabel();
}
}
ident = subs[j].getNodeIdentification();
String targetLabel = subs[j].getName();
if (ident != null) {
foreignSource = ident.getForeignSource();
foreignId = ident.getForeignId();
targetNode = m_nodeDao.findByForeignId(foreignSource, foreignId);
if (targetNode == null) {
continue;
}
if (targetLabel == null) {
targetLabel = targetNode.getLabel();
}
}
String sourceElementName = subs[i].getForeignSource() + "::" + subs[i].getForeignId();
String targetElementName = subs[j].getForeignSource() + "::" + subs[j].getForeignId();
retval.add(new NCSEdge(subs[i].getForeignId(), service.getName(), sourceElementName, targetElementName, new NCSVertex(String.valueOf(sourceNode.getId()), sourceLabel), new NCSVertex(String.valueOf(targetNode.getId()), targetLabel)));
}
}
}
}
} catch (ClassCastException e) {
}
}
return retval;
}
use of org.opennms.features.topology.api.topo.Edge in project opennms by OpenNMS.
the class NCSServicePath method getEdges.
public List<Edge> getEdges() {
List<Edge> edges = new ArrayList<>();
if (m_vertices.size() >= 2) {
String deviceA = m_vertices.get(0).getLabel();
String deviceZ = m_vertices.get(m_vertices.size() - 1).getLabel();
ListIterator<NCSVertex> iterator = m_vertices.listIterator();
while (iterator.hasNext()) {
NCSVertex sourceRef = iterator.next();
if (iterator.hasNext()) {
NCSVertex targetRef = m_vertices.get(iterator.nextIndex());
NCSPathEdge ncsPathEdge = new NCSPathEdge(m_serviceName, deviceA, deviceZ, sourceRef, targetRef);
ncsPathEdge.setStyleName("ncs edge direct");
edges.add(ncsPathEdge);
}
}
}
return edges;
}
use of org.opennms.features.topology.api.topo.Edge in project opennms by OpenNMS.
the class ShowNCSPathOperation method getVertexRefsForNCSService.
private Collection<VertexRef> getVertexRefsForNCSService(NCSServiceCriteria storedCriteria) {
List<Edge> edges = m_ncsEdgeProvider.getEdges(storedCriteria);
Set<VertexRef> vertRefList = new HashSet<>();
for (Edge edge : edges) {
vertRefList.add(edge.getSource().getVertex());
vertRefList.add(edge.getTarget().getVertex());
}
return vertRefList;
}
use of org.opennms.features.topology.api.topo.Edge in project opennms by OpenNMS.
the class VertexHopGraphProvider method collapseEdges.
/**
* This function assumes that all criteria passed in are marked as collapsed.
* @param edges
* @param criteria
* @return
*/
public static Set<Edge> collapseEdges(Set<Edge> edges, CollapsibleCriteria[] criteria) {
// Make a map of all of the vertices to their new collapsed representations
Map<VertexRef, Set<Vertex>> vertexToCollapsedVertices = getMapOfVerticesToCollapsedVertices(criteria);
if (vertexToCollapsedVertices.size() > 0) {
Set<Edge> retval = new HashSet<Edge>();
for (Edge edge : edges) {
// Add the original edge to retval unless we replace it with an edge that points to a
// collapsed vertex
boolean addOriginalEdge = true;
// If the source vertex is in the collapsed list...
Set<Vertex> collapsedSources = vertexToCollapsedVertices.get(edge.getSource().getVertex());
if (collapsedSources != null) {
for (VertexRef collapsedSource : collapsedSources) {
// Add a new edge with the source as the collapsed vertex
Edge newCollapsedEdge = edge.clone();
newCollapsedEdge.setId("collapsedSource-" + newCollapsedEdge.getId());
newCollapsedEdge.getSource().setVertex(collapsedSource);
retval.add(newCollapsedEdge);
}
// Since we just added a replacement edge, don't add the original
addOriginalEdge = false;
}
Set<Vertex> collapsedTargets = vertexToCollapsedVertices.get(edge.getTarget().getVertex());
if (collapsedTargets != null) {
for (VertexRef collapsedTarget : collapsedTargets) {
// Add a new edge with the target as the collapsed vertex
Edge newCollapsedEdge = edge.clone();
newCollapsedEdge.setId("collapsedTarget-" + newCollapsedEdge.getId());
newCollapsedEdge.getTarget().setVertex(collapsedTarget);
retval.add(newCollapsedEdge);
}
// Since we just added a replacement edge, don't add the original
addOriginalEdge = false;
}
//
if (collapsedSources != null && collapsedTargets != null) {
for (VertexRef collapsedEndpoint : collapsedSources) {
for (VertexRef collapsedTarget : collapsedTargets) {
// Add a new edge with the target as the collapsed vertex
Edge newCollapsedEdge = edge.clone();
newCollapsedEdge.setId("collapsed-" + newCollapsedEdge.getId());
newCollapsedEdge.getSource().setVertex(collapsedEndpoint);
newCollapsedEdge.getTarget().setVertex(collapsedTarget);
retval.add(newCollapsedEdge);
}
}
// Since we just added a replacement edge, don't add the original
addOriginalEdge = false;
}
// Add the original edge if it wasn't replaced with an edge to a collapsed vertex
if (addOriginalEdge) {
retval.add(edge);
}
}
return retval;
} else {
return edges;
}
}
use of org.opennms.features.topology.api.topo.Edge in project opennms by OpenNMS.
the class HierarchyLayoutAlgorithm method updateLayout.
/**
* Updates the current layout by extracting the containers graph and then perform a (x,y) tranformation
* of all vertices.
*
* @param graph The container of the current graph. Contains all relevant information to perform the transformation
* of the {@link Graph} by changing its {@link Layout}
*/
@Override
public void updateLayout(final Graph graph) {
final Layout graphLayout = graph.getLayout();
// fully level aware. See NMS-8703
if (isFullyLevelAware(graph)) {
final HierarchyLayout<VertexRef, Edge> treeLayout = createTreeLayout(graph);
applyLayoutPositions(graph.getDisplayVertices(), treeLayout, graphLayout);
} else {
// SEE NMS-8703
LOG.warn("The selected graph is not fully level aware. Cannot layout hierarchical. Falling back to D3 Layout");
new D3TopoLayoutAlgorithm().updateLayout(graph);
}
}
Aggregations