Search in sources :

Example 86 with ClusterGroup

use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.

the class GridClosureProcessorSelfTest method broadcast.

/**
 * @param idx Node index.
 * @param job Runnable job.
 * @param p Optional node predicate.
 * @return Future object.
 */
private IgniteFuture<?> broadcast(int idx, IgniteRunnable job, @Nullable IgnitePredicate<ClusterNode> p) {
    assert idx >= 0 && idx < NODES_CNT;
    assert job != null;
    execCntr.set(0);
    ClusterGroup prj = grid(idx).cluster();
    if (p != null)
        prj = prj.forPredicate(p);
    return compute(prj).broadcastAsync(job);
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup)

Example 87 with ClusterGroup

use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.

the class GridCacheCommandHandler method executeCommand.

/**
 * Executes command on flagged cache projection. Checks {@code destId} to find if command could be performed locally
 * or routed to a remote node.
 *
 * @param destId Target node Id for the operation. If {@code null} - operation could be executed anywhere.
 * @param cacheName Cache name.
 * @param cacheFlags Cache flags.
 * @param key Key to set affinity mapping in the response.
 * @param op Operation to perform.
 * @return Operation result in future.
 * @throws IgniteCheckedException If failed
 */
private IgniteInternalFuture<GridRestResponse> executeCommand(@Nullable UUID destId, final String cacheName, final Set<GridClientCacheFlag> cacheFlags, final Object key, final CacheProjectionCommand op) throws IgniteCheckedException {
    final boolean locExec = destId == null || destId.equals(ctx.localNodeId()) || replicatedCacheAvailable(cacheName);
    if (locExec) {
        IgniteInternalCache<?, ?> prj = localCache(cacheName).setSkipStore(cacheFlags.contains(SKIP_STORE));
        if (cacheFlags.contains(KEEP_BINARIES))
            prj = prj.keepBinary();
        return op.apply((IgniteInternalCache<Object, Object>) prj, ctx).chain(resultWrapper((IgniteInternalCache<Object, Object>) prj, key));
    } else {
        ClusterGroup prj = ctx.grid().cluster().forPredicate(F.nodeForNodeId(destId));
        ctx.task().setThreadContext(TC_NO_FAILOVER, true);
        return ctx.closure().callAsync(BALANCE, new FlaggedCacheOperationCallable(cacheName, cacheFlags, op, key), prj.nodes());
    }
}
Also used : IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) ClusterGroup(org.apache.ignite.cluster.ClusterGroup)

Example 88 with ClusterGroup

use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.

the class IgniteClientCheckClusterGroupLocalIdAfterReconnect method testClusterGroupLocalIdAfterClientReconnect.

/**
 * Test checks that local id in cluster group was change and client
 * will be able to send the message to itself after reconnect.
 */
@Test
public void testClusterGroupLocalIdAfterClientReconnect() throws Exception {
    Ignite server = startGrid(0);
    Ignite client = startClientGrid(1);
    UUID clientId = client.cluster().node().id();
    ClusterGroup cg1 = client.cluster().forLocal();
    assertNotNull("Local client ID is different with local ClusterGroup node id. ", cg1.node(clientId));
    // check sending messages is possible while connected
    IgniteMessaging messaging = client.message(client.cluster().forLocal());
    CountDownLatch topicSignal = new CountDownLatch(2);
    messaging.localListen("topic", (IgniteBiPredicate<UUID, Object>) (uuid, n) -> {
        topicSignal.countDown();
        return true;
    });
    // countDown latch = 1
    messaging.send("topic", new External());
    CountDownLatch discSignal = new CountDownLatch(1);
    client.events().localListen((IgnitePredicate<DiscoveryEvent>) evt -> {
        discSignal.countDown();
        return true;
    }, EventType.EVT_CLIENT_NODE_DISCONNECTED);
    server.close();
    assertTrue("client did not disconnect", discSignal.await(LATCH_TIMEOUT, TimeUnit.SECONDS));
    startGrid(0);
    // wait for client reconnect
    IgniteFuture future = client.cluster().clientReconnectFuture();
    assertNotNull(future);
    // throws if times out
    future.get(20_000);
    ClusterGroup cg2 = client.cluster().forLocal();
    UUID newClientId = client.cluster().localNode().id();
    assertNotNull("Local client ID wasn't changed for local ClusterGroup.", cg2.node(newClientId));
    awaitPartitionMapExchange();
    // check sending messages is possible after reconnecting
    // countDown latch = 0
    messaging = client.message(client.cluster().forLocal());
    messaging.send("topic", new External());
    assertTrue("Message wasn't received", topicSignal.await(LATCH_TIMEOUT, TimeUnit.SECONDS));
}
Also used : IgniteMessaging(org.apache.ignite.IgniteMessaging) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) IgniteFuture(org.apache.ignite.lang.IgniteFuture) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Externalizable(java.io.Externalizable) EventType(org.apache.ignite.events.EventType) ObjectOutput(java.io.ObjectOutput) IOException(java.io.IOException) Test(org.junit.Test) UUID(java.util.UUID) Ignite(org.apache.ignite.Ignite) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) After(org.junit.After) ObjectInput(java.io.ObjectInput) IgniteMessaging(org.apache.ignite.IgniteMessaging) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) IgniteFuture(org.apache.ignite.lang.IgniteFuture) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) CountDownLatch(java.util.concurrent.CountDownLatch) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 89 with ClusterGroup

use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.

the class GridSelfTest method testRemoteProjection.

/**
 * {@inheritDoc}
 */
@Test
@Override
public void testRemoteProjection() throws Exception {
    ClusterGroup remotePrj = projection().forRemotes();
    int size = remotePrj.nodes().size();
    String name = "oneMoreGrid";
    try {
        Ignite g = startGrid(name);
        UUID joinedId = g.cluster().localNode().id();
        assert remotePrj.nodes().size() == size + 1;
        assert F.nodeIds(remotePrj.nodes()).contains(joinedId);
    } finally {
        stopGrid(name);
    }
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) Test(org.junit.Test) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest)

Example 90 with ClusterGroup

use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.

the class GridProjectionForCachesSelfTest method testProjectionForDefaultCache.

/**
 * @throws Exception If failed.
 */
@Test
public void testProjectionForDefaultCache() throws Exception {
    final ClusterGroup prj = ignite.cluster().forCacheNodes(DEFAULT_CACHE_NAME);
    assertNotNull(prj);
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return prj.nodes().size() == 3;
        }
    }, 5000);
    assertEquals(3, prj.nodes().size());
    assertTrue(prj.nodes().contains(grid(0).localNode()));
    assertFalse(prj.nodes().contains(grid(1).localNode()));
    assertTrue(prj.nodes().contains(grid(2).localNode()));
    assertTrue(prj.nodes().contains(grid(3).localNode()));
    assertFalse(prj.nodes().contains(grid(4).localNode()));
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

ClusterGroup (org.apache.ignite.cluster.ClusterGroup)99 Ignite (org.apache.ignite.Ignite)51 Test (org.junit.Test)49 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)36 UUID (java.util.UUID)26 CountDownLatch (java.util.concurrent.CountDownLatch)18 ClusterNode (org.apache.ignite.cluster.ClusterNode)16 GridCommonTest (org.apache.ignite.testframework.junits.common.GridCommonTest)14 IgniteException (org.apache.ignite.IgniteException)12 ArrayList (java.util.ArrayList)9 IgniteCompute (org.apache.ignite.IgniteCompute)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 IgniteCluster (org.apache.ignite.IgniteCluster)6 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)6 GridConcurrentHashSet (org.apache.ignite.internal.util.GridConcurrentHashSet)5 IgniteFuture (org.apache.ignite.lang.IgniteFuture)5 Map (java.util.Map)4 IgniteEx (org.apache.ignite.internal.IgniteEx)4 IgniteClusterEx (org.apache.ignite.internal.cluster.IgniteClusterEx)4 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)4