Search in sources :

Example 46 with Pool

use of bio.terra.buffer.common.Pool 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());
}
Also used : Resource(bio.terra.buffer.common.Resource) Pool(bio.terra.buffer.common.Pool) IntegrationUtils.preparePool(bio.terra.buffer.integration.IntegrationUtils.preparePool) FlightManager(bio.terra.buffer.service.resource.FlightManager) StubSubmissionFlightFactory(bio.terra.buffer.integration.IntegrationUtils.StubSubmissionFlightFactory) Test(org.junit.jupiter.api.Test) BaseIntegrationTest(bio.terra.buffer.common.BaseIntegrationTest)

Example 47 with Pool

use of bio.terra.buffer.common.Pool in project terra-resource-buffer by DataBiosphere.

the class CreateProjectFlightIntegrationTest method testCreateGoogleProject_keepDefaultComputeEngineServiceAcct.

@Test
public void testCreateGoogleProject_keepDefaultComputeEngineServiceAcct() throws Exception {
    FlightManager manager = new FlightManager(bufferDao, flightSubmissionFactoryImpl, stairwayComponent, transactionTemplate);
    Pool pool = preparePool(bufferDao, newBasicGcpConfig().computeEngine(new ComputeEngine().keepDefaultServiceAcct(true)));
    String flightId = manager.submitCreationFlight(pool).get();
    ResourceId resourceId = extractResourceIdFromFlightState(blockUntilFlightComplete(stairwayComponent, flightId));
    Project project = assertProjectExists(resourceId);
    assertDefaultServiceAccountExists(project);
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project) ResourceId(bio.terra.buffer.common.ResourceId) Pool(bio.terra.buffer.common.Pool) IntegrationUtils.preparePool(bio.terra.buffer.integration.IntegrationUtils.preparePool) FlightManager(bio.terra.buffer.service.resource.FlightManager) Test(org.junit.jupiter.api.Test) BaseIntegrationTest(bio.terra.buffer.common.BaseIntegrationTest)

Example 48 with Pool

use of bio.terra.buffer.common.Pool in project terra-resource-buffer by DataBiosphere.

the class CreateProjectFlightIntegrationTest method testCreateGoogleProject_basicCreation.

@Test
public void testCreateGoogleProject_basicCreation() throws Exception {
    FlightManager manager = new FlightManager(bufferDao, flightSubmissionFactoryImpl, stairwayComponent, transactionTemplate);
    Pool pool = preparePool(bufferDao, newBasicGcpConfig());
    String flightId = manager.submitCreationFlight(pool).get();
    ResourceId resourceId = extractResourceIdFromFlightState(blockUntilFlightComplete(stairwayComponent, flightId));
    Project project = assertProjectExists(resourceId);
    assertBillingIs(project, pool.resourceConfig().getGcpProjectConfig().getBillingAccount());
    assertEnableApisContains(project, pool.resourceConfig().getGcpProjectConfig().getEnabledApis());
    assertLogStorageBucketExists(project);
    assertNetworkExists(project);
    assertFirewallRulesExist(project);
    assertSubnetsExist(project, NetworkMonitoring.DISABLED);
    assertRouteNotExists(project);
    assertDnsNotExists(project);
    assertDefaultVpcNotExists(project);
    assertDefaultServiceAccountNotExists(project);
    String logBucketName = "storage-logs-" + project.getProjectId();
    assertNotNull(storageCow.get(logBucketName));
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project) ResourceId(bio.terra.buffer.common.ResourceId) Pool(bio.terra.buffer.common.Pool) IntegrationUtils.preparePool(bio.terra.buffer.integration.IntegrationUtils.preparePool) FlightManager(bio.terra.buffer.service.resource.FlightManager) Test(org.junit.jupiter.api.Test) BaseIntegrationTest(bio.terra.buffer.common.BaseIntegrationTest)

Example 49 with Pool

use of bio.terra.buffer.common.Pool 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());
}
Also used : ResourceId(bio.terra.buffer.common.ResourceId) Resource(bio.terra.buffer.common.Resource) IntegrationUtils.preparePool(bio.terra.buffer.integration.IntegrationUtils.preparePool) Pool(bio.terra.buffer.common.Pool) FlightManager(bio.terra.buffer.service.resource.FlightManager) StubSubmissionFlightFactory(bio.terra.buffer.integration.IntegrationUtils.StubSubmissionFlightFactory) BaseIntegrationTest(bio.terra.buffer.common.BaseIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Pool (bio.terra.buffer.common.Pool)49 Test (org.junit.jupiter.api.Test)43 BaseUnitTest (bio.terra.buffer.common.BaseUnitTest)25 Resource (bio.terra.buffer.common.Resource)21 BaseIntegrationTest (bio.terra.buffer.common.BaseIntegrationTest)18 IntegrationUtils.preparePool (bio.terra.buffer.integration.IntegrationUtils.preparePool)18 FlightManager (bio.terra.buffer.service.resource.FlightManager)18 ResourceId (bio.terra.buffer.common.ResourceId)17 PoolId (bio.terra.buffer.common.PoolId)13 Project (com.google.api.services.cloudresourcemanager.v3.model.Project)13 PoolConfig (bio.terra.buffer.generated.model.PoolConfig)7 StubSubmissionFlightFactory (bio.terra.buffer.integration.IntegrationUtils.StubSubmissionFlightFactory)7 ResourceConfig (bio.terra.buffer.generated.model.ResourceConfig)4 PoolAndResourceStates (bio.terra.buffer.common.PoolAndResourceStates)3 RequestHandoutId (bio.terra.buffer.common.RequestHandoutId)3 ResourceState (bio.terra.buffer.common.ResourceState)3 ResourceType (bio.terra.buffer.common.ResourceType)3 bio.terra.buffer.generated.model (bio.terra.buffer.generated.model)3 CloudResourceUid (bio.terra.buffer.generated.model.CloudResourceUid)3 PrimaryConfiguration (bio.terra.buffer.app.configuration.PrimaryConfiguration)2