Search in sources :

Example 16 with Pool

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

the class PoolServiceTest method updateFromConfig_createPool.

@Test
public void updateFromConfig_createPool() throws Exception {
    PoolId poolId = PoolId.create("poolId");
    PoolWithResourceConfig parsedPoolConfig = PoolWithResourceConfig.create(new PoolConfig().poolId(poolId.toString()).size(10).resourceConfigName(RESOURCE_CONFIG_NAME), newResourceConfig());
    poolService.updateFromConfig(ImmutableList.of(parsedPoolConfig));
    List<Pool> pools = bufferDao.retrievePools();
    assertEquals(1, pools.size());
    Pool createdPool = pools.get(0);
    assertEquals(poolId, createdPool.id());
    assertEquals(ResourceType.GOOGLE_PROJECT, createdPool.resourceType());
    assertEquals(PoolStatus.ACTIVE, createdPool.status());
    assertEquals(parsedPoolConfig.resourceConfig(), createdPool.resourceConfig());
}
Also used : PoolId(bio.terra.buffer.common.PoolId) PoolConfig(bio.terra.buffer.generated.model.PoolConfig) Pool(bio.terra.buffer.common.Pool) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 17 with Pool

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

the class PoolServiceTest method updateFromConfig_alreadyExists.

@Test
public void updateFromConfig_alreadyExists() throws Exception {
    PoolId poolId = PoolId.create("poolId");
    PoolWithResourceConfig parsedPoolConfig = PoolWithResourceConfig.create(new PoolConfig().poolId(poolId.toString()).size(10).resourceConfigName(RESOURCE_CONFIG_NAME), newResourceConfig());
    poolService.updateFromConfig(ImmutableList.of(parsedPoolConfig));
    List<Pool> pools = bufferDao.retrievePools();
    assertEquals(1, pools.size());
    Pool createdPool = pools.get(0);
    assertEquals(poolId, createdPool.id());
    assertEquals(ResourceType.GOOGLE_PROJECT, createdPool.resourceType());
    assertEquals(PoolStatus.ACTIVE, createdPool.status());
    assertEquals(parsedPoolConfig.resourceConfig(), createdPool.resourceConfig());
    poolService.updateFromConfig(ImmutableList.of(parsedPoolConfig));
    assertThat(bufferDao.retrievePools(), Matchers.containsInAnyOrder(pools.toArray()));
}
Also used : PoolId(bio.terra.buffer.common.PoolId) PoolConfig(bio.terra.buffer.generated.model.PoolConfig) Pool(bio.terra.buffer.common.Pool) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 18 with Pool

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

the class PoolServiceTest method updateFromConfig_updateResourceConfigOnExistingPool_throwsException.

@Test
public void updateFromConfig_updateResourceConfigOnExistingPool_throwsException() throws Exception {
    PoolId poolId = PoolId.create("poolId");
    PoolConfig poolConfig = new PoolConfig().poolId(poolId.toString()).size(1).resourceConfigName(RESOURCE_CONFIG_NAME);
    PoolWithResourceConfig parsedPoolConfig = PoolWithResourceConfig.create(poolConfig, newResourceConfig());
    poolService.updateFromConfig(ImmutableList.of(parsedPoolConfig));
    // Sets ResourceConfig's GCP project id prefix to newer value.
    PoolWithResourceConfig updatedPoolConfig = PoolWithResourceConfig.create(poolConfig, newResourceConfig(new GcpProjectConfig().projectIdSchema(new ProjectIdSchema().prefix("aou-rw-test2").scheme(ProjectIdSchema.SchemeEnum.RANDOM_CHAR))));
    assertThrows(RuntimeException.class, () -> poolService.updateFromConfig(ImmutableList.of(updatedPoolConfig)));
    assertThat(bufferDao.retrievePools().stream().map(Pool::resourceConfig).collect(Collectors.toList()), Matchers.containsInAnyOrder(parsedPoolConfig.resourceConfig()));
}
Also used : PoolId(bio.terra.buffer.common.PoolId) ProjectIdSchema(bio.terra.buffer.generated.model.ProjectIdSchema) GcpProjectConfig(bio.terra.buffer.generated.model.GcpProjectConfig) PoolConfig(bio.terra.buffer.generated.model.PoolConfig) Pool(bio.terra.buffer.common.Pool) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 19 with Pool

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

the class PoolServiceTest method updateFromConfig_deactivatePool_updatePoolStatusSuccess.

@Test
public void updateFromConfig_deactivatePool_updatePoolStatusSuccess() throws Exception {
    PoolId poolId = PoolId.create("poolId");
    PoolWithResourceConfig parsedPoolConfig = PoolWithResourceConfig.create(new PoolConfig().poolId(poolId.toString()).size(10).resourceConfigName(RESOURCE_CONFIG_NAME), newResourceConfig());
    poolService.updateFromConfig(ImmutableList.of(parsedPoolConfig));
    List<Pool> pools = bufferDao.retrievePools();
    Pool createdPool = pools.get(0);
    assertEquals(poolId, createdPool.id());
    assertEquals(PoolStatus.ACTIVE, createdPool.status());
    poolService.updateFromConfig(ImmutableList.of());
    Pool resizedPool = bufferDao.retrievePools().get(0);
    assertEquals(poolId, resizedPool.id());
    assertEquals(PoolStatus.DEACTIVATED, resizedPool.status());
}
Also used : PoolId(bio.terra.buffer.common.PoolId) PoolConfig(bio.terra.buffer.generated.model.PoolConfig) Pool(bio.terra.buffer.common.Pool) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 20 with Pool

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

the class PoolServiceTest method updateFromConfig_createDeactivateReactivate_success.

@Test
public void updateFromConfig_createDeactivateReactivate_success() throws Exception {
    // Create two pools so we fully exercise the batch methods in the DAO.
    PoolId poolId1 = PoolId.create("poolId1");
    PoolWithResourceConfig parsedPoolConfig1 = PoolWithResourceConfig.create(new PoolConfig().poolId(poolId1.toString()).size(10).resourceConfigName(RESOURCE_CONFIG_NAME), newResourceConfig());
    PoolId poolId2 = PoolId.create("poolId2");
    PoolWithResourceConfig parsedPoolConfig2 = PoolWithResourceConfig.create(new PoolConfig().poolId(poolId2.toString()).size(50).resourceConfigName(RESOURCE_CONFIG_NAME), newResourceConfig());
    poolService.updateFromConfig(ImmutableList.of(parsedPoolConfig1, parsedPoolConfig2));
    List<Pool> pools = bufferDao.retrievePools();
    assertEquals(2, pools.size());
    Pool createdPool1 = pools.stream().filter(p -> p.id().equals(poolId1)).findFirst().orElseThrow();
    assertEquals(poolId1, createdPool1.id());
    assertEquals(ResourceType.GOOGLE_PROJECT, createdPool1.resourceType());
    assertEquals(PoolStatus.ACTIVE, createdPool1.status());
    assertEquals(parsedPoolConfig1.resourceConfig(), createdPool1.resourceConfig());
    Pool createdPool2 = pools.stream().filter(p -> p.id().equals(poolId2)).findFirst().orElseThrow();
    ;
    assertEquals(poolId2, createdPool2.id());
    assertEquals(ResourceType.GOOGLE_PROJECT, createdPool2.resourceType());
    assertEquals(PoolStatus.ACTIVE, createdPool2.status());
    assertEquals(parsedPoolConfig1.resourceConfig(), createdPool1.resourceConfig());
    // Deactivate both pools
    poolService.updateFromConfig(Collections.emptyList());
    List<Pool> deactivatedPools = bufferDao.retrievePools();
    assertEquals(2, deactivatedPools.size());
    Pool deactivatedPool1 = deactivatedPools.stream().filter(p -> p.id().equals(poolId1)).findFirst().orElseThrow();
    assertEquals(ResourceType.GOOGLE_PROJECT, deactivatedPool1.resourceType());
    assertEquals(PoolStatus.DEACTIVATED, deactivatedPool1.status());
    Pool deactivatedPool2 = deactivatedPools.stream().filter(p -> p.id().equals(poolId2)).findFirst().orElseThrow();
    assertEquals(ResourceType.GOOGLE_PROJECT, deactivatedPool2.resourceType());
    assertEquals(PoolStatus.DEACTIVATED, deactivatedPool2.status());
    // Re-activate pools
    // Resize pool 2
    PoolWithResourceConfig resizedPoolConfig2 = PoolWithResourceConfig.create(new PoolConfig().poolId(poolId2.toString()).size(25).resourceConfigName(RESOURCE_CONFIG_NAME), newResourceConfig());
    poolService.updateFromConfig(ImmutableList.of(parsedPoolConfig1, resizedPoolConfig2));
    List<Pool> reactivatedPools = bufferDao.retrievePools();
    Pool reactivatedPool1 = reactivatedPools.stream().filter(p -> p.id().equals(poolId1)).findFirst().orElseThrow();
    assertEquals(ResourceType.GOOGLE_PROJECT, reactivatedPool1.resourceType());
    assertEquals(PoolStatus.ACTIVE, reactivatedPool1.status());
    assertEquals(10, reactivatedPool1.size());
    Pool reactivatedPool2 = reactivatedPools.stream().filter(p -> p.id().equals(poolId2)).findFirst().orElseThrow();
    assertEquals(ResourceType.GOOGLE_PROJECT, reactivatedPool2.resourceType());
    assertEquals(PoolStatus.ACTIVE, reactivatedPool2.status());
    assertEquals(25, reactivatedPool2.size());
}
Also used : PoolId(bio.terra.buffer.common.PoolId) PoolConfig(bio.terra.buffer.generated.model.PoolConfig) Pool(bio.terra.buffer.common.Pool) 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