Search in sources :

Example 21 with Resource

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

the class BufferDaoTest method updateOneReadyResourceToHandedOut.

@Test
public void updateOneReadyResourceToHandedOut() {
    Pool pool = newPool(PoolId.create("poolId"));
    RequestHandoutId requestHandoutId = RequestHandoutId.create("handoutId");
    Resource ready = newResource(pool.id(), ResourceState.READY);
    bufferDao.createPools(ImmutableList.of(pool));
    bufferDao.createResource(ready);
    Resource resource = bufferDao.updateOneReadyResourceToHandedOut(pool.id(), requestHandoutId).get();
    Resource handedOutResource = bufferDao.retrieveResource(resource.id()).get();
    assertEquals(requestHandoutId, handedOutResource.requestHandoutId());
    assertEquals(ResourceState.HANDED_OUT, handedOutResource.state());
    // Now use the same requestHandoutId again, expect getting the same resource back.
    assertEquals(handedOutResource, bufferDao.updateOneReadyResourceToHandedOut(pool.id(), requestHandoutId).get());
}
Also used : Resource(bio.terra.buffer.common.Resource) RequestHandoutId(bio.terra.buffer.common.RequestHandoutId) Pool(bio.terra.buffer.common.Pool) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 22 with Resource

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

the class BufferIntegrationTest method testCreateGoogleProject.

@Test
public void testCreateGoogleProject() throws Exception {
    // The pool id in config file.
    PoolId poolId = PoolId.create("ws_test_v1");
    List<PoolWithResourceConfig> config = loadPoolConfig("test/config", Optional.empty());
    poolService.updateFromConfig(config);
    List<Resource> resources = pollUntilResourcesMatch(bufferDao, poolId, ResourceState.READY, 2);
    resources.forEach(resource -> {
        try {
            assertProjectMatch(resource.cloudResourceUid(), config.get(0).resourceConfig().getGcpProjectConfig());
        } catch (Exception e) {
            fail("Error occurs when verifying GCP project creation", e);
        }
    });
    // Upgrade the size from 2 to 5. Expect 3 more resources will be created.
    bufferDao.updatePoolsSizes(ImmutableMap.of(poolId, 5));
    resources = pollUntilResourcesMatch(bufferDao, poolId, ResourceState.READY, 5);
    resources.forEach(resource -> {
        try {
            assertProjectMatch(resource.cloudResourceUid(), config.get(0).resourceConfig().getGcpProjectConfig());
        } catch (Exception e) {
            fail("Error occurs when verifying GCP project creation", e);
        }
    });
}
Also used : PoolWithResourceConfig(bio.terra.buffer.service.pool.PoolWithResourceConfig) PoolId(bio.terra.buffer.common.PoolId) Resource(bio.terra.buffer.common.Resource) BaseIntegrationTest(bio.terra.buffer.common.BaseIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 23 with Resource

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

the class CreateProjectFlightIntegrationTest method assertProjectExists.

private Project assertProjectExists(ResourceId resourceId) throws Exception {
    Resource resource = bufferDao.retrieveResource(resourceId).get();
    Project project = rmCow.projects().get(resource.cloudResourceUid().getGoogleProjectUid().getProjectId()).execute();
    assertEquals("ACTIVE", project.getState());
    assertThat(project.getLabels().entrySet(), Matchers.hasItems(Map.entry(NETWORK_LABEL_KEY, NETWORK_NAME), Map.entry(SUB_NETWORK_LABEL_KEY, SUBNETWORK_NAME), Map.entry(LEONARDO_ALLOW_HTTPS_FIREWALL_RULE_NAME_LABEL_KEY, LEONARDO_SSL_FOR_VPC_NETWORK_RULE_NAME), Map.entry(LEONARDO_ALLOW_INTERNAL_RULE_NAME_LABEL_KEY, ALLOW_INTERNAL_FOR_VPC_NETWORK_RULE_NAME), Map.entry(CONFIG_NAME_LABEL_KEY, TEST_CONFIG_NAME)));
    return project;
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project) Resource(bio.terra.buffer.common.Resource)

Example 24 with Resource

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

the class CreateProjectFlightIntegrationTest method errorCreateProject_noRollbackAfterResourceReady.

@Test
public void errorCreateProject_noRollbackAfterResourceReady() throws Exception {
    // Verify project and db entity won't get deleted if resource id READY, even the flight fails.
    FlightManager manager = new FlightManager(bufferDao, new StubSubmissionFlightFactory(ErrorAfterCreateResourceFlight.class), stairwayComponent, transactionTemplate);
    Pool pool = preparePool(bufferDao, newBasicGcpConfig());
    String flightId = manager.submitCreationFlight(pool).get();
    extractResourceIdFromFlightState(blockUntilFlightComplete(stairwayComponent, flightId));
    Resource resource = bufferDao.retrieveResourcesRandomly(pool.id(), ResourceState.READY, 1).get(0);
    assertEquals("ACTIVE", rmCow.projects().get(resource.cloudResourceUid().getGoogleProjectUid().getProjectId()).execute().getState());
    assertEquals(FlightStatus.ERROR, stairwayComponent.get().getFlightState(flightId).getFlightStatus());
}
Also used : Resource(bio.terra.buffer.common.Resource) Pool(bio.terra.buffer.common.Pool) IntegrationUtils.preparePool(bio.terra.buffer.integration.IntegrationUtils.preparePool) FlightManager(bio.terra.buffer.service.resource.FlightManager) StubSubmissionFlightFactory(bio.terra.buffer.integration.IntegrationUtils.StubSubmissionFlightFactory) Test(org.junit.jupiter.api.Test) BaseIntegrationTest(bio.terra.buffer.common.BaseIntegrationTest)

Example 25 with Resource

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

the class DeleteProjectFlightIntegrationTest method testDeleteGoogleProject_errorWhenResourceStateChange.

@Test
public void testDeleteGoogleProject_errorWhenResourceStateChange() throws Exception {
    LatchStep.startNewLatch();
    Pool pool = preparePool(bufferDao, newBasicGcpConfig());
    ResourceId resourceId = ResourceId.create(UUID.randomUUID());
    bufferDao.createResource(Resource.builder().id(resourceId).poolId(pool.id()).creation(Instant.now()).state(ResourceState.READY).build());
    Resource resource = bufferDao.retrieveResource(resourceId).get();
    FlightManager manager = new FlightManager(bufferDao, new StubSubmissionFlightFactory(LatchBeforeAssertResourceStep.class), stairwayComponent, transactionTemplate);
    String deleteFlightId = manager.submitDeletionFlight(resource, ResourceType.GOOGLE_PROJECT).get();
    // Delete the resource from DB.
    assertTrue(bufferDao.deleteResource(resource.id()));
    // Release the latch, and resume the flight, assert flight failed.
    LatchStep.releaseLatch();
    extractResourceIdFromFlightState(blockUntilFlightComplete(stairwayComponent, deleteFlightId));
    // Resource is deleted.
    assertFalse(bufferDao.retrieveResource(resource.id()).isPresent());
    assertEquals(FlightStatus.ERROR, stairwayComponent.get().getFlightState(deleteFlightId).getFlightStatus());
}
Also used : ResourceId(bio.terra.buffer.common.ResourceId) Resource(bio.terra.buffer.common.Resource) IntegrationUtils.preparePool(bio.terra.buffer.integration.IntegrationUtils.preparePool) Pool(bio.terra.buffer.common.Pool) FlightManager(bio.terra.buffer.service.resource.FlightManager) StubSubmissionFlightFactory(bio.terra.buffer.integration.IntegrationUtils.StubSubmissionFlightFactory) BaseIntegrationTest(bio.terra.buffer.common.BaseIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Resource (bio.terra.buffer.common.Resource)25 Pool (bio.terra.buffer.common.Pool)18 Test (org.junit.jupiter.api.Test)18 BaseUnitTest (bio.terra.buffer.common.BaseUnitTest)11 BaseIntegrationTest (bio.terra.buffer.common.BaseIntegrationTest)7 IntegrationUtils.preparePool (bio.terra.buffer.integration.IntegrationUtils.preparePool)6 FlightManager (bio.terra.buffer.service.resource.FlightManager)6 StubSubmissionFlightFactory (bio.terra.buffer.integration.IntegrationUtils.StubSubmissionFlightFactory)5 PoolId (bio.terra.buffer.common.PoolId)3 ResourceId (bio.terra.buffer.common.ResourceId)3 Project (com.google.api.services.cloudresourcemanager.v3.model.Project)3 CloudResourceUid (bio.terra.buffer.generated.model.CloudResourceUid)2 GoogleProjectUid (bio.terra.buffer.generated.model.GoogleProjectUid)2 InternalServerErrorException (bio.terra.common.exception.InternalServerErrorException)2 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)2 Transactional (org.springframework.transaction.annotation.Transactional)2 PrimaryConfiguration (bio.terra.buffer.app.configuration.PrimaryConfiguration)1 RequestHandoutId (bio.terra.buffer.common.RequestHandoutId)1 NotFoundException (bio.terra.buffer.common.exception.NotFoundException)1 ResourceConfig (bio.terra.buffer.generated.model.ResourceConfig)1