/** * Helper method to create an HBase table in an Amazon EMR cluster with HBase installed * * @param tableName - name for table to create * @param dnsId - Amazon EMR master node public DNS * @param hbaseRestPort - HBase Rest port */ public static void createTable(String tableName, String dnsId, int hbaseRestPort) { Configuration config = HBaseConfiguration.create(); RemoteAdmin admin = new RemoteAdmin(new Client(new Cluster().add(dnsId, hbaseRestPort)), config); String [] families = {"user", "address", "contact", "likes"}; try { if (admin.isTableAvailable(tableName)) { LOG.info("table already exists!"); return; } else { HTableDescriptor tableDesc = new HTableDescriptor(tableName); for (int i = 0; i < families.length; i++) { tableDesc.addFamily(new HColumnDescriptor(families[i])); } admin.createTable(tableDesc); isTableAvailable = true; LOG.info("create table " + tableName + " ok."); } } catch (IOException e) { LOG.error(e, e.getCause()); } }
/** * Helper method that checks if a table exists in HBase * * @param tableName - table to check * @param dnsId - Amazon EMR master node public DNS * @param hbaseRestPort - HBase Rest port * @return */ public static boolean tablesExists(String tableName, String dnsId, int hbaseRestPort) { Configuration config = HBaseConfiguration.create(); RemoteAdmin admin = new RemoteAdmin(new Client(new Cluster().add(dnsId, hbaseRestPort)), config); try { if (admin.isTableAvailable(tableName)) { LOG.info("table already exists!"); System.out.println("table already exists!"); return true; } } catch (IOException e) { e.printStackTrace(); LOG.error(e, e.getCause()); } return false; }
private void runNIsMoreThanOne(final Class<? extends Test> cmd) throws IOException, InterruptedException, ClassNotFoundException { RemoteAdmin remoteAdmin = new RemoteAdmin(new Client(cluster), getConf()); checkTable(remoteAdmin); if (nomapred) { doMultipleClients(cmd); } else { doMapReduce(cmd); } }
private boolean checkTable() throws IOException { HTableDescriptor tableDescriptor = getTableDescriptor(); RemoteAdmin admin = new RemoteAdmin(new Client(cluster), conf); if (!admin.isTableAvailable(tableDescriptor.getName())) { admin.createTable(tableDescriptor); return true; } return false; }
public static void main(String[] args) throws Exception { Cluster cluster = new Cluster(); for (String arg : args) cluster.add(arg, 8088); Client client = new Client(cluster); RemoteAdmin remoteAdmin = new RemoteAdmin(client, new Configuration()); VersionModel restVersion = remoteAdmin.getRestVersion(); System.out.println(restVersion.toString()); }
private boolean checkTable() throws IOException { HTableDescriptor tableDescriptor = getTableDescriptor(); RemoteAdmin admin = new RemoteAdmin(new Client(cluster), conf); if (!admin.isTableAvailable(tableDescriptor.getTableName().getName())) { admin.createTable(tableDescriptor); return true; } return false; }