Java Code Examples for org.apache.ignite.internal.IgniteEx#localNode()

The following examples show how to use org.apache.ignite.internal.IgniteEx#localNode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GridCommonAbstractTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Compares checksums between primary and backup partitions of specified caches.
 * Works properly only on idle cluster - there may be false positive conflict reports if data in cluster is being
 * concurrently updated.
 *
 * @param ig Ignite instance.
 * @param caches Cache names (if null, all user caches will be verified).
 * @return Conflicts result.
 * @throws IgniteException If none caches or node found.
 */
protected IdleVerifyResultV2 idleVerify(Ignite ig, String... caches) {
    IgniteEx ig0 = (IgniteEx)ig;

    Set<String> cacheNames = new HashSet<>();

    if (F.isEmpty(caches))
        cacheNames.addAll(ig0.cacheNames());
    else
        Collections.addAll(cacheNames, caches);

    if (cacheNames.isEmpty())
        throw new IgniteException("None cache for checking.");

    ClusterNode node = !ig0.localNode().isClient() ? ig0.localNode() : ig0.cluster().forServers().forRandom().node();

    if (node == null)
        throw new IgniteException("None server node for verification.");

    VisorIdleVerifyTaskArg taskArg = new VisorIdleVerifyTaskArg(cacheNames);

    return ig.compute().execute(
        VisorIdleVerifyTaskV2.class.getName(),
        new VisorTaskArgument<>(node.id(), taskArg, false)
    );
}
 
Example 2
Source File: GridCacheAtomicPreloadSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param key Key to check.
 * @param val Expected value.
 */
private void checkValues(int key, int val) {
    for (int i = 0; i < 3; i++) {
        IgniteEx grid = grid(i);

        ClusterNode node = grid.localNode();

        IgniteCache<Object, Object> cache = grid.cache(DEFAULT_CACHE_NAME);

        boolean primary = grid.affinity(DEFAULT_CACHE_NAME).isPrimary(node, key);
        boolean backup = grid.affinity(DEFAULT_CACHE_NAME).isBackup(node, key);

        if (primary || backup)
            assertEquals("Invalid cache value [nodeId=" + node.id() + ", primary=" + primary +
                ", backup=" + backup + ", key=" + key + ']', val, cache.localPeek(key, CachePeekMode.ONHEAP));
    }
}
 
Example 3
Source File: VisorTaskUtils.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param ignite Ignite.
 * @param cacheName Cache name to check.
 * @return {@code true} if cache on local node is not a data cache or near cache disabled.
 */
public static boolean isProxyCache(IgniteEx ignite, String cacheName) {
    GridDiscoveryManager discovery = ignite.context().discovery();

    ClusterNode locNode = ignite.localNode();

    return !(discovery.cacheAffinityNode(locNode, cacheName) || discovery.cacheNearNode(locNode, cacheName));
}