Search in sources :

Example 1 with ComputeUserUndeclaredException

use of org.apache.ignite.compute.ComputeUserUndeclaredException in project ignite by apache.

the class GridTaskWorker method body.

/**
     * Maps this task's jobs to nodes and sends them out.
     */
@SuppressWarnings({ "unchecked" })
@Override
protected void body() {
    evtLsnr.onTaskStarted(this);
    try {
        // Use either user task or deployed one.
        if (task == null) {
            assert taskCls != null;
            assert ComputeTask.class.isAssignableFrom(taskCls);
            try {
                task = newTask((Class<? extends ComputeTask<T, R>>) taskCls);
            } catch (IgniteCheckedException e) {
                // If cannot instantiate task, then assign internal flag based
                // on information available.
                internal = dep.internalTask(null, taskCls);
                recordTaskEvent(EVT_TASK_STARTED, "Task started.");
                throw e;
            }
        }
        internal = ses.isInternal();
        recordTaskEvent(EVT_TASK_STARTED, "Task started.");
        initializeSpis();
        ses.setClassLoader(dep.classLoader());
        // Nodes are ignored by affinity tasks.
        final List<ClusterNode> shuffledNodes = affCacheIds == null ? getTaskTopology() : Collections.<ClusterNode>emptyList();
        // Load balancer.
        ComputeLoadBalancer balancer = ctx.loadBalancing().getLoadBalancer(ses, shuffledNodes);
        continuous = ctx.resource().isAnnotationPresent(dep, task, TaskContinuousMapperResource.class);
        if (log.isDebugEnabled())
            log.debug("Injected task resources [continuous=" + continuous + ']');
        // Inject resources.
        ctx.resource().inject(dep, task, ses, balancer, mapper);
        Map<? extends ComputeJob, ClusterNode> mappedJobs = U.wrapThreadLoader(dep.classLoader(), new Callable<Map<? extends ComputeJob, ClusterNode>>() {

            @Override
            public Map<? extends ComputeJob, ClusterNode> call() {
                return task.map(shuffledNodes, arg);
            }
        });
        if (log.isDebugEnabled())
            log.debug("Mapped task jobs to nodes [jobCnt=" + (mappedJobs != null ? mappedJobs.size() : 0) + ", mappedJobs=" + mappedJobs + ", ses=" + ses + ']');
        if (F.isEmpty(mappedJobs)) {
            synchronized (mux) {
                // Check if some jobs are sent from continuous mapper.
                if (F.isEmpty(jobRes))
                    throw new IgniteCheckedException("Task map operation produced no mapped jobs: " + ses);
            }
        } else
            processMappedJobs(mappedJobs);
        synchronized (mux) {
            lockRespProc = false;
        }
        processDelayedResponses();
    } catch (ClusterGroupEmptyCheckedException e) {
        U.warn(log, "Failed to map task jobs to nodes (topology projection is empty): " + ses);
        finishTask(null, e);
    } catch (IgniteException | IgniteCheckedException e) {
        if (!fut.isCancelled()) {
            if (!(e instanceof VisorClusterGroupEmptyException))
                U.error(log, "Failed to map task jobs to nodes: " + ses, e);
            finishTask(null, e);
        } else if (log.isDebugEnabled())
            log.debug("Failed to map task jobs to nodes due to task cancellation: " + ses);
    }// Catch throwable to protect against bad user code.
     catch (Throwable e) {
        String errMsg = "Failed to map task jobs to nodes due to undeclared user exception" + " [cause=" + e.getMessage() + ", ses=" + ses + "]";
        U.error(log, errMsg, e);
        finishTask(null, new ComputeUserUndeclaredException(errMsg, e));
        if (e instanceof Error)
            throw e;
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ComputeTask(org.apache.ignite.compute.ComputeTask) ComputeUserUndeclaredException(org.apache.ignite.compute.ComputeUserUndeclaredException) TaskContinuousMapperResource(org.apache.ignite.resources.TaskContinuousMapperResource) ComputeJob(org.apache.ignite.compute.ComputeJob) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterGroupEmptyCheckedException(org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException) ComputeLoadBalancer(org.apache.ignite.compute.ComputeLoadBalancer) VisorClusterGroupEmptyException(org.apache.ignite.internal.visor.util.VisorClusterGroupEmptyException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with ComputeUserUndeclaredException

use of org.apache.ignite.compute.ComputeUserUndeclaredException in project ignite by apache.

the class GridTaskWorker method result.

/**
     * @param jobRes Job result.
     * @param results Existing job results.
     * @return Job result policy.
     */
@SuppressWarnings({ "CatchGenericClass" })
@Nullable
private ComputeJobResultPolicy result(final ComputeJobResult jobRes, final List<ComputeJobResult> results) {
    assert !Thread.holdsLock(mux);
    return U.wrapThreadLoader(dep.classLoader(), new CO<ComputeJobResultPolicy>() {

        @Nullable
        @Override
        public ComputeJobResultPolicy apply() {
            try {
                // Obtain job result policy.
                ComputeJobResultPolicy plc = null;
                try {
                    plc = task.result(jobRes, results);
                    if (plc == FAILOVER && noFailover) {
                        IgniteException e = jobRes.getException();
                        if (e != null)
                            throw e;
                        plc = WAIT;
                    }
                } finally {
                    recordJobEvent(EVT_JOB_RESULTED, jobRes.getJobContext().getJobId(), jobRes.getNode(), "Job got resulted with: " + plc);
                }
                if (log.isDebugEnabled())
                    log.debug("Obtained job result policy [policy=" + plc + ", ses=" + ses + ']');
                return plc;
            } catch (IgniteException e) {
                if (X.hasCause(e, GridInternalException.class) || X.hasCause(e, IgfsOutOfSpaceException.class)) {
                    // Print internal exceptions only if debug is enabled.
                    if (log.isDebugEnabled())
                        U.error(log, "Failed to obtain remote job result policy for result from " + "ComputeTask.result(..) method (will fail the whole task): " + jobRes, e);
                } else if (X.hasCause(e, ComputeJobFailoverException.class)) {
                    IgniteCheckedException e0 = new IgniteCheckedException(" Job was not failed over because " + "ComputeJobResultPolicy.FAILOVER was not returned from " + "ComputeTask.result(...) method for job result with ComputeJobFailoverException.", e);
                    finishTask(null, e0);
                    return null;
                } else if (X.hasCause(e, GridServiceNotFoundException.class) || X.hasCause(e, ClusterTopologyCheckedException.class)) {
                    // Should be throttled, because GridServiceProxy continuously retry getting service.
                    LT.error(log, e, "Failed to obtain remote job result policy for result from " + "ComputeTask.result(..) method (will fail the whole task): " + jobRes);
                } else
                    U.error(log, "Failed to obtain remote job result policy for result from " + "ComputeTask.result(..) method (will fail the whole task): " + jobRes, e);
                finishTask(null, e);
                return null;
            } catch (Throwable e) {
                String errMsg = "Failed to obtain remote job result policy for result from" + "ComputeTask.result(..) method due to undeclared user exception " + "(will fail the whole task): " + jobRes;
                U.error(log, errMsg, e);
                Throwable tmp = new ComputeUserUndeclaredException(errMsg, e);
                // Failed to successfully obtain result policy and
                // hence forced to fail the whole deployed task.
                finishTask(null, tmp);
                if (e instanceof Error)
                    throw e;
                return null;
            }
        }
    });
}
Also used : GridServiceNotFoundException(org.apache.ignite.internal.processors.service.GridServiceNotFoundException) ComputeUserUndeclaredException(org.apache.ignite.compute.ComputeUserUndeclaredException) ComputeJobFailoverException(org.apache.ignite.compute.ComputeJobFailoverException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ComputeJobResultPolicy(org.apache.ignite.compute.ComputeJobResultPolicy) GridInternalException(org.apache.ignite.internal.GridInternalException) IgniteException(org.apache.ignite.IgniteException) IgfsOutOfSpaceException(org.apache.ignite.igfs.IgfsOutOfSpaceException) Nullable(org.jetbrains.annotations.Nullable) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ComputeUserUndeclaredException

use of org.apache.ignite.compute.ComputeUserUndeclaredException in project ignite by apache.

the class GridTaskWorker method failover.

/**
     * @param res Execution response.
     * @param jobRes Job result.
     * @param top Topology.
     * @return {@code True} if fail-over SPI returned a new node.
     */
private boolean failover(GridJobExecuteResponse res, GridJobResultImpl jobRes, Collection<? extends ClusterNode> top) {
    assert Thread.holdsLock(mux);
    try {
        ctx.resource().invokeAnnotated(dep, jobRes.getJob(), ComputeJobBeforeFailover.class);
        ClusterNode node = ctx.failover().failover(ses, jobRes, new ArrayList<>(top), affPartId, affCacheName, mapTopVer);
        return checkTargetNode(res, jobRes, node);
    }// Catch Throwable to protect against bad user code.
     catch (Throwable e) {
        String errMsg = "Failed to failover job due to undeclared user exception [job=" + jobRes.getJob() + ", err=" + e + ']';
        U.error(log, errMsg, e);
        finishTask(null, new ComputeUserUndeclaredException(errMsg, e));
        if (e instanceof Error)
            throw (Error) e;
        return false;
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ComputeUserUndeclaredException(org.apache.ignite.compute.ComputeUserUndeclaredException)

Example 4 with ComputeUserUndeclaredException

use of org.apache.ignite.compute.ComputeUserUndeclaredException 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 + ']';
        ex = new ComputeUserUndeclaredException(msg, e);
    }
    assert msg != null;
    assert ex != null;
    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)

Example 5 with ComputeUserUndeclaredException

use of org.apache.ignite.compute.ComputeUserUndeclaredException in project ignite by apache.

the class GridTaskWorker method reduce.

/**
     * @param results Job results.
     */
private void reduce(final List<ComputeJobResult> results) {
    R reduceRes = null;
    Throwable userE = null;
    try {
        try {
            // Reduce results.
            reduceRes = U.wrapThreadLoader(dep.classLoader(), new Callable<R>() {

                @Nullable
                @Override
                public R call() {
                    return task.reduce(results);
                }
            });
        } finally {
            synchronized (mux) {
                assert state == State.REDUCING : "Invalid task state: " + state;
                state = State.REDUCED;
            }
        }
        if (log.isDebugEnabled())
            log.debug(S.toString("Reduced job responses", "reduceRes", reduceRes, true, "ses", ses, false));
        recordTaskEvent(EVT_TASK_REDUCED, "Task reduced.");
    } catch (ClusterTopologyCheckedException e) {
        U.warn(log, "Failed to reduce job results for task (any nodes from task topology left grid?): " + task);
        userE = e;
    } catch (IgniteCheckedException e) {
        U.error(log, "Failed to reduce job results for task: " + task, e);
        userE = e;
    }// Catch Throwable to protect against bad user code.
     catch (Throwable e) {
        String errMsg = "Failed to reduce job results due to undeclared user exception [task=" + task + ", err=" + e + ']';
        U.error(log, errMsg, e);
        userE = new ComputeUserUndeclaredException(errMsg, e);
        if (e instanceof Error)
            throw e;
    } finally {
        finishTask(reduceRes, userE);
    }
}
Also used : EVT_JOB_FAILED_OVER(org.apache.ignite.events.EventType.EVT_JOB_FAILED_OVER) TC_NO_FAILOVER(org.apache.ignite.internal.processors.task.GridTaskThreadContextKey.TC_NO_FAILOVER) FAILOVER(org.apache.ignite.compute.ComputeJobResultPolicy.FAILOVER) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ComputeUserUndeclaredException(org.apache.ignite.compute.ComputeUserUndeclaredException) Callable(java.util.concurrent.Callable) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Aggregations

ComputeUserUndeclaredException (org.apache.ignite.compute.ComputeUserUndeclaredException)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 IgniteException (org.apache.ignite.IgniteException)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 ComputeExecutionRejectedException (org.apache.ignite.compute.ComputeExecutionRejectedException)1 ComputeJob (org.apache.ignite.compute.ComputeJob)1 ComputeJobFailoverException (org.apache.ignite.compute.ComputeJobFailoverException)1 ComputeJobResultPolicy (org.apache.ignite.compute.ComputeJobResultPolicy)1 FAILOVER (org.apache.ignite.compute.ComputeJobResultPolicy.FAILOVER)1 ComputeLoadBalancer (org.apache.ignite.compute.ComputeLoadBalancer)1 ComputeTask (org.apache.ignite.compute.ComputeTask)1 EVT_JOB_FAILED_OVER (org.apache.ignite.events.EventType.EVT_JOB_FAILED_OVER)1 IgfsOutOfSpaceException (org.apache.ignite.igfs.IgfsOutOfSpaceException)1 GridInternalException (org.apache.ignite.internal.GridInternalException)1 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)1 ClusterGroupEmptyCheckedException (org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException)1