use of bio.terra.service.resourcemanagement.BillingProfile in project jade-data-repo by DataBiosphere.
the class GoogleResourceService method setupBilling.
private void setupBilling(GoogleProjectResource project) {
BillingProfile billingProfile = profileService.getProfileById(project.getProfileId());
billingService.assignProjectBilling(billingProfile, project);
}
use of bio.terra.service.resourcemanagement.BillingProfile in project jade-data-repo by DataBiosphere.
the class GoogleResourceService method newProject.
private GoogleProjectResource newProject(GoogleProjectRequest projectRequest, String googleProjectId) throws InterruptedException {
BillingProfile profile = profileService.getProfileById(projectRequest.getProfileId());
logger.info("creating a new project: {}", projectRequest.getProjectId());
if (!profile.isAccessible()) {
throw new InaccessibleBillingAccountException("The repository needs access to this billing account " + "in order to create: " + googleProjectId);
}
// projects created by service accounts must live under a parent resource (either a folder or an organization)
ResourceId parentResource = new ResourceId().setType(resourceConfiguration.getParentResourceType()).setId(resourceConfiguration.getParentResourceId());
Project requestBody = new Project().setName(googleProjectId).setProjectId(googleProjectId).setParent(parentResource);
try {
// kick off a project create request and poll until it is done
CloudResourceManager resourceManager = cloudResourceManager();
CloudResourceManager.Projects.Create request = resourceManager.projects().create(requestBody);
Operation operation = request.execute();
long timeout = resourceConfiguration.getProjectCreateTimeoutSeconds();
blockUntilResourceOperationComplete(resourceManager, operation, timeout);
// it should be retrievable once the create operation is complete
Project project = getProject(googleProjectId);
if (project == null) {
throw new GoogleResourceException("Could not get project after creation");
}
String googleProjectNumber = project.getProjectNumber().toString();
GoogleProjectResource googleProjectResource = new GoogleProjectResource(projectRequest).googleProjectId(googleProjectId).googleProjectNumber(googleProjectNumber);
setupBilling(googleProjectResource);
enableServices(googleProjectResource);
enableIamPermissions(googleProjectResource.getRoleIdentityMapping(), googleProjectId);
UUID repositoryId = resourceDao.createProject(googleProjectResource);
return googleProjectResource.repositoryId(repositoryId);
} catch (IOException | GeneralSecurityException e) {
throw new GoogleResourceException("Could not create project", e);
}
}
Aggregations