Search in sources :

Example 21 with ComputeJob

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

Example 22 with ComputeJob

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

Example 23 with ComputeJob

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

Example 24 with ComputeJob

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());
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ComputeJob(org.apache.ignite.compute.ComputeJob) VisorClusterGroupEmptyException(org.apache.ignite.internal.visor.util.VisorClusterGroupEmptyException) UUID(java.util.UUID)

Example 25 with ComputeJob

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);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) NotNull(org.jetbrains.annotations.NotNull) CyclicBarrier(java.util.concurrent.CyclicBarrier) ComputeJobView(org.apache.ignite.spi.systemview.view.ComputeJobView) ComputeJob(org.apache.ignite.compute.ComputeJob) ComputeJobResultPolicy(org.apache.ignite.compute.ComputeJobResultPolicy) IgniteException(org.apache.ignite.IgniteException) Map(java.util.Map) Nullable(org.jetbrains.annotations.Nullable) ComputeJobResult(org.apache.ignite.compute.ComputeJobResult) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

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