use of bio.terra.buffer.generated.model.CloudResourceUid in project terra-resource-buffer by DataBiosphere.
the class CleanupSchedulerTest method testScheduleCleanup.
@Test
public void testScheduleCleanup() throws Exception {
Pool pool = Pool.builder().creation(CREATION).id(PoolId.create("poolId")).resourceType(ResourceType.GOOGLE_PROJECT).size(1).resourceConfig(new ResourceConfig()).status(PoolStatus.ACTIVE).build();
CloudResourceUid cloudResourceUid = new CloudResourceUid().googleProjectUid(new GoogleProjectUid().projectId("p1"));
Resource resource = Resource.builder().id(ResourceId.create(UUID.randomUUID())).poolId(pool.id()).creation(Instant.now()).state(ResourceState.CREATING).build();
bufferDao.createPools(ImmutableList.of(pool));
bufferDao.createResource(resource);
bufferDao.updateResourceAsReady(resource.id(), cloudResourceUid);
bufferDao.updateOneReadyResourceToHandedOut(pool.id(), RequestHandoutId.create("1111"));
assertEquals(1, bufferDao.retrieveResourceToCleanup(10).size());
cleanupScheduler.initialize();
Thread.sleep(1000);
verify(mockPublisher).publish(messageArgumentCaptor.capture());
assertThat(messageArgumentCaptor.getAllValues().stream().map(m -> m.getData().toStringUtf8()).collect(Collectors.toList()), Matchers.containsInAnyOrder(objectMapper.writeValueAsString(new CreateResourceRequestBody().creation(CREATION.atOffset(ZoneOffset.UTC)).expiration(CREATION.plus(crlConfiguration.getTestResourceTimeToLive()).atOffset(ZoneOffset.UTC)).putLabelsItem("client", CLIENT_NAME).resourceUid(new bio.terra.janitor.model.CloudResourceUid().googleProjectUid(new bio.terra.janitor.model.GoogleProjectUid().projectId("p1"))))));
assertTrue(bufferDao.retrieveResourceToCleanup(10).isEmpty());
}
use of bio.terra.buffer.generated.model.CloudResourceUid in project terra-resource-buffer by DataBiosphere.
the class PoolServiceTest method handoutResource_success.
@Test
public void handoutResource_success() throws Exception {
PoolId poolId = PoolId.create("poolId");
RequestHandoutId requestHandoutId = RequestHandoutId.create("handoutId");
newReadyPool(poolId, 2);
List<CloudResourceUid> resourceUids = bufferDao.retrieveResourcesRandomly(poolId, ResourceState.READY, 2).stream().map(Resource::cloudResourceUid).collect(Collectors.toList());
ResourceInfo resourceInfo = poolService.handoutResource(poolId, requestHandoutId);
assertEquals(poolId.id(), resourceInfo.getPoolId());
assertEquals(requestHandoutId.id(), resourceInfo.getRequestHandoutId());
// CloudResource may be either of the two resources.
assertTrue(resourceInfo.getCloudResourceUid().equals(resourceUids.get(0)) || resourceInfo.getCloudResourceUid().equals(resourceUids.get(1)));
// Use the same requestHandoutId, expect to get the same resource back.
ResourceInfo secondResourceInfo = poolService.handoutResource(poolId, requestHandoutId);
assertEquals(resourceInfo, secondResourceInfo);
}
use of bio.terra.buffer.generated.model.CloudResourceUid in project terra-resource-buffer by DataBiosphere.
the class GenerateProjectIdStep method doStep.
@Override
public StepResult doStep(FlightContext flightContext) {
FlightMap workingMap = flightContext.getWorkingMap();
try {
String projectId = projectIdGenerator.generateIdWithRetries(gcpProjectConfig.getProjectIdSchema());
// Terra. in that case, the project creation step will fail.
if (retrieveProject(rmCow, projectId).isPresent()) {
logger.info("Generated GCP project is already in use: {}", projectId);
// without hitting project get quota issues.
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY);
}
flightContext.getWorkingMap().put(GOOGLE_PROJECT_ID, projectId);
workingMap.put(CLOUD_RESOURCE_UID, new CloudResourceUid().googleProjectUid(new GoogleProjectUid().projectId(projectId)));
return StepResult.getStepResultSuccess();
} catch (IOException | InterruptedException ex) {
logger.info("Error when generating GCP project id.", ex);
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, ex);
}
}
use of bio.terra.buffer.generated.model.CloudResourceUid in project terra-resource-buffer by DataBiosphere.
the class BufferDaoTest method updateResourceAsReady.
@Test
public void updateResourceAsReady() {
PoolId poolId = PoolId.create("poolId");
Pool pool = newPool(poolId);
bufferDao.createPools(ImmutableList.of(pool));
Resource resource = newResource(poolId, ResourceState.CREATING);
CloudResourceUid resourceUid = new CloudResourceUid().googleProjectUid(new GoogleProjectUid().projectId("p-123"));
bufferDao.createResource(resource);
bufferDao.updateResourceAsReady(resource.id(), resourceUid);
Resource updatedResource = bufferDao.retrieveResource(resource.id()).get();
assertEquals(ResourceState.READY, updatedResource.state());
assertEquals(resourceUid, updatedResource.cloudResourceUid());
}
Aggregations