geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinmeil...@apache.org
Subject [4/4] geode git commit: GEODE-2261: do not use remote function calls to update the shared configuration
Date Mon, 09 Jan 2017 18:18:04 GMT
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 <jiliao@pivotal.io>
Authored: Wed Dec 28 11:44:58 2016 -0800
Committer: Jinmei Liao <jiliao@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();
-  }
-
-}


Mime
View raw message