use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.
the class ClusterConfigurationService method persistSecuritySettings.
private void persistSecuritySettings(final Region<String, Configuration> configRegion) {
Properties securityProps = this.cache.getDistributedSystem().getSecurityProperties();
Configuration clusterPropertiesConfig = configRegion.get(ClusterConfigurationService.CLUSTER_CONFIG);
if (clusterPropertiesConfig == null) {
clusterPropertiesConfig = new Configuration(ClusterConfigurationService.CLUSTER_CONFIG);
configRegion.put(ClusterConfigurationService.CLUSTER_CONFIG, clusterPropertiesConfig);
}
// put security-manager and security-post-processor in the cluster config
Properties clusterProperties = clusterPropertiesConfig.getGemfireProperties();
if (securityProps.containsKey(SECURITY_MANAGER)) {
clusterProperties.setProperty(SECURITY_MANAGER, securityProps.getProperty(SECURITY_MANAGER));
}
if (securityProps.containsKey(SECURITY_POST_PROCESSOR)) {
clusterProperties.setProperty(SECURITY_POST_PROCESSOR, securityProps.getProperty(SECURITY_POST_PROCESSOR));
}
}
use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.
the class ClusterConfigurationService method deleteXmlEntity.
/**
* Deletes the xml entity from the shared configuration.
*/
public void deleteXmlEntity(final XmlEntity xmlEntity, String[] groups) {
lockSharedConfiguration();
try {
Region<String, Configuration> configRegion = getConfigurationRegion();
// No group is specified, so delete in every single group if it exists.
if (groups == null) {
Set<String> groupSet = configRegion.keySet();
groups = groupSet.toArray(new String[groupSet.size()]);
}
for (String group : groups) {
Configuration configuration = configRegion.get(group);
if (configuration != null) {
String xmlContent = configuration.getCacheXmlContent();
try {
if (xmlContent != null && !xmlContent.isEmpty()) {
Document doc = XmlUtils.createAndUpgradeDocumentFromXml(xmlContent);
XmlUtils.deleteNode(doc, xmlEntity);
configuration.setCacheXmlContent(XmlUtils.prettyXml(doc));
configRegion.put(group, configuration);
}
} catch (Exception e) {
logger.error("error updating cluster configuration for group {}", group, e);
}
}
}
} finally {
unlockSharedConfiguration();
}
}
use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.
the class ClusterConfigurationService method getJarBytesFromThisLocator.
/**
* read the jar bytes in the file system
* <p>
* used when creating cluster config response and used when uploading the jars to another locator
*/
public byte[] getJarBytesFromThisLocator(String group, String jarName) throws IOException {
Configuration configuration = getConfiguration(group);
File jar = getPathToJarOnThisLocator(group, jarName).toFile();
if (configuration == null || !configuration.getJarNames().contains(jarName) || !jar.exists()) {
return null;
}
return FileUtils.readFileToByteArray(jar);
}
use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.
the class ClusterConfigurationServiceDUnitTest method testSharedConfigurationService.
@Test
public void testSharedConfigurationService() throws Exception {
// Start the Locator and wait for shared configuration to be available
final String testGroup = "G1";
final String clusterLogLevel = "error";
final String groupLogLevel = "fine";
final String testName = getName();
final VM locator1Vm = getHost(0).getVM(1);
final VM dataMemberVm = getHost(0).getVM(2);
final VM locator2Vm = getHost(0).getVM(3);
final int[] ports = getRandomAvailableTCPPorts(3);
final int locator1Port = ports[0];
locator1Vm.invoke(() -> {
final File locatorLogFile = new File(testName + "-locator-" + locator1Port + ".log");
final Properties locatorProps = new Properties();
locatorProps.setProperty(NAME, "Locator1");
locatorProps.setProperty(MCAST_PORT, "0");
locatorProps.setProperty(LOG_LEVEL, "info");
locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
try {
final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator1Port, 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, TIMEOUT, INTERVAL, true);
} catch (IOException e) {
fail("Unable to create a locator with a shared configuration", e);
}
});
XmlEntity xmlEntity = dataMemberVm.invoke(() -> {
Properties localProps = new Properties();
localProps.setProperty(MCAST_PORT, "0");
localProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
localProps.setProperty(GROUPS, testGroup);
getSystem(localProps);
Cache cache = getCache();
assertNotNull(cache);
DiskStoreFactory dsFactory = cache.createDiskStoreFactory();
File dsDir = new File("dsDir");
if (!dsDir.exists()) {
dsDir.mkdir();
}
dsFactory.setDiskDirs(new File[] { dsDir });
dsFactory.create(DISKSTORENAME);
RegionFactory regionFactory = getCache().createRegionFactory(RegionShortcut.REPLICATE);
regionFactory.create(REGION1);
return new XmlEntity(CacheXml.REGION, "name", REGION1);
});
locator1Vm.invoke(() -> {
ClusterConfigurationService sc = InternalLocator.getLocator().getSharedConfiguration();
sc.addXmlEntity(xmlEntity, new String[] { testGroup });
// Modify property and cache attributes
Properties clusterProperties = new Properties();
clusterProperties.setProperty(LOG_LEVEL, clusterLogLevel);
XmlEntity cacheEntity = XmlEntity.builder().withType(CacheXml.CACHE).build();
Map<String, String> cacheAttributes = new HashMap<String, String>();
cacheAttributes.put(CacheXml.COPY_ON_READ, "true");
sc.modifyXmlAndProperties(clusterProperties, cacheEntity, null);
clusterProperties.setProperty(LOG_LEVEL, groupLogLevel);
sc.modifyXmlAndProperties(clusterProperties, cacheEntity, new String[] { testGroup });
// Add a jar
byte[][] jarBytes = new byte[1][];
jarBytes[0] = "Hello".getBytes();
assertTrue(sc.addJarsToThisLocator(new String[] { "foo.jar" }, jarBytes, null));
// Add a jar for the group
jarBytes = new byte[1][];
jarBytes[0] = "Hello".getBytes();
assertTrue(sc.addJarsToThisLocator(new String[] { "bar.jar" }, jarBytes, new String[] { testGroup }));
});
final int locator2Port = ports[1];
// Create another locator in VM2
locator2Vm.invoke(() -> {
final File locatorLogFile = new File(testName + "-locator-" + locator2Port + ".log");
final Properties locatorProps = new Properties();
locatorProps.setProperty(NAME, "Locator2");
locatorProps.setProperty(MCAST_PORT, "0");
locatorProps.setProperty(LOG_LEVEL, "info");
locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
locatorProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
try {
final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator2Port, 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, TIMEOUT, INTERVAL, true);
} catch (IOException e) {
fail("Unable to create a locator with a shared configuration", e);
}
InternalLocator locator = (InternalLocator) Locator.getLocator();
ClusterConfigurationService sharedConfig = locator.getSharedConfiguration();
Map<String, Configuration> entireConfiguration = sharedConfig.getEntireConfiguration();
Configuration clusterConfig = entireConfiguration.get(ClusterConfigurationService.CLUSTER_CONFIG);
assertNotNull(clusterConfig);
assertNotNull(clusterConfig.getJarNames());
assertTrue(clusterConfig.getJarNames().contains("foo.jar"));
assertTrue(clusterConfig.getGemfireProperties().getProperty(LOG_LEVEL).equals(clusterLogLevel));
assertNotNull(clusterConfig.getCacheXmlContent());
Configuration testGroupConfiguration = entireConfiguration.get(testGroup);
assertNotNull(testGroupConfiguration);
assertNotNull(testGroupConfiguration.getJarNames());
assertTrue(testGroupConfiguration.getJarNames().contains("bar.jar"));
assertTrue(testGroupConfiguration.getGemfireProperties().getProperty(LOG_LEVEL).equals(groupLogLevel));
assertNotNull(testGroupConfiguration.getCacheXmlContent());
assertTrue(testGroupConfiguration.getCacheXmlContent().contains(REGION1));
Map<String, byte[]> jarData = sharedConfig.getAllJarsFromThisLocator(entireConfiguration.keySet());
String[] jarNames = jarData.keySet().stream().toArray(String[]::new);
byte[][] jarBytes = jarData.values().toArray(new byte[jarNames.length][]);
assertNotNull(jarNames);
assertNotNull(jarBytes);
sharedConfig.deleteXmlEntity(new XmlEntity(CacheXml.REGION, "name", REGION1), new String[] { testGroup });
sharedConfig.removeJars(new String[] { "foo.jar" }, null);
sharedConfig.removeJars(null, null);
});
dataMemberVm.invoke(() -> {
Set<String> groups = new HashSet<String>();
groups.add(testGroup);
ConfigurationRequest configRequest = new ConfigurationRequest(groups);
ConfigurationResponse configResponse = (ConfigurationResponse) new TcpClient().requestToServer(InetAddress.getByName("localhost"), locator2Port, configRequest, 1000);
assertNotNull(configResponse);
Map<String, Configuration> requestedConfiguration = configResponse.getRequestedConfiguration();
Configuration clusterConfiguration = requestedConfiguration.get(ClusterConfigurationService.CLUSTER_CONFIG);
assertNotNull(clusterConfiguration);
assertTrue(configResponse.getJarNames().length == 0);
assertTrue(configResponse.getJars().length == 0);
assertTrue(clusterConfiguration.getJarNames().isEmpty());
assertTrue(clusterConfiguration.getGemfireProperties().getProperty(LOG_LEVEL).equals(clusterLogLevel));
Configuration testGroupConfiguration = requestedConfiguration.get(testGroup);
assertNotNull(testGroupConfiguration);
assertFalse(testGroupConfiguration.getCacheXmlContent().contains(REGION1));
assertTrue(testGroupConfiguration.getJarNames().isEmpty());
assertTrue(testGroupConfiguration.getGemfireProperties().getProperty(LOG_LEVEL).equals(groupLogLevel));
GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
Map<InternalDistributedMember, Collection<String>> locatorsWithSharedConfiguration = cache.getDistributionManager().getAllHostedLocatorsWithSharedConfiguration();
assertFalse(locatorsWithSharedConfiguration.isEmpty());
assertTrue(locatorsWithSharedConfiguration.size() == 2);
Set<InternalDistributedMember> locatorMembers = locatorsWithSharedConfiguration.keySet();
for (InternalDistributedMember locatorMember : locatorMembers) {
System.out.println(locatorMember);
}
return null;
});
}
use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.
the class ClusterConfig method verifyLocator.
public void verifyLocator(MemberVM<Locator> locatorVM) {
Set<String> expectedGroupConfigs = this.getGroups().stream().map(ConfigGroup::getName).collect(toSet());
// verify info exists in memory
locatorVM.invoke(() -> {
InternalLocator internalLocator = LocatorServerStartupRule.locatorStarter.getLocator();
ClusterConfigurationService sc = internalLocator.getSharedConfiguration();
// verify no extra configs exist in memory
Set<String> actualGroupConfigs = sc.getEntireConfiguration().keySet();
assertThat(actualGroupConfigs).isEqualTo(expectedGroupConfigs);
for (ConfigGroup configGroup : this.getGroups()) {
// verify jars are as expected
Configuration config = sc.getConfiguration(configGroup.name);
assertThat(config.getJarNames()).isEqualTo(configGroup.getJars());
// verify property is as expected
if (StringUtils.isNotBlank(configGroup.getMaxLogFileSize())) {
Properties props = config.getGemfireProperties();
assertThat(props.getProperty(LOG_FILE_SIZE_LIMIT)).isEqualTo(configGroup.getMaxLogFileSize());
}
// verify region is in the region xml
for (String regionName : configGroup.getRegions()) {
String regionXml = "<region name=\"" + regionName + "\"";
assertThat(config.getCacheXmlContent()).contains(regionXml);
}
}
});
File clusterConfigDir = new File(locatorVM.getWorkingDir(), "/cluster_config");
for (ConfigGroup configGroup : this.getGroups()) {
Set<String> actualFiles = toSetIgnoringHiddenFiles(new File(clusterConfigDir, configGroup.name).list());
Set<String> expectedFiles = configGroup.getAllFiles();
assertThat(actualFiles).isEqualTo(expectedFiles);
}
}
Aggregations