Search in sources :

Example 1 with BufferServiceAPIException

use of bio.terra.workspace.service.buffer.exception.BufferServiceAPIException 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 BufferServiceAPIException

use of bio.terra.workspace.service.buffer.exception.BufferServiceAPIException 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)

Example 3 with BufferServiceAPIException

use of bio.terra.workspace.service.buffer.exception.BufferServiceAPIException in project terra-workspace-manager by DataBiosphere.

the class BufferService method getPoolInfo.

/**
 * Return the PoolInfo object for the ResourceBuffer pool that we are using to create Google Cloud
 * projects. Note that this is configured once per Workspace Manager instance (both the instance
 * of RBS to use and which pool) so no configuration happens here.
 *
 * @return PoolInfo
 */
@Traced
public PoolInfo getPoolInfo() {
    try {
        BufferApi bufferApi = bufferApi(bufferServiceConfiguration.getInstanceUrl());
        PoolInfo info = bufferApi.getPoolInfo(bufferServiceConfiguration.getPoolId());
        logger.info("Retrieved pool {} on Buffer Service instance {}", bufferServiceConfiguration.getPoolId(), bufferServiceConfiguration.getInstanceUrl());
        return info;
    } catch (IOException e) {
        throw new BufferServiceAuthorizationException("Error reading or parsing credentials file", 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 : BufferServiceAPIException(bio.terra.workspace.service.buffer.exception.BufferServiceAPIException) BufferApi(bio.terra.buffer.api.BufferApi) BufferServiceAuthorizationException(bio.terra.workspace.service.buffer.exception.BufferServiceAuthorizationException) PoolInfo(bio.terra.buffer.model.PoolInfo) IOException(java.io.IOException) ApiException(bio.terra.buffer.client.ApiException) Traced(io.opencensus.contrib.spring.aop.Traced)

Aggregations

BufferServiceAPIException (bio.terra.workspace.service.buffer.exception.BufferServiceAPIException)3 BufferServiceAuthorizationException (bio.terra.workspace.service.buffer.exception.BufferServiceAuthorizationException)3 BufferApi (bio.terra.buffer.api.BufferApi)2 ApiException (bio.terra.buffer.client.ApiException)2 ResourceInfo (bio.terra.buffer.model.ResourceInfo)2 IOException (java.io.IOException)2 HandoutRequestBody (bio.terra.buffer.model.HandoutRequestBody)1 PoolInfo (bio.terra.buffer.model.PoolInfo)1 StepResult (bio.terra.stairway.StepResult)1 Traced (io.opencensus.contrib.spring.aop.Traced)1