private static void waitForResourcesOrTimeout(PrepareParams params, Session session, Optional<Provisioner> provisioner) {
        if (!params.waitForResourcesInPrepare() || provisioner.isEmpty()) return;

        Set<HostSpec> preparedHosts = session.getAllocatedHosts().getHosts();
        ActivationContext context = new ActivationContext(session.getSessionId(), params.isBootstrap());
        AtomicReference<Exception> lastException = new AtomicReference<>();

        while (true) {
            params.getTimeoutBudget().assertNotTimedOut(
                    () -> "Timeout exceeded while waiting for application resources of '" + session.getApplicationId() + "'" +
                          Optional.ofNullable(lastException.get()).map(e -> ". Last exception: " + Exceptions.toMessageString(e)).orElse(""),
                    lastException.get());
            try (ApplicationMutex lock = provisioner.get().lock(session.getApplicationId())) {
                // Call to activate to make sure that everything is ready, but do not commit the transaction
                ApplicationTransaction transaction = new ApplicationTransaction(lock, new NestedTransaction());
                provisioner.get().activate(preparedHosts, context, transaction);
                return;
            } catch (ApplicationLockException | TransientException e) {
                lastException.set(e);
                try {
                    Thread.sleep(durationBetweenResourceReadyChecks.toMillis());
                } catch (InterruptedException e1) {
                    throw new RuntimeException(e1);
                }
            }
        }
    }
@param clock system clock
@param timeout total timeout duration of prepare + activate
@param session the local session for this deployment
@param isBootstrap true if this deployment is done to bootstrap the config server
@param ignoreValidationErrors whether this model should be validated
@param force whether activation of this model should be forced
configserver/src/main/java/com/yahoo/vespa/config/server/deploy/Deployment.java