use of org.apache.geode.distributed.internal.ClusterConfigurationService in project geode by apache.
the class ExportImportClusterConfigurationCommands method exportSharedConfig.
@CliCommand(value = { CliStrings.EXPORT_SHARED_CONFIG }, help = CliStrings.EXPORT_SHARED_CONFIG__HELP)
@CliMetaData(interceptor = "org.apache.geode.management.internal.cli.commands.ExportImportClusterConfigurationCommands$ExportInterceptor", relatedTopic = { CliStrings.TOPIC_GEODE_CONFIG })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result exportSharedConfig(@CliOption(key = { CliStrings.EXPORT_SHARED_CONFIG__FILE }, mandatory = true, help = CliStrings.EXPORT_SHARED_CONFIG__FILE__HELP) String zipFileName) {
InternalLocator locator = InternalLocator.getLocator();
if (!locator.isSharedConfigurationRunning()) {
return ResultBuilder.createGemFireErrorResult(CliStrings.SHARED_CONFIGURATION_NOT_STARTED);
}
Path tempDir;
try {
tempDir = Files.createTempDirectory("clusterConfig");
} catch (IOException e) {
logSevere(e);
ErrorResultData errorData = ResultBuilder.createErrorResultData().addLine("Unable to create temp directory");
return ResultBuilder.buildResult(errorData);
}
File zipFile = tempDir.resolve("exportedCC.zip").toFile();
ClusterConfigurationService sc = locator.getSharedConfiguration();
Result result;
try {
for (Configuration config : sc.getEntireConfiguration().values()) {
sc.writeConfigToFile(config);
}
ZipUtils.zipDirectory(sc.getSharedConfigurationDirPath(), zipFile.getCanonicalPath());
InfoResultData infoData = ResultBuilder.createInfoResultData();
byte[] byteData = FileUtils.readFileToByteArray(zipFile);
infoData.addAsFile(zipFileName, byteData, InfoResultData.FILE_TYPE_BINARY, CliStrings.EXPORT_SHARED_CONFIG__DOWNLOAD__MSG, false);
result = ResultBuilder.buildResult(infoData);
} catch (Exception e) {
ErrorResultData errorData = ResultBuilder.createErrorResultData();
errorData.addLine("Export failed");
logSevere(e);
result = ResultBuilder.buildResult(errorData);
} finally {
zipFile.delete();
}
return result;
}
use of org.apache.geode.distributed.internal.ClusterConfigurationService in project geode by apache.
the class GfshCommand method persistClusterConfiguration.
default default void persistClusterConfiguration(Result result, Runnable runnable) {
if (result == null) {
throw new IllegalArgumentException("Result should not be null");
}
ClusterConfigurationService sc = getSharedConfiguration();
if (sc == null) {
result.setCommandPersisted(false);
} else {
runnable.run();
result.setCommandPersisted(true);
}
}
use of org.apache.geode.distributed.internal.ClusterConfigurationService in project geode by apache.
the class IndexCommandsDUnitTest method testCreateDestroyUpdatesSharedConfig.
/**
* Asserts that creating and destroying indexes correctly updates the shared configuration.
*/
// GEODE-1954
@Category(FlakyTest.class)
@Test
public void testCreateDestroyUpdatesSharedConfig() {
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 = "testIndexSharedConfigRegion";
final String groupName = "testIndexSharedConfigGroup";
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));
// Start the Locator and wait for shared configuration to be available
final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
final File locatorLogFile = new File("locator-" + locatorPort + ".log");
try {
final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort, locatorLogFile, null, locatorProps);
WaitCriterion wc = new WaitCriterion() {
@Override
public boolean done() {
return locator.isSharedConfigurationRunning();
}
@Override
public String description() {
return "Waiting for shared configuration to be started";
}
};
Wait.waitForCriterion(wc, 5000, 500, true);
} catch (IOException ioex) {
fail("Unable to create a locator with a shared configuration");
}
}
});
// Start the default manager
connect(jmxHost, jmxPort, httpPort, getDefaultShell());
// Create a cache in VM 1
VM vm = Host.getHost(0).getVM(1);
vm.invoke(new SerializableRunnable() {
@Override
public void run() {
Properties localProps = new Properties();
localProps.setProperty(MCAST_PORT, "0");
localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
localProps.setProperty(GROUPS, groupName);
getSystem(localProps);
assertNotNull(getCache());
Region parReg = createParReg(regionName, getCache(), String.class, Stock.class);
parReg.put("VMW", new Stock("VMW", 98));
}
});
// Test creating the index
CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_INDEX);
commandStringBuilder.addOption(CliStrings.CREATE_INDEX__EXPRESSION, "key");
commandStringBuilder.addOption(CliStrings.CREATE_INDEX__NAME, indexName);
commandStringBuilder.addOption(CliStrings.CREATE_INDEX__GROUP, groupName);
commandStringBuilder.addOption(CliStrings.CREATE_INDEX__REGION, "\"/" + regionName + " p\"");
CommandResult cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure the index exists in the shared config
Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
String xmlFromConfig;
try {
xmlFromConfig = sharedConfig.getConfiguration(groupName).getCacheXmlContent();
assertTrue(xmlFromConfig.contains(indexName));
} catch (Exception e) {
Assert.fail("Error occurred in cluster configuration service", e);
}
}
});
// Restart a member and make sure he gets the shared configuration
vm = Host.getHost(0).getVM(1);
vm.invoke(new SerializableRunnable() {
@Override
public void run() {
getCache().close();
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 cache = getCache();
assertNotNull(cache);
Region region = cache.getRegion(regionName);
assertNotNull(region);
Index index = cache.getQueryService().getIndex(region, indexName);
assertNotNull(index);
}
});
// Test destroying the index
commandStringBuilder = new CommandStringBuilder(CliStrings.DESTROY_INDEX);
commandStringBuilder.addOption(CliStrings.DESTROY_INDEX__NAME, indexName);
commandStringBuilder.addOption(CliStrings.DESTROY_INDEX__GROUP, groupName);
commandStringBuilder.addOption(CliStrings.DESTROY_INDEX__REGION, "/" + regionName);
cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure the index was removed from the shared config
Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
String xmlFromConfig;
try {
xmlFromConfig = sharedConfig.getConfiguration(groupName).getCacheXmlContent();
assertFalse(xmlFromConfig.contains(indexName));
} catch (Exception e) {
Assert.fail("Error occurred in cluster configuration service", e);
}
}
});
// Restart the data member cache to make sure that the index is destroyed.
vm = Host.getHost(0).getVM(1);
vm.invoke(new SerializableRunnable() {
@Override
public void run() {
getCache().close();
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 cache = getCache();
assertNotNull(cache);
Region region = cache.getRegion(regionName);
assertNotNull(region);
Index index = cache.getQueryService().getIndex(region, indexName);
assertNull(index);
}
});
}
use of org.apache.geode.distributed.internal.ClusterConfigurationService in project geode by apache.
the class CreateAlterDestroyRegionCommandsDUnitTest method testCreateAlterDestroyUpdatesSharedConfig.
/**
* Asserts that creating, altering and destroying regions correctly updates the shared
* configuration.
*/
// GEODE-2009
@Category(FlakyTest.class)
@Test
public void testCreateAlterDestroyUpdatesSharedConfig() throws Exception {
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());
ManagementService managementService = ManagementService.getExistingManagementService(GemFireCacheImpl.getInstance());
assertNotNull(managementService);
assertTrue(managementService.isManager());
assertTrue(checkIfCommandsAreLoadedOrNot());
} 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 in cluster configuration service", e);
}
});
// Restart the data vm to make sure the changes are in place
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);
assertNotNull(region);
});
// Test altering the region
commandStringBuilder = new CommandStringBuilder(CliStrings.ALTER_REGION);
commandStringBuilder.addOption(CliStrings.ALTER_REGION__REGION, regionName);
commandStringBuilder.addOption(CliStrings.ALTER_REGION__GROUP, groupName);
commandStringBuilder.addOption(CliStrings.ALTER_REGION__ENTRYEXPIRATIONTIMETOLIVE, "45635");
commandStringBuilder.addOption(CliStrings.ALTER_REGION__ENTRYEXPIRATIONTTLACTION, "DESTROY");
cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure the region was altered in the shared config
Host.getHost(0).getVM(0).invoke(() -> {
ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
try {
assertTrue(sharedConfig.getConfiguration(groupName).getCacheXmlContent().contains("45635"));
} catch (Exception e) {
fail("Error in cluster configuration service");
}
});
// Restart the data vm to make sure the changes are in place
vm = Host.getHost(0).getVM(1);
vm.invoke(new SerializableCallable() {
@Override
public Object call() {
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);
assertNotNull(region);
return null;
}
});
}
use of org.apache.geode.distributed.internal.ClusterConfigurationService in project geode by apache.
the class ConfigCommandsDUnitTest method testAlterUpdatesSharedConfig.
/**
* Asserts that altering the runtime config correctly updates the shared configuration.
*/
@Test
public void testAlterUpdatesSharedConfig() throws Exception {
final String groupName = getName();
final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
jmxPort = ports[0];
httpPort = ports[1];
try {
jmxHost = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException ignore) {
jmxHost = "localhost";
}
// Start the Locator and wait for shared configuration to be available
final int locatorPort = getRandomAvailablePort(SOCKET);
final String locatorDirectory = this.temporaryFolder.newFolder("Locator").getAbsolutePath();
final Properties locatorProps = new Properties();
locatorProps.setProperty(NAME, "Locator");
locatorProps.setProperty(MCAST_PORT, "0");
locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
locatorProps.setProperty(CLUSTER_CONFIGURATION_DIR, locatorDirectory);
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(new SerializableRunnable() {
@Override
public void run() {
final File locatorLogFile = new File(locatorDirectory, "locator-" + locatorPort + ".log");
try {
final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort, locatorLogFile, null, locatorProps);
WaitCriterion wc = new WaitCriterion() {
@Override
public boolean done() {
return locator.isSharedConfigurationRunning();
}
@Override
public String description() {
return "Waiting for shared configuration to be started";
}
};
waitForCriterion(wc, 5000, 500, true);
} catch (IOException e) {
fail("Unable to create a locator with a shared configuration", e);
}
}
});
connect(jmxHost, jmxPort, httpPort, getDefaultShell());
// Create a cache in VM 1
VM vm = Host.getHost(0).getVM(1);
vm.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
Properties localProps = new Properties();
localProps.setProperty(MCAST_PORT, "0");
localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
localProps.setProperty(LOG_LEVEL, "error");
localProps.setProperty(GROUPS, groupName);
getSystem(localProps);
assertNotNull(getCache());
assertEquals("error", basicGetSystem().getConfig().getAttribute(LOG_LEVEL));
return null;
}
});
// Test altering the runtime config
CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.ALTER_RUNTIME_CONFIG);
commandStringBuilder.addOption(CliStrings.ALTER_RUNTIME_CONFIG__GROUP, groupName);
commandStringBuilder.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL, "fine");
CommandResult cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure the shared config was updated
Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
Properties gemfireProperties = null;
try {
gemfireProperties = sharedConfig.getConfiguration(groupName).getGemfireProperties();
} catch (Exception e) {
fail("Error occurred in cluster configuration service", e);
}
assertEquals("fine", gemfireProperties.get(LOG_LEVEL));
}
});
}
Aggregations