geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinmeil...@apache.org
Subject [geode] branch develop updated: GEODE-5971: refactor remaining command's usage of Result (#3481)
Date Mon, 22 Apr 2019 17:53:25 GMT
This is an automated email from the ASF dual-hosted git repository.

jinmeiliao 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 c7e43c7  GEODE-5971: refactor remaining command's usage of Result (#3481)
c7e43c7 is described below

commit c7e43c7ba1f2f47b255606788af4267056965ce2
Author: jinmeiliao <jiliao@pivotal.io>
AuthorDate: Mon Apr 22 10:53:05 2019 -0700

    GEODE-5971: refactor remaining command's usage of Result (#3481)
---
 .../jdbc/internal/cli/CreateMappingCommand.java    | 14 ++---
 .../cli/CreateMappingCommandInterceptorTest.java   | 22 +++++---
 .../cli/commands/ChangeLogLevelCommand.java        | 10 +---
 .../cli/commands/CreateGatewaySenderCommand.java   | 10 ++--
 .../internal/cli/commands/DeployCommand.java       |  3 +-
 .../internal/cli/commands/ListClientCommand.java   |  4 --
 .../cli/commands/lifecycle/StartPulseCommand.java  | 64 +++++++++-------------
 .../cli/commands/lifecycle/StartVsdCommand.java    | 61 ++++++++-------------
 .../internal/cli/result/ResultBuilder.java         | 30 ----------
 .../test/junit/assertions/ResultModelAssert.java   |  4 ++
 10 files changed, 78 insertions(+), 144 deletions(-)

diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommand.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommand.java
index 84b08d5..3607a89 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommand.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommand.java
@@ -50,7 +50,6 @@ import org.apache.geode.distributed.ConfigurationPersistenceService;
 import org.apache.geode.distributed.DistributedMember;
 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.cli.SingleGfshCommand;
 import org.apache.geode.management.internal.ManagementAgent;
 import org.apache.geode.management.internal.SystemManagementService;
@@ -60,8 +59,6 @@ import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
 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.FileResult;
-import org.apache.geode.management.internal.cli.result.ModelCommandResult;
-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.security.ResourceOperation;
 import org.apache.geode.security.ResourcePermission;
@@ -433,25 +430,24 @@ public class CreateMappingCommand extends SingleGfshCommand {
   public static class Interceptor extends AbstractCliAroundInterceptor {
 
     @Override
-    public Result preExecution(GfshParseResult parseResult) {
+    public Object preExecution(GfshParseResult parseResult) {
       String pdxClassFileName = (String) parseResult.getParamValue(CREATE_MAPPING__PDX_CLASS_FILE);
 
       if (StringUtils.isBlank(pdxClassFileName)) {
-        return new ModelCommandResult(ResultModel.createInfo(""));
+        return ResultModel.createInfo("");
       }
 
       FileResult fileResult = new FileResult();
       File pdxClassFile = new File(pdxClassFileName);
       if (!pdxClassFile.exists()) {
-        return ResultBuilder.createUserErrorResult(pdxClassFile + " not found.");
+        return ResultModel.createError(pdxClassFile + " not found.");
       }
       if (!pdxClassFile.isFile()) {
-        return ResultBuilder.createUserErrorResult(pdxClassFile + " is not a file.");
+        return ResultModel.createError(pdxClassFile + " is not a file.");
       }
       String fileExtension = FilenameUtils.getExtension(pdxClassFileName);
       if (!fileExtension.equalsIgnoreCase("jar") && !fileExtension.equalsIgnoreCase("class"))
{
-        return ResultBuilder
-            .createUserErrorResult(pdxClassFile + " must end with \".jar\" or \".class\".");
+        return ResultModel.createError(pdxClassFile + " must end with \".jar\" or \".class\".");
       }
       fileResult.addFile(pdxClassFile);
 
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandInterceptorTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandInterceptorTest.java
index d85348b..05c898a 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandInterceptorTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandInterceptorTest.java
@@ -14,6 +14,7 @@
  */
 package org.apache.geode.connectors.jdbc.internal.cli;
 
+import static org.apache.geode.test.junit.assertions.ResultModelAssert.assertResultModel;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -29,6 +30,7 @@ import org.apache.geode.connectors.util.internal.MappingConstants;
 import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.cli.GfshParseResult;
 import org.apache.geode.management.internal.cli.result.FileResult;
+import org.apache.geode.management.internal.cli.result.model.ResultModel;
 
 public class CreateMappingCommandInterceptorTest {
 
@@ -43,7 +45,7 @@ public class CreateMappingCommandInterceptorTest {
   @Test
   public void preExecutionGivenNullPdxClassFileReturnsOK() {
     when(gfshParseResult.getParamValue(MappingConstants.PDX_CLASS_FILE)).thenReturn(null);
-    Result result = interceptor.preExecution(gfshParseResult);
+    ResultModel result = (ResultModel) interceptor.preExecution(gfshParseResult);
     assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
   }
 
@@ -51,9 +53,10 @@ public class CreateMappingCommandInterceptorTest {
   public void preExecutionGivenNonExistingPdxClassFileReturnsError() {
     when(gfshParseResult.getParamValue(MappingConstants.PDX_CLASS_FILE))
         .thenReturn("NonExistingFile");
-    Result result = interceptor.preExecution(gfshParseResult);
+    ResultModel result = (ResultModel) interceptor.preExecution(gfshParseResult);
     assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
-    assertThat(result.nextLine()).contains("NonExistingFile not found.");
+    assertResultModel(result).hasInfoResultModel("info").hasOutput()
+        .contains("NonExistingFile not found.");
   }
 
   @Test
@@ -61,9 +64,10 @@ public class CreateMappingCommandInterceptorTest {
     File tempFolder = testFolder.newFolder("tempFolder");
     when(gfshParseResult.getParamValue(MappingConstants.PDX_CLASS_FILE))
         .thenReturn(tempFolder.getAbsolutePath());
-    Result result = interceptor.preExecution(gfshParseResult);
+    ResultModel result = (ResultModel) interceptor.preExecution(gfshParseResult);
     assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
-    assertThat(result.nextLine()).contains(tempFolder.getAbsolutePath() + " is not a file.");
+    assertResultModel(result).hasInfoResultModel("info").hasOutput()
+        .contains(tempFolder.getAbsolutePath() + " is not a file.");
   }
 
   @Test
@@ -71,9 +75,9 @@ public class CreateMappingCommandInterceptorTest {
     File tempFile = testFolder.newFile("tempFile");
     when(gfshParseResult.getParamValue(MappingConstants.PDX_CLASS_FILE))
         .thenReturn(tempFile.getAbsolutePath());
-    Result result = interceptor.preExecution(gfshParseResult);
+    ResultModel result = (ResultModel) interceptor.preExecution(gfshParseResult);
     assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
-    assertThat(result.nextLine())
+    assertResultModel(result).hasInfoResultModel("info").hasOutput()
         .contains(tempFile.getAbsolutePath() + " must end with \".jar\" or \".class\".");
   }
 
@@ -82,7 +86,7 @@ public class CreateMappingCommandInterceptorTest {
     File tempFile = testFolder.newFile("tempFile.class");
     when(gfshParseResult.getParamValue(MappingConstants.PDX_CLASS_FILE))
         .thenReturn(tempFile.getAbsolutePath());
-    Result result = interceptor.preExecution(gfshParseResult);
+    Result result = (Result) interceptor.preExecution(gfshParseResult);
     assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
     assertThat(result).isInstanceOf(FileResult.class);
     FileResult fileResult = (FileResult) result;
@@ -94,7 +98,7 @@ public class CreateMappingCommandInterceptorTest {
     File tempFile = testFolder.newFile("tempFile.jar");
     when(gfshParseResult.getParamValue(MappingConstants.PDX_CLASS_FILE))
         .thenReturn(tempFile.getAbsolutePath());
-    Result result = interceptor.preExecution(gfshParseResult);
+    Result result = (Result) interceptor.preExecution(gfshParseResult);
     assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
     assertThat(result).isInstanceOf(FileResult.class);
     FileResult fileResult = (FileResult) result;
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommand.java
index 128626a..b1bd2a8 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommand.java
@@ -39,9 +39,6 @@ import org.apache.geode.management.internal.cli.AbstractCliAroundInterceptor;
 import org.apache.geode.management.internal.cli.GfshParseResult;
 import org.apache.geode.management.internal.cli.functions.ChangeLogLevelFunction;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
-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.result.model.ResultModel;
 import org.apache.geode.management.internal.cli.result.model.TabularResultModel;
 import org.apache.geode.management.internal.security.ResourceOperation;
@@ -101,10 +98,7 @@ public class ChangeLogLevelCommand extends GfshCommand {
     Object[] functionArgs = new Object[1];
     functionArgs[0] = logLevel;
 
-    CompositeResultData compositeResultData = ResultBuilder.createCompositeResultData();
-    CompositeResultData.SectionResultData section = compositeResultData.addSection("section");
-    TabularResultData resultTable = section.addTable("ChangeLogLevel");
-    resultTable = resultTable.setHeader("Summary");
+    ResultModel result = new ResultModel();
 
     Execution execution = FunctionService.onMembers(dsMembers).setArguments(functionArgs);
     if (execution == null) {
@@ -113,7 +107,7 @@ public class ChangeLogLevelCommand extends GfshCommand {
     List<?> resultList =
         (List<?>) this.executeFunction(logFunction, functionArgs, dsMembers).getResult();
 
-    ResultModel result = new ResultModel();
+
     TabularResultModel tableInfo = result.addTable("result");
     tableInfo.setColumnHeader(CliStrings.CHANGE_LOGLEVEL__COLUMN_MEMBER,
         CliStrings.CHANGE_LOGLEVEL__COLUMN_STATUS);
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateGatewaySenderCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateGatewaySenderCommand.java
index c09a313..397ac54 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateGatewaySenderCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateGatewaySenderCommand.java
@@ -32,7 +32,6 @@ import org.apache.geode.distributed.internal.membership.InternalDistributedMembe
 import org.apache.geode.internal.Version;
 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.cli.SingleGfshCommand;
 import org.apache.geode.management.internal.cli.AbstractCliAroundInterceptor;
 import org.apache.geode.management.internal.cli.GfshParseResult;
@@ -40,7 +39,6 @@ import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
 import org.apache.geode.management.internal.cli.functions.GatewaySenderCreateFunction;
 import org.apache.geode.management.internal.cli.functions.GatewaySenderFunctionArgs;
 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.security.ResourceOperation;
 import org.apache.geode.security.ResourcePermission;
@@ -223,7 +221,7 @@ public class CreateGatewaySenderCommand extends SingleGfshCommand {
 
   public static class Interceptor extends AbstractCliAroundInterceptor {
     @Override
-    public Result preExecution(GfshParseResult parseResult) {
+    public ResultModel preExecution(GfshParseResult parseResult) {
       Boolean parallel =
           (Boolean) parseResult.getParamValue(CliStrings.CREATE_GATEWAYSENDER__PARALLEL);
       OrderPolicy orderPolicy =
@@ -232,16 +230,16 @@ public class CreateGatewaySenderCommand extends SingleGfshCommand {
           (Integer) parseResult.getParamValue(CliStrings.CREATE_GATEWAYSENDER__DISPATCHERTHREADS);
 
       if (dispatcherThreads != null && dispatcherThreads > 1 && orderPolicy
== null) {
-        return ResultBuilder.createUserErrorResult(
+        return ResultModel.createError(
             "Must specify --order-policy when --dispatcher-threads is larger than 1.");
       }
 
       if (parallel && orderPolicy == OrderPolicy.THREAD) {
-        return ResultBuilder.createUserErrorResult(
+        return ResultModel.createError(
             "Parallel Gateway Sender can not be created with THREAD OrderPolicy");
       }
 
-      return ResultBuilder.createInfoResult("");
+      return ResultModel.createInfo("");
     }
   }
 }
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommand.java
index 880bd5b..62b0033 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommand.java
@@ -53,7 +53,6 @@ import org.apache.geode.management.internal.cli.i18n.CliStrings;
 import org.apache.geode.management.internal.cli.remote.CommandExecutionContext;
 import org.apache.geode.management.internal.cli.remote.CommandExecutor;
 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.model.ResultModel;
 import org.apache.geode.management.internal.cli.result.model.TabularResultModel;
 import org.apache.geode.management.internal.security.ResourceOperation;
@@ -209,7 +208,7 @@ public class DeployCommand extends GfshCommand {
               + "MB\n\nContinue? ";
 
       if (readYesNo(message, Response.YES) == Response.NO) {
-        return ResultBuilder.createShellClientAbortOperationResult(
+        return ResultModel.createError(
             "Aborted deploy of " + fileResult.getFormattedFileList() + ".");
       }
 
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListClientCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListClientCommand.java
index 8871f42..d7251c4 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListClientCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListClientCommand.java
@@ -30,8 +30,6 @@ import org.apache.geode.management.cli.CliMetaData;
 import org.apache.geode.management.cli.GfshCommand;
 import org.apache.geode.management.internal.cli.LogWrapper;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
-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.model.ResultModel;
 import org.apache.geode.management.internal.cli.result.model.TabularResultModel;
 import org.apache.geode.management.internal.security.ResourceOperation;
@@ -44,8 +42,6 @@ public class ListClientCommand extends GfshCommand {
       operation = ResourcePermission.Operation.READ)
   public ResultModel listClient() throws Exception {
     ResultModel result = new ResultModel();
-    CompositeResultData compositeResultData = ResultBuilder.createCompositeResultData();
-    CompositeResultData.SectionResultData section = compositeResultData.addSection("section1");
 
     TabularResultModel resultTable = result.addTable("clientList");
     String headerText = "Client List";
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/lifecycle/StartPulseCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/lifecycle/StartPulseCommand.java
index ad21e98..e4cd18c 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/lifecycle/StartPulseCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/lifecycle/StartPulseCommand.java
@@ -22,17 +22,15 @@ import java.net.URI;
 
 import javax.management.ObjectName;
 
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.shell.core.annotation.CliCommand;
 import org.springframework.shell.core.annotation.CliOption;
 
-import org.apache.geode.SystemFailure;
-import org.apache.geode.internal.lang.StringUtils;
 import org.apache.geode.management.cli.CliMetaData;
-import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.ManagementConstants;
 import org.apache.geode.management.internal.cli.commands.OfflineGfshCommand;
 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.OperationInvoker;
 
 public class StartPulseCommand extends OfflineGfshCommand {
@@ -40,48 +38,36 @@ public class StartPulseCommand extends OfflineGfshCommand {
   @CliCommand(value = CliStrings.START_PULSE, help = CliStrings.START_PULSE__HELP)
   @CliMetaData(shellOnly = true, relatedTopic = {CliStrings.TOPIC_GEODE_MANAGER,
       CliStrings.TOPIC_GEODE_JMX, CliStrings.TOPIC_GEODE_M_AND_M})
-  public Result startPulse(@CliOption(key = CliStrings.START_PULSE__URL,
+  public ResultModel startPulse(@CliOption(key = CliStrings.START_PULSE__URL,
       unspecifiedDefaultValue = "http://localhost:7070/pulse",
-      help = CliStrings.START_PULSE__URL__HELP) final String url) {
-    try {
-      if (StringUtils.isNotBlank(url)) {
-        browse(URI.create(url));
-        return ResultBuilder.createInfoResult(CliStrings.START_PULSE__RUN);
-      } else {
-        if (isConnectedAndReady()) {
-          OperationInvoker operationInvoker = getGfsh().getOperationInvoker();
+      help = CliStrings.START_PULSE__URL__HELP) final String url) throws IOException {
+    if (StringUtils.isNotBlank(url)) {
+      browse(URI.create(url));
+      return ResultModel.createInfo(CliStrings.START_PULSE__RUN);
+    } else {
+      if (isConnectedAndReady()) {
+        OperationInvoker operationInvoker = getGfsh().getOperationInvoker();
 
-          ObjectName managerObjectName = (ObjectName) operationInvoker.getAttribute(
-              ManagementConstants.OBJECTNAME__DISTRIBUTEDSYSTEM_MXBEAN, "ManagerObjectName");
+        ObjectName managerObjectName = (ObjectName) operationInvoker.getAttribute(
+            ManagementConstants.OBJECTNAME__DISTRIBUTEDSYSTEM_MXBEAN, "ManagerObjectName");
 
-          String pulseURL =
-              (String) operationInvoker.getAttribute(managerObjectName.toString(), "PulseURL");
+        String pulseURL =
+            (String) operationInvoker.getAttribute(managerObjectName.toString(), "PulseURL");
 
-          if (StringUtils.isNotBlank(pulseURL)) {
-            browse(URI.create(pulseURL));
-            return ResultBuilder
-                .createInfoResult(CliStrings.START_PULSE__RUN + " with URL: " + pulseURL);
-          } else {
-            String pulseMessage = (String) operationInvoker
-                .getAttribute(managerObjectName.toString(), "StatusMessage");
-            return (StringUtils.isNotBlank(pulseMessage)
-                ? ResultBuilder.createGemFireErrorResult(pulseMessage)
-                : ResultBuilder.createGemFireErrorResult(CliStrings.START_PULSE__URL__NOTFOUND));
-          }
+        if (StringUtils.isNotBlank(pulseURL)) {
+          browse(URI.create(pulseURL));
+          return ResultModel.createError(CliStrings.START_PULSE__RUN + " with URL: " + pulseURL);
         } else {
-          return ResultBuilder.createUserErrorResult(CliStrings
-              .format(CliStrings.GFSH_MUST_BE_CONNECTED_FOR_LAUNCHING_0, "GemFire Pulse"));
+          String pulseMessage = (String) operationInvoker
+              .getAttribute(managerObjectName.toString(), "StatusMessage");
+          return (StringUtils.isNotBlank(pulseMessage)
+              ? ResultModel.createError(pulseMessage)
+              : ResultModel.createError(CliStrings.START_PULSE__URL__NOTFOUND));
         }
+      } else {
+        return ResultModel.createError(CliStrings
+            .format(CliStrings.GFSH_MUST_BE_CONNECTED_FOR_LAUNCHING_0, "GemFire Pulse"));
       }
-    } catch (Exception e) {
-      return ResultBuilder.createShellClientErrorResult(e.getMessage());
-    } catch (VirtualMachineError e) {
-      SystemFailure.initiateFailure(e);
-      throw e;
-    } catch (Throwable t) {
-      SystemFailure.checkFailure();
-      return ResultBuilder.createShellClientErrorResult(
-          String.format(CliStrings.START_PULSE__ERROR, t.getMessage()));
     }
   }
 
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/lifecycle/StartVsdCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/lifecycle/StartVsdCommand.java
index c0f1dd8..de8f3f4 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/lifecycle/StartVsdCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/lifecycle/StartVsdCommand.java
@@ -29,65 +29,52 @@ import java.util.TreeSet;
 import org.springframework.shell.core.annotation.CliCommand;
 import org.springframework.shell.core.annotation.CliOption;
 
-import org.apache.geode.GemFireException;
-import org.apache.geode.SystemFailure;
 import org.apache.geode.annotations.Immutable;
-import org.apache.geode.internal.lang.StringUtils;
 import org.apache.geode.internal.lang.SystemUtils;
 import org.apache.geode.internal.util.IOUtils;
 import org.apache.geode.management.cli.CliMetaData;
-import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.cli.commands.OfflineGfshCommand;
 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;
 
 public class StartVsdCommand extends OfflineGfshCommand {
   @CliCommand(value = CliStrings.START_VSD, help = CliStrings.START_VSD__HELP)
   @CliMetaData(shellOnly = true,
       relatedTopic = {CliStrings.TOPIC_GEODE_M_AND_M, CliStrings.TOPIC_GEODE_STATISTICS})
-  public Result startVsd(@CliOption(key = CliStrings.START_VSD__FILE,
-      help = CliStrings.START_VSD__FILE__HELP) final String[] statisticsArchiveFilePathnames)
{
-    try {
-      String geodeHome = System.getenv("GEODE_HOME");
+  public ResultModel startVsd(@CliOption(key = CliStrings.START_VSD__FILE,
+      help = CliStrings.START_VSD__FILE__HELP) final String[] statisticsArchiveFilePathnames)
+      throws Exception {
 
-      assertState(StringUtils.isNotBlank(geodeHome), CliStrings.GEODE_HOME_NOT_FOUND_ERROR_MESSAGE);
+    String geodeHome = System.getenv("GEODE_HOME");
 
-      assertState(IOUtils.isExistingPathname(getPathToVsd()),
-          String.format(CliStrings.START_VSD__NOT_FOUND_ERROR_MESSAGE, geodeHome));
+    assertState(org.apache.commons.lang3.StringUtils.isNotBlank(geodeHome),
+        CliStrings.GEODE_HOME_NOT_FOUND_ERROR_MESSAGE);
 
-      String[] vsdCommandLine = createdVsdCommandLine(statisticsArchiveFilePathnames);
+    assertState(IOUtils.isExistingPathname(getPathToVsd()),
+        String.format(CliStrings.START_VSD__NOT_FOUND_ERROR_MESSAGE, geodeHome));
 
-      if (isDebugging()) {
-        getGfsh().printAsInfo(
-            String.format("GemFire VSD command-line (%1$s)", Arrays.toString(vsdCommandLine)));
-      }
+    String[] vsdCommandLine = createdVsdCommandLine(statisticsArchiveFilePathnames);
 
-      Process vsdProcess = Runtime.getRuntime().exec(vsdCommandLine);
+    if (isDebugging()) {
+      getGfsh().printAsInfo(
+          String.format("GemFire VSD command-line (%1$s)", Arrays.toString(vsdCommandLine)));
+    }
 
-      getGfsh().printAsInfo(CliStrings.START_VSD__RUN);
+    Process vsdProcess = Runtime.getRuntime().exec(vsdCommandLine);
 
-      String vsdProcessOutput = waitAndCaptureProcessStandardErrorStream(vsdProcess);
+    getGfsh().printAsInfo(CliStrings.START_VSD__RUN);
 
-      InfoResultData infoResultData = ResultBuilder.createInfoResultData();
+    String vsdProcessOutput = waitAndCaptureProcessStandardErrorStream(vsdProcess);
 
-      if (StringUtils.isNotBlank(vsdProcessOutput)) {
-        infoResultData.addLine(StringUtils.LINE_SEPARATOR);
-        infoResultData.addLine(vsdProcessOutput);
-      }
+    ResultModel result = new ResultModel();
+    InfoResultModel info = result.addInfo("info");
 
-      return ResultBuilder.buildResult(infoResultData);
-    } catch (GemFireException | IllegalStateException | IllegalArgumentException
-        | FileNotFoundException e) {
-      return ResultBuilder.createShellClientErrorResult(e.getMessage());
-    } catch (VirtualMachineError e) {
-      SystemFailure.initiateFailure(e);
-      throw e;
-    } catch (Throwable t) {
-      SystemFailure.checkFailure();
-      return ResultBuilder.createShellClientErrorResult(
-          String.format(CliStrings.START_VSD__ERROR_MESSAGE, t.getMessage()));
+    if (org.apache.commons.lang3.StringUtils.isNotBlank(vsdProcessOutput)) {
+      info.addLine(vsdProcessOutput);
     }
+
+    return result;
   }
 
   protected String[] createdVsdCommandLine(final String[] statisticsArchiveFilePathnames)
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/ResultBuilder.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/ResultBuilder.java
index 8f1feea..e2141e5 100755
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/ResultBuilder.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/ResultBuilder.java
@@ -15,12 +15,10 @@
 package org.apache.geode.management.internal.cli.result;
 
 import java.nio.file.Paths;
-import java.util.List;
 
 import org.apache.commons.lang3.StringUtils;
 
 import org.apache.geode.management.cli.Result;
-import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
 import org.apache.geode.management.internal.cli.json.GfJsonException;
 import org.apache.geode.management.internal.cli.json.GfJsonObject;
 import org.apache.geode.management.internal.cli.result.model.ResultModel;
@@ -185,34 +183,6 @@ public class ResultBuilder {
     return new LegacyCommandResult(resultData);
   }
 
-  public static CommandResult buildResult(List<CliFunctionResult> functionResults)
{
-    return buildResult(functionResults, null, null);
-  }
-
-  public static CommandResult buildResult(List<CliFunctionResult> functionResults,
String header,
-      String footer) {
-    TabularResultData tabularData = ResultBuilder.createTabularResultData();
-    boolean success = false;
-    for (CliFunctionResult result : functionResults) {
-      tabularData.accumulate("Member", result.getMemberIdOrName());
-      tabularData.accumulate("Status", result.getLegacyStatus());
-      // if one member returns back successful results, the command results in success
-      if (result.isSuccessful()) {
-        success = true;
-      }
-    }
-
-    if (header != null) {
-      tabularData.setHeader(header);
-    }
-    if (footer != null) {
-      tabularData.setFooter(footer);
-    }
-
-    tabularData.setStatus(success ? Result.Status.OK : Result.Status.ERROR);
-    return ResultBuilder.buildResult(tabularData);
-  }
-
   /**
    * Prepare Result from JSON. Type of result is expected to there in the JSON as 'contentType'
    * which should be one of {@link ResultData#TYPE_TABULAR}, {@link ResultData#TYPE_COMPOSITE},
diff --git a/geode-junit/src/main/java/org/apache/geode/test/junit/assertions/ResultModelAssert.java
b/geode-junit/src/main/java/org/apache/geode/test/junit/assertions/ResultModelAssert.java
index 99b8b8d..743e810 100644
--- a/geode-junit/src/main/java/org/apache/geode/test/junit/assertions/ResultModelAssert.java
+++ b/geode-junit/src/main/java/org/apache/geode/test/junit/assertions/ResultModelAssert.java
@@ -47,4 +47,8 @@ public class ResultModelAssert extends AbstractAssert<ResultModelAssert,
ResultM
     assertThat(dataSection).isNotNull();
     return new TabularResultModelAssert(dataSection);
   }
+
+  public static ResultModelAssert assertResultModel(ResultModel model) {
+    return new ResultModelAssert(model);
+  }
 }


Mime
View raw message