Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impr: small usability improvements #481

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions conf/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,18 @@
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.datastudios.ParentDataStudioRefOptions",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.datastudios.ParentDataStudioRefOptions$ParentDataStudioRef",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.datastudios.StartAsNewCmd",
"allDeclaredFields":true,
Expand Down Expand Up @@ -1889,6 +1901,12 @@
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.datastudios.DataStudioDeleted",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.datastudios.DataStudioStartSubmitted",
"allDeclaredFields":true,
Expand Down Expand Up @@ -1925,12 +1943,6 @@
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.datastudios.DataStudioDeleted",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.labels.DeleteLabelsResponse",
"allDeclaredFields":true,
Expand Down Expand Up @@ -3315,7 +3327,7 @@
"allDeclaredFields":true,
"allDeclaredMethods":true,
"allDeclaredConstructors":true,
"methods":[{"name":"<init>","parameterTypes":[] }, {"name":"getAllowInstanceCredentials","parameterTypes":[] }, {"name":"getAllowLocalRepos","parameterTypes":[] }, {"name":"getAnalytics","parameterTypes":[] }, {"name":"getApiVersion","parameterTypes":[] }, {"name":"getArm64Enabled","parameterTypes":[] }, {"name":"getAuthTypes","parameterTypes":[] }, {"name":"getCommitId","parameterTypes":[] }, {"name":"getContentMaxFileSize","parameterTypes":[] }, {"name":"getContentUrl","parameterTypes":[] }, {"name":"getDataExplorerAllowedWorkspaces","parameterTypes":[] }, {"name":"getEvalWorkspaceIds","parameterTypes":[] }, {"name":"getForgePrefix","parameterTypes":[] }, {"name":"getGroundswellAllowedWorkspaces","parameterTypes":[] }, {"name":"getGroundswellEnabled","parameterTypes":[] }, {"name":"getHeartbeatInterval","parameterTypes":[] }, {"name":"getLandingUrl","parameterTypes":[] }, {"name":"getLoginPath","parameterTypes":[] }, {"name":"getNavbar","parameterTypes":[] }, {"name":"getSeqeraCloud","parameterTypes":[] }, {"name":"getTermsOfUseUrl","parameterTypes":[] }, {"name":"getUserWorkspaceEnabled","parameterTypes":[] }, {"name":"getVersion","parameterTypes":[] }, {"name":"getWaveAllowedWorkspaces","parameterTypes":[] }, {"name":"getWaveEnabled","parameterTypes":[] }, {"name":"setAllowInstanceCredentials","parameterTypes":["java.lang.Boolean"] }, {"name":"setAllowLocalRepos","parameterTypes":["java.lang.Boolean"] }, {"name":"setAllowNextflowCliLogs","parameterTypes":["java.lang.Boolean"] }, {"name":"setAnalytics","parameterTypes":["io.seqera.tower.model.Analytics"] }, {"name":"setApiVersion","parameterTypes":["java.lang.String"] }, {"name":"setArm64Enabled","parameterTypes":["java.lang.Boolean"] }, {"name":"setAuthTypes","parameterTypes":["java.util.List"] }, {"name":"setCommitId","parameterTypes":["java.lang.String"] }, {"name":"setContactEmail","parameterTypes":["java.lang.String"] }, {"name":"setContentMaxFileSize","parameterTypes":["java.lang.Long"] }, {"name":"setContentUrl","parameterTypes":["java.lang.String"] }, {"name":"setDataExplorerAllowedWorkspaces","parameterTypes":["java.util.List"] }, {"name":"setEvalWorkspaceIds","parameterTypes":["java.util.List"] }, {"name":"setForgePrefix","parameterTypes":["java.lang.String"] }, {"name":"setGroundswellAllowedWorkspaces","parameterTypes":["java.util.List"] }, {"name":"setGroundswellEnabled","parameterTypes":["java.lang.Boolean"] }, {"name":"setHeartbeatInterval","parameterTypes":["java.lang.Integer"] }, {"name":"setLandingUrl","parameterTypes":["java.lang.String"] }, {"name":"setLoginPath","parameterTypes":["java.lang.String"] }, {"name":"setNavbar","parameterTypes":["io.seqera.tower.model.NavbarConfig"] }, {"name":"setSeqeraCloud","parameterTypes":["java.lang.Boolean"] }, {"name":"setTermsOfUseUrl","parameterTypes":["java.lang.String"] }, {"name":"setUserWorkspaceEnabled","parameterTypes":["java.lang.Boolean"] }, {"name":"setVersion","parameterTypes":["java.lang.String"] }, {"name":"setWaveAllowedWorkspaces","parameterTypes":["java.util.List"] }, {"name":"setWaveEnabled","parameterTypes":["java.lang.Boolean"] }]
"methods":[{"name":"<init>","parameterTypes":[] }, {"name":"getAllowInstanceCredentials","parameterTypes":[] }, {"name":"getAllowLocalRepos","parameterTypes":[] }, {"name":"getAnalytics","parameterTypes":[] }, {"name":"getApiVersion","parameterTypes":[] }, {"name":"getArm64Enabled","parameterTypes":[] }, {"name":"getAuthTypes","parameterTypes":[] }, {"name":"getCommitId","parameterTypes":[] }, {"name":"getContentMaxFileSize","parameterTypes":[] }, {"name":"getContentUrl","parameterTypes":[] }, {"name":"getDataExplorerAllowedWorkspaces","parameterTypes":[] }, {"name":"getEvalWorkspaceIds","parameterTypes":[] }, {"name":"getForgePrefix","parameterTypes":[] }, {"name":"getGroundswellAllowedWorkspaces","parameterTypes":[] }, {"name":"getGroundswellEnabled","parameterTypes":[] }, {"name":"getHeartbeatInterval","parameterTypes":[] }, {"name":"getLandingUrl","parameterTypes":[] }, {"name":"getLoginPath","parameterTypes":[] }, {"name":"getNavbar","parameterTypes":[] }, {"name":"getSeqeraCloud","parameterTypes":[] }, {"name":"getTermsOfUseUrl","parameterTypes":[] }, {"name":"getUserWorkspaceEnabled","parameterTypes":[] }, {"name":"getVersion","parameterTypes":[] }, {"name":"getWaveAllowedWorkspaces","parameterTypes":[] }, {"name":"getWaveEnabled","parameterTypes":[] }, {"name":"setAllowInstanceCredentials","parameterTypes":["java.lang.Boolean"] }, {"name":"setAllowLocalRepos","parameterTypes":["java.lang.Boolean"] }, {"name":"setAllowNextflowCliLogs","parameterTypes":["java.lang.Boolean"] }, {"name":"setAnalytics","parameterTypes":["io.seqera.tower.model.Analytics"] }, {"name":"setApiVersion","parameterTypes":["java.lang.String"] }, {"name":"setArm64Enabled","parameterTypes":["java.lang.Boolean"] }, {"name":"setAuthTypes","parameterTypes":["java.util.List"] }, {"name":"setCommitId","parameterTypes":["java.lang.String"] }, {"name":"setContactEmail","parameterTypes":["java.lang.String"] }, {"name":"setContentMaxFileSize","parameterTypes":["java.lang.Long"] }, {"name":"setContentUrl","parameterTypes":["java.lang.String"] }, {"name":"setDataExplorerAllowedWorkspaces","parameterTypes":["java.util.List"] }, {"name":"setEvalWorkspaceIds","parameterTypes":["java.util.List"] }, {"name":"setForgePrefix","parameterTypes":["java.lang.String"] }, {"name":"setGroundswellAllowedWorkspaces","parameterTypes":["java.util.List"] }, {"name":"setGroundswellEnabled","parameterTypes":["java.lang.Boolean"] }, {"name":"setHeartbeatInterval","parameterTypes":["java.lang.Integer"] }, {"name":"setLandingUrl","parameterTypes":["java.lang.String"] }, {"name":"setLoginPath","parameterTypes":["java.lang.String"] }, {"name":"setLogoutUrl_JsonNullable","parameterTypes":["org.openapitools.jackson.nullable.JsonNullable"] }, {"name":"setNavbar","parameterTypes":["io.seqera.tower.model.NavbarConfig"] }, {"name":"setSeqeraCloud","parameterTypes":["java.lang.Boolean"] }, {"name":"setTermsOfUseUrl","parameterTypes":["java.lang.String"] }, {"name":"setUserWorkspaceEnabled","parameterTypes":["java.lang.Boolean"] }, {"name":"setVersion","parameterTypes":["java.lang.String"] }, {"name":"setWaveAllowedWorkspaces","parameterTypes":["java.util.List"] }, {"name":"setWaveEnabled","parameterTypes":["java.lang.Boolean"] }]
},
{
"name":"io.seqera.tower.model.ServiceInfoResponse",
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/seqera/tower/cli/commands/LaunchCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ protected Integer onBeforeExit(int exitCode, Response response) {
WorkflowStatus.CANCELLED, WorkflowStatus.FAILED, WorkflowStatus.SUCCEEDED
);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return exitCode;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ protected Integer onBeforeExit(int exitCode, Response response) {
ComputeEnvStatus.AVAILABLE, ComputeEnvStatus.ERRORED, ComputeEnvStatus.INVALID
);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return exitCode;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void waitForDoneStatus(Long wspId, String credId) {
DataLinksFetchStatus.DONE, DataLinksFetchStatus.ERROR
);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@
import io.seqera.tower.model.DataStudioProgressStep;
import io.seqera.tower.model.DataStudioStatus;
import io.seqera.tower.model.DataStudioStatusInfo;
import io.seqera.tower.model.DataStudioTemplate;
import io.seqera.tower.model.DataStudioTemplatesListResponse;

import static io.seqera.tower.cli.utils.ResponseHelper.waitStatus;
import static io.seqera.tower.model.DataStudioProgressStepStatus.ERRORED;
import static io.seqera.tower.model.DataStudioProgressStepStatus.IN_PROGRESS;

public class AbstractStudiosCmd extends AbstractApiCmd {

private static final Integer DEFAULT_MAX_TEMPLATES_TO_QUERY = 20;
protected String getSessionId(DataStudioRefOptions dataStudioRefOptions, Long wspId) throws ApiException {
return dataStudioRefOptions.dataStudio.sessionId != null
? dataStudioRefOptions.dataStudio.sessionId
Expand All @@ -56,6 +59,24 @@ protected DataStudioDto fetchDataStudio(DataStudioRefOptions dataStudioRefOption
return dataStudio;
}

protected String getParentDataStudioSessionId(ParentDataStudioRefOptions parentDataStudioRefOptions, Long wspId) throws ApiException {
if (parentDataStudioRefOptions.studio.sessionId != null) {
return parentDataStudioRefOptions.studio.sessionId;
} else {
DataStudioDto dataStudio = getDataStudioByName(wspId, parentDataStudioRefOptions.studio.name);
return dataStudio.getSessionId();
}
}

protected List<DataStudioTemplate> fetchDataStudioTemplates(Long workspaceId) throws ApiException {
return fetchDataStudioTemplates(workspaceId,DEFAULT_MAX_TEMPLATES_TO_QUERY);
}

protected List<DataStudioTemplate> fetchDataStudioTemplates(Long workspaceId, Integer max) throws ApiException {
DataStudioTemplatesListResponse response = api().listDataStudioTemplates(workspaceId,max,0);
return response.getTemplates();
}

private DataStudioDto getDataStudioByName(Long wspId, String dataStudioName) throws ApiException {
List<DataStudioDto> studios = api().listDataStudios(wspId, null, null, null).getStudios();

Expand Down Expand Up @@ -83,6 +104,7 @@ protected Integer onBeforeExit(int exitCode, String sessionId, Long workspaceId,
DataStudioStatus.STOPPED, DataStudioStatus.ERRORED, DataStudioStatus.RUNNING
);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return exitCode;
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/io/seqera/tower/cli/commands/datastudios/AddCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import io.seqera.tower.ApiException;
import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions;
import io.seqera.tower.cli.exceptions.DataStudiosTemplateNotFoundException;
import io.seqera.tower.cli.exceptions.TowerException;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.responses.datastudios.DataStudiosCreated;
Expand All @@ -28,10 +29,13 @@
import io.seqera.tower.model.DataStudioCreateResponse;
import io.seqera.tower.model.DataStudioDto;
import io.seqera.tower.model.DataStudioStatus;
import io.seqera.tower.model.DataStudioTemplate;
import picocli.CommandLine;

import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;

@CommandLine.Command(
name = "add",
Expand Down Expand Up @@ -71,6 +75,7 @@ protected Response exec() throws ApiException {
Long wspId = workspaceId(workspace.workspace);

try {
checkIfTemplateIsAvailable(template, wspId);
DataStudioCreateRequest request = prepareRequest();
DataStudioCreateResponse response = api().createDataStudio(request, wspId, autoStart);
DataStudioDto dataStudioDto = response.getStudio();
Expand All @@ -84,6 +89,16 @@ protected Response exec() throws ApiException {
}
}

void checkIfTemplateIsAvailable(String template, Long workspaceId) throws ApiException {
List<DataStudioTemplate> availableTemplates = fetchDataStudioTemplates(workspaceId);
boolean validTemplate = availableTemplates.stream()
.anyMatch(t -> t.getRepository() != null && t.getRepository().equals(template));

if (!validTemplate) {
throw new DataStudiosTemplateNotFoundException(template, availableTemplates.stream().map(DataStudioTemplate::getRepository).collect(Collectors.toList()));
}
}

DataStudioCreateRequest prepareRequest() throws ApiException {
DataStudioCreateRequest request = new DataStudioCreateRequest();
request.setName(name);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2021-2023, Seqera.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package io.seqera.tower.cli.commands.datastudios;

import picocli.CommandLine;

public class ParentDataStudioRefOptions {

@CommandLine.ArgGroup(multiplicity = "1")
public ParentDataStudioRefOptions.ParentDataStudioRef studio;

public static class ParentDataStudioRef {
@CommandLine.Option(names = {"-pid", "--parentId"}, description = "Parent DataStudio session ID.")
public String sessionId;

@CommandLine.Option(names = {"-pn", "--parentName"}, description = "Parent DataStudio name.")
public String name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
)
public class StartAsNewCmd extends AbstractStudiosCmd{

@CommandLine.Option(names = {"-pid", "--parentId"}, description = "Parent DataStudio session ID.", required = true)
public String parentStudioSessionId;
@CommandLine.Mixin
public ParentDataStudioRefOptions parentDataStudioRefOptions;

@CommandLine.Option(names = {"-n", "--name"}, description = "Data Studio name.", required = true)
public String name;
Expand All @@ -66,6 +66,7 @@ protected Response exec() throws ApiException {
Long wspId = workspaceId(workspace.workspace);

try {
String parentStudioSessionId = getParentDataStudioSessionId(parentDataStudioRefOptions, wspId);
DataStudioDto parentDataStudio = api().describeDataStudio(parentStudioSessionId, wspId);
if (parentDataStudio == null) {
throw new TowerException(String.format("Parent DataStudio %s not found at %s workspace", parentStudioSessionId, wspId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ protected Response exec() throws ApiException {
Long wspId = workspaceId(workspace.workspace);

try {
DataStudioTemplatesListResponse response = api().listDataStudioTemplates(wspId,max,0);

return new DataStudiosTemplatesList(response.getTemplates());
return new DataStudiosTemplatesList(fetchDataStudioTemplates(wspId, max));
} catch (ApiException e) {
if (e.getCode() == 403) {
throw new TowerException("User not entitled to list studio templates");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2021-2023, Seqera.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package io.seqera.tower.cli.exceptions;

import java.util.List;

public class DataStudiosTemplateNotFoundException extends TowerException {

public DataStudiosTemplateNotFoundException(String template, List<String> templatesAvailable) {
super(String.format("DataStudio template '%s' is not one of available templates '%s'", template, templatesAvailable));
}
}
1 change: 1 addition & 0 deletions src/main/java/io/seqera/tower/cli/utils/TarFileHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public void close() throws IOException, TowerException {
throw new TowerException("Timeout compressing logs");
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}

Expand Down
Loading
Loading