use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.
the class ConfigurationChangeListener method addOrRemoveJarFromFilesystem.
// when a new jar is added, if it does not exist in the current locator, download it from
// another locator.
// when a jar is removed, if it exists in the current locator, remove it.
private void addOrRemoveJarFromFilesystem(EntryEvent<String, Configuration> event) {
String group = event.getKey();
Configuration newConfig = (Configuration) event.getNewValue();
Configuration oldConfig = (Configuration) event.getOldValue();
Set<String> newJars = newConfig.getJarNames();
Set<String> oldJars = (oldConfig == null) ? new HashSet<>() : oldConfig.getJarNames();
Set<String> jarsAdded = new HashSet<>(newJars);
Set<String> jarsRemoved = new HashSet<>(oldJars);
jarsAdded.removeAll(oldJars);
jarsRemoved.removeAll(newJars);
if (!jarsAdded.isEmpty() && !jarsRemoved.isEmpty()) {
throw new IllegalStateException("We don't expect to have jars both added and removed in one event");
}
for (String jarAdded : jarsAdded) {
if (!jarExistsInFilesystem(group, jarAdded)) {
try {
sharedConfig.downloadJarFromOtherLocators(group, jarAdded);
} catch (Exception e) {
logger.error("Unable to add jar: " + jarAdded, e);
}
}
}
for (String jarRemoved : jarsRemoved) {
File jar = sharedConfig.getPathToJarOnThisLocator(group, jarRemoved).toFile();
if (jar.exists()) {
try {
FileUtils.forceDelete(jar);
} catch (IOException e) {
logger.error("Exception occurred while attempting to delete a jar from the filesystem: {}", jarRemoved, e);
}
}
}
}
use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.
the class ClusterConfigurationService method getAllJarsFromThisLocator.
// used when creating cluster config response
public Map<String, byte[]> getAllJarsFromThisLocator(Set<String> groups) throws IOException {
Map<String, byte[]> jarNamesToJarBytes = new HashMap<>();
for (String group : groups) {
Configuration groupConfig = getConfiguration(group);
if (groupConfig == null) {
break;
}
Set<String> jars = groupConfig.getJarNames();
for (String jar : jars) {
byte[] jarBytes = getJarBytesFromThisLocator(group, jar);
jarNamesToJarBytes.put(jar, jarBytes);
}
}
return jarNamesToJarBytes;
}
use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.
the class ClusterConfigurationService method modifyXmlAndProperties.
/**
* we don't need to trigger the change listener for this modification, so it's ok to operate on
* the original configuration object
*/
public void modifyXmlAndProperties(Properties properties, XmlEntity xmlEntity, String[] groups) {
lockSharedConfiguration();
try {
if (groups == null) {
groups = new String[] { ClusterConfigurationService.CLUSTER_CONFIG };
}
Region<String, Configuration> configRegion = getConfigurationRegion();
for (String group : groups) {
Configuration configuration = configRegion.get(group);
if (configuration == null) {
configuration = new Configuration(group);
}
if (xmlEntity != null) {
String xmlContent = configuration.getCacheXmlContent();
if (xmlContent == null || xmlContent.isEmpty()) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
CacheXmlGenerator.generateDefault(pw);
xmlContent = sw.toString();
}
try {
Document doc = XmlUtils.createAndUpgradeDocumentFromXml(xmlContent);
// Modify the cache attributes
XmlUtils.modifyRootAttributes(doc, xmlEntity);
// Change the xml content of the configuration and put it the config region
configuration.setCacheXmlContent(XmlUtils.prettyXml(doc));
} catch (Exception e) {
logger.error("error updating cluster configuration for group {}", group, e);
}
}
if (properties != null) {
configuration.getGemfireProperties().putAll(properties);
}
configRegion.put(group, configuration);
}
} finally {
unlockSharedConfiguration();
}
}
use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.
the class ClusterConfigurationService method loadSharedConfigurationFromDisk.
/**
* Loads the internal region with the configuration in the configDirPath
*/
public void loadSharedConfigurationFromDisk() throws SAXException, ParserConfigurationException, TransformerException, IOException {
lockSharedConfiguration();
File[] groupNames = new File(this.configDirPath).listFiles((FileFilter) DirectoryFileFilter.INSTANCE);
try {
Map<String, Configuration> sharedConfiguration = new HashMap<>();
for (File groupName : groupNames) {
Configuration configuration = readConfiguration(groupName);
sharedConfiguration.put(groupName.getName(), configuration);
}
Region<String, Configuration> clusterRegion = getConfigurationRegion();
clusterRegion.clear();
clusterRegion.putAll(sharedConfiguration);
// Overwrite the security settings using the locator's properties, ignoring whatever
// in the import
persistSecuritySettings(clusterRegion);
} finally {
unlockSharedConfiguration();
}
}
use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.
the class ClusterConfigurationService method getConfigurationRegion.
/**
* Gets the region containing the shared configuration data. The region is created , if it does
* not exist already. Note : this could block if this locator contains stale persistent
* configuration data.
*
* @return {@link Region} ConfigurationRegion, this should never be null
*/
private Region<String, Configuration> getConfigurationRegion() {
Region<String, Configuration> configRegion = this.cache.getRegion(CONFIG_REGION_NAME);
try {
if (configRegion == null) {
File diskDir = new File(this.configDiskDirPath);
if (!diskDir.exists()) {
if (!diskDir.mkdirs()) {
// TODO: throw caught by containing try statement
throw new IOException("Cannot create directory at " + this.configDiskDirPath);
}
}
File[] diskDirs = { diskDir };
this.cache.createDiskStoreFactory().setDiskDirs(diskDirs).setAutoCompact(true).setMaxOplogSize(10).create(CLUSTER_CONFIG_DISK_STORE_NAME);
AttributesFactory<String, Configuration> regionAttrsFactory = new AttributesFactory<>();
regionAttrsFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
regionAttrsFactory.setCacheListener(new ConfigurationChangeListener(this));
regionAttrsFactory.setDiskStoreName(CLUSTER_CONFIG_DISK_STORE_NAME);
regionAttrsFactory.setScope(Scope.DISTRIBUTED_ACK);
InternalRegionArguments internalArgs = new InternalRegionArguments();
internalArgs.setIsUsedForMetaRegion(true);
internalArgs.setMetaRegionWithTransactions(false);
configRegion = this.cache.createVMRegion(CONFIG_REGION_NAME, regionAttrsFactory.create(), internalArgs);
}
} catch (CancelException e) {
if (configRegion == null) {
this.status.set(SharedConfigurationStatus.STOPPED);
}
// CONFIG: don't rethrow as Exception, keep it a subclass of CancelException
throw e;
} catch (Exception e) {
if (configRegion == null) {
this.status.set(SharedConfigurationStatus.STOPPED);
}
throw new RuntimeException("Error occurred while initializing cluster configuration", e);
}
return configRegion;
}
Aggregations