use of org.apache.ignite.compute.ComputeJob in project ignite by apache.
the class IgfsTask method map.
/**
* {@inheritDoc}
*/
@Nullable
@Override
public final Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, @Nullable IgfsTaskArgs<T> args) {
assert ignite != null;
assert args != null;
IgniteFileSystem fs = ignite.fileSystem(args.igfsName());
IgfsProcessorAdapter igfsProc = ((IgniteKernal) ignite).context().igfs();
Map<ComputeJob, ClusterNode> splitMap = new HashMap<>();
Map<UUID, ClusterNode> nodes = mapSubgrid(subgrid);
for (IgfsPath path : args.paths()) {
IgfsFile file = fs.info(path);
if (file == null) {
if (args.skipNonExistentFiles())
continue;
else
throw new IgniteException("Failed to process IGFS file because it doesn't exist: " + path);
}
Collection<IgfsBlockLocation> aff = fs.affinity(path, 0, file.length(), args.maxRangeLength());
long totalLen = 0;
for (IgfsBlockLocation loc : aff) {
ClusterNode node = null;
for (UUID nodeId : loc.nodeIds()) {
node = nodes.get(nodeId);
if (node != null)
break;
}
if (node == null)
throw new IgniteException("Failed to find any of block affinity nodes in subgrid [loc=" + loc + ", subgrid=" + subgrid + ']');
IgfsJob job = createJob(path, new IgfsFileRange(file.path(), loc.start(), loc.length()), args);
if (job != null) {
ComputeJob jobImpl = igfsProc.createJob(job, fs.name(), file.path(), loc.start(), loc.length(), args.recordResolver());
splitMap.put(jobImpl, node);
}
totalLen += loc.length();
}
assert totalLen == file.length();
}
return splitMap;
}
use of org.apache.ignite.compute.ComputeJob in project ignite by apache.
the class GroupTrainerBaseProcessorTask method map.
/**
* {@inheritDoc}
*/
@Nullable
@Override
public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, @Nullable Void arg) throws IgniteException {
Map<ComputeJob, ClusterNode> res = new HashMap<>();
for (ClusterNode node : subgrid) {
BaseLocalProcessorJob<K, V, T, R> job = createJob();
res.put(job, node);
}
return res;
}
use of org.apache.ignite.compute.ComputeJob 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.ComputeJob in project ignite by apache.
the class PlatformBroadcastingMultiClosureTask method map.
/**
* {@inheritDoc}
*/
@NotNull
@Override
public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, @Nullable Object arg) {
assert !F.isEmpty(jobs) : "Jobs emptiness must be checked in native platform.";
if (!F.isEmpty(subgrid)) {
Map<ComputeJob, ClusterNode> map = new HashMap<>(jobs.size() * subgrid.size(), 1);
for (PlatformJob job : jobs) {
boolean first = true;
for (ClusterNode node : subgrid) {
if (first) {
map.put(job, node);
first = false;
} else
map.put(ctx.createClosureJob(this, job.pointer(), job.job()), node);
}
}
return map;
} else
return Collections.emptyMap();
}
use of org.apache.ignite.compute.ComputeJob in project ignite by apache.
the class PlatformBroadcastingSingleClosureTask method map.
/**
* {@inheritDoc}
*/
@NotNull
@Override
public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, @Nullable Object arg) {
assert job != null : "Job null-check must be performed in native platform.";
if (!F.isEmpty(subgrid)) {
Map<ComputeJob, ClusterNode> map = new HashMap<>(subgrid.size(), 1);
boolean first = true;
for (ClusterNode node : subgrid) {
if (first) {
map.put(job, node);
first = false;
} else
map.put(ctx.createClosureJob(this, job.pointer(), job.job()), node);
}
return map;
} else
return Collections.emptyMap();
}
Aggregations