Search in sources :

Example 1 with GraphMLServiceAccessor

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());
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) GraphMLServiceAccessor(org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) File(java.io.File) Test(org.junit.Test)

Example 2 with GraphMLServiceAccessor

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());
}
Also used : IOException(java.io.IOException) Test(org.junit.Test) EasyMock(org.easymock.EasyMock) DefaultTopologyService(org.opennms.features.topology.app.internal.service.DefaultTopologyService) OnmsServiceManager(org.opennms.osgi.OnmsServiceManager) Collectors(java.util.stream.Collectors) SearchBox(org.opennms.features.topology.app.internal.ui.SearchBox) List(java.util.List) OperationContext(org.opennms.features.topology.api.OperationContext) InvalidGraphException(org.opennms.features.graphml.model.InvalidGraphException) SearchSuggestion(org.opennms.features.topology.app.internal.gwt.client.SearchSuggestion) VEProviderGraphContainer(org.opennms.features.topology.app.internal.VEProviderGraphContainer) Assert(org.junit.Assert) SimpleServiceLocator(org.opennms.features.topology.app.internal.service.SimpleServiceLocator) GraphMLGraph(org.opennms.features.graphml.model.GraphMLGraph) GraphMLServiceAccessor(org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor) Hashtable(java.util.Hashtable) SearchProvider(org.opennms.features.topology.api.topo.SearchProvider) OperationContext(org.opennms.features.topology.api.OperationContext) OnmsServiceManager(org.opennms.osgi.OnmsServiceManager) SearchSuggestion(org.opennms.features.topology.app.internal.gwt.client.SearchSuggestion) DefaultTopologyService(org.opennms.features.topology.app.internal.service.DefaultTopologyService) VEProviderGraphContainer(org.opennms.features.topology.app.internal.VEProviderGraphContainer) Hashtable(java.util.Hashtable) SimpleServiceLocator(org.opennms.features.topology.app.internal.service.SimpleServiceLocator) SearchProvider(org.opennms.features.topology.api.topo.SearchProvider) SearchBox(org.opennms.features.topology.app.internal.ui.SearchBox) GraphMLServiceAccessor(org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor) Test(org.junit.Test)

Example 3 with GraphMLServiceAccessor

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);
}
Also used : DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) ImmutableMap(com.google.common.collect.ImmutableMap) Date(java.util.Date) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) Test(org.junit.Test) GraphML(org.opennms.features.graphml.model.GraphML) GraphMLReader(org.opennms.features.graphml.model.GraphMLReader) Collectors(java.util.stream.Collectors) List(java.util.List) Lists(com.google.common.collect.Lists) Map(java.util.Map) InvalidGraphException(org.opennms.features.graphml.model.InvalidGraphException) Criteria(org.opennms.features.topology.api.topo.Criteria) Status(org.opennms.features.topology.api.topo.Status) Assert(org.junit.Assert) VertexRef(org.opennms.features.topology.api.topo.VertexRef) GraphMLServiceAccessor(org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) Status(org.opennms.features.topology.api.topo.Status) GraphML(org.opennms.features.graphml.model.GraphML) GraphMLServiceAccessor(org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Test(org.junit.Test)

Example 4 with GraphMLServiceAccessor

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"))));
}
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 5 with GraphMLServiceAccessor

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);
}
Also used : Date(java.util.Date) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) GraphMLReader(org.opennms.features.graphml.model.GraphMLReader) QueryResponse(org.opennms.netmgt.measurements.model.QueryResponse) GraphMLPropagateVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLPropagateVertexStatusProvider) SnmpInterfaceDao(org.opennms.netmgt.dao.api.SnmpInterfaceDao) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Files(com.google.common.io.Files) Map(java.util.Map) InvalidGraphException(org.opennms.features.graphml.model.InvalidGraphException) GraphMLServiceAccessor(org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor) ServiceReference(org.osgi.framework.ServiceReference) Before(org.junit.Before) DatabasePopulator(org.opennms.netmgt.dao.DatabasePopulator) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) NodeDao(org.opennms.netmgt.dao.api.NodeDao) JUnitConfigurationEnvironment(org.opennms.test.JUnitConfigurationEnvironment) Resources(com.google.common.io.Resources) ImmutableMap(com.google.common.collect.ImmutableMap) ScriptEngineManager(javax.script.ScriptEngineManager) Test(org.junit.Test) GraphML(org.opennms.features.graphml.model.GraphML) EasyMock(org.easymock.EasyMock) Collectors(java.util.stream.Collectors) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) BeanUtils(org.opennms.core.spring.BeanUtils) List(java.util.List) StatusProvider(org.opennms.features.topology.api.topo.StatusProvider) Rule(org.junit.Rule) OpenNMSJUnit4ClassRunner(org.opennms.core.test.OpenNMSJUnit4ClassRunner) GraphMLDefaultVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLDefaultVertexStatusProvider) Paths(java.nio.file.Paths) GraphMLVertexStatus(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLVertexStatus) AlarmSummaryWrapper(org.opennms.features.topology.plugins.topo.graphml.internal.AlarmSummaryWrapper) TransactionOperations(org.springframework.transaction.support.TransactionOperations) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) Criteria(org.opennms.features.topology.api.topo.Criteria) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Status(org.opennms.features.topology.api.topo.Status) GraphMLScriptVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLScriptVertexStatusProvider) Assert(org.junit.Assert) VertexRef(org.opennms.features.topology.api.topo.VertexRef) TemporaryFolder(org.junit.rules.TemporaryFolder) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) GraphML(org.opennms.features.graphml.model.GraphML) GraphMLServiceAccessor(org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor) ScriptEngineManager(javax.script.ScriptEngineManager) GraphMLScriptVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLScriptVertexStatusProvider) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Test(org.junit.Test)

Aggregations

GraphMLServiceAccessor (org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor)9 Test (org.junit.Test)8 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 Assert (org.junit.Assert)5 InvalidGraphException (org.opennms.features.graphml.model.InvalidGraphException)5 VertexRef (org.opennms.features.topology.api.topo.VertexRef)5 QueryResponse (org.opennms.netmgt.measurements.model.QueryResponse)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 Lists (com.google.common.collect.Lists)4 File (java.io.File)4 Date (java.util.Date)4 Map (java.util.Map)4 ScriptEngineManager (javax.script.ScriptEngineManager)4 EasyMock (org.easymock.EasyMock)4 Before (org.junit.Before)4 GraphML (org.opennms.features.graphml.model.GraphML)4 GraphMLReader (org.opennms.features.graphml.model.GraphMLReader)4 Criteria (org.opennms.features.topology.api.topo.Criteria)4 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)4