(self, new_target_capacity: float)
return targets
Compute a balanced distribution of target capacities for the resource groups in the cluster

        :param new_target_capacity: the desired new target capacity that needs to be distributed
        :returns: A list of target_capacity values, sorted in order of resource groups
Compute a balanced distribution of target capacities for the resource groups in the cluster
Compute a balanced distribution of target capacities for the resource groups in the cluster
def _compute_new_resource_group_targets(self, new_target_capacity: float) -> Mapping[str, float]:
        """ Compute a balanced distribution of target capacities for the resource groups in the cluster

        :param new_target_capacity: the desired new target capacity that needs to be distributed
        :returns: A list of target_capacity values, sorted in order of resource groups
        """

        stale_groups = [group for group in self.resource_groups.values() if group.is_stale]
        non_stale_groups = [group for group in self.resource_groups.values() if not group.is_stale]

        # If we're scaling down the logic is identical but reversed, so we multiply everything by -1
        coeff = -1 if new_target_capacity < self.target_capacity else 1
        targets: Dict[str, float] = {g.id: g.target_capacity for g in non_stale_groups}

        # For stale groups, we set target_capacity to 0. This is a noop on SpotFleetResourceGroup.
        for stale_group in stale_groups:
            targets[stale_group.id] = 0

        def is_constrained(group):
            if coeff > 0:
                return targets[group.id] + coeff > group.max_capacity
            else:
                return targets[group.id] + coeff < group.min_capacity

        while sum(targets.values()) * coeff < math.ceil(new_target_capacity) * coeff:
            try:
                group = sorted(
                    [g for g in non_stale_groups if not is_constrained(g)], key=lambda g: (coeff * targets[g.id], g.id),
                )[0]
            except IndexError:
                logger.warning(
                    " ".join(
                        [
                            "All resource groups are stale or constrained.",
                            f"The closest we could get to {new_target_capacity} is {sum(targets.values())}",
                        ]
                    )
                )
                break

            targets[group.id] += coeff

        return targets
def _compute_new_resource_group_targets ( self , new_target_capacity : float ) -> Mapping [ str , float ] : stale_groups = [ group for group in self . resource_groups . values ( ) if group . is_stale ] non_stale_groups = [ group for group in self . resource_groups . values ( ) if not group . is_stale ] # If we're scaling down the logic is identical but reversed, so we multiply everything by -1 coeff = - 1 if new_target_capacity < self . target_capacity else 1 targets : Dict [ str , float ] = { g . id : g . target_capacity for g in non_stale_groups } # For stale groups, we set target_capacity to 0. This is a noop on SpotFleetResourceGroup. for stale_group in stale_groups : targets [ stale_group . id ] = 0 def is_constrained ( group ) : if coeff > 0 : return targets [ group . id ] + coeff > group . max_capacity else : return targets [ group . id ] + coeff < group . min_capacity while sum ( targets . values ( ) ) * coeff < math . ceil ( new_target_capacity ) * coeff : try : group = sorted ( [ g for g in non_stale_groups if not is_constrained ( g ) ] , key = lambda g : ( coeff * targets [ g . id ] , g . id ) , ) [ 0 ] except IndexError : logger . warning ( " " . join ( [ "All resource groups are stale or constrained." , f"The closest we could get to {new_target_capacity} is {sum(targets.values())}" , ] ) ) break targets [ group . id ] += coeff return targets