-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLAT-1152 - Add Data studios CLI list command
- Loading branch information
1 parent
161abf2
commit 0feab34
Showing
6 changed files
with
680 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/main/java/io/seqera/tower/cli/commands/datastudios/ListCmd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
src/main/java/io/seqera/tower/cli/responses/datastudios/DataStudiosList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(""); | ||
} | ||
|
||
} |
Oops, something went wrong.