use of bio.terra.service.job.exception.InternalStairwayException 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);
}
}
use of bio.terra.service.job.exception.InternalStairwayException in project jade-data-repo by DataBiosphere.
the class JobService method enumerateJobs.
public List<JobModel> enumerateJobs(int offset, int limit, AuthenticatedUserRequest userReq) {
boolean canListAnyJob = checkUserCanListAnyJob(userReq);
// if the user has access to all jobs, then fetch everything
// otherwise, filter the jobs on the user
List<FlightState> flightStateList;
try {
FlightFilter filter = new FlightFilter();
if (!canListAnyJob) {
filter.addFilterInputParameter(JobMapKeys.SUBJECT_ID.getKeyName(), FlightFilterOp.EQUAL, userReq.getSubjectId());
}
flightStateList = stairway.getFlights(offset, limit, filter);
} catch (StairwayException stairwayEx) {
throw new InternalStairwayException(stairwayEx);
} catch (InterruptedException ex) {
throw new JobServiceShutdownException("Job service interrupted", ex);
}
List<JobModel> jobModelList = new ArrayList<>();
for (FlightState flightState : flightStateList) {
JobModel jobModel = mapFlightStateToJobModel(flightState);
jobModelList.add(jobModel);
}
return jobModelList;
}
use of bio.terra.service.job.exception.InternalStairwayException in project jade-data-repo by DataBiosphere.
the class JobService method verifyUserAccess.
private void verifyUserAccess(String jobId, AuthenticatedUserRequest userReq) {
try {
FlightState flightState = stairway.getFlightState(jobId);
FlightMap inputParameters = flightState.getInputParameters();
String flightSubjectId = inputParameters.get(JobMapKeys.SUBJECT_ID.getKeyName(), String.class);
if (!StringUtils.equals(flightSubjectId, userReq.getSubjectId())) {
throw new JobUnauthorizedException("Unauthorized");
}
} catch (DatabaseOperationException ex) {
throw new InternalStairwayException("Stairway exception looking up the job", ex);
} catch (FlightNotFoundException ex) {
throw new JobNotFoundException("Job not found", ex);
} catch (InterruptedException ex) {
throw new JobServiceShutdownException("Job service interrupted", ex);
}
}
Aggregations