Search in sources :

Example 1 with GoogleProjectRequest

use of bio.terra.service.resourcemanagement.google.GoogleProjectRequest in project jade-data-repo by DataBiosphere.

the class DataLocationService method getOrCreateProject.

/**
 * Fetch existing SnapshotDataProject for the Snapshot.
 * Create a new one if none exists already.
 * @param snapshot
 * @return a populated and valid SnapshotDataProject
 */
public SnapshotDataProject getOrCreateProject(Snapshot snapshot) throws InterruptedException {
    // check if for an existing SnapshotDataProject first, and return here if found one
    Optional<SnapshotDataProject> existingDataProject = getProject(snapshot);
    if (existingDataProject.isPresent()) {
        return existingDataProject.get();
    }
    // if we've made it here, then we need to create a new cloud resource and SnapshotDataProject
    GoogleProjectRequest googleProjectRequest = new GoogleProjectRequest().projectId(dataLocationSelector.projectIdForSnapshot(snapshot)).profileId(snapshot.getProfileId()).serviceIds(DATA_PROJECT_SERVICE_IDS);
    GoogleProjectResource googleProjectResource = resourceService.getOrCreateProject(googleProjectRequest);
    // create the SnapshotDataProjectSummary object first, which just holds all the IDs
    SnapshotDataProjectSummary snapshotDataProjectSummary = new SnapshotDataProjectSummary().projectResourceId(googleProjectResource.getRepositoryId()).snapshotId(snapshot.getId());
    UUID snapshotDataProjectId = dataProjectDao.createSnapshotDataProject(snapshotDataProjectSummary);
    snapshotDataProjectSummary.id(snapshotDataProjectId);
    // then create the SnapshotDataProject object from the summary
    return new SnapshotDataProject(snapshotDataProjectSummary).googleProjectResource(googleProjectResource);
}
Also used : SnapshotDataProjectSummary(bio.terra.service.snapshot.SnapshotDataProjectSummary) GoogleProjectResource(bio.terra.service.resourcemanagement.google.GoogleProjectResource) GoogleProjectRequest(bio.terra.service.resourcemanagement.google.GoogleProjectRequest) UUID(java.util.UUID) SnapshotDataProject(bio.terra.service.snapshot.SnapshotDataProject)

Example 2 with GoogleProjectRequest

use of bio.terra.service.resourcemanagement.google.GoogleProjectRequest in project jade-data-repo by DataBiosphere.

the class DataLocationService method getOrCreateProject.

/**
 * Fetch existing DatasetDataProject for the Dataset.
 * Create a new one if none exists already.
 * Note that there can be only one project for a Dataset. This is assumed throughout the application logic, most of
 * which currently resides in the Flights, and they would not work correctly if this one-to-one mapping were ever
 * violated. For this reason, the check for an existing project below needs to stay at the beginning of this method.
 * @param dataset
 * @return a populated and valid DatasetDataProject
 */
public DatasetDataProject getOrCreateProject(Dataset dataset) throws InterruptedException {
    // check if for an existing DatasetDataProject first, and return here if found one
    Optional<DatasetDataProject> existingDataProject = getProject(dataset);
    if (existingDataProject.isPresent()) {
        return existingDataProject.get();
    }
    // if we've made it here, then we need to create a new cloud resource and DatasetDataProject
    // TODO: if we are in production, don't reuse projects we don't know about
    // TODO: add a property to specify which people can view data projects
    GoogleProjectRequest googleProjectRequest = new GoogleProjectRequest().projectId(dataLocationSelector.projectIdForDataset(dataset)).profileId(dataset.getDefaultProfileId()).serviceIds(DATA_PROJECT_SERVICE_IDS).roleIdentityMapping(getStewardPolicy());
    GoogleProjectResource googleProjectResource = resourceService.getOrCreateProject(googleProjectRequest);
    // create the DatasetDataProjectSummary object first, which just holds all the IDs
    DatasetDataProjectSummary datasetDataProjectSummary = new DatasetDataProjectSummary().projectResourceId(googleProjectResource.getRepositoryId()).datasetId(dataset.getId());
    UUID datasetDataProjectId = dataProjectDao.createDatasetDataProject(datasetDataProjectSummary);
    datasetDataProjectSummary.id(datasetDataProjectId);
    // then create the DatasetDataProject object from the summary
    return new DatasetDataProject(datasetDataProjectSummary).googleProjectResource(googleProjectResource);
}
Also used : GoogleProjectResource(bio.terra.service.resourcemanagement.google.GoogleProjectResource) GoogleProjectRequest(bio.terra.service.resourcemanagement.google.GoogleProjectRequest) DatasetDataProjectSummary(bio.terra.service.dataset.DatasetDataProjectSummary) DatasetDataProject(bio.terra.service.dataset.DatasetDataProject) UUID(java.util.UUID)

Example 3 with GoogleProjectRequest

use of bio.terra.service.resourcemanagement.google.GoogleProjectRequest in project jade-data-repo by DataBiosphere.

the class ResourceServiceTest method createAndDeleteProjectTest.

@Test
// this test should be unignored whenever there are changes to the project creation or deletion code
@Ignore
public void createAndDeleteProjectTest() throws Exception {
    // the project id can't be more than 30 characters
    String projectId = ("test-" + UUID.randomUUID().toString()).substring(0, 30);
    String role = "roles/bigquery.jobUser";
    String stewardsGroupEmail = "group:JadeStewards-dev@dev.test.firecloud.org";
    List<String> stewardsGroupEmailList = Lists.newArrayList();
    stewardsGroupEmailList.add(stewardsGroupEmail);
    Map<String, List<String>> roleToStewardMap = new HashMap();
    roleToStewardMap.put(role, stewardsGroupEmailList);
    GoogleProjectRequest projectRequest = new GoogleProjectRequest().projectId(projectId).profileId(UUID.fromString(profile.getId())).serviceIds(DataLocationService.DATA_PROJECT_SERVICE_IDS).roleIdentityMapping(roleToStewardMap);
    GoogleProjectResource projectResource = resourceService.getOrCreateProject(projectRequest);
    Project project = resourceService.getProject(projectId);
    assertThat("the project is active", project.getLifecycleState(), equalTo("ACTIVE"));
    // TODO check to make sure a steward can complete a job in another test
    resourceService.deleteProjectResource(projectResource.getRepositoryId());
    project = resourceService.getProject(projectId);
    assertThat("the project is not active after delete", project.getLifecycleState(), not(equalTo("ACTIVE")));
}
Also used : Project(com.google.api.services.cloudresourcemanager.model.Project) GoogleProjectResource(bio.terra.service.resourcemanagement.google.GoogleProjectResource) HashMap(java.util.HashMap) GoogleProjectRequest(bio.terra.service.resourcemanagement.google.GoogleProjectRequest) List(java.util.List) Ignore(org.junit.Ignore) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with GoogleProjectRequest

use of bio.terra.service.resourcemanagement.google.GoogleProjectRequest in project jade-data-repo by DataBiosphere.

the class BucketResourceTest method buildBucketRequest.

private GoogleBucketRequest buildBucketRequest(String bucketName) throws Exception {
    // build project request
    String role = "roles/bigquery.jobUser";
    String stewardsGroupEmail = "group:JadeStewards-dev@dev.test.firecloud.org";
    List<String> stewardsGroupEmailList = Lists.newArrayList();
    stewardsGroupEmailList.add(stewardsGroupEmail);
    Map<String, List<String>> roleToStewardMap = new HashMap();
    roleToStewardMap.put(role, stewardsGroupEmailList);
    GoogleProjectRequest projectRequest = new GoogleProjectRequest().projectId(resourceConfiguration.getProjectId() + "-data").profileId(UUID.fromString(profile.getId())).serviceIds(DataLocationService.DATA_PROJECT_SERVICE_IDS).roleIdentityMapping(roleToStewardMap);
    // create project metadata
    GoogleProjectResource projectResource = resourceService.getOrCreateProject(projectRequest);
    // create the bucket request
    BillingProfile billingProfile = profileService.getProfileById(UUID.fromString(profile.getId()));
    GoogleBucketRequest googleBucketRequest = new GoogleBucketRequest().googleProjectResource(projectResource).bucketName(bucketName).profileId(billingProfile.getId()).region(billingProfile.getGcsRegion());
    return googleBucketRequest;
}
Also used : GoogleProjectResource(bio.terra.service.resourcemanagement.google.GoogleProjectResource) HashMap(java.util.HashMap) GoogleProjectRequest(bio.terra.service.resourcemanagement.google.GoogleProjectRequest) ArrayList(java.util.ArrayList) List(java.util.List) GoogleBucketRequest(bio.terra.service.resourcemanagement.google.GoogleBucketRequest)

Aggregations

GoogleProjectRequest (bio.terra.service.resourcemanagement.google.GoogleProjectRequest)4 GoogleProjectResource (bio.terra.service.resourcemanagement.google.GoogleProjectResource)4 HashMap (java.util.HashMap)2 List (java.util.List)2 UUID (java.util.UUID)2 DatasetDataProject (bio.terra.service.dataset.DatasetDataProject)1 DatasetDataProjectSummary (bio.terra.service.dataset.DatasetDataProjectSummary)1 GoogleBucketRequest (bio.terra.service.resourcemanagement.google.GoogleBucketRequest)1 SnapshotDataProject (bio.terra.service.snapshot.SnapshotDataProject)1 SnapshotDataProjectSummary (bio.terra.service.snapshot.SnapshotDataProjectSummary)1 Project (com.google.api.services.cloudresourcemanager.model.Project)1 ArrayList (java.util.ArrayList)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1