Search in sources :

Example 11 with ResourceConfig

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

the class CleanupSchedulerTest method testScheduleCleanup.

@Test
public void testScheduleCleanup() throws Exception {
    Pool pool = Pool.builder().creation(CREATION).id(PoolId.create("poolId")).resourceType(ResourceType.GOOGLE_PROJECT).size(1).resourceConfig(new ResourceConfig()).status(PoolStatus.ACTIVE).build();
    CloudResourceUid cloudResourceUid = new CloudResourceUid().googleProjectUid(new GoogleProjectUid().projectId("p1"));
    Resource resource = Resource.builder().id(ResourceId.create(UUID.randomUUID())).poolId(pool.id()).creation(Instant.now()).state(ResourceState.CREATING).build();
    bufferDao.createPools(ImmutableList.of(pool));
    bufferDao.createResource(resource);
    bufferDao.updateResourceAsReady(resource.id(), cloudResourceUid);
    bufferDao.updateOneReadyResourceToHandedOut(pool.id(), RequestHandoutId.create("1111"));
    assertEquals(1, bufferDao.retrieveResourceToCleanup(10).size());
    cleanupScheduler.initialize();
    Thread.sleep(1000);
    verify(mockPublisher).publish(messageArgumentCaptor.capture());
    assertThat(messageArgumentCaptor.getAllValues().stream().map(m -> m.getData().toStringUtf8()).collect(Collectors.toList()), Matchers.containsInAnyOrder(objectMapper.writeValueAsString(new CreateResourceRequestBody().creation(CREATION.atOffset(ZoneOffset.UTC)).expiration(CREATION.plus(crlConfiguration.getTestResourceTimeToLive()).atOffset(ZoneOffset.UTC)).putLabelsItem("client", CLIENT_NAME).resourceUid(new bio.terra.janitor.model.CloudResourceUid().googleProjectUid(new bio.terra.janitor.model.GoogleProjectUid().projectId("p1"))))));
    assertTrue(bufferDao.retrieveResourceToCleanup(10).isEmpty());
}
Also used : CloudResourceUid(bio.terra.buffer.generated.model.CloudResourceUid) CreateResourceRequestBody(bio.terra.janitor.model.CreateResourceRequestBody) Resource(bio.terra.buffer.common.Resource) Pool(bio.terra.buffer.common.Pool) ResourceConfig(bio.terra.buffer.generated.model.ResourceConfig) GoogleProjectUid(bio.terra.buffer.generated.model.GoogleProjectUid) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 12 with ResourceConfig

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

the class PoolConfigLoaderTest method combineParsedResult.

@Test
public void combineParsedResult() {
    String resourceConfigName = "configName";
    PoolConfig poolConfig = new PoolConfig().poolId("id").resourceConfigName(resourceConfigName);
    PoolConfigs pools = new PoolConfigs().poolConfigs(ImmutableList.of(poolConfig));
    ResourceConfig resourceConfig = new ResourceConfig().configName(resourceConfigName);
    PoolWithResourceConfig expected = PoolWithResourceConfig.create(poolConfig, resourceConfig);
    assertThat(combineParsedConfig(pools, ImmutableMap.of(resourceConfigName, resourceConfig)), Matchers.contains(expected));
}
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 13 with ResourceConfig

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

the class PoolConfigLoaderTest method combineParsedResult_duplicatePoolId.

@Test
public void combineParsedResult_duplicatePoolId() {
    String resourceConfigName = "configName";
    PoolConfig poolConfig = new PoolConfig().poolId("id").resourceConfigName(resourceConfigName);
    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 14 with ResourceConfig

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

the class MetricsHelperTest method testRecordResourceState.

@Test
public void testRecordResourceState() throws Exception {
    PoolId poolId = PoolId.create("poolId");
    Pool pool = Pool.builder().id(poolId).size(10).creation(Instant.now()).status(PoolStatus.ACTIVE).resourceType(ResourceType.GOOGLE_PROJECT).resourceConfig(new ResourceConfig().configName("configName")).build();
    PoolAndResourceStates resourceStates = PoolAndResourceStates.builder().setPool(pool).setResourceStateCount(ResourceState.READY, 2).setResourceStateCount(ResourceState.HANDED_OUT, 1).build();
    MetricsHelper.recordResourceStateCount(resourceStates);
    sleepForSpansExport();
    assertLongValueLongIs(RESOURCE_STATE_COUNT_VIEW.getName(), getResourceCountTags(poolId, ResourceState.READY, PoolStatus.ACTIVE), 2);
    assertLongValueLongIs(RESOURCE_STATE_COUNT_VIEW.getName(), getResourceCountTags(poolId, ResourceState.HANDED_OUT, PoolStatus.ACTIVE), 1);
    assertLongValueLongIs(RESOURCE_STATE_COUNT_VIEW.getName(), getResourceCountTags(poolId, ResourceState.DELETED, PoolStatus.ACTIVE), 0);
    // 2 ready out of size 10
    assertLastValueDoubleIs(READY_RESOURCE_RATIO_VIEW.getName(), getPoolIdTag(poolId), 0.20);
    // Now decrease READY resource count to 0, verifies it can sill count.
    PoolAndResourceStates noReadyResourceStates = PoolAndResourceStates.builder().setPool(pool).setResourceStateCount(ResourceState.HANDED_OUT, 1).build();
    MetricsHelper.recordResourceStateCount(noReadyResourceStates);
    sleepForSpansExport();
    assertLongValueLongIs(RESOURCE_STATE_COUNT_VIEW.getName(), getResourceCountTags(poolId, ResourceState.READY, PoolStatus.ACTIVE), 0);
    assertLastValueDoubleIs(READY_RESOURCE_RATIO_VIEW.getName(), getPoolIdTag(poolId), 0.0);
    // Now deactivate the pool and verifies READY resource ratio changed to 1.
    PoolAndResourceStates deactivatedResourceStates = PoolAndResourceStates.builder().setPool(pool.toBuilder().status(PoolStatus.DEACTIVATED).build()).setResourceStateCount(ResourceState.HANDED_OUT, 1).build();
    MetricsHelper.recordResourceStateCount(deactivatedResourceStates);
    sleepForSpansExport();
    assertLastValueDoubleIs(READY_RESOURCE_RATIO_VIEW.getName(), getPoolIdTag(poolId), 1.0);
}
Also used : ResourceConfig(bio.terra.buffer.generated.model.ResourceConfig) Test(org.junit.jupiter.api.Test)

Aggregations

ResourceConfig (bio.terra.buffer.generated.model.ResourceConfig)14 Test (org.junit.jupiter.api.Test)8 BaseUnitTest (bio.terra.buffer.common.BaseUnitTest)7 PoolConfigs (bio.terra.buffer.generated.model.PoolConfigs)5 PoolConfig (bio.terra.buffer.generated.model.PoolConfig)4 Pool (bio.terra.buffer.common.Pool)3 InvalidPoolConfigException (bio.terra.buffer.common.exception.InvalidPoolConfigException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 IOException (java.io.IOException)2 Resource (org.springframework.core.io.Resource)2 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)2 PoolId (bio.terra.buffer.common.PoolId)1 Resource (bio.terra.buffer.common.Resource)1 ResourceId (bio.terra.buffer.common.ResourceId)1 ResourceState (bio.terra.buffer.common.ResourceState)1 CloudResourceUid (bio.terra.buffer.generated.model.CloudResourceUid)1 GoogleProjectUid (bio.terra.buffer.generated.model.GoogleProjectUid)1 ProjectIdSchema (bio.terra.buffer.generated.model.ProjectIdSchema)1