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;
}
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;
}
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");
}
}
}
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);
}
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);
}
Aggregations