use of bio.terra.stairway.exception.FlightWaitTimedOutException in project terra-workspace-manager by DataBiosphere.
the class AwaitCreateGcpContextFlightStep method doStep.
@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
FlightUtils.validateRequiredEntries(context.getWorkingMap(), ControlledResourceKeys.CREATE_CLOUD_CONTEXT_FLIGHT_ID);
final var jobId = context.getWorkingMap().get(ControlledResourceKeys.CREATE_CLOUD_CONTEXT_FLIGHT_ID, String.class);
try {
final FlightState subflightState = context.getStairway().waitForFlight(jobId, FLIGHT_POLL_SECONDS, FLIGHT_POLL_CYCLES);
if (FlightStatus.SUCCESS != subflightState.getFlightStatus()) {
// no point in retrying the await step
return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, subflightState.getException().orElseGet(() -> new RuntimeException(String.format("Subflight had unexpected status %s. No exception for subflight found.", subflightState.getFlightStatus()))));
}
} catch (DatabaseOperationException | FlightWaitTimedOutException e) {
// Retry for database issues or expired wait loop
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
return StepResult.getStepResultSuccess();
}
use of bio.terra.stairway.exception.FlightWaitTimedOutException in project terra-workspace-manager by DataBiosphere.
the class AwaitCloneAllResourcesFlightStep method doStep.
@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
validateRequiredEntries(context.getInputParameters(), ControlledResourceKeys.SOURCE_WORKSPACE_ID, JobMapKeys.REQUEST.getKeyName());
validateRequiredEntries(context.getWorkingMap(), ControlledResourceKeys.CLONE_ALL_RESOURCES_FLIGHT_ID);
final var cloneAllResourcesFlightId = context.getWorkingMap().get(ControlledResourceKeys.CLONE_ALL_RESOURCES_FLIGHT_ID, String.class);
final var destinationWorkspace = context.getInputParameters().get(JobMapKeys.REQUEST.getKeyName(), Workspace.class);
try {
// noinspection deprecation
final FlightState subflightState = context.getStairway().waitForFlight(cloneAllResourcesFlightId, FLIGHT_POLL_SECONDS, FLIGHT_POLL_CYCLES);
if (FlightStatus.SUCCESS != subflightState.getFlightStatus()) {
// no point in retrying the await step
return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, subflightState.getException().orElseGet(() -> new RuntimeException(String.format("Subflight had unexpected status %s. No exception for subflight found.", subflightState.getFlightStatus()))));
}
final FlightMap subflightResultMap = FlightUtils.getResultMapRequired(subflightState);
// Build the response object from the resource ID to details map. The map won't have been
// instantiated if there are no resources in the workspace, so just use an empty map in that
// case.
final var resourceIdToDetails = Optional.ofNullable(subflightResultMap.get(ControlledResourceKeys.RESOURCE_ID_TO_CLONE_RESULT, new TypeReference<Map<UUID, WsmResourceCloneDetails>>() {
})).orElse(Collections.emptyMap());
final var apiClonedWorkspace = new ApiClonedWorkspace();
apiClonedWorkspace.setDestinationWorkspaceId(destinationWorkspace.getWorkspaceId());
final var sourceWorkspaceId = context.getInputParameters().get(ControlledResourceKeys.SOURCE_WORKSPACE_ID, UUID.class);
apiClonedWorkspace.setSourceWorkspaceId(sourceWorkspaceId);
final List<ApiResourceCloneDetails> resources = resourceIdToDetails.values().stream().map(WsmResourceCloneDetails::toApiModel).collect(Collectors.toList());
apiClonedWorkspace.setResources(resources);
// Set overall response for workspace clone flights
FlightUtils.setResponse(context, apiClonedWorkspace, HttpStatus.OK);
} catch (DatabaseOperationException | FlightWaitTimedOutException e) {
// Retry for database issues or expired wait loop
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
return StepResult.getStepResultSuccess();
}
use of bio.terra.stairway.exception.FlightWaitTimedOutException 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.exception.FlightWaitTimedOutException in project terra-workspace-manager by DataBiosphere.
the class AwaitCreateReferenceResourceFlightStep method doStep.
@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
try {
// add to the result map
final var resourceIdToResult = Optional.ofNullable(context.getWorkingMap().get(ControlledResourceKeys.RESOURCE_ID_TO_CLONE_RESULT, new TypeReference<Map<UUID, WsmResourceCloneDetails>>() {
})).orElseGet(HashMap::new);
final WsmResourceCloneDetails cloneDetails = new WsmResourceCloneDetails();
if (CloningInstructions.COPY_REFERENCE == sourceResource.getCloningInstructions()) {
FlightUtils.validateRequiredEntries(context.getWorkingMap(), ControlledResourceKeys.DESTINATION_REFERENCED_RESOURCE);
final FlightState subflightState = context.getStairway().waitForFlight(flightId, FLIGHT_POLL_SECONDS, FLIGHT_POLL_CYCLES);
final WsmCloneResourceResult cloneResult = WorkspaceCloneUtils.flightStatusToCloneResult(subflightState.getFlightStatus(), sourceResource);
cloneDetails.setResult(cloneResult);
final FlightMap resultMap = FlightUtils.getResultMapRequired(subflightState);
// Input to the create flight
final var destinationReferencedResource = context.getWorkingMap().get(ControlledResourceKeys.DESTINATION_REFERENCED_RESOURCE, ReferencedResource.class);
final var clonedReferencedResourceId = resultMap.get(JobMapKeys.RESPONSE.getKeyName(), UUID.class);
// Use the destination referenced resource for things that are fixed over
// the operation, and the one from the database to verify the resource ID
cloneDetails.setResourceType(destinationReferencedResource.getResourceType());
cloneDetails.setStewardshipType(destinationReferencedResource.getStewardshipType());
cloneDetails.setCloningInstructions(destinationReferencedResource.getCloningInstructions());
cloneDetails.setSourceResourceId(sourceResource.getResourceId());
cloneDetails.setDestinationResourceId(clonedReferencedResourceId);
cloneDetails.setErrorMessage(FlightUtils.getFlightErrorMessage(subflightState));
cloneDetails.setName(sourceResource.getName());
cloneDetails.setDescription(sourceResource.getDescription());
} else {
// No flight was created
cloneDetails.setResult(WsmCloneResourceResult.SKIPPED);
cloneDetails.setResourceType(sourceResource.getResourceType());
cloneDetails.setStewardshipType(sourceResource.getStewardshipType());
cloneDetails.setCloningInstructions(sourceResource.getCloningInstructions());
cloneDetails.setSourceResourceId(sourceResource.getResourceId());
cloneDetails.setDestinationResourceId(null);
cloneDetails.setErrorMessage(null);
cloneDetails.setName(sourceResource.getName());
cloneDetails.setDescription(sourceResource.getDescription());
}
resourceIdToResult.put(sourceResource.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.exception.FlightWaitTimedOutException in project terra-workspace-manager by DataBiosphere.
the class AwaitCloneControlledGcpBigQueryDatasetResourceFlightStep 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 WsmResourceCloneDetails cloneDetails = new WsmResourceCloneDetails();
final WsmCloneResourceResult cloneResult = WorkspaceCloneUtils.flightStatusToCloneResult(subflightState.getFlightStatus(), resource);
cloneDetails.setResult(cloneResult);
final FlightMap resultMap = FlightUtils.getResultMapRequired(subflightState);
final var clonedDataset = resultMap.get(JobMapKeys.RESPONSE.getKeyName(), ApiClonedControlledGcpBigQueryDataset.class);
cloneDetails.setStewardshipType(StewardshipType.CONTROLLED);
cloneDetails.setResourceType(WsmResourceType.CONTROLLED_GCP_BIG_QUERY_DATASET);
cloneDetails.setCloningInstructions(resource.getCloningInstructions());
cloneDetails.setSourceResourceId(resource.getResourceId());
cloneDetails.setDestinationResourceId(Optional.ofNullable(clonedDataset).map(ApiClonedControlledGcpBigQueryDataset::getDataset).map(ApiGcpBigQueryDatasetResource::getMetadata).map(ApiResourceMetadata::getResourceId).orElse(null));
String errorMessage = FlightUtils.getFlightErrorMessage(subflightState);
cloneDetails.setErrorMessage(errorMessage);
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();
}
Aggregations