Search in sources :

Example 1 with Category

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

the class AvailabilityServiceIT method categoryIsFullyAvailableWhenNoServicesArePresent.

@Test
public void categoryIsFullyAvailableWhenNoServicesArePresent() throws Exception {
    final RTCCategory rtcCat = EasyMock.createNiceMock(RTCCategory.class);
    EasyMock.expect(rtcCat.getLabel()).andReturn("Routers");
    // This nodeid should not exist in the database
    EasyMock.expect(rtcCat.getNodes()).andReturn(Lists.newArrayList(99999));
    EasyMock.replay(rtcCat);
    final EuiLevel euiLevel = m_availabilityService.getEuiLevel(rtcCat);
    assertEquals(1, euiLevel.getCategory().size());
    final Category category = euiLevel.getCategory().get(0);
    assertEquals(100.0, category.getCatvalue(), 0.001);
    assertEquals(1, category.getNode().size());
    final Node node = category.getNode().get(0);
    assertEquals(100.0, node.getNodevalue(), 0.001);
    assertEquals(0, node.getNodesvccount());
    assertEquals(0, node.getNodesvcdowncount());
}
Also used : RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) Category(org.opennms.netmgt.xml.rtc.Category) Node(org.opennms.netmgt.xml.rtc.Node) EuiLevel(org.opennms.netmgt.xml.rtc.EuiLevel) RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) Test(org.junit.Test)

Example 2 with Category

use of org.opennms.netmgt.xml.rtc.Category 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)

Example 3 with Category

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

the class AvailabilityServiceHibernateImpl method getEuiLevel.

/**
 * Optimized method for calculating the category statistics.
 *
 * We start off by retrieving outages affecting the nodes and services
 * in the given category, and group these by node id.
 *
 * Using the outages, we calculate node-level statistics
 * and tally the values to calculate the category statistics.
 */
@Override
@Transactional(readOnly = true)
public synchronized EuiLevel getEuiLevel(RTCCategory category) {
    final Header header = new Header();
    header.setVer("1.9a");
    header.setMstation("");
    // current time
    final Date curDate = new Date();
    final long curTime = curDate.getTime();
    // get the rolling window
    final long rWindow = 24L * 60L * 60L * 1000L;
    LOG.debug("Retrieving availability statistics for {} with current date: {} and rolling window: {}", category.getLabel(), curDate, rWindow);
    // create the data
    final EuiLevel level = new EuiLevel();
    // set created in m_header and add to level
    header.setCreated(EventConstants.formatToString(curDate));
    level.setHeader(header);
    final Category levelCat = new Category();
    // category label
    levelCat.setCatlabel(category.getLabel());
    double outageTimeInCategory = 0.0;
    int numServicesInCategory = 0;
    // window bounds
    final Date windowStart = new Date(curTime - rWindow);
    final Date windowEnd = new Date(curTime);
    // category specifics
    final List<Integer> nodeIds = getNodes(category);
    final List<String> serviceNames = category.getServices();
    // retrieve the outages associated with the given nodes, only retrieving those that affect our window
    final Map<Integer, List<OnmsOutage>> outagesByNode = getOutages(nodeIds, serviceNames, windowStart, windowEnd);
    // calculate the node level statistics
    for (final int nodeId : nodeIds) {
        List<OnmsOutage> outages = outagesByNode.get(nodeId);
        if (outages == null) {
            outages = Lists.newArrayList();
        }
        // sum the outage time
        final double outageTime = getOutageTimeInWindow(outages, windowStart, windowEnd);
        // determine the number of services
        final int numServices = getNumServices(nodeId, serviceNames);
        // count the number of outstanding outages
        final long numServicesDown = outages.stream().filter(outage -> outage.getIfRegainedService() == null).count();
        final Node levelNode = new Node();
        levelNode.setNodeid(nodeId);
        // value for this node for this category
        levelNode.setNodevalue(RTCUtils.getOutagePercentage(outageTime, rWindow, numServices));
        // node service count
        levelNode.setNodesvccount(numServices);
        // node service down count
        levelNode.setNodesvcdowncount(numServicesDown);
        // add the node
        levelCat.getNode().add(levelNode);
        // update the category statistics
        numServicesInCategory += numServices;
        outageTimeInCategory += outageTime;
    }
    // calculate the outage percentage using tallied values
    levelCat.setCatvalue(RTCUtils.getOutagePercentage(outageTimeInCategory, rWindow, numServicesInCategory));
    // add category
    level.getCategory().add(levelCat);
    LOG.debug("Done retrieving availability statistics for {} with {} services.", category.getLabel(), numServicesInCategory);
    return level;
}
Also used : NullRestriction(org.opennms.core.criteria.restrictions.NullRestriction) AllRestriction(org.opennms.core.criteria.restrictions.AllRestriction) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) EventConstants(org.opennms.netmgt.events.api.EventConstants) MonitoredServiceDao(org.opennms.netmgt.dao.api.MonitoredServiceDao) RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) Lists(com.google.common.collect.Lists) Map(java.util.Map) EuiLevel(org.opennms.netmgt.xml.rtc.EuiLevel) Node(org.opennms.netmgt.xml.rtc.Node) Header(org.opennms.netmgt.xml.rtc.Header) GtRestriction(org.opennms.core.criteria.restrictions.GtRestriction) Logger(org.slf4j.Logger) OutageDao(org.opennms.netmgt.dao.api.OutageDao) FilterDao(org.opennms.netmgt.filter.api.FilterDao) Category(org.opennms.netmgt.xml.rtc.Category) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) LeRestriction(org.opennms.core.criteria.restrictions.LeRestriction) List(java.util.List) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Preconditions(com.google.common.base.Preconditions) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) Transactional(org.springframework.transaction.annotation.Transactional) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) Category(org.opennms.netmgt.xml.rtc.Category) Node(org.opennms.netmgt.xml.rtc.Node) Date(java.util.Date) Header(org.opennms.netmgt.xml.rtc.Header) List(java.util.List) EuiLevel(org.opennms.netmgt.xml.rtc.EuiLevel) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

RTCCategory (org.opennms.netmgt.rtc.datablock.RTCCategory)3 Category (org.opennms.netmgt.xml.rtc.Category)3 EuiLevel (org.opennms.netmgt.xml.rtc.EuiLevel)3 Date (java.util.Date)2 Test (org.junit.Test)2 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)2 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)2 Node (org.opennms.netmgt.xml.rtc.Node)2 Preconditions (com.google.common.base.Preconditions)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)1 AllRestriction (org.opennms.core.criteria.restrictions.AllRestriction)1 GtRestriction (org.opennms.core.criteria.restrictions.GtRestriction)1 LeRestriction (org.opennms.core.criteria.restrictions.LeRestriction)1 NullRestriction (org.opennms.core.criteria.restrictions.NullRestriction)1 MonitoredServiceDao (org.opennms.netmgt.dao.api.MonitoredServiceDao)1