Search in sources :

Example 1 with GoogleBucketResource

use of bio.terra.service.resourcemanagement.google.GoogleBucketResource 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 GoogleBucketResource

use of bio.terra.service.resourcemanagement.google.GoogleBucketResource in project jade-data-repo by DataBiosphere.

the class IngestFilePrimaryDataLocationStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException {
    FlightMap workingMap = context.getWorkingMap();
    Boolean loadComplete = workingMap.get(FileMapKeys.LOAD_COMPLETED, Boolean.class);
    if (loadComplete == null || !loadComplete) {
        try {
            GoogleBucketResource bucketForFile = locationService.getOrCreateBucketForFile(profileId, context.getFlightId());
            workingMap.put(FileMapKeys.BUCKET_INFO, bucketForFile);
        } catch (BucketLockException blEx) {
            return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, blEx);
        }
    }
    return StepResult.getStepResultSuccess();
}
Also used : GoogleBucketResource(bio.terra.service.resourcemanagement.google.GoogleBucketResource) FlightMap(bio.terra.stairway.FlightMap) StepResult(bio.terra.stairway.StepResult) BucketLockException(bio.terra.service.resourcemanagement.exception.BucketLockException)

Example 3 with GoogleBucketResource

use of bio.terra.service.resourcemanagement.google.GoogleBucketResource in project jade-data-repo by DataBiosphere.

the class IngestFilePrimaryDataStep method undoStep.

@Override
public StepResult undoStep(FlightContext context) {
    FlightMap workingMap = context.getWorkingMap();
    String fileId = workingMap.get(FileMapKeys.FILE_ID, String.class);
    GoogleBucketResource bucketResource = workingMap.get(FileMapKeys.BUCKET_INFO, GoogleBucketResource.class);
    gcsPdao.deleteFileById(dataset, fileId, bucketResource);
    return StepResult.getStepResultSuccess();
}
Also used : GoogleBucketResource(bio.terra.service.resourcemanagement.google.GoogleBucketResource) FlightMap(bio.terra.stairway.FlightMap)

Example 4 with GoogleBucketResource

use of bio.terra.service.resourcemanagement.google.GoogleBucketResource in project jade-data-repo by DataBiosphere.

the class DeleteFilePrimaryDataStep method doStep.

@Override
public StepResult doStep(FlightContext context) {
    FlightMap workingMap = context.getWorkingMap();
    FireStoreFile fireStoreFile = workingMap.get(FileMapKeys.FIRESTORE_FILE, FireStoreFile.class);
    if (fireStoreFile != null) {
        GoogleBucketResource bucketResource = locationService.lookupBucket(fireStoreFile.getBucketResourceId());
        gcsPdao.deleteFileByGspath(fireStoreFile.getGspath(), bucketResource);
    }
    return StepResult.getStepResultSuccess();
}
Also used : FireStoreFile(bio.terra.service.filedata.google.firestore.FireStoreFile) GoogleBucketResource(bio.terra.service.resourcemanagement.google.GoogleBucketResource) FlightMap(bio.terra.stairway.FlightMap)

Example 5 with GoogleBucketResource

use of bio.terra.service.resourcemanagement.google.GoogleBucketResource in project jade-data-repo by DataBiosphere.

the class GcsPdao method deleteFile.

// Consumer method for deleting GCS files driven from a scan over the firestore files
public void deleteFile(FireStoreFile fireStoreFile) {
    if (fireStoreFile != null) {
        GoogleBucketResource bucketResource = dataLocationService.lookupBucket(fireStoreFile.getBucketResourceId());
        deleteFileByGspath(fireStoreFile.getGspath(), bucketResource);
    }
}
Also used : GoogleBucketResource(bio.terra.service.resourcemanagement.google.GoogleBucketResource)

Aggregations

GoogleBucketResource (bio.terra.service.resourcemanagement.google.GoogleBucketResource)14 FlightMap (bio.terra.stairway.FlightMap)5 GoogleBucketRequest (bio.terra.service.resourcemanagement.google.GoogleBucketRequest)4 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Bucket (com.google.cloud.storage.Bucket)3 GoogleResourceNotFoundException (bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException)2 CorruptMetadataException (bio.terra.service.snapshot.exception.CorruptMetadataException)2 StepResult (bio.terra.stairway.StepResult)2 DRSAccessMethod (bio.terra.model.DRSAccessMethod)1 DRSAccessURL (bio.terra.model.DRSAccessURL)1 DRSObject (bio.terra.model.DRSObject)1 FileLoadModel (bio.terra.model.FileLoadModel)1 FSFile (bio.terra.service.filedata.FSFile)1 FSFileInfo (bio.terra.service.filedata.FSFileInfo)1 FSItem (bio.terra.service.filedata.FSItem)1 FireStoreFile (bio.terra.service.filedata.google.firestore.FireStoreFile)1 LoadCandidates (bio.terra.service.load.LoadCandidates)1 BucketLockException (bio.terra.service.resourcemanagement.exception.BucketLockException)1 DatabaseOperationException (bio.terra.stairway.exception.DatabaseOperationException)1