You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by nn...@apache.org on 2018/06/14 15:47:37 UTC
[geode] branch develop updated: GEODE-5318: Extract the valid
region name (#2054)
This is an automated email from the ASF dual-hosted git repository.
nnag pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new 3668888 GEODE-5318: Extract the valid region name (#2054)
3668888 is described below
commit 36688887a2e30c4618f9ec4b84213482cb8e6cc3
Author: Nabarun Nag <na...@users.noreply.github.com>
AuthorDate: Thu Jun 14 08:47:12 2018 -0700
GEODE-5318: Extract the valid region name (#2054)
* Incase of entrySet being used in the from clause while defining an index
* the region name extracted should not include entrySet part.
* Including the entrySet causes updates to cluster config to fail.
---
.../cli/commands/CreateDefinedIndexesCommand.java | 20 +++++++--
...rConfigurationIndexWithFromClauseDUnitTest.java | 48 ++++++++++++++++++++++
2 files changed, 65 insertions(+), 3 deletions(-)
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateDefinedIndexesCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateDefinedIndexesCommand.java
index c7d23de..31a589a 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateDefinedIndexesCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateDefinedIndexesCommand.java
@@ -80,12 +80,26 @@ public class CreateDefinedIndexesCommand extends SingleGfshCommand {
}
for (RegionConfig.Index index : updatedIndexes) {
- RegionConfig region = config.findRegionConfiguration(index.getFromClause());
- if (region == null) {
+ RegionConfig regionConfig = getValidRegionConfig(index.getFromClause(), config);
+ if (regionConfig == null) {
throw new IllegalStateException("RegionConfig is null");
}
- region.getIndexes().add(index);
+ regionConfig.getIndexes().add(index);
}
}
+
+ RegionConfig getValidRegionConfig(String regionPath, CacheConfig cacheConfig) {
+ // Check to see if the region path contains an alias e.g "/region1 r1"
+ // Then the first string will be the regionPath
+ String[] regionPathTokens = regionPath.trim().split(" ");
+ regionPath = regionPathTokens[0];
+ // check to see if the region path is in the form of "--region=region.entrySet() z"
+ RegionConfig regionConfig = cacheConfig.findRegionConfiguration(regionPath);
+ while (regionPath.contains(".") && (regionConfig) == null) {
+ regionPath = regionPath.substring(0, regionPath.lastIndexOf("."));
+ regionConfig = cacheConfig.findRegionConfiguration(regionPath);
+ }
+ return regionConfig;
+ }
}
diff --git a/geode-wan/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationIndexWithFromClauseDUnitTest.java b/geode-wan/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationIndexWithFromClauseDUnitTest.java
index 5213aec..14c1bc8 100644
--- a/geode-wan/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationIndexWithFromClauseDUnitTest.java
+++ b/geode-wan/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationIndexWithFromClauseDUnitTest.java
@@ -28,6 +28,7 @@ import org.junit.runner.RunWith;
import org.apache.geode.cache.RegionShortcut;
import org.apache.geode.management.internal.cli.i18n.CliStrings;
import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
+import org.apache.geode.test.dunit.IgnoredException;
import org.apache.geode.test.dunit.rules.ClusterStartupRule;
import org.apache.geode.test.dunit.rules.MemberVM;
import org.apache.geode.test.junit.categories.DistributedTest;
@@ -77,6 +78,44 @@ public class ClusterConfigurationIndexWithFromClauseDUnitTest {
verifyIndexRecreated(INDEX_NAME);
}
+ @Test
+ @Parameters(method = "getRegionTypes")
+ public void indexCreatedWithDefinedIndexWithEntrySetInFromClauseMustPersistInClusterConfig(
+ RegionShortcut regionShortcut)
+ throws Exception {
+ IgnoredException.addIgnoredException("java.lang.IllegalStateException");
+ MemberVM vm1 = lsRule.startServerVM(1, locator.getPort());
+ gfshCommandRule.connectAndVerify(locator);
+ createRegionUsingGfsh(REGION_NAME, regionShortcut, null);
+ createIndexUsingGfsh("\"" + REGION_NAME + ".entrySet() z\"", "z.key", INDEX_NAME);
+ String serverName = vm1.getName();
+ CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_DEFINED_INDEXES);
+ gfshCommandRule.executeAndAssertThat(csb.toString()).statusIsSuccess();
+ lsRule.stopVM(1);
+ lsRule.startServerVM(1, locator.getPort());
+ verifyIndexRecreated(INDEX_NAME);
+
+ }
+
+ @Test
+ @Parameters(method = "getRegionTypes")
+ public void indexCreatedWithDefinedIndexWithAliasInFromClauseMustPersistInClusterConfig(
+ RegionShortcut regionShortcut)
+ throws Exception {
+ IgnoredException.addIgnoredException("java.lang.IllegalStateException");
+ MemberVM vm1 = lsRule.startServerVM(1, locator.getPort());
+ gfshCommandRule.connectAndVerify(locator);
+ createRegionUsingGfsh(REGION_NAME, regionShortcut, null);
+ createIndexUsingGfsh("\"" + REGION_NAME + " z\"", "z.ID", INDEX_NAME);
+ String serverName = vm1.getName();
+ CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_DEFINED_INDEXES);
+ gfshCommandRule.executeAndAssertThat(csb.toString()).statusIsSuccess();
+ lsRule.stopVM(1);
+ lsRule.startServerVM(1, locator.getPort());
+ verifyIndexRecreated(INDEX_NAME);
+
+ }
+
private void verifyIndexRecreated(String indexName) throws Exception {
CommandStringBuilder csb = new CommandStringBuilder(CliStrings.LIST_INDEX);
gfshCommandRule.executeAndAssertThat(csb.toString()).statusIsSuccess();
@@ -93,6 +132,15 @@ public class ClusterConfigurationIndexWithFromClauseDUnitTest {
gfshCommandRule.executeAndAssertThat(csb.toString()).statusIsSuccess();
}
+ private void defineIndexUsingGfsh(String regionName, String expression, String indexName)
+ throws Exception {
+ CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DEFINE_INDEX);
+ csb.addOption(CliStrings.DEFINE_INDEX__EXPRESSION, expression);
+ csb.addOption(CliStrings.DEFINE_INDEX__REGION, regionName);
+ csb.addOption(CliStrings.DEFINE_INDEX_NAME, indexName);
+ gfshCommandRule.executeAndAssertThat(csb.toString()).statusIsSuccess();
+ }
+
private void createRegionUsingGfsh(String regionName, RegionShortcut regionShortCut, String group)
throws Exception {
CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_REGION);
--
To stop receiving notification emails like this one, please contact
nnag@apache.org.