Search in sources :

Example 26 with Workspace

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);
}
Also used : JobBuilder(bio.terra.workspace.service.job.JobBuilder) Workspace(bio.terra.workspace.service.workspace.model.Workspace)

Example 27 with Workspace

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();
}
Also used : FlightMap(bio.terra.stairway.FlightMap) SpendProfileId(bio.terra.workspace.service.spendprofile.SpendProfileId) Workspace(bio.terra.workspace.service.workspace.model.Workspace) SpendProfile(bio.terra.workspace.service.spendprofile.SpendProfile)

Example 28 with Workspace

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();
}
Also used : DuplicateWorkspaceException(bio.terra.workspace.service.workspace.exceptions.DuplicateWorkspaceException) UUID(java.util.UUID) Workspace(bio.terra.workspace.service.workspace.model.Workspace)

Example 29 with Workspace

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);
}
Also used : Workspace(bio.terra.workspace.service.workspace.model.Workspace) Traced(io.opencensus.contrib.spring.aop.Traced)

Example 30 with Workspace

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();
}
Also used : CreateGcpContextFlightV2(bio.terra.workspace.service.workspace.flight.CreateGcpContextFlightV2) BufferServiceDisabledException(bio.terra.workspace.service.workspace.exceptions.BufferServiceDisabledException) Workspace(bio.terra.workspace.service.workspace.model.Workspace) Traced(io.opencensus.contrib.spring.aop.Traced)

Aggregations

Workspace (bio.terra.workspace.service.workspace.model.Workspace)56 Test (org.junit.jupiter.api.Test)32 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)23 UUID (java.util.UUID)13 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)9 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)8 FlightDebugInfo (bio.terra.stairway.FlightDebugInfo)6 HashMap (java.util.HashMap)6 FlightMap (bio.terra.stairway.FlightMap)5 StepStatus (bio.terra.stairway.StepStatus)5 ApiClonedWorkspace (bio.terra.workspace.generated.model.ApiClonedWorkspace)5 ApiCreatedWorkspace (bio.terra.workspace.generated.model.ApiCreatedWorkspace)5 SpendProfileId (bio.terra.workspace.service.spendprofile.SpendProfileId)5 DisabledIfEnvironmentVariable (org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)5 ResponseEntity (org.springframework.http.ResponseEntity)5 Traced (io.opencensus.contrib.spring.aop.Traced)4 FlightState (bio.terra.stairway.FlightState)3 ControlledBigQueryDatasetResource (bio.terra.workspace.service.resource.controlled.cloud.gcp.bqdataset.ControlledBigQueryDatasetResource)3 CreateWorkspaceStep (bio.terra.workspace.service.workspace.flight.CreateWorkspaceStep)3 GcpCloudContext (bio.terra.workspace.service.workspace.model.GcpCloudContext)3