Search in sources :

Example 21 with Pool

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

the class PoolServiceTest method newReadyPool.

/**
 * Creates a pool with resources with given size.
 */
private void newReadyPool(PoolId poolId, int poolSize) {
    Pool pool = Pool.builder().creation(Instant.now()).id(poolId).resourceType(ResourceType.GOOGLE_PROJECT).size(poolSize).resourceConfig(new ResourceConfig().configName("resourceName")).status(PoolStatus.ACTIVE).build();
    bufferDao.createPools(ImmutableList.of(pool));
    for (int i = 0; i < poolSize; i++) {
        ResourceId id = ResourceId.create(UUID.randomUUID());
        bufferDao.createResource(Resource.builder().id(id).poolId(poolId).creation(Instant.now()).state(ResourceState.CREATING).build());
        bufferDao.updateResourceAsReady(id, newProjectUid());
    }
}
Also used : ResourceId(bio.terra.buffer.common.ResourceId) Pool(bio.terra.buffer.common.Pool) ResourceConfig(bio.terra.buffer.generated.model.ResourceConfig)

Example 22 with Pool

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

the class FlightSchedulerTest method scheduleDeactivationFlights_poolDeactivated.

@Test
public void scheduleDeactivationFlights_poolDeactivated() throws Exception {
    // pool is delete, should delete the 2 READY resources.
    Pool pool = newPoolWithResourceCount(5, ImmutableMultiset.of(ResourceState.READY, ResourceState.READY, ResourceState.CREATING));
    bufferDao.deactivatePools(ImmutableList.of(pool.id()));
    List<Resource> resources = bufferDao.retrieveResourcesRandomly(pool.id(), ResourceState.READY, 2);
    initializeScheduler();
    TimeUnit.SECONDS.sleep(4);
    resources.forEach(resource -> verify(flightManager).submitDeletionFlight(resource, ResourceType.GOOGLE_PROJECT));
    verify(flightManager, never()).submitCreationFlight(any(Pool.class));
}
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 23 with Pool

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

the class FlightSchedulerTest method scheduleDeactivationFlights_smallerLimitPerExecute.

@Test
public void scheduleDeactivationFlights_smallerLimitPerExecute() throws Exception {
    // Pool1 size 5, need to deactivate the 4 READY resources.
    // Expect number of resourceDeactivationPerPoolLimit(3) flights are submitted at most.
    Pool pool = newPoolWithResourceCount(5, ImmutableMultiset.of(ResourceState.READY, ResourceState.READY, ResourceState.READY, ResourceState.READY, ResourceState.CREATING));
    bufferDao.deactivatePools(ImmutableList.of(pool.id()));
    List<Resource> resources = bufferDao.retrieveResourcesRandomly(pool.id(), ResourceState.READY, 4);
    PrimaryConfiguration primaryConfiguration = newPrimaryConfiguration();
    primaryConfiguration.setResourceDeletionPerPoolLimit(3);
    initializeScheduler(primaryConfiguration);
    TimeUnit.SECONDS.sleep(4);
    verify(flightManager, times(3)).submitDeletionFlight(resourceArgumentCaptor.capture(), eq(ResourceType.GOOGLE_PROJECT));
    assertThat(resources, (Matcher) Matchers.hasItems(resourceArgumentCaptor.getAllValues().toArray()));
    verify(flightManager, never()).submitCreationFlight(any(Pool.class));
}
Also used : Resource(bio.terra.buffer.common.Resource) PrimaryConfiguration(bio.terra.buffer.app.configuration.PrimaryConfiguration) Pool(bio.terra.buffer.common.Pool) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 24 with Pool

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

the class FlightSchedulerTest method newPoolWithResourceCount.

/**
 * Creates a pool with resources with given {@code resourceStates}.
 */
private Pool newPoolWithResourceCount(int poolSize, Multiset<ResourceState> resourceStates) {
    PoolId poolId = PoolId.create(UUID.randomUUID().toString());
    Pool pool = Pool.builder().creation(Instant.now()).id(poolId).resourceType(ResourceType.GOOGLE_PROJECT).size(poolSize).resourceConfig(new ResourceConfig().configName("resourceName")).status(PoolStatus.ACTIVE).build();
    bufferDao.createPools(ImmutableList.of(pool));
    for (ResourceState state : resourceStates) {
        bufferDao.createResource(Resource.builder().id(ResourceId.create(UUID.randomUUID())).poolId(poolId).creation(Instant.now()).state(state).build());
    }
    return pool;
}
Also used : PoolId(bio.terra.buffer.common.PoolId) Pool(bio.terra.buffer.common.Pool) ResourceState(bio.terra.buffer.common.ResourceState) ResourceConfig(bio.terra.buffer.generated.model.ResourceConfig)

Example 25 with Pool

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

the class FlightSchedulerTest method scheduleCreationFlights.

@Test
public void scheduleCreationFlights() throws Exception {
    // Pool1 size 5, should create 2 more resources.
    Pool pool1 = newPoolWithResourceCount(5, ImmutableMultiset.of(ResourceState.READY, ResourceState.READY, ResourceState.CREATING));
    // Pool2 size 3, nothing to create.
    Pool pool2 = newPoolWithResourceCount(3, ImmutableMultiset.of(ResourceState.READY, ResourceState.READY, ResourceState.CREATING));
    initializeScheduler();
    TimeUnit.SECONDS.sleep(4);
    verify(flightManager, times(2)).submitCreationFlight(pool1);
    verify(flightManager, never()).submitCreationFlight(pool2);
    verify(flightManager, never()).submitDeletionFlight(any(Resource.class), any(ResourceType.class));
}
Also used : Resource(bio.terra.buffer.common.Resource) Pool(bio.terra.buffer.common.Pool) ResourceType(bio.terra.buffer.common.ResourceType) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) 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