Search in sources :

Example 11 with EventHandler

use of org.opennms.netmgt.events.api.annotations.EventHandler in project opennms by OpenNMS.

the class Bsmd method handleReloadEvent.

@EventHandler(uei = EventConstants.RELOAD_DAEMON_CONFIG_UEI)
public void handleReloadEvent(Event e) {
    LOG.info("Received a reload configuration event: {}", e);
    final Parm daemonNameParm = e.getParm(EventConstants.PARM_DAEMON_NAME);
    if (daemonNameParm == null || daemonNameParm.getValue() == null) {
        LOG.warn("The {} parameter has no value. Ignoring.", EventConstants.PARM_DAEMON_NAME);
        return;
    }
    if (NAME.equalsIgnoreCase(daemonNameParm.getValue().getContent())) {
        LOG.info("Reloading bsmd.");
        EventBuilder ebldr = null;
        try {
            handleConfigurationChanged();
            ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_SUCCESSFUL_UEI, NAME);
            ebldr.addParam(EventConstants.PARM_DAEMON_NAME, NAME);
            LOG.info("Reload successful.");
        } catch (Throwable t) {
            ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_FAILED_UEI, NAME);
            ebldr.addParam(EventConstants.PARM_REASON, t.getLocalizedMessage().substring(0, 128));
            LOG.error("Reload failed.", t);
        }
        ebldr.addParam(EventConstants.PARM_DAEMON_NAME, NAME);
        m_eventIpcManager.sendNow(ebldr.getEvent());
    }
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Parm(org.opennms.netmgt.xml.event.Parm) EventHandler(org.opennms.netmgt.events.api.annotations.EventHandler)

Example 12 with EventHandler

use of org.opennms.netmgt.events.api.annotations.EventHandler in project opennms by OpenNMS.

the class AnnotationBasedEventListenerAdapter method populateUeiToHandlerMap.

private void populateUeiToHandlerMap() {
    Method[] methods = m_annotatedListener.getClass().getMethods();
    for (Method method : methods) {
        EventHandler handlerInfo = AnnotationUtils.findAnnotation(method, EventHandler.class);
        if (handlerInfo != null) {
            String singleUei = handlerInfo.uei();
            if (singleUei != null && !"".equals(singleUei)) {
                validateMethodAsEventHandler(method);
                Assert.state(!m_ueiToHandlerMap.containsKey(singleUei), "Cannot define method " + method + " as a handler for event " + singleUei + " since " + m_ueiToHandlerMap.get(singleUei) + " is already defined as a handler");
                m_ueiToHandlerMap.put(singleUei, method);
            }
            String[] ueis = handlerInfo.ueis();
            if (ueis != null && ueis.length > 0) {
                validateMethodAsEventHandler(method);
                for (String uei : ueis) {
                    Assert.state(!m_ueiToHandlerMap.containsKey(uei), "Cannot define method " + method + " as a handler for event " + uei + " since " + m_ueiToHandlerMap.get(uei) + " is already defined as a handler");
                    m_ueiToHandlerMap.put(uei, method);
                }
            }
        }
    }
    Assert.state(!m_ueiToHandlerMap.isEmpty(), "annotatedListener must have public EventHandler annotated methods");
}
Also used : EventHandler(org.opennms.netmgt.events.api.annotations.EventHandler) Method(java.lang.reflect.Method)

Example 13 with EventHandler

use of org.opennms.netmgt.events.api.annotations.EventHandler in project opennms by OpenNMS.

the class InterfaceToNodeCacheEventProcessor method handleInterfaceReparented.

@EventHandler(uei = EventConstants.INTERFACE_REPARENTED_EVENT_UEI)
@Transactional
public void handleInterfaceReparented(Event event) {
    LOG.debug("Received event: {}", event.getUei());
    final String oldNodeId = event.getParm(EventConstants.PARM_OLD_NODEID).getValue().getContent();
    final String newNodeId = event.getParm(EventConstants.PARM_NEW_NODEID).getValue().getContent();
    if (oldNodeId == null) {
        LOG.error(EventConstants.INTERFACE_REPARENTED_EVENT_UEI + ": Event with no node ID: " + event.toString());
        return;
    }
    if (newNodeId == null) {
        LOG.error(EventConstants.INTERFACE_REPARENTED_EVENT_UEI + ": Event with no node ID: " + event.toString());
        return;
    }
    final OnmsNode oldNode = m_nodeDao.get(oldNodeId);
    if (oldNode == null) {
        LOG.warn(EventConstants.INTERFACE_REPARENTED_EVENT_UEI + ": Cannot find node in DB: " + oldNodeId);
        return;
    }
    final OnmsNode newNode = m_nodeDao.get(newNodeId);
    if (newNode == null) {
        LOG.warn(EventConstants.INTERFACE_REPARENTED_EVENT_UEI + ": Cannot find node in DB: " + newNodeId);
        return;
    }
    // add to known nodes
    m_cache.removeNodeId(oldNode.getLocation().getLocationName(), event.getInterfaceAddress(), oldNode.getId());
    m_cache.setNodeId(newNode.getLocation().getLocationName(), event.getInterfaceAddress(), newNode.getId());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) EventHandler(org.opennms.netmgt.events.api.annotations.EventHandler) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with EventHandler

use of org.opennms.netmgt.events.api.annotations.EventHandler in project opennms by OpenNMS.

the class InterfaceToNodeCacheEventProcessor method handleInterfaceDeleted.

@EventHandler(uei = EventConstants.INTERFACE_DELETED_EVENT_UEI)
@Transactional
public void handleInterfaceDeleted(Event event) {
    LOG.debug("Received event: {}", event.getUei());
    Long nodeId = event.getNodeid();
    if (nodeId == null) {
        LOG.error(EventConstants.INTERFACE_DELETED_EVENT_UEI + ": Event with no node ID: " + event.toString());
        return;
    }
    OnmsNode node = m_nodeDao.get(nodeId.intValue());
    if (node == null) {
        LOG.warn(EventConstants.INTERFACE_DELETED_EVENT_UEI + ": Cannot find node in DB: " + nodeId);
        return;
    }
    // remove from known nodes
    m_cache.removeNodeId(node.getLocation().getLocationName(), event.getInterfaceAddress(), nodeId.intValue());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) EventHandler(org.opennms.netmgt.events.api.annotations.EventHandler) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with EventHandler

use of org.opennms.netmgt.events.api.annotations.EventHandler in project opennms by OpenNMS.

the class SnmpAssetProvisioningAdapter method handleReloadConfigEvent.

/**
 * <p>handleReloadConfigEvent</p>
 *
 * @param event a {@link org.opennms.netmgt.xml.event.Event} object.
 */
@EventHandler(uei = EventConstants.RELOAD_DAEMON_CONFIG_UEI)
public void handleReloadConfigEvent(final Event event) {
    if (isReloadConfigEventTarget(event)) {
        EventBuilder ebldr = null;
        LOG.debug("Reloading the SNMP asset adapter configuration");
        try {
            m_config.update();
            ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_SUCCESSFUL_UEI, "Provisiond." + NAME);
            ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "Provisiond." + NAME);
        } catch (Throwable e) {
            LOG.info("Unable to reload SNMP asset adapter configuration", e);
            ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_FAILED_UEI, "Provisiond." + NAME);
            ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "Provisiond." + NAME);
            ebldr.addParam(EventConstants.PARM_REASON, e.getLocalizedMessage().substring(1, 128));
        }
        if (ebldr != null) {
            getEventForwarder().sendNow(ebldr.getEvent());
        }
    }
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) EventHandler(org.opennms.netmgt.events.api.annotations.EventHandler)

Aggregations

EventHandler (org.opennms.netmgt.events.api.annotations.EventHandler)23 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)9 Parm (org.opennms.netmgt.xml.event.Parm)8 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ExecutionException (java.util.concurrent.ExecutionException)2 Task (org.opennms.core.tasks.Task)2 Value (org.opennms.netmgt.xml.event.Value)2 Method (java.lang.reflect.Method)1 InetAddress (java.net.InetAddress)1 ParseException (java.text.ParseException)1 IPAddress (org.opennms.core.network.IPAddress)1 IPAddressRange (org.opennms.core.network.IPAddressRange)1 RancidAdapterConfigFactory (org.opennms.netmgt.config.RancidAdapterConfigFactory)1 SnmpEventInfo (org.opennms.netmgt.config.SnmpEventInfo)1 OnmsAcknowledgment (org.opennms.netmgt.model.OnmsAcknowledgment)1 Event (org.opennms.netmgt.xml.event.Event)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1