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);
}
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);
}
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")));
}
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;
}
Aggregations