Search in sources :

Example 1 with FlightWaitTimedOutException

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();
}
Also used : FlightState(bio.terra.stairway.FlightState) DatabaseOperationException(bio.terra.stairway.exception.DatabaseOperationException) StepResult(bio.terra.stairway.StepResult) FlightWaitTimedOutException(bio.terra.stairway.exception.FlightWaitTimedOutException)

Example 2 with FlightWaitTimedOutException

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();
}
Also used : ApiResourceCloneDetails(bio.terra.workspace.generated.model.ApiResourceCloneDetails) FlightWaitTimedOutException(bio.terra.stairway.exception.FlightWaitTimedOutException) FlightState(bio.terra.stairway.FlightState) ApiClonedWorkspace(bio.terra.workspace.generated.model.ApiClonedWorkspace) DatabaseOperationException(bio.terra.stairway.exception.DatabaseOperationException) FlightMap(bio.terra.stairway.FlightMap) StepResult(bio.terra.stairway.StepResult) Map(java.util.Map) FlightMap(bio.terra.stairway.FlightMap)

Example 3 with FlightWaitTimedOutException

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();
}
Also used : WsmResourceCloneDetails(bio.terra.workspace.service.workspace.model.WsmResourceCloneDetails) WsmCloneResourceResult(bio.terra.workspace.service.workspace.model.WsmCloneResourceResult) HashMap(java.util.HashMap) FlightWaitTimedOutException(bio.terra.stairway.exception.FlightWaitTimedOutException) ApiCreatedControlledGcpGcsBucket(bio.terra.workspace.generated.model.ApiCreatedControlledGcpGcsBucket) FlightState(bio.terra.stairway.FlightState) DatabaseOperationException(bio.terra.stairway.exception.DatabaseOperationException) FlightStatus(bio.terra.stairway.FlightStatus) FlightMap(bio.terra.stairway.FlightMap) StepResult(bio.terra.stairway.StepResult) HashMap(java.util.HashMap) Map(java.util.Map) FlightMap(bio.terra.stairway.FlightMap)

Example 4 with FlightWaitTimedOutException

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();
}
Also used : FlightState(bio.terra.stairway.FlightState) WsmResourceCloneDetails(bio.terra.workspace.service.workspace.model.WsmResourceCloneDetails) DatabaseOperationException(bio.terra.stairway.exception.DatabaseOperationException) HashMap(java.util.HashMap) WsmCloneResourceResult(bio.terra.workspace.service.workspace.model.WsmCloneResourceResult) FlightMap(bio.terra.stairway.FlightMap) FlightWaitTimedOutException(bio.terra.stairway.exception.FlightWaitTimedOutException) StepResult(bio.terra.stairway.StepResult) HashMap(java.util.HashMap) Map(java.util.Map) FlightMap(bio.terra.stairway.FlightMap)

Example 5 with FlightWaitTimedOutException

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();
}
Also used : WsmResourceCloneDetails(bio.terra.workspace.service.workspace.model.WsmResourceCloneDetails) ApiResourceMetadata(bio.terra.workspace.generated.model.ApiResourceMetadata) WsmCloneResourceResult(bio.terra.workspace.service.workspace.model.WsmCloneResourceResult) HashMap(java.util.HashMap) FlightWaitTimedOutException(bio.terra.stairway.exception.FlightWaitTimedOutException) ApiClonedControlledGcpBigQueryDataset(bio.terra.workspace.generated.model.ApiClonedControlledGcpBigQueryDataset) FlightState(bio.terra.stairway.FlightState) DatabaseOperationException(bio.terra.stairway.exception.DatabaseOperationException) FlightMap(bio.terra.stairway.FlightMap) StepResult(bio.terra.stairway.StepResult) HashMap(java.util.HashMap) Map(java.util.Map) FlightMap(bio.terra.stairway.FlightMap)

Aggregations

FlightState (bio.terra.stairway.FlightState)6 StepResult (bio.terra.stairway.StepResult)6 DatabaseOperationException (bio.terra.stairway.exception.DatabaseOperationException)6 FlightWaitTimedOutException (bio.terra.stairway.exception.FlightWaitTimedOutException)6 FlightMap (bio.terra.stairway.FlightMap)4 Map (java.util.Map)4 WsmCloneResourceResult (bio.terra.workspace.service.workspace.model.WsmCloneResourceResult)3 WsmResourceCloneDetails (bio.terra.workspace.service.workspace.model.WsmResourceCloneDetails)3 HashMap (java.util.HashMap)3 FlightStatus (bio.terra.stairway.FlightStatus)1 ApiClonedControlledGcpBigQueryDataset (bio.terra.workspace.generated.model.ApiClonedControlledGcpBigQueryDataset)1 ApiClonedWorkspace (bio.terra.workspace.generated.model.ApiClonedWorkspace)1 ApiCreatedControlledGcpGcsBucket (bio.terra.workspace.generated.model.ApiCreatedControlledGcpGcsBucket)1 ApiResourceCloneDetails (bio.terra.workspace.generated.model.ApiResourceCloneDetails)1 ApiResourceMetadata (bio.terra.workspace.generated.model.ApiResourceMetadata)1