Search in sources :

Example 1 with ComputeJobResultPolicy

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

the class SystemViewSelfTest method testComputeTask.

/**
 */
@Test
public void testComputeTask() throws Exception {
    CyclicBarrier barrier = new CyclicBarrier(2);
    try (IgniteEx g1 = startGrid(0)) {
        SystemView<ComputeTaskView> tasks = g1.context().systemView().view(TASKS_VIEW);
        IgniteCache<Integer, Integer> cache = g1.createCache("test-cache");
        cache.put(1, 1);
        g1.compute().executeAsync(new ComputeTask<Object, Object>() {

            @Override
            @NotNull
            public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, @Nullable Object arg) throws IgniteException {
                return Collections.singletonMap(new ComputeJob() {

                    @Override
                    public void cancel() {
                    // No-op.
                    }

                    @Override
                    public Object execute() throws IgniteException {
                        return 1;
                    }
                }, subgrid.get(0));
            }

            @Override
            public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) throws IgniteException {
                try {
                    barrier.await();
                    barrier.await();
                } catch (InterruptedException | BrokenBarrierException e) {
                    throw new RuntimeException(e);
                }
                return null;
            }

            @Nullable
            @Override
            public Object reduce(List<ComputeJobResult> results) throws IgniteException {
                return 1;
            }
        }, 1);
        barrier.await();
        assertEquals(1, tasks.size());
        ComputeTaskView t = tasks.iterator().next();
        assertFalse(t.internal());
        assertNull(t.affinityCacheName());
        assertEquals(-1, t.affinityPartitionId());
        assertTrue(t.taskClassName().startsWith(getClass().getName()));
        assertTrue(t.taskName().startsWith(getClass().getName()));
        assertEquals(g1.localNode().id(), t.taskNodeId());
        assertEquals("0", t.userVersion());
        barrier.await();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) NotNull(org.jetbrains.annotations.NotNull) ComputeTaskView(org.apache.ignite.spi.systemview.view.ComputeTaskView) CyclicBarrier(java.util.concurrent.CyclicBarrier) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComputeJob(org.apache.ignite.compute.ComputeJob) ComputeJobResultPolicy(org.apache.ignite.compute.ComputeJobResultPolicy) IgniteException(org.apache.ignite.IgniteException) IgniteEx(org.apache.ignite.internal.IgniteEx) Map(java.util.Map) Nullable(org.jetbrains.annotations.Nullable) ComputeJobResult(org.apache.ignite.compute.ComputeJobResult) Test(org.junit.Test) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)

Example 2 with ComputeJobResultPolicy

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

the class VerifyBackupPartitionsTask method result.

/**
 * {@inheritDoc}
 */
@Override
public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) {
    ComputeJobResultPolicy superRes = super.result(res, rcvd);
    // Deny failover.
    if (superRes == ComputeJobResultPolicy.FAILOVER) {
        superRes = ComputeJobResultPolicy.WAIT;
        log.warning("VerifyBackupPartitionsJob failed on node " + "[consistentId=" + res.getNode().consistentId() + "]", res.getException());
    }
    return superRes;
}
Also used : ComputeJobResultPolicy(org.apache.ignite.compute.ComputeJobResultPolicy)

Example 3 with ComputeJobResultPolicy

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

the class RetrieveConflictPartitionValuesTask method result.

/**
 * {@inheritDoc}
 */
@Override
public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) {
    ComputeJobResultPolicy superRes = super.result(res, rcvd);
    // Deny failover.
    if (superRes == ComputeJobResultPolicy.FAILOVER) {
        superRes = ComputeJobResultPolicy.WAIT;
        log.warning("RetrieveConflictValuesJob failed on node " + "[consistentId=" + res.getNode().consistentId() + "]", res.getException());
    }
    return superRes;
}
Also used : ComputeJobResultPolicy(org.apache.ignite.compute.ComputeJobResultPolicy)

Example 4 with ComputeJobResultPolicy

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

the class GridTaskWorker method result.

/**
 * @param jobRes Job result.
 * @param results Existing job results.
 * @return Job result policy.
 */
@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(), plc, "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, 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)) {
                    if (log.isDebugEnabled()) {
                        // 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 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);
                }
                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;
                if (log.isDebugEnabled())
                    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 : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ComputeJobResultPolicy(org.apache.ignite.compute.ComputeJobResultPolicy) IgniteException(org.apache.ignite.IgniteException) ComputeUserUndeclaredException(org.apache.ignite.compute.ComputeUserUndeclaredException) Nullable(org.jetbrains.annotations.Nullable) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with ComputeJobResultPolicy

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

the class CollectConflictPartitionKeysTask method result.

/**
 * {@inheritDoc}
 */
@Override
public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) {
    ComputeJobResultPolicy superRes = super.result(res, rcvd);
    // Deny failover.
    if (superRes == ComputeJobResultPolicy.FAILOVER) {
        superRes = ComputeJobResultPolicy.WAIT;
        log.warning("CollectPartitionEntryHashesJob failed on node " + "[consistentId=" + res.getNode().consistentId() + "]", res.getException());
    }
    return superRes;
}
Also used : ComputeJobResultPolicy(org.apache.ignite.compute.ComputeJobResultPolicy)

Aggregations

ComputeJobResultPolicy (org.apache.ignite.compute.ComputeJobResultPolicy)9 IgniteException (org.apache.ignite.IgniteException)6 ComputeJobResult (org.apache.ignite.compute.ComputeJobResult)4 Nullable (org.jetbrains.annotations.Nullable)4 Map (java.util.Map)3 CyclicBarrier (java.util.concurrent.CyclicBarrier)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 ComputeJob (org.apache.ignite.compute.ComputeJob)3 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)3 NotNull (org.jetbrains.annotations.NotNull)3 Test (org.junit.Test)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 ComputeJobView (org.apache.ignite.spi.systemview.view.ComputeJobView)2 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ComputeJobAfterSend (org.apache.ignite.compute.ComputeJobAfterSend)1 ComputeUserUndeclaredException (org.apache.ignite.compute.ComputeUserUndeclaredException)1 GridJobExecuteResponse (org.apache.ignite.internal.GridJobExecuteResponse)1 GridJobResultImpl (org.apache.ignite.internal.GridJobResultImpl)1