use of org.pmiops.workbench.model.ClusterLocalizeResponse 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);
}
Aggregations