use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.
the class ClusterConfigurationService method initSharedConfiguration.
/**
* Creates the shared configuration service
*
* @param loadSharedConfigFromDir when set to true, loads the configuration from the share_config
* directory
*/
void initSharedConfiguration(boolean loadSharedConfigFromDir) throws CacheLoaderException, TimeoutException, IllegalStateException, IOException, TransformerException, SAXException, ParserConfigurationException {
this.status.set(SharedConfigurationStatus.STARTED);
Region<String, Configuration> configRegion = this.getConfigurationRegion();
lockSharedConfiguration();
try {
if (loadSharedConfigFromDir) {
logger.info("Reading cluster configuration from '{}' directory", ClusterConfigurationService.CLUSTER_CONFIG_ARTIFACTS_DIR_NAME);
loadSharedConfigurationFromDisk();
} else {
persistSecuritySettings(configRegion);
// if it doesn't exist yet
for (Entry<String, Configuration> stringConfigurationEntry : configRegion.entrySet()) {
Configuration config = stringConfigurationEntry.getValue();
for (String jar : config.getJarNames()) {
if (!getPathToJarOnThisLocator(stringConfigurationEntry.getKey(), jar).toFile().exists()) {
downloadJarFromOtherLocators(stringConfigurationEntry.getKey(), jar);
}
}
}
}
} finally {
unlockSharedConfiguration();
}
this.status.set(SharedConfigurationStatus.RUNNING);
}
use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.
the class ClusterConfigurationService method destroySharedConfiguration.
/**
* For tests only. TODO: clean this up and remove from production code
* <p>
* Throws {@code AssertionError} wrapping any exception thrown by operation.
*/
public void destroySharedConfiguration() {
try {
Region<String, Configuration> configRegion = getConfigurationRegion();
if (configRegion != null) {
configRegion.destroyRegion();
}
DiskStore configDiskStore = this.cache.findDiskStore(CLUSTER_CONFIG_ARTIFACTS_DIR_NAME);
if (configDiskStore != null) {
configDiskStore.destroy();
File file = new File(this.configDiskDirPath);
FileUtils.deleteDirectory(file);
}
FileUtils.deleteDirectory(new File(this.configDirPath));
} catch (Exception exception) {
throw new AssertionError(exception);
}
}
use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.
the class ClusterConfigurationLoader method applyClusterPropertiesConfiguration.
/***
* Apply the gemfire properties cluster configuration on this member
*
* @param cache Cache created for this member
* @param response {@link ConfigurationResponse} containing the requested {@link Configuration}
* @param config this member's config
*/
public static void applyClusterPropertiesConfiguration(Cache cache, ConfigurationResponse response, DistributionConfig config) {
if (response == null || response.getRequestedConfiguration().isEmpty()) {
return;
}
List<String> groups = getGroups(config);
Map<String, Configuration> requestedConfiguration = response.getRequestedConfiguration();
final Properties runtimeProps = new Properties();
// apply the cluster config first
Configuration clusterConfiguration = requestedConfiguration.get(ClusterConfigurationService.CLUSTER_CONFIG);
if (clusterConfiguration != null) {
runtimeProps.putAll(clusterConfiguration.getGemfireProperties());
}
// then apply the group config
for (String group : groups) {
Configuration groupConfiguration = requestedConfiguration.get(group);
if (groupConfiguration != null) {
runtimeProps.putAll(groupConfiguration.getGemfireProperties());
}
}
Set<Object> attNames = runtimeProps.keySet();
for (Object attNameObj : attNames) {
String attName = (String) attNameObj;
String attValue = runtimeProps.getProperty(attName);
try {
config.setAttribute(attName, attValue, ConfigSource.runtime());
} catch (IllegalArgumentException e) {
logger.info(e.getMessage());
} catch (UnmodifiableException e) {
logger.info(e.getMessage());
}
}
}
use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.
the class ExportImportClusterConfigurationCommands method importSharedConfig.
@CliCommand(value = { CliStrings.IMPORT_SHARED_CONFIG }, help = CliStrings.IMPORT_SHARED_CONFIG__HELP)
@CliMetaData(interceptor = "org.apache.geode.management.internal.cli.commands.ExportImportClusterConfigurationCommands$ImportInterceptor", relatedTopic = { CliStrings.TOPIC_GEODE_CONFIG })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.MANAGE)
@SuppressWarnings("unchecked")
public Result importSharedConfig(@CliOption(key = { CliStrings.IMPORT_SHARED_CONFIG__ZIP }, mandatory = true, help = CliStrings.IMPORT_SHARED_CONFIG__ZIP__HELP) String zip) {
InternalLocator locator = InternalLocator.getLocator();
if (!locator.isSharedConfigurationRunning()) {
ErrorResultData errorData = ResultBuilder.createErrorResultData();
errorData.addLine(CliStrings.SHARED_CONFIGURATION_NOT_STARTED);
return ResultBuilder.buildResult(errorData);
}
InternalCache cache = getCache();
Set<DistributedMember> servers = CliUtil.getAllNormalMembers(cache);
Set<String> regionsWithData = servers.stream().map(this::getRegionNamesOnServer).flatMap(Collection::stream).collect(toSet());
if (!regionsWithData.isEmpty()) {
return ResultBuilder.createGemFireErrorResult("Cannot import cluster configuration with existing regions: " + regionsWithData.stream().collect(joining(",")));
}
byte[][] shellBytesData = CommandExecutionContext.getBytesFromShell();
String zipFileName = CliUtil.bytesToNames(shellBytesData)[0];
byte[] zipBytes = CliUtil.bytesToData(shellBytesData)[0];
Result result;
InfoResultData infoData = ResultBuilder.createInfoResultData();
File zipFile = new File(zipFileName);
try {
ClusterConfigurationService sc = locator.getSharedConfiguration();
// backup the old config
for (Configuration config : sc.getEntireConfiguration().values()) {
sc.writeConfigToFile(config);
}
sc.renameExistingSharedConfigDirectory();
FileUtils.writeByteArrayToFile(zipFile, zipBytes);
ZipUtils.unzip(zipFileName, sc.getSharedConfigurationDirPath());
// load it from the disk
sc.loadSharedConfigurationFromDisk();
infoData.addLine(CliStrings.IMPORT_SHARED_CONFIG__SUCCESS__MSG);
} catch (Exception e) {
ErrorResultData errorData = ResultBuilder.createErrorResultData();
errorData.addLine("Import failed");
logSevere(e);
result = ResultBuilder.buildResult(errorData);
// if import is unsuccessful, don't need to bounce the server.
return result;
} finally {
FileUtils.deleteQuietly(zipFile);
}
// Bounce the cache of each member
Set<CliFunctionResult> functionResults = servers.stream().map(this::reCreateCache).collect(toSet());
for (CliFunctionResult functionResult : functionResults) {
if (functionResult.isSuccessful()) {
infoData.addLine("Successfully applied the imported cluster configuration on " + functionResult.getMemberIdOrName());
} else {
infoData.addLine("Failed to apply the imported cluster configuration on " + functionResult.getMemberIdOrName() + " due to " + functionResult.getMessage());
}
}
result = ResultBuilder.buildResult(infoData);
return result;
}
use of org.apache.geode.management.internal.configuration.domain.Configuration 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;
}
Aggregations