Package org.apache.accumulo.core.client

Examples of org.apache.accumulo.core.client.Connector


   
  }
 
  @Test
  public void testUpdate() throws Exception {
    Connector c = new MockConnector("root", new MockInstance());
    c.tableOperations().create("test");
    BatchWriter bw = c.createBatchWriter("test", new BatchWriterConfig());
   
    for (int i = 0; i < 10; i++) {
      Mutation m = new Mutation("r1");
      m.put("cf1", "cq1", "" + i);
      bw.addMutation(m);
    }
   
    bw.close();
   
    Scanner scanner = c.createScanner("test", Constants.NO_AUTHS);
   
    Entry<Key,Value> entry = scanner.iterator().next();
   
    assertEquals("9", entry.getValue().toString());
   
View Full Code Here


  public int run(String[] args) throws Exception {
    ClientOpts opts = new ClientOpts();
    opts.parseArgs(LocalityCheck.class.getName(), args);
   
    FileSystem fs = FileSystem.get(CachedConfiguration.getInstance());
    Connector connector = opts.getConnector();
    Scanner scanner = connector.createScanner(Constants.METADATA_TABLE_NAME, Constants.NO_AUTHS);
    scanner.fetchColumnFamily(Constants.METADATA_CURRENT_LOCATION_COLUMN_FAMILY);
    scanner.fetchColumnFamily(Constants.METADATA_DATAFILE_COLUMN_FAMILY);
    scanner.setRange(Constants.METADATA_KEYSPACE);
   
    Map<String,Long> totalBlocks = new HashMap<String,Long>();
View Full Code Here

  }

  @Test
  public void test1() throws Exception {
    MockInstance instance = new MockInstance("rft1");
    Connector conn = instance.getConnector("", new PasswordToken(""));

    conn.tableOperations().create("table1");
    BatchWriter bw = conn.createBatchWriter("table1", new BatchWriterConfig());

    for (Mutation m : createMutations()) {
      bw.addMutation(m);
    }
    IteratorSetting is = new IteratorSetting(40, SummingRowFilter.class);
    conn.tableOperations().attachIterator("table1", is);

    Scanner scanner = conn.createScanner("table1", Constants.NO_AUTHS);
    assertEquals(new HashSet<String>(Arrays.asList("2", "3")), getRows(scanner));

    scanner.fetchColumn(new Text("cf1"), new Text("cq2"));
    assertEquals(new HashSet<String>(Arrays.asList("1", "3")), getRows(scanner));
View Full Code Here

  }

  @Test
  public void testChainedRowFilters() throws Exception {
    MockInstance instance = new MockInstance("rft1");
    Connector conn = instance.getConnector("", new PasswordToken(""));

    conn.tableOperations().create("chained_row_filters");
    BatchWriter bw = conn.createBatchWriter("chained_row_filters", new BatchWriterConfig());
    for (Mutation m : createMutations()) {
      bw.addMutation(m);
    }
    conn.tableOperations().attachIterator("chained_row_filters", new IteratorSetting(40, "trueFilter1", TrueFilter.class));
    conn.tableOperations().attachIterator("chained_row_filters", new IteratorSetting(41, "trueFilter2", TrueFilter.class));
    Scanner scanner = conn.createScanner("chained_row_filters", Constants.NO_AUTHS);
    assertEquals(new HashSet<String>(Arrays.asList("0", "1", "2", "3", "4")), getRows(scanner));
  }
View Full Code Here

  }

  @Test
  public void testFilterConjunction() throws Exception {
    MockInstance instance = new MockInstance("rft1");
    Connector conn = instance.getConnector("", new PasswordToken(""));

    conn.tableOperations().create("filter_conjunction");
    BatchWriter bw = conn.createBatchWriter("filter_conjunction", new BatchWriterConfig());
    for (Mutation m : createMutations()) {
      bw.addMutation(m);
    }
    conn.tableOperations().attachIterator("filter_conjunction", new IteratorSetting(40, "rowZeroOrOne", RowZeroOrOneFilter.class));
    conn.tableOperations().attachIterator("filter_conjunction", new IteratorSetting(41, "rowOneOrTwo", RowOneOrTwoFilter.class));
    Scanner scanner = conn.createScanner("filter_conjunction", Constants.NO_AUTHS);
    assertEquals(new HashSet<String>(Arrays.asList("1")), getRows(scanner));
  }
View Full Code Here

  public void start(String[] args) throws MergeException {
    Opts opts = new Opts();
    opts.parseArgs(Merge.class.getCanonicalName(), args);
   
    try {
      Connector conn = opts.getConnector();
     
      if (!conn.tableOperations().exists(opts.tableName)) {
        System.err.println("table " + opts.tableName + " does not exist");
        return;
      }
      if (opts.goalSize == null || opts.goalSize < 1) {
        AccumuloConfiguration tableConfig = new ConfigurationCopy(conn.tableOperations().getProperties(opts.tableName));
        opts.goalSize = tableConfig.getMemoryInBytes(Property.TABLE_SPLIT_THRESHOLD);
      }
     
      message("Merging tablets in table %s to %d bytes", opts.tableName, opts.goalSize);
      mergomatic(conn, opts.tableName, opts.begin, opts.end, opts.goalSize, opts.force);
View Full Code Here

  public void checkOutputSpecs(JobContext job) throws IOException {
    if (!isConnectorInfoSet(job))
      throw new IOException("Connector info has not been set.");
    try {
      // if the instance isn't configured, it will complain here
      Connector c = getInstance(job).getConnector(getPrincipal(job), CredentialHelper.extractToken(getTokenClass(job), getToken(job)));
      if (!c.securityOperations().authenticateUser(getPrincipal(job), CredentialHelper.extractToken(getTokenClass(job), getToken(job))))
        throw new IOException("Unable to authenticate user");
    } catch (AccumuloException e) {
      throw new IOException(e);
    } catch (AccumuloSecurityException e) {
      throw new IOException(e);
View Full Code Here

        columns = getFetchedColumns(job);
      }

      try {
        log.debug("Creating connector with user: " + principal);
        Connector conn = instance.getConnector(principal, token);
        log.debug("Creating scanner for table: " + table);
        log.debug("Authorizations are: " + authorizations);
        if (isOffline) {
          String tokenClass = token.getClass().getCanonicalName();
          ByteBuffer tokenBuffer = ByteBuffer.wrap(CredentialHelper.toBytes(token));
          scanner = new OfflineScanner(instance, new TCredentials(principal, tokenClass, tokenBuffer, instance.getInstanceID()), Tables.getTableId(instance,
              table), authorizations);
        } else {
          scanner = conn.createScanner(table, authorizations);
        }
        if (isIsolated) {
          log.info("Creating isolated scanner");
          scanner = new IsolatedScanner(scanner);
        }
View Full Code Here

 
  protected Connector getConnector(ByteBuffer login) throws Exception {
    TCredentials user = CredentialHelper.fromByteArray(ByteBufferUtil.toBytes(login));
    if (user == null)
      throw new org.apache.accumulo.proxy.thrift.AccumuloSecurityException("unknown user");
    Connector connector = instance.getConnector(user.getPrincipal(), CredentialHelper.extractToken(user));
    return connector;
  }
View Full Code Here

  @Override
  public ByteBuffer getMaxRow(ByteBuffer login, String tableName, Set<ByteBuffer> auths, ByteBuffer startRow, boolean startInclusive, ByteBuffer endRow,
      boolean endInclusive) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException,
      org.apache.accumulo.proxy.thrift.TableNotFoundException, TException {
    try {
      Connector connector = getConnector(login);
      Text startText = ByteBufferUtil.toText(startRow);
      Text endText = ByteBufferUtil.toText(endRow);
      Authorizations auth;
      if (auths != null) {
        auth = getAuthorizations(auths);
      } else {
        auth = connector.securityOperations().getUserAuthorizations(connector.whoami());
      }
      Text max = connector.tableOperations().getMaxRow(tableName, auth, startText, startInclusive, endText, endInclusive);
      return TextUtil.getByteBuffer(max);
    } catch (Exception e) {
      handleExceptionTNF(e);
      return null;
    }
View Full Code Here

TOP

Related Classes of org.apache.accumulo.core.client.Connector

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.