use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerTest method testSnapshotRestoreSynchronously.
/**
* @throws Exception If fails.
*/
@Test
public void testSnapshotRestoreSynchronously() throws Exception {
String snpName = "snapshot_02052020";
int keysCnt = 100;
IgniteEx ig = startGrids(2);
ig.cluster().state(ACTIVE);
injectTestSystemOut();
String cacheName = "test-cache";
createCacheAndPreload(ig, cacheName, keysCnt, 32, null);
ig.snapshot().createSnapshot(snpName).get(getTestTimeout());
CommandHandler h = new CommandHandler();
autoConfirmation = false;
// Invalid command syntax checks.
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "restore", snpName));
assertContains(log, testOut.toString(), "One of [--start, --cancel, --status] is expected.");
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "restore", snpName, "--cancel", "--sync"));
assertContains(log, testOut.toString(), "Invalid argument: --sync.");
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "restore", snpName, "blah"));
assertContains(log, testOut.toString(), "Invalid argument: blah. One of [--start, --cancel, --status] is expected.");
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "restore", snpName, "--status", "--sync"));
assertContains(log, testOut.toString(), "Invalid argument: --sync. Action \"--status\" does not support specified option.");
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "restore", snpName, "--sync", "--start"));
assertContains(log, testOut.toString(), "Invalid argument: --sync.");
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "restore", snpName, "--start", "blah"));
assertContains(log, testOut.toString(), "Invalid argument: blah. Possible options: --groups, --sync.");
autoConfirmation = true;
// Cache exists.
assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute(h, "--snapshot", "restore", snpName, "--start", "--sync"));
assertContains(log, testOut.toString(), "Unable to restore cache group - directory is not empty. " + "Cache group should be destroyed manually before perform restore operation [group=" + cacheName);
ig.cache(cacheName).destroy();
awaitPartitionMapExchange();
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", snpName, "--start", "--sync"));
assertContains(log, testOut.toString(), "Snapshot cache group restore operation completed successfully");
IgniteCache<Object, Object> cache = ig.cache(cacheName);
assertNotNull(cache);
for (int i = 0; i < keysCnt; i++) assertEquals("key=" + i, i, cache.get(i));
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerTest method testMasterKeyChangeOnInactiveCluster.
/**
* @throws Exception If failed.
*/
@Test
public void testMasterKeyChangeOnInactiveCluster() throws Exception {
encryptionEnabled = true;
injectTestSystemOut();
Ignite ignite = startGrids(1);
CommandHandler h = new CommandHandler();
assertEquals(EXIT_CODE_OK, execute(h, "--encryption", "get_master_key_name"));
Object res = h.getLastOperationResult();
assertEquals(ignite.encryption().getMasterKeyName(), res);
assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute(h, "--encryption", "change_master_key", MASTER_KEY_NAME_2));
assertContains(log, testOut.toString(), "Master key change was rejected. The cluster is inactive.");
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerTest method testSnapshotRestore.
/**
* @throws Exception If fails.
*/
@Test
public void testSnapshotRestore() throws Exception {
autoConfirmation = false;
int keysCnt = 100;
String snpName = "snapshot_02052020";
String cacheName1 = "cache1";
String cacheName2 = "cache2";
String cacheName3 = "cache3";
IgniteEx ig = startGrids(2);
ig.cluster().state(ACTIVE);
injectTestSystemOut();
injectTestSystemIn(CONFIRM_MSG);
createCacheAndPreload(ig, cacheName1, keysCnt, 32, null);
createCacheAndPreload(ig, cacheName2, keysCnt, 32, null);
createCacheAndPreload(ig, cacheName3, keysCnt, 32, null);
ig.snapshot().createSnapshot(snpName).get(getTestTimeout());
IgniteCache<Integer, Integer> cache1 = ig.cache(cacheName1);
IgniteCache<Integer, Integer> cache2 = ig.cache(cacheName2);
IgniteCache<Integer, Integer> cache3 = ig.cache(cacheName3);
cache1.destroy();
cache2.destroy();
cache3.destroy();
awaitPartitionMapExchange();
assertNull(ig.cache(cacheName1));
assertNull(ig.cache(cacheName2));
assertNull(ig.cache(cacheName3));
CommandHandler h = new CommandHandler();
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "restore", snpName, "--start", cacheName1));
assertContains(log, testOut.toString(), "Invalid argument: " + cacheName1 + ". Possible options: --groups, --sync.");
// Restore single cache group.
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", snpName, "--start", "--groups", cacheName1));
assertContains(log, testOut.toString(), "Snapshot cache group restore operation started [snapshot=" + snpName + ", group(s)=" + cacheName1 + ']');
waitForCondition(() -> ig.cache(cacheName1) != null, getTestTimeout());
cache1 = ig.cache(cacheName1);
assertNotNull(cache1);
for (int i = 0; i < keysCnt; i++) assertEquals(cacheName1, Integer.valueOf(i), cache1.get(i));
cache1.destroy();
awaitPartitionMapExchange();
assertNull(ig.cache(cacheName1));
assertNull(ig.cache(cacheName2));
assertNull(ig.cache(cacheName3));
String cacheNames = cacheName1 + ',' + cacheName2;
// Restore two (of three) groups of caches.
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", snpName, "--start", "--groups", cacheNames));
assertContains(log, testOut.toString(), "Snapshot cache group restore operation started [snapshot=" + snpName + ", group(s)=");
waitForCondition(() -> ig.cache(cacheName1) != null, getTestTimeout());
waitForCondition(() -> ig.cache(cacheName2) != null, getTestTimeout());
cache1 = ig.cache(cacheName1);
cache2 = ig.cache(cacheName2);
assertNotNull(cache1);
assertNotNull(cache2);
for (int i = 0; i < keysCnt; i++) {
assertEquals(cacheName1, Integer.valueOf(i), cache1.get(i));
assertEquals(cacheName2, Integer.valueOf(i), cache2.get(i));
}
cache1.destroy();
cache2.destroy();
awaitPartitionMapExchange();
assertNull(ig.cache(cacheName1));
assertNull(ig.cache(cacheName2));
assertNull(ig.cache(cacheName3));
// Restore all public cache groups.
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", snpName, "--start"));
String out = testOut.toString();
assertContains(log, out, "Warning: command will restore ALL USER-CREATED CACHE GROUPS from the snapshot");
assertContains(log, out, "Snapshot cache group restore operation started [snapshot=" + snpName + ']');
waitForCondition(() -> ig.cache(cacheName1) != null, getTestTimeout());
waitForCondition(() -> ig.cache(cacheName2) != null, getTestTimeout());
waitForCondition(() -> ig.cache(cacheName3) != null, getTestTimeout());
cache1 = ig.cache(cacheName1);
cache2 = ig.cache(cacheName2);
cache3 = ig.cache(cacheName3);
assertNotNull(cache1);
assertNotNull(cache2);
assertNotNull(cache3);
for (int i = 0; i < keysCnt; i++) {
assertEquals(cacheName1, Integer.valueOf(i), cache1.get(i));
assertEquals(cacheName2, Integer.valueOf(i), cache2.get(i));
assertEquals(cacheName3, Integer.valueOf(i), cache2.get(i));
}
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerTest method testKillHangingRemoteTransactions.
/**
* Simulate uncommitted backup transactions and test rolling back using utility.
*/
@Test
public void testKillHangingRemoteTransactions() throws Exception {
final int cnt = 3;
startGridsMultiThreaded(cnt);
Ignite[] clients = new Ignite[] { startGrid("client1"), startGrid("client2"), startGrid("client3"), startGrid("client4") };
clients[0].getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME).setBackups(2).setAtomicityMode(TRANSACTIONAL).setWriteSynchronizationMode(FULL_SYNC).setAffinity(new RendezvousAffinityFunction(false, 64)));
awaitPartitionMapExchange();
for (Ignite client : clients) {
assertTrue(client.configuration().isClientMode());
assertNotNull(client.cache(DEFAULT_CACHE_NAME));
}
LongAdder progress = new LongAdder();
AtomicInteger idx = new AtomicInteger();
int tc = clients.length;
CountDownLatch lockLatch = new CountDownLatch(1);
CountDownLatch commitLatch = new CountDownLatch(1);
Ignite prim = primaryNode(0L, DEFAULT_CACHE_NAME);
TestRecordingCommunicationSpi primSpi = TestRecordingCommunicationSpi.spi(prim);
primSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message message) {
return message instanceof GridDhtTxFinishRequest;
}
});
Set<IgniteUuid> xidSet = new GridConcurrentHashSet<>();
IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {
@Override
public void run() {
int id = idx.getAndIncrement();
Ignite client = clients[id];
try (Transaction tx = client.transactions().txStart(PESSIMISTIC, READ_COMMITTED, 0, 1)) {
xidSet.add(tx.xid());
IgniteCache<Long, Long> cache = client.cache(DEFAULT_CACHE_NAME);
if (id != 0)
U.awaitQuiet(lockLatch);
cache.invoke(0L, new IncrementClosure(), null);
if (id == 0) {
lockLatch.countDown();
U.awaitQuiet(commitLatch);
// Wait until candidates will enqueue.
doSleep(500);
}
tx.commit();
} catch (Exception e) {
assertTrue(X.hasCause(e, TransactionTimeoutException.class));
}
progress.increment();
}
}, tc, "invoke-thread");
U.awaitQuiet(lockLatch);
commitLatch.countDown();
primSpi.waitForBlocked(clients.length);
// Unblock only finish messages from clients from 2 to 4.
primSpi.stopBlock(true, blockedMsg -> {
GridIoMessage iom = blockedMsg.ioMessage();
Message m = iom.message();
if (m instanceof GridDhtTxFinishRequest) {
GridDhtTxFinishRequest r = (GridDhtTxFinishRequest) m;
return !r.nearNodeId().equals(clients[0].cluster().localNode().id());
}
return true;
});
// Wait until queue is stable
for (Ignite ignite : G.allGrids()) {
if (ignite.configuration().isClientMode())
continue;
Collection<IgniteInternalTx> txs = ((IgniteEx) ignite).context().cache().context().tm().activeTransactions();
waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
for (IgniteInternalTx tx : txs) if (!tx.local()) {
IgniteTxEntry entry = tx.writeEntries().iterator().next();
GridCacheEntryEx cached = entry.cached();
Collection<GridCacheMvccCandidate> candidates = cached.remoteMvccSnapshot();
if (candidates.size() != clients.length)
return false;
}
return true;
}
}, 10_000);
}
CommandHandler h = new CommandHandler();
// Check listing.
validate(h, map -> {
for (int i = 0; i < cnt; i++) {
IgniteEx grid = grid(i);
// Skip primary.
if (grid.localNode().id().equals(prim.cluster().localNode().id()))
continue;
VisorTxTaskResult res = map.get(grid.localNode());
List<VisorTxInfo> infos = res.getInfos().stream().filter(info -> xidSet.contains(info.getNearXid())).collect(Collectors.toList());
// Validate queue length on backups.
assertEquals(clients.length, infos.size());
}
}, "--tx");
// Check kill.
validate(h, map -> {
// No-op.
}, "--tx", "--kill");
// Wait for all remote txs to finish.
for (Ignite ignite : G.allGrids()) {
if (ignite.configuration().isClientMode())
continue;
Collection<IgniteInternalTx> txs = ((IgniteEx) ignite).context().cache().context().tm().activeTransactions();
for (IgniteInternalTx tx : txs) if (!tx.local())
tx.finishFuture().get();
}
// Unblock finish message from client1.
primSpi.stopBlock(true);
fut.get();
Long cur = (Long) clients[0].cache(DEFAULT_CACHE_NAME).get(0L);
assertEquals(tc - 1, cur.longValue());
checkUserFutures();
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerSslTest method activate.
/**
* @param nodeCipherSuite Ciphers suites to set on node.
* @param utilityCipherSuite Ciphers suites to set on utility.
* @param expRes Expected result.
* @throws Exception If failed.
*/
private void activate(String nodeCipherSuite, String utilityCipherSuite, int expRes) throws Exception {
cipherSuites = F.isEmpty(nodeCipherSuite) ? null : nodeCipherSuite.split(",");
Ignite ignite = startGrids(1);
assertFalse(ignite.cluster().active());
final CommandHandler cmd = new CommandHandler();
List<String> params = new ArrayList<>();
addSslParams(params);
if (!F.isEmpty(utilityCipherSuite)) {
params.add("--ssl-cipher-suites");
params.add(utilityCipherSuite);
}
params.add("--activate");
assertEquals(expRes, execute(params));
if (expRes == EXIT_CODE_OK)
assertTrue(ignite.cluster().active());
else
assertFalse(ignite.cluster().active());
assertEquals(EXIT_CODE_CONNECTION_FAILED, cmd.execute(Arrays.asList("--deactivate", "--yes")));
}
Aggregations