Java Code Examples for org.apache.ignite.Ignition#allGrids()

The following examples show how to use org.apache.ignite.Ignition#allGrids() . 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: IgniteDynamicClientCacheStartSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param ignite Node.
 * @param cacheName Cache name.
 * @throws Exception If failed.
 */
private void checkNoCache(Ignite ignite, final String cacheName) throws Exception {
    GridCacheAdapter<Object, Object> cache = ((IgniteKernal)ignite).context().cache().internalCache(cacheName);

    assertNull("Unexpected cache on node " + ignite.name(), cache);

    final ClusterNode node = ((IgniteKernal)ignite).localNode();

    for (Ignite ignite0 : Ignition.allGrids()) {
        final GridDiscoveryManager disco = ((IgniteKernal)ignite0).context().discovery();

        if (ignite0 == ignite)
            assertFalse(ignite0.name(), disco.cacheNode(node, cacheName));
        else {
            assertTrue(ignite0.name(), GridTestUtils.waitForCondition(new GridAbsPredicate() {
                @Override public boolean apply() {
                    return !disco.cacheNode(node, cacheName);
                }
            }, 5000));
        }

        assertFalse(disco.cacheAffinityNode(node, cacheName));
        assertFalse(disco.cacheNearNode(node, cacheName));
    }
}
 
Example 2
Source File: IgniteClientAffinityAssignmentSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param topVer Topology version.
 * @throws Exception If failed.
 */
private void awaitTopology(final long topVer) throws Exception {
    for (Ignite grid : Ignition.allGrids()) {
        final GridCacheAdapter cache = ((IgniteKernal)grid).internalCache(DEFAULT_CACHE_NAME);

        if (cache == null)
            continue;

        GridTestUtils.waitForCondition(new GridAbsPredicate() {
            @Override public boolean apply() {
                return cache.context().affinity().affinityTopologyVersion().topologyVersion() == topVer;
            }
        }, 5000);

        assertEquals(topVer, cache.context().affinity().affinityTopologyVersion().topologyVersion());
    }
}
 
Example 3
Source File: DynamicIndexAbstractBasicSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Test that operations fail on LOCAL cache.
 *
 * @throws Exception If failed.
 */
@Test
public void testFailOnLocalCache() throws Exception {
    for (Ignite node : Ignition.allGrids()) {
        if (!node.configuration().isClientMode())
            createSqlCache(node, localCacheConfiguration());
    }

    final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1_ESCAPED));

    assertIgniteSqlException(new RunnableX() {
        @Override public void runx() throws Exception {
            dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, true, 0);
        }
    }, IgniteQueryErrorCode.UNSUPPORTED_OPERATION);

    assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);

    assertIgniteSqlException(new RunnableX() {
        @Override public void runx() throws Exception {
            dynamicIndexDrop(CACHE_NAME, IDX_NAME_LOCAL, true);
        }
    }, IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
}
 
Example 4
Source File: WalModeChangeCommonAbstractSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Execute certain logic for all nodes.
 *
 * @param task Task.
 * @throws Exception If failed.
 */
protected void forAllNodes(IgniteInClosureX<Ignite> task) throws Exception {
    for (Ignite node : Ignition.allGrids()) {
        try {
            info("");
            info(">>> Executing test on node: " + node.name());

            task.applyx(node);
        }
        finally {
            for (Ignite node0 : Ignition.allGrids()) {
                Collection<String> cacheNames = node0.cacheNames();

                for (String cacheName : cacheNames)
                    destroyCache(node0, cacheName);
            }
        }
    }
}
 
Example 5
Source File: TestPutIgniteCache.java    From nifi with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUpClass() {
    if (preJava11) {
        List<Ignite> grids = Ignition.allGrids();
        if ( grids.size() == 1 )
            ignite = grids.get(0);
        else
            ignite = Ignition.start("test-ignite.xml");
    }

}
 
Example 6
Source File: ClusterNodeMetricsUpdateTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param expNodes Expected nodes.
 * @param expJobs Expected jobs number per node.
 */
private void checkMetrics0(int expNodes, Map<UUID, Integer> expJobs) {
    List<Ignite> nodes = Ignition.allGrids();

    assertEquals(expNodes, nodes.size());
    assertEquals(expNodes, expJobs.size());

    int totalJobs = 0;

    for (Integer c : expJobs.values())
        totalJobs += c;

    for (final Ignite ignite : nodes) {
        ClusterMetrics m = ignite.cluster().metrics();

        assertEquals(expNodes, m.getTotalNodes());
        assertEquals(totalJobs, m.getTotalExecutedJobs());

        for (Map.Entry<UUID, Integer> e : expJobs.entrySet()) {
            UUID nodeId = e.getKey();

            ClusterGroup g = ignite.cluster().forNodeId(nodeId);

            ClusterMetrics nodeM = g.metrics();

            assertEquals(e.getValue(), (Integer)nodeM.getTotalExecutedJobs());
        }
    }
}
 
Example 7
Source File: AbstractIgniteProcessor.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize ignite instance
 * @param context process context
 */
public void initializeIgnite(ProcessContext context) {

    if ( getIgnite() != null ) {
        getLogger().info("Ignite already initialized");
        return;
    }


    synchronized(Ignition.class) {
        List<Ignite> grids = Ignition.allGrids();

        if ( grids.size() == 1 ) {
            getLogger().info("Ignite grid already available");
            ignite = grids.get(0);
            return;
        }
        Ignition.setClientMode(true);

        String configuration = context.getProperty(IGNITE_CONFIGURATION_FILE).getValue();
        getLogger().info("Initializing ignite with configuration {} ", new Object[] { configuration });
        if ( StringUtils.isEmpty(configuration) ) {
            ignite = Ignition.start();
        } else {
            ignite = Ignition.start(configuration);
        }
    }
}
 
Example 8
Source File: IgnitionComponentProxyTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 *
 */
@Test
public void testAllGrids() {
    Supplier<Collection<Ignite>> s = new Supplier<Collection<Ignite>>() {
        @Override public Collection<Ignite> get() {
            return Ignition.allGrids();
        }
    };

    checkCollection(s);
}
 
Example 9
Source File: GridTestUtils.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param cacheName Cache name.
 * @param backups Number of backups.
 * @param log Logger.
 * @throws Exception If failed.
 */
@SuppressWarnings("BusyWait")
public static <K, V> void waitTopologyUpdate(@Nullable String cacheName, int backups, IgniteLogger log)
    throws Exception {
    for (Ignite g : Ignition.allGrids()) {
        IgniteCache<K, V> cache = ((IgniteEx)g).cache(cacheName);

        GridDhtPartitionTopology top = dht(cache).topology();

        while (true) {
            boolean wait = false;

            for (int p = 0; p < g.affinity(cacheName).partitions(); p++) {
                Collection<ClusterNode> nodes = top.nodes(p, AffinityTopologyVersion.NONE);

                if (nodes.size() > backups + 1) {
                    LT.warn(log, "Partition map was not updated yet (will wait) [igniteInstanceName=" + g.name() +
                        ", p=" + p + ", nodes=" + F.nodeIds(nodes) + ']');

                    wait = true;

                    break;
                }
            }

            if (wait)
                Thread.sleep(20);
            else
                break; // While.
        }
    }
}
 
Example 10
Source File: GridMBeanBaselineTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param ignite Ignite.
 */
private void checkBaselineInFromMBean(IgniteEx ignite) {
    Set<Object> cIds = ignite.cluster().currentBaselineTopology().stream()
        .map(BaselineNode::consistentId)
        .collect(Collectors.toSet());

    for (Ignite ign : Ignition.allGrids()) {
        IgniteMXBean igniteMXBean = (IgniteMXBean)ign;

        assertEquals(cIds.contains(ign.cluster().localNode().consistentId()),
            igniteMXBean.isNodeInBaseline());
    }
}
 
Example 11
Source File: BaseSqlTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Applies specified closure to each cluster node.
 */
protected void testAllNodes(Consumer<Ignite> consumer) {
    for (Ignite node : Ignition.allGrids()) {
        log.info("Testing on node " + node.name() + '.');

        consumer.accept(node);

        log.info("Testing on node " + node.name() + " is done.");
    }
}
 
Example 12
Source File: HadoopIgfsInProc.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates instance of the HadoopIgfsInProcWithIgniteRefsCount by IGFS name.
 *
 * @param igfsName Target IGFS name.
 * @param log Log.
 * @param userName User name.
 * @return HadoopIgfsInProcWithIgniteRefsCount instance. {@code null} if the IGFS not fount in the current VM.
 */
public static HadoopIgfsInProc create(String igfsName, Log log, String userName) {
    synchronized (REF_CTR_MUX) {
        for (Ignite ignite : Ignition.allGrids()) {
            HadoopIgfsInProc delegate = create0(ignite, igfsName, log, userName);

            if (delegate != null)
                return delegate;
        }
    }

    return null;
}
 
Example 13
Source File: IgniteTestHelper.java    From hibernate-ogm-ignite with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void dropSchemaAndDatabase(SessionFactory sessionFactory) {
	if ( Ignition.allGrids().size() > 1 ) { // some tests doesn't stop DatastareProvider
		String currentGridName = getProvider( sessionFactory ).getGridName();
		for ( Ignite grid : Ignition.allGrids() ) {
			if ( !Objects.equals( currentGridName, grid.name() ) ) {
				grid.close();
			}
		}
	}
}
 
Example 14
Source File: GridCommonAbstractTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param key Key.
 * @return Near cache for key.
 */
protected IgniteCache<Integer, Integer> nearCache(Integer key) {
    List<Ignite> allGrids = Ignition.allGrids();

    assertFalse("There are no alive nodes.", F.isEmpty(allGrids));

    Affinity<Integer> aff = allGrids.get(0).affinity(DEFAULT_CACHE_NAME);

    Collection<ClusterNode> nodes = aff.mapKeyToPrimaryAndBackups(key);

    for (Ignite ignite : allGrids) {
        if (!nodes.contains(ignite.cluster().localNode()))
            return ignite.cache(DEFAULT_CACHE_NAME);
    }

    fail();

    return null;
}
 
Example 15
Source File: GridCommonAbstractTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param key Key.
 * @param cacheName Cache name.
 * @return Ignite instance which has primary cache for given key.
 */
protected Ignite primaryNode(Object key, String cacheName) {
    List<Ignite> allGrids = Ignition.allGrids();

    assertFalse("There are no alive nodes.", F.isEmpty(allGrids));

    Ignite ignite = allGrids.get(0);

    Affinity<Object> aff = ignite.affinity(cacheName);

    ClusterNode node = aff.mapKeyToNode(key);

    assertNotNull("There are no cache affinity nodes", node);

    return grid(node);
}
 
Example 16
Source File: GridCommonAbstractTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param key Key.
 * @param cacheName Cache name.
 * @return Ignite instance which has backup cache for given key.
 */
protected Ignite backupNode(Object key, String cacheName) {
    List<Ignite> allGrids = Ignition.allGrids();

    assertFalse("There are no alive nodes.", F.isEmpty(allGrids));

    Ignite ignite = allGrids.get(0);

    Affinity<Object> aff = ignite.affinity(cacheName);

    Collection<ClusterNode> nodes = aff.mapKeyToPrimaryAndBackups(key);

    assertTrue("Expected more than one node for key [key=" + key + ", nodes=" + nodes + ']', nodes.size() > 1);

    Iterator<ClusterNode> it = nodes.iterator();

    it.next(); // Skip primary.

    return grid(it.next());
}
 
Example 17
Source File: GridCommonAbstractTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param key Key.
 * @param cacheName Cache name.
 * @return Ignite instances which has backup cache for given key.
 */
protected List<Ignite> backupNodes(Object key, String cacheName) {
    List<Ignite> allGrids = Ignition.allGrids();

    assertFalse("There are no alive nodes.", F.isEmpty(allGrids));

    Ignite ignite = allGrids.get(0);

    Affinity<Object> aff = ignite.affinity(cacheName);

    Collection<ClusterNode> nodes = aff.mapKeyToPrimaryAndBackups(key);

    assertTrue("Expected more than one node for key [key=" + key + ", nodes=" + nodes + ']', nodes.size() > 1);

    Iterator<ClusterNode> it = nodes.iterator();

    it.next(); // Skip primary.

    List<Ignite> backups = new ArrayList<>(nodes.size() - 1);

    while (it.hasNext())
        backups.add(grid(it.next()));

    return backups;
}
 
Example 18
Source File: AbstractSchemaSelfTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * Assert index state on all <b>affinity</b> nodes.
 *
 * @param cacheName Cache name.
 * @param tblName Table name.
 * @param idxName Index name.
 * @param inlineSize Inline size.
 * @param fields Fields.
 */
static void assertIndex(String cacheName, String tblName, String idxName,
    int inlineSize, IgniteBiTuple<String, Boolean>... fields) {
    for (Ignite node : Ignition.allGrids())
        assertIndex(node, cacheName, tblName, idxName, inlineSize, fields);
}
 
Example 19
Source File: DynamicIndexAbstractSelfTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * Assert SQL simple data state.
 *
 * @param sql SQL query.
 * @param expSize Expected size.
 */
protected static void assertSqlSimpleData(String sql, int expSize) {
    for (Ignite node : Ignition.allGrids())
        assertSqlSimpleData(node, sql, expSize);
}
 
Example 20
Source File: DynamicIndexAbstractSelfTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * Ensure index is used in plan.
 *
 * @param idxName Index name.
 * @param sql SQL.
 * @param args Arguments.
 */
protected static void assertIndexUsed(String idxName, String sql, Object... args) {
    for (Ignite node : Ignition.allGrids())
        assertIndexUsed((IgniteEx)node, idxName, sql, args);
}