Search in sources :

Example 1 with StairwayExecutionException

use of bio.terra.stairway.exception.StairwayExecutionException in project jade-data-repo by DataBiosphere.

the class IngestDriverStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException {
    // Gather inputs
    FlightMap workingMap = context.getWorkingMap();
    String loadIdString = workingMap.get(LoadMapKeys.LOAD_ID, String.class);
    UUID loadId = UUID.fromString(loadIdString);
    GoogleBucketResource bucketResource = workingMap.get(FileMapKeys.BUCKET_INFO, GoogleBucketResource.class);
    try {
        // Check for launch orphans - these are loads in the RUNNING state that never
        // got recorded by stairway.
        checkForOrphans(context, loadId);
        // Load Loop
        while (true) {
            int podCount = kubeService.getActivePodCount();
            int concurrentFiles = configurationService.getParameterValue(ConfigEnum.LOAD_CONCURRENT_FILES);
            int scaledConcurrentFiles = podCount * concurrentFiles;
            // Get the state of active and failed loads
            LoadCandidates candidates = getLoadCandidates(context, loadId, scaledConcurrentFiles);
            int currentRunning = candidates.getRunningLoads().size();
            int candidateCount = candidates.getCandidateFiles().size();
            if (currentRunning == 0 && candidateCount == 0) {
                // Nothing doing and nothing to do
                break;
            }
            // Test for exceeding max failed loads; if so, wait for all RUNNINGs to finish
            if (candidates.getFailedLoads() > maxFailedFileLoads) {
                waitForAll(context, loadId, scaledConcurrentFiles);
                break;
            }
            // Launch new loads
            if (currentRunning < scaledConcurrentFiles) {
                // Compute how many loads to launch
                int launchCount = scaledConcurrentFiles - currentRunning;
                if (candidateCount < launchCount) {
                    launchCount = candidateCount;
                }
                launchLoads(context, launchCount, candidates.getCandidateFiles(), profileId, loadId, bucketResource);
                currentRunning += launchCount;
            }
            // Wait until some loads complete
            waitForAny(context, loadId, scaledConcurrentFiles, currentRunning);
        }
    } catch (DatabaseOperationException | StairwayExecutionException ex) {
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, ex);
    }
    return StepResult.getStepResultSuccess();
}
Also used : GoogleBucketResource(bio.terra.service.resourcemanagement.google.GoogleBucketResource) DatabaseOperationException(bio.terra.stairway.exception.DatabaseOperationException) LoadCandidates(bio.terra.service.load.LoadCandidates) StairwayExecutionException(bio.terra.stairway.exception.StairwayExecutionException) FlightMap(bio.terra.stairway.FlightMap) UUID(java.util.UUID) StepResult(bio.terra.stairway.StepResult)

Example 2 with StairwayExecutionException

use of bio.terra.stairway.exception.StairwayExecutionException in project terra-workspace-manager by DataBiosphere.

the class LaunchCloneGcsBucketResourceFlightStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
    validateRequiredEntries(context.getInputParameters(), JobMapKeys.AUTH_USER_INFO.getKeyName(), ControlledResourceKeys.DESTINATION_WORKSPACE_ID);
    @Nullable final var location = context.getInputParameters().get(ControlledResourceKeys.LOCATION, String.class);
    final var userRequest = context.getInputParameters().get(JobMapKeys.AUTH_USER_INFO.getKeyName(), AuthenticatedUserRequest.class);
    final var destinationWorkspaceId = context.getInputParameters().get(ControlledResourceKeys.DESTINATION_WORKSPACE_ID, UUID.class);
    // Gather input parameters for flight. See
    // bio.terra.workspace.service.resource.controlled.ControlledResourceService#cloneGcsBucket.
    final FlightMap subflightInputParameters = new FlightMap();
    subflightInputParameters.put(ControlledResourceKeys.LOCATION, location);
    subflightInputParameters.put(ControlledResourceKeys.DESTINATION_WORKSPACE_ID, destinationWorkspaceId);
    subflightInputParameters.put(JobMapKeys.AUTH_USER_INFO.getKeyName(), userRequest);
    subflightInputParameters.put(ResourceKeys.RESOURCE, resource);
    subflightInputParameters.put(ControlledResourceKeys.CLONING_INSTRUCTIONS, resource.getCloningInstructions());
    // submit flight
    try {
        context.getStairway().submit(subflightId, CloneControlledGcsBucketResourceFlight.class, subflightInputParameters);
    } catch (DuplicateFlightIdException unused) {
        return StepResult.getStepResultSuccess();
    } catch (DatabaseOperationException | StairwayExecutionException e) {
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
    }
    return StepResult.getStepResultSuccess();
}
Also used : DatabaseOperationException(bio.terra.stairway.exception.DatabaseOperationException) StairwayExecutionException(bio.terra.stairway.exception.StairwayExecutionException) FlightMap(bio.terra.stairway.FlightMap) StepResult(bio.terra.stairway.StepResult) Nullable(javax.annotation.Nullable) DuplicateFlightIdException(bio.terra.stairway.exception.DuplicateFlightIdException)

Example 3 with StairwayExecutionException

use of bio.terra.stairway.exception.StairwayExecutionException in project terra-workspace-manager by DataBiosphere.

the class LaunchCreateReferenceResourceFlightStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
    if (CloningInstructions.COPY_REFERENCE != resource.getCloningInstructions()) {
        // Nothing to do -- don't launch flight
        return StepResult.getStepResultSuccess();
    }
    FlightUtils.validateRequiredEntries(context.getInputParameters(), ControlledResourceKeys.DESTINATION_WORKSPACE_ID, JobMapKeys.AUTH_USER_INFO.getKeyName());
    final var destinationWorkspaceId = context.getInputParameters().get(ControlledResourceKeys.DESTINATION_WORKSPACE_ID, UUID.class);
    final var userRequest = context.getInputParameters().get(JobMapKeys.AUTH_USER_INFO.getKeyName(), AuthenticatedUserRequest.class);
    final String description = String.format("Clone of Referenced Resource %s", resource.getResourceId());
    final ReferencedResource destinationResource = WorkspaceCloneUtils.buildDestinationReferencedResource(resource, destinationWorkspaceId, null, description);
    // put the destination resource in the map, because it's not communicated
    // from the flight as the response (and we need the workspace ID)
    context.getWorkingMap().put(ControlledResourceKeys.DESTINATION_REFERENCED_RESOURCE, destinationResource);
    final FlightMap subflightInputParameters = new FlightMap();
    subflightInputParameters.put(ResourceKeys.RESOURCE, destinationResource);
    subflightInputParameters.put(JobMapKeys.AUTH_USER_INFO.getKeyName(), userRequest);
    subflightInputParameters.put(WorkspaceFlightMapKeys.ResourceKeys.RESOURCE_TYPE, resource.getResourceType().name());
    try {
        context.getStairway().submit(subflightId, CreateReferenceResourceFlight.class, subflightInputParameters);
    } catch (DatabaseOperationException | StairwayExecutionException e) {
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
    } catch (DuplicateFlightIdException unused) {
        // already submitted the flight - treat as success
        return StepResult.getStepResultSuccess();
    }
    FlightUtils.validateRequiredEntries(context.getWorkingMap(), ControlledResourceKeys.DESTINATION_REFERENCED_RESOURCE);
    return StepResult.getStepResultSuccess();
}
Also used : ReferencedResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource) DatabaseOperationException(bio.terra.stairway.exception.DatabaseOperationException) StairwayExecutionException(bio.terra.stairway.exception.StairwayExecutionException) FlightMap(bio.terra.stairway.FlightMap) StepResult(bio.terra.stairway.StepResult) DuplicateFlightIdException(bio.terra.stairway.exception.DuplicateFlightIdException)

Example 4 with StairwayExecutionException

use of bio.terra.stairway.exception.StairwayExecutionException in project terra-resource-buffer by DataBiosphere.

the class FlightManagerTest method setup.

@BeforeEach
public void setup() throws Exception {
    when(mockStairwayComponent.get()).thenReturn(mockStairway);
    when(mockStairway.createFlightId()).thenReturn("flightId");
    doThrow(new StairwayExecutionException("test")).when(mockStairway).submitToQueue(anyString(), any(), any());
    flightManager = new FlightManager(bufferDao, flightSubmissionFactory, mockStairwayComponent, transactionTemplate);
}
Also used : StairwayExecutionException(bio.terra.stairway.exception.StairwayExecutionException) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with StairwayExecutionException

use of bio.terra.stairway.exception.StairwayExecutionException in project terra-workspace-manager by DataBiosphere.

the class LaunchCloneControlledGcpBigQueryDatasetResourceFlightStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
    validateRequiredEntries(context.getInputParameters(), JobMapKeys.AUTH_USER_INFO.getKeyName(), ControlledResourceKeys.DESTINATION_WORKSPACE_ID);
    final var userRequest = context.getInputParameters().get(JobMapKeys.AUTH_USER_INFO.getKeyName(), AuthenticatedUserRequest.class);
    final var destinationWorkspaceId = context.getInputParameters().get(ControlledResourceKeys.DESTINATION_WORKSPACE_ID, UUID.class);
    @Nullable final var location = context.getInputParameters().get(ControlledResourceKeys.LOCATION, String.class);
    // build input parameter map. Leave out resource name, description, and dataset name so that
    // they will take values from the source dataset.
    final var subflightInputParameters = new FlightMap();
    subflightInputParameters.put(JobMapKeys.AUTH_USER_INFO.getKeyName(), userRequest);
    subflightInputParameters.put(ControlledResourceKeys.DESTINATION_WORKSPACE_ID, destinationWorkspaceId);
    subflightInputParameters.put(ControlledResourceKeys.LOCATION, location);
    subflightInputParameters.put(ControlledResourceKeys.CLONING_INSTRUCTIONS, resource.getCloningInstructions());
    subflightInputParameters.put(ResourceKeys.RESOURCE, resource);
    subflightInputParameters.put(ControlledResourceKeys.LOCATION, location);
    // launch the flight
    try {
        context.getStairway().submit(subflightId, CloneControlledGcpBigQueryDatasetResourceFlight.class, subflightInputParameters);
    } catch (DuplicateFlightIdException unused) {
        return StepResult.getStepResultSuccess();
    } catch (DatabaseOperationException | StairwayExecutionException e) {
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
    }
    return StepResult.getStepResultSuccess();
}
Also used : DatabaseOperationException(bio.terra.stairway.exception.DatabaseOperationException) StairwayExecutionException(bio.terra.stairway.exception.StairwayExecutionException) FlightMap(bio.terra.stairway.FlightMap) StepResult(bio.terra.stairway.StepResult) Nullable(javax.annotation.Nullable) DuplicateFlightIdException(bio.terra.stairway.exception.DuplicateFlightIdException)

Aggregations

StairwayExecutionException (bio.terra.stairway.exception.StairwayExecutionException)6 FlightMap (bio.terra.stairway.FlightMap)5 StepResult (bio.terra.stairway.StepResult)5 DatabaseOperationException (bio.terra.stairway.exception.DatabaseOperationException)5 DuplicateFlightIdException (bio.terra.stairway.exception.DuplicateFlightIdException)4 Nullable (javax.annotation.Nullable)2 LoadCandidates (bio.terra.service.load.LoadCandidates)1 GoogleBucketResource (bio.terra.service.resourcemanagement.google.GoogleBucketResource)1 ReferencedResource (bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource)1 UUID (java.util.UUID)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1