Search in sources :

Example 1 with CreateControlledGcpAiNotebookInstanceRequestBody

use of bio.terra.workspace.model.CreateControlledGcpAiNotebookInstanceRequestBody 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 2 with CreateControlledGcpAiNotebookInstanceRequestBody

use of bio.terra.workspace.model.CreateControlledGcpAiNotebookInstanceRequestBody in project terra-cli by DataBiosphere.

the class WorkspaceManagerService method createControlledGcpNotebookInstance.

/**
 * Call the Workspace Manager POST
 * "/api/workspaces/v1/{workspaceId}/resources/controlled/gcp/ai-notebook-instance" endpoint to
 * add a GCP notebook instance as a controlled resource in the workspace.
 *
 * @param workspaceId the workspace to add the resource to
 * @param createParams resource definition to create
 * @return the GCP notebook instance resource object
 */
public GcpAiNotebookInstanceResource createControlledGcpNotebookInstance(UUID workspaceId, CreateGcpNotebookParams createParams) {
    // convert the CLI object to a WSM request object
    String jobId = UUID.randomUUID().toString();
    CreateControlledGcpAiNotebookInstanceRequestBody createRequest = new CreateControlledGcpAiNotebookInstanceRequestBody().common(createCommonFields(createParams.resourceFields)).aiNotebookInstance(fromCLIObject(createParams)).jobControl(new JobControl().id(jobId));
    logger.debug("Create controlled GCP notebook request {}", createRequest);
    return handleClientExceptions(() -> {
        ControlledGcpResourceApi controlledGcpResourceApi = new ControlledGcpResourceApi(apiClient);
        // Start the GCP notebook creation job.
        HttpUtils.callWithRetries(() -> controlledGcpResourceApi.createAiNotebookInstance(createRequest, workspaceId), WorkspaceManagerService::isRetryable);
        // Poll the result endpoint until the job is no longer RUNNING.
        CreatedControlledGcpAiNotebookInstanceResult createResult = HttpUtils.pollWithRetries(() -> controlledGcpResourceApi.getCreateAiNotebookInstanceResult(workspaceId, jobId), (result) -> isDone(result.getJobReport()), WorkspaceManagerService::isRetryable, // Creating a GCP notebook instance should take less than ~10 minutes.
        60, Duration.ofSeconds(10));
        logger.debug("Create controlled GCP notebook result {}", createResult);
        throwIfJobNotCompleted(createResult.getJobReport(), createResult.getErrorReport());
        return createResult.getAiNotebookInstance();
    }, "Error creating controlled GCP Notebook instance in the workspace.");
}
Also used : CreatedControlledGcpAiNotebookInstanceResult(bio.terra.workspace.model.CreatedControlledGcpAiNotebookInstanceResult) CreateControlledGcpAiNotebookInstanceRequestBody(bio.terra.workspace.model.CreateControlledGcpAiNotebookInstanceRequestBody) JobControl(bio.terra.workspace.model.JobControl) ControlledGcpResourceApi(bio.terra.workspace.api.ControlledGcpResourceApi)

Aggregations

CreateControlledGcpAiNotebookInstanceRequestBody (bio.terra.workspace.model.CreateControlledGcpAiNotebookInstanceRequestBody)2 JobControl (bio.terra.workspace.model.JobControl)2 ControlledGcpResourceApi (bio.terra.workspace.api.ControlledGcpResourceApi)1 ControlledResourceCommonFields (bio.terra.workspace.model.ControlledResourceCommonFields)1 CreatedControlledGcpAiNotebookInstanceResult (bio.terra.workspace.model.CreatedControlledGcpAiNotebookInstanceResult)1 GcpAiNotebookInstanceCreationParameters (bio.terra.workspace.model.GcpAiNotebookInstanceCreationParameters)1 GcpAiNotebookInstanceVmImage (bio.terra.workspace.model.GcpAiNotebookInstanceVmImage)1