Search in sources :

Example 1 with AccessPointPoller

use of org.opennms.netmgt.accesspointmonitor.poller.AccessPointPoller in project opennms by OpenNMS.

the class DefaultPollingContext method run.

@Override
@Transactional
public void run() {
    // Determine the list of interfaces to poll at runtime
    OnmsIpInterfaceList ifaces = getInterfaceList();
    // If the list of interfaces is empty, print a warning message
    if (ifaces.getIpInterfaces().isEmpty()) {
        LOG.warn("Package '{}' was scheduled, but no interfaces were matched.", getPackage().getName());
    }
    // Get the complete list of APs that we are responsible for polling
    OnmsAccessPointCollection apsDown = m_accessPointDao.findByPackage(getPackage().getName());
    LOG.debug("Found {} APs in package '{}'", apsDown.size(), getPackage().getName());
    // Keep track of all APs that we've confirmed to be ONLINE
    OnmsAccessPointCollection apsUp = new OnmsAccessPointCollection();
    Set<Callable<OnmsAccessPointCollection>> callables = new HashSet<Callable<OnmsAccessPointCollection>>();
    // Iterate over all of the matched interfaces
    for (final OnmsIpInterface iface : ifaces.getIpInterfaces()) {
        // Create a new instance of the poller
        final AccessPointPoller p = m_package.getPoller(m_pollerConfig.getMonitors());
        p.setInterfaceToPoll(iface);
        p.setAccessPointDao(m_accessPointDao);
        p.setPackage(m_package);
        p.setPropertyMap(m_parameters);
        // Schedule the poller for execution
        callables.add(p);
    }
    boolean succesfullyPolledAController = false;
    try {
        if (m_pool == null) {
            LOG.warn("run() called, but no thread pool has been initialized.  Calling init()");
            init();
        }
        // Invoke all of the pollers using the thread pool
        List<Future<OnmsAccessPointCollection>> futures = m_pool.invokeAll(callables);
        // Gather the list of APs that are ONLINE
        for (Future<OnmsAccessPointCollection> future : futures) {
            try {
                apsUp.addAll(future.get().getObjects());
                succesfullyPolledAController = true;
            } catch (ExecutionException e) {
                LOG.error("An error occurred while polling", e);
            }
        }
    } catch (InterruptedException e) {
        LOG.error("I was interrupted", e);
    }
    // Remove the APs from the list that are ONLINE
    apsDown.removeAll(apsUp.getObjects());
    LOG.debug("({}) APs Online, ({}) APs offline in package '{}'", apsUp.size(), apsDown.size(), getPackage().getName());
    if (!succesfullyPolledAController) {
        LOG.warn("Failed to poll at least one controller in the package '{}'", getPackage().getName());
    }
    updateApStatus(apsUp, apsDown);
    // Reschedule the service
    LOG.debug("Re-scheduling the package '{}' in {}", getPackage().getName(), m_interval);
    m_scheduler.schedule(m_interval, getReadyRunnable());
}
Also used : OnmsAccessPointCollection(org.opennms.netmgt.model.OnmsAccessPointCollection) Callable(java.util.concurrent.Callable) AccessPointPoller(org.opennms.netmgt.accesspointmonitor.poller.AccessPointPoller) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) OnmsIpInterfaceList(org.opennms.netmgt.model.OnmsIpInterfaceList) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

HashSet (java.util.HashSet)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 AccessPointPoller (org.opennms.netmgt.accesspointmonitor.poller.AccessPointPoller)1 OnmsAccessPointCollection (org.opennms.netmgt.model.OnmsAccessPointCollection)1 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)1 OnmsIpInterfaceList (org.opennms.netmgt.model.OnmsIpInterfaceList)1 Transactional (org.springframework.transaction.annotation.Transactional)1