diff --git a/src/main/java/io/seqera/tower/cli/commands/computeenvs/DeleteCmd.java b/src/main/java/io/seqera/tower/cli/commands/computeenvs/DeleteCmd.java index 59f819963..b5f7d9a84 100644 --- a/src/main/java/io/seqera/tower/cli/commands/computeenvs/DeleteCmd.java +++ b/src/main/java/io/seqera/tower/cli/commands/computeenvs/DeleteCmd.java @@ -19,7 +19,6 @@ import io.seqera.tower.ApiException; import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions; -import io.seqera.tower.cli.exceptions.ComputeEnvNotFoundException; import io.seqera.tower.cli.responses.Response; import io.seqera.tower.cli.responses.computeenvs.ComputeEnvDeleted; import io.seqera.tower.model.ComputeEnvResponseDto; @@ -50,15 +49,7 @@ protected Response exec() throws ApiException { id = computeEnv.getId(); } - try { - computeEnvsApi().deleteComputeEnv(id, wspId); - return new ComputeEnvDeleted(id, workspaceRef(wspId)); - } catch (ApiException e) { - if (e.getCode() == 403) { - // Customize the forbidden message - throw new ComputeEnvNotFoundException(id, workspaceRef(wspId)); - } - throw e; - } + computeEnvsApi().deleteComputeEnv(id, wspId); + return new ComputeEnvDeleted(id, workspaceRef(wspId)); } } diff --git a/src/main/java/io/seqera/tower/cli/commands/computeenvs/UpdateCmd.java b/src/main/java/io/seqera/tower/cli/commands/computeenvs/UpdateCmd.java index 1644be553..4bb530c8b 100644 --- a/src/main/java/io/seqera/tower/cli/commands/computeenvs/UpdateCmd.java +++ b/src/main/java/io/seqera/tower/cli/commands/computeenvs/UpdateCmd.java @@ -19,7 +19,6 @@ import io.seqera.tower.ApiException; import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions; -import io.seqera.tower.cli.exceptions.ComputeEnvNotFoundException; import io.seqera.tower.cli.exceptions.InvalidResponseException; import io.seqera.tower.cli.responses.Response; import io.seqera.tower.cli.responses.computeenvs.ComputeEnvUpdated; @@ -70,20 +69,7 @@ protected Response exec() throws ApiException, IOException { } - private ComputeEnvResponseDto describeCE(ComputeEnvRefOptions computeEnvRefOptions, Long wspId) throws ComputeEnvNotFoundException, ApiException { - try { - return fetchComputeEnv(computeEnvRefOptions, wspId); - - } catch (ApiException e) { - if (e.getCode() == 403) { - String ref = computeEnvRefOptions.computeEnv.computeEnvId != null - ? computeEnvRefOptions.computeEnv.computeEnvId - : computeEnvRefOptions.computeEnv.computeEnvName; - // Customize the forbidden message - throw new ComputeEnvNotFoundException(ref, workspaceRef(wspId)); - } - - throw e; - } + private ComputeEnvResponseDto describeCE(ComputeEnvRefOptions computeEnvRefOptions, Long wspId) throws ApiException { + return fetchComputeEnv(computeEnvRefOptions, wspId); } } diff --git a/src/main/java/io/seqera/tower/cli/commands/computeenvs/ViewCmd.java b/src/main/java/io/seqera/tower/cli/commands/computeenvs/ViewCmd.java index 7aa66f78f..6a48e333e 100644 --- a/src/main/java/io/seqera/tower/cli/commands/computeenvs/ViewCmd.java +++ b/src/main/java/io/seqera/tower/cli/commands/computeenvs/ViewCmd.java @@ -19,7 +19,6 @@ import io.seqera.tower.ApiException; import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions; -import io.seqera.tower.cli.exceptions.ComputeEnvNotFoundException; import io.seqera.tower.cli.responses.Response; import io.seqera.tower.cli.responses.computeenvs.ComputeEnvView; import io.seqera.tower.model.ComputeEnvResponseDto; @@ -42,19 +41,8 @@ public class ViewCmd extends AbstractComputeEnvCmd { protected Response exec() throws ApiException { Long wspId = workspaceId(workspace.workspace); - try { - ComputeEnvResponseDto computeEnv = fetchComputeEnv(computeEnvRefOptions, wspId); - - return new ComputeEnvView(computeEnv.getId(), workspaceRef(wspId), computeEnv, baseWorkspaceUrl(wspId)); - } catch (ApiException e) { - if (e.getCode() == 403) { - String ref = computeEnvRefOptions.computeEnv.computeEnvId != null ? computeEnvRefOptions.computeEnv.computeEnvId : computeEnvRefOptions.computeEnv.computeEnvName; - - // Customize the forbidden message - throw new ComputeEnvNotFoundException(ref, workspaceRef(wspId)); - } - throw e; - } + ComputeEnvResponseDto computeEnv = fetchComputeEnv(computeEnvRefOptions, wspId); + return new ComputeEnvView(computeEnv.getId(), workspaceRef(wspId), computeEnv, baseWorkspaceUrl(wspId)); } } diff --git a/src/main/java/io/seqera/tower/cli/commands/credentials/DeleteCmd.java b/src/main/java/io/seqera/tower/cli/commands/credentials/DeleteCmd.java index d1757f20d..eda4e8025 100644 --- a/src/main/java/io/seqera/tower/cli/commands/credentials/DeleteCmd.java +++ b/src/main/java/io/seqera/tower/cli/commands/credentials/DeleteCmd.java @@ -19,7 +19,6 @@ import io.seqera.tower.ApiException; import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions; -import io.seqera.tower.cli.exceptions.CredentialsNotFoundException; import io.seqera.tower.cli.responses.CredentialsDeleted; import io.seqera.tower.cli.responses.Response; import io.seqera.tower.model.Credentials; @@ -50,15 +49,7 @@ protected Response exec() throws ApiException { id = credentials.getId(); } - try { - deleteCredentialsById(id, wspId); - return new CredentialsDeleted(id, workspaceRef(wspId)); - } catch (ApiException e) { - if (e.getCode() == 403) { - // Customize the forbidden message - throw new CredentialsNotFoundException(id, workspaceRef(wspId)); - } - throw e; - } + deleteCredentialsById(id, wspId); + return new CredentialsDeleted(id, workspaceRef(wspId)); } } diff --git a/src/main/java/io/seqera/tower/cli/commands/credentials/update/AbstractUpdateCmd.java b/src/main/java/io/seqera/tower/cli/commands/credentials/update/AbstractUpdateCmd.java index 14123524c..50f75ba6c 100644 --- a/src/main/java/io/seqera/tower/cli/commands/credentials/update/AbstractUpdateCmd.java +++ b/src/main/java/io/seqera/tower/cli/commands/credentials/update/AbstractUpdateCmd.java @@ -22,7 +22,6 @@ import io.seqera.tower.cli.commands.credentials.CredentialsRefOptions; import io.seqera.tower.cli.commands.credentials.providers.CredentialsProvider; import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions; -import io.seqera.tower.cli.exceptions.CredentialsNotFoundException; import io.seqera.tower.cli.responses.CredentialsUpdated; import io.seqera.tower.cli.responses.Response; import io.seqera.tower.model.Credentials; @@ -48,20 +47,8 @@ public AbstractUpdateCmd() { protected Response exec() throws ApiException, IOException { Long wspId = workspaceId(workspace.workspace); - // Check that exists - try { -// DescribeCredentialsResponse response = api().describeCredentials(credentials, wspId); - Credentials credentials = fetchCredentials(credentialsRefOptions, wspId); - return update(credentials, wspId); - } catch (ApiException e) { - if (e.getCode() == 403) { - String ref = credentialsRefOptions.credentialsRef.credentialsId != null ? credentialsRefOptions.credentialsRef.credentialsId : credentialsRefOptions.credentialsRef.credentialsName; - - // Customize the forbidden message - throw new CredentialsNotFoundException(ref, workspaceRef(wspId)); - } - throw e; - } + Credentials credentials = fetchCredentials(credentialsRefOptions, wspId); + return update(credentials, wspId); } protected Response update(Credentials creds, Long wspId) throws ApiException, IOException { diff --git a/src/main/java/io/seqera/tower/cli/commands/runs/CancelCmd.java b/src/main/java/io/seqera/tower/cli/commands/runs/CancelCmd.java index 766e7a251..4be289c6b 100644 --- a/src/main/java/io/seqera/tower/cli/commands/runs/CancelCmd.java +++ b/src/main/java/io/seqera/tower/cli/commands/runs/CancelCmd.java @@ -19,7 +19,6 @@ import io.seqera.tower.ApiException; import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions; -import io.seqera.tower.cli.exceptions.RunNotFoundException; import io.seqera.tower.cli.responses.Response; import io.seqera.tower.cli.responses.runs.RunCanceled; import picocli.CommandLine; @@ -42,15 +41,7 @@ public class CancelCmd extends AbstractRunsCmd { protected Response exec() throws ApiException, IOException { Long wspId = workspaceId(workspace.workspace); - try { - workflowsApi().cancelWorkflow(id, wspId, null, null); - - return new RunCanceled(id, workspaceRef(wspId)); - } catch (ApiException e) { - if (e.getCode() == 403) { - throw new RunNotFoundException(id, workspaceRef(wspId)); - } - throw e; - } + workflowsApi().cancelWorkflow(id, wspId, null, null); + return new RunCanceled(id, workspaceRef(wspId)); } } diff --git a/src/main/java/io/seqera/tower/cli/commands/runs/DeleteCmd.java b/src/main/java/io/seqera/tower/cli/commands/runs/DeleteCmd.java index e46a2ea1a..17bb67f0e 100644 --- a/src/main/java/io/seqera/tower/cli/commands/runs/DeleteCmd.java +++ b/src/main/java/io/seqera/tower/cli/commands/runs/DeleteCmd.java @@ -19,7 +19,6 @@ import io.seqera.tower.ApiException; import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions; -import io.seqera.tower.cli.exceptions.RunNotFoundException; import io.seqera.tower.cli.responses.Response; import io.seqera.tower.cli.responses.runs.RunDeleted; import picocli.CommandLine; @@ -45,15 +44,7 @@ public class DeleteCmd extends AbstractRunsCmd { protected Response exec() throws ApiException, IOException { Long wspId = workspaceId(workspace.workspace); - try { - workflowsApi().deleteWorkflow(id, wspId, force); - - return new RunDeleted(id, workspaceRef(wspId)); - } catch (ApiException e) { - if (e.getCode() == 403) { - throw new RunNotFoundException(id, workspaceRef(wspId)); - } - throw e; - } + workflowsApi().deleteWorkflow(id, wspId, force); + return new RunDeleted(id, workspaceRef(wspId)); } } diff --git a/src/main/java/io/seqera/tower/cli/commands/runs/ViewCmd.java b/src/main/java/io/seqera/tower/cli/commands/runs/ViewCmd.java index 9295bad36..4fd38cdb2 100644 --- a/src/main/java/io/seqera/tower/cli/commands/runs/ViewCmd.java +++ b/src/main/java/io/seqera/tower/cli/commands/runs/ViewCmd.java @@ -68,129 +68,119 @@ public class ViewCmd extends AbstractRunsCmd { protected Response exec() throws ApiException { Long wspId = workspaceId(workspace.workspace); - try { - String workspaceRef = workspaceRef(wspId); - DescribeWorkflowResponse workflowResponse = workflowsApi().describeWorkflow(id, wspId, List.of(WorkflowQueryAttribute.labels)); - - if (workflowResponse == null) { - throw new RunNotFoundException(id, workspaceRef(wspId)); - } - - Workflow workflow = workflowResponse.getWorkflow(); - WorkflowLoad workflowLoad = workflowLoadByWorkflowId(wspId, id); + String workspaceRef = workspaceRef(wspId); + DescribeWorkflowResponse workflowResponse = workflowsApi().describeWorkflow(id, wspId, List.of(WorkflowQueryAttribute.labels)); - DescribeWorkflowLaunchResponse wfLaunch = workflowsApi().describeWorkflowLaunch(workflow.getId(), wspId); - ComputeEnvComputeConfig computeEnv = wfLaunch.getLaunch() != null ? wfLaunch.getLaunch().getComputeEnv() : null; + if (workflowResponse == null) { + throw new RunNotFoundException(id, workspaceRef(wspId)); + } - ProgressData progress = null; - if (opts.processes || opts.stats || opts.load || opts.utilization) { - progress = workflowsApi().describeWorkflowProgress(id, wspId).getProgress(); - } + Workflow workflow = workflowResponse.getWorkflow(); + WorkflowLoad workflowLoad = workflowLoadByWorkflowId(wspId, id); - Map general = new LinkedHashMap<>(); - general.put("id", workflow.getId()); - general.put("operationId", workflowResponse.getJobInfo() != null ? workflowResponse.getJobInfo().getOperationId() : null); - general.put("runName", workflow.getRunName()); - general.put("startingDate", workflow.getStart()); - general.put("commitId", workflow.getCommitId()); - general.put("sessionId", workflow.getSessionId()); - general.put("username", workflow.getUserName()); - general.put("workdir", workflow.getWorkDir()); - general.put("container", workflow.getContainer()); - general.put("executors", workflowLoad.getExecutors() != null ? String.join(", ", workflowLoad.getExecutors()) : null); - general.put("computeEnv", computeEnv == null ? '-' : computeEnv.getName()); - general.put("nextflowVersion", workflow.getNextflow() != null ? workflow.getNextflow().getVersion() : null); - general.put("status", workflow.getStatus()); - general.put("labels", formatLabels(workflowResponse.getLabels())); - - List configFiles = new ArrayList<>(); - String configText = null; - if (opts.config) { - configFiles = workflow.getConfigFiles(); - configText = workflow.getConfigText(); - } + DescribeWorkflowLaunchResponse wfLaunch = workflowsApi().describeWorkflowLaunch(workflow.getId(), wspId); + ComputeEnvComputeConfig computeEnv = wfLaunch.getLaunch() != null ? wfLaunch.getLaunch().getComputeEnv() : null; - Map params = new HashMap(); - if (opts.params) { - params = workflow.getParams(); - } + ProgressData progress = null; + if (opts.processes || opts.stats || opts.load || opts.utilization) { + progress = workflowsApi().describeWorkflowProgress(id, wspId).getProgress(); + } - String command = null; - if (opts.command) { - command = workflow.getCommandLine(); - } + Map general = new LinkedHashMap<>(); + general.put("id", workflow.getId()); + general.put("operationId", workflowResponse.getJobInfo() != null ? workflowResponse.getJobInfo().getOperationId() : null); + general.put("runName", workflow.getRunName()); + general.put("startingDate", workflow.getStart()); + general.put("commitId", workflow.getCommitId()); + general.put("sessionId", workflow.getSessionId()); + general.put("username", workflow.getUserName()); + general.put("workdir", workflow.getWorkDir()); + general.put("container", workflow.getContainer()); + general.put("executors", workflowLoad.getExecutors() != null ? String.join(", ", workflowLoad.getExecutors()) : null); + general.put("computeEnv", computeEnv == null ? '-' : computeEnv.getName()); + general.put("nextflowVersion", workflow.getNextflow() != null ? workflow.getNextflow().getVersion() : null); + general.put("status", workflow.getStatus()); + general.put("labels", formatLabels(workflowResponse.getLabels())); + + List configFiles = new ArrayList<>(); + String configText = null; + if (opts.config) { + configFiles = workflow.getConfigFiles(); + configText = workflow.getConfigText(); + } - Map status = new HashMap<>(); - if (opts.status) { - status.put("pending", workflowLoad.getPending()); - status.put("submitted", workflowLoad.getSubmitted()); - status.put("running", workflowLoad.getRunning()); - status.put("cached", workflowLoad.getCached()); - status.put("succeeded", workflowLoad.getSucceeded()); - status.put("failed", workflowLoad.getFailed()); - } + Map params = new HashMap(); + if (opts.params) { + params = workflow.getParams(); + } - final List> processes = new ArrayList<>(); - if (opts.processes) { - progress.getProcessesProgress().forEach(it -> { - Map data = new HashMap<>(); - data.put("name", it.getProcess()); - data.put("completedTasks", it.getSucceeded() + it.getCached()); - data.put("totalTasks", it.getPending() + it.getRunning() + it.getCached() + it.getSubmitted() + it.getSucceeded() + it.getFailed()); + String command = null; + if (opts.command) { + command = workflow.getCommandLine(); + } - processes.add(data); - }); - } + Map status = new HashMap<>(); + if (opts.status) { + status.put("pending", workflowLoad.getPending()); + status.put("submitted", workflowLoad.getSubmitted()); + status.put("running", workflowLoad.getRunning()); + status.put("cached", workflowLoad.getCached()); + status.put("succeeded", workflowLoad.getSucceeded()); + status.put("failed", workflowLoad.getFailed()); + } - Map stats = new HashMap<>(); - if (opts.stats) { - if( workflow.getDuration() != null ) - stats.put("wallTime", TimeUnit.MILLISECONDS.toSeconds(workflow.getDuration()) / 60D); - if(progress.getWorkflowProgress() != null) { - stats.put("cpuTime", TimeUnit.MILLISECONDS.toMinutes(progress.getWorkflowProgress().getCpuTime()) / 60D); - stats.put("totalMemory", progress.getWorkflowProgress().getMemoryRss() / 1024 / 1024 / 1024D); - stats.put("read", progress.getWorkflowProgress().getReadBytes() / 1024 / 1024 / 1024D); - stats.put("write", progress.getWorkflowProgress().getWriteBytes() / 1024 / 1024 / 1024D); - stats.put("cost", progress.getWorkflowProgress().getCost()); - } - } + final List> processes = new ArrayList<>(); + if (opts.processes) { + progress.getProcessesProgress().forEach(it -> { + Map data = new HashMap<>(); + data.put("name", it.getProcess()); + data.put("completedTasks", it.getSucceeded() + it.getCached()); + data.put("totalTasks", it.getPending() + it.getRunning() + it.getCached() + it.getSubmitted() + it.getSucceeded() + it.getFailed()); - Map load = new HashMap<>(); - if (opts.load && progress.getWorkflowProgress() != null) { - load.put("peakCpus", progress.getWorkflowProgress().getPeakCpus()); - load.put("loadCpus", progress.getWorkflowProgress().getLoadCpus()); - load.put("peakTasks", progress.getWorkflowProgress().getPeakTasks()); - load.put("loadTasks", progress.getWorkflowProgress().getLoadTasks()); - } + processes.add(data); + }); + } - Map utilization = new HashMap<>(); - if (opts.utilization && progress.getWorkflowProgress() != null) { - utilization.put("memoryEfficiency", progress.getWorkflowProgress().getMemoryEfficiency()); - utilization.put("cpuEfficiency", progress.getWorkflowProgress().getCpuEfficiency()); + Map stats = new HashMap<>(); + if (opts.stats) { + if( workflow.getDuration() != null ) + stats.put("wallTime", TimeUnit.MILLISECONDS.toSeconds(workflow.getDuration()) / 60D); + if(progress.getWorkflowProgress() != null) { + stats.put("cpuTime", TimeUnit.MILLISECONDS.toMinutes(progress.getWorkflowProgress().getCpuTime()) / 60D); + stats.put("totalMemory", progress.getWorkflowProgress().getMemoryRss() / 1024 / 1024 / 1024D); + stats.put("read", progress.getWorkflowProgress().getReadBytes() / 1024 / 1024 / 1024D); + stats.put("write", progress.getWorkflowProgress().getWriteBytes() / 1024 / 1024 / 1024D); + stats.put("cost", progress.getWorkflowProgress().getCost()); } + } - return new RunView( - workspaceRef, - general, - configFiles, - configText, - params, - command, - status, - processes, - stats, - load, - utilization, - baseWorkspaceUrl(wspId) - ); - - } catch (ApiException e) { - if (e.getCode() == 403) { - // Customize the forbidden message - throw new RunNotFoundException(id, workspaceRef(wspId)); - } + Map load = new HashMap<>(); + if (opts.load && progress.getWorkflowProgress() != null) { + load.put("peakCpus", progress.getWorkflowProgress().getPeakCpus()); + load.put("loadCpus", progress.getWorkflowProgress().getLoadCpus()); + load.put("peakTasks", progress.getWorkflowProgress().getPeakTasks()); + load.put("loadTasks", progress.getWorkflowProgress().getLoadTasks()); + } - throw e; + Map utilization = new HashMap<>(); + if (opts.utilization && progress.getWorkflowProgress() != null) { + utilization.put("memoryEfficiency", progress.getWorkflowProgress().getMemoryEfficiency()); + utilization.put("cpuEfficiency", progress.getWorkflowProgress().getCpuEfficiency()); } + + return new RunView( + workspaceRef, + general, + configFiles, + configText, + params, + command, + status, + processes, + stats, + load, + utilization, + baseWorkspaceUrl(wspId) + ); } } diff --git a/src/main/java/io/seqera/tower/cli/commands/studios/AddAsNewCmd.java b/src/main/java/io/seqera/tower/cli/commands/studios/AddAsNewCmd.java index 3d890761f..a0aa3a742 100644 --- a/src/main/java/io/seqera/tower/cli/commands/studios/AddAsNewCmd.java +++ b/src/main/java/io/seqera/tower/cli/commands/studios/AddAsNewCmd.java @@ -77,24 +77,17 @@ public class AddAsNewCmd extends AbstractStudiosCmd{ protected Response exec() throws ApiException { Long wspId = workspaceId(workspace.workspace); - try { - String parentStudioSessionId = getParentStudioSessionId(parentStudioRefOptions, wspId); - DataStudioDto parentStudio = studiosApi().describeDataStudio(parentStudioSessionId, wspId); - if (parentStudio == null) { - throw new TowerException(String.format("Parent Studio %s not found at %s workspace", parentStudioSessionId, wspId)); - } - - DataStudioCreateRequest request = prepareRequest(parentStudio, parentCheckpointId, wspId); - DataStudioCreateResponse response = studiosApi().createDataStudio(request, wspId, autoStart); - DataStudioDto studioDto = response.getStudio(); - assert studioDto != null; - return new StudiosCreated(studioDto.getSessionId(), wspId, workspaceRef(wspId), baseWorkspaceUrl(wspId), autoStart); - } catch (ApiException e) { - if (e.getCode() == 403) { - throw new TowerException(String.format("User not entitled to create studio at %s workspace", wspId)); - } - throw e; + String parentStudioSessionId = getParentStudioSessionId(parentStudioRefOptions, wspId); + DataStudioDto parentStudio = studiosApi().describeDataStudio(parentStudioSessionId, wspId); + if (parentStudio == null) { + throw new TowerException(String.format("Parent Studio %s not found at %s workspace", parentStudioSessionId, wspId)); } + + DataStudioCreateRequest request = prepareRequest(parentStudio, parentCheckpointId, wspId); + DataStudioCreateResponse response = studiosApi().createDataStudio(request, wspId, autoStart); + DataStudioDto studioDto = response.getStudio(); + assert studioDto != null; + return new StudiosCreated(studioDto.getSessionId(), wspId, workspaceRef(wspId), baseWorkspaceUrl(wspId), autoStart); } DataStudioCreateRequest prepareRequest(DataStudioDto parentDataStudio, String parentCheckpointId, Long wspId) throws ApiException { diff --git a/src/main/java/io/seqera/tower/cli/commands/studios/AddCmd.java b/src/main/java/io/seqera/tower/cli/commands/studios/AddCmd.java index 59b8aeaed..ce710034d 100644 --- a/src/main/java/io/seqera/tower/cli/commands/studios/AddCmd.java +++ b/src/main/java/io/seqera/tower/cli/commands/studios/AddCmd.java @@ -84,19 +84,12 @@ public class AddCmd extends AbstractStudiosCmd{ protected Response exec() throws ApiException { Long wspId = workspaceId(workspace.workspace); - try { - templateValidation(templateOptions, condaEnv, wspId); - DataStudioCreateRequest request = prepareRequest(wspId); - DataStudioCreateResponse response = studiosApi().createDataStudio(request, wspId, autoStart); - DataStudioDto studioDto = response.getStudio(); - assert studioDto != null; - return new StudiosCreated(studioDto.getSessionId(), wspId, workspaceRef(wspId), baseWorkspaceUrl(wspId), autoStart); - } catch (ApiException e) { - if (e.getCode() == 403) { - throw new TowerException(String.format("User not entitled to create studio at %s workspace", wspId)); - } - throw e; - } + templateValidation(templateOptions, condaEnv, wspId); + DataStudioCreateRequest request = prepareRequest(wspId); + DataStudioCreateResponse response = studiosApi().createDataStudio(request, wspId, autoStart); + DataStudioDto studioDto = response.getStudio(); + assert studioDto != null; + return new StudiosCreated(studioDto.getSessionId(), wspId, workspaceRef(wspId), baseWorkspaceUrl(wspId), autoStart); } private void templateValidation(StudioTemplateOptions templateOptions, Path condaEnv, Long wspId) throws ApiException { diff --git a/src/main/java/io/seqera/tower/cli/commands/studios/CheckpointsCmd.java b/src/main/java/io/seqera/tower/cli/commands/studios/CheckpointsCmd.java index 361aef6e1..201309b96 100644 --- a/src/main/java/io/seqera/tower/cli/commands/studios/CheckpointsCmd.java +++ b/src/main/java/io/seqera/tower/cli/commands/studios/CheckpointsCmd.java @@ -20,7 +20,6 @@ import io.seqera.tower.ApiException; import io.seqera.tower.cli.commands.global.PaginationOptions; import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions; -import io.seqera.tower.cli.exceptions.TowerException; import io.seqera.tower.cli.exceptions.WorkspaceNotFoundException; import io.seqera.tower.cli.responses.Response; import io.seqera.tower.cli.responses.studios.StudioCheckpointsList; @@ -70,9 +69,6 @@ protected Response exec() throws ApiException, IOException { if (e.getCode() == 404){ throw new WorkspaceNotFoundException(wspId); } - if (e.getCode() == 403) { - throw new TowerException(String.format("User not entitled to %s workspace", wspId)); - } throw e; } diff --git a/src/main/java/io/seqera/tower/cli/commands/studios/DeleteCmd.java b/src/main/java/io/seqera/tower/cli/commands/studios/DeleteCmd.java index cefd83944..d457212c6 100644 --- a/src/main/java/io/seqera/tower/cli/commands/studios/DeleteCmd.java +++ b/src/main/java/io/seqera/tower/cli/commands/studios/DeleteCmd.java @@ -20,7 +20,6 @@ import io.seqera.tower.ApiException; import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions; import io.seqera.tower.cli.exceptions.StudioNotFoundException; -import io.seqera.tower.cli.exceptions.TowerException; import io.seqera.tower.cli.responses.Response; import io.seqera.tower.cli.responses.studios.StudioDeleted; import picocli.CommandLine; @@ -51,9 +50,6 @@ protected Response exec() throws ApiException { if (e.getCode() == 404) { throw new StudioNotFoundException(studioRefOptions.getStudioIdentifier(), workspace.workspace); } - if (e.getCode() == 403) { - throw new TowerException(String.format("User not entitled to view studio '%s' at %s workspace", studioRefOptions.getStudioIdentifier(), workspace.workspace)); - } throw e; } } diff --git a/src/main/java/io/seqera/tower/cli/commands/studios/ListCmd.java b/src/main/java/io/seqera/tower/cli/commands/studios/ListCmd.java index aa00304e2..ea352b4c4 100644 --- a/src/main/java/io/seqera/tower/cli/commands/studios/ListCmd.java +++ b/src/main/java/io/seqera/tower/cli/commands/studios/ListCmd.java @@ -21,7 +21,6 @@ import io.seqera.tower.cli.commands.global.PaginationOptions; import io.seqera.tower.cli.commands.global.ShowLabelsOption; import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions; -import io.seqera.tower.cli.exceptions.TowerException; import io.seqera.tower.cli.exceptions.WorkspaceNotFoundException; import io.seqera.tower.cli.responses.Response; import io.seqera.tower.cli.responses.studios.StudiosList; @@ -70,9 +69,6 @@ protected Response exec() throws ApiException, IOException { if (e.getCode() == 404){ throw new WorkspaceNotFoundException(wspId); } - if (e.getCode() == 403) { - throw new TowerException(String.format("User not entitled to %s workspace", wspId)); - } throw e; } diff --git a/src/main/java/io/seqera/tower/cli/commands/studios/StartCmd.java b/src/main/java/io/seqera/tower/cli/commands/studios/StartCmd.java index 45b9d4f39..eda8e722b 100644 --- a/src/main/java/io/seqera/tower/cli/commands/studios/StartCmd.java +++ b/src/main/java/io/seqera/tower/cli/commands/studios/StartCmd.java @@ -24,7 +24,6 @@ import io.seqera.tower.cli.commands.labels.Label; import io.seqera.tower.cli.commands.labels.LabelsOptionalOptions; import io.seqera.tower.cli.exceptions.StudioNotFoundException; -import io.seqera.tower.cli.exceptions.TowerException; import io.seqera.tower.cli.responses.Response; import io.seqera.tower.cli.responses.studios.StudioStartSubmitted; import io.seqera.tower.model.DataStudioConfiguration; @@ -76,9 +75,6 @@ protected Response exec() throws ApiException { if (e.getCode() == 404) { throw new StudioNotFoundException(studioRefOptions.getStudioIdentifier(), workspace.workspace); } - if (e.getCode() == 403) { - throw new TowerException(String.format("User not entitled to view studio '%s' at %s workspace", studioRefOptions.getStudioIdentifier(), workspace.workspace)); - } throw e; } } diff --git a/src/main/java/io/seqera/tower/cli/commands/studios/StopCmd.java b/src/main/java/io/seqera/tower/cli/commands/studios/StopCmd.java index c779be7f2..c37f53219 100644 --- a/src/main/java/io/seqera/tower/cli/commands/studios/StopCmd.java +++ b/src/main/java/io/seqera/tower/cli/commands/studios/StopCmd.java @@ -20,7 +20,6 @@ import io.seqera.tower.ApiException; import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions; import io.seqera.tower.cli.exceptions.StudioNotFoundException; -import io.seqera.tower.cli.exceptions.TowerException; import io.seqera.tower.cli.responses.Response; import io.seqera.tower.cli.responses.studios.StudioStopSubmitted; import io.seqera.tower.model.DataStudioStatus; @@ -58,9 +57,6 @@ protected Response exec() throws ApiException { if (e.getCode() == 404) { throw new StudioNotFoundException(studioRefOptions.getStudioIdentifier(), workspace.workspace); } - if (e.getCode() == 403) { - throw new TowerException(String.format("User not entitled to view studio '%s' at %s workspace", studioRefOptions.getStudioIdentifier(), workspace.workspace)); - } throw e; } } diff --git a/src/main/java/io/seqera/tower/cli/commands/studios/TemplatesCmd.java b/src/main/java/io/seqera/tower/cli/commands/studios/TemplatesCmd.java index 2e49e3d3e..b0edd12a9 100644 --- a/src/main/java/io/seqera/tower/cli/commands/studios/TemplatesCmd.java +++ b/src/main/java/io/seqera/tower/cli/commands/studios/TemplatesCmd.java @@ -19,7 +19,6 @@ import io.seqera.tower.ApiException; import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions; -import io.seqera.tower.cli.exceptions.TowerException; import io.seqera.tower.cli.responses.Response; import io.seqera.tower.cli.responses.studios.StudiosTemplatesList; import picocli.CommandLine; @@ -40,13 +39,6 @@ public class TemplatesCmd extends AbstractStudiosCmd { protected Response exec() throws ApiException { Long wspId = workspaceId(workspace.workspace); - try { - return new StudiosTemplatesList(fetchStudioTemplates(wspId, max)); - } catch (ApiException e) { - if (e.getCode() == 403) { - throw new TowerException("User not entitled to list studio templates"); - } - throw e; - } + return new StudiosTemplatesList(fetchStudioTemplates(wspId, max)); } } diff --git a/src/main/java/io/seqera/tower/cli/commands/studios/ViewCmd.java b/src/main/java/io/seqera/tower/cli/commands/studios/ViewCmd.java index 6ca1ae4fb..f3d08658f 100644 --- a/src/main/java/io/seqera/tower/cli/commands/studios/ViewCmd.java +++ b/src/main/java/io/seqera/tower/cli/commands/studios/ViewCmd.java @@ -20,7 +20,6 @@ import io.seqera.tower.ApiException; import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions; import io.seqera.tower.cli.exceptions.StudioNotFoundException; -import io.seqera.tower.cli.exceptions.TowerException; import io.seqera.tower.cli.responses.Response; import io.seqera.tower.cli.responses.studios.StudiosView; import io.seqera.tower.model.DataStudioDto; @@ -50,9 +49,6 @@ protected Response exec() throws ApiException { if (e.getCode() == 404) { throw new StudioNotFoundException(studioRefOptions.getStudioIdentifier(), workspace.workspace); } - if (e.getCode() == 403) { - throw new TowerException(String.format("User not entitled to view studio '%s' at %s workspace", studioRefOptions.getStudioIdentifier(), workspace.workspace)); - } throw e; } } diff --git a/src/main/java/io/seqera/tower/cli/utils/ResponseHelper.java b/src/main/java/io/seqera/tower/cli/utils/ResponseHelper.java index a51b192dc..7e1a8fee1 100644 --- a/src/main/java/io/seqera/tower/cli/utils/ResponseHelper.java +++ b/src/main/java/io/seqera/tower/cli/utils/ResponseHelper.java @@ -96,8 +96,7 @@ public static void errorMessage(PrintWriter err, Exception e) { break; case 403: - String errorMessage = decodeMessage(ex); - print(err, (errorMessage == null ? "Forbidden" : errorMessage) + "."); + print(err, decodeMessage(ex)); break; default: diff --git a/src/test/java/io/seqera/tower/cli/computeenvs/ComputeEnvsCmdTest.java b/src/test/java/io/seqera/tower/cli/computeenvs/ComputeEnvsCmdTest.java index 06826b4a4..1d90f4670 100644 --- a/src/test/java/io/seqera/tower/cli/computeenvs/ComputeEnvsCmdTest.java +++ b/src/test/java/io/seqera/tower/cli/computeenvs/ComputeEnvsCmdTest.java @@ -96,16 +96,16 @@ void testDeleteInvalidAuth(MockServerClient mock) { } @Test - void testDeleteNotFound(MockServerClient mock) { + void testDeleteForbidden(MockServerClient mock) { mock.when( request().withMethod("DELETE").withPath("/compute-envs/vYOK4vn7spw7bHHWBDXZ3"), exactly(1) ).respond( - response().withStatusCode(403) + response().withStatusCode(403).withBody("{\"message\":\"Forbidden\"}").withContentType(MediaType.APPLICATION_JSON) ); ExecOut out = exec(mock, "compute-envs", "delete", "-i", "vYOK4vn7spw7bHHWBDXZ3"); - assertEquals(errorMessage(out.app, new ComputeEnvNotFoundException("vYOK4vn7spw7bHHWBDXZ3", USER_WORKSPACE_NAME)), out.stdErr); + assertEquals(errorMessage(out.app, new ApiException(403, "", null, "{\"message\":\"Forbidden\"}")), out.stdErr); assertEquals("", out.stdOut); assertEquals(1, out.exitCode); } @@ -253,17 +253,17 @@ void testViewAwsManual(OutputType format, MockServerClient mock) throws JsonProc } @Test - void testViewNotFound(MockServerClient mock) { + void testViewForbidden(MockServerClient mock) { mock.when( request().withMethod("GET").withPath("/compute-envs/isnEDBLvHDAIteOEF44or"), exactly(1) ).respond( - response().withStatusCode(403) + response().withStatusCode(403).withBody("{\"message\":\"Forbidden\"}").withContentType(MediaType.APPLICATION_JSON) ); ExecOut out = exec(mock, "compute-envs", "view", "-i", "isnEDBLvHDAIteOEF44or"); - assertEquals(errorMessage(out.app, new TowerException(String.format("Compute environment '%s' not found at user workspace", "isnEDBLvHDAIteOEF44or"))), out.stdErr); + assertEquals(errorMessage(out.app, new ApiException(403, "", null, "{\"message\":\"Forbidden\"}")), out.stdErr); assertEquals("", out.stdOut); assertEquals(1, out.exitCode); } diff --git a/src/test/java/io/seqera/tower/cli/credentials/CredentialsCmdTest.java b/src/test/java/io/seqera/tower/cli/credentials/CredentialsCmdTest.java index 1625a7fb8..04ea3fe4c 100644 --- a/src/test/java/io/seqera/tower/cli/credentials/CredentialsCmdTest.java +++ b/src/test/java/io/seqera/tower/cli/credentials/CredentialsCmdTest.java @@ -65,16 +65,16 @@ void testDelete(OutputType format, MockServerClient mock) { } @Test - void testDeleteNotFound(MockServerClient mock) { + void testDeleteForbidden(MockServerClient mock) { mock.when( request().withMethod("DELETE").withPath("/credentials/1cz5A8cuBkB5iKKiCwJCFU"), exactly(1) ).respond( - response().withStatusCode(403) + response().withStatusCode(403).withBody("{\"message\":\"Forbidden\"}").withContentType(MediaType.APPLICATION_JSON) ); ExecOut out = exec(mock, "credentials", "delete", "-i", "1cz5A8cuBkB5iKKiCwJCFU"); - assertEquals(errorMessage(out.app, new CredentialsNotFoundException("1cz5A8cuBkB5iKKiCwJCFU", USER_WORKSPACE_NAME)), out.stdErr); + assertEquals(errorMessage(out.app, new ApiException(403, "", null, "{\"message\":\"Forbidden\"}")), out.stdErr); assertEquals("", out.stdOut); assertEquals(1, out.exitCode); } diff --git a/src/test/java/io/seqera/tower/cli/credentials/providers/AwsProviderTest.java b/src/test/java/io/seqera/tower/cli/credentials/providers/AwsProviderTest.java index 42194e046..de1a9c2a0 100644 --- a/src/test/java/io/seqera/tower/cli/credentials/providers/AwsProviderTest.java +++ b/src/test/java/io/seqera/tower/cli/credentials/providers/AwsProviderTest.java @@ -111,12 +111,12 @@ void testUpdateNotFound(MockServerClient mock) { mock.when( request().withMethod("GET").withPath("/credentials/kfKx9xRgzpIIZrbCMOcU5"), exactly(1) ).respond( - response().withStatusCode(403) + response().withStatusCode(403).withBody("{\"message\":\"Forbidden\"}").withContentType(MediaType.APPLICATION_JSON) ); ExecOut out = exec(mock, "credentials", "update", "aws", "-i", "kfKx9xRgzpIIZrbCMOcU5", "-r", "changeAssumeRole"); - assertEquals(errorMessage(out.app, new CredentialsNotFoundException("kfKx9xRgzpIIZrbCMOcU5", USER_WORKSPACE_NAME)), out.stdErr); + assertEquals(errorMessage(out.app, new ApiException(403, "", null, "{\"message\":\"Forbidden\"}")), out.stdErr); assertEquals("", out.stdOut); assertEquals(1, out.exitCode); } diff --git a/src/test/java/io/seqera/tower/cli/runs/RunsCmdTest.java b/src/test/java/io/seqera/tower/cli/runs/RunsCmdTest.java index 26a75103b..61b3ecf11 100644 --- a/src/test/java/io/seqera/tower/cli/runs/RunsCmdTest.java +++ b/src/test/java/io/seqera/tower/cli/runs/RunsCmdTest.java @@ -94,16 +94,16 @@ void testDelete(OutputType format, MockServerClient mock) { } @Test - void testDeleteNotFound(MockServerClient mock) { + void testDeleteForbidden(MockServerClient mock) { mock.when( request().withMethod("DELETE").withPath("/workflow/5dAZoXrcmZXRO4"), exactly(1) ).respond( - response().withStatusCode(403) + response().withStatusCode(403).withBody("{\"message\":\"Forbidden\"}").withContentType(MediaType.APPLICATION_JSON) ); ExecOut out = exec(mock, "runs", "delete", "-i", "5dAZoXrcmZXRO4"); - assertEquals(errorMessage(out.app, new RunNotFoundException("5dAZoXrcmZXRO4", USER_WORKSPACE_NAME)), out.stdErr); + assertEquals(errorMessage(out.app, new ApiException(403, "", null, "{\"message\":\"Forbidden\"}")), out.stdErr); assertEquals("", out.stdOut); assertEquals(1, out.exitCode); } @@ -122,16 +122,16 @@ void testCancel(OutputType format, MockServerClient mock) { } @Test - void testCancelNotFound(MockServerClient mock) { + void testCancelForbidden(MockServerClient mock) { mock.when( request().withMethod("POST").withPath("/workflow/5dAZoXrcmZXRO4/cancel"), exactly(1) ).respond( - response().withStatusCode(403) + response().withStatusCode(403).withBody("{\"message\":\"Forbidden\"}").withContentType(MediaType.APPLICATION_JSON) ); ExecOut out = exec(mock, "runs", "cancel", "-i", "5dAZoXrcmZXRO4"); - assertEquals(errorMessage(out.app, new RunNotFoundException("5dAZoXrcmZXRO4", USER_WORKSPACE_NAME)), out.stdErr); + assertEquals(errorMessage(out.app, new ApiException(403, "", null, "{\"message\":\"Forbidden\"}")), out.stdErr); assertEquals("", out.stdOut); assertEquals(1, out.exitCode); } @@ -483,16 +483,16 @@ void testView(OutputType format, MockServerClient mock) throws JsonProcessingExc } @Test - void testViewNotFound(MockServerClient mock) { + void testViewForbidden(MockServerClient mock) { mock.when( request().withMethod("GET").withPath("/workflow/5dAZoXrcmZXRO4"), exactly(1) ).respond( - response().withStatusCode(403) + response().withStatusCode(403).withBody("{\"message\":\"Forbidden\"}").withContentType(MediaType.APPLICATION_JSON) ); ExecOut out = exec(mock, "runs", "view", "-i", "5dAZoXrcmZXRO4"); - assertEquals(errorMessage(out.app, new RunNotFoundException("5dAZoXrcmZXRO4", USER_WORKSPACE_NAME)), out.stdErr); + assertEquals(errorMessage(out.app, new ApiException(403, "", null, "{\"message\":\"Forbidden\"}")), out.stdErr); assertEquals("", out.stdOut); assertEquals(1, out.exitCode); }