Do not throw exception if file reference is not found
@@ -526,10 +526,10 @@ public class SessionRepository {
/**
* Returns a new session instance for the given session id.
*/
- LocalSession createLocalSessionUsingDistributedApplicationPackage(long sessionId) {
+ Optional<LocalSession> createLocalSessionUsingDistributedApplicationPackage(long sessionId) {
if (applicationRepo.hasLocalSession(sessionId)) {
log.log(Level.FINE, "Local session for session id " + sessionId + " already exists");
- return createSessionFromId(sessionId);
+ return Optional.of(createSessionFromId(sessionId));
}
log.log(Level.INFO, "Creating local session for session id " + sessionId);
@@ -539,15 +539,18 @@ public class SessionRepository {
if (fileReference != null) {
File rootDir = new File(Defaults.getDefaults().underVespaHome(componentRegistry.getConfigserverConfig().fileReferencesDir()));
File sessionDir = new FileDirectory(rootDir).getFile(fileReference);
- if (!sessionDir.exists())
- throw new RuntimeException("File reference for session " + sessionId + " not found (" + sessionDir.getAbsolutePath() + ")");
+ if (!sessionDir.exists()) {
+ // We cannot be guaranteed that the file reference exists (it could be that it has not been downloaded
+ // yet), and e.g when bootstrapping we cannot throw an exception if that is the case, so return instead
+ return Optional.empty();
+ }
ApplicationId applicationId = sessionZKClient.readApplicationId();
- return createLocalSession(sessionDir,
+ return Optional.of(createLocalSession(sessionDir,
applicationId,
sessionId,
- applicationRepo.activeSessionOf(applicationId).orElse(nonExistingActiveSession));
+ applicationRepo.activeSessionOf(applicationId).orElse(nonExistingActiveSession)));
}
- return null;
+ return Optional.empty();
}
// Return Optional instead of faking it with nonExistingActiveSession
