use of bio.terra.workspace.model.CreateWorkspaceRequestBody 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");
}
use of bio.terra.workspace.model.CreateWorkspaceRequestBody in project terra-workspace-manager by DataBiosphere.
the class WorkspaceAllocateTestScriptBase method createWorkspace.
/**
* Utility for making the WSM calls to create a workspace. Exposed as protected for test
* implementations which need to create additional workspaces.
*/
protected CreatedWorkspace createWorkspace(UUID workspaceId, String spendProfileId, WorkspaceApi workspaceApi) throws Exception {
final var requestBody = new CreateWorkspaceRequestBody().id(workspaceId).spendProfile(spendProfileId).stage(getStageModel());
final CreatedWorkspace workspace = workspaceApi.createWorkspace(requestBody);
assertThat(workspace.getId(), equalTo(workspaceId));
return workspace;
}
use of bio.terra.workspace.model.CreateWorkspaceRequestBody in project terra-cli by DataBiosphere.
the class WorkspaceManagerService method createWorkspace.
/**
* Call the Workspace Manager POST "/api/workspaces/v1" endpoint to create a new workspace, then
* call the POST "/api/workspaces/v1/{workspaceId}/cloudcontexts" endpoint to create a new backing
* Google context. Poll the "/api/workspaces/v1/{workspaceId}/cloudcontexts/results/{jobId}"
* endpoint to wait for the job to finish.
*
* @param displayName optional display name
* @param description optional description
* @return the Workspace Manager workspace description object
* @throws SystemException if the job to create the workspace cloud context fails
* @throws UserActionableException if the CLI times out waiting for the job to complete
*/
public WorkspaceDescription createWorkspace(@Nullable String displayName, @Nullable String description) {
return handleClientExceptions(() -> {
// create the Terra workspace object
UUID workspaceId = UUID.randomUUID();
CreateWorkspaceRequestBody workspaceRequestBody = new CreateWorkspaceRequestBody();
workspaceRequestBody.setId(workspaceId);
workspaceRequestBody.setStage(WorkspaceStageModel.MC_WORKSPACE);
workspaceRequestBody.setSpendProfile(Context.getServer().getWsmDefaultSpendProfile());
workspaceRequestBody.setDisplayName(displayName);
workspaceRequestBody.setDescription(description);
// make the create workspace request
WorkspaceApi workspaceApi = new WorkspaceApi(apiClient);
HttpUtils.callWithRetries(() -> workspaceApi.createWorkspace(workspaceRequestBody), WorkspaceManagerService::isRetryable);
// create the Google project that backs the Terra workspace object
UUID jobId = UUID.randomUUID();
CreateCloudContextRequest cloudContextRequest = new CreateCloudContextRequest();
cloudContextRequest.setCloudPlatform(CloudPlatform.GCP);
cloudContextRequest.setJobControl(new JobControl().id(jobId.toString()));
// make the initial create context request
HttpUtils.callWithRetries(() -> workspaceApi.createCloudContext(cloudContextRequest, workspaceId), WorkspaceManagerService::isRetryable);
// poll the result endpoint until the job is no longer RUNNING
CreateCloudContextResult createContextResult = HttpUtils.pollWithRetries(() -> workspaceApi.getCreateCloudContextResult(workspaceId, jobId.toString()), (result) -> isDone(result.getJobReport()), WorkspaceManagerService::isRetryable, CREATE_WORKSPACE_MAXIMUM_RETRIES, CREATE_WORKSPACE_DURATION_SLEEP_FOR_RETRY);
logger.debug("create workspace context result: {}", createContextResult);
StatusEnum status = createContextResult.getJobReport().getStatus();
if (StatusEnum.FAILED == status) {
// need to delete the empty workspace before continuing
boolean workspaceSuccessfullyDeleted = false;
try {
deleteWorkspace(workspaceId);
workspaceSuccessfullyDeleted = true;
} catch (RuntimeException ex) {
logger.error("Failed to delete workspace {} when cleaning up failed creation of cloud context. ", workspaceId, ex);
}
// message
if (createContextResult.getErrorReport().getMessage().contains("spend profile") && createContextResult.getErrorReport().getStatusCode() == HttpStatusCodes.STATUS_CODE_FORBIDDEN) {
final String errorMessage;
if (workspaceSuccessfullyDeleted) {
errorMessage = "Accessing the spend profile failed. Ask an administrator to grant you access.";
} else {
errorMessage = String.format("Accessing the spend profile failed. Ask an administrator to grant you access. " + "There was a problem cleaning up the partially created workspace ID %s", workspaceId);
}
throw new UserActionableException(errorMessage);
}
}
// handle non-spend-profile-related failures
throwIfJobNotCompleted(createContextResult.getJobReport(), createContextResult.getErrorReport());
// call the get workspace endpoint to get the full description object
return HttpUtils.callWithRetries(() -> workspaceApi.getWorkspace(workspaceId), WorkspaceManagerService::isRetryable);
}, "Error creating a new workspace");
}
Aggregations