use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class ClusterGroupSelfTest method testForDaemons.
/**
* @throws Exception If failed.
*/
@Test
public void testForDaemons() throws Exception {
assertEquals(4, ignite.cluster().nodes().size());
ClusterGroup daemons = ignite.cluster().forDaemons();
ClusterGroup srvs = ignite.cluster().forServers();
assertEquals(0, daemons.nodes().size());
assertEquals(2, srvs.nodes().size());
Ignition.setDaemon(true);
try (Ignite g = startGrid(NODES_CNT)) {
Ignition.setDaemon(false);
try (Ignite g1 = startGrid(NODES_CNT + 1)) {
assertEquals(1, ignite.cluster().forDaemons().nodes().size());
assertEquals(3, srvs.nodes().size());
assertEquals(1, daemons.nodes().size());
}
}
}
use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class GridCacheAbstractFullApiSelfTest method testTransformResourceInjection.
/**
* @throws Exception If failed.
*/
@Test
public void testTransformResourceInjection() throws Exception {
ClusterGroup servers = grid(0).cluster().forServers();
if (F.isEmpty(servers.nodes()))
return;
grid(0).services(grid(0).cluster()).deployNodeSingleton(SERVICE_NAME1, new DummyServiceImpl());
IgniteCache<String, Integer> cache = jcache();
Ignite ignite = ignite(0);
doTransformResourceInjection(ignite, cache, false, false);
doTransformResourceInjection(ignite, cache, true, false);
doTransformResourceInjection(ignite, cache, true, true);
if (txEnabled()) {
doTransformResourceInjectionInTx(ignite, cache, false, false);
doTransformResourceInjectionInTx(ignite, cache, true, false);
doTransformResourceInjectionInTx(ignite, cache, true, true);
}
}
use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class ComputeUtils method affinityCallWithRetries.
/**
* Calls the specified {@code fun} function on all partitions so that is't guaranteed that partitions with the same
* index of all specified caches will be placed on the same node and will not be moved before computation is
* finished. If partitions are placed on different nodes then call will be retried, but not more than {@code
* retries} times with {@code interval} interval specified in milliseconds.
*
* @param ignite Ignite instance.
* @param cacheNames Collection of cache names.
* @param fun Function to be applied on all partitions.
* @param retries Number of retries for the case when one of partitions not found on the node.
* @param interval Interval of retries for the case when one of partitions not found on the node.
* @param deployingCtx Deploy context of user-defined classes for peer class loading.
* @param <R> Type of a result.
* @return Collection of results.
*/
public static <R> Collection<R> affinityCallWithRetries(Ignite ignite, Collection<String> cacheNames, IgniteFunction<Integer, R> fun, int retries, int interval, DeployingContext deployingCtx) {
assert !cacheNames.isEmpty();
assert interval >= 0;
String primaryCache = cacheNames.iterator().next();
Affinity<?> affinity = ignite.affinity(primaryCache);
int partitions = affinity.partitions();
BitSet completionFlags = new BitSet(partitions);
Collection<R> results = new ArrayList<>();
for (int t = 0; t <= retries; t++) {
ClusterGroup clusterGrp = ignite.cluster().forDataNodes(primaryCache);
// Sends jobs.
Map<Integer, IgniteFuture<R>> futures = new HashMap<>();
for (int part = 0; part < partitions; part++) if (!completionFlags.get(part)) {
final int currPart = part;
futures.put(currPart, ignite.compute(clusterGrp).affinityCallAsync(cacheNames, currPart, new DeployableCallable<>(deployingCtx, part, fun)));
}
// Collects results.
for (Map.Entry<Integer, IgniteFuture<R>> entry : futures.entrySet()) try {
R res = entry.getValue().get();
results.add(res);
completionFlags.set(entry.getKey());
} catch (IgniteException ignore) {
}
if (completionFlags.cardinality() == partitions)
return results;
LockSupport.parkNanos(interval * 1_000_000);
}
throw new IllegalStateException();
}
use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class IgniteCacheRandomOperationBenchmark method doScanQuery.
/**
* @param cache Ignite cache.
* @throws Exception If failed.
*/
private void doScanQuery(IgniteCache<Object, Object> cache) throws Exception {
if (!affCaches.contains(cache))
return;
Map<UUID, List<Integer>> partitionsMap = personCachePartitions(cache.getName());
ScanQueryBroadcastClosure c = new ScanQueryBroadcastClosure(cache.getName(), partitionsMap);
ClusterGroup clusterGrp = ignite().cluster().forNodeIds(partitionsMap.keySet());
IgniteCompute compute = ignite().compute(clusterGrp);
compute.broadcast(c);
}
Aggregations