Java Code Examples for org.apache.hadoop.hbase.client.HBaseAdmin#isTableEnabled()

The following examples show how to use org.apache.hadoop.hbase.client.HBaseAdmin#isTableEnabled() . 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: KylinHealthCheckJob.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private void checkHBaseTables(List<CubeInstance> cubes) throws IOException {
    reporter.log("## Checking HBase Table of segments");
    HBaseAdmin hbaseAdmin = new HBaseAdmin(HBaseConfiguration.create());
    try {
        for (CubeInstance cube : cubes) {
            for (CubeSegment segment : cube.getSegments()) {
                if (segment.getStatus() != SegmentStatusEnum.NEW) {
                    String tableName = segment.getStorageLocationIdentifier();
                    if ((!hbaseAdmin.tableExists(tableName)) || (!hbaseAdmin.isTableEnabled(tableName))) {
                        reporter.log("HBase table: {} not exist for segment: {}, project: {}", tableName, segment,
                                cube.getProject());
                        reporter.log(
                                "The rebuild url: -d '{\"startTime\":{}, \"endTime\":{}, \"buildType\":\"REFRESH\"}' /kylin/api/cubes/{}/build",
                                segment.getTSRange().start, segment.getTSRange().end, cube.getName());
                    }
                }
            }
        }
    } finally {
        if (null != hbaseAdmin) {
            hbaseAdmin.close();
        }
    }

}
 
Example 2
Source File: HBaseDDLHandler.java    From bigdata-tutorial with Apache License 2.0 6 votes vote down vote up
/**
 * @param tableName
 * @return
 */
public boolean deleteTable(String tableName) throws IOException {

	HBaseAdmin admin = new HBaseAdmin(getConnPool().getConn());
	if (admin.tableExists(tableName)) {
		try {
			if (admin.isTableEnabled(tableName)) {
				admin.disableTable(tableName);
			}
			admin.deleteTable(tableName);
			LOGGER.info(">>>> Table {} delete success!", tableName);
		} catch (Exception ex) {
			LOGGER.error("delete table error:", ex);
			return false;
		}
	} else {
		LOGGER.warn(">>>> Table {} delete but not exist.", tableName);
	}
	admin.close();
	return true;
}
 
Example 3
Source File: KylinHealthCheckJob.java    From kylin with Apache License 2.0 6 votes vote down vote up
private void checkHBaseTables(List<CubeInstance> cubes) throws IOException {
    reporter.log("## Checking HBase Table of segments");
    HBaseAdmin hbaseAdmin = new HBaseAdmin(HBaseConfiguration.create());
    try {
        for (CubeInstance cube : cubes) {
            for (CubeSegment segment : cube.getSegments()) {
                if (segment.getStatus() != SegmentStatusEnum.NEW) {
                    String tableName = segment.getStorageLocationIdentifier();
                    if ((!hbaseAdmin.tableExists(tableName)) || (!hbaseAdmin.isTableEnabled(tableName))) {
                        reporter.log("HBase table: {} not exist for segment: {}, project: {}", tableName, segment,
                                cube.getProject());
                        reporter.log(
                                "The rebuild url: -d '{\"startTime\":{}, \"endTime\":{}, \"buildType\":\"REFRESH\"}' /kylin/api/cubes/{}/build",
                                segment.getTSRange().start, segment.getTSRange().end, cube.getName());
                    }
                }
            }
        }
    } finally {
        if (null != hbaseAdmin) {
            hbaseAdmin.close();
        }
    }

}
 
Example 4
Source File: HBaseWriter.java    From hiped2 with Apache License 2.0 6 votes vote down vote up
public static void createTableAndColumn(Configuration conf,
                                        String table,
                                        byte[] columnFamily)
    throws IOException {
  HBaseAdmin hbase = new HBaseAdmin(conf);
  HTableDescriptor desc = new HTableDescriptor(table);
  HColumnDescriptor meta = new HColumnDescriptor(columnFamily);
  desc.addFamily(meta);
  if (hbase.tableExists(table)) {
    if(hbase.isTableEnabled(table)) {
      hbase.disableTable(table);
    }
    hbase.deleteTable(table);
  }
  hbase.createTable(desc);
}
 
Example 5
Source File: HbaseUtil.java    From DataLink with Apache License 2.0 5 votes vote down vote up
private static void check(HBaseAdmin admin, HTable htable) throws DataXException, IOException {
	if (!admin.isMasterRunning()) {
		throw new IllegalStateException("HBase master 没有运行, 请检查您的配置 或者 联系 Hbase 管理员.");
	}
	if (!admin.tableExists(htable.getTableName())) {
		throw new IllegalStateException("HBase源头表" + Bytes.toString(htable.getTableName()) + "不存在, 请检查您的配置 或者 联系 Hbase 管理员.");
	}
	if (!admin.isTableAvailable(htable.getTableName()) || !admin.isTableEnabled(htable.getTableName())) {
		throw new IllegalStateException("HBase源头表" + Bytes.toString(htable.getTableName()) + " 不可用, 请检查您的配置 或者 联系 Hbase 管理员.");
	}
}
 
Example 6
Source File: HbaseUtil.java    From DataLink with Apache License 2.0 5 votes vote down vote up
private static void check(HBaseAdmin admin, HTable htable) throws DataXException, IOException {
    if (!admin.isMasterRunning()) {
        throw new IllegalStateException("HBase master 没有运行, 请检查您的配置 或者 联系 Hbase 管理员.");
    }
    if (!admin.tableExists(htable.getTableName())) {
        throw new IllegalStateException("HBase源头表" + Bytes.toString(htable.getTableName())
                + "不存在, 请检查您的配置 或者 联系 Hbase 管理员.");
    }
    if (!admin.isTableAvailable(htable.getTableName()) || !admin.isTableEnabled(htable.getTableName())) {
        throw new IllegalStateException("HBase源头表" + Bytes.toString(htable.getTableName())
                + " 不可用, 请检查您的配置 或者 联系 Hbase 管理员.");
    }
}
 
Example 7
Source File: Util.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
public static void validateTable(HBaseAdmin admin, String tableName) throws IOException, InterruptedException {
    if (tableName.equals(Args.ALL_TABLES)) return;

    boolean tableExists = false;
    try {
        if (tableName.contains(Constant.TABLE_DELIMITER)) {
            String[] tables = tableName.split(Constant.TABLE_DELIMITER);
            for (String table : tables) {
                tableExists = admin.tableExists(table);
            }
        } else {
            tableExists = admin.listTables(tableName).length > 0;
        }
    } catch (Exception e) {
        Thread.sleep(1000);
        System.out.println();
        System.out.println(admin.getConfiguration().get("hbase.zookeeper.quorum") + " is invalid zookeeper quorum");
        System.exit(1);
    }
    if (tableExists) {
        try {
            if (!admin.isTableEnabled(tableName)) {
                throw new InvalidTableException("Table is not enabled.");
            }
        } catch (Exception ignore) {
        }
    } else {
        throw new InvalidTableException("Table does not exist.");
    }
}
 
Example 8
Source File: Util.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
public static void validateTable(HBaseAdmin admin, String tableName) throws IOException, InterruptedException {
    if (tableName.equals(Args.ALL_TABLES)) return;

    boolean tableExists = false;
    try {
        if (tableName.contains(Constant.TABLE_DELIMITER)) {
            String[] tables = tableName.split(Constant.TABLE_DELIMITER);
            for (String table : tables) {
                tableExists = admin.tableExists(table);
            }
        } else {
            tableExists = admin.listTables(tableName).length > 0;
        }
    } catch (Exception e) {
        Thread.sleep(1000);
        System.out.println();
        System.out.println(admin.getConfiguration().get("hbase.zookeeper.quorum") + " is invalid zookeeper quorum");
        System.exit(1);
    }
    if (tableExists) {
        try {
            if (!admin.isTableEnabled(tableName)) {
                throw new InvalidTableException("Table is not enabled.");
            }
        } catch (Exception ignore) {
        }
    } else {
        throw new InvalidTableException("Table does not exist.");
    }
}
 
Example 9
Source File: TestBase.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
protected static void validateTable(HBaseAdmin admin, String tableName) throws IOException, InterruptedException {
    if (tableName.equals(Args.ALL_TABLES)) return;

    boolean tableExists = admin.tableExists(tableName);
    if (tableExists) {
        if (!admin.isTableEnabled(tableName)) {
            throw new InvalidTableException("Table is not enabled.");
        }
    } else {
        throw new InvalidTableException("Table does not exist.");
    }
}
 
Example 10
Source File: Util.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
public static void validateTable(HBaseAdmin admin, String tableName) throws IOException, InterruptedException {
    if (tableName.equals(Args.ALL_TABLES)) return;

    boolean tableExists = false;
    try {
        if (tableName.contains(Constant.TABLE_DELIMITER)) {
            String[] tables = tableName.split(Constant.TABLE_DELIMITER);
            for (String table : tables) {
                tableExists = admin.tableExists(table);
            }
        } else {
            tableExists = admin.listTables(tableName).length > 0;
        }
    } catch (Exception e) {
        Thread.sleep(1000);
        System.out.println();
        System.out.println(admin.getConfiguration().get("hbase.zookeeper.quorum") + " is invalid zookeeper quorum");
        System.exit(1);
    }
    if (tableExists) {
        try {
            if (!admin.isTableEnabled(tableName)) {
                throw new InvalidTableException("Table is not enabled.");
            }
        } catch (Exception ignore) {
        }
    } else {
        throw new InvalidTableException("Table does not exist.");
    }
}
 
Example 11
Source File: TestBase.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
protected static void validateTable(HBaseAdmin admin, String tableName) throws IOException, InterruptedException {
    if (tableName.equals(Args.ALL_TABLES)) return;

    boolean tableExists = admin.tableExists(tableName);
    if (tableExists) {
        if (!admin.isTableEnabled(tableName)) {
            throw new InvalidTableException("Table is not enabled.");
        }
    } else {
        throw new InvalidTableException("Table does not exist.");
    }
}
 
Example 12
Source File: Util.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
public static void validateTable(HBaseAdmin admin, String tableName) throws IOException, InterruptedException {
    if (tableName.equals(Args.ALL_TABLES)) return;

    boolean tableExists = false;
    try {
        if (tableName.contains(Constant.TABLE_DELIMITER)) {
            String[] tables = tableName.split(Constant.TABLE_DELIMITER);
            for (String table : tables) {
                tableExists = admin.tableExists(table);
            }
        } else {
            tableExists = admin.listTables(tableName).length > 0;
        }
    } catch (Exception e) {
        Thread.sleep(1000);
        System.out.println();
        System.out.println(admin.getConfiguration().get("hbase.zookeeper.quorum") + " is invalid zookeeper quorum");
        System.exit(1);
    }
    if (tableExists) {
        try {
            if (!admin.isTableEnabled(tableName)) {
                throw new InvalidTableException("Table is not enabled.");
            }
        } catch (Exception ignore) {
        }
    } else {
        throw new InvalidTableException("Table does not exist.");
    }
}
 
Example 13
Source File: TestBase.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
protected static void validateTable(HBaseAdmin admin, String tableName) throws IOException, InterruptedException {
    if (tableName.equals(Args.ALL_TABLES)) return;

    boolean tableExists = admin.tableExists(tableName);
    if (tableExists) {
        if (!admin.isTableEnabled(tableName)) {
            throw new InvalidTableException("Table is not enabled.");
        }
    } else {
        throw new InvalidTableException("Table does not exist.");
    }
}
 
Example 14
Source File: Util.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
public static void validateTable(HBaseAdmin admin, String tableName) throws IOException, InterruptedException {
    if (tableName.equals(Args.ALL_TABLES)) return;

    boolean tableExists = false;
    try {
        if (tableName.contains(Constant.TABLE_DELIMITER)) {
            String[] tables = tableName.split(Constant.TABLE_DELIMITER);
            for (String table : tables) {
                tableExists = admin.tableExists(table);
            }
        } else {
            tableExists = admin.listTables(tableName).length > 0;
        }
    } catch (Exception e) {
        Thread.sleep(1000);
        System.out.println();
        System.out.println(admin.getConfiguration().get("hbase.zookeeper.quorum") + " is invalid zookeeper quorum");
        System.exit(1);
    }
    if (tableExists) {
        try {
            if (!admin.isTableEnabled(tableName)) {
                throw new InvalidTableException("Table is not enabled.");
            }
        } catch (Exception ignore) {
        }
    } else {
        throw new InvalidTableException("Table does not exist.");
    }
}
 
Example 15
Source File: TestBase.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
protected static void validateTable(HBaseAdmin admin, String tableName) throws IOException, InterruptedException {
    if (tableName.equals(Args.ALL_TABLES)) return;

    boolean tableExists = admin.tableExists(tableName);
    if (tableExists) {
        if (!admin.isTableEnabled(tableName)) {
            throw new InvalidTableException("Table is not enabled.");
        }
    } else {
        throw new InvalidTableException("Table does not exist.");
    }
}