@Override public boolean tableExists(String tableName) throws IOException { return adm.tableExists(tableName); }
@Override public boolean tableExists(String tableName) throws IOException { return adm.tableExists(tableName); }
@Override public boolean tableExists(String tableName) throws IOException { return adm.tableExists(tableName); }
@Override public boolean checkState(int tries) throws IOException { return !getAdmin().tableExists(tableName); } });
public boolean tableExists(String tableName) { try (HBaseAdmin admin = (HBaseAdmin) getConnection().getAdmin()) { return admin.tableExists(TableName.valueOf(tableName)); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public Future<Void> cloneSnapshotAsync(final String snapshotName, final TableName tableName) throws IOException, TableExistsException { if (tableExists(tableName)) { throw new TableExistsException(tableName); } return internalRestoreSnapshotAsync(snapshotName, tableName, false); }
public Object call() throws Exception { logger.info("Deleting HBase table " + htableName); if (hbaseAdmin.tableExists(htableName)) { if (hbaseAdmin.isTableEnabled(htableName)) { hbaseAdmin.disableTable(htableName); } hbaseAdmin.deleteTable(htableName); logger.info("Deleted HBase table " + htableName); } else { logger.info("HBase table" + htableName + " does not exist"); } return null; } }
@Override public void disableTableReplication(final TableName tableName) throws IOException { if (tableName == null) { throw new IllegalArgumentException("Table name is null"); } if (!tableExists(tableName)) { throw new TableNotFoundException("Table '" + tableName.getNameAsString() + "' does not exists."); } setTableRep(tableName, false); }
@Override public void cloneSnapshot(String snapshotName, TableName tableName, boolean restoreAcl) throws IOException, TableExistsException, RestoreSnapshotException { if (tableExists(tableName)) { throw new TableExistsException(tableName); } get( internalRestoreSnapshotAsync(snapshotName, tableName, restoreAcl), Integer.MAX_VALUE, TimeUnit.MILLISECONDS); }
@Override public void enableTableReplication(final TableName tableName) throws IOException { if (tableName == null) { throw new IllegalArgumentException("Table name cannot be null"); } if (!tableExists(tableName)) { throw new TableNotFoundException("Table '" + tableName.getNameAsString() + "' does not exists."); } byte[][] splits = getTableSplits(tableName); checkAndSyncTableDescToPeers(tableName, splits); setTableRep(tableName, true); }
@Override public Future<Void> restoreSnapshotAsync(final String snapshotName) throws IOException, RestoreSnapshotException { TableName tableName = getTableNameBeforeRestoreSnapshot(snapshotName); // The table does not exists, switch to clone. if (!tableExists(tableName)) { return cloneSnapshotAsync(snapshotName, tableName); } // Check if the table is disabled if (!isTableDisabled(tableName)) { throw new TableNotDisabledException(tableName); } return internalRestoreSnapshotAsync(snapshotName, tableName, false); }
@Test public void test() throws IOException { HBaseAdmin hBaseAdmin = mock(HBaseAdmin.class); HTableDescriptor[] hds = new HTableDescriptor[2]; HTableDescriptor d1 = mock(HTableDescriptor.class); HTableDescriptor d2 = mock(HTableDescriptor.class); hds[0] = d1; hds[1] = d2; when(d1.getValue("KYLIN_HOST")).thenReturn("../examples/test_metadata/"); when(d2.getValue("KYLIN_HOST")).thenReturn("../examples/test_metadata/"); when(d1.getTableName()).thenReturn(TableName.valueOf("KYLIN_J9TE08D9IA")); String toBeDel = "to-be-del"; when(d2.getTableName()).thenReturn(TableName.valueOf(toBeDel)); when(hBaseAdmin.listTables("KYLIN_.*")).thenReturn(hds); when(hBaseAdmin.tableExists(toBeDel)).thenReturn(true); when(hBaseAdmin.isTableEnabled(toBeDel)).thenReturn(false); StorageCleanJobHbaseUtil.cleanUnusedHBaseTables(hBaseAdmin, true, 100000); ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); verify(hBaseAdmin).deleteTable(captor.capture()); assertEquals(Lists.newArrayList(toBeDel), captor.getAllValues()); } }
@Override public void cloneTableSchema(final TableName tableName, final TableName newTableName, final boolean preserveSplits) throws IOException { checkTableExists(tableName); if (tableExists(newTableName)) { throw new TableExistsException(newTableName); } TableDescriptor htd = TableDescriptorBuilder.copy(newTableName, getTableDescriptor(tableName)); if (preserveSplits) { createTable(htd, getTableSplits(tableName)); } else { createTable(htd); } }
/** * Verify that a single table is restored using overwrite. * * @throws Exception if doing the backup or an operation on the tables fails */ @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(); }
@Test public void testFullRestoreCheckCommand() throws Exception { LOG.info("test full restore on a single table: command-line, check only"); List<TableName> tables = Lists.newArrayList(table1); String backupId = fullTableBackup(tables); LOG.info("backup complete"); assertTrue(checkSucceeded(backupId)); // restore <backup_root_path> <backup_id> <tables> [tableMapping] String[] args = new String[] { BACKUP_ROOT_DIR, backupId, "-t", table1.getNameAsString(), "-m", table1_restore.getNameAsString(), "-c" }; // Run backup int ret = ToolRunner.run(conf1, new RestoreDriver(), args); assertTrue(ret == 0); //Verify that table has not been restored HBaseAdmin hba = TEST_UTIL.getHBaseAdmin(); assertFalse(hba.tableExists(table1_restore)); }
/** * Verify that a single empty table is restored to a new table. * * @throws Exception if doing the backup or an operation on the tables fails */ @Test public void testFullRestoreSingleEmpty() throws Exception { LOG.info("test full restore on a single table empty table"); String backupId = fullTableBackup(toList(table1.getNameAsString())); LOG.info("backup complete"); TableName[] tableset = new TableName[] { table1 }; TableName[] tablemap = new TableName[] { table1_restore }; getBackupAdmin().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); }
@Test public void testFullRestoreSingleCommand() 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); LOG.info("backup complete"); assertTrue(checkSucceeded(backupId)); // restore <backup_root_path> <backup_id> <tables> [tableMapping] String[] args = new String[] { BACKUP_ROOT_DIR, backupId, "-t", table1.getNameAsString(), "-m", table1_restore.getNameAsString() }; // Run backup int ret = ToolRunner.run(conf1, new RestoreDriver(), args); assertTrue(ret == 0); HBaseAdmin hba = TEST_UTIL.getHBaseAdmin(); assertTrue(hba.tableExists(table1_restore)); TEST_UTIL.deleteTable(table1_restore); hba.close(); }
/** * Verify that multiple tables are restored to new tables. * * @throws Exception if doing the backup or an operation on the tables fails */ @Test public void testFullRestoreMultipleEmpty() throws Exception { LOG.info("create full backup image on multiple tables"); List<TableName> tables = toList(table2.getNameAsString(), table3.getNameAsString()); String backupId = fullTableBackup(tables); TableName[] restore_tableset = new TableName[] { table2, table3 }; TableName[] tablemap = new TableName[] { table2_restore, table3_restore }; getBackupAdmin().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(); } }
/** * Verify that a remote restore on a single table is successful. * * @throws Exception if doing the backup or an operation on the tables fails */ @Test public void testFullRestoreRemote() throws Exception { LOG.info("test remote full backup on a single table"); String backupId = backupTables(BackupType.FULL, toList(table1.getNameAsString()), BACKUP_REMOTE_ROOT_DIR); LOG.info("backup complete"); TableName[] tableset = new TableName[] { table1 }; TableName[] tablemap = new TableName[] { table1_restore }; getBackupAdmin().restore( BackupUtils.createRestoreRequest(BACKUP_REMOTE_ROOT_DIR, backupId, false, tableset, tablemap, false)); HBaseAdmin hba = TEST_UTIL.getHBaseAdmin(); assertTrue(hba.tableExists(table1_restore)); TEST_UTIL.deleteTable(table1_restore); hba.close(); } }
/** * Verify that a single table is restored to a new table. * * @throws Exception if doing the backup, restoring it or an operation on the tables fails */ @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(); }