use of bio.terra.buffer.model.HandoutRequestBody in project terra-workspace-manager by DataBiosphere.
the class PullProjectFromPoolStep method doStep.
@Override
public StepResult doStep(FlightContext flightContext) {
try {
String resourceId = flightContext.getWorkingMap().get(RBS_RESOURCE_ID, String.class);
logger.info("Preparing to query Buffer Service for resource with ID: " + resourceId);
HandoutRequestBody body = new HandoutRequestBody();
body.setHandoutRequestId(resourceId);
ResourceInfo info = bufferService.handoutResource(body);
String projectId = info.getCloudResourceUid().getGoogleProjectUid().getProjectId();
logger.info("Buffer Service returned project with id: " + projectId);
flightContext.getWorkingMap().put(GCP_PROJECT_ID, projectId);
return StepResult.getStepResultSuccess();
} catch (BufferServiceAPIException e) {
// must retry. Retrying TOO_MANY_REQUESTS gives the service time to recover from load.
if (e.getStatusCode() == HttpStatus.NOT_FOUND || e.getStatusCode() == HttpStatus.TOO_MANY_REQUESTS) {
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, e);
} catch (BufferServiceAuthorizationException e) {
// If authorization fails, there is no recovering
return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, e);
}
}
use of bio.terra.buffer.model.HandoutRequestBody in project terra-resource-buffer by DataBiosphere.
the class BufferServiceUtils method retryHandout.
/**
* Retries Handout resource API if resource is no resource is available.
*/
public static String retryHandout(BufferApi bufferApi, String handoutRequestId) throws InterruptedException, ApiException {
int numAttempts = 1;
int maxNumAttempts = 5;
while (numAttempts <= maxNumAttempts) {
try {
return bufferApi.handoutResource(new HandoutRequestBody().handoutRequestId(handoutRequestId), POOL_ID).getCloudResourceUid().getGoogleProjectUid().getProjectId();
} catch (ApiException e) {
// Only retry when resource is not available (404).
if (e.getCode() != 404) {
throw e;
}
logger.info("No resource available, retrying... Attempts so far: {}", numAttempts, e);
}
++numAttempts;
TimeUnit.SECONDS.sleep(5);
}
throw new InterruptedException("Exceeds maximum number of retries.");
}
Aggregations