use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerTracingConfigurationTest method beforeTestsStarted.
/**
* {@inheritDoc}
*/
@Override
protected void beforeTestsStarted() throws Exception {
super.beforeTestsStarted();
ignite = startGrids(2);
hnd = new CommandHandler();
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerSslWithSecurityTest method flushCommandOutput.
/**
* Flushes all Logger handlers to make log data available to test.
* @param hnd Command handler.
*/
private void flushCommandOutput(CommandHandler hnd) {
Logger log = U.field(hnd, "logger");
Arrays.stream(log.getHandlers()).forEach(Handler::flush);
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerDefragmentationTest method testDefragmentationSchedule.
/**
* @throws Exception If failed.
*/
@Test
public void testDefragmentationSchedule() throws Exception {
Ignite ignite = startGrids(2);
ignite.cluster().state(ACTIVE);
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute("--defragmentation", "schedule"));
String grid0ConsId = grid(0).configuration().getConsistentId().toString();
String grid1ConsId = grid(1).configuration().getConsistentId().toString();
ListeningTestLogger testLog = new ListeningTestLogger();
CommandHandler cmd = createCommandHandler(testLog);
LogListener logLsnr = LogListener.matches("Scheduling completed successfully.").build();
testLog.registerListener(logLsnr);
assertEquals(EXIT_CODE_OK, execute(cmd, "--defragmentation", "schedule", "--nodes", grid0ConsId));
assertTrue(logLsnr.check());
MaintenanceTask mntcTask = DefragmentationParameters.toStore(Collections.emptyList());
assertNotNull(grid(0).context().maintenanceRegistry().registerMaintenanceTask(mntcTask));
assertNull(grid(1).context().maintenanceRegistry().registerMaintenanceTask(mntcTask));
stopGrid(0);
startGrid(0);
logLsnr = LogListener.matches("Node is already in Maintenance Mode").build();
testLog.clearListeners();
testLog.registerListener(logLsnr);
assertEquals(EXIT_CODE_OK, execute(cmd, "--defragmentation", "schedule", "--nodes", grid0ConsId));
assertTrue(logLsnr.check());
stopGrid(0);
startGrid(0);
stopGrid(1);
startGrid(1);
stopAllGrids();
startGrids(2);
logLsnr = LogListener.matches("Scheduling completed successfully.").times(2).build();
testLog.clearListeners();
testLog.registerListener(logLsnr);
assertEquals(EXIT_CODE_OK, execute(cmd, "--defragmentation", "schedule", "--nodes", String.join(",", grid0ConsId, grid1ConsId)));
assertTrue(logLsnr.check());
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerDefragmentationTest method testDefragmentationCancel.
/**
* @throws Exception If failed.
*/
@Test
public void testDefragmentationCancel() throws Exception {
Ignite ignite = startGrids(2);
ignite.cluster().state(ACTIVE);
String grid0ConsId = grid(0).configuration().getConsistentId().toString();
ListeningTestLogger testLog = new ListeningTestLogger();
CommandHandler cmd = createCommandHandler(testLog);
assertEquals(EXIT_CODE_OK, execute(cmd, "--defragmentation", "schedule", "--nodes", grid0ConsId));
LogListener logLsnr = LogListener.matches("Scheduled defragmentation task cancelled successfully.").atLeast(1).build();
testLog.registerListener(logLsnr);
assertEquals(EXIT_CODE_OK, execute(cmd, "--port", grid(0).localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString(), "--defragmentation", "cancel"));
assertTrue(logLsnr.check());
testLog.clearListeners();
logLsnr = LogListener.matches("Scheduled defragmentation task is not found.").build();
testLog.registerListener(logLsnr);
assertEquals(EXIT_CODE_OK, execute(cmd, "--port", grid(1).localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString(), "--defragmentation", "cancel"));
assertTrue(logLsnr.check());
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerTest method testSnapshotRestoreCancelAndStatus.
/**
* @throws Exception If fails.
*/
@Test
public void testSnapshotRestoreCancelAndStatus() throws Exception {
int keysCnt = 2048;
String snpName = "snapshot_25052021";
String missingSnpName = "snapshot_MISSING";
IgniteEx ig = startGrid(getConfiguration(getTestIgniteInstanceName(0)).setSnapshotThreadPoolSize(1));
startGrid(1).cluster().state(ACTIVE);
injectTestSystemOut();
createCacheAndPreload(ig, keysCnt);
ig.snapshot().createSnapshot(snpName).get(getTestTimeout());
int locPartsCnt = ig.cachex(DEFAULT_CACHE_NAME).context().topology().localPartitions().size();
ig.destroyCache(DEFAULT_CACHE_NAME);
awaitPartitionMapExchange();
CommandHandler h = new CommandHandler();
CountDownLatch ioStartLatch = new CountDownLatch(1);
IgniteSnapshotManager snpMgr = ig.context().cache().context().snapshotMgr();
// Replace the IO factory in the snapshot manager so we have enough time to test the status command.
snpMgr.ioFactory(new SlowDownFileIoFactory(snpMgr.ioFactory(), getTestTimeout() / locPartsCnt, ioStartLatch));
// Restore single cache group.
IgniteFuture<Void> restoreFut = snpMgr.restoreSnapshot(snpName, Collections.singleton(DEFAULT_CACHE_NAME));
ioStartLatch.await(getTestTimeout(), TimeUnit.MILLISECONDS);
assertFalse(restoreFut.isDone());
// Check the status with a control command.
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", snpName, "--status"));
assertContains(log, testOut.toString(), "Snapshot cache group restore operation is running [snapshot=" + snpName + ']');
// Check "status" with the wrong snapshot name.
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", missingSnpName, "--status"));
assertContains(log, testOut.toString(), "Snapshot cache group restore operation is NOT running [snapshot=" + missingSnpName + ']');
// Check "cancel" with the wrong snapshot name.
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", missingSnpName, "--cancel"));
assertContains(log, testOut.toString(), "Snapshot cache group restore operation is NOT running [snapshot=" + missingSnpName + ']');
// Cancel operation using control command.
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", snpName, "--cancel"));
assertContains(log, testOut.toString(), "Snapshot cache group restore operation canceled [snapshot=" + snpName + ']');
GridTestUtils.assertThrowsAnyCause(log, () -> restoreFut.get(getTestTimeout()), IgniteCheckedException.class, "Operation has been canceled by the user.");
// Make sure the context disappeared at node 1.
boolean ctxDisposed = waitForCondition(() -> !grid(1).context().cache().context().snapshotMgr().isRestoring(), getTestTimeout());
assertTrue(ctxDisposed);
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", snpName, "--status"));
assertContains(log, testOut.toString(), "Snapshot cache group restore operation is NOT running [snapshot=" + snpName + ']');
assertNull(ig.cache(DEFAULT_CACHE_NAME));
}
Aggregations