Search in sources :

Example 1 with IgniteClusterEx

use of org.apache.ignite.internal.cluster.IgniteClusterEx in project ignite by apache.

the class GridCacheAdapter method sizeLongAsync.

/**
 * {@inheritDoc}
 */
@Override
public IgniteInternalFuture<Long> sizeLongAsync(final CachePeekMode[] peekModes) {
    assert peekModes != null;
    PeekModes modes = parsePeekModes(peekModes, true);
    IgniteClusterEx cluster = ctx.grid().cluster();
    ClusterGroup grp = modes.near ? cluster.forCacheNodes(name(), true, true, false) : cluster.forDataNodes(name());
    Collection<ClusterNode> nodes = new ArrayList<>(grp.nodes());
    if (nodes.isEmpty())
        return new GridFinishedFuture<>(0L);
    ctx.kernalContext().task().setThreadContext(TC_SUBGRID, nodes);
    return ctx.kernalContext().task().execute(new SizeLongTask(ctx.name(), ctx.affinity().affinityTopologyVersion(), peekModes), null);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteClusterNode(org.apache.ignite.internal.managers.discovery.IgniteClusterNode) IgniteClusterEx(org.apache.ignite.internal.cluster.IgniteClusterEx) ArrayList(java.util.ArrayList) ClusterGroup(org.apache.ignite.cluster.ClusterGroup)

Example 2 with IgniteClusterEx

use of org.apache.ignite.internal.cluster.IgniteClusterEx in project ignite by apache.

the class GridCacheAdapter method sizeAsync.

/**
 * {@inheritDoc}
 */
@Override
public IgniteInternalFuture<Integer> sizeAsync(final CachePeekMode[] peekModes) {
    assert peekModes != null;
    PeekModes modes = parsePeekModes(peekModes, true);
    IgniteClusterEx cluster = ctx.grid().cluster();
    ClusterGroup grp = modes.near ? cluster.forCacheNodes(name(), true, true, false) : cluster.forDataNodes(name());
    Collection<ClusterNode> nodes = new ArrayList<>(grp.nodes());
    if (nodes.isEmpty())
        return new GridFinishedFuture<>(0);
    ctx.kernalContext().task().setThreadContext(TC_SUBGRID, nodes);
    return ctx.kernalContext().task().execute(new SizeTask(ctx.name(), ctx.affinity().affinityTopologyVersion(), peekModes), null);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteClusterNode(org.apache.ignite.internal.managers.discovery.IgniteClusterNode) IgniteClusterEx(org.apache.ignite.internal.cluster.IgniteClusterEx) ArrayList(java.util.ArrayList) ClusterGroup(org.apache.ignite.cluster.ClusterGroup)

Example 3 with IgniteClusterEx

use of org.apache.ignite.internal.cluster.IgniteClusterEx in project ignite by apache.

the class PlatformAffinityUtils method readPartitionAssignment.

/**
 * Reads the partition assignment.
 *
 * @param reader Reader.
 * @param ctx Platform context.
 * @return Partitions.
 */
@NotNull
public static List<List<ClusterNode>> readPartitionAssignment(BinaryRawReader reader, PlatformContext ctx) {
    assert reader != null;
    assert ctx != null;
    int partCnt = reader.readInt();
    List<List<ClusterNode>> res = new ArrayList<>(partCnt);
    IgniteClusterEx cluster = ctx.kernalContext().grid().cluster();
    for (int i = 0; i < partCnt; i++) {
        int partSize = reader.readInt();
        List<ClusterNode> part = new ArrayList<>(partSize);
        for (int j = 0; j < partSize; j++) part.add(cluster.node(reader.readUuid()));
        res.add(part);
    }
    return res;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteClusterEx(org.apache.ignite.internal.cluster.IgniteClusterEx) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with IgniteClusterEx

use of org.apache.ignite.internal.cluster.IgniteClusterEx in project ignite by apache.

the class BaselineEventsTest method testEventsDisabledByDefault.

/**
 */
@Test
public void testEventsDisabledByDefault() throws Exception {
    // noinspection ZeroLengthArrayAllocation
    includedEvtTypes = new int[0];
    IgniteClusterEx cluster = startGrid(0).cluster();
    cluster.active(true);
    AtomicInteger evtsTriggered = new AtomicInteger();
    listen(grid(0), event -> {
        evtsTriggered.incrementAndGet();
        return true;
    }, EventType.EVT_BASELINE_AUTO_ADJUST_ENABLED_CHANGED, EventType.EVT_BASELINE_AUTO_ADJUST_AWAITING_TIME_CHANGED);
    startGrid(1);
    String consistentIds = grid(0).localNode().consistentId() + "," + grid(1).localNode().consistentId();
    assertEquals(CommandHandler.EXIT_CODE_OK, new CommandHandler().execute(Arrays.asList("--baseline", "set", consistentIds, "--yes")));
    awaitPartitionMapExchange();
    startGrid(2);
    cluster.setBaselineTopology(cluster.topologyVersion());
    awaitPartitionMapExchange();
    assertEquals(CommandHandler.EXIT_CODE_OK, new CommandHandler().execute(Arrays.asList("--baseline", "auto_adjust", "enable", "timeout", "10", "--yes")));
    cluster.baselineAutoAdjustEnabled(false);
    cluster.baselineAutoAdjustTimeout(50);
    assertFalse(GridTestUtils.waitForCondition(() -> evtsTriggered.get() > 0, 3_000L));
}
Also used : IgniteClusterEx(org.apache.ignite.internal.cluster.IgniteClusterEx) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with IgniteClusterEx

use of org.apache.ignite.internal.cluster.IgniteClusterEx in project ignite by apache.

the class BaselineEventsTest method testChangeAutoAdjustEnabled.

/**
 */
@Test
public void testChangeAutoAdjustEnabled() throws Exception {
    IgniteClusterEx cluster = startGrids(2).cluster();
    cluster.active(true);
    assertFalse(cluster.isBaselineAutoAdjustEnabled());
    AtomicBoolean autoAdjustEnabled = new AtomicBoolean();
    listen(grid(0), event -> {
        BaselineConfigurationChangedEvent bltCfgChangedEvt = (BaselineConfigurationChangedEvent) event;
        autoAdjustEnabled.set(bltCfgChangedEvt.isAutoAdjustEnabled());
        return true;
    }, EventType.EVT_BASELINE_AUTO_ADJUST_ENABLED_CHANGED);
    assertEquals(CommandHandler.EXIT_CODE_OK, new CommandHandler().execute(Arrays.asList("--baseline", "auto_adjust", "enable", "timeout", "10", "--yes")));
    assertTrue(GridTestUtils.waitForCondition(autoAdjustEnabled::get, 3_000));
    assertEquals(CommandHandler.EXIT_CODE_OK, new CommandHandler().execute(Arrays.asList("--baseline", "auto_adjust", "disable", "--yes")));
    assertFalse(autoAdjustEnabled.get());
    cluster.baselineAutoAdjustEnabled(true);
    assertTrue(GridTestUtils.waitForCondition(autoAdjustEnabled::get, 3_000));
    cluster.baselineAutoAdjustEnabled(false);
    assertTrue(GridTestUtils.waitForCondition(() -> !autoAdjustEnabled.get(), 3_000));
}
Also used : IgniteClusterEx(org.apache.ignite.internal.cluster.IgniteClusterEx) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

IgniteClusterEx (org.apache.ignite.internal.cluster.IgniteClusterEx)18 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)7 Test (org.junit.Test)7 ClusterGroup (org.apache.ignite.cluster.ClusterGroup)5 ClusterNode (org.apache.ignite.cluster.ClusterNode)5 ArrayList (java.util.ArrayList)4 CommandHandler (org.apache.ignite.internal.commandline.CommandHandler)3 IgniteClusterNode (org.apache.ignite.internal.managers.discovery.IgniteClusterNode)3 UUID (java.util.UUID)2 GridStringLogger (org.apache.ignite.testframework.GridStringLogger)2 GridTestLog4jLogger (org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1