org.apache.accumulo.core.client.AccumuloClient Java Examples

The following examples show how to use org.apache.accumulo.core.client.AccumuloClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CopyPlus5K.java    From accumulo-examples with Apache License 2.0 6 votes vote down vote up
private static void cleanupAndCreateTables(Properties props) throws Exception {
  FileSystem hdfs = FileSystem.get(new Configuration());
  if (hdfs.exists(rootPath)) {
    hdfs.delete(rootPath, true);
  }
  try (AccumuloClient client = Accumulo.newClient().from(props).build()) {
    if (client.tableOperations().exists(inputTable)) {
      client.tableOperations().delete(inputTable);
    }
    if (client.tableOperations().exists(outputTable)) {
      client.tableOperations().delete(outputTable);
    }
    // Create tables
    client.tableOperations().create(inputTable);
    client.tableOperations().create(outputTable);

    // Write data to input table
    try (BatchWriter bw = client.createBatchWriter(inputTable)) {
      for (int i = 0; i < 100; i++) {
        Mutation m = new Mutation(String.format("%03d", i));
        m.at().family("cf1").qualifier("cq1").put("" + i);
        bw.addMutation(m);
      }
    }
  }
}
 
Example #2
Source File: FileDataIngest.java    From accumulo-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  Opts opts = new Opts();
  BatchWriterOpts bwOpts = new BatchWriterOpts();
  opts.parseArgs(FileDataIngest.class.getName(), args, bwOpts);

  try (AccumuloClient client = opts.createAccumuloClient()) {
    if (!client.tableOperations().exists(opts.getTableName())) {
      client.tableOperations().create(opts.getTableName());
      client.tableOperations().attachIterator(opts.getTableName(),
          new IteratorSetting(1, ChunkCombiner.class));
    }
    try (BatchWriter bw = client.createBatchWriter(opts.getTableName(),
        bwOpts.getBatchWriterConfig())) {
      FileDataIngest fdi = new FileDataIngest(opts.chunkSize, opts.visibility);
      for (String filename : opts.files) {
        fdi.insertFileData(filename, bw);
      }
    }
  }
}
 
Example #3
Source File: BloomFiltersNotFound.java    From accumulo-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args)
    throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
  ClientOpts opts = new ClientOpts();
  opts.parseArgs(BloomFiltersNotFound.class.getName(), args);

  try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build()) {
    try {
      client.tableOperations().create("bloom_test3");
      client.tableOperations().create("bloom_test4");
      client.tableOperations().setProperty("bloom_test4", "table.bloom.enabled", "true");
    } catch (TableExistsException e) {
      // ignore
    }
    System.out.println("Writing data to bloom_test3 and bloom_test4 (bloom filters enabled)");
    writeData(client, "bloom_test3", 7);
    client.tableOperations().flush("bloom_test3", null, null, true);
    writeData(client, "bloom_test4", 7);
    client.tableOperations().flush("bloom_test4", null, null, true);

    BloomBatchScanner.scan(client, "bloom_test3", 8);
    BloomBatchScanner.scan(client, "bloom_test4", 8);
  }
}
 
Example #4
Source File: ScanUtil.java    From fluo with Apache License 2.0 6 votes vote down vote up
public static void scanNotifications(ScanOpts options, FluoConfiguration sConfig, PrintStream out)
    throws IOException {

  AccumuloClient client = AccumuloUtil.getClient(sConfig);

  Span span = getSpan(options);
  Collection<Column> columns = getColumns(options);

  try (Scanner scanner = client.createScanner(sConfig.getAccumuloTable(), Authorizations.EMPTY)) {
    scanner.setRange(SpanUtil.toRange(span));

    NotificationScanner ntfyScanner = new NotificationScanner(scanner, columns);

    scan(options, out, ntfyScanner);
  } catch (TableNotFoundException e) {
    throw new RuntimeException(e);
  }
}
 
Example #5
Source File: Query.java    From accumulo-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  QueryOpts opts = new QueryOpts();
  opts.parseArgs(Query.class.getName(), args);

  try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build();
      BatchScanner bs = client.createBatchScanner(opts.tableName, Authorizations.EMPTY, 10)) {
    if (opts.useSample) {
      SamplerConfiguration samplerConfig = client.tableOperations()
          .getSamplerConfiguration(opts.tableName);
      CutoffIntersectingIterator.validateSamplerConfig(
          client.tableOperations().getSamplerConfiguration(opts.tableName));
      bs.setSamplerConfiguration(samplerConfig);
    }
    for (String entry : query(bs, opts.terms, opts.sampleCutoff)) {
      System.out.println("  " + entry);
    }
  }
}
 
Example #6
Source File: ScanUtil.java    From fluo with Apache License 2.0 6 votes vote down vote up
public static void scanAccumulo(ScanOpts options, FluoConfiguration sConfig, PrintStream out) {

    Span span = getSpan(options);
    Collection<Column> columns = getColumns(options);

    try (AccumuloClient client = AccumuloUtil.getClient(sConfig);
        Scanner scanner = client.createScanner(sConfig.getAccumuloTable(), Authorizations.EMPTY)) {

      scanner.setRange(SpanUtil.toRange(span));
      for (Column col : columns) {
        if (col.isQualifierSet()) {
          scanner.fetchColumn(ByteUtil.toText(col.getFamily()),
              ByteUtil.toText(col.getQualifier()));
        } else {
          scanner.fetchColumnFamily(ByteUtil.toText(col.getFamily()));
        }
      }

      for (String entry : Iterables.transform(scanner, FluoFormatter::toString)) {
        out.println(entry);
      }
      out.flush();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
 
Example #7
Source File: BloomFilters.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args)
    throws AccumuloException, AccumuloSecurityException, TableNotFoundException {

  ClientOpts opts = new ClientOpts();
  opts.parseArgs(BloomFilters.class.getName(), args);

  try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build()) {
    try {
      System.out.println("Creating bloom_test1 and bloom_test2");
      client.tableOperations().create("bloom_test1");
      client.tableOperations().setProperty("bloom_test1", "table.compaction.major.ratio", "7");
      client.tableOperations().create("bloom_test2");
      client.tableOperations().setProperty("bloom_test2", "table.bloom.enabled", "true");
      client.tableOperations().setProperty("bloom_test2", "table.compaction.major.ratio", "7");
    } catch (TableExistsException e) {
      // ignore
    }

    // Write a million rows 3 times flushing files to disk separately
    System.out.println("Writing data to bloom_test1");
    writeData(client, "bloom_test1", 7);
    client.tableOperations().flush("bloom_test1", null, null, true);
    writeData(client, "bloom_test1", 8);
    client.tableOperations().flush("bloom_test1", null, null, true);
    writeData(client, "bloom_test1", 9);
    client.tableOperations().flush("bloom_test1", null, null, true);

    System.out.println("Writing data to bloom_test2");
    writeData(client, "bloom_test2", 7);
    client.tableOperations().flush("bloom_test2", null, null, true);
    writeData(client, "bloom_test2", 8);
    client.tableOperations().flush("bloom_test2", null, null, true);
    writeData(client, "bloom_test2", 9);
    client.tableOperations().flush("bloom_test2", null, null, true);
  }
}
 
Example #8
Source File: FluoAdminImplIT.java    From fluo with Apache License 2.0 5 votes vote down vote up
@Test
public void testInitializeConfig() throws Exception {

  // stop oracle to avoid spurious exceptions when initializing
  oserver.stop();

  FluoConfiguration localConfig = new FluoConfiguration(config);
  localConfig.setProperty("fluo.test123", "${fluo.connection.application.name}");
  Assert.assertEquals(localConfig.getApplicationName(), localConfig.getString("fluo.test123"));

  try (FluoAdmin admin = new FluoAdminImpl(localConfig)) {

    InitializationOptions opts =
        new InitializationOptions().setClearZookeeper(true).setClearTable(true);
    admin.initialize(opts);

    // verify locality groups were set on the table
    try (AccumuloClient client = AccumuloUtil.getClient(config)) {
      Map<String, Set<Text>> localityGroups =
          client.tableOperations().getLocalityGroups(config.getAccumuloTable());
      Assert.assertEquals("Unexpected locality group count.", 1, localityGroups.size());
      Entry<String, Set<Text>> localityGroup = localityGroups.entrySet().iterator().next();
      Assert.assertEquals("'notify' locality group not found.",
          ColumnConstants.NOTIFY_LOCALITY_GROUP_NAME, localityGroup.getKey());
      Assert.assertEquals("'notify' locality group does not contain exactly 1 column family.", 1,
          localityGroup.getValue().size());
      Text colFam = localityGroup.getValue().iterator().next();
      Assert.assertTrue("'notify' locality group does not contain the correct column family.",
          ColumnConstants.NOTIFY_CF.contentEquals(colFam.getBytes(), 0, colFam.getLength()));
    }
  }

  try (FluoClientImpl client = new FluoClientImpl(localConfig)) {
    FluoConfiguration sharedConfig = client.getSharedConfiguration();
    Assert.assertEquals(localConfig.getApplicationName(), sharedConfig.getString("fluo.test123"));
    Assert.assertEquals(localConfig.getApplicationName(), sharedConfig.getApplicationName());
  }
}
 
Example #9
Source File: BloomFilters.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
static void writeData(AccumuloClient client, String tableName, int seed)
    throws TableNotFoundException, MutationsRejectedException {
  Random r = new Random(seed);
  try (BatchWriter bw = client.createBatchWriter(tableName)) {
    for (int x = 0; x < 1_000_000; x++) {
      long rowId = RandomBatchWriter.abs(r.nextLong()) % 1_000_000_000;
      Mutation m = RandomBatchWriter.createMutation(rowId, 50, new ColumnVisibility());
      bw.addMutation(m);
    }
  }
}
 
Example #10
Source File: ContinuousQuery.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  Opts opts = new Opts();
  opts.parseArgs(ContinuousQuery.class.getName(), args);

  try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build()) {

    ArrayList<Text[]> randTerms = findRandomTerms(
        client.createScanner(opts.doc2Term, Authorizations.EMPTY), opts.numTerms);

    Random rand = new Random();

    try (BatchScanner bs = client.createBatchScanner(opts.tableName, Authorizations.EMPTY, 5)) {
      for (long i = 0; i < opts.iterations; i += 1) {
        Text[] columns = randTerms.get(rand.nextInt(randTerms.size()));

        bs.clearScanIterators();
        bs.clearColumns();

        IteratorSetting ii = new IteratorSetting(20, "ii", IntersectingIterator.class);
        IntersectingIterator.setColumnFamilies(ii, columns);
        bs.addScanIterator(ii);
        bs.setRanges(Collections.singleton(new Range()));

        long t1 = System.currentTimeMillis();
        int count = Iterators.size(bs.iterator());
        long t2 = System.currentTimeMillis();

        System.out.printf("  %s %,d %6.3f%n", Arrays.asList(columns), count, (t2 - t1) / 1000.0);
      }
    }
  }
}
 
Example #11
Source File: Index.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  IndexOpts opts = new IndexOpts();
  opts.parseArgs(Index.class.getName(), args);

  String splitRegex = "\\W+";

  try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build();
      BatchWriter bw = client.createBatchWriter(opts.tableName)) {
    for (String filename : opts.files) {
      index(opts.partitions, new File(filename), splitRegex, bw);
    }
  }
}
 
Example #12
Source File: Reverse.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  Opts opts = new Opts();
  opts.parseArgs(Reverse.class.getName(), args);

  try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build();
      Scanner scanner = client.createScanner(opts.shardTable, Authorizations.EMPTY);
      BatchWriter bw = client.createBatchWriter(opts.doc2TermTable)) {
    for (Entry<Key,Value> entry : scanner) {
      Key key = entry.getKey();
      Mutation m = new Mutation(key.getColumnQualifier());
      m.put(key.getColumnFamily(), new Text(), new Value(new byte[0]));
      bw.addMutation(m);
    }
  }
}
 
Example #13
Source File: FluoAdminImpl.java    From fluo with Apache License 2.0 5 votes vote down vote up
public boolean accumuloTableExists() {
  if (!config.hasRequiredAdminProps()) {
    throw new IllegalArgumentException("Admin configuration is missing required properties");
  }
  try (AccumuloClient client = AccumuloUtil.getClient(config)) {
    return client.tableOperations().exists(config.getAccumuloTable());
  }
}
 
Example #14
Source File: WordCount.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  Opts opts = new Opts();
  opts.parseArgs(WordCount.class.getName(), args);

  // Create Accumulo table and attach Summing iterator
  try (AccumuloClient client = opts.createAccumuloClient()) {
    client.tableOperations().create(opts.tableName);
    IteratorSetting is = new IteratorSetting(10, SummingCombiner.class);
    SummingCombiner.setColumns(is,
        Collections.singletonList(new IteratorSetting.Column("count")));
    SummingCombiner.setEncodingType(is, SummingCombiner.Type.STRING);
    client.tableOperations().attachIterator(opts.tableName, is);
  } catch (TableExistsException e) {
    // ignore
  }

  // Create M/R job
  Job job = Job.getInstance(opts.getHadoopConfig());
  job.setJobName(WordCount.class.getName());
  job.setJarByClass(WordCount.class);
  job.setInputFormatClass(TextInputFormat.class);
  TextInputFormat.setInputPaths(job, new Path(opts.inputDirectory));

  job.setMapperClass(MapClass.class);
  job.setNumReduceTasks(0);
  job.setOutputFormatClass(AccumuloOutputFormat.class);
  job.setOutputKeyClass(Text.class);
  job.setOutputValueClass(Mutation.class);

  if (opts.hdfsPath != null) {
    AccumuloOutputFormat.configure().clientPropertiesPath(opts.hdfsPath)
        .defaultTable(opts.tableName).store(job);
  } else {
    AccumuloOutputFormat.configure().clientProperties(opts.getClientProperties())
        .defaultTable(opts.tableName).store(job);
  }
  System.exit(job.waitForCompletion(true) ? 0 : 1);
}
 
Example #15
Source File: SetupTable.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  ClientOpts opts = new ClientOpts();
  opts.parseArgs(SetupTable.class.getName(), args);

  try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build()) {
    try {
      client.tableOperations().create(tableName);
    } catch (TableExistsException e) {
      // ignore
    }

    // create a table with initial partitions
    TreeSet<Text> intialPartitions = new TreeSet<>();
    for (String split : splits) {
      intialPartitions.add(new Text(split));
    }
    client.tableOperations().addSplits(tableName, intialPartitions);

    FileSystem fs = FileSystem.get(new Configuration());
    try (PrintStream out = new PrintStream(
        new BufferedOutputStream(fs.create(new Path(outputFile))))) {
      // create some data in outputFile
      for (int i = 0; i < numRows; i++) {
        out.println(String.format("row_%010d\tvalue_%010d", i, i));
      }
    }
  }
}
 
Example #16
Source File: FluoAdminImpl.java    From fluo with Apache License 2.0 5 votes vote down vote up
private void initializeApplicationInZooKeeper(AccumuloClient client) throws Exception {

    final String accumuloInstanceName =
        client.properties().getProperty(AccumuloProps.CLIENT_INSTANCE_NAME);
    final String accumuloInstanceID = client.instanceOperations().getInstanceID();
    final String fluoApplicationID = UUID.randomUUID().toString();

    // Create node specified by chroot suffix of Zookeeper connection string (if it doesn't exist)
    CuratorUtil.putData(rootCurator, appRootDir, new byte[0], CuratorUtil.NodeExistsPolicy.FAIL);

    // Retrieve Fluo curator now that chroot has been created
    CuratorFramework curator = getAppCurator();

    // Initialize Zookeeper & Accumulo for this Fluo instance
    // TODO set Fluo data version
    CuratorUtil.putData(curator, ZookeeperPath.CONFIG, new byte[0],
        CuratorUtil.NodeExistsPolicy.FAIL);
    CuratorUtil.putData(curator, ZookeeperPath.CONFIG_ACCUMULO_TABLE,
        config.getAccumuloTable().getBytes(StandardCharsets.UTF_8),
        CuratorUtil.NodeExistsPolicy.FAIL);
    CuratorUtil.putData(curator, ZookeeperPath.CONFIG_ACCUMULO_INSTANCE_NAME,
        accumuloInstanceName.getBytes(StandardCharsets.UTF_8), CuratorUtil.NodeExistsPolicy.FAIL);
    CuratorUtil.putData(curator, ZookeeperPath.CONFIG_ACCUMULO_INSTANCE_ID,
        accumuloInstanceID.getBytes(StandardCharsets.UTF_8), CuratorUtil.NodeExistsPolicy.FAIL);
    CuratorUtil.putData(curator, ZookeeperPath.CONFIG_FLUO_APPLICATION_ID,
        fluoApplicationID.getBytes(StandardCharsets.UTF_8), CuratorUtil.NodeExistsPolicy.FAIL);
    CuratorUtil.putData(curator, ZookeeperPath.ORACLE_SERVER, new byte[0],
        CuratorUtil.NodeExistsPolicy.FAIL);
    CuratorUtil.putData(curator, ZookeeperPath.ORACLE_MAX_TIMESTAMP, new byte[] {'2'},
        CuratorUtil.NodeExistsPolicy.FAIL);
    CuratorUtil.putData(curator, ZookeeperPath.ORACLE_GC_TIMESTAMP, new byte[] {'0'},
        CuratorUtil.NodeExistsPolicy.FAIL);
  }
 
Example #17
Source File: FluoAdminImpl.java    From fluo with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(InitializationOptions opts)
    throws AlreadyInitializedException, TableExistsException {
  if (!config.hasRequiredAdminProps()) {
    throw new IllegalArgumentException("Admin configuration is missing required properties");
  }
  Preconditions.checkArgument(
      !ZookeeperUtil.parseRoot(config.getInstanceZookeepers()).equals("/"),
      "The Zookeeper connection string (set by 'fluo.connection.zookeepers') "
          + " must have a chroot suffix.");

  Preconditions.checkArgument(
      config.getObserverJarsUrl().isEmpty() || config.getObserverInitDir().isEmpty(),
      "Only one of 'fluo.observer.init.dir' and 'fluo.observer.jars.url' can be set");
  if (applicationRunning()) {
    throw new AlreadyInitializedException("Error - The Fluo '" + config.getApplicationName()
        + "' application" + " is already running and must be stopped before initializing. "
        + " Aborted initialization.");
  }
  if (zookeeperInitialized() && !opts.getClearZookeeper()) {
    throw new AlreadyInitializedException(
        "Fluo application already initialized at " + config.getAppZookeepers());
  }

  try (AccumuloClient client = AccumuloUtil.getClient(config)) {
    initialize(opts, client);
  }
}
 
Example #18
Source File: NGramIngest.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  Opts opts = new Opts();
  opts.parseArgs(NGramIngest.class.getName(), args);

  Job job = Job.getInstance(opts.getHadoopConfig());
  job.setJobName(NGramIngest.class.getSimpleName());
  job.setJarByClass(NGramIngest.class);

  job.setInputFormatClass(TextInputFormat.class);
  job.setOutputFormatClass(AccumuloOutputFormat.class);
  AccumuloOutputFormat.configure().clientProperties(opts.getClientProperties())
      .defaultTable(opts.tableName).store(job);

  job.setMapperClass(NGramMapper.class);
  job.setMapOutputKeyClass(Text.class);
  job.setMapOutputValueClass(Mutation.class);

  job.setNumReduceTasks(0);
  job.setSpeculativeExecution(false);

  try (AccumuloClient client = opts.createAccumuloClient()) {
    if (!client.tableOperations().exists(opts.tableName)) {
      log.info("Creating table " + opts.tableName);
      client.tableOperations().create(opts.tableName);
      SortedSet<Text> splits = new TreeSet<>();
      String numbers[] = "1 2 3 4 5 6 7 8 9".split("\\s");
      String lower[] = "a b c d e f g h i j k l m n o p q r s t u v w x y z".split("\\s");
      String upper[] = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z".split("\\s");
      for (String[] array : new String[][] {numbers, lower, upper}) {
        for (String s : array) {
          splits.add(new Text(s));
        }
      }
      client.tableOperations().addSplits(opts.tableName, splits);
    }
  }

  TextInputFormat.addInputPath(job, new Path(opts.inputDirectory));
  System.exit(job.waitForCompletion(true) ? 0 : 1);
}
 
Example #19
Source File: InterferenceTest.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  Opts opts = new Opts();
  BatchWriterOpts bwOpts = new BatchWriterOpts();
  opts.parseArgs(InterferenceTest.class.getName(), args, bwOpts);

  if (opts.iterations < 1)
    opts.iterations = Long.MAX_VALUE;

  try (AccumuloClient client = opts.createAccumuloClient()) {
    if (!client.tableOperations().exists(opts.getTableName()))
      client.tableOperations().create(opts.getTableName());

    Thread writer = new Thread(
        new Writer(client.createBatchWriter(opts.getTableName(), bwOpts.getBatchWriterConfig()),
            opts.iterations));
    writer.start();
    Reader r;
    if (opts.isolated)
      r = new Reader(new IsolatedScanner(client.createScanner(opts.getTableName(), opts.auths)));
    else
      r = new Reader(client.createScanner(opts.getTableName(), opts.auths));
    Thread reader;
    reader = new Thread(r);
    reader.start();
    writer.join();
    r.stopNow();
    reader.join();
    System.out.println("finished");
  }
}
 
Example #20
Source File: BloomBatchScanner.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws TableNotFoundException {
  ClientOpts opts = new ClientOpts();
  opts.parseArgs(BloomBatchScanner.class.getName(), args);

  try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build()) {
    scan(client, "bloom_test1", 7);
    scan(client, "bloom_test2", 7);
  }
}
 
Example #21
Source File: TracingExample.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
  Opts opts = new Opts();
  ScannerOpts scannerOpts = new ScannerOpts();
  opts.parseArgs(TracingExample.class.getName(), args, scannerOpts);

  try (AccumuloClient client = opts.createAccumuloClient()) {
    TracingExample tracingExample = new TracingExample(client);
    tracingExample.enableTracing();
    tracingExample.execute(opts);
  } catch (Exception e) {
    log.error("Caught exception running TraceExample", e);
    System.exit(1);
  }
}
 
Example #22
Source File: Flush.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args)
    throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
  ClientOnRequiredTable opts = new ClientOnRequiredTable();
  opts.parseArgs(Flush.class.getName(), args);
  try (AccumuloClient client = opts.createAccumuloClient()) {
    client.tableOperations().flush(opts.getTableName(), null, null, true);
  }
}
 
Example #23
Source File: RowOperations.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
private static void deleteRow(String row, AccumuloClient client, BatchWriter bw)
    throws MutationsRejectedException, TableNotFoundException {
  Mutation mut = new Mutation(row);
  try (Scanner scanner = client.createScanner(table, Authorizations.EMPTY)) {
    scanner.setRange(Range.exact(row));
    for (Entry<Key,Value> entry : scanner) {
      mut.putDelete(entry.getKey().getColumnFamily(), entry.getKey().getColumnQualifier());
    }
  }
  bw.addMutation(mut);
  bw.flush();
}
 
Example #24
Source File: RowOperations.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
private static void printRow(String row, AccumuloClient client) throws TableNotFoundException {
  try (Scanner scanner = client.createScanner(table, Authorizations.EMPTY)) {
    scanner.setRange(Range.exact(row));
    for (Entry<Key,Value> entry : scanner) {
      log.info("Key: " + entry.getKey().toString() + " Value: " + entry.getValue().toString());
    }
  }
}
 
Example #25
Source File: RowOperations.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
private static void printAll(AccumuloClient client) throws TableNotFoundException {
  try (Scanner scanner = client.createScanner(table, Authorizations.EMPTY)) {
    for (Entry<Key,Value> entry : scanner) {
      log.info("Key: " + entry.getKey().toString() + " Value: " + entry.getValue().toString());
    }
  }
}
 
Example #26
Source File: Ingest.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  Opts opts = new Opts();
  BatchWriterOpts bwOpts = new BatchWriterOpts();
  opts.parseArgs(Ingest.class.getName(), args, bwOpts);

  try (AccumuloClient client = opts.createAccumuloClient()) {
    if (!client.tableOperations().exists(opts.nameTable))
      client.tableOperations().create(opts.nameTable);
    if (!client.tableOperations().exists(opts.indexTable))
      client.tableOperations().create(opts.indexTable);
    if (!client.tableOperations().exists(opts.dataTable)) {
      client.tableOperations().create(opts.dataTable);
      client.tableOperations().attachIterator(opts.dataTable,
          new IteratorSetting(1, ChunkCombiner.class));
    }

    BatchWriter dirBW = client.createBatchWriter(opts.nameTable, bwOpts.getBatchWriterConfig());
    BatchWriter indexBW = client.createBatchWriter(opts.indexTable,
        bwOpts.getBatchWriterConfig());
    BatchWriter dataBW = client.createBatchWriter(opts.dataTable, bwOpts.getBatchWriterConfig());
    FileDataIngest fdi = new FileDataIngest(opts.chunkSize, opts.visibility);
    for (String dir : opts.directories) {
      recurse(new File(dir), opts.visibility, dirBW, indexBW, fdi, dataBW);

      // fill in parent directory info
      int slashIndex = -1;
      while ((slashIndex = dir.lastIndexOf("/")) > 0) {
        dir = dir.substring(0, slashIndex);
        ingest(new File(dir), opts.visibility, dirBW, indexBW, fdi, dataBW);
      }
    }
    ingest(new File("/"), opts.visibility, dirBW, indexBW, fdi, dataBW);

    dirBW.close();
    indexBW.close();
    dataBW.close();
  }
}
 
Example #27
Source File: FileCount.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  Opts opts = new Opts();
  ScannerOpts scanOpts = new ScannerOpts();
  BatchWriterOpts bwOpts = new BatchWriterOpts();
  String programName = FileCount.class.getName();
  opts.parseArgs(programName, args, scanOpts, bwOpts);

  try (AccumuloClient client = opts.createAccumuloClient()) {
    FileCount fileCount = new FileCount(client, opts.getTableName(), opts.auths, opts.visibility,
        scanOpts, bwOpts);
    fileCount.run();
  }
}
 
Example #28
Source File: FileCount.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
public FileCount(AccumuloClient client, String tableName, Authorizations auths,
    ColumnVisibility cv, ScannerOpts scanOpts, BatchWriterOpts bwOpts) throws Exception {
  this.client = client;
  this.tableName = tableName;
  this.auths = auths;
  this.visibility = cv;
  this.scanOpts = scanOpts;
  this.bwOpts = bwOpts;
}
 
Example #29
Source File: Viewer.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  Opts opts = new Opts();
  opts.parseArgs(Viewer.class.getName(), args);
  try (AccumuloClient client = opts.createAccumuloClient()) {
    Viewer v = new Viewer(client, opts);
    v.init();
    v.setVisible(true);
  }
}
 
Example #30
Source File: Viewer.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
public Viewer(AccumuloClient client, Opts opts) throws Exception {
  super("File Viewer");
  setSize(1000, 800);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  q = new QueryUtil(client, opts);
  fdq = new FileDataQuery(client, opts.dataTable, opts.auths);
  this.topPath = opts.path;
}