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();
}
}
}
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);
}
}
}
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);
}
}
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);
}
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();
}
Aggregations