Search in sources :

Example 6 with EventProxyException

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

the class DefaultRequisitionAccessService method importRequisition.

@Override
public void importRequisition(final String foreignSource, final String rescanExisting) {
    final URL activeUrl = createSnapshot(foreignSource);
    final String url = activeUrl.toString();
    LOG.debug("importRequisition: Sending import event with URL {}", url);
    final EventBuilder bldr = new EventBuilder(EventConstants.RELOAD_IMPORT_UEI, "Web");
    bldr.addParam(EventConstants.PARM_URL, url);
    if (rescanExisting != null) {
        bldr.addParam(EventConstants.PARM_IMPORT_RESCAN_EXISTING, rescanExisting);
    }
    try {
        getEventProxy().send(bldr.getEvent());
    } catch (final EventProxyException e) {
        throw new DataAccessResourceFailureException("Unable to send event to import group " + foreignSource, e);
    }
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) EventProxyException(org.opennms.netmgt.events.api.EventProxyException) URL(java.net.URL)

Example 7 with EventProxyException

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

the class DefaultResourceService method promoteGraphAttributesForResource.

/** {@inheritDoc} */
@Override
public void promoteGraphAttributesForResource(OnmsResource resource) {
    final String rrdBaseDir = System.getProperty("rrd.base.dir");
    List<String> rrdFiles = new LinkedList<String>();
    for (RrdGraphAttribute attribute : resource.getRrdGraphAttributes().values()) {
        rrdFiles.add(rrdBaseDir + File.separator + attribute.getRrdRelativePath());
    }
    EventBuilder bldr = new EventBuilder(EventConstants.PROMOTE_QUEUE_DATA_UEI, "OpenNMS.Webapp");
    bldr.addParam(EventConstants.PARM_FILES_TO_PROMOTE, rrdFiles);
    try {
        m_eventProxy.send(bldr.getEvent());
    } catch (EventProxyException e) {
        LOG.warn("Unable to send file promotion event to opennms: {}", e, e);
    }
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) EventProxyException(org.opennms.netmgt.events.api.EventProxyException) LinkedList(java.util.LinkedList) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute)

Example 8 with EventProxyException

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

the class NCSComponentServiceImpl method addOrUpdateComponents.

@Override
@Transactional
public NCSComponent addOrUpdateComponents(final NCSComponent component, final boolean deleteOrphans) {
    final ComponentIdentifier componentId = getIdentifier(component);
    LOG.debug("addOrUpdateComponents({}, {})", componentId, Boolean.valueOf(deleteOrphans));
    final ComponentEventQueue ceq = new ComponentEventQueue();
    final NCSComponent updatedComponent = addOrUpdateComponents(componentId, component, ceq, deleteOrphans);
    try {
        ceq.sendAll(m_eventProxy);
    } catch (final EventProxyException e) {
        LOG.warn("Component {} added, but an error occured while sending add/delete/update events.", componentId, e);
    }
    return updatedComponent;
}
Also used : NCSComponent(org.opennms.netmgt.model.ncs.NCSComponent) EventProxyException(org.opennms.netmgt.events.api.EventProxyException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with EventProxyException

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

the class HeartbeatConsumer method handleMessage.

@Override
@Transactional
public void handleMessage(MinionIdentityDTO minionHandle) {
    LOG.info("Received heartbeat for Minion with id: {} at location: {}", minionHandle.getId(), minionHandle.getLocation());
    OnmsMinion minion = minionDao.findById(minionHandle.getId());
    if (minion == null) {
        minion = new OnmsMinion();
        minion.setId(minionHandle.getId());
        // The real location is filled in below, but we set this to null
        // for now to detect requisition changes
        minion.setLocation(null);
    }
    final String prevLocation = minion.getLocation();
    final String nextLocation = minionHandle.getLocation();
    minion.setLocation(minionHandle.getLocation());
    // Provision the minions node before we alter the location
    this.provision(minion, prevLocation, nextLocation);
    if (minionHandle.getTimestamp() == null) {
        // The heartbeat does not contain a timestamp - use the current time
        minion.setLastUpdated(new Date());
        LOG.info("Received heartbeat without a timestamp: {}", minionHandle);
    } else if (minion.getLastUpdated() == null) {
        // The heartbeat does contain a timestamp, and we don't have
        // one set yet, so use whatever we've been given
        minion.setLastUpdated(minionHandle.getTimestamp());
    } else if (minionHandle.getTimestamp().after(minion.getLastUpdated())) {
        // The timestamp in the heartbeat is more recent than the one we
        // have stored, so update it
        minion.setLastUpdated(minionHandle.getTimestamp());
    } else {
        // The timestamp in the heartbeat is earlier than the
        // timestamp we have stored, so ignore it
        LOG.info("Ignoring stale timestamp from heartbeat: {}", minionHandle);
    }
    minionDao.saveOrUpdate(minion);
    if (prevLocation == null) {
        final EventBuilder eventBuilder = new EventBuilder(EventConstants.MONITORING_SYSTEM_ADDED_UEI, "OpenNMS.Minion.Heartbeat");
        eventBuilder.addParam(EventConstants.PARAM_MONITORING_SYSTEM_TYPE, OnmsMonitoringSystem.TYPE_MINION);
        eventBuilder.addParam(EventConstants.PARAM_MONITORING_SYSTEM_ID, minionHandle.getId());
        eventBuilder.addParam(EventConstants.PARAM_MONITORING_SYSTEM_LOCATION, nextLocation);
        try {
            eventProxy.send(eventBuilder.getEvent());
        } catch (final EventProxyException e) {
            throw new DataAccessResourceFailureException("Unable to send event", e);
        }
    } else if (!prevLocation.equals(nextLocation)) {
        final EventBuilder eventBuilder = new EventBuilder(EventConstants.MONITORING_SYSTEM_LOCATION_CHANGED_UEI, "OpenNMS.Minion.Heartbeat");
        eventBuilder.addParam(EventConstants.PARAM_MONITORING_SYSTEM_TYPE, OnmsMonitoringSystem.TYPE_MINION);
        eventBuilder.addParam(EventConstants.PARAM_MONITORING_SYSTEM_ID, minionHandle.getId());
        eventBuilder.addParam(EventConstants.PARAM_MONITORING_SYSTEM_PREV_LOCATION, prevLocation);
        eventBuilder.addParam(EventConstants.PARAM_MONITORING_SYSTEM_LOCATION, nextLocation);
        try {
            eventProxy.send(eventBuilder.getEvent());
        } catch (final EventProxyException e) {
            throw new DataAccessResourceFailureException("Unable to send event", e);
        }
    }
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsMinion(org.opennms.netmgt.model.minion.OnmsMinion) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) EventProxyException(org.opennms.netmgt.events.api.EventProxyException) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with EventProxyException

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

the class IfServicesRestService method sendEvent.

private void sendEvent(String eventUEI, OnmsMonitoredService dbObj) {
    final EventBuilder bldr = new EventBuilder(eventUEI, "ReST");
    bldr.setNodeid(dbObj.getNodeId());
    bldr.setInterface(dbObj.getIpAddress());
    bldr.setService(dbObj.getServiceName());
    try {
        m_eventProxy.send(bldr.getEvent());
    } catch (EventProxyException ex) {
        throw getException(Status.INTERNAL_SERVER_ERROR, "Cannot send event {} : {}", eventUEI, ex.getMessage());
    }
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) EventProxyException(org.opennms.netmgt.events.api.EventProxyException)

Aggregations

EventProxyException (org.opennms.netmgt.events.api.EventProxyException)15 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)9 Transactional (org.springframework.transaction.annotation.Transactional)4 NCSComponent (org.opennms.netmgt.model.ncs.NCSComponent)3 DataAccessResourceFailureException (org.springframework.dao.DataAccessResourceFailureException)3 Date (java.util.Date)2 Consumes (javax.ws.rs.Consumes)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 OnmsNode (org.opennms.netmgt.model.OnmsNode)2 OnmsMinion (org.opennms.netmgt.model.minion.OnmsMinion)2 Event (org.opennms.netmgt.xml.event.Event)2 BeanWrapper (org.springframework.beans.BeanWrapper)2 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 ConnectException (java.net.ConnectException)1 URL (java.net.URL)1 LinkedList (java.util.LinkedList)1 DELETE (javax.ws.rs.DELETE)1 Response (javax.ws.rs.core.Response)1