use of bio.terra.buffer.common.Resource in project terra-resource-buffer by DataBiosphere.
the class BufferDaoTest method updateOneReadyResourceToHandedOut.
@Test
public void updateOneReadyResourceToHandedOut() {
Pool pool = newPool(PoolId.create("poolId"));
RequestHandoutId requestHandoutId = RequestHandoutId.create("handoutId");
Resource ready = newResource(pool.id(), ResourceState.READY);
bufferDao.createPools(ImmutableList.of(pool));
bufferDao.createResource(ready);
Resource resource = bufferDao.updateOneReadyResourceToHandedOut(pool.id(), requestHandoutId).get();
Resource handedOutResource = bufferDao.retrieveResource(resource.id()).get();
assertEquals(requestHandoutId, handedOutResource.requestHandoutId());
assertEquals(ResourceState.HANDED_OUT, handedOutResource.state());
// Now use the same requestHandoutId again, expect getting the same resource back.
assertEquals(handedOutResource, bufferDao.updateOneReadyResourceToHandedOut(pool.id(), requestHandoutId).get());
}
use of bio.terra.buffer.common.Resource in project terra-resource-buffer by DataBiosphere.
the class BufferIntegrationTest method testCreateGoogleProject.
@Test
public void testCreateGoogleProject() throws Exception {
// The pool id in config file.
PoolId poolId = PoolId.create("ws_test_v1");
List<PoolWithResourceConfig> config = loadPoolConfig("test/config", Optional.empty());
poolService.updateFromConfig(config);
List<Resource> resources = pollUntilResourcesMatch(bufferDao, poolId, ResourceState.READY, 2);
resources.forEach(resource -> {
try {
assertProjectMatch(resource.cloudResourceUid(), config.get(0).resourceConfig().getGcpProjectConfig());
} catch (Exception e) {
fail("Error occurs when verifying GCP project creation", e);
}
});
// Upgrade the size from 2 to 5. Expect 3 more resources will be created.
bufferDao.updatePoolsSizes(ImmutableMap.of(poolId, 5));
resources = pollUntilResourcesMatch(bufferDao, poolId, ResourceState.READY, 5);
resources.forEach(resource -> {
try {
assertProjectMatch(resource.cloudResourceUid(), config.get(0).resourceConfig().getGcpProjectConfig());
} catch (Exception e) {
fail("Error occurs when verifying GCP project creation", e);
}
});
}
use of bio.terra.buffer.common.Resource in project terra-resource-buffer by DataBiosphere.
the class CreateProjectFlightIntegrationTest method assertProjectExists.
private Project assertProjectExists(ResourceId resourceId) throws Exception {
Resource resource = bufferDao.retrieveResource(resourceId).get();
Project project = rmCow.projects().get(resource.cloudResourceUid().getGoogleProjectUid().getProjectId()).execute();
assertEquals("ACTIVE", project.getState());
assertThat(project.getLabels().entrySet(), Matchers.hasItems(Map.entry(NETWORK_LABEL_KEY, NETWORK_NAME), Map.entry(SUB_NETWORK_LABEL_KEY, SUBNETWORK_NAME), Map.entry(LEONARDO_ALLOW_HTTPS_FIREWALL_RULE_NAME_LABEL_KEY, LEONARDO_SSL_FOR_VPC_NETWORK_RULE_NAME), Map.entry(LEONARDO_ALLOW_INTERNAL_RULE_NAME_LABEL_KEY, ALLOW_INTERNAL_FOR_VPC_NETWORK_RULE_NAME), Map.entry(CONFIG_NAME_LABEL_KEY, TEST_CONFIG_NAME)));
return project;
}
use of bio.terra.buffer.common.Resource in project terra-resource-buffer by DataBiosphere.
the class CreateProjectFlightIntegrationTest method errorCreateProject_noRollbackAfterResourceReady.
@Test
public void errorCreateProject_noRollbackAfterResourceReady() throws Exception {
// Verify project and db entity won't get deleted if resource id READY, even the flight fails.
FlightManager manager = new FlightManager(bufferDao, new StubSubmissionFlightFactory(ErrorAfterCreateResourceFlight.class), stairwayComponent, transactionTemplate);
Pool pool = preparePool(bufferDao, newBasicGcpConfig());
String flightId = manager.submitCreationFlight(pool).get();
extractResourceIdFromFlightState(blockUntilFlightComplete(stairwayComponent, flightId));
Resource resource = bufferDao.retrieveResourcesRandomly(pool.id(), ResourceState.READY, 1).get(0);
assertEquals("ACTIVE", rmCow.projects().get(resource.cloudResourceUid().getGoogleProjectUid().getProjectId()).execute().getState());
assertEquals(FlightStatus.ERROR, stairwayComponent.get().getFlightState(flightId).getFlightStatus());
}
use of bio.terra.buffer.common.Resource in project terra-resource-buffer by DataBiosphere.
the class DeleteProjectFlightIntegrationTest method testDeleteGoogleProject_errorWhenResourceStateChange.
@Test
public void testDeleteGoogleProject_errorWhenResourceStateChange() throws Exception {
LatchStep.startNewLatch();
Pool pool = preparePool(bufferDao, newBasicGcpConfig());
ResourceId resourceId = ResourceId.create(UUID.randomUUID());
bufferDao.createResource(Resource.builder().id(resourceId).poolId(pool.id()).creation(Instant.now()).state(ResourceState.READY).build());
Resource resource = bufferDao.retrieveResource(resourceId).get();
FlightManager manager = new FlightManager(bufferDao, new StubSubmissionFlightFactory(LatchBeforeAssertResourceStep.class), stairwayComponent, transactionTemplate);
String deleteFlightId = manager.submitDeletionFlight(resource, ResourceType.GOOGLE_PROJECT).get();
// Delete the resource from DB.
assertTrue(bufferDao.deleteResource(resource.id()));
// Release the latch, and resume the flight, assert flight failed.
LatchStep.releaseLatch();
extractResourceIdFromFlightState(blockUntilFlightComplete(stairwayComponent, deleteFlightId));
// Resource is deleted.
assertFalse(bufferDao.retrieveResource(resource.id()).isPresent());
assertEquals(FlightStatus.ERROR, stairwayComponent.get().getFlightState(deleteFlightId).getFlightStatus());
}
Aggregations