This is an automated email from the ASF dual-hosted git repository.

jensdeppe pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 5a8ef65  GEODE-5971: Refactor Start/Status/Stop Locator commands to 
return ResultModel (#2869)
5a8ef65 is described below

commit 5a8ef6562ecd52da0308f7014320ad0182360ce9
Author: Jens Deppe <jde...@pivotal.io>
AuthorDate: Tue Nov 20 09:42:15 2018 -0800

    GEODE-5971: Refactor Start/Status/Stop Locator commands to return 
ResultModel (#2869)
---
 .../internal/cli/commands/StartLocatorCommand.java | 54 +++++++++++-----------
 .../internal/cli/commands/StartServerCommand.java  | 23 +++++----
 .../commands/lifecycle/StatusLocatorCommand.java   | 24 +++++-----
 .../cli/commands/lifecycle/StopLocatorCommand.java | 13 +++---
 4 files changed, 56 insertions(+), 58 deletions(-)

diff --git 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommand.java
 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommand.java
index aa4680b..0874a04 100644
--- 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommand.java
+++ 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommand.java
@@ -43,12 +43,11 @@ import org.apache.geode.internal.process.ProcessType;
 import org.apache.geode.internal.util.IOUtils;
 import org.apache.geode.management.cli.CliMetaData;
 import org.apache.geode.management.cli.ConverterHint;
-import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.cli.GfshParser;
 import org.apache.geode.management.internal.cli.domain.ConnectToLocatorResult;
 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.cli.result.model.InfoResultModel;
+import org.apache.geode.management.internal.cli.result.model.ResultModel;
 import org.apache.geode.management.internal.cli.shell.Gfsh;
 import org.apache.geode.management.internal.cli.shell.JmxOperationInvoker;
 import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
@@ -61,7 +60,7 @@ public class StartLocatorCommand extends InternalGfshCommand {
   @CliCommand(value = CliStrings.START_LOCATOR, help = 
CliStrings.START_LOCATOR__HELP)
   @CliMetaData(shellOnly = true,
       relatedTopic = {CliStrings.TOPIC_GEODE_LOCATOR, 
CliStrings.TOPIC_GEODE_LIFECYCLE})
-  public Result startLocator(
+  public ResultModel startLocator(
       @CliOption(key = CliStrings.START_LOCATOR__MEMBER_NAME,
           help = CliStrings.START_LOCATOR__MEMBER_NAME__HELP) String 
memberName,
       @CliOption(key = CliStrings.START_LOCATOR__BIND_ADDRESS,
@@ -141,7 +140,7 @@ public class StartLocatorCommand extends 
InternalGfshCommand {
 
   }
 
-  Result doStartLocator(
+  ResultModel doStartLocator(
       String memberName,
       String bindAddress,
       String classpath,
@@ -171,13 +170,13 @@ public class StartLocatorCommand extends 
InternalGfshCommand {
       throws MalformedObjectNameException, IOException, InterruptedException,
       ClassNotFoundException {
     if (gemfirePropertiesFile != null && !gemfirePropertiesFile.exists()) {
-      return ResultBuilder.createUserErrorResult(
+      return ResultModel.createError(
           CliStrings.format(CliStrings.GEODE_0_PROPERTIES_1_NOT_FOUND_MESSAGE, 
StringUtils.EMPTY,
               gemfirePropertiesFile.getAbsolutePath()));
     }
 
     if (gemfireSecurityPropertiesFile != null && 
!gemfireSecurityPropertiesFile.exists()) {
-      return ResultBuilder.createUserErrorResult(
+      return ResultModel.createError(
           CliStrings.format(CliStrings.GEODE_0_PROPERTIES_1_NOT_FOUND_MESSAGE, 
"Security ",
               gemfireSecurityPropertiesFile.getAbsolutePath()));
     }
@@ -285,7 +284,7 @@ public class StartLocatorCommand extends 
InternalGfshCommand {
         } else {
           final int exitValue = locatorProcess.exitValue();
 
-          return ResultBuilder.createShellClientErrorResult(
+          return ResultModel.createError(
               
String.format(CliStrings.START_LOCATOR__PROCESS_TERMINATED_ABNORMALLY_ERROR_MESSAGE,
                   exitValue, locatorLauncher.getWorkingDirectory(), 
message.toString()));
         }
@@ -305,21 +304,22 @@ public class StartLocatorCommand extends 
InternalGfshCommand {
         (registeredLocatorSignalListener && locatorSignalListener.isSignaled()
             && 
ServerLauncher.ServerState.isStartingNotRespondingOrNull(locatorState));
 
-    InfoResultData infoResultData = ResultBuilder.createInfoResultData();
+    ResultModel result = new ResultModel();
+    InfoResultModel infoResult = result.addInfo();
 
     if (loadSharedConfigurationFromDirectory) {
-      infoResultData.addLine("Warning: Option --load-cluster-config-from-dir 
is deprecated, use '"
+      infoResult.addLine("Warning: Option --load-cluster-config-from-dir is 
deprecated, use '"
           + CliStrings.IMPORT_SHARED_CONFIG
           + "' command instead to import any existing configuration.\n");
     }
 
     if (asyncStart) {
-      infoResultData.addLine(
+      infoResult.addLine(
           String.format(CliStrings.ASYNC_PROCESS_LAUNCH_MESSAGE, 
CliStrings.LOCATOR_TERM_NAME));
-      return ResultBuilder.buildResult(infoResultData);
+      return result;
     }
 
-    infoResultData.addLine(locatorState.toString());
+    infoResult.addLine(locatorState.toString());
     String locatorHostName;
     InetAddress bindAddr = locatorLauncher.getBindAddress();
     if (bindAddr != null) {
@@ -341,16 +341,16 @@ public class StartLocatorCommand extends 
InternalGfshCommand {
     // Else, ask the user to use the "connect" command to connect to the 
Locator.
     if (shouldAutoConnect(connect)) {
       boolean connected =
-          doAutoConnect(locatorHostName, locatorPort, configProperties, 
infoResultData);
+          doAutoConnect(locatorHostName, locatorPort, configProperties, 
infoResult);
 
       // Report on the state of the Shared Configuration service if enabled...
       if (enableSharedConfiguration && connected) {
-        
infoResultData.addLine(ClusterConfigurationStatusRetriever.fromLocator(locatorHostName,
+        
infoResult.addLine(ClusterConfigurationStatusRetriever.fromLocator(locatorHostName,
             locatorPort, configProperties));
       }
     }
 
-    return ResultBuilder.buildResult(infoResultData);
+    return result;
   }
 
   // TODO should we connect implicitly when in non-interactive, headless mode 
(e.g. gfsh -e "start
@@ -362,7 +362,7 @@ public class StartLocatorCommand extends 
InternalGfshCommand {
   }
 
   private boolean doAutoConnect(final String locatorHostname, final int 
locatorPort,
-      final Properties configurationProperties, final InfoResultData 
infoResultData) {
+      final Properties configurationProperties, final InfoResultModel 
infoResult) {
     boolean connectSuccess = false;
     boolean jmxManagerAuthEnabled = false;
     boolean jmxManagerSslEnabled = false;
@@ -385,8 +385,8 @@ public class StartLocatorCommand extends 
InternalGfshCommand {
         String shellAndLogMessage = 
CliStrings.format(CliStrings.CONNECT__MSG__SUCCESS,
             "JMX Manager " + memberEndpoint.toString(false));
 
-        infoResultData.addLine("\n");
-        infoResultData.addLine(shellAndLogMessage);
+        infoResult.addLine("\n");
+        infoResult.addLine(shellAndLogMessage);
         getGfsh().logToFile(shellAndLogMessage, null);
 
         connectSuccess = true;
@@ -411,20 +411,20 @@ public class StartLocatorCommand extends 
InternalGfshCommand {
 
     if (!connectSuccess) {
       doOnConnectionFailure(locatorHostname, locatorPort, 
jmxManagerAuthEnabled,
-          jmxManagerSslEnabled, infoResultData);
+          jmxManagerSslEnabled, infoResult);
     }
 
     if (StringUtils.isNotBlank(responseFailureMessage)) {
-      infoResultData.addLine("\n");
-      infoResultData.addLine(responseFailureMessage);
+      infoResult.addLine("\n");
+      infoResult.addLine(responseFailureMessage);
     }
     return connectSuccess;
   }
 
   private void doOnConnectionFailure(final String locatorHostName, final int 
locatorPort,
       final boolean jmxManagerAuthEnabled, final boolean jmxManagerSslEnabled,
-      final InfoResultData infoResultData) {
-    infoResultData.addLine("\n");
+      final InfoResultModel infoResult) {
+    infoResult.addLine("\n");
     CommandStringBuilder commandUsage = new 
CommandStringBuilder(CliStrings.CONNECT)
         .addOption(CliStrings.CONNECT__LOCATOR, locatorHostName + "[" + 
locatorPort + "]");
 
@@ -438,12 +438,12 @@ public class StartLocatorCommand extends 
InternalGfshCommand {
       message.append(jmxManagerAuthEnabled ? " and " : StringUtils.EMPTY)
           .append("SSL configuration");
     }
-    infoResultData.addLine(CliStrings.format(
+    infoResult.addLine(CliStrings.format(
         CliStrings.START_LOCATOR__USE__0__TO__CONNECT_WITH_SECURITY, 
commandUsage.toString()));
     if (jmxManagerAuthEnabled || jmxManagerSslEnabled) {
       message.append(" required to connect to the Manager.");
-      infoResultData.addLine("\n");
-      infoResultData.addLine(message.toString());
+      infoResult.addLine("\n");
+      infoResult.addLine(message.toString());
     }
   }
 
diff --git 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java
 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java
index ec87c2f..8d37214 100644
--- 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java
+++ 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java
@@ -41,11 +41,10 @@ import org.apache.geode.internal.process.ProcessType;
 import org.apache.geode.internal.util.IOUtils;
 import org.apache.geode.management.cli.CliMetaData;
 import org.apache.geode.management.cli.ConverterHint;
-import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.cli.CliUtil;
 import org.apache.geode.management.internal.cli.GfshParser;
 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.result.model.ResultModel;
 import org.apache.geode.management.internal.cli.shell.Gfsh;
 import org.apache.geode.management.internal.security.ResourceConstants;
 
@@ -55,7 +54,7 @@ public class StartServerCommand extends InternalGfshCommand {
   @CliCommand(value = CliStrings.START_SERVER, help = 
CliStrings.START_SERVER__HELP)
   @CliMetaData(shellOnly = true,
       relatedTopic = {CliStrings.TOPIC_GEODE_SERVER, 
CliStrings.TOPIC_GEODE_LIFECYCLE})
-  public Result startServer(
+  public ResultModel startServer(
       @CliOption(key = CliStrings.START_SERVER__NAME,
           help = CliStrings.START_SERVER__NAME__HELP) String memberName,
       @CliOption(key = CliStrings.START_SERVER__ASSIGN_BUCKETS, 
unspecifiedDefaultValue = "false",
@@ -194,8 +193,8 @@ public class StartServerCommand extends InternalGfshCommand 
{
         passwordToUse = 
getGfsh().readPassword(CliStrings.START_SERVER__PASSWORD + ": ");
       }
       if (StringUtils.isBlank(passwordToUse)) {
-        return ResultBuilder
-            
.createConnectionErrorResult(CliStrings.START_SERVER__MSG__PASSWORD_MUST_BE_SPECIFIED);
+        return ResultModel
+            
.createError(CliStrings.START_SERVER__MSG__PASSWORD_MUST_BE_SPECIFIED);
       }
     }
 
@@ -215,7 +214,7 @@ public class StartServerCommand extends InternalGfshCommand 
{
         httpServicePort, httpServiceBindAddress, userName, passwordToUse, 
redirectOutput);
   }
 
-  Result doStartServer(String memberName, Boolean assignBuckets, String 
bindAddress,
+  ResultModel doStartServer(String memberName, Boolean assignBuckets, String 
bindAddress,
       String cacheXmlPathname, String classpath, Float criticalHeapPercentage,
       Float criticalOffHeapPercentage, String workingDirectory, Boolean 
disableDefaultServer,
       Boolean disableExitWhenOutOfMemory, Boolean enableTimeStatistics,
@@ -237,7 +236,7 @@ public class StartServerCommand extends InternalGfshCommand 
{
 
     if (StringUtils.isNotBlank(cacheXmlPathname)) {
       if (!IOUtils.isExistingPathname(cacheXmlPathname)) {
-        return ResultBuilder.createUserErrorResult(
+        return ResultModel.createError(
             CliStrings.format(CliStrings.CACHE_XML_NOT_FOUND_MESSAGE, 
cacheXmlPathname));
       } else {
         getGfsh().logWarning(
@@ -246,13 +245,13 @@ public class StartServerCommand extends 
InternalGfshCommand {
     }
 
     if (gemfirePropertiesFile != null && !gemfirePropertiesFile.exists()) {
-      return ResultBuilder.createUserErrorResult(
+      return ResultModel.createError(
           CliStrings.format(CliStrings.GEODE_0_PROPERTIES_1_NOT_FOUND_MESSAGE, 
StringUtils.EMPTY,
               gemfirePropertiesFile.getAbsolutePath()));
     }
 
     if (gemfireSecurityPropertiesFile != null && 
!gemfireSecurityPropertiesFile.exists()) {
-      return ResultBuilder.createUserErrorResult(
+      return ResultModel.createError(
           CliStrings.format(CliStrings.GEODE_0_PROPERTIES_1_NOT_FOUND_MESSAGE, 
"Security ",
               gemfireSecurityPropertiesFile.getAbsolutePath()));
     }
@@ -402,7 +401,7 @@ public class StartServerCommand extends InternalGfshCommand 
{
         } else {
           final int exitValue = serverProcess.exitValue();
 
-          return ResultBuilder.createShellClientErrorResult(
+          return ResultModel.createError(
               
String.format(CliStrings.START_SERVER__PROCESS_TERMINATED_ABNORMALLY_ERROR_MESSAGE,
                   exitValue, serverLauncher.getWorkingDirectory(), 
message.toString()));
 
@@ -422,9 +421,9 @@ public class StartServerCommand extends InternalGfshCommand 
{
 
     if (asyncStart) { // async start
       Gfsh.print(String.format(CliStrings.ASYNC_PROCESS_LAUNCH_MESSAGE, 
SERVER_TERM_NAME));
-      return ResultBuilder.createInfoResult("");
+      return ResultModel.createInfo("");
     } else {
-      return ResultBuilder.createInfoResult(serverState.toString());
+      return ResultModel.createInfo(serverState.toString());
     }
   }
 
diff --git 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/lifecycle/StatusLocatorCommand.java
 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/lifecycle/StatusLocatorCommand.java
index cd7c6ac..5fc6c07 100644
--- 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/lifecycle/StatusLocatorCommand.java
+++ 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/lifecycle/StatusLocatorCommand.java
@@ -28,18 +28,17 @@ import org.apache.geode.internal.lang.StringUtils;
 import org.apache.geode.management.MemberMXBean;
 import org.apache.geode.management.cli.CliMetaData;
 import org.apache.geode.management.cli.ConverterHint;
-import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.cli.commands.InternalGfshCommand;
 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.cli.result.model.InfoResultModel;
+import org.apache.geode.management.internal.cli.result.model.ResultModel;
 import 
org.apache.geode.management.internal.configuration.utils.ClusterConfigurationStatusRetriever;
 
 public class StatusLocatorCommand extends InternalGfshCommand {
   @CliCommand(value = CliStrings.STATUS_LOCATOR, help = 
CliStrings.STATUS_LOCATOR__HELP)
   @CliMetaData(shellOnly = true,
       relatedTopic = {CliStrings.TOPIC_GEODE_LOCATOR, 
CliStrings.TOPIC_GEODE_LIFECYCLE})
-  public Result statusLocator(
+  public ResultModel statusLocator(
       @CliOption(key = CliStrings.STATUS_LOCATOR__MEMBER,
           optionContext = ConverterHint.LOCATOR_MEMBER_IDNAME,
           help = CliStrings.STATUS_LOCATOR__MEMBER__HELP) final String member,
@@ -62,11 +61,11 @@ public class StatusLocatorCommand extends 
InternalGfshCommand {
               LocatorLauncher.LocatorState.fromJson(locatorProxy.status());
           return createStatusLocatorResult(state);
         } else {
-          return ResultBuilder.createUserErrorResult(CliStrings.format(
+          return ResultModel.createError(CliStrings.format(
               
CliStrings.STATUS_LOCATOR__NO_LOCATOR_FOUND_FOR_MEMBER_ERROR_MESSAGE, member));
         }
       } else {
-        return ResultBuilder.createUserErrorResult(CliStrings.format(
+        return ResultModel.createError(CliStrings.format(
             CliStrings.STATUS_SERVICE__GFSH_NOT_CONNECTED_ERROR_MESSAGE, 
LOCATOR_TERM_NAME));
       }
     } else {
@@ -78,18 +77,19 @@ public class StatusLocatorCommand extends 
InternalGfshCommand {
       final LocatorLauncher.LocatorState status = locatorLauncher.status();
       if (status.getStatus().equals(AbstractLauncher.Status.NOT_RESPONDING)
           || status.getStatus().equals(AbstractLauncher.Status.STOPPED)) {
-        return ResultBuilder.createShellClientErrorResult(status.toString());
+        return ResultModel.createError(status.toString());
       }
       return createStatusLocatorResult(status);
     }
 
   }
 
-  protected Result createStatusLocatorResult(final 
LocatorLauncher.LocatorState state)
+  protected ResultModel createStatusLocatorResult(final 
LocatorLauncher.LocatorState state)
       throws NumberFormatException, IOException, ClassNotFoundException {
-    InfoResultData infoResultData = ResultBuilder.createInfoResultData();
-    infoResultData.addLine(state.toString());
-    
infoResultData.addLine(ClusterConfigurationStatusRetriever.fromLocator(state));
-    return ResultBuilder.buildResult(infoResultData);
+    ResultModel result = new ResultModel();
+    InfoResultModel info = result.addInfo();
+    info.addLine(state.toString());
+    info.addLine(ClusterConfigurationStatusRetriever.fromLocator(state));
+    return result;
   }
 }
diff --git 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/lifecycle/StopLocatorCommand.java
 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/lifecycle/StopLocatorCommand.java
index cef8293..6690ab2 100644
--- 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/lifecycle/StopLocatorCommand.java
+++ 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/lifecycle/StopLocatorCommand.java
@@ -29,10 +29,9 @@ import org.apache.geode.internal.util.StopWatch;
 import org.apache.geode.management.MemberMXBean;
 import org.apache.geode.management.cli.CliMetaData;
 import org.apache.geode.management.cli.ConverterHint;
-import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.cli.commands.InternalGfshCommand;
 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.result.model.ResultModel;
 import org.apache.geode.management.internal.cli.shell.Gfsh;
 
 public class StopLocatorCommand extends InternalGfshCommand {
@@ -41,7 +40,7 @@ public class StopLocatorCommand extends InternalGfshCommand {
   @CliCommand(value = CliStrings.STOP_LOCATOR, help = 
CliStrings.STOP_LOCATOR__HELP)
   @CliMetaData(shellOnly = true,
       relatedTopic = {CliStrings.TOPIC_GEODE_LOCATOR, 
CliStrings.TOPIC_GEODE_LIFECYCLE})
-  public Result stopLocator(
+  public ResultModel stopLocator(
       @CliOption(key = CliStrings.STOP_LOCATOR__MEMBER,
           optionContext = ConverterHint.LOCATOR_MEMBER_IDNAME,
           help = CliStrings.STOP_LOCATOR__MEMBER__HELP) final String member,
@@ -70,11 +69,11 @@ public class StopLocatorCommand extends InternalGfshCommand 
{
           locatorState = 
LocatorLauncher.LocatorState.fromJson(locatorProxy.status());
           locatorProxy.shutDownMember();
         } else {
-          return ResultBuilder.createUserErrorResult(CliStrings
+          return ResultModel.createError(CliStrings
               
.format(CliStrings.STOP_LOCATOR__NO_LOCATOR_FOUND_FOR_MEMBER_ERROR_MESSAGE, 
member));
         }
       } else {
-        return ResultBuilder.createUserErrorResult(CliStrings
+        return ResultModel.createError(CliStrings
             .format(CliStrings.STOP_SERVICE__GFSH_NOT_CONNECTED_ERROR_MESSAGE, 
LOCATOR_TERM_NAME));
       }
     } else {
@@ -104,9 +103,9 @@ public class StopLocatorCommand extends InternalGfshCommand 
{
         }
       }
 
-      return ResultBuilder.createInfoResult(StringUtils.EMPTY);
+      return ResultModel.createInfo(StringUtils.EMPTY);
     } else {
-      return ResultBuilder.createUserErrorResult(locatorState.toString());
+      return ResultModel.createError(locatorState.toString());
     }
   }
 }

Reply via email to