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);
}
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());
}
}
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));
}
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);
}
}
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()));
}
Aggregations