Search in sources :

Example 1 with PoolConfig

use of bio.terra.buffer.generated.model.PoolConfig in project terra-resource-buffer by DataBiosphere.

the class PoolConfigLoaderTest method combineParsedResult_resourceConfigNotFound.

@Test
public void combineParsedResult_resourceConfigNotFound() {
    String resourceConfigName = "configName";
    PoolConfig poolConfig = new PoolConfig().poolId("id").resourceConfigName("badName");
    PoolConfigs pools = new PoolConfigs().poolConfigs(ImmutableList.of(poolConfig, poolConfig));
    ResourceConfig resourceConfig = new ResourceConfig().configName(resourceConfigName);
    assertThrows(BadPoolConfigException.class, () -> combineParsedConfig(pools, ImmutableMap.of(resourceConfigName, resourceConfig)));
}
Also used : PoolConfigs(bio.terra.buffer.generated.model.PoolConfigs) PoolConfig(bio.terra.buffer.generated.model.PoolConfig) ResourceConfig(bio.terra.buffer.generated.model.ResourceConfig) Test(org.junit.jupiter.api.Test) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest)

Example 2 with PoolConfig

use of bio.terra.buffer.generated.model.PoolConfig 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 3 with PoolConfig

use of bio.terra.buffer.generated.model.PoolConfig 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 4 with PoolConfig

use of bio.terra.buffer.generated.model.PoolConfig 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 5 with PoolConfig

use of bio.terra.buffer.generated.model.PoolConfig 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)

Aggregations

PoolConfig (bio.terra.buffer.generated.model.PoolConfig)12 BaseUnitTest (bio.terra.buffer.common.BaseUnitTest)10 Test (org.junit.jupiter.api.Test)10 Pool (bio.terra.buffer.common.Pool)7 PoolId (bio.terra.buffer.common.PoolId)7 PoolConfigs (bio.terra.buffer.generated.model.PoolConfigs)3 ResourceConfig (bio.terra.buffer.generated.model.ResourceConfig)3 PoolInfo (bio.terra.buffer.generated.model.PoolInfo)2 PoolAndResourceStates (bio.terra.buffer.common.PoolAndResourceStates)1 ResourceState (bio.terra.buffer.common.ResourceState)1 NotFoundException (bio.terra.buffer.common.exception.NotFoundException)1 GcpProjectConfig (bio.terra.buffer.generated.model.GcpProjectConfig)1 ProjectIdSchema (bio.terra.buffer.generated.model.ProjectIdSchema)1 PoolConfigLoader.loadPoolConfig (bio.terra.buffer.service.pool.PoolConfigLoader.loadPoolConfig)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1