use of org.opennms.features.topology.api.topo.GraphProvider in project opennms by OpenNMS.
the class DefaultTopologyService method getGraph.
@Override
public Graph getGraph(String metaTopologyId, String namespace, Criteria[] criteria, int semanticZoomLevel) {
Objects.requireNonNull(metaTopologyId);
Objects.requireNonNull(namespace);
Objects.requireNonNull(metaTopologyId);
Objects.requireNonNull(criteria);
if (semanticZoomLevel < 0) {
LOG.warn("Semantic Zoom Level was {}. Only values >= 0 are allowed, forcing it to be 1", semanticZoomLevel);
semanticZoomLevel = 0;
}
final GraphProvider graphProvider = getGraphProvider(metaTopologyId, namespace);
// Determine visible vertices and edges
final List<Vertex> displayVertices = new ArrayList<>();
for (Vertex v : graphProvider.getVertices(criteria)) {
int vzl = graphProvider.getSemanticZoomLevel(v);
if (vzl == semanticZoomLevel || (vzl < semanticZoomLevel && !graphProvider.hasChildren(v))) {
displayVertices.add(v);
}
}
final Collection<Edge> displayEdges = graphProvider.getEdges(criteria);
// Create graph object
final DefaultGraph graph = new DefaultGraph(displayVertices, displayEdges);
// Calculate status
final StatusProvider vertexStatusProvider = serviceLocator != null ? findVertexStatusProvider(graphProvider) : null;
final EdgeStatusProvider edgeStatusProvider = serviceLocator != null ? findEdgeStatusProvider(graphProvider) : null;
if (vertexStatusProvider != null) {
graph.setVertexStatus(vertexStatusProvider.getStatusForVertices(graphProvider, new ArrayList<>(displayVertices), criteria));
}
if (edgeStatusProvider != null) {
graph.setEdgeStatus(edgeStatusProvider.getStatusForEdges(graphProvider, new ArrayList<>(graph.getDisplayEdges()), criteria));
}
return graph;
}
use of org.opennms.features.topology.api.topo.GraphProvider in project opennms by OpenNMS.
the class TopologyContextMenu method addNavigateToItems.
// adds menu items for the "navigate to" operation
private static void addNavigateToItems(MenuBuilder menuBuilder, List<VertexRef> targets, OperationContext operationContext) {
if (!targets.isEmpty()) {
menuBuilder.createPath("Navigate To");
final GraphContainer graphContainer = operationContext.getGraphContainer();
// Find the vertices in other graphs that this vertex links to
final Collection<VertexRef> oppositeVertices = graphContainer.getTopologyServiceClient().getOppositeVertices(targets.get(0));
// Find all namespaces
final Set<String> targetNamespaces = oppositeVertices.stream().map(VertexRef::getNamespace).collect(Collectors.toSet());
// Find provider for namespaces and add menu entry
for (String eachTargetNamespace : targetNamespaces) {
// Find the graph provider for the target namespace
final GraphProvider targetGraphProvider = graphContainer.getTopologyServiceClient().getGraphProviders().stream().filter(g -> g.getNamespace().equals(eachTargetNamespace)).findFirst().orElse(null);
if (targetGraphProvider == null) {
LOG.warn("No graph provider found for namespace '{}'.", eachTargetNamespace);
continue;
}
NavigationMenuItem item = new NavigationMenuItem(targetGraphProvider, targets.get(0));
menuBuilder.addMenuItem(item, "Navigate To");
}
}
}
use of org.opennms.features.topology.api.topo.GraphProvider in project opennms by OpenNMS.
the class CategoryHopCriteria method getVertices.
@Override
public Set<VertexRef> getVertices() {
OnmsCategory category = categoryProvider.findCategoryByName(m_categoryName);
if (category == null) {
return Collections.emptySet();
} else {
List<OnmsNode> nodes = categoryProvider.findNodesForCategory(category);
List<Integer> nodeIds = nodes.stream().map(n -> n.getId()).collect(Collectors.toList());
GraphProvider graphProvider = graphContainer.getTopologyServiceClient().getGraphProviderBy(graphContainer.getTopologyServiceClient().getNamespace());
return graphProvider.getVertices(new IgnoreHopCriteria()).stream().filter(v -> v.getNodeID() != null).filter(v -> nodeIds.contains(v.getNodeID())).collect(Collectors.toSet());
}
}
use of org.opennms.features.topology.api.topo.GraphProvider in project opennms by OpenNMS.
the class GraphMLMetaTopologyFactory method updated.
@Override
public void updated(String pid, @SuppressWarnings("rawtypes") Dictionary properties) throws ConfigurationException {
LOG.debug("updated(String, Dictionary) invoked");
String location = (String) properties.get(TOPOLOGY_LOCATION);
if (!m_serviceRegistration.containsKey(pid)) {
LOG.debug("Service with pid '{}' is new. Register {}", pid, GraphMLMetaTopologyProvider.class.getSimpleName());
final Dictionary<String, Object> metaData = new Hashtable<>();
metaData.put(Constants.SERVICE_PID, pid);
if (properties.get(LABEL) != null) {
metaData.put(LABEL, properties.get(LABEL));
}
// Expose the MetaTopologyProvider
try {
final GraphMLMetaTopologyProvider metaTopologyProvider = new GraphMLMetaTopologyProvider(m_serviceAccessor);
metaTopologyProvider.setTopologyLocation(location);
metaTopologyProvider.reload();
registerService(pid, MetaTopologyProvider.class, metaTopologyProvider, metaData);
// Create and register additional services
final Set<String> iconKeys = metaTopologyProvider.getGraphProviders().stream().map(GraphProvider::getNamespace).flatMap(eachNamespace -> metaTopologyProvider.getRawTopologyProvider(eachNamespace).getVertices().stream()).map(Vertex::getIconKey).filter(Objects::nonNull).collect(Collectors.toSet());
registerService(pid, IconRepository.class, new GraphMLIconRepository(iconKeys));
// Create an OSGi aware script engine manager
final ScriptEngineManager scriptEngineManager = new OSGiScriptEngineManager(m_bundleContext);
metaTopologyProvider.getGraphProviders().forEach(it -> {
// Find Topology Provider
final GraphMLTopologyProvider rawTopologyProvider = metaTopologyProvider.getRawTopologyProvider(it.getNamespace());
// EdgeStatusProvider
registerService(pid, EdgeStatusProvider.class, new GraphMLEdgeStatusProvider(rawTopologyProvider, scriptEngineManager, m_serviceAccessor));
// SearchProvider
registerService(pid, SearchProvider.class, new GraphMLSearchProvider(rawTopologyProvider));
// Vertex Status Provider
// Only add status provider if explicitly set in GraphML document
this.buildStatusProvider(metaTopologyProvider, scriptEngineManager, rawTopologyProvider).ifPresent(statusProvider -> registerService(pid, StatusProvider.class, statusProvider));
});
} catch (InvalidGraphException | IOException e) {
LOG.error("An error occurred while loading GraphMLTopology from file {}. Ignoring...", location, e);
}
} else {
LOG.warn("Service with pid '{}' updated. Updating is not supported. Ignoring...");
}
}
use of org.opennms.features.topology.api.topo.GraphProvider 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);
}
}
Aggregations