[jira] [Commented] (GEODE-7954) Create restore redundancy and status redundancy gfsh commands
[ https://issues.apache.org/jira/browse/GEODE-7954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17097531#comment-17097531 ] ASF subversion and git services commented on GEODE-7954: Commit af73331714d1622e9897690a18be3224965a57de in geode's branch refs/heads/develop from Donal Evans [ https://gitbox.apache.org/repos/asf?p=geode.git;h=af73331 ] GEODE-7954: restore redundancy and status redundancy gfsh commands - Add redundancyStatus method to RestoreRedundancyOperation interface - Add RestoreRedundancyCommand - Add StatusRedundancyCommand - Add RedundancyCommandFunction for use by the new commands - Create RedundancyCommandUtils to hold shared code used by both commands - Unit and DUnit tests for all the above Authored-by: Donal Evans > 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)
[jira] [Commented] (GEODE-7954) Create restore redundancy and status redundancy gfsh commands
[ https://issues.apache.org/jira/browse/GEODE-7954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17097532#comment-17097532 ] ASF subversion and git services commented on GEODE-7954: Commit 84387cefa3baa4a3ef5c9274fe43489bc7aa9ac3 in geode's branch refs/heads/develop from Donal Evans [ https://gitbox.apache.org/repos/asf?p=geode.git;h=84387ce ] GEODE-7954: restore redundancy and status redundancy gfsh commands (#5004) * GEODE-7954: restore redundancy and status redundancy gfsh commands - Add redundancyStatus method to RestoreRedundancyOperation interface - Add RestoreRedundancyCommand - Add StatusRedundancyCommand - Add RedundancyCommandFunction for use by the new commands - Create RedundancyCommandUtils to hold shared code used by both commands - Unit and DUnit tests for all the above Authored-by: Donal Evans * Addressing review comments - Have the gfsh commands extend GfshCommand instead of SingleGfshCommand - Remove unnecessary try/catch from RedundancyCommandFunction Authored-by: Donal Evans * Fix LGTM alerts Authored-by: Donal Evans * Applying review feedback - Refactored tests to reduce code duplication - Refactored to condense duplicated Restore and Status command code into one class - Refactored to condense unit tests for the above classes into one class Authored-by: Donal Evans > 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)
[jira] [Commented] (GEODE-7954) Create restore redundancy and status redundancy gfsh commands
[ https://issues.apache.org/jira/browse/GEODE-7954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17097533#comment-17097533 ] ASF subversion and git services commented on GEODE-7954: Commit 84387cefa3baa4a3ef5c9274fe43489bc7aa9ac3 in geode's branch refs/heads/develop from Donal Evans [ https://gitbox.apache.org/repos/asf?p=geode.git;h=84387ce ] GEODE-7954: restore redundancy and status redundancy gfsh commands (#5004) * GEODE-7954: restore redundancy and status redundancy gfsh commands - Add redundancyStatus method to RestoreRedundancyOperation interface - Add RestoreRedundancyCommand - Add StatusRedundancyCommand - Add RedundancyCommandFunction for use by the new commands - Create RedundancyCommandUtils to hold shared code used by both commands - Unit and DUnit tests for all the above Authored-by: Donal Evans * Addressing review comments - Have the gfsh commands extend GfshCommand instead of SingleGfshCommand - Remove unnecessary try/catch from RedundancyCommandFunction Authored-by: Donal Evans * Fix LGTM alerts Authored-by: Donal Evans * Applying review feedback - Refactored tests to reduce code duplication - Refactored to condense duplicated Restore and Status command code into one class - Refactored to condense unit tests for the above classes into one class Authored-by: Donal Evans > 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)
[jira] [Commented] (GEODE-7954) Create restore redundancy and status redundancy gfsh commands
[ https://issues.apache.org/jira/browse/GEODE-7954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=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 membersForEachRegion, + List noMemberRegions, String[] includeRegions, String[] excludeRegions, + InternalCache cache) { +// Include all regions +if (includeRegions == null) { + // Exclude these regions + List
[jira] [Commented] (GEODE-7954) Create restore redundancy and status redundancy gfsh commands
[ https://issues.apache.org/jira/browse/GEODE-7954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17096885#comment-17096885 ] 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_r418172673 ## File path: geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/RestoreRedundancyCommand.java ## @@ -0,0 +1,128 @@ +/* + * 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.management.internal.cli.commands.RedundancyCommandUtils.REDUNDANCY_COMMAND_ADDED_VERSION; +import static org.apache.geode.management.internal.functions.CliFunctionResult.StatusState.ERROR; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; + +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.GfshCommand; +import org.apache.geode.management.internal.cli.functions.RedundancyCommandFunction; +import org.apache.geode.management.internal.cli.result.model.ResultModel; +import org.apache.geode.management.internal.functions.CliFunctionResult; +import org.apache.geode.management.internal.i18n.CliStrings; +import org.apache.geode.management.internal.operation.RebalanceOperationPerformer; +import org.apache.geode.management.internal.security.ResourceOperation; +import org.apache.geode.security.ResourcePermission; + +public class RestoreRedundancyCommand extends GfshCommand { + static final String COMMAND_NAME = "restore redundancy"; + private static final String COMMAND_HELP = + "Restore redundancy and optionally reassign primary bucket hosting for partitioned regions in connected members. The default is for all regions to have redundancy restored and for primary buckets to be reassigned for better load balance."; + static final String INCLUDE_REGION = "include-region"; Review comment: The existing `rebalance` command uses `--include-region` and `--exclude-region`, so that naming was kept here for consistency, and also in the `StatusRedundancyCommand` class. 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: us...@infra.apache.org > 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
[jira] [Commented] (GEODE-7954) Create restore redundancy and status redundancy gfsh commands
[ https://issues.apache.org/jira/browse/GEODE-7954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17096883#comment-17096883 ] 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_r418222622 ## File path: geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/StatusRedundancyCommand.java ## @@ -0,0 +1,121 @@ +/* + * 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.management.internal.cli.commands.RedundancyCommandUtils.REDUNDANCY_COMMAND_ADDED_VERSION; +import static org.apache.geode.management.internal.functions.CliFunctionResult.StatusState.ERROR; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; + +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.GfshCommand; +import org.apache.geode.management.internal.cli.functions.RedundancyCommandFunction; +import org.apache.geode.management.internal.cli.result.model.ResultModel; +import org.apache.geode.management.internal.functions.CliFunctionResult; +import org.apache.geode.management.internal.i18n.CliStrings; +import org.apache.geode.management.internal.operation.RebalanceOperationPerformer; +import org.apache.geode.management.internal.security.ResourceOperation; +import org.apache.geode.security.ResourcePermission; + +public class StatusRedundancyCommand extends GfshCommand { + static final String COMMAND_NAME = "status redundancy"; + private static final String COMMAND_HELP = + "Report the redundancy status for partitioned regions in connected members. The default is to report status for all regions."; + static final String INCLUDE_REGION = "include-region"; + private static final String INCLUDE_REGION_HELP = + "Partitioned regions to be included when reporting redundancy status. Includes take precedence over excludes."; + static final String EXCLUDE_REGION = "exclude-region"; + private static final String EXCLUDE_REGION_HELP = + "Partitioned regions to be excluded when reporting redundancy status."; + + @CliCommand(value = COMMAND_NAME, help = COMMAND_HELP) + @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_DATA, CliStrings.TOPIC_GEODE_REGION}) + @ResourceOperation(resource = ResourcePermission.Resource.DATA, + operation = ResourcePermission.Operation.READ) + public ResultModel execute( + @CliOption(key = INCLUDE_REGION, help = INCLUDE_REGION_HELP) String[] includeRegions, + @CliOption(key = EXCLUDE_REGION, help = EXCLUDE_REGION_HELP) String[] excludeRegions) { +RedundancyCommandUtils utils = getUtils(); + +List membersForEachRegion = new ArrayList<>(); +List includedRegionsWithNoMembers = new ArrayList<>(); + +utils.populateLists(membersForEachRegion, includedRegionsWithNoMembers, includeRegions, +excludeRegions, (InternalCache) getCache()); + +for (RebalanceOperationPerformer.MemberPRInfo prInfo : membersForEachRegion) { + // Filter out any members using older versions of Geode + List viableMembers = + utils.filterViableMembersForVersion(prInfo, REDUNDANCY_COMMAND_ADDED_VERSION); + + if (viableMembers.size() == 0) { +// If no viable members were found, return with error status +return utils.getNoViableMembersResult(REDUNDANCY_COMMAND_ADDED_VERSION, prInfo.region); + } else { +// Update the MemberPRInfo with the viable members +prInfo.dsMemberList = viableMembers; + } +} + +List functionResults = +executeFunctionOnMembers(includeRegions, excludeRegions, membersForEachRegion); + +return utils.buildResultModelFromFunctionResults(functionResults, includedRegionsWithNoMembers, +true); + } + + List executeFunctionOnMembers(String[]
[jira] [Commented] (GEODE-7954) Create restore redundancy and status redundancy gfsh commands
[ https://issues.apache.org/jira/browse/GEODE-7954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17096802#comment-17096802 ] 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_r418172673 ## File path: geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/RestoreRedundancyCommand.java ## @@ -0,0 +1,128 @@ +/* + * 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.management.internal.cli.commands.RedundancyCommandUtils.REDUNDANCY_COMMAND_ADDED_VERSION; +import static org.apache.geode.management.internal.functions.CliFunctionResult.StatusState.ERROR; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; + +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.GfshCommand; +import org.apache.geode.management.internal.cli.functions.RedundancyCommandFunction; +import org.apache.geode.management.internal.cli.result.model.ResultModel; +import org.apache.geode.management.internal.functions.CliFunctionResult; +import org.apache.geode.management.internal.i18n.CliStrings; +import org.apache.geode.management.internal.operation.RebalanceOperationPerformer; +import org.apache.geode.management.internal.security.ResourceOperation; +import org.apache.geode.security.ResourcePermission; + +public class RestoreRedundancyCommand extends GfshCommand { + static final String COMMAND_NAME = "restore redundancy"; + private static final String COMMAND_HELP = + "Restore redundancy and optionally reassign primary bucket hosting for partitioned regions in connected members. The default is for all regions to have redundancy restored and for primary buckets to be reassigned for better load balance."; + static final String INCLUDE_REGION = "include-region"; Review comment: The existing `rebalance` command uses `--include-region` and `--exclude-region`, so that naming was kept here for consistency. 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: us...@infra.apache.org > 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
[jira] [Commented] (GEODE-7954) Create restore redundancy and status redundancy gfsh commands
[ https://issues.apache.org/jira/browse/GEODE-7954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17095430#comment-17095430 ] ASF GitHub Bot commented on GEODE-7954: --- jujoramos commented on a change in pull request #5004: URL: https://github.com/apache/geode/pull/5004#discussion_r417251767 ## File path: geode-gfsh/src/test/java/org/apache/geode/management/internal/cli/functions/RedundancyCommandFunctionTest.java ## @@ -0,0 +1,137 @@ +/* + * 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.functions; + +import static org.apache.geode.management.internal.functions.CliFunctionResult.StatusState.ERROR; +import static org.apache.geode.management.internal.functions.CliFunctionResult.StatusState.OK; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; + +import org.junit.Before; +import org.junit.Test; + +import org.apache.geode.cache.Cache; +import org.apache.geode.cache.control.RestoreRedundancyOperation; +import org.apache.geode.cache.control.RestoreRedundancyResults; +import org.apache.geode.cache.execute.FunctionContext; +import org.apache.geode.management.internal.functions.CliFunctionResult; + +public class RedundancyCommandFunctionTest { + + @SuppressWarnings("unchecked") + private FunctionContext mockContext = mock(FunctionContext.class); + private Cache mockCache = mock(Cache.class, RETURNS_DEEP_STUBS); + private RestoreRedundancyOperation mockOperation = + mock(RestoreRedundancyOperation.class, RETURNS_DEEP_STUBS); + private RestoreRedundancyResults mockResults = mock(RestoreRedundancyResults.class); + private String message = "expected message"; Review comment: These attributes can all be made `final`. ## File path: geode-gfsh/src/test/java/org/apache/geode/management/internal/cli/commands/StatusRedundancyCommandTest.java ## @@ -0,0 +1,253 @@ +/* + * 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.management.cli.Result.Status.ERROR; +import static org.apache.geode.management.cli.Result.Status.OK; +import static org.apache.geode.management.internal.cli.commands.RedundancyCommandUtils.REDUNDANCY_COMMAND_ADDED_VERSION; +import static org.hamcrest.CoreMatchers.everyItem; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; + +import
[jira] [Commented] (GEODE-7954) Create restore redundancy and status redundancy gfsh commands
[ https://issues.apache.org/jira/browse/GEODE-7954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17094059#comment-17094059 ] ASF GitHub Bot commented on GEODE-7954: --- lgtm-com[bot] commented on pull request #5004: URL: https://github.com/apache/geode/pull/5004#issuecomment-620315436 This pull request **introduces 2 alerts** when merging 4426e0621a2f3a3778fe0ec5432f13dd89614ac1 into 6d358846566fd74ee85ecab311d2eeb004c44897 - [view on LGTM.com](https://lgtm.com/projects/g/apache/geode/rev/pr-22aebb54a0f8dd3dc909416cc5650c3281d317ba) **new alerts:** * 2 for Cast from abstract to concrete collection 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: us...@infra.apache.org > 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)
[jira] [Commented] (GEODE-7954) Create restore redundancy and status redundancy gfsh commands
[ https://issues.apache.org/jira/browse/GEODE-7954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17093916#comment-17093916 ] 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_r416133323 ## File path: geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/functions/RedundancyCommandFunction.java ## @@ -0,0 +1,78 @@ +/* + * 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.functions; + +import static org.apache.geode.cache.control.RestoreRedundancyResults.Status.ERROR; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import org.apache.geode.cache.control.RestoreRedundancyOperation; +import org.apache.geode.cache.control.RestoreRedundancyResults; +import org.apache.geode.cache.execute.FunctionContext; +import org.apache.geode.management.cli.CliFunction; +import org.apache.geode.management.internal.functions.CliFunctionResult; + +public class RedundancyCommandFunction extends CliFunction { + private static final long serialVersionUID = 5633636343813884996L; + + @Override + public CliFunctionResult executeFunction(FunctionContext context) { +Object[] arguments = context.getArguments(); +String[] includeRegions = (String[]) arguments[0]; +Set includeRegionsSet = null; +if (includeRegions != null) { + includeRegionsSet = new HashSet<>(Arrays.asList(includeRegions)); +} + +String[] excludeRegions = (String[]) arguments[1]; +Set excludeRegionsSet = null; +if (excludeRegions != null) { + excludeRegionsSet = new HashSet<>(Arrays.asList(excludeRegions)); +} + +boolean shouldReassignPrimaries = (boolean) arguments[2]; + +boolean isStatusCommand = false; +if (arguments.length > 3) { + isStatusCommand = (boolean) arguments[3]; +} + +RestoreRedundancyResults results; +try { + RestoreRedundancyOperation redundancyOperation = + context.getCache().getResourceManager().createRestoreRedundancyOperation(); + redundancyOperation.includeRegions(includeRegionsSet); + redundancyOperation.excludeRegions(excludeRegionsSet); + if (isStatusCommand) { +results = redundancyOperation.redundancyStatus(); + } else { +redundancyOperation.shouldReassignPrimaries(shouldReassignPrimaries); +results = redundancyOperation.start().get(); + } +} catch (Exception ex) { Review comment: Will do 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: us...@infra.apache.org > 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
[jira] [Commented] (GEODE-7954) Create restore redundancy and status redundancy gfsh commands
[ https://issues.apache.org/jira/browse/GEODE-7954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17093914#comment-17093914 ] 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_r416133022 ## File path: geode-gfsh/src/test/java/org/apache/geode/management/internal/cli/commands/RestoreRedundancyCommandTest.java ## @@ -0,0 +1,256 @@ +/* + * 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.management.cli.Result.Status.ERROR; +import static org.apache.geode.management.cli.Result.Status.OK; +import static org.apache.geode.management.internal.cli.commands.RedundancyCommandUtils.REDUNDANCY_COMMAND_ADDED_VERSION; +import static org.hamcrest.CoreMatchers.everyItem; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; + +import org.apache.geode.cache.Cache; +import org.apache.geode.distributed.DistributedMember; +import org.apache.geode.internal.cache.InternalCache; +import org.apache.geode.management.internal.functions.CliFunctionResult; +import org.apache.geode.management.internal.operation.RebalanceOperationPerformer; + +public class RestoreRedundancyCommandTest { Review comment: The results should be being examined in the DUnit tests for these commands, so the unit tests are just intended to confirm that the methods in the class are providing the expected behaviour. 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: us...@infra.apache.org > 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). >
[jira] [Commented] (GEODE-7954) Create restore redundancy and status redundancy gfsh commands
[ https://issues.apache.org/jira/browse/GEODE-7954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17093915#comment-17093915 ] 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_r416133248 ## File path: geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/RestoreRedundancyCommand.java ## @@ -0,0 +1,128 @@ +/* + * 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.management.internal.cli.commands.RedundancyCommandUtils.REDUNDANCY_COMMAND_ADDED_VERSION; +import static org.apache.geode.management.internal.functions.CliFunctionResult.StatusState.ERROR; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; + +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.SingleGfshCommand; +import org.apache.geode.management.internal.cli.functions.RedundancyCommandFunction; +import org.apache.geode.management.internal.cli.result.model.ResultModel; +import org.apache.geode.management.internal.functions.CliFunctionResult; +import org.apache.geode.management.internal.i18n.CliStrings; +import org.apache.geode.management.internal.operation.RebalanceOperationPerformer; +import org.apache.geode.management.internal.security.ResourceOperation; +import org.apache.geode.security.ResourcePermission; + +public class RestoreRedundancyCommand extends SingleGfshCommand { Review comment: Thanks for catching this. 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: us...@infra.apache.org > 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
[jira] [Commented] (GEODE-7954) Create restore redundancy and status redundancy gfsh commands
[ https://issues.apache.org/jira/browse/GEODE-7954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17093887#comment-17093887 ] ASF GitHub Bot commented on GEODE-7954: --- jinmeiliao commented on a change in pull request #5004: URL: https://github.com/apache/geode/pull/5004#discussion_r416090678 ## File path: geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/functions/RedundancyCommandFunction.java ## @@ -0,0 +1,78 @@ +/* + * 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.functions; + +import static org.apache.geode.cache.control.RestoreRedundancyResults.Status.ERROR; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import org.apache.geode.cache.control.RestoreRedundancyOperation; +import org.apache.geode.cache.control.RestoreRedundancyResults; +import org.apache.geode.cache.execute.FunctionContext; +import org.apache.geode.management.cli.CliFunction; +import org.apache.geode.management.internal.functions.CliFunctionResult; + +public class RedundancyCommandFunction extends CliFunction { + private static final long serialVersionUID = 5633636343813884996L; + + @Override + public CliFunctionResult executeFunction(FunctionContext context) { +Object[] arguments = context.getArguments(); +String[] includeRegions = (String[]) arguments[0]; +Set includeRegionsSet = null; +if (includeRegions != null) { + includeRegionsSet = new HashSet<>(Arrays.asList(includeRegions)); +} + +String[] excludeRegions = (String[]) arguments[1]; +Set excludeRegionsSet = null; +if (excludeRegions != null) { + excludeRegionsSet = new HashSet<>(Arrays.asList(excludeRegions)); +} + +boolean shouldReassignPrimaries = (boolean) arguments[2]; + +boolean isStatusCommand = false; +if (arguments.length > 3) { + isStatusCommand = (boolean) arguments[3]; +} + +RestoreRedundancyResults results; +try { + RestoreRedundancyOperation redundancyOperation = + context.getCache().getResourceManager().createRestoreRedundancyOperation(); + redundancyOperation.includeRegions(includeRegionsSet); + redundancyOperation.excludeRegions(excludeRegionsSet); + if (isStatusCommand) { +results = redundancyOperation.redundancyStatus(); + } else { +redundancyOperation.shouldReassignPrimaries(shouldReassignPrimaries); +results = redundancyOperation.start().get(); + } +} catch (Exception ex) { Review comment: consider get rid of the try/catch block, the CliFunction already handles any exception thrown by the child in a uniform way. ## File path: geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/StatusRedundancyCommand.java ## @@ -0,0 +1,121 @@ +/* + * 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.management.internal.cli.commands.RedundancyCommandUtils.REDUNDANCY_COMMAND_ADDED_VERSION; +import static org.apache.geode.management.internal.functions.CliFunctionResult.StatusState.ERROR; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; + +import
[jira] [Commented] (GEODE-7954) Create restore redundancy and status redundancy gfsh commands
[ https://issues.apache.org/jira/browse/GEODE-7954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17093800#comment-17093800 ] ASF GitHub Bot commented on GEODE-7954: --- DonalEvans opened a new pull request #5004: URL: https://github.com/apache/geode/pull/5004 - Add redundancyStatus method to RestoreRedundancyOperation interface - Add RestoreRedundancyCommand - Add StatusRedundancyCommand - Add RedundancyCommandFunction for use by the new commands - Create RedundancyCommandUtils to hold shared code used by both commands - Unit and DUnit tests for all the above Authored-by: Donal Evans Thank you for submitting a contribution to Apache Geode. In order to streamline the review of the contribution we ask you to ensure the following steps have been taken: ### For all changes: - [x] Is there a JIRA ticket associated with this PR? Is it referenced in the commit message? - [x] Has your PR been rebased against the latest commit within the target branch (typically `develop`)? - [x] Is your initial contribution a single, squashed commit? - [x] Does `gradlew build` run cleanly? - [x] Have you written or updated unit tests to verify your changes? - [N/A] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? ### Note: Please ensure that once the PR is submitted, check Concourse for build issues and submit an update to your PR as soon as possible. If you need help, please send an email to d...@geode.apache.org. 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: us...@infra.apache.org > 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
[jira] [Commented] (GEODE-7954) Create restore redundancy and status redundancy gfsh commands
[ https://issues.apache.org/jira/browse/GEODE-7954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17076697#comment-17076697 ] Donal Evans commented on GEODE-7954: It will be possible for a user to determine if full redundancy has been satisfied by looking at the result of the command. If the command returns success and there is no info section for members with partially satisfied redundancy, then they know that all included regions have fully satisfied redundancy. As a side note, it would have been better timing if this feedback had been provided during the RFC discussion process, since that's where the design details were intended to be hammered out and agreed on. Changes can be made, of course, but there is already consensus on the proposed design at this point. > 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)*] [--dont-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: > * At least one redundant copy exists for every bucket in regions with > redundancy configured 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 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 > {{\-\-dont-reassign-primaries}} argument to determine if primaries should not > be reassigned 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)
[jira] [Commented] (GEODE-7954) Create restore redundancy and status redundancy gfsh commands
[ https://issues.apache.org/jira/browse/GEODE-7954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17076679#comment-17076679 ] Eric Shu commented on GEODE-7954: - User might want to wait until the full redundancy level is satisfied. Is it possible that we could supply this information as well e.g. user can stop members to the extents of the redundancy level for maintenance etc. Have an extra option set so that the command only returns successful when full redundancy level is satisfied. This can allow user to determine which command they should be using. > 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)*] [--dont-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: > * At least one redundant copy exists for every bucket in regions with > redundancy configured 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 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 > {{\-\-dont-reassign-primaries}} argument to determine if primaries should not > be reassigned 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)
[jira] [Commented] (GEODE-7954) Create restore redundancy and status redundancy gfsh commands
[ https://issues.apache.org/jira/browse/GEODE-7954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17076624#comment-17076624 ] Donal Evans commented on GEODE-7954: {quote}Do this mean if redundancy is configured for 2 redundant copies, restore redundancy command would return successfully if there is only one redundant copy in the cluster? {quote} The command will return success status, yes. But the output will also include information about how many regions do not have fully satisfied redundancy (if any), so it will be clear to the user what the state of the system is. The reasoning behind this is that as long as one redundant copy exists, we have redundancy, although we may not have as much redundancy as we would ideally want (if it's below the configured level), and so we have protection from data loss in the event that we lose a member from the system. The difference between fully satisfied redundancy (x out of x configured copies exist for each bucket) and partially satisfied redundancy (at least 1 out of x configured copies exist for each bucket) is much less critical than the difference between partially satisfied redundancy and zero redundant copies existing at all, where if we lose a member, we lose all data on that member. > 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)*] [--dont-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: > * At least one redundant copy exists for every bucket in regions with > redundancy configured 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 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 > {{\-\-dont-reassign-primaries}} argument to determine if primaries should not > be reassigned 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)
[jira] [Commented] (GEODE-7954) Create restore redundancy and status redundancy gfsh commands
[ https://issues.apache.org/jira/browse/GEODE-7954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17076510#comment-17076510 ] Eric Shu commented on GEODE-7954: - Do we know why only one copy is needed to satisfy redundancy? "At least one redundant copy exists for every bucket in regions" Do this mean if redundancy is configured for 2 redundant copies, restore redundancy command would return successfully if there is only one redundant copy in the cluster? > 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)*] [--dont-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: > * At least one redundant copy exists for every bucket in regions with > redundancy configured 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 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 > {{\-\-dont-reassign-primaries}} argument to determine if primaries should not > be reassigned 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)