Search in sources :

Example 21 with Traced

use of io.opencensus.contrib.spring.aop.Traced in project terra-workspace-manager by DataBiosphere.

the class SamService method deleteControlledResource.

/**
 * Delete controlled resource with an access token
 *
 * @param resource the controlled resource whose Sam resource to delete
 * @param token access token
 * @throws InterruptedException on thread interrupt
 */
@Traced
public void deleteControlledResource(ControlledResource resource, String token) throws InterruptedException {
    ResourcesApi resourceApi = samResourcesApi(token);
    try {
        SamRetry.retry(() -> resourceApi.deleteResourceV2(resource.getCategory().getSamResourceName(), resource.getResourceId().toString()));
        logger.info("Deleted Sam controlled resource {}", resource.getResourceId());
    } catch (ApiException apiException) {
        // Do nothing if the resource to delete is not found, this may not be the first time delete is
        // called. Other exceptions still need to be surfaced.
        logger.info("Sam API error while deleting a controlled resource, code is " + apiException.getCode());
        if (apiException.getCode() == HttpStatus.NOT_FOUND.value()) {
            logger.info("Sam error was NOT_FOUND on a deletion call. " + "This just means the deletion was tried twice so no error thrown.");
            return;
        }
        throw SamExceptionFactory.create("Error deleting controlled resource in Sam", apiException);
    }
}
Also used : ResourcesApi(org.broadinstitute.dsde.workbench.client.sam.api.ResourcesApi) ApiException(org.broadinstitute.dsde.workbench.client.sam.ApiException) Traced(io.opencensus.contrib.spring.aop.Traced)

Example 22 with Traced

use of io.opencensus.contrib.spring.aop.Traced in project terra-workspace-manager by DataBiosphere.

the class JobService method retrieveJob.

@Traced
public ApiJobReport retrieveJob(String jobId, AuthenticatedUserRequest userRequest) {
    try {
        // jobId=flightId
        verifyUserAccess(jobId, userRequest);
        FlightState flightState = stairwayComponent.get().getFlightState(jobId);
        return mapFlightStateToApiJobReport(flightState);
    } catch (StairwayException | InterruptedException stairwayEx) {
        throw new InternalStairwayException(stairwayEx);
    }
}
Also used : FlightState(bio.terra.stairway.FlightState) StairwayException(bio.terra.stairway.exception.StairwayException) InternalStairwayException(bio.terra.workspace.service.job.exception.InternalStairwayException) InternalStairwayException(bio.terra.workspace.service.job.exception.InternalStairwayException) Traced(io.opencensus.contrib.spring.aop.Traced)

Example 23 with Traced

use of io.opencensus.contrib.spring.aop.Traced 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

Traced (io.opencensus.contrib.spring.aop.Traced)23 ApiException (org.broadinstitute.dsde.workbench.client.sam.ApiException)11 ResourcesApi (org.broadinstitute.dsde.workbench.client.sam.api.ResourcesApi)11 Workspace (bio.terra.workspace.service.workspace.model.Workspace)5 JobBuilder (bio.terra.workspace.service.job.JobBuilder)3 CreateResourceRequestV2 (org.broadinstitute.dsde.workbench.client.sam.model.CreateResourceRequestV2)3 ForbiddenException (bio.terra.common.exception.ForbiddenException)2 ControlledResource (bio.terra.workspace.service.resource.controlled.model.ControlledResource)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 BufferApi (bio.terra.buffer.api.BufferApi)1 ApiException (bio.terra.buffer.client.ApiException)1 PoolInfo (bio.terra.buffer.model.PoolInfo)1 ServiceAccountName (bio.terra.cloudres.google.iam.ServiceAccountName)1 InternalServerErrorException (bio.terra.common.exception.InternalServerErrorException)1 SamRetry (bio.terra.common.sam.SamRetry)1 SamExceptionFactory (bio.terra.common.sam.exception.SamExceptionFactory)1 RepositoryApi (bio.terra.datarepo.api.RepositoryApi)1 ApiException (bio.terra.datarepo.client.ApiException)1