Search in sources :

Example 6 with Pool

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

the class BufferDaoTest method retrievePoolWithResourceState.

@Test
public void retrievePoolWithResourceState() {
    Pool pool1 = newPool(PoolId.create("poolId1"));
    Pool pool2 = newPool(PoolId.create("poolId2"));
    Pool pool3 = newPool(PoolId.create("poolId3"));
    // Pool1 has 1 CREATING, 2 READY, Pool2 has 1 READY, 1 HANDED_OUT, Pool3 is empty
    bufferDao.createPools(ImmutableList.of(pool1, pool2, pool3));
    bufferDao.createResource(newResource(pool1.id(), ResourceState.CREATING));
    bufferDao.createResource(newResource(pool1.id(), ResourceState.READY));
    bufferDao.createResource(newResource(pool1.id(), ResourceState.READY));
    bufferDao.createResource(newResource(pool2.id(), ResourceState.READY));
    bufferDao.createResource(newResource(pool2.id(), ResourceState.HANDED_OUT));
    PoolAndResourceStates pool1State = PoolAndResourceStates.builder().setPool(pool1).setResourceStateCount(ResourceState.CREATING, 1).setResourceStateCount(ResourceState.READY, 2).build();
    assertThat(bufferDao.retrievePoolAndResourceStates(), Matchers.containsInAnyOrder(pool1State, PoolAndResourceStates.builder().setPool(pool2).setResourceStateCount(ResourceState.READY, 1).setResourceStateCount(ResourceState.HANDED_OUT, 1).build(), PoolAndResourceStates.builder().setPool(pool3).build()));
    assertEquals(pool1State, bufferDao.retrievePoolAndResourceStatesById(pool1.id()).get());
}
Also used : PoolAndResourceStates(bio.terra.buffer.common.PoolAndResourceStates) Pool(bio.terra.buffer.common.Pool) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 7 with Pool

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

the class BufferDaoTest method updateReadyResourceAsDeleting_success.

@Test
public void updateReadyResourceAsDeleting_success() {
    Pool pool = newPool(PoolId.create("poolId"));
    Resource resource = newResource(pool.id(), ResourceState.READY);
    bufferDao.createPools(ImmutableList.of(pool));
    bufferDao.createResource(resource);
    assertTrue(bufferDao.updateReadyResourceToDeleting(resource.id()));
    assertEquals(ResourceState.DELETING, bufferDao.retrieveResource(resource.id()).get().state());
}
Also used : Resource(bio.terra.buffer.common.Resource) Pool(bio.terra.buffer.common.Pool) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 8 with Pool

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

the class BufferDaoTest method insertAndRetrieveCleanupRecord.

@Test
public void insertAndRetrieveCleanupRecord() {
    // Prepare 2 HANDED_OUT and 1 READY resources.
    Pool pool = newPool(PoolId.create("poolId"));
    Resource resource1 = newResource(pool.id(), ResourceState.READY);
    Resource resource2 = newResource(pool.id(), ResourceState.READY);
    Resource resource3 = newResource(pool.id(), ResourceState.READY);
    bufferDao.createPools(ImmutableList.of(pool));
    bufferDao.createResource(resource1);
    bufferDao.createResource(resource2);
    bufferDao.createResource(resource3);
    Resource handedOutR1 = bufferDao.updateOneReadyResourceToHandedOut(pool.id(), RequestHandoutId.create("1111")).get();
    Resource handedOutR2 = bufferDao.updateOneReadyResourceToHandedOut(pool.id(), RequestHandoutId.create("2222")).get();
    // handedOutR1 is already in cleanup_record table, expect only handedOutR2 is returned.
    bufferDao.insertCleanupRecord(handedOutR1.id());
    assertThat(bufferDao.retrieveResourceToCleanup(1), Matchers.contains(bufferDao.retrieveResource(handedOutR2.id()).get()));
}
Also used : Resource(bio.terra.buffer.common.Resource) Pool(bio.terra.buffer.common.Pool) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 9 with Pool

use of bio.terra.buffer.common.Pool 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 10 with Pool

use of bio.terra.buffer.common.Pool 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)

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