geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jensde...@apache.org
Subject [geode] branch develop updated: GEODE-5952: Provide full cache XML entity for root region when a subregion is created with gfsh (#2747)
Date Wed, 31 Oct 2018 19:24:39 GMT
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 fd4072e  GEODE-5952: Provide full cache XML entity for root region when a subregion
is created with gfsh (#2747)
fd4072e is described below

commit fd4072e39927964fa7307bd34af32c09e7f06bc7
Author: Aditya Anchuri <aanchuri@pivotal.io>
AuthorDate: Wed Oct 31 12:24:31 2018 -0700

    GEODE-5952: Provide full cache XML entity for root region when a subregion is created
with gfsh (#2747)
    
    
    Signed-off-by: Jens Deppe <jdeppe@pivotal.io>
---
 .../cli/commands/CreateRegionCommandDUnitTest.java | 48 ++++++++++++++++++++++
 .../main/java/org/apache/geode/cache/Region.java   |  4 +-
 .../internal/cli/commands/CreateRegionCommand.java |  4 +-
 .../cli/functions/RegionCreateFunction.java        | 20 +++++++--
 4 files changed, 67 insertions(+), 9 deletions(-)

diff --git a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandDUnitTest.java
b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandDUnitTest.java
index 4c9e802..8d8dc19 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandDUnitTest.java
@@ -33,6 +33,9 @@ import org.junit.rules.TestName;
 import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.PartitionResolver;
 import org.apache.geode.cache.Region;
+import org.apache.geode.cache.configuration.CacheConfig;
+import org.apache.geode.cache.configuration.CacheElement;
+import org.apache.geode.cache.configuration.RegionConfig;
 import org.apache.geode.cache.util.CacheListenerAdapter;
 import org.apache.geode.compression.SnappyCompressor;
 import org.apache.geode.internal.cache.PartitionedRegion;
@@ -122,6 +125,51 @@ public class CreateRegionCommandDUnitTest {
   }
 
   @Test
+  public void testCreateRegionWithSubregion() throws Exception {
+    String regionName = testName.getMethodName();
+    gfsh.executeAndAssertThat("create region --name=" + regionName + " --type=REPLICATE")
+        .statusIsSuccess();
+    String subRegionName = "subregion";
+    String subRegionPath = regionName + "/" + subRegionName;
+
+    gfsh.executeAndAssertThat("create region --name=" + subRegionPath +
+        " --type=REPLICATE")
+        .statusIsSuccess();
+
+    String subSubRegionName = "subregion2";
+    String subSubRegionPath = regionName + "/" + subRegionName + "/" + subSubRegionName;
+    gfsh.executeAndAssertThat("create region --name=" + subSubRegionPath +
+        " --type=REPLICATE")
+        .statusIsSuccess();
+
+    server1.invoke(() -> {
+      Cache cache = ClusterStartupRule.getCache();
+      Region region = cache.getRegion(regionName);
+      assertThat(region).isNotNull();
+
+      Region subRegion = cache.getRegion(subRegionPath);
+      assertThat(subRegion).isNotNull();
+
+      Region subSubRegion = cache.getRegion(subSubRegionPath);
+      assertThat(subSubRegion).isNotNull();
+    });
+
+    locator.invoke(() -> {
+      CacheConfig config = ClusterStartupRule.getLocator().getConfigurationPersistenceService()
+          .getCacheConfig("cluster");
+      assertThat(CacheElement.findElement(config.getRegions(), regionName)).isNotNull();
+
+      RegionConfig parentConfig = CacheElement.findElement(config.getRegions(), regionName);
+      assertThat(CacheElement.findElement(parentConfig.getRegions(), subRegionName)).isNotNull();
+
+      RegionConfig subRegionConfig = CacheElement.findElement(parentConfig.getRegions(),
+          subRegionName);
+      assertThat(CacheElement.findElement(subRegionConfig.getRegions(), subSubRegionName))
+          .isNotNull();
+    });
+  }
+
+  @Test
   public void testCreateRegionWithPartitionResolver() throws Exception {
     String regionName = testName.getMethodName();
     String PR_STRING = "package io.pivotal; "
diff --git a/geode-core/src/main/java/org/apache/geode/cache/Region.java b/geode-core/src/main/java/org/apache/geode/cache/Region.java
index a0e78ee..dc6a402 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/Region.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/Region.java
@@ -169,7 +169,8 @@ public interface Region<K, V> extends ConcurrentMap<K, V>
{
   String getFullPath();
 
   /**
-   * Gets the parent region of this region. If this region is a root region, returns null.
+   * Gets the parent region of this region. If this region is a root region (i.e. has no
parents),
+   * returns null.
    * <p>
    * Does not throw a <code>CacheClosedException</code> or a <code>RegionDestroyedException</code>.
    *
@@ -193,7 +194,6 @@ public interface Region<K, V> extends ConcurrentMap<K, V>
{
    */
   RegionAttributes<K, V> getAttributes();
 
-
   /**
    * Returns a mutator object used for modifying this region's attributes after region creation.
    * Note that some attributes are immutable after region creation.
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommand.java
index 05931c0..6e50265 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommand.java
@@ -41,7 +41,6 @@ import org.apache.geode.cache.RegionAttributes;
 import org.apache.geode.cache.RegionShortcut;
 import org.apache.geode.cache.execute.ResultCollector;
 import org.apache.geode.distributed.DistributedMember;
-import org.apache.geode.distributed.internal.InternalConfigurationPersistenceService;
 import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.management.DistributedRegionMXBean;
 import org.apache.geode.management.DistributedSystemMXBean;
@@ -442,8 +441,7 @@ public class CreateRegionCommand extends InternalGfshCommand {
     if (xmlEntity != null) {
       verifyDistributedRegionMbean(cache, regionPath);
       persistClusterConfiguration(result,
-          () -> ((InternalConfigurationPersistenceService) getConfigurationPersistenceService())
-              .addXmlEntity(xmlEntity, groups));
+          () -> getConfigurationPersistenceService().addXmlEntity(xmlEntity, groups));
     }
     return result;
   }
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java
index 0d0191c..ceceba8 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java
@@ -93,7 +93,8 @@ public class RegionCreateFunction implements InternalFunction {
 
     try {
       Region<?, ?> createdRegion = createRegion(cache, regionCreateArgs);
-      XmlEntity xmlEntity = new XmlEntity(CacheXml.REGION, "name", createdRegion.getName());
+      XmlEntity xmlEntity = getXmlEntityForRegion(createdRegion);
+
       resultSender.lastResult(new CliFunctionResult(memberNameOrId, xmlEntity,
           CliStrings.format(CliStrings.CREATE_REGION__MSG__REGION_0_CREATED_ON_1,
               createdRegion.getFullPath(), memberNameOrId)));
@@ -128,14 +129,25 @@ public class RegionCreateFunction implements InternalFunction {
     if (e != null && logger.isDebugEnabled()) {
       logger.debug(e.getMessage(), e);
     }
+
     if (exceptionMsg != null) {
-      return new CliFunctionResult(memberNameOrId, false, exceptionMsg);
+      return new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.ERROR,
+          exceptionMsg);
+    }
+
+    return new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.ERROR);
+  }
+
+  private XmlEntity getXmlEntityForRegion(Region<?, ?> region) {
+    Region<?, ?> curRegion = region;
+    while (curRegion != null && curRegion.getParentRegion() != null) {
+      curRegion = curRegion.getParentRegion();
     }
 
-    return new CliFunctionResult(memberNameOrId);
+    return new XmlEntity(CacheXml.REGION, "name", curRegion.getName());
   }
 
-  public static <K, V> Region<?, ?> createRegion(Cache cache, RegionFunctionArgs
regionCreateArgs) {
+  private <K, V> Region<?, ?> createRegion(Cache cache, RegionFunctionArgs regionCreateArgs)
{
     Region<K, V> createdRegion = null;
 
     final RegionShortcut regionShortcut = regionCreateArgs.getRegionShortcut();


Mime
View raw message