@Before
  public void setUp() {
    volMgr = createMock(VolumeManager.class);
    instance = createMock(Instance.class);
    SiteConfiguration siteConfig = EasyMock.createMock(SiteConfiguration.class);
    expect(instance.getInstanceID()).andReturn("mock").anyTimes();
    expect(instance.getZooKeepers()).andReturn("localhost").anyTimes();
    expect(instance.getZooKeepersSessionTimeOut()).andReturn(30000).anyTimes();

    opts = new Opts();
    systemConfig = createSystemConfig();
    ServerConfigurationFactory factory = createMock(ServerConfigurationFactory.class);
    expect(factory.getInstance()).andReturn(instance).anyTimes();
    expect(factory.getConfiguration()).andReturn(systemConfig).anyTimes();
    expect(factory.getSiteConfiguration()).andReturn(siteConfig).anyTimes();

    // Just make the SiteConfiguration delegate to our AccumuloConfiguration
    // Presently, we only need get(Property) and iterator().
    EasyMock.expect(siteConfig.get(EasyMock.anyObject(Property.class)))
        .andAnswer(
            new IAnswer<String>() {
              @Override
              public String answer() {
                Object[] args = EasyMock.getCurrentArguments();
                return systemConfig.get((Property) args[0]);
              }
            })
        .anyTimes();
    EasyMock.expect(siteConfig.getBoolean(EasyMock.anyObject(Property.class)))
        .andAnswer(
            new IAnswer<Boolean>() {
              @Override
              public Boolean answer() {
                Object[] args = EasyMock.getCurrentArguments();
                return systemConfig.getBoolean((Property) args[0]);
              }
            })
        .anyTimes();

    EasyMock.expect(siteConfig.iterator())
        .andAnswer(
            new IAnswer<Iterator<Entry<String, String>>>() {
              @Override
              public Iterator<Entry<String, String>> answer() {
                return systemConfig.iterator();
              }
            })
        .anyTimes();

    replay(instance, factory, siteConfig);

    credentials = SystemCredentials.get(instance);
    gc = new SimpleGarbageCollector(opts, volMgr, factory);
  }
Example #2
0
  /**
   * Dump a Log File (Map or Sequence) to stdout. Will read from HDFS or local file system.
   *
   * @param args - first argument is the file to print
   */
  public static void main(String[] args) throws IOException {
    Opts opts = new Opts();
    opts.parseArgs(LogReader.class.getName(), args);
    VolumeManager fs = VolumeManagerImpl.get();

    Matcher rowMatcher = null;
    KeyExtent ke = null;
    Text row = null;
    if (opts.files.isEmpty()) {
      new JCommander(opts).usage();
      return;
    }
    if (opts.row != null) row = new Text(opts.row);
    if (opts.extent != null) {
      String sa[] = opts.extent.split(";");
      ke = new KeyExtent(new Text(sa[0]), new Text(sa[1]), new Text(sa[2]));
    }
    if (opts.regexp != null) {
      Pattern pattern = Pattern.compile(opts.regexp);
      rowMatcher = pattern.matcher("");
    }

    Set<Integer> tabletIds = new HashSet<Integer>();

    for (String file : opts.files) {

      Path path = new Path(file);
      LogFileKey key = new LogFileKey();
      LogFileValue value = new LogFileValue();

      if (fs.isFile(path)) {
        // read log entries from a simple hdfs file
        DFSLoggerInputStreams streams =
            DfsLogger.readHeaderAndReturnStream(fs, path, SiteConfiguration.getInstance());
        DataInputStream input = streams.getDecryptingInputStream();

        try {
          while (true) {
            try {
              key.readFields(input);
              value.readFields(input);
            } catch (EOFException ex) {
              break;
            }
            printLogEvent(key, value, row, rowMatcher, ke, tabletIds, opts.maxMutations);
          }
        } finally {
          input.close();
        }
      } else {
        // read the log entries sorted in a map file
        MultiReader input = new MultiReader(fs, path);
        while (input.next(key, value)) {
          printLogEvent(key, value, row, rowMatcher, ke, tabletIds, opts.maxMutations);
        }
      }
    }
  }
Example #3
0
  protected synchronized IZooReaderWriter getZooReaderWriter(Instance instance, String secret) {

    if (secret == null) {
      AccumuloConfiguration conf =
          SiteConfiguration.getInstance(DefaultConfiguration.getInstance());
      secret = conf.get(Property.INSTANCE_SECRET);
    }

    return new ZooReaderWriter(
        instance.getZooKeepers(),
        instance.getZooKeepersSessionTimeOut(),
        SCHEME,
        (USER + ":" + secret).getBytes());
  }
 @After
 public void tearDown() {
   shell.shutdown();
   SiteConfiguration.clearInstance();
 }
Example #5
0
 public static synchronized SiteConfiguration getSiteConfiguration() {
   checkPermissions();
   return SiteConfiguration.getInstance(getDefaultConfiguration());
 }