Search in sources :

Example 1 with ResourceInfo

use of bio.terra.buffer.model.ResourceInfo 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);
    }
}
Also used : ResourceInfo(bio.terra.buffer.model.ResourceInfo) BufferServiceAPIException(bio.terra.workspace.service.buffer.exception.BufferServiceAPIException) HandoutRequestBody(bio.terra.buffer.model.HandoutRequestBody) BufferServiceAuthorizationException(bio.terra.workspace.service.buffer.exception.BufferServiceAuthorizationException) StepResult(bio.terra.stairway.StepResult)

Example 2 with ResourceInfo

use of bio.terra.buffer.model.ResourceInfo in project terra-workspace-manager by DataBiosphere.

the class BufferService method handoutResource.

/**
 * Retrieve a single resource from the Buffer Service. The instance and pool are already
 * configured.
 *
 * @param requestBody
 * @return ResourceInfo
 */
public ResourceInfo handoutResource(HandoutRequestBody requestBody) {
    try {
        BufferApi bufferApi = bufferApi(bufferServiceConfiguration.getInstanceUrl());
        ResourceInfo info = bufferApi.handoutResource(requestBody, bufferServiceConfiguration.getPoolId());
        logger.info("Retrieved resource from pool {} on Buffer Service instance {}", bufferServiceConfiguration.getPoolId(), bufferServiceConfiguration.getInstanceUrl());
        return info;
    } catch (IOException e) {
        throw new BufferServiceAuthorizationException(String.format("Error reading or parsing credentials file at %s", bufferServiceConfiguration.getClientCredentialFilePath()), e.getCause());
    } catch (ApiException e) {
        if (e.getCode() == HttpStatus.UNAUTHORIZED.value()) {
            throw new BufferServiceAuthorizationException("Not authorized to access Buffer Service", e.getCause());
        } else {
            throw new BufferServiceAPIException(e);
        }
    }
}
Also used : ResourceInfo(bio.terra.buffer.model.ResourceInfo) BufferServiceAPIException(bio.terra.workspace.service.buffer.exception.BufferServiceAPIException) BufferApi(bio.terra.buffer.api.BufferApi) BufferServiceAuthorizationException(bio.terra.workspace.service.buffer.exception.BufferServiceAuthorizationException) IOException(java.io.IOException) ApiException(bio.terra.buffer.client.ApiException)

Aggregations

ResourceInfo (bio.terra.buffer.model.ResourceInfo)2 BufferServiceAPIException (bio.terra.workspace.service.buffer.exception.BufferServiceAPIException)2 BufferServiceAuthorizationException (bio.terra.workspace.service.buffer.exception.BufferServiceAuthorizationException)2 BufferApi (bio.terra.buffer.api.BufferApi)1 ApiException (bio.terra.buffer.client.ApiException)1 HandoutRequestBody (bio.terra.buffer.model.HandoutRequestBody)1 StepResult (bio.terra.stairway.StepResult)1 IOException (java.io.IOException)1