[ https://issues.apache.org/jira/browse/GEODE-8272?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17138876#comment-17138876 ]
ASF GitHub Bot commented on GEODE-8272: --------------------------------------- mhansonp commented on a change in pull request #5249: URL: https://github.com/apache/geode/pull/5249#discussion_r441868918 ########## File path: geode-core/src/main/java/org/apache/geode/management/internal/operation/RestoreRedundancyPerformer.java ########## @@ -0,0 +1,179 @@ +/* + * 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.operation; + +import static org.apache.geode.cache.Region.SEPARATOR; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.geode.annotations.Immutable; +import org.apache.geode.cache.Cache; +import org.apache.geode.cache.execute.Function; +import org.apache.geode.cache.execute.ResultCollector; +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.serialization.Version; +import org.apache.geode.management.ManagementService; +import org.apache.geode.management.internal.functions.RestoreRedundancyFunction; +import org.apache.geode.management.internal.util.ManagementUtils; +import org.apache.geode.management.operation.RestoreRedundancyRequest; +import org.apache.geode.management.runtime.RestoreRedundancyResults; + +public class RestoreRedundancyPerformer + implements OperationPerformer<RestoreRedundancyRequest, RestoreRedundancyResults> { + @Immutable + public static final Version ADDED_VERSION = Version.GEODE_1_13_0; + 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 EXCEPTION_MEMBER_MESSAGE = "Exception occurred on member %s: %s"; + + @Override + public RestoreRedundancyResults perform(Cache cache, RestoreRedundancyRequest operation) { + return perform(cache, operation, false); + } + + public RestoreRedundancyResults perform(Cache cache, RestoreRedundancyRequest operation, + boolean checkStatus) { + List<RebalanceOperationPerformer.MemberPRInfo> membersForEachRegion = new ArrayList<>(); + List<String> includedRegionsWithNoMembers = new ArrayList<>(); + + populateLists(membersForEachRegion, includedRegionsWithNoMembers, operation.getIncludeRegions(), + operation.getExcludeRegions(), (InternalCache) cache); + + for (RebalanceOperationPerformer.MemberPRInfo prInfo : membersForEachRegion) { + // Filter out any members using older versions of Geode + List<DistributedMember> viableMembers = filterViableMembers(prInfo); + + if (viableMembers.size() != 0) { + // Update the MemberPRInfo with the viable members + prInfo.dsMemberList = viableMembers; + } else { + RestoreRedundancyResultsImpl results = new RestoreRedundancyResultsImpl(); + results.setStatusMessage(String.format(NO_MEMBERS_WITH_VERSION_FOR_REGION, + ADDED_VERSION.getName(), prInfo.region)); + results.setSuccess(false); + return results; + } + } + + List<RestoreRedundancyResults> functionResults = new ArrayList<>(); + Object[] functionArgs = new Object[] {operation, checkStatus}; + List<DistributedMember> completedMembers = new ArrayList<>(); + for (RebalanceOperationPerformer.MemberPRInfo memberPRInfo : membersForEachRegion) { + // Check to see if an earlier function execution has already targeted a member hosting this + // region. If one has, there is no point sending a function for this region as it has already + // had redundancy restored + if (!Collections.disjoint(completedMembers, memberPRInfo.dsMemberList)) { + continue; + } + // Try the function on the first member for this region + DistributedMember targetMember = memberPRInfo.dsMemberList.get(0); + RestoreRedundancyResults functionResult = executeFunctionAndGetFunctionResult( + new RestoreRedundancyFunction(), functionArgs, targetMember); + if (!functionResult.getSuccess()) { + // Record the error and then give up + RestoreRedundancyResultsImpl results = new RestoreRedundancyResultsImpl(); + results.setSuccess(false); + String errorString = + String.format(EXCEPTION_MEMBER_MESSAGE, targetMember.getName(), + functionResult.getStatusMessage()); + results.setStatusMessage(errorString); + results.setSuccess(false); + return results; + } + functionResults.add(functionResult); + completedMembers.add(targetMember); + } + + RestoreRedundancyResultsImpl finalResult = new RestoreRedundancyResultsImpl(); + finalResult.addIncludedRegionsWithNoMembers(includedRegionsWithNoMembers); + for (RestoreRedundancyResults functionResult : functionResults) { + finalResult.addRegionResults(functionResult); + finalResult.setSuccess(functionResult.getSuccess()); + finalResult.setStatusMessage(functionResult.getStatusMessage()); Review comment: Agreed. Since we no longer getting errors, this can be simplified. ---------------------------------------------------------------- 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 > Refactor GFSH Restore Redundancy Command code to allow for REST API > ------------------------------------------------------------------- > > Key: GEODE-8272 > URL: https://issues.apache.org/jira/browse/GEODE-8272 > Project: Geode > Issue Type: Bug > Components: gfsh > Reporter: Mark Hanson > Assignee: Mark Hanson > Priority: Major > > Refactor GFSH Restore Redundancy Command code to allow for REST API > > The core code path is specific to GFSH right now and needs a few changes to > support the REST API command. -- This message was sent by Atlassian Jira (v8.3.4#803005)