This is an automated email from the ASF dual-hosted git repository. jensdeppe 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 d4b80d2727 GEODE-10284: Add partition-listener option to gfsh create region command (#7666) d4b80d2727 is described below commit d4b80d27277d3eda22f692cf95d95026096470d5 Author: Jens Deppe <jde...@vmware.com> AuthorDate: Mon May 9 21:09:38 2022 -0700 GEODE-10284: Add partition-listener option to gfsh create region command (#7666) * Update documentation Co-authored-by: Dave Barnes <dav...@vmware.com> --- .../geode/management/internal/i18n/CliStrings.java | 4 ++++ .../gfsh/command-pages/create.html.md.erb | 13 ++++++++++--- .../cli/commands/CreateRegionCommandDUnitTest.java | 22 ++++++++++++++++++++++ .../GfshParserAutoCompletionIntegrationTest.java | 2 +- .../internal/cli/commands/CreateRegionCommand.java | 11 ++++++++++- 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/i18n/CliStrings.java b/geode-core/src/main/java/org/apache/geode/management/internal/i18n/CliStrings.java index 4cd6bdf177..26d5ed7da2 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/i18n/CliStrings.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/i18n/CliStrings.java @@ -1076,6 +1076,10 @@ public class CliStrings { public static final String CREATE_REGION__OFF_HEAP__HELP = "Causes the values of the region to be stored in off-heap memory. The default is on heap."; + public static final String CREATE_REGION__PARTITION_LISTENER = "partition-listener"; + public static final String CREATE_REGION__PARTITION_LISTENER__HELP = + "The fully-qualified class name of a partition listener"; + public static final String CREATE_REGION__PARTITION_RESOLVER = "partition-resolver"; public static final String CREATE_REGION__PARTITION_RESOLVER__HELP = "The fully-qualified class name of the region's partition resolver"; diff --git a/geode-docs/tools_modules/gfsh/command-pages/create.html.md.erb b/geode-docs/tools_modules/gfsh/command-pages/create.html.md.erb index 7f7568483b..c8503ade89 100644 --- a/geode-docs/tools_modules/gfsh/command-pages/create.html.md.erb +++ b/geode-docs/tools_modules/gfsh/command-pages/create.html.md.erb @@ -861,8 +861,10 @@ for syntax details. [--recovery-delay=value] [--redundant-copies=value] [--startup-recovery-delay=value] [--total-max-memory=value] [--total-num-buckets=value] [--compressor=value] [--off-heap(=value)?] - [--partition-resolver=value] [--eviction-entry-count=value] [--scope=value] - [--eviction-max-memory=value] [--eviction-action=value] [--eviction-object-sizer=value] + [--partition-listener=value(,value)*] [--partition-resolver=value] + [--eviction-entry-count=value] [--scope=value] + [--eviction-max-memory=value] [--eviction-action=value] + [--eviction-object-sizer=value] ``` **Parameters, create region:** @@ -1079,8 +1081,13 @@ If this option is specified without a value or is specified with a value of <cod <td>false</td> </tr> <tr> +<td><span class="keyword parmname">‑‑partition-listener</span></td> +<td>Specifies fully-qualified class names of one or more custom partition listeners.</td> +<td></td> +</tr> +<tr> <td><span class="keyword parmname">‑‑partition-resolver</span></td> -<td>Specifies the full path to a custom partition resolver. Specify <code class="ph codeph">org.apache.geode.cache.util.StringPrefixPartitionResolver</code> to use the included string prefix partition resolver.</td> +<td>Specifies the full path to a custom partition resolver. Specify <code class="ph codeph">org.apache.geode.cache.util.StringPrefixPartitionResolver</code> to use the included string prefix <code class="ph codeph">PartitionResolver</code>.</td> <td></td> </tr> <tr> diff --git a/geode-gfsh/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandDUnitTest.java b/geode-gfsh/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandDUnitTest.java index 3475fd900c..ccf4b8de88 100644 --- a/geode-gfsh/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandDUnitTest.java +++ b/geode-gfsh/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandDUnitTest.java @@ -46,6 +46,8 @@ import org.apache.geode.cache.asyncqueue.AsyncEvent; import org.apache.geode.cache.asyncqueue.AsyncEventListener; import org.apache.geode.cache.configuration.CacheConfig; import org.apache.geode.cache.configuration.RegionConfig; +import org.apache.geode.cache.partition.PartitionListener; +import org.apache.geode.cache.partition.PartitionListenerAdapter; import org.apache.geode.cache.util.CacheListenerAdapter; import org.apache.geode.compression.Compressor; import org.apache.geode.compression.SnappyCompressor; @@ -105,6 +107,9 @@ public class CreateRegionCommandDUnitTest { } } + public static class TestPartitionListener extends PartitionListenerAdapter implements Declarable { + } + @ClassRule public static ClusterStartupRule lsRule = new ClusterStartupRule(); @@ -266,6 +271,23 @@ public class CreateRegionCommandDUnitTest { }); } + @Test + public void testCreateRegionWithPartitionListener() { + String regionName = testName.getMethodName(); + + gfsh.executeAndAssertThat("create region --name=" + regionName + + " --type=PARTITION --partition-listener=" + TestPartitionListener.class.getName()) + .statusIsSuccess(); + + server1.invoke(() -> { + Cache cache = ClusterStartupRule.getCache(); + PartitionedRegion region = (PartitionedRegion) cache.getRegion(regionName); + PartitionListener[] listeners = region.getPartitionAttributes().getPartitionListeners(); + assertThat(listeners).isNotNull(); + assertThat(listeners[0].getClass().getSimpleName()).isEqualTo("TestPartitionListener"); + }); + } + @Test public void testCreateRegionWithInvalidPartitionResolver() { gfsh.executeAndAssertThat("create region --name=" + testName.getMethodName() diff --git a/geode-gfsh/src/integrationTest/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionIntegrationTest.java b/geode-gfsh/src/integrationTest/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionIntegrationTest.java index c3096dc7a6..c74d0d8dfb 100644 --- a/geode-gfsh/src/integrationTest/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionIntegrationTest.java +++ b/geode-gfsh/src/integrationTest/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionIntegrationTest.java @@ -302,7 +302,7 @@ public class GfshParserAutoCompletionIntegrationTest { public void testCompleteWithRegionTypeWithSpace() { String buffer = "create region --name=test --type=REPLICATE "; CommandCandidate candidate = gfshParserRule.complete(buffer); - assertThat(candidate.getCandidates()).hasSize(46); + assertThat(candidate.getCandidates()).hasSize(47); assertThat(candidate.getFirstCandidate()).isEqualTo(buffer + "--async-event-queue-id"); } diff --git a/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommand.java b/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommand.java index caf35d4ad8..f90df55641 100644 --- a/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommand.java +++ b/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommand.java @@ -78,6 +78,7 @@ public class CreateRegionCommand extends SingleGfshCommand { CliStrings.CREATE_REGION__STARTUPRECOVERYDDELAY, CliStrings.CREATE_REGION__TOTALMAXMEMORY, CliStrings.CREATE_REGION__TOTALNUMBUCKETS, + CliStrings.CREATE_REGION__PARTITION_LISTENER, CliStrings.CREATE_REGION__PARTITION_RESOLVER }; @@ -168,6 +169,9 @@ public class CreateRegionCommand extends SingleGfshCommand { help = CliStrings.CREATE_REGION__LOCALMAXMEMORY__HELP) Integer prLocalMaxMemory, @CliOption(key = CliStrings.CREATE_REGION__OFF_HEAP, specifiedDefaultValue = "true", help = CliStrings.CREATE_REGION__OFF_HEAP__HELP) Boolean offHeap, + @CliOption(key = CliStrings.CREATE_REGION__PARTITION_LISTENER, + optionContext = "splittingRegex=,(?![^{]*\\})", + help = CliStrings.CREATE_REGION__PARTITION_LISTENER__HELP) ClassName[] partitionListener, @CliOption(key = CliStrings.CREATE_REGION__PARTITION_RESOLVER, help = CliStrings.CREATE_REGION__PARTITION_RESOLVER__HELP) String partitionResolver, @CliOption(key = CliStrings.CREATE_REGION__REGIONEXPIRATIONIDLETIME, @@ -288,10 +292,15 @@ public class CreateRegionCommand extends SingleGfshCommand { regionConfig.setName(regionPathData.getName()); + List<String> partitionListeners = partitionListener == null ? Collections.emptyList() + : Arrays.stream(partitionListener) + .map(ClassName::getClassName).collect(Collectors.toList()); + // set partition attributes RegionAttributesType regionAttributes = regionConfig.getRegionAttributes(); RegionAttributesType.PartitionAttributes delta = - RegionAttributesType.PartitionAttributes.generate(partitionResolver, null, prLocalMaxMemory, + RegionAttributesType.PartitionAttributes.generate(partitionResolver, + partitionListeners, prLocalMaxMemory, prRecoveryDelay, prRedundantCopies, prStartupRecoveryDelay, prTotalMaxMemory, prTotalNumBuckets, prColocatedWith);