Search in sources :

Example 96 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project opennms by OpenNMS.

the class BgpSessionDetector method isServiceDetected.

/**
     * {@inheritDoc}
     *
     * Returns true if the protocol defined by this plugin is supported. If
     * the protocol is not supported then a false value is returned to the
     * caller. The qualifier map passed to the method is used by the plugin to
     * return additional information by key-name. These key-value pairs can be
     * added to service events if needed.
     */
@Override
public boolean isServiceDetected(final InetAddress address, final SnmpAgentConfig agentConfig) {
    try {
        String bgpPeerIp = getBgpPeerIp();
        configureAgentPTR(agentConfig);
        configureAgentVersion(agentConfig);
        String bgpPeerState = getValue(agentConfig, BGP_PEER_STATE_OID + "." + bgpPeerIp, isHex());
        LOG.debug("BgpSessionMonitor.capsd: bgpPeerState: {}", bgpPeerState);
        if (bgpPeerState != null && Integer.parseInt(bgpPeerState) >= 1 && Integer.parseInt(bgpPeerState) <= 6) {
            return true;
        }
    } catch (Throwable t) {
        throw new UndeclaredThrowableException(t);
    }
    return false;
}
Also used : UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Example 97 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project opennms by OpenNMS.

the class OmsaStorageDetector method isServiceDetected.

/**
     * {@inheritDoc}
     *
     * Returns true if the protocol defined by this plugin is supported. If
     * the protocol is not supported then a false value is returned to the
     * caller. The qualifier map passed to the method is used by the plugin to
     * return additional information by key-name. These key-value pairs can be
     * added to service events if needed.
     */
@Override
public boolean isServiceDetected(final InetAddress address, final SnmpAgentConfig agentConfig) {
    try {
        configureAgentPTR(agentConfig);
        configureAgentVersion(agentConfig);
        SnmpObjId virtualDiskRollUpStatusSnmpObject = SnmpObjId.get(virtualDiskRollUpStatus + '.' + m_virtualDiskNumber);
        SnmpValue virtualDiskRollUpStatus = SnmpUtils.get(agentConfig, virtualDiskRollUpStatusSnmpObject);
        if (virtualDiskRollUpStatus == null || virtualDiskRollUpStatus.isNull()) {
            LOG.debug("SNMP poll failed: no results, addr={} oid={}", agentConfig.getAddress(), virtualDiskRollUpStatusSnmpObject);
            return false;
        }
        if (virtualDiskRollUpStatus.toInt() != 3) {
            // 3 means Online
            LOG.debug("OMSAStorageMonitor.poll: Bad Disk Found. Log vol({}) degraded", m_virtualDiskNumber);
            return false;
        }
    } catch (Throwable t) {
        throw new UndeclaredThrowableException(t);
    }
    return true;
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId)

Example 98 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project opennms by OpenNMS.

the class LegacyScheduler method run.

/**
     * The main method of the scheduler. This method is responsible for checking
     * the runnable queues for ready objects and then enqueuing them into the
     * thread pool for execution.
     */
@Override
public void run() {
    synchronized (this) {
        m_status = RUNNING;
    }
    LOG.debug("run: scheduler running");
    /*
         * Loop until a fatal exception occurs or until
         * the thread is interrupted.
         */
    for (; ; ) {
        /*
             * Block if there is nothing in the queue(s).
             * When something is added to the queue it
             * signals us to wakeup.
             */
        synchronized (this) {
            if (m_status != RUNNING && m_status != PAUSED && m_status != PAUSE_PENDING && m_status != RESUME_PENDING) {
                LOG.debug("run: status = {}, time to exit", m_status);
                break;
            }
            // if paused or pause pending then block
            while (m_status == PAUSE_PENDING || m_status == PAUSED) {
                if (m_status == PAUSE_PENDING) {
                    LOG.debug("run: pausing.");
                }
                m_status = PAUSED;
                try {
                    wait();
                } catch (InterruptedException ex) {
                    // exit
                    break;
                }
            }
            if (m_status == RESUME_PENDING) {
                LOG.debug("run: resuming.");
                m_status = RUNNING;
            }
            if (m_scheduled == 0) {
                try {
                    LOG.debug("run: no ready runnables scheduled, waiting...");
                    wait();
                } catch (InterruptedException ex) {
                    break;
                }
            }
        }
        /*
             * Cycle through the queues checking for
             * what's ready to run.  The queues are keyed
             * by the interval, but the mapped elements
             * are peekable fifo queues.
             */
        int runned = 0;
        synchronized (m_queues) {
            /*
                 * Get an iterator so that we can cycle
                 * through the queue elements.
                 */
            for (Entry<Long, BlockingQueue<ReadyRunnable>> entry : m_queues.entrySet()) {
                /*
                     * Peak for Runnable objects until
                     * there are no more ready runnables.
                     *
                     * Also, only go through each queue once!
                     * if we didn't add a count then it would
                     * be possible to starve other queues.
                     */
                BlockingQueue<ReadyRunnable> in = entry.getValue();
                ReadyRunnable readyRun = null;
                int maxLoops = in.size();
                do {
                    try {
                        readyRun = in.peek();
                        if (readyRun != null && readyRun.isReady()) {
                            LOG.debug("run: found ready runnable {}", readyRun);
                            /*
                                 * Pop the interface/readyRunnable from the
                                 * queue for execution.
                                 */
                            in.take();
                            // Add runnable to the execution queue
                            m_runner.execute(readyRun);
                            ++runned;
                            // Increment the execution counter
                            ++m_numTasksExecuted;
                            // Thread Pool Statistics
                            if (m_runner instanceof ThreadPoolExecutor) {
                                ThreadPoolExecutor e = (ThreadPoolExecutor) m_runner;
                                String ratio = String.format("%.3f", e.getTaskCount() > 0 ? new Double(e.getCompletedTaskCount()) / new Double(e.getTaskCount()) : 0);
                                LOG.debug("thread pool statistics: activeCount={}, taskCount={}, completedTaskCount={}, completedRatio={}, poolSize={}", e.getActiveCount(), e.getTaskCount(), e.getCompletedTaskCount(), ratio, e.getPoolSize());
                            }
                        }
                    } catch (InterruptedException e) {
                        // jump all the way out
                        return;
                    } catch (RejectedExecutionException e) {
                        throw new UndeclaredThrowableException(e);
                    }
                } while (readyRun != null && readyRun.isReady() && --maxLoops > 0);
            }
        }
        /*
             * Wait for 1 second if there were no runnables
             * executed during this loop, otherwise just
             * start over.
             */
        synchronized (this) {
            m_scheduled -= runned;
            if (runned == 0) {
                try {
                    wait(1000);
                } catch (InterruptedException ex) {
                    // exit for loop
                    break;
                }
            }
        }
    }
    LOG.debug("run: scheduler exiting, state = STOPPED");
    synchronized (this) {
        m_status = STOPPED;
    }
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 99 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project opennms by OpenNMS.

the class Util method createEventProxy.

/**
     * <p>createEventProxy</p>
     * 
     * @deprecated Use dependency injection to wire in an instance of the {@link EventProxy} instead
     *
     * @return a {@link org.opennms.netmgt.events.api.EventProxy} object.
     */
public static EventProxy createEventProxy() {
    /*
         * Rather than defaulting to localhost all the time, give an option in properties
         */
    final String vaultHost = Vault.getProperty("opennms.rtc.event.proxy.host");
    final String vaultPort = Vault.getProperty("opennms.rtc.event.proxy.port");
    final String vaultTimeout = Vault.getProperty("opennms.rtc.event.proxy.timeout");
    final String proxyHostName = vaultHost == null ? "127.0.0.1" : vaultHost;
    final String proxyHostPort = vaultPort == null ? Integer.toString(TcpEventProxy.DEFAULT_PORT) : vaultPort;
    final String proxyHostTimeout = vaultTimeout == null ? Integer.toString(TcpEventProxy.DEFAULT_TIMEOUT) : vaultTimeout;
    InetAddress proxyAddr = null;
    EventProxy proxy = null;
    proxyAddr = InetAddressUtils.addr(proxyHostName);
    if (proxyAddr == null) {
        try {
            proxy = new TcpEventProxy();
        } catch (final UnknownHostException e) {
            // XXX Ewwww!  We should just let the first UnknownException bubble up. 
            throw new UndeclaredThrowableException(e);
        }
    } else {
        proxy = new TcpEventProxy(new InetSocketAddress(proxyAddr, Integer.parseInt(proxyHostPort)), Integer.parseInt(proxyHostTimeout));
    }
    return proxy;
}
Also used : UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) TcpEventProxy(org.opennms.netmgt.events.api.support.TcpEventProxy) InetAddress(java.net.InetAddress) TcpEventProxy(org.opennms.netmgt.events.api.support.TcpEventProxy) EventProxy(org.opennms.netmgt.events.api.EventProxy)

Example 100 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project opennms by OpenNMS.

the class AbstractSimpleServer method getRunnable.

/**
     * <p>getRunnable</p>
     *
     * @return a {@link java.lang.Runnable} object.
     * @throws java.lang.Exception if any.
     */
public Runnable getRunnable() throws Exception {
    return new Runnable() {

        @Override
        public void run() {
            try {
                m_serverSocket.setSoTimeout(getTimeout());
                Socket socket = m_serverSocket.accept();
                OutputStream out = socket.getOutputStream();
                BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                attemptConversation(in, out);
                socket.close();
            } catch (Throwable e) {
                throw new UndeclaredThrowableException(e);
            }
        }
    };
}
Also used : InputStreamReader(java.io.InputStreamReader) OutputStream(java.io.OutputStream) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) BufferedReader(java.io.BufferedReader) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket)

Aggregations

UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)121 IOException (java.io.IOException)36 InvocationTargetException (java.lang.reflect.InvocationTargetException)14 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)14 Test (org.junit.Test)12 BufferedReader (java.io.BufferedReader)10 InputStreamReader (java.io.InputStreamReader)10 ServerSocket (java.net.ServerSocket)10 Socket (java.net.Socket)9 PollStatus (org.opennms.netmgt.poller.PollStatus)9 HashMap (java.util.HashMap)8 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)7 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)7 BadRequestException (org.apache.hadoop.yarn.webapp.BadRequestException)7 Method (java.lang.reflect.Method)6 AccessControlException (java.security.AccessControlException)6 SQLException (java.sql.SQLException)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)6