Search in sources :

Example 6 with GraphProvider

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;
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) EdgeStatusProvider(org.opennms.features.topology.api.topo.EdgeStatusProvider) EdgeStatusProvider(org.opennms.features.topology.api.topo.EdgeStatusProvider) StatusProvider(org.opennms.features.topology.api.topo.StatusProvider) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) ArrayList(java.util.ArrayList) Edge(org.opennms.features.topology.api.topo.Edge)

Example 7 with GraphProvider

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");
        }
    }
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 8 with GraphProvider

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());
    }
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) Constants(org.opennms.features.topology.api.Constants) SearchResult(org.opennms.features.topology.api.topo.SearchResult) Vertex(org.opennms.features.topology.api.topo.Vertex) Set(java.util.Set) CategoryProvider(org.opennms.features.topology.app.internal.CategoryProvider) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) Objects(java.util.Objects) GroupRef(org.opennms.features.topology.api.topo.GroupRef) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) List(java.util.List) IgnoreHopCriteria(org.opennms.features.topology.api.support.IgnoreHopCriteria) SearchCriteria(org.opennms.features.topology.api.topo.SearchCriteria) VertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.VertexHopCriteria) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Collections(java.util.Collections) OnmsNode(org.opennms.netmgt.model.OnmsNode) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) IgnoreHopCriteria(org.opennms.features.topology.api.support.IgnoreHopCriteria) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider)

Example 9 with GraphProvider

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...");
    }
}
Also used : GraphMLSearchProvider(org.opennms.features.topology.plugins.topo.graphml.GraphMLSearchProvider) Constants(org.osgi.framework.Constants) Vertex(org.opennms.features.topology.api.topo.Vertex) LoggerFactory(org.slf4j.LoggerFactory) EdgeStatusProvider(org.opennms.features.topology.api.topo.EdgeStatusProvider) OSGiScriptEngineManager(org.opennms.features.osgi.script.OSGiScriptEngineManager) GraphMLPropagateVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLPropagateVertexStatusProvider) Lists(com.google.common.collect.Lists) ConfigurationException(org.osgi.service.cm.ConfigurationException) Map(java.util.Map) InvalidGraphException(org.opennms.features.graphml.model.InvalidGraphException) IconRepository(org.opennms.features.topology.api.IconRepository) Hashtable(java.util.Hashtable) SearchProvider(org.opennms.features.topology.api.topo.SearchProvider) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) ServiceRegistration(org.osgi.framework.ServiceRegistration) ManagedServiceFactory(org.osgi.service.cm.ManagedServiceFactory) Logger(org.slf4j.Logger) Set(java.util.Set) ScriptEngineManager(javax.script.ScriptEngineManager) GraphMLTopologyProvider(org.opennms.features.topology.plugins.topo.graphml.GraphMLTopologyProvider) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) MetaTopologyProvider(org.opennms.features.topology.api.topo.MetaTopologyProvider) BundleContext(org.osgi.framework.BundleContext) Objects(java.util.Objects) List(java.util.List) StatusProvider(org.opennms.features.topology.api.topo.StatusProvider) GraphMLDefaultVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLDefaultVertexStatusProvider) GraphMLEdgeStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLEdgeStatusProvider) Optional(java.util.Optional) GraphMLMetaTopologyProvider(org.opennms.features.topology.plugins.topo.graphml.GraphMLMetaTopologyProvider) GraphMLScriptVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLScriptVertexStatusProvider) Dictionary(java.util.Dictionary) Vertex(org.opennms.features.topology.api.topo.Vertex) GraphMLTopologyProvider(org.opennms.features.topology.plugins.topo.graphml.GraphMLTopologyProvider) OSGiScriptEngineManager(org.opennms.features.osgi.script.OSGiScriptEngineManager) InvalidGraphException(org.opennms.features.graphml.model.InvalidGraphException) Hashtable(java.util.Hashtable) EdgeStatusProvider(org.opennms.features.topology.api.topo.EdgeStatusProvider) GraphMLPropagateVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLPropagateVertexStatusProvider) StatusProvider(org.opennms.features.topology.api.topo.StatusProvider) GraphMLDefaultVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLDefaultVertexStatusProvider) GraphMLEdgeStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLEdgeStatusProvider) GraphMLScriptVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLScriptVertexStatusProvider) GraphMLMetaTopologyProvider(org.opennms.features.topology.plugins.topo.graphml.GraphMLMetaTopologyProvider) OSGiScriptEngineManager(org.opennms.features.osgi.script.OSGiScriptEngineManager) ScriptEngineManager(javax.script.ScriptEngineManager) IOException(java.io.IOException) GraphMLEdgeStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLEdgeStatusProvider) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) GraphMLSearchProvider(org.opennms.features.topology.plugins.topo.graphml.GraphMLSearchProvider)

Example 10 with GraphProvider

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);
    }
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) VertexHopGraphProvider(org.opennms.features.topology.api.support.VertexHopGraphProvider) Objects(java.util.Objects) Callbacks(org.opennms.features.topology.api.Callbacks) List(java.util.List) Lists(com.google.common.collect.Lists) Criteria(org.opennms.features.topology.api.topo.Criteria) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Collections(java.util.Collections) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) VertexHopGraphProvider(org.opennms.features.topology.api.support.VertexHopGraphProvider) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) VertexHopGraphProvider(org.opennms.features.topology.api.support.VertexHopGraphProvider) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Aggregations

GraphProvider (org.opennms.features.topology.api.topo.GraphProvider)12 VertexRef (org.opennms.features.topology.api.topo.VertexRef)6 List (java.util.List)5 Objects (java.util.Objects)4 Collectors (java.util.stream.Collectors)4 Test (org.junit.Test)4 GraphContainer (org.opennms.features.topology.api.GraphContainer)4 Vertex (org.opennms.features.topology.api.topo.Vertex)4 Lists (com.google.common.collect.Lists)3 Optional (java.util.Optional)3 Set (java.util.Set)3 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)3 Maps (com.google.common.collect.Maps)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Map (java.util.Map)2 Before (org.junit.Before)2 SimpleGraphBuilder (org.opennms.features.topology.api.support.SimpleGraphBuilder)2