Search in sources :

Example 41 with UndeclaredThrowableException

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

the class RTCUtils method createCategoriesMap.

/**
	 * Creates the categories map. Reads the categories from the categories.xml
	 * and creates the 'RTCCategory's map
	 */
public static HashMap<String, RTCCategory> createCategoriesMap() {
    CatFactory cFactory = null;
    try {
        CategoryFactory.init();
        cFactory = CategoryFactory.getInstance();
    } catch (IOException ex) {
        LOG.error("Failed to load categories information", ex);
        throw new UndeclaredThrowableException(ex);
    }
    HashMap<String, RTCCategory> retval = new HashMap<String, RTCCategory>();
    cFactory.getReadLock().lock();
    try {
        for (CategoryGroup cg : cFactory.getConfig().getCategoryGroups()) {
            final String commonRule = cg.getCommon().getRule();
            for (final org.opennms.netmgt.config.categories.Category cat : cg.getCategories()) {
                RTCCategory rtcCat = new RTCCategory(cat, commonRule);
                retval.put(rtcCat.getLabel(), rtcCat);
            }
        }
    } finally {
        cFactory.getReadLock().unlock();
    }
    return retval;
}
Also used : HashMap(java.util.HashMap) CatFactory(org.opennms.netmgt.config.api.CatFactory) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) IOException(java.io.IOException) RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) CategoryGroup(org.opennms.netmgt.config.categories.CategoryGroup)

Example 42 with UndeclaredThrowableException

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

the class XmpCollector method initialize.

/* handleTableQuery() */
/* public methods ************************************ */
/**
     * {@inheritDoc}
     *
     * initialize our XmpCollector with global parameters *
     */
@Override
public void initialize() {
    // initialize our data collection factory
    LOG.debug("initialize(params) called");
    try {
        XmpCollectionFactory.init();
    } catch (Throwable e) {
        LOG.error("initialize: XmpCollectionFactory failed to initialize");
        throw new UndeclaredThrowableException(e);
    }
    try {
        XmpPeerFactory.init();
    } catch (Throwable e) {
        LOG.error("initialize: XmpPeerFactory failed to initialize");
        throw new UndeclaredThrowableException(e);
    }
    try {
        XmpConfigFactory.init();
    } catch (Throwable e) {
        LOG.error("initialize: config factory failed to initialize");
        throw new UndeclaredThrowableException(e);
    }
    if (m_resourceTypesDao == null) {
        m_resourceTypesDao = BeanUtils.getBean("daoContext", "resourceTypesDao", ResourceTypesDao.class);
    }
    // get our top-level object for our protocol config file,
    // xmp-config.xml, already parsed and ready to examine
    XmpConfig protoConfig = XmpConfigFactory.getInstance().getXmpConfig();
    if (protoConfig.hasPort())
        xmpPort = protoConfig.getPort();
    if (protoConfig.hasTimeout())
        timeout = protoConfig.getTimeout();
    // be non-null
    if (protoConfig.getAuthenUser() != null)
        authenUser = protoConfig.getAuthenUser();
    LOG.debug("initialize: authenUser '{}' port {}", authenUser, xmpPort);
    LOG.debug("initialize: keystore found? {}", sockopts.getKeystoreFound());
    return;
}
Also used : ResourceTypesDao(org.opennms.netmgt.config.api.ResourceTypesDao) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) XmpConfig(org.opennms.netmgt.config.xmpConfig.XmpConfig)

Example 43 with UndeclaredThrowableException

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

the class DataManager method nodeGainedService.

/**
     * Handles a node gained service event. Add a new entry to the map and the
     * categories on a 'serviceGained' event
     *
     * @param nodeid
     *            the node id
     * @param ip
     *            the IP address
     * @param svcName
     *            the service name
     */
public synchronized void nodeGainedService(int nodeid, InetAddress ip, String svcName) {
    //
    // check the 'status' flag for the service
    //
    String svcStatus = m_monitoredServiceDao.get((int) nodeid, ip, svcName).getStatus();
    //
    if (!"A".equals(svcStatus)) {
        LOG.info("nodeGainedSvc: {}/{}/{} IGNORED because status is not active: {}", nodeid, ip, svcName, svcStatus);
    } else {
        LOG.debug("nodeGainedSvc: {}/{}/{}/{}", nodeid, ip, svcName, svcStatus);
        // I ran into problems with adding new services, so I just ripped
        // all that out and added
        // a call to the rescan method. -T
        // Hrm - since the rules can be based on things other than the
        // service name
        // we really need to rescan every time a new service is discovered.
        // For
        // example, if I have a category where the rule is "ipaddr =
        // 10.1.1.1 & isHTTP"
        // yet I only have ICMP in the service list, the node will not be
        // added when
        // HTTP is discovered, because it is not in the services list.
        // 
        // This is mainly useful when SNMP is discovered on a node.
        LOG.debug("rtcN : Rescanning services on : {}", ip);
        try {
            rtcNodeRescan(nodeid);
        } catch (FilterParseException ex) {
            LOG.warn("Failed to unmarshall database config", ex);
            throw new UndeclaredThrowableException(ex);
        } catch (SQLException ex) {
            LOG.warn("Failed to get database connection", ex);
            throw new UndeclaredThrowableException(ex);
        } catch (RTCException ex) {
            LOG.warn("Failed to get database connection", ex);
            throw new UndeclaredThrowableException(ex);
        }
    }
}
Also used : FilterParseException(org.opennms.netmgt.filter.api.FilterParseException) SQLException(java.sql.SQLException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Example 44 with UndeclaredThrowableException

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

the class Vacuumd method onInit.

/*
     * (non-Javadoc)
     * 
     * @see org.opennms.netmgt.vacuumd.jmx.VacuumdMBean#init()
     */
/** {@inheritDoc} */
@Override
protected void onInit() {
    try {
        LOG.info("Loading the configuration file.");
        VacuumdConfigFactory.init();
        getEventManager().addEventListener(this, EventConstants.RELOAD_VACUUMD_CONFIG_UEI);
        getEventManager().addEventListener(this, EventConstants.RELOAD_DAEMON_CONFIG_UEI);
        initializeDataSources();
    } catch (Throwable ex) {
        LOG.error("Failed to load outage configuration", ex);
        throw new UndeclaredThrowableException(ex);
    }
    LOG.info("Vacuumd initialization complete");
    createScheduler();
    scheduleAutomations();
}
Also used : UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Example 45 with UndeclaredThrowableException

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

the class Poller method isServer.

/**
     * <p>
     * This method actually tests the remote host to determine if it is
     * running a functional DHCP server.
     * </p>
     * <p>
     * Formats a DHCP query and encodes it in a client request message which
     * is sent to the DHCP daemon over the established TCP socket connection.
     * If a matching DHCP response packet is not received from the DHCP daemon
     * within the specified timeout the client request message will be re-sent
     * up to the specified number of retries.
     * </p>
     * <p>
     * If a response is received from the DHCP daemon it is validated to
     * ensure that:
     * </p>
     * <ul>
     * <li>The DHCP response packet was sent from the remote host to which the
     * original request packet was directed.</li>
     * <li>The XID of the DHCP response packet matches the XID of the original
     * DHCP request packet.</li>
     * </ul>
     * <p>
     * If the response validates 'true' is returned. Otherwise the request is
     * resent until max retry count is exceeded.
     * </p>
     * <p>
     * Before returning, a client disconnect message (remote host field set to
     * zero) is sent to the DHCP daemon.
     * </p>
     * 
     * @return response time in milliseconds if the specified host responded
     *         with a valid DHCP offer datagram within the context of the
     *         specified timeout and retry values or negative one (-1)
     *         otherwise.
     */
static long isServer(InetAddress host, long timeout, int retries) throws IOException {
    boolean isDhcpServer = false;
    // List of DHCP queries to try. The default when extended
    // mode = false must be listed first. (DISCOVER)
    byte[] typeList = { (byte) DHCPMessage.DISCOVER, (byte) DHCPMessage.INFORM, (byte) DHCPMessage.REQUEST };
    String[] typeName = { "DISCOVER", "INFORM", "REQUEST" };
    DhcpdConfigFactory dcf = DhcpdConfigFactory.getInstance();
    if (!paramsChecked) {
        String s_extendedMode = dcf.getExtendedMode();
        if (s_extendedMode == null) {
            extendedMode = false;
        } else {
            extendedMode = Boolean.parseBoolean(s_extendedMode);
        }
        LOG.debug("isServer: DHCP extended mode is {}", extendedMode);
        String hwAddressStr = dcf.getMacAddress();
        LOG.debug("isServer: DHCP query hardware/MAC address is {}", hwAddressStr);
        setHwAddress(hwAddressStr);
        String myIpStr = dcf.getMyIpAddress();
        LOG.debug("isServer: DHCP relay agent address is {}", myIpStr);
        if (myIpStr == null || myIpStr.equals("") || myIpStr.equalsIgnoreCase("broadcast")) {
        // do nothing
        } else {
            try {
                InetAddressUtils.toIpAddrBytes(myIpStr);
                s_myIpAddress = setIpAddress(myIpStr);
                relayMode = true;
            } catch (IllegalArgumentException e) {
                LOG.warn("isServer: DHCP relay agent address is invalid: {}", myIpStr);
            }
        }
        if (extendedMode == true) {
            String requestStr = dcf.getRequestIpAddress();
            LOG.debug("isServer: REQUEST query target is {}", requestStr);
            if (requestStr == null || requestStr.equals("") || requestStr.equalsIgnoreCase("targetSubnet")) {
            // do nothing
            } else if (requestStr.equalsIgnoreCase("targetHost")) {
                targetOffset = false;
            } else {
                try {
                    InetAddressUtils.toIpAddrBytes(requestStr);
                    s_requestIpAddress = setIpAddress(requestStr);
                    reqTargetIp = false;
                    targetOffset = false;
                } catch (IllegalArgumentException e) {
                    LOG.warn("isServer: REQUEST query target is invalid: {}", requestStr);
                }
            }
            LOG.debug("REQUEST query options are: reqTargetIp = {}, targetOffset = {}", reqTargetIp, targetOffset);
        }
        paramsChecked = true;
    }
    int j = 1;
    if (extendedMode == true) {
        j = typeList.length;
    }
    if (timeout < 500) {
        timeout = 500;
    }
    Poller p = new Poller(timeout);
    long responseTime = -1;
    try {
        pollit: for (int i = 0; i < j; i++) {
            Message ping = getPollingRequest(host, (byte) typeList[i]);
            int rt = retries;
            while (rt >= 0 && !isDhcpServer) {
                LOG.debug("isServer: sending DHCP {} query to host {} with Xid: {}", typeName[i], InetAddressUtils.str(host), ping.getMessage().getXid());
                long start = System.currentTimeMillis();
                p.m_outs.writeObject(ping);
                long end;
                do {
                    Message resp = null;
                    try {
                        resp = (Message) p.m_ins.readObject();
                    } catch (InterruptedIOException ex) {
                        resp = null;
                    }
                    if (resp != null) {
                        responseTime = System.currentTimeMillis() - start;
                        // DEBUG only
                        LOG.debug("isServer: got a DHCP response from host {} with Xid: {}", InetAddressUtils.str(resp.getAddress()), resp.getMessage().getXid());
                        if (host.equals(resp.getAddress()) && ping.getMessage().getXid() == resp.getMessage().getXid()) {
                            // Inspect response message to see if it is a valid DHCP response
                            byte[] type = resp.getMessage().getOption(MESSAGE_TYPE);
                            if (type[0] == DHCPMessage.OFFER) {
                                LOG.debug("isServer: got a DHCP OFFER response, validating...");
                            } else if (type[0] == DHCPMessage.ACK) {
                                LOG.debug("isServer: got a DHCP ACK response, validating...");
                            } else if (type[0] == DHCPMessage.NAK) {
                                LOG.debug("isServer: got a DHCP NAK response, validating...");
                            }
                            // accept offer or ACK or NAK
                            if (type[0] == DHCPMessage.OFFER || (extendedMode == true && (type[0] == DHCPMessage.ACK || type[0] == DHCPMessage.NAK))) {
                                LOG.debug("isServer: got a valid DHCP response. responseTime= {}ms", responseTime);
                                isDhcpServer = true;
                                break pollit;
                            }
                        }
                    }
                    end = System.currentTimeMillis();
                } while ((end - start) < timeout);
                if (!isDhcpServer) {
                    LOG.debug("Timed out waiting for DHCP response, remaining retries: {}", rt);
                }
                --rt;
            }
        }
        LOG.debug("Sending disconnect request");
        p.m_outs.writeObject(getDisconnectRequest());
        LOG.debug("wait half a sec before closing connection");
        Thread.sleep(500);
        p.close();
    } catch (IOException ex) {
        LOG.error("IO Exception caught.", ex);
        p.close();
        throw ex;
    } catch (Throwable t) {
        LOG.error("Unexpected Exception caught.", t);
        p.close();
        throw new UndeclaredThrowableException(t);
    }
    // server or -1 if the remote box is NOT a DHCP server.
    if (isDhcpServer) {
        return responseTime;
    } else {
        return -1;
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) DHCPMessage(edu.bucknell.net.JDHCP.DHCPMessage) DhcpdConfigFactory(org.opennms.netmgt.config.dhcpd.DhcpdConfigFactory) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

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