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-1418 - Workaround fix for mount-data options showing as mandatry in the --help, while they are optional #484

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 7 additions & 7 deletions conf/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1920,37 +1920,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 +2740,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 @@ -91,8 +91,8 @@ public enum DataLinksFetchStatus {

public List<String> getDataLinkIds(DataLinkRefOptions.DataLinkRef dataLinkRef, Long wspId) {
// if DataLink IDs are supplied - use those directly
if (dataLinkRef.mountDataIds != null) {
return dataLinkRef.mountDataIds;
if (dataLinkRef.getMountDataIds() != null) {
return dataLinkRef.getMountDataIds();
}

// Check and wait if DataLinks are still being fetched
Expand All @@ -103,14 +103,14 @@ public List<String> getDataLinkIds(DataLinkRefOptions.DataLinkRef dataLinkRef, L

List<String> dataLinkIds = new ArrayList<>();

if (dataLinkRef.mountDataNames != null) {
dataLinkIds = dataLinkRef.mountDataNames.stream()
if (dataLinkRef.getMountDataNames() != null) {
dataLinkIds = dataLinkRef.getMountDataNames().stream()
.map(name -> getDataLinkIdByName(wspId, name))
.collect(Collectors.toList());
}

if (dataLinkRef.mountDataResourceRefs != null) {
dataLinkIds = dataLinkRef.mountDataResourceRefs.stream()
if (dataLinkRef.getMountDataResourceRefs() != null) {
dataLinkIds = dataLinkRef.getMountDataResourceRefs().stream()
.map(resourceRef -> getDataLinkIdByResourceRef(wspId, resourceRef))
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,52 @@

import java.util.List;

import io.seqera.tower.cli.exceptions.TowerRuntimeException;
import picocli.CommandLine;

public class DataLinkRefOptions {

@CommandLine.ArgGroup
// TODO: The use of the validate option is a work around to an existing Picocli issue. Please refer to https://github.com/seqeralabs/tower-cli/pull/72#issuecomment-952588876
@CommandLine.ArgGroup(validate = false, heading = "Option to mount data by passing in one of the below options:\n")
public DataLinkRef dataLinkRef;

public static class DataLinkRef {
@CommandLine.Option(names = {"--mount-data"}, description = "Optional configuration override for 'mountData' setting (comma separate list of data-link names)", split = ",")
public List<String> mountDataNames;
private List<String> mountDataNames;

@CommandLine.Option(names = {"--mount-data-ids"}, description = "Optional configuration override for 'mountData' setting (comma separate list of data-link Ids)", split = ",")
public List<String> mountDataIds;
private List<String> mountDataIds;

@CommandLine.Option(names = {"--mount-data-resource-refs"}, description = "Optional configuration override for 'mountData' setting (comma separate list of data-link resource refs)", split = ",")
public List<String> mountDataResourceRefs;
private List<String> mountDataResourceRefs;

public List<String> getMountDataNames() {
validate();
return mountDataNames;
}

public List<String> getMountDataIds() {
validate();
return mountDataIds;
}

public List<String> getMountDataResourceRefs() {
validate();
return mountDataResourceRefs;
}

private void validate() {
boolean namesProvided = mountDataNames != null;
boolean resourceRefsProvided = mountDataResourceRefs != null;
boolean idsProvided = mountDataIds != null;

// XOR function + check that not all 3 are provided covers that exactly 1 is provided
boolean valid = (namesProvided ^ resourceRefsProvided ^ idsProvided) && !(namesProvided && resourceRefsProvided && idsProvided);
Copy link
Member

Choose a reason for hiding this comment

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

minor: this is a bit too clever for my taste, but it checks out :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeaaah, I felt it as I was writing it too, but I just got excited at the opportunity to use the ^ operator :D

but I agree, it's not worth the weird complexity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I revised this a bit to make it more readable


if (!valid) {
throw new TowerRuntimeException("Error: --mount-data=<mountDataNames>, --mount-data-ids=<mountDataIds>, --mount-data-resource-refs=<mountDataResourceRefs> are mutually exclusive (specify only one)");
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public DataStudioStartSubmitted(String sessionId, String userSuppliedStudioIdent
@Override
public String toString() {
String isSuccess = jobSubmitted ? "successfully submitted" : "failed to submit";
return ansi(String.format("%n @|yellow Data Studio %s START %s at %s workspace.|@%n%n @|bold %s|@%n", userSuppliedStudioIdentifier, isSuccess, workspaceRef, studioUrl));
return ansi(String.format("%n @|yellow Data Studio %s START %s at %s workspace.|@%n%n To connect to this data studio session, copy and paste the following URL in your browser:%n%n @|bold %s|@%n", userSuppliedStudioIdentifier, isSuccess, workspaceRef, studioUrl));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public DataStudiosCreated(String sessionId, Long workspaceId, String workspaceRe
@Override
public String toString() {
if (autoStart){
return ansi(String.format("%n @|yellow Data Studio %s CREATED at %s workspace and auto started.|@%n%n @|bold %s|@%n", sessionId, workspaceRef, studioUrl));
return ansi(String.format("%n @|yellow Data Studio %s CREATED at %s workspace and auto started.|@%n%n To connect to this data studio session, copy and paste the following URL in your browser:%n%n @|bold %s|@%n", sessionId, workspaceRef, studioUrl));
} else {
return ansi(String.format("%n @|yellow Data Studio %s CREATED at %s workspace.|@%n", sessionId, workspaceRef));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.seqera.tower.cli.exceptions.DataStudiosCustomTemplateWithCondaException;
import io.seqera.tower.cli.exceptions.DataStudiosTemplateNotFoundException;
import io.seqera.tower.cli.exceptions.MultipleDataLinksFoundException;
import io.seqera.tower.cli.exceptions.TowerRuntimeException;
import io.seqera.tower.cli.responses.datastudios.DataStudioCheckpointsList;
import io.seqera.tower.cli.responses.datastudios.DataStudioDeleted;
import io.seqera.tower.cli.responses.datastudios.DataStudioStartSubmitted;
Expand Down Expand Up @@ -759,6 +760,41 @@ void testStartWithMountDateByName(OutputType format, MockServerClient mock) {
"[organization1 / workspace1]", "http://localhost:"+mock.getPort()+"/orgs/organization1/workspaces/workspace1", true));
}


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

mock.when(
request().withMethod("GET").withPath("/user/1264/workspaces"), exactly(2)
).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(2)
).respond(
response().withStatusCode(200).withBody(loadResource("datastudios/datastudios_view_response_studio_stopped")).withContentType(MediaType.APPLICATION_JSON)
);

ExecOut out = exec(format, mock, "studios", "start", "-w", "75887156211589", "-i" ,"3e8370e7", "--mount-data", "a-test-bucket-eend-us-east-1", "--mount-data-ids", "ids");

assertEquals(errorMessage(out.app, new TowerRuntimeException("Error: --mount-data=<mountDataNames>, --mount-data-ids=<mountDataIds>, --mount-data-resource-refs=<mountDataResourceRefs> are mutually exclusive (specify only one)")), out.stdErr);
assertEquals("", out.stdOut);
assertEquals(1, out.exitCode);

ExecOut out2 = exec(format, mock, "studios", "start", "-w", "75887156211589", "-i" ,"3e8370e7", "--mount-data", "a-test-bucket-eend-us-east-1", "--mount-data-ids", "ids", "--mount-data-resource-refs", "s3//ref");

assertEquals(errorMessage(out2.app, new TowerRuntimeException("Error: --mount-data=<mountDataNames>, --mount-data-ids=<mountDataIds>, --mount-data-resource-refs=<mountDataResourceRefs> are mutually exclusive (specify only one)")), out2.stdErr);
assertEquals("", out2.stdOut);
assertEquals(1, out2.exitCode);
}

@ParameterizedTest
@EnumSource(OutputType.class)
void testStartMultipleDataLinksFoundThrowsError(OutputType format, MockServerClient mock) {
Expand Down
Loading