Search in sources :

Example 11 with CommandHandler

use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.

the class GridCommandHandlerIndexListTest method checkCacheNameFilter.

/**
 */
private void checkCacheNameFilter(String cacheRegEx, Predicate<String> predicate, int expectedResNum) {
    final CommandHandler handler = new CommandHandler(createTestLogger());
    assertEquals(EXIT_CODE_OK, execute(handler, "--cache", "indexes_list", "--cache-name", cacheRegEx));
    Set<IndexListInfoContainer> cmdResult = handler.getLastOperationResult();
    assertNotNull(cmdResult);
    boolean isResCorrect = cmdResult.stream().map(IndexListInfoContainer::cacheName).allMatch(predicate);
    assertTrue("Unexpected command result", isResCorrect);
    int indexesNum = cmdResult.size();
    assertEquals("Unexpected number of indexes: " + indexesNum, indexesNum, expectedResNum);
}
Also used : CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) IndexListInfoContainer(org.apache.ignite.internal.visor.cache.index.IndexListInfoContainer)

Example 12 with CommandHandler

use of org.apache.ignite.internal.commandline.CommandHandler 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 13 with CommandHandler

use of org.apache.ignite.internal.commandline.CommandHandler 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)

Example 14 with CommandHandler

use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.

the class GridCommandHandlerSslWithSecurityTest method testConnector.

/**
 * Checks that control.sh script can connect to the cluster, that has SSL enabled.
 */
@Test
public void testConnector() throws Exception {
    IgniteEx crd = startGrid();
    crd.cluster().state(ACTIVE);
    injectTestSystemOut();
    CommandHandler hnd = new CommandHandler();
    int exitCode = hnd.execute(Arrays.asList("--state", "--user", login, "--password", pwd, "--keystore", keyStorePath("connectorClient"), "--keystore-password", keyStorePassword(), "--truststore", keyStorePath("trustthree"), "--truststore-password", keyStorePassword()));
    assertEquals(EXIT_CODE_OK, exitCode);
    flushCommandOutput(hnd);
    // Make sure all sensitive information is masked.
    String testOutput = testOut.toString();
    assertContains(log, testOutput, "--password *****");
    assertContains(log, testOutput, "--keystore-password *****");
    assertContains(log, testOutput, "--truststore-password *****");
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 15 with CommandHandler

use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.

the class GridCommandHandlerSslWithSecurityTest method testInputKeyTrustStorePwdOnlyOnce.

/**
 * Verify that the command work correctly when entering passwords for
 * keystore and truststore, and that these passwords are requested only
 * once.
 *
 * @throws Exception If failed.
 */
@Test
public void testInputKeyTrustStorePwdOnlyOnce() throws Exception {
    IgniteEx crd = startGrid();
    crd.cluster().state(ACTIVE);
    CommandHandler cmd = new CommandHandler();
    AtomicInteger keyStorePwdCnt = new AtomicInteger();
    AtomicInteger trustStorePwdCnt = new AtomicInteger();
    cmd.console = new NoopConsole() {

        /**
         * {@inheritDoc}
         */
        @Override
        public char[] readPassword(String fmt, Object... args) {
            if (fmt.contains("keystore")) {
                keyStorePwdCnt.incrementAndGet();
                return keyStorePassword().toCharArray();
            } else if (fmt.contains("truststore")) {
                trustStorePwdCnt.incrementAndGet();
                return keyStorePassword().toCharArray();
            }
            return pwd.toCharArray();
        }
    };
    List<String> args = new ArrayList<>();
    args.add(DEACTIVATE.text());
    args.add("--force");
    args.add("--yes");
    args.add("--user");
    args.add(login);
    args.add("--keystore");
    args.add(keyStorePath("connectorServer"));
    args.add("--truststore");
    args.add(keyStorePath("trustthree"));
    assertEquals(EXIT_CODE_OK, cmd.execute(args));
    assertEquals(1, keyStorePwdCnt.get());
    assertEquals(1, trustStorePwdCnt.get());
}
Also used : NoopConsole(org.apache.ignite.internal.commandline.NoopConsole) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) ArrayList(java.util.ArrayList) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

CommandHandler (org.apache.ignite.internal.commandline.CommandHandler)35 Test (org.junit.Test)26 IgniteEx (org.apache.ignite.internal.IgniteEx)16 Ignite (org.apache.ignite.Ignite)12 IgniteCacheGroupsWithRestartsTest (org.apache.ignite.internal.processors.cache.persistence.db.IgniteCacheGroupsWithRestartsTest)10 AbstractSnapshotSelfTest.doSnapshotCancellationTest (org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.doSnapshotCancellationTest)10 Logger (java.util.logging.Logger)6 ArrayList (java.util.ArrayList)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 ListeningTestLogger (org.apache.ignite.testframework.ListeningTestLogger)5 Arrays (java.util.Arrays)4 Formatter (java.util.logging.Formatter)4 LogRecord (java.util.logging.LogRecord)4 StreamHandler (java.util.logging.StreamHandler)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 IOException (java.io.IOException)3 Collections (java.util.Collections)3 List (java.util.List)3