Search in sources :

Example 31 with Project

use of com.blackducksoftware.bdio2.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 32 with Project

use of com.blackducksoftware.bdio2.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 33 with Project

use of com.blackducksoftware.bdio2.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 34 with Project

use of com.blackducksoftware.bdio2.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)

Example 35 with Project

use of com.blackducksoftware.bdio2.model.Project in project terra-resource-buffer by DataBiosphere.

the class CreateProjectStep method doStep.

@Override
public StepResult doStep(FlightContext flightContext) throws RetryException {
    String projectId = flightContext.getWorkingMap().get(GOOGLE_PROJECT_ID, String.class);
    try {
        Project project = new Project().setProjectId(projectId).setLabels(createLabelMap(flightContext, gcpProjectConfig)).setParent("folders/" + gcpProjectConfig.getParentFolderId());
        OperationCow<?> operation = rmCow.operations().operationCow(rmCow.projects().create(project).execute());
        pollUntilSuccess(operation, Duration.ofSeconds(5), Duration.ofMinutes(5));
        Project createdProject = rmCow.projects().get(projectId).execute();
        flightContext.getWorkingMap().put(GOOGLE_PROJECT_NUMBER, getNumber(createdProject));
    } catch (IOException | InterruptedException e) {
        logger.info("Error when creating GCP project", e);
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
    }
    return StepResult.getStepResultSuccess();
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project) IOException(java.io.IOException)

Aggregations

Project (com.google.api.services.cloudresourcemanager.v3.model.Project)38 Test (org.junit.jupiter.api.Test)32 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 StepStatus (bio.terra.stairway.StepStatus)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 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 Project (com.blackducksoftware.bdio2.model.Project)6 UUID (java.util.UUID)6 Resource (bio.terra.buffer.common.Resource)5 bio.terra.buffer.generated.model (bio.terra.buffer.generated.model)5