You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ji...@apache.org on 2017/01/09 18:18:01 UTC

[1/4] geode git commit: GEODE-2261: do not use remote function calls to update the shared configuration

Repository: geode
Updated Branches:
  refs/heads/develop 95a329638 -> 602ac4f4c


http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-wan/src/test/java/org/apache/geode/management/internal/configuration/WanDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-wan/src/test/java/org/apache/geode/management/internal/configuration/WanDUnitTest.java b/geode-wan/src/test/java/org/apache/geode/management/internal/configuration/WanDUnitTest.java
new file mode 100644
index 0000000..c1aeae6
--- /dev/null
+++ b/geode-wan/src/test/java/org/apache/geode/management/internal/configuration/WanDUnitTest.java
@@ -0,0 +1,159 @@
+/*
+ * 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;
+
+import static org.apache.geode.test.dunit.Assert.assertFalse;
+import static org.apache.geode.test.dunit.Assert.assertNotNull;
+import static org.apache.geode.test.dunit.Assert.assertTrue;
+import static org.apache.geode.test.dunit.IgnoredException.addIgnoredException;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.wan.GatewayReceiver;
+import org.apache.geode.cache.wan.GatewaySender;
+import org.apache.geode.cache.wan.GatewaySender.OrderPolicy;
+import org.apache.geode.management.internal.cli.i18n.CliStrings;
+import org.apache.geode.management.internal.cli.result.CommandResult;
+import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
+import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
+import org.apache.geode.test.dunit.rules.GfshShellConnectionRule;
+import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
+import org.apache.geode.test.dunit.rules.Server;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.Properties;
+import java.util.Set;
+
+@Category(DistributedTest.class)
+public class WanDUnitTest extends JUnit4DistributedTestCase {
+  private org.apache.geode.test.dunit.rules.Locator locator;
+  private GfshShellConnectionRule gfshConnector;
+
+  @Before
+  public void before() throws Exception {
+    locator = lsRule.startLocatorVM(0);
+
+    gfshConnector = new GfshShellConnectionRule(locator);
+    gfshConnector.connect();
+    assertThat(gfshConnector.isConnected()).isTrue();
+
+    // start a server so that we can execute data commands that requires at least a server running
+    lsRule.startServerVM(1, locator.getPort());
+  }
+
+  @Rule
+  public LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
+
+  @Test
+  public void testCreateGatewaySenderReceiver() throws Exception {
+    addIgnoredException("could not get remote locator");
+
+    final String gsId = "GatewaySender1";
+    final String batchSize = "1000";
+    final String dispatcherThreads = "5";
+    final String enableConflation = "false";
+    final String manualStart = "false";
+    final String alertThreshold = "1000";
+    final String batchTimeInterval = "20";
+    final String maxQueueMemory = "100";
+    final String orderPolicy = OrderPolicy.KEY.toString();
+    final String parallel = "true";
+    final String rmDsId = "250";
+    final String socketBufferSize =
+        String.valueOf(GatewaySender.MINIMUM_SOCKET_READ_TIMEOUT + 1000);
+    final String socketReadTimeout =
+        String.valueOf(GatewaySender.MINIMUM_SOCKET_READ_TIMEOUT + 200);
+
+    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_GATEWAYRECEIVER);
+    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYRECEIVER__MANUALSTART, "true");
+    csb.addOption(CliStrings.CREATE_GATEWAYRECEIVER__STARTPORT, "10000");
+    csb.addOption(CliStrings.CREATE_GATEWAYRECEIVER__ENDPORT, "20000");
+    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYRECEIVER__MAXTIMEBETWEENPINGS, "20");
+    gfshConnector.executeAndVerifyCommand(csb.getCommandString());
+
+    csb = new CommandStringBuilder(CliStrings.CREATE_GATEWAYSENDER);
+    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__ID, gsId);
+    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__BATCHSIZE, batchSize);
+    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__ALERTTHRESHOLD, alertThreshold);
+    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__BATCHTIMEINTERVAL,
+        batchTimeInterval);
+    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__DISPATCHERTHREADS,
+        dispatcherThreads);
+    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__ENABLEBATCHCONFLATION,
+        enableConflation);
+    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__MANUALSTART, manualStart);
+    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__MAXQUEUEMEMORY, maxQueueMemory);
+    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__ORDERPOLICY, orderPolicy);
+    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__PARALLEL, parallel);
+    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__REMOTEDISTRIBUTEDSYSTEMID, rmDsId);
+    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__SOCKETBUFFERSIZE,
+        socketBufferSize);
+    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__SOCKETREADTIMEOUT,
+        socketReadTimeout);
+
+    gfshConnector.executeAndVerifyCommand(csb.getCommandString());
+
+    // Start a new member which receives the shared configuration
+    // Verify the config creation on this member
+    Server server = lsRule.startServerVM(2, new Properties(), locator.getPort());
+
+    server.invoke(() -> {
+      Cache cache = LocatorServerStartupRule.serverStarter.cache;
+      assertNotNull(cache);
+
+      // GatewayReceiver verification
+      Set<GatewayReceiver> gatewayReceivers = cache.getGatewayReceivers();
+      assertFalse(gatewayReceivers.isEmpty());
+      assertTrue(gatewayReceivers.size() == 1);
+
+      // Gateway Sender verification
+      GatewaySender gs = cache.getGatewaySender(gsId);
+      assertNotNull(gs);
+      assertTrue(alertThreshold.equals(Integer.toString(gs.getAlertThreshold())));
+      assertTrue(batchSize.equals(Integer.toString(gs.getBatchSize())));
+      assertTrue(dispatcherThreads.equals(Integer.toString(gs.getDispatcherThreads())));
+      assertTrue(enableConflation.equals(Boolean.toString(gs.isBatchConflationEnabled())));
+      assertTrue(manualStart.equals(Boolean.toString(gs.isManualStart())));
+      assertTrue(alertThreshold.equals(Integer.toString(gs.getAlertThreshold())));
+      assertTrue(batchTimeInterval.equals(Integer.toString(gs.getBatchTimeInterval())));
+      assertTrue(maxQueueMemory.equals(Integer.toString(gs.getMaximumQueueMemory())));
+      assertTrue(orderPolicy.equals(gs.getOrderPolicy().toString()));
+      assertTrue(parallel.equals(Boolean.toString(gs.isParallel())));
+      assertTrue(rmDsId.equals(Integer.toString(gs.getRemoteDSId())));
+      assertTrue(socketBufferSize.equals(Integer.toString(gs.getSocketBufferSize())));
+      assertTrue(socketReadTimeout.equals(Integer.toString(gs.getSocketReadTimeout())));
+    });
+  }
+
+  @Test
+  public void testConfigurePDX() throws Exception {
+    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CONFIGURE_PDX);
+    csb.addOptionWithValueCheck(CliStrings.CONFIGURE_PDX__AUTO__SERIALIZER__CLASSES, "com.foo.*");
+    csb.addOptionWithValueCheck(CliStrings.CONFIGURE_PDX__IGNORE__UNREAD_FIELDS, "true");
+    csb.addOptionWithValueCheck(CliStrings.CONFIGURE_PDX__PERSISTENT, "true");
+    csb.addOptionWithValueCheck(CliStrings.CONFIGURE_PDX__READ__SERIALIZED, "true");
+
+    CommandResult result = gfshConnector.executeAndVerifyCommand(csb.getCommandString());
+    String message = (String) result.getResultData().getGfJsonObject().getJSONObject("content")
+        .getJSONArray("message").get(0);
+    assertEquals(CliStrings.CONFIGURE_PDX__NORMAL__MEMBERS__WARNING, message);
+  }
+
+}


[4/4] geode git commit: GEODE-2261: do not use remote function calls to update the shared configuration

Posted by ji...@apache.org.
GEODE-2261: do not use remote function calls to update the shared configuration


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

Branch: refs/heads/develop
Commit: 602ac4f4c8a3d07efb0eeb704d6800dfdf97bb24
Parents: 95a3296
Author: Jinmei Liao <ji...@pivotal.io>
Authored: Wed Dec 28 11:44:58 2016 -0800
Committer: Jinmei Liao <ji...@pivotal.io>
Committed: Mon Jan 9 09:54:27 2017 -0800

----------------------------------------------------------------------
 .../apache/geode/distributed/internal/DM.java   |    2 +
 .../internal/DistributionManager.java           |    8 +
 .../internal/SharedConfiguration.java           |   90 +-
 .../cli/commands/AbstractCommandsSupport.java   |   23 +-
 .../internal/cli/commands/ConfigCommands.java   |   14 +-
 .../CreateAlterDestroyRegionCommands.java       |   88 +-
 .../internal/cli/commands/DeployCommands.java   |   11 +-
 .../cli/commands/DiskStoreCommands.java         |   26 +-
 ...ExportImportSharedConfigurationCommands.java |  136 +--
 .../internal/cli/commands/IndexCommands.java    |   64 +-
 .../internal/cli/commands/PDXCommands.java      |   26 +-
 .../internal/cli/commands/QueueCommands.java    |   20 +-
 .../internal/cli/commands/WanCommands.java      |   34 +-
 .../ExportSharedConfigurationFunction.java      |   72 --
 ...ortSharedConfigurationArtifactsFunction.java |   82 --
 .../LoadSharedConfigurationFunction.java        |   64 --
 .../cli/remote/RemoteExecutionStrategy.java     |    1 +
 .../SharedConfigurationWriter.java              |  160 ---
 .../configuration/functions/AddJarFunction.java |   65 --
 .../functions/AddXmlEntityFunction.java         |   58 -
 .../functions/DeleteJarFunction.java            |   65 --
 .../functions/DeleteXmlEntityFunction.java      |   63 --
 .../ModifyXmlAndPropertiesFunction.java         |   62 -
 .../functions/UploadJarFunction.java            |    9 +-
 .../internal/configuration/utils/XmlUtils.java  |   20 +
 .../internal/SharedConfigurationJUnitTest.java  |   53 -
 .../extension/mock/MockExtensionCommands.java   |   18 +-
 .../cli/commands/ConfigCommandsDUnitTest.java   |   87 +-
 ...eateAlterDestroyRegionCommandsDUnitTest.java |  168 ++-
 .../cli/commands/DeployCommandsDUnitTest.java   |   98 +-
 .../commands/DiskStoreCommandsDUnitTest.java    |   67 +-
 .../cli/commands/IndexCommandsDUnitTest.java    |   78 +-
 .../cli/commands/QueueCommandsDUnitTest.java    |   65 +-
 .../configuration/ClusterConfigBaseTest.java    |    5 +-
 .../ClusterConfigDeployJarDUnitTest.java        |    2 +-
 .../ClusterConfigDistributionDUnitTest.java     |  164 +++
 .../ClusterConfigImportDUnitTest.java           |   10 +-
 .../SharedConfigurationDUnitTest.java           |   36 +-
 .../configuration/utils/XmlUtilsJUnitTest.java  |   18 +
 .../org/apache/geode/redis/SetsJUnitTest.java   |   14 +-
 .../dunit/rules/GfshShellConnectionRule.java    |    9 +
 .../rules/LocatorServerConfigurationRule.java   |  151 +++
 .../dunit/rules/LocatorServerStartupRule.java   |    8 +
 .../internal/SharedConfigurationJUnitTest.xml   |   23 -
 .../utils/SharedConfigurationJUnitTest.xml      |   23 +
 .../ClusterConfigurationDUnitTest.java          | 1055 ------------------
 ...ClusterConfigurationExtensionsDUnitTest.java |  429 +++++++
 .../internal/configuration/WanDUnitTest.java    |  159 +++
 48 files changed, 1686 insertions(+), 2317 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/distributed/internal/DM.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/DM.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/DM.java
index 19381d4..328a4f8 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/DM.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/DM.java
@@ -423,6 +423,8 @@ public interface DM extends ReplySender {
    * Gets the map of all members hosting locators. The key is the member, and the value is a
    * collection of host[port] strings. If a bind-address was used for a locator then the form is
    * bind-addr[port].
+   *
+   *
    * <p>
    * This currently only tracks stand-alone/dedicated locators, not embedded locators.
    * 

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionManager.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionManager.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionManager.java
index 5ae5431..3efbafc 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionManager.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionManager.java
@@ -1662,6 +1662,14 @@ public class DistributionManager implements DM {
    * Returns a copy of the map of all members hosting locators. The key is the member, and the value
    * is a collection of host[port] strings. If a bind-address was used for a locator then the form
    * is bind-addr[port].
+   *
+   * The member is the vm that hosts one or more locator, if another locator starts up linking to
+   * this locator, it will put that member in this map as well, and this member will in the map on
+   * the other locato vm as well.
+   *
+   * The keyset of the map are the locator vms in this cluster.
+   *
+   * the value is a collection of strings in case one vm can have multiple locators ????
    * 
    * @since GemFire 6.6.3
    */

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/distributed/internal/SharedConfiguration.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/SharedConfiguration.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/SharedConfiguration.java
index ec22b02..901b3c9 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/SharedConfiguration.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/SharedConfiguration.java
@@ -38,7 +38,6 @@ import org.apache.geode.internal.cache.InternalRegionArguments;
 import org.apache.geode.internal.cache.persistence.PersistentMemberID;
 import org.apache.geode.internal.cache.persistence.PersistentMemberManager;
 import org.apache.geode.internal.cache.persistence.PersistentMemberPattern;
-import org.apache.geode.internal.cache.xmlcache.CacheXml;
 import org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator;
 import org.apache.geode.internal.lang.StringUtils;
 import org.apache.geode.internal.logging.LogService;
@@ -59,7 +58,6 @@ import org.xml.sax.SAXException;
 import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileFilter;
-import java.io.FileInputStream;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintWriter;
@@ -76,13 +74,10 @@ import java.util.Objects;
 import java.util.Properties;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicReference;
-import java.util.stream.Collector;
 import java.util.stream.Collectors;
-import java.util.stream.Stream;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactoryConfigurationError;
-import javax.xml.xpath.XPathExpressionException;
 
 @SuppressWarnings({"deprecation", "unchecked"})
 public class SharedConfiguration {
@@ -141,9 +136,10 @@ public class SharedConfiguration {
 
   public SharedConfiguration(Cache cache) throws IOException {
     this.cache = (GemFireCacheImpl) cache;
+    Properties properties = cache.getDistributedSystem().getProperties();
     // resolve the cluster config dir
-    String clusterConfigRootDir =
-        cache.getDistributedSystem().getProperties().getProperty(CLUSTER_CONFIGURATION_DIR);
+    String clusterConfigRootDir = properties.getProperty(CLUSTER_CONFIGURATION_DIR);
+
     if (StringUtils.isBlank(clusterConfigRootDir)) {
       clusterConfigRootDir = System.getProperty("user.dir");
     } else {
@@ -169,7 +165,7 @@ public class SharedConfiguration {
    * Adds/replaces the xml entity in the shared configuration we don't need to trigger the change
    * listener for this modification, so it's ok to operate on the original configuration object
    */
-  public void addXmlEntity(XmlEntity xmlEntity, String[] groups) throws Exception {
+  public void addXmlEntity(XmlEntity xmlEntity, String[] groups) {
     Region<String, Configuration> configRegion = getConfigurationRegion();
     if (groups == null || groups.length == 0) {
       groups = new String[] {SharedConfiguration.CLUSTER_CONFIG};
@@ -186,17 +182,21 @@ public class SharedConfiguration {
         CacheXmlGenerator.generateDefault(pw);
         xmlContent = sw.toString();
       }
-      final Document doc = createAndUpgradeDocumentFromXml(xmlContent);
-      XmlUtils.addNewNode(doc, xmlEntity);
-      configuration.setCacheXmlContent(XmlUtils.prettyXml(doc));
-      configRegion.put(group, configuration);
+      try {
+        final Document doc = XmlUtils.createAndUpgradeDocumentFromXml(xmlContent);
+        XmlUtils.addNewNode(doc, xmlEntity);
+        configuration.setCacheXmlContent(XmlUtils.prettyXml(doc));
+        configRegion.put(group, configuration);
+      } catch (Exception e) {
+        logger.error("error updating cluster configuration for group " + group, e);
+      }
     }
   }
 
   /**
    * Deletes the xml entity from the shared configuration.
    */
-  public void deleteXmlEntity(final XmlEntity xmlEntity, String[] groups) throws Exception {
+  public void deleteXmlEntity(final XmlEntity xmlEntity, String[] groups) {
     Region<String, Configuration> configRegion = getConfigurationRegion();
     // No group is specified, so delete in every single group if it exists.
     if (groups == null) {
@@ -207,11 +207,15 @@ public class SharedConfiguration {
       Configuration configuration = (Configuration) configRegion.get(group);
       if (configuration != null) {
         String xmlContent = configuration.getCacheXmlContent();
-        if (xmlContent != null && !xmlContent.isEmpty()) {
-          Document doc = createAndUpgradeDocumentFromXml(xmlContent);
-          XmlUtils.deleteNode(doc, xmlEntity);
-          configuration.setCacheXmlContent(XmlUtils.prettyXml(doc));
-          configRegion.put(group, configuration);
+        try {
+          if (xmlContent != null && !xmlContent.isEmpty()) {
+            Document doc = XmlUtils.createAndUpgradeDocumentFromXml(xmlContent);
+            XmlUtils.deleteNode(doc, xmlEntity);
+            configuration.setCacheXmlContent(XmlUtils.prettyXml(doc));
+            configRegion.put(group, configuration);
+          }
+        } catch (Exception e) {
+          logger.error("error updating cluster configuration for group " + group, e);
         }
       }
     }
@@ -219,8 +223,7 @@ public class SharedConfiguration {
 
   // we don't need to trigger the change listener for this modification, so it's ok to
   // operate on the original configuration object
-  public void modifyXmlAndProperties(Properties properties, XmlEntity xmlEntity, String[] groups)
-      throws Exception {
+  public void modifyXmlAndProperties(Properties properties, XmlEntity xmlEntity, String[] groups) {
     if (groups == null) {
       groups = new String[] {SharedConfiguration.CLUSTER_CONFIG};
     }
@@ -239,14 +242,15 @@ public class SharedConfiguration {
           CacheXmlGenerator.generateDefault(pw);
           xmlContent = sw.toString();
         }
-
-        Document doc = createAndUpgradeDocumentFromXml(xmlContent);
-
-        // Modify the cache attributes
-        XmlUtils.modifyRootAttributes(doc, xmlEntity);
-
-        // Change the xml content of the configuration and put it the config region
-        configuration.setCacheXmlContent(XmlUtils.prettyXml(doc));
+        try {
+          Document doc = XmlUtils.createAndUpgradeDocumentFromXml(xmlContent);
+          // Modify the cache attributes
+          XmlUtils.modifyRootAttributes(doc, xmlEntity);
+          // Change the xml content of the configuration and put it the config region
+          configuration.setCacheXmlContent(XmlUtils.prettyXml(doc));
+        } catch (Exception e) {
+          logger.error("error updating cluster configuration for group " + group, e);
+        }
       }
 
       if (properties != null) {
@@ -290,7 +294,9 @@ public class SharedConfiguration {
         }
 
         // update the record after writing the jars to the file system, since the listener
-        // will need the jars on file to upload to other locators.
+        // will need the jars on file to upload to other locators. Need to update the jars
+        // using a new copy of the Configuration so that the change listener will pick up the jar
+        // name changes.
         Configuration configurationCopy = new Configuration(configuration);
         configurationCopy.addJarNames(jarNames);
         configRegion.put(group, configurationCopy);
@@ -310,12 +316,12 @@ public class SharedConfiguration {
   public byte[] getJarBytesFromThisLocator(String group, String jarName) throws Exception {
     Configuration configuration = getConfiguration(group);
 
-    // TODO: Should we check like this, or just check jar.exists below()?
-    if (configuration == null || !configuration.getJarNames().contains(jarName)) {
+    File jar = getPathToJarOnThisLocator(group, jarName).toFile();
+
+    if (configuration == null || !configuration.getJarNames().contains(jarName) || !jar.exists()) {
       return null;
     }
 
-    File jar = getPathToJarOnThisLocator(group, jarName).toFile();
     return FileUtils.readFileToByteArray(jar);
   }
 
@@ -738,24 +744,4 @@ public class SharedConfiguration {
 
     return configDir;
   }
-
-  /**
-   * Create a {@link Document} using {@link XmlUtils#createDocumentFromXml(String)} and if the
-   * version attribute is not equal to the current version then update the XML to the current schema
-   * and return the document.
-   * 
-   * @param xmlContent XML content to load and upgrade.
-   * @return {@link Document} from xmlContent.
-   * @since GemFire 8.1
-   */
-  static Document createAndUpgradeDocumentFromXml(final String xmlContent)
-      throws SAXException, ParserConfigurationException, IOException, XPathExpressionException {
-    Document doc = XmlUtils.createDocumentFromXml(xmlContent);
-    if (!CacheXml.VERSION_LATEST.equals(XmlUtils.getAttribute(doc.getDocumentElement(),
-        CacheXml.VERSION, CacheXml.GEODE_NAMESPACE))) {
-      doc = XmlUtils.upgradeSchema(doc, CacheXml.GEODE_NAMESPACE, CacheXml.LATEST_SCHEMA_LOCATION,
-          CacheXml.VERSION_LATEST);
-    }
-    return doc;
-  }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AbstractCommandsSupport.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AbstractCommandsSupport.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AbstractCommandsSupport.java
index 6db6415..41671a4 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AbstractCommandsSupport.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AbstractCommandsSupport.java
@@ -21,9 +21,12 @@ import org.apache.geode.cache.execute.Execution;
 import org.apache.geode.cache.execute.Function;
 import org.apache.geode.cache.execute.FunctionService;
 import org.apache.geode.distributed.DistributedMember;
+import org.apache.geode.distributed.internal.InternalLocator;
+import org.apache.geode.distributed.internal.SharedConfiguration;
 import org.apache.geode.internal.lang.StringUtils;
 import org.apache.geode.internal.security.SecurityService;
 import org.apache.geode.management.cli.CliMetaData;
+import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
 import org.apache.geode.management.internal.cli.shell.Gfsh;
 import org.apache.geode.management.internal.cli.util.MemberNotFoundException;
@@ -97,6 +100,24 @@ public abstract class AbstractCommandsSupport implements CommandMarker {
     return (getGfsh() != null && getGfsh().isConnectedAndReady());
   }
 
+  protected SharedConfiguration getSharedConfiguration() {
+    InternalLocator locator = InternalLocator.getLocator();
+    return (locator == null) ? null : locator.getSharedConfiguration();
+  }
+
+  protected void persistClusterConfiguration(Result result, Runnable runnable) {
+    if (result == null) {
+      throw new IllegalArgumentException("Result should not be null");
+    }
+    SharedConfiguration sc = getSharedConfiguration();
+    if (sc == null) {
+      result.setCommandPersisted(false);
+    } else {
+      runnable.run();
+      result.setCommandPersisted(true);
+    }
+  }
+
   protected boolean isDebugging() {
     return (getGfsh() != null && getGfsh().getDebug());
   }
@@ -109,7 +130,7 @@ public abstract class AbstractCommandsSupport implements CommandMarker {
     return CacheFactory.getAnyInstance();
   }
 
-  protected Gfsh getGfsh() {
+  protected static Gfsh getGfsh() {
     return Gfsh.getCurrentInstance();
   }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConfigCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConfigCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConfigCommands.java
index 4eac4e9..5154b75 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConfigCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConfigCommands.java
@@ -53,8 +53,6 @@ import org.apache.geode.management.internal.cli.result.ErrorResultData;
 import org.apache.geode.management.internal.cli.result.InfoResultData;
 import org.apache.geode.management.internal.cli.result.ResultBuilder;
 import org.apache.geode.management.internal.cli.result.TabularResultData;
-import org.apache.geode.management.internal.cli.shell.Gfsh;
-import org.apache.geode.management.internal.configuration.SharedConfigurationWriter;
 import org.apache.geode.management.internal.configuration.domain.XmlEntity;
 import org.apache.geode.management.internal.security.ResourceOperation;
 import org.apache.geode.security.ResourcePermission.Operation;
@@ -69,17 +67,13 @@ import org.springframework.shell.core.annotation.CliOption;
  * @since GemFire 7.0
  *
  */
-public class ConfigCommands implements CommandMarker {
+public class ConfigCommands extends AbstractCommandsSupport {
   private final ExportConfigFunction exportConfigFunction = new ExportConfigFunction();
   private final GetMemberConfigInformationFunction getMemberConfigFunction =
       new GetMemberConfigInformationFunction();
   private final AlterRuntimeConfigFunction alterRunTimeConfigFunction =
       new AlterRuntimeConfigFunction();
 
-  private static Gfsh getGfsh() {
-    return Gfsh.getCurrentInstance();
-  }
-
   @CliCommand(value = {CliStrings.DESCRIBE_CONFIG}, help = CliStrings.DESCRIBE_CONFIG__HELP)
   @CliMetaData(shellOnly = false, relatedTopic = {CliStrings.TOPIC_GEODE_CONFIG})
   @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
@@ -427,9 +421,9 @@ public class ConfigCommands implements CommandMarker {
           // Set the Cache attributes to be modified
           final XmlEntity xmlEntity = XmlEntity.builder().withType(CacheXml.CACHE)
               .withAttributes(rumTimeCacheAttributes).build();
-          result.setCommandPersisted(
-              new SharedConfigurationWriter().modifyPropertiesAndCacheAttributes(properties,
-                  xmlEntity, group != null ? group.split(",") : null));
+          persistClusterConfiguration(result,
+              () -> getSharedConfiguration().modifyXmlAndProperties(properties, xmlEntity,
+                  group != null ? group.split(",") : null));
           return result;
         } else {
           StringBuilder errorMessageBuilder = new StringBuilder();

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java
index 358cdc1..7df4112 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java
@@ -14,29 +14,16 @@
  */
 package org.apache.geode.management.internal.cli.commands;
 
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.TreeSet;
-import java.util.regex.Pattern;
-
-import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-
-import org.apache.geode.cache.*;
-import org.springframework.shell.core.annotation.CliAvailabilityIndicator;
-import org.springframework.shell.core.annotation.CliCommand;
-import org.springframework.shell.core.annotation.CliOption;
-
 import org.apache.geode.LogWriter;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.cache.DataPolicy;
+import org.apache.geode.cache.ExpirationAttributes;
+import org.apache.geode.cache.PartitionResolver;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionAttributes;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.Scope;
 import org.apache.geode.cache.execute.ResultCollector;
 import org.apache.geode.compression.Compressor;
 import org.apache.geode.distributed.DistributedMember;
@@ -72,14 +59,32 @@ import org.apache.geode.management.internal.cli.result.CommandResultException;
 import org.apache.geode.management.internal.cli.result.ResultBuilder;
 import org.apache.geode.management.internal.cli.result.TabularResultData;
 import org.apache.geode.management.internal.cli.util.RegionPath;
-import org.apache.geode.management.internal.configuration.SharedConfigurationWriter;
 import org.apache.geode.management.internal.configuration.domain.XmlEntity;
 import org.apache.geode.management.internal.security.ResourceOperation;
 import org.apache.geode.security.ResourcePermission.Operation;
 import org.apache.geode.security.ResourcePermission.Resource;
+import org.springframework.shell.core.annotation.CliAvailabilityIndicator;
+import org.springframework.shell.core.annotation.CliCommand;
+import org.springframework.shell.core.annotation.CliOption;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.regex.Pattern;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
 
 /**
- *
  * @since GemFire 7.0
  */
 public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport {
@@ -225,7 +230,7 @@ public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport {
   // NOTICE: keep the region attributes params in alphabetical order
   ) {
     Result result = null;
-    XmlEntity xmlEntity = null;
+    AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
 
     try {
       Cache cache = CacheFactory.getAnyInstance();
@@ -274,12 +279,10 @@ public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport {
               new Object[] {CliStrings.CREATE_REGION__USEATTRIBUTESFROM, useAttributesFrom}));
         }
 
-
         FetchRegionAttributesFunctionResult<Object, Object> regionAttributesResult =
             getRegionAttributes(cache, useAttributesFrom);
         RegionAttributes<?, ?> regionAttributes = regionAttributesResult.getRegionAttributes();
 
-
         // give preference to user specified plugins than the ones retrieved from other region
         String[] cacheListenerClasses = cacheListener != null && cacheListener.length != 0
             ? cacheListener : regionAttributesResult.getCacheListenerClasses();
@@ -297,7 +300,6 @@ public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport {
             prStartupRecoveryDelay, prTotalMaxMemory, prTotalNumBuckets, offHeap, mcastEnabled,
             regionAttributes, partitionResolver);
 
-
         if (regionAttributes.getPartitionAttributes() == null
             && regionFunctionArgs.hasPartitionAttributes()) {
           throw new IllegalArgumentException(CliStrings.format(
@@ -362,7 +364,7 @@ public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport {
             (success ? "" : errorPrefix) + regionCreateResult.getMessage());
 
         if (success) {
-          xmlEntity = regionCreateResult.getXmlEntity();
+          xmlEntity.set(regionCreateResult.getXmlEntity());
         }
       }
       result = ResultBuilder.buildResult(tabularResultData);
@@ -379,9 +381,11 @@ public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport {
       result = ResultBuilder.createGemFireErrorResult(e.getMessage());
 
     }
-    if (xmlEntity != null) {
-      result.setCommandPersisted((new SharedConfigurationWriter()).addXmlEntity(xmlEntity, groups));
+    if (xmlEntity.get() != null) {
+      persistClusterConfiguration(result,
+          () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), groups));
     }
+
     return result;
   }
 
@@ -478,7 +482,7 @@ public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport {
           unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = "0",
           help = CliStrings.ALTER_REGION__EVICTIONMAX__HELP) Integer evictionMax) {
     Result result = null;
-    XmlEntity xmlEntity = null;
+    AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
 
     this.securityService.authorizeRegionManage(regionPath);
 
@@ -595,7 +599,7 @@ public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport {
         tabularResultData.accumulate("Member", regionAlterResult.getMemberIdOrName());
         if (success) {
           tabularResultData.accumulate("Status", regionAlterResult.getMessage());
-          xmlEntity = regionAlterResult.getXmlEntity();
+          xmlEntity.set(regionAlterResult.getXmlEntity());
         } else {
           tabularResultData.accumulate("Status", errorPrefix + regionAlterResult.getMessage());
           tabularResultData.setStatus(Status.ERROR);
@@ -612,8 +616,10 @@ public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport {
       LogWrapper.getInstance().info(e.getMessage(), e);
       result = ResultBuilder.createGemFireErrorResult(e.getMessage());
     }
-    if (xmlEntity != null) {
-      result.setCommandPersisted((new SharedConfigurationWriter()).addXmlEntity(xmlEntity, groups));
+
+    if (xmlEntity.get() != null) {
+      persistClusterConfiguration(result,
+          () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), groups));
     }
     return result;
   }
@@ -989,7 +995,6 @@ public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport {
       } // regionAssociatedMembers is not-empty
     } // attributes are null because do not exist on local member
 
-
     return attributes;
   }
 
@@ -1054,7 +1059,7 @@ public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport {
     }
 
     Result result = null;
-    XmlEntity xmlEntity = null;
+    AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
     try {
       String message = "";
       Cache cache = CacheFactory.getAnyInstance();
@@ -1087,7 +1092,7 @@ public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport {
       for (int i = 0; i < resultsList.size(); i++) {
         destroyRegionResult = resultsList.get(i);
         if (destroyRegionResult.isSuccessful()) {
-          xmlEntity = destroyRegionResult.getXmlEntity();
+          xmlEntity.set(destroyRegionResult.getXmlEntity());
         } else if (destroyRegionResult.getThrowable() != null) {
           Throwable t = destroyRegionResult.getThrowable();
           LogWrapper.getInstance().info(t.getMessage(), t);
@@ -1117,10 +1122,11 @@ public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport {
           new Object[] {regionPath, e.getMessage()}));
     }
 
-    if (xmlEntity != null) {
-      result
-          .setCommandPersisted((new SharedConfigurationWriter()).deleteXmlEntity(xmlEntity, null));
+    if (xmlEntity.get() != null) {
+      persistClusterConfiguration(result,
+          () -> getSharedConfiguration().deleteXmlEntity(xmlEntity.get(), null));
     }
+
     return result;
   }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommands.java
index 7c887be..f076cec 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommands.java
@@ -34,7 +34,6 @@ import org.apache.geode.management.internal.cli.result.CommandResultException;
 import org.apache.geode.management.internal.cli.result.FileResult;
 import org.apache.geode.management.internal.cli.result.ResultBuilder;
 import org.apache.geode.management.internal.cli.result.TabularResultData;
-import org.apache.geode.management.internal.configuration.SharedConfigurationWriter;
 import org.apache.geode.management.internal.security.ResourceOperation;
 import org.apache.geode.security.NotAuthorizedException;
 import org.apache.geode.security.ResourcePermission.Operation;
@@ -59,7 +58,7 @@ import java.util.Set;
  * @see org.apache.geode.management.internal.cli.commands.AbstractCommandsSupport
  * @since GemFire 7.0
  */
-public final class DeployCommands extends AbstractCommandsSupport implements CommandMarker {
+public final class DeployCommands extends AbstractCommandsSupport {
 
   private final DeployFunction deployFunction = new DeployFunction();
   private final UndeployFunction undeployFunction = new UndeployFunction();
@@ -142,8 +141,8 @@ public final class DeployCommands extends AbstractCommandsSupport implements Com
 
       Result result = ResultBuilder.buildResult(tabularData);
       if (tabularData.getStatus().equals(Status.OK)) {
-        result.setCommandPersisted(
-            (new SharedConfigurationWriter()).addJars(jarNames, jarBytes, groups));
+        persistClusterConfiguration(result,
+            () -> getSharedConfiguration().addJarsToThisLocator(jarNames, jarBytes, groups));
       }
       return result;
     } catch (NotAuthorizedException e) {
@@ -218,8 +217,8 @@ public final class DeployCommands extends AbstractCommandsSupport implements Com
 
       Result result = ResultBuilder.buildResult(tabularData);
       if (tabularData.getStatus().equals(Status.OK)) {
-        result.setCommandPersisted((new SharedConfigurationWriter())
-            .deleteJars(jars == null ? null : jars.split(","), groups));
+        persistClusterConfiguration(result, () -> getSharedConfiguration()
+            .removeJars(jars == null ? null : jars.split(","), groups));
       }
       return result;
     } catch (VirtualMachineError e) {

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommands.java
index 505b6a8..14114cf 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommands.java
@@ -32,6 +32,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.geode.GemFireIOException;
 import org.apache.geode.SystemFailure;
@@ -89,7 +90,6 @@ import org.apache.geode.management.internal.cli.util.DiskStoreNotFoundException;
 import org.apache.geode.management.internal.cli.util.DiskStoreUpgrader;
 import org.apache.geode.management.internal.cli.util.DiskStoreValidater;
 import org.apache.geode.management.internal.cli.util.MemberNotFoundException;
-import org.apache.geode.management.internal.configuration.SharedConfigurationWriter;
 import org.apache.geode.management.internal.configuration.domain.XmlEntity;
 import org.apache.geode.management.internal.messages.CompactRequest;
 import org.apache.geode.management.internal.security.ResourceOperation;
@@ -377,7 +377,7 @@ public class DiskStoreCommands extends AbstractCommandsSupport {
           new Object[] {name, diskStoreAttributes}, targetMembers);
       List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult());
 
-      XmlEntity xmlEntity = null;
+      AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
       for (CliFunctionResult result : results) {
         if (result.getThrowable() != null) {
           tabularData.accumulate("Member", result.getMemberIdOrName());
@@ -390,8 +390,8 @@ public class DiskStoreCommands extends AbstractCommandsSupport {
           tabularData.accumulate("Result", result.getMessage());
           accumulatedData = true;
 
-          if (xmlEntity == null) {
-            xmlEntity = result.getXmlEntity();
+          if (xmlEntity.get() == null) {
+            xmlEntity.set(result.getXmlEntity());
           }
         }
       }
@@ -402,9 +402,9 @@ public class DiskStoreCommands extends AbstractCommandsSupport {
 
       Result result = ResultBuilder.buildResult(tabularData);
 
-      if (xmlEntity != null) {
-        result
-            .setCommandPersisted((new SharedConfigurationWriter()).addXmlEntity(xmlEntity, groups));
+      if (xmlEntity.get() != null) {
+        persistClusterConfiguration(result,
+            () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), groups));
       }
 
       return ResultBuilder.buildResult(tabularData);
@@ -1459,7 +1459,7 @@ public class DiskStoreCommands extends AbstractCommandsSupport {
           new Object[] {name}, targetMembers);
       List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult());
 
-      XmlEntity xmlEntity = null;
+      AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
       for (CliFunctionResult result : results) {
         if (result.getThrowable() != null) {
           tabularData.accumulate("Member", result.getMemberIdOrName());
@@ -1472,8 +1472,8 @@ public class DiskStoreCommands extends AbstractCommandsSupport {
           tabularData.accumulate("Result", result.getMessage());
           accumulatedData = true;
 
-          if (xmlEntity == null) {
-            xmlEntity = result.getXmlEntity();
+          if (xmlEntity.get() == null) {
+            xmlEntity.set(result.getXmlEntity());
           }
         }
       }
@@ -1484,9 +1484,9 @@ public class DiskStoreCommands extends AbstractCommandsSupport {
       }
 
       Result result = ResultBuilder.buildResult(tabularData);
-      if (xmlEntity != null) {
-        result.setCommandPersisted(
-            (new SharedConfigurationWriter()).deleteXmlEntity(xmlEntity, groups));
+      if (xmlEntity.get() != null) {
+        persistClusterConfiguration(result,
+            () -> getSharedConfiguration().deleteXmlEntity(xmlEntity.get(), groups));
       }
 
       return result;

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportSharedConfigurationCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportSharedConfigurationCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportSharedConfigurationCommands.java
index 3a2d949..59740e9 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportSharedConfigurationCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportSharedConfigurationCommands.java
@@ -14,30 +14,29 @@
  */
 package org.apache.geode.management.internal.cli.commands;
 
-import org.apache.geode.cache.execute.ResultCollector;
-import org.apache.geode.distributed.DistributedMember;
-import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.commons.io.FileUtils;
+import org.apache.geode.distributed.internal.InternalLocator;
+import org.apache.geode.distributed.internal.SharedConfiguration;
 import org.apache.geode.internal.cache.GemFireCacheImpl;
 import org.apache.geode.internal.lang.StringUtils;
+import org.apache.geode.internal.logging.LogService;
 import org.apache.geode.management.cli.CliMetaData;
 import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.cli.AbstractCliAroundInterceptor;
 import org.apache.geode.management.internal.cli.CliUtil;
 import org.apache.geode.management.internal.cli.GfshParseResult;
-import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
-import org.apache.geode.management.internal.cli.functions.ExportSharedConfigurationFunction;
-import org.apache.geode.management.internal.cli.functions.ImportSharedConfigurationArtifactsFunction;
-import org.apache.geode.management.internal.cli.functions.LoadSharedConfigurationFunction;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
 import org.apache.geode.management.internal.cli.remote.CommandExecutionContext;
 import org.apache.geode.management.internal.cli.result.ErrorResultData;
 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.cli.result.TabularResultData;
+import org.apache.geode.management.internal.configuration.domain.Configuration;
+import org.apache.geode.management.internal.configuration.utils.ZipUtils;
 import org.apache.geode.management.internal.security.ResourceOperation;
 import org.apache.geode.security.ResourcePermission.Operation;
 import org.apache.geode.security.ResourcePermission.Resource;
+import org.apache.logging.log4j.Logger;
 import org.springframework.shell.core.annotation.CliAvailabilityIndicator;
 import org.springframework.shell.core.annotation.CliCommand;
 import org.springframework.shell.core.annotation.CliOption;
@@ -45,12 +44,7 @@ import org.springframework.shell.core.annotation.CliOption;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
 
 /****
  * Commands for the shared configuration
@@ -58,14 +52,6 @@ import java.util.Set;
  */
 @SuppressWarnings("unused")
 public class ExportImportSharedConfigurationCommands extends AbstractCommandsSupport {
-
-  private final ExportSharedConfigurationFunction exportSharedConfigurationFunction =
-      new ExportSharedConfigurationFunction();
-  private final ImportSharedConfigurationArtifactsFunction importSharedConfigurationFunction =
-      new ImportSharedConfigurationArtifactsFunction();
-  private final LoadSharedConfigurationFunction loadSharedConfiguration =
-      new LoadSharedConfigurationFunction();
-
   @CliCommand(value = {CliStrings.EXPORT_SHARED_CONFIG},
       help = CliStrings.EXPORT_SHARED_CONFIG__HELP)
   @CliMetaData(
@@ -78,38 +64,39 @@ public class ExportImportSharedConfigurationCommands extends AbstractCommandsSup
       @CliOption(key = {CliStrings.EXPORT_SHARED_CONFIG__DIR},
           help = CliStrings.EXPORT_SHARED_CONFIG__DIR__HELP) String dir) {
 
-    GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
-    Set<? extends DistributedMember> locators =
-        cache.getDistributionManager().getAllHostedLocatorsWithSharedConfiguration().keySet();
+    InternalLocator locator = InternalLocator.getLocator();
+    if (!locator.isSharedConfigurationRunning()) {
+      return ResultBuilder.createGemFireErrorResult(CliStrings.SHARED_CONFIGURATION_NOT_STARTED);
+    }
 
-    Optional<CliFunctionResult> functionResult = locators.stream()
-        .map((DistributedMember locator) -> exportSharedConfigurationFromLocator(locator, null))
-        .filter(CliFunctionResult::isSuccessful).findFirst();
+    SharedConfiguration sc = locator.getSharedConfiguration();
+    File zipFile = new File(zipFileName);
+    zipFile.getParentFile().mkdirs();
 
     Result result;
-    if (functionResult.isPresent()) {
+    try {
+      for (Configuration config : sc.getEntireConfiguration().values()) {
+        sc.writeConfig(config);
+      }
+      ZipUtils.zip(sc.getSharedConfigurationDirPath(), zipFile.getCanonicalPath());
+
       InfoResultData infoData = ResultBuilder.createInfoResultData();
-      byte[] byteData = functionResult.get().getByteData();
+      byte[] byteData = FileUtils.readFileToByteArray(zipFile);
       infoData.addAsFile(zipFileName, byteData, InfoResultData.FILE_TYPE_BINARY,
           CliStrings.EXPORT_SHARED_CONFIG__DOWNLOAD__MSG, false);
       result = ResultBuilder.buildResult(infoData);
-    } else {
+    } catch (Exception e) {
       ErrorResultData errorData = ResultBuilder.createErrorResultData();
       errorData.addLine("Export failed");
+      logSevere(e);
       result = ResultBuilder.buildResult(errorData);
+    } finally {
+      zipFile.delete();
     }
 
     return result;
   }
 
-  private CliFunctionResult exportSharedConfigurationFromLocator(DistributedMember locator,
-      Object[] args) {
-    ResultCollector rc = CliUtil.executeFunction(exportSharedConfigurationFunction, args, locator);
-    List<CliFunctionResult> results = (List<CliFunctionResult>) rc.getResult();
-
-    return results.get(0);
-  }
-
 
   @CliCommand(value = {CliStrings.IMPORT_SHARED_CONFIG},
       help = CliStrings.IMPORT_SHARED_CONFIG__HELP)
@@ -128,50 +115,50 @@ public class ExportImportSharedConfigurationCommands extends AbstractCommandsSup
           .createGemFireErrorResult(CliStrings.IMPORT_SHARED_CONFIG__CANNOT__IMPORT__MSG);
     }
 
-    Set<? extends DistributedMember> locators =
-        cache.getDistributionManager().getAllHostedLocatorsWithSharedConfiguration().keySet();
+    byte[][] shellBytesData = CommandExecutionContext.getBytesFromShell();
+    String zipFileName = CliUtil.bytesToNames(shellBytesData)[0];
+    byte[] zipBytes = CliUtil.bytesToData(shellBytesData)[0];
+
+    InternalLocator locator = InternalLocator.getLocator();
 
-    if (locators.isEmpty()) {
-      return ResultBuilder.createGemFireErrorResult(CliStrings.NO_LOCATORS_WITH_SHARED_CONFIG);
+    if (!locator.isSharedConfigurationRunning()) {
+      ErrorResultData errorData = ResultBuilder.createErrorResultData();
+      errorData.addLine(CliStrings.SHARED_CONFIGURATION_NOT_STARTED);
+      return ResultBuilder.buildResult(errorData);
     }
 
     Result result;
-    byte[][] shellBytesData = CommandExecutionContext.getBytesFromShell();
-    String[] names = CliUtil.bytesToNames(shellBytesData);
-    byte[][] bytes = CliUtil.bytesToData(shellBytesData);
-
-    String zipFileName = names[0];
-    byte[] zipBytes = bytes[0];
+    File zipFile = new File(zipFileName);
+    try {
+      SharedConfiguration sc = locator.getSharedConfiguration();
 
-    Object[] args = new Object[] {zipFileName, zipBytes};
+      // backup the old config
+      for (Configuration config : sc.getEntireConfiguration().values()) {
+        sc.writeConfig(config);
+      }
+      sc.renameExistingSharedConfigDirectory();
 
+      sc.clearSharedConfiguration();
+      FileUtils.writeByteArrayToFile(zipFile, zipBytes);
+      ZipUtils.unzip(zipFileName, sc.getSharedConfigurationDirPath());
 
-    Optional<CliFunctionResult> functionResult = locators.stream()
-        .map((DistributedMember locator) -> importSharedConfigurationFromLocator(locator, args))
-        .filter(CliFunctionResult::isSuccessful).findFirst();
+      // load it from the disk
+      sc.loadSharedConfigurationFromDisk();
 
-    if (functionResult.isPresent()) {
       InfoResultData infoData = ResultBuilder.createInfoResultData();
-      infoData.addLine(functionResult.get().getMessage());
+      infoData.addLine(CliStrings.IMPORT_SHARED_CONFIG__SUCCESS__MSG);
       result = ResultBuilder.buildResult(infoData);
-    } else {
+    } catch (Exception e) {
       ErrorResultData errorData = ResultBuilder.createErrorResultData();
       errorData.addLine("Import failed");
+      logSevere(e);
       result = ResultBuilder.buildResult(errorData);
+    } finally {
+      FileUtils.deleteQuietly(zipFile);
     }
-
     return result;
   }
 
-  private CliFunctionResult importSharedConfigurationFromLocator(DistributedMember locator,
-      Object[] args) {
-    ResultCollector rc = CliUtil.executeFunction(importSharedConfigurationFunction, args, locator);
-    List<CliFunctionResult> results = (List<CliFunctionResult>) rc.getResult();
-
-    return results.get(0);
-  }
-
-
   @CliAvailabilityIndicator({CliStrings.EXPORT_SHARED_CONFIG, CliStrings.IMPORT_SHARED_CONFIG})
   public boolean sharedConfigCommandsAvailable() {
     boolean isAvailable = true; // always available on server
@@ -186,6 +173,7 @@ public class ExportImportSharedConfigurationCommands extends AbstractCommandsSup
    */
   public static class ExportInterceptor extends AbstractCliAroundInterceptor {
     private String saveDirString;
+    private static final Logger logger = LogService.getLogger();
 
     @Override
     public Result preExecution(GfshParseResult parseResult) {
@@ -212,28 +200,28 @@ public class ExportImportSharedConfigurationCommands extends AbstractCommandsSup
           if (dir != null && !dir.isEmpty()) {
             saveDirFile = new File(dir);
             if (saveDirFile.exists()) {
-              if (!saveDirFile.isDirectory())
+              if (!saveDirFile.isDirectory()) {
                 return ResultBuilder.createGemFireErrorResult(
                     CliStrings.format(CliStrings.EXPORT_SHARED_CONFIG__MSG__NOT_A_DIRECTORY, dir));
+              }
             } else if (!saveDirFile.mkdirs()) {
               return ResultBuilder.createGemFireErrorResult(
                   CliStrings.format(CliStrings.EXPORT_SHARED_CONFIG__MSG__CANNOT_CREATE_DIR, dir));
             }
           }
-          try {
-            if (!saveDirFile.canWrite()) {
-              return ResultBuilder.createGemFireErrorResult(
-                  CliStrings.format(CliStrings.EXPORT_SHARED_CONFIG__MSG__NOT_WRITEABLE,
-                      saveDirFile.getCanonicalPath()));
-            }
-          } catch (IOException ioex) {
+          if (!saveDirFile.canWrite()) {
+            return ResultBuilder.createGemFireErrorResult(
+                CliStrings.format(CliStrings.EXPORT_SHARED_CONFIG__MSG__NOT_WRITEABLE,
+                    saveDirFile.getCanonicalPath()));
           }
           saveDirString = saveDirFile.getAbsolutePath();
           commandResult.saveIncomingFiles(saveDirString);
           return commandResult;
         } catch (IOException ioex) {
+          logger.error(ioex);
           return ResultBuilder.createShellClientErrorResult(
-              CliStrings.EXPORT_SHARED_CONFIG__UNABLE__TO__EXPORT__CONFIG);
+              CliStrings.EXPORT_SHARED_CONFIG__UNABLE__TO__EXPORT__CONFIG + ": "
+                  + ioex.getMessage());
         }
       }
       return null;

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommands.java
index adb03c6..bc436ba 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommands.java
@@ -14,15 +14,6 @@
  */
 package org.apache.geode.management.internal.cli.commands;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-
 import org.apache.geode.SystemFailure;
 import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.CacheFactory;
@@ -53,16 +44,24 @@ import org.apache.geode.management.internal.cli.result.ErrorResultData;
 import org.apache.geode.management.internal.cli.result.InfoResultData;
 import org.apache.geode.management.internal.cli.result.ResultBuilder;
 import org.apache.geode.management.internal.cli.result.TabularResultData;
-import org.apache.geode.management.internal.configuration.SharedConfigurationWriter;
 import org.apache.geode.management.internal.configuration.domain.XmlEntity;
 import org.apache.geode.management.internal.security.ResourceOperation;
 import org.apache.geode.security.ResourcePermission.Operation;
 import org.apache.geode.security.ResourcePermission.Resource;
-
 import org.springframework.shell.core.annotation.CliAvailabilityIndicator;
 import org.springframework.shell.core.annotation.CliCommand;
 import org.springframework.shell.core.annotation.CliOption;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.concurrent.atomic.AtomicReference;
+
 /**
  * The IndexCommands class encapsulates all GemFire shell (Gfsh) commands related to indexes defined
  * in GemFire.
@@ -199,7 +198,7 @@ public class IndexCommands extends AbstractCommandsSupport {
           help = CliStrings.CREATE_INDEX__GROUP__HELP) final String group) {
 
     Result result = null;
-    XmlEntity xmlEntity = null;
+    AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
 
     this.securityService.authorizeRegionManage(regionPath);
     try {
@@ -253,8 +252,8 @@ public class IndexCommands extends AbstractCommandsSupport {
           if (cliFunctionResult.isSuccessful()) {
             successfulMembers.add(cliFunctionResult.getMemberIdOrName());
 
-            if (xmlEntity == null) {
-              xmlEntity = cliFunctionResult.getXmlEntity();
+            if (xmlEntity.get() == null) {
+              xmlEntity.set(cliFunctionResult.getXmlEntity());
             }
           } else {
             final String exceptionMessage = cliFunctionResult.getMessage();
@@ -315,10 +314,12 @@ public class IndexCommands extends AbstractCommandsSupport {
       result = ResultBuilder.createGemFireErrorResult(e.getMessage());
     }
 
-    if (xmlEntity != null) {
-      result.setCommandPersisted((new SharedConfigurationWriter()).addXmlEntity(xmlEntity,
-          group != null ? group.split(",") : null));
+
+    if (xmlEntity.get() != null) {
+      persistClusterConfiguration(result, () -> getSharedConfiguration()
+          .addXmlEntity(xmlEntity.get(), group != null ? group.split(",") : null));
     }
+
     return result;
   }
 
@@ -343,7 +344,6 @@ public class IndexCommands extends AbstractCommandsSupport {
           help = CliStrings.DESTROY_INDEX__GROUP__HELP) final String group) {
 
     Result result = null;
-    XmlEntity xmlEntity = null;
 
     if (StringUtils.isBlank(indexName) && StringUtils.isBlank(regionPath)
         && StringUtils.isBlank(memberNameOrID) && StringUtils.isBlank(group)) {
@@ -378,17 +378,18 @@ public class IndexCommands extends AbstractCommandsSupport {
     Set<String> successfulMembers = new TreeSet<String>();
     Map<String, Set<String>> indexOpFailMap = new HashMap<String, Set<String>>();
 
+    AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
     for (Object funcResult : funcResults) {
       if (!(funcResult instanceof CliFunctionResult)) {
         continue;
       }
 
       CliFunctionResult cliFunctionResult = (CliFunctionResult) funcResult;
+
       if (cliFunctionResult.isSuccessful()) {
         successfulMembers.add(cliFunctionResult.getMemberIdOrName());
-
-        if (xmlEntity == null) {
-          xmlEntity = cliFunctionResult.getXmlEntity();
+        if (xmlEntity.get() == null) {
+          xmlEntity.set(cliFunctionResult.getXmlEntity());
         }
       } else {
         String exceptionMessage = cliFunctionResult.getMessage();
@@ -454,12 +455,11 @@ public class IndexCommands extends AbstractCommandsSupport {
       }
       result = ResultBuilder.buildResult(erd);
     }
-
-
-    if (xmlEntity != null) {
-      result.setCommandPersisted((new SharedConfigurationWriter()).deleteXmlEntity(xmlEntity,
-          group != null ? group.split(",") : null));
+    if (xmlEntity.get() != null) {
+      persistClusterConfiguration(result, () -> getSharedConfiguration()
+          .deleteXmlEntity(xmlEntity.get(), group != null ? group.split(",") : null));
     }
+
     return result;
   }
 
@@ -548,7 +548,7 @@ public class IndexCommands extends AbstractCommandsSupport {
           help = CliStrings.CREATE_DEFINED_INDEXES__GROUP__HELP) final String group) {
 
     Result result = null;
-    XmlEntity xmlEntity = null;
+    AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
 
     if (indexDefinitions.isEmpty()) {
       final InfoResultData infoResult = ResultBuilder.createInfoResultData();
@@ -575,8 +575,8 @@ public class IndexCommands extends AbstractCommandsSupport {
           if (cliFunctionResult.isSuccessful()) {
             successfulMembers.add(cliFunctionResult.getMemberIdOrName());
 
-            if (xmlEntity == null) {
-              xmlEntity = cliFunctionResult.getXmlEntity();
+            if (xmlEntity.get() == null) {
+              xmlEntity.set(cliFunctionResult.getXmlEntity());
             }
           } else {
             final String exceptionMessage = cliFunctionResult.getMessage();
@@ -630,9 +630,9 @@ public class IndexCommands extends AbstractCommandsSupport {
       result = ResultBuilder.createGemFireErrorResult(e.getMessage());
     }
 
-    if (xmlEntity != null) {
-      result.setCommandPersisted((new SharedConfigurationWriter()).addXmlEntity(xmlEntity,
-          group != null ? group.split(",") : null));
+    if (xmlEntity.get() != null) {
+      persistClusterConfiguration(result, () -> getSharedConfiguration()
+          .addXmlEntity(xmlEntity.get(), group != null ? group.split(",") : null));
     }
     return result;
   }

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/PDXCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/PDXCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/PDXCommands.java
index c5e9a4e..72d5c0f 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/PDXCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/PDXCommands.java
@@ -14,14 +14,6 @@
  */
 package org.apache.geode.management.internal.cli.commands;
 
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.Arrays;
-import java.util.Collection;
-
 import org.apache.geode.internal.cache.CacheConfig;
 import org.apache.geode.internal.cache.DiskStoreImpl;
 import org.apache.geode.internal.cache.xmlcache.CacheCreation;
@@ -33,7 +25,6 @@ import org.apache.geode.management.internal.cli.CliUtil;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
 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.SharedConfigurationWriter;
 import org.apache.geode.management.internal.configuration.domain.XmlEntity;
 import org.apache.geode.management.internal.security.ResourceOperation;
 import org.apache.geode.pdx.ReflectionBasedAutoSerializer;
@@ -41,11 +32,18 @@ import org.apache.geode.pdx.internal.EnumInfo;
 import org.apache.geode.pdx.internal.PdxType;
 import org.apache.geode.security.ResourcePermission.Operation;
 import org.apache.geode.security.ResourcePermission.Resource;
-
 import org.springframework.shell.core.annotation.CliAvailabilityIndicator;
 import org.springframework.shell.core.annotation.CliCommand;
 import org.springframework.shell.core.annotation.CliOption;
 
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Arrays;
+import java.util.Collection;
+
 public class PDXCommands extends AbstractCommandsSupport {
 
 
@@ -149,12 +147,10 @@ public class PDXCommands extends AbstractCommandsSupport {
       XmlEntity xmlEntity =
           XmlEntity.builder().withType(CacheXml.PDX).withConfig(xmlDefinition).build();
 
-
-      SharedConfigurationWriter scWriter = new SharedConfigurationWriter();
-      boolean commandPersisted = scWriter.addXmlEntity(xmlEntity, null);
-
       result = ResultBuilder.buildResult(ird);
-      result.setCommandPersisted(commandPersisted);
+      persistClusterConfiguration(result,
+          () -> getSharedConfiguration().addXmlEntity(xmlEntity, null));
+
     } catch (Exception e) {
       return ResultBuilder.createGemFireErrorResult(e.getMessage());
     }

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/QueueCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/QueueCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/QueueCommands.java
index ebdae56..095bd68 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/QueueCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/QueueCommands.java
@@ -18,6 +18,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.geode.SystemFailure;
 import org.apache.geode.cache.execute.ResultCollector;
@@ -36,8 +37,6 @@ import org.apache.geode.management.internal.cli.i18n.CliStrings;
 import org.apache.geode.management.internal.cli.result.CommandResultException;
 import org.apache.geode.management.internal.cli.result.ResultBuilder;
 import org.apache.geode.management.internal.cli.result.TabularResultData;
-import org.apache.geode.management.internal.cli.shell.Gfsh;
-import org.apache.geode.management.internal.configuration.SharedConfigurationWriter;
 import org.apache.geode.management.internal.configuration.domain.XmlEntity;
 import org.apache.geode.management.internal.security.ResourceOperation;
 import org.apache.geode.security.ResourcePermission.Operation;
@@ -54,10 +53,7 @@ import org.springframework.shell.core.annotation.CliOption;
  * 
  * @since GemFire 8.0
  */
-public class QueueCommands implements CommandMarker {
-  private Gfsh getGfsh() {
-    return Gfsh.getCurrentInstance();
-  }
+public class QueueCommands extends AbstractCommandsSupport {
 
   @CliCommand(value = CliStrings.CREATE_ASYNC_EVENT_QUEUE,
       help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__HELP)
@@ -150,7 +146,7 @@ public class QueueCommands implements CommandMarker {
 
       List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult());
 
-      XmlEntity xmlEntity = null;
+      AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
       for (CliFunctionResult result : results) {
         if (result.getThrowable() != null) {
           tabularData.accumulate("Member", result.getMemberIdOrName());
@@ -163,8 +159,8 @@ public class QueueCommands implements CommandMarker {
           tabularData.accumulate("Result", result.getMessage());
           accumulatedData = true;
 
-          if (xmlEntity == null) {
-            xmlEntity = result.getXmlEntity();
+          if (xmlEntity.get() == null) {
+            xmlEntity.set(result.getXmlEntity());
           }
         }
       }
@@ -174,9 +170,9 @@ public class QueueCommands implements CommandMarker {
       }
 
       Result result = ResultBuilder.buildResult(tabularData);
-      if (xmlEntity != null) {
-        result
-            .setCommandPersisted((new SharedConfigurationWriter()).addXmlEntity(xmlEntity, groups));
+      if (xmlEntity.get() != null) {
+        persistClusterConfiguration(result,
+            () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), groups));
       }
       return result;
     } catch (VirtualMachineError e) {

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/WanCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/WanCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/WanCommands.java
index dd6a327..cbf5891 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/WanCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/WanCommands.java
@@ -27,6 +27,7 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
 import javax.management.ObjectName;
 
 import org.apache.geode.cache.Cache;
@@ -50,8 +51,6 @@ import org.apache.geode.management.internal.cli.result.CommandResultException;
 import org.apache.geode.management.internal.cli.result.CompositeResultData;
 import org.apache.geode.management.internal.cli.result.ResultBuilder;
 import org.apache.geode.management.internal.cli.result.TabularResultData;
-import org.apache.geode.management.internal.cli.shell.Gfsh;
-import org.apache.geode.management.internal.configuration.SharedConfigurationWriter;
 import org.apache.geode.management.internal.configuration.domain.XmlEntity;
 import org.apache.geode.management.internal.security.ResourceOperation;
 import org.apache.geode.security.ResourcePermission.Operation;
@@ -62,12 +61,7 @@ import org.springframework.shell.core.annotation.CliAvailabilityIndicator;
 import org.springframework.shell.core.annotation.CliCommand;
 import org.springframework.shell.core.annotation.CliOption;
 
-public class WanCommands implements CommandMarker {
-
-  private Gfsh getGfsh() {
-    return Gfsh.getCurrentInstance();
-  }
-
+public class WanCommands extends AbstractCommandsSupport {
   @CliCommand(value = CliStrings.CREATE_GATEWAYSENDER, help = CliStrings.CREATE_GATEWAYSENDER__HELP)
   @CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN, writesToSharedConfiguration = true)
   @ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
@@ -140,7 +134,7 @@ public class WanCommands implements CommandMarker {
 
     Result result = null;
 
-    XmlEntity xmlEntity = null;
+    AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
     try {
       GatewaySenderFunctionArgs gatewaySenderFunctionArgs = new GatewaySenderFunctionArgs(id,
           remoteDistributedSystemId, parallel, manualStart, socketBufferSize, socketReadTimeout,
@@ -166,8 +160,8 @@ public class WanCommands implements CommandMarker {
         tabularResultData.accumulate("Status",
             (success ? "" : errorPrefix) + gatewaySenderCreateResult.getMessage());
 
-        if (success && xmlEntity == null) {
-          xmlEntity = gatewaySenderCreateResult.getXmlEntity();
+        if (success && xmlEntity.get() == null) {
+          xmlEntity.set(gatewaySenderCreateResult.getXmlEntity());
         }
       }
       result = ResultBuilder.buildResult(tabularResultData);
@@ -178,9 +172,9 @@ public class WanCommands implements CommandMarker {
       result = handleCommandResultException(crex);
     }
 
-    if (xmlEntity != null) {
-      result
-          .setCommandPersisted((new SharedConfigurationWriter()).addXmlEntity(xmlEntity, onGroups));
+    if (xmlEntity.get() != null) {
+      persistClusterConfiguration(result,
+          () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), onGroups));
     }
     return result;
   }
@@ -627,7 +621,7 @@ public class WanCommands implements CommandMarker {
 
     Result result = null;
 
-    XmlEntity xmlEntity = null;
+    AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
     try {
       GatewayReceiverFunctionArgs gatewayReceiverFunctionArgs =
           new GatewayReceiverFunctionArgs(manualStart, startPort, endPort, bindAddress,
@@ -652,8 +646,8 @@ public class WanCommands implements CommandMarker {
         tabularResultData.accumulate("Status",
             (success ? "" : errorPrefix) + gatewayReceiverCreateResult.getMessage());
 
-        if (success && xmlEntity == null) {
-          xmlEntity = gatewayReceiverCreateResult.getXmlEntity();
+        if (success && xmlEntity.get() == null) {
+          xmlEntity.set(gatewayReceiverCreateResult.getXmlEntity());
         }
       }
       result = ResultBuilder.buildResult(tabularResultData);
@@ -664,9 +658,9 @@ public class WanCommands implements CommandMarker {
       result = handleCommandResultException(crex);
     }
 
-    if (xmlEntity != null) {
-      result
-          .setCommandPersisted((new SharedConfigurationWriter()).addXmlEntity(xmlEntity, onGroups));
+    if (xmlEntity.get() != null) {
+      persistClusterConfiguration(result,
+          () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), onGroups));
     }
 
     return result;

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ExportSharedConfigurationFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ExportSharedConfigurationFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ExportSharedConfigurationFunction.java
deleted file mode 100644
index f20d9d4..0000000
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ExportSharedConfigurationFunction.java
+++ /dev/null
@@ -1,72 +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.cli.functions;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.geode.cache.execute.Function;
-import org.apache.geode.cache.execute.FunctionContext;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
-import org.apache.geode.internal.InternalEntity;
-import org.apache.geode.management.internal.cli.i18n.CliStrings;
-import org.apache.geode.management.internal.configuration.domain.Configuration;
-import org.apache.geode.management.internal.configuration.utils.ZipUtils;
-
-import java.io.File;
-import java.util.UUID;
-
-public class ExportSharedConfigurationFunction implements Function, InternalEntity {
-
-  private static final long serialVersionUID = 1L;
-
-  @Override
-  public void execute(FunctionContext context) {
-    InternalLocator locator = InternalLocator.getLocator();
-    String memberName = locator.getDistributedSystem().getName();
-
-    if (!locator.isSharedConfigurationRunning()) {
-      CliFunctionResult result =
-          new CliFunctionResult(memberName, false, CliStrings.SHARED_CONFIGURATION_NOT_STARTED);
-      context.getResultSender().lastResult(result);
-      return;
-    }
-
-    SharedConfiguration sc = locator.getSharedConfiguration();
-    String zipFileName =
-        CliStrings.format(CliStrings.EXPORT_SHARED_CONFIG__FILE__NAME, UUID.randomUUID());
-    File zipFile = new File(sc.getSharedConfigurationDirPath(), zipFileName);
-
-    try {
-      for (Configuration config : sc.getEntireConfiguration().values()) {
-        sc.writeConfig(config);
-      }
-
-      ZipUtils.zip(sc.getSharedConfigurationDirPath(), zipFile.getCanonicalPath());
-
-      byte[] zippedConfigData = FileUtils.readFileToByteArray(zipFile);
-      FileUtils.forceDelete(zipFile);
-      CliFunctionResult result = new CliFunctionResult(locator.getDistributedSystem().getName(),
-          zippedConfigData, new String[] {zipFileName});
-      context.getResultSender().lastResult(result);
-    } catch (Exception e) {
-      context.getResultSender().lastResult(new CliFunctionResult(memberName, e, e.getMessage()));
-    }
-  }
-
-  @Override
-  public String getId() {
-    return ExportSharedConfigurationFunction.class.getName();
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ImportSharedConfigurationArtifactsFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ImportSharedConfigurationArtifactsFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ImportSharedConfigurationArtifactsFunction.java
deleted file mode 100644
index beee3db..0000000
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ImportSharedConfigurationArtifactsFunction.java
+++ /dev/null
@@ -1,82 +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.cli.functions;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.geode.cache.execute.FunctionAdapter;
-import org.apache.geode.cache.execute.FunctionContext;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
-import org.apache.geode.internal.InternalEntity;
-import org.apache.geode.management.internal.cli.CliUtil;
-import org.apache.geode.management.internal.cli.i18n.CliStrings;
-import org.apache.geode.management.internal.configuration.utils.ZipUtils;
-
-import java.io.File;
-
-/******
- * This function copies the zipped shared configuration, renames the existing shared configuration
- * directory and unzips the shared configuration.
- *
- */
-public class ImportSharedConfigurationArtifactsFunction extends FunctionAdapter
-    implements InternalEntity {
-
-  private static final long serialVersionUID = 1L;
-
-  @Override
-  public void execute(FunctionContext context) {
-    Object[] args = (Object[]) context.getArguments();
-    String zipFileName = (String) args[0];
-    byte[] zipFileData = (byte[]) args[1];
-
-    InternalLocator locator = InternalLocator.getLocator();
-    String memberName = locator.getDistributedSystem().getName();
-
-    if (locator.isSharedConfigurationRunning()) {
-      File zippedSharedConfiguration = new File(zipFileName);
-
-      try {
-        SharedConfiguration sc = locator.getSharedConfiguration();
-        sc.renameExistingSharedConfigDirectory();
-        sc.clearSharedConfiguration();
-        FileUtils.writeByteArrayToFile(zippedSharedConfiguration, zipFileData);
-        ZipUtils.unzip(zipFileName, sc.getSharedConfigurationDirPath());
-
-        // load it from the disk
-        sc.loadSharedConfigurationFromDisk();
-
-        CliFunctionResult cliFunctionResult =
-            new CliFunctionResult(memberName, true, CliStrings.IMPORT_SHARED_CONFIG__SUCCESS__MSG);
-        context.getResultSender().lastResult(cliFunctionResult);
-      } catch (Exception e) {
-        CliFunctionResult result =
-            new CliFunctionResult(memberName, e, CliUtil.stackTraceAsString(e));
-        context.getResultSender().lastResult(result);
-      } finally {
-        FileUtils.deleteQuietly(zippedSharedConfiguration);
-      }
-    } else {
-      CliFunctionResult cliFunctionResult =
-          new CliFunctionResult(memberName, false, CliStrings.SHARED_CONFIGURATION_NOT_STARTED);
-      context.getResultSender().lastResult(cliFunctionResult);
-    }
-  }
-
-  @Override
-  public String getId() {
-    return ImportSharedConfigurationArtifactsFunction.class.getName();
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/LoadSharedConfigurationFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/LoadSharedConfigurationFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/LoadSharedConfigurationFunction.java
deleted file mode 100644
index c4fa6ee..0000000
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/LoadSharedConfigurationFunction.java
+++ /dev/null
@@ -1,64 +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.cli.functions;
-
-import org.apache.geode.cache.execute.FunctionAdapter;
-import org.apache.geode.cache.execute.FunctionContext;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
-import org.apache.geode.internal.InternalEntity;
-import org.apache.geode.management.internal.cli.CliUtil;
-import org.apache.geode.management.internal.cli.i18n.CliStrings;
-
-/***
- * Function to load the shared configuration (already imported) from the disk.
- *
- */
-public class LoadSharedConfigurationFunction extends FunctionAdapter implements InternalEntity {
-
-  /**
-   * 
-   */
-  private static final long serialVersionUID = 1L;
-
-  @Override
-  public void execute(FunctionContext context) {
-    InternalLocator locator = InternalLocator.getLocator();
-    String memberName = locator.getDistributedSystem().getName();
-
-    try {
-      if (locator.isSharedConfigurationRunning()) {
-        SharedConfiguration sc = locator.getSharedConfiguration();
-        sc.loadSharedConfigurationFromDisk();
-        CliFunctionResult cliFunctionResult =
-            new CliFunctionResult(memberName, true, CliStrings.IMPORT_SHARED_CONFIG__SUCCESS__MSG);
-        context.getResultSender().lastResult(cliFunctionResult);
-      } else {
-        CliFunctionResult cliFunctionResult =
-            new CliFunctionResult(memberName, false, CliStrings.SHARED_CONFIGURATION_NOT_STARTED);
-        context.getResultSender().lastResult(cliFunctionResult);
-      }
-    } catch (Exception e) {
-      context.getResultSender()
-          .lastResult(new CliFunctionResult(memberName, e, CliUtil.stackTraceAsString(e)));
-    }
-  }
-
-  @Override
-  public String getId() {
-    return LoadSharedConfigurationFunction.class.getName();
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/RemoteExecutionStrategy.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/RemoteExecutionStrategy.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/RemoteExecutionStrategy.java
index 4ae1a1c..708ea6b 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/RemoteExecutionStrategy.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/RemoteExecutionStrategy.java
@@ -97,6 +97,7 @@ public class RemoteExecutionStrategy {
 
         // Do the locking and annotation check only if the shared configuration service is enabled
         // Else go the usual route of command execution
+        // TODO: why do we need to care about this here?
         if (gfc.getDistributionManager().isSharedConfigurationServiceEnabledForDS()
             && (writesToSharedConfiguration(method) || readsFromSharedConfiguration(method))) {
           DistributedLockService dls = SharedConfiguration

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/configuration/SharedConfigurationWriter.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/SharedConfigurationWriter.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/SharedConfigurationWriter.java
deleted file mode 100644
index 2be9873..0000000
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/SharedConfigurationWriter.java
+++ /dev/null
@@ -1,160 +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;
-
-import org.apache.geode.cache.execute.Function;
-import org.apache.geode.cache.execute.ResultCollector;
-import org.apache.geode.distributed.DistributedMember;
-import org.apache.geode.internal.cache.GemFireCacheImpl;
-import org.apache.geode.internal.logging.LogService;
-import org.apache.geode.management.internal.cli.CliUtil;
-import org.apache.geode.management.internal.configuration.domain.ConfigurationChangeResult;
-import org.apache.geode.management.internal.configuration.domain.XmlEntity;
-import org.apache.geode.management.internal.configuration.functions.AddJarFunction;
-import org.apache.geode.management.internal.configuration.functions.AddXmlEntityFunction;
-import org.apache.geode.management.internal.configuration.functions.DeleteJarFunction;
-import org.apache.geode.management.internal.configuration.functions.DeleteXmlEntityFunction;
-import org.apache.geode.management.internal.configuration.functions.ModifyXmlAndPropertiesFunction;
-import org.apache.logging.log4j.Logger;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Properties;
-import java.util.Set;
-
-/***
- * Class for writing configuration changes to the Shared Configuration at the Locator(s). This class
- * is used in the Gfsh commands, to persist the configuration changes to the shared configuration
- * hosted on locators.
- *
- *
- */
-public class SharedConfigurationWriter {
-  private static final Logger logger = LogService.getLogger();
-
-  private GemFireCacheImpl cache;
-  private final AddJarFunction addJarFunction = new AddJarFunction();
-  private final DeleteJarFunction deleteJarFunction = new DeleteJarFunction();
-  private final AddXmlEntityFunction addXmlEntityFunction = new AddXmlEntityFunction();
-  private final DeleteXmlEntityFunction deleteXmlEntityFunction = new DeleteXmlEntityFunction();
-  private final ModifyXmlAndPropertiesFunction modifyXmlAndPropertiesFunction =
-      new ModifyXmlAndPropertiesFunction();
-  private boolean isSharedConfigEnabled;
-
-  public SharedConfigurationWriter() {
-    cache = GemFireCacheImpl.getInstance();
-    isSharedConfigEnabled =
-        cache.getDistributionManager().isSharedConfigurationServiceEnabledForDS();
-  }
-
-  // /***
-  // * Adds or replaces the xml entity in the cache-xml for the specified groups in the shared
-  // configuration.
-  // * @param xmlEntity XmlEntity that is to be added/replaced in the shared configuration
-  // * @param groups target groups
-  // * @return true on adding the xml-entity in the shared configuration
-  // */
-  public boolean addXmlEntity(XmlEntity xmlEntity, String[] groups) {
-    Object[] args = new Object[2];
-    args[0] = xmlEntity;
-    args[1] = groups;
-    return saveConfigChanges(addXmlEntityFunction, args);
-  }
-
-  // /*****
-  // * Removes an xml entity from the cache-xml for the specified groups in the shared
-  // configuration.
-  // * @param xmlEntity
-  // * @param groups
-  // * @return true on successful deletion
-  // */
-  public boolean deleteXmlEntity(XmlEntity xmlEntity, String[] groups) {
-    Object[] args = new Object[2];
-    args[0] = xmlEntity;
-    args[1] = groups;
-    return saveConfigChanges(deleteXmlEntityFunction, args);
-  }
-
-
-  public boolean modifyPropertiesAndCacheAttributes(Properties properties, XmlEntity xmlEntity,
-      String[] groups) {
-    Object[] args = new Object[3];
-    args[0] = properties;
-    args[1] = xmlEntity;
-    args[2] = groups;
-    return saveConfigChanges(modifyXmlAndPropertiesFunction, args);
-  }
-
-  // /*****
-  // * Adds the deployed jars to the shared configuration on all the locators
-  // * @param jarNames Name of jar files to be added
-  // * @param jarBytes Contents of jar files
-  // * @param groups member groups on which these jars were deployed
-  // * @return true when the jar files are saved on all the locators.
-  // */
-  public boolean addJars(String[] jarNames, byte[][] jarBytes, String[] groups) {
-    Object[] args = new Object[3];
-    args[0] = jarNames;
-    args[1] = jarBytes;
-    args[2] = groups;
-    return saveConfigChanges(addJarFunction, args);
-  }
-
-  // /****
-  // * Deletes the jar files from the shared configuration on all the locators
-  // * @param jarNames Name of the jar files to be deleted
-  // * @param groups member groups on which these jars were undeployed
-  // * @return true when the jar files are deleted from shared configuration on all the locators.
-  // */
-  public boolean deleteJars(String[] jarNames, String[] groups) {
-    Object[] args = new Object[3];
-    args[0] = jarNames;
-    args[1] = groups;
-    return saveConfigChanges(deleteJarFunction, args);
-  }
-
-
-  private boolean saveConfigChanges(Function function, Object[] args) {
-    if (!isSharedConfigEnabled) {
-      return true;
-    }
-    Set<DistributedMember> locators = new HashSet<DistributedMember>(
-        cache.getDistributionManager().getAllHostedLocatorsWithSharedConfiguration().keySet());
-
-    boolean success = locators.stream()
-        .map((DistributedMember locator) -> saveConfigChangeOnLocator(locator, function, args))
-        .anyMatch((Boolean result) -> result);
-
-    if (!success) {
-      logger.error("Failed to save the configuration change.");
-    }
-
-    return success;
-  }
-
-  private boolean saveConfigChangeOnLocator(DistributedMember locator, Function function,
-      Object[] args) {
-    ResultCollector<?, ?> rc = CliUtil.executeFunction(function, args, locator);
-    List<ConfigurationChangeResult> results = (List<ConfigurationChangeResult>) rc.getResult();
-
-    Optional<ConfigurationChangeResult> result = results.stream().filter(Objects::nonNull)
-        .filter(ConfigurationChangeResult::isSuccessful).findFirst();
-
-    return result.isPresent();
-  }
-
-}


[3/4] geode git commit: GEODE-2261: do not use remote function calls to update the shared configuration

Posted by ji...@apache.org.
http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/AddJarFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/AddJarFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/AddJarFunction.java
deleted file mode 100644
index b986372..0000000
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/AddJarFunction.java
+++ /dev/null
@@ -1,65 +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 org.apache.geode.cache.execute.FunctionAdapter;
-import org.apache.geode.cache.execute.FunctionContext;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
-import org.apache.geode.internal.InternalEntity;
-import org.apache.geode.management.internal.cli.CliUtil;
-import org.apache.geode.management.internal.configuration.domain.ConfigurationChangeResult;
-
-public class AddJarFunction extends FunctionAdapter implements InternalEntity {
-
-  /**
-   * 
-   */
-  private static final long serialVersionUID = 1L;
-
-  public AddJarFunction() {}
-
-  public void execute(FunctionContext context) {
-    InternalLocator locator = InternalLocator.getLocator();
-    ConfigurationChangeResult configChangeResult = new ConfigurationChangeResult();
-
-    try {
-      if (locator.isSharedConfigurationRunning()) {
-        final Object[] args = (Object[]) context.getArguments();
-        final String[] jarFilenames = (String[]) args[0];
-        final byte[][] jarBytes = (byte[][]) args[1];
-        final String[] groups = (String[]) args[2];
-
-        SharedConfiguration sharedConfiguration = locator.getSharedConfiguration();
-        sharedConfiguration.addJarsToThisLocator(jarFilenames, jarBytes, groups);
-
-      } else {
-        configChangeResult
-            .setErrorMessage("Shared Configuration has not been started in locator : " + locator);
-      }
-    } catch (Exception e) {
-      configChangeResult.setException(e);
-      configChangeResult.setErrorMessage(CliUtil.stackTraceAsString(e));
-    } finally {
-      context.getResultSender().lastResult(configChangeResult);
-    }
-  }
-
-  @Override
-  public String getId() {
-    return AddJarFunction.class.getName();
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/AddXmlEntityFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/AddXmlEntityFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/AddXmlEntityFunction.java
deleted file mode 100644
index c562c9c..0000000
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/AddXmlEntityFunction.java
+++ /dev/null
@@ -1,58 +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 org.apache.geode.cache.execute.FunctionAdapter;
-import org.apache.geode.cache.execute.FunctionContext;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
-import org.apache.geode.internal.InternalEntity;
-import org.apache.geode.management.internal.cli.CliUtil;
-import org.apache.geode.management.internal.configuration.domain.ConfigurationChangeResult;
-import org.apache.geode.management.internal.configuration.domain.XmlEntity;
-
-public class AddXmlEntityFunction extends FunctionAdapter implements InternalEntity {
-
-  private static final long serialVersionUID = 1L;
-
-  @Override
-  public void execute(FunctionContext context) {
-    InternalLocator locator = InternalLocator.getLocator();
-    ConfigurationChangeResult configChangeResult = new ConfigurationChangeResult();
-    try {
-      if (locator.isSharedConfigurationRunning()) {
-        Object[] args = (Object[]) context.getArguments();
-        XmlEntity xmlEntity = (XmlEntity) args[0];
-        String[] groups = (String[]) args[1];
-        SharedConfiguration sharedConfig = locator.getSharedConfiguration();
-        sharedConfig.addXmlEntity(xmlEntity, groups);
-      } else {
-        configChangeResult
-            .setErrorMessage("Shared Configuration has not been started in locator : " + locator);
-      }
-    } catch (Exception e) {
-      configChangeResult.setException(e);
-      configChangeResult.setErrorMessage(CliUtil.stackTraceAsString(e));
-    } finally {
-      context.getResultSender().lastResult(configChangeResult);
-    }
-  }
-
-  @Override
-  public String getId() {
-    return AddXmlEntityFunction.class.getName();
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/DeleteJarFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/DeleteJarFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/DeleteJarFunction.java
deleted file mode 100644
index d0d36a8..0000000
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/DeleteJarFunction.java
+++ /dev/null
@@ -1,65 +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 org.apache.geode.cache.execute.FunctionAdapter;
-import org.apache.geode.cache.execute.FunctionContext;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
-import org.apache.geode.internal.InternalEntity;
-import org.apache.geode.management.internal.cli.CliUtil;
-import org.apache.geode.management.internal.configuration.domain.ConfigurationChangeResult;
-
-public class DeleteJarFunction extends FunctionAdapter implements InternalEntity {
-
-  /**
-   * 
-   */
-  private static final long serialVersionUID = 1L;
-
-  public DeleteJarFunction() {}
-
-  @Override
-  public void execute(FunctionContext context) {
-
-    InternalLocator locator = InternalLocator.getLocator();
-    ConfigurationChangeResult configChangeResult = new ConfigurationChangeResult();
-
-    try {
-      if (locator.isSharedConfigurationRunning()) {
-        final Object[] args = (Object[]) context.getArguments();
-        final String[] jarFilenames = (String[]) args[0];
-        final String[] groups = (String[]) args[1];
-
-        SharedConfiguration sharedConfiguration = locator.getSharedConfiguration();
-        sharedConfiguration.removeJars(jarFilenames, groups);
-      } else {
-        configChangeResult
-            .setErrorMessage("Shared Configuration has not been started in locator : " + locator);
-      }
-    } catch (Exception e) {
-      configChangeResult.setException(e);
-      configChangeResult.setErrorMessage(CliUtil.stackTraceAsString(e));
-    } finally {
-      context.getResultSender().lastResult(configChangeResult);
-    }
-  }
-
-  @Override
-  public String getId() {
-    return DeleteJarFunction.class.getName();
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/DeleteXmlEntityFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/DeleteXmlEntityFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/DeleteXmlEntityFunction.java
deleted file mode 100644
index 1138d5f..0000000
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/DeleteXmlEntityFunction.java
+++ /dev/null
@@ -1,63 +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 org.apache.geode.cache.execute.FunctionAdapter;
-import org.apache.geode.cache.execute.FunctionContext;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
-import org.apache.geode.internal.InternalEntity;
-import org.apache.geode.management.internal.cli.CliUtil;
-import org.apache.geode.management.internal.configuration.domain.ConfigurationChangeResult;
-import org.apache.geode.management.internal.configuration.domain.XmlEntity;
-
-public class DeleteXmlEntityFunction extends FunctionAdapter implements InternalEntity {
-
-  /**
-   * 
-   */
-  private static final long serialVersionUID = 1L;
-
-  @Override
-  public void execute(FunctionContext context) {
-    InternalLocator locator = InternalLocator.getLocator();
-    ConfigurationChangeResult configChangeResult = new ConfigurationChangeResult();
-    try {
-      if (locator.isSharedConfigurationRunning()) {
-        Object[] args = (Object[]) context.getArguments();
-        XmlEntity xmlEntity = (XmlEntity) args[0];
-        String[] groups = (String[]) args[1];
-        SharedConfiguration sharedConfig = locator.getSharedConfiguration();
-        sharedConfig.deleteXmlEntity(xmlEntity, groups);
-      } else {
-        configChangeResult
-            .setErrorMessage("Shared Configuration has not been started in locator : " + locator);
-      }
-    } catch (Exception e) {
-      configChangeResult.setException(e);
-      configChangeResult.setErrorMessage(CliUtil.stackTraceAsString(e));
-
-    } finally {
-      context.getResultSender().lastResult(configChangeResult);
-
-    }
-  }
-
-  @Override
-  public String getId() {
-    return DeleteXmlEntityFunction.class.getName();
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/ModifyXmlAndPropertiesFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/ModifyXmlAndPropertiesFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/ModifyXmlAndPropertiesFunction.java
deleted file mode 100644
index 97b9ec9..0000000
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/ModifyXmlAndPropertiesFunction.java
+++ /dev/null
@@ -1,62 +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 java.util.Properties;
-
-import org.apache.geode.cache.execute.Function;
-import org.apache.geode.cache.execute.FunctionContext;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
-import org.apache.geode.internal.InternalEntity;
-import org.apache.geode.management.internal.cli.CliUtil;
-import org.apache.geode.management.internal.configuration.domain.ConfigurationChangeResult;
-import org.apache.geode.management.internal.configuration.domain.XmlEntity;
-
-public class ModifyXmlAndPropertiesFunction implements Function, InternalEntity {
-
-  private static final long serialVersionUID = 1L;
-
-  @Override
-  public void execute(FunctionContext context) {
-    InternalLocator locator = InternalLocator.getLocator();
-    ConfigurationChangeResult configChangeResult = new ConfigurationChangeResult();
-    try {
-      if (locator.isSharedConfigurationRunning()) {
-        Object[] args = (Object[]) context.getArguments();
-        Properties properties = (Properties) args[0];
-        XmlEntity xmlEntity = (XmlEntity) args[1];
-        String[] groups = (String[]) args[2];
-
-        SharedConfiguration sharedConfig = locator.getSharedConfiguration();
-        sharedConfig.modifyXmlAndProperties(properties, xmlEntity, groups);
-      } else {
-        configChangeResult
-            .setErrorMessage("Shared Configuration has not been started in locator : " + locator);
-      }
-    } catch (Exception e) {
-      configChangeResult.setException(e);
-      configChangeResult.setErrorMessage(CliUtil.stackTraceAsString(e));
-    } finally {
-      context.getResultSender().lastResult(configChangeResult);
-    }
-  }
-
-  @Override
-  public String getId() {
-    return ModifyXmlAndPropertiesFunction.class.getName();
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/UploadJarFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/UploadJarFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/UploadJarFunction.java
index 7ea8682..aa211ac 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/UploadJarFunction.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/UploadJarFunction.java
@@ -21,10 +21,11 @@ import org.apache.geode.distributed.Locator;
 import org.apache.geode.distributed.internal.InternalLocator;
 import org.apache.geode.distributed.internal.SharedConfiguration;
 import org.apache.geode.internal.InternalEntity;
-
-import java.io.IOException;
+import org.apache.geode.internal.logging.LogService;
+import org.apache.logging.log4j.Logger;
 
 public class UploadJarFunction implements Function, InternalEntity {
+  private static final Logger logger = LogService.getLogger();
 
   private static final long serialVersionUID = 1L;
 
@@ -42,10 +43,8 @@ public class UploadJarFunction implements Function, InternalEntity {
           byte[] jarBytes = sharedConfig.getJarBytesFromThisLocator(group, jarName);
           context.getResultSender().lastResult(jarBytes);
 
-          // TODO: should we just return here if jarbytes was not null?
-        } catch (IOException e) {
-          context.getResultSender().sendException(e);
         } catch (Exception e) {
+          logger.error(e);
           context.getResultSender().sendException(e);
         }
       }

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/configuration/utils/XmlUtils.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/utils/XmlUtils.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/utils/XmlUtils.java
index cad770c..2471c83 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/utils/XmlUtils.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/utils/XmlUtils.java
@@ -465,6 +465,26 @@ public class XmlUtils {
   }
 
   /**
+   * Create a {@link Document} using {@link XmlUtils#createDocumentFromXml(String)} and if the
+   * version attribute is not equal to the current version then update the XML to the current schema
+   * and return the document.
+   *
+   * @param xmlContent XML content to load and upgrade.
+   * @return {@link Document} from xmlContent.
+   * @since GemFire 8.1
+   */
+  public static Document createAndUpgradeDocumentFromXml(String xmlContent)
+      throws SAXException, ParserConfigurationException, IOException, XPathExpressionException {
+    Document doc = XmlUtils.createDocumentFromXml(xmlContent);
+    if (!CacheXml.VERSION_LATEST.equals(XmlUtils.getAttribute(doc.getDocumentElement(),
+        CacheXml.VERSION, CacheXml.GEODE_NAMESPACE))) {
+      doc = upgradeSchema(doc, CacheXml.GEODE_NAMESPACE, CacheXml.LATEST_SCHEMA_LOCATION,
+          CacheXml.VERSION_LATEST);
+    }
+    return doc;
+  }
+
+  /**
    * Upgrade the schema of a given Config XMl <code>document</code> to the given
    * <code>namespace</code>, <code>schemaLocation</code> and <code>version</code>.
    * 

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/distributed/internal/SharedConfigurationJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/internal/SharedConfigurationJUnitTest.java b/geode-core/src/test/java/org/apache/geode/distributed/internal/SharedConfigurationJUnitTest.java
deleted file mode 100644
index e3e5620..0000000
--- a/geode-core/src/test/java/org/apache/geode/distributed/internal/SharedConfigurationJUnitTest.java
+++ /dev/null
@@ -1,53 +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.distributed.internal;
-
-import static org.apache.geode.management.internal.configuration.utils.XmlConstants.*;
-import static javax.xml.XMLConstants.*;
-import static org.junit.Assert.*;
-
-import org.apache.commons.io.IOUtils;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.w3c.dom.Document;
-
-import org.apache.geode.internal.cache.xmlcache.CacheXml;
-import org.apache.geode.management.internal.configuration.utils.XmlUtils;
-import org.apache.geode.test.junit.categories.UnitTest;
-
-/**
- * Unit tests for {@link SharedConfiguration}.
- *
- * @since GemFire 8.1
- */
-@Category(UnitTest.class)
-public class SharedConfigurationJUnitTest {
-
-  @Test
-  public void testCreateAndUpgradeDocumentFromXml() throws Exception {
-    Document doc = SharedConfiguration.createAndUpgradeDocumentFromXml(
-        IOUtils.toString(this.getClass().getResourceAsStream("SharedConfigurationJUnitTest.xml")));
-
-    String schemaLocation = XmlUtils.getAttribute(doc.getDocumentElement(),
-        W3C_XML_SCHEMA_INSTANCE_ATTRIBUTE_SCHEMA_LOCATION, W3C_XML_SCHEMA_INSTANCE_NS_URI);
-
-    assertNotNull(schemaLocation);
-    assertEquals(CacheXml.GEODE_NAMESPACE + " " + CacheXml.LATEST_SCHEMA_LOCATION, schemaLocation);
-
-    assertEquals(CacheXml.VERSION_LATEST,
-        XmlUtils.getAttribute(doc.getDocumentElement(), "version"));
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/internal/cache/extension/mock/MockExtensionCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/extension/mock/MockExtensionCommands.java b/geode-core/src/test/java/org/apache/geode/internal/cache/extension/mock/MockExtensionCommands.java
index e2a56fd..1bd4478 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/extension/mock/MockExtensionCommands.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/extension/mock/MockExtensionCommands.java
@@ -17,6 +17,7 @@ package org.apache.geode.internal.cache.extension.mock;
 
 import java.util.List;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.CacheFactory;
@@ -28,10 +29,10 @@ import org.apache.geode.management.cli.CliMetaData;
 import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.cli.Result.Status;
 import org.apache.geode.management.internal.cli.CliUtil;
+import org.apache.geode.management.internal.cli.commands.AbstractCommandsSupport;
 import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
 import org.apache.geode.management.internal.cli.result.ResultBuilder;
 import org.apache.geode.management.internal.cli.result.TabularResultData;
-import org.apache.geode.management.internal.configuration.SharedConfigurationWriter;
 import org.apache.geode.management.internal.configuration.domain.XmlEntity;
 import org.apache.geode.management.internal.security.ResourceOperation;
 import org.apache.geode.security.ResourcePermission.Operation;
@@ -47,7 +48,7 @@ import org.springframework.shell.core.annotation.CliOption;
  *
  * @since GemFire 8.1
  */
-public class MockExtensionCommands implements CommandMarker {
+public class MockExtensionCommands extends AbstractCommandsSupport {
 
   public static final String OPTION_VALUE = "value";
 
@@ -191,7 +192,7 @@ public class MockExtensionCommands implements CommandMarker {
     final List<CliFunctionResult> functionResults =
         (List<CliFunctionResult>) resultCollector.getResult();
 
-    XmlEntity xmlEntity = null;
+    AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
     final TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
     final String errorPrefix = "ERROR: ";
     for (CliFunctionResult functionResult : functionResults) {
@@ -199,7 +200,7 @@ public class MockExtensionCommands implements CommandMarker {
       tabularResultData.accumulate("Member", functionResult.getMemberIdOrName());
       if (success) {
         tabularResultData.accumulate("Status", functionResult.getMessage());
-        xmlEntity = functionResult.getXmlEntity();
+        xmlEntity.set(functionResult.getXmlEntity());
       } else {
         tabularResultData.accumulate("Status", errorPrefix + functionResult.getMessage());
         tabularResultData.setStatus(Status.ERROR);
@@ -209,12 +210,13 @@ public class MockExtensionCommands implements CommandMarker {
     final Result result = ResultBuilder.buildResult(tabularResultData);
 
     System.out.println("MockExtensionCommands: persisting xmlEntity=" + xmlEntity);
-    if (null != xmlEntity) {
+    if (null != xmlEntity.get()) {
       if (addXmlElement) {
-        result.setCommandPersisted((new SharedConfigurationWriter()).addXmlEntity(xmlEntity, null));
+        persistClusterConfiguration(result,
+            () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), null));
       } else {
-        result.setCommandPersisted(
-            (new SharedConfigurationWriter()).deleteXmlEntity(xmlEntity, null));
+        persistClusterConfiguration(result,
+            () -> getSharedConfiguration().deleteXmlEntity(xmlEntity.get(), null));
       }
     }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigCommandsDUnitTest.java
index d86cb0b..87e6f66 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigCommandsDUnitTest.java
@@ -14,6 +14,33 @@
  */
 package org.apache.geode.management.internal.cli.commands;
 
+import static org.apache.commons.io.FileUtils.deleteDirectory;
+import static org.apache.geode.distributed.ConfigurationProperties.ARCHIVE_FILE_SIZE_LIMIT;
+import static org.apache.geode.distributed.ConfigurationProperties.CLUSTER_CONFIGURATION_DIR;
+import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_TIME_STATISTICS;
+import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
+import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_BIND_ADDRESS;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_START;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.NAME;
+import static org.apache.geode.distributed.ConfigurationProperties.STATISTIC_SAMPLING_ENABLED;
+import static org.apache.geode.internal.AvailablePort.SOCKET;
+import static org.apache.geode.internal.AvailablePort.getRandomAvailablePort;
+import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts;
+import static org.apache.geode.test.dunit.Assert.assertEquals;
+import static org.apache.geode.test.dunit.Assert.assertFalse;
+import static org.apache.geode.test.dunit.Assert.assertNotNull;
+import static org.apache.geode.test.dunit.Assert.assertTrue;
+import static org.apache.geode.test.dunit.Assert.fail;
+import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
+import static org.apache.geode.test.dunit.Wait.waitForCriterion;
+
 import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.server.CacheServer;
 import org.apache.geode.distributed.Locator;
@@ -21,6 +48,7 @@ import org.apache.geode.distributed.internal.DistributionConfig;
 import org.apache.geode.distributed.internal.InternalDistributedSystem;
 import org.apache.geode.distributed.internal.InternalLocator;
 import org.apache.geode.distributed.internal.SharedConfiguration;
+import org.apache.geode.internal.AvailablePortHelper;
 import org.apache.geode.internal.cache.GemFireCacheImpl;
 import org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator;
 import org.apache.geode.internal.logging.LogWriterImpl;
@@ -30,28 +58,29 @@ import org.apache.geode.management.internal.cli.i18n.CliStrings;
 import org.apache.geode.management.internal.cli.remote.CommandProcessor;
 import org.apache.geode.management.internal.cli.result.CommandResult;
 import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
-import org.apache.geode.test.dunit.*;
+import org.apache.geode.test.dunit.Host;
+import org.apache.geode.test.dunit.SerializableCallable;
+import org.apache.geode.test.dunit.SerializableRunnable;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.WaitCriterion;
 import org.apache.geode.test.junit.categories.DistributedTest;
 import org.apache.geode.test.junit.categories.FlakyTest;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import java.io.*;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.lang.management.ManagementFactory;
 import java.lang.management.RuntimeMXBean;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.util.Collections;
 import java.util.List;
 import java.util.Properties;
 
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.apache.geode.internal.AvailablePort.SOCKET;
-import static org.apache.geode.internal.AvailablePort.getRandomAvailablePort;
-import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts;
-import static org.apache.geode.test.dunit.Assert.*;
-import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
-import static org.apache.geode.test.dunit.Wait.waitForCriterion;
-import static org.apache.commons.io.FileUtils.deleteDirectory;
-
 /**
  * Dunit class for testing GemFire config commands : export config
  *
@@ -426,22 +455,34 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
   @Test
   public void testAlterUpdatesSharedConfig() throws Exception {
     final String groupName = getName();
+    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
+    jmxPort = ports[0];
+    httpPort = ports[1];
+    try {
+      jmxHost = InetAddress.getLocalHost().getHostName();
+    } catch (UnknownHostException ignore) {
+      jmxHost = "localhost";
+    }
 
     // Start the Locator and wait for shared configuration to be available
     final int locatorPort = getRandomAvailablePort(SOCKET);
     final String locatorDirectory = this.temporaryFolder.newFolder("Locator").getAbsolutePath();
 
-    Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+    final Properties locatorProps = new Properties();
+    locatorProps.setProperty(NAME, "Locator");
+    locatorProps.setProperty(MCAST_PORT, "0");
+    locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+    locatorProps.setProperty(CLUSTER_CONFIGURATION_DIR, locatorDirectory);
+    locatorProps.setProperty(JMX_MANAGER, "true");
+    locatorProps.setProperty(JMX_MANAGER_START, "true");
+    locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
+    locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
+    locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
+
+    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
       @Override
       public void run() {
         final File locatorLogFile = new File(locatorDirectory, "locator-" + locatorPort + ".log");
-
-        final Properties locatorProps = new Properties();
-        locatorProps.setProperty(NAME, "Locator");
-        locatorProps.setProperty(MCAST_PORT, "0");
-        locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
-        locatorProps.setProperty(CLUSTER_CONFIGURATION_DIR, locatorDirectory);
-
         try {
           final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort,
               locatorLogFile, null, locatorProps);
@@ -465,11 +506,7 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
       }
     });
 
-    // Start the default manager
-    Properties managerProps = new Properties();
-    managerProps.setProperty(MCAST_PORT, "0");
-    managerProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
-    setUpJmxManagerOnVm0ThenConnect(managerProps);
+    connect(jmxHost, jmxPort, httpPort, getDefaultShell());
 
     // Create a cache in VM 1
     VM vm = Host.getHost(0).getVM(1);
@@ -499,7 +536,7 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
     assertEquals(Result.Status.OK, cmdResult.getStatus());
 
     // Make sure the shared config was updated
-    Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
       @Override
       public void run() {
         SharedConfiguration sharedConfig =

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
index 7a75cfa..f910721 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
@@ -14,33 +14,36 @@
  */
 package org.apache.geode.management.internal.cli.commands;
 
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.apache.geode.test.dunit.Assert.*;
-import static org.apache.geode.test.dunit.LogWriterUtils.*;
-import static com.jayway.awaitility.Awaitility.*;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.text.MessageFormat;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-import java.util.concurrent.Callable;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.TimeUnit;
-
-import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-
-import org.apache.geode.cache.*;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.internal.cache.PartitionedRegion;
+import static com.jayway.awaitility.Awaitility.waitAtMost;
+import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
+import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_BIND_ADDRESS;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_START;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.NAME;
+import static org.apache.geode.distributed.ConfigurationProperties.USE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.test.dunit.Assert.assertEquals;
+import static org.apache.geode.test.dunit.Assert.assertFalse;
+import static org.apache.geode.test.dunit.Assert.assertNotNull;
+import static org.apache.geode.test.dunit.Assert.assertNull;
+import static org.apache.geode.test.dunit.Assert.assertTrue;
+import static org.apache.geode.test.dunit.Assert.fail;
+import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.PartitionAttributes;
+import org.apache.geode.cache.PartitionAttributesFactory;
+import org.apache.geode.cache.PartitionResolver;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionAttributes;
+import org.apache.geode.cache.RegionFactory;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.Scope;
 import org.apache.geode.cache.asyncqueue.AsyncEvent;
 import org.apache.geode.cache.asyncqueue.AsyncEventListener;
 import org.apache.geode.cache.wan.GatewaySenderFactory;
@@ -49,9 +52,13 @@ import org.apache.geode.distributed.Locator;
 import org.apache.geode.distributed.internal.InternalLocator;
 import org.apache.geode.distributed.internal.SharedConfiguration;
 import org.apache.geode.internal.AvailablePort;
+import org.apache.geode.internal.AvailablePortHelper;
 import org.apache.geode.internal.ClassBuilder;
 import org.apache.geode.internal.FileUtil;
+import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.internal.cache.PartitionedRegion;
 import org.apache.geode.internal.cache.RegionEntryContext;
+import org.apache.geode.management.ManagementService;
 import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.MBeanJMXAdapter;
 import org.apache.geode.management.internal.ManagementConstants;
@@ -63,6 +70,26 @@ import org.apache.geode.test.dunit.SerializableCallable;
 import org.apache.geode.test.dunit.VM;
 import org.apache.geode.test.junit.categories.DistributedTest;
 import org.apache.geode.test.junit.categories.FlakyTest;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.text.MessageFormat;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.TimeUnit;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
 
 @Category(DistributedTest.class)
 public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBase {
@@ -839,8 +866,17 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
    */
   @Category(FlakyTest.class) // GEODE-2009
   @Test
-  public void testCreateAlterDestroyUpdatesSharedConfig() {
+  public void testCreateAlterDestroyUpdatesSharedConfig() throws Exception {
     disconnectAllFromDS();
+    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
+    jmxPort = ports[0];
+    httpPort = ports[1];
+    try {
+      jmxHost = InetAddress.getLocalHost().getHostName();
+    } catch (UnknownHostException ignore) {
+      jmxHost = "localhost";
+    }
+
 
     final String regionName = "testRegionSharedConfigRegion";
     final String regionPath = "/" + regionName;
@@ -848,28 +884,38 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
 
     // Start the Locator and wait for shared configuration to be available
     final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-    Host.getHost(0).getVM(3).invoke(() -> {
+
+    final Properties locatorProps = new Properties();
+    locatorProps.setProperty(NAME, "Locator");
+    locatorProps.setProperty(MCAST_PORT, "0");
+    locatorProps.setProperty(LOG_LEVEL, "fine");
+    locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+    locatorProps.setProperty(JMX_MANAGER, "true");
+    locatorProps.setProperty(JMX_MANAGER_START, "true");
+    locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
+    locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
+    locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
+
+    Host.getHost(0).getVM(0).invoke(() -> {
       final File locatorLogFile = new File("locator-" + locatorPort + ".log");
-      final Properties locatorProps = new Properties();
-      locatorProps.setProperty(NAME, "Locator");
-      locatorProps.setProperty(MCAST_PORT, "0");
-      locatorProps.setProperty(LOG_LEVEL, "fine");
-      locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
       try {
         final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort,
             locatorLogFile, null, locatorProps);
 
         waitAtMost(5, TimeUnit.SECONDS).until(() -> locator.isSharedConfigurationRunning());
+
+        ManagementService managementService =
+            ManagementService.getExistingManagementService(GemFireCacheImpl.getInstance());
+        assertNotNull(managementService);
+        assertTrue(managementService.isManager());
+        assertTrue(checkIfCommandsAreLoadedOrNot());
+
       } catch (IOException ioex) {
         fail("Unable to create a locator with a shared configuration");
       }
     });
 
-    // Start the default manager
-    Properties managerProps = new Properties();
-    managerProps.setProperty(MCAST_PORT, "0");
-    managerProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
-    setUpJmxManagerOnVm0ThenConnect(managerProps);
+    connect(jmxHost, jmxPort, httpPort, getDefaultShell());
 
     // Create a cache in VM 1
     VM vm = Host.getHost(0).getVM(1);
@@ -895,7 +941,7 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
     waitForRegionMBeanCreation(regionPath, 1);
 
     // Make sure the region exists in the shared config
-    Host.getHost(0).getVM(3).invoke(() -> {
+    Host.getHost(0).getVM(0).invoke(() -> {
       SharedConfiguration sharedConfig =
           ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
       try {
@@ -937,7 +983,7 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
     assertEquals(Result.Status.OK, cmdResult.getStatus());
 
     // Make sure the region was altered in the shared config
-    Host.getHost(0).getVM(3).invoke(() -> {
+    Host.getHost(0).getVM(0).invoke(() -> {
       SharedConfiguration sharedConfig =
           ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
       try {
@@ -976,22 +1022,38 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
 
   @Test
   public void testDestroyRegionWithSharedConfig() {
-
     disconnectAllFromDS();
 
+    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
+    jmxPort = ports[0];
+    httpPort = ports[1];
+    try {
+      jmxHost = InetAddress.getLocalHost().getHostName();
+    } catch (UnknownHostException ignore) {
+      jmxHost = "localhost";
+    }
+
+
     final String regionName = "testRegionSharedConfigRegion";
     final String regionPath = "/" + regionName;
     final String groupName = "testRegionSharedConfigGroup";
 
     // Start the Locator and wait for shared configuration to be available
     final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-    Host.getHost(0).getVM(3).invoke(() -> {
+
+    final Properties locatorProps = new Properties();
+    locatorProps.setProperty(NAME, "Locator");
+    locatorProps.setProperty(MCAST_PORT, "0");
+    locatorProps.setProperty(LOG_LEVEL, "fine");
+    locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+    locatorProps.setProperty(JMX_MANAGER, "true");
+    locatorProps.setProperty(JMX_MANAGER_START, "true");
+    locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
+    locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
+    locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
+
+    Host.getHost(0).getVM(0).invoke(() -> {
       final File locatorLogFile = new File("locator-" + locatorPort + ".log");
-      final Properties locatorProps = new Properties();
-      locatorProps.setProperty(NAME, "Locator");
-      locatorProps.setProperty(MCAST_PORT, "0");
-      locatorProps.setProperty(LOG_LEVEL, "fine");
-      locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
       try {
         final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort,
             locatorLogFile, null, locatorProps);
@@ -1002,11 +1064,7 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
       }
     });
 
-    // Start the default manager
-    Properties managerProps = new Properties();
-    managerProps.setProperty(MCAST_PORT, "0");
-    managerProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
-    setUpJmxManagerOnVm0ThenConnect(managerProps);
+    connect(jmxHost, jmxPort, httpPort, getDefaultShell());
 
     // Create a cache in VM 1
     VM vm = Host.getHost(0).getVM(1);
@@ -1032,7 +1090,7 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
     waitForRegionMBeanCreation(regionPath, 1);
 
     // Make sure the region exists in the shared config
-    Host.getHost(0).getVM(3).invoke(() -> {
+    Host.getHost(0).getVM(0).invoke(() -> {
       SharedConfiguration sharedConfig =
           ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
       try {
@@ -1051,7 +1109,7 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
     assertEquals(Result.Status.OK, cmdResult.getStatus());
 
     // Make sure the region was removed from the shared config
-    Host.getHost(0).getVM(3).invoke(() -> {
+    Host.getHost(0).getVM(0).invoke(() -> {
       SharedConfiguration sharedConfig =
           ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
       try {

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java
index 7cf9a3a..34ffc7c 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java
@@ -14,11 +14,28 @@
  */
 package org.apache.geode.management.internal.cli.commands;
 
+import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
+import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_BIND_ADDRESS;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_START;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.NAME;
+import static org.apache.geode.test.dunit.Assert.assertEquals;
+import static org.apache.geode.test.dunit.Assert.assertFalse;
+import static org.apache.geode.test.dunit.Assert.assertTrue;
+import static org.apache.geode.test.dunit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+
 import org.apache.geode.distributed.Locator;
 import org.apache.geode.distributed.internal.DistributionManager;
 import org.apache.geode.distributed.internal.InternalLocator;
 import org.apache.geode.distributed.internal.SharedConfiguration;
 import org.apache.geode.internal.AvailablePort;
+import org.apache.geode.internal.AvailablePortHelper;
 import org.apache.geode.internal.ClassBuilder;
 import org.apache.geode.internal.JarDeployer;
 import org.apache.geode.management.cli.Result;
@@ -26,7 +43,13 @@ import org.apache.geode.management.internal.cli.i18n.CliStrings;
 import org.apache.geode.management.internal.cli.remote.CommandExecutionContext;
 import org.apache.geode.management.internal.cli.remote.CommandProcessor;
 import org.apache.geode.management.internal.cli.result.CommandResult;
-import org.apache.geode.test.dunit.*;
+import org.apache.geode.test.dunit.Assert;
+import org.apache.geode.test.dunit.Host;
+import org.apache.geode.test.dunit.SerializableRunnable;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.Wait;
+import org.apache.geode.test.dunit.WaitCriterion;
+import org.apache.geode.test.dunit.rules.ServerStarterRule;
 import org.apache.geode.test.junit.categories.DistributedTest;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -34,12 +57,11 @@ import org.junit.experimental.categories.Category;
 import java.io.File;
 import java.io.FilenameFilter;
 import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.util.Properties;
 import java.util.regex.Pattern;
 
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.apache.geode.test.dunit.Assert.*;
-
 /**
  * Unit tests for the DeployCommands class
  *
@@ -315,24 +337,35 @@ public class DeployCommandsDUnitTest extends CliCommandTestBase {
   @Test
   public void testEndToEnd() throws Exception {
     final String groupName = getName();
+    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
+    jmxPort = ports[0];
+    httpPort = ports[1];
+    try {
+      jmxHost = InetAddress.getLocalHost().getHostName();
+    } catch (UnknownHostException ignore) {
+      jmxHost = "localhost";
+    }
 
     // Start the Locator and wait for shared configuration to be available
     final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
     final String locatorLogPath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator
         + "locator-" + locatorPort + ".log";
 
-    Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+    final Properties locatorProps = new Properties();
+    locatorProps.setProperty(NAME, "Locator");
+    locatorProps.setProperty(MCAST_PORT, "0");
+    locatorProps.setProperty(LOG_LEVEL, "fine");
+    locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+    locatorProps.setProperty(JMX_MANAGER, "true");
+    locatorProps.setProperty(JMX_MANAGER_START, "true");
+    locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
+    locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
+    locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
+
+    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
       @Override
       public void run() {
-
         final File locatorLogFile = new File(locatorLogPath);
-
-        final Properties locatorProps = new Properties();
-        locatorProps.setProperty(NAME, "Locator");
-        locatorProps.setProperty(MCAST_PORT, "0");
-        locatorProps.setProperty(LOG_LEVEL, "fine");
-        locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
-
         try {
           final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort,
               locatorLogFile, null, locatorProps);
@@ -356,12 +389,15 @@ public class DeployCommandsDUnitTest extends CliCommandTestBase {
       }
     });
 
-    // Start the default manager
-    Properties managerProps = new Properties();
-    managerProps.setProperty(MCAST_PORT, "0");
-    managerProps.setProperty(GROUPS, groupName);
-    managerProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
-    setUpJmxManagerOnVm0ThenConnect(managerProps);
+    connect(jmxHost, jmxPort, httpPort, getDefaultShell());
+
+    Host.getHost(0).getVM(1).invoke(() -> {
+      Properties properties = new Properties();
+      properties.setProperty("name", "Manager");
+      properties.setProperty("groups", groupName);
+      ServerStarterRule serverStarterRule = new ServerStarterRule(properties);
+      serverStarterRule.startServer(locatorPort);
+    });
 
     // Create a JAR file
     this.classBuilder.writeJarFromName("DeployCommandsDUnitA", this.newDeployableJarFile);
@@ -383,23 +419,29 @@ public class DeployCommandsDUnitTest extends CliCommandTestBase {
 
     stringResult = commandResultToString(cmdResult);
     assertEquals(3, countLinesInString(stringResult, false));
-    assertTrue(stringContainsLine(stringResult, "Member.*JAR.*Un-Deployed From JAR Location"));
-    assertTrue(stringContainsLine(stringResult, "Manager.*DeployCommandsDUnit1.jar.*"
-        + JarDeployer.JAR_PREFIX + "DeployCommandsDUnit1.jar#1"));
+    assertThat(stringContainsLine(stringResult, "Member.*JAR.*Un-Deployed From JAR Location"))
+        .describedAs(stringResult).isTrue();
+    assertThat(stringContainsLine(stringResult, "Manager.*DeployCommandsDUnit1.jar.*"
+        + JarDeployer.JAR_PREFIX + "DeployCommandsDUnit1.jar#1")).describedAs(stringResult)
+            .isTrue();;
+
 
     // Deploy the JAR to a group
     cmdResult = executeCommand(
         "deploy --jar=" + this.newDeployableJarFile.getCanonicalPath() + " --group=" + groupName);
-    assertEquals(Result.Status.OK, cmdResult.getStatus());
+    assertThat(cmdResult.getStatus()).describedAs(cmdResult.toString()).isEqualTo(Result.Status.OK);
 
     stringResult = commandResultToString(cmdResult);
     assertEquals(3, countLinesInString(stringResult, false));
-    assertTrue(stringContainsLine(stringResult, "Member.*JAR.*JAR Location"));
-    assertTrue(stringContainsLine(stringResult, "Manager.*DeployCommandsDUnit1.jar.*"
-        + JarDeployer.JAR_PREFIX + "DeployCommandsDUnit1.jar#1"));
+    assertThat(stringContainsLine(stringResult, "Member.*JAR.*JAR Location"))
+        .describedAs(stringResult).isTrue();
+
+    assertThat(stringContainsLine(stringResult, "Manager.*DeployCommandsDUnit1.jar.*"
+        + JarDeployer.JAR_PREFIX + "DeployCommandsDUnit1.jar#1")).describedAs(stringResult)
+            .isTrue();
 
     // Make sure the deployed jar in the shared config
-    Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
       @Override
       public void run() {
         SharedConfiguration sharedConfig =
@@ -434,7 +476,7 @@ public class DeployCommandsDUnitTest extends CliCommandTestBase {
         + JarDeployer.JAR_PREFIX + "DeployCommandsDUnit1.jar#1"));
 
     // Make sure the deployed jar was removed from the shared config
-    Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
       @Override
       public void run() {
         SharedConfiguration sharedConfig =

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsDUnitTest.java
index 901ed29..a04bbe8 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsDUnitTest.java
@@ -16,6 +16,11 @@ package org.apache.geode.management.internal.cli.commands;
 
 import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
 import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
+import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_BIND_ADDRESS;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_START;
 import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
 import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
 import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
@@ -30,18 +35,6 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.StringTokenizer;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.TimeUnit;
 
 import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.CacheFactory;
@@ -86,6 +79,19 @@ import org.apache.geode.test.junit.categories.FlakyTest;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
+import java.io.File;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.TimeUnit;
+
 /**
  * The DiskStoreCommandsDUnitTest class is a distributed test suite of test cases for testing the
  * disk store commands that are part of Gfsh.
@@ -722,22 +728,35 @@ public class DiskStoreCommandsDUnitTest extends CliCommandTestBase {
   @Test
   public void testCreateDestroyUpdatesSharedConfig() {
     disconnectAllFromDS();
+    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
+    jmxPort = ports[0];
+    httpPort = ports[1];
+    try {
+      jmxHost = InetAddress.getLocalHost().getHostName();
+    } catch (UnknownHostException ignore) {
+      jmxHost = "localhost";
+    }
 
     final String groupName = "testDiskStoreSharedConfigGroup";
     final String diskStoreName = "testDiskStoreSharedConfigDiskStore";
 
     // Start the Locator and wait for shared configuration to be available
     final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-    Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+    final Properties locatorProps = new Properties();
+    locatorProps.setProperty(NAME, "Locator");
+    locatorProps.setProperty(MCAST_PORT, "0");
+    locatorProps.setProperty(LOG_LEVEL, "fine");
+    locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+    locatorProps.setProperty(JMX_MANAGER, "true");
+    locatorProps.setProperty(JMX_MANAGER_START, "true");
+    locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
+    locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
+    locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
+
+    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
       @Override
       public void run() {
-
         final File locatorLogFile = new File("locator-" + locatorPort + ".log");
-        final Properties locatorProps = new Properties();
-        locatorProps.setProperty(NAME, "Locator");
-        locatorProps.setProperty(MCAST_PORT, "0");
-        locatorProps.setProperty(LOG_LEVEL, "fine");
-        locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
         try {
           final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort,
               locatorLogFile, null, locatorProps);
@@ -760,11 +779,7 @@ public class DiskStoreCommandsDUnitTest extends CliCommandTestBase {
       }
     });
 
-    // Start the default manager
-    Properties managerProps = new Properties();
-    managerProps.setProperty(MCAST_PORT, "0");
-    managerProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
-    setUpJmxManagerOnVm0ThenConnect(managerProps);
+    connect(jmxHost, jmxPort, httpPort, getDefaultShell());
 
     // Create a cache in VM 1
     final File diskStoreDir = new File(new File(".").getAbsolutePath(), diskStoreName);
@@ -795,7 +810,7 @@ public class DiskStoreCommandsDUnitTest extends CliCommandTestBase {
     assertEquals(Result.Status.OK, cmdResult.getStatus());
 
     // Make sure the disk store exists in the shared config
-    Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
       @Override
       public void run() {
         SharedConfiguration sharedConfig =
@@ -847,7 +862,7 @@ public class DiskStoreCommandsDUnitTest extends CliCommandTestBase {
     assertEquals(Result.Status.OK, cmdResult.getStatus());
 
     // Make sure the disk store was removed from the shared config
-    Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
       @Override
       public void run() {
         SharedConfiguration sharedConfig =

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/IndexCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/IndexCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/IndexCommandsDUnitTest.java
index 6dbd10c..81c4545 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/IndexCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/IndexCommandsDUnitTest.java
@@ -14,19 +14,52 @@
  */
 package org.apache.geode.management.internal.cli.commands;
 
-import org.apache.geode.cache.*;
+import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
+import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_BIND_ADDRESS;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_START;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.NAME;
+import static org.apache.geode.distributed.ConfigurationProperties.USE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.test.dunit.Assert.assertEquals;
+import static org.apache.geode.test.dunit.Assert.assertFalse;
+import static org.apache.geode.test.dunit.Assert.assertNotNull;
+import static org.apache.geode.test.dunit.Assert.assertNull;
+import static org.apache.geode.test.dunit.Assert.assertTrue;
+import static org.apache.geode.test.dunit.Assert.fail;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.DataPolicy;
+import org.apache.geode.cache.DiskStoreFactory;
+import org.apache.geode.cache.EvictionAction;
+import org.apache.geode.cache.EvictionAttributes;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionFactory;
 import org.apache.geode.cache.query.Index;
 import org.apache.geode.distributed.Locator;
 import org.apache.geode.distributed.internal.InternalLocator;
 import org.apache.geode.distributed.internal.SharedConfiguration;
 import org.apache.geode.internal.AvailablePort;
+import org.apache.geode.internal.AvailablePortHelper;
 import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.cli.Result.Status;
 import org.apache.geode.management.internal.cli.domain.Stock;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
 import org.apache.geode.management.internal.cli.result.CommandResult;
 import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
-import org.apache.geode.test.dunit.*;
+import org.apache.geode.test.dunit.Assert;
+import org.apache.geode.test.dunit.Host;
+import org.apache.geode.test.dunit.LogWriterUtils;
+import org.apache.geode.test.dunit.SerializableCallable;
+import org.apache.geode.test.dunit.SerializableRunnable;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.Wait;
+import org.apache.geode.test.dunit.WaitCriterion;
 import org.apache.geode.test.junit.categories.DistributedTest;
 import org.apache.geode.test.junit.categories.FlakyTest;
 import org.junit.Test;
@@ -34,11 +67,10 @@ import org.junit.experimental.categories.Category;
 
 import java.io.File;
 import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.util.Properties;
 
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.apache.geode.test.dunit.Assert.*;
-
 @Category(DistributedTest.class)
 public class IndexCommandsDUnitTest extends CliCommandTestBase {
 
@@ -595,22 +627,35 @@ public class IndexCommandsDUnitTest extends CliCommandTestBase {
   @Test
   public void testCreateDestroyUpdatesSharedConfig() {
     disconnectAllFromDS();
+    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
+    jmxPort = ports[0];
+    httpPort = ports[1];
+    try {
+      jmxHost = InetAddress.getLocalHost().getHostName();
+    } catch (UnknownHostException ignore) {
+      jmxHost = "localhost";
+    }
 
     final String regionName = "testIndexSharedConfigRegion";
     final String groupName = "testIndexSharedConfigGroup";
 
+    final Properties locatorProps = new Properties();
+    locatorProps.setProperty(NAME, "Locator");
+    locatorProps.setProperty(MCAST_PORT, "0");
+    locatorProps.setProperty(LOG_LEVEL, "fine");
+    locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+    locatorProps.setProperty(JMX_MANAGER, "true");
+    locatorProps.setProperty(JMX_MANAGER_START, "true");
+    locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
+    locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
+    locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
+
     // Start the Locator and wait for shared configuration to be available
     final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-    Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
       @Override
       public void run() {
-
         final File locatorLogFile = new File("locator-" + locatorPort + ".log");
-        final Properties locatorProps = new Properties();
-        locatorProps.setProperty(NAME, "Locator");
-        locatorProps.setProperty(MCAST_PORT, "0");
-        locatorProps.setProperty(LOG_LEVEL, "fine");
-        locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
         try {
           final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort,
               locatorLogFile, null, locatorProps);
@@ -634,10 +679,7 @@ public class IndexCommandsDUnitTest extends CliCommandTestBase {
     });
 
     // Start the default manager
-    Properties managerProps = new Properties();
-    managerProps.setProperty(MCAST_PORT, "0");
-    managerProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
-    setUpJmxManagerOnVm0ThenConnect(managerProps);
+    connect(jmxHost, jmxPort, httpPort, getDefaultShell());
 
     // Create a cache in VM 1
     VM vm = Host.getHost(0).getVM(1);
@@ -666,7 +708,7 @@ public class IndexCommandsDUnitTest extends CliCommandTestBase {
     assertEquals(Result.Status.OK, cmdResult.getStatus());
 
     // Make sure the index exists in the shared config
-    Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
       @Override
       public void run() {
         SharedConfiguration sharedConfig =
@@ -712,7 +754,7 @@ public class IndexCommandsDUnitTest extends CliCommandTestBase {
     assertEquals(Result.Status.OK, cmdResult.getStatus());
 
     // Make sure the index was removed from the shared config
-    Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
       @Override
       public void run() {
         SharedConfiguration sharedConfig =

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/QueueCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/QueueCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/QueueCommandsDUnitTest.java
index b1897ba..98014a4 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/QueueCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/QueueCommandsDUnitTest.java
@@ -14,7 +14,25 @@
  */
 package org.apache.geode.management.internal.cli.commands;
 
-import static org.apache.geode.distributed.ConfigurationProperties.*;
+import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
+import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_BIND_ADDRESS;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_START;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.NAME;
+import static org.apache.geode.distributed.ConfigurationProperties.USE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.test.dunit.Assert.assertEquals;
+import static org.apache.geode.test.dunit.Assert.assertFalse;
+import static org.apache.geode.test.dunit.Assert.assertNotNull;
+import static org.apache.geode.test.dunit.Assert.assertTrue;
+import static org.apache.geode.test.dunit.Assert.fail;
+import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
+import static org.apache.geode.test.dunit.Wait.waitForCriterion;
 
 import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.asyncqueue.AsyncEventQueue;
@@ -22,6 +40,7 @@ import org.apache.geode.distributed.Locator;
 import org.apache.geode.distributed.internal.InternalLocator;
 import org.apache.geode.distributed.internal.SharedConfiguration;
 import org.apache.geode.internal.AvailablePort;
+import org.apache.geode.internal.AvailablePortHelper;
 import org.apache.geode.internal.ClassBuilder;
 import org.apache.geode.internal.FileUtil;
 import org.apache.geode.management.cli.Result;
@@ -41,16 +60,12 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.util.List;
 import java.util.Properties;
 import java.util.concurrent.CopyOnWriteArrayList;
 
-import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
-import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
-import static org.apache.geode.test.dunit.Assert.*;
-import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
-import static org.apache.geode.test.dunit.Wait.waitForCriterion;
-
 /**
  * A distributed test suite of test cases for testing the queue commands that are part of Gfsh.
  *
@@ -257,22 +272,36 @@ public class QueueCommandsDUnitTest extends CliCommandTestBase {
   @Test
   public void testCreateUpdatesSharedConfig() throws IOException {
     disconnectAllFromDS();
+    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
+    jmxPort = ports[0];
+    httpPort = ports[1];
+    try {
+      jmxHost = InetAddress.getLocalHost().getHostName();
+    } catch (UnknownHostException ignore) {
+      jmxHost = "localhost";
+    }
 
     final String queueName = "testAsyncEventQueueQueue";
     final String groupName = "testAsyncEventQueueSharedConfigGroup";
 
+    final Properties locatorProps = new Properties();
+    locatorProps.setProperty(NAME, "Locator");
+    locatorProps.setProperty(MCAST_PORT, "0");
+    locatorProps.setProperty(LOG_LEVEL, "fine");
+    locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+    locatorProps.setProperty(JMX_MANAGER, "true");
+    locatorProps.setProperty(JMX_MANAGER_START, "true");
+    locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
+    locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
+    locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
+
     // Start the Locator and wait for shared configuration to be available
     final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-    Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
       @Override
       public void run() {
-
         final File locatorLogFile = new File("locator-" + locatorPort + ".log");
-        final Properties locatorProps = new Properties();
-        locatorProps.setProperty(NAME, "Locator");
-        locatorProps.setProperty(MCAST_PORT, "0");
-        locatorProps.setProperty(LOG_LEVEL, "fine");
-        locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+
         try {
           final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort,
               locatorLogFile, null, locatorProps);
@@ -295,11 +324,7 @@ public class QueueCommandsDUnitTest extends CliCommandTestBase {
       }
     });
 
-    // Start the default manager
-    Properties managerProps = new Properties();
-    managerProps.setProperty(MCAST_PORT, "0");
-    managerProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
-    setUpJmxManagerOnVm0ThenConnect(managerProps);
+    connect(jmxHost, jmxPort, httpPort, getDefaultShell());
 
     // Create a cache in VM 1
     VM vm = Host.getHost(0).getVM(1);
@@ -347,7 +372,7 @@ public class QueueCommandsDUnitTest extends CliCommandTestBase {
     assertEquals(Result.Status.OK, cmdResult.getStatus());
 
     // Make sure the queue exists in the shared config
-    Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
       @Override
       public void run() {
         SharedConfiguration sharedConfig =

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java
index 28890b8..506428a 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java
@@ -57,9 +57,10 @@ public class ClusterConfigBaseTest extends JUnit4DistributedTestCase {
   @Before
   public void before() throws Exception {
     locatorProps = new Properties();
-    locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
-
     serverProps = new Properties();
+
+    // the following are default values, we don't need to set them. We do it for clarity purpose
+    locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
     serverProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
   }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java
index a501235..51a77d2 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java
@@ -66,7 +66,7 @@ public class ClusterConfigDeployJarDUnitTest extends ClusterConfigBaseTest {
   }
 
   @Test
-  public void testDeployToMultipleLocaotrs() throws Exception {
+  public void testDeployToMultipleLocators() throws Exception {
     Locator locator = lsRule.startLocatorVM(0, locatorProps);
     locatorProps.setProperty(LOCATORS, "localhost[" + locator.getPort() + "]");
     Locator locator2 = lsRule.startLocatorVM(1, locatorProps);

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDistributionDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDistributionDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDistributionDUnitTest.java
new file mode 100644
index 0000000..d72e386
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDistributionDUnitTest.java
@@ -0,0 +1,164 @@
+/*
+ * 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;
+
+import static org.apache.commons.io.FileUtils.writeByteArrayToFile;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.asyncqueue.AsyncEventQueue;
+import org.apache.geode.cache.query.Index;
+import org.apache.geode.internal.ClassBuilder;
+import org.apache.geode.management.internal.cli.i18n.CliStrings;
+import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
+import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
+import org.apache.geode.test.dunit.rules.GfshShellConnectionRule;
+import org.apache.geode.test.dunit.rules.Locator;
+import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
+import org.apache.geode.test.dunit.rules.Server;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+
+@Category(DistributedTest.class)
+public class ClusterConfigDistributionDUnitTest extends JUnit4DistributedTestCase {
+  private static final String REPLICATE_REGION = "ReplicateRegion1";
+  private static final String PARTITION_REGION = "PartitionRegion1";
+  private static final String INDEX1 = "ID1";
+  private static final String INDEX2 = "ID2";
+  private static final String AsyncEventQueue1 = "Q1";
+
+  private Locator locator;
+  private GfshShellConnectionRule gfshConnector;
+
+  @Before
+  public void before() throws Exception {
+    locator = lsRule.startLocatorVM(0);
+
+    gfshConnector = new GfshShellConnectionRule(locator);
+    gfshConnector.connect();
+    assertThat(gfshConnector.isConnected()).isTrue();
+  }
+
+  @Rule
+  public LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
+
+  @Test
+  public void testIndexAndAsyncEventQueueCommands() throws Exception {
+    lsRule.startServerVM(1, locator.getPort());
+
+    final String DESTROY_REGION = "regionToBeDestroyed";
+
+    gfshConnector
+        .executeAndVerifyCommand("create region --name=" + REPLICATE_REGION + " --type=REPLICATE");
+    gfshConnector
+        .executeAndVerifyCommand("create region --name=" + PARTITION_REGION + " --type=PARTITION");
+    gfshConnector
+        .executeAndVerifyCommand("create region --name=" + DESTROY_REGION + " --type=REPLICATE");
+
+    gfshConnector.executeAndVerifyCommand(
+        "create index --name=" + INDEX1 + " --expression=AAPL --region=" + REPLICATE_REGION);
+    gfshConnector.executeAndVerifyCommand(
+        "create index --name=" + INDEX2 + " --expression=VMW --region=" + PARTITION_REGION);
+
+
+    String asyncEventQueueJarPath = createAsyncEventQueueJar();
+    gfshConnector.executeAndVerifyCommand("deploy jar --jar=" + asyncEventQueueJarPath);
+
+
+    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_ASYNC_EVENT_QUEUE);
+    csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__ID, AsyncEventQueue1);
+    csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__LISTENER,
+        "com.qcdunit.QueueCommandsDUnitTestListener");
+    csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISK_STORE, null);
+    csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__BATCH_SIZE, "1000");
+    csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__GROUP, null);
+    csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__PERSISTENT, "false");
+    csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__MAXIMUM_QUEUE_MEMORY, "1000");
+    gfshConnector.executeAndVerifyCommand(csb.getCommandString());
+
+    gfshConnector.executeAndVerifyCommand("destroy region --name=" + DESTROY_REGION);
+
+    gfshConnector.executeAndVerifyCommand(
+        "destroy index --name=" + INDEX2 + " --region=" + PARTITION_REGION);
+    gfshConnector.executeAndVerifyCommand("alter runtime --copy-on-read=true");
+
+    // Start a new member which receives the shared configuration
+    // Verify the config creation on this member
+
+    Server server = lsRule.startServerVM(2, new Properties(), locator.getPort());
+
+    server.invoke(() -> {
+      Cache cache = LocatorServerStartupRule.serverStarter.cache;
+      assertNotNull(cache);
+      assertTrue(cache.getCopyOnRead());
+
+      Region region1 = cache.getRegion(REPLICATE_REGION);
+      assertNotNull(region1);
+      Region region2 = cache.getRegion(PARTITION_REGION);
+      assertNotNull(region2);
+
+      Region region3 = cache.getRegion(DESTROY_REGION);
+      assertNull(region3);
+
+      // Index verification
+      Index index1 = cache.getQueryService().getIndex(region1, INDEX1);
+      assertNotNull(index1);
+      assertNull(cache.getQueryService().getIndex(region2, INDEX2));
+
+      // ASYNC-EVENT-QUEUE verification
+      AsyncEventQueue aeq = cache.getAsyncEventQueue(AsyncEventQueue1);
+      assertNotNull(aeq);
+      assertFalse(aeq.isPersistent());
+      assertTrue(aeq.getBatchSize() == 1000);
+      assertTrue(aeq.getMaximumQueueMemory() == 1000);
+    });
+  }
+
+
+  private String createAsyncEventQueueJar() throws IOException {
+    String queueCommandsJarName = this.lsRule.getTempFolder().getRoot().getCanonicalPath()
+        + File.separator + "testEndToEndSC-QueueCommands.jar";
+    final File jarFile = new File(queueCommandsJarName);
+
+    ClassBuilder classBuilder = new ClassBuilder();
+    byte[] jarBytes =
+        classBuilder.createJarFromClassContent("com/qcdunit/QueueCommandsDUnitTestListener",
+            "package com.qcdunit;" + "import java.util.List; import java.util.Properties;"
+                + "import org.apache.geode.internal.cache.xmlcache.Declarable2; import org.apache.geode.cache.asyncqueue.AsyncEvent;"
+                + "import org.apache.geode.cache.asyncqueue.AsyncEventListener;"
+                + "public class QueueCommandsDUnitTestListener implements Declarable2, AsyncEventListener {"
+                + "Properties props;"
+                + "public boolean processEvents(List<AsyncEvent> events) { return true; }"
+                + "public void close() {}"
+                + "public void init(final Properties props) {this.props = props;}"
+                + "public Properties getConfig() {return this.props;}}");
+
+    writeByteArrayToFile(jarFile, jarBytes);
+    return queueCommandsJarName;
+  }
+}


[2/4] geode git commit: GEODE-2261: do not use remote function calls to update the shared configuration

Posted by ji...@apache.org.
http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/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 cd8500a..b301b80 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
@@ -83,7 +83,10 @@ public class ClusterConfigImportDUnitTest extends ClusterConfigBaseTest {
         "import cluster-configuration --zip-file-name=" + EXPORTED_CLUSTER_CONFIG_PATH);
     assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
 
-    // TODO: For [GEODE-2229] we will want to assert that a backup is created
+    // Make sure that a backup of the old clusterConfig was created
+    assertThat(locator.getWorkingDir().listFiles())
+        .filteredOn((File file) -> file.getName().contains("cluster_config")).hasSize(2);
+
     CONFIG_FROM_ZIP.verify(locator);
 
     // start server1 with no group
@@ -102,12 +105,10 @@ public class ClusterConfigImportDUnitTest extends ClusterConfigBaseTest {
   }
 
   @Test
-  @Category(FlakyTest.class) // remove after GEODE-2261 is implemented
   public void testImportWithMultipleLocators() throws Exception {
     locatorProps.setProperty(LOCATORS, "localhost[" + locator.getPort() + "]");
     Locator locator1 = lsRule.startLocatorVM(1, locatorProps);
 
-
     locatorProps.setProperty(LOCATORS,
         "localhost[" + locator.getPort() + "],localhost[" + locator1.getPort() + "]");
     Locator locator2 = lsRule.startLocatorVM(2, locatorProps);
@@ -116,6 +117,7 @@ public class ClusterConfigImportDUnitTest extends ClusterConfigBaseTest {
         "import cluster-configuration --zip-file-name=" + EXPORTED_CLUSTER_CONFIG_PATH);
     assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
 
+    CONFIG_FROM_ZIP.verify(locator);
     REPLICATED_CONFIG_FROM_ZIP.verify(locator1);
     REPLICATED_CONFIG_FROM_ZIP.verify(locator2);
   }
@@ -136,6 +138,8 @@ public class ClusterConfigImportDUnitTest extends ClusterConfigBaseTest {
     Path exportedZipPath = lsRule.getTempFolder().getRoot().toPath().resolve("exportedCC.zip");
     result = gfshConnector
         .executeCommand("export cluster-configuration --zip-file-name=" + exportedZipPath);
+    System.out.println(result.getContent());
+
     assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
 
     File exportedZip = exportedZipPath.toFile();

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationDUnitTest.java
index 2e733a7..b310c50 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationDUnitTest.java
@@ -245,11 +245,9 @@ public class SharedConfigurationDUnitTest extends JUnit4CacheTestCase {
       } catch (IOException e) {
         fail("Unable to create a locator with a shared configuration", e);
       }
-
-      return null;
     });
 
-    dataMemberVm.invoke(() -> {
+    XmlEntity xmlEntity = dataMemberVm.invoke(() -> {
       Properties localProps = new Properties();
       localProps.setProperty(MCAST_PORT, "0");
       localProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
@@ -269,13 +267,13 @@ public class SharedConfigurationDUnitTest extends JUnit4CacheTestCase {
 
       RegionFactory regionFactory = getCache().createRegionFactory(RegionShortcut.REPLICATE);
       regionFactory.create(REGION1);
+      return new XmlEntity(CacheXml.REGION, "name", REGION1);
+    });
 
-      XmlEntity xmlEntity = new XmlEntity(CacheXml.REGION, "name", REGION1);
-      final SharedConfigurationWriter scw = new SharedConfigurationWriter();
-      assertTrue(scw.addXmlEntity(xmlEntity, new String[] {testGroup}));
+    locator1Vm.invoke(() -> {
+      SharedConfiguration sc = InternalLocator.getLocator().getSharedConfiguration();
+      sc.addXmlEntity(xmlEntity, new String[] {testGroup});
 
-      xmlEntity = new XmlEntity(CacheXml.DISK_STORE, "name", DISKSTORENAME);
-      assertTrue(scw.addXmlEntity(xmlEntity, new String[] {testGroup}));
       // Modify property and cache attributes
       Properties clusterProperties = new Properties();
       clusterProperties.setProperty(LOG_LEVEL, clusterLogLevel);
@@ -283,22 +281,21 @@ public class SharedConfigurationDUnitTest extends JUnit4CacheTestCase {
       Map<String, String> cacheAttributes = new HashMap<String, String>();
       cacheAttributes.put(CacheXml.COPY_ON_READ, "true");
 
-      assertTrue(scw.modifyPropertiesAndCacheAttributes(clusterProperties, cacheEntity, null));
+      sc.modifyXmlAndProperties(clusterProperties, cacheEntity, null);
 
       clusterProperties.setProperty(LOG_LEVEL, groupLogLevel);
-      assertTrue(scw.modifyPropertiesAndCacheAttributes(clusterProperties, cacheEntity,
-          new String[] {testGroup}));
+      sc.modifyXmlAndProperties(clusterProperties, cacheEntity, new String[] {testGroup});
 
       // Add a jar
       byte[][] jarBytes = new byte[1][];
       jarBytes[0] = "Hello".getBytes();
-      assertTrue(scw.addJars(new String[] {"foo.jar"}, jarBytes, null));
+      assertTrue(sc.addJarsToThisLocator(new String[] {"foo.jar"}, jarBytes, null));
 
       // Add a jar for the group
       jarBytes = new byte[1][];
       jarBytes[0] = "Hello".getBytes();
-      assertTrue(scw.addJars(new String[] {"bar.jar"}, jarBytes, new String[] {testGroup}));
-      return null;
+      assertTrue(
+          sc.addJarsToThisLocator(new String[] {"bar.jar"}, jarBytes, new String[] {testGroup}));
     });
 
     final int locator2Port = ports[1];
@@ -363,16 +360,13 @@ public class SharedConfigurationDUnitTest extends JUnit4CacheTestCase {
       assertNotNull(jarNames);
       assertNotNull(jarBytes);
 
-      return null;
+      sharedConfig.deleteXmlEntity(new XmlEntity(CacheXml.REGION, "name", REGION1),
+          new String[] {testGroup});
+      sharedConfig.removeJars(new String[] {"foo.jar"}, null);
+      sharedConfig.removeJars(null, null);
     });
 
     dataMemberVm.invoke(() -> {
-      SharedConfigurationWriter scw = new SharedConfigurationWriter();
-      scw.deleteXmlEntity(new XmlEntity(CacheXml.REGION, "name", REGION1),
-          new String[] {testGroup});
-      scw.deleteJars(new String[] {"foo.jar"}, null);
-      scw.deleteJars(null, null);
-
       Set<String> groups = new HashSet<String>();
       groups.add(testGroup);
       ConfigurationRequest configRequest = new ConfigurationRequest(groups);

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/management/internal/configuration/utils/XmlUtilsJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/utils/XmlUtilsJUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/utils/XmlUtilsJUnitTest.java
index 3992146..c5bdf07 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/utils/XmlUtilsJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/utils/XmlUtilsJUnitTest.java
@@ -28,6 +28,8 @@ import javax.xml.XMLConstants;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.xpath.XPathExpressionException;
 
+import org.apache.commons.io.IOUtils;
+import org.apache.geode.internal.cache.xmlcache.CacheXml;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.w3c.dom.Document;
@@ -236,4 +238,20 @@ public class XmlUtilsJUnitTest {
     assertEquals(ns2, root.getElementsByTagName("childWithNamespace").item(0).getNamespaceURI());
   }
 
+  @Test
+  public void testCreateAndUpgradeDocumentFromXml() throws Exception {
+    Document doc = XmlUtils.createAndUpgradeDocumentFromXml(
+        IOUtils.toString(this.getClass().getResourceAsStream("SharedConfigurationJUnitTest.xml")));
+
+    String schemaLocation = XmlUtils.getAttribute(doc.getDocumentElement(),
+        W3C_XML_SCHEMA_INSTANCE_ATTRIBUTE_SCHEMA_LOCATION, W3C_XML_SCHEMA_INSTANCE_NS_URI);
+
+    assertNotNull(schemaLocation);
+    assertEquals(CacheXml.GEODE_NAMESPACE + " " + CacheXml.LATEST_SCHEMA_LOCATION, schemaLocation);
+
+    assertEquals(CacheXml.VERSION_LATEST,
+        XmlUtils.getAttribute(doc.getDocumentElement(), "version"));
+  }
+
+
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/redis/SetsJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/redis/SetsJUnitTest.java b/geode-core/src/test/java/org/apache/geode/redis/SetsJUnitTest.java
index 2d4a929..aaa7724 100755
--- a/geode-core/src/test/java/org/apache/geode/redis/SetsJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/redis/SetsJUnitTest.java
@@ -14,28 +14,28 @@
  */
 package org.apache.geode.redis;
 
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 import org.apache.geode.cache.CacheFactory;
 import org.apache.geode.cache.GemFireCache;
 import org.apache.geode.internal.AvailablePortHelper;
 import org.apache.geode.test.junit.categories.IntegrationTest;
-
-import org.apache.geode.redis.GeodeRedisServer;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
-import redis.clients.jedis.Jedis;
 
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Random;
 import java.util.Set;
-
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import redis.clients.jedis.Jedis;
 
 @Category(IntegrationTest.class)
 public class SetsJUnitTest {

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java
index 9e46ad0..718c816 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java
@@ -14,6 +14,8 @@
  */
 package org.apache.geode.test.dunit.rules;
 
+import static org.assertj.core.api.Assertions.assertThat;
+
 import com.jayway.awaitility.Awaitility;
 import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.cli.CliUtil;
@@ -130,6 +132,13 @@ public class GfshShellConnectionRule extends DescribedExternalResource {
     return (CommandResult) gfsh.getResult();
   }
 
+  public CommandResult executeAndVerifyCommand(String command) throws Exception {
+    CommandResult result = executeCommand(command);
+    assertThat(result.getStatus()).describedAs(result.getContent().toString())
+        .isEqualTo(Result.Status.OK);
+    return result;
+  }
+
   public boolean isConnected() {
     return connected;
   }

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerConfigurationRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerConfigurationRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerConfigurationRule.java
new file mode 100644
index 0000000..bbca60c
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerConfigurationRule.java
@@ -0,0 +1,151 @@
+/*
+ * 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.test.dunit.rules;
+
+import static org.apache.geode.distributed.ConfigurationProperties.*;
+import static org.apache.geode.test.dunit.Host.*;
+import static org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase.*;
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+import com.jayway.awaitility.Awaitility;
+import org.junit.rules.ExternalResource;
+
+import org.apache.geode.distributed.Locator;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.distributed.internal.InternalLocator;
+import org.apache.geode.test.dunit.Host;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
+import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
+
+
+public class LocatorServerConfigurationRule extends ExternalResource implements Serializable {
+
+  private int locatorPort = 0;
+
+  private boolean locatorInitialized = false;
+
+  private JUnit4DistributedTestCase testCase;
+
+  public LocatorServerConfigurationRule(JUnit4DistributedTestCase testCase) {
+    this.testCase = testCase;
+  }
+
+  Host host = getHost(0);
+  VM locator = host.getVM(0);
+
+  @Override
+  protected void before() {
+    // Add initialization requirement if any.
+    disconnectAllFromDS();
+  }
+
+  @Override
+  protected void after() {
+    disconnectAllFromDS();
+  }
+
+  /**
+   * Returns getHost(0).getVM(0) as a locator instance with the given configuration properties.
+   * 
+   * @param locatorProperties
+   *
+   * @return VM locator vm
+   *
+   * @throws IOException
+   */
+  public VM getLocatorVM(Properties locatorProperties) throws IOException {
+    if (!locatorProperties.containsKey(MCAST_PORT)) {
+      locatorProperties.setProperty(MCAST_PORT, "0");
+    }
+
+    locatorPort = locator.invoke(() -> {
+      InternalLocator locator =
+          (InternalLocator) Locator.startLocatorAndDS(0, null, locatorProperties);
+      locator.resetInternalLocatorFileNamesWithCorrectPortNumber(locatorPort);
+
+      if (locator.getConfig().getEnableClusterConfiguration()) {
+        Awaitility.await().atMost(65, TimeUnit.SECONDS)
+            .until(() -> assertTrue(locator.isSharedConfigurationRunning()));
+      }
+      return locator.getPort();
+    });
+
+    this.locatorInitialized = true;
+    return locator;
+  }
+
+  /**
+   * Returns a node VM with given configuration properties.
+   * 
+   * @param index valid 1 to 3 (returns getHist(0).getVM(index)
+   * @param properties
+   *
+   * @return VM node vm
+   */
+  public VM getServerVM(int index, Properties properties) {
+    assertTrue("Locator not initialized. Initialize locator by calling getLocatorVM()",
+        this.locatorInitialized);
+    assertTrue("VM with index 0 is used for locator service.", (index != 0));
+    VM nodeVM = getNodeVM(index);
+    nodeVM.invoke(() -> {
+      getSystem(properties);
+    });
+    return nodeVM;
+  }
+
+  /**
+   * this will simply returns the node
+   * 
+   * @param index
+   * @return
+   */
+  public VM getNodeVM(int index) {
+    return host.getVM(index);
+  }
+
+  public InternalDistributedSystem getSystem(Properties properties) {
+    if (!properties.containsKey(MCAST_PORT)) {
+      properties.setProperty(MCAST_PORT, "0");
+    }
+    properties.setProperty(LOCATORS, getHostName() + "[" + locatorPort + "]");
+    InternalDistributedSystem ds = testCase.getSystem(properties);
+    if (testCase instanceof JUnit4CacheTestCase) {
+      ((JUnit4CacheTestCase) testCase).getCache();
+    }
+    return ds;
+  }
+
+  public int getLocatorPort() {
+    return locatorPort;
+  }
+
+  private String getHostName() {
+    try {
+      return InetAddress.getLocalHost().getHostName();
+    } catch (UnknownHostException ignore) {
+      return "localhost";
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
index 04fad5d..300d75a 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
@@ -97,6 +97,10 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial
     return locator;
   }
 
+  public Locator startLocatorVM(int index) throws IOException {
+    return startLocatorVM(index, new Properties());
+  }
+
   /**
    * starts a cache server that does not connect to a locator
    * 
@@ -106,6 +110,10 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial
     return startServerVM(index, properties, 0);
   }
 
+  public Server startServerVM(int index, int locatorPort) throws IOException {
+    return startServerVM(index, new Properties(), locatorPort);
+  }
+
   /**
    * Starts a cache server that connect to the locator running at the given port.
    */

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/resources/org/apache/geode/distributed/internal/SharedConfigurationJUnitTest.xml
----------------------------------------------------------------------
diff --git a/geode-core/src/test/resources/org/apache/geode/distributed/internal/SharedConfigurationJUnitTest.xml b/geode-core/src/test/resources/org/apache/geode/distributed/internal/SharedConfigurationJUnitTest.xml
deleted file mode 100644
index 68ce00f..0000000
--- a/geode-core/src/test/resources/org/apache/geode/distributed/internal/SharedConfigurationJUnitTest.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.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.
--->
-
-<!DOCTYPE cache PUBLIC
-    "-//GemStone Systems, Inc.//GemFire Declarative Caching 8.0//EN"
-    "http://www.gemstone.com/dtd/cache8_0.dtd">
-<cache>
-</cache>

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/utils/SharedConfigurationJUnitTest.xml
----------------------------------------------------------------------
diff --git a/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/utils/SharedConfigurationJUnitTest.xml b/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/utils/SharedConfigurationJUnitTest.xml
new file mode 100644
index 0000000..68ce00f
--- /dev/null
+++ b/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/utils/SharedConfigurationJUnitTest.xml
@@ -0,0 +1,23 @@
+<?xml version="1.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.
+-->
+
+<!DOCTYPE cache PUBLIC
+    "-//GemStone Systems, Inc.//GemFire Declarative Caching 8.0//EN"
+    "http://www.gemstone.com/dtd/cache8_0.dtd">
+<cache>
+</cache>

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-wan/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-wan/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationDUnitTest.java b/geode-wan/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationDUnitTest.java
deleted file mode 100644
index f73a393..0000000
--- a/geode-wan/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationDUnitTest.java
+++ /dev/null
@@ -1,1055 +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;
-
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionShortcut;
-import org.apache.geode.cache.asyncqueue.AsyncEventQueue;
-import org.apache.geode.cache.query.Index;
-import org.apache.geode.cache.wan.GatewayReceiver;
-import org.apache.geode.cache.wan.GatewaySender;
-import org.apache.geode.cache.wan.GatewaySender.OrderPolicy;
-import org.apache.geode.distributed.Locator;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.internal.ClassBuilder;
-import org.apache.geode.internal.JarClassLoader;
-import org.apache.geode.internal.JarDeployer;
-import org.apache.geode.internal.admin.remote.ShutdownAllRequest;
-import org.apache.geode.internal.cache.DiskStoreImpl;
-import org.apache.geode.internal.cache.GemFireCacheImpl;
-import org.apache.geode.internal.cache.extension.Extensible;
-import org.apache.geode.internal.cache.extension.Extension;
-import org.apache.geode.internal.cache.extension.mock.MockCacheExtension;
-import org.apache.geode.internal.cache.extension.mock.MockExtensionCommands;
-import org.apache.geode.internal.cache.extension.mock.MockRegionExtension;
-import org.apache.geode.internal.cache.xmlcache.XmlGenerator;
-import org.apache.geode.internal.cache.xmlcache.XmlParser;
-import org.apache.geode.management.cli.Result.Status;
-import org.apache.geode.management.internal.cli.HeadlessGfsh;
-import org.apache.geode.management.internal.cli.commands.CliCommandTestBase;
-import org.apache.geode.management.internal.cli.i18n.CliStrings;
-import org.apache.geode.management.internal.cli.result.CommandResult;
-import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
-import org.apache.geode.management.internal.configuration.domain.XmlEntity;
-import org.apache.geode.test.dunit.SerializableCallable;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.WaitCriterion;
-import org.apache.geode.test.junit.categories.DistributedTest;
-import org.apache.geode.test.junit.categories.FlakyTest;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.*;
-import java.util.Map.Entry;
-
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts;
-import static org.apache.geode.internal.FileUtil.delete;
-import static org.apache.geode.internal.FileUtil.deleteMatching;
-import static org.apache.geode.internal.lang.StringUtils.isBlank;
-import static org.apache.geode.management.internal.cli.CliUtil.getAllNormalMembers;
-import static org.apache.geode.test.dunit.Assert.*;
-import static org.apache.geode.test.dunit.Host.getHost;
-import static org.apache.geode.test.dunit.IgnoredException.addIgnoredException;
-import static org.apache.geode.test.dunit.Wait.waitForCriterion;
-import static org.apache.commons.io.FileUtils.*;
-
-@Category(DistributedTest.class)
-public class ClusterConfigurationDUnitTest extends CliCommandTestBase {
-
-  private static final int TIMEOUT = 10000;
-  private static final int INTERVAL = 500;
-
-  private static final String REPLICATE_REGION = "ReplicateRegion1";
-  private static final String PARTITION_REGION = "PartitionRegion1";
-  private static final String DISK_REGION1 = "DR1";
-  private static final String INDEX1 = "ID1";
-  private static final String INDEX2 = "ID2";
-  private static final String GROUP1 = "G1";
-  private static final String GROUP2 = "G2";
-  private static final String JAR1 = "D1.jar";
-  private static final String JAR2 = "D2.jar";
-  private static final String JAR3 = "D3.jar";
-  private static final String AsyncEventQueue1 = "Q1";
-
-  private static final String dataMember = "DataMember";
-  private static final String newMember = "NewMember";
-
-  private static Set<String> serverNames = new HashSet<>();
-  private static Set<String> jarFileNames = new HashSet<>();
-
-  private transient ClassBuilder classBuilder = new ClassBuilder();
-
-  @Override
-  public final void postSetUpCliCommandTestBase() throws Exception {
-    disconnectAllFromDS();
-  }
-
-  @Override
-  public final void preTearDownCliCommandTestBase() throws Exception {
-    shutdownAll();
-
-    serverNames.clear();
-    jarFileNames.clear();
-  }
-
-  @Category(FlakyTest.class) // GEODE-1335
-  @Test
-  public void testConfigDistribution() throws Exception {
-    addIgnoredException("could not get remote locator");
-    addIgnoredException("EntryDestroyedException");
-
-    String workingDir = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator;
-
-    Object[] result = setup();
-    final int locatorPort = (Integer) result[0];
-    final String jmxHost = (String) result[1];
-    final int jmxPort = (Integer) result[2];
-    final int httpPort = (Integer) result[3];
-    final String locatorString = "localHost[" + locatorPort + "]";
-
-    String gatewayReceiverStartPort = "10000";
-    String gatewayReceiverEndPort = "20000";
-    final String gsId = "GatewaySender1";
-    final String batchSize = "1000";
-    final String dispatcherThreads = "5";
-    final String enableConflation = "false";
-    final String manualStart = "false";
-    final String receiverManualStart = "true";
-    final String alertThreshold = "1000";
-    final String batchTimeInterval = "20";
-    final String maxQueueMemory = "100";
-    final String orderPolicy = OrderPolicy.KEY.toString();
-    final String parallel = "true";
-    final String rmDsId = "250";
-    final String socketBufferSize =
-        String.valueOf(GatewaySender.MINIMUM_SOCKET_READ_TIMEOUT + 1000);
-    final String socketReadTimeout =
-        String.valueOf(GatewaySender.MINIMUM_SOCKET_READ_TIMEOUT + 200);
-    final String DESTROY_REGION = "regionToBeDestroyed";
-
-    createRegion(REPLICATE_REGION, RegionShortcut.REPLICATE, null);
-    createRegion(PARTITION_REGION, RegionShortcut.PARTITION, null);
-    createRegion(DESTROY_REGION, RegionShortcut.REPLICATE, null);
-    createIndex(INDEX1, "AAPL", REPLICATE_REGION, null);
-    createIndex(INDEX2, "VMW", PARTITION_REGION, null);
-
-    createAndDeployJar(workingDir + JAR1, null);
-    createAndDeployJar(workingDir + JAR2, null);
-    createAndDeployJar(workingDir + JAR3, null);
-
-    createAsyncEventQueue(AsyncEventQueue1, "false", null, "1000", "1000", null);
-    destroyRegion(DESTROY_REGION);
-    destroyIndex(INDEX2, PARTITION_REGION, null);
-
-    undeployJar(JAR3, null);
-
-    alterRuntime("true", "", "", "");
-    createGatewayReceiver(receiverManualStart, "", gatewayReceiverStartPort, gatewayReceiverEndPort,
-        "20", "");
-    createGatewaySender(gsId, batchSize, alertThreshold, batchTimeInterval, dispatcherThreads,
-        enableConflation, manualStart, maxQueueMemory, orderPolicy, parallel, rmDsId,
-        socketBufferSize, socketReadTimeout);
-
-    // alterRegion(PARTITION_REGION, "false", AsyncEventQueue1, "", "", "", "", "", "", gsId);
-    // Start a new member which receives the shared configuration
-    // Verify the config creation on this member
-
-    final String newMemberWorkingDir =
-        this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + newMember;
-
-    VM newMember = getHost(0).getVM(2);
-    newMember.invoke(new SerializableCallable() {
-      @Override
-      public Object call() throws IOException {
-        Properties localProps = new Properties();
-
-        File workingDir = new File(newMemberWorkingDir);
-        workingDir.mkdirs();
-
-        localProps.setProperty(MCAST_PORT, "0");
-        localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
-        localProps.setProperty(NAME, ClusterConfigurationDUnitTest.newMember);
-        localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
-        localProps.setProperty(DEPLOY_WORKING_DIR, workingDir.getCanonicalPath());
-
-        getSystem(localProps);
-        Cache cache = getCache();
-
-        assertNotNull(cache);
-        assertTrue(cache.getCopyOnRead());
-
-        Region region1 = cache.getRegion(REPLICATE_REGION);
-        assertNotNull(region1);
-        Region region2 = cache.getRegion(PARTITION_REGION);
-        assertNotNull(region2);
-
-        Region region3 = cache.getRegion(DESTROY_REGION);
-        assertNull(region3);
-
-        // Index verification
-        Index index1 = cache.getQueryService().getIndex(region1, INDEX1);
-        assertNotNull(index1);
-        assertNull(cache.getQueryService().getIndex(region2, INDEX2));
-
-        final JarDeployer jarDeployer = new JarDeployer(
-            ((GemFireCacheImpl) cache).getDistributedSystem().getConfig().getDeployWorkingDir());
-
-        final List<JarClassLoader> jarClassLoaders = jarDeployer.findJarClassLoaders();
-
-        Set<String> jarNames = new HashSet<String>();
-
-        for (JarClassLoader jarClassLoader : jarClassLoaders) {
-          jarNames.add(jarClassLoader.getJarName());
-        }
-
-        assertTrue(jarNames.contains(JAR1));
-        assertTrue(jarNames.contains(JAR2));
-        assertFalse(jarNames.contains(JAR3));
-
-        // ASYNC-EVENT-QUEUE verification
-        AsyncEventQueue aeq = cache.getAsyncEventQueue(AsyncEventQueue1);
-        assertNotNull(aeq);
-        assertFalse(aeq.isPersistent());
-        assertTrue(aeq.getBatchSize() == 1000);
-        assertTrue(aeq.getMaximumQueueMemory() == 1000);
-
-        // GatewayReceiver verification
-        Set<GatewayReceiver> gatewayReceivers = cache.getGatewayReceivers();
-        assertFalse(gatewayReceivers.isEmpty());
-        assertTrue(gatewayReceivers.size() == 1);
-
-        // Gateway Sender verification
-        GatewaySender gs = cache.getGatewaySender(gsId);
-        assertNotNull(gs);
-        assertTrue(alertThreshold.equals(Integer.toString(gs.getAlertThreshold())));
-        assertTrue(batchSize.equals(Integer.toString(gs.getBatchSize())));
-        assertTrue(dispatcherThreads.equals(Integer.toString(gs.getDispatcherThreads())));
-        assertTrue(enableConflation.equals(Boolean.toString(gs.isBatchConflationEnabled())));
-        assertTrue(manualStart.equals(Boolean.toString(gs.isManualStart())));
-        assertTrue(alertThreshold.equals(Integer.toString(gs.getAlertThreshold())));
-        assertTrue(batchTimeInterval.equals(Integer.toString(gs.getBatchTimeInterval())));
-        assertTrue(maxQueueMemory.equals(Integer.toString(gs.getMaximumQueueMemory())));
-        assertTrue(orderPolicy.equals(gs.getOrderPolicy().toString()));
-        assertTrue(parallel.equals(Boolean.toString(gs.isParallel())));
-        assertTrue(rmDsId.equals(Integer.toString(gs.getRemoteDSId())));
-        assertTrue(socketBufferSize.equals(Integer.toString(gs.getSocketBufferSize())));
-        assertTrue(socketReadTimeout.equals(Integer.toString(gs.getSocketReadTimeout())));
-
-        return getAllNormalMembers(cache);
-      }
-    });
-  }
-
-  /**
-   * Tests for {@link Extension}, {@link Extensible}, {@link XmlParser}, {@link XmlGenerator},
-   * {@link XmlEntity} as it applies to Extensions. Asserts that Mock Extension is created and
-   * altered on region and cache.
-   * 
-   * @since GemFire 8.1
-   */
-  @Category(FlakyTest.class) // GEODE-1334
-  @Test
-  public void testCreateExtensions() throws Exception {
-    Object[] result = setup();
-    final int locatorPort = (Integer) result[0];
-
-    createRegion(REPLICATE_REGION, RegionShortcut.REPLICATE, null);
-    createMockRegionExtension(REPLICATE_REGION, "value1");
-    alterMockRegionExtension(REPLICATE_REGION, "value2");
-    createMockCacheExtension("value1");
-    alterMockCacheExtension("value2");
-
-    // Start a new member which receives the shared configuration
-    // Verify the config creation on this member
-
-    final String newMemberWorkDir =
-        this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + newMember;
-
-    VM newMember = getHost(0).getVM(2);
-    newMember.invoke(new SerializableCallable() {
-      private static final long serialVersionUID = 1L;
-
-      @Override
-      public Object call() throws IOException {
-        Properties localProps = new Properties();
-
-        File workingDir = new File(newMemberWorkDir);
-        workingDir.mkdirs();
-
-        localProps.setProperty(MCAST_PORT, "0");
-        localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
-        localProps.setProperty(NAME, ClusterConfigurationDUnitTest.newMember);
-        localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
-        localProps.setProperty(DEPLOY_WORKING_DIR, workingDir.getCanonicalPath());
-
-        getSystem(localProps);
-        Cache cache = getCache();
-
-        assertNotNull(cache);
-
-        Region<?, ?> region1 = cache.getRegion(REPLICATE_REGION);
-        assertNotNull(region1);
-
-        // MockRegionExtension verification
-        @SuppressWarnings("unchecked")
-        // should only be one region extension
-        final MockRegionExtension mockRegionExtension =
-            (MockRegionExtension) ((Extensible<Region<?, ?>>) region1).getExtensionPoint()
-                .getExtensions().iterator().next();
-        assertNotNull(mockRegionExtension);
-        assertEquals(1, mockRegionExtension.beforeCreateCounter.get());
-        assertEquals(1, mockRegionExtension.onCreateCounter.get());
-        assertEquals("value2", mockRegionExtension.getValue());
-
-        // MockCacheExtension verification
-        @SuppressWarnings("unchecked")
-        // should only be one cache extension
-        final MockCacheExtension mockCacheExtension =
-            (MockCacheExtension) ((Extensible<Cache>) cache).getExtensionPoint().getExtensions()
-                .iterator().next();
-        assertNotNull(mockCacheExtension);
-        assertEquals(1, mockCacheExtension.beforeCreateCounter.get());
-        assertEquals(1, mockCacheExtension.onCreateCounter.get());
-        assertEquals("value2", mockCacheExtension.getValue());
-
-        return getAllNormalMembers(cache);
-      }
-    });
-  }
-
-  /**
-   * Tests for {@link Extension}, {@link Extensible}, {@link XmlParser}, {@link XmlGenerator},
-   * {@link XmlEntity} as it applies to Extensions. Asserts that Mock Extension is created and
-   * destroyed on region and cache.
-   * 
-   * @since GemFire 8.1
-   */
-  @Category(FlakyTest.class) // GEODE-1333
-  @Test
-  public void testDestroyExtensions() throws Exception {
-    Object[] result = setup();
-    final int locatorPort = (Integer) result[0];
-
-    createRegion(REPLICATE_REGION, RegionShortcut.REPLICATE, null);
-    createMockRegionExtension(REPLICATE_REGION, "value1");
-    destroyMockRegionExtension(REPLICATE_REGION);
-    createMockCacheExtension("value1");
-    destroyMockCacheExtension();
-
-    // Start a new member which receives the shared configuration
-    // Verify the config creation on this member
-
-    final String newMemberWorkingDir =
-        this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + newMember;
-
-    VM newMember = getHost(0).getVM(2);
-    newMember.invoke(new SerializableCallable() {
-
-      @Override
-      public Object call() throws IOException {
-        Properties localProps = new Properties();
-
-        File workingDir = new File(newMemberWorkingDir);
-        workingDir.mkdirs();
-
-        localProps.setProperty(MCAST_PORT, "0");
-        localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
-        localProps.setProperty(NAME, ClusterConfigurationDUnitTest.newMember);
-        localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
-        localProps.setProperty(DEPLOY_WORKING_DIR, workingDir.getCanonicalPath());
-
-        getSystem(localProps);
-        Cache cache = getCache();
-
-        assertNotNull(cache);
-
-        Region<?, ?> region1 = cache.getRegion(REPLICATE_REGION);
-        assertNotNull(region1);
-
-        // MockRegionExtension verification
-        @SuppressWarnings("unchecked")
-        final Extensible<Region<?, ?>> extensibleRegion = (Extensible<Region<?, ?>>) region1;
-        // Should not be any region extensions
-        assertTrue(!extensibleRegion.getExtensionPoint().getExtensions().iterator().hasNext());
-
-        // MockCacheExtension verification
-        @SuppressWarnings("unchecked")
-        final Extensible<Cache> extensibleCache = (Extensible<Cache>) cache;
-        // Should not be any cache extensions
-        assertTrue(!extensibleCache.getExtensionPoint().getExtensions().iterator().hasNext());
-
-        return getAllNormalMembers(cache);
-      }
-    });
-  }
-
-  @Ignore("disabled for unknown reason") // this passes when @Ignore is removed
-  @Test
-  public void testCreateDiskStore() throws Exception {
-    Object[] result = setup();
-    final int locatorPort = (Integer) result[0];
-    final String jmxHost = (String) result[1];
-    final int jmxPort = (Integer) result[2];
-    final int httpPort = (Integer) result[3];
-    final String locatorString = "localHost[" + locatorPort + "]";
-
-    final String diskStoreName = "clusterConfigTestDiskStore";
-    final String diskDirs = "dir1";
-
-    // final String
-    // createPersistentRegion(peersRegion, RegionShortcut.PARTITION_PERSISTENT, "", diskStoreName);
-
-    final String autoCompact = "true";
-    final String allowForceCompaction = "true";
-    final String compactionThreshold = "50";
-    final String duCritical = "90";
-    final String duWarning = "85";
-    final String maxOplogSize = "1000";
-    final String queueSize = "300";
-    final String timeInterval = "10";
-    final String writeBufferSize = "100";
-
-    createDiskStore(diskStoreName, diskDirs, autoCompact, allowForceCompaction, compactionThreshold,
-        duCritical, duWarning, maxOplogSize, queueSize, timeInterval, writeBufferSize);
-
-    // createAsyncEventQueue(id, persistent, diskStoreName, batchSize, maxQueueMemory, group)
-
-    // Stop the existing data member
-    VM dataMember = getHost(0).getVM(1);
-    dataMember.invoke(new SerializableCallable() {
-      @Override
-      public Object call() throws IOException {
-
-        CacheFactory cf = new CacheFactory();
-        GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
-        File[] diskDirs = null;
-        Collection<DiskStoreImpl> diskStoreList = cache.listDiskStores();
-
-        assertFalse(diskStoreList.isEmpty());
-        assertTrue(diskStoreList.size() == 1);
-
-        for (DiskStoreImpl diskStore : diskStoreList) {
-          diskDirs = diskStore.getDiskDirs();
-          break;
-        }
-
-        assertNotNull(diskDirs);
-        assertTrue(diskDirs.length > 0);
-
-        // close the cache
-        cache.close();
-
-        // Delete the disk-store files
-        for (File diskDir : diskDirs) {
-          deleteDirectory(diskDir);
-        }
-        return getAllNormalMembers(cache);
-      }
-    });
-
-    final String newMemberWorkingDir =
-        this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + newMember;
-
-    // Now start the new data member and it should create all the disk-store artifacts
-    VM newMember = getHost(0).getVM(2);
-    newMember.invoke(new SerializableCallable() {
-      @Override
-      public Object call() throws IOException {
-        Properties localProps = new Properties();
-
-        File workingDir = new File(newMemberWorkingDir);
-        workingDir.mkdirs();
-
-        localProps.setProperty(MCAST_PORT, "0");
-        localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
-        localProps.setProperty(NAME, ClusterConfigurationDUnitTest.newMember);
-        localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
-        localProps.setProperty(DEPLOY_WORKING_DIR, workingDir.getCanonicalPath());
-
-        getSystem(localProps);
-        GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
-        assertNotNull(cache);
-
-
-        Collection<DiskStoreImpl> diskStoreList = cache.listDiskStores();
-
-        assertFalse(diskStoreList.isEmpty());
-        assertTrue(diskStoreList.size() == 1);
-
-        for (DiskStoreImpl diskStore : diskStoreList) {
-          assertTrue(diskStore.getName().equals(diskStoreName));
-          assertTrue(Boolean.toString(diskStore.getAutoCompact()).equals(autoCompact));
-          assertTrue(
-              Boolean.toString(diskStore.getAllowForceCompaction()).equals(allowForceCompaction));
-          assertTrue(
-              Integer.toString(diskStore.getCompactionThreshold()).equals(compactionThreshold));
-          assertTrue(Long.toString(diskStore.getMaxOplogSize()).equals(maxOplogSize));
-          assertTrue(Integer.toString(diskStore.getQueueSize()).equals(queueSize));
-          assertTrue(Integer.toString(diskStore.getWriteBufferSize()).equals(writeBufferSize));
-          assertTrue(Long.toString(diskStore.getTimeInterval()).equals(timeInterval));
-          break;
-        }
-        cache.close();
-        return null;
-      }
-    });
-  }
-
-  @Ignore("disabled for unknown reason") // this fails in configurePDX when @Ignore is removed
-  @Test
-  public void testConfigurePDX() throws Exception {
-    Object[] result = setup();
-    final int locatorPort = (Integer) result[0];
-    final String jmxHost = (String) result[1];
-    final int jmxPort = (Integer) result[2];
-    final int httpPort = (Integer) result[3];
-    final String locatorString = "localHost[" + locatorPort + "]";
-
-    configurePDX("com.foo.*", "true", "true", null, "true");
-
-    VM dataMember = getHost(0).getVM(1);
-    dataMember.invoke(new SerializableCallable() {
-      @Override
-      public Object call() throws IOException {
-        GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
-        assertTrue(cache.getPdxReadSerialized());
-        assertTrue(cache.getPdxIgnoreUnreadFields());
-        assertTrue(cache.getPdxPersistent());
-        return null;
-      }
-    });
-  }
-
-  @Test
-  public void testClusterConfigDir() throws Exception {
-    final int[] ports = getRandomAvailableTCPPorts(3);
-    final int locator1Port = ports[0];
-    final String locator1Name = "locator1-" + locator1Port;
-
-    final String locatorLogPath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator
-        + "locator-" + locator1Port + ".log";
-    final String clusterConfigPath =
-        this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "userSpecifiedDir";
-
-    VM locatorAndMgr = getHost(0).getVM(3);
-    Object[] result = (Object[]) locatorAndMgr.invoke(new SerializableCallable() {
-      @Override
-      public Object call() throws IOException {
-        int httpPort;
-        int jmxPort;
-        String jmxHost;
-
-        try {
-          jmxHost = InetAddress.getLocalHost().getHostName();
-        } catch (UnknownHostException ignore) {
-          jmxHost = "localhost";
-        }
-
-        final int[] ports = getRandomAvailableTCPPorts(2);
-
-        jmxPort = ports[0];
-        httpPort = ports[1];
-
-        final File locatorLogFile = new File(locatorLogPath);
-
-        final Properties locatorProps = new Properties();
-        locatorProps.setProperty(NAME, locator1Name);
-        locatorProps.setProperty(MCAST_PORT, "0");
-        locatorProps.setProperty(LOG_LEVEL, "config");
-        locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
-        locatorProps.setProperty(JMX_MANAGER, "true");
-        locatorProps.setProperty(JMX_MANAGER_START, "true");
-        locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
-        locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
-
-        File clusterConfigDir = new File(clusterConfigPath);
-        assertTrue(clusterConfigDir.mkdir());
-
-        locatorProps.setProperty(CLUSTER_CONFIGURATION_DIR, clusterConfigDir.getCanonicalPath());
-        locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
-
-        final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator1Port,
-            locatorLogFile, null, locatorProps);
-
-        WaitCriterion wc = new WaitCriterion() {
-          @Override
-          public boolean done() {
-            return locator.isSharedConfigurationRunning();
-          }
-
-          @Override
-          public String description() {
-            return "Waiting for shared configuration to be started";
-          }
-        };
-        waitForCriterion(wc, TIMEOUT, INTERVAL, true);
-
-        assertTrue(clusterConfigDir.list().length > 0);
-
-        final Object[] result = new Object[4];
-        result[0] = locator1Port;
-        result[1] = jmxHost;
-        result[2] = jmxPort;
-        result[3] = httpPort;
-        return result;
-      }
-    });
-  }
-
-  @Test
-  public void testConfigurePDXForWarning() throws Exception {
-    setup();
-    CommandResult commandResult = configurePDX("com.foo.*", "true", "true", null, "true");
-    String result = (String) commandResult.getResultData().getGfJsonObject()
-        .getJSONObject("content").getJSONArray("message").get(0);
-    assertEquals(CliStrings.CONFIGURE_PDX__NORMAL__MEMBERS__WARNING, result);
-  }
-
-  private Object[] setup() throws IOException {
-    final int[] ports = getRandomAvailableTCPPorts(3);
-    final int locator1Port = ports[0];
-    final String locator1Name = "locator1-" + locator1Port;
-    final String locatorLogPath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator
-        + "locator-" + locator1Port + ".log";
-
-    VM locatorAndMgr = getHost(0).getVM(3);
-    Object[] result = (Object[]) locatorAndMgr.invoke(new SerializableCallable() {
-      @Override
-      public Object call() throws IOException {
-        int httpPort;
-        int jmxPort;
-        String jmxHost;
-
-        try {
-          jmxHost = InetAddress.getLocalHost().getHostName();
-        } catch (UnknownHostException ignore) {
-          jmxHost = "localhost";
-        }
-
-        final int[] ports = getRandomAvailableTCPPorts(2);
-
-        jmxPort = ports[0];
-        httpPort = ports[1];
-
-        final File locatorLogFile = new File(locatorLogPath);
-
-        final Properties locatorProps = new Properties();
-        locatorProps.setProperty(NAME, locator1Name);
-        locatorProps.setProperty(MCAST_PORT, "0");
-        locatorProps.setProperty(LOG_LEVEL, "config");
-        locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
-        locatorProps.setProperty(JMX_MANAGER, "true");
-        locatorProps.setProperty(JMX_MANAGER_START, "true");
-        locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
-        locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
-        locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
-
-        final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator1Port,
-            locatorLogFile, null, locatorProps);
-
-        WaitCriterion wc = new WaitCriterion() {
-          @Override
-          public boolean done() {
-            return locator.isSharedConfigurationRunning();
-          }
-
-          @Override
-          public String description() {
-            return "Waiting for shared configuration to be started";
-          }
-        };
-        waitForCriterion(wc, TIMEOUT, INTERVAL, true);
-
-        final Object[] result = new Object[4];
-        result[0] = locator1Port;
-        result[1] = jmxHost;
-        result[2] = jmxPort;
-        result[3] = httpPort;
-        return result;
-      }
-    });
-
-    HeadlessGfsh gfsh = getDefaultShell();
-    String jmxHost = (String) result[1];
-    int jmxPort = (Integer) result[2];
-    int httpPort = (Integer) result[3];
-
-    connect(jmxHost, jmxPort, httpPort, gfsh);
-
-    final String dataMemberWorkingDir =
-        this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + dataMember;
-
-    // Create a cache in VM 1
-    VM dataMember = getHost(0).getVM(1);
-    dataMember.invoke(new SerializableCallable() {
-      @Override
-      public Object call() throws IOException {
-        Properties localProps = new Properties();
-        File workingDir = new File(dataMemberWorkingDir);
-        workingDir.mkdirs();
-
-        localProps.setProperty(MCAST_PORT, "0");
-        localProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
-        localProps.setProperty(NAME, ClusterConfigurationDUnitTest.dataMember);
-        localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
-        localProps.setProperty(DEPLOY_WORKING_DIR, workingDir.getCanonicalPath());
-
-        getSystem(localProps);
-        Cache cache = getCache();
-        assertNotNull(cache);
-        return getAllNormalMembers(cache);
-      }
-    });
-
-    return result;
-  }
-
-  private void createRegion(String regionName, RegionShortcut regionShortCut, String group) {
-    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_REGION);
-    csb.addOption(CliStrings.CREATE_REGION__REGION, regionName);
-    csb.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, regionShortCut.name());
-    csb.addOptionWithValueCheck(CliStrings.CREATE_REGION__GROUP, group);
-    executeAndVerifyCommand(csb.toString());
-  }
-
-  private void createMockRegionExtension(final String regionName, final String value) {
-    CommandStringBuilder csb =
-        new CommandStringBuilder(MockExtensionCommands.CREATE_MOCK_REGION_EXTENSION);
-    csb.addOption(MockExtensionCommands.OPTION_REGION_NAME, regionName);
-    csb.addOption(MockExtensionCommands.OPTION_VALUE, value);
-    executeAndVerifyCommand(csb.toString());
-  }
-
-  private void alterMockRegionExtension(final String regionName, final String value) {
-    CommandStringBuilder csb =
-        new CommandStringBuilder(MockExtensionCommands.ALTER_MOCK_REGION_EXTENSION);
-    csb.addOption(MockExtensionCommands.OPTION_REGION_NAME, regionName);
-    csb.addOption(MockExtensionCommands.OPTION_VALUE, value);
-    executeAndVerifyCommand(csb.toString());
-  }
-
-  private void destroyMockRegionExtension(final String regionName) {
-    CommandStringBuilder csb =
-        new CommandStringBuilder(MockExtensionCommands.DESTROY_MOCK_REGION_EXTENSION);
-    csb.addOption(MockExtensionCommands.OPTION_REGION_NAME, regionName);
-    executeAndVerifyCommand(csb.toString());
-  }
-
-  private void createMockCacheExtension(final String value) {
-    CommandStringBuilder csb =
-        new CommandStringBuilder(MockExtensionCommands.CREATE_MOCK_CACHE_EXTENSION);
-    csb.addOption(MockExtensionCommands.OPTION_VALUE, value);
-    executeAndVerifyCommand(csb.toString());
-  }
-
-  private void alterMockCacheExtension(final String value) {
-    CommandStringBuilder csb =
-        new CommandStringBuilder(MockExtensionCommands.ALTER_MOCK_CACHE_EXTENSION);
-    csb.addOption(MockExtensionCommands.OPTION_VALUE, value);
-    executeAndVerifyCommand(csb.toString());
-  }
-
-  private void destroyMockCacheExtension() {
-    CommandStringBuilder csb =
-        new CommandStringBuilder(MockExtensionCommands.DESTROY_MOCK_CACHE_EXTENSION);
-    executeAndVerifyCommand(csb.toString());
-  }
-
-  private void createPersistentRegion(String regionName, RegionShortcut regionShortCut,
-      String group, String diskStoreName) {
-    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_REGION);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_REGION__REGION, regionName);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_REGION__REGIONSHORTCUT, regionShortCut.name());
-    csb.addOptionWithValueCheck(CliStrings.CREATE_REGION__DISKSTORE, diskStoreName);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_REGION__GROUP, group);
-    executeAndVerifyCommand(csb.getCommandString());
-  }
-
-  private void destroyRegion(String regionName) {
-    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DESTROY_REGION);
-    csb.addOption(CliStrings.DESTROY_REGION__REGION, regionName);
-    executeAndVerifyCommand(csb.getCommandString());
-  }
-
-  private void alterRegion(String regionName, String cloningEnabled, String aeqId,
-      String cacheListener, String cacheWriter, String cacheLoader, String entryExpIdleTime,
-      String entryExpIdleTimeAction, String evictionMax, String gsId) {
-
-    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.ALTER_REGION);
-    csb.addOptionWithValueCheck(CliStrings.ALTER_REGION__CLONINGENABLED, "false");
-    csb.addOptionWithValueCheck(CliStrings.ALTER_REGION__ASYNCEVENTQUEUEID, aeqId);
-    csb.addOptionWithValueCheck(CliStrings.ALTER_REGION__CACHELISTENER, cacheListener);
-    csb.addOptionWithValueCheck(CliStrings.ALTER_REGION__CACHEWRITER, cacheWriter);
-    csb.addOptionWithValueCheck(CliStrings.ALTER_REGION__CACHELOADER, cacheLoader);
-    csb.addOptionWithValueCheck(CliStrings.ALTER_REGION__CLONINGENABLED, cloningEnabled);
-    csb.addOptionWithValueCheck(CliStrings.ALTER_REGION__ENTRYEXPIRATIONIDLETIME, entryExpIdleTime);
-    csb.addOptionWithValueCheck(CliStrings.ALTER_REGION__ENTRYEXPIRATIONIDLETIMEACTION,
-        entryExpIdleTimeAction);
-    csb.addOptionWithValueCheck(CliStrings.ALTER_REGION__EVICTIONMAX, evictionMax);
-    csb.addOptionWithValueCheck(CliStrings.ALTER_REGION__GATEWAYSENDERID, gsId);
-
-    executeAndVerifyCommand(csb.getCommandString());
-  }
-
-  private CommandResult executeAndVerifyCommand(String commandString) {
-    CommandResult cmdResult = executeCommand(commandString);
-    org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("Command : " + commandString);
-    org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()
-        .info("Command Result : " + commandResultToString(cmdResult));
-    assertEquals(Status.OK, cmdResult.getStatus());
-    assertFalse(cmdResult.failedToPersist());
-    return cmdResult;
-  }
-
-  private void createIndex(String indexName, String expression, String regionName, String group) {
-    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_INDEX);
-    csb.addOption(CliStrings.CREATE_INDEX__NAME, indexName);
-    csb.addOption(CliStrings.CREATE_INDEX__EXPRESSION, expression);
-    csb.addOption(CliStrings.CREATE_INDEX__REGION, regionName);
-    executeAndVerifyCommand(csb.getCommandString());
-  }
-
-  private void destroyIndex(String indexName, String regionName, String group) {
-    if (isBlank(indexName) && isBlank(regionName) && isBlank(group)) {
-      return;
-    }
-    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DESTROY_INDEX);
-    csb.addOptionWithValueCheck(CliStrings.DESTROY_INDEX__NAME, indexName);
-    csb.addOptionWithValueCheck(CliStrings.DESTROY_INDEX__REGION, regionName);
-    csb.addOptionWithValueCheck(CliStrings.DESTROY_INDEX__GROUP, group);
-    executeAndVerifyCommand(csb.getCommandString());
-  }
-
-  private void createDiskStore(String diskStoreName, String diskDirs, String autoCompact,
-      String allowForceCompaction, String compactionThreshold, String duCritical, String duWarning,
-      String maxOplogSize, String queueSize, String timeInterval, String writeBufferSize) {
-
-    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_DISK_STORE);
-    csb.addOption(CliStrings.CREATE_DISK_STORE__NAME, diskStoreName);
-    csb.addOption(CliStrings.CREATE_DISK_STORE__DIRECTORY_AND_SIZE, diskDirs);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__AUTO_COMPACT, autoCompact);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__ALLOW_FORCE_COMPACTION,
-        allowForceCompaction);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__COMPACTION_THRESHOLD,
-        compactionThreshold);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__DISK_USAGE_CRITICAL_PCT, duCritical);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__DISK_USAGE_WARNING_PCT, duWarning);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__MAX_OPLOG_SIZE, maxOplogSize);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__QUEUE_SIZE, queueSize);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__TIME_INTERVAL, timeInterval);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__WRITE_BUFFER_SIZE, writeBufferSize);
-    executeAndVerifyCommand(csb.getCommandString());
-  }
-
-  private void destroyDiskStore(String diskStoreName, String group) {
-    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DESTROY_DISK_STORE);
-    csb.addOption(CliStrings.DESTROY_DISK_STORE__NAME, diskStoreName);
-    csb.addOptionWithValueCheck(CliStrings.DESTROY_DISK_STORE__GROUP, group);
-    executeAndVerifyCommand(csb.toString());
-  }
-
-  private void createGatewayReceiver(String manualStart, String bindAddress, String startPort,
-      String endPort, String maxTimeBetweenPings, String group) {
-    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_GATEWAYRECEIVER);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYRECEIVER__MANUALSTART, manualStart);
-    csb.addOption(CliStrings.CREATE_GATEWAYRECEIVER__STARTPORT, startPort);
-    csb.addOption(CliStrings.CREATE_GATEWAYRECEIVER__ENDPORT, endPort);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYRECEIVER__BINDADDRESS, bindAddress);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYRECEIVER__GROUP, group);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYRECEIVER__MAXTIMEBETWEENPINGS,
-        maxTimeBetweenPings);
-    executeAndVerifyCommand(csb.getCommandString());
-  }
-
-  private void createGatewaySender(String id, String batchSize, String alertThreshold,
-      String batchTimeInterval, String dispatcherThreads, String enableConflation,
-      String manualStart, String maxQueueMemory, String orderPolicy, String parallel, String rmDsId,
-      String socketBufferSize, String socketReadTimeout) {
-
-    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_GATEWAYSENDER);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__ID, id);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__BATCHSIZE, batchSize);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__ALERTTHRESHOLD, alertThreshold);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__BATCHTIMEINTERVAL,
-        batchTimeInterval);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__DISPATCHERTHREADS,
-        dispatcherThreads);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__ENABLEBATCHCONFLATION,
-        enableConflation);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__MANUALSTART, manualStart);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__MAXQUEUEMEMORY, maxQueueMemory);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__ORDERPOLICY, orderPolicy);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__PARALLEL, parallel);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__REMOTEDISTRIBUTEDSYSTEMID, rmDsId);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__SOCKETBUFFERSIZE,
-        socketBufferSize);
-    csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__SOCKETREADTIMEOUT,
-        socketReadTimeout);
-
-    executeAndVerifyCommand(csb.getCommandString());
-  }
-
-  private void createAsyncEventQueue(String id, String persistent, String diskStoreName,
-      String batchSize, String maxQueueMemory, String group) throws IOException {
-    String queueCommandsJarName = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator
-        + "testEndToEndSC-QueueCommands.jar";
-    final File jarFile = new File(queueCommandsJarName);
-
-    try {
-      ClassBuilder classBuilder = new ClassBuilder();
-      byte[] jarBytes =
-          classBuilder.createJarFromClassContent("com/qcdunit/QueueCommandsDUnitTestListener",
-              "package com.qcdunit;" + "import java.util.List; import java.util.Properties;"
-                  + "import org.apache.geode.internal.cache.xmlcache.Declarable2; import org.apache.geode.cache.asyncqueue.AsyncEvent;"
-                  + "import org.apache.geode.cache.asyncqueue.AsyncEventListener;"
-                  + "public class QueueCommandsDUnitTestListener implements Declarable2, AsyncEventListener {"
-                  + "Properties props;"
-                  + "public boolean processEvents(List<AsyncEvent> events) { return true; }"
-                  + "public void close() {}"
-                  + "public void init(final Properties props) {this.props = props;}"
-                  + "public Properties getConfig() {return this.props;}}");
-
-      writeByteArrayToFile(jarFile, jarBytes);
-      CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DEPLOY);
-      csb.addOption(CliStrings.DEPLOY__JAR, queueCommandsJarName);
-      executeAndVerifyCommand(csb.getCommandString());
-
-      csb = new CommandStringBuilder(CliStrings.CREATE_ASYNC_EVENT_QUEUE);
-      csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__ID, id);
-      csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__LISTENER,
-          "com.qcdunit.QueueCommandsDUnitTestListener");
-      csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISK_STORE, diskStoreName);
-      csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__BATCH_SIZE, batchSize);
-      csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__GROUP, group);
-      csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__PERSISTENT, persistent);
-      csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__MAXIMUM_QUEUE_MEMORY,
-          maxQueueMemory);
-      executeAndVerifyCommand(csb.getCommandString());
-
-    } finally {
-      deleteQuietly(jarFile);
-    }
-  }
-
-  private CommandResult configurePDX(String autoSerializerClasses, String ignoreUnreadFields,
-      String persistent, String portableAutoSerializerClasses, String readSerialized) {
-    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CONFIGURE_PDX);
-    csb.addOptionWithValueCheck(CliStrings.CONFIGURE_PDX__AUTO__SERIALIZER__CLASSES,
-        autoSerializerClasses);
-    csb.addOptionWithValueCheck(CliStrings.CONFIGURE_PDX__IGNORE__UNREAD_FIELDS,
-        ignoreUnreadFields);
-    csb.addOptionWithValueCheck(CliStrings.CONFIGURE_PDX__PERSISTENT, persistent);
-    csb.addOptionWithValueCheck(CliStrings.CONFIGURE_PDX__PORTABLE__AUTO__SERIALIZER__CLASSES,
-        portableAutoSerializerClasses);
-    csb.addOptionWithValueCheck(CliStrings.CONFIGURE_PDX__READ__SERIALIZED, readSerialized);
-
-    return executeAndVerifyCommand(csb.getCommandString());
-  }
-
-  private void createAndDeployJar(String jarName, String group) throws IOException {
-    File newDeployableJarFile = new File(jarName);
-    this.classBuilder.writeJarFromName("ShareConfigClass", newDeployableJarFile);
-    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DEPLOY);
-    csb.addOption(CliStrings.DEPLOY__JAR, jarName);
-    if (!isBlank(group)) {
-      csb.addOption(CliStrings.DEPLOY__GROUP, group);
-    }
-    executeAndVerifyCommand(csb.getCommandString());
-    jarFileNames.add(jarName);
-  }
-
-  private void undeployJar(String jarName, String group) {
-    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.UNDEPLOY);
-    if (!isBlank(jarName)) {
-      csb.addOption(CliStrings.UNDEPLOY__JAR, jarName);
-    }
-    if (!isBlank(group)) {
-      csb.addOption(CliStrings.UNDEPLOY__GROUP, group);
-    }
-    executeAndVerifyCommand(csb.getCommandString());
-  }
-
-  private void alterRuntime(String copyOnRead, String lockLease, String lockTimeout,
-      String messageSyncInterval) {
-    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.ALTER_RUNTIME_CONFIG);
-    csb.addOptionWithValueCheck(CliStrings.ALTER_RUNTIME_CONFIG__COPY__ON__READ, copyOnRead);
-    csb.addOptionWithValueCheck(CliStrings.ALTER_RUNTIME_CONFIG__LOCK__LEASE, lockLease);
-    csb.addOptionWithValueCheck(CliStrings.ALTER_RUNTIME_CONFIG__LOCK__TIMEOUT, lockTimeout);
-    csb.addOptionWithValueCheck(CliStrings.ALTER_RUNTIME_CONFIG__MESSAGE__SYNC__INTERVAL,
-        messageSyncInterval);
-    executeAndVerifyCommand(csb.toString());
-  }
-
-  private void deleteSavedJarFiles() throws IOException {
-    deleteMatching(new File("."), "^" + JarDeployer.JAR_PREFIX + "Deploy1.*#\\d++$");
-    delete(new File("Deploy1.jar"));
-  }
-
-  private void shutdownAll() throws IOException {
-    VM locatorAndMgr = getHost(0).getVM(3);
-    locatorAndMgr.invoke(new SerializableCallable() {
-      @Override
-      public Object call() throws Exception {
-        GemFireCacheImpl cache = (GemFireCacheImpl) CacheFactory.getAnyInstance();
-        ShutdownAllRequest.send(cache.getDistributedSystem().getDistributionManager(), -1);
-        return null;
-      }
-    });
-
-    locatorAndMgr.invoke(SharedConfigurationTestUtils.cleanupLocator);
-    // Clean up the directories
-    if (serverNames != null && !serverNames.isEmpty()) {
-      for (String serverName : serverNames) {
-        final File serverDir = new File(serverName);
-        cleanDirectory(serverDir);
-        deleteDirectory(serverDir);
-      }
-    }
-  }
-
-  private static class CommandBuilder {
-
-    private CommandStringBuilder csb;
-
-    public CommandBuilder(String commandName, Map<String, String> options) {
-      csb = new CommandStringBuilder(commandName);
-
-      Set<Entry<String, String>> entries = options.entrySet();
-
-      Iterator<Entry<String, String>> iter = entries.iterator();
-
-      while (iter.hasNext()) {
-        Entry<String, String> entry = iter.next();
-        String option = entry.getKey();
-
-        if (isBlank(option)) {
-          csb.addOption(option, entry.getValue());
-        }
-      }
-    }
-
-    public String getCommandString() {
-      return csb.toString();
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-wan/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationExtensionsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-wan/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationExtensionsDUnitTest.java b/geode-wan/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationExtensionsDUnitTest.java
new file mode 100644
index 0000000..f9786c7
--- /dev/null
+++ b/geode-wan/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationExtensionsDUnitTest.java
@@ -0,0 +1,429 @@
+/*
+ * 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;
+
+import static org.apache.commons.io.FileUtils.cleanDirectory;
+import static org.apache.commons.io.FileUtils.deleteDirectory;
+import static org.apache.geode.distributed.ConfigurationProperties.DEPLOY_WORKING_DIR;
+import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_BIND_ADDRESS;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_START;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.NAME;
+import static org.apache.geode.distributed.ConfigurationProperties.USE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts;
+import static org.apache.geode.management.internal.cli.CliUtil.getAllNormalMembers;
+import static org.apache.geode.test.dunit.Assert.assertEquals;
+import static org.apache.geode.test.dunit.Assert.assertFalse;
+import static org.apache.geode.test.dunit.Assert.assertNotNull;
+import static org.apache.geode.test.dunit.Assert.assertTrue;
+import static org.apache.geode.test.dunit.Host.getHost;
+import static org.apache.geode.test.dunit.Wait.waitForCriterion;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.distributed.Locator;
+import org.apache.geode.distributed.internal.InternalLocator;
+import org.apache.geode.internal.admin.remote.ShutdownAllRequest;
+import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.internal.cache.extension.Extensible;
+import org.apache.geode.internal.cache.extension.Extension;
+import org.apache.geode.internal.cache.extension.mock.MockCacheExtension;
+import org.apache.geode.internal.cache.extension.mock.MockExtensionCommands;
+import org.apache.geode.internal.cache.extension.mock.MockRegionExtension;
+import org.apache.geode.internal.cache.xmlcache.XmlGenerator;
+import org.apache.geode.internal.cache.xmlcache.XmlParser;
+import org.apache.geode.management.cli.Result.Status;
+import org.apache.geode.management.internal.cli.HeadlessGfsh;
+import org.apache.geode.management.internal.cli.commands.CliCommandTestBase;
+import org.apache.geode.management.internal.cli.i18n.CliStrings;
+import org.apache.geode.management.internal.cli.result.CommandResult;
+import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
+import org.apache.geode.management.internal.configuration.domain.XmlEntity;
+import org.apache.geode.test.dunit.SerializableCallable;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.WaitCriterion;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.categories.FlakyTest;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+
+@Category(DistributedTest.class)
+public class ClusterConfigurationExtensionsDUnitTest extends CliCommandTestBase {
+
+  private static final int TIMEOUT = 10000;
+  private static final int INTERVAL = 500;
+
+  private static final String REPLICATE_REGION = "ReplicateRegion1";
+
+  private static final String dataMember = "DataMember";
+  private static final String newMember = "NewMember";
+
+  private static Set<String> serverNames = new HashSet<>();
+  private static Set<String> jarFileNames = new HashSet<>();
+
+  @Override
+  public final void postSetUpCliCommandTestBase() throws Exception {
+    disconnectAllFromDS();
+  }
+
+  @Override
+  public final void preTearDownCliCommandTestBase() throws Exception {
+    shutdownAll();
+
+    serverNames.clear();
+    jarFileNames.clear();
+  }
+
+  /**
+   * Tests for {@link Extension}, {@link Extensible}, {@link XmlParser}, {@link XmlGenerator},
+   * {@link XmlEntity} as it applies to Extensions. Asserts that Mock Extension is created and
+   * altered on region and cache.
+   * 
+   * @since GemFire 8.1
+   */
+  @Category(FlakyTest.class) // GEODE-1334
+  @Test
+  public void testCreateExtensions() throws Exception {
+    Object[] result = setup();
+    final int locatorPort = (Integer) result[0];
+
+    createRegion(REPLICATE_REGION, RegionShortcut.REPLICATE, null);
+    createMockRegionExtension(REPLICATE_REGION, "value1");
+    alterMockRegionExtension(REPLICATE_REGION, "value2");
+    createMockCacheExtension("value1");
+    alterMockCacheExtension("value2");
+
+    // Start a new member which receives the shared configuration
+    // Verify the config creation on this member
+
+    final String newMemberWorkDir =
+        this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + newMember;
+
+    VM newMember = getHost(0).getVM(2);
+    newMember.invoke(new SerializableCallable() {
+      private static final long serialVersionUID = 1L;
+
+      @Override
+      public Object call() throws IOException {
+        Properties localProps = new Properties();
+
+        File workingDir = new File(newMemberWorkDir);
+        workingDir.mkdirs();
+
+        localProps.setProperty(MCAST_PORT, "0");
+        localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
+        localProps.setProperty(NAME, ClusterConfigurationExtensionsDUnitTest.newMember);
+        localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
+        localProps.setProperty(DEPLOY_WORKING_DIR, workingDir.getCanonicalPath());
+
+        getSystem(localProps);
+        Cache cache = getCache();
+
+        assertNotNull(cache);
+
+        Region<?, ?> region1 = cache.getRegion(REPLICATE_REGION);
+        assertNotNull(region1);
+
+        // MockRegionExtension verification
+        @SuppressWarnings("unchecked")
+        // should only be one region extension
+        final MockRegionExtension mockRegionExtension =
+            (MockRegionExtension) ((Extensible<Region<?, ?>>) region1).getExtensionPoint()
+                .getExtensions().iterator().next();
+        assertNotNull(mockRegionExtension);
+        assertEquals(1, mockRegionExtension.beforeCreateCounter.get());
+        assertEquals(1, mockRegionExtension.onCreateCounter.get());
+        assertEquals("value2", mockRegionExtension.getValue());
+
+        // MockCacheExtension verification
+        @SuppressWarnings("unchecked")
+        // should only be one cache extension
+        final MockCacheExtension mockCacheExtension =
+            (MockCacheExtension) ((Extensible<Cache>) cache).getExtensionPoint().getExtensions()
+                .iterator().next();
+        assertNotNull(mockCacheExtension);
+        assertEquals(1, mockCacheExtension.beforeCreateCounter.get());
+        assertEquals(1, mockCacheExtension.onCreateCounter.get());
+        assertEquals("value2", mockCacheExtension.getValue());
+
+        return getAllNormalMembers(cache);
+      }
+    });
+  }
+
+  /**
+   * Tests for {@link Extension}, {@link Extensible}, {@link XmlParser}, {@link XmlGenerator},
+   * {@link XmlEntity} as it applies to Extensions. Asserts that Mock Extension is created and
+   * destroyed on region and cache.
+   * 
+   * @since GemFire 8.1
+   */
+  @Category(FlakyTest.class) // GEODE-1333
+  @Test
+  public void testDestroyExtensions() throws Exception {
+    Object[] result = setup();
+    final int locatorPort = (Integer) result[0];
+
+    createRegion(REPLICATE_REGION, RegionShortcut.REPLICATE, null);
+    createMockRegionExtension(REPLICATE_REGION, "value1");
+    destroyMockRegionExtension(REPLICATE_REGION);
+    createMockCacheExtension("value1");
+    destroyMockCacheExtension();
+
+    // Start a new member which receives the shared configuration
+    // Verify the config creation on this member
+
+    final String newMemberWorkingDir =
+        this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + newMember;
+
+    VM newMember = getHost(0).getVM(2);
+    newMember.invoke(new SerializableCallable() {
+
+      @Override
+      public Object call() throws IOException {
+        Properties localProps = new Properties();
+
+        File workingDir = new File(newMemberWorkingDir);
+        workingDir.mkdirs();
+
+        localProps.setProperty(MCAST_PORT, "0");
+        localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
+        localProps.setProperty(NAME, ClusterConfigurationExtensionsDUnitTest.newMember);
+        localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
+        localProps.setProperty(DEPLOY_WORKING_DIR, workingDir.getCanonicalPath());
+
+        getSystem(localProps);
+        Cache cache = getCache();
+
+        assertNotNull(cache);
+
+        Region<?, ?> region1 = cache.getRegion(REPLICATE_REGION);
+        assertNotNull(region1);
+
+        // MockRegionExtension verification
+        @SuppressWarnings("unchecked")
+        final Extensible<Region<?, ?>> extensibleRegion = (Extensible<Region<?, ?>>) region1;
+        // Should not be any region extensions
+        assertTrue(!extensibleRegion.getExtensionPoint().getExtensions().iterator().hasNext());
+
+        // MockCacheExtension verification
+        @SuppressWarnings("unchecked")
+        final Extensible<Cache> extensibleCache = (Extensible<Cache>) cache;
+        // Should not be any cache extensions
+        assertTrue(!extensibleCache.getExtensionPoint().getExtensions().iterator().hasNext());
+
+        return getAllNormalMembers(cache);
+      }
+    });
+  }
+
+  private Object[] setup() throws IOException {
+    final int[] ports = getRandomAvailableTCPPorts(3);
+    final int locator1Port = ports[0];
+    final String locator1Name = "locator1-" + locator1Port;
+    final String locatorLogPath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator
+        + "locator-" + locator1Port + ".log";
+
+    VM locatorAndMgr = getHost(0).getVM(3);
+    Object[] result = (Object[]) locatorAndMgr.invoke(new SerializableCallable() {
+      @Override
+      public Object call() throws IOException {
+        int httpPort;
+        int jmxPort;
+        String jmxHost;
+
+        try {
+          jmxHost = InetAddress.getLocalHost().getHostName();
+        } catch (UnknownHostException ignore) {
+          jmxHost = "localhost";
+        }
+
+        final int[] ports = getRandomAvailableTCPPorts(2);
+
+        jmxPort = ports[0];
+        httpPort = ports[1];
+
+        final File locatorLogFile = new File(locatorLogPath);
+
+        final Properties locatorProps = new Properties();
+        locatorProps.setProperty(NAME, locator1Name);
+        locatorProps.setProperty(MCAST_PORT, "0");
+        locatorProps.setProperty(LOG_LEVEL, "config");
+        locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+        locatorProps.setProperty(JMX_MANAGER, "true");
+        locatorProps.setProperty(JMX_MANAGER_START, "true");
+        locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
+        locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
+        locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
+
+        final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator1Port,
+            locatorLogFile, null, locatorProps);
+
+        WaitCriterion wc = new WaitCriterion() {
+          @Override
+          public boolean done() {
+            return locator.isSharedConfigurationRunning();
+          }
+
+          @Override
+          public String description() {
+            return "Waiting for shared configuration to be started";
+          }
+        };
+        waitForCriterion(wc, TIMEOUT, INTERVAL, true);
+
+        final Object[] result = new Object[4];
+        result[0] = locator1Port;
+        result[1] = jmxHost;
+        result[2] = jmxPort;
+        result[3] = httpPort;
+        return result;
+      }
+    });
+
+    HeadlessGfsh gfsh = getDefaultShell();
+    String jmxHost = (String) result[1];
+    int jmxPort = (Integer) result[2];
+    int httpPort = (Integer) result[3];
+
+    connect(jmxHost, jmxPort, httpPort, gfsh);
+
+    final String dataMemberWorkingDir =
+        this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + dataMember;
+
+    // Create a cache in VM 1
+    VM dataMember = getHost(0).getVM(1);
+    dataMember.invoke(new SerializableCallable() {
+      @Override
+      public Object call() throws IOException {
+        Properties localProps = new Properties();
+        File workingDir = new File(dataMemberWorkingDir);
+        workingDir.mkdirs();
+
+        localProps.setProperty(MCAST_PORT, "0");
+        localProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
+        localProps.setProperty(NAME, ClusterConfigurationExtensionsDUnitTest.dataMember);
+        localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
+        localProps.setProperty(DEPLOY_WORKING_DIR, workingDir.getCanonicalPath());
+
+        getSystem(localProps);
+        Cache cache = getCache();
+        assertNotNull(cache);
+        return getAllNormalMembers(cache);
+      }
+    });
+
+    return result;
+  }
+
+  private void createRegion(String regionName, RegionShortcut regionShortCut, String group) {
+    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_REGION);
+    csb.addOption(CliStrings.CREATE_REGION__REGION, regionName);
+    csb.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, regionShortCut.name());
+    csb.addOptionWithValueCheck(CliStrings.CREATE_REGION__GROUP, group);
+    executeAndVerifyCommand(csb.toString());
+  }
+
+  private void createMockRegionExtension(final String regionName, final String value) {
+    CommandStringBuilder csb =
+        new CommandStringBuilder(MockExtensionCommands.CREATE_MOCK_REGION_EXTENSION);
+    csb.addOption(MockExtensionCommands.OPTION_REGION_NAME, regionName);
+    csb.addOption(MockExtensionCommands.OPTION_VALUE, value);
+    executeAndVerifyCommand(csb.toString());
+  }
+
+  private void alterMockRegionExtension(final String regionName, final String value) {
+    CommandStringBuilder csb =
+        new CommandStringBuilder(MockExtensionCommands.ALTER_MOCK_REGION_EXTENSION);
+    csb.addOption(MockExtensionCommands.OPTION_REGION_NAME, regionName);
+    csb.addOption(MockExtensionCommands.OPTION_VALUE, value);
+    executeAndVerifyCommand(csb.toString());
+  }
+
+  private void destroyMockRegionExtension(final String regionName) {
+    CommandStringBuilder csb =
+        new CommandStringBuilder(MockExtensionCommands.DESTROY_MOCK_REGION_EXTENSION);
+    csb.addOption(MockExtensionCommands.OPTION_REGION_NAME, regionName);
+    executeAndVerifyCommand(csb.toString());
+  }
+
+  private void createMockCacheExtension(final String value) {
+    CommandStringBuilder csb =
+        new CommandStringBuilder(MockExtensionCommands.CREATE_MOCK_CACHE_EXTENSION);
+    csb.addOption(MockExtensionCommands.OPTION_VALUE, value);
+    executeAndVerifyCommand(csb.toString());
+  }
+
+  private void alterMockCacheExtension(final String value) {
+    CommandStringBuilder csb =
+        new CommandStringBuilder(MockExtensionCommands.ALTER_MOCK_CACHE_EXTENSION);
+    csb.addOption(MockExtensionCommands.OPTION_VALUE, value);
+    executeAndVerifyCommand(csb.toString());
+  }
+
+  private void destroyMockCacheExtension() {
+    CommandStringBuilder csb =
+        new CommandStringBuilder(MockExtensionCommands.DESTROY_MOCK_CACHE_EXTENSION);
+    executeAndVerifyCommand(csb.toString());
+  }
+
+  private CommandResult executeAndVerifyCommand(String commandString) {
+    CommandResult cmdResult = executeCommand(commandString);
+    org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("Command : " + commandString);
+    org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()
+        .info("Command Result : " + commandResultToString(cmdResult));
+    assertEquals(Status.OK, cmdResult.getStatus());
+    assertFalse(cmdResult.failedToPersist());
+    return cmdResult;
+  }
+
+  private void shutdownAll() throws IOException {
+    VM locatorAndMgr = getHost(0).getVM(3);
+    locatorAndMgr.invoke(new SerializableCallable() {
+      @Override
+      public Object call() throws Exception {
+        GemFireCacheImpl cache = (GemFireCacheImpl) CacheFactory.getAnyInstance();
+        ShutdownAllRequest.send(cache.getDistributedSystem().getDistributionManager(), -1);
+        return null;
+      }
+    });
+
+    locatorAndMgr.invoke(SharedConfigurationTestUtils.cleanupLocator);
+    // Clean up the directories
+    if (serverNames != null && !serverNames.isEmpty()) {
+      for (String serverName : serverNames) {
+        final File serverDir = new File(serverName);
+        cleanDirectory(serverDir);
+        deleteDirectory(serverDir);
+      }
+    }
+  }
+}