use of bio.terra.workspace.service.buffer.exception.BufferServiceAuthorizationException 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.workspace.service.buffer.exception.BufferServiceAuthorizationException 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);
}
}
}
use of bio.terra.workspace.service.buffer.exception.BufferServiceAuthorizationException 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);
}
}
}
Aggregations