private static void setResourceConfig(String clusterName, String resourceName, ConfigAccessor configAccessor,
      PropertyStoreToDataNodeConfigAdapter propertyStoreToDataNodeConfigAdapter, HelixAdmin helixAdmin,
      ClusterConfigFields clusterConfigFields, boolean setPreferenceList, boolean dryRun) throws IOException {

    ResourceConfig resourceConfig = configAccessor.getResourceConfig(clusterName, resourceName);
    if (resourceConfig == null) {
      ResourceConfig.Builder resourceBuilder = new ResourceConfig.Builder(resourceName);
      resourceConfig = resourceBuilder.build();
    }

    // Get weights for Partitions of the resource from property store
    Map<String, Map<String, Integer>> partitionCapacityMap = new HashMap<>();

    // 1. Get list of instances hosting partitions of this resource
    IdealState idealState = helixAdmin.getResourceIdealState(clusterName, resourceName);
    Set<String> partitions = idealState.getPartitionSet();
    Set<String> instances = new HashSet<>();
    for (String partition : partitions) {
      instances.addAll(idealState.getInstanceSet(partition));
    }

    // 2. Get weights of partitions residing on these instances from property store and update them in resource config
    // if they are different from default values
    for (String instanceName : instances) {
      DataNodeConfig dataNodeConfig =
          getDataNodeConfigFromHelix(clusterName, instanceName, propertyStoreToDataNodeConfigAdapter, null, helixAdmin,
              PROPERTY_STORE);
      // Get Disk configs on the node
      Map<String, DataNodeConfig.DiskConfig> diskConfigs = dataNodeConfig.getDiskConfigs();
      for (DataNodeConfig.DiskConfig diskConfig : diskConfigs.values()) {
        // Get replica configs for each replica on the disk
        for (Map.Entry<String, DataNodeConfig.ReplicaConfig> replicaConfigEntry : diskConfig.getReplicaConfigs()
            .entrySet()) {
          String partitionName = replicaConfigEntry.getKey();
          int capacityInGB =
              Math.toIntExact(replicaConfigEntry.getValue().getReplicaCapacityInBytes() / 1024 / 1024 / 1024);
          if (capacityInGB != clusterConfigFields.partitionDiskWeightInGB) {
            partitionCapacityMap.put(partitionName, Collections.singletonMap(DISK_KEY,
                Math.toIntExact(capacityInGB) + PARTITION_BUFFER_CAPACITY_FOR_INDEX_FILES_IN_GB));
          }
        }
      }
    }
    partitionCapacityMap.put(DEFAULT_PARTITION_KEY, Collections.singletonMap(DISK_KEY,
        clusterConfigFields.partitionDiskWeightInGB + PARTITION_BUFFER_CAPACITY_FOR_INDEX_FILES_IN_GB));
    resourceConfig.setPartitionCapacityMap(partitionCapacityMap);

    // 3. Add a simple config with value of default partition capacity. Servers use this value to know the
    // partition capacity during boot up
    final long GB = 1024 * 1024 * 1024;
    resourceConfig.putSimpleConfig(DEFAULT_REPLICA_CAPACITY_STR,
        String.valueOf(GB * clusterConfigFields.partitionDiskWeightInGB));

    // 4. Set semi-auto placement as preference list so that no replicas are moved.
    if (setPreferenceList) {
      Map<String, List<String>> semiAutoPreferenceLists = idealState.getPreferenceLists();
      resourceConfig.setPreferenceLists(semiAutoPreferenceLists);
    }

    // 5. Update resource configs in helix
    if (!dryRun) {
      configAccessor.setResourceConfig(clusterName, resourceName, resourceConfig);
      info("Updated resource config/partition weights for resource {}. PARTITION_CAPACITY_MAP: {}, PREFERENCE_LIST: {}",
          resourceName, resourceConfig.getPartitionCapacityMap(), resourceConfig.getPreferenceLists());
    } else {
      info(
          "Dry run. This will update resource config/partition weights for resource {}. PARTITION_CAPACITY_MAP: {}, PREFERENCE_LIST: {}",
          resourceName, resourceConfig.getPartitionCapacityMap(), resourceConfig.getPreferenceLists());
    }
  }
Set resource configs for waged rebalancer

@param clusterName
@param resourceName                         resource
@param configAccessor                       the {@link ConfigAccessor} to access configuration in Helix.
@param propertyStoreToDataNodeConfigAdapter {@link PropertyStoreToDataNodeConfigAdapter} to access property store
                                            data.
@param helixAdmin                           {@link HelixAdmin}
@param clusterConfigFields                  inputted cluster configuration
@param setPreferenceList                    if {@code true}, sets semi-auto placement as preference list for
                                            full-auto
@param dryRun                               if true, perform a dry run; do not change ideal state to Full-Auto in Helix.
ambry-clustermap/src/main/java/com/github/ambry/clustermap/HelixBootstrapUpgradeUtil.java