Search in sources :

Example 1 with ComputeExecutionRejectedException

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;
}
Also used : Executor(java.util.concurrent.Executor) IgniteException(org.apache.ignite.IgniteException) ComputeExecutionRejectedException(org.apache.ignite.compute.ComputeExecutionRejectedException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 2 with ComputeExecutionRejectedException

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;
}
Also used : IgniteException(org.apache.ignite.IgniteException) ComputeExecutionRejectedException(org.apache.ignite.compute.ComputeExecutionRejectedException) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest)

Example 3 with ComputeExecutionRejectedException

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);
}
Also used : IgniteException(org.apache.ignite.IgniteException) ComputeExecutionRejectedException(org.apache.ignite.compute.ComputeExecutionRejectedException)

Example 4 with ComputeExecutionRejectedException

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;
}
Also used : IgniteException(org.apache.ignite.IgniteException) ComputeExecutionRejectedException(org.apache.ignite.compute.ComputeExecutionRejectedException)

Example 5 with ComputeExecutionRejectedException

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;
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteException(org.apache.ignite.IgniteException) ComputeExecutionRejectedException(org.apache.ignite.compute.ComputeExecutionRejectedException) ComputeUserUndeclaredException(org.apache.ignite.compute.ComputeUserUndeclaredException)

Aggregations

ComputeExecutionRejectedException (org.apache.ignite.compute.ComputeExecutionRejectedException)7 IgniteException (org.apache.ignite.IgniteException)5 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 Ignite (org.apache.ignite.Ignite)2 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)2 Test (org.junit.Test)2 Collection (java.util.Collection)1 UUID (java.util.UUID)1 Executor (java.util.concurrent.Executor)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 ComputeTask (org.apache.ignite.compute.ComputeTask)1 ComputeTaskMapAsync (org.apache.ignite.compute.ComputeTaskMapAsync)1 ComputeUserUndeclaredException (org.apache.ignite.compute.ComputeUserUndeclaredException)1 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)1 Event (org.apache.ignite.events.Event)1 TaskEvent (org.apache.ignite.events.TaskEvent)1 ComputeTaskInternalFuture (org.apache.ignite.internal.ComputeTaskInternalFuture)1 GridTaskSessionImpl (org.apache.ignite.internal.GridTaskSessionImpl)1 IgniteDeploymentCheckedException (org.apache.ignite.internal.IgniteDeploymentCheckedException)1