Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
12 changes: 12 additions & 0 deletions conf/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,12 @@
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.studios.UpdateCmd",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.studios.StudioCheckpointRefOptions",
"allDeclaredFields":true,
Expand Down Expand Up @@ -2399,6 +2405,12 @@
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.studios.StudioUpdated",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.studios.StudiosCreated",
"allDeclaredFields":true,
Expand Down
4 changes: 2 additions & 2 deletions conf/resource-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@
"locales":["und"]
}, {
"name":"org.glassfish.jersey.client.internal.localization",
"locales":["", "und"]
"locales":["und"]
}, {
"name":"org.glassfish.jersey.internal.localization",
"locales":["", "und"]
"locales":["und"]
}, {
"name":"org.glassfish.jersey.media.multipart.internal.localization"
}]
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/seqera/tower/cli/commands/StudiosCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.seqera.tower.cli.commands.studios.StartCmd;
import io.seqera.tower.cli.commands.studios.TemplatesCmd;
import io.seqera.tower.cli.commands.studios.StopCmd;
import io.seqera.tower.cli.commands.studios.UpdateCmd;
import io.seqera.tower.cli.commands.studios.ViewCmd;
import picocli.CommandLine;

Expand All @@ -39,6 +40,7 @@
CheckpointsCmd.class,
AddAsNewCmd.class,
StopCmd.class,
UpdateCmd.class,
DeleteCmd.class,
}
)
Expand Down
99 changes: 99 additions & 0 deletions src/main/java/io/seqera/tower/cli/commands/studios/UpdateCmd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright 2021-2026, 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.studios;

import java.util.List;

import io.seqera.tower.ApiException;
import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions;
import io.seqera.tower.cli.commands.labels.Label;
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.StudioUpdated;
import io.seqera.tower.model.DataStudioConfiguration;
import io.seqera.tower.model.DataStudioDto;
import io.seqera.tower.model.DataStudioUpdateRequest;
import picocli.CommandLine;

@CommandLine.Command(
name = "update",
description = "Update a studio."
)
public class UpdateCmd extends AbstractStudiosCmd {

@CommandLine.Mixin
public WorkspaceOptionalOptions workspace;

@CommandLine.Mixin
public StudioRefOptions studioRefOptions;

@CommandLine.Mixin
public StudioConfigurationOptions studioConfigOptions;

@CommandLine.Option(names = {"--labels"}, description = "Comma-separated list of labels", split = ",", converter = Label.StudioResourceLabelsConverter.class)
public List<Label> labels;

@CommandLine.Option(names = {"--description"}, description = "Optional configuration override for 'description'.")
public String description;

@CommandLine.Option(names = {"--new-name"}, description = "Optional new name for the studio.")
public String newName;

@Override
protected Response exec() throws ApiException {
Long wspId = workspaceId(workspace.workspace);

try {
DataStudioDto studioDto = fetchStudio(studioRefOptions, wspId);

DataStudioUpdateRequest request = getUpdateRequestWithOverridesApplied(studioDto);

DataStudioDto updatedStudio = studiosApi().updateDataStudio(studioDto.getSessionId(), request, wspId);

return new StudioUpdated(updatedStudio.getSessionId(), studioRefOptions.getStudioIdentifier(), wspId, workspaceRef(wspId));
} catch (ApiException e) {
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;
}
}

private DataStudioUpdateRequest getUpdateRequestWithOverridesApplied(DataStudioDto studioDto) throws ApiException {
DataStudioConfiguration newConfig = studioConfigurationFrom(studioDto.getWorkspaceId(), studioDto, studioConfigOptions);
String appliedDescription = description == null
? studioDto.getDescription()
: description;

DataStudioUpdateRequest request = new DataStudioUpdateRequest();

request.setConfiguration(newConfig);
request.setDescription(appliedDescription);
request.setLabelIds(getLabelIds(labels, studioDto.getWorkspaceId()));

if (newName != null) {
request.setName(newName);
}

return request;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2021-2026, 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.responses.studios;

import io.seqera.tower.cli.responses.Response;

public class StudioUpdated extends Response {

public final String sessionId;
public final String userSuppliedStudioIdentifier;
public final Long workspaceId;
public final String workspaceRef;

public StudioUpdated(String sessionId, String userSuppliedStudioIdentifier, Long workspaceId, String workspaceRef) {
this.sessionId = sessionId;
this.userSuppliedStudioIdentifier = userSuppliedStudioIdentifier;
this.workspaceId = workspaceId;
this.workspaceRef = workspaceRef;
}

@Override
public String toString() {
return ansi(String.format("%n @|yellow Studio %s UPDATED at %s workspace.|@%n", userSuppliedStudioIdentifier, workspaceRef));
}
}
177 changes: 177 additions & 0 deletions src/test/java/io/seqera/tower/cli/studios/StudiosCmdTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.seqera.tower.cli.responses.studios.StudioDeleted;
import io.seqera.tower.cli.responses.studios.StudioStartSubmitted;
import io.seqera.tower.cli.responses.studios.StudioStopSubmitted;
import io.seqera.tower.cli.responses.studios.StudioUpdated;
import io.seqera.tower.cli.responses.studios.StudiosTemplatesList;
import io.seqera.tower.cli.responses.studios.StudiosView;
import io.seqera.tower.cli.utils.PaginationInfo;
Expand Down Expand Up @@ -2025,4 +2026,180 @@ void testCheckpoints(OutputType format, MockServerClient mock) throws JsonProces
), null));
}

@ParameterizedTest
@EnumSource(OutputType.class)
void testUpdate(OutputType format, MockServerClient mock) {

mock.when(
request().withMethod("GET").withPath("/user-info"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("user")).withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("GET").withPath("/user/1264/workspaces"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("workspaces/workspaces_list")).withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("GET").withPath("/studios/3e8370e7").withQueryStringParameter("workspaceId", "75887156211589"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("studios/studios_view_response_studio_stopped")).withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("PUT").withPath("/studios/3e8370e7").withQueryStringParameter("workspaceId", "75887156211589").withBody(json("""
{
"configuration": {
"gpu": 0,
"cpu": 2,
"memory": 8192,
"mountData": [
"v1-user-1ccf131810375d303bf0402dd8423433"
]
},
"description": "my first studio"
}
"""
)

), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("studios/studios_update_response")).withContentType(MediaType.APPLICATION_JSON)
);


ExecOut out = exec(format, mock, "studios", "update", "-w", "75887156211589", "-i" ,"3e8370e7");

assertOutput(format, out, new StudioUpdated("3e8370e7", "3e8370e7", 75887156211589L,
"[organization1 / workspace1]"));
}

@ParameterizedTest
@EnumSource(OutputType.class)
void testUpdateByName(OutputType format, MockServerClient mock) {

mock.when(
request().withMethod("GET").withPath("/user-info"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("user")).withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("GET").withPath("/user/1264/workspaces"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("workspaces/workspaces_list")).withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("GET").withPath("/studios").withQueryStringParameter("workspaceId", "75887156211589"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("studios/studios_list_response")).withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("GET").withPath("/studios/3e8370e7").withQueryStringParameter("workspaceId", "75887156211589"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("studios/studios_view_response_studio_stopped")).withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("PUT").withPath("/studios/3e8370e7").withQueryStringParameter("workspaceId", "75887156211589").withBody(json("""
{
"configuration": {
"gpu": 0,
"cpu": 2,
"memory": 8192,
"mountData": [
"v1-user-1ccf131810375d303bf0402dd8423433"
]
},
"description": "my first studio"
}
"""
)

), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("studios/studios_update_response")).withContentType(MediaType.APPLICATION_JSON)
);


ExecOut out = exec(format, mock, "studios", "update", "-w", "organization1/workspace1", "-n" ,"studio-a66d");

assertOutput(format, out, new StudioUpdated("3e8370e7", "studio-a66d", 75887156211589L,
"[organization1 / workspace1]"));
}

@ParameterizedTest
@EnumSource(OutputType.class)
void testUpdateWithConfigOverride(OutputType format, MockServerClient mock) {
mock.when(
request().withMethod("GET").withPath("/user-info"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("user")).withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("GET").withPath("/user/1264/workspaces"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("workspaces/workspaces_list")).withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("GET").withPath("/studios/3e8370e7").withQueryStringParameter("workspaceId", "75887156211589"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("studios/studios_view_response_studio_stopped")).withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("GET").withPath("/labels")
).respond(
response().withStatusCode(200).withBody(json("""
{
"labels": [
{
"id": 10,
"name": "owner",
"resource": true,
"value": "jack"
}
],
"totalSize": 1
}
"""))
);

mock.when(
request().withMethod("PUT").withPath("/studios/3e8370e7").withQueryStringParameter("workspaceId", "75887156211589").withBody(json("""
{
"configuration": {
"gpu": 0,
"cpu": 4,
"memory": 8192,
"mountData": [
"v1-user-1ccf131810375d303bf0402dd8423433"
],
"lifespanHours" : 24
},
"labelIds": [10],
"description": "Override description",
"name": "new-studio-name"
}
"""
)

), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("studios/studios_update_response")).withContentType(MediaType.APPLICATION_JSON)
);


ExecOut out = exec(format, mock, "studios", "update", "-w", "75887156211589", "-i" ,"3e8370e7", "--cpu", "4", "--description", "Override description", "--lifespan", "24", "--labels", "owner=jack", "--new-name", "new-studio-name");

assertOutput(format, out, new StudioUpdated("3e8370e7", "3e8370e7", 75887156211589L,
"[organization1 / workspace1]"));
}

}
Loading
Loading