use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.
the class ExportLogsFunction method createOrGetExistingExportLogsRegion.
public static Region createOrGetExistingExportLogsRegion(boolean isInitiatingMember, InternalCache cache) throws IOException, ClassNotFoundException {
Region exportLogsRegion = cache.getRegion(EXPORT_LOGS_REGION);
if (exportLogsRegion == null) {
AttributesFactory<String, Configuration> regionAttrsFactory = new AttributesFactory<>();
regionAttrsFactory.setDataPolicy(DataPolicy.EMPTY);
regionAttrsFactory.setScope(Scope.DISTRIBUTED_ACK);
if (isInitiatingMember) {
regionAttrsFactory.setCacheWriter(new ExportLogsCacheWriter());
}
InternalRegionArguments internalArgs = new InternalRegionArguments();
internalArgs.setIsUsedForMetaRegion(true);
exportLogsRegion = cache.createVMRegion(EXPORT_LOGS_REGION, regionAttrsFactory.create(), internalArgs);
}
return exportLogsRegion;
}
use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.
the class ClusterConfigurationLoader method applyClusterXmlConfiguration.
/***
* Apply the cache-xml 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 applyClusterXmlConfiguration(Cache cache, ConfigurationResponse response, DistributionConfig config) {
if (response == null || response.getRequestedConfiguration().isEmpty()) {
return;
}
List<String> groups = getGroups(config);
Map<String, Configuration> requestedConfiguration = response.getRequestedConfiguration();
List<String> cacheXmlContentList = new LinkedList<String>();
// apply the cluster config first
Configuration clusterConfiguration = requestedConfiguration.get(ClusterConfigurationService.CLUSTER_CONFIG);
if (clusterConfiguration != null) {
String cacheXmlContent = clusterConfiguration.getCacheXmlContent();
if (StringUtils.isNotBlank(cacheXmlContent)) {
cacheXmlContentList.add(cacheXmlContent);
}
}
// then apply the groups config
for (String group : groups) {
Configuration groupConfiguration = requestedConfiguration.get(group);
if (groupConfiguration != null) {
String cacheXmlContent = groupConfiguration.getCacheXmlContent();
if (StringUtils.isNotBlank(cacheXmlContent)) {
cacheXmlContentList.add(cacheXmlContent);
}
}
}
// apply the requested cache xml
for (String cacheXmlContent : cacheXmlContentList) {
InputStream is = new ByteArrayInputStream(cacheXmlContent.getBytes());
try {
cache.loadCacheXml(is);
} finally {
try {
is.close();
} catch (IOException e) {
}
}
}
}
use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.
the class ClusterConfigurationLoader method deployJarsReceivedFromClusterConfiguration.
/**
* Deploys the jars received from shared configuration, it undeploys any other jars that were not
* part of shared configuration
*
* @param cache Cache of this member
* @param response {@link ConfigurationResponse} received from the locators
*/
public static void deployJarsReceivedFromClusterConfiguration(Cache cache, ConfigurationResponse response) throws IOException, ClassNotFoundException {
logger.info("Requesting cluster configuration");
if (response == null) {
return;
}
String[] jarFileNames = response.getJarNames();
byte[][] jarBytes = response.getJars();
logger.info("Got response with jars: {}", Stream.of(jarFileNames).collect(joining(",")));
if (jarFileNames != null && jarBytes != null) {
JarDeployer jarDeployer = ClassPathLoader.getLatest().getJarDeployer();
jarDeployer.suspendAll();
try {
List<String> extraJarsOnServer = jarDeployer.findDeployedJars().stream().map(DeployedJar::getJarName).filter(jarName -> !ArrayUtils.contains(jarFileNames, jarName)).collect(toList());
for (String extraJar : extraJarsOnServer) {
logger.info("Removing jar not present in cluster configuration: {}", extraJar);
jarDeployer.deleteAllVersionsOfJar(extraJar);
}
List<DeployedJar> deployedJars = jarDeployer.deploy(jarFileNames, jarBytes);
deployedJars.stream().filter(Objects::nonNull).forEach((jar) -> logger.info("Deployed: {}", jar.getFile().getAbsolutePath()));
} finally {
jarDeployer.resumeAll();
}
}
}
use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.
the class GemFireCacheImpl method requestSharedConfiguration.
/**
* Request the shared configuration from the locator(s) which have the Cluster config service
* running
*/
private ConfigurationResponse requestSharedConfiguration() {
final DistributionConfig config = this.system.getConfig();
if (!(this.dm instanceof DistributionManager)) {
return null;
}
// do nothing if this vm is/has locator or this is a client
if (this.dm.getDMType() == DistributionManager.LOCATOR_DM_TYPE || this.isClient || Locator.getLocator() != null) {
return null;
}
// can't simply return null if server is not using shared configuration, since we need to find
// out
// if the locator is running in secure mode or not, if yes, then we need to throw an exception
// if server is not using cluster config
Map<InternalDistributedMember, Collection<String>> scl = getDistributionManager().getAllHostedLocatorsWithSharedConfiguration();
// then do not make requests to the locators
if (scl.isEmpty()) {
logger.info(LocalizedMessage.create(LocalizedStrings.GemFireCache_NO_LOCATORS_FOUND_WITH_SHARED_CONFIGURATION));
return null;
}
List<String> locatorConnectionStrings = getSharedConfigLocatorConnectionStringList();
try {
ConfigurationResponse response = ClusterConfigurationLoader.requestConfigurationFromLocators(this.system.getConfig(), locatorConnectionStrings);
// log the configuration received from the locator
logger.info(LocalizedMessage.create(LocalizedStrings.GemFireCache_RECEIVED_SHARED_CONFIGURATION_FROM_LOCATORS));
logger.info(response.describeConfig());
Configuration clusterConfig = response.getRequestedConfiguration().get(ClusterConfigurationService.CLUSTER_CONFIG);
Properties clusterSecProperties = clusterConfig == null ? new Properties() : clusterConfig.getGemfireProperties();
// If not using shared configuration, return null or throw an exception is locator is secured
if (!config.getUseSharedConfiguration()) {
if (clusterSecProperties.containsKey(ConfigurationProperties.SECURITY_MANAGER)) {
throw new GemFireConfigException(LocalizedStrings.GEMFIRE_CACHE_SECURITY_MISCONFIGURATION_2.toLocalizedString());
} else {
logger.info(LocalizedMessage.create(LocalizedStrings.GemFireCache_NOT_USING_SHARED_CONFIGURATION));
return null;
}
}
Properties serverSecProperties = config.getSecurityProps();
// check for possible mis-configuration
if (isMisConfigured(clusterSecProperties, serverSecProperties, ConfigurationProperties.SECURITY_MANAGER) || isMisConfigured(clusterSecProperties, serverSecProperties, ConfigurationProperties.SECURITY_POST_PROCESSOR)) {
throw new GemFireConfigException(LocalizedStrings.GEMFIRE_CACHE_SECURITY_MISCONFIGURATION.toLocalizedString());
}
return response;
} catch (ClusterConfigurationNotAvailableException e) {
throw new GemFireConfigException(LocalizedStrings.GemFireCache_SHARED_CONFIGURATION_NOT_AVAILABLE.toLocalizedString(), e);
} catch (UnknownHostException e) {
throw new GemFireConfigException(e.getLocalizedMessage(), e);
}
}
use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.
the class ConfigurationResponse method describeConfig.
public String describeConfig() {
StringBuffer sb = new StringBuffer();
if (requestedConfiguration.isEmpty()) {
sb.append("Received an empty shared configuration");
} else {
Set<Entry<String, Configuration>> entries = requestedConfiguration.entrySet();
Iterator<Entry<String, Configuration>> iter = entries.iterator();
while (iter.hasNext()) {
Entry<String, Configuration> entry = iter.next();
String configType = entry.getKey();
Configuration config = entry.getValue();
if (config != null) {
sb.append("\n***************************************************************");
sb.append("\nConfiguration for '" + configType + "'");
sb.append("\n\nJar files to deployed");
Set<String> jarNames = config.getJarNames();
Iterator<String> jarIter = jarNames.iterator();
int jarCounter = 0;
while (jarIter.hasNext()) {
sb.append("\n" + ++jarCounter + "." + jarIter.next());
}
try {
String cacheXmlContent = config.getCacheXmlContent();
if (StringUtils.isNotBlank(cacheXmlContent)) {
sb.append("\n" + XmlUtils.prettyXml(cacheXmlContent));
}
} catch (IOException | TransformerFactoryConfigurationError | TransformerException | SAXException | ParserConfigurationException e) {
throw new InternalGemFireError(e);
}
}
}
}
return sb.toString();
}
Aggregations