use of bio.terra.workspace.service.job.JobBuilder in project terra-workspace-manager by DataBiosphere.
the class WorkspaceService method createWorkspace.
/**
* Create a workspace with the specified parameters. Returns workspaceID of the new workspace.
*/
@Traced
public UUID createWorkspace(Workspace workspace, AuthenticatedUserRequest userRequest) {
String workspaceName = workspace.getDisplayName().orElse("");
String workspaceId = workspace.getWorkspaceId().toString();
String jobDescription = String.format("Create workspace: name: '%s' id: '%s' ", workspaceName, workspaceId);
JobBuilder createJob = jobService.newJob().description(jobDescription).flightClass(WorkspaceCreateFlight.class).request(workspace).userRequest(userRequest).workspaceId(workspaceId).operationType(OperationType.CREATE).addParameter(WorkspaceFlightMapKeys.WORKSPACE_STAGE, workspace.getWorkspaceStage().name()).addParameter(WorkspaceFlightMapKeys.DISPLAY_NAME, workspaceName).addParameter(WorkspaceFlightMapKeys.DESCRIPTION, workspace.getDescription().orElse(""));
if (workspace.getSpendProfileId().isPresent()) {
createJob.addParameter(WorkspaceFlightMapKeys.SPEND_PROFILE_ID, workspace.getSpendProfileId().get().getId());
}
// Skip the access check, which would fail since this workspace doesn't exist yet.
return createJob.submitAndWait(UUID.class, false);
}
use of bio.terra.workspace.service.job.JobBuilder in project terra-workspace-manager by DataBiosphere.
the class ReferencedResourceService method updateReferenceResource.
/**
* Updates name, description and/or referencing traget of the reference resource.
*
* @param workspaceId workspace of interest
* @param resourceId resource to update
* @param name name to change - may be null
* @param description description to change - may be null
* @param resource referencedResource to be updated to - may be null if not intending to update
* referencing target.
*/
public void updateReferenceResource(UUID workspaceId, UUID resourceId, @Nullable String name, @Nullable String description, @Nullable ReferencedResource resource, AuthenticatedUserRequest userRequest) {
workspaceService.validateWorkspaceAndAction(userRequest, workspaceId, SamConstants.SamWorkspaceAction.UPDATE_REFERENCE);
// Name may be null if the user is not updating it in this request.
if (name != null) {
ResourceValidationUtils.validateResourceName(name);
}
// Description may also be null, but this validator accepts null descriptions.
ResourceValidationUtils.validateResourceDescriptionName(description);
boolean updated;
if (resource != null) {
JobBuilder updateJob = jobService.newJob().description("Update reference target").flightClass(UpdateReferenceResourceFlight.class).resource(resource).userRequest(userRequest).operationType(OperationType.UPDATE).workspaceId(workspaceId.toString()).resourceType(resource.getResourceType()).resourceName(name).addParameter(ResourceKeys.RESOURCE_DESCRIPTION, description);
updated = updateJob.submitAndWait(Boolean.class);
} else {
updated = resourceDao.updateResource(workspaceId, resourceId, name, description);
}
if (!updated) {
logger.warn("There's no update to the referenced resource");
}
}
use of bio.terra.workspace.service.job.JobBuilder in project terra-workspace-manager by DataBiosphere.
the class PrivateResourceCleanupService method runCleanupFlight.
private void runCleanupFlight(WorkspaceUserPair workspaceUserPair) {
String description = "Clean up after user " + workspaceUserPair.getUserEmail() + " in workspace " + workspaceUserPair.getWorkspaceId().toString();
String wsmSaToken = samService.getWsmServiceAccountToken();
AuthenticatedUserRequest wsmSaRequest = new AuthenticatedUserRequest().token(Optional.of(wsmSaToken));
JobBuilder userCleanupJob = jobService.newJob().description(description).flightClass(RemoveUserFromWorkspaceFlight.class).userRequest(wsmSaRequest).workspaceId(workspaceUserPair.getWorkspaceId().toString()).addParameter(WorkspaceFlightMapKeys.WORKSPACE_ID, workspaceUserPair.getWorkspaceId().toString()).addParameter(WorkspaceFlightMapKeys.USER_TO_REMOVE, workspaceUserPair.getUserEmail()).addParameter(WorkspaceFlightMapKeys.ROLE_TO_REMOVE, null);
try {
// Skip the job access check as the "manager" role does not grant read access to a workspace.
userCleanupJob.submitAndWait(null, /*doAccessCheck=*/
false);
} catch (RuntimeException e) {
// Log the error, but don't kill this thread as it still needs to clean up other users.
logger.error("Flight cleaning up user {} in workspace {} failed: ", workspaceUserPair.getUserEmail(), workspaceUserPair.getWorkspaceId(), e);
}
}
use of bio.terra.workspace.service.job.JobBuilder in project terra-workspace-manager by DataBiosphere.
the class ControlledResourceService method createAiNotebookInstance.
/**
* Starts a create controlled AI Notebook instance resource job, returning the job id.
*/
public String createAiNotebookInstance(ControlledAiNotebookInstanceResource resource, ApiGcpAiNotebookInstanceCreationParameters creationParameters, @Nullable ControlledResourceIamRole privateResourceIamRole, @Nullable ApiJobControl jobControl, String resultPath, AuthenticatedUserRequest userRequest) {
// Special check for notebooks: READER is not a useful role
if (privateResourceIamRole == ControlledResourceIamRole.READER) {
throw new BadRequestException("A private, controlled AI Notebook instance must have the writer or editor role or else it is not useful.");
}
JobBuilder jobBuilder = commonCreationJobBuilder(resource, privateResourceIamRole, jobControl, resultPath, userRequest);
String petSaEmail = SamRethrow.onInterrupted(() -> samService.getOrCreatePetSaEmail(gcpCloudContextService.getRequiredGcpProject(resource.getWorkspaceId()), userRequest.getRequiredToken()), "enablePet");
jobBuilder.addParameter(ControlledResourceKeys.CREATE_NOTEBOOK_PARAMETERS, creationParameters);
jobBuilder.addParameter(ControlledResourceKeys.NOTEBOOK_PET_SERVICE_ACCOUNT, petSaEmail);
String jobId = jobBuilder.submit();
waitForResourceOrJob(resource.getWorkspaceId(), resource.getResourceId(), jobId);
return jobId;
}
use of bio.terra.workspace.service.job.JobBuilder in project terra-workspace-manager by DataBiosphere.
the class ControlledResourceService method createAzureVm.
public String createAzureVm(ControlledAzureVmResource resource, ApiAzureVmCreationParameters creationParameters, ControlledResourceIamRole privateResourceIamRole, ApiJobControl jobControl, String resultPath, AuthenticatedUserRequest userRequest) {
features.azureEnabledCheck();
JobBuilder jobBuilder = commonCreationJobBuilder(resource, privateResourceIamRole, jobControl, resultPath, userRequest).addParameter(ControlledResourceKeys.CREATION_PARAMETERS, creationParameters);
String jobId = jobBuilder.submit();
waitForResourceOrJob(resource.getWorkspaceId(), resource.getResourceId(), jobId);
return jobId;
}
Aggregations