Search in sources :

Example 6 with AvailCalculator

use of org.opennms.web.rest.v1.AvailCalculator 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)

Aggregations

Date (java.util.Date)6 Test (org.junit.Test)5 TimeChunker (org.opennms.web.rest.v1.support.TimeChunker)5 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 Collection (java.util.Collection)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