Search in sources :

Example 36 with UndeclaredThrowableException

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

the class SmtpMonitorIT method testPollCaseForCRLFCheck.

@Test
public void testPollCaseForCRLFCheck() throws UnknownHostException, InterruptedException {
    m_serverThread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                m_serverSocket.setSoTimeout(1000);
                Socket s = m_serverSocket.accept();
                System.out.println("S: 220 localhost.localdomain ESMTP bogon");
                // Having \r should fail in cheking for end of the line as the requirement is for CRLF
                s.getOutputStream().write("220 localhost.localdomain ESMTP bogon\r".getBytes());
                BufferedReader r = new BufferedReader(new InputStreamReader(s.getInputStream()));
                String command = r.readLine();
                System.out.println("C: " + command);
                if (command.startsWith("HELO ")) {
                    System.out.println("S: 250 Hello");
                    s.getOutputStream().write("250 Hello\r\n".getBytes());
                }
                command = r.readLine();
                System.out.println("C: " + command);
                if (command.equals("QUIT")) {
                    System.out.println("S: 221-Goodbye, friend.");
                    s.getOutputStream().write("221-Goodbye, friend.\r\n".getBytes());
                    System.out.println("S: 221 See ya");
                    s.getOutputStream().write("221 See ya\r\n".getBytes());
                }
            } catch (Throwable e) {
                throw new UndeclaredThrowableException(e);
            }
        }
    });
    m_serverThread.start();
    ServiceMonitor sm = new SmtpMonitor();
    MonitoredService svc = new MockMonitoredService(1, "Node One", InetAddressUtils.addr("127.0.0.1"), "SMTP");
    Map<String, Object> parms = new HashMap<String, Object>();
    parms.put("port", m_serverSocket.getLocalPort());
    PollStatus ps = sm.poll(svc, parms);
    assertTrue(ps.isUnavailable());
    assertFalse(ps.isUp());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) BufferedReader(java.io.BufferedReader) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Test(org.junit.Test)

Example 37 with UndeclaredThrowableException

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

the class SmtpMonitorIT method testPoll.

@Test
public void testPoll() throws UnknownHostException, InterruptedException {
    m_serverThread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                m_serverSocket.setSoTimeout(1000);
                Socket s = m_serverSocket.accept();
                System.out.println("S: 220 localhost.localdomain ESMTP bogon");
                s.getOutputStream().write("220 localhost.localdomain ESMTP bogon\r\n".getBytes());
                BufferedReader r = new BufferedReader(new InputStreamReader(s.getInputStream()));
                String command = r.readLine();
                System.out.println("C: " + command);
                if (command.startsWith("HELO ")) {
                    System.out.println("S: 250 Hello");
                    s.getOutputStream().write("250 Hello\r\n".getBytes());
                }
                command = r.readLine();
                System.out.println("C: " + command);
                if (command.equals("QUIT")) {
                    System.out.println("S: 250 Hello");
                    s.getOutputStream().write("221 See ya\r\n".getBytes());
                }
            } catch (Throwable e) {
                throw new UndeclaredThrowableException(e);
            }
        }
    });
    m_serverThread.start();
    ServiceMonitor sm = new SmtpMonitor();
    MonitoredService svc = new MockMonitoredService(1, "Node One", InetAddressUtils.addr("127.0.0.1"), "SMTP");
    Map<String, Object> parms = new HashMap<String, Object>();
    parms.put("port", m_serverSocket.getLocalPort());
    PollStatus ps = sm.poll(svc, parms);
    assertTrue(ps.isUp());
    assertFalse(ps.isDown());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) BufferedReader(java.io.BufferedReader) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Test(org.junit.Test)

Example 38 with UndeclaredThrowableException

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

the class JdbcFilterDao method getNodeMap.

/**
     * {@inheritDoc}
     *
     * This method returns a map of all nodeids and nodelabels that match
     * the rule that is passed in, sorted by nodeid.
     * @exception FilterParseException
     *                if a rule is syntactically incorrect or failed in
     *                executing the SQL statement
     */
@Override
public SortedMap<Integer, String> getNodeMap(final String rule) throws FilterParseException {
    final SortedMap<Integer, String> resultMap = new TreeMap<Integer, String>();
    String sqlString;
    LOG.debug("Filter.getNodeMap({})", rule);
    // get the database connection
    Connection conn = null;
    final DBUtils d = new DBUtils(getClass());
    try {
        conn = getDataSource().getConnection();
        d.watch(conn);
        // parse the rule and get the sql select statement
        sqlString = getNodeMappingStatement(rule);
        LOG.debug("Filter.getNodeMap({}): SQL statement: {}", rule, sqlString);
        // execute query
        final Statement stmt = conn.createStatement();
        d.watch(stmt);
        final ResultSet rset = stmt.executeQuery(sqlString);
        d.watch(rset);
        if (rset != null) {
            // Iterate through the result and build the map
            while (rset.next()) {
                resultMap.put(Integer.valueOf(rset.getInt(1)), rset.getString(2));
            }
        }
    } catch (final FilterParseException e) {
        LOG.warn("Filter Parse Exception occurred getting node map.", e);
        throw new FilterParseException("Filter Parse Exception occurred getting node map: " + e.getLocalizedMessage(), e);
    } catch (final SQLException e) {
        LOG.warn("SQL Exception occurred getting node map.", e);
        throw new FilterParseException("SQL Exception occurred getting node map: " + e.getLocalizedMessage(), e);
    } catch (final Throwable e) {
        LOG.error("Exception getting database connection.", e);
        throw new UndeclaredThrowableException(e);
    } finally {
        d.cleanUp();
    }
    return Collections.unmodifiableSortedMap(resultMap);
}
Also used : FilterParseException(org.opennms.netmgt.filter.api.FilterParseException) SQLException(java.sql.SQLException) Statement(java.sql.Statement) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) Connection(java.sql.Connection) DBUtils(org.opennms.core.utils.DBUtils) ResultSet(java.sql.ResultSet) TreeMap(java.util.TreeMap)

Example 39 with UndeclaredThrowableException

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

the class FtpMonitorTest method testMonitorFailureWithBogusResponse.

public void testMonitorFailureWithBogusResponse() throws Exception {
    Thread m_serverThread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                m_serverSocket.setSoTimeout(1000);
                Socket s = m_serverSocket.accept();
                s.getOutputStream().write("Go away!".getBytes());
            } catch (Throwable e) {
                throw new UndeclaredThrowableException(e);
            }
        }
    });
    m_serverThread.start();
    PollStatus status = doPoll();
    assertTrue("status should be unavailable (Down), but is: " + status, status.isUnavailable());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket)

Example 40 with UndeclaredThrowableException

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

the class Scriptd method onInit.

/**
     * Initialize the <em>Scriptd</em> service.
     */
@Override
protected void onInit() {
    // Load the configuration information
    //
    ScriptdConfigFactory aFactory = null;
    try {
        ScriptdConfigFactory.reload();
        aFactory = ScriptdConfigFactory.getInstance();
    } catch (IOException ex) {
        LOG.error("Failed to load scriptd configuration", ex);
        throw new UndeclaredThrowableException(ex);
    }
    // get the node DAO
    BeanFactoryReference bf = BeanUtils.getBeanFactory("daoContext");
    NodeDao nodeDao = BeanUtils.getBean(bf, "nodeDao", NodeDao.class);
    m_executor = new Executor(aFactory, nodeDao);
}
Also used : BeanFactoryReference(org.springframework.beans.factory.access.BeanFactoryReference) NodeDao(org.opennms.netmgt.dao.api.NodeDao) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ScriptdConfigFactory(org.opennms.netmgt.config.ScriptdConfigFactory) IOException(java.io.IOException)

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