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

feat: imrpove studios command parameters #485

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -1148,6 +1148,18 @@
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.datastudios.DataStudioCheckpointRefOptions",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.datastudios.DataStudioCheckpointRefOptions$DataStudioCheckpointRef",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.datastudios.DataStudioConfigurationOptions",
"allDeclaredFields":true,
Expand Down Expand Up @@ -1920,37 +1932,37 @@
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.datastudios.DataStudioDeleted",
"name":"io.seqera.tower.cli.responses.datastudios.DataStudioCheckpointsList",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.datastudios.DataStudioStartSubmitted",
"name":"io.seqera.tower.cli.responses.datastudios.DataStudioDeleted",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.datastudios.DataStudioStopSubmitted",
"name":"io.seqera.tower.cli.responses.datastudios.DataStudioStartSubmitted",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.datastudios.DataStudiosCreated",
"name":"io.seqera.tower.cli.responses.datastudios.DataStudioStopSubmitted",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.datastudios.DataStudiosList",
"name":"io.seqera.tower.cli.responses.datastudios.DataStudiosCreated",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.datastudios.DataStudioCheckpointsList",
"name":"io.seqera.tower.cli.responses.datastudios.DataStudiosList",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
Expand Down Expand Up @@ -2740,7 +2752,7 @@
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true,
"methods":[{"name":"<init>","parameterTypes":[] }, {"name":"setAuthor","parameterTypes":["io.seqera.tower.model.StudioUser"] }, {"name":"setDateCreated","parameterTypes":["java.time.OffsetDateTime"] }, {"name":"setDateSaved","parameterTypes":["java.time.OffsetDateTime"] }, {"name":"setId","parameterTypes":["java.lang.Long"] }, {"name":"setName","parameterTypes":["java.lang.String"] }, {"name":"getAuthor","parameterTypes":[] }, {"name":"getDateCreated","parameterTypes":[] }, {"name":"getDateSaved","parameterTypes":[] }, {"name":"getId","parameterTypes":[] }, {"name":"getName","parameterTypes":[] }]
"methods":[{"name":"<init>","parameterTypes":[] }, {"name":"getAuthor","parameterTypes":[] }, {"name":"getDateCreated","parameterTypes":[] }, {"name":"getDateSaved","parameterTypes":[] }, {"name":"getId","parameterTypes":[] }, {"name":"getName","parameterTypes":[] }, {"name":"setAuthor","parameterTypes":["io.seqera.tower.model.StudioUser"] }, {"name":"setDateCreated","parameterTypes":["java.time.OffsetDateTime"] }, {"name":"setDateSaved","parameterTypes":["java.time.OffsetDateTime"] }, {"name":"setId","parameterTypes":["java.lang.Long"] }, {"name":"setName","parameterTypes":["java.lang.String"] }]
},
{
"name":"io.seqera.tower.model.DataStudioComputeEnvDto",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.responses.datastudios.DataStudiosCreated;
import io.seqera.tower.cli.utils.FilesHelper;
import io.seqera.tower.model.ComputeEnvResponseDto;
import io.seqera.tower.model.DataStudioConfiguration;
import io.seqera.tower.model.DataStudioCreateRequest;
import io.seqera.tower.model.DataStudioCreateResponse;
Expand Down Expand Up @@ -77,7 +78,7 @@ protected Response exec() throws ApiException {

try {
templateValidation(templateOptions, condaEnv, wspId);
DataStudioCreateRequest request = prepareRequest();
DataStudioCreateRequest request = prepareRequest(wspId);
DataStudioCreateResponse response = api().createDataStudio(request, wspId, autoStart);
DataStudioDto dataStudioDto = response.getStudio();
assert dataStudioDto != null;
Expand Down Expand Up @@ -108,12 +109,13 @@ void checkIfTemplateIsAvailable(String template, Long workspaceId) throws ApiExc
}
}

DataStudioCreateRequest prepareRequest() throws ApiException {
DataStudioCreateRequest prepareRequest(Long wspId) throws ApiException {
DataStudioCreateRequest request = new DataStudioCreateRequest();
request.setName(name);
if (description != null && !description.isEmpty()) {request.description(description);}
request.setDataStudioToolUrl(templateOptions.getTemplate());
request.setComputeEnvId(computeEnv);
ComputeEnvResponseDto ceResponse = computeEnvByRef(wspId, computeEnv);
request.setComputeEnvId(ceResponse.getId());

String condaEnvString = null;
if (condaEnv != null) {
Expand Down
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.InvalidDataStudioParentCheckpointException;
import io.seqera.tower.cli.exceptions.TowerException;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.responses.datastudios.DataStudiosCreated;
Expand All @@ -43,6 +44,9 @@ public class StartAsNewCmd extends AbstractStudiosCmd{
@CommandLine.Mixin
public ParentDataStudioRefOptions parentDataStudioRefOptions;

@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.")
public String parentCheckpointId;

@CommandLine.Option(names = {"-n", "--name"}, description = "Data Studio name.", required = true)
public String name;

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

DataStudioListCheckpointsResponse checkpoints = api().listDataStudioCheckpoints(parentDataStudio.getSessionId(), parentDataStudio.getWorkspaceId(), null, 1, null);

DataStudioCreateRequest request = prepareRequest(parentDataStudio, checkpoints.getCheckpoints());
DataStudioCreateRequest request = prepareRequest(parentDataStudio, parentCheckpointId, wspId);
DataStudioCreateResponse response = api().createDataStudio(request, wspId, autoStart);
DataStudioDto dataStudioDto = response.getStudio();
assert dataStudioDto != null;
Expand All @@ -87,17 +89,30 @@ protected Response exec() throws ApiException {
}
}

DataStudioCreateRequest prepareRequest(DataStudioDto parentDataStudio, List<DataStudioCheckpointDto> checkpoints) throws ApiException {
DataStudioCreateRequest prepareRequest(DataStudioDto parentDataStudio, String parentCheckpointId, Long wspId) throws ApiException {
DataStudioCreateRequest request = new DataStudioCreateRequest();
request.setName(name);
if (description == null || description.isEmpty()) {
request.description(String.format("Started from studio %s", parentDataStudio.getName()));
} else {
request.description(description);
}
if (checkpoints != null && !checkpoints.isEmpty()) {
request.setInitialCheckpointId(checkpoints.get(0).getId());

if (parentCheckpointId == null) {
DataStudioListCheckpointsResponse response = api().listDataStudioCheckpoints(parentDataStudio.getSessionId(), parentDataStudio.getWorkspaceId(), null, 1, null);
if (!response.getCheckpoints().isEmpty()) {
request.setInitialCheckpointId(response.getCheckpoints().get(0).getId());
}
} else {
try {
Long checkpoint = Long.valueOf(parentCheckpointId);
DataStudioCheckpointDto response = api().getDataStudioCheckpoint(parentDataStudio.getSessionId(), checkpoint, wspId);
request.setInitialCheckpointId(response.getId());
} catch (NumberFormatException | ApiException e) {
throw new InvalidDataStudioParentCheckpointException(parentCheckpointId);
}
}

request.setDataStudioToolUrl(Objects.requireNonNull(parentDataStudio.getTemplate()).getRepository());
request.setComputeEnvId(Objects.requireNonNull(parentDataStudio.getComputeEnv()).getId());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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;

public class InvalidDataStudioParentCheckpointException extends TowerException {

public InvalidDataStudioParentCheckpointException(String parentCheckpointId) {
super(String.format("Parent checkpoint parameter error, invalid checkpoint id: '%s'. Use studios checkpoints command to list exiting checkpoints", parentCheckpointId));
}
}
Loading
Loading