Search in sources :

Example 36 with Project

use of com.google.api.services.cloudresourcemanager.v3.model.Project in project terra-cloud-resource-lib by DataBiosphere.

the class CloudBillingClientCowTest method getSetProjectBillingInfo.

@Test
public void getSetProjectBillingInfo() throws Exception {
    Project project = ProjectUtils.executeCreateProject();
    try (CloudBillingClientCow billingCow = defaultBillingCow()) {
        ProjectBillingInfo initialBilling = billingCow.getProjectBillingInfo("projects/" + project.getProjectId());
        assertEquals(project.getProjectId(), initialBilling.getProjectId());
        assertEquals("", initialBilling.getBillingAccountName());
        ProjectBillingInfo setBilling = ProjectBillingInfo.newBuilder().setBillingAccountName(BILLING_ACCOUNT_NAME).build();
        ProjectBillingInfo updatedBilling = billingCow.updateProjectBillingInfo("projects/" + project.getProjectId(), setBilling);
        assertEquals(project.getProjectId(), updatedBilling.getProjectId());
        assertEquals(BILLING_ACCOUNT_NAME, updatedBilling.getBillingAccountName());
    }
    ProjectUtils.getManagerCow().projects().delete(project.getProjectId());
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project) ProjectBillingInfo(com.google.cloud.billing.v1.ProjectBillingInfo) Test(org.junit.jupiter.api.Test)

Example 37 with Project

use of com.google.api.services.cloudresourcemanager.v3.model.Project in project terra-cloud-resource-lib by DataBiosphere.

the class CloudResourceManagerCowTest method createGetDeleteProject.

@Test
public void createGetDeleteProject() throws Exception {
    CloudResourceManagerCow managerCow = defaultManager();
    String projectId = ProjectUtils.randomProjectId();
    assertThrows(GoogleJsonResponseException.class, () -> managerCow.projects().get(projectId).execute());
    Operation operation = managerCow.projects().create(defaultProject(projectId)).execute();
    OperationTestUtils.pollAndAssertSuccess(managerCow.operations().operationCow(operation), Duration.ofSeconds(5), Duration.ofSeconds(30));
    Project project = managerCow.projects().get(projectId).execute();
    assertEquals(projectId, project.getProjectId());
    assertEquals("ACTIVE", project.getState());
    Operation deleteOperation = managerCow.projects().delete(projectId).execute();
    OperationTestUtils.pollAndAssertSuccess(managerCow.operations().operationCow(deleteOperation), Duration.ofSeconds(5), Duration.ofSeconds(30));
    // After "deletion," the project still exists for up to 30 days where it can be recovered.
    project = managerCow.projects().get(projectId).execute();
    assertEquals("DELETE_REQUESTED", project.getState());
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project) Operation(com.google.api.services.cloudresourcemanager.v3.model.Operation) Test(org.junit.jupiter.api.Test)

Example 38 with Project

use of com.google.api.services.cloudresourcemanager.v3.model.Project in project terra-cloud-resource-lib by DataBiosphere.

the class CloudComputeCowTest method createPreparedProject.

/**
 * Create Project then set billing account, enable compute compute service
 */
private static Project createPreparedProject() throws Exception {
    Project project = ProjectUtils.executeCreateProject();
    CloudBillingUtils.setDefaultProjectBilling(project.getProjectId());
    ServiceUsageUtils.enableServices(project.getProjectId(), ImmutableList.of(COMPUTE_SERVICE_ID));
    return project;
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project)

Example 39 with Project

use of com.google.api.services.cloudresourcemanager.v3.model.Project in project terra-cloud-resource-lib by DataBiosphere.

the class DnsCowTest method createAndGetChange.

@Test
public void createAndGetChange() throws Exception {
    Project project = ProjectUtils.executeCreateProject();
    String projectId = project.getProjectId();
    CloudBillingUtils.setDefaultProjectBilling(projectId);
    ServiceUsageUtils.enableServices(projectId, SERVICE_IDS);
    DnsCow dnsCow = defaultDns();
    ManagedZone managedZone = new ManagedZone().setName("zone-name").setDnsName("googleapis.com.").setVisibility("private").setDescription("description");
    dnsCow.managedZones().create(project.getProjectId(), managedZone).execute();
    ResourceRecordSet resourceRecordSet = new ResourceRecordSet().setType("A").setName("restricted.googleapis.com.").setRrdatas(ImmutableList.of("199.36.153.4")).setTtl(300);
    Change createdChange = dnsCow.changes().create(project.getProjectId(), managedZone.getName(), new Change().setAdditions(ImmutableList.of(resourceRecordSet))).execute();
    List<ResourceRecordSet> actualRecordSet = dnsCow.changes().get(projectId, managedZone.getName(), createdChange.getId()).execute().getAdditions();
    assertEquals(1, actualRecordSet.size());
    assertEquals("A", actualRecordSet.get(0).getType());
    assertEquals("restricted.googleapis.com.", actualRecordSet.get(0).getName());
    assertEquals("199.36.153.4", actualRecordSet.get(0).getRrdatas().get(0));
    assertEquals(300, actualRecordSet.get(0).getTtl());
    assertThat(dnsCow.resourceRecordSets().list(projectId, managedZone.getName()).execute().getRrsets(), Matchers.hasItem(actualRecordSet.get(0)));
}
Also used : ResourceRecordSet(com.google.api.services.dns.model.ResourceRecordSet) Project(com.google.api.services.cloudresourcemanager.v3.model.Project) ManagedZone(com.google.api.services.dns.model.ManagedZone) Change(com.google.api.services.dns.model.Change) Test(org.junit.jupiter.api.Test)

Example 40 with Project

use of com.google.api.services.cloudresourcemanager.v3.model.Project in project terra-cloud-resource-lib by DataBiosphere.

the class ProjectUtils method executeCreateProject.

/**
 * Creates a new Google Project in GCP for testing.
 */
public static Project executeCreateProject() throws Exception {
    Project project = new Project().setProjectId(randomProjectId()).setParent(PARENT_RESOURCE);
    Operation operation = getManagerCow().projects().create(project).execute();
    OperationCow<Operation> operationCow = managerCow.operations().operationCow(operation);
    OperationTestUtils.pollAndAssertSuccess(operationCow, Duration.ofSeconds(5), Duration.ofSeconds(60));
    return managerCow.projects().get(project.getProjectId()).execute();
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project) Operation(com.google.api.services.cloudresourcemanager.v3.model.Operation)

Aggregations

Project (com.google.api.services.cloudresourcemanager.v3.model.Project)38 Test (org.junit.jupiter.api.Test)30 BaseIntegrationTest (bio.terra.buffer.common.BaseIntegrationTest)15 Pool (bio.terra.buffer.common.Pool)15 ResourceId (bio.terra.buffer.common.ResourceId)15 IntegrationUtils.preparePool (bio.terra.buffer.integration.IntegrationUtils.preparePool)15 FlightManager (bio.terra.buffer.service.resource.FlightManager)15 IOException (java.io.IOException)13 Binding (com.google.api.services.cloudresourcemanager.v3.model.Binding)10 StepStatus (bio.terra.stairway.StepStatus)9 ArrayList (java.util.ArrayList)9 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)8 List (java.util.List)8 DisabledIfEnvironmentVariable (org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)8 FlightDebugInfo (bio.terra.stairway.FlightDebugInfo)7 FlightState (bio.terra.stairway.FlightState)7 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)7 GetIamPolicyRequest (com.google.api.services.cloudresourcemanager.v3.model.GetIamPolicyRequest)7 FlightMap (bio.terra.stairway.FlightMap)6 Project (com.blackducksoftware.bdio2.model.Project)6