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

PLAT-1245 - Delete command for Data Studio #480

Merged
merged 2 commits into from
Jan 30, 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
25 changes: 19 additions & 6 deletions conf/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,12 @@
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.datastudios.DeleteCmd",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.datastudios.ListCmd",
"allDeclaredFields":true,
Expand All @@ -1179,13 +1185,13 @@
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.datastudios.TemplatesCmd",
"name":"io.seqera.tower.cli.commands.datastudios.StopCmd",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.datastudios.StopCmd",
"name":"io.seqera.tower.cli.commands.datastudios.TemplatesCmd",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
Expand Down Expand Up @@ -1895,26 +1901,32 @@
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.datastudios.DataStudiosCreated",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.datastudios.DataStudiosList",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.datastudios.DataStudiosView",
"name":"io.seqera.tower.cli.responses.datastudios.DataStudiosTemplatesList",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.datastudios.DataStudiosCreated",
"name":"io.seqera.tower.cli.responses.datastudios.DataStudiosView",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.datastudios.DataStudiosTemplatesList",
"name":"io.seqera.tower.cli.responses.datastudios.DataStudioDeleted",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
Expand Down Expand Up @@ -2691,7 +2703,8 @@
"name":"io.seqera.tower.model.DataStudioCheckpointDto",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":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":"io.seqera.tower.model.DataStudioComputeEnvDto",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package io.seqera.tower.cli.commands;

import io.seqera.tower.cli.commands.datastudios.AddCmd;
import io.seqera.tower.cli.commands.datastudios.DeleteCmd;
import io.seqera.tower.cli.commands.datastudios.ListCmd;
import io.seqera.tower.cli.commands.datastudios.StartAsNewCmd;
import io.seqera.tower.cli.commands.datastudios.StartCmd;
Expand All @@ -36,7 +37,8 @@
AddCmd.class,
TemplatesCmd.class,
StartAsNewCmd.class,
StopCmd.class
StopCmd.class,
DeleteCmd.class,
}
)
public class DataStudiosCmd extends AbstractRootCmd {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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 io.seqera.tower.ApiException;
import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions;
import io.seqera.tower.cli.exceptions.DataStudioNotFoundException;
import io.seqera.tower.cli.exceptions.TowerException;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.responses.datastudios.DataStudioDeleted;
import picocli.CommandLine;

@CommandLine.Command(
name = "delete",
description = "Delete a data studio."
)
public class DeleteCmd extends AbstractStudiosCmd {

@CommandLine.Mixin
public WorkspaceOptionalOptions workspace;

@CommandLine.Mixin
public DataStudioRefOptions dataStudioRefOptions;

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

try {
String sessionId = getSessionId(dataStudioRefOptions, wspId);

api().deleteDataStudio(sessionId, wspId);

return new DataStudioDeleted(dataStudioRefOptions.getDataStudioIdentifier(), workspaceRef(wspId));
} catch (ApiException e) {
if (e.getCode() == 404) {
throw new DataStudioNotFoundException(dataStudioRefOptions.getDataStudioIdentifier(), workspace.workspace);
}
if (e.getCode() == 403) {
throw new TowerException(String.format("User not entitled to view studio '%s' at %s workspace", dataStudioRefOptions.getDataStudioIdentifier(), workspace.workspace));
}
throw e;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.responses.datastudios;

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

public class DataStudioDeleted extends Response {

public final String userSuppliedStudioIdentifier;

public final String workspaceRef;

public DataStudioDeleted(String userSuppliedStudioIdentifier, String workspaceRef) {
this.userSuppliedStudioIdentifier = userSuppliedStudioIdentifier;
this.workspaceRef = workspaceRef;
}

@Override
public String toString() {
return ansi(String.format("%n @|yellow Data Studio %s deleted at %s workspace.|@%n", userSuppliedStudioIdentifier, workspaceRef));
}

}
111 changes: 111 additions & 0 deletions src/test/java/io/seqera/tower/cli/datastudios/DataStudiosCmdTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.seqera.tower.cli.BaseCmdTest;
import io.seqera.tower.cli.commands.enums.OutputType;
import io.seqera.tower.cli.exceptions.MultipleDataLinksFoundException;
import io.seqera.tower.cli.responses.datastudios.DataStudioDeleted;
import io.seqera.tower.cli.responses.datastudios.DataStudioStartSubmitted;
import io.seqera.tower.cli.responses.datastudios.DataStudiosCreated;
import io.seqera.tower.cli.responses.datastudios.DataStudioStopSubmitted;
Expand Down Expand Up @@ -1102,4 +1103,114 @@ void testStartAsNew(OutputType format, MockServerClient mock) throws JsonProcess
""", DataStudioDto.class), "[organization1 / workspace1]"));
}

@ParameterizedTest
@EnumSource(OutputType.class)
void testStop(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("PUT").withPath("/studios/3e8370e7/stop").withQueryStringParameter("workspaceId", "75887156211589"), exactly(1)
).respond(
response().withStatusCode(200).withBody(json("""
{
"jobSubmitted": true,
"sessionId": "3e8370e7",
"statusInfo": {
"status": "stopping",
"message": "",
"lastUpdate": "2025-01-22T15:16:11.508692Z"
}
}
""")).withContentType(MediaType.APPLICATION_JSON)
);

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

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

@ParameterizedTest
@EnumSource(OutputType.class)
void testStopByName(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("datastudios/datastudios_list_response")).withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("PUT").withPath("/studios/3e8370e7/stop").withQueryStringParameter("workspaceId", "75887156211589"), exactly(1)
).respond(
response().withStatusCode(200).withBody(json("""
{
"jobSubmitted": true,
"sessionId": "3e8370e7",
"statusInfo": {
"status": "stopping",
"message": "",
"lastUpdate": "2025-01-22T15:16:11.508692Z"
}
}
""")).withContentType(MediaType.APPLICATION_JSON)
);

ExecOut out = exec(format, mock, "studios", "stop", "-w", "75887156211589", "-n" ,"studio-a66d");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is implementing delete, are you adding those tests just because you forgot with other PR or It's a mistake?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeaah, in the previous PR I had to resolve a some merge conflicts after rebasing and somehow these couple of tests got dropped accidentally after so I am re-adding them in this PR.


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

@ParameterizedTest
@EnumSource(OutputType.class)
void testDelete(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("DELETE").withPath("/studios/3e8370e7").withQueryStringParameter("workspaceId", "75887156211589"), exactly(1)
).respond(
response().withStatusCode(200).withContentType(MediaType.APPLICATION_JSON)
);


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

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

}
Loading