Search in sources :

Example 1 with Cluster

use of org.pmiops.workbench.model.Cluster in project workbench by all-of-us.

the class ClusterController method localize.

@Override
public ResponseEntity<ClusterLocalizeResponse> localize(String projectName, String clusterName, ClusterLocalizeRequest body) {
    String workspaceBucket;
    try {
        workspaceBucket = "gs://" + fireCloudService.getWorkspace(body.getWorkspaceNamespace(), body.getWorkspaceId()).getWorkspace().getBucketName();
    } catch (ApiException e) {
        if (e.getCode() == 404) {
            log.log(Level.INFO, "Firecloud workspace not found", e);
            throw new NotFoundException(String.format("workspace %s/%s not found or not accessible", body.getWorkspaceNamespace(), body.getWorkspaceId()));
        }
        throw ExceptionUtils.convertFirecloudException(e);
    }
    // For the common case where the notebook cluster matches the workspace
    // namespace, simply name the directory as the workspace ID; else we
    // include the namespace in the directory name to avoid possible conflicts
    // in workspace IDs.
    String workspacePath = body.getWorkspaceId();
    if (!projectName.equals(body.getWorkspaceNamespace())) {
        workspacePath = body.getWorkspaceNamespace() + ":" + body.getWorkspaceId();
    }
    String apiDir = String.join("/", "workspaces", workspacePath);
    String localDir = String.join("/", "~", apiDir);
    Map<String, String> toLocalize = body.getNotebookNames().stream().collect(Collectors.<String, String, String>toMap(name -> localDir + "/" + name, name -> String.join("/", workspaceBucket, "notebooks", name)));
    // TODO(calbach): Localize a delocalize config JSON file as well, once Leo supports this.
    toLocalize.put(localDir + "/.all_of_us_config.json", workspaceBucket + "/" + WorkspacesController.CONFIG_FILENAME);
    notebooksService.localize(projectName, clusterName, toLocalize);
    ClusterLocalizeResponse resp = new ClusterLocalizeResponse();
    resp.setClusterLocalDirectory(apiDir);
    return ResponseEntity.ok(resp);
}
Also used : ExceptionUtils(org.pmiops.workbench.exceptions.ExceptionUtils) ClusterLocalizeResponse(org.pmiops.workbench.model.ClusterLocalizeResponse) Provider(javax.inject.Provider) ImmutableMap(com.google.common.collect.ImmutableMap) FireCloudService(org.pmiops.workbench.firecloud.FireCloudService) ClusterListResponse(org.pmiops.workbench.model.ClusterListResponse) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ApiException(org.pmiops.workbench.firecloud.ApiException) Logger(java.util.logging.Logger) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) Level(java.util.logging.Level) WorkbenchConfig(org.pmiops.workbench.config.WorkbenchConfig) ClusterLocalizeRequest(org.pmiops.workbench.model.ClusterLocalizeRequest) Map(java.util.Map) NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) NotebooksService(org.pmiops.workbench.notebooks.NotebooksService) ResponseEntity(org.springframework.http.ResponseEntity) Cluster(org.pmiops.workbench.model.Cluster) ClusterStatus(org.pmiops.workbench.model.ClusterStatus) User(org.pmiops.workbench.db.model.User) ClusterLocalizeResponse(org.pmiops.workbench.model.ClusterLocalizeResponse) NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) ApiException(org.pmiops.workbench.firecloud.ApiException)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Function (java.util.function.Function)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 Collectors (java.util.stream.Collectors)1 Provider (javax.inject.Provider)1 WorkbenchConfig (org.pmiops.workbench.config.WorkbenchConfig)1 User (org.pmiops.workbench.db.model.User)1 ExceptionUtils (org.pmiops.workbench.exceptions.ExceptionUtils)1 NotFoundException (org.pmiops.workbench.exceptions.NotFoundException)1 ApiException (org.pmiops.workbench.firecloud.ApiException)1 FireCloudService (org.pmiops.workbench.firecloud.FireCloudService)1 Cluster (org.pmiops.workbench.model.Cluster)1 ClusterListResponse (org.pmiops.workbench.model.ClusterListResponse)1 ClusterLocalizeRequest (org.pmiops.workbench.model.ClusterLocalizeRequest)1 ClusterLocalizeResponse (org.pmiops.workbench.model.ClusterLocalizeResponse)1 ClusterStatus (org.pmiops.workbench.model.ClusterStatus)1 NotebooksService (org.pmiops.workbench.notebooks.NotebooksService)1