[ 
https://issues.apache.org/jira/browse/GEODE-7954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17096884#comment-17096884
 ] 

ASF GitHub Bot commented on GEODE-7954:
---------------------------------------

DonalEvans commented on a change in pull request #5004:
URL: https://github.com/apache/geode/pull/5004#discussion_r418223262



##########
File path: 
geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/RedundancyCommandUtils.java
##########
@@ -0,0 +1,269 @@
+/*
+ * 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 static 
org.apache.geode.internal.cache.control.RestoreRedundancyResultsImpl.NO_REDUNDANT_COPIES_FOR_REGIONS;
+import static 
org.apache.geode.internal.cache.control.RestoreRedundancyResultsImpl.PRIMARY_TRANSFERS_COMPLETED;
+import static 
org.apache.geode.internal.cache.control.RestoreRedundancyResultsImpl.PRIMARY_TRANSFER_TIME;
+import static 
org.apache.geode.internal.cache.control.RestoreRedundancyResultsImpl.REDUNDANCY_NOT_SATISFIED_FOR_REGIONS;
+import static 
org.apache.geode.internal.cache.control.RestoreRedundancyResultsImpl.REDUNDANCY_SATISFIED_FOR_REGIONS;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import org.apache.geode.cache.control.RegionRedundancyStatus;
+import org.apache.geode.cache.control.RestoreRedundancyResults;
+import org.apache.geode.distributed.DistributedMember;
+import 
org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.control.RestoreRedundancyResultsImpl;
+import org.apache.geode.internal.serialization.Version;
+import org.apache.geode.management.ManagementService;
+import org.apache.geode.management.cli.Result;
+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.functions.CliFunctionResult;
+import 
org.apache.geode.management.internal.operation.RebalanceOperationPerformer;
+
+public class RedundancyCommandUtils {
+  public static final String NO_MEMBERS_WITH_VERSION_FOR_REGION =
+      "No members with a version greater than or equal to %s were found for 
region %s";
+  public static final String NO_MEMBERS_SECTION = "no-members";
+  public static final String NO_MEMBERS_HEADER =
+      "No partitioned regions were found.";
+  public static final String NO_MEMBERS_FOR_REGION_SECTION = 
"no-members-for-region";
+  public static final String NO_MEMBERS_FOR_REGION_HEADER =
+      "No members hosting the following regions were found: ";
+  public static final String ERROR_SECTION = "errors";
+  public static final String ERROR_SECTION_HEADER =
+      "The following errors or exceptions were encountered: ";
+  public static final String SUMMARY_SECTION = "summary-section";
+  public static final String ZERO_REDUNDANT_COPIES =
+      "Number of regions with zero redundant copies = ";
+  public static final String PARTIALLY_SATISFIED_REDUNDANCY =
+      "Number of regions with partially satisfied redundancy = ";
+  public static final String FULLY_SATISFIED_REDUNDANCY =
+      "Number of regions with fully satisfied redundancy = ";
+  public static final String ZERO_REDUNDANCY_SECTION = "zero-redundancy";
+  public static final String UNDER_REDUNDANCY_SECTION = "under-redundancy";
+  public static final String SATISFIED_REDUNDANCY_SECTION = 
"satisfied-redundancy";
+  public static final String PRIMARIES_INFO_SECTION = "primaries-info";
+  public static final String EXCEPTION_MEMBER_MESSAGE = "Exception occurred on 
member %s: %s";
+  public static final Version REDUNDANCY_COMMAND_ADDED_VERSION = 
Version.GEODE_1_13_0;
+  public static final String INDENT = "  ";
+
+  void populateLists(List<RebalanceOperationPerformer.MemberPRInfo> 
membersForEachRegion,
+      List<String> noMemberRegions, String[] includeRegions, String[] 
excludeRegions,
+      InternalCache cache) {
+    // Include all regions
+    if (includeRegions == null) {
+      // Exclude these regions
+      List<String> excludedRegionList =
+          excludeRegions != null ? Arrays.asList(excludeRegions) : new 
ArrayList<>();
+
+      List<RebalanceOperationPerformer.MemberPRInfo> memberRegionList =
+          getMembersForEachRegion(excludedRegionList, cache);
+      membersForEachRegion.addAll(memberRegionList);
+    } else {
+      for (String regionName : includeRegions) {
+        DistributedMember memberForRegion = getOneMemberForRegion(regionName, 
cache);
+
+        // If we did not find a member for this region name, add it to the 
list of regions with no
+        // members
+        if (memberForRegion == null) {
+          noMemberRegions.add(regionName);
+        } else {
+          RebalanceOperationPerformer.MemberPRInfo memberPRInfo =
+              new RebalanceOperationPerformer.MemberPRInfo();
+          memberPRInfo.region = regionName;
+          memberPRInfo.dsMemberList.add(memberForRegion);
+          membersForEachRegion.add(memberPRInfo);
+        }
+      }
+    }
+  }
+
+  // Extracted for testing
+  List<RebalanceOperationPerformer.MemberPRInfo> getMembersForEachRegion(
+      List<String> excludedRegionList, InternalCache cache) {
+    return RebalanceOperationPerformer.getMemberRegionList(
+        ManagementService.getManagementService(cache), cache, 
excludedRegionList);
+  }
+
+  // Extracted for testing
+  DistributedMember getOneMemberForRegion(String regionName, InternalCache 
cache) {
+    String regionNameWithSeparator = regionName;
+    // The getAssociatedMembers method requires region names start with '/'
+    if (!regionName.startsWith("/")) {
+      regionNameWithSeparator = "/" + regionName;

Review comment:
       Good call




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


> Create restore redundancy and status redundancy gfsh commands
> -------------------------------------------------------------
>
>                 Key: GEODE-7954
>                 URL: https://issues.apache.org/jira/browse/GEODE-7954
>             Project: Geode
>          Issue Type: New Feature
>          Components: gfsh
>            Reporter: Donal Evans
>            Assignee: Donal Evans
>            Priority: Major
>
> Add two gfsh commands to allow redundancy to be restored and to check the 
> current redundancy status:
> {{restore redundancy [--include-region=value(,value)*] 
> [--exclude-region=value(,value)*] [--reassign-primaries(=value)]}}
> {{status redundancy [--include-region=value(,value)*] 
> [--exclude-region=value(,value)*]}}
> The first command will execute a function on members hosting the specified 
> partitioned regions and trigger the restore redundancy operation for those 
> regions, then report the final redundancy status of those regions.
> The command will return success status if:
>  * Redundancy is fully satisfied for all regions that were included, either 
> explicitly or implicitly.
>  * No partitioned regions were found and none were explicitly included.
> The command will return error status if:
>  * At least one bucket in a region has zero redundant copies, and that region 
> has redundancy configured.
> At least one bucket in a region has fewer than the configured number of 
> redundant copies.
>  * At least one of the explicitly included partitioned regions is not found.
>  * There is a member in the system with a version of Geode older than 1.13.0 
> (assuming that is the version in which this feature is implemented).
>  * The restore redundancy function encounters an exception.
> The second command will determine the current redundancy status for the 
> specified regions and report it to the user.
> Both commands will take optional {{\-\-include-region}} and 
> {{\-\-exclude-region}} arguments, similar to the existing rebalance command. 
> If neither argument is specified, all regions will be included. Included 
> regions will take precedence over excluded regions when both are specified. 
> The restore redundancy command will also take an optional 
> {{\-\-reassign-primaries}} argument to determine if primaries should be 
> reassigned or not during the operation. The default behaviour will be to 
> reassign primaries.
> Both commands will output a list of regions with zero redundant copies first 
> (unless they are configured to have zero redundancy), then regions with less 
> than their configured redundancy, then regions with full redundancy. The 
> restore redundancy command will also output information about how many 
> primaries were reassigned and how long that process took, similar to the 
> existing rebalance command.
> As described here: 
> [https://cwiki.apache.org/confluence/display/GEODE/Redundancy+Gfsh+Commands]



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to