Java Code Examples for org.apache.hadoop.hbase.client.Admin#createTable()

The following examples show how to use org.apache.hadoop.hbase.client.Admin#createTable() . 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: TestTableDescriptorModificationFromClient.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteColumn() throws IOException {
  Admin admin = TEST_UTIL.getAdmin();
  // Create a table with two families
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(TABLE_NAME);

  tableDescriptor.setColumnFamily(
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(FAMILY_0));
  tableDescriptor.setColumnFamily(
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(FAMILY_1));
  admin.createTable(tableDescriptor);
  admin.disableTable(TABLE_NAME);
  try {
    // Verify the table descriptor
    verifyTableDescriptor(TABLE_NAME, FAMILY_0, FAMILY_1);

    // Modify the table removing one family and verify the descriptor
    admin.deleteColumnFamily(TABLE_NAME, FAMILY_1);
    verifyTableDescriptor(TABLE_NAME, FAMILY_0);
  } finally {
    admin.deleteTable(TABLE_NAME);
  }
}
 
Example 2
Source File: HBaseNotificationStoreIntegrationTest.java    From streamline with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUpClass() throws IOException {
    connection = ConnectionFactory.createConnection();
    Admin admin = connection.getAdmin();

    for (Map.Entry<String, List<String>> tableInfo : tableToCfs.entrySet()) {
        TableName tableName = TableName.valueOf(tableInfo.getKey());
        if (!admin.tableExists(tableName)) {
            // table not found, creating
            HTableDescriptor tableDescriptor = new HTableDescriptor(tableName);
            for (String columnFamily : tableInfo.getValue()) {
                tableDescriptor.addFamily(new HColumnDescriptor(columnFamily));
            }
            admin.createTable(tableDescriptor);
        }
    }
}
 
Example 3
Source File: HelloHBase.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Invokes Admin#createNamespace and Admin#createTable to create a namespace
 * with a table that has one column-family.
 *
 * @param admin Standard Admin object
 * @throws IOException If IO problem encountered
 */
static void createNamespaceAndTable(final Admin admin) throws IOException {

  if (!namespaceExists(admin, MY_NAMESPACE_NAME)) {
    System.out.println("Creating Namespace [" + MY_NAMESPACE_NAME + "].");

    admin.createNamespace(NamespaceDescriptor
            .create(MY_NAMESPACE_NAME).build());
  }
  if (!admin.tableExists(MY_TABLE_NAME)) {
    System.out.println("Creating Table [" + MY_TABLE_NAME.getNameAsString()
            + "], with one Column Family ["
            + Bytes.toString(MY_COLUMN_FAMILY_NAME) + "].");

    admin.createTable(new TableDescriptorBuilder.ModifyableTableDescriptor(MY_TABLE_NAME)
      .setColumnFamily(
        new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(
          MY_COLUMN_FAMILY_NAME)));
  }
}
 
Example 4
Source File: HelloWorldTest.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void beforeClass() {
  projectId = requireEnv("GOOGLE_CLOUD_PROJECT");
  instanceId = requireEnv(INSTANCE_ENV);
  try (Connection connection = BigtableConfiguration.connect(projectId, instanceId)) {
    Admin admin = connection.getAdmin();
    HTableDescriptor descriptor = new HTableDescriptor(TableName.valueOf(TABLE_ID));
    descriptor.addFamily(new HColumnDescriptor(COLUMN_FAMILY_NAME));
    admin.createTable(descriptor);

    Table table = connection.getTable(TableName.valueOf(Bytes.toBytes(TABLE_ID)));

    String rowKey = "phone#4c410523#20190401";
    Put put = new Put(Bytes.toBytes(rowKey));

    put.addColumn(
        Bytes.toBytes(COLUMN_FAMILY_NAME), Bytes.toBytes("os_name"), Bytes.toBytes("android"));
    table.put(put);

  } catch (Exception e) {
    System.out.println("Error during beforeClass: \n" + e.toString());
  }
}
 
Example 5
Source File: SecureTestUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
public static void createTable(HBaseTestingUtility testUtil, Admin admin, TableDescriptor htd,
    byte[][] splitKeys) throws Exception {
  // NOTE: We need a latch because admin is not sync,
  // so the postOp coprocessor method may be called after the admin operation returned.
  MasterSyncObserver observer = testUtil.getHBaseCluster().getMaster()
    .getMasterCoprocessorHost().findCoprocessor(MasterSyncObserver.class);
  observer.tableCreationLatch = new CountDownLatch(1);
  if (splitKeys != null) {
    admin.createTable(htd, splitKeys);
  } else {
    admin.createTable(htd);
  }
  observer.tableCreationLatch.await();
  observer.tableCreationLatch = null;
  testUtil.waitUntilAllRegionsAssigned(htd.getTableName());
}
 
Example 6
Source File: IntegrationTestBigLinkedListWithVisibility.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void createTable(Admin admin, TableName tableName, boolean setVersion,
    boolean acl) throws IOException {
  if (!admin.tableExists(tableName)) {
    TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
      new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);
    ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
      new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(FAMILY_NAME);
    if (setVersion) {
      familyDescriptor.setMaxVersions(DEFAULT_TABLES_COUNT);
    }
    tableDescriptor.setColumnFamily(familyDescriptor);
    admin.createTable(tableDescriptor);
    if (acl) {
      LOG.info("Granting permissions for user " + USER.getShortName());
      Permission.Action[] actions = { Permission.Action.READ };
      try {
        AccessControlClient.grant(ConnectionFactory.createConnection(getConf()), tableName,
            USER.getShortName(), null, null, actions);
      } catch (Throwable e) {
        LOG.error(HBaseMarkers.FATAL, "Error in granting permission for the user " +
            USER.getShortName(), e);
        throw new IOException(e);
      }
    }
  }
}
 
Example 7
Source File: TestClassLoading.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
// HBASE-3516: Test CP Class loading from local file system
public void testClassLoadingFromLocalFS() throws Exception {
  File jarFile = buildCoprocessorJar(cpName3);

  // create a table that references the jar
  TableDescriptorBuilder tdb = TableDescriptorBuilder.newBuilder(TableName.valueOf(cpName3));
  tdb.setColumnFamily(ColumnFamilyDescriptorBuilder
    .newBuilder(Bytes.toBytes("test")).build());
  tdb.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName3 + "|" +
    Coprocessor.PRIORITY_USER);
  TableDescriptor tableDescriptor = tdb.build();
  Admin admin = TEST_UTIL.getAdmin();
  admin.createTable(tableDescriptor);
  waitForTable(tableDescriptor.getTableName());

  // verify that the coprocessor was loaded
  boolean found = false;
  MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster();
  for (HRegion region: hbase.getRegionServer(0).getOnlineRegionsLocalContext()) {
    if (region.getRegionInfo().getRegionNameAsString().startsWith(cpName3)) {
      found = (region.getCoprocessorHost().findCoprocessor(cpName3) != null);
    }
  }
  assertTrue("Class " + cpName3 + " was missing on a region", found);
}
 
Example 8
Source File: IntegrationTestLoadAndVerify.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testLoadAndVerify() throws Exception {
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(TableName.valueOf(TEST_NAME));

  tableDescriptor.setColumnFamily(
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(TEST_FAMILY));

  Admin admin = getTestingUtil(getConf()).getAdmin();
  admin.createTable(tableDescriptor, Bytes.toBytes(0L), Bytes.toBytes(-1L), 40);

  doLoad(getConf(), tableDescriptor);
  doVerify(getConf(), tableDescriptor);

  // Only disable and drop if we succeeded to verify - otherwise it's useful
  // to leave it around for post-mortem
  getTestingUtil(getConf()).deleteTable(tableDescriptor.getTableName());
}
 
Example 9
Source File: TestVerifyReplicationCrossDiffHdfs.java    From hbase with Apache License 2.0 5 votes vote down vote up
private static void createTestingTable(Admin admin) throws IOException {
  TableDescriptor table = TableDescriptorBuilder.newBuilder(TABLE_NAME)
      .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(FAMILY).setMaxVersions(100)
          .setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build())
      .build();
  admin.createTable(table);
}
 
Example 10
Source File: TestCoprocessorEndpoint.java    From hbase with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setupBeforeClass() throws Exception {
  // set configure to indicate which cp should be loaded
  Configuration conf = util.getConfiguration();
  conf.setInt(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, 5000);
  conf.setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
      org.apache.hadoop.hbase.coprocessor.ColumnAggregationEndpoint.class.getName(),
      ProtobufCoprocessorService.class.getName());
  conf.setStrings(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY,
      ProtobufCoprocessorService.class.getName());
  util.startMiniCluster(2);
  Admin admin = util.getAdmin();

  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(TEST_TABLE);
  tableDescriptor.setColumnFamily(
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(TEST_FAMILY));
  admin.createTable(tableDescriptor, new byte[][]{ROWS[rowSeperator1], ROWS[rowSeperator2]});
  util.waitUntilAllRegionsAssigned(TEST_TABLE);

  Table table = util.getConnection().getTable(TEST_TABLE);
  for (int i = 0; i < ROWSIZE; i++) {
    Put put = new Put(ROWS[i]);
    put.addColumn(TEST_FAMILY, TEST_QUALIFIER, Bytes.toBytes(i));
    table.put(put);
  }
  table.close();
}
 
Example 11
Source File: TestMultiRowResource.java    From hbase with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  conf = TEST_UTIL.getConfiguration();
  conf.setBoolean(RESTServer.REST_CSRF_ENABLED_KEY, csrfEnabled);
  if (csrfEnabled) {
    conf.set(RESTServer.REST_CSRF_BROWSER_USERAGENTS_REGEX_KEY, ".*");
  }
  extraHdr = new BasicHeader(RESTServer.REST_CSRF_CUSTOM_HEADER_DEFAULT, "");
  TEST_UTIL.startMiniCluster();
  REST_TEST_UTIL.startServletContainer(conf);
  context = JAXBContext.newInstance(
          CellModel.class,
          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.getAdmin();
  if (admin.tableExists(TABLE)) {
    return;
  }
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(TABLE);
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(CFA)).build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(CFB)).build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  admin.createTable(tableDescriptorBuilder.build());
}
 
Example 12
Source File: IntegrationTestDDLMasterFailover.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
void perform() throws IOException {
  Admin admin = connection.getAdmin();
  try {
    TableDescriptor td = createTableDesc();
    TableName tableName = td.getTableName();
    if ( admin.tableExists(tableName)){
      return;
    }
    String numRegionKey = String.format(NUM_REGIONS_KEY, this.getClass().getSimpleName());
    numRegions = getConf().getInt(numRegionKey, DEFAULT_NUM_REGIONS);
    byte[] startKey = Bytes.toBytes("row-0000000000");
    byte[] endKey = Bytes.toBytes("row-" + Integer.MAX_VALUE);
    LOG.info("Creating table:" + td);
    admin.createTable(td, startKey, endKey, numRegions);
    Assert.assertTrue("Table: " + td + " was not created", admin.tableExists(tableName));
    TableDescriptor freshTableDesc = admin.getDescriptor(tableName);
    Assert.assertTrue(
      "After create, Table: " + tableName + " in not enabled", admin.isTableEnabled(tableName));
    enabledTables.put(tableName, freshTableDesc);
    LOG.info("Created table:" + freshTableDesc);
  } catch (Exception e) {
    LOG.warn("Caught exception in action: " + this.getClass());
    throw e;
  } finally {
    admin.close();
  }
}
 
Example 13
Source File: TestRegionMover.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  // Create a pre-split table just to populate some regions
  TableName tableName = TableName.valueOf("testRegionMover");
  Admin admin = TEST_UTIL.getAdmin();
  if (admin.tableExists(tableName)) {
    TEST_UTIL.deleteTable(tableName);
  }
  TableDescriptor tableDesc = TableDescriptorBuilder.newBuilder(tableName)
    .setColumnFamily(ColumnFamilyDescriptorBuilder.of("fam1")).build();
  String startKey = "a";
  String endKey = "z";
  admin.createTable(tableDesc, Bytes.toBytes(startKey), Bytes.toBytes(endKey), 9);
}
 
Example 14
Source File: GridTableHBaseBenchmark.java    From kylin with Apache License 2.0 5 votes vote down vote up
private static void createHTableIfNeeded(Connection conn, String tableName) throws IOException {
    Admin hbase = conn.getAdmin();

    try {
        boolean tableExist = false;
        try {
            hbase.getTableDescriptor(TableName.valueOf(tableName));
            tableExist = true;
        } catch (TableNotFoundException e) {
            //do nothing?
        }

        if (tableExist) {
            logger.info("HTable '{}' already exists", tableName);
            return;
        }

        logger.info("Creating HTable '{}'", tableName);

        HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName));

        HColumnDescriptor fd = new HColumnDescriptor(CF);
        fd.setBlocksize(CELL_SIZE);
        desc.addFamily(fd);
        hbase.createTable(desc);

        logger.info("HTable '{}' created", tableName);
    } finally {
        hbase.close();
    }
}
 
Example 15
Source File: GridTableHBaseBenchmark.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private static void createHTableIfNeeded(Connection conn, String tableName) throws IOException {
    Admin hbase = conn.getAdmin();

    try {
        boolean tableExist = false;
        try {
            hbase.getTableDescriptor(TableName.valueOf(tableName));
            tableExist = true;
        } catch (TableNotFoundException e) {
            //do nothing?
        }

        if (tableExist) {
            logger.info("HTable '{}' already exists", tableName);
            return;
        }

        logger.info("Creating HTable '{}'", tableName);

        HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName));

        HColumnDescriptor fd = new HColumnDescriptor(CF);
        fd.setBlocksize(CELL_SIZE);
        desc.addFamily(fd);
        hbase.createTable(desc);

        logger.info("HTable '{}' created", tableName);
    } finally {
        hbase.close();
    }
}
 
Example 16
Source File: TestMasterQuotasObserver.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void createTable(Admin admin, TableName tn) throws Exception {
  // Create a table
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(tn);
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("F1")).build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  admin.createTable(tableDescriptorBuilder.build());
}
 
Example 17
Source File: TestClassLoading.java    From hbase with Apache License 2.0 4 votes vote down vote up
void loadingClassFromLibDirInJar(String libPrefix) throws Exception {
  FileSystem fs = cluster.getFileSystem();

  File innerJarFile1 = buildCoprocessorJar(cpName1);
  File innerJarFile2 = buildCoprocessorJar(cpName2);
  File outerJarFile = new File(TEST_UTIL.getDataTestDir().toString(), "outer.jar");

  ClassLoaderTestHelper.addJarFilesToJar(
    outerJarFile, libPrefix, innerJarFile1, innerJarFile2);

  // copy the jars into dfs
  fs.copyFromLocalFile(new Path(outerJarFile.getPath()),
    new Path(fs.getUri().toString() + Path.SEPARATOR));
  String jarFileOnHDFS = fs.getUri().toString() + Path.SEPARATOR +
    outerJarFile.getName();
  assertTrue("Copy jar file to HDFS failed.",
    fs.exists(new Path(jarFileOnHDFS)));
  LOG.info("Copied jar file to HDFS: " + jarFileOnHDFS);

  // create a table that references the coprocessors
  TableDescriptorBuilder tdb = TableDescriptorBuilder.newBuilder(tableName);
  tdb.setColumnFamily(ColumnFamilyDescriptorBuilder
    .newBuilder(Bytes.toBytes("test")).build());
    // without configuration values
  tdb.setValue("COPROCESSOR$1", jarFileOnHDFS + "|" + cpName1
    + "|" + Coprocessor.PRIORITY_USER);
    // with configuration values
  tdb.setValue("COPROCESSOR$2", jarFileOnHDFS + "|" + cpName2
    + "|" + Coprocessor.PRIORITY_USER + "|k1=v1,k2=v2,k3=v3");
  Admin admin = TEST_UTIL.getAdmin();
  if (admin.tableExists(tableName)) {
    if (admin.isTableEnabled(tableName)) {
      admin.disableTable(tableName);
    }
    admin.deleteTable(tableName);
  }

  TableDescriptor tableDescriptor = tdb.build();
  admin.createTable(tableDescriptor);
  waitForTable(tableDescriptor.getTableName());

  // verify that the coprocessors were loaded
  boolean found1 = false, found2 = false, found2_k1 = false,
      found2_k2 = false, found2_k3 = false;
  MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster();
  for (HRegion region: hbase.getRegionServer(0).getOnlineRegionsLocalContext()) {
    if (region.getRegionInfo().getRegionNameAsString().startsWith(tableName.getNameAsString())) {
      CoprocessorEnvironment env;
      env = region.getCoprocessorHost().findCoprocessorEnvironment(cpName1);
      if (env != null) {
        found1 = true;
      }
      env = region.getCoprocessorHost().findCoprocessorEnvironment(cpName2);
      if (env != null) {
        found2 = true;
        Configuration conf = env.getConfiguration();
        found2_k1 = conf.get("k1") != null;
        found2_k2 = conf.get("k2") != null;
        found2_k3 = conf.get("k3") != null;
      }
    }
  }
  assertTrue("Class " + cpName1 + " was missing on a region", found1);
  assertTrue("Class " + cpName2 + " was missing on a region", found2);
  assertTrue("Configuration key 'k1' was missing on a region", found2_k1);
  assertTrue("Configuration key 'k2' was missing on a region", found2_k2);
  assertTrue("Configuration key 'k3' was missing on a region", found2_k3);
}
 
Example 18
Source File: TestQuotaAdmin.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testMultiQuotaThrottling() throws Exception {
  byte[] FAMILY = Bytes.toBytes("testFamily");
  byte[] ROW = Bytes.toBytes("testRow");
  byte[] QUALIFIER = Bytes.toBytes("testQualifier");
  byte[] VALUE = Bytes.toBytes("testValue");

  Admin admin = TEST_UTIL.getAdmin();
  TableName tableName = TableName.valueOf("testMultiQuotaThrottling");
  TableDescriptor desc = TableDescriptorBuilder.newBuilder(tableName)
      .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)).build();
  admin.createTable(desc);

  // Set up the quota.
  admin.setQuota(QuotaSettingsFactory.throttleTable(tableName, ThrottleType.WRITE_NUMBER, 6,
      TimeUnit.SECONDS));

  Thread.sleep(1000);
  TEST_UTIL.getRSForFirstRegionInTable(tableName).getRegionServerRpcQuotaManager().
      getQuotaCache().triggerCacheRefresh();
  Thread.sleep(1000);

  Table t =  TEST_UTIL.getConnection().getTable(tableName);
  try {
    int size = 5;
    List actions = new ArrayList();
    Object[] results = new Object[size];

    for (int i = 0; i < size; i++) {
      Put put1 = new Put(ROW);
      put1.addColumn(FAMILY, QUALIFIER, VALUE);
      actions.add(put1);
    }
    t.batch(actions, results);
    t.batch(actions, results);
  } catch (IOException e) {
    fail("Not supposed to get ThrottlingExcepiton " + e);
  } finally {
    t.close();
  }
}
 
Example 19
Source File: TestMasterObserver.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testSnapshotOperations() throws Exception {
  final TableName tableName = TableName.valueOf(name.getMethodName());
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();
  HMaster master = cluster.getMaster();
  MasterCoprocessorHost host = master.getMasterCoprocessorHost();
  CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class);
  cp.resetStates();

  // create a table
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);

  tableDescriptor.setColumnFamily(
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(TEST_FAMILY));
  Admin admin = UTIL.getAdmin();

  tableCreationLatch = new CountDownLatch(1);
  admin.createTable(tableDescriptor);
  tableCreationLatch.await();
  tableCreationLatch = new CountDownLatch(1);

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

  try {
    // Test snapshot operation
    assertFalse("Coprocessor should not have been called yet",
      cp.wasSnapshotCalled());
    admin.snapshot(TEST_SNAPSHOT, tableName);
    assertTrue("Coprocessor should have been called on snapshot",
      cp.wasSnapshotCalled());

    //Test list operation
    admin.listSnapshots();
    assertTrue("Coprocessor should have been called on snapshot list",
      cp.wasListSnapshotCalled());

    // Test clone operation
    admin.cloneSnapshot(TEST_SNAPSHOT, TEST_CLONE);
    assertTrue("Coprocessor should have been called on snapshot clone",
      cp.wasCloneSnapshotCalled());
    assertFalse("Coprocessor restore should not have been called on snapshot clone",
      cp.wasRestoreSnapshotCalled());
    admin.disableTable(TEST_CLONE);
    assertTrue(admin.isTableDisabled(tableName));
    deleteTable(admin, TEST_CLONE);

    // Test restore operation
    cp.resetStates();
    admin.restoreSnapshot(TEST_SNAPSHOT);
    assertTrue("Coprocessor should have been called on snapshot restore",
      cp.wasRestoreSnapshotCalled());
    assertFalse("Coprocessor clone should not have been called on snapshot restore",
      cp.wasCloneSnapshotCalled());

    admin.deleteSnapshot(TEST_SNAPSHOT);
    assertTrue("Coprocessor should have been called on snapshot delete",
      cp.wasDeleteSnapshotCalled());
  } finally {
    deleteTable(admin, tableName);
  }
}
 
Example 20
Source File: BigtableTargetIT.java    From datacollector with Apache License 2.0 4 votes vote down vote up
private void createTable(String tab) throws Exception {
  Connection conn = BigtableConfiguration.connect(projectID, instanceID);
  Admin admin = conn.getAdmin();
  admin.createTable(new HTableDescriptor(TableName.valueOf(tab)));
}