use of org.opennms.core.tasks.Task in project opennms by OpenNMS.
the class Provisioner method handleNewSuspectEvent.
@EventHandler(uei = EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI)
public void handleNewSuspectEvent(Event e) {
final Event event = e;
final String uei = e.getUei();
final String ip = e.getInterface();
final Map<String, String> paramMap = Maps.newHashMap();
e.getParmCollection().forEach(eachParam -> paramMap.put(eachParam.getParmName(), eachParam.getValue().getContent()));
if (ip == null) {
LOG.error("Received a {} event with a null ipAddress", uei);
return;
}
if (!getProvisionService().isDiscoveryEnabled()) {
LOG.info("Ignoring {} event for ip {} since discovery handling is disabled in provisiond", uei, ip);
return;
}
Runnable r = new Runnable() {
@Override
public void run() {
try {
final InetAddress addr = addr(ip);
if (addr == null) {
LOG.error("Unable to convert {} to an InetAddress.", ip);
return;
}
final String location;
if (paramMap.containsKey("location")) {
location = paramMap.get("location");
} else if (event.getDistPoller() != null) {
location = monitoringSystemDao.get(event.getDistPoller()).getLocation();
} else {
location = MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID;
}
final String foreignSource = paramMap.get("foreignSource");
LOG.debug("Triggering new suspect scan for: {} at location: {} with foreign source: {}.", addr, location, foreignSource);
final NewSuspectScan scan = createNewSuspectScan(addr, foreignSource, location);
Task t = scan.createTask();
t.schedule();
t.waitFor();
} catch (InterruptedException ex) {
LOG.error("Task interrupted waiting for new suspect scan of {} to finish", ip, ex);
} catch (ExecutionException ex) {
LOG.error("An expected execution occurred waiting for new suspect scan of {} to finish", ip, ex);
}
}
};
m_scheduledExecutor.execute(r);
}
use of org.opennms.core.tasks.Task in project opennms by OpenNMS.
the class Provisioner method handleForceRescan.
/**
* <p>handleForceRescan</p>
*
* @param e a {@link org.opennms.netmgt.xml.event.Event} object.
*/
@EventHandler(uei = EventConstants.FORCE_RESCAN_EVENT_UEI)
public void handleForceRescan(Event e) {
final Integer nodeId = new Integer(e.getNodeid().intValue());
removeNodeFromScheduleQueue(nodeId);
Runnable r = new Runnable() {
@Override
public void run() {
try {
ForceRescanScan scan = createForceRescanScan(nodeId);
Task t = scan.createTask();
t.schedule();
t.waitFor();
// It has 'false' because a node scan was already executed by ForceRescanScan.
NodeScanSchedule scheduleForNode = getProvisionService().getScheduleForNode(nodeId, false);
if (scheduleForNode != null) {
addToScheduleQueue(scheduleForNode);
}
} catch (InterruptedException ex) {
LOG.error("Task interrupted waiting for rescan of nodeId {} to finish", nodeId, ex);
} catch (ExecutionException ex) {
LOG.error("An expected execution occurred waiting for rescan of nodeId {} to finish", nodeId, ex);
}
}
};
m_scheduledExecutor.execute(r);
}
use of org.opennms.core.tasks.Task in project opennms by OpenNMS.
the class Nms5414IT method runScan.
public void runScan(final NodeScan scan) throws InterruptedException, ExecutionException {
final Task t = scan.createTask();
t.schedule();
t.waitFor();
waitForEverything();
}
use of org.opennms.core.tasks.Task in project opennms by OpenNMS.
the class PolicyIT method runScan.
public void runScan(final NodeScan scan) throws InterruptedException, ExecutionException {
final Task t = scan.createTask();
t.schedule();
t.waitFor();
}
Aggregations