Search in sources :

Example 1 with ControlledResourceCommonFields

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);
}
Also used : ControlledResourceCommonFields(bio.terra.workspace.model.ControlledResourceCommonFields) GcpGcsBucketCreationParameters(bio.terra.workspace.model.GcpGcsBucketCreationParameters) CreateControlledGcpGcsBucketRequestBody(bio.terra.workspace.model.CreateControlledGcpGcsBucketRequestBody) GcpGcsBucketLifecycle(bio.terra.workspace.model.GcpGcsBucketLifecycle)

Example 2 with ControlledResourceCommonFields

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;
}
Also used : GcpAiNotebookInstanceCreationParameters(bio.terra.workspace.model.GcpAiNotebookInstanceCreationParameters) ControlledResourceCommonFields(bio.terra.workspace.model.ControlledResourceCommonFields) CreateControlledGcpAiNotebookInstanceRequestBody(bio.terra.workspace.model.CreateControlledGcpAiNotebookInstanceRequestBody) JobControl(bio.terra.workspace.model.JobControl) GcpAiNotebookInstanceVmImage(bio.terra.workspace.model.GcpAiNotebookInstanceVmImage)

Example 3 with ControlledResourceCommonFields

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;
}
Also used : ControlledResourceCommonFields(bio.terra.workspace.model.ControlledResourceCommonFields) PrivateResourceUser(bio.terra.workspace.model.PrivateResourceUser) PrivateResourceIamRoles(bio.terra.workspace.model.PrivateResourceIamRoles)

Aggregations

ControlledResourceCommonFields (bio.terra.workspace.model.ControlledResourceCommonFields)3 CreateControlledGcpAiNotebookInstanceRequestBody (bio.terra.workspace.model.CreateControlledGcpAiNotebookInstanceRequestBody)1 CreateControlledGcpGcsBucketRequestBody (bio.terra.workspace.model.CreateControlledGcpGcsBucketRequestBody)1 GcpAiNotebookInstanceCreationParameters (bio.terra.workspace.model.GcpAiNotebookInstanceCreationParameters)1 GcpAiNotebookInstanceVmImage (bio.terra.workspace.model.GcpAiNotebookInstanceVmImage)1 GcpGcsBucketCreationParameters (bio.terra.workspace.model.GcpGcsBucketCreationParameters)1 GcpGcsBucketLifecycle (bio.terra.workspace.model.GcpGcsBucketLifecycle)1 JobControl (bio.terra.workspace.model.JobControl)1 PrivateResourceIamRoles (bio.terra.workspace.model.PrivateResourceIamRoles)1 PrivateResourceUser (bio.terra.workspace.model.PrivateResourceUser)1