Search in sources :

Example 11 with IgniteCompute

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

the class GridClusterStateProcessor method sendComputeCheckGlobalState.

/**
 *  Check cluster state.
 *
 *  @return Cluster state, {@code True} if cluster active, {@code False} if inactive.
 */
private boolean sendComputeCheckGlobalState() {
    AffinityTopologyVersion topVer = ctx.discovery().topologyVersionEx();
    if (log.isInfoEnabled()) {
        log.info("Sending check cluster state request from node [id=" + ctx.localNodeId() + ", topVer=" + topVer + ", client=" + ctx.clientNode() + ", daemon" + ctx.isDaemon() + "]");
    }
    IgniteCompute comp = ((ClusterGroupAdapter) ctx.cluster().get().forServers()).compute();
    return comp.call(new IgniteCallable<Boolean>() {

        @IgniteInstanceResource
        private Ignite ig;

        @Override
        public Boolean call() throws Exception {
            return ig.active();
        }
    });
}
Also used : IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) Ignite(org.apache.ignite.Ignite) IgniteCompute(org.apache.ignite.IgniteCompute) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) ClusterGroupAdapter(org.apache.ignite.internal.cluster.ClusterGroupAdapter)

Example 12 with IgniteCompute

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

the class GridClusterStateProcessor method sendComputeChangeGlobalState.

/**
 * @param activate New cluster state.
 * @param resFut State change future.
 */
private void sendComputeChangeGlobalState(boolean activate, BaselineTopology blt, boolean forceBlt, final GridFutureAdapter<Void> resFut) {
    AffinityTopologyVersion topVer = ctx.discovery().topologyVersionEx();
    if (log.isInfoEnabled()) {
        log.info("Sending " + prettyStr(activate) + " request from node [id=" + ctx.localNodeId() + ", topVer=" + topVer + ", client=" + ctx.clientNode() + ", daemon=" + ctx.isDaemon() + "]");
    }
    IgniteCompute comp = ((ClusterGroupAdapter) ctx.cluster().get().forServers()).compute();
    IgniteFuture<Void> fut = comp.runAsync(new ClientChangeGlobalStateComputeRequest(activate, blt, forceBlt));
    fut.listen(new CI1<IgniteFuture>() {

        @Override
        public void apply(IgniteFuture fut) {
            try {
                fut.get();
                resFut.onDone();
            } catch (Exception e) {
                resFut.onDone(e);
            }
        }
    });
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteFuture(org.apache.ignite.lang.IgniteFuture) IgniteCompute(org.apache.ignite.IgniteCompute) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) ClusterGroupAdapter(org.apache.ignite.internal.cluster.ClusterGroupAdapter)

Example 13 with IgniteCompute

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

the class PlatformCompute method executeJavaTask.

/**
 * Execute task taking arguments from the given reader.
 *
 * @param reader Reader.
 * @param async Execute asynchronously flag.
 * @return Task result.
 * @throws IgniteCheckedException On error.
 */
protected Object executeJavaTask(BinaryRawReaderEx reader, boolean async) throws IgniteCheckedException {
    String taskName = reader.readString();
    boolean keepBinary = reader.readBoolean();
    Object arg = reader.readObjectDetached();
    Collection<UUID> nodeIds = readNodeIds(reader);
    IgniteCompute compute0 = computeForTask(nodeIds);
    if (!keepBinary && arg instanceof BinaryObjectImpl)
        arg = ((BinaryObject) arg).deserialize();
    if (async)
        return readAndListenFuture(reader, new ComputeConvertingFuture(compute0.executeAsync(taskName, arg)));
    else
        return toBinary(compute0.execute(taskName, arg));
}
Also used : BinaryObjectImpl(org.apache.ignite.internal.binary.BinaryObjectImpl) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObject(org.apache.ignite.binary.BinaryObject) UUID(java.util.UUID) IgniteCompute(org.apache.ignite.IgniteCompute)

Example 14 with IgniteCompute

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

the class GridDsiClient method call.

/**
 * {@inheritDoc}
 */
@SuppressWarnings({ "unchecked", "InfiniteLoopStatement" })
@Nullable
@Override
public Object call() throws Exception {
    IgniteCompute comp = g.compute(g.cluster().forPredicate(serverNode()));
    while (!finish.get()) {
        try {
            long t0 = System.currentTimeMillis();
            long submitTime1 = t0;
            ComputeTaskFuture<T3<Long, Integer, Integer>> f1 = comp.executeAsync(GridDsiRequestTask.class, new GridDsiMessage(terminalId, nodeId));
            submitTime.setIfGreater(System.currentTimeMillis() - submitTime1);
            T3<Long, Integer, Integer> res1 = f1.get();
            submitTime1 = System.currentTimeMillis();
            ComputeTaskFuture<T3<Long, Integer, Integer>> f2 = comp.executeAsync(GridDsiResponseTask.class, new GridDsiMessage(terminalId, nodeId));
            submitTime.setIfGreater(System.currentTimeMillis() - submitTime1);
            T3<Long, Integer, Integer> res2 = f2.get();
            long t1 = System.currentTimeMillis();
            txCnt.incrementAndGet();
            latency.addAndGet(t1 - t0);
            if (res1 != null)
                srvStats = res1;
            if (res2 != null)
                srvStats = res2;
        } catch (IgniteException e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : IgniteException(org.apache.ignite.IgniteException) GridAtomicLong(org.apache.ignite.internal.util.GridAtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) IgniteCompute(org.apache.ignite.IgniteCompute) T3(org.apache.ignite.internal.util.typedef.T3) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with IgniteCompute

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

the class GridJobExecutionLoadTestClient 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)

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