Search in sources :

Example 1 with ComputeTaskCancelledCheckedException

use of org.apache.ignite.internal.compute.ComputeTaskCancelledCheckedException in project ignite by apache.

the class GridTaskProcessor method onCancelled.

/**
 * Handles user cancellation.
 *
 * @param sesId Session ID.
 */
public void onCancelled(IgniteUuid sesId) {
    assert sesId != null;
    lock.readLock();
    try {
        if (stopping && !waiting) {
            U.warn(log, "Attempt to cancel task while stopping grid (will ignore): " + sesId);
            return;
        }
        GridTaskWorker<?, ?> task = tasks.get(sesId);
        if (task == null) {
            if (log.isDebugEnabled())
                log.debug("Attempt to cancel unknown task (was task already reduced?): " + sesId);
            return;
        }
        task.finishTask(null, new ComputeTaskCancelledCheckedException("Task was cancelled."), true);
    } finally {
        lock.readUnlock();
    }
}
Also used : ComputeTaskCancelledCheckedException(org.apache.ignite.internal.compute.ComputeTaskCancelledCheckedException)

Example 2 with ComputeTaskCancelledCheckedException

use of org.apache.ignite.internal.compute.ComputeTaskCancelledCheckedException in project ignite by apache.

the class GridTaskProcessor method onKernalStop.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("TooBroadScope")
@Override
public void onKernalStop(boolean cancel) {
    lock.writeLock();
    try {
        stopping = true;
        waiting = !cancel;
    } finally {
        lock.writeUnlock();
    }
    startLatch.countDown();
    int size = tasks.size();
    if (size > 0) {
        if (cancel)
            U.warn(log, "Will cancel unfinished tasks due to stopping of the grid [cnt=" + size + "]");
        else
            U.warn(log, "Will wait for all job responses from worker nodes before stopping grid.");
        for (GridTaskWorker<?, ?> task : tasks.values()) {
            if (!cancel) {
                try {
                    task.getTaskFuture().get();
                } catch (ComputeTaskCancelledCheckedException e) {
                    U.warn(log, e.getMessage());
                } catch (IgniteCheckedException e) {
                    U.error(log, "Task failed: " + task, e);
                }
            } else {
                for (ClusterNode node : ctx.discovery().nodes(task.getSession().getTopology())) {
                    if (ctx.localNodeId().equals(node.id()))
                        ctx.job().masterLeaveLocal(task.getSession().getId());
                }
                task.cancel();
                Throwable ex = new ComputeTaskCancelledCheckedException("Task cancelled due to stopping of the grid: " + task);
                task.finishTask(null, ex, false);
            }
        }
        U.join(tasks.values(), log);
    }
    // Remove discovery and message listeners.
    ctx.event().removeLocalEventListener(discoLsnr);
    ctx.io().removeMessageListener(TOPIC_JOB_SIBLINGS);
    ctx.io().removeMessageListener(TOPIC_TASK_CANCEL);
    // listener notifications any more.
    if (!cancel) {
        lock.writeLock();
        try {
            waiting = false;
        } finally {
            lock.writeUnlock();
        }
    }
    assert tasks.isEmpty();
    if (log.isDebugEnabled())
        log.debug("Finished executing task processor onKernalStop() callback.");
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ComputeTaskCancelledCheckedException(org.apache.ignite.internal.compute.ComputeTaskCancelledCheckedException)

Aggregations

ComputeTaskCancelledCheckedException (org.apache.ignite.internal.compute.ComputeTaskCancelledCheckedException)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1