private static Map<ClusterId, Set<ClusterSpec.Group>> groupsOf(NodeList nodes) {
        return nodes.stream()
                    .filter(node -> node.allocation().isPresent() &&
                                    node.allocation().get().membership().cluster().isStateful() &&
                                    node.allocation().get().membership().cluster().group().isPresent())
                    .collect(Collectors.groupingBy(node -> new ClusterId(node.allocation().get().owner(),
                                                                         node.allocation().get().membership().cluster().id()),
                                                   HashMap::new,
                                                   Collectors.mapping(n -> n.allocation().get().membership().cluster().group().get(),
                                                                      Collectors.toCollection(HashSet::new))));
    }
Returns the stateful groups present on given nodes, grouped by their cluster ID
node-repository/src/main/java/com/yahoo/vespa/hosted/provision/os/RetiringOsUpgrader.java