private List<MODELRESULT> buildModelVersions(Set<Version> versions,
                                                 ApplicationId applicationId,
                                                 Optional<DockerImage> wantedDockerImageRepository,
                                                 Version wantedNodeVespaVersion,
                                                 ApplicationPackage applicationPackage,
                                                 AllocatedHostsFromAllModels allocatedHosts,
                                                 Instant now,
                                                 boolean buildLatestModelForThisMajor,
                                                 Optional<Version> versionToBuildFirst,
                                                 int majorVersion) {
        List<MODELRESULT> built = new ArrayList<>();
        if (buildLatestModelForThisMajor) {
            if (versionToBuildFirst.isEmpty())
                versionToBuildFirst = Optional.of(findLatest(versions));
            var builtFirst = buildModelVersion(modelFactoryRegistry.getFactory(versionToBuildFirst.get()),
                                               applicationPackage,
                                               applicationId,
                                               wantedDockerImageRepository,
                                               wantedNodeVespaVersion);
            allocatedHosts.add(builtFirst.getModel().allocatedHosts(), versionToBuildFirst.get());
            built.add(builtFirst);
        }

        versions = versionsToBuild(versions, wantedNodeVespaVersion, majorVersion, allocatedHosts);
        for (Version version : versions) {
            if (alreadyBuilt(version, built)) continue;

            try {
                MODELRESULT modelVersion = buildModelVersion(modelFactoryRegistry.getFactory(version),
                                                             applicationPackage,
                                                             applicationId,
                                                             wantedDockerImageRepository,
                                                             wantedNodeVespaVersion);
                allocatedHosts.add(modelVersion.getModel().allocatedHosts(), version);
                built.add(modelVersion);
            } catch (RuntimeException e) {
                if (allowBuildToFail(now, built))
                    log.log(Level.INFO, applicationId + ": Failed to build version " + version +
                            ", but allow failure due to validation override or manual deployment:"
                            + Exceptions.toMessageString(e));
                else {
                    log.log(Level.SEVERE, applicationId + ": Failed to build version " + version);
                    throw e;
                }
            }
        }
        return built;
    }
Builds all applicable model versions

@param allocatedHosts the newest version (major and minor) (which is loaded first) decides the allocated hosts
                      and assigns to this SettableOptional such that it can be used after this method returns
configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ModelsBuilder.java