From commits-return-27254-archive-asf-public=cust-asf.ponee.io@geode.apache.org Thu Jun 14 17:47:40 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 0B006180600 for ; Thu, 14 Jun 2018 17:47:39 +0200 (CEST) Received: (qmail 31452 invoked by uid 500); 14 Jun 2018 15:47:39 -0000 Mailing-List: contact commits-help@geode.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.apache.org Delivered-To: mailing list commits@geode.apache.org Received: (qmail 31440 invoked by uid 99); 14 Jun 2018 15:47:39 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jun 2018 15:47:39 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 344C985317; Thu, 14 Jun 2018 15:47:38 +0000 (UTC) Date: Thu, 14 Jun 2018 15:47:37 +0000 To: "commits@geode.apache.org" Subject: [geode] branch develop updated: GEODE-5318: Extract the valid region name (#2054) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <152899125732.29923.17064786091092543204@gitbox.apache.org> From: nnag@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: geode X-Git-Refname: refs/heads/develop X-Git-Reftype: branch X-Git-Oldrev: 3f4c33b0588bfc147bdb052e45d149a7397dffe9 X-Git-Newrev: 36688887a2e30c4618f9ec4b84213482cb8e6cc3 X-Git-Rev: 36688887a2e30c4618f9ec4b84213482cb8e6cc3 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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 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.