use of bio.terra.workspace.service.workspace.model.Workspace in project terra-workspace-manager by DataBiosphere.
the class WsmApplicationService method commonAbleJob.
// Common method to launch and wait for enable and disable flights.
private WsmWorkspaceApplication commonAbleJob(AuthenticatedUserRequest userRequest, UUID workspaceId, UUID applicationId, AbleEnum ableEnum) {
Workspace workspace = workspaceService.validateWorkspaceAndAction(userRequest, workspaceId, SamConstants.SamWorkspaceAction.OWN);
stageService.assertMcWorkspace(workspace, (ableEnum == AbleEnum.ENABLE) ? "enableWorkspaceApplication" : "disableWorkspaceApplication");
String description = String.format("%s application %s on workspace %s", ableEnum.name().toLowerCase(), applicationId.toString(), workspaceId.toString());
JobBuilder job = jobService.newJob().description(description).flightClass(ApplicationAbleFlight.class).userRequest(userRequest).workspaceId(workspaceId.toString()).addParameter(WorkspaceFlightMapKeys.APPLICATION_ID, applicationId).addParameter(WsmApplicationKeys.APPLICATION_ABLE_ENUM, ableEnum);
return job.submitAndWait(WsmWorkspaceApplication.class);
}
use of bio.terra.workspace.service.workspace.model.Workspace in project terra-workspace-manager by DataBiosphere.
the class CheckSpendProfileStep method doStep.
@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
FlightMap workingMap = context.getWorkingMap();
Workspace workspace = workspaceDao.getWorkspace(workspaceId);
SpendProfileId spendProfileId = workspace.getSpendProfileId().orElseThrow(() -> MissingSpendProfileException.forWorkspace(workspaceId));
SpendProfile spendProfile = spendProfileService.authorizeLinking(spendProfileId, userRequest);
if (spendProfile.billingAccountId().isEmpty()) {
throw NoBillingAccountException.forSpendProfile(spendProfileId);
}
workingMap.put(BILLING_ACCOUNT_ID, spendProfile.billingAccountId());
return StepResult.getStepResultSuccess();
}
use of bio.terra.workspace.service.workspace.model.Workspace in project terra-workspace-manager by DataBiosphere.
the class CreateWorkspaceStep method doStep.
@Override
public StepResult doStep(FlightContext flightContext) throws RetryException, InterruptedException {
UUID workspaceId = workspace.getWorkspaceId();
try {
workspaceDao.createWorkspace(workspace);
} catch (DuplicateWorkspaceException ex) {
// This might be the result of a step re-running, or it might be an ID conflict. We can ignore
// this if the existing workspace matches the one we were about to create, otherwise rethrow.
Workspace existingWorkspace = workspaceDao.getWorkspace(workspaceId);
if (!workspace.equals(existingWorkspace)) {
throw ex;
}
}
FlightUtils.setResponse(flightContext, workspaceId, HttpStatus.OK);
logger.info("Workspace created with id {}", workspaceId);
return StepResult.getStepResultSuccess();
}
use of bio.terra.workspace.service.workspace.model.Workspace in project terra-workspace-manager by DataBiosphere.
the class WorkspaceService method deleteGcpCloudContext.
/**
* Delete the GCP cloud context for the workspace. Verifies workspace existence and write
* permission before deleting the cloud context.
*/
@Traced
public void deleteGcpCloudContext(UUID workspaceId, AuthenticatedUserRequest userRequest) {
Workspace workspace = validateWorkspaceAndAction(userRequest, workspaceId, SamConstants.SamWorkspaceAction.WRITE);
stageService.assertMcWorkspace(workspace, "deleteGcpCloudContext");
String workspaceName = workspace.getDisplayName().orElse("");
String jobDescription = String.format("Delete GCP cloud context for workspace: name: '%s' id: '%s' ", workspaceName, workspaceId);
jobService.newJob().description(jobDescription).flightClass(DeleteGcpContextFlight.class).userRequest(userRequest).operationType(OperationType.DELETE).workspaceId(workspaceId.toString()).submitAndWait(null);
}
use of bio.terra.workspace.service.workspace.model.Workspace in project terra-workspace-manager by DataBiosphere.
the class WorkspaceService method createGcpCloudContext.
/**
* Process the request to create a GCP cloud context
*
* @param workspaceId workspace in which to create the context
* @param jobId caller-supplied job id of the async job
* @param userRequest user authentication info
* @param resultPath optional endpoint where the result of the completed job can be retrieved
*/
@Traced
public void createGcpCloudContext(UUID workspaceId, String jobId, AuthenticatedUserRequest userRequest, @Nullable String resultPath) {
if (!bufferServiceConfiguration.getEnabled()) {
throw new BufferServiceDisabledException("Cannot create a GCP context in an environment where buffer service is disabled or not configured.");
}
Workspace workspace = validateWorkspaceAndAction(userRequest, workspaceId, SamConstants.SamWorkspaceAction.WRITE);
stageService.assertMcWorkspace(workspace, "createCloudContext");
String workspaceName = workspace.getDisplayName().orElse("");
String jobDescription = String.format("Create GCP cloud context for workspace: name: '%s' id: '%s' ", workspaceName, workspaceId);
jobService.newJob().description(jobDescription).jobId(jobId).flightClass(CreateGcpContextFlightV2.class).userRequest(userRequest).operationType(OperationType.CREATE).workspaceId(workspaceId.toString()).addParameter(JobMapKeys.RESULT_PATH.getKeyName(), resultPath).submit();
}
Aggregations