Search in sources :

Example 1 with StatusProvider

use of org.opennms.features.topology.api.topo.StatusProvider 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 2 with StatusProvider

use of org.opennms.features.topology.api.topo.StatusProvider 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(eachProvider -> eachProvider.getNamespace()).flatMap(eachNamespace -> metaTopologyProvider.getRawTopologyProvider(eachNamespace).getVertices().stream()).map(eachVertex -> eachVertex.getIconKey()).filter(eachIconKey -> eachIconKey != null).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 -> {
                final GraphMLTopologyProvider rawTopologyProvider = metaTopologyProvider.getRawTopologyProvider(it.getNamespace());
                registerService(pid, EdgeStatusProvider.class, new GraphMLEdgeStatusProvider(rawTopologyProvider, scriptEngineManager, m_serviceAccessor));
                registerService(pid, SearchProvider.class, new GraphMLSearchProvider(rawTopologyProvider));
                if (rawTopologyProvider.requiresStatusProvider()) {
                    GraphMLVertexStatusProvider statusProvider = new GraphMLVertexStatusProvider(rawTopologyProvider.getNamespace(), (nodeIds) -> m_serviceAccessor.getAlarmDao().getNodeAlarmSummariesIncludeAcknowledgedOnes(nodeIds));
                    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) LoggerFactory(org.slf4j.LoggerFactory) EdgeStatusProvider(org.opennms.features.topology.api.topo.EdgeStatusProvider) GraphMLVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.GraphMLVertexStatusProvider) 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) 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) GraphMLEdgeStatusProvider(org.opennms.features.topology.plugins.topo.graphml.GraphMLEdgeStatusProvider) OSGiScriptEngineManager(org.opennms.features.topology.plugins.topo.graphml.internal.scripting.OSGiScriptEngineManager) GraphMLMetaTopologyProvider(org.opennms.features.topology.plugins.topo.graphml.GraphMLMetaTopologyProvider) Dictionary(java.util.Dictionary) GraphMLTopologyProvider(org.opennms.features.topology.plugins.topo.graphml.GraphMLTopologyProvider) GraphMLVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.GraphMLVertexStatusProvider) OSGiScriptEngineManager(org.opennms.features.topology.plugins.topo.graphml.internal.scripting.OSGiScriptEngineManager) InvalidGraphException(org.opennms.features.graphml.model.InvalidGraphException) Hashtable(java.util.Hashtable) GraphMLMetaTopologyProvider(org.opennms.features.topology.plugins.topo.graphml.GraphMLMetaTopologyProvider) ScriptEngineManager(javax.script.ScriptEngineManager) OSGiScriptEngineManager(org.opennms.features.topology.plugins.topo.graphml.internal.scripting.OSGiScriptEngineManager) IOException(java.io.IOException) GraphMLEdgeStatusProvider(org.opennms.features.topology.plugins.topo.graphml.GraphMLEdgeStatusProvider) GraphMLSearchProvider(org.opennms.features.topology.plugins.topo.graphml.GraphMLSearchProvider)

Aggregations

EdgeStatusProvider (org.opennms.features.topology.api.topo.EdgeStatusProvider)2 StatusProvider (org.opennms.features.topology.api.topo.StatusProvider)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Dictionary (java.util.Dictionary)1 Hashtable (java.util.Hashtable)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 ScriptEngineManager (javax.script.ScriptEngineManager)1 InvalidGraphException (org.opennms.features.graphml.model.InvalidGraphException)1 IconRepository (org.opennms.features.topology.api.IconRepository)1 Edge (org.opennms.features.topology.api.topo.Edge)1 GraphProvider (org.opennms.features.topology.api.topo.GraphProvider)1 MetaTopologyProvider (org.opennms.features.topology.api.topo.MetaTopologyProvider)1 SearchProvider (org.opennms.features.topology.api.topo.SearchProvider)1