private static double getOutageTimeInWindow(List<OnmsOutage> outages, Date start, Date end) { if (outages == null || outages.size() == 0) { return 0.0d; } final long windowStart = start.getTime(); final long windowEnd = end.getTime(); final long windowLength = windowEnd - windowStart; Preconditions.checkArgument(0 <= windowStart && windowStart < windowEnd); long downtimeInWindow = 0; for (final OnmsOutage outage : outages) { // When did the service go down? // Use the start of the window if the service went down before this final long lostAt = Math.max(windowStart, outage.getIfLostService().getTime()); // When did the service come back up? long regainedAt; if (outage.getIfRegainedService() == null) { // It's still offline - use the end of the window regainedAt = windowEnd; } else { // Use the end of the window if the service came back up after this regainedAt = Math.min(windowEnd, outage.getIfRegainedService().getTime()); } downtimeInWindow += (regainedAt - lostAt); } // Bound the downtime by the length of the window return Math.min(downtimeInWindow, windowLength); }
if (outage.getIfLostService().before(periodStart)) { begin = periodStart; } else { begin = outage.getIfLostService();
if (outage.getIfLostService().before(periodStart)) { begin = periodStart; } else if (outage.getIfLostService().after(periodEnd)) { LoggerFactory.getLogger(DefaultRtcService.class).warn("Outage beginning is after period end {}, discarding outage: {}", periodEnd, outage.toString()); continue; } else { begin = outage.getIfLostService();
if (outage.getIfLostService().before(periodStart)) { begin = periodStart; } else if (outage.getIfLostService().after(periodEnd)) { LoggerFactory.getLogger(DefaultRtcService.class).warn("Outage beginning is after period end {}, discarding outage: {}", periodEnd, outage.toString()); continue; } else { begin = outage.getIfLostService();
if (outage.getIfLostService().before(periodStart)) { begin = periodStart; } else { begin = outage.getIfLostService();
boolean active = "A".equals(service.getStatus()); final Number svcLostEventId = event == null ? null : event.getId(); final Date ifLostService = outage == null ? null : outage.getIfLostService(); final String svcLostUei = event == null ? null : event.getEventUei();
assertEquals(2, httpOutages.size()); assertNotNull(httpOutages.get(0).getIfRegainedService()); assertNotNull(httpOutages.get(0).getIfLostService()); assertNotNull(httpOutages.get(0).getIfRegainedService()); assertNotNull(httpOutages.get(0).getServiceRegainedEvent()); assertNotNull(httpOutages.get(1).getIfLostService()); assertNotNull(httpOutages.get(1).getIfRegainedService()); assertNotNull(httpOutages.get(1).getServiceRegainedEvent());