Skip to content

Commit

Permalink
Simplify getReplacementName
Browse files Browse the repository at this point in the history
  • Loading branch information
dakrone committed Oct 4, 2021
1 parent 238112a commit 2402803
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;

import java.util.Optional;

public class NodeReplacementAllocationDecider extends AllocationDecider {

public static final String NAME = "node_replacement";
Expand Down Expand Up @@ -153,14 +155,12 @@ private static boolean isReplacementTargetName(Metadata metadata, String nodeNam
.anyMatch(shutdown -> shutdown.getTargetNodeName().equals(nodeName));
}

private static String getReplacementName(Metadata metadata, String nodeBeingReplaced) {
if (nodeBeingReplaced == null || replacementOngoing(metadata) == false) {
private static String getReplacementName(Metadata metadata, String nodeIdBeingReplaced) {
if (nodeIdBeingReplaced == null || replacementOngoing(metadata) == false) {
return null;
}
return metadata.nodeShutdowns().values().stream()
return Optional.ofNullable(metadata.nodeShutdowns().get(nodeIdBeingReplaced))
.filter(shutdown -> shutdown.getType().equals(SingleNodeShutdownMetadata.Type.REPLACE))
.filter(shutdown -> shutdown.getNodeId().equals(nodeBeingReplaced))
.findFirst()
.map(SingleNodeShutdownMetadata::getTargetNodeName)
.orElse(null);
}
Expand Down

0 comments on commit 2402803

Please sign in to comment.