Search in sources :

Example 6 with ResourceId

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

the class PoolServiceTest method newReadyPool.

/**
 * Creates a pool with resources with given size.
 */
private void newReadyPool(PoolId poolId, int poolSize) {
    Pool pool = Pool.builder().creation(Instant.now()).id(poolId).resourceType(ResourceType.GOOGLE_PROJECT).size(poolSize).resourceConfig(new ResourceConfig().configName("resourceName")).status(PoolStatus.ACTIVE).build();
    bufferDao.createPools(ImmutableList.of(pool));
    for (int i = 0; i < poolSize; i++) {
        ResourceId id = ResourceId.create(UUID.randomUUID());
        bufferDao.createResource(Resource.builder().id(id).poolId(poolId).creation(Instant.now()).state(ResourceState.CREATING).build());
        bufferDao.updateResourceAsReady(id, newProjectUid());
    }
}
Also used : ResourceId(bio.terra.buffer.common.ResourceId) Pool(bio.terra.buffer.common.Pool) ResourceConfig(bio.terra.buffer.generated.model.ResourceConfig)

Example 7 with ResourceId

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

the class FlightManager method createResourceEntityAndSubmitFlight.

/**
 * Create entity in resource table with CREATING and submit creation flight.
 *
 * <p>If the Stairway submission fails, the transaction will be rolled back. If the Stairway
 * submission succeeds but the DB update transaction fails, the flight checks the DB state and
 * aborts if the state is bad.
 */
private Optional<String> createResourceEntityAndSubmitFlight(Pool pool, TransactionStatus status) {
    ResourceId resourceId = ResourceId.create(UUID.randomUUID());
    bufferDao.createResource(Resource.builder().id(resourceId).poolId(pool.id()).creation(Instant.now()).state(ResourceState.CREATING).build());
    return submitToStairway(flightSubmissionFactory.getCreationFlightSubmission(pool, resourceId), status);
}
Also used : ResourceId(bio.terra.buffer.common.ResourceId)

Example 8 with ResourceId

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

the class UpdateResourceAsDeletedStep method doStep.

@Override
public StepResult doStep(FlightContext flightContext) {
    ResourceId resourceId = ResourceId.retrieve(flightContext.getInputParameters());
    bufferDao.updateResourceAsDeleted(resourceId, Instant.now());
    return StepResult.getStepResultSuccess();
}
Also used : ResourceId(bio.terra.buffer.common.ResourceId)

Example 9 with ResourceId

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

the class CreateProjectFlightIntegrationTest method testCreateGoogleProject_createGkeSA_true.

@Test
public void testCreateGoogleProject_createGkeSA_true() throws Exception {
    FlightManager manager = new FlightManager(bufferDao, flightSubmissionFactoryImpl, stairwayComponent, transactionTemplate);
    Pool pool = preparePool(bufferDao, newBasicGcpConfig().kubernetesEngine(new KubernetesEngine().createGkeDefaultServiceAccount(true)));
    String flightId = manager.submitCreationFlight(pool).get();
    ResourceId resourceId = extractResourceIdFromFlightState(blockUntilFlightComplete(stairwayComponent, flightId));
    Project project = assertProjectExists(resourceId);
    String projectId = project.getProjectId();
    String serviceAccountEmail = ServiceAccountName.emailFromAccountId(GKE_SA_NAME, projectId);
    assertServiceAccountExists(project, serviceAccountEmail);
    List<IamBinding> expectedGkeSABindings = new ArrayList<>();
    GKE_SA_ROLES.forEach(r -> expectedGkeSABindings.add(new IamBinding().role(r).addMembersItem("serviceAccount:" + serviceAccountEmail)));
    assertIamBindingsContains(project, expectedGkeSABindings);
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project) ResourceId(bio.terra.buffer.common.ResourceId) ArrayList(java.util.ArrayList) Pool(bio.terra.buffer.common.Pool) IntegrationUtils.preparePool(bio.terra.buffer.integration.IntegrationUtils.preparePool) FlightManager(bio.terra.buffer.service.resource.FlightManager) Test(org.junit.jupiter.api.Test) BaseIntegrationTest(bio.terra.buffer.common.BaseIntegrationTest)

Example 10 with ResourceId

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

the class CreateProjectFlightIntegrationTest method testCreateGoogleProject_blockInternetAccessWithGcrDnsEnabled.

@Test
public void testCreateGoogleProject_blockInternetAccessWithGcrDnsEnabled() throws Exception {
    FlightManager manager = new FlightManager(bufferDao, flightSubmissionFactoryImpl, stairwayComponent, transactionTemplate);
    Pool pool = preparePool(bufferDao, newBasicGcpConfig().network(new bio.terra.buffer.generated.model.Network().enableNetworkMonitoring(true).enablePrivateGoogleAccess(true).enableCloudRegistryPrivateGoogleAccess(true).blockBatchInternetAccess(true)));
    String flightId = manager.submitCreationFlight(pool).get();
    ResourceId resourceId = extractResourceIdFromFlightState(blockUntilFlightComplete(stairwayComponent, flightId));
    Project project = assertProjectExists(resourceId);
    assertNetworkExists(project);
    assertSubnetsExist(project, NetworkMonitoring.ENABLED);
    assertRouteExists(project);
    assertDnsExists(project);
    assertGcrDnsExists(project);
    assertDefaultVpcNotExists(project);
    assertFirewallRulesExistForBlockInternetAccess(project);
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project) ResourceId(bio.terra.buffer.common.ResourceId) Network(com.google.api.services.compute.model.Network) Pool(bio.terra.buffer.common.Pool) IntegrationUtils.preparePool(bio.terra.buffer.integration.IntegrationUtils.preparePool) FlightManager(bio.terra.buffer.service.resource.FlightManager) Test(org.junit.jupiter.api.Test) BaseIntegrationTest(bio.terra.buffer.common.BaseIntegrationTest)

Aggregations

ResourceId (bio.terra.buffer.common.ResourceId)18 Pool (bio.terra.buffer.common.Pool)16 BaseIntegrationTest (bio.terra.buffer.common.BaseIntegrationTest)15 IntegrationUtils.preparePool (bio.terra.buffer.integration.IntegrationUtils.preparePool)15 FlightManager (bio.terra.buffer.service.resource.FlightManager)15 Test (org.junit.jupiter.api.Test)15 Project (com.google.api.services.cloudresourcemanager.v3.model.Project)13 StubSubmissionFlightFactory (bio.terra.buffer.integration.IntegrationUtils.StubSubmissionFlightFactory)4 Resource (bio.terra.buffer.common.Resource)3 bio.terra.buffer.generated.model (bio.terra.buffer.generated.model)3 Network (com.google.api.services.compute.model.Network)2 ResourceConfig (bio.terra.buffer.generated.model.ResourceConfig)1 ServiceUsageCow (bio.terra.cloudres.google.serviceusage.ServiceUsageCow)1 ListConsumerOverridesResponse (com.google.api.services.serviceusage.v1beta1.model.ListConsumerOverridesResponse)1 QuotaOverride (com.google.api.services.serviceusage.v1beta1.model.QuotaOverride)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Disabled (org.junit.jupiter.api.Disabled)1