Search in sources :

Example 1 with ComputeJob

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;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgfsProcessorAdapter(org.apache.ignite.internal.processors.igfs.IgfsProcessorAdapter) HashMap(java.util.HashMap) IgniteFileSystem(org.apache.ignite.IgniteFileSystem) IgfsBlockLocation(org.apache.ignite.igfs.IgfsBlockLocation) IgfsPath(org.apache.ignite.igfs.IgfsPath) ComputeJob(org.apache.ignite.compute.ComputeJob) IgniteException(org.apache.ignite.IgniteException) UUID(java.util.UUID) IgfsFile(org.apache.ignite.igfs.IgfsFile) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ComputeJob

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;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ComputeJob(org.apache.ignite.compute.ComputeJob) HashMap(java.util.HashMap) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ComputeJob

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();
    }
}
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 4 with ComputeJob

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();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ComputeJob(org.apache.ignite.compute.ComputeJob) HashMap(java.util.HashMap) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with ComputeJob

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();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ComputeJob(org.apache.ignite.compute.ComputeJob) HashMap(java.util.HashMap) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ComputeJob (org.apache.ignite.compute.ComputeJob)28 ClusterNode (org.apache.ignite.cluster.ClusterNode)26 HashMap (java.util.HashMap)14 NotNull (org.jetbrains.annotations.NotNull)11 Map (java.util.Map)10 IgniteException (org.apache.ignite.IgniteException)9 Nullable (org.jetbrains.annotations.Nullable)8 UUID (java.util.UUID)7 List (java.util.List)5 ComputeJobResult (org.apache.ignite.compute.ComputeJobResult)5 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)5 Test (org.junit.Test)5 Affinity (org.apache.ignite.cache.affinity.Affinity)4 ArrayList (java.util.ArrayList)3 CyclicBarrier (java.util.concurrent.CyclicBarrier)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 ComputeJobAdapter (org.apache.ignite.compute.ComputeJobAdapter)3 ComputeJobResultPolicy (org.apache.ignite.compute.ComputeJobResultPolicy)3 Collection (java.util.Collection)2