Package org.apache.hadoop.hbase.client

Examples of org.apache.hadoop.hbase.client.Admin


      return run(numMappers, numNodes, tmpOutput, width, wrapMuplitplier);
    }

    protected void createSchema() throws IOException {
      Configuration conf = getConf();
      Admin admin = new HBaseAdmin(conf);
      TableName tableName = getTableName(conf);
      try {
        if (!admin.tableExists(tableName)) {
          HTableDescriptor htd = new HTableDescriptor(getTableName(getConf()));
          htd.addFamily(new HColumnDescriptor(FAMILY_NAME));
          int numberOfServers = admin.getClusterStatus().getServers().size();
          if (numberOfServers == 0) {
            throw new IllegalStateException("No live regionservers");
          }
          int regionsPerServer = conf.getInt(HBaseTestingUtility.REGIONS_PER_SERVER_KEY,
                                HBaseTestingUtility.DEFAULT_REGIONS_PER_SERVER);
          int totalNumberOfRegions = numberOfServers * regionsPerServer;
          LOG.info("Number of live regionservers: " + numberOfServers + ", " +
              "pre-splitting table into " + totalNumberOfRegions + " regions " +
              "(default regions per server: " + regionsPerServer + ")");

          byte[][] splits = new RegionSplitter.UniformSplit().split(
              totalNumberOfRegions);

          admin.createTable(htd, splits);
        }
      } catch (MasterNotRunningException e) {
        LOG.error("Master not running", e);
        throw new IOException(e);
      } finally {
        admin.close();
      }
    }
View Full Code Here


    assertFalse("No table created yet", cp.wasCreateTableCalled());

    // create a table
    HTableDescriptor htd = new HTableDescriptor(TEST_TABLE);
    htd.addFamily(new HColumnDescriptor(TEST_FAMILY));
    Admin admin = UTIL.getHBaseAdmin();

    tableCreationLatch = new CountDownLatch(1);
    admin.createTable(htd);
    // preCreateTable can't bypass default action.
    assertTrue("Test table should be created", cp.wasCreateTableCalled());
    tableCreationLatch.await();
    assertTrue("Table pre create handler called.", cp
        .wasPreCreateTableHandlerCalled());
    assertTrue("Table create handler should be called.",
        cp.wasCreateTableHandlerCalled());

    tableCreationLatch = new CountDownLatch(1);
    admin.disableTable(TEST_TABLE);
    assertTrue(admin.isTableDisabled(TEST_TABLE));
    // preDisableTable can't bypass default action.
    assertTrue("Coprocessor should have been called on table disable",
      cp.wasDisableTableCalled());
    assertTrue("Disable table handler should be called.",
        cp.wasDisableTableHandlerCalled());

    // enable
    assertFalse(cp.wasEnableTableCalled());
    admin.enableTable(TEST_TABLE);
    assertTrue(admin.isTableEnabled(TEST_TABLE));
    // preEnableTable can't bypass default action.
    assertTrue("Coprocessor should have been called on table enable",
      cp.wasEnableTableCalled());
    assertTrue("Enable table handler should be called.",
        cp.wasEnableTableHandlerCalled());

    admin.disableTable(TEST_TABLE);
    assertTrue(admin.isTableDisabled(TEST_TABLE));

    // modify table
    htd.setMaxFileSize(512 * 1024 * 1024);
    modifyTableSync(admin, TEST_TABLE, htd);
    // preModifyTable can't bypass default action.
    assertTrue("Test table should have been modified",
      cp.wasModifyTableCalled());

    // add a column family
    admin.addColumn(TEST_TABLE, new HColumnDescriptor(TEST_FAMILY2));
    assertTrue("New column family shouldn't have been added to test table",
      cp.preAddColumnCalledOnly());

    // modify a column family
    HColumnDescriptor hcd1 = new HColumnDescriptor(TEST_FAMILY2);
    hcd1.setMaxVersions(25);
    admin.modifyColumn(TEST_TABLE, hcd1);
    assertTrue("Second column family should be modified",
      cp.preModifyColumnCalledOnly());

    // truncate table
    admin.truncateTable(TEST_TABLE, false);

    // delete table
    admin.disableTable(TEST_TABLE);
    assertTrue(admin.isTableDisabled(TEST_TABLE));
    admin.deleteTable(TEST_TABLE);
    assertFalse("Test table should have been deleted",
        admin.tableExists(TEST_TABLE));
    // preDeleteTable can't bypass default action.
    assertTrue("Coprocessor should have been called on table delete",
        cp.wasDeleteTableCalled());
    assertTrue("Delete table handler should be called.",
        cp.wasDeleteTableHandlerCalled());

    // turn off bypass, run the tests again
    cp.enableBypass(false);
    cp.resetStates();

    admin.createTable(htd);
    assertTrue("Test table should be created", cp.wasCreateTableCalled());
    tableCreationLatch.await();
    assertTrue("Table pre create handler called.", cp
        .wasPreCreateTableHandlerCalled());
    assertTrue("Table create handler should be called.",
        cp.wasCreateTableHandlerCalled());

    // disable
    assertFalse(cp.wasDisableTableCalled());
    assertFalse(cp.wasDisableTableHandlerCalled());
    admin.disableTable(TEST_TABLE);
    assertTrue(admin.isTableDisabled(TEST_TABLE));
    assertTrue("Coprocessor should have been called on table disable",
      cp.wasDisableTableCalled());
    assertTrue("Disable table handler should be called.",
        cp.wasDisableTableHandlerCalled());

    // modify table
    htd.setMaxFileSize(512 * 1024 * 1024);
    modifyTableSync(admin, TEST_TABLE, htd);
    assertTrue("Test table should have been modified",
        cp.wasModifyTableCalled());
    // add a column family
    admin.addColumn(TEST_TABLE, new HColumnDescriptor(TEST_FAMILY2));
    assertTrue("New column family should have been added to test table",
        cp.wasAddColumnCalled());
    assertTrue("Add column handler should be called.",
        cp.wasAddColumnHandlerCalled());

    // modify a column family
    HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY2);
    hcd.setMaxVersions(25);
    admin.modifyColumn(TEST_TABLE, hcd);
    assertTrue("Second column family should be modified",
        cp.wasModifyColumnCalled());
    assertTrue("Modify table handler should be called.",
        cp.wasModifyColumnHandlerCalled());

    // enable
    assertFalse(cp.wasEnableTableCalled());
    assertFalse(cp.wasEnableTableHandlerCalled());
    admin.enableTable(TEST_TABLE);
    assertTrue(admin.isTableEnabled(TEST_TABLE));
    assertTrue("Coprocessor should have been called on table enable",
        cp.wasEnableTableCalled());
    assertTrue("Enable table handler should be called.",
        cp.wasEnableTableHandlerCalled());

    // disable again
    admin.disableTable(TEST_TABLE);
    assertTrue(admin.isTableDisabled(TEST_TABLE));

    // delete column
    assertFalse("No column family deleted yet", cp.wasDeleteColumnCalled());
    assertFalse("Delete table column handler should not be called.",
        cp.wasDeleteColumnHandlerCalled());
    admin.deleteColumn(TEST_TABLE, TEST_FAMILY2);
    HTableDescriptor tableDesc = admin.getTableDescriptor(TEST_TABLE);
    assertNull("'"+Bytes.toString(TEST_FAMILY2)+"' should have been removed",
        tableDesc.getFamily(TEST_FAMILY2));
    assertTrue("Coprocessor should have been called on column delete",
        cp.wasDeleteColumnCalled());
    assertTrue("Delete table column handler should be called.",
        cp.wasDeleteColumnHandlerCalled());

    // delete table
    assertFalse("No table deleted yet", cp.wasDeleteTableCalled());
    assertFalse("Delete table handler should not be called.",
        cp.wasDeleteTableHandlerCalled());
    admin.deleteTable(TEST_TABLE);
    assertFalse("Test table should have been deleted",
        admin.tableExists(TEST_TABLE));
    assertTrue("Coprocessor should have been called on table delete",
        cp.wasDeleteTableCalled());
    assertTrue("Delete table handler should be called.",
        cp.wasDeleteTableHandlerCalled());
  }
View Full Code Here

  private void installSlowingCoproc() throws IOException, InterruptedException {
    int replicaCount = conf.getInt(NUM_REPLICA_COUNT_KEY, NUM_REPLICA_COUNT_DEFAULT);
    if (replicaCount == NUM_REPLICA_COUNT_DEFAULT) return;

    TableName t = getTablename();
    Admin admin = util.getHBaseAdmin();
    HTableDescriptor desc = admin.getTableDescriptor(t);
    desc.addCoprocessor(SlowMeCoproScanOperations.class.getName());
    HBaseTestingUtility.modifyTableSync(admin, desc);
  }
View Full Code Here

    conf.set(Constants.CUSTOM_FILTERS, "CustomFilter:" + CustomFilter.class.getName());
    TEST_UTIL.startMiniCluster();
    REST_TEST_UTIL.startServletContainer(conf);
    client = new Client(new Cluster().add("localhost",
      REST_TEST_UTIL.getServletPort()));
    Admin admin = TEST_UTIL.getHBaseAdmin();
    if (!admin.tableExists(TABLE)) {
    HTableDescriptor htd = new HTableDescriptor(TABLE);
    htd.addFamily(new HColumnDescriptor(CFA));
    htd.addFamily(new HColumnDescriptor(CFB));
    admin.createTable(htd);
    expectedRows1 = TestScannerResource.insertData(conf, TABLE, COLUMN_1, 1.0);
    expectedRows2 = TestScannerResource.insertData(conf, TABLE, COLUMN_2, 0.5);
    }
  }
View Full Code Here

    }
    return 0;
  }

  private int stopMaster() {
    Admin adm = null;
    try {
      Configuration conf = getConf();
      // Don't try more than once
      conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);
      adm = new HBaseAdmin(getConf());
    } catch (MasterNotRunningException e) {
      LOG.error("Master not running");
      return 1;
    } catch (ZooKeeperConnectionException e) {
      LOG.error("ZooKeeper not available");
      return 1;
    } catch (IOException e) {
      LOG.error("Got IOException: " +e.getMessage(), e);
      return 1;
    }
    try {
      adm.shutdown();
    } catch (Throwable t) {
      LOG.error("Failed to stop master", t);
      return 1;
    }
    return 0;
View Full Code Here

  private void runTest(final Class<? extends Test> cmd, TestOptions opts) throws IOException,
      InterruptedException, ClassNotFoundException {
    // Log the configuration we're going to run with. Uses JSON mapper because lazy. It'll do
    // the TestOptions introspection for us and dump the output in a readable format.
    LOG.info(cmd.getSimpleName() + " test run options=" + MAPPER.writeValueAsString(opts));
    Admin admin = null;
    try {
      admin = new HBaseAdmin(getConf());
      checkTable(admin, opts);
    } finally {
      if (admin != null) admin.close();
    }
    if (opts.nomapred) {
      doLocalClients(opts, getConf());
    } else {
      doMapReduce(opts, getConf());
View Full Code Here

            CellSetModel.class,
            RowModel.class);
    marshaller = context.createMarshaller();
    unmarshaller = context.createUnmarshaller();
    client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort()));
    Admin admin = TEST_UTIL.getHBaseAdmin();
    if (admin.tableExists(TABLE)) {
      return;
    }
    HTableDescriptor htd = new HTableDescriptor(TABLE);
    htd.addFamily(new HColumnDescriptor(CFA));
    htd.addFamily(new HColumnDescriptor(CFB));
    admin.createTable(htd);
  }
View Full Code Here

  public static void setUpBeforeClass() throws Exception {
    TEST_UTIL.startMiniCluster();
    REST_TEST_UTIL.startServletContainer(TEST_UTIL.getConfiguration());
    client = new Client(new Cluster().add("localhost",
      REST_TEST_UTIL.getServletPort()));
    Admin admin = TEST_UTIL.getHBaseAdmin();
    if (admin.tableExists(TABLE)) {
      return;
    }
    HTableDescriptor htd = new HTableDescriptor(TABLE);
    htd.addFamily(new HColumnDescriptor(CFA));
    admin.createTable(htd);
  }
View Full Code Here

    fam.setMaxVersions(3);
    fam.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
    table.addFamily(fam);
    fam = new HColumnDescriptor(noRepfamName);
    table.addFamily(fam);
    Admin admin1 = new HBaseAdmin(conf1);
    Admin admin2 = new HBaseAdmin(conf2);
    admin1.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
    admin2.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
    htable1 = new HTable(conf1, tableName);
    htable1.setWriteBufferSize(1024);
    htable2 = new HTable(conf2, tableName);
  }
View Full Code Here

  }

  private void createTableOnClusters(HTableDescriptor table) throws Exception {
    int numClusters = configurations.length;
    for (int i = 0; i < numClusters; i++) {
      Admin hbaseAdmin = null;
      try {
        hbaseAdmin = new HBaseAdmin(configurations[i]);
        hbaseAdmin.createTable(table);
      } finally {
        close(hbaseAdmin);
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.client.Admin

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.