use of bio.terra.buffer.model.PoolInfo 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);
}
}
}
use of bio.terra.buffer.model.PoolInfo in project terra-resource-buffer by DataBiosphere.
the class GetPoolInfo method userJourney.
@Override
public void userJourney(TestUserSpecification testUser) throws Exception {
ApiClient apiClient = BufferServiceUtils.getClient(server);
BufferApi bufferApi = new BufferApi(apiClient);
// TODO: is there a valid pool id that I could use here instead of expecting failure?
try {
PoolInfo poolInfo = bufferApi.getPoolInfo("123");
logger.debug("poolInfo: {}", poolInfo);
assertThat("GET pool info did not throw not found exception", false);
} catch (ApiException apiEx) {
logger.debug("Caught exception fetching pool info", apiEx);
assertThat("Exception text reason", apiEx.getResponseBody().contains("Pool 123 not found"));
}
int httpCode = bufferApi.getApiClient().getStatusCode();
logger.info("GET pool info HTTP code: {}", httpCode);
assertThat(httpCode, equalTo(404));
}
use of bio.terra.buffer.model.PoolInfo in project terra-resource-buffer by DataBiosphere.
the class HandoutResource method cleanup.
@Override
public void cleanup(List<TestUserSpecification> testUsers) throws Exception {
logger.info("Success count: {}", successCount);
// For now we verifies all RESOURCE_COUNT calls successfully. Not sure that is too ideal or we
// want to set some threshold like we allow 0.1% failure rate is allowable in this burst case.
PoolInfo poolInfo = pollUntilResourceCountExceeds(server, Duration.ofHours(2), beforeCount);
assertThat(poolInfo.getResourceStateCount().get("CREATING"), equalTo(0));
assertThat(poolInfo.getResourceStateCount().get("READY"), greaterThanOrEqualTo(poolSize));
}
use of bio.terra.buffer.model.PoolInfo in project terra-resource-buffer by DataBiosphere.
the class BufferServiceUtils method pollUntilResourceCountExceeds.
/**
* Poll pool info from Buffer Service until READY resource is more than expect number.
*/
public static PoolInfo pollUntilResourceCountExceeds(ServerSpecification server, Duration timeout, int mimimumSize) throws InterruptedException, ApiException, IOException {
Instant deadline = Instant.now().plus(timeout);
int count = 0;
while (true) {
ApiClient apiClient = BufferServiceUtils.getClient(server);
BufferApi bufferApi = new BufferApi(apiClient);
count++;
PoolInfo poolInfo = bufferApi.getPoolInfo(POOL_ID);
logger.info("Total polling count: {}, poolInfo: {}", count, poolInfo);
if (poolInfo.getResourceStateCount().get("READY") >= mimimumSize) {
logger.info("Done after {} times poll. ", count);
return poolInfo;
}
if (Instant.now().plus(POLLING_INTERVAL).isAfter(deadline)) {
throw new InterruptedException("Timeout during pollUntilPoolFull");
}
Thread.sleep(POLLING_INTERVAL.toMillis());
}
}
Aggregations