Source:
private BestPossibleStateOutput compute(ClusterEvent event, Map<String, Resource> resourceMap, CurrentStateOutput currentStateOutput) throws JMException { ResourceControllerDataProvider cache = event.getAttribute(AttributeName.ControllerDataProvider.name()); BestPossibleStateOutput output = new BestPossibleStateOutput(); HelixManager helixManager = event.getAttribute(AttributeName.helixmanager.name()); ClusterStatusMonitor clusterStatusMonitor = event.getAttribute(AttributeName.clusterStatusMonitor.name()); boolean isValid = validateOfflineInstancesLimit(cache, event.getAttribute(AttributeName.helixmanager.name())); final List<String> failureResources = new ArrayList<>(); Map<String, Resource> calculatedResourceMap = computeResourceBestPossibleStateWithWagedRebalancer(cache, currentStateOutput, helixManager, resourceMap, output, failureResources); Map<String, Resource> remainingResourceMap = new HashMap<>(resourceMap); remainingResourceMap.keySet().removeAll(calculatedResourceMap.keySet()); Iterator<Resource> itr = remainingResourceMap.values().iterator(); while (itr.hasNext()) { Resource resource = itr.next(); boolean result = false; try { result = computeSingleResourceBestPossibleState(event, cache, currentStateOutput, resource, output); } catch (HelixException ex) { LogUtil.logError(logger, _eventId, String .format("Exception when calculating best possible states for %s", resource.getResourceName()), ex); } if (!result) { failureResources.add(resource.getResourceName()); LogUtil.logWarn(logger, _eventId, String .format("Failed to calculate best possible states for %s", resource.getResourceName())); } } updateRebalanceStatus(!isValid || !failureResources.isEmpty(), failureResources, helixManager, cache, clusterStatusMonitor, String .format("Failed to calculate best possible states for %d resources.", failureResources.size())); return output; }

Target:
private BestPossibleStateOutput compute(ClusterEvent event, Map<String, Resource> resourceMap, CurrentStateOutput currentStateOutput) { ResourceControllerDataProvider cache = event.getAttribute(AttributeName.ControllerDataProvider.name()); BestPossibleStateOutput output = new BestPossibleStateOutput(); HelixManager helixManager = event.getAttribute(AttributeName.helixmanager.name()); ClusterStatusMonitor clusterStatusMonitor = event.getAttribute(AttributeName.clusterStatusMonitor.name()); boolean isValid = validateOfflineInstancesLimit(cache, event.getAttribute(AttributeName.helixmanager.name())); final List<String> failureResources = new ArrayList<>(); Map<String, Resource> calculatedResourceMap = computeResourceBestPossibleStateWithWagedRebalancer(cache, currentStateOutput, helixManager, resourceMap, output, failureResources); Map<String, Resource> remainingResourceMap = new HashMap<>(resourceMap); remainingResourceMap.keySet().removeAll(calculatedResourceMap.keySet()); Iterator<Resource> itr = remainingResourceMap.values().iterator(); while (itr.hasNext()) { Resource resource = itr.next(); boolean result = false; try { result = computeSingleResourceBestPossibleState(event, cache, currentStateOutput, resource, output); } catch (HelixException ex) { LogUtil.logError(logger, _eventId, String .format("Exception when calculating best possible states for %s", resource.getResourceName()), ex); } if (!result) { failureResources.add(resource.getResourceName()); LogUtil.logWarn(logger, _eventId, String .format("Failed to calculate best possible states for %s", resource.getResourceName())); } } updateRebalanceStatus(!isValid || !failureResources.isEmpty(), failureResources, helixManager, cache, clusterStatusMonitor, String .format("Failed to calculate best possible states for %d resources.", failureResources.size())); return output; }