Search in sources :

Example 16 with IgniteCompute

use of org.apache.ignite.IgniteCompute in project ignite by apache.

the class GridJobExecutionLoadTestClient method call.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("InfiniteLoopStatement")
@Nullable
@Override
public Object call() throws Exception {
    IgniteCompute rmts = g.compute(g.cluster().forRemotes());
    while (!finish) {
        try {
            rmts.execute(GridJobExecutionLoadTestTask.class, null);
            txCnt.increment();
        } catch (IgniteException e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : IgniteException(org.apache.ignite.IgniteException) IgniteCompute(org.apache.ignite.IgniteCompute) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with IgniteCompute

use of org.apache.ignite.IgniteCompute in project ignite by apache.

the class GridJobExecutionLoadTestClientSemaphore method warmUp.

/**
 * Warms the JVM up.
 *
 * @param noThreads Number of threads to use.
 */
private static void warmUp(int noThreads) {
    X.println("Warming up...");
    final IgniteCompute rmts = g.compute(g.cluster().forRemotes());
    GridLoadTestUtils.runMultithreadedInLoop(new Callable<Object>() {

        @Nullable
        @Override
        public Object call() {
            try {
                rmts.execute(GridJobExecutionLoadTestTask.class, null);
            } catch (IgniteException e) {
                e.printStackTrace();
            }
            return null;
        }
    }, noThreads, WARM_UP_DURATION);
    // Run GC on all nodes.
    try {
        g.compute().run(new GridAbsClosure() {

            @Override
            public void apply() {
                System.gc();
            }
        });
    } catch (IgniteException e) {
        throw new IllegalStateException(e);
    }
}
Also used : GridAbsClosure(org.apache.ignite.internal.util.lang.GridAbsClosure) IgniteException(org.apache.ignite.IgniteException) IgniteCompute(org.apache.ignite.IgniteCompute) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with IgniteCompute

use of org.apache.ignite.IgniteCompute in project ignite by apache.

the class GridClusterStateProcessor method changeGlobalState.

/**
     *
     */
public IgniteInternalFuture<?> changeGlobalState(final boolean activate) {
    if (cacheProc.transactions().tx() != null || sharedCtx.lockedTopologyVersion(null) != null)
        throw new IgniteException("Cannot " + prettyStr(activate) + " cluster, because cache locked on transaction.");
    if ((globalState == ACTIVE && activate) || (this.globalState == INACTIVE && !activate))
        return new GridFinishedFuture<>();
    final UUID requestId = UUID.randomUUID();
    final GridChangeGlobalStateFuture cgsFut = new GridChangeGlobalStateFuture(requestId, activate, ctx);
    if (!cgsLocFut.compareAndSet(null, cgsFut)) {
        GridChangeGlobalStateFuture locF = cgsLocFut.get();
        if (locF.activate == activate)
            return locF;
        else
            return new GridFinishedFuture<>(new IgniteException("fail " + prettyStr(activate) + ", because now in progress" + prettyStr(locF.activate)));
    }
    try {
        if (ctx.clientNode()) {
            AffinityTopologyVersion topVer = ctx.discovery().topologyVersionEx();
            IgniteCompute comp = ((ClusterGroupAdapter) ctx.cluster().get().forServers()).compute().withAsync();
            if (log.isInfoEnabled())
                log.info("Send " + prettyStr(activate) + " request from client node [id=" + ctx.localNodeId() + " topVer=" + topVer + " ]");
            comp.run(new ClientChangeGlobalStateComputeRequest(activate));
            comp.future().listen(new CI1<IgniteFuture>() {

                @Override
                public void apply(IgniteFuture fut) {
                    try {
                        fut.get();
                        cgsFut.onDone();
                    } catch (Exception e) {
                        cgsFut.onDone(e);
                    }
                }
            });
        } else {
            List<DynamicCacheChangeRequest> reqs = new ArrayList<>();
            DynamicCacheChangeRequest changeGlobalStateReq = new DynamicCacheChangeRequest(requestId, activate ? ACTIVE : INACTIVE, ctx.localNodeId());
            reqs.add(changeGlobalStateReq);
            reqs.addAll(activate ? cacheProc.startAllCachesRequests() : cacheProc.stopAllCachesRequests());
            ChangeGlobalStateMessage changeGlobalStateMsg = new ChangeGlobalStateMessage(requestId, ctx.localNodeId(), activate, new DynamicCacheChangeBatch(reqs));
            try {
                ctx.discovery().sendCustomEvent(changeGlobalStateMsg);
                if (ctx.isStopping())
                    cgsFut.onDone(new IgniteCheckedException("Failed to execute " + prettyStr(activate) + " request, " + "node is stopping."));
            } catch (IgniteCheckedException e) {
                log.error("Fail create or send change global state request." + cgsFut, e);
                cgsFut.onDone(e);
            }
        }
    } catch (IgniteCheckedException e) {
        log.error("Fail create or send change global state request." + cgsFut, e);
        cgsFut.onDone(e);
    }
    return cgsFut;
}
Also used : DynamicCacheChangeRequest(org.apache.ignite.internal.processors.cache.DynamicCacheChangeRequest) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ArrayList(java.util.ArrayList) ChangeGlobalStateMessage(org.apache.ignite.internal.processors.cache.ChangeGlobalStateMessage) IgniteFuture(org.apache.ignite.lang.IgniteFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) DynamicCacheChangeBatch(org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch) UUID(java.util.UUID) IgniteCompute(org.apache.ignite.IgniteCompute)

Example 19 with IgniteCompute

use of org.apache.ignite.IgniteCompute in project ignite by apache.

the class ComputeAsyncExample method main.

/**
     * Executes example.
     *
     * @param args Command line arguments, none required.
     * @throws IgniteException If example execution failed.
     */
public static void main(String[] args) throws IgniteException {
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        System.out.println();
        System.out.println("Compute asynchronous example started.");
        // Enable asynchronous mode.
        IgniteCompute compute = ignite.compute().withAsync();
        Collection<IgniteFuture<?>> futs = new ArrayList<>();
        // Iterate through all words in the sentence and create runnable jobs.
        for (final String word : "Print words using runnable".split(" ")) {
            // Execute runnable on some node.
            compute.run(() -> {
                System.out.println();
                System.out.println(">>> Printing '" + word + "' on this node from ignite job.");
            });
            futs.add(compute.future());
        }
        // Wait for completion of all futures.
        futs.forEach(IgniteFuture::get);
        System.out.println();
        System.out.println(">>> Finished printing words using runnable execution.");
        System.out.println(">>> Check all nodes for output (this node is also part of the cluster).");
    }
}
Also used : ArrayList(java.util.ArrayList) IgniteFuture(org.apache.ignite.lang.IgniteFuture) Ignite(org.apache.ignite.Ignite) IgniteCompute(org.apache.ignite.IgniteCompute)

Example 20 with IgniteCompute

use of org.apache.ignite.IgniteCompute in project ignite by apache.

the class GridTaskExecutionSelfTest method testJobIdCollision.

/**
 * Test for https://issues.apache.org/jira/browse/IGNITE-1384
 *
 * @throws Exception If failed.
 */
public void testJobIdCollision() throws Exception {
    fail("Test refactoring is needed: https://issues.apache.org/jira/browse/IGNITE-4706");
    long locId = IgniteUuid.lastLocalId();
    ArrayList<IgniteFuture<Object>> futs = new ArrayList<>(2016);
    IgniteCompute compute = grid(1).compute(grid(1).cluster().forNodeId(grid(3).localNode().id()));
    for (int i = 0; i < 1000; i++) {
        futs.add(compute.callAsync(new IgniteCallable<Object>() {

            @JobContextResource
            ComputeJobContext ctx;

            boolean held;

            @Override
            public Object call() throws Exception {
                if (!held) {
                    ctx.holdcc(1000);
                    held = true;
                }
                return null;
            }
        }));
    }
    info("Finished first loop.");
    AtomicLong idx = U.field(IgniteUuid.class, "cntGen");
    idx.set(locId);
    IgniteCompute compute1 = grid(2).compute(grid(2).cluster().forNodeId(grid(3).localNode().id()));
    for (int i = 0; i < 100; i++) {
        futs.add(compute1.callAsync(new IgniteCallable<Object>() {

            @JobContextResource
            ComputeJobContext ctx;

            boolean held;

            @Override
            public Object call() throws Exception {
                if (!held) {
                    ctx.holdcc(1000);
                    held = true;
                }
                return null;
            }
        }));
    }
    for (IgniteFuture<Object> fut : futs) fut.get();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ComputeJobContext(org.apache.ignite.compute.ComputeJobContext) IgniteCallable(org.apache.ignite.lang.IgniteCallable) ArrayList(java.util.ArrayList) IgniteFuture(org.apache.ignite.lang.IgniteFuture) IgniteCompute(org.apache.ignite.IgniteCompute)

Aggregations

IgniteCompute (org.apache.ignite.IgniteCompute)41 Ignite (org.apache.ignite.Ignite)19 IgniteException (org.apache.ignite.IgniteException)14 ArrayList (java.util.ArrayList)10 IgniteFuture (org.apache.ignite.lang.IgniteFuture)9 UUID (java.util.UUID)6 ClusterGroup (org.apache.ignite.cluster.ClusterGroup)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgniteEx (org.apache.ignite.internal.IgniteEx)4 IgniteCallable (org.apache.ignite.lang.IgniteCallable)4 Nullable (org.jetbrains.annotations.Nullable)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)3 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)3 Collection (java.util.Collection)2 Callable (java.util.concurrent.Callable)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2