private NodeCandidate retireSurplusNodeInGroup(NodeCandidate candidate, int[] countInGroup) {
        if (candidate.allocation().get().membership().retired()) return candidate;
        var currentGroup = candidate.allocation().get().membership().cluster().group();
        if (currentGroup.isEmpty()) return candidate;
        if (currentGroup.get().index() >= requested.groups()) return candidate;
        if (requested.count().isEmpty()) return candidate; // Can't retire
        if (countInGroup[currentGroup.get().index()] <= requested.groupSize()) return candidate;
        countInGroup[currentGroup.get().index()]--;
        return candidate.withNode(candidate.toNode().retire(Agent.application, clock.instant()));
    }
Assign a group to new or to be reactivated nodes.
node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/GroupAssigner.java