Search in sources :

Example 1 with MetaTopologyProvider

use of org.opennms.features.topology.api.topo.MetaTopologyProvider in project opennms by OpenNMS.

the class BreadcrumbPathCalculatorTest method setUp.

@Before
public void setUp() {
    final GraphProvider layer1 = new SimpleGraphBuilder("layer1").vertex("A1").vertex("A2").get();
    final GraphProvider layer2 = new SimpleGraphBuilder("layer2").vertex("B1").vertex("B2").vertex("B3").vertex("B4").get();
    final GraphProvider layer3 = new SimpleGraphBuilder("layer3").vertex("C1").vertex("C2").vertex("C3").vertex("C4").vertex("C5").vertex("C6").edge("e1", "C1", "C4").edge("e2", "C1", "C5").edge("e3", "C4", "C5").get();
    final Map<VertexRef, List<VertexRef>> oppositesMap = Maps.newHashMap();
    oppositesMap.put(new DefaultVertexRef("layer1", "A1"), Lists.newArrayList(new DefaultVertexRef("layer2", "B3"), new DefaultVertexRef("layer2", "B4")));
    oppositesMap.put(new DefaultVertexRef("layer1", "A2"), Lists.newArrayList(new DefaultVertexRef("layer2", "B1"), new DefaultVertexRef("layer2", "B2")));
    oppositesMap.put(new DefaultVertexRef("layer2", "B1"), Lists.newArrayList(new DefaultVertexRef("layer3", "C2")));
    oppositesMap.put(new DefaultVertexRef("layer2", "B2"), Lists.newArrayList(new DefaultVertexRef("layer3", "C1")));
    oppositesMap.put(new DefaultVertexRef("layer2", "B3"), Lists.newArrayList(new DefaultVertexRef("layer3", "C3")));
    MetaTopologyProvider metaTopologyProvider = new MetaTopologyProvider() {

        @Override
        public GraphProvider getDefaultGraphProvider() {
            return layer1;
        }

        @Override
        public Collection<GraphProvider> getGraphProviders() {
            return Lists.newArrayList(layer1, layer2, layer3);
        }

        @Override
        public Collection<VertexRef> getOppositeVertices(VertexRef vertexRef) {
            return Optional.ofNullable(oppositesMap.get(vertexRef)).orElse(Lists.newArrayList());
        }

        @Override
        public GraphProvider getGraphProviderBy(String namespace) {
            return getGraphProviders().stream().filter(p -> p.getNamespace().equals(namespace)).findFirst().orElse(null);
        }

        @Override
        public BreadcrumbStrategy getBreadcrumbStrategy() {
            return BreadcrumbStrategy.NONE;
        }

        @Override
        public String getId() {
            return getGraphProviders().stream().map(g -> g.getNamespace()).collect(Collectors.joining(":"));
        }
    };
    DefaultTopologyService topologyService = new DefaultTopologyService();
    topologyService.setServiceLocator(new SimpleServiceLocator(metaTopologyProvider));
    DefaultTopologyServiceClient client = new DefaultTopologyServiceClient(topologyService);
    client.setMetaTopologyId(metaTopologyProvider.getId());
    client.setNamespace(metaTopologyProvider.getDefaultGraphProvider().getNamespace());
    topologyServiceClient = client;
}
Also used : DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) DefaultTopologyServiceClient(org.opennms.features.topology.app.internal.DefaultTopologyServiceClient) Collection(java.util.Collection) IOException(java.io.IOException) Test(org.junit.Test) DefaultTopologyService(org.opennms.features.topology.app.internal.service.DefaultTopologyService) Collectors(java.util.stream.Collectors) TopologyServiceClient(org.opennms.features.topology.api.TopologyServiceClient) Maps(com.google.common.collect.Maps) MetaTopologyProvider(org.opennms.features.topology.api.topo.MetaTopologyProvider) List(java.util.List) BreadcrumbStrategy(org.opennms.features.topology.api.support.breadcrumbs.BreadcrumbStrategy) Lists(com.google.common.collect.Lists) Map(java.util.Map) Optional(java.util.Optional) SimpleGraphBuilder(org.opennms.features.topology.api.support.SimpleGraphBuilder) Assert(org.junit.Assert) VertexRef(org.opennms.features.topology.api.topo.VertexRef) SimpleServiceLocator(org.opennms.features.topology.app.internal.service.SimpleServiceLocator) Before(org.junit.Before) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) MetaTopologyProvider(org.opennms.features.topology.api.topo.MetaTopologyProvider) SimpleGraphBuilder(org.opennms.features.topology.api.support.SimpleGraphBuilder) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) DefaultTopologyServiceClient(org.opennms.features.topology.app.internal.DefaultTopologyServiceClient) DefaultTopologyService(org.opennms.features.topology.app.internal.service.DefaultTopologyService) SimpleServiceLocator(org.opennms.features.topology.app.internal.service.SimpleServiceLocator) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) List(java.util.List) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Before(org.junit.Before)

Example 2 with MetaTopologyProvider

use of org.opennms.features.topology.api.topo.MetaTopologyProvider in project opennms by OpenNMS.

the class AbstractLayoutTest method setUp.

@Before
public void setUp() {
    SimpleGraphBuilder bldr = new SimpleGraphBuilder("nodes");
    for (int i = 0; i < 100; i++) {
        bldr.vertex("v" + i).vLabel("vertex" + i).vIconKey("server").vTooltip("tooltip").vStyleName("vertex");
    }
    bldr.edge("e1", "v1", "v2").eStyleName("edge").edge("e2", "v1", "v3").eStyleName("edge").edge("e3", "v1", "v4").eStyleName("edge").edge("e4", "v1", "v5").eStyleName("edge").edge("e5", "v1", "v6").eStyleName("edge").edge("e6", "v1", "v7").eStyleName("edge").edge("e7", "v1", "v8").eStyleName("edge").edge("e8", "v1", "v8").eStyleName("edge").edge("e9", "v2", "v8").eStyleName("edge").edge("e10", "v2", "v7").eStyleName("edge").edge("e11", "v3", "v8").eStyleName("edge").edge("e12", "v5", "v8").eStyleName("edge").edge("e13", "v6", "v8").eStyleName("edge").edge("e14", "v7", "v8").eStyleName("edge");
    final DefaultTopologyService topologyService = new DefaultTopologyService();
    final MetaTopologyProvider metaTopologyProvider = new SimpleMetaTopologyProvider(getGraphProvider());
    topologyService.setServiceLocator(new SimpleServiceLocator(metaTopologyProvider));
    final VEProviderGraphContainer graphContainer = new VEProviderGraphContainer();
    graphContainer.setTopologyService(topologyService);
    graphContainer.setSelectedNamespace(metaTopologyProvider.getDefaultGraphProvider().getNamespace());
    graphContainer.setMetaTopologyId(metaTopologyProvider.getId());
    m_graphContainer = graphContainer;
}
Also used : SimpleMetaTopologyProvider(org.opennms.features.topology.api.topo.SimpleMetaTopologyProvider) MetaTopologyProvider(org.opennms.features.topology.api.topo.MetaTopologyProvider) SimpleGraphBuilder(org.opennms.features.topology.api.support.SimpleGraphBuilder) DefaultTopologyService(org.opennms.features.topology.app.internal.service.DefaultTopologyService) VEProviderGraphContainer(org.opennms.features.topology.app.internal.VEProviderGraphContainer) SimpleServiceLocator(org.opennms.features.topology.app.internal.service.SimpleServiceLocator) SimpleMetaTopologyProvider(org.opennms.features.topology.api.topo.SimpleMetaTopologyProvider) Before(org.junit.Before)

Example 3 with MetaTopologyProvider

use of org.opennms.features.topology.api.topo.MetaTopologyProvider in project opennms by OpenNMS.

the class VEProviderGraphContainerTest method setUp.

@Before
public void setUp() {
    MockLogAppender.setupLogging();
    m_graphProvider = new SimpleGraphBuilder("nodes").vertex("g0").vLabel("group0").vIconKey("group").vTooltip("root group").vStyleName("vertex").vertex("g1").parent("g0").vLabel("group1").vIconKey("group").vTooltip("group 1").vStyleName("vertex").vertex("v1").parent("g1").vLabel("vertex1").vIconKey("server").vTooltip("tooltip").vStyleName("vertex").vertex("v2").parent("g1").vLabel("vertex2").vIconKey("server").vTooltip("tooltip").vStyleName("vertex").vertex("g2").parent("g0").vLabel("group2").vIconKey("group").vTooltip("group 2").vStyleName("vertex").vertex("v3").parent("g2").vLabel("vertex3").vIconKey("server").vTooltip("tooltip").vStyleName("vertex").vertex("v4").parent("g2").vLabel("vertex4").vIconKey("server").vTooltip("tooltip").vStyleName("vertex").edge("e1", "v1", "v2").eStyleName("edge").edge("e2", "v2", "v3").eStyleName("edge").edge("e3", "v3", "v4").eStyleName("edge").edge("e4", "v4", "v1").eStyleName("edge").get();
    MetaTopologyProvider metaTopologyProvider = new SimpleMetaTopologyProvider(m_graphProvider);
    DefaultTopologyService topologyService = new DefaultTopologyService();
    topologyService.setServiceLocator(new SimpleServiceLocator(metaTopologyProvider));
    VEProviderGraphContainer graphContainer = new VEProviderGraphContainer();
    graphContainer.setSemanticZoomLevel(0);
    graphContainer.setTopologyService(topologyService);
    graphContainer.setSelectedNamespace(m_graphProvider.getNamespace());
    graphContainer.setMetaTopologyId(m_graphProvider.getNamespace());
    m_graphContainer = graphContainer;
}
Also used : SimpleMetaTopologyProvider(org.opennms.features.topology.api.topo.SimpleMetaTopologyProvider) MetaTopologyProvider(org.opennms.features.topology.api.topo.MetaTopologyProvider) SimpleGraphBuilder(org.opennms.features.topology.api.support.SimpleGraphBuilder) DefaultTopologyService(org.opennms.features.topology.app.internal.service.DefaultTopologyService) SimpleServiceLocator(org.opennms.features.topology.app.internal.service.SimpleServiceLocator) SimpleMetaTopologyProvider(org.opennms.features.topology.api.topo.SimpleMetaTopologyProvider) Before(org.junit.Before)

Example 4 with MetaTopologyProvider

use of org.opennms.features.topology.api.topo.MetaTopologyProvider in project opennms by OpenNMS.

the class DefaultTopologyService method getMetaTopologyProvider.

@Override
public MetaTopologyProvider getMetaTopologyProvider(String metaTopologyId) throws NoSuchProviderException {
    Optional<MetaTopologyProvider> metaTopologyProviderOptional = serviceLocator.findServices(MetaTopologyProvider.class, null).stream().filter(metaTopologyProvider -> metaTopologyId.equals(metaTopologyProvider.getId())).findFirst();
    MetaTopologyProvider metaTopologyProvider = metaTopologyProviderOptional.orElseThrow(() -> new NoSuchMetaTopologyProvider(metaTopologyId));
    return metaTopologyProvider;
}
Also used : LoadingCache(com.google.common.cache.LoadingCache) ServiceLocator(org.opennms.features.topology.api.support.ServiceLocator) Edge(org.opennms.features.topology.api.topo.Edge) Vertex(org.opennms.features.topology.api.topo.Vertex) LoggerFactory(org.slf4j.LoggerFactory) CheckedOperation(org.opennms.features.topology.api.CheckedOperation) EdgeStatusProvider(org.opennms.features.topology.api.topo.EdgeStatusProvider) D3TopoLayoutAlgorithm(org.opennms.features.topology.app.internal.jung.D3TopoLayoutAlgorithm) ArrayList(java.util.ArrayList) LayoutOperation(org.opennms.features.topology.app.internal.operations.LayoutOperation) LayoutAlgorithm(org.opennms.features.topology.api.LayoutAlgorithm) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) Logger(org.slf4j.Logger) Collection(java.util.Collection) Throwables(com.google.common.base.Throwables) Graph(org.opennms.features.topology.api.Graph) MetaTopologyProvider(org.opennms.features.topology.api.topo.MetaTopologyProvider) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) TopologyService(org.opennms.features.topology.api.TopologyService) CacheLoader(com.google.common.cache.CacheLoader) List(java.util.List) StatusProvider(org.opennms.features.topology.api.topo.StatusProvider) Criteria(org.opennms.features.topology.api.topo.Criteria) Optional(java.util.Optional) CacheBuilder(com.google.common.cache.CacheBuilder) MetaTopologyProvider(org.opennms.features.topology.api.topo.MetaTopologyProvider)

Example 5 with MetaTopologyProvider

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

MetaTopologyProvider (org.opennms.features.topology.api.topo.MetaTopologyProvider)5 List (java.util.List)3 Optional (java.util.Optional)3 Before (org.junit.Before)3 SimpleGraphBuilder (org.opennms.features.topology.api.support.SimpleGraphBuilder)3 GraphProvider (org.opennms.features.topology.api.topo.GraphProvider)3 DefaultTopologyService (org.opennms.features.topology.app.internal.service.DefaultTopologyService)3 SimpleServiceLocator (org.opennms.features.topology.app.internal.service.SimpleServiceLocator)3 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 IOException (java.io.IOException)2 Collection (java.util.Collection)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Collectors (java.util.stream.Collectors)2 EdgeStatusProvider (org.opennms.features.topology.api.topo.EdgeStatusProvider)2 SimpleMetaTopologyProvider (org.opennms.features.topology.api.topo.SimpleMetaTopologyProvider)2 StatusProvider (org.opennms.features.topology.api.topo.StatusProvider)2 Vertex (org.opennms.features.topology.api.topo.Vertex)2 Throwables (com.google.common.base.Throwables)1