Search in sources :

Example 1 with GraphMLEdgeStatusProvider

use of org.opennms.features.topology.plugins.topo.graphml.status.GraphMLEdgeStatusProvider in project opennms by OpenNMS.

the class GraphMLEdgeStatusProviderIT method verify.

@Test
public void verify() throws Exception {
    final GraphMLServiceAccessor serviceAccessor = new GraphMLServiceAccessor();
    serviceAccessor.setTransactionOperations(transactionOperations);
    serviceAccessor.setNodeDao(nodeDao);
    serviceAccessor.setSnmpInterfaceDao(snmpInterfaceDao);
    serviceAccessor.setMeasurementsService(request -> new QueryResponse());
    final GraphMLGraph graph = GraphMLReader.read(getClass().getResourceAsStream("/test-graph2.xml")).getGraphs().get(0);
    final GraphMLTopologyProvider topologyProvider = new GraphMLTopologyProvider(null, graph, serviceAccessor);
    final GraphMLEdgeStatusProvider provider = new GraphMLEdgeStatusProvider(topologyProvider, new ScriptEngineManager(), serviceAccessor, Paths.get("src", "test", "opennms-home", "etc", "graphml-edge-status"));
    assertThat(provider.contributesTo("acme:regions"), is(true));
    assertThat(provider.getNamespace(), is("acme:regions"));
    // Calculating the status executes some tests defined int the according scripts as a side effect
    final EdgeRef edgeRef = topologyProvider.getEdge("acme:regions", "center_north");
    final Map<? extends EdgeRef, ? extends Status> status = provider.getStatusForEdges(topologyProvider, ImmutableList.of(edgeRef), new Criteria[0]);
    // Checking nodeID creation for vertices with only foreignSource/foreignID set
    final VertexRef vertexRef = topologyProvider.getVertex("acme:regions", "west");
    assertThat(vertexRef, is(notNullValue()));
    assertThat(vertexRef, is(instanceOf(GraphMLVertex.class)));
    assertThat(((GraphMLVertex) vertexRef).getNodeID(), is(4));
    // Testing status merging from two scripts
    assertThat(status, is(notNullValue()));
    assertThat(status, is(hasEntry(edgeRef, new GraphMLEdgeStatus().severity(OnmsSeverity.WARNING).style("stroke", "pink").style("stroke-width", "3em"))));
}
Also used : GraphMLEdgeStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLEdgeStatusProvider) QueryResponse(org.opennms.netmgt.measurements.model.QueryResponse) GraphMLServiceAccessor(org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor) GraphMLGraph(org.opennms.features.graphml.model.GraphMLGraph) ScriptEngineManager(javax.script.ScriptEngineManager) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) GraphMLEdgeStatus(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLEdgeStatus) Test(org.junit.Test)

Example 2 with GraphMLEdgeStatusProvider

use of org.opennms.features.topology.plugins.topo.graphml.status.GraphMLEdgeStatusProvider 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)

Aggregations

ScriptEngineManager (javax.script.ScriptEngineManager)2 GraphMLEdgeStatusProvider (org.opennms.features.topology.plugins.topo.graphml.status.GraphMLEdgeStatusProvider)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 IOException (java.io.IOException)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 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Test (org.junit.Test)1 GraphMLGraph (org.opennms.features.graphml.model.GraphMLGraph)1 InvalidGraphException (org.opennms.features.graphml.model.InvalidGraphException)1 OSGiScriptEngineManager (org.opennms.features.osgi.script.OSGiScriptEngineManager)1 IconRepository (org.opennms.features.topology.api.IconRepository)1 EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)1 EdgeStatusProvider (org.opennms.features.topology.api.topo.EdgeStatusProvider)1