use of org.apache.ignite.compute.ComputeExecutionRejectedException in project ignite by apache.
the class GridJobProcessor method executeAsync.
/**
* @param jobWorker Job worker.
* @return {@code True} if job has been submitted to pool.
*/
private boolean executeAsync(GridJobWorker jobWorker) {
try {
if (jobWorker.executorName() != null) {
Executor customExec = ctx.pools().customExecutor(jobWorker.executorName());
if (customExec != null)
customExec.execute(jobWorker);
else {
LT.warn(log, "Custom executor doesn't exist (local job will be processed in default " + "thread pool): " + jobWorker.executorName());
ctx.pools().getExecutorService().execute(jobWorker);
}
} else
ctx.pools().getExecutorService().execute(jobWorker);
if (metricsUpdateFreq > -1L)
startedJobsCnt.increment();
startedJobsMetric.increment();
return true;
} catch (RejectedExecutionException e) {
// Remove from active jobs.
removeFromActive(jobWorker);
// Even if job was removed from another thread, we need to reject it
// here since job has never been executed.
IgniteException e2 = new ComputeExecutionRejectedException("Job has been rejected " + "[jobSes=" + jobWorker.getSession() + ", job=" + jobWorker.getJob() + ']', e);
if (metricsUpdateFreq > -1L)
rejectedJobsCnt.increment();
rejectedJobsMetric.increment();
jobWorker.finishJob(null, e2, true);
}
return false;
}
use of org.apache.ignite.compute.ComputeExecutionRejectedException in project ignite by apache.
the class GridAlwaysFailoverSpiFailSelfTest method testFailoverTask.
/**
*/
@Test
public void testFailoverTask() {
isFailoverCalled1 = false;
Ignite ignite = G.ignite(getTestIgniteInstanceName());
ignite.compute().localDeployTask(GridTestFailoverTask.class, GridTestFailoverTask.class.getClassLoader());
try {
ignite.compute().execute(GridTestFailoverTask.class.getName(), new ComputeExecutionRejectedException("Task should be failed over"));
assert false;
} catch (IgniteException e) {
// No-op
}
assert isFailoverCalled1;
}
use of org.apache.ignite.compute.ComputeExecutionRejectedException in project ignite by apache.
the class GridJobProcessor method rejectJob.
/**
* @param job Rejected job.
* @param sndReply {@code True} to send reply.
*/
private void rejectJob(GridJobWorker job, boolean sndReply) {
IgniteException e = new ComputeExecutionRejectedException("Job was cancelled before execution [taskSesId=" + job.getSession().getId() + ", jobId=" + job.getJobId() + ", job=" + job.getJob() + ']');
job.finishJob(null, e, sndReply);
}
use of org.apache.ignite.compute.ComputeExecutionRejectedException in project ignite by apache.
the class GridJobProcessor method onBeforeActivateJob.
/**
* @param jobWorker Worker.
* @return {@code True} if job has not been cancelled and should be activated.
*/
private boolean onBeforeActivateJob(GridJobWorker jobWorker) {
assert jobWorker != null;
activeJobs.put(jobWorker.getJobId(), jobWorker);
activeJobsMetric.increment();
// Check if job has been concurrently cancelled.
Boolean sysCancelled = cancelReqs.get(jobWorker.getSession().getId());
if (sysCancelled == null)
sysCancelled = cancelReqs.get(jobWorker.getJobId());
if (sysCancelled != null) {
// Job has been concurrently cancelled.
// Remove from active jobs.
removeFromActive(jobWorker);
// Even if job has been removed from another thread, we need to reject it
// here since job has never been executed.
IgniteException e2 = new ComputeExecutionRejectedException("Job was cancelled before execution [jobSes=" + jobWorker.getSession() + ", job=" + jobWorker.getJob() + ']');
jobWorker.finishJob(null, e2, !sysCancelled);
return false;
}
// its runner thread for proper master leave handling.
if (ctx.discovery().node(jobWorker.getTaskNode().id()) == null && removeFromActive(jobWorker)) {
// Add to cancelled jobs.
cancelledJobs.put(jobWorker.getJobId(), jobWorker);
if (!jobWorker.onMasterNodeLeft()) {
U.warn(log, "Job is being cancelled because master task node left grid " + "(as there is no one waiting for results, job will not be failed over): " + jobWorker.getJobId());
cancelJob(jobWorker, true);
}
}
return true;
}
use of org.apache.ignite.compute.ComputeExecutionRejectedException in project ignite by apache.
the class GridJobWorker method handleThrowable.
/**
* Handles {@link Throwable} generic exception for task
* deployment and execution.
*
* @param e Exception.
* @return Wrapped exception.
*/
private IgniteException handleThrowable(Throwable e) {
String msg = null;
IgniteException ex = null;
// happens due to JDk 1.5 bug.
if (e instanceof InterruptedException && !sysStopping) {
msg = "Failed to execute job due to interrupted exception.";
// Turn interrupted exception into checked exception.
ex = new IgniteException(msg, e);
} else // about this exception and decided to change error message.
if ((e instanceof NoClassDefFoundError || e instanceof ClassNotFoundException) && ctx.config().isPeerClassLoadingEnabled()) {
msg = "Failed to execute job due to class or resource loading exception (make sure that task " + "originating node is still in grid and requested class is in the task class path) [jobId=" + ses.getJobId() + ", ses=" + ses + ']';
ex = new ComputeUserUndeclaredException(msg, e);
} else if (sysStopping && X.hasCause(e, InterruptedException.class, IgniteInterruptedCheckedException.class)) {
msg = "Job got interrupted due to system stop (will attempt failover).";
ex = new ComputeExecutionRejectedException(e);
}
if (msg == null) {
msg = "Failed to execute job due to unexpected runtime exception [jobId=" + ses.getJobId() + ", ses=" + ses + ", err=" + e.getMessage() + ']';
ex = new ComputeUserUndeclaredException(msg, e);
}
assert msg != null;
assert ex != null;
if (log.isDebugEnabled())
U.error(log, msg, e);
return ex;
}
Aggregations