use of bio.terra.workspace.model.ControlledResourceCommonFields in project terra-workspace-manager by DataBiosphere.
the class GcsBucketUtils method makeControlledGcsBucket.
// Fully parameterized version; category-specific versions below
public static CreatedControlledGcpGcsBucket makeControlledGcsBucket(ControlledGcpResourceApi resourceApi, UUID workspaceId, String name, @Nullable String bucketName, AccessScope accessScope, ManagedBy managedBy, CloningInstructionsEnum cloningInstructions, @Nullable PrivateResourceUser privateUser) throws Exception {
var body = new CreateControlledGcpGcsBucketRequestBody().common(new ControlledResourceCommonFields().accessScope(accessScope).managedBy(managedBy).cloningInstructions(cloningInstructions).description("Description of " + name).name(name).privateResourceUser(privateUser)).gcsBucket(new GcpGcsBucketCreationParameters().name(bucketName).defaultStorageClass(GcpGcsBucketDefaultStorageClass.STANDARD).lifecycle(new GcpGcsBucketLifecycle().rules(BUCKET_LIFECYCLE_RULES)));
logger.info("Creating {} {} bucket in workspace {}", managedBy.name(), accessScope.name(), workspaceId);
return resourceApi.createBucket(body, workspaceId);
}
use of bio.terra.workspace.model.ControlledResourceCommonFields in project terra-workspace-manager by DataBiosphere.
the class NotebookUtils method makeControlledNotebookUserPrivate.
/**
* Create and return a private AI Platform Notebook controlled resource with constant values. This
* method calls the asynchronous creation endpoint and polls until the creation job completes.
*/
public static CreatedControlledGcpAiNotebookInstanceResult makeControlledNotebookUserPrivate(UUID workspaceId, @Nullable String instanceId, @Nullable String location, ControlledGcpResourceApi resourceApi) throws ApiException, InterruptedException {
// Fill out the minimum required fields to arbitrary values.
var creationParameters = new GcpAiNotebookInstanceCreationParameters().instanceId(instanceId).location(location).machineType("e2-standard-2").vmImage(new GcpAiNotebookInstanceVmImage().projectId("deeplearning-platform-release").imageFamily("r-latest-cpu-experimental"));
var commonParameters = new ControlledResourceCommonFields().name(RandomStringUtils.randomAlphabetic(6)).cloningInstructions(CloningInstructionsEnum.NOTHING).accessScope(AccessScope.PRIVATE_ACCESS).managedBy(ManagedBy.USER).privateResourceUser(null);
var body = new CreateControlledGcpAiNotebookInstanceRequestBody().aiNotebookInstance(creationParameters).common(commonParameters).jobControl(new JobControl().id(UUID.randomUUID().toString()));
var creationResult = resourceApi.createAiNotebookInstance(body, workspaceId);
String creationJobId = creationResult.getJobReport().getId();
creationResult = ClientTestUtils.pollWhileRunning(creationResult, () -> resourceApi.getCreateAiNotebookInstanceResult(workspaceId, creationJobId), CreatedControlledGcpAiNotebookInstanceResult::getJobReport, Duration.ofSeconds(10));
ClientTestUtils.assertJobSuccess("create ai notebook", creationResult.getJobReport(), creationResult.getErrorReport());
return creationResult;
}
use of bio.terra.workspace.model.ControlledResourceCommonFields in project terra-cli by DataBiosphere.
the class WorkspaceManagerService method createCommonFields.
/**
* Create a common fields WSM object from a Resource that is being used to create a controlled
* resource.
*/
private static ControlledResourceCommonFields createCommonFields(CreateResourceParams createParams) {
ControlledResourceCommonFields commonFields = new ControlledResourceCommonFields().name(createParams.name).description(createParams.description).cloningInstructions(createParams.cloningInstructions).accessScope(createParams.accessScope).managedBy(ManagedBy.USER);
if (createParams.accessScope == AccessScope.PRIVATE_ACCESS) {
// since private resources cannot be reassigned, it never makes sense to have less than full
// access to the resource, so add all possible IAM roles here.
PrivateResourceIamRoles privateResourceIamRoles = new PrivateResourceIamRoles();
privateResourceIamRoles.add(ControlledResourceIamRole.READER);
privateResourceIamRoles.add(ControlledResourceIamRole.WRITER);
privateResourceIamRoles.add(ControlledResourceIamRole.EDITOR);
commonFields.privateResourceUser(new PrivateResourceUser().userName(Context.requireUser().getEmail()).privateResourceIamRoles(privateResourceIamRoles));
}
return commonFields;
}
Aggregations