use of bio.terra.stairway.FlightStatus in project jade-data-repo by DataBiosphere.
the class JobServiceShutdownTest method testShutdown.
@Test
public void testShutdown() throws Exception {
// Segregated into its own test, since the Stairway object is not usable after it completes
// scenario:
// - start a thread that creates one flight every X second; keeping track of the flights
// - each flight sleeps Y secs and then returns; we want to get a backlog of flights in the queue
// when thread catches JobServiceShutdown exception, it stops launching and returns its flight list
// - sleep Z seconds to let the system fill up
// - call shutdown
// - validate that flights are either SUCCESS or READY
// Test Control Parameters
final int flightPerSecond = 1;
final int flightWaitSeconds = 30;
int maxStairwayThreads = appConfig.getMaxStairwayThreads();
logger.info("maxStairwayThreads: " + maxStairwayThreads);
JobTestShutdownFlightLauncher launcher = new JobTestShutdownFlightLauncher(flightPerSecond, flightWaitSeconds, testUser, jobService);
Thread launchThread = new Thread(launcher);
launchThread.start();
// Build a backlog in the queue
TimeUnit.SECONDS.sleep(2 * maxStairwayThreads);
jobService.shutdown();
launchThread.join();
List<String> flightIdList = launcher.getFlightIdList();
Stairway stairway = jobService.getStairway();
for (String flightId : flightIdList) {
FlightState state = stairway.getFlightState(flightId);
FlightStatus status = state.getFlightStatus();
logger.info("Flightid: " + flightId + "; status: " + status);
assertTrue(status == FlightStatus.SUCCESS || status == FlightStatus.READY);
}
}
use of bio.terra.stairway.FlightStatus in project terra-workspace-manager by DataBiosphere.
the class AwaitCloneGcsBucketResourceFlightStep method doStep.
@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
// wait for the flight
try {
final FlightState subflightState = context.getStairway().waitForFlight(subflightId, FLIGHT_POLL_SECONDS, FLIGHT_POLL_CYCLES);
final FlightStatus subflightStatus = subflightState.getFlightStatus();
final WsmCloneResourceResult cloneResult = WorkspaceCloneUtils.flightStatusToCloneResult(subflightStatus, resource);
final var cloneDetails = new WsmResourceCloneDetails();
cloneDetails.setResult(cloneResult);
final FlightMap resultMap = FlightUtils.getResultMapRequired(subflightState);
final var clonedBucket = resultMap.get(JobMapKeys.RESPONSE.getKeyName(), ApiClonedControlledGcpGcsBucket.class);
cloneDetails.setStewardshipType(StewardshipType.CONTROLLED);
cloneDetails.setResourceType(WsmResourceType.CONTROLLED_GCP_GCS_BUCKET);
cloneDetails.setCloningInstructions(resource.getCloningInstructions());
cloneDetails.setSourceResourceId(resource.getResourceId());
cloneDetails.setDestinationResourceId(Optional.ofNullable(clonedBucket).map(ApiClonedControlledGcpGcsBucket::getBucket).map(ApiCreatedControlledGcpGcsBucket::getResourceId).orElse(null));
cloneDetails.setErrorMessage(FlightUtils.getFlightErrorMessage(subflightState));
cloneDetails.setName(resource.getName());
cloneDetails.setDescription(resource.getDescription());
// add to the map
final var resourceIdToResult = Optional.ofNullable(context.getWorkingMap().get(ControlledResourceKeys.RESOURCE_ID_TO_CLONE_RESULT, new TypeReference<Map<UUID, WsmResourceCloneDetails>>() {
})).orElseGet(HashMap::new);
resourceIdToResult.put(resource.getResourceId(), cloneDetails);
context.getWorkingMap().put(ControlledResourceKeys.RESOURCE_ID_TO_CLONE_RESULT, resourceIdToResult);
} catch (DatabaseOperationException | FlightWaitTimedOutException e) {
// Retry for database issues or expired wait loop
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
validateRequiredEntries(context.getWorkingMap(), ControlledResourceKeys.RESOURCE_ID_TO_CLONE_RESULT);
return StepResult.getStepResultSuccess();
}
use of bio.terra.stairway.FlightStatus in project terra-workspace-manager by DataBiosphere.
the class JobService method mapFlightStateToApiJobReport.
public ApiJobReport mapFlightStateToApiJobReport(FlightState flightState) {
FlightMap inputParameters = flightState.getInputParameters();
String description = inputParameters.get(JobMapKeys.DESCRIPTION.getKeyName(), String.class);
FlightStatus flightStatus = flightState.getFlightStatus();
String submittedDate = flightState.getSubmitted().toString();
ApiJobReport.StatusEnum jobStatus = getJobStatus(flightStatus);
String completedDate = null;
HttpStatus statusCode = HttpStatus.ACCEPTED;
if (jobStatus != StatusEnum.RUNNING) {
// If the job is completed, the JobReport should include a result code indicating success or
// failure. For failed jobs, this code is the error code. For successful jobs, this is the
// code specified by the flight if present, or a default of 200 if not.
completedDate = flightState.getCompleted().get().toString();
switch(jobStatus) {
case FAILED:
int errorCode = flightState.getException().map(e -> ErrorReportUtils.buildApiErrorReport(e).getStatusCode()).orElseThrow(() -> new InvalidResultStateException("Flight failed with no exception reported"));
statusCode = HttpStatus.valueOf(errorCode);
break;
case SUCCEEDED:
FlightMap resultMap = getResultMap(flightState);
statusCode = resultMap.get(JobMapKeys.STATUS_CODE.getKeyName(), HttpStatus.class);
if (statusCode == null) {
statusCode = HttpStatus.OK;
}
break;
default:
throw new IllegalStateException("Cannot get status code of flight in unknown state " + jobStatus);
}
}
ApiJobReport jobReport = new ApiJobReport().id(flightState.getFlightId()).description(description).status(jobStatus).statusCode(statusCode.value()).submitted(submittedDate).completed(completedDate).resultURL(resultUrlFromFlightState(flightState));
return jobReport;
}
use of bio.terra.stairway.FlightStatus in project jade-data-repo by DataBiosphere.
the class JobService method mapFlightStateToJobModel.
public JobModel mapFlightStateToJobModel(FlightState flightState) {
FlightMap inputParameters = flightState.getInputParameters();
String description = inputParameters.get(JobMapKeys.DESCRIPTION.getKeyName(), String.class);
FlightStatus flightStatus = flightState.getFlightStatus();
String submittedDate = flightState.getSubmitted().toString();
JobModel.JobStatusEnum jobStatus = getJobStatus(flightStatus);
String completedDate = null;
HttpStatus statusCode = HttpStatus.ACCEPTED;
if (flightState.getCompleted().isPresent()) {
FlightMap resultMap = getResultMap(flightState);
// The STATUS_CODE return only needs to be used to return alternate success responses.
// If it is not present, then we set it to the default OK status.
statusCode = resultMap.get(JobMapKeys.STATUS_CODE.getKeyName(), HttpStatus.class);
if (statusCode == null) {
statusCode = HttpStatus.OK;
}
completedDate = flightState.getCompleted().get().toString();
}
JobModel jobModel = new JobModel().id(flightState.getFlightId()).description(description).jobStatus(jobStatus).statusCode(statusCode.value()).submitted(submittedDate).completed(completedDate);
return jobModel;
}
Aggregations