private void controlPartitionState() {
    // for now, we only support controlling state of single partition on certain node. Hence, there should be only 1 dc
    // in adminForDc map.
    if (adminForDc.size() != 1) {
      throw new IllegalStateException("The dc count is not 1 for partition state control operation");
    }
    HelixAdmin helixAdmin = adminForDc.values().iterator().next();
    String instanceName;
    if (portNum == null) {
      Optional<DataNodeId> optionalDataNode =
          staticClusterMap.getDataNodeIds().stream().filter(node -> node.getHostname().equals(hostName)).findFirst();
      if (!optionalDataNode.isPresent()) {
        throw new IllegalStateException("Host " + hostName + " is not found in static clustermap");
      }
      DataNode dataNode = (DataNode) optionalDataNode.get();
      instanceName = getInstanceName(dataNode);
    } else {
      instanceName = ClusterMapUtils.getInstanceName(hostName, portNum);
    }
    InstanceConfig instanceConfig = helixAdmin.getInstanceConfig(clusterName, instanceName);
    String resourceNameForPartition = getResourceNameOfPartition(helixAdmin, clusterName, partitionName);
    info("{} partition {} under resource {} on node {}",
        helixAdminOperation == HelixAdminOperation.EnablePartition ? "Enabling" : "Disabling", partitionName,
        resourceNameForPartition, instanceName);
    instanceConfig.setInstanceEnabledForPartition(resourceNameForPartition, partitionName,
        helixAdminOperation == HelixAdminOperation.EnablePartition);
    // clean up the disabled partition entry if it exists and is empty.
    Map<String, String> disabledPartitions =
        instanceConfig.getRecord().getMapFields().get(HELIX_DISABLED_PARTITION_STR);
    if (disabledPartitions != null && disabledPartitions.isEmpty()) {
      instanceConfig.getRecord().getMapFields().remove(HELIX_DISABLED_PARTITION_STR);
    }
    helixAdmin.setInstanceConfig(clusterName, instanceName, instanceConfig);
    instancesUpdated.getAndIncrement();
    if (helixAdminOperation == HelixAdminOperation.EnablePartition) {
      partitionsEnabled.getAndIncrement();
    } else {
      partitionsDisabled.getAndIncrement();
    }
  }
Control state of partition on certain node. (i.e. DisablePartition, EnablePartition)
ambry-clustermap/src/main/java/com/github/ambry/clustermap/HelixBootstrapUpgradeUtil.java