From 171435cb6640399c20614c5f1f1975470573ea42 Mon Sep 17 00:00:00 2001 From: Himanshu Kandwal Date: Thu, 12 Oct 2023 11:29:39 -0700 Subject: [PATCH] [apache/helix] -- Updated code to be build compatible with JDK-8. (#2650) We will release codebase to be build with JDK-8. We will continue to release the Open source Helix on Java 11 and this PR is for backward compatibility. --- .../controller/rebalancer/DelayedAutoRebalancer.java | 3 ++- .../controller/rebalancer/util/DelayedRebalanceUtil.java | 2 +- .../controller/rebalancer/waged/WagedRebalancer.java | 3 ++- .../waged/constraints/ConstraintBasedAlgorithm.java | 2 +- .../rebalancer/waged/model/ClusterModelProvider.java | 2 +- .../controller/rebalancer/waged/TestWagedRebalancer.java | 9 +++++---- .../stages/TestCurrentStateComputationStage.java | 6 ++++-- 7 files changed, 16 insertions(+), 11 deletions(-) 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 ff5824722d7..9cd0f71cd7f 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 f42176a0a48..84dd0f4eca2 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 e717aa99621..ad3c7b20da9 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 d7dffaa4db4..5dbeb5c38a6 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 dfc648aa7cf..dffaec3e047 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 fff24828235..608a4d3afe4 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 f66638ec61b..0072b3917aa 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);