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();
}
}
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;
}
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;
}
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;
}
}
});
}
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;
}
Aggregations