Search in sources :

Example 6 with HBaseAdmin

use of org.apache.hadoop.hbase.client.HBaseAdmin in project hbase by apache.

the class TestFullRestore method testFullRestoreMultiple.

/**
   * Verify that multiple tables are restored to new tables.
   * @throws Exception
   */
@Test
public void testFullRestoreMultiple() throws Exception {
    LOG.info("create full backup image on multiple tables");
    List<TableName> tables = Lists.newArrayList(table2, table3);
    String backupId = fullTableBackup(tables);
    assertTrue(checkSucceeded(backupId));
    TableName[] restore_tableset = new TableName[] { table2, table3 };
    TableName[] tablemap = new TableName[] { table2_restore, table3_restore };
    BackupAdmin client = getBackupAdmin();
    client.restore(BackupUtils.createRestoreRequest(BACKUP_ROOT_DIR, backupId, false, restore_tableset, tablemap, false));
    HBaseAdmin hba = TEST_UTIL.getHBaseAdmin();
    assertTrue(hba.tableExists(table2_restore));
    assertTrue(hba.tableExists(table3_restore));
    TEST_UTIL.deleteTable(table2_restore);
    TEST_UTIL.deleteTable(table3_restore);
    hba.close();
}
Also used : TableName(org.apache.hadoop.hbase.TableName) HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) Test(org.junit.Test)

Example 7 with HBaseAdmin

use of org.apache.hadoop.hbase.client.HBaseAdmin in project hbase by apache.

the class TestFullRestore method testFullRestoreSingle.

/**
   * Verify that a single table is restored to a new table
   * @throws Exception
   */
@Test
public void testFullRestoreSingle() throws Exception {
    LOG.info("test full restore on a single table empty table");
    List<TableName> tables = Lists.newArrayList(table1);
    String backupId = fullTableBackup(tables);
    assertTrue(checkSucceeded(backupId));
    LOG.info("backup complete");
    TableName[] tableset = new TableName[] { table1 };
    TableName[] tablemap = new TableName[] { table1_restore };
    BackupAdmin client = getBackupAdmin();
    client.restore(BackupUtils.createRestoreRequest(BACKUP_ROOT_DIR, backupId, false, tableset, tablemap, false));
    HBaseAdmin hba = TEST_UTIL.getHBaseAdmin();
    assertTrue(hba.tableExists(table1_restore));
    TEST_UTIL.deleteTable(table1_restore);
    hba.close();
}
Also used : TableName(org.apache.hadoop.hbase.TableName) HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) Test(org.junit.Test)

Example 8 with HBaseAdmin

use of org.apache.hadoop.hbase.client.HBaseAdmin in project hbase by apache.

the class TestFullRestore method testFullRestoreSingleOverwriteCommand.

/**
   * Verify that a single table is restored using overwrite
   * @throws Exception
   */
@Test
public void testFullRestoreSingleOverwriteCommand() throws Exception {
    LOG.info("test full restore on a single table empty table: command-line");
    List<TableName> tables = Lists.newArrayList(table1);
    String backupId = fullTableBackup(tables);
    assertTrue(checkSucceeded(backupId));
    LOG.info("backup complete");
    TableName[] tableset = new TableName[] { table1 };
    // restore <backup_root_path> <backup_id> <tables> [tableMapping]
    String[] args = new String[] { BACKUP_ROOT_DIR, backupId, "-t", StringUtils.join(tableset, ","), "-o" };
    // Run restore
    int ret = ToolRunner.run(conf1, new RestoreDriver(), args);
    assertTrue(ret == 0);
    HBaseAdmin hba = TEST_UTIL.getHBaseAdmin();
    assertTrue(hba.tableExists(table1));
    hba.close();
}
Also used : TableName(org.apache.hadoop.hbase.TableName) HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) Test(org.junit.Test)

Example 9 with HBaseAdmin

use of org.apache.hadoop.hbase.client.HBaseAdmin in project hbase by apache.

the class TestFullRestore method testFullRestoreMultipleOverwriteCommand.

/**
   * Verify that multiple tables are restored to new tables using overwrite.
   * @throws Exception
   */
@Test
public void testFullRestoreMultipleOverwriteCommand() throws Exception {
    LOG.info("create full backup image on multiple tables: command-line");
    List<TableName> tables = Lists.newArrayList(table2, table3);
    String backupId = fullTableBackup(tables);
    assertTrue(checkSucceeded(backupId));
    TableName[] restore_tableset = new TableName[] { table2, table3 };
    // restore <backup_root_path> <backup_id> <tables> [tableMapping]
    String[] args = new String[] { BACKUP_ROOT_DIR, backupId, "-t", StringUtils.join(restore_tableset, ","), "-o" };
    // Run backup
    int ret = ToolRunner.run(conf1, new RestoreDriver(), args);
    assertTrue(ret == 0);
    HBaseAdmin hba = TEST_UTIL.getHBaseAdmin();
    assertTrue(hba.tableExists(table2));
    assertTrue(hba.tableExists(table3));
    hba.close();
}
Also used : TableName(org.apache.hadoop.hbase.TableName) HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) Test(org.junit.Test)

Example 10 with HBaseAdmin

use of org.apache.hadoop.hbase.client.HBaseAdmin in project hbase by apache.

the class TestBackupBase method createTables.

protected static void createTables() throws Exception {
    long tid = System.currentTimeMillis();
    table1 = TableName.valueOf("ns1:test-" + tid);
    HBaseAdmin ha = TEST_UTIL.getHBaseAdmin();
    // Create namespaces
    NamespaceDescriptor desc1 = NamespaceDescriptor.create("ns1").build();
    NamespaceDescriptor desc2 = NamespaceDescriptor.create("ns2").build();
    NamespaceDescriptor desc3 = NamespaceDescriptor.create("ns3").build();
    NamespaceDescriptor desc4 = NamespaceDescriptor.create("ns4").build();
    ha.createNamespace(desc1);
    ha.createNamespace(desc2);
    ha.createNamespace(desc3);
    ha.createNamespace(desc4);
    HTableDescriptor desc = new HTableDescriptor(table1);
    HColumnDescriptor fam = new HColumnDescriptor(famName);
    desc.addFamily(fam);
    ha.createTable(desc);
    table1Desc = desc;
    Connection conn = ConnectionFactory.createConnection(conf1);
    Table table = conn.getTable(table1);
    loadTable(table);
    table.close();
    table2 = TableName.valueOf("ns2:test-" + tid + 1);
    desc = new HTableDescriptor(table2);
    desc.addFamily(fam);
    ha.createTable(desc);
    table = conn.getTable(table2);
    loadTable(table);
    table.close();
    table3 = TableName.valueOf("ns3:test-" + tid + 2);
    table = TEST_UTIL.createTable(table3, famName);
    table.close();
    table4 = TableName.valueOf("ns4:test-" + tid + 3);
    table = TEST_UTIL.createTable(table4, famName);
    table.close();
    ha.close();
    conn.close();
}
Also used : HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) BackupSystemTable(org.apache.hadoop.hbase.backup.impl.BackupSystemTable) HTable(org.apache.hadoop.hbase.client.HTable) Table(org.apache.hadoop.hbase.client.Table) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) Connection(org.apache.hadoop.hbase.client.Connection) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Aggregations

HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)180 Test (org.junit.Test)93 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)76 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)72 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)70 Connection (java.sql.Connection)66 Properties (java.util.Properties)54 TableName (org.apache.hadoop.hbase.TableName)36 IOException (java.io.IOException)33 ResultSet (java.sql.ResultSet)27 BaseTest (org.apache.phoenix.query.BaseTest)27 HTable (org.apache.hadoop.hbase.client.HTable)26 SQLException (java.sql.SQLException)22 TestUtil.closeConnection (org.apache.phoenix.util.TestUtil.closeConnection)22 Put (org.apache.hadoop.hbase.client.Put)16 Configuration (org.apache.hadoop.conf.Configuration)13 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)13 PreparedStatement (java.sql.PreparedStatement)12 PhoenixIOException (org.apache.phoenix.exception.PhoenixIOException)12 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)9