use of org.opennms.web.rest.v1.support.TimeChunker in project opennms by OpenNMS.
the class AvailCalculatorTest method testGetAvailabilityUnavailableBefore.
@Test
public void testGetAvailabilityUnavailableBefore() {
Date endTime = new Date(System.currentTimeMillis());
Date startTime = new Date(endTime.getTime() - 100);
TimeChunker chunker = new TimeChunker((int) (endTime.getTime() - startTime.getTime()), startTime, endTime);
AvailCalculator calculator = new AvailCalculator(chunker);
calculator.onStatusChange(createStatusChange(PollStatus.unavailable(), new Date(endTime.getTime() - 150)));
calculator.onStatusChange(createStatusChange(PollStatus.available(), new Date(endTime.getTime() - 50)));
Collection<OnmsMonitoredService> svcs = getServices();
double uptimePercent = calculator.getAvailabilityFor(svcs, 0);
assertEquals(0.5, uptimePercent, 0.00);
}
use of org.opennms.web.rest.v1.support.TimeChunker in project opennms by OpenNMS.
the class RemotePollerAvailabilityRestServiceIT method testGetAvailability.
@Test
public void testGetAvailability() {
final long endMillis = System.currentTimeMillis();
final long startMillis = endMillis - 12000;
final long totalTime = endMillis - startMillis;
m_transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
final TimeChunker timeChunker = new TimeChunker(totalTime, new Date(startMillis), new Date(endMillis));
// increment the time segment
timeChunker.getNextSegment();
final Collection<OnmsLocationSpecificStatus> allStatusChanges = m_locationMonitorDao.getStatusChangesForApplicationBetween(new Date(startMillis), new Date(endMillis), "IPv6");
final AvailCalculator calc = new AvailCalculator(timeChunker);
for (final OnmsLocationSpecificStatus statusChange : allStatusChanges) {
calc.onStatusChange(statusChange);
}
final Collection<OnmsMonitoredService> svcs = m_monServiceDao.findByApplication(m_applicationDao.findByName("IPv6"));
final double avail = calc.getAvailabilityFor(svcs, 0);
assertEquals(0.8333, avail, 0.0333);
}
});
}
use of org.opennms.web.rest.v1.support.TimeChunker in project opennms by OpenNMS.
the class ResolutionTest method testGetTimeIndex.
@Test
public void testGetTimeIndex() {
Date startDate = new Date(new Date().getTime() - 300000);
long endTime = startDate.getTime() + 300000;
TimeChunker resolution = new TimeChunker(60000, startDate, new Date(endTime));
Date date = new Date(startDate.getTime() + 150000);
assertEquals(2, resolution.getIndexContaining(date));
}
use of org.opennms.web.rest.v1.support.TimeChunker in project opennms by OpenNMS.
the class RemotePollerAvailabilityService method getTimeChunkerFromMidnight.
protected static TimeChunker getTimeChunkerFromMidnight() {
Calendar calendar = Calendar.getInstance();
Date startTime = new GregorianCalendar(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), 0, 0, 0).getTime();
return new TimeChunker(TimeChunker.MINUTE, startTime, new Date(System.currentTimeMillis()));
}
use of org.opennms.web.rest.v1.support.TimeChunker in project opennms by OpenNMS.
the class RemotePollerAvailabilityService method createTimeChunker.
private static TimeChunker createTimeChunker(MultivaluedMap<String, String> params) {
TimeChunker timeChunker;
Date start = getStartTime(params);
Date end = getEndTime(params);
if ((end.getTime() - start.getTime()) < TimeChunker.MINUTE) {
throw getException(Status.BAD_REQUEST, "The endTime has to be after the startTime by 5 minutes.\nCurrently the startTime is {} and endTime is {}.", start.toString(), end.toString());
}
timeChunker = new TimeChunker(getResolution(params), start, end);
return timeChunker;
}
Aggregations