Search in sources :

Example 6 with EuiLevel

use of org.opennms.netmgt.xml.rtc.EuiLevel in project opennms by OpenNMS.

the class AvailabilityServiceIT method canCalculateAvailability.

@Test
public void canCalculateAvailability() throws Exception {
    final MockNetwork mockNetwork = new MockNetwork();
    // This test depends on the specifics in the standard network definition
    mockNetwork.createStandardNetwork();
    m_mockDatabase.populate(mockNetwork);
    final RTCCategory rtcCat = EasyMock.createNiceMock(RTCCategory.class);
    EasyMock.expect(rtcCat.getLabel()).andReturn("NOC").anyTimes();
    EasyMock.expect(rtcCat.getNodes()).andReturn(Lists.newArrayList(1, 2)).anyTimes();
    EasyMock.replay(rtcCat);
    // Verify the availability when no outages are present
    EuiLevel euiLevel = m_availabilityService.getEuiLevel(rtcCat);
    assertEquals(1, euiLevel.getCategory().size());
    Category category = euiLevel.getCategory().get(0);
    assertEquals(100.0, category.getCatvalue(), 0.001);
    assertEquals(2, category.getNode().size());
    // Assumes the nodes are sorted
    assertEquals(4, category.getNode().get(0).getNodesvccount());
    assertEquals(2, category.getNode().get(1).getNodesvccount());
    // Create an outage that is both open and closed within the window
    final Date now = new Date();
    final Date oneHourAgo = new Date(now.getTime() - (60 * 60 * 1000));
    final Date thirtyMinutesAgo = new Date(now.getTime() - (30 * 60 * 1000));
    final OnmsMonitoredService icmpService = toMonitoredService(mockNetwork.getService(1, "192.168.1.1", "ICMP"));
    OnmsOutage outage = new OnmsOutage();
    outage.setMonitoredService(icmpService);
    outage.setIfLostService(oneHourAgo);
    outage.setIfRegainedService(thirtyMinutesAgo);
    m_outageDao.save(outage);
    m_outageDao.flush();
    // Verify the availability when outages are present
    euiLevel = m_availabilityService.getEuiLevel(rtcCat);
    assertEquals(1, euiLevel.getCategory().size());
    category = euiLevel.getCategory().get(0);
    // This number should only need to be adjusted if the duration of the outage
    // or the number of services in the category changes
    assertEquals(RTCUtils.getOutagePercentage(1800000, 86400000, 6), category.getCatvalue(), 0.0001);
    assertEquals(2, category.getNode().size());
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) Category(org.opennms.netmgt.xml.rtc.Category) MockNetwork(org.opennms.netmgt.mock.MockNetwork) EuiLevel(org.opennms.netmgt.xml.rtc.EuiLevel) Date(java.util.Date) RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test)

Aggregations

RTCCategory (org.opennms.netmgt.rtc.datablock.RTCCategory)6 EuiLevel (org.opennms.netmgt.xml.rtc.EuiLevel)6 Date (java.util.Date)3 Category (org.opennms.netmgt.xml.rtc.Category)3 Node (org.opennms.netmgt.xml.rtc.Node)3 InputStream (java.io.InputStream)2 StringReader (java.io.StringReader)2 Test (org.junit.Test)2 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)2 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)2 HttpPostInfo (org.opennms.netmgt.rtc.datablock.HttpPostInfo)2 Preconditions (com.google.common.base.Preconditions)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 ConnectException (java.net.ConnectException)1 MalformedURLException (java.net.MalformedURLException)1 List (java.util.List)1 Map (java.util.Map)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 Collectors (java.util.stream.Collectors)1