use of org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor in project opennms by OpenNMS.
the class GraphMLMetaTopologyProviderTest method load.
@Test
public void load() throws IOException, InvalidGraphException {
final File graphXml = tempFolder.newFile();
Resources.asByteSource(Resources.getResource("test-graph.xml")).copyTo(Files.asByteSink(graphXml));
// Initialize the meta topology provider
final GraphMLMetaTopologyProvider metaTopoProvider = new GraphMLMetaTopologyProvider(new GraphMLServiceAccessor());
metaTopoProvider.setTopologyLocation(graphXml.getAbsolutePath());
metaTopoProvider.reload();
// Verify Breadcrumb-Strategy
Assert.assertEquals(BreadcrumbStrategy.SHORTEST_PATH_TO_ROOT, metaTopoProvider.getBreadcrumbStrategy());
// We should have two graph providers (one for each graph)
Collection<GraphProvider> graphProviders = metaTopoProvider.getGraphProviders();
Iterator<GraphProvider> it = graphProviders.iterator();
assertEquals(2, graphProviders.size());
// The first graph should be 'regions'
GraphProvider regionsGraphProvider = it.next();
assertEquals("acme:regions", regionsGraphProvider.getNamespace());
assertEquals("regions", regionsGraphProvider.getTopologyProviderInfo().getName());
assertNull(regionsGraphProvider.getDefaults().getPreferredLayout());
assertEquals(GraphMLTopologyProvider.DEFAULT_DESCRIPTION, regionsGraphProvider.getTopologyProviderInfo().getDescription());
assertEquals(Defaults.DEFAULT_SEMANTIC_ZOOM_LEVEL, regionsGraphProvider.getDefaults().getSemanticZoomLevel());
assertEquals(4, regionsGraphProvider.getVertexTotalCount());
for (String region : Lists.newArrayList("north", "south", "east", "west")) {
// Every vertex should link to 4 other vertices
Vertex vertex = regionsGraphProvider.getVertex("acme:regions", region);
assertEquals(4, metaTopoProvider.getOppositeVertices(vertex).size());
}
// The second graph should be 'markets'
GraphProvider marketsGraphProvider = it.next();
assertEquals("acme:markets", marketsGraphProvider.getNamespace());
assertEquals("Markets", marketsGraphProvider.getTopologyProviderInfo().getName());
assertEquals("The Markets Layer", marketsGraphProvider.getTopologyProviderInfo().getDescription());
assertEquals("Some Layout", marketsGraphProvider.getDefaults().getPreferredLayout());
assertEquals(0, marketsGraphProvider.getDefaults().getSemanticZoomLevel());
assertEquals(16, marketsGraphProvider.getVertexTotalCount());
}
use of org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor in project opennms by OpenNMS.
the class GraphMLSearchProviderTest method canSearchAllSearchProviders.
@Test
public void canSearchAllSearchProviders() throws IOException, InvalidGraphException {
final GraphMLMetaTopologyProvider metaTopologyProvider = new GraphMLMetaTopologyProvider(new GraphMLServiceAccessor());
metaTopologyProvider.setTopologyLocation("target/test-classes/test-graph.xml");
metaTopologyProvider.reload();
Assert.assertNotNull(metaTopologyProvider.getDefaultGraphProvider());
List<SearchProvider> searchProviders = metaTopologyProvider.getGraphProviders().stream().map(eachProvider -> new GraphMLSearchProvider(metaTopologyProvider.getRawTopologyProvider(eachProvider.getNamespace()))).collect(Collectors.toList());
Assert.assertEquals(2, searchProviders.size());
DefaultTopologyService defaultTopologyService = new DefaultTopologyService();
defaultTopologyService.setServiceLocator(new SimpleServiceLocator(metaTopologyProvider));
VEProviderGraphContainer graphContainer = new VEProviderGraphContainer();
graphContainer.setTopologyService(defaultTopologyService);
graphContainer.setMetaTopologyId(metaTopologyProvider.getId());
graphContainer.setSelectedNamespace(metaTopologyProvider.getDefaultGraphProvider().getNamespace());
OperationContext operationContext = EasyMock.niceMock(OperationContext.class);
EasyMock.expect(operationContext.getGraphContainer()).andReturn(graphContainer).anyTimes();
OnmsServiceManager onmsServiceManager = EasyMock.niceMock(OnmsServiceManager.class);
EasyMock.expect(onmsServiceManager.getServices(SearchProvider.class, null, new Hashtable<>())).andReturn(searchProviders).anyTimes();
EasyMock.replay(onmsServiceManager, operationContext);
SearchBox searchBox = new SearchBox(onmsServiceManager, operationContext);
List<SearchSuggestion> results = searchBox.getQueryResults("North");
Assert.assertEquals(5, results.size());
}
use of org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor in project opennms by OpenNMS.
the class GraphMLVertexStatusProviderTest method testStatusProvider.
@Test
public void testStatusProvider() throws InvalidGraphException {
GraphML graphML = GraphMLReader.read(getClass().getResourceAsStream("/test-graph.xml"));
GraphMLTopologyProvider topologyProvider = new GraphMLTopologyProvider(graphML.getGraphs().get(0), new GraphMLServiceAccessor());
GraphMLVertexStatusProvider statusProvider = new GraphMLVertexStatusProvider(topologyProvider.getNamespace(), nodeIds -> Lists.newArrayList(createSummary(1, "North", OnmsSeverity.WARNING, 1), createSummary(2, "West", OnmsSeverity.MINOR, 2), createSummary(3, "South", OnmsSeverity.MAJOR, 3)));
List<VertexRef> vertices = topologyProvider.getVertices().stream().map(eachVertex -> (VertexRef) eachVertex).collect(Collectors.toList());
Assert.assertEquals(4, vertices.size());
Assert.assertEquals(topologyProvider.getNamespace(), statusProvider.getNamespace());
Assert.assertEquals(Boolean.TRUE, statusProvider.contributesTo(topologyProvider.getNamespace()));
Map<VertexRef, Status> statusForVertices = statusProvider.getStatusForVertices(topologyProvider, vertices, new Criteria[0]);
Assert.assertEquals(4, statusForVertices.size());
Assert.assertEquals(ImmutableMap.of(createVertexRef(topologyProvider.getNamespace(), "north"), createStatus(OnmsSeverity.WARNING, 1), createVertexRef(topologyProvider.getNamespace(), "west"), createStatus(OnmsSeverity.MINOR, 2), createVertexRef(topologyProvider.getNamespace(), "south"), createStatus(OnmsSeverity.MAJOR, 3), createVertexRef(topologyProvider.getNamespace(), "east"), createStatus(OnmsSeverity.NORMAL, 0)), statusForVertices);
}
use of org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor 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"))));
}
use of org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor in project opennms by OpenNMS.
the class GraphMLVertexStatusProviderIT method testScriptStatusProvider.
@Test
public void testScriptStatusProvider() throws InvalidGraphException {
GraphML graphML = GraphMLReader.read(getClass().getResourceAsStream("/test-graph.xml"));
GraphMLTopologyProvider topologyProvider = new GraphMLTopologyProvider(null, graphML.getGraphs().get(0), new GraphMLServiceAccessor());
GraphMLScriptVertexStatusProvider statusProvider = new GraphMLScriptVertexStatusProvider(topologyProvider.getNamespace(), this.alarmSummaryWrapper, new ScriptEngineManager(), this.serviceAccessor, Paths.get("src", "test", "opennms-home", "etc", "graphml-vertex-status"));
List<VertexRef> vertices = topologyProvider.getVertices().stream().map(eachVertex -> (VertexRef) eachVertex).collect(Collectors.toList());
Assert.assertEquals(4, vertices.size());
Assert.assertEquals(topologyProvider.getNamespace(), statusProvider.getNamespace());
Assert.assertTrue(statusProvider.contributesTo(topologyProvider.getNamespace()));
Map<? extends VertexRef, ? extends Status> statusForVertices = statusProvider.getStatusForVertices(topologyProvider, vertices, new Criteria[0]);
Assert.assertEquals(4, statusForVertices.size());
Assert.assertEquals(ImmutableMap.of(createVertexRef(topologyProvider.getNamespace(), "north"), createStatus(OnmsSeverity.NORMAL, 0), createVertexRef(topologyProvider.getNamespace(), "west"), createStatus(OnmsSeverity.NORMAL, 0), createVertexRef(topologyProvider.getNamespace(), "south"), createStatus(OnmsSeverity.WARNING, 42), createVertexRef(topologyProvider.getNamespace(), "east"), createStatus(OnmsSeverity.CRITICAL, 23)), statusForVertices);
}
Aggregations