Search in sources :

Example 1 with EventProxyException

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

the class TcpEventProxy method send.

/**
     * This method is called to send an event log containing multiple events
     * out.
     *
     * @param eventLog
     *            the events to be sent out
     * @exception UndeclaredThrowableException
     *                thrown if the send fails for any reason
     * @throws org.opennms.netmgt.events.api.EventProxyException if any.
     */
@Override
public void send(Log eventLog) throws EventProxyException {
    Connection connection = null;
    try {
        connection = new Connection();
        final Writer writer = connection.getWriter();
        JaxbUtils.marshal(eventLog, writer);
        writer.flush();
    } catch (ConnectException e) {
        throw new EventProxyException("Could not connect to event daemon " + m_address + " to send event: " + e.getMessage(), e);
    } catch (Throwable e) {
        throw new EventProxyException("Unknown exception while sending event: " + e, e);
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : EventProxyException(org.opennms.netmgt.events.api.EventProxyException) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) ConnectException(java.net.ConnectException)

Example 2 with EventProxyException

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

the class HeartbeatConsumer method provision.

private void provision(final OnmsMinion minion, final String prevLocation, final String nextLocation) {
    // Return fast if automatic provisioning is disabled
    if (!PROVISIONING) {
        return;
    }
    // Return fast until the provisioner is running to pick up the events sent below
    if (!this.eventSubscriptionService.hasEventListener(EventConstants.RELOAD_IMPORT_UEI)) {
        return;
    }
    final String prevForeignSource = String.format(PROVISIONING_FOREIGN_SOURCE_PATTERN, prevLocation);
    final String nextForeignSource = String.format(PROVISIONING_FOREIGN_SOURCE_PATTERN, nextLocation);
    final Set<String> alteredForeignSources = Sets.newHashSet();
    // Remove the node from the previous requisition, if location has changed
    if (!Objects.equals(prevForeignSource, nextForeignSource)) {
        final Requisition prevRequisition = this.deployedForeignSourceRepository.getRequisition(prevForeignSource);
        if (prevRequisition != null && prevRequisition.getNode(minion.getId()) != null) {
            prevRequisition.deleteNode(minion.getId());
            prevRequisition.updateDateStamp();
            deployedForeignSourceRepository.save(prevRequisition);
            deployedForeignSourceRepository.flush();
            alteredForeignSources.add(prevForeignSource);
        }
    }
    Requisition nextRequisition = deployedForeignSourceRepository.getRequisition(nextForeignSource);
    if (nextRequisition == null) {
        nextRequisition = new Requisition(nextForeignSource);
        nextRequisition.updateDateStamp();
        // We have to save the requisition before we can alter the according foreign source definition
        deployedForeignSourceRepository.save(nextRequisition);
        // Remove all policies and detectors from the foreign source
        final ForeignSource foreignSource = deployedForeignSourceRepository.getForeignSource(nextForeignSource);
        foreignSource.setDetectors(Collections.emptyList());
        foreignSource.setPolicies(Collections.emptyList());
        deployedForeignSourceRepository.save(foreignSource);
        alteredForeignSources.add(nextForeignSource);
    }
    RequisitionNode requisitionNode = nextRequisition.getNode(minion.getId());
    if (requisitionNode == null) {
        final RequisitionMonitoredService requisitionMonitoredService = new RequisitionMonitoredService();
        requisitionMonitoredService.setServiceName("Minion-Heartbeat");
        final RequisitionInterface requisitionInterface = new RequisitionInterface();
        requisitionInterface.setIpAddr("127.0.0.1");
        requisitionInterface.putMonitoredService(requisitionMonitoredService);
        requisitionNode = new RequisitionNode();
        requisitionNode.setNodeLabel(minion.getId());
        requisitionNode.setForeignId(minion.getLabel() != null ? minion.getLabel() : minion.getId());
        requisitionNode.setLocation(minion.getLocation());
        requisitionNode.putInterface(requisitionInterface);
        nextRequisition.putNode(requisitionNode);
        nextRequisition.setDate(new Date());
        deployedForeignSourceRepository.save(nextRequisition);
        deployedForeignSourceRepository.flush();
        alteredForeignSources.add(nextForeignSource);
    }
    for (final String alteredForeignSource : alteredForeignSources) {
        final EventBuilder eventBuilder = new EventBuilder(EventConstants.RELOAD_IMPORT_UEI, "Web");
        eventBuilder.addParam(EventConstants.PARM_URL, String.valueOf(deployedForeignSourceRepository.getRequisitionURL(alteredForeignSource)));
        try {
            eventProxy.send(eventBuilder.getEvent());
        } catch (final EventProxyException e) {
            throw new DataAccessResourceFailureException("Unable to send event to import group " + alteredForeignSource, e);
        }
    }
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) EventProxyException(org.opennms.netmgt.events.api.EventProxyException) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) RequisitionMonitoredService(org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService) Date(java.util.Date)

Example 3 with EventProxyException

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

the class NCSComponentServiceImpl method deleteComponent.

@Override
@Transactional
public void deleteComponent(final String type, final String foreignSource, final String foreignId, final boolean deleteOrphans) {
    LOG.debug("deleteSubcomponent({}, {}, {}, {})", type, foreignSource, foreignId, Boolean.valueOf(deleteOrphans));
    final NCSComponent component = getComponent(type, foreignSource, foreignId);
    final ComponentIdentifier id = getIdentifier(component);
    final ComponentEventQueue ceq = new ComponentEventQueue();
    deleteComponent(id, ceq, deleteOrphans);
    try {
        ceq.sendAll(m_eventProxy);
    } catch (final EventProxyException e) {
        LOG.warn("Component {} deleted, but an error occured while sending delete/update events.", id, e);
    }
}
Also used : NCSComponent(org.opennms.netmgt.model.ncs.NCSComponent) EventProxyException(org.opennms.netmgt.events.api.EventProxyException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with EventProxyException

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

the class NCSComponentServiceImpl method addSubcomponent.

@Override
@Transactional
public NCSComponent addSubcomponent(final String type, final String foreignSource, final String foreignId, final NCSComponent subComponent, final boolean deleteOrphans) {
    final ComponentIdentifier subComponentId = getIdentifier(subComponent);
    LOG.debug("addSubcomponent({}, {}, {}, {}, {})", type, foreignSource, foreignId, subComponentId, Boolean.valueOf(deleteOrphans));
    final NCSComponent component = getComponent(type, foreignSource, foreignId);
    final ComponentIdentifier id = getIdentifier(component);
    final ComponentEventQueue ceq = new ComponentEventQueue();
    if (component == null) {
        throw new ObjectRetrievalFailureException(NCSComponent.class, "Unable to locate component with type=" + type + ", foreignSource=" + foreignSource + ", foreignId=" + foreignId);
    }
    final NCSComponent updatedSubComponent = addOrUpdateComponents(subComponentId, subComponent, ceq, deleteOrphans);
    component.addSubcomponent(updatedSubComponent);
    m_componentDao.update(component);
    ceq.componentUpdated(id);
    try {
        ceq.sendAll(m_eventProxy);
    } catch (final EventProxyException e) {
        LOG.warn("Component {} added to {}, but an error occured while sending add/delete/update events.", subComponentId, id, e);
    }
    return getComponent(id);
}
Also used : NCSComponent(org.opennms.netmgt.model.ncs.NCSComponent) EventProxyException(org.opennms.netmgt.events.api.EventProxyException) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with EventProxyException

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

the class DefaultPollingContext method updateApStatus.

private void updateApStatus(OnmsAccessPointCollection apsUp, OnmsAccessPointCollection apsDown) {
    // events
    for (OnmsAccessPoint ap : apsUp) {
        // Update the status in the database
        ap.setStatus(AccessPointStatus.ONLINE);
        // Use merge() here because the object may have been updated in a separate thread
        m_accessPointDao.merge(ap);
        try {
            // Generate an AP UP event
            Event e = createApStatusEvent(ap.getPhysAddr(), ap.getNodeId(), "UP");
            m_eventMgr.send(e);
        } catch (EventProxyException e) {
            LOG.error("Error occured sending events ", e);
        }
    }
    // events
    for (OnmsAccessPoint ap : apsDown) {
        // Update the status in the database
        ap.setStatus(AccessPointStatus.OFFLINE);
        // Use merge() here because the object may have been updated in a separate thread
        m_accessPointDao.merge(ap);
        try {
            // Generate an AP DOWN event
            Event e = createApStatusEvent(ap.getPhysAddr(), ap.getNodeId(), "DOWN");
            m_eventMgr.send(e);
        } catch (EventProxyException e) {
            LOG.error("Error occured sending events ", e);
        }
    }
    m_accessPointDao.flush();
}
Also used : OnmsAccessPoint(org.opennms.netmgt.model.OnmsAccessPoint) EventProxyException(org.opennms.netmgt.events.api.EventProxyException) Event(org.opennms.netmgt.xml.event.Event)

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