Search in sources :

Example 1 with FlightManager

use of bio.terra.buffer.service.resource.FlightManager in project terra-resource-buffer by DataBiosphere.

the class CreateProjectFlightIntegrationTest method testCreateGoogleProject_createsConsumerOverride.

@Test
public void testCreateGoogleProject_createsConsumerOverride() throws Exception {
    FlightManager manager = new FlightManager(bufferDao, new StubSubmissionFlightFactory(LatchBeforeAssertResourceStep.class), stairwayComponent, transactionTemplate);
    GcpProjectConfig gcpProjectConfig = newBasicGcpConfig().serviceUsage(new ServiceUsage().bigQuery(new BigQueryQuotas().overrideBigQueryDailyUsageQuota(true).bigQueryDailyUsageQuotaOverrideValueMebibytes(new BigDecimal(CONSUMER_QUOTA_OVERRIDE_VALUE_MEBIBYTES))));
    Pool pool = preparePool(bufferDao, gcpProjectConfig);
    String flightId = manager.submitCreationFlight(pool).orElseThrow();
    ResourceId resourceId = extractResourceIdFromFlightState(blockUntilFlightComplete(stairwayComponent, flightId));
    Project project = assertProjectExists(resourceId);
    String projectNumber = getProjectNumberFromName(project.getName());
    String parent = String.format("projects/%s/services/bigquery.googleapis.com/consumerQuotaMetrics/" + "bigquery.googleapis.com%%2Fquota%%2Fquery%%2Fusage/limits/%%2Fd%%2Fproject", projectNumber);
    ServiceUsageCow.Services.ConsumerQuotaMetrics.Limits.ConsumerOverrides.List list = serviceUsageCow.services().consumerQuotaMetrics().limits().consumerOverrides().list(parent);
    ListConsumerOverridesResponse response = list.execute();
    assertEquals(1, response.getOverrides().size(), "single override expected");
    QuotaOverride quotaOverride = response.getOverrides().get(0);
    assertEquals(CONSUMER_QUOTA_OVERRIDE_VALUE_MEBIBYTES, quotaOverride.getOverrideValue());
}
Also used : ListConsumerOverridesResponse(com.google.api.services.serviceusage.v1beta1.model.ListConsumerOverridesResponse) FlightManager(bio.terra.buffer.service.resource.FlightManager) StubSubmissionFlightFactory(bio.terra.buffer.integration.IntegrationUtils.StubSubmissionFlightFactory) BigDecimal(java.math.BigDecimal) Project(com.google.api.services.cloudresourcemanager.v3.model.Project) QuotaOverride(com.google.api.services.serviceusage.v1beta1.model.QuotaOverride) ResourceId(bio.terra.buffer.common.ResourceId) Pool(bio.terra.buffer.common.Pool) IntegrationUtils.preparePool(bio.terra.buffer.integration.IntegrationUtils.preparePool) ServiceUsageCow(bio.terra.cloudres.google.serviceusage.ServiceUsageCow) Test(org.junit.jupiter.api.Test) BaseIntegrationTest(bio.terra.buffer.common.BaseIntegrationTest)

Example 2 with FlightManager

use of bio.terra.buffer.service.resource.FlightManager in project terra-resource-buffer by DataBiosphere.

the class CreateProjectFlightIntegrationTest method testCreateGoogleProject_errorWhenResourceStateChange.

@Test
public void testCreateGoogleProject_errorWhenResourceStateChange() throws Exception {
    LatchStep.startNewLatch();
    FlightManager manager = new FlightManager(bufferDao, new StubSubmissionFlightFactory(LatchBeforeAssertResourceStep.class), stairwayComponent, transactionTemplate);
    Pool pool = preparePool(bufferDao, newBasicGcpConfig());
    String flightId = manager.submitCreationFlight(pool).get();
    // Resource is created in db
    Resource resource = pollUntilResourcesMatch(bufferDao, pool.id(), ResourceState.CREATING, 1).get(0);
    // 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, flightId));
    // Resource is deleted.
    assertFalse(bufferDao.retrieveResource(resource.id()).isPresent());
    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 3 with FlightManager

use of bio.terra.buffer.service.resource.FlightManager in project terra-resource-buffer by DataBiosphere.

the class CreateProjectFlightIntegrationTest method testCreateGoogleProject_errorDuringProjectCreation.

@Test
public void testCreateGoogleProject_errorDuringProjectCreation() throws Exception {
    // Verify flight is able to successfully rollback when project fails to create and doesn't
    // exist.
    LatchStep.startNewLatch();
    FlightManager manager = new FlightManager(bufferDao, new StubSubmissionFlightFactory(ErrorCreateProjectFlight.class), stairwayComponent, transactionTemplate);
    Pool pool = preparePool(bufferDao, newBasicGcpConfig());
    String flightId = manager.submitCreationFlight(pool).get();
    // Resource is created in db
    Resource resource = pollUntilResourcesMatch(bufferDao, pool.id(), ResourceState.CREATING, 1).get(0);
    LatchStep.releaseLatch();
    extractResourceIdFromFlightState(blockUntilFlightComplete(stairwayComponent, flightId));
    // Resource is deleted.
    assertFalse(bufferDao.retrieveResource(resource.id()).isPresent());
    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 4 with FlightManager

use of bio.terra.buffer.service.resource.FlightManager in project terra-resource-buffer by DataBiosphere.

the class CreateProjectFlightIntegrationTest method testCreateGoogleProject_keepDefaultNetwork.

@Disabled("In Broad deployment, skipDefaultNetworkCreation is turned on orignization policy")
@Test
public void testCreateGoogleProject_keepDefaultNetwork() throws Exception {
    FlightManager manager = new FlightManager(bufferDao, flightSubmissionFactoryImpl, stairwayComponent, transactionTemplate);
    Pool pool = preparePool(bufferDao, newBasicGcpConfig().network(new bio.terra.buffer.generated.model.Network().keepDefaultNetwork(true)));
    String flightId = manager.submitCreationFlight(pool).get();
    ResourceId resourceId = extractResourceIdFromFlightState(blockUntilFlightComplete(stairwayComponent, flightId));
    Project project = assertProjectExists(resourceId);
    assertNetworkExists(project);
    assertFirewallRulesExist(project);
    assertDefaultVpcExists(project);
    assertFirewallRulesExistForDefaultVpc(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) bio.terra.buffer.generated.model(bio.terra.buffer.generated.model) FlightManager(bio.terra.buffer.service.resource.FlightManager) Test(org.junit.jupiter.api.Test) BaseIntegrationTest(bio.terra.buffer.common.BaseIntegrationTest) Disabled(org.junit.jupiter.api.Disabled)

Example 5 with FlightManager

use of bio.terra.buffer.service.resource.FlightManager in project terra-resource-buffer by DataBiosphere.

the class CreateProjectFlightIntegrationTest method testCreateGoogleProject_blockedRegions_invalidBlockedRegion.

@Test
public void testCreateGoogleProject_blockedRegions_invalidBlockedRegion() throws Exception {
    // If a blocked region is invalid, project configuration still succeeds.
    String validBlockedRegion = "europe-west2";
    String invalidBlockedRegion = "u-west4";
    List<String> blockedRegions = ImmutableList.of(validBlockedRegion, invalidBlockedRegion);
    FlightManager manager = new FlightManager(bufferDao, flightSubmissionFactoryImpl, stairwayComponent, transactionTemplate);
    Pool pool = preparePool(bufferDao, newBasicGcpConfig().network(new bio.terra.buffer.generated.model.Network().blockedRegions(blockedRegions)));
    String flightId = manager.submitCreationFlight(pool).get();
    ResourceId resourceId = extractResourceIdFromFlightState(blockUntilFlightComplete(stairwayComponent, flightId));
    Project project = assertProjectExists(resourceId);
    assertNoSubnetsInBlockedRegions(project, ImmutableList.of(validBlockedRegion));
}
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) bio.terra.buffer.generated.model(bio.terra.buffer.generated.model) FlightManager(bio.terra.buffer.service.resource.FlightManager) Test(org.junit.jupiter.api.Test) BaseIntegrationTest(bio.terra.buffer.common.BaseIntegrationTest)

Aggregations

BaseIntegrationTest (bio.terra.buffer.common.BaseIntegrationTest)18 Pool (bio.terra.buffer.common.Pool)18 IntegrationUtils.preparePool (bio.terra.buffer.integration.IntegrationUtils.preparePool)18 FlightManager (bio.terra.buffer.service.resource.FlightManager)18 Test (org.junit.jupiter.api.Test)18 ResourceId (bio.terra.buffer.common.ResourceId)15 Project (com.google.api.services.cloudresourcemanager.v3.model.Project)13 StubSubmissionFlightFactory (bio.terra.buffer.integration.IntegrationUtils.StubSubmissionFlightFactory)7 Resource (bio.terra.buffer.common.Resource)6 bio.terra.buffer.generated.model (bio.terra.buffer.generated.model)3 Network (com.google.api.services.compute.model.Network)2 ServiceUsageCow (bio.terra.cloudres.google.serviceusage.ServiceUsageCow)1 ListConsumerOverridesResponse (com.google.api.services.serviceusage.v1beta1.model.ListConsumerOverridesResponse)1 QuotaOverride (com.google.api.services.serviceusage.v1beta1.model.QuotaOverride)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Disabled (org.junit.jupiter.api.Disabled)1