You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by sa...@apache.org on 2019/08/16 06:33:15 UTC

[hadoop] branch trunk updated: HDDS-1894. Add filter to scmcli listPipelines. (#1286)

This is an automated email from the ASF dual-hosted git repository.

sammichen pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new bf37515  HDDS-1894. Add filter to scmcli listPipelines. (#1286)
bf37515 is described below

commit bf3751521b51f8de25c12d6366e3fc535106cbb3
Author: Li Cheng <bl...@gmail.com>
AuthorDate: Fri Aug 16 14:33:04 2019 +0800

    HDDS-1894. Add filter to scmcli listPipelines. (#1286)
---
 .../scm/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 0f8cf28..1489ed0 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<Void> {
   @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


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org