Search in sources :

Example 1 with GraphProvider

use of org.opennms.features.topology.api.topo.GraphProvider 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 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 3 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(v -> v.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) GraphContainer(org.opennms.features.topology.api.GraphContainer) Logger(org.slf4j.Logger) ContextMenu(org.vaadin.peter.contextmenu.ContextMenu) MenuBar(com.vaadin.ui.MenuBar) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) UI(com.vaadin.ui.UI) Set(java.util.Set) ContextMenuState(org.vaadin.peter.contextmenu.client.ContextMenuState) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) DefaultOperationContext(org.opennms.features.topology.app.internal.DefaultOperationContext) OperationContext(org.opennms.features.topology.api.OperationContext) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Collections(java.util.Collections) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 4 with GraphProvider

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

the class GraphMLSearchProvider method onFocusSearchResult.

@Override
public void onFocusSearchResult(SearchResult searchResult, OperationContext operationContext) {
    final GraphContainer graphContainer = operationContext.getGraphContainer();
    final DefaultVertexRef vertexRef = new DefaultVertexRef(searchResult.getNamespace(), searchResult.getId(), searchResult.getLabel());
    if (graphContainer.getTopologyServiceClient().getVertex(vertexRef) == null) {
        // The vertex to add to focus is not in the current layer
        // Find the GraphProvider it belongs to
        Optional<GraphProvider> first = graphContainer.getTopologyServiceClient().getGraphProviders().stream().filter(eachProvider -> eachProvider.getNamespace().equals(searchResult.getNamespace())).findFirst();
        // If there is a graph provider (which should) select it
        if (first.isPresent() && first.get().getVertex(vertexRef) != null) {
            graphContainer.selectTopologyProvider(first.get());
            graphContainer.clearCriteria();
        }
    }
    super.onFocusSearchResult(searchResult, operationContext);
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) Objects(java.util.Objects) GraphContainer(org.opennms.features.topology.api.GraphContainer) List(java.util.List) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) SearchResult(org.opennms.features.topology.api.topo.SearchResult) OperationContext(org.opennms.features.topology.api.OperationContext) SimpleSearchProvider(org.opennms.features.topology.api.topo.SimpleSearchProvider) Optional(java.util.Optional) SearchQuery(org.opennms.features.topology.api.topo.SearchQuery) VertexRef(org.opennms.features.topology.api.topo.VertexRef) ArrayList(java.util.ArrayList) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider)

Example 5 with GraphProvider

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

the class VertexHopGraphProviderTest method setUp.

@Before
public void setUp() {
    MockLogAppender.setupLogging();
    GraphProvider baseProvider = 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", "g0", "g1").eLabel("edge1").eStyleName("edge").edge("e2", "g0", "g2").eLabel("edge2").eStyleName("edge").edge("e3", "g1", "v1").eLabel("edge3").eStyleName("edge").edge("e4", "g1", "v2").eLabel("edge4").eStyleName("edge").edge("e5", "g2", "v3").eLabel("edge5").eStyleName("edge").edge("e6", "g2", "v4").eLabel("edge6").eStyleName("edge").get();
    m_provider = new VertexHopGraphProvider(baseProvider);
}
Also used : GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) Before(org.junit.Before)

Aggregations

GraphProvider (org.opennms.features.topology.api.topo.GraphProvider)10 VertexRef (org.opennms.features.topology.api.topo.VertexRef)5 List (java.util.List)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 Collectors (java.util.stream.Collectors)3 GraphContainer (org.opennms.features.topology.api.GraphContainer)3 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)3 Lists (com.google.common.collect.Lists)2 Collections (java.util.Collections)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Before (org.junit.Before)2 OperationContext (org.opennms.features.topology.api.OperationContext)2 SimpleGraphBuilder (org.opennms.features.topology.api.support.SimpleGraphBuilder)2 Vertex (org.opennms.features.topology.api.topo.Vertex)2 Maps (com.google.common.collect.Maps)1 MenuBar (com.vaadin.ui.MenuBar)1 UI (com.vaadin.ui.UI)1