use of bio.terra.workspace.service.resource.controlled.exception.BucketDeleteTimeoutException in project terra-workspace-manager by DataBiosphere.
the class DeleteGcsBucketStep method doStep.
@Override
public StepResult doStep(FlightContext flightContext) throws InterruptedException {
int deleteTries = 0;
final GcpCloudContext gcpCloudContext = FlightUtils.getRequired(flightContext.getWorkingMap(), ControlledResourceKeys.GCP_CLOUD_CONTEXT, GcpCloudContext.class);
final StorageCow storageCow = crlService.createStorageCow(gcpCloudContext.getGcpProjectId());
// If the bucket is already deleted (e.g. this step is being retried), storageCow.get() will
// return null.
BucketCow bucket = storageCow.get(resource.getBucketName());
boolean bucketExists = bucket != null;
while (bucketExists) {
// We always replace the lifecycle rules. This covers the case where the step is rerun
// and covers the case where the rules are changed out of band of this operation.
BucketCow bucketCow = bucket.toBuilder().setLifecycleRules(ImmutableList.of(new BucketInfo.LifecycleRule(BucketInfo.LifecycleRule.LifecycleAction.newDeleteAction(), BucketInfo.LifecycleRule.LifecycleCondition.newBuilder().setAge(0).build()))).build();
bucket = bucketCow.update();
bucketExists = tryBucketDelete(bucket);
if (bucketExists) {
TimeUnit.HOURS.sleep(1);
}
deleteTries++;
if (deleteTries >= MAX_DELETE_TRIES) {
// This will cause the flight to fail.
throw new BucketDeleteTimeoutException(String.format("Failed to delete bucket after %d tries", MAX_DELETE_TRIES));
}
}
return StepResult.getStepResultSuccess();
}
Aggregations