accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ktur...@apache.org
Subject [accumulo] branch master updated: Add filter to listcompactions (#519)
Date Wed, 11 Jul 2018 19:36:10 GMT
This is an automated email from the ASF dual-hosted git repository.

kturner pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/master by this push:
     new 8cc970c  Add filter to listcompactions (#519)
8cc970c is described below

commit 8cc970c95046f2d2f7026b8637eeaf88ddce9c0a
Author: Adam Lerman <alerman@gmail.com>
AuthorDate: Wed Jun 6 12:19:57 2018 +0000

    Add filter to listcompactions (#519)
---
 .../shell/commands/ListCompactionsCommand.java      | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/shell/src/main/java/org/apache/accumulo/shell/commands/ListCompactionsCommand.java
b/shell/src/main/java/org/apache/accumulo/shell/commands/ListCompactionsCommand.java
index 3c264f6..7f87878 100644
--- a/shell/src/main/java/org/apache/accumulo/shell/commands/ListCompactionsCommand.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/commands/ListCompactionsCommand.java
@@ -17,6 +17,7 @@
 package org.apache.accumulo.shell.commands;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
 import org.apache.accumulo.core.client.admin.InstanceOperations;
@@ -26,9 +27,11 @@ import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.Options;
 
+import com.google.common.collect.Iterators;
+
 public class ListCompactionsCommand extends Command {
 
-  private Option tserverOption, disablePaginationOpt;
+  private Option tserverOption, disablePaginationOpt, filterOption;
 
   @Override
   public String description() {
@@ -42,6 +45,7 @@ public class ListCompactionsCommand extends Command {
       throws Exception {
 
     List<String> tservers;
+    String filterText = null;
 
     final InstanceOperations instanceOps = shellState.getConnector().instanceOperations();
 
@@ -54,7 +58,18 @@ public class ListCompactionsCommand extends Command {
       tservers = instanceOps.getTabletServers();
     }
 
-    shellState.printLines(new ActiveCompactionIterator(tservers, instanceOps), paginate);
+    if (cl.hasOption(filterOption.getOpt())) {
+      filterText = ".*" + cl.getOptionValue(filterOption.getOpt()) + ".*";
+    }
+
+    Iterator<String> activeCompactionIterator = new ActiveCompactionIterator(tservers,
instanceOps);
+    if (filterText != null) {
+      String finalFilterText = filterText;
+      activeCompactionIterator = Iterators.filter(activeCompactionIterator,
+          t -> t.matches(finalFilterText));
+    }
+
+    shellState.printLines(activeCompactionIterator, paginate);
 
     return 0;
   }
@@ -67,6 +82,8 @@ public class ListCompactionsCommand extends Command {
   @Override
   public Options getOptions() {
     final Options opts = new Options();
+    filterOption = new Option("f", "filter", true, "show only compactions that match the
regex");
+    opts.addOption(filterOption);
 
     tserverOption = new Option("ts", "tabletServer", true, "tablet server to list compactions
for");
     tserverOption.setArgName("tablet server");


Mime
View raw message