Skip to content

Commit

Permalink
PLAT-1152 - Add Data studios CLI list command
Browse files Browse the repository at this point in the history
  • Loading branch information
georgi-seqera committed Jan 15, 2025
1 parent 161abf2 commit 0feab34
Show file tree
Hide file tree
Showing 6 changed files with 680 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package io.seqera.tower.cli.commands;

import io.seqera.tower.cli.commands.datastudios.ListCmd;
import io.seqera.tower.cli.commands.datastudios.ViewCmd;
import picocli.CommandLine;

Expand All @@ -25,6 +26,7 @@
description = "Manage data studios.",
subcommands = {
ViewCmd.class,
ListCmd.class,
}
)
public class DataStudiosCmd extends AbstractRootCmd {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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.PaginationOptions;
import io.seqera.tower.cli.commands.global.ShowLabelsOption;
import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions;
import io.seqera.tower.cli.commands.pipelines.AbstractPipelinesCmd;
import io.seqera.tower.cli.commands.pipelines.PipelineVisibility;
import io.seqera.tower.cli.exceptions.WorkspaceNotFoundException;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.responses.datastudios.DataStudiosList;
import io.seqera.tower.cli.responses.pipelines.PipelinesList;
import io.seqera.tower.cli.utils.PaginationInfo;
import io.seqera.tower.model.DataStudioListResponse;
import io.seqera.tower.model.ListPipelinesResponse;
import io.seqera.tower.model.PipelineQueryAttribute;
import picocli.CommandLine;
import picocli.CommandLine.Command;

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

@Command(
name = "list",
description = "List workspace data studios."
)
public class ListCmd extends AbstractStudiosCmd {

@CommandLine.Mixin
public WorkspaceOptionalOptions workspace;

@CommandLine.Option(names = {"-f", "--filter"}, description = "Optional filter criteria, allowing free text search on name and templateUrl " +
"and keywords: `userName`, `computeEnvName` and `status`. Example keyword usage: -f status:RUNNING")
public String filter;

@CommandLine.Mixin
PaginationOptions paginationOptions;

@Override
protected Response exec() throws ApiException, IOException {
Long wspId = workspaceId(workspace.workspace);
Integer max = PaginationOptions.getMax(paginationOptions);
Integer offset = PaginationOptions.getOffset(paginationOptions, max);

DataStudioListResponse response = new DataStudioListResponse();

try {
response = api().listDataStudios(wspId, filter, max, offset);
} catch (ApiException apiException) {
if (apiException.getCode() == 404){
throw new WorkspaceNotFoundException(wspId);
}
}

return new DataStudiosList(workspaceRef(wspId), response.getStudios(), PaginationInfo.from(paginationOptions, response.getTotalSize()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* 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 java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.utils.PaginationInfo;
import io.seqera.tower.cli.utils.TableList;
import io.seqera.tower.model.DataStudioDto;
import io.seqera.tower.model.DataStudioStatusInfo;
import io.seqera.tower.model.StudioUser;

import static io.seqera.tower.cli.utils.FormatHelper.formatDataStudioStatus;
import static io.seqera.tower.cli.utils.FormatHelper.formatPipelineId;

public class DataStudiosList extends Response {

public final String workspaceRef;
public final List<DataStudioDto> studios;

@JsonIgnore
@Nullable
private final PaginationInfo paginationInfo;

public DataStudiosList(String workspaceRef, List<DataStudioDto> studios, @Nullable PaginationInfo paginationInfo) {
this.workspaceRef = workspaceRef;
this.studios = studios;
this.paginationInfo = paginationInfo;
}

@Override
public void toString(PrintWriter out) {

out.println(ansi(String.format("%n @|bold Data Studios at %s workspace:|@%n", workspaceRef)));

if (studios.isEmpty()) {
out.println(ansi(" @|yellow No data studios found|@"));
return;
}

List<String> descriptions = new ArrayList<>(List.of("ID", "Name", "Description", "", "User", "Status"));

TableList table = new TableList(out, descriptions.size(), descriptions.toArray(new String[descriptions.size()])).sortBy(0);
table.setPrefix(" ");

studios.forEach(studio -> {

DataStudioStatusInfo statusInfo = studio.getStatusInfo();
StudioUser user = studio.getUser();
List<String> rows = new ArrayList<>(List.of(
studio.getSessionId() == null ? "" : studio.getSessionId(),
studio.getName() == null ? "" : studio.getName(),
studio.getDescription() == null ? "" : studio.getDescription(),
user == null ? "" : user.getUserName(),
formatDataStudioStatus(statusInfo == null ? null : statusInfo.getStatus())
));

table.addRow(rows.toArray(new String[rows.size()]));
});

table.print();

PaginationInfo.addFooter(out, paginationInfo);

out.println("");
}

}
Loading

0 comments on commit 0feab34

Please sign in to comment.