Search in sources :

Example 6 with TimeChunker

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);
}
Also used : AvailCalculator(org.opennms.web.rest.v1.AvailCalculator) TimeChunker(org.opennms.web.rest.v1.support.TimeChunker) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test)

Example 7 with TimeChunker

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);
        }
    });
}
Also used : OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) TransactionStatus(org.springframework.transaction.TransactionStatus) Collection(java.util.Collection) TimeChunker(org.opennms.web.rest.v1.support.TimeChunker) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Date(java.util.Date) Test(org.junit.Test)

Example 8 with TimeChunker

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));
}
Also used : TimeChunker(org.opennms.web.rest.v1.support.TimeChunker) Date(java.util.Date) Test(org.junit.Test)

Example 9 with TimeChunker

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()));
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) TimeChunker(org.opennms.web.rest.v1.support.TimeChunker) Date(java.util.Date)

Example 10 with TimeChunker

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;
}
Also used : TimeChunker(org.opennms.web.rest.v1.support.TimeChunker) Date(java.util.Date)

Aggregations

Date (java.util.Date)10 TimeChunker (org.opennms.web.rest.v1.support.TimeChunker)9 Test (org.junit.Test)7 AvailCalculator (org.opennms.web.rest.v1.AvailCalculator)4 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)3 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)3 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Collection (java.util.Collection)1 GregorianCalendar (java.util.GregorianCalendar)1 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)1 OnmsLocationAvailDataPoint (org.opennms.netmgt.model.OnmsLocationAvailDataPoint)1 OnmsLocationAvailDefinition (org.opennms.netmgt.model.OnmsLocationAvailDefinition)1 OnmsLocationAvailDefinitionList (org.opennms.netmgt.model.OnmsLocationAvailDefinitionList)1 PollStatus (org.opennms.netmgt.poller.PollStatus)1 TimeChunk (org.opennms.web.rest.v1.support.TimeChunker.TimeChunk)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1