Search in sources :

Example 1 with BufferApi

use of bio.terra.buffer.api.BufferApi in project terra-resource-buffer by DataBiosphere.

the class HandoutResource method userJourney.

@Override
public void userJourney(TestUserSpecification testUser) throws Exception {
    ApiClient apiClient = BufferServiceUtils.getClient(server);
    BufferApi bufferApi = new BufferApi(apiClient);
    String handoutRequestId = UUID.randomUUID().toString();
    logger.info("Generated handoutRequestId: {}", handoutRequestId);
    String projectId = retryHandout(bufferApi, handoutRequestId);
    successCount++;
    logger.info("project Id: {} for handoutRequestId: {}", projectId, handoutRequestId);
}
Also used : BufferApi(bio.terra.buffer.api.BufferApi) ApiClient(bio.terra.buffer.client.ApiClient)

Example 2 with BufferApi

use of bio.terra.buffer.api.BufferApi in project terra-resource-buffer by DataBiosphere.

the class HandoutResource method setup.

@Override
public void setup(List<TestUserSpecification> testUsers) throws Exception {
    // Verify pool is full before the test. If pool is not empty, poll until it is full.
    ApiClient apiClient = BufferServiceUtils.getClient(server);
    BufferApi bufferApi = new BufferApi(apiClient);
    poolSize = bufferApi.getPoolInfo(POOL_ID).getPoolConfig().getSize();
    // Poll until pool is full.
    pollUntilResourceCountExceeds(server, Duration.ofMinutes(30), poolSize);
    assertThat(bufferApi.getPoolInfo(POOL_ID).getResourceStateCount().get("READY"), greaterThanOrEqualTo(poolSize));
    beforeCount = bufferApi.getPoolInfo(POOL_ID).getResourceStateCount().get("READY");
}
Also used : BufferApi(bio.terra.buffer.api.BufferApi) ApiClient(bio.terra.buffer.client.ApiClient)

Example 3 with BufferApi

use of bio.terra.buffer.api.BufferApi in project terra-resource-buffer by DataBiosphere.

the class UnauthorizedAccess method userJourney.

@Override
public void userJourney(TestUserSpecification testUser) throws Exception {
    ApiClient apiClient = BufferServiceUtils.getClient(server);
    BufferApi bufferApi = new BufferApi(apiClient);
    try {
        retryHandout(bufferApi, UUID.randomUUID().toString());
        assertThat("Invalid SA account access not throwing exception", false);
    } catch (ApiException apiEx) {
        assertThat(apiEx.getCode(), equalTo(401));
    }
}
Also used : BufferApi(bio.terra.buffer.api.BufferApi) ApiClient(bio.terra.buffer.client.ApiClient) ApiException(bio.terra.buffer.client.ApiException)

Example 4 with BufferApi

use of bio.terra.buffer.api.BufferApi 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 5 with BufferApi

use of bio.terra.buffer.api.BufferApi 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

BufferApi (bio.terra.buffer.api.BufferApi)7 ApiClient (bio.terra.buffer.client.ApiClient)5 ApiException (bio.terra.buffer.client.ApiException)4 PoolInfo (bio.terra.buffer.model.PoolInfo)3 BufferServiceAPIException (bio.terra.workspace.service.buffer.exception.BufferServiceAPIException)2 BufferServiceAuthorizationException (bio.terra.workspace.service.buffer.exception.BufferServiceAuthorizationException)2 IOException (java.io.IOException)2 ResourceInfo (bio.terra.buffer.model.ResourceInfo)1 Traced (io.opencensus.contrib.spring.aop.Traced)1 Instant (java.time.Instant)1