This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 28ba9bd9fe HDDS-6802. Implement JSON output for pipeline list CLI
(#4343)
28ba9bd9fe is described below
commit 28ba9bd9fe997986e75b7953f4445f6992e5e5a1
Author: nilotpalnandi <[email protected]>
AuthorDate: Mon Mar 6 16:12:57 2023 +0530
HDDS-6802. Implement JSON output for pipeline list CLI (#4343)
---
.../hdds/scm/cli/pipeline/ListPipelinesSubcommand.java | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git
a/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/pipeline/ListPipelinesSubcommand.java
b/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/pipeline/ListPipelinesSubcommand.java
index 88c771eb4a..b64673bc0c 100644
---
a/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/pipeline/ListPipelinesSubcommand.java
+++
b/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/pipeline/ListPipelinesSubcommand.java
@@ -28,11 +28,14 @@ import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.scm.cli.ScmSubcommand;
import org.apache.hadoop.hdds.scm.client.ScmClient;
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
+import org.apache.hadoop.hdds.server.JsonUtils;
import picocli.CommandLine;
import java.io.IOException;
+import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
@@ -68,6 +71,11 @@ public class ListPipelinesSubcommand extends ScmSubcommand {
defaultValue = "")
private String state;
+ @CommandLine.Option(names = { "--json" },
+ defaultValue = "false",
+ description = "Format output as JSON")
+ private boolean json;
+
@Override
public void execute(ScmClient scmClient) throws IOException {
Optional<Predicate<? super Pipeline>> replicationFilter =
@@ -81,7 +89,14 @@ public class ListPipelinesSubcommand extends ScmSubcommand {
stream = stream.filter(p -> p.getPipelineState().toString()
.compareToIgnoreCase(state) == 0);
}
- stream.forEach(System.out::println);
+
+ if (json) {
+ List<Pipeline> pipelineList = stream.collect(Collectors.toList());
+ System.out.print(
+ JsonUtils.toJsonStringWithDefaultPrettyPrinter(pipelineList));
+ } else {
+ stream.forEach(System.out::println);
+ }
}
private Optional<Predicate<? super Pipeline>> getReplicationFilter() {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]