Search in sources :

Example 1 with JobBuilder

use of bio.terra.workspace.service.job.JobBuilder in project terra-workspace-manager by DataBiosphere.

the class ControlledResourceService method deleteControlledResourceSync.

/**
 * Synchronously delete a controlled resource.
 */
public void deleteControlledResourceSync(UUID workspaceId, UUID resourceId, AuthenticatedUserRequest userRequest) {
    JobBuilder deleteJob = commonDeletionJobBuilder(UUID.randomUUID().toString(), workspaceId, resourceId, null, userRequest);
    // Delete flight does not produce a result, so the resultClass parameter here is never used.
    deleteJob.submitAndWait(Void.class);
}
Also used : JobBuilder(bio.terra.workspace.service.job.JobBuilder)

Example 2 with JobBuilder

use of bio.terra.workspace.service.job.JobBuilder in project terra-workspace-manager by DataBiosphere.

the class ControlledResourceService method updateBqDataset.

/**
 * Starts an update controlled BigQuery dataset resource, blocking until its job is finished.
 */
public ControlledBigQueryDatasetResource updateBqDataset(ControlledBigQueryDatasetResource resource, @Nullable ApiGcpBigQueryDatasetUpdateParameters updateParameters, AuthenticatedUserRequest userRequest, @Nullable String resourceName, @Nullable String resourceDescription) {
    controlledResourceMetadataManager.validateControlledResourceAndAction(userRequest, resource.getWorkspaceId(), resource.getResourceId(), SamControlledResourceActions.EDIT_ACTION);
    final String jobDescription = String.format("Update controlled BigQuery Dataset name %s ; resource id %s; resource name %s", resource.getDatasetName(), resource.getResourceId(), resource.getName());
    final JobBuilder jobBuilder = jobService.newJob().description(jobDescription).flightClass(UpdateControlledBigQueryDatasetResourceFlight.class).resource(resource).userRequest(userRequest).operationType(OperationType.UPDATE).resourceType(resource.getResourceType()).resourceName(resource.getName()).workspaceId(resource.getWorkspaceId().toString()).stewardshipType(resource.getStewardshipType()).addParameter(ControlledResourceKeys.UPDATE_PARAMETERS, updateParameters).addParameter(ResourceKeys.RESOURCE_NAME, resourceName).addParameter(ResourceKeys.RESOURCE_DESCRIPTION, resourceDescription);
    return jobBuilder.submitAndWait(ControlledBigQueryDatasetResource.class);
}
Also used : JobBuilder(bio.terra.workspace.service.job.JobBuilder)

Example 3 with JobBuilder

use of bio.terra.workspace.service.job.JobBuilder in project terra-workspace-manager by DataBiosphere.

the class ReferencedResourceService method createReferenceResource.

@Traced
public ReferencedResource createReferenceResource(ReferencedResource resource, AuthenticatedUserRequest userRequest) {
    workspaceService.validateWorkspaceAndAction(userRequest, resource.getWorkspaceId(), SamConstants.SamWorkspaceAction.CREATE_REFERENCE);
    String jobDescription = String.format("Create reference %s; id %s; name %s", resource.getResourceType(), resource.getResourceId(), resource.getName());
    // The reason for separately passing in the ResourceType is to retrieve the class for this
    // particular request. In the flight, when we get the request object from the input parameters,
    // we can supply the right target class.
    JobBuilder createJob = jobService.newJob().description(jobDescription).flightClass(CreateReferenceResourceFlight.class).resource(resource).userRequest(userRequest).operationType(OperationType.CREATE).workspaceId(resource.getWorkspaceId().toString()).resourceType(resource.getResourceType()).stewardshipType(StewardshipType.REFERENCED);
    UUID resourceIdResult = createJob.submitAndWait(UUID.class);
    if (!resourceIdResult.equals(resource.getResourceId())) {
        throw new InvalidMetadataException("Input and output resource ids do not match");
    }
    return getReferenceResource(resource.getWorkspaceId(), resourceIdResult, userRequest);
}
Also used : InvalidMetadataException(bio.terra.workspace.db.exception.InvalidMetadataException) JobBuilder(bio.terra.workspace.service.job.JobBuilder) UUID(java.util.UUID) Traced(io.opencensus.contrib.spring.aop.Traced)

Example 4 with JobBuilder

use of bio.terra.workspace.service.job.JobBuilder 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 5 with JobBuilder

use of bio.terra.workspace.service.job.JobBuilder in project terra-workspace-manager by DataBiosphere.

the class WorkspaceService method deleteWorkspace.

/**
 * Delete an existing workspace by ID.
 */
@Traced
public void deleteWorkspace(UUID id, AuthenticatedUserRequest userRequest) {
    Workspace workspace = validateWorkspaceAndAction(userRequest, id, SamWorkspaceAction.DELETE);
    String description = "Delete workspace " + id;
    JobBuilder deleteJob = jobService.newJob().description(description).flightClass(WorkspaceDeleteFlight.class).operationType(OperationType.DELETE).workspaceId(id.toString()).userRequest(userRequest).addParameter(WorkspaceFlightMapKeys.WORKSPACE_STAGE, workspace.getWorkspaceStage().name());
    // Skip access check, which can't succeed after the workspace is deleted
    deleteJob.submitAndWait(null, false);
}
Also used : JobBuilder(bio.terra.workspace.service.job.JobBuilder) Workspace(bio.terra.workspace.service.workspace.model.Workspace) Traced(io.opencensus.contrib.spring.aop.Traced)

Aggregations

JobBuilder (bio.terra.workspace.service.job.JobBuilder)13 Traced (io.opencensus.contrib.spring.aop.Traced)3 ControlledResource (bio.terra.workspace.service.resource.controlled.model.ControlledResource)2 CloningInstructions (bio.terra.workspace.service.resource.model.CloningInstructions)2 Workspace (bio.terra.workspace.service.workspace.model.Workspace)2 BadRequestException (bio.terra.common.exception.BadRequestException)1 InvalidMetadataException (bio.terra.workspace.db.exception.InvalidMetadataException)1 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)1 CloneControlledGcsBucketResourceFlight (bio.terra.workspace.service.resource.controlled.flight.clone.bucket.CloneControlledGcsBucketResourceFlight)1 UpdateReferenceResourceFlight (bio.terra.workspace.service.resource.referenced.flight.update.UpdateReferenceResourceFlight)1 RemoveUserFromWorkspaceFlight (bio.terra.workspace.service.workspace.flight.RemoveUserFromWorkspaceFlight)1 WorkspaceCreateFlight (bio.terra.workspace.service.workspace.flight.WorkspaceCreateFlight)1 UUID (java.util.UUID)1