use of bio.terra.workspace.generated.model.ApiClonedWorkspace 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();
}
Aggregations