Search in sources :

Example 96 with ClusterGroup

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());
        }
    }
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest)

Example 97 with ClusterGroup

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);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test)

Example 98 with ClusterGroup

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();
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BitSet(java.util.BitSet) ArrayList(java.util.ArrayList) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) IgniteFuture(org.apache.ignite.lang.IgniteFuture) IgniteException(org.apache.ignite.IgniteException) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 99 with ClusterGroup

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);
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) List(java.util.List) ArrayList(java.util.ArrayList) UUID(java.util.UUID) IgniteCompute(org.apache.ignite.IgniteCompute)

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