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

khowe 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 ce52674  GEODE-5971: Refactor StatusClusterConfigServiceCommand to 
extend GfshCommand base type (#2960)
ce52674 is described below

commit ce52674d70a5188737661de9512780c912c9fd7d
Author: Aditya Anchuri <[email protected]>
AuthorDate: Fri Dec 7 08:54:38 2018 -0800

    GEODE-5971: Refactor StatusClusterConfigServiceCommand to extend 
GfshCommand base type (#2960)
    
    GEODE-5971: Refactor StartClusterConfigServiceCommand to extend GfshCommand 
base type
    * Remove unnecessary cleanup step
    * Add more test coverage to status-cluster-config, by shutting down a 
locator
    
    Signed-off-by: Ken Howe <[email protected]>
    Signed-off-by: Aditya Anchuri <[email protected]>
---
 ...StatusClusterConfigServiceCommandDUnitTest.java | 57 ++++++++++++++++++++++
 .../StatusClusterConfigServiceCommand.java         | 46 ++++++++---------
 .../FetchSharedConfigurationStatusFunction.java    |  2 +-
 3 files changed, 82 insertions(+), 23 deletions(-)

diff --git 
a/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/StatusClusterConfigServiceCommandDUnitTest.java
 
b/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/StatusClusterConfigServiceCommandDUnitTest.java
new file mode 100644
index 0000000..3aa4e05
--- /dev/null
+++ 
b/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/StatusClusterConfigServiceCommandDUnitTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.GfshCommandRule;
+
+public class StatusClusterConfigServiceCommandDUnitTest {
+  private static MemberVM locator1, locator2;
+
+  @ClassRule
+  public static ClusterStartupRule cluster = new ClusterStartupRule();
+
+  @ClassRule
+  public static GfshCommandRule gfsh = new GfshCommandRule();
+
+  @BeforeClass
+  public static void beforeClass() throws Exception {
+    locator1 = cluster.startLocatorVM(0, 0);
+    locator2 = cluster.startLocatorVM(1, locator1.getPort());
+
+    gfsh.connectAndVerify(locator1);
+  }
+
+  @Test
+  public void testStatusClusterConfigService() {
+    gfsh.executeAndAssertThat("status cluster-config-service")
+        .statusIsSuccess()
+        .tableHasRowCount("Name", 2)
+        .tableHasRowWithValues("Name", "Status", "locator-0", "RUNNING")
+        .tableHasRowWithValues("Name", "Status", "locator-1", "RUNNING");
+
+    locator2.stop();
+
+    gfsh.executeAndAssertThat("status cluster-config-service")
+        .statusIsSuccess()
+        .tableHasRowCount("Name", 1)
+        .tableHasRowWithValues("Name", "Status", "locator-0", "RUNNING");
+  }
+}
diff --git 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StatusClusterConfigServiceCommand.java
 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StatusClusterConfigServiceCommand.java
index fa47b6c..6b3cb4d 100644
--- 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StatusClusterConfigServiceCommand.java
+++ 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StatusClusterConfigServiceCommand.java
@@ -24,58 +24,60 @@ import org.apache.geode.cache.execute.ResultCollector;
 import org.apache.geode.distributed.DistributedMember;
 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.cli.GfshCommand;
 import org.apache.geode.management.cli.Result.Status;
 import org.apache.geode.management.internal.cli.CliUtil;
 import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
 import 
org.apache.geode.management.internal.cli.functions.FetchSharedConfigurationStatusFunction;
 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.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.configuration.domain.SharedConfigurationStatus;
 import org.apache.geode.management.internal.security.ResourceOperation;
 import org.apache.geode.security.ResourcePermission.Operation;
 import org.apache.geode.security.ResourcePermission.Resource;
 
-public class StatusClusterConfigServiceCommand extends InternalGfshCommand {
-  private static final FetchSharedConfigurationStatusFunction 
fetchSharedConfigStatusFunction =
-      new FetchSharedConfigurationStatusFunction();
-
+public class StatusClusterConfigServiceCommand extends GfshCommand {
   @SuppressWarnings("unchecked")
   @CliCommand(value = CliStrings.STATUS_SHARED_CONFIG, help = 
CliStrings.STATUS_SHARED_CONFIG_HELP)
   @CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_LOCATOR)
   @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
-  public Result statusSharedConfiguration() {
+  public ResultModel statusSharedConfiguration() {
     final InternalCache cache = (InternalCache) getCache();
     final Set<DistributedMember> locators = new HashSet<>(
         
cache.getDistributionManager().getAllHostedLocatorsWithSharedConfiguration().keySet());
+
     if (locators.isEmpty()) {
-      return 
ResultBuilder.createInfoResult(CliStrings.NO_LOCATORS_WITH_SHARED_CONFIG);
-    } else {
-      return ResultBuilder.buildResult(getSharedConfigurationStatus(locators));
+      return ResultModel.createInfo(CliStrings.NO_LOCATORS_WITH_SHARED_CONFIG);
+    }
+
+    ResultModel resultModel = new ResultModel();
+    TabularResultModel tabularResultModel =
+        resultModel.addTable("Status of shared configuration on locators");
+    if (!populateSharedConfigurationStatus(locators, tabularResultModel)) {
+      resultModel.setStatus(Status.ERROR);
     }
+
+    return resultModel;
   }
 
-  private TabularResultData 
getSharedConfigurationStatus(Set<DistributedMember> locators) {
+  private boolean populateSharedConfigurationStatus(Set<DistributedMember> 
locators,
+      TabularResultModel tabularResultModel) {
     boolean isSharedConfigRunning = false;
     ResultCollector<?, ?> rc =
-        CliUtil.executeFunction(fetchSharedConfigStatusFunction, null, 
locators);
+        CliUtil.executeFunction(new FetchSharedConfigurationStatusFunction(), 
null, locators);
     List<CliFunctionResult> results = (List<CliFunctionResult>) rc.getResult();
-    TabularResultData table = ResultBuilder.createTabularResultData();
-    table.setHeader("Status of shared configuration on locators");
 
     for (CliFunctionResult result : results) {
-      table.accumulate(CliStrings.STATUS_SHARED_CONFIG_NAME_HEADER, 
result.getMemberIdOrName());
-      String status = (String) result.getSerializables()[0];
-      table.accumulate(CliStrings.STATUS_SHARED_CONFIG_STATUS, status);
+      
tabularResultModel.accumulate(CliStrings.STATUS_SHARED_CONFIG_NAME_HEADER,
+          result.getMemberIdOrName());
+      String status = (String) result.getResultObject();
+      tabularResultModel.accumulate(CliStrings.STATUS_SHARED_CONFIG_STATUS, 
status);
       if (SharedConfigurationStatus.RUNNING.name().equals(status)) {
         isSharedConfigRunning = true;
       }
     }
 
-    if (!isSharedConfigRunning) {
-      table.setStatus(Status.ERROR);
-    }
-    return table;
+    return isSharedConfigRunning;
   }
 }
diff --git 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/FetchSharedConfigurationStatusFunction.java
 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/FetchSharedConfigurationStatusFunction.java
index 5a235a2..293b5ab 100644
--- 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/FetchSharedConfigurationStatusFunction.java
+++ 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/FetchSharedConfigurationStatusFunction.java
@@ -39,7 +39,7 @@ public class FetchSharedConfigurationStatusFunction 
implements InternalFunction
       memberId = member.getId();
     }
 
-    CliFunctionResult result = new CliFunctionResult(memberId, new String[] 
{status.name()});
+    CliFunctionResult result = new CliFunctionResult(memberId, status.name(), 
null);
     context.getResultSender().lastResult(result);
   }
 

Reply via email to