geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstew...@apache.org
Subject [5/5] geode git commit: GEODE-2966: RefactorLauncherLifecycleCommands
Date Thu, 01 Jun 2017 16:06:23 GMT
GEODE-2966: RefactorLauncherLifecycleCommands

 - Extract several commands into their own classes.
 - Extract utility methods into their own classes.
 - Rename AbstractCommandsSupport to GfshCommand, and convert it from an abstract class to an interface


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

Branch: refs/heads/develop
Commit: 9046c8dcd3bf530997fbb374085f1c1213db15e3
Parents: 2f50aef
Author: Jared Stewart <jstewart@pivotal.io>
Authored: Wed May 24 13:36:09 2017 -0700
Committer: Jared Stewart <jstewart@pivotal.io>
Committed: Thu Jun 1 09:01:12 2017 -0700

----------------------------------------------------------------------
 .../LauncherLifecycleCommandsDUnitTest.java     |   11 +-
 .../commands/LauncherLifecycleCommandsTest.java |   81 --
 .../geode/distributed/AbstractLauncher.java     |   14 +
 .../geode/distributed/LocatorLauncher.java      |   12 +
 .../geode/distributed/ServerLauncher.java       |   12 +
 .../java/org/apache/geode/internal/Assert.java  |   19 +
 .../internal/process/ProcessStreamReader.java   |   52 +
 .../management/internal/cli/CommandManager.java |    4 +-
 .../cli/commands/AbstractCommandsSupport.java   |  221 ----
 .../internal/cli/commands/ClientCommands.java   |   10 +-
 .../internal/cli/commands/ConfigCommands.java   |    5 +-
 .../CreateAlterDestroyRegionCommands.java       |    2 +-
 .../internal/cli/commands/DataCommands.java     |   11 +-
 .../internal/cli/commands/DeployCommands.java   |    6 +-
 .../cli/commands/DiskStoreCommands.java         |   11 +-
 .../cli/commands/DurableClientCommands.java     |    2 +-
 ...xportImportClusterConfigurationCommands.java |    2 +-
 .../cli/commands/ExportLogsCommand.java         |   39 +-
 .../internal/cli/commands/FunctionCommands.java |   52 +-
 .../internal/cli/commands/GfshCommand.java      |  195 +++
 .../internal/cli/commands/GfshHelpCommands.java |    2 +-
 .../internal/cli/commands/IndexCommands.java    |   10 +-
 .../cli/commands/LauncherLifecycleCommands.java | 1190 +-----------------
 .../internal/cli/commands/MemberCommands.java   |   10 +-
 .../cli/commands/MiscellaneousCommands.java     |   81 +-
 .../internal/cli/commands/PDXCommands.java      |    2 +-
 .../internal/cli/commands/QueueCommands.java    |    2 +-
 .../internal/cli/commands/RegionCommands.java   |   36 +-
 .../internal/cli/commands/ShellCommands.java    |    7 +-
 .../internal/cli/commands/StatusCommands.java   |    2 +-
 .../internal/cli/commands/WanCommands.java      |    2 +-
 .../lifecycle/StartJConsoleCommand.java         |  175 +++
 .../lifecycle/StartJVisualVMCommand.java        |   91 ++
 .../commands/lifecycle/StartPulseCommand.java   |   92 ++
 .../cli/commands/lifecycle/StartVsdCommand.java |  177 +++
 .../lifecycle/StatusLocatorCommand.java         |  102 ++
 .../commands/lifecycle/StatusServerCommand.java |   86 ++
 .../commands/lifecycle/StopLocatorCommand.java  |  124 ++
 .../commands/lifecycle/StopServerCommand.java   |  122 ++
 .../internal/cli/i18n/CliStrings.java           |    1 +
 .../management/internal/cli/shell/Gfsh.java     |    4 +
 .../internal/cli/shell/MXBeanProvider.java      |  100 ++
 .../management/internal/cli/util/HostUtils.java |   47 +
 .../management/internal/cli/util/JdkTool.java   |   97 ++
 .../ClusterConfigurationStatusRetriever.java    |  116 ++
 .../apache/geode/internal/AssertJUnitTest.java  |   62 +
 .../extension/mock/MockExtensionCommands.java   |    4 +-
 .../AbstractCommandsSupportJUnitTest.java       |  435 -------
 .../commands/DiskStoreCommandsJUnitTest.java    |    6 +-
 .../cli/commands/GfshCommandJUnitTest.java      |  397 ++++++
 .../cli/commands/IndexCommandsJUnitTest.java    |    6 +-
 .../lifecycle/StartJConsoleCommandTest.java     |   42 +
 .../internal/cli/util/HostUtilsTest.java        |   44 +
 .../internal/cli/util/JdkToolTest.java          |   75 ++
 .../internal/cli/LuceneIndexCommands.java       |    6 +-
 .../cli/LuceneIndexCommandsJUnitTest.java       |    6 +-
 56 files changed, 2401 insertions(+), 2121 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsDUnitTest.java b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsDUnitTest.java
index 27bc098..4455249 100644
--- a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsDUnitTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsDUnitTest.java
@@ -44,6 +44,7 @@ import org.apache.geode.internal.lang.ObjectUtils;
 import org.apache.geode.internal.lang.StringUtils;
 import org.apache.geode.internal.lang.SystemUtils;
 import org.apache.geode.internal.process.ProcessType;
+import org.apache.geode.internal.process.ProcessUtils;
 import org.apache.geode.internal.util.IOUtils;
 import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
@@ -151,7 +152,7 @@ public class LauncherLifecycleCommandsDUnitTest extends CliCommandTestBase {
     Integer pid;
 
     while ((pid = processIds.poll()) != null) {
-      if (launcherLifecycleCommands.isVmWithProcessIdRunning(pid)) {
+      if (ProcessUtils.isProcessAlive(pid)) {
         try {
           String killCommand = String.format("%1$s %2$d",
               SystemUtils.isWindows() ? "taskkill /F /PID" : "kill -9", pid);
@@ -258,7 +259,7 @@ public class LauncherLifecycleCommandsDUnitTest extends CliCommandTestBase {
 
             @Override
             public boolean done() {
-              return !launcherLifecycleCommands.isVmWithProcessIdRunning(pid);
+              return !ProcessUtils.isProcessAlive(pid);
             }
 
             @Override
@@ -1010,7 +1011,7 @@ public class LauncherLifecycleCommandsDUnitTest extends CliCommandTestBase {
     assertEquals(Status.ONLINE, serverState.getStatus());
 
     // Verify our GemFire Server JVM process is running!
-    assertTrue(new LauncherLifecycleCommands().isVmWithProcessIdRunning(serverState.getPid()));
+    assertTrue(serverState.isVmWithProcessIdRunning());
 
     ClientCache clientCache = setupClientCache(pathname + String.valueOf(serverPort), serverPort);
 
@@ -1035,7 +1036,7 @@ public class LauncherLifecycleCommandsDUnitTest extends CliCommandTestBase {
 
         @Override
         public boolean done() {
-          return !launcherLifecycleCommands.isVmWithProcessIdRunning(serverPid);
+          return !ProcessUtils.isProcessAlive(serverPid);
         }
 
         @Override
@@ -1048,7 +1049,7 @@ public class LauncherLifecycleCommandsDUnitTest extends CliCommandTestBase {
           true);
 
       // Verify our GemFire Server JVM process is was terminated!
-      assertFalse(new LauncherLifecycleCommands().isVmWithProcessIdRunning(serverState.getPid()));
+      assertFalse(serverState.isVmWithProcessIdRunning());
 
       serverState = serverLauncher.status();
 

http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsTest.java b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsTest.java
index 2a1662e..cc74398 100755
--- a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsTest.java
@@ -402,87 +402,6 @@ public class LauncherLifecycleCommandsTest {
   }
 
   @Test
-  public void testGetJavaPathname() {
-    assertEquals(
-        IOUtils.appendToPath(System.getProperty("java.home"), "bin",
-            "java" + LauncherLifecycleCommands.getExecutableSuffix()),
-        getLauncherLifecycleCommands().getJdkToolPathname(
-            "java" + LauncherLifecycleCommands.getExecutableSuffix(), new GemFireException() {}));
-  }
-
-  @Test(expected = NullPointerException.class)
-  public void testGetJdkToolPathnameWithNullPathnames() {
-    try {
-      getLauncherLifecycleCommands().getJdkToolPathname((Stack<String>) null,
-          new GemFireException() {});
-    } catch (NullPointerException expected) {
-      assertEquals("The JDK tool executable pathnames cannot be null!", expected.getMessage());
-      throw expected;
-    }
-  }
-
-  @Test(expected = NullPointerException.class)
-  public void testGetJdkToolPathnameWithNullGemFireException() {
-    try {
-      getLauncherLifecycleCommands().getJdkToolPathname(new Stack<String>(), null);
-    } catch (NullPointerException expected) {
-      assertEquals("The GemFireException cannot be null!", expected.getMessage());
-      throw expected;
-    }
-  }
-
-  @Test
-  public void testGetJdkToolPathnameForNonExistingTool() {
-    try {
-      final GemFireException expected = new GemFireException() {
-        @Override
-        public String getMessage() {
-          return "expected";
-        }
-      };
-
-      getLauncherLifecycleCommands().getJdkToolPathname("nonExistingTool.exe", expected);
-    } catch (GemFireException expected) {
-      assertEquals("expected", expected.getMessage());
-    }
-  }
-
-  @Test
-  public void testGetLocatorId() {
-    assertEquals("machine[11235]", getLauncherLifecycleCommands().getLocatorId("machine", 11235));
-    assertEquals("machine.domain.org[11235]",
-        getLauncherLifecycleCommands().getLocatorId("machine.domain.org", 11235));
-    assertEquals("machine[" + DistributionLocator.DEFAULT_LOCATOR_PORT + "]",
-        getLauncherLifecycleCommands().getLocatorId("machine", null));
-  }
-
-  @Test
-  public void testGetServerId() {
-    assertEquals("machine[12480]", getLauncherLifecycleCommands().getServerId("machine", 12480));
-    assertEquals("machine.domain.org[12480]",
-        getLauncherLifecycleCommands().getServerId("machine.domain.org", 12480));
-    assertEquals("machine[" + CacheServer.DEFAULT_PORT + "]",
-        getLauncherLifecycleCommands().getServerId("machine", null));
-  }
-
-  @Test
-  public void testCreateJmxServerUrlWithMemberName() {
-    assertEquals("service:jmx:rmi://localhost:8192/jndi/rmi://localhost:8192/jmxrmi",
-        getLauncherLifecycleCommands().getJmxServiceUrlAsString("localhost[8192]"));
-  }
-
-  @Test(expected = IllegalArgumentException.class)
-  public void testCreateJmxServiceUrlWithInvalidMemberName() {
-    try {
-      System.err.println(getLauncherLifecycleCommands().getJmxServiceUrlAsString("memberOne[]"));
-    } catch (IllegalArgumentException expected) {
-      assertEquals(CliStrings.START_JCONSOLE__CONNECT_BY_MEMBER_NAME_ID_ERROR_MESSAGE,
-          expected.getMessage());
-      throw expected;
-    }
-  }
-
-  @Test
   public void testCreateServerCommandLine() throws Exception {
     ServerLauncher serverLauncher = new ServerLauncher.Builder()
         .setCommand(ServerLauncher.Command.START).setDisableDefaultServer(true)

http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/geode-core/src/main/java/org/apache/geode/distributed/AbstractLauncher.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/AbstractLauncher.java b/geode-core/src/main/java/org/apache/geode/distributed/AbstractLauncher.java
index ce66057..28a156a 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/AbstractLauncher.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/AbstractLauncher.java
@@ -591,6 +591,20 @@ public abstract class AbstractLauncher<T extends Comparable<T>> implements Runna
       return new GfJsonObject(map).toString();
     }
 
+    public static boolean isStartingNotRespondingOrNull(final ServiceState serviceState) {
+      return (serviceState == null || serviceState.isStartingOrNotResponding());
+    }
+
+    public boolean isStartingOrNotResponding() {
+      return (Status.NOT_RESPONDING.equals(this.getStatus())
+          || Status.STARTING.equals(this.getStatus()));
+    }
+
+    public boolean isVmWithProcessIdRunning() {
+      // note: this will use JNA if available or return false
+      return ProcessUtils.isProcessAlive(this.getPid());
+    }
+
     /**
      * Gets the Java classpath used when launching the GemFire service.
      *

http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/geode-core/src/main/java/org/apache/geode/distributed/LocatorLauncher.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/LocatorLauncher.java b/geode-core/src/main/java/org/apache/geode/distributed/LocatorLauncher.java
index 43ab546..e06949c 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/LocatorLauncher.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/LocatorLauncher.java
@@ -2013,6 +2013,18 @@ public class LocatorLauncher extends AbstractLauncher<String> {
       }
     }
 
+    public static LocatorState fromDirectory(final String workingDirectory,
+        final String memberName) {
+      LocatorState locatorState =
+          new LocatorLauncher.Builder().setWorkingDirectory(workingDirectory).build().status();
+
+      if (ObjectUtils.equals(locatorState.getMemberName(), memberName)) {
+        return locatorState;
+      }
+
+      return new LocatorState(new LocatorLauncher.Builder().build(), Status.NOT_RESPONDING);
+    }
+
     public LocatorState(final LocatorLauncher launcher, final Status status) {
       // if status is NOT_RESPONDING then this is executing inside the JVM asking for he status; pid
       // etc will be set according to the caller's JVM instead

http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/geode-core/src/main/java/org/apache/geode/distributed/ServerLauncher.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/ServerLauncher.java b/geode-core/src/main/java/org/apache/geode/distributed/ServerLauncher.java
index a6d3064..4de1a95 100755
--- a/geode-core/src/main/java/org/apache/geode/distributed/ServerLauncher.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/ServerLauncher.java
@@ -2632,6 +2632,18 @@ public class ServerLauncher extends AbstractLauncher<String> {
       }
     }
 
+    public static ServerState fromDirectory(final String workingDirectory,
+        final String memberName) {
+      ServerState serverState = new ServerLauncher.Builder().setWorkingDirectory(workingDirectory)
+          .setDisableDefaultServer(true).build().status();
+
+      if (ObjectUtils.equals(serverState.getMemberName(), memberName)) {
+        return serverState;
+      }
+
+      return new ServerState(new ServerLauncher.Builder().build(), Status.NOT_RESPONDING);
+    }
+
     public ServerState(final ServerLauncher launcher, final Status status) {
       this(status, launcher.statusMessage, System.currentTimeMillis(), launcher.getId(),
           identifyPid(), ManagementFactory.getRuntimeMXBean().getUptime(),

http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/geode-core/src/main/java/org/apache/geode/internal/Assert.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/Assert.java b/geode-core/src/main/java/org/apache/geode/internal/Assert.java
index 4f54ca4..5823e2e 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/Assert.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/Assert.java
@@ -177,4 +177,23 @@ public class Assert {
 
     return true;
   }
+
+  public static void assertArgument(final boolean valid, final String message,
+      final Object... args) {
+    if (!valid) {
+      throw new IllegalArgumentException(String.format(message, args));
+    }
+  }
+
+  public static void assertNotNull(final Object obj, final String message, final Object... args) {
+    if (obj == null) {
+      throw new NullPointerException(String.format(message, args));
+    }
+  }
+
+  public static void assertState(final boolean valid, final String message, final Object... args) {
+    if (!valid) {
+      throw new IllegalStateException(String.format(message, args));
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/geode-core/src/main/java/org/apache/geode/internal/process/ProcessStreamReader.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/process/ProcessStreamReader.java b/geode-core/src/main/java/org/apache/geode/internal/process/ProcessStreamReader.java
index 18fca98..b514c6a 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/process/ProcessStreamReader.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/process/ProcessStreamReader.java
@@ -19,6 +19,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 
+import org.apache.commons.lang.SystemUtils;
 import org.apache.logging.log4j.Logger;
 
 import org.apache.geode.internal.logging.LogService;
@@ -29,6 +30,7 @@ import org.apache.geode.internal.logging.LogService;
  * @since GemFire 7.0
  */
 public abstract class ProcessStreamReader implements Runnable {
+  private static final int DEFAULT_PROCESS_OUTPUT_WAIT_TIME_MILLISECONDS = 5000;
   private static final Logger logger = LogService.getLogger();
 
   protected final Process process;
@@ -205,6 +207,56 @@ public abstract class ProcessStreamReader implements Runnable {
     BLOCKING, NON_BLOCKING;
   }
 
+  public static String waitAndCaptureProcessStandardOutputStream(final Process process) {
+    return waitAndCaptureProcessStandardOutputStream(process,
+        DEFAULT_PROCESS_OUTPUT_WAIT_TIME_MILLISECONDS);
+  }
+
+  public static String waitAndCaptureProcessStandardOutputStream(final Process process,
+      final long waitTimeMilliseconds) {
+    return waitAndCaptureProcessStream(process, process.getInputStream(), waitTimeMilliseconds);
+  }
+
+  public static String waitAndCaptureProcessStandardErrorStream(final Process process) {
+    return waitAndCaptureProcessStandardErrorStream(process,
+        DEFAULT_PROCESS_OUTPUT_WAIT_TIME_MILLISECONDS);
+  }
+
+  public static String waitAndCaptureProcessStandardErrorStream(final Process process,
+      final long waitTimeMilliseconds) {
+    return waitAndCaptureProcessStream(process, process.getErrorStream(), waitTimeMilliseconds);
+  }
+
+  private static String waitAndCaptureProcessStream(final Process process,
+      final InputStream processInputStream, long waitTimeMilliseconds) {
+    final StringBuffer buffer = new StringBuffer();
+
+    InputListener inputListener = line -> {
+      buffer.append(line);
+      buffer.append(SystemUtils.LINE_SEPARATOR);
+    };
+
+    ProcessStreamReader reader = new ProcessStreamReader.Builder(process)
+        .inputStream(processInputStream).inputListener(inputListener).build();
+
+    try {
+      reader.start();
+
+      final long endTime = (System.currentTimeMillis() + waitTimeMilliseconds);
+
+      while (System.currentTimeMillis() < endTime) {
+        try {
+          reader.join(waitTimeMilliseconds);
+        } catch (InterruptedException ignore) {
+        }
+      }
+    } finally {
+      reader.stop();
+    }
+
+    return buffer.toString();
+  }
+
   /**
    * Builds a ProcessStreamReader.
    * 

http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/geode-core/src/main/java/org/apache/geode/management/internal/cli/CommandManager.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/CommandManager.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/CommandManager.java
index f28f9f6..3c8f6cf 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/CommandManager.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/CommandManager.java
@@ -21,7 +21,7 @@ import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.geode.distributed.ConfigurationProperties;
 import org.apache.geode.distributed.internal.DistributionConfig;
 import org.apache.geode.internal.ClassPathLoader;
-import org.apache.geode.management.internal.cli.commands.AbstractCommandsSupport;
+import org.apache.geode.management.internal.cli.commands.GfshCommand;
 import org.apache.geode.management.internal.cli.help.Helper;
 import org.apache.geode.management.internal.cli.shell.Gfsh;
 import org.apache.geode.management.internal.cli.util.ClasspathScanLoadHelper;
@@ -221,7 +221,7 @@ public class CommandManager {
     try {
       // geode's commands
       foundClasses = ClasspathScanLoadHelper.scanPackageForClassesImplementing(
-          AbstractCommandsSupport.class.getPackage().getName(), CommandMarker.class);
+          GfshCommand.class.getPackage().getName(), CommandMarker.class);
 
       for (Class<?> klass : foundClasses) {
         try {

http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/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
deleted file mode 100644
index 26b903b..0000000
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AbstractCommandsSupport.java
+++ /dev/null
@@ -1,221 +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.commands;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.geode.cache.CacheFactory;
-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.ClusterConfigurationService;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.internal.cache.InternalCache;
-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;
-import org.springframework.shell.core.CommandMarker;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * The AbstractCommandsSupport class is an abstract base class encapsulating common functionality
- * for implementing command classes with command for the GemFire shell (gfsh).
- * <p>
- * 
- * @see org.apache.geode.cache.Cache
- * @see org.apache.geode.cache.execute.FunctionService
- * @see org.apache.geode.distributed.DistributedMember
- * @see org.apache.geode.management.internal.cli.shell.Gfsh
- * @see org.springframework.shell.core.CommandMarker
- * @since GemFire 7.0
- */
-@SuppressWarnings("unused")
-public abstract class AbstractCommandsSupport implements CommandMarker {
-  protected static SecurityService securityService = SecurityService.getSecurityService();
-
-  protected static void assertArgument(final boolean valid, final String message,
-      final Object... args) {
-    if (!valid) {
-      throw new IllegalArgumentException(String.format(message, args));
-    }
-  }
-
-  protected static void assertNotNull(final Object obj, final String message,
-      final Object... args) {
-    if (obj == null) {
-      throw new NullPointerException(String.format(message, args));
-    }
-  }
-
-  protected static void assertState(final boolean valid, final String message,
-      final Object... args) {
-    if (!valid) {
-      throw new IllegalStateException(String.format(message, args));
-    }
-  }
-
-  protected static String convertDefaultValue(final String from, final String to) {
-    return (CliMetaData.ANNOTATION_DEFAULT_VALUE.equals(from) ? to : from);
-  }
-
-  protected static String toString(final Boolean condition, final String trueValue,
-      final String falseValue) {
-    return (Boolean.TRUE.equals(condition) ? StringUtils.defaultIfBlank(trueValue, "true")
-        : StringUtils.defaultIfBlank(falseValue, "false"));
-  }
-
-  protected static String toString(final Throwable t, final boolean printStackTrace) {
-    String message = t.getMessage();
-
-    if (printStackTrace) {
-      StringWriter writer = new StringWriter();
-      t.printStackTrace(new PrintWriter(writer));
-      message = writer.toString();
-    }
-
-    return message;
-  }
-
-  protected boolean isConnectedAndReady() {
-    return (getGfsh() != null && getGfsh().isConnectedAndReady());
-  }
-
-  protected ClusterConfigurationService 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");
-    }
-    ClusterConfigurationService sc = getSharedConfiguration();
-    if (sc == null) {
-      result.setCommandPersisted(false);
-    } else {
-      runnable.run();
-      result.setCommandPersisted(true);
-    }
-  }
-
-  protected boolean isDebugging() {
-    return (getGfsh() != null && getGfsh().getDebug());
-  }
-
-  protected boolean isLogging() {
-    return (getGfsh() != null);
-  }
-
-  protected InternalCache getCache() {
-    return (InternalCache) CacheFactory.getAnyInstance();
-  }
-
-  protected static Gfsh getGfsh() {
-    return Gfsh.getCurrentInstance();
-  }
-
-  @SuppressWarnings("deprecated")
-  protected DistributedMember getMember(final InternalCache cache, final String memberName) {
-    for (final DistributedMember member : getMembers(cache)) {
-      if (memberName.equalsIgnoreCase(member.getName())
-          || memberName.equalsIgnoreCase(member.getId())) {
-        return member;
-      }
-    }
-
-    throw new MemberNotFoundException(
-        CliStrings.format(CliStrings.MEMBER_NOT_FOUND_ERROR_MESSAGE, memberName));
-  }
-
-  /**
-   * Gets all members in the GemFire distributed system/cache.
-   *
-   * @param cache the GemFire cache.
-   * @return all members in the GemFire distributed system/cache.
-   * @see org.apache.geode.management.internal.cli.CliUtil#getAllMembers(org.apache.geode.internal.cache.InternalCache)
-   * @deprecated use CliUtil.getAllMembers(org.apache.geode.cache.Cache) instead
-   */
-  @Deprecated
-  protected Set<DistributedMember> getMembers(final InternalCache cache) {
-    Set<DistributedMember> members = new HashSet<DistributedMember>(cache.getMembers());
-    members.add(cache.getDistributedSystem().getDistributedMember());
-    return members;
-  }
-
-  protected Execution getMembersFunctionExecutor(final Set<DistributedMember> members) {
-    return FunctionService.onMembers(members);
-  }
-
-  protected void logInfo(final String message) {
-    logInfo(message, null);
-  }
-
-  protected void logInfo(final Throwable cause) {
-    logInfo(cause.getMessage(), cause);
-  }
-
-  protected void logInfo(final String message, final Throwable cause) {
-    if (isLogging()) {
-      getGfsh().logInfo(message, cause);
-    }
-  }
-
-  protected void logWarning(final String message) {
-    logWarning(message, null);
-  }
-
-  protected void logWarning(final Throwable cause) {
-    logWarning(cause.getMessage(), cause);
-  }
-
-  protected void logWarning(final String message, final Throwable cause) {
-    if (isLogging()) {
-      getGfsh().logWarning(message, cause);
-    }
-  }
-
-  protected void logSevere(final String message) {
-    logSevere(message, null);
-  }
-
-  protected void logSevere(final Throwable cause) {
-    logSevere(cause.getMessage(), cause);
-  }
-
-  protected void logSevere(final String message, final Throwable cause) {
-    if (isLogging()) {
-      getGfsh().logSevere(message, cause);
-    }
-  }
-
-  @SuppressWarnings("unchecked")
-  protected <T extends Function> T register(T function) {
-    if (FunctionService.isRegistered(function.getId())) {
-      function = (T) FunctionService.getFunction(function.getId());
-    } else {
-      FunctionService.registerFunction(function);
-    }
-
-    return function;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ClientCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ClientCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ClientCommands.java
index 18940fc..e619342 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ClientCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ClientCommands.java
@@ -54,11 +54,7 @@ import javax.management.ObjectName;
 /**
  * @since GemFire 8.0
  */
-public class ClientCommands implements CommandMarker {
-
-  private Gfsh getGfsh() {
-    return Gfsh.getCurrentInstance();
-  }
+public class ClientCommands implements GfshCommand {
 
   @CliCommand(value = CliStrings.LIST_CLIENTS, help = CliStrings.LIST_CLIENT__HELP)
   @CliMetaData(relatedTopic = {CliStrings.TOPIC_CLIENT})
@@ -148,10 +144,6 @@ public class ClientCommands implements CommandMarker {
     return result;
   }
 
-  private InternalCache getCache() {
-    return (InternalCache) CacheFactory.getAnyInstance();
-  }
-
   @CliCommand(value = CliStrings.DESCRIBE_CLIENT, help = CliStrings.DESCRIBE_CLIENT__HELP)
   @CliMetaData(relatedTopic = {CliStrings.TOPIC_CLIENT})
   @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)

http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/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 52a0a9d..bc9c05b 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
@@ -43,6 +43,7 @@ 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.domain.XmlEntity;
 import org.apache.geode.management.internal.security.ResourceOperation;
 import org.apache.geode.security.ResourcePermission.Operation;
@@ -67,7 +68,7 @@ import java.util.TreeSet;
  * @since GemFire 7.0
  *
  */
-public class ConfigCommands extends AbstractCommandsSupport {
+public class ConfigCommands implements GfshCommand {
   private final ExportConfigFunction exportConfigFunction = new ExportConfigFunction();
   private final GetMemberConfigInformationFunction getMemberConfigFunction =
       new GetMemberConfigInformationFunction();
@@ -490,7 +491,7 @@ public class ConfigCommands extends AbstractCommandsSupport {
         try {
           commandResult.saveIncomingFiles(saveDirString);
         } catch (IOException ioex) {
-          getGfsh().logSevere("Unable to export config", ioex);
+          Gfsh.getCurrentInstance().logSevere("Unable to export config", ioex);
         }
       }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/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 6e1a74e..ad40518 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
@@ -85,7 +85,7 @@ import javax.management.ObjectName;
 /**
  * @since GemFire 7.0
  */
-public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport {
+public class CreateAlterDestroyRegionCommands implements GfshCommand {
 
   public static final Set<RegionShortcut> PERSISTENT_OVERFLOW_SHORTCUTS = new TreeSet<>();
 

http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java
index a38e545..cb9c4fe 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java
@@ -62,7 +62,6 @@ 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.shiro.subject.Subject;
-import org.springframework.shell.core.CommandMarker;
 import org.springframework.shell.core.annotation.CliAvailabilityIndicator;
 import org.springframework.shell.core.annotation.CliCommand;
 import org.springframework.shell.core.annotation.CliOption;
@@ -85,7 +84,7 @@ import java.util.concurrent.TimeoutException;
 /**
  * @since GemFire 7.0
  */
-public class DataCommands implements CommandMarker {
+public class DataCommands implements GfshCommand {
 
   final int resultItemCount = 9;
 
@@ -95,14 +94,6 @@ public class DataCommands implements CommandMarker {
 
   private SecurityService securityService = IntegratedSecurityService.getSecurityService();
 
-  private Gfsh getGfsh() {
-    return Gfsh.getCurrentInstance();
-  }
-
-  private InternalCache getCache() {
-    return (InternalCache) CacheFactory.getAnyInstance();
-  }
-
   @CliCommand(value = CliStrings.REBALANCE, help = CliStrings.REBALANCE__HELP)
   @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_DATA, CliStrings.TOPIC_GEODE_REGION})
   @ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)

http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/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 544a517..30d840a 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
@@ -17,6 +17,7 @@ package org.apache.geode.management.internal.cli.commands;
 import org.apache.geode.SystemFailure;
 import org.apache.geode.cache.execute.ResultCollector;
 import org.apache.geode.distributed.DistributedMember;
+import org.apache.geode.internal.security.SecurityService;
 import org.apache.geode.management.cli.CliMetaData;
 import org.apache.geode.management.cli.ConverterHint;
 import org.apache.geode.management.cli.Result;
@@ -54,10 +55,10 @@ import java.util.Set;
  * Commands for deploying, un-deploying and listing files deployed using the command line shell.
  * <p/>
  * 
- * @see org.apache.geode.management.internal.cli.commands.AbstractCommandsSupport
+ * @see GfshCommand
  * @since GemFire 7.0
  */
-public class DeployCommands extends AbstractCommandsSupport {
+public class DeployCommands implements GfshCommand {
 
   private final DeployFunction deployFunction = new DeployFunction();
   private final UndeployFunction undeployFunction = new UndeployFunction();
@@ -84,6 +85,7 @@ public class DeployCommands extends AbstractCommandsSupport {
 
       // since deploy function can potentially do a lot of damage to security, this action should
       // require these following privileges
+      SecurityService securityService = SecurityService.getSecurityService();
       securityService.authorizeClusterManage();
       securityService.authorizeClusterWrite();
       securityService.authorizeDataManage();

http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/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 226cfaf..64fafda 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
@@ -99,18 +99,11 @@ import org.apache.geode.security.ResourcePermission.Resource;
 /**
  * The DiskStoreCommands class encapsulates all GemFire Disk Store commands in Gfsh.
  *
- * @see org.apache.geode.management.internal.cli.commands.AbstractCommandsSupport
+ * @see GfshCommand
  * @since GemFire 7.0
  */
 @SuppressWarnings("unused")
-public class DiskStoreCommands extends AbstractCommandsSupport {
-
-  @Override
-  protected Set<DistributedMember> getMembers(final InternalCache cache) {
-    // TODO determine what this does (as it is untested and unmockable!)
-    return CliUtil.getAllMembers(cache);
-  }
-
+public class DiskStoreCommands implements GfshCommand {
   protected Set<DistributedMember> getNormalMembers(final InternalCache cache) {
     // TODO determine what this does (as it is untested and unmockable!)
     return CliUtil.getAllNormalMembers(cache);

http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DurableClientCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DurableClientCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DurableClientCommands.java
index 9cb87ac..6441f20 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DurableClientCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DurableClientCommands.java
@@ -54,7 +54,7 @@ import org.springframework.shell.core.annotation.CliOption;
  * </p>
  */
 @SuppressWarnings("unused")
-public class DurableClientCommands extends AbstractCommandsSupport {
+public class DurableClientCommands implements GfshCommand {
 
   private static final ListDurableCqNamesFunction listDurableCqNamesFunction =
       new ListDurableCqNamesFunction();

http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java
index ea10182..9d263d1 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java
@@ -63,7 +63,7 @@ import java.util.Set;
  * Commands for the cluster configuration
  */
 @SuppressWarnings("unused")
-public class ExportImportClusterConfigurationCommands extends AbstractCommandsSupport {
+public class ExportImportClusterConfigurationCommands implements GfshCommand {
 
   @CliCommand(value = {CliStrings.EXPORT_SHARED_CONFIG},
       help = CliStrings.EXPORT_SHARED_CONFIG__HELP)

http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java
index b824bc9..0ff780c 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java
@@ -14,25 +14,8 @@
  */
 package org.apache.geode.management.internal.cli.commands;
 
-import java.io.File;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
-import org.apache.logging.log4j.Logger;
-import org.springframework.shell.core.CommandMarker;
-import org.springframework.shell.core.annotation.CliCommand;
-import org.springframework.shell.core.annotation.CliOption;
-
-import org.apache.geode.cache.CacheFactory;
 import org.apache.geode.cache.Region;
 import org.apache.geode.cache.execute.ResultCollector;
 import org.apache.geode.distributed.DistributedMember;
@@ -47,13 +30,27 @@ import org.apache.geode.management.internal.cli.functions.ExportLogsFunction;
 import org.apache.geode.management.internal.cli.functions.SizeExportLogsFunction;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
 import org.apache.geode.management.internal.cli.result.ResultBuilder;
-import org.apache.geode.management.internal.cli.util.ExportLogsCacheWriter;
 import org.apache.geode.management.internal.cli.util.BytesToString;
+import org.apache.geode.management.internal.cli.util.ExportLogsCacheWriter;
 import org.apache.geode.management.internal.configuration.utils.ZipUtils;
 import org.apache.geode.management.internal.security.ResourceOperation;
 import org.apache.geode.security.ResourcePermission;
+import org.apache.logging.log4j.Logger;
+import org.springframework.shell.core.annotation.CliCommand;
+import org.springframework.shell.core.annotation.CliOption;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
-public class ExportLogsCommand implements CommandMarker {
+public class ExportLogsCommand implements GfshCommand {
 
   private static final Logger logger = LogService.getLogger();
 
@@ -64,10 +61,6 @@ public class ExportLogsCommand implements CommandMarker {
 
   private static final Pattern DISK_SPACE_LIMIT_PATTERN = Pattern.compile("(\\d+)([kmgtKMGT]?)");
 
-  InternalCache getCache() {
-    return (InternalCache) CacheFactory.getAnyInstance();
-  }
-
   @CliCommand(value = CliStrings.EXPORT_LOGS, help = CliStrings.EXPORT_LOGS__HELP)
   @CliMetaData(shellOnly = false, isFileDownloadOverHttp = true,
       interceptor = "org.apache.geode.management.internal.cli.commands.ExportLogsInterceptor",

http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/FunctionCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/FunctionCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/FunctionCommands.java
index 8ea65ff..2774584 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/FunctionCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/FunctionCommands.java
@@ -14,22 +14,7 @@
  */
 package org.apache.geode.management.internal.cli.commands;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-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 org.springframework.shell.core.CommandMarker;
-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.SystemFailure;
-import org.apache.geode.cache.CacheFactory;
 import org.apache.geode.cache.Region;
 import org.apache.geode.cache.execute.Execution;
 import org.apache.geode.cache.execute.Function;
@@ -60,27 +45,30 @@ import org.apache.geode.management.internal.cli.result.CompositeResultData;
 import org.apache.geode.management.internal.cli.result.ErrorResultData;
 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.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.Arrays;
+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;
 
 /**
  * @since GemFire 7.0
  */
 @SuppressWarnings("unused")
-public class FunctionCommands implements CommandMarker {
+public class FunctionCommands implements GfshCommand {
 
   private final ListFunctionFunction listFunctionFunction = new ListFunctionFunction();
 
-  private Gfsh getGfsh() {
-    return Gfsh.getCurrentInstance();
-  }
-
-  private InternalCache getCache() {
-    return (InternalCache) CacheFactory.getAnyInstance();
-  }
-
   @CliCommand(value = CliStrings.EXECUTE_FUNCTION, help = CliStrings.EXECUTE_FUNCTION__HELP)
   @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_FUNCTION})
   @ResourceOperation(resource = Resource.DATA, operation = Operation.WRITE)
@@ -352,20 +340,6 @@ public class FunctionCommands implements CommandMarker {
     return result;
   }
 
-  DistributedMember getMember(InternalCache cache, String memberNameOrId) {
-    DistributedMember member = null;
-    Set<DistributedMember> dsMembers = CliUtil.getAllMembers(cache);
-    Iterator<DistributedMember> it = dsMembers.iterator();
-    while (it.hasNext()) {
-      DistributedMember tempMember = (DistributedMember) it.next();
-      if (memberNameOrId.equals(tempMember.getId())
-          || memberNameOrId.equals(tempMember.getName())) {
-        return tempMember;
-      }
-    }
-    return member;
-  }
-
   void executeAndGetResults(String functionId, String filterString, String resultCollector,
       String[] arguments, InternalCache cache, DistributedMember member,
       TabularResultData resultTable, String onRegion) {

http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GfshCommand.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GfshCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GfshCommand.java
new file mode 100644
index 0000000..d46024d
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GfshCommand.java
@@ -0,0 +1,195 @@
+/*
+ * 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.commands;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.geode.cache.CacheFactory;
+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.ClusterConfigurationService;
+import org.apache.geode.distributed.internal.InternalLocator;
+import org.apache.geode.internal.cache.InternalCache;
+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;
+import org.springframework.shell.core.CommandMarker;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Encapsulates common functionality for implementing command classes for the Geode shell (gfsh).
+ * <p>
+ * 
+ * @see org.apache.geode.cache.Cache
+ * @see org.apache.geode.cache.execute.FunctionService
+ * @see org.apache.geode.distributed.DistributedMember
+ * @see org.apache.geode.management.internal.cli.shell.Gfsh
+ * @see org.springframework.shell.core.CommandMarker
+ */
+@SuppressWarnings("unused")
+public interface GfshCommand extends CommandMarker {
+  default String convertDefaultValue(final String from, final String to) {
+    return (CliMetaData.ANNOTATION_DEFAULT_VALUE.equals(from) ? to : from);
+  }
+
+  default String toString(final Boolean condition, final String trueValue,
+      final String falseValue) {
+    return (Boolean.TRUE.equals(condition) ? StringUtils.defaultIfBlank(trueValue, "true")
+        : StringUtils.defaultIfBlank(falseValue, "false"));
+  }
+
+  default String toString(final Throwable t, final boolean printStackTrace) {
+    String message = t.getMessage();
+
+    if (printStackTrace) {
+      StringWriter writer = new StringWriter();
+      t.printStackTrace(new PrintWriter(writer));
+      message = writer.toString();
+    }
+
+    return message;
+  }
+
+  default boolean isConnectedAndReady() {
+    return (getGfsh() != null && getGfsh().isConnectedAndReady());
+  }
+
+  default ClusterConfigurationService getSharedConfiguration() {
+    InternalLocator locator = InternalLocator.getLocator();
+    return (locator == null) ? null : locator.getSharedConfiguration();
+  }
+
+  default void persistClusterConfiguration(Result result, Runnable runnable) {
+    if (result == null) {
+      throw new IllegalArgumentException("Result should not be null");
+    }
+    ClusterConfigurationService sc = getSharedConfiguration();
+    if (sc == null) {
+      result.setCommandPersisted(false);
+    } else {
+      runnable.run();
+      result.setCommandPersisted(true);
+    }
+  }
+
+  default boolean isDebugging() {
+    return (getGfsh() != null && getGfsh().getDebug());
+  }
+
+  default boolean isLogging() {
+    return (getGfsh() != null);
+  }
+
+  default InternalCache getCache() {
+    return (InternalCache) CacheFactory.getAnyInstance();
+  }
+
+  default Gfsh getGfsh() {
+    return Gfsh.getCurrentInstance();
+  }
+
+  @SuppressWarnings("deprecated")
+  default DistributedMember getMember(final InternalCache cache, final String memberName) {
+    for (final DistributedMember member : getMembers(cache)) {
+      if (memberName.equalsIgnoreCase(member.getName())
+          || memberName.equalsIgnoreCase(member.getId())) {
+        return member;
+      }
+    }
+
+    throw new MemberNotFoundException(
+        CliStrings.format(CliStrings.MEMBER_NOT_FOUND_ERROR_MESSAGE, memberName));
+  }
+
+  /**
+   * Gets all members in the GemFire distributed system/cache.
+   * 
+   * @param cache the GemFire cache.
+   * @return all members in the GemFire distributed system/cache.
+   * @see org.apache.geode.management.internal.cli.CliUtil#getAllMembers(org.apache.geode.internal.cache.InternalCache)
+   * @deprecated use CliUtil.getAllMembers(org.apache.geode.cache.Cache) instead
+   */
+  @Deprecated
+  default Set<DistributedMember> getMembers(final InternalCache cache) {
+    Set<DistributedMember> members = new HashSet<DistributedMember>(cache.getMembers());
+    members.add(cache.getDistributedSystem().getDistributedMember());
+    return members;
+  }
+
+  default Execution getMembersFunctionExecutor(final Set<DistributedMember> members) {
+    return FunctionService.onMembers(members);
+  }
+
+  default void logInfo(final String message) {
+    logInfo(message, null);
+  }
+
+  default void logInfo(final Throwable cause) {
+    logInfo(cause.getMessage(), cause);
+  }
+
+  default void logInfo(final String message, final Throwable cause) {
+    if (isLogging()) {
+      getGfsh().logInfo(message, cause);
+    }
+  }
+
+  default void logWarning(final String message) {
+    logWarning(message, null);
+  }
+
+  default void logWarning(final Throwable cause) {
+    logWarning(cause.getMessage(), cause);
+  }
+
+  default void logWarning(final String message, final Throwable cause) {
+    if (isLogging()) {
+      getGfsh().logWarning(message, cause);
+    }
+  }
+
+  default void logSevere(final String message) {
+    logSevere(message, null);
+  }
+
+  default void logSevere(final Throwable cause) {
+    logSevere(cause.getMessage(), cause);
+  }
+
+  default void logSevere(final String message, final Throwable cause) {
+    if (isLogging()) {
+      getGfsh().logSevere(message, cause);
+    }
+  }
+
+  @SuppressWarnings("unchecked")
+  default <T extends Function> T register(T function) {
+    if (FunctionService.isRegistered(function.getId())) {
+      function = (T) FunctionService.getFunction(function.getId());
+    } else {
+      FunctionService.registerFunction(function);
+    }
+
+    return function;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GfshHelpCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GfshHelpCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GfshHelpCommands.java
index da13cdf..5fd7988 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GfshHelpCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/GfshHelpCommands.java
@@ -28,7 +28,7 @@ import org.springframework.shell.core.annotation.CliOption;
 /**
  * @since GemFire 7.0
  */
-public class GfshHelpCommands implements CommandMarker, CommandManagerAware {
+public class GfshHelpCommands implements GfshCommand, CommandManagerAware {
   private CommandManager commandManager = null;
 
   public void setCommandManager(CommandManager commandManager) {

http://git-wip-us.apache.org/repos/asf/geode/blob/9046c8dc/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 407424a..b3d9675 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
@@ -69,13 +69,13 @@ import java.util.concurrent.atomic.AtomicReference;
  * in GemFire.
  * </p>
  * 
- * @see org.apache.geode.management.internal.cli.commands.AbstractCommandsSupport
+ * @see GfshCommand
  * @see org.apache.geode.management.internal.cli.domain.IndexDetails
  * @see org.apache.geode.management.internal.cli.functions.ListIndexFunction
  * @since GemFire 7.0
  */
 @SuppressWarnings("unused")
-public class IndexCommands extends AbstractCommandsSupport {
+public class IndexCommands implements GfshCommand {
 
   private static final CreateIndexFunction createIndexFunction = new CreateIndexFunction();
   private static final DestroyIndexFunction destroyIndexFunction = new DestroyIndexFunction();
@@ -86,12 +86,6 @@ public class IndexCommands extends AbstractCommandsSupport {
 
   private SecurityService securityService = IntegratedSecurityService.getSecurityService();
 
-  @Override
-  protected Set<DistributedMember> getMembers(final InternalCache cache) {
-    // TODO determine what this does (as it is untested and unmockable!)
-    return CliUtil.getAllMembers(cache);
-  }
-
   @CliCommand(value = CliStrings.LIST_INDEX, help = CliStrings.LIST_INDEX__HELP)
   @CliMetaData(shellOnly = false,
       relatedTopic = {CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA})


Mime
View raw message