diff --git a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/DelayedAutoRebalancer.java b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/DelayedAutoRebalancer.java index ff5824722d..9cd0f71cd7 100644 --- a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/DelayedAutoRebalancer.java +++ b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/DelayedAutoRebalancer.java @@ -19,6 +19,7 @@ * under the License. */ +import com.google.common.collect.ImmutableSet; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -55,7 +56,7 @@ */ public class DelayedAutoRebalancer extends AbstractRebalancer { private static final Logger LOG = LoggerFactory.getLogger(DelayedAutoRebalancer.class); - public static final Set INSTANCE_OPERATION_TO_EXCLUDE_FROM_ASSIGNMENT = Set.of("EVACUATE", "SWAP_IN"); + public static final Set INSTANCE_OPERATION_TO_EXCLUDE_FROM_ASSIGNMENT = ImmutableSet.of("EVACUATE", "SWAP_IN"); @Override public IdealState computeNewIdealState(String resourceName, diff --git a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/util/DelayedRebalanceUtil.java b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/util/DelayedRebalanceUtil.java index f42176a0a4..84dd0f4eca 100644 --- a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/util/DelayedRebalanceUtil.java +++ b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/util/DelayedRebalanceUtil.java @@ -400,7 +400,7 @@ private static Map> findPartitionsMissingMinActiveReplica( Map currentAssignment) { return currentAssignment.entrySet() .parallelStream() - .map(e -> Map.entry(e.getKey(), findPartitionsMissingMinActiveReplica(clusterData, e.getValue()))) + .map(e -> new HashMap.SimpleEntry<>(e.getKey(), findPartitionsMissingMinActiveReplica(clusterData, e.getValue()))) .filter(e -> !e.getValue().isEmpty()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } diff --git a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/WagedRebalancer.java b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/WagedRebalancer.java index e717aa9962..ad3c7b20da 100644 --- a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/WagedRebalancer.java +++ b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/WagedRebalancer.java @@ -19,6 +19,7 @@ * under the License. */ +import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -80,7 +81,7 @@ public class WagedRebalancer implements StatefulRebalancer FAILURE_TYPES_TO_PROPAGATE = - List.of(HelixRebalanceException.Type.INVALID_REBALANCER_STATUS, HelixRebalanceException.Type.UNKNOWN_FAILURE); + ImmutableList.of(HelixRebalanceException.Type.INVALID_REBALANCER_STATUS, HelixRebalanceException.Type.UNKNOWN_FAILURE); private final HelixManager _manager; private final MappingCalculator _mappingCalculator; diff --git a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/constraints/ConstraintBasedAlgorithm.java b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/constraints/ConstraintBasedAlgorithm.java index d7dffaa4db..5dbeb5c38a 100644 --- a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/constraints/ConstraintBasedAlgorithm.java +++ b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/constraints/ConstraintBasedAlgorithm.java @@ -100,7 +100,7 @@ public OptimalAssignment calculate(ClusterModel clusterModel) throws HelixRebala getNodeWithHighestPoints(replica, nodes, clusterModel.getContext(), busyInstances, optimalAssignment); // stop immediately if any replica cannot find best assignable node - if (maybeBestNode.isEmpty() || optimalAssignment.hasAnyFailure()) { + if (!maybeBestNode.isPresent() || optimalAssignment.hasAnyFailure()) { String errorMessage = String.format( "Unable to find any available candidate node for partition %s; Fail reasons: %s", replica.getPartitionName(), optimalAssignment.getFailures()); diff --git a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/model/ClusterModelProvider.java b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/model/ClusterModelProvider.java index dfc648aa7c..dffaec3e04 100644 --- a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/model/ClusterModelProvider.java +++ b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/model/ClusterModelProvider.java @@ -581,7 +581,7 @@ private static Map> getAllAssignableReplicas( } } } - return Map.entry(resourceName, replicas); + return new HashMap.SimpleEntry<>(resourceName, replicas); }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } diff --git a/helix-core/src/test/java/org/apache/helix/controller/rebalancer/waged/TestWagedRebalancer.java b/helix-core/src/test/java/org/apache/helix/controller/rebalancer/waged/TestWagedRebalancer.java index fff2482823..608a4d3afe 100644 --- a/helix-core/src/test/java/org/apache/helix/controller/rebalancer/waged/TestWagedRebalancer.java +++ b/helix-core/src/test/java/org/apache/helix/controller/rebalancer/waged/TestWagedRebalancer.java @@ -20,6 +20,7 @@ */ import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import java.io.IOException; import java.util.Collections; import java.util.HashMap; @@ -737,7 +738,7 @@ public void testRebalanceOverwrite() throws HelixRebalanceException, IOException instances.add(offlineInstance); when(clusterData.getAllInstances()).thenReturn(instances); when(clusterData.getEnabledInstances()).thenReturn(instances); - when(clusterData.getEnabledLiveInstances()).thenReturn(Set.of(instance0, instance1, instance2)); + when(clusterData.getEnabledLiveInstances()).thenReturn(ImmutableSet.of(instance0, instance1, instance2)); Map instanceOfflineTimeMap = new HashMap<>(); instanceOfflineTimeMap.put(offlineInstance, System.currentTimeMillis() + Integer.MAX_VALUE); when(clusterData.getInstanceOfflineTimeMap()).thenReturn(instanceOfflineTimeMap); @@ -862,10 +863,10 @@ private void validateRebalanceResult(Map resourceMap, public void testResourceWeightProvider() throws IOException { ResourceControllerDataProvider testCache = setupClusterDataCache(); WagedResourceWeightsProvider dataProvider = new WagedResourceWeightsProvider(testCache); - Map weights1 = Map.of("item1", 3, "item2", 6, "item3", 0); + Map weights1 = ImmutableMap.of("item1", 3, "item2", 6, "item3", 0); Assert.assertEquals(dataProvider.getPartitionWeights("Resource1", "Partition1"), weights1); Assert.assertEquals(dataProvider.getPartitionWeights("Resource1", "Partition2"), weights1); - Map weights2 = Map.of("item1", 5, "item2", 10, "item3", 0); + Map weights2 = ImmutableMap.of("item1", 5, "item2", 10, "item3", 0); Assert.assertEquals(dataProvider.getPartitionWeights("Resource2", "Partition2"), weights2); } @@ -898,7 +899,7 @@ public void testInstanceCapacityProvider() throws IOException, HelixRebalanceExc })); WagedInstanceCapacity provider = new WagedInstanceCapacity(clusterData); - Map weights1 = Map.of("item1", 20, "item2", 40, "item3", 30); + Map weights1 = ImmutableMap.of("item1", 20, "item2", 40, "item3", 30); Map capacity = provider.getInstanceAvailableCapacity("testInstanceId"); Assert.assertEquals(provider.getInstanceAvailableCapacity("testInstanceId"), weights1); Assert.assertEquals(provider.getInstanceAvailableCapacity("testInstanceId1"), weights1); diff --git a/helix-core/src/test/java/org/apache/helix/controller/stages/TestCurrentStateComputationStage.java b/helix-core/src/test/java/org/apache/helix/controller/stages/TestCurrentStateComputationStage.java index f66638ec61..0072b3917a 100644 --- a/helix-core/src/test/java/org/apache/helix/controller/stages/TestCurrentStateComputationStage.java +++ b/helix-core/src/test/java/org/apache/helix/controller/stages/TestCurrentStateComputationStage.java @@ -19,6 +19,8 @@ * under the License. */ +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import java.util.HashMap; import java.util.Map; import java.util.List; @@ -50,9 +52,9 @@ public void testEmptyCS() { CurrentStateComputationStage stage = new CurrentStateComputationStage(); runStage(event, new ReadClusterDataStage()); ClusterConfig clsCfg = dataCache.getClusterConfig(); - clsCfg.setInstanceCapacityKeys(List.of("s1", "s2", "s3")); + clsCfg.setInstanceCapacityKeys(ImmutableList.of("s1", "s2", "s3")); dataCache.setClusterConfig(clsCfg); - dataCache.setInstanceConfigMap(Map.of( + dataCache.setInstanceConfigMap(ImmutableMap.of( "a", new InstanceConfig("a") )); runStage(event, stage);