Skip to content

Commit 7c71c92

Browse files
authored
feat: imrpove studios command parameters (#485)
1 parent b28aa95 commit 7c71c92

File tree

6 files changed

+234
-14
lines changed

6 files changed

+234
-14
lines changed

conf/reflect-config.json

+12
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,18 @@
11481148
"queryAllDeclaredMethods":true,
11491149
"methods":[{"name":"<init>","parameterTypes":[] }]
11501150
},
1151+
{
1152+
"name":"io.seqera.tower.cli.commands.datastudios.DataStudioCheckpointRefOptions",
1153+
"allDeclaredFields":true,
1154+
"queryAllDeclaredMethods":true,
1155+
"methods":[{"name":"<init>","parameterTypes":[] }]
1156+
},
1157+
{
1158+
"name":"io.seqera.tower.cli.commands.datastudios.DataStudioCheckpointRefOptions$DataStudioCheckpointRef",
1159+
"allDeclaredFields":true,
1160+
"queryAllDeclaredMethods":true,
1161+
"methods":[{"name":"<init>","parameterTypes":[] }]
1162+
},
11511163
{
11521164
"name":"io.seqera.tower.cli.commands.datastudios.DataStudioConfigurationOptions",
11531165
"allDeclaredFields":true,

src/main/java/io/seqera/tower/cli/commands/datastudios/AddCmd.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.seqera.tower.cli.responses.Response;
2626
import io.seqera.tower.cli.responses.datastudios.DataStudiosCreated;
2727
import io.seqera.tower.cli.utils.FilesHelper;
28+
import io.seqera.tower.model.ComputeEnvResponseDto;
2829
import io.seqera.tower.model.DataStudioConfiguration;
2930
import io.seqera.tower.model.DataStudioCreateRequest;
3031
import io.seqera.tower.model.DataStudioCreateResponse;
@@ -77,7 +78,7 @@ protected Response exec() throws ApiException {
7778

7879
try {
7980
templateValidation(templateOptions, condaEnv, wspId);
80-
DataStudioCreateRequest request = prepareRequest();
81+
DataStudioCreateRequest request = prepareRequest(wspId);
8182
DataStudioCreateResponse response = api().createDataStudio(request, wspId, autoStart);
8283
DataStudioDto dataStudioDto = response.getStudio();
8384
assert dataStudioDto != null;
@@ -108,12 +109,13 @@ void checkIfTemplateIsAvailable(String template, Long workspaceId) throws ApiExc
108109
}
109110
}
110111

111-
DataStudioCreateRequest prepareRequest() throws ApiException {
112+
DataStudioCreateRequest prepareRequest(Long wspId) throws ApiException {
112113
DataStudioCreateRequest request = new DataStudioCreateRequest();
113114
request.setName(name);
114115
if (description != null && !description.isEmpty()) {request.description(description);}
115116
request.setDataStudioToolUrl(templateOptions.getTemplate());
116-
request.setComputeEnvId(computeEnv);
117+
ComputeEnvResponseDto ceResponse = computeEnvByRef(wspId, computeEnv);
118+
request.setComputeEnvId(ceResponse.getId());
117119

118120
String condaEnvString = null;
119121
if (condaEnv != null) {

src/main/java/io/seqera/tower/cli/commands/datastudios/StartAsNewCmd.java

+21-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import io.seqera.tower.ApiException;
2121
import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions;
22+
import io.seqera.tower.cli.exceptions.InvalidDataStudioParentCheckpointException;
2223
import io.seqera.tower.cli.exceptions.TowerException;
2324
import io.seqera.tower.cli.responses.Response;
2425
import io.seqera.tower.cli.responses.datastudios.DataStudiosCreated;
@@ -43,6 +44,9 @@ public class StartAsNewCmd extends AbstractStudiosCmd{
4344
@CommandLine.Mixin
4445
public ParentDataStudioRefOptions parentDataStudioRefOptions;
4546

47+
@CommandLine.Option(names = {"--parent-checkpoint-id"}, description = "Parent Data Studio checkpoint id, to be used as staring point for the new Data Studio. If not provided, if will defaults to latest existing checkpoint of parent Data Studio.")
48+
public String parentCheckpointId;
49+
4650
@CommandLine.Option(names = {"-n", "--name"}, description = "Data Studio name.", required = true)
4751
public String name;
4852

@@ -72,9 +76,7 @@ protected Response exec() throws ApiException {
7276
throw new TowerException(String.format("Parent DataStudio %s not found at %s workspace", parentStudioSessionId, wspId));
7377
}
7478

75-
DataStudioListCheckpointsResponse checkpoints = api().listDataStudioCheckpoints(parentDataStudio.getSessionId(), parentDataStudio.getWorkspaceId(), null, 1, null);
76-
77-
DataStudioCreateRequest request = prepareRequest(parentDataStudio, checkpoints.getCheckpoints());
79+
DataStudioCreateRequest request = prepareRequest(parentDataStudio, parentCheckpointId, wspId);
7880
DataStudioCreateResponse response = api().createDataStudio(request, wspId, autoStart);
7981
DataStudioDto dataStudioDto = response.getStudio();
8082
assert dataStudioDto != null;
@@ -87,17 +89,30 @@ protected Response exec() throws ApiException {
8789
}
8890
}
8991

90-
DataStudioCreateRequest prepareRequest(DataStudioDto parentDataStudio, List<DataStudioCheckpointDto> checkpoints) throws ApiException {
92+
DataStudioCreateRequest prepareRequest(DataStudioDto parentDataStudio, String parentCheckpointId, Long wspId) throws ApiException {
9193
DataStudioCreateRequest request = new DataStudioCreateRequest();
9294
request.setName(name);
9395
if (description == null || description.isEmpty()) {
9496
request.description(String.format("Started from studio %s", parentDataStudio.getName()));
9597
} else {
9698
request.description(description);
9799
}
98-
if (checkpoints != null && !checkpoints.isEmpty()) {
99-
request.setInitialCheckpointId(checkpoints.get(0).getId());
100+
101+
if (parentCheckpointId == null) {
102+
DataStudioListCheckpointsResponse response = api().listDataStudioCheckpoints(parentDataStudio.getSessionId(), parentDataStudio.getWorkspaceId(), null, 1, null);
103+
if (!response.getCheckpoints().isEmpty()) {
104+
request.setInitialCheckpointId(response.getCheckpoints().get(0).getId());
105+
}
106+
} else {
107+
try {
108+
Long checkpoint = Long.valueOf(parentCheckpointId);
109+
DataStudioCheckpointDto response = api().getDataStudioCheckpoint(parentDataStudio.getSessionId(), checkpoint, wspId);
110+
request.setInitialCheckpointId(response.getId());
111+
} catch (NumberFormatException | ApiException e) {
112+
throw new InvalidDataStudioParentCheckpointException(parentCheckpointId);
113+
}
100114
}
115+
101116
request.setDataStudioToolUrl(Objects.requireNonNull(parentDataStudio.getTemplate()).getRepository());
102117
request.setComputeEnvId(Objects.requireNonNull(parentDataStudio.getComputeEnv()).getId());
103118

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2021-2023, Seqera.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package io.seqera.tower.cli.exceptions;
19+
20+
public class InvalidDataStudioParentCheckpointException extends TowerException {
21+
22+
public InvalidDataStudioParentCheckpointException(String parentCheckpointId) {
23+
super(String.format("Parent checkpoint parameter error, invalid checkpoint id: '%s'. Use studios checkpoints command to list exiting checkpoints", parentCheckpointId));
24+
}
25+
}

0 commit comments

Comments
 (0)