use of org.apache.geode.management.internal.cli.util.CommandStringBuilder in project geode by apache.
the class DiskStoreCommandsDUnitTest method testDestroyDiskStore.
@Test
public void testDestroyDiskStore() {
final String diskStore1Name = "testDestroyDiskStore1";
final String diskStore2Name = "testDestroyDiskStore2";
final String region1Name = "testDestroyDiskStoreRegion1";
final String region2Name = "testDestroyDiskStoreRegion2";
Properties localProps = new Properties();
localProps.setProperty(GROUPS, "Group0");
setUpJmxManagerOnVm0ThenConnect(localProps);
CommandResult cmdResult = executeCommand(CliStrings.LIST_DISK_STORE);
assertEquals(Result.Status.OK, cmdResult.getStatus());
assertTrue(commandResultToString(cmdResult).contains("No Disk Stores Found"));
final VM vm1 = Host.getHost(0).getVM(1);
final String vm1Name = "VM" + vm1.getPid();
final File diskStore1Dir1 = new File(new File(".").getAbsolutePath(), diskStore1Name + ".1");
this.filesToBeDeleted.add(diskStore1Dir1.getAbsolutePath());
final File diskStore2Dir1 = new File(new File(".").getAbsolutePath(), diskStore2Name + ".1");
this.filesToBeDeleted.add(diskStore2Dir1.getAbsolutePath());
vm1.invoke(new SerializableRunnable() {
public void run() {
diskStore1Dir1.mkdirs();
diskStore2Dir1.mkdirs();
Properties localProps = new Properties();
localProps.setProperty(NAME, vm1Name);
localProps.setProperty(GROUPS, "Group1,Group2");
getSystem(localProps);
Cache cache = getCache();
DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
diskStoreFactory.setDiskDirs(new File[] { diskStore1Dir1 });
diskStoreFactory.create(diskStore1Name);
diskStoreFactory.setDiskDirs(new File[] { diskStore2Dir1 });
diskStoreFactory.create(diskStore2Name);
}
});
final VM vm2 = Host.getHost(0).getVM(2);
final String vm2Name = "VM" + vm2.getPid();
final File diskStore1Dir2 = new File(new File(".").getAbsolutePath(), diskStore1Name + ".2");
this.filesToBeDeleted.add(diskStore1Dir2.getAbsolutePath());
final File diskStore2Dir2 = new File(new File(".").getAbsolutePath(), diskStore2Name + ".2");
this.filesToBeDeleted.add(diskStore2Dir2.getAbsolutePath());
vm2.invoke(new SerializableRunnable() {
public void run() {
diskStore1Dir2.mkdirs();
diskStore2Dir2.mkdirs();
Properties localProps = new Properties();
localProps.setProperty(NAME, vm2Name);
localProps.setProperty(GROUPS, "Group2");
getSystem(localProps);
Cache cache = getCache();
DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
diskStoreFactory.setDiskDirs(new File[] { diskStore1Dir2 });
diskStoreFactory.create(diskStore1Name);
RegionFactory regionFactory = cache.createRegionFactory();
regionFactory.setDiskStoreName(diskStore1Name);
regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
regionFactory.create(region1Name);
regionFactory.create(region2Name);
diskStoreFactory.setDiskDirs(new File[] { diskStore2Dir2 });
diskStoreFactory.create(diskStore2Name);
}
});
// TEST DELETING ON 1 MEMBER
CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.DESTROY_DISK_STORE);
commandStringBuilder.addOption(CliStrings.DESTROY_DISK_STORE__NAME, diskStore1Name);
commandStringBuilder.addOption(CliStrings.DESTROY_DISK_STORE__GROUP, "Group1");
cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
String stringResult = commandResultToString(cmdResult);
assertEquals(3, countLinesInString(stringResult, false));
assertEquals(false, stringResult.contains("ERROR"));
assertTrue(stringContainsLine(stringResult, vm1Name + ".*Success"));
// Verify that the disk store was destroyed on the correct member
cmdResult = executeCommand(CliStrings.LIST_DISK_STORE);
assertEquals(Result.Status.OK, cmdResult.getStatus());
stringResult = commandResultToString(cmdResult);
assertEquals(5, countLinesInString(stringResult, false));
assertFalse(stringContainsLine(stringResult, vm1Name + ".*" + diskStore1Name + " .*"));
assertTrue(stringContainsLine(stringResult, vm2Name + ".*" + diskStore1Name + " .*"));
// Verify that the disk store files were deleted from the correct directory.
assertEquals(0, diskStore1Dir1.listFiles().length);
assertEquals(4, diskStore1Dir2.listFiles().length);
// TEST DELETING ON 2 MEMBERS
commandStringBuilder = new CommandStringBuilder(CliStrings.DESTROY_DISK_STORE);
commandStringBuilder.addOption(CliStrings.DESTROY_DISK_STORE__NAME, diskStore2Name);
commandStringBuilder.addOption(CliStrings.DESTROY_DISK_STORE__GROUP, "Group2");
cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
stringResult = commandResultToString(cmdResult);
assertEquals(4, countLinesInString(stringResult, false));
assertEquals(false, stringResult.contains("ERROR"));
assertTrue(stringContainsLine(stringResult, vm1Name + ".*Success"));
assertTrue(stringContainsLine(stringResult, vm2Name + ".*Success"));
// Verify that the disk store was destroyed on the correct member
cmdResult = executeCommand(CliStrings.LIST_DISK_STORE);
assertEquals(Result.Status.OK, cmdResult.getStatus());
stringResult = commandResultToString(cmdResult);
assertEquals(3, countLinesInString(stringResult, false));
assertFalse(stringContainsLine(stringResult, vm1Name + ".*" + diskStore2Name + " .*"));
assertFalse(stringContainsLine(stringResult, vm2Name + ".*" + diskStore2Name + " .*"));
// Verify that the disk store files were deleted from the correct directories.
assertEquals(0, diskStore2Dir1.listFiles().length);
assertEquals(0, diskStore2Dir2.listFiles().length);
// TEST FOR DISK STORE IN USE
commandStringBuilder = new CommandStringBuilder(CliStrings.DESTROY_DISK_STORE);
commandStringBuilder.addOption(CliStrings.DESTROY_DISK_STORE__NAME, diskStore1Name);
commandStringBuilder.addOption(CliStrings.DESTROY_DISK_STORE__GROUP, "Group2");
cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
stringResult = commandResultToString(cmdResult);
assertEquals(4, countLinesInString(stringResult, false));
assertEquals(false, stringResult.contains("ERROR"));
assertTrue(stringContainsLine(stringResult, vm1Name + ".*Disk store not found on this member"));
assertTrue(stringContainsLine(stringResult, vm2Name + ".*" + region1Name + ".*" + region2Name + ".*"));
// TEST DELETING ON ALL MEMBERS
vm2.invoke(new SerializableRunnable() {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(region1Name);
region.destroyRegion();
region = cache.getRegion(region2Name);
region.destroyRegion();
}
});
commandStringBuilder = new CommandStringBuilder(CliStrings.DESTROY_DISK_STORE);
commandStringBuilder.addOption(CliStrings.DESTROY_DISK_STORE__NAME, diskStore1Name);
cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
stringResult = commandResultToString(cmdResult);
assertEquals(5, countLinesInString(stringResult, false));
assertEquals(false, stringResult.contains("ERROR"));
assertTrue(stringContainsLine(stringResult, "Manager.*Disk store not found on this member"));
assertTrue(stringContainsLine(stringResult, vm1Name + ".*Disk store not found on this member"));
assertTrue(stringContainsLine(stringResult, vm2Name + ".*Success"));
// Verify that there are no disk stores left.
cmdResult = executeCommand(CliStrings.LIST_DISK_STORE);
assertEquals(Result.Status.OK, cmdResult.getStatus());
assertTrue(commandResultToString(cmdResult).contains("No Disk Stores Found"));
// Verify that the disk store files were deleted from the correct directory.
assertEquals(0, diskStore1Dir2.listFiles().length);
}
use of org.apache.geode.management.internal.cli.util.CommandStringBuilder in project geode by apache.
the class CreateAlterDestroyRegionCommandsDUnitTest method testCreateRegionWithBadCompressor.
/**
* Asserts that the "compressor" option for the "create region" command fails for an unrecognized
* compressorc.
*/
@Test
public void testCreateRegionWithBadCompressor() {
setUpJmxManagerOnVm0ThenConnect(null);
VM vm = Host.getHost(0).getVM(1);
// Create a cache in vm 1
vm.invoke(() -> {
assertNotNull(getCache());
});
// Create a region with an unrecognized compressor
CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_REGION);
commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGION, "compressedRegion");
commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, "REPLICATE");
commandStringBuilder.addOption(CliStrings.CREATE_REGION__COMPRESSOR, "BAD_COMPRESSOR");
CommandResult cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.ERROR, cmdResult.getStatus());
// Assert that our region was not created
vm.invoke(() -> {
Region region = getCache().getRegion("compressedRegion");
assertNull(region);
});
}
use of org.apache.geode.management.internal.cli.util.CommandStringBuilder in project geode by apache.
the class CreateAlterDestroyRegionCommandsDUnitTest method testCreateRegionWithGoodCompressor.
/**
* Asserts that the "compressor" option for the "create region" command succeeds for a recognized
* compressor.
*/
@Test
public void testCreateRegionWithGoodCompressor() {
setUpJmxManagerOnVm0ThenConnect(null);
VM vm = Host.getHost(0).getVM(1);
// Create a cache in vm 1
vm.invoke(() -> {
assertNotNull(getCache());
});
// Run create region command with compression
CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_REGION);
commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGION, "compressedRegion");
commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, "REPLICATE");
commandStringBuilder.addOption(CliStrings.CREATE_REGION__COMPRESSOR, RegionEntryContext.DEFAULT_COMPRESSION_PROVIDER);
CommandResult cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure our region exists with compression enabled
vm.invoke(() -> {
Region region = getCache().getRegion("compressedRegion");
assertNotNull(region);
assertTrue(SnappyCompressor.getDefaultInstance().equals(region.getAttributes().getCompressor()));
});
// cleanup
commandStringBuilder = new CommandStringBuilder(CliStrings.DESTROY_REGION);
commandStringBuilder.addOption(CliStrings.DESTROY_REGION__REGION, "compressedRegion");
cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
}
use of org.apache.geode.management.internal.cli.util.CommandStringBuilder in project geode by apache.
the class CreateAlterDestroyRegionCommandsDUnitTest method testDestroyRegionWithSharedConfig.
@Test
public void testDestroyRegionWithSharedConfig() {
disconnectAllFromDS();
final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
jmxPort = ports[0];
httpPort = ports[1];
try {
jmxHost = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException ignore) {
jmxHost = "localhost";
}
final String regionName = "testRegionSharedConfigRegion";
final String regionPath = "/" + regionName;
final String groupName = "testRegionSharedConfigGroup";
// Start the Locator and wait for shared configuration to be available
final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
final Properties locatorProps = new Properties();
locatorProps.setProperty(NAME, "Locator");
locatorProps.setProperty(MCAST_PORT, "0");
locatorProps.setProperty(LOG_LEVEL, "fine");
locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
locatorProps.setProperty(JMX_MANAGER, "true");
locatorProps.setProperty(JMX_MANAGER_START, "true");
locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
Host.getHost(0).getVM(0).invoke(() -> {
final File locatorLogFile = new File("locator-" + locatorPort + ".log");
try {
final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort, locatorLogFile, null, locatorProps);
waitAtMost(5, TimeUnit.SECONDS).until(() -> locator.isSharedConfigurationRunning());
} catch (IOException ioex) {
fail("Unable to create a locator with a shared configuration");
}
});
connect(jmxHost, jmxPort, httpPort, getDefaultShell());
// Create a cache in VM 1
VM vm = Host.getHost(0).getVM(1);
vm.invoke(() -> {
Properties localProps = new Properties();
localProps.setProperty(MCAST_PORT, "0");
localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
localProps.setProperty(GROUPS, groupName);
getSystem(localProps);
assertNotNull(getCache());
});
// Test creating the region
CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_REGION);
commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGION, regionName);
commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, "REPLICATE");
commandStringBuilder.addOption(CliStrings.CREATE_REGION__STATISTICSENABLED, "true");
commandStringBuilder.addOption(CliStrings.CREATE_REGION__GROUP, groupName);
CommandResult cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure that the region has been registered with the Manager MXBean
waitForRegionMBeanCreation(regionPath, 1);
// Make sure the region exists in the shared config
Host.getHost(0).getVM(0).invoke(() -> {
ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
try {
assertTrue(sharedConfig.getConfiguration(groupName).getCacheXmlContent().contains(regionName));
} catch (Exception e) {
fail("Error occurred in cluster configuration service");
}
});
// Test destroying the region
commandStringBuilder = new CommandStringBuilder(CliStrings.DESTROY_REGION);
commandStringBuilder.addOption(CliStrings.DESTROY_REGION__REGION, regionName);
cmdResult = executeCommand(commandStringBuilder.toString());
getLogWriter().info("#SB" + commandResultToString(cmdResult));
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure the region was removed from the shared config
Host.getHost(0).getVM(0).invoke(() -> {
ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
try {
assertFalse(sharedConfig.getConfiguration(groupName).getCacheXmlContent().contains(regionName));
} catch (Exception e) {
fail("Error occurred in cluster configuration service");
}
});
// Restart the data vm to make sure the region is not existing any more
vm = Host.getHost(0).getVM(1);
vm.invoke(() -> {
Cache cache = getCache();
assertNotNull(cache);
cache.close();
assertTrue(cache.isClosed());
Properties localProps = new Properties();
localProps.setProperty(MCAST_PORT, "0");
localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
localProps.setProperty(GROUPS, groupName);
localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
getSystem(localProps);
cache = getCache();
assertNotNull(cache);
Region region = cache.getRegion(regionName);
assertNull(region);
return null;
});
}
use of org.apache.geode.management.internal.cli.util.CommandStringBuilder in project geode by apache.
the class ConfigCommandsDUnitTest method testAlterRuntimeConfigOnAllMembers.
@Test
public void testAlterRuntimeConfigOnAllMembers() throws Exception {
final String member1 = "VM1";
final String controller = "controller";
String controllerDirectory = this.temporaryFolder.newFolder(controller).getAbsolutePath();
String controllerStatFilePath = new File(controllerDirectory, "stat.gfs").getAbsolutePath();
setUpJmxManagerOnVm0ThenConnect(null);
Properties localProps = new Properties();
localProps.setProperty(NAME, controller);
localProps.setProperty(LOG_LEVEL, "error");
getSystem(localProps);
final GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
final DistributionConfig config = cache.getSystem().getConfig();
Host.getHost(0).getVM(1).invoke(new SerializableRunnable() {
public void run() {
Properties localProps = new Properties();
localProps.setProperty(NAME, member1);
getSystem(localProps);
Cache cache = getCache();
}
});
CommandStringBuilder csb = new CommandStringBuilder(CliStrings.ALTER_RUNTIME_CONFIG);
csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL, "info");
csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__FILE__SIZE__LIMIT, "50");
csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT, "32");
csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT, "49");
csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE, "2000");
csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE, controllerStatFilePath);
csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLING__ENABLED, "true");
csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT, "10");
CommandResult cmdResult = executeCommand(csb.getCommandString());
String resultString = commandResultToString(cmdResult);
getLogWriter().info("#SB Result\n");
getLogWriter().info(resultString);
assertEquals(true, cmdResult.getStatus().equals(Status.OK));
assertEquals(LogWriterImpl.INFO_LEVEL, config.getLogLevel());
assertEquals(50, config.getLogFileSizeLimit());
assertEquals(49, config.getArchiveFileSizeLimit());
assertEquals(32, config.getArchiveDiskSpaceLimit());
assertEquals(2000, config.getStatisticSampleRate());
assertEquals("stat.gfs", config.getStatisticArchiveFile().getName());
assertEquals(true, config.getStatisticSamplingEnabled());
assertEquals(10, config.getLogDiskSpaceLimit());
// Validate the changes in the vm1
Host.getHost(0).getVM(1).invoke(new SerializableRunnable() {
public void run() {
GemFireCacheImpl cacheVM1 = (GemFireCacheImpl) getCache();
DistributionConfig configVM1 = cacheVM1.getSystem().getConfig();
assertEquals(LogWriterImpl.INFO_LEVEL, configVM1.getLogLevel());
assertEquals(50, configVM1.getLogFileSizeLimit());
assertEquals(49, configVM1.getArchiveFileSizeLimit());
assertEquals(32, configVM1.getArchiveDiskSpaceLimit());
assertEquals(2000, configVM1.getStatisticSampleRate());
assertEquals("stat.gfs", configVM1.getStatisticArchiveFile().getName());
assertEquals(true, configVM1.getStatisticSamplingEnabled());
assertEquals(10, configVM1.getLogDiskSpaceLimit());
}
});
}
Aggregations