public StorageGroup buildHosted(DeployState deployState,
                                            ContentCluster owner,
                                            Optional<GroupBuilder> parent,
                                            ConfigModelContext context) {
                if (storageGroup.getIndex() != null)
                    throw new IllegalArgumentException("Specifying individual groups is not supported on hosted applications");
                Map<HostResource, ClusterMembership> hostMapping =
                        nodeRequirement.isPresent() ?
                        provisionHosts(nodeRequirement.get(),
                                       owner.getStorageCluster().getClusterName(),
                                       owner.getRoot().hostSystem(),
                                       context) :
                        Map.of();

                Map<Optional<ClusterSpec.Group>, Map<HostResource, ClusterMembership>> hostGroups = collectAllocatedSubgroups(hostMapping);
                if (hostGroups.size() > 1) {
                    if (parent.isPresent())
                        throw new IllegalArgumentException("Cannot specify groups using the groups attribute in nested content groups");

                    // create subgroups as returned from allocation
                    for (Map.Entry<Optional<ClusterSpec.Group>, Map<HostResource, ClusterMembership>> hostGroup : hostGroups.entrySet()) {
                        String groupIndex = String.valueOf(hostGroup.getKey().get().index());
                        StorageGroup subgroup = new StorageGroup(true, groupIndex, groupIndex);
                        for (Map.Entry<HostResource, ClusterMembership> host : hostGroup.getValue().entrySet()) {
                            subgroup.nodes.add(createStorageNode(deployState, owner, host.getKey(), subgroup, host.getValue()));
                        }
                        storageGroup.subgroups.add(subgroup);
                    }
                }
                else { // or otherwise just create the nodes directly on this group, or the explicitly enumerated subgroups
                    for (Map.Entry<HostResource, ClusterMembership> host : hostMapping.entrySet()) {
                        storageGroup.nodes.add(createStorageNode(deployState, owner, host.getKey(), storageGroup, host.getValue()));
                    }
                    for (GroupBuilder subGroup : subGroups) {
                        storageGroup.subgroups.add(subGroup.buildHosted(deployState, owner, Optional.of(this), context));
                    }
                }
                return storageGroup;
            }
Builds a storage group for a hosted environment

@param owner the cluster owning this
@param parent the parent storage group, or empty if this is the root group
@return the storage group build by this
config-model/src/main/java/com/yahoo/vespa/model/content/StorageGroup.java