Repository: geode
Updated Branches:
  refs/heads/develop da91cd401 -> de135a45e


GEODE-2198: do not import cluster config if any region exists to prevent 
different servers having conflicing region definitions at one point of time.


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/de135a45
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/de135a45
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/de135a45

Branch: refs/heads/develop
Commit: de135a45e18c5351a665dda91aa6ea461fafe4c6
Parents: da91cd4
Author: Jinmei Liao <[email protected]>
Authored: Thu Feb 9 16:56:32 2017 -0800
Committer: Jinmei Liao <[email protected]>
Committed: Fri Feb 10 09:53:56 2017 -0800

----------------------------------------------------------------------
 ...xportImportClusterConfigurationCommands.java | 13 +++---
 .../functions/GetRegionNamesFunction.java       | 43 ++++++++++++++++++++
 .../RegionsWithDataOnServerFunction.java        | 43 --------------------
 .../ClusterConfigImportDUnitTest.java           | 32 ++++-----------
 .../codeAnalysis/sanctionedSerializables.txt    |  2 +-
 5 files changed, 58 insertions(+), 75 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/de135a45/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java
 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java
index f822c67..e94af4f 100644
--- 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java
+++ 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java
@@ -38,8 +38,8 @@ import 
org.apache.geode.management.internal.cli.result.FileResult;
 import org.apache.geode.management.internal.cli.result.InfoResultData;
 import org.apache.geode.management.internal.cli.result.ResultBuilder;
 import org.apache.geode.management.internal.configuration.domain.Configuration;
+import 
org.apache.geode.management.internal.configuration.functions.GetRegionNamesFunction;
 import 
org.apache.geode.management.internal.configuration.functions.RecreateCacheFunction;
-import 
org.apache.geode.management.internal.configuration.functions.RegionsWithDataOnServerFunction;
 import org.apache.geode.management.internal.configuration.utils.ZipUtils;
 import org.apache.geode.management.internal.security.ResourceOperation;
 import org.apache.geode.security.ResourcePermission.Operation;
@@ -140,12 +140,12 @@ public class ExportImportClusterConfigurationCommands 
extends AbstractCommandsSu
 
     Set<DistributedMember> servers = CliUtil.getAllNormalMembers(cache);
 
-    Set<String> regionsWithData = 
servers.stream().map(this::getNonEmptyRegionsOnServer)
+    Set<String> regionsWithData = 
servers.stream().map(this::getRegionNamesOnServer)
         .flatMap(Collection::stream).collect(toSet());
 
     if (!regionsWithData.isEmpty()) {
-      return ResultBuilder.createGemFireErrorResult(
-          "Cannot import cluster configuration with existing data in regions: "
+      return ResultBuilder
+          .createGemFireErrorResult("Cannot import cluster configuration with 
existing regions: "
               + regionsWithData.stream().collect(joining(",")));
     }
 
@@ -202,9 +202,8 @@ public class ExportImportClusterConfigurationCommands 
extends AbstractCommandsSu
     return result;
   }
 
-  private Set<String> getNonEmptyRegionsOnServer(DistributedMember server) {
-    ResultCollector rc =
-        CliUtil.executeFunction(new RegionsWithDataOnServerFunction(), null, 
server);
+  private Set<String> getRegionNamesOnServer(DistributedMember server) {
+    ResultCollector rc = CliUtil.executeFunction(new GetRegionNamesFunction(), 
null, server);
     List<Set<String>> results = (List<Set<String>>) rc.getResult();
 
     return results.get(0);

http://git-wip-us.apache.org/repos/asf/geode/blob/de135a45/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/GetRegionNamesFunction.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/GetRegionNamesFunction.java
 
b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/GetRegionNamesFunction.java
new file mode 100644
index 0000000..0fd8876
--- /dev/null
+++ 
b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/GetRegionNamesFunction.java
@@ -0,0 +1,43 @@
+/*
+ * 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.functions;
+
+import static java.util.stream.Collectors.toSet;
+
+import org.apache.geode.cache.execute.Function;
+import org.apache.geode.cache.execute.FunctionContext;
+import org.apache.geode.internal.InternalEntity;
+import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.internal.cache.LocalRegion;
+
+import java.util.Set;
+
+public class GetRegionNamesFunction implements Function, InternalEntity {
+  @Override
+  public void execute(FunctionContext context) {
+    GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
+
+    Set<String> regions =
+        
cache.getApplicationRegions().stream().map(LocalRegion::getName).collect(toSet());
+
+    context.getResultSender().lastResult(regions);
+  }
+
+  @Override
+  public String getId() {
+    return GetRegionNamesFunction.class.getName();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/de135a45/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/RegionsWithDataOnServerFunction.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/RegionsWithDataOnServerFunction.java
 
b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/RegionsWithDataOnServerFunction.java
deleted file mode 100644
index c7ec2bb..0000000
--- 
a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/RegionsWithDataOnServerFunction.java
+++ /dev/null
@@ -1,43 +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.configuration.functions;
-
-import static java.util.stream.Collectors.toSet;
-
-import org.apache.geode.cache.execute.Function;
-import org.apache.geode.cache.execute.FunctionContext;
-import org.apache.geode.internal.InternalEntity;
-import org.apache.geode.internal.cache.GemFireCacheImpl;
-import org.apache.geode.internal.cache.LocalRegion;
-
-import java.util.Set;
-
-public class RegionsWithDataOnServerFunction implements Function, 
InternalEntity {
-  @Override
-  public void execute(FunctionContext context) {
-    GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
-
-    Set<String> nonEmptyRegions = cache.getApplicationRegions().stream()
-        .filter(region -> 
!region.isEmpty()).map(LocalRegion::getName).collect(toSet());
-
-    context.getResultSender().lastResult(nonEmptyRegions);
-  }
-
-  @Override
-  public String getId() {
-    return RegionsWithDataOnServerFunction.class.getName();
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/de135a45/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 b4cba61..72daf0d 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
@@ -21,9 +21,7 @@ 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;
@@ -64,32 +62,28 @@ public class ClusterConfigImportDUnitTest extends 
ClusterConfigBaseTest {
   }
 
   @Test
-  public void testImportWithRunningServerWithData() throws Exception {
-    Server server = lsRule.startServerVM(1, serverProps, locator.getPort());
+  public void testImportWithRunningServerWithRegion() throws Exception {
+    Server server1 = lsRule.startServerVM(1, serverProps, locator.getPort());
+    // create another server as well
+    Server server2 = lsRule.startServerVM(2, serverProps, locator.getPort());
     String regionName = "regionA";
-    server.invoke(() -> {
+    server1.invoke(() -> {
+      // this region will be created on both servers, but we should only be 
getting the name once.
       Cache cache = LocatorServerStartupRule.serverStarter.cache;
-      Region region = 
cache.createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
-      region.put("key", "value");
+      cache.createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
     });
 
     CommandResult result = gfshConnector
         .executeCommand("import cluster-configuration --zip-file-name=" + 
clusterConfigZipPath);
 
     assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
-    assertThat(result.getContent().toString()).contains("existing data in 
regions: " + regionName);
+    assertThat(result.getContent().toString()).contains("existing regions: " + 
regionName);
   }
 
   @Test
   public void testImportWithRunningServer() throws Exception {
     Server server1 = lsRule.startServerVM(1, serverProps, locator.getPort());
 
-    // 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");
-    });
-
     serverProps.setProperty("groups", "group2");
     Server server2 = lsRule.startServerVM(2, serverProps, locator.getPort());
 
@@ -103,16 +97,6 @@ public class ClusterConfigImportDUnitTest extends 
ClusterConfigBaseTest {
         .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

http://git-wip-us.apache.org/repos/asf/geode/blob/de135a45/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 2686661..8c0fb45 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
@@ -625,7 +625,7 @@ 
org/apache/geode/management/internal/cli/util/MemberNotFoundException,true,56867
 
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/RecreateCacheFunction,false
-org/apache/geode/management/internal/configuration/functions/RegionsWithDataOnServerFunction,false
+org/apache/geode/management/internal/configuration/functions/GetRegionNamesFunction,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

Reply via email to