Repository: geode Updated Branches: refs/heads/develop 0bfd2ea50 -> 6f418be11
http://git-wip-us.apache.org/repos/asf/geode/blob/6f418be1/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ClusterConfigurationServiceCommandsDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ClusterConfigurationServiceCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ClusterConfigurationServiceCommandsDUnitTest.java deleted file mode 100644 index 87cac55..0000000 --- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ClusterConfigurationServiceCommandsDUnitTest.java +++ /dev/null @@ -1,344 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.management.internal.cli.commands; - -import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CacheFactory; -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.distributed.Locator; -import org.apache.geode.distributed.internal.InternalLocator; -import org.apache.geode.distributed.internal.ClusterConfigurationService; -import org.apache.geode.internal.ClassBuilder; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.cli.Result.Status; -import org.apache.geode.management.internal.cli.HeadlessGfsh; -import org.apache.geode.management.internal.cli.result.CommandResult; -import org.apache.geode.management.internal.cli.util.CommandStringBuilder; -import org.apache.geode.management.internal.configuration.SharedConfigurationTestUtils; -import org.apache.geode.management.internal.configuration.domain.Configuration; -import org.apache.geode.test.dunit.SerializableCallable; -import org.apache.geode.test.dunit.SerializableRunnable; -import org.apache.geode.test.dunit.VM; -import org.apache.geode.test.dunit.WaitCriterion; -import org.apache.geode.test.junit.categories.DistributedTest; -import org.apache.geode.test.junit.categories.FlakyTest; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import java.io.File; -import java.io.IOException; -import java.util.Properties; -import java.util.Set; - -import static org.apache.geode.distributed.ConfigurationProperties.*; -import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts; -import static org.apache.geode.management.internal.cli.CliUtil.getAllNormalMembers; -import static org.apache.geode.management.internal.cli.i18n.CliStrings.*; -import static org.apache.geode.test.dunit.Assert.*; -import static org.apache.geode.test.dunit.Host.getHost; -import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter; -import static org.apache.geode.test.dunit.NetworkUtils.getIPLiteral; -import static org.apache.geode.test.dunit.Wait.waitForCriterion; - -/** - * DUnit test to test export and import of shared configuration. - */ -@Category(DistributedTest.class) -@SuppressWarnings("unchecked") -public class ClusterConfigurationServiceCommandsDUnitTest extends CliCommandTestBase { - - private static final int TIMEOUT = 10000; - private static final int INTERVAL = 500; - - private final String region1Name = "r1"; - private final String region2Name = "r2"; - private final String logLevel = "info"; - - private String groupName; - - private String deployedJarName; - private File newDeployableJarFile; - private ClassBuilder classBuilder; - - private String sharedConfigZipFileName; - private String startArchiveFileName; - private int[] ports; - - private int locator1Port; - private String locator1Name; - private String locator1LogFilePath; - - private int locator2Port; - private String locator2Name; - private String locator2LogFilePath; - - private int locator1HttpPort; - private int locator1JmxPort; - private String locator1JmxHost; - - @Override - protected final void postSetUpCliCommandTestBase() throws Exception { - disconnectAllFromDS(); - - this.groupName = getName(); - this.deployedJarName = "DeployCommandsDUnit1.jar"; - this.newDeployableJarFile = new File( - this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + deployedJarName); - this.classBuilder = new ClassBuilder(); - - this.sharedConfigZipFileName = - this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "sharedConfig.zip"; - this.startArchiveFileName = - this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "stats.gfs"; - this.ports = getRandomAvailableTCPPorts(4); - - this.locator1Port = this.ports[0]; - this.locator1Name = "locator1-" + this.locator1Port; - this.locator1LogFilePath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator - + "locator-" + this.locator1Port + ".log"; - - this.locator2Port = this.ports[1]; - this.locator2Name = "Locator2-" + this.locator2Port; - this.locator2LogFilePath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator - + "locator-" + this.locator2Port + ".log"; - - this.locator1HttpPort = ports[2]; - this.locator1JmxPort = ports[3]; - this.locator1JmxHost = getIPLiteral(); - } - - @Override - public final void postTearDownCacheTestCase() throws Exception { - for (int i = 0; i < 4; i++) { - getHost(0).getVM(i).invoke(SharedConfigurationTestUtils.cleanupLocator); - } - } - - @Category(FlakyTest.class) // GEODE-1519 - @Test - public void testExportImportSharedConfiguration() throws IOException { - // Start the Locator and wait for shared configuration to be available - VM locatorAndMgr = getHost(0).getVM(3); - Set<DistributedMember> normalMembers1 = - (Set<DistributedMember>) locatorAndMgr.invoke(new SerializableCallable() { - @Override - public Object call() { - final File locatorLogFile = new File(locator1LogFilePath); - - final Properties locatorProps = new Properties(); - locatorProps.setProperty(NAME, locator1Name); - locatorProps.setProperty(MCAST_PORT, "0"); - locatorProps.setProperty(LOG_LEVEL, "config"); - 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(locator1JmxHost)); - locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(locator1JmxPort)); - locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(locator1HttpPort)); - - 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); - } - - return getAllNormalMembers(CacheFactory.getAnyInstance()); - } - }); - - HeadlessGfsh gfsh = getDefaultShell(); - connect(locator1JmxHost, locator1JmxPort, locator1HttpPort, gfsh); - - // Create a cache in VM 1 - VM dataMember = getHost(0).getVM(1); - normalMembers1 = (Set<DistributedMember>) dataMember.invoke(new SerializableCallable() { - @Override - public Object call() { - Properties localProps = new Properties(); - localProps.setProperty(MCAST_PORT, "0"); - localProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]"); - localProps.setProperty(GROUPS, groupName); - localProps.setProperty(NAME, "DataMember"); - getSystem(localProps); - Cache cache = getCache(); - assertNotNull(cache); - return getAllNormalMembers(cache); - } - }); - - // Create a JAR file - this.classBuilder.writeJarFromName("DeployCommandsDUnitA", this.newDeployableJarFile); - - // Deploy the JAR - CommandResult cmdResult = - executeCommand("deploy --jar=" + this.newDeployableJarFile.getCanonicalPath()); - assertEquals(Result.Status.OK, cmdResult.getStatus()); - - // Create the region1 on the group - CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CREATE_REGION); - commandStringBuilder.addOption(CREATE_REGION__REGION, region1Name); - commandStringBuilder.addOption(CREATE_REGION__REGIONSHORTCUT, "REPLICATE"); - commandStringBuilder.addOption(CREATE_REGION__STATISTICSENABLED, "true"); - commandStringBuilder.addOption(CREATE_REGION__GROUP, groupName); - - cmdResult = executeCommand(commandStringBuilder.toString()); - assertEquals(Result.Status.OK, cmdResult.getStatus()); - - commandStringBuilder = new CommandStringBuilder(CREATE_REGION); - commandStringBuilder.addOption(CREATE_REGION__REGION, region2Name); - commandStringBuilder.addOption(CREATE_REGION__REGIONSHORTCUT, "PARTITION"); - commandStringBuilder.addOption(CREATE_REGION__STATISTICSENABLED, "true"); - cmdResult = executeCommand(commandStringBuilder.toString()); - assertEquals(Result.Status.OK, cmdResult.getStatus()); - - // Alter runtime configuration - commandStringBuilder = new CommandStringBuilder(ALTER_RUNTIME_CONFIG); - commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__LOG__LEVEL, logLevel); - commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__LOG__FILE__SIZE__LIMIT, "50"); - commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT, "32"); - commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT, "49"); - commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE, "120"); - commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE, - this.startArchiveFileName); - commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLING__ENABLED, "true"); - commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT, "10"); - cmdResult = executeCommand(commandStringBuilder.getCommandString()); - String resultString = commandResultToString(cmdResult); - - getLogWriter().info("#SB Result\n"); - getLogWriter().info(resultString); - assertEquals(true, cmdResult.getStatus().equals(Status.OK)); - - commandStringBuilder = new CommandStringBuilder(STATUS_SHARED_CONFIG); - cmdResult = executeCommand(commandStringBuilder.getCommandString()); - resultString = commandResultToString(cmdResult); - getLogWriter().info("#SB Result\n"); - getLogWriter().info(resultString); - assertEquals(Status.OK, cmdResult.getStatus()); - - commandStringBuilder = new CommandStringBuilder(EXPORT_SHARED_CONFIG); - commandStringBuilder.addOption(EXPORT_SHARED_CONFIG__FILE, this.sharedConfigZipFileName); - cmdResult = executeCommand(commandStringBuilder.getCommandString()); - resultString = commandResultToString(cmdResult); - getLogWriter().info("#SB Result\n"); - getLogWriter().info(resultString); - assertEquals(Status.OK, cmdResult.getStatus()); - - // Import into a running system should fail - commandStringBuilder = new CommandStringBuilder(IMPORT_SHARED_CONFIG); - commandStringBuilder.addOption(IMPORT_SHARED_CONFIG__ZIP, this.sharedConfigZipFileName); - cmdResult = executeCommand(commandStringBuilder.getCommandString()); - assertEquals(Status.ERROR, cmdResult.getStatus()); - - // Stop the data members and remove the shared configuration in the locator. - dataMember.invoke(new SerializableCallable() { - @Override - public Object call() throws Exception { - Cache cache = getCache(); - cache.close(); - assertTrue(cache.isClosed()); - disconnectFromDS(); - return null; - } - }); - - // Clear shared configuration in this locator to test the import shared configuration - locatorAndMgr.invoke(new SerializableCallable() { - @Override - public Object call() throws Exception { - InternalLocator locator = InternalLocator.getLocator(); - ClusterConfigurationService sc = locator.getSharedConfiguration(); - assertNotNull(sc); - sc.clearSharedConfiguration(); - return null; - } - }); - - // Now execute import shared configuration - // Now import the shared configuration and it should succeed. - commandStringBuilder = new CommandStringBuilder(IMPORT_SHARED_CONFIG); - commandStringBuilder.addOption(IMPORT_SHARED_CONFIG__ZIP, this.sharedConfigZipFileName); - cmdResult = executeCommand(commandStringBuilder.getCommandString()); - assertEquals(Status.OK, cmdResult.getStatus()); - - // Start a new locator , test if it has all the imported shared configuration artifacts - VM newLocator = getHost(0).getVM(2); - newLocator.invoke(new SerializableRunnable() { - @Override - public void run() { - final File locatorLogFile = new File(locator2LogFilePath); - final Properties locatorProps = new Properties(); - locatorProps.setProperty(NAME, locator2Name); - locatorProps.setProperty(MCAST_PORT, "0"); - locatorProps.setProperty(LOG_LEVEL, "fine"); - 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, 5000, 500, true); - - ClusterConfigurationService sc = locator.getSharedConfiguration(); - assertNotNull(sc); - Configuration groupConfig = sc.getConfiguration(groupName); - assertNotNull(groupConfig); - assertTrue(groupConfig.getCacheXmlContent().contains(region1Name)); - - Configuration clusterConfig = - sc.getConfiguration(ClusterConfigurationService.CLUSTER_CONFIG); - assertNotNull(clusterConfig); - assertTrue(clusterConfig.getCacheXmlContent().contains(region2Name)); - assertTrue(clusterConfig.getJarNames().contains(deployedJarName)); - assertTrue(clusterConfig.getGemfireProperties().getProperty(LOG_LEVEL).equals(logLevel)); - assertTrue(clusterConfig.getGemfireProperties().getProperty(STATISTIC_ARCHIVE_FILE) - .equals(startArchiveFileName)); - - } catch (IOException e) { - fail("Unable to create a locator with a shared configuration", e); - } catch (Exception e) { - fail("Error occurred in cluster configuration service", e); - } - } - }); - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/6f418be1/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfig.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfig.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfig.java index c2d511d..94eec0a 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfig.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfig.java @@ -26,6 +26,7 @@ import org.apache.geode.distributed.internal.ClusterConfigurationService; import org.apache.geode.internal.ClassPathLoader; import org.apache.geode.internal.JarClassLoader; import org.apache.geode.internal.JarDeployer; +import org.apache.geode.internal.cache.GemFireCacheImpl; import org.apache.geode.internal.lang.StringUtils; import org.apache.geode.management.internal.configuration.domain.Configuration; import org.apache.geode.test.dunit.rules.Locator; @@ -140,7 +141,7 @@ public class ClusterConfig implements Serializable { // verify config exists in memory server.invoke(() -> { - Cache cache = LocatorServerStartupRule.serverStarter.cache; + Cache cache = GemFireCacheImpl.getInstance(); // TODO: set compare to fail if there are extra regions for (String region : this.getRegions()) { http://git-wip-us.apache.org/repos/asf/geode/blob/6f418be1/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java index 506428a..0632935 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java @@ -27,9 +27,9 @@ import org.junit.Rule; import java.util.Properties; public class ClusterConfigBaseTest extends JUnit4DistributedTestCase { - public static final String EXPORTED_CLUSTER_CONFIG_ZIP_FILENAME = "cluster_config.zip"; - public static final String EXPORTED_CLUSTER_CONFIG_PATH = - ClusterConfigBaseTest.class.getResource(EXPORTED_CLUSTER_CONFIG_ZIP_FILENAME).getPath(); + public static final String CLUSTER_CONFIG_ZIP_FILENAME = "cluster_config.zip"; + public static final String CLUSTER_CONFIG_ZIP_PATH = + ClusterConfigBaseTest.class.getResource(CLUSTER_CONFIG_ZIP_FILENAME).getPath(); public static final ConfigGroup CLUSTER = new ConfigGroup("cluster").regions("regionForCluster") .jars("cluster.jar").maxLogFileSize("5000").configFiles("cluster.properties", "cluster.xml"); http://git-wip-us.apache.org/repos/asf/geode/blob/6f418be1/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java index b301b80..7333c23 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java @@ -20,13 +20,17 @@ import static org.apache.geode.distributed.ConfigurationProperties.GROUPS; import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS; import static org.assertj.core.api.Assertions.assertThat; +import org.apache.geode.cache.Cache; +import org.apache.geode.cache.Region; +import org.apache.geode.cache.RegionShortcut; +import org.apache.geode.internal.cache.GemFireCacheImpl; import org.apache.geode.management.cli.Result; import org.apache.geode.management.internal.cli.result.CommandResult; import org.apache.geode.test.dunit.rules.GfshShellConnectionRule; import org.apache.geode.test.dunit.rules.Locator; +import org.apache.geode.test.dunit.rules.LocatorServerStartupRule; import org.apache.geode.test.dunit.rules.Server; import org.apache.geode.test.junit.categories.DistributedTest; -import org.apache.geode.test.junit.categories.FlakyTest; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -67,20 +71,66 @@ public class ClusterConfigImportDUnitTest extends ClusterConfigBaseTest { } } + + @Test + public void testImportWithRunningServerWithData() throws Exception { + Server server = lsRule.startServerVM(1, serverProps, locator.getPort()); + String regionName = "regionA"; + server.invoke(() -> { + Cache cache = LocatorServerStartupRule.serverStarter.cache; + Region region = cache.createRegionFactory(RegionShortcut.REPLICATE).create(regionName); + region.put("key", "value"); + }); + + CommandResult result = gfshConnector + .executeCommand("import cluster-configuration --zip-file-name=" + CLUSTER_CONFIG_ZIP_PATH); + + assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR); + assertThat(result.getContent().toString()).contains("existing data in regions: " + regionName); + } + @Test public void testImportWithRunningServer() throws Exception { - lsRule.startServerVM(1, serverProps, locator.getPort()); + Server server1 = lsRule.startServerVM(1, serverProps, locator.getPort()); - CommandResult result = gfshConnector.executeCommand( - "import cluster-configuration --zip-file-name=" + EXPORTED_CLUSTER_CONFIG_PATH); + // create a testRegion and verify that after import, this region does not exist anymore + server1.invoke(() -> { + Cache cache = LocatorServerStartupRule.serverStarter.cache; + cache.createRegionFactory(RegionShortcut.REPLICATE).create("testRegion"); + }); - assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR); + serverProps.setProperty("groups", "group2"); + Server server2 = lsRule.startServerVM(2, serverProps, locator.getPort()); + + // even though we have a region recreated, we can still import since there is no data + // in the region + CommandResult result = gfshConnector + .executeCommand("import cluster-configuration --zip-file-name=" + CLUSTER_CONFIG_ZIP_PATH); + + assertThat(result.getStatus()).isEqualTo(Result.Status.OK) + .describedAs(result.getContent().toString()); + assertThat(result.getContent().toString()) + .contains("Successfully applied the imported cluster configuration on server-1"); + assertThat(result.getContent().toString()) + .contains("Successfully applied the imported cluster configuration on server-2"); + new ClusterConfig(CLUSTER).verify(server1); + new ClusterConfig(CLUSTER, GROUP2).verify(server2); + + // verify "testRegion" does not exist in either server anymore + server1.invoke(() -> { + Cache cache = GemFireCacheImpl.getInstance(); + assertThat(cache.getRegion("testRegion")).isNull(); + }); + server2.invoke(() -> { + Cache cache = GemFireCacheImpl.getInstance(); + assertThat(cache.getRegion("testRegion")).isNull(); + }); } @Test public void testImportClusterConfig() throws Exception { - CommandResult result = gfshConnector.executeCommand( - "import cluster-configuration --zip-file-name=" + EXPORTED_CLUSTER_CONFIG_PATH); + CommandResult result = gfshConnector + .executeCommand("import cluster-configuration --zip-file-name=" + CLUSTER_CONFIG_ZIP_PATH); assertThat(result.getStatus()).isEqualTo(Result.Status.OK); // Make sure that a backup of the old clusterConfig was created @@ -113,8 +163,8 @@ public class ClusterConfigImportDUnitTest extends ClusterConfigBaseTest { "localhost[" + locator.getPort() + "],localhost[" + locator1.getPort() + "]"); Locator locator2 = lsRule.startLocatorVM(2, locatorProps); - CommandResult result = gfshConnector.executeCommand( - "import cluster-configuration --zip-file-name=" + EXPORTED_CLUSTER_CONFIG_PATH); + CommandResult result = gfshConnector + .executeCommand("import cluster-configuration --zip-file-name=" + CLUSTER_CONFIG_ZIP_PATH); assertThat(result.getStatus()).isEqualTo(Result.Status.OK); CONFIG_FROM_ZIP.verify(locator); http://git-wip-us.apache.org/repos/asf/geode/blob/6f418be1/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigStartMemberDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigStartMemberDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigStartMemberDUnitTest.java index 7dd0da6..fb4aa54 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigStartMemberDUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigStartMemberDUnitTest.java @@ -89,7 +89,7 @@ public class ClusterConfigStartMemberDUnitTest extends ClusterConfigBaseTest { // tempFolder/locator-0/cluster_config/cluster/cluster.jar // tempFolder/locator-0/cluster_config/group1/ {group1.xml, group1.properties, group1.jar} // tempFolder/locator-0/cluster_config/group2/ ... - ZipUtils.unzip(EXPORTED_CLUSTER_CONFIG_PATH, configDir.getCanonicalPath()); + ZipUtils.unzip(CLUSTER_CONFIG_ZIP_PATH, configDir.getCanonicalPath()); Properties properties = new Properties(); properties.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true"); http://git-wip-us.apache.org/repos/asf/geode/blob/6f418be1/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigWithSecurityDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigWithSecurityDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigWithSecurityDUnitTest.java new file mode 100644 index 0000000..995e18e --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigWithSecurityDUnitTest.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.apache.geode.management.internal.configuration; + +import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS; +import static org.apache.geode.distributed.ConfigurationProperties.LOG_FILE_SIZE_LIMIT; +import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT; +import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANAGER; +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.geode.distributed.internal.ClusterConfigurationService; +import org.apache.geode.distributed.internal.InternalLocator; +import org.apache.geode.management.internal.cli.i18n.CliStrings; +import org.apache.geode.security.SimpleTestSecurityManager; +import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase; +import org.apache.geode.test.dunit.rules.GfshShellConnectionRule; +import org.apache.geode.test.dunit.rules.Locator; +import org.apache.geode.test.dunit.rules.LocatorServerStartupRule; +import org.apache.geode.test.junit.categories.DistributedTest; +import org.apache.geode.test.junit.categories.SecurityTest; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.util.Properties; + +@Category({DistributedTest.class, SecurityTest.class}) +public class ClusterConfigWithSecurityDUnitTest extends JUnit4DistributedTestCase { + + // the zip file is under test/resource/org/apache/geode/management/internal/configuration + // it only contains cluster.properites whose content is + // mcast-port=0 + // log-file-size-limit=8000 + // security-manager=org.apache.geode.example.security.ExampleSecurityManager + + public static final String CLUSTER_CONFIG_ZIP_FILENAME = "cluster_config_security.zip"; + public static final String CLUSTER_CONFIG_ZIP_PATH = + ClusterConfigBaseTest.class.getResource(CLUSTER_CONFIG_ZIP_FILENAME).getPath(); + + @Rule + public LocatorServerStartupRule lsRule = new LocatorServerStartupRule(); + + Locator locator0; + Properties locatorProps; + + @Before + public void before() throws Exception { + locatorProps = new Properties(); + locatorProps.setProperty(SECURITY_MANAGER, SimpleTestSecurityManager.class.getName()); + locator0 = lsRule.startLocatorVM(0, locatorProps); + } + + @Test + @Ignore("GEODE-2315") + public void testSecurityPropsInheritance() throws Exception { + locatorProps.clear(); + locatorProps.setProperty(LOCATORS, "localhost[" + locator0.getPort() + "]"); + locatorProps.setProperty("security-username", "cluster"); + locatorProps.setProperty("security-password", "cluster"); + Locator locator1 = lsRule.startLocatorVM(1, locatorProps); + + // the second locator should inherit the first locator's security props + locator1.invoke(() -> { + InternalLocator locator = LocatorServerStartupRule.locatorStarter.locator; + ClusterConfigurationService sc = locator.getSharedConfiguration(); + Properties clusterConfigProps = sc.getConfiguration("cluster").getGemfireProperties(); + assertThat(clusterConfigProps.getProperty(SECURITY_MANAGER)) + .isEqualTo(SimpleTestSecurityManager.class.getName()); + assertThat(locator.getConfig().getSecurityManager()).isNotEmpty(); + }); + } + + @Test + public void testImportNotOverwriteSecurity() throws Exception { + GfshShellConnectionRule connector = new GfshShellConnectionRule(locator0); + connector.connect(CliStrings.CONNECT__USERNAME, "cluster", CliStrings.CONNECT__PASSWORD, + "cluster"); + + connector.executeAndVerifyCommand( + "import cluster-configuration --zip-file-name=" + CLUSTER_CONFIG_ZIP_PATH); + + locator0.invoke(() -> { + InternalLocator locator = LocatorServerStartupRule.locatorStarter.locator; + ClusterConfigurationService sc = locator.getSharedConfiguration(); + Properties properties = sc.getConfiguration("cluster").getGemfireProperties(); + assertThat(properties.getProperty(MCAST_PORT)).isEqualTo("0"); + assertThat(properties.getProperty(LOG_FILE_SIZE_LIMIT)).isEqualTo("8000"); + + // the security manager is still the locator's security manager, not the imported one. + assertThat(properties.getProperty(SECURITY_MANAGER)) + .isEqualTo(SimpleTestSecurityManager.class.getName()); + }); + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/6f418be1/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterRule.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterRule.java index c94185a..60013ca 100644 --- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterRule.java +++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterRule.java @@ -106,6 +106,9 @@ public class ServerStarterRule extends ExternalResource implements Serializable @Override public void after() { + // make sure this cache is the once currently open. A server cache can be recreated due to + // importing a new set of cluster configuration. + cache = GemFireCacheImpl.getInstance(); if (cache != null) { cache.close(); cache = null; http://git-wip-us.apache.org/repos/asf/geode/blob/6f418be1/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt ---------------------------------------------------------------------- diff --git a/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt b/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt index 9626be7..2ab6173 100755 --- a/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt +++ b/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt @@ -561,7 +561,6 @@ org/apache/geode/management/internal/cli/functions/DestroyDiskStoreFunction,true org/apache/geode/management/internal/cli/functions/DestroyIndexFunction,true,1 org/apache/geode/management/internal/cli/functions/ExportConfigFunction,true,1 org/apache/geode/management/internal/cli/functions/ExportDataFunction,true,1 -org/apache/geode/management/internal/cli/functions/ExportSharedConfigurationFunction,true,1 org/apache/geode/management/internal/cli/functions/FetchRegionAttributesFunction,true,4366812590788342070 org/apache/geode/management/internal/cli/functions/FetchRegionAttributesFunction$FetchRegionAttributesFunctionResult,true,-3970828263897978845,cacheListenerClasses:java/lang/String[],cacheLoaderClass:java/lang/String,cacheWriterClass:java/lang/String,regionAttributes:org/apache/geode/cache/RegionAttributes org/apache/geode/management/internal/cli/functions/FetchSharedConfigurationStatusFunction,true,1 @@ -579,14 +578,12 @@ org/apache/geode/management/internal/cli/functions/GetRegionsFunction,true,1 org/apache/geode/management/internal/cli/functions/GetStackTracesFunction,true,1 org/apache/geode/management/internal/cli/functions/GetSubscriptionQueueSizeFunction,true,1 org/apache/geode/management/internal/cli/functions/ImportDataFunction,true,1 -org/apache/geode/management/internal/cli/functions/ImportSharedConfigurationArtifactsFunction,true,1 org/apache/geode/management/internal/cli/functions/ListAsyncEventQueuesFunction,true,1 org/apache/geode/management/internal/cli/functions/ListDeployedFunction,true,1 org/apache/geode/management/internal/cli/functions/ListDiskStoresFunction,false org/apache/geode/management/internal/cli/functions/ListDurableCqNamesFunction,true,1 org/apache/geode/management/internal/cli/functions/ListFunctionFunction,true,1 org/apache/geode/management/internal/cli/functions/ListIndexFunction,false -org/apache/geode/management/internal/cli/functions/LoadSharedConfigurationFunction,true,1 org/apache/geode/management/internal/cli/functions/LogFileFunction,true,1 org/apache/geode/management/internal/cli/functions/MemberRegionFunction,true,1 org/apache/geode/management/internal/cli/functions/MembersForRegionFunction,true,8746830191680509335 @@ -625,11 +622,8 @@ org/apache/geode/management/internal/cli/util/MemberInformation,true,1,cacheXmlF org/apache/geode/management/internal/cli/util/MemberNotFoundException,true,5686788909239181174 org/apache/geode/management/internal/cli/util/VisualVmNotFoundException,true,-8491645604829510102 org/apache/geode/management/internal/configuration/domain/SharedConfigurationStatus,false -org/apache/geode/management/internal/configuration/functions/AddJarFunction,true,1 -org/apache/geode/management/internal/configuration/functions/AddXmlEntityFunction,true,1 -org/apache/geode/management/internal/configuration/functions/DeleteJarFunction,true,1 -org/apache/geode/management/internal/configuration/functions/DeleteXmlEntityFunction,true,1 -org/apache/geode/management/internal/configuration/functions/ModifyXmlAndPropertiesFunction,true,1 +org/apache/geode/management/internal/configuration/functions/RecreateCacheFunction,false +org/apache/geode/management/internal/configuration/functions/RegionsWithDataOnServerFunction,false org/apache/geode/management/internal/configuration/functions/UploadJarFunction,true,1 org/apache/geode/management/internal/web/domain/Link,false,href:java/net/URI,method:org/apache/geode/management/internal/web/http/HttpMethod,relation:java/lang/String org/apache/geode/management/internal/web/domain/QueryParameterSource,true,34131123582155,objectName:javax/management/ObjectName,queryExpression:javax/management/QueryExp http://git-wip-us.apache.org/repos/asf/geode/blob/6f418be1/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster_config_security.zip ---------------------------------------------------------------------- diff --git a/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster_config_security.zip b/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster_config_security.zip new file mode 100644 index 0000000..c09114e Binary files /dev/null and b/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster_config_security.zip differ http://git-wip-us.apache.org/repos/asf/geode/blob/6f418be1/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommands.java ---------------------------------------------------------------------- diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommands.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommands.java index 8f5a3d6..e7fb0b9 100755 --- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommands.java +++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommands.java @@ -14,25 +14,12 @@ */ package org.apache.geode.cache.lucene.internal.cli; -import java.util.ArrayList; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -import org.apache.geode.security.ResourcePermission.Operation; -import org.apache.geode.security.ResourcePermission.Resource; -import org.springframework.shell.core.annotation.CliAvailabilityIndicator; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - import org.apache.geode.SystemFailure; import org.apache.geode.cache.Cache; import org.apache.geode.cache.execute.Execution; import org.apache.geode.cache.execute.FunctionAdapter; import org.apache.geode.cache.execute.FunctionInvocationTargetException; import org.apache.geode.cache.execute.ResultCollector; - import org.apache.geode.cache.lucene.internal.cli.functions.LuceneCreateIndexFunction; import org.apache.geode.cache.lucene.internal.cli.functions.LuceneDescribeIndexFunction; import org.apache.geode.cache.lucene.internal.cli.functions.LuceneListIndexFunction; @@ -55,6 +42,16 @@ import org.apache.geode.management.internal.cli.result.TabularResultData; import org.apache.geode.management.internal.cli.shell.Gfsh; import org.apache.geode.management.internal.configuration.domain.XmlEntity; import org.apache.geode.management.internal.security.ResourceOperation; +import org.apache.geode.security.ResourcePermission.Operation; +import org.apache.geode.security.ResourcePermission.Resource; +import org.springframework.shell.core.annotation.CliAvailabilityIndicator; +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; + +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; /** * The LuceneIndexCommands class encapsulates all Geode shell (Gfsh) commands related to Lucene @@ -162,8 +159,7 @@ public class LuceneIndexCommands extends AbstractCommandsSupport { @CliCommand(value = LuceneCliStrings.LUCENE_CREATE_INDEX, help = LuceneCliStrings.LUCENE_CREATE_INDEX__HELP) @CliMetaData(shellOnly = false, - relatedTopic = {CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA}, - writesToSharedConfiguration = true) + relatedTopic = {CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA}) // TODO : Add optionContext for indexName public Result createIndex(@CliOption(key = LuceneCliStrings.LUCENE__INDEX_NAME, mandatory = true, help = LuceneCliStrings.LUCENE_CREATE_INDEX__NAME__HELP) final String indexName, http://git-wip-us.apache.org/repos/asf/geode/blob/6f418be1/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java index a1810b6..d4869c2 100644 --- a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java +++ b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java @@ -36,9 +36,8 @@ import org.apache.geode.test.junit.runner.SuiteRunner; MiscellaneousCommandsExportLogsPart2DUnitTest.class, MiscellaneousCommandsExportLogsPart3DUnitTest.class, MiscellaneousCommandsExportLogsPart4DUnitTest.class, QueueCommandsDUnitTest.class, - ClusterConfigurationServiceCommandsDUnitTest.class, ShellCommandsDUnitTest.class, - ShowDeadlockDUnitTest.class, ShowMetricsDUnitTest.class, ShowStackTraceDUnitTest.class, - UserCommandsDUnitTest.class}) + ShellCommandsDUnitTest.class, ShowDeadlockDUnitTest.class, ShowMetricsDUnitTest.class, + ShowStackTraceDUnitTest.class, UserCommandsDUnitTest.class}) public class CommandOverHttpDUnitTest { @ClassRule public static ProvideSystemProperty provideSystemProperty =
