Search in sources :

Example 1 with WorkspaceDescription

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

the class Workspace method get.

/**
 * Fetch an existing workspace, with resources populated
 *
 * @param id workspace id
 */
public static Workspace get(UUID id) {
    // call WSM to fetch the existing workspace object and backing Google context
    WorkspaceDescription loadedWorkspace = WorkspaceManagerService.fromContext().getWorkspace(id);
    logger.info("Loaded workspace: {}", loadedWorkspace);
    // convert the WSM object to a CLI object
    Workspace workspace = new Workspace(loadedWorkspace);
    workspace.populateResources();
    return workspace;
}
Also used : WorkspaceDescription(bio.terra.workspace.model.WorkspaceDescription) PDWorkspace(bio.terra.cli.serialization.persisted.PDWorkspace) ClonedWorkspace(bio.terra.workspace.model.ClonedWorkspace)

Example 2 with WorkspaceDescription

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

the class Workspace method create.

/**
 * Create a new workspace and set it as the current workspace.
 *
 * @param name optional display name
 * @param description optional description
 */
public static Workspace create(String name, String description) {
    // call WSM to create the workspace object and backing Google context
    WorkspaceDescription createdWorkspace = WorkspaceManagerService.fromContext().createWorkspace(name, description);
    logger.info("Created workspace: {}", createdWorkspace);
    // convert the WSM object to a CLI object
    Workspace workspace = new Workspace(createdWorkspace);
    // update the global context with the current workspace
    Context.setWorkspace(workspace);
    // fetch the pet SA email for the user + this workspace
    // do this here so we have them stored locally before the user tries to run an app in the
    // workspace. this is so we pay the cost of a SAM round-trip ahead of time, instead of slowing
    // down an app call
    Context.requireUser().fetchPetSaEmail();
    return workspace;
}
Also used : WorkspaceDescription(bio.terra.workspace.model.WorkspaceDescription) PDWorkspace(bio.terra.cli.serialization.persisted.PDWorkspace) ClonedWorkspace(bio.terra.workspace.model.ClonedWorkspace)

Example 3 with WorkspaceDescription

use of bio.terra.workspace.model.WorkspaceDescription in project terra-workspace-manager by DataBiosphere.

the class WorkspaceLifecycle method doUserJourney.

@Override
public void doUserJourney(TestUserSpecification testUser, WorkspaceApi workspaceApi) throws ApiException {
    UUID workspaceId = UUID.randomUUID();
    CreateWorkspaceRequestBody requestBody = new CreateWorkspaceRequestBody().id(workspaceId).stage(WorkspaceStageModel.MC_WORKSPACE);
    workspaceApi.createWorkspace(requestBody);
    ClientTestUtils.assertHttpSuccess(workspaceApi, "CREATE workspace");
    WorkspaceDescription workspaceDescription = workspaceApi.getWorkspace(workspaceId);
    ClientTestUtils.assertHttpSuccess(workspaceApi, "GET workspace");
    assertThat(workspaceDescription.getId(), equalTo(workspaceId));
    assertThat(workspaceDescription.getStage(), equalTo(WorkspaceStageModel.MC_WORKSPACE));
    UpdateWorkspaceRequestBody updateBody = new UpdateWorkspaceRequestBody().displayName(workspaceName).description(workspaceDescriptionString);
    WorkspaceDescription updatedDescription = workspaceApi.updateWorkspace(updateBody, workspaceId);
    ClientTestUtils.assertHttpSuccess(workspaceApi, "PATCH workspace");
    assertThat(updatedDescription.getDisplayName(), equalTo(workspaceName));
    assertThat(updatedDescription.getDescription(), equalTo(workspaceDescriptionString));
    workspaceApi.deleteWorkspace(workspaceId);
    ClientTestUtils.assertHttpSuccess(workspaceApi, "DELETE workspace");
}
Also used : WorkspaceDescription(bio.terra.workspace.model.WorkspaceDescription) CreateWorkspaceRequestBody(bio.terra.workspace.model.CreateWorkspaceRequestBody) UUID(java.util.UUID) UpdateWorkspaceRequestBody(bio.terra.workspace.model.UpdateWorkspaceRequestBody)

Example 4 with WorkspaceDescription

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

the class WorkspaceManagerService method getWorkspace.

/**
 * Call the Workspace Manager GET "/api/workspaces/v1/{id}" endpoint to fetch an existing
 * workspace.
 *
 * @param workspaceId the id of the workspace to fetch
 * @return the Workspace Manager workspace description object
 */
public WorkspaceDescription getWorkspace(UUID workspaceId) {
    WorkspaceDescription workspaceWithContext = callWithRetries(() -> new WorkspaceApi(apiClient).getWorkspace(workspaceId), "Error fetching workspace");
    String googleProjectId = (workspaceWithContext.getGcpContext() == null) ? null : workspaceWithContext.getGcpContext().getProjectId();
    logger.info("Workspace context: {}, project id: {}", workspaceWithContext.getId(), googleProjectId);
    return workspaceWithContext;
}
Also used : WorkspaceDescription(bio.terra.workspace.model.WorkspaceDescription) WorkspaceApi(bio.terra.workspace.api.WorkspaceApi)

Example 5 with WorkspaceDescription

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

the class Workspace method update.

/**
 * Update the mutable properties of the current workspace.
 *
 * @param name optional display name
 * @param description optional description
 * @throws UserActionableException if there is no current workspace
 */
public Workspace update(@Nullable String name, @Nullable String description) {
    // call WSM to update the existing workspace object
    WorkspaceDescription updatedWorkspace = WorkspaceManagerService.fromContext().updateWorkspace(id, name, description);
    logger.info("Updated workspace: {}", updatedWorkspace);
    // convert the WSM object to a CLI object
    Workspace workspace = new Workspace(updatedWorkspace);
    // update the global context with the current workspace
    Context.setWorkspace(workspace);
    return workspace;
}
Also used : WorkspaceDescription(bio.terra.workspace.model.WorkspaceDescription) PDWorkspace(bio.terra.cli.serialization.persisted.PDWorkspace) ClonedWorkspace(bio.terra.workspace.model.ClonedWorkspace)

Aggregations

WorkspaceDescription (bio.terra.workspace.model.WorkspaceDescription)8 PDWorkspace (bio.terra.cli.serialization.persisted.PDWorkspace)3 ClonedWorkspace (bio.terra.workspace.model.ClonedWorkspace)3 UUID (java.util.UUID)2 WorkspaceApi (bio.terra.workspace.api.WorkspaceApi)1 CloneWorkspaceRequest (bio.terra.workspace.model.CloneWorkspaceRequest)1 CloneWorkspaceResult (bio.terra.workspace.model.CloneWorkspaceResult)1 CreateWorkspaceRequestBody (bio.terra.workspace.model.CreateWorkspaceRequestBody)1 GcpGcsBucketResource (bio.terra.workspace.model.GcpGcsBucketResource)1 ResourceCloneDetails (bio.terra.workspace.model.ResourceCloneDetails)1 UpdateWorkspaceRequestBody (bio.terra.workspace.model.UpdateWorkspaceRequestBody)1 WorkspaceDescriptionList (bio.terra.workspace.model.WorkspaceDescriptionList)1 BigQuery (com.google.cloud.bigquery.BigQuery)1 QueryJobConfiguration (com.google.cloud.bigquery.QueryJobConfiguration)1 TableId (com.google.cloud.bigquery.TableId)1 TableResult (com.google.cloud.bigquery.TableResult)1 ArrayList (java.util.ArrayList)1