Skip to content
Open
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
36 changes: 36 additions & 0 deletions conf/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,18 @@
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.datasets.DatasetMultiRefOptions",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.datasets.DatasetMultiRefOptions$DatasetMultiRef",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.datasets.DatasetRefOptions",
"allDeclaredFields":true,
Expand All @@ -1224,12 +1236,30 @@
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.datasets.HideCmd",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.datasets.LabelsCmd",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.datasets.ListCmd",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.datasets.ShowCmd",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.datasets.UpdateCmd",
"allDeclaredFields":true,
Expand Down Expand Up @@ -2153,6 +2183,12 @@
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.datasets.DatasetsVisibility",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.labels.DeleteLabelsResponse",
"allDeclaredFields":true,
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/io/seqera/tower/cli/commands/DatasetsCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import io.seqera.tower.cli.commands.datasets.AddCmd;
import io.seqera.tower.cli.commands.datasets.DeleteCmd;
import io.seqera.tower.cli.commands.datasets.DownloadCmd;
import io.seqera.tower.cli.commands.datasets.HideCmd;
import io.seqera.tower.cli.commands.datasets.LabelsCmd;
import io.seqera.tower.cli.commands.datasets.ListCmd;
import io.seqera.tower.cli.commands.datasets.ShowCmd;
import io.seqera.tower.cli.commands.datasets.UpdateCmd;
import io.seqera.tower.cli.commands.datasets.UrlCmd;
import io.seqera.tower.cli.commands.datasets.ViewCmd;
Expand All @@ -33,7 +36,10 @@
AddCmd.class,
DeleteCmd.class,
DownloadCmd.class,
HideCmd.class,
LabelsCmd.class,
ListCmd.class,
ShowCmd.class,
ViewCmd.class,
UpdateCmd.class,
UrlCmd.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.seqera.tower.model.ListDatasetsResponse;
import picocli.CommandLine;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
Expand All @@ -35,7 +36,7 @@
public abstract class AbstractDatasetsCmd extends AbstractApiCmd {

protected DatasetDto datasetByName(Long workspaceId, String datasetName) throws ApiException {
ListDatasetsResponse listDatasetsResponse = datasetsApi().listDatasets(workspaceId);
ListDatasetsResponse listDatasetsResponse = datasetsApi().listDatasetsV2(workspaceId, null, null, datasetName, null, null, "all", List.of());

if (listDatasetsResponse == null || listDatasetsResponse.getDatasets() == null) {
throw new DatasetNotFoundException(workspaceRef(workspaceId));
Expand All @@ -49,36 +50,14 @@ protected DatasetDto datasetByName(Long workspaceId, String datasetName) throws
throw new DatasetNotFoundException(datasetName, workspaceRef(workspaceId));
}

return datasetList.stream().findFirst().orElse(null);
}

protected List<DatasetDto> searchByName(Long workspaceId, String datasetName) throws ApiException {
ListDatasetsResponse listDatasetsResponse = datasetsApi().listDatasets(workspaceId);

if (datasetName == null) {
return listDatasetsResponse.getDatasets();
}

if (listDatasetsResponse == null || listDatasetsResponse.getDatasets() == null) {
throw new DatasetNotFoundException(workspaceRef(workspaceId));
}

List<DatasetDto> datasetList = listDatasetsResponse.getDatasets().stream()
.filter(it -> it.getName().startsWith(datasetName))
.collect(Collectors.toList());

if (datasetList.isEmpty()) {
throw new DatasetNotFoundException(datasetName, workspaceRef(workspaceId));
}

return datasetList;
return datasetList.get(0);
}

protected DatasetDto fetchDescribeDatasetResponse(DatasetRefOptions datasetRefOptions, Long wspId) throws ApiException {
DatasetDto response;

if (datasetRefOptions.dataset.datasetId != null) {
response = datasetsApi().describeDataset(wspId, datasetRefOptions.dataset.datasetId, List.of()).getDataset();
response = datasetsApi().describeDatasetV2(datasetRefOptions.dataset.datasetId, wspId, List.of()).getDataset();
} else {
response = datasetByName(wspId, datasetRefOptions.dataset.datasetName);
}
Expand All @@ -89,7 +68,7 @@ protected DatasetDto fetchDescribeDatasetResponse(DatasetRefOptions datasetRefOp
protected DatasetVersionDto fetchDatasetVersion(Long wspId, String datasetId, String datasetMediaType, Long version) throws ApiException {
DatasetVersionDto datasetVersion;

ListDatasetVersionsResponse listDatasetVersionsResponse = datasetsApi().listDatasetVersions(wspId, datasetId, datasetMediaType);
ListDatasetVersionsResponse listDatasetVersionsResponse = datasetsApi().listDatasetVersionsV2(datasetId, wspId, datasetMediaType);

if (listDatasetVersionsResponse == null || listDatasetVersionsResponse.getVersions() == null) {
throw new TowerException(String.format("No versions were found for dataset %s", datasetId));
Expand Down Expand Up @@ -129,13 +108,26 @@ protected String getDatasetRef(DatasetRefOptions datasetRefOptions) {
return datasetRefOptions.dataset.datasetName != null ? datasetRefOptions.dataset.datasetName : datasetRefOptions.dataset.datasetId;
}

protected List<String> resolveDatasetIds(DatasetMultiRefOptions options, Long wspId) throws ApiException {
List<String> ids = new ArrayList<>();
if (options.dataset.datasetIds != null) {
ids.addAll(options.dataset.datasetIds);
}
if (options.dataset.datasetNames != null) {
for (String name : options.dataset.datasetNames) {
ids.add(datasetByName(wspId, name).getId());
}
}
return ids;
}

protected void deleteDatasetByName(String datasetName, Long wspId) throws DatasetNotFoundException, ApiException {
DatasetDto response = datasetByName(wspId, datasetName);
deleteDatasetById(response.getId(), wspId);
}

protected void deleteDatasetById(String datasetId, Long wspId) throws DatasetNotFoundException, ApiException {
datasetsApi().deleteDataset(wspId, datasetId);
datasetsApi().deleteDatasetV2(datasetId, wspId);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ protected Response exec() throws ApiException, IOException {

if (overwrite) tryDeleteDataset(name, wspId);

CreateDatasetResponse response = datasetsApi().createDataset(wspId, request);
CreateDatasetResponse response = datasetsApi().createDatasetV2(request, wspId);

datasetsApi().uploadDataset(wspId, response.getDataset().getId(), header, fileName.toFile());
datasetsApi().uploadDatasetV2(response.getDataset().getId(), wspId, header, fileName.toFile());

return new DatasetCreate(response.getDataset().getName(), workspace.workspace, response.getDataset().getId());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.datasets;

import picocli.CommandLine;

import java.util.List;

public class DatasetMultiRefOptions {

@CommandLine.ArgGroup(multiplicity = "1")
public DatasetMultiRef dataset;

public static class DatasetMultiRef {

@CommandLine.Option(names = {"-i", "--id"}, arity = "1..*", description = "Dataset unique identifier(s). May be combined with --name.")
public List<String> datasetIds;

@CommandLine.Option(names = {"-n", "--name"}, arity = "1..*", description = "Dataset name(s). May be combined with --id.")
public List<String> datasetNames;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.datasets;

import io.seqera.tower.ApiException;
import io.seqera.tower.api.LabelsApi;
import io.seqera.tower.cli.commands.labels.BaseLabelsManager;
import io.seqera.tower.model.AssociateDatasetsLabelsRequest;

import java.util.List;

public class DatasetsLabelsManager extends BaseLabelsManager<AssociateDatasetsLabelsRequest, String> {

public DatasetsLabelsManager(LabelsApi api) {
super(api, "dataset");
}

@Override
protected AssociateDatasetsLabelsRequest getRequest(List<Long> labelsIds, String entityId) {
return new AssociateDatasetsLabelsRequest().labelIds(labelsIds).datasetIds(List.of(entityId));
}

@Override
protected void apply(AssociateDatasetsLabelsRequest request, Long wspId) throws ApiException {
api.applyLabelsToDatasets(request, wspId);
}

@Override
protected void remove(AssociateDatasetsLabelsRequest request, Long wspId) throws ApiException {
api.removeLabelsFromDatasets(request, wspId);
}

@Override
protected void append(AssociateDatasetsLabelsRequest request, Long wspId) throws ApiException {
api.addLabelsToDatasets(request, wspId);
}
}
51 changes: 51 additions & 0 deletions src/main/java/io/seqera/tower/cli/commands/datasets/HideCmd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.datasets;

import io.seqera.tower.ApiException;
import io.seqera.tower.cli.commands.global.WorkspaceRequiredOptions;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.responses.datasets.DatasetsVisibility;
import io.seqera.tower.model.ChangeDatasetVisibilityRequest;
import picocli.CommandLine;

import java.io.IOException;
import java.util.List;

@CommandLine.Command(
name = "hide",
description = "Hide one or more datasets"
)
public class HideCmd extends AbstractDatasetsCmd {

@CommandLine.Mixin
public DatasetMultiRefOptions datasetMultiRefOptions;

@CommandLine.Mixin
public WorkspaceRequiredOptions workspace;

@Override
protected Response exec() throws ApiException, IOException {
Long wspId = workspaceId(workspace.workspace);
List<String> ids = resolveDatasetIds(datasetMultiRefOptions, wspId);

ChangeDatasetVisibilityRequest request = new ChangeDatasetVisibilityRequest().datasetIds(ids);
datasetsApi().hideDatasets(request, wspId);

return new DatasetsVisibility(ids, workspace.workspace, true);
}
}
43 changes: 43 additions & 0 deletions src/main/java/io/seqera/tower/cli/commands/datasets/LabelsCmd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.datasets;

import io.seqera.tower.ApiException;
import io.seqera.tower.cli.commands.labels.LabelsSubcmdOptions;
import io.seqera.tower.cli.responses.Response;
import picocli.CommandLine;

import java.io.IOException;

@CommandLine.Command(name = "labels", description = "Manage dataset labels")
public class LabelsCmd extends AbstractDatasetsCmd {

@CommandLine.Mixin
public DatasetRefOptions datasetRefOptions;

@CommandLine.Mixin
public LabelsSubcmdOptions labelsSubcmdOptions;

@Override
protected Response exec() throws ApiException, IOException {
Long wspId = workspaceId(labelsSubcmdOptions.workspace.workspace);
String datasetId = fetchDescribeDatasetResponse(datasetRefOptions, wspId).getId();

DatasetsLabelsManager manager = new DatasetsLabelsManager(labelsApi());
return manager.execute(wspId, datasetId, labelsSubcmdOptions);
}
}
Loading
Loading