Search in sources :

Example 1 with GraphMLDefaultVertexStatusProvider

use of org.opennms.features.topology.plugins.topo.graphml.status.GraphMLDefaultVertexStatusProvider 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 2 with GraphMLDefaultVertexStatusProvider

use of org.opennms.features.topology.plugins.topo.graphml.status.GraphMLDefaultVertexStatusProvider 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)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Lists (com.google.common.collect.Lists)2 Files (com.google.common.io.Files)2 Resources (com.google.common.io.Resources)2 File (java.io.File)2 Paths (java.nio.file.Paths)2 Date (java.util.Date)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 ScriptEngineManager (javax.script.ScriptEngineManager)2 EasyMock (org.easymock.EasyMock)2 Assert (org.junit.Assert)2 Before (org.junit.Before)2 Rule (org.junit.Rule)2 Test (org.junit.Test)2 TemporaryFolder (org.junit.rules.TemporaryFolder)2 RunWith (org.junit.runner.RunWith)2 BeanUtils (org.opennms.core.spring.BeanUtils)2