use of bio.terra.service.job.exception.JobServiceStartupException in project jade-data-repo by DataBiosphere.
the class JobService method initialize.
/**
* This method is called from StartupInitializer as part of the sequence of migrating databases
* and recovering any jobs; i.e., Stairway flights. It lives in this class so that JobService encapsulates
* all Stairway interaction.
*/
public void initialize() {
try {
List<String> recordedStairways;
boolean weMigrated = false;
try {
weMigrated = migrate.migrateDatabase();
// Initialize stairway - only do the stairway migration if we did the data repo migration
recordedStairways = stairway.initialize(stairwayJdbcConfiguration.getDataSource(), (weMigrated && migrateConfiguration.getDropAllOnStart()), (weMigrated && migrateConfiguration.getUpdateAllOnStart()));
} finally {
if (weMigrated) {
migrate.releaseMigrateLock();
}
}
// Order is important here. There are two concerns we need to handle:
// 1. We need to avoid a window where a running pod could get onto the Stairway list, but not be
// on the pod list. That is why we get the recorded list from Stairway *before* we read the Kubernetes
// pod list.
// 2. We want to clean up pods that fail, so we start the kubePodListener as early as possible so we
// detect pods that get deleted. The Stairway recovery method called by kubePodListener works once
// Stairway initialization is done, so it is safe to start the listener before we have called
// Stairway recoveryAndStart
kubeService.startPodListener(stairway);
// Lookup all of the stairway instances we know about
Set<String> existingStairways = kubeService.getApiPodList();
List<String> obsoleteStairways = new LinkedList<>();
// Any instances that stairway knows about, but we cannot see are obsolete.
for (String recordedStairway : recordedStairways) {
if (!existingStairways.contains(recordedStairway)) {
obsoleteStairways.add(recordedStairway);
}
}
// Recover and start stairway - step 3 of the stairway startup sequence
stairway.recoverAndStart(obsoleteStairways);
} catch (StairwayException stairwayEx) {
throw new InternalStairwayException("Stairway initialization failed", stairwayEx);
} catch (InterruptedException ex) {
throw new JobServiceStartupException("Stairway startup process interrupted", ex);
}
}
Aggregations