@Override
public void cancel(String username, JobId jobId, String reason) throws JobException {
final ForemenTool tool = this.foremenTool.get();
final ExternalId id = ExternalIdHelper.toExternal(QueryIdHelper.getQueryIdFromString(jobId.getId()));
if(tool.cancel(id, reason)){
logger.debug("Job cancellation requested on current node.");
return;
}
final Job job = getJob(jobId);
NodeEndpoint endpoint = job.getJobAttempt().getEndpoint();
if(endpoint.equals(identity)){
throw new JobWarningException(jobId, "Unable to cancel job started on current node. It may have completed before cancellation was requested.");
}
try{
final CoordTunnel tunnel = coordTunnelCreator.get().getTunnel(JobsServiceUtil.toPB(endpoint));
Ack ack = tunnel.requestCancelQuery(id, reason).checkedGet(15, TimeUnit.SECONDS);
if(ack.getOk()){
logger.debug("Job cancellation requested on {}.", endpoint.getAddress());
return;
} else {
throw new JobWarningException(jobId, String.format("Unable to cancel job started on %s. It may have completed before cancellation was requested.", endpoint.getAddress()));
}
}catch(TimeoutException | RpcException | RuntimeException e){
logger.info("Unable to cancel remote job for external id: {}", ExternalIdHelper.toString(id), e);
throw new JobWarningException(jobId, String.format("Unable to cancel job on node %s.", endpoint.getAddress()));
}
}