accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ktur...@apache.org
Subject svn commit: r1438318 - in /accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell: ./ commands/
Date Fri, 25 Jan 2013 04:37:17 GMT
Author: kturner
Date: Fri Jan 25 04:37:16 2013
New Revision: 1438318

URL: http://svn.apache.org/viewvc?rev=1438318&view=rev
Log:
ACCUMULO-420 added commands to the shell for configuring iterators profiles.  These iterator
profiles can be used by scans and compactions.

Added:
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteShellterCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListShellIterCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetShellIterCommand.java
Modified:
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CompactCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteManyCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ScanCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetScanIterCommand.java

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java?rev=1438318&r1=1438317&r2=1438318&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java Fri Jan
25 04:37:16 2013
@@ -82,6 +82,7 @@ import org.apache.accumulo.core.util.she
 import org.apache.accumulo.core.util.shell.commands.DeleteManyCommand;
 import org.apache.accumulo.core.util.shell.commands.DeleteRowsCommand;
 import org.apache.accumulo.core.util.shell.commands.DeleteScanIterCommand;
+import org.apache.accumulo.core.util.shell.commands.DeleteShellterCommand;
 import org.apache.accumulo.core.util.shell.commands.DeleteTableCommand;
 import org.apache.accumulo.core.util.shell.commands.DeleteUserCommand;
 import org.apache.accumulo.core.util.shell.commands.DropTableCommand;
@@ -108,6 +109,7 @@ import org.apache.accumulo.core.util.she
 import org.apache.accumulo.core.util.shell.commands.ListCompactionsCommand;
 import org.apache.accumulo.core.util.shell.commands.ListIterCommand;
 import org.apache.accumulo.core.util.shell.commands.ListScansCommand;
+import org.apache.accumulo.core.util.shell.commands.ListShellIterCommand;
 import org.apache.accumulo.core.util.shell.commands.MaxRowCommand;
 import org.apache.accumulo.core.util.shell.commands.MergeCommand;
 import org.apache.accumulo.core.util.shell.commands.NoTableCommand;
@@ -125,6 +127,7 @@ import org.apache.accumulo.core.util.she
 import org.apache.accumulo.core.util.shell.commands.SetGroupsCommand;
 import org.apache.accumulo.core.util.shell.commands.SetIterCommand;
 import org.apache.accumulo.core.util.shell.commands.SetScanIterCommand;
+import org.apache.accumulo.core.util.shell.commands.SetShellIterCommand;
 import org.apache.accumulo.core.util.shell.commands.SleepCommand;
 import org.apache.accumulo.core.util.shell.commands.SystemPermissionsCommand;
 import org.apache.accumulo.core.util.shell.commands.TableCommand;
@@ -169,6 +172,7 @@ public class Shell extends ShellOptions 
   private Class<? extends Formatter> defaultFormatterClass = DefaultFormatter.class;
   private Class<? extends Formatter> binaryFormatterClass = BinaryFormatter.class;
   public Map<String,List<IteratorSetting>> scanIteratorOptions = new HashMap<String,List<IteratorSetting>>();
+  public Map<String,List<IteratorSetting>> iteratorProfiles = new HashMap<String,List<IteratorSetting>>();
   
   private Token rootToken;
   public final Map<String,Command> commandFactory = new TreeMap<String,Command>();
@@ -301,7 +305,8 @@ public class Shell extends ShellOptions 
     Command[] execCommands = {new ExecfileCommand(), new HistoryCommand()};
     Command[] exitCommands = {new ByeCommand(), new ExitCommand(), new QuitCommand()};
     Command[] helpCommands = {new AboutCommand(), new HelpCommand(), new InfoCommand(), new
QuestionCommand()};
-    Command[] iteratorCommands = {new DeleteIterCommand(), new DeleteScanIterCommand(), new
ListIterCommand(), new SetIterCommand(), new SetScanIterCommand()};
+    Command[] iteratorCommands = {new DeleteIterCommand(), new DeleteScanIterCommand(), new
ListIterCommand(), new SetIterCommand(), new SetScanIterCommand(),
+        new SetShellIterCommand(), new ListShellIterCommand(), new DeleteShellterCommand()};
     Command[] otherCommands = {new HiddenCommand()};
     Command[] permissionsCommands = {new GrantCommand(), new RevokeCommand(), new SystemPermissionsCommand(),
new TablePermissionsCommand(),
         new UserPermissionsCommand()};

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CompactCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CompactCommand.java?rev=1438318&r1=1438317&r2=1438318&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CompactCommand.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CompactCommand.java
Fri Jan 25 04:37:16 2013
@@ -16,8 +16,13 @@
  */
 package org.apache.accumulo.core.util.shell.commands;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
 import org.apache.accumulo.core.client.AccumuloException;
 import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.IteratorSetting;
 import org.apache.accumulo.core.util.shell.Shell;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.Option;
@@ -25,10 +30,11 @@ import org.apache.commons.cli.Options;
 import org.apache.hadoop.io.Text;
 
 public class CompactCommand extends TableOperation {
-  private Option noFlushOption, waitOpt;
+  private Option noFlushOption, waitOpt, profileOpt;
   private boolean flush;
   private Text startRow;
   private Text endRow;
+  private List<IteratorSetting> iterators;
   
   boolean override = false;
   private boolean wait;
@@ -44,7 +50,8 @@ public class CompactCommand extends Tabl
       if (wait) {
         Shell.log.info("Compacting table ...");
       }
-      shellState.getConnector().tableOperations().compact(tableName, startRow, endRow, flush,
wait);
+      
+      shellState.getConnector().tableOperations().compact(tableName, startRow, endRow, iterators,
flush, wait);
       
       Shell.log.info("Compaction of table " + tableName + " " + (wait ? "completed" : "started")
+ " for given range");
     } catch (Exception ex) {
@@ -59,6 +66,19 @@ public class CompactCommand extends Tabl
     endRow = OptUtil.getEndRow(cl);
     wait = cl.hasOption(waitOpt.getOpt());
     
+    if (cl.hasOption(profileOpt.getOpt())) {
+      List<IteratorSetting> iterators = shellState.iteratorProfiles.get(cl.getOptionValue(profileOpt.getOpt()));
+      if (iterators == null) {
+        Shell.log.error("Profile " + cl.getOptionValue(profileOpt.getOpt()) + " does not
exist");
+        return -1;
+      }
+      
+      this.iterators = new ArrayList<IteratorSetting>(iterators);
+    } else {
+      this.iterators = Collections.emptyList();
+    }
+
+
     return super.execute(fullCommand, cl, shellState);
   }
   
@@ -73,6 +93,10 @@ public class CompactCommand extends Tabl
     waitOpt = new Option("w", "wait", false, "wait for compact to finish");
     opts.addOption(waitOpt);
     
+    profileOpt = new Option("pn", "profile", true, "iterator profile name");
+    profileOpt.setArgName("profile");
+    opts.addOption(profileOpt);
+
     return opts;
   }
 }

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteManyCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteManyCommand.java?rev=1438318&r1=1438317&r2=1438318&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteManyCommand.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteManyCommand.java
Fri Jan 25 04:37:16 2013
@@ -47,7 +47,7 @@ public class DeleteManyCommand extends S
     scanner.addScanIterator(new IteratorSetting(Integer.MAX_VALUE, "NOVALUE", SortedKeyIterator.class));
     
     // handle session-specific scan iterators
-    addScanIterators(shellState, scanner, tableName);
+    addScanIterators(shellState, cl, scanner, tableName);
     
     // handle remaining optional arguments
     scanner.setRange(getRange(cl, interpeter));

Added: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteShellterCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteShellterCommand.java?rev=1438318&view=auto
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteShellterCommand.java
(added)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteShellterCommand.java
Fri Jan 25 04:37:16 2013
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.Shell.Command;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionGroup;
+import org.apache.commons.cli.Options;
+
+public class DeleteShellterCommand extends Command {
+  private Option nameOpt, allOpt, profileOpt;
+  
+  @Override
+  public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
throws Exception {
+
+    String profile = cl.getOptionValue(profileOpt.getOpt());
+    if (shellState.iteratorProfiles.containsKey(profile)) {
+      if (cl.hasOption(allOpt.getOpt())) {
+        shellState.iteratorProfiles.remove(profile);
+        Shell.log.info("Removed profile " + profile);
+      } else {
+        List<IteratorSetting> iterSettings = shellState.iteratorProfiles.get(profile);
+        String name = cl.getOptionValue(nameOpt.getOpt());
+        boolean found = false;
+        for (Iterator<IteratorSetting> iter = iterSettings.iterator(); iter.hasNext();)
{
+          if (iter.next().getName().equals(name)) {
+            iter.remove();
+            found = true;
+            break;
+          }
+        }
+        if (!found) {
+          Shell.log.info("No iterator named " + name + " found");
+        } else {
+          Shell.log.info("Removed iterator " + name + " from profile " + profile + " (" +
iterSettings.size() + " left)");
+        }
+      }
+      
+    } else {
+      Shell.log.info("No profile named " + profile);
+    }
+    
+    return 0;
+  }
+  
+  @Override
+  public String description() {
+    return "deletes iterators profiles configured in this shell session";
+  }
+  
+  @Override
+  public Options getOptions() {
+    final Options o = new Options();
+    
+    OptionGroup nameGroup = new OptionGroup();
+    
+    nameOpt = new Option("n", "name", true, "iterator to delete");
+    nameOpt.setArgName("itername");
+    
+    allOpt = new Option("a", "all", false, "delete all scan iterators");
+    allOpt.setArgName("all");
+    
+    nameGroup.addOption(nameOpt);
+    nameGroup.addOption(allOpt);
+    nameGroup.setRequired(true);
+    o.addOptionGroup(nameGroup);
+    
+    profileOpt = new Option("pn", "profile", true, "iterator profile name");
+    profileOpt.setRequired(true);
+    profileOpt.setArgName("profile");
+    o.addOption(profileOpt);
+
+    return o;
+  }
+  
+  @Override
+  public int numArgs() {
+    return 0;
+  }
+}

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java?rev=1438318&r1=1438317&r2=1438318&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java
Fri Jan 25 04:37:16 2013
@@ -79,7 +79,7 @@ public class ListIterCommand extends Com
   }
   
   public String description() {
-    return "lists table-specific iterators";
+    return "lists table-specific iterators configured in this shell session";
   }
   
   @Override

Added: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListShellIterCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListShellIterCommand.java?rev=1438318&view=auto
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListShellIterCommand.java
(added)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListShellIterCommand.java
Fri Jan 25 04:37:16 2013
@@ -0,0 +1,105 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.Shell.Command;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+
+/**
+ * 
+ */
+public class ListShellIterCommand extends Command {
+  
+  private Option nameOpt, profileOpt;
+
+  @Override
+  public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
throws Exception {
+    if (shellState.iteratorProfiles.size() == 0)
+      return 0;
+    
+    final StringBuilder sb = new StringBuilder();
+
+    String profile = null;
+    if (cl.hasOption(profileOpt.getOpt()))
+      profile = cl.getOptionValue(profileOpt.getOpt());
+
+    String name = null;
+    if (cl.hasOption(nameOpt.getOpt()))
+      name = cl.getOptionValue(nameOpt.getOpt());
+
+    Set<Entry<String,List<IteratorSetting>>> es = shellState.iteratorProfiles.entrySet();
+    for (Entry<String,List<IteratorSetting>> entry : es) {
+      if (profile != null && !profile.equals(entry.getKey()))
+        continue;
+
+      sb.append("-\n");
+      sb.append("- Profile : " + entry.getKey() + "\n");
+      for (IteratorSetting setting : entry.getValue()) {
+        if (name != null && !name.equals(setting.getName()))
+          continue;
+
+        sb.append("-    Iterator ").append(setting.getName()).append(", ").append(" options:\n");
+        sb.append("-        ").append("iteratorPriority").append(" = ").append(setting.getPriority()).append("\n");
+        sb.append("-        ").append("iteratorClassName").append(" = ").append(setting.getIteratorClass()).append("\n");
+        for (Entry<String,String> optEntry : setting.getOptions().entrySet()) {
+          sb.append("-        ").append(optEntry.getKey()).append(" = ").append(optEntry.getValue()).append("\n");
+        }
+      }
+    }
+    
+    if (sb.length() > 0) {
+      sb.append("-\n");
+    }
+
+    shellState.getReader().printString(sb.toString());
+
+    return 0;
+  }
+  
+  public String description() {
+    return "lists iterators profiles configured in shell";
+  }
+  
+  @Override
+  public int numArgs() {
+    return 0;
+  }
+  
+  @Override
+  public Options getOptions() {
+    final Options o = new Options();
+    
+    profileOpt = new Option("pn", "profile", true, "iterator profile name");
+    profileOpt.setArgName("profile");
+
+    nameOpt = new Option("n", "name", true, "iterator to list");
+    nameOpt.setArgName("itername");
+    
+    o.addOption(profileOpt);
+    o.addOption(nameOpt);
+
+    return o;
+  }
+}

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ScanCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ScanCommand.java?rev=1438318&r1=1438317&r2=1438318&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ScanCommand.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ScanCommand.java
Fri Jan 25 04:37:16 2013
@@ -55,6 +55,7 @@ public class ScanCommand extends Command
   private Option optStartRowExclusive;
   private Option optEndRowExclusive;
   private Option timeoutOption;
+  private Option profileOpt;
   
   public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
throws Exception {
 
@@ -72,7 +73,7 @@ public class ScanCommand extends Command
     final Scanner scanner = shellState.getConnector().createScanner(tableName, auths);
     
     // handle session-specific scan iterators
-    addScanIterators(shellState, scanner, tableName);
+    addScanIterators(shellState, cl, scanner, tableName);
     
     // handle remaining optional arguments
     scanner.setRange(getRange(cl, interpeter));
@@ -117,12 +118,24 @@ public class ScanCommand extends Command
     return Long.MAX_VALUE;
   }
 
-  protected void addScanIterators(final Shell shellState, final Scanner scanner, final String
tableName) {
-    final List<IteratorSetting> tableScanIterators = shellState.scanIteratorOptions.get(shellState.getTableName());
-    if (tableScanIterators == null) {
-      Shell.log.debug("Found no scan iterators to set");
-      return;
+  protected void addScanIterators(final Shell shellState, CommandLine cl, final Scanner scanner,
final String tableName) {
+    
+    List<IteratorSetting> tableScanIterators;
+    if (cl.hasOption(profileOpt.getOpt())) {
+      String profile = cl.getOptionValue(profileOpt.getOpt());
+      tableScanIterators = shellState.iteratorProfiles.get(profile);
+      
+      if (tableScanIterators == null) {
+        throw new IllegalArgumentException("Profile " + profile + " does not exist");
+      }
+    } else {
+      tableScanIterators = shellState.scanIteratorOptions.get(shellState.getTableName());
+      if (tableScanIterators == null) {
+        Shell.log.debug("Found no scan iterators to set");
+        return;
+      }
     }
+
     Shell.log.debug("Found " + tableScanIterators.size() + " scan iterators to set");
     
     for (IteratorSetting setting : tableScanIterators) {
@@ -287,6 +300,9 @@ public class ScanCommand extends Command
     timeoutOption.setArgName("timeout");
     outputFileOpt.setArgName("file");
     
+    profileOpt = new Option("pn", "profile", true, "iterator profile name");
+    profileOpt.setArgName("profile");
+
     o.addOption(scanOptAuths);
     o.addOption(scanOptRow);
     o.addOption(OptUtil.startRowOpt());
@@ -303,6 +319,7 @@ public class ScanCommand extends Command
     o.addOption(formatterInterpeterOpt);
     o.addOption(timeoutOption);
     o.addOption(outputFileOpt);
+    o.addOption(profileOpt);
     
     return o;
   }

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java?rev=1438318&r1=1438317&r2=1438318&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java
Fri Jan 25 04:37:16 2013
@@ -57,7 +57,6 @@ public class SetIterCommand extends Comm
   
   public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
throws AccumuloException, AccumuloSecurityException, TableNotFoundException,
       IOException, ShellCommandException {
-    final String tableName = OptUtil.getTableOpt(cl, shellState);
     
     final int priority = Integer.parseInt(cl.getOptionValue(priorityOpt.getOpt()));
     
@@ -87,14 +86,18 @@ public class SetIterCommand extends Comm
       throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, "Servers are unable
to load " + aggregatorClass + " as type "
           + Aggregator.class.getName());
     }    
-    setTableProperties(cl, shellState, tableName, priority, options, classname, name);
+    setTableProperties(cl, shellState, priority, options, classname, name);
     
     return 0;
   }
   
-  protected void setTableProperties(final CommandLine cl, final Shell shellState, final String
tableName, final int priority, final Map<String,String> options, final String classname,
final String name)
+  protected void setTableProperties(final CommandLine cl, final Shell shellState, final int
priority, final Map<String,String> options, final String classname,
+      final String name)
       throws AccumuloException, AccumuloSecurityException, ShellCommandException, TableNotFoundException
{
     // remove empty values
+    
+    final String tableName = OptUtil.getTableOpt(cl, shellState);
+
     for (Iterator<Entry<String,String>> i = options.entrySet().iterator(); i.hasNext();)
{
       final Entry<String,String> entry = i.next();
       if (entry.getValue() == null || entry.getValue().isEmpty()) {

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetScanIterCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetScanIterCommand.java?rev=1438318&r1=1438317&r2=1438318&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetScanIterCommand.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetScanIterCommand.java
Fri Jan 25 04:37:16 2013
@@ -22,6 +22,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import org.apache.accumulo.core.client.AccumuloException;
 import org.apache.accumulo.core.client.AccumuloSecurityException;
@@ -43,17 +44,29 @@ public class SetScanIterCommand extends 
   @Override
   public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
throws AccumuloException, AccumuloSecurityException, TableNotFoundException,
       IOException, ShellCommandException {
+    Shell.log.warn("Deprecated, use " + new SetShellIterCommand().getName());
     return super.execute(fullCommand, cl, shellState);
   }
   
   @Override
-  protected void setTableProperties(final CommandLine cl, final Shell shellState, final String
tableName, final int priority, final Map<String,String> options, final String classname,
final String name)
-      throws AccumuloException, AccumuloSecurityException, ShellCommandException, TableNotFoundException
{
+  protected void setTableProperties(final CommandLine cl, final Shell shellState, final int
priority, final Map<String,String> options, final String classname,
+      final String name) throws AccumuloException, AccumuloSecurityException, ShellCommandException,
TableNotFoundException {
+    
+    final String tableName = OptUtil.getTableOpt(cl, shellState);
+
     // instead of setting table properties, just put the options in a list to use at scan
time
     if (!shellState.getConnector().instanceOperations().testClassLoad(classname, SortedKeyValueIterator.class.getName()))
{
       throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, "Servers are unable
to load " + classname + " as type "
           + SortedKeyValueIterator.class.getName());
     }
+    
+    for (Iterator<Entry<String,String>> i = options.entrySet().iterator(); i.hasNext();)
{
+      final Entry<String,String> entry = i.next();
+      if (entry.getValue() == null || entry.getValue().isEmpty()) {
+        i.remove();
+      }
+    }
+
     List<IteratorSetting> tableScanIterators = shellState.scanIteratorOptions.get(tableName);
     if (tableScanIterators == null) {
       tableScanIterators = new ArrayList<IteratorSetting>();

Added: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetShellIterCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetShellIterCommand.java?rev=1438318&view=auto
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetShellIterCommand.java
(added)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetShellIterCommand.java
Fri Jan 25 04:37:16 2013
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.ShellCommandException;
+import org.apache.accumulo.core.util.shell.ShellCommandException.ErrorCode;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionGroup;
+import org.apache.commons.cli.Options;
+
+public class SetShellIterCommand extends SetIterCommand {
+  private Option profileOpt;
+
+  @Override
+  public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
throws AccumuloException, AccumuloSecurityException,
+      TableNotFoundException, IOException, ShellCommandException {
+    return super.execute(fullCommand, cl, shellState);
+  }
+  
+  @Override
+  protected void setTableProperties(final CommandLine cl, final Shell shellState, final int
priority, final Map<String,String> options, final String classname,
+      final String name) throws AccumuloException, AccumuloSecurityException, ShellCommandException,
TableNotFoundException {
+    // instead of setting table properties, just put the options in a list to use at scan
time
+    
+    String profile = cl.getOptionValue(profileOpt.getOpt());
+
+    if (!shellState.getConnector().instanceOperations().testClassLoad(classname, SortedKeyValueIterator.class.getName()))
{
+      throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, "Servers are unable
to load " + classname + " as type "
+          + SortedKeyValueIterator.class.getName());
+    }
+    
+    for (Iterator<Entry<String,String>> i = options.entrySet().iterator(); i.hasNext();)
{
+      final Entry<String,String> entry = i.next();
+      if (entry.getValue() == null || entry.getValue().isEmpty()) {
+        i.remove();
+      }
+    }
+
+    List<IteratorSetting> tableScanIterators = shellState.iteratorProfiles.get(profile);
+    if (tableScanIterators == null) {
+      tableScanIterators = new ArrayList<IteratorSetting>();
+      shellState.iteratorProfiles.put(profile, tableScanIterators);
+    }
+    final IteratorSetting setting = new IteratorSetting(priority, name, classname);
+    setting.addOptions(options);
+
+    Iterator<IteratorSetting> iter = tableScanIterators.iterator();
+    while (iter.hasNext()) {
+      if (iter.next().getName().equals(name)) {
+        iter.remove();
+      }
+    }
+
+    tableScanIterators.add(setting);
+  }
+  
+  @Override
+  public String description() {
+    return "adds an iterator to a profile for this shell session";
+  }
+  
+  @Override
+  public Options getOptions() {
+    // Remove the options that specify which type of iterator this is, since
+    // they are all scan iterators with this command.
+    final HashSet<OptionGroup> groups = new HashSet<OptionGroup>();
+    final Options parentOptions = super.getOptions();
+    final Options modifiedOptions = new Options();
+    for (Iterator<?> it = parentOptions.getOptions().iterator(); it.hasNext();) {
+      Option o = (Option) it.next();
+      if (!IteratorScope.majc.name().equals(o.getOpt()) && !IteratorScope.minc.name().equals(o.getOpt())
&& !IteratorScope.scan.name().equals(o.getOpt())
+          && !"table".equals(o.getLongOpt())) {
+        modifiedOptions.addOption(o);
+        OptionGroup group = parentOptions.getOptionGroup(o);
+        if (group != null)
+          groups.add(group);
+      }
+    }
+    for (OptionGroup group : groups) {
+      modifiedOptions.addOptionGroup(group);
+    }
+    
+    profileOpt = new Option("pn", "profile", true, "iterator profile name");
+    profileOpt.setRequired(true);
+    profileOpt.setArgName("profile");
+    
+    modifiedOptions.addOption(profileOpt);
+
+    return modifiedOptions;
+  }
+  
+}



Mime
View raw message