Package org.apache.accumulo.core.iterators

Examples of org.apache.accumulo.core.iterators.OptionDescriber$IteratorOptions


 
  private static String setUpOptions(ClassLoader classloader, final ConsoleReader reader, final String className, final Map<String,String> options)
      throws IOException,
      ShellCommandException {
    String input;
    OptionDescriber skvi;
    Class<? extends OptionDescriber> clazz;
    try {
      clazz = classloader.loadClass(className).asSubclass(OptionDescriber.class);
      skvi = clazz.newInstance();
    } catch (ClassNotFoundException e) {
      StringBuilder msg = new StringBuilder("Unable to load ").append(className);
      if (className.indexOf('.') < 0) {
        msg.append("; did you use a fully qualified package name?");
      } else {
        msg.append("; class not found.");
      }
      throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, msg.toString());
    } catch (InstantiationException e) {
      throw new IllegalArgumentException(e.getMessage());
    } catch (IllegalAccessException e) {
      throw new IllegalArgumentException(e.getMessage());
    } catch (ClassCastException e) {
      StringBuilder msg = new StringBuilder("Loaded ");
      msg.append(className).append(" but it does not implement ");
      msg.append(OptionDescriber.class.getSimpleName());
      msg.append("; use 'config -s' instead.");
      throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, msg.toString());
    }
   
    final IteratorOptions itopts = skvi.describeOptions();
    if (itopts.getName() == null) {
      throw new IllegalArgumentException(className + " described its default distinguishing name as null");
    }
    String shortClassName = className;
    if (className.contains(".")) {
      shortClassName = className.substring(className.lastIndexOf('.') + 1);
    }
    final Map<String,String> localOptions = new HashMap<String,String>();
    do {
      // clean up the overall options that caused things to fail
      for (String key : localOptions.keySet()) {
        options.remove(key);
      }
      localOptions.clear();
     
      reader.printString(itopts.getDescription());
      reader.printNewline();
     
      String prompt;
      if (itopts.getNamedOptions() != null) {
        for (Entry<String,String> e : itopts.getNamedOptions().entrySet()) {
          prompt = Shell.repeat("-", 10) + "> set " + shortClassName + " parameter " + e.getKey() + ", " + e.getValue() + ": ";
          reader.flushConsole();
          input = reader.readLine(prompt);
          if (input == null) {
            reader.printNewline();
            throw new IOException("Input stream closed");
          }
          // Places all Parameters and Values into the LocalOptions, even if the value is "".
          // This allows us to check for "" values when setting the iterators and allows us to remove
          // the parameter and value from the table property.
          localOptions.put(e.getKey(), input);
        }
      }
     
      if (itopts.getUnnamedOptionDescriptions() != null) {
        for (String desc : itopts.getUnnamedOptionDescriptions()) {
          reader.printString(Shell.repeat("-", 10) + "> entering options: " + desc + "\n");
          input = "start";
          while (true) {
            prompt = Shell.repeat("-", 10) + "> set " + shortClassName + " option (<name> <value>, hit enter to skip): ";
           
            reader.flushConsole();
            input = reader.readLine(prompt);
            if (input == null) {
              reader.printNewline();
              throw new IOException("Input stream closed");
            }
           
            if (input.length() == 0)
              break;
           
            String[] sa = input.split(" ", 2);
            localOptions.put(sa[0], sa[1]);
          }
        }
      }
     
      options.putAll(localOptions);
      if (!skvi.validateOptions(options))
        reader.printString("invalid options for " + clazz.getName() + "\n");
     
    } while (!skvi.validateOptions(options));
    return itopts.getName();
  }
View Full Code Here


      throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, msg.toString());
    }

    @SuppressWarnings("unchecked")
    SortedKeyValueIterator<Key,Value> skvi = (SortedKeyValueIterator<Key,Value>) untypedInstance;
    OptionDescriber iterOptions = null;
    if (OptionDescriber.class.isAssignableFrom(skvi.getClass())) {
      iterOptions = (OptionDescriber) skvi;
    }

    String iteratorName;
    if (null != iterOptions) {
      final IteratorOptions itopts = iterOptions.describeOptions();
      iteratorName = itopts.getName();
     
      if (iteratorName == null) {
        throw new IllegalArgumentException(className + " described its default distinguishing name as null");
      }
      String shortClassName = className;
      if (className.contains(".")) {
        shortClassName = className.substring(className.lastIndexOf('.') + 1);
      }
      final Map<String,String> localOptions = new HashMap<String,String>();
      do {
        // clean up the overall options that caused things to fail
        for (String key : localOptions.keySet()) {
          options.remove(key);
        }
        localOptions.clear();
 
        reader.println(itopts.getDescription());
 
        String prompt;
        if (itopts.getNamedOptions() != null) {
          for (Entry<String,String> e : itopts.getNamedOptions().entrySet()) {
            prompt = Shell.repeat("-", 10) + "> set " + shortClassName + " parameter " + e.getKey() + ", " + e.getValue() + ": ";
            reader.flush();
            input = reader.readLine(prompt);
            if (input == null) {
              reader.println();
              throw new IOException("Input stream closed");
            }
            // Places all Parameters and Values into the LocalOptions, even if the value is "".
            // This allows us to check for "" values when setting the iterators and allows us to remove
            // the parameter and value from the table property.
            localOptions.put(e.getKey(), input);
          }
        }
 
        if (itopts.getUnnamedOptionDescriptions() != null) {
          for (String desc : itopts.getUnnamedOptionDescriptions()) {
            reader.println(Shell.repeat("-", 10) + "> entering options: " + desc);
            input = "start";
            prompt = Shell.repeat("-", 10) + "> set " + shortClassName + " option (<name> <value>, hit enter to skip): ";
            while (true) {
              reader.flush();
              input = reader.readLine(prompt);
              if (input == null) {
                reader.println();
                throw new IOException("Input stream closed");
              } else {
                input = new String(input);
              }
 
              if (input.length() == 0)
                break;
 
              String[] sa = input.split(" ", 2);
              localOptions.put(sa[0], sa[1]);
            }
          }
        }
 
        options.putAll(localOptions);
        if (!iterOptions.validateOptions(options))
          reader.println("invalid options for " + clazz.getName());
 
      } while (!iterOptions.validateOptions(options));
    } else {
      reader.flush();
      reader.println("The iterator class does not implement OptionDescriber. Consider this for better iterator configuration using this setiter command.");
      iteratorName = reader.readLine("Name for iterator (enter to skip): ");
      if (null == iteratorName) {
View Full Code Here

      }
    }
   
    private static String setUpOptions(ConsoleReader reader, String className, Map<String,String> options) throws IOException {
      String input;
      OptionDescriber skvi;
      Class<? extends OptionDescriber> clazz;
      try {
        clazz = AccumuloClassLoader.loadClass(className, OptionDescriber.class);
        skvi = clazz.newInstance();
      } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException(e.getMessage());
      } catch (InstantiationException e) {
        throw new IllegalArgumentException(e.getMessage());
      } catch (IllegalAccessException e) {
        throw new IllegalArgumentException(e.getMessage());
      }
     
      IteratorOptions itopts = skvi.describeOptions();
      if (itopts.name == null)
        throw new IllegalArgumentException(className + " described its default distinguishing name as null");
     
      Map<String,String> localOptions = new HashMap<String,String>();
      do {
        // clean up the overall options that caused things to fail
        for (String key : localOptions.keySet())
          options.remove(key);
        localOptions.clear();
       
        reader.printString(itopts.description);
        reader.printNewline();
       
        String prompt;
        if (itopts.namedOptions != null) {
          for (Entry<String,String> e : itopts.namedOptions.entrySet()) {
            prompt = repeat("-", 10) + "> set " + className + " parameter " + e.getKey() + ", " + e.getValue() + ": ";
           
            input = reader.readLine(prompt);
            if (input == null) {
              reader.printNewline();
              throw new IOException("Input stream closed");
            }
           
            if (input.length() > 0)
              localOptions.put(e.getKey(), input);
          }
        }
       
        if (itopts.unnamedOptionDescriptions != null) {
          for (String desc : itopts.unnamedOptionDescriptions) {
            reader.printString(repeat("-", 10) + "> entering options: " + desc + "\n");
            input = "start";
            while (true) {
              prompt = repeat("-", 10) + "> set " + className + " option (<name> <value>, hit enter to skip): ";
             
              input = reader.readLine(prompt);
              if (input == null) {
                reader.printNewline();
                throw new IOException("Input stream closed");
              }
             
              if (input.length() == 0)
                break;
             
              String[] sa = input.split(" ", 2);
              localOptions.put(sa[0], sa[1]);
            }
          }
        }
       
        options.putAll(localOptions);
        if (!skvi.validateOptions(options))
          reader.printString("invalid options for " + clazz.getName() + "\n");
       
      } while (!skvi.validateOptions(options));
      return itopts.name;
    }
View Full Code Here

    shellState.getConnector().tableOperations().attachIterator(tableName, setting, scopes);
  }
 
  private static String setUpOptions(ConsoleReader reader, String className, Map<String,String> options) throws IOException, ShellCommandException {
    String input;
    OptionDescriber skvi;
    Class<? extends OptionDescriber> clazz;
    try {
      clazz = AccumuloClassLoader.loadClass(className, OptionDescriber.class);
      skvi = clazz.newInstance();
    } catch (ClassNotFoundException e) {
      throw new IllegalArgumentException(e.getMessage());
    } catch (InstantiationException e) {
      throw new IllegalArgumentException(e.getMessage());
    } catch (IllegalAccessException e) {
      throw new IllegalArgumentException(e.getMessage());
    } catch (ClassCastException e) {
      throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, "Unable to load " + className + " as type " + OptionDescriber.class.getName()
          + "; configure with 'config' instead");
    }
   
    IteratorOptions itopts = skvi.describeOptions();
    if (itopts.getName() == null)
      throw new IllegalArgumentException(className + " described its default distinguishing name as null");
   
    String shortClassName = className;
    if (className.contains("."))
      shortClassName = className.substring(className.lastIndexOf('.') + 1);
   
    Map<String,String> localOptions = new HashMap<String,String>();
    do {
      // clean up the overall options that caused things to fail
      for (String key : localOptions.keySet())
        options.remove(key);
      localOptions.clear();
     
      reader.printString(itopts.getDescription());
      reader.printNewline();
     
      String prompt;
      if (itopts.getNamedOptions() != null) {
        for (Entry<String,String> e : itopts.getNamedOptions().entrySet()) {
          prompt = Shell.repeat("-", 10) + "> set " + shortClassName + " parameter " + e.getKey() + ", " + e.getValue() + ": ";
         
          input = reader.readLine(prompt);
          if (input == null) {
            reader.printNewline();
            throw new IOException("Input stream closed");
          }
          // Places all Parameters and Values into the LocalOptions, even if the value is "".
          // This allows us to check for "" values when setting the iterators and allows us to remove
          // the parameter and value from the table property.
          localOptions.put(e.getKey(), input);
        }
      }
     
      if (itopts.getUnnamedOptionDescriptions() != null) {
        for (String desc : itopts.getUnnamedOptionDescriptions()) {
          reader.printString(Shell.repeat("-", 10) + "> entering options: " + desc + "\n");
          input = "start";
          while (true) {
            prompt = Shell.repeat("-", 10) + "> set " + shortClassName + " option (<name> <value>, hit enter to skip): ";
           
            input = reader.readLine(prompt);
            if (input == null) {
              reader.printNewline();
              throw new IOException("Input stream closed");
            }
           
            if (input.length() == 0)
              break;
           
            String[] sa = input.split(" ", 2);
            localOptions.put(sa[0], sa[1]);
          }
        }
      }
     
      options.putAll(localOptions);
      if (!skvi.validateOptions(options))
        reader.printString("invalid options for " + clazz.getName() + "\n");
     
    } while (!skvi.validateOptions(options));
    return itopts.getName();
  }
View Full Code Here

 
  private static String setUpOptions(ClassLoader classloader, final ConsoleReader reader, final String className, final Map<String,String> options)
      throws IOException,
      ShellCommandException {
    String input;
    OptionDescriber skvi;
    Class<? extends OptionDescriber> clazz;
    try {
      clazz = classloader.loadClass(className).asSubclass(OptionDescriber.class);
      skvi = clazz.newInstance();
    } catch (ClassNotFoundException e) {
      StringBuilder msg = new StringBuilder("Unable to load ").append(className);
      if (className.indexOf('.') < 0) {
        msg.append("; did you use a fully qualified package name?");
      } else {
        msg.append("; class not found.");
      }
      throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, msg.toString());
    } catch (InstantiationException e) {
      throw new IllegalArgumentException(e.getMessage());
    } catch (IllegalAccessException e) {
      throw new IllegalArgumentException(e.getMessage());
    } catch (ClassCastException e) {
      StringBuilder msg = new StringBuilder("Loaded ");
      msg.append(className).append(" but it does not implement ");
      msg.append(OptionDescriber.class.getSimpleName());
      msg.append("; use 'config -s' instead.");
      throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, msg.toString());
    }
   
    final IteratorOptions itopts = skvi.describeOptions();
    if (itopts.getName() == null) {
      throw new IllegalArgumentException(className + " described its default distinguishing name as null");
    }
    String shortClassName = className;
    if (className.contains(".")) {
      shortClassName = className.substring(className.lastIndexOf('.') + 1);
    }
    final Map<String,String> localOptions = new HashMap<String,String>();
    do {
      // clean up the overall options that caused things to fail
      for (String key : localOptions.keySet()) {
        options.remove(key);
      }
      localOptions.clear();
     
      reader.printString(itopts.getDescription());
      reader.printNewline();
     
      String prompt;
      if (itopts.getNamedOptions() != null) {
        for (Entry<String,String> e : itopts.getNamedOptions().entrySet()) {
          prompt = Shell.repeat("-", 10) + "> set " + shortClassName + " parameter " + e.getKey() + ", " + e.getValue() + ": ";
          reader.flushConsole();
          input = reader.readLine(prompt);
          if (input == null) {
            reader.printNewline();
            throw new IOException("Input stream closed");
          } else {
            input = new String(input);
          }
          // Places all Parameters and Values into the LocalOptions, even if the value is "".
          // This allows us to check for "" values when setting the iterators and allows us to remove
          // the parameter and value from the table property.
          localOptions.put(e.getKey(), input);
        }
      }
     
      if (itopts.getUnnamedOptionDescriptions() != null) {
        for (String desc : itopts.getUnnamedOptionDescriptions()) {
          reader.printString(Shell.repeat("-", 10) + "> entering options: " + desc + "\n");
          input = "start";
          while (true) {
            prompt = Shell.repeat("-", 10) + "> set " + shortClassName + " option (<name> <value>, hit enter to skip): ";
           
            reader.flushConsole();
            input = reader.readLine(prompt);
            if (input == null) {
              reader.printNewline();
              throw new IOException("Input stream closed");
            } else {
              input = new String(input);
            }
           
            if (input.length() == 0)
              break;
           
            String[] sa = input.split(" ", 2);
            localOptions.put(sa[0], sa[1]);
          }
        }
      }
     
      options.putAll(localOptions);
      if (!skvi.validateOptions(options))
        reader.printString("invalid options for " + clazz.getName() + "\n");
     
    } while (!skvi.validateOptions(options));
    return itopts.getName();
  }
View Full Code Here

      throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, msg.toString());
    }

    @SuppressWarnings("unchecked")
    SortedKeyValueIterator<Key,Value> skvi = (SortedKeyValueIterator<Key,Value>) untypedInstance;
    OptionDescriber iterOptions = null;
    if (OptionDescriber.class.isAssignableFrom(skvi.getClass())) {
      iterOptions = (OptionDescriber) skvi;
    }

    String iteratorName;
    if (null != iterOptions) {
      final IteratorOptions itopts = iterOptions.describeOptions();
      iteratorName = itopts.getName();
     
      if (iteratorName == null) {
        throw new IllegalArgumentException(className + " described its default distinguishing name as null");
      }
      String shortClassName = className;
      if (className.contains(".")) {
        shortClassName = className.substring(className.lastIndexOf('.') + 1);
      }
      final Map<String,String> localOptions = new HashMap<String,String>();
      do {
        // clean up the overall options that caused things to fail
        for (String key : localOptions.keySet()) {
          options.remove(key);
        }
        localOptions.clear();
 
        reader.println(itopts.getDescription());
 
        String prompt;
        if (itopts.getNamedOptions() != null) {
          for (Entry<String,String> e : itopts.getNamedOptions().entrySet()) {
            prompt = Shell.repeat("-", 10) + "> set " + shortClassName + " parameter " + e.getKey() + ", " + e.getValue() + ": ";
            reader.flush();
            input = reader.readLine(prompt);
            if (input == null) {
              reader.println();
              throw new IOException("Input stream closed");
            }
            // Places all Parameters and Values into the LocalOptions, even if the value is "".
            // This allows us to check for "" values when setting the iterators and allows us to remove
            // the parameter and value from the table property.
            localOptions.put(e.getKey(), input);
          }
        }
 
        if (itopts.getUnnamedOptionDescriptions() != null) {
          for (String desc : itopts.getUnnamedOptionDescriptions()) {
            reader.println(Shell.repeat("-", 10) + "> entering options: " + desc);
            input = "start";
            prompt = Shell.repeat("-", 10) + "> set " + shortClassName + " option (<name> <value>, hit enter to skip): ";
            while (true) {
              reader.flush();
              input = reader.readLine(prompt);
              if (input == null) {
                reader.println();
                throw new IOException("Input stream closed");
              } else {
                input = new String(input);
              }
 
              if (input.length() == 0)
                break;
 
              String[] sa = input.split(" ", 2);
              localOptions.put(sa[0], sa[1]);
            }
          }
        }
 
        options.putAll(localOptions);
        if (!iterOptions.validateOptions(options))
          reader.println("invalid options for " + clazz.getName());
 
      } while (!iterOptions.validateOptions(options));
    } else {
      reader.flush();
      reader.println("The iterator class does not implement OptionDescriber. Consider this for better iterator configuration using this setiter command.");
      iteratorName = reader.readLine("Name for iterator (enter to skip): ");
      if (null == iteratorName) {
View Full Code Here

    shellState.getConnector().tableOperations().attachIterator(tableName, setting, scopes);
  }
 
  private static String setUpOptions(ConsoleReader reader, String className, Map<String,String> options) throws IOException, ShellCommandException {
    String input;
    OptionDescriber skvi;
    Class<? extends OptionDescriber> clazz;
    try {
      clazz = AccumuloClassLoader.loadClass(className, OptionDescriber.class);
      skvi = clazz.newInstance();
    } catch (ClassNotFoundException e) {
      throw new IllegalArgumentException(e.getMessage());
    } catch (InstantiationException e) {
      throw new IllegalArgumentException(e.getMessage());
    } catch (IllegalAccessException e) {
      throw new IllegalArgumentException(e.getMessage());
    } catch (ClassCastException e) {
      throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, "Unable to load " + className + " as type " + OptionDescriber.class.getName()
          + "; configure with 'config' instead");
    }
   
    IteratorOptions itopts = skvi.describeOptions();
    if (itopts.getName() == null)
      throw new IllegalArgumentException(className + " described its default distinguishing name as null");
   
    String shortClassName = className;
    if (className.contains("."))
      shortClassName = className.substring(className.lastIndexOf('.') + 1);
   
    Map<String,String> localOptions = new HashMap<String,String>();
    do {
      // clean up the overall options that caused things to fail
      for (String key : localOptions.keySet())
        options.remove(key);
      localOptions.clear();
     
      reader.printString(itopts.getDescription());
      reader.printNewline();
     
      String prompt;
      if (itopts.getNamedOptions() != null) {
        for (Entry<String,String> e : itopts.getNamedOptions().entrySet()) {
          prompt = Shell.repeat("-", 10) + "> set " + shortClassName + " parameter " + e.getKey() + ", " + e.getValue() + ": ";
         
          input = reader.readLine(prompt);
          if (input == null) {
            reader.printNewline();
            throw new IOException("Input stream closed");
          }
          // Places all Parameters and Values into the LocalOptions, even if the value is "".
          // This allows us to check for "" values when setting the iterators and allows us to remove
          // the parameter and value from the table property.
          localOptions.put(e.getKey(), input);
        }
      }
     
      if (itopts.getUnnamedOptionDescriptions() != null) {
        for (String desc : itopts.getUnnamedOptionDescriptions()) {
          reader.printString(Shell.repeat("-", 10) + "> entering options: " + desc + "\n");
          input = "start";
          while (true) {
            prompt = Shell.repeat("-", 10) + "> set " + shortClassName + " option (<name> <value>, hit enter to skip): ";
           
            input = reader.readLine(prompt);
            if (input == null) {
              reader.printNewline();
              throw new IOException("Input stream closed");
            }
           
            if (input.length() == 0)
              break;
           
            String[] sa = input.split(" ", 2);
            localOptions.put(sa[0], sa[1]);
          }
        }
      }
     
      options.putAll(localOptions);
      if (!skvi.validateOptions(options))
        reader.printString("invalid options for " + clazz.getName() + "\n");
     
    } while (!skvi.validateOptions(options));
    return itopts.getName();
  }
View Full Code Here

      }
    }
   
    private static String setUpOptions(ConsoleReader reader, String className, Map<String,String> options) throws IOException {
      String input;
      OptionDescriber skvi;
      Class<? extends OptionDescriber> clazz;
      try {
        clazz = AccumuloClassLoader.loadClass(className, OptionDescriber.class);
        skvi = clazz.newInstance();
      } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException(e.getMessage());
      } catch (InstantiationException e) {
        throw new IllegalArgumentException(e.getMessage());
      } catch (IllegalAccessException e) {
        throw new IllegalArgumentException(e.getMessage());
      }
     
      IteratorOptions itopts = skvi.describeOptions();
      if (itopts.name == null)
        throw new IllegalArgumentException(className + " described its default distinguishing name as null");
     
      Map<String,String> localOptions = new HashMap<String,String>();
      do {
        // clean up the overall options that caused things to fail
        for (String key : localOptions.keySet())
          options.remove(key);
        localOptions.clear();
       
        reader.printString(itopts.description);
        reader.printNewline();
       
        String prompt;
        if (itopts.namedOptions != null) {
          for (Entry<String,String> e : itopts.namedOptions.entrySet()) {
            prompt = repeat("-", 10) + "> set " + className + " parameter " + e.getKey() + ", " + e.getValue() + ": ";
           
            input = reader.readLine(prompt);
            if (input == null) {
              reader.printNewline();
              throw new IOException("Input stream closed");
            }
           
            if (input.length() > 0)
              localOptions.put(e.getKey(), input);
          }
        }
       
        if (itopts.unnamedOptionDescriptions != null) {
          for (String desc : itopts.unnamedOptionDescriptions) {
            reader.printString(repeat("-", 10) + "> entering options: " + desc + "\n");
            input = "start";
            while (true) {
              prompt = repeat("-", 10) + "> set " + className + " option (<name> <value>, hit enter to skip): ";
             
              input = reader.readLine(prompt);
              if (input == null) {
                reader.printNewline();
                throw new IOException("Input stream closed");
              }
             
              if (input.length() == 0)
                break;
             
              String[] sa = input.split(" ", 2);
              localOptions.put(sa[0], sa[1]);
            }
          }
        }
       
        options.putAll(localOptions);
        if (!skvi.validateOptions(options))
          reader.printString("invalid options for " + clazz.getName() + "\n");
       
      } while (!skvi.validateOptions(options));
      return itopts.name;
    }
View Full Code Here

TOP

Related Classes of org.apache.accumulo.core.iterators.OptionDescriber$IteratorOptions

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.