diff options
author | Harald Musum <musum@oath.com> | 2018-11-20 12:22:16 +0100 |
---|---|---|
committer | Harald Musum <musum@oath.com> | 2018-11-20 12:22:16 +0100 |
commit | db9f204b0cafee4881613eee4629b4fe87a6413b (patch) | |
tree | e4bab9d9cc92ed2a0758069898bb322032001c25 /configserver | |
parent | a549b3d81757eb3670982c936c1312a939003816 (diff) |
Simplify handling of missing tenant or application
Diffstat (limited to 'configserver')
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java | 48 |
1 files changed, 18 insertions, 30 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java index e7b9012483f..d9714c7c9af 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java @@ -406,20 +406,14 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye public Set<String> deleteUnusedFiledistributionReferences(File fileReferencesPath) { if (!fileReferencesPath.isDirectory()) throw new RuntimeException(fileReferencesPath + " is not a directory"); - // Find all file references in use Set<String> fileReferencesInUse = new HashSet<>(); - Set<ApplicationId> applicationIds = listApplications(); - applicationIds.forEach(applicationId -> { - try { - Set<String> fileReferences = getApplication(applicationId).getModel().fileReferences() - .stream() - .map(FileReference::value) - .collect(Collectors.toSet()); - fileReferencesInUse.addAll(fileReferences); - } catch (IllegalArgumentException e) { - log.log(LogLevel.WARNING, "Failed deleting unused file references for ': " + applicationId + "'", e); - } - }); + // Intentionally skip applications that we for some reason do not find + listApplications().stream() + .map(this::getOptionalApplication) + .map(Optional::get) + .forEach(application -> fileReferencesInUse.addAll(application.getModel().fileReferences().stream() + .map(FileReference::value) + .collect(Collectors.toSet()))); log.log(LogLevel.DEBUG, "File references in use : " + fileReferencesInUse); // Find those on disk that are not in use @@ -464,6 +458,14 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye } } + private Optional<Application> getOptionalApplication(ApplicationId applicationId) { + try { + return Optional.of(getApplication(applicationId)); + } catch (Exception e) { + return Optional.empty(); + } + } + Set<ApplicationId> listApplications() { return tenantRepository.getAllTenants().stream() .flatMap(tenant -> tenant.getApplicationRepo().listApplications().stream()) @@ -575,27 +577,13 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye } public void deleteExpiredLocalSessions() { - listApplications().forEach(app -> { - Tenant tenant = tenantRepository.getTenant(app.tenant()); - if (tenant == null) - log.log(LogLevel.WARNING, "Cannot delete expired local sessions for tenant '" + app.tenant() + "', tenant not found"); - else - tenant.getLocalSessionRepo().purgeOldSessions(); - }); + tenantRepository.getAllTenants().forEach(tenant -> tenant.getLocalSessionRepo().purgeOldSessions()); } public int deleteExpiredRemoteSessions(Duration expiryTime) { - return listApplications() + return tenantRepository.getAllTenants() .stream() - .map(app -> { - Tenant tenant = tenantRepository.getTenant(app.tenant()); - if (tenant == null) { - log.log(LogLevel.WARNING, "Cannot delete expired remote sessions for tenant '" + app.tenant() + "', tenant not found"); - return 0; - } else { - return tenant.getRemoteSessionRepo().deleteExpiredSessions(expiryTime); - } - }) + .map(tenant -> tenant.getRemoteSessionRepo().deleteExpiredSessions(expiryTime)) .mapToInt(i -> i) .sum(); } |