Search in sources :

Example 36 with OnmsLocationSpecificStatus

use of org.opennms.netmgt.model.OnmsLocationSpecificStatus in project opennms by OpenNMS.

the class PollerBackEndTest method testStatusUpWhenNoneKnown.

public void testStatusUpWhenNoneKnown() {
    expect(m_locMonDao.get(LOCATION_MONITOR_ID)).andReturn(m_locationMonitor);
    expect(m_monSvcDao.get(2)).andReturn(m_dnsService);
    expect(m_locMonDao.getMostRecentStatusChange(m_locationMonitor, m_dnsService)).andReturn(null);
    // called when saving performance data
    expect(m_monitoringLocationDao.get(m_locationDefinition.getLocationName())).andReturn(m_locationDefinition);
    expect(m_pollerConfig.getPackage(m_package.getName())).andReturn(m_package);
    expect(m_pollerConfig.getServiceInPackage("DNS", m_package)).andReturn(m_dnsSvcConfig).times(3);
    expect(m_pollerConfig.parameters(m_dnsSvcConfig)).andReturn(m_dnsSvcConfig.getParameters()).times(6);
    final PollStatus newStatus = PollStatus.available(1234.0);
    OnmsLocationSpecificStatus expectedStatus = new OnmsLocationSpecificStatus(m_locationMonitor, m_dnsService, newStatus);
    m_locMonDao.saveStatusChange(isA(OnmsLocationSpecificStatus.class));
    expectLastCall().andAnswer(new StatusChecker(expectedStatus));
    m_mocks.replayAll();
    m_backEnd.saveResponseTimeData(m_locationMonitor.getId(), m_dnsService, 1234, m_package);
    m_backEnd.reportResult(LOCATION_MONITOR_ID, 2, newStatus);
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus)

Example 37 with OnmsLocationSpecificStatus

use of org.opennms.netmgt.model.OnmsLocationSpecificStatus in project opennms by OpenNMS.

the class RemotePollerAvailabilityRestServiceIT method createLocationMonitors.

private void createLocationMonitors() throws InterruptedException {
    m_transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            System.err.println("======= Starting createLocationMonitors() ======");
            OnmsLocationMonitor locMon1 = new OnmsLocationMonitor();
            locMon1.setId(UUID.randomUUID().toString());
            locMon1.setLocation("RDU");
            locMon1.setLastUpdated(new Date());
            locMon1.setStatus(MonitorStatus.STARTED);
            m_locationMonitorDao.save(locMon1);
            OnmsApplication ipv6App = new OnmsApplication();
            ipv6App.setName("IPv6");
            m_applicationDao.saveOrUpdate(ipv6App);
            OnmsApplication ipv4App = new OnmsApplication();
            ipv4App.setName("IPv4");
            m_applicationDao.saveOrUpdate(ipv4App);
            OnmsMonitoredService service2 = m_monServiceDao.findByType("HTTP").get(1);
            service2.addApplication(ipv4App);
            ipv4App.addMonitoredService(service2);
            m_monServiceDao.saveOrUpdate(service2);
            m_applicationDao.saveOrUpdate(ipv4App);
            List<OnmsMonitoredService> services = m_monServiceDao.findByType("HTTP");
            for (OnmsMonitoredService service : services) {
                service = m_monServiceDao.findByType("HTTP").get(0);
                service.addApplication(ipv6App);
                ipv6App.addMonitoredService(service);
                m_monServiceDao.saveOrUpdate(service);
                m_applicationDao.saveOrUpdate(ipv6App);
                OnmsLocationMonitor locMon = m_locationMonitorDao.findAll().get(0);
                OnmsLocationSpecificStatus statusChange = new OnmsLocationSpecificStatus();
                statusChange.setLocationMonitor(locMon);
                statusChange.setPollResult(PollStatus.available());
                statusChange.setMonitoredService(service);
                m_locationMonitorDao.saveStatusChange(statusChange);
            }
            System.err.println("======= End createLocationMonitors() ======");
        }
    });
    Thread.sleep(2000L);
    m_transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            List<OnmsMonitoredService> services = m_monServiceDao.findByType("HTTP");
            for (OnmsMonitoredService service : services) {
                OnmsLocationMonitor locMon = m_locationMonitorDao.findAll().get(0);
                OnmsLocationSpecificStatus statusChange = new OnmsLocationSpecificStatus();
                statusChange.setLocationMonitor(locMon);
                statusChange.setPollResult(PollStatus.unavailable());
                statusChange.setMonitoredService(service);
                m_locationMonitorDao.saveStatusChange(statusChange);
            }
        }
    });
    Thread.sleep(2000L);
    m_transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            List<OnmsMonitoredService> services = m_monServiceDao.findByType("HTTP");
            for (OnmsMonitoredService service : services) {
                OnmsLocationMonitor locMon = m_locationMonitorDao.findAll().get(0);
                OnmsLocationSpecificStatus statusChange = new OnmsLocationSpecificStatus();
                statusChange.setLocationMonitor(locMon);
                statusChange.setPollResult(PollStatus.available());
                statusChange.setMonitoredService(service);
                m_locationMonitorDao.saveStatusChange(statusChange);
            }
        }
    });
}
Also used : OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) TransactionStatus(org.springframework.transaction.TransactionStatus) List(java.util.List) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 38 with OnmsLocationSpecificStatus

use of org.opennms.netmgt.model.OnmsLocationSpecificStatus 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 39 with OnmsLocationSpecificStatus

use of org.opennms.netmgt.model.OnmsLocationSpecificStatus in project opennms by OpenNMS.

the class DefaultDistributedStatusServiceTest method expectEverything.

public void expectEverything() {
    expect(m_applicationDao.findByName("Application 1")).andReturn(m_application1);
    expect(m_monitoringLocationDao.get(m_locationDefinition1.getLocationName())).andReturn(m_locationDefinition1);
    expect(m_locationMonitorDao.findByLocationDefinition(m_locationDefinition1)).andReturn(Collections.singleton(m_locationMonitor1_1));
    OnmsMonitoredService httpService = findMonitoredService(m_services, m_ip, "HTTP");
    OnmsMonitoredService httpsService = findMonitoredService(m_services, m_ip, "HTTPS");
    expect(m_locationMonitorDao.getMostRecentStatusChange(m_locationMonitor1_1, httpService)).andReturn(new OnmsLocationSpecificStatus(m_locationMonitor1_1, httpService, PollStatus.available()));
    expect(m_locationMonitorDao.getMostRecentStatusChange(m_locationMonitor1_1, httpsService)).andReturn(null);
}
Also used : OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Aggregations

OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)39 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)18 Date (java.util.Date)17 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)14 ArrayList (java.util.ArrayList)13 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)11 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)8 PollStatus (org.opennms.netmgt.poller.PollStatus)8 Transactional (org.springframework.transaction.annotation.Transactional)8 HashSet (java.util.HashSet)7 SimpleWebTable (org.opennms.web.svclayer.model.SimpleWebTable)6 LinkedList (java.util.LinkedList)5 GWTLocationMonitor (org.opennms.features.poller.remote.gwt.client.GWTLocationMonitor)5 LinkedHashSet (java.util.LinkedHashSet)4 Test (org.junit.Test)4 StatusDetails (org.opennms.features.poller.remote.gwt.client.StatusDetails)4 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 ApplicationInfo (org.opennms.features.poller.remote.gwt.client.ApplicationInfo)3 GWTLocationSpecificStatus (org.opennms.features.poller.remote.gwt.client.GWTLocationSpecificStatus)3