Code review comment: SO this won't work before all deployemnts are re-done, but I guess that's OK?

Code under review:
protected double maintain() {
        Map<ZoneId, Set<TenantName>> tenantsByZone = new HashMap<>();
        Map<ZoneId, Set<CloudAccount>> accountsByZone = new HashMap<>();

        controller().zoneRegistry().zonesIncludingSystem().reachable().zones().forEach(zone -> {
            tenantsByZone.put(zone.getVirtualId(), new HashSet<>(INFRASTRUCTURE_TENANTS));
            accountsByZone.put(zone.getVirtualId(), new HashSet<>());
        });

        for (var application : applications.asList()) {
            for (var instance : application.instances().values()) {
                for (var deployment : instance.deployments().values()) {
                    if (zoneRegistry.isEnclave(deployment.cloudAccount())) accountsByZone.get(deployment.zone()).add(deployment.cloudAccount());
                    else tenantsByZone.get(deployment.zone()).add(instance.id().tenant());
                }
            }
        }

        int failures = 0;
        for (ZoneId zone : tenantsByZone.keySet()) {
            try {
                ArchiveUris zoneArchiveUris = nodeRepository.getArchiveUris(zone);

                Stream.of(
                        
                        tenantsByZone.get(zone).stream()
                                .flatMap(tenant -> archiveBucketDb.archiveUriFor(zone, tenant, true)
                                        .filter(uri -> !uri.equals(zoneArchiveUris.tenantArchiveUris().get(tenant)))
                                        .map(uri -> ArchiveUriUpdate.setArchiveUriFor(tenant, uri))
                                        .stream()),
                        
                        accountsByZone.get(zone).stream()
                                .flatMap(account -> archiveBucketDb.archiveUriFor(zone, account, true)
                                        .filter(uri -> !uri.equals(zoneArchiveUris.accountArchiveUris().get(account)))
                                        .map(uri -> ArchiveUriUpdate.setArchiveUriFor(account, uri))
                                        .stream()),
                        
                        zoneArchiveUris.tenantArchiveUris().keySet().stream()
                                .filter(tenant -> !tenantsByZone.get(zone).contains(tenant))
                                .map(ArchiveUriUpdate::deleteArchiveUriFor),
                        
                        zoneArchiveUris.accountArchiveUris().keySet().stream()
                                .filter(account -> !accountsByZone.get(zone).contains(account))
                                .map(ArchiveUriUpdate::deleteArchiveUriFor))
                        .flatMap(s -> s)
                        .forEach(update -> nodeRepository.updateArchiveUri(zone, update));
            } catch (Exception e) {
                log.log(Level.WARNING, "Failed to update archive URI in " + zone + ". Retrying in " + interval() + ". Error: " +
                        Exceptions.toMessageString(e));
                failures++;
            }
        }

        return asSuccessFactor(tenantsByZone.size(), failures);
    }

Line commented on: else tenantsByZone.get(deployment.zone()).add(instance.id().tenant());

Revised code:
protected double maintain() {
        Map<ZoneId, Set<TenantName>> tenantsByZone = new HashMap<>();
        Map<ZoneId, Set<CloudAccount>> accountsByZone = new HashMap<>();

        controller().zoneRegistry().zonesIncludingSystem().reachable().zones().forEach(zone -> {
            tenantsByZone.put(zone.getVirtualId(), new HashSet<>(INFRASTRUCTURE_TENANTS));
            accountsByZone.put(zone.getVirtualId(), new HashSet<>());
        });

        for (var application : applications.asList()) {
            for (var instance : application.instances().values()) {
                for (var deployment : instance.deployments().values()) {
                    if (zoneRegistry.isEnclave(deployment.cloudAccount())) accountsByZone.get(deployment.zone()).add(deployment.cloudAccount());
                    else tenantsByZone.get(deployment.zone()).add(instance.id().tenant());
                }
            }
        }

        int failures = 0;
        for (ZoneId zone : tenantsByZone.keySet()) {
            try {
                ArchiveUris zoneArchiveUris = nodeRepository.getArchiveUris(zone);

                Stream.of(
                        
                        tenantsByZone.get(zone).stream()
                                .flatMap(tenant -> archiveBucketDb.archiveUriFor(zone, tenant, true)
                                        .filter(uri -> !uri.equals(zoneArchiveUris.tenantArchiveUris().get(tenant)))
                                        .map(uri -> ArchiveUriUpdate.setArchiveUriFor(tenant, uri))
                                        .stream()),
                        
                        accountsByZone.get(zone).stream()
                                .flatMap(account -> archiveBucketDb.archiveUriFor(zone, account, true)
                                        .filter(uri -> !uri.equals(zoneArchiveUris.accountArchiveUris().get(account)))
                                        .map(uri -> ArchiveUriUpdate.setArchiveUriFor(account, uri))
                                        .stream()),
                        
                        zoneArchiveUris.tenantArchiveUris().keySet().stream()
                                .filter(tenant -> !tenantsByZone.get(zone).contains(tenant))
                                .map(ArchiveUriUpdate::deleteArchiveUriFor),
                        
                        zoneArchiveUris.accountArchiveUris().keySet().stream()
                                .filter(account -> !accountsByZone.get(zone).contains(account))
                                .map(ArchiveUriUpdate::deleteArchiveUriFor))
                        .flatMap(s -> s)
                        .forEach(update -> nodeRepository.updateArchiveUri(zone, update));
            } catch (Exception e) {
                log.log(Level.WARNING, "Failed to update archive URI in " + zone + ". Retrying in " + interval() + ". Error: " +
                        Exceptions.toMessageString(e));
                failures++;
            }
        }

        return asSuccessFactor(tenantsByZone.size(), failures);
    }