From bf3751521b51f8de25c12d6366e3fc535106cbb3 Mon Sep 17 00:00:00 2001 From: Li Cheng Date: Fri, 16 Aug 2019 14:33:04 +0800 Subject: [PATCH] HDDS-1894. Add filter to scmcli listPipelines. (#1286) --- .../cli/pipeline/ListPipelinesSubcommand.java | 24 ++++++++++++++++++- 1 file changed, 23 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 0f8cf282068..1489ed06bfd 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 @@ -38,11 +38,33 @@ public class ListPipelinesSubcommand implements Callable { @CommandLine.ParentCommand private SCMCLI parent; + @CommandLine.Option( names = {"-ffc", "--filterByFactor"}, + description = "Filter listed pipelines by Factor(ONE/one)", defaultValue = "", + required = false) + private String factor; + + @CommandLine.Option( names = {"-fst", "--filterByState"}, + description = "Filter listed pipelines by State(OPEN/CLOSE)", defaultValue = "", + required = false) + private String state; + + @Override public Void call() throws Exception { try (ScmClient scmClient = parent.createScmClient()) { - scmClient.listPipelines().forEach(System.out::println); + if (isNullOrEmpty(factor) && isNullOrEmpty(state)) { + scmClient.listPipelines().forEach(System.out::println); + } else { + scmClient.listPipelines().stream() + .filter(p -> ((isNullOrEmpty(factor) || (p.getFactor().toString().compareToIgnoreCase(factor) == 0)) + && (isNullOrEmpty(state) || (p.getPipelineState().toString().compareToIgnoreCase(state) == 0)))) + .forEach(System.out::println); + } return null; } } + + protected static boolean isNullOrEmpty(String str) { + return ((str == null) || str.trim().isEmpty()); + } } \ No newline at end of file