@Override
    protected double maintain() {
        int attempts = 0;
        int[] failures = new int[1];

        List<Runnable> futureDownloads = new ArrayList<>();
        for (Session session : preparedAndActivatedSessions()) {
            if (shuttingDown())
                return asSuccessFactorDeviation(attempts, failures[0]);

            ApplicationId applicationId = session.getOptionalApplicationId().orElse(null);
            if (applicationId == null) // dry-run sessions have no application id
                continue;

            Optional<FileReference> appFileReference = session.getApplicationPackageReference();
            if (appFileReference.isPresent()) {
                long sessionId = session.getSessionId();
                FileReference fileReference = appFileReference.get();

                attempts++;
                if (! fileReferenceExistsOnDisk(downloadDirectory, fileReference)) {
                    Future<Optional<File>> futureDownload = startDownload(fileReference, sessionId, applicationId);
                    futureDownloads.add(() -> {
                        try {
                            if (futureDownload.get().isPresent()) {
                                createLocalSessionIfMissing(applicationId, sessionId);
                                return;
                            }
                        }
                        catch (Exception e) {
                            log.log(WARNING, "Exception when downloading application package (" + fileReference + ")" +
                                    " for " + applicationId + " (session " + sessionId + "): " + e.getMessage());
                        }
                        failures[0]++;
                        logFailure(session, fileReference, applicationId);
                    });
                }
                else {
                    createLocalSessionIfMissing(applicationId, sessionId);
                }
            }
        }
        futureDownloads.forEach(Runnable::run);
        return asSuccessFactorDeviation(attempts, failures[0]);
    }
Verifies that all active sessions has an application package on local disk.
If not, the package is downloaded with file distribution. This can happen e.g.
if a config server is down when the application is deployed. This maintainer should only be run
if there is more than 1 config server

@author gjoranv
configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ApplicationPackageMaintainer.java