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());
}
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));
}
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)));
}
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);
}
Aggregations