Search in sources :

Example 6 with GraphMLServiceAccessor

use of org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor in project opennms by OpenNMS.

the class GraphMLVertexStatusProviderIT method testPropagateStatusProvider.

@Test
public void testPropagateStatusProvider() throws Exception {
    final File graphXml = this.tempFolder.newFile();
    Resources.asByteSource(Resources.getResource("test-graph.xml")).copyTo(Files.asByteSink(graphXml));
    final GraphMLMetaTopologyProvider metaTopoProvider = new GraphMLMetaTopologyProvider(new GraphMLServiceAccessor());
    metaTopoProvider.setTopologyLocation(graphXml.getAbsolutePath());
    metaTopoProvider.reload();
    final GraphMLTopologyProvider childTopologyProvider = metaTopoProvider.getRawTopologyProvider("acme:markets");
    final GraphMLDefaultVertexStatusProvider childStatusProvider = new GraphMLDefaultVertexStatusProvider(childTopologyProvider.getNamespace(), this.alarmSummaryWrapper);
    final ServiceReference<StatusProvider> statusProviderReference = EasyMock.niceMock(ServiceReference.class);
    final BundleContext bundleContext = EasyMock.niceMock(BundleContext.class);
    EasyMock.expect(bundleContext.getServiceReferences(StatusProvider.class, null)).andReturn(ImmutableList.of(statusProviderReference)).anyTimes();
    EasyMock.expect(bundleContext.getService(statusProviderReference)).andReturn(childStatusProvider);
    EasyMock.replay(statusProviderReference, bundleContext);
    final GraphMLTopologyProvider topologyProvider = metaTopoProvider.getRawTopologyProvider("acme:regions");
    final GraphMLPropagateVertexStatusProvider statusProvider = new GraphMLPropagateVertexStatusProvider(topologyProvider.getNamespace(), metaTopoProvider, bundleContext);
    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.MAJOR, 4), createVertexRef(topologyProvider.getNamespace(), "south"), createStatus(OnmsSeverity.NORMAL, 0), createVertexRef(topologyProvider.getNamespace(), "east"), createStatus(OnmsSeverity.CRITICAL, 11)), 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) 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) GraphMLScriptVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLScriptVertexStatusProvider) GraphMLDefaultVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLDefaultVertexStatusProvider) 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) File(java.io.File) GraphMLPropagateVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLPropagateVertexStatusProvider) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 7 with GraphMLServiceAccessor

use of org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor in project opennms by OpenNMS.

the class GraphMLVertexStatusProviderIT method testDefaultStatusProvider.

@Test
public void testDefaultStatusProvider() throws InvalidGraphException {
    GraphML graphML = GraphMLReader.read(getClass().getResourceAsStream("/test-graph.xml"));
    GraphMLTopologyProvider topologyProvider = new GraphMLTopologyProvider(null, graphML.getGraphs().get(0), new GraphMLServiceAccessor());
    GraphMLDefaultVertexStatusProvider statusProvider = new GraphMLDefaultVertexStatusProvider(topologyProvider.getNamespace(), this.alarmSummaryWrapper);
    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.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 : 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) GraphMLDefaultVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLDefaultVertexStatusProvider) 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 8 with GraphMLServiceAccessor

use of org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor in project opennms by OpenNMS.

the class GraphMLSearchProviderTest method verifyContributesTo.

@Test
public void verifyContributesTo() {
    GraphMLGraph graph = new GraphMLGraph();
    graph.setProperty(GraphMLProperties.NAMESPACE, "namespace1:graph1");
    GraphMLTopologyProvider topologyProvider = new GraphMLTopologyProvider(null, graph, new GraphMLServiceAccessor());
    GraphMLSearchProvider searchProvider = new GraphMLSearchProvider(topologyProvider);
    Assert.assertEquals(true, searchProvider.contributesTo("namespace1:graph1"));
    Assert.assertEquals(true, searchProvider.contributesTo("namespace1:graph2"));
    Assert.assertEquals(true, searchProvider.contributesTo("namespace1:graph3"));
    Assert.assertEquals(false, searchProvider.contributesTo("namespace1"));
}
Also used : GraphMLGraph(org.opennms.features.graphml.model.GraphMLGraph) GraphMLServiceAccessor(org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor) Test(org.junit.Test)

Example 9 with GraphMLServiceAccessor

use of org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor in project opennms by OpenNMS.

the class GraphMLVertexStatusProviderIT method before.

@Before
public void before() {
    BeanUtils.assertAutowiring(this);
    this.databasePopulator.populateDatabase();
    this.serviceAccessor = new GraphMLServiceAccessor();
    this.serviceAccessor.setTransactionOperations(this.transactionOperations);
    this.serviceAccessor.setNodeDao(this.nodeDao);
    this.serviceAccessor.setSnmpInterfaceDao(this.snmpInterfaceDao);
    this.serviceAccessor.setMeasurementsService(request -> new QueryResponse());
    this.alarmSummaryWrapper = nodeIds -> Lists.newArrayList(createSummary(1, "North", OnmsSeverity.WARNING, 1), createSummary(2, "West", OnmsSeverity.MINOR, 2), createSummary(3, "South", OnmsSeverity.MAJOR, 3), createSummary(4, "West 2", OnmsSeverity.MAJOR, 4), createSummary(5, "East 1", OnmsSeverity.CRITICAL, 5), createSummary(6, "East 2", OnmsSeverity.WARNING, 6));
}
Also used : QueryResponse(org.opennms.netmgt.measurements.model.QueryResponse) GraphMLServiceAccessor(org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor) Before(org.junit.Before)

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