use of org.apache.ignite.compute.ComputeJob in project ignite by apache.
the class IgniteKillTask method map.
/**
* {@inheritDoc}
*/
@NotNull
@Override
public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, Boolean restart) {
assert restart != null;
this.restart = restart;
Map<ComputeJob, ClusterNode> jobs = U.newHashMap(subgrid.size());
for (ClusterNode n : subgrid) if (!daemon(n))
jobs.put(new IgniteKillJob(), n);
return jobs;
}
use of org.apache.ignite.compute.ComputeJob in project ignite by apache.
the class RetrieveConflictPartitionValuesTask method map.
/**
* {@inheritDoc}
*/
@NotNull
@Override
public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, Map<PartitionHashRecord, List<PartitionEntryHashRecord>> collectTaskRes) throws IgniteException {
Map<ComputeJob, ClusterNode> jobs = new HashMap<>();
Map<Object, ClusterNode> consIdToNode = new HashMap<>();
for (ClusterNode node : subgrid) consIdToNode.put(node.consistentId(), node);
for (Map.Entry<PartitionHashRecord, List<PartitionEntryHashRecord>> e : collectTaskRes.entrySet()) jobs.put(new RetrieveConflictValuesJob(new T2<>(e.getKey(), e.getValue())), consIdToNode.get(e.getKey().consistentId()));
return jobs;
}
use of org.apache.ignite.compute.ComputeJob in project ignite by apache.
the class PlatformFullTask method read.
/**
* Read map result.
*
* @param reader Reader.
* @param nodes Current topology nodes.
* @return Map result.
*/
private Map<ComputeJob, ClusterNode> read(BinaryRawReaderEx reader, Collection<ClusterNode> nodes) {
if (reader.readBoolean()) {
if (!reader.readBoolean())
return null;
int size = reader.readInt();
Map<ComputeJob, ClusterNode> map = U.newHashMap(size);
for (int i = 0; i < size; i++) {
long ptr = reader.readLong();
Object nativeJob = reader.readBoolean() ? reader.readObjectDetached() : null;
PlatformJob job = ctx.createJob(this, ptr, nativeJob);
UUID jobNodeId = reader.readUuid();
assert jobNodeId != null;
ClusterNode jobNode = ctx.kernalContext().discovery().node(jobNodeId);
if (jobNode == null) {
// We expect task processor to perform necessary failover.
for (ClusterNode node : nodes) {
if (node.id().equals(jobNodeId)) {
jobNode = node;
break;
}
}
assert jobNode != null;
}
map.put(job, jobNode);
}
return map;
} else
throw new IgniteException(reader.readString());
}
use of org.apache.ignite.compute.ComputeJob in project ignite by apache.
the class VisorQueryCleanupTask method map0.
/**
* {@inheritDoc}
*/
@Override
protected Map<? extends ComputeJob, ClusterNode> map0(List<ClusterNode> subgrid, @Nullable VisorTaskArgument<VisorQueryCleanupTaskArg> arg) {
Set<UUID> nodeIds = taskArg.getQueryIds().keySet();
if (nodeIds.isEmpty())
throw new VisorClusterGroupEmptyException("Nothing to clear. List with node IDs is empty!");
Map<ComputeJob, ClusterNode> map = U.newHashMap(nodeIds.size());
try {
for (ClusterNode node : subgrid) if (nodeIds.contains(node.id()))
map.put(new VisorQueryCleanupJob(taskArg.getQueryIds().get(node.id()), debug), node);
if (map.isEmpty()) {
StringBuilder notFoundNodes = new StringBuilder();
for (UUID nid : nodeIds) notFoundNodes.append((notFoundNodes.length() == 0) ? "" : ",").append(U.id8(nid));
throw new VisorClusterGroupEmptyException("Failed to clear query results. Nodes are not available: [" + notFoundNodes + "]");
}
return map;
} finally {
if (debug)
logMapped(ignite.log(), getClass(), map.values());
}
}
use of org.apache.ignite.compute.ComputeJob in project ignite by apache.
the class SystemViewComputeJobTest method testCancelComputeTask.
/**
*/
@Test
public void testCancelComputeTask() throws Exception {
barrier = new CyclicBarrier(2);
SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
client.compute().withName("cancel-task").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 {
try {
Thread.sleep(60_000);
} catch (InterruptedException e) {
throw new IgniteException(e);
}
return null;
}
}, subgrid.get(0));
}
@Override
public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) throws IgniteException {
return null;
}
@Nullable
@Override
public Object reduce(List<ComputeJobResult> results) throws IgniteException {
return 1;
}
}, 1);
barrier.await(TIMEOUT, MILLISECONDS);
assertEquals(1, jobs.size());
checkJobView(jobs.iterator().next(), "cancel-task", PASSIVE);
barrier.await(TIMEOUT, MILLISECONDS);
barrier.await(TIMEOUT, MILLISECONDS);
assertEquals(1, jobs.size());
checkJobView(jobs.iterator().next(), "cancel-task", CANCELED);
barrier.await(TIMEOUT, MILLISECONDS);
boolean res = waitForCondition(() -> jobs.size() == 0, TIMEOUT);
assertTrue(res);
}
Aggregations