keith-turner closed pull request #519: Add filter to listcompactions
URL: https://github.com/apache/accumulo/pull/519
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 3c264f6e87..11ca1a29ed 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.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 int execute(final String fullCommand, final 
CommandLine cl, final Shell s
       throws Exception {
 
     List<String> tservers;
+    String filterText = null;
 
     final InstanceOperations instanceOps = 
shellState.getConnector().instanceOperations();
 
@@ -54,7 +58,18 @@ public int execute(final String fullCommand, final 
CommandLine cl, final Shell s
       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 int numArgs() {
   @Override
   public Options getOptions() {
     final Options opts = new Options();
+    filterOption = new Option("f", "filter", true, "show only compactions that 
match the string");
+    opts.addOption(filterOption);
 
     tserverOption = new Option("ts", "tabletServer", true, "tablet server to 
list compactions for");
     tserverOption.setArgName("tablet server");


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to