Hbase.Client client = new Hbase.Client(protocol); for (ByteBuffer name : client.getTableNames()) { System.out.println(" found: " + utf8(name.array())); if (utf8(name.array()).equals(utf8(t))) { if (client.isTableEnabled(name)) { System.out.println(" disabling table: " + utf8(name.array())); client.disableTable(name); client.deleteTable(name); client.createTable(ByteBuffer.wrap(t), columns); } catch (AlreadyExists ae) { System.out.println("WARN: " + ae.message); Map<ByteBuffer, ColumnDescriptor> columnMap = client.getColumnDescriptors(ByteBuffer.wrap(t)); for (ColumnDescriptor col2 : columnMap.values()) { System.out.println(" column: " + utf8(col2.name.array()) + ", maxVer: " + Integer.toString(col2.maxVersions)); mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:foo")), ByteBuffer.wrap(invalid), writeToWal)); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(bytes("foo")), mutations, dummyAttributes); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(valid), mutations, dummyAttributes); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(invalid), mutations, dummyAttributes); int scanner = client.scannerOpen(ByteBuffer.wrap(t), ByteBuffer.wrap(bytes("")), columnNames, dummyAttributes);
Hbase.Client client = new Hbase.Client(protocol); for (ByteBuffer name : client.getTableNames()) { System.out.println(" found: " + utf8(name.array())); if (utf8(name.array()).equals(utf8(t))) { if (client.isTableEnabled(name)) { System.out.println(" disabling table: " + utf8(name.array())); client.disableTable(name); client.deleteTable(name); client.createTable(ByteBuffer.wrap(t), columns); } catch (AlreadyExists ae) { System.out.println("WARN: " + ae.message); Map<ByteBuffer, ColumnDescriptor> columnMap = client.getColumnDescriptors(ByteBuffer.wrap(t)); for (ColumnDescriptor col2 : columnMap.values()) { System.out.println(" column: " + utf8(col2.name.array()) + ", maxVer: " + Integer.toString(col2.maxVersions)); mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:foo")), ByteBuffer.wrap(invalid), writeToWal)); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(bytes("foo")), mutations, dummyAttributes); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(valid), mutations, dummyAttributes); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(invalid), mutations, dummyAttributes); int scanner = client.scannerOpen(ByteBuffer.wrap(t), ByteBuffer.wrap(bytes("")), columnNames, dummyAttributes);
httpClient.open(); TProtocol protocol = new TBinaryProtocol(httpClient); Hbase.Client client = new Hbase.Client(protocol); for (ByteBuffer name : refresh(client, httpClient).getTableNames()) { System.out.println(" found: " + utf8(name.array())); if (utf8(name.array()).equals(utf8(t))) { if (refresh(client, httpClient).isTableEnabled(name)) { System.out.println(" disabling table: " + utf8(name.array())); refresh(client, httpClient).disableTable(name); refresh(client, httpClient).deleteTable(name); try { refresh(client, httpClient).createTable(ByteBuffer.wrap(t), columns); } catch (AlreadyExists ae) { System.out.println("WARN: " + ae.message); .getColumnDescriptors(ByteBuffer.wrap(t)); for (ColumnDescriptor col2 : columnMap.values()) { System.out.println(" column: " + utf8(col2.name.array()) + ", maxVer: " + Integer.toString(col2.maxVersions));
client = new Hbase.Client(protocol); try { transport.open();
private void addOrUpdateRow(String tableName, Row row, List<Mutation> mutations) { int size=0; if (row!=null) { for (Column c: row.getColumns()) { size+=(c.getValue().length); } } try { synchronized (mutex) { client.mutateRow(ByteBuffer.wrap(tableName.getBytes()), ByteBuffer.wrap(row.getId()), mutations, Collections.<ByteBuffer, ByteBuffer> emptyMap()); } } catch (IOError e) { log.error("Problem with row : "+((row==null || row.getId()==null)?"null" :new String(row.getId()))+" size : "+ size); throw new ModifyTableException(e); } catch (IllegalArgument e) { log.error("Problem with row : "+((row==null || row.getId()==null)?"null" :new String(row.getId()))+" size : "+ size); throw new ModifyTableException(e); } catch (TException e) { log.error("Problem with row : "+((row==null || row.getId()==null)?"null" :new String(row.getId()))+" size : "+ size); throw new ModifyTableException(e); } }
void talkToThriftServer(String url, int customHeaderSize) throws Exception { THttpClient httpClient = new THttpClient(url); httpClient.open(); if (customHeaderSize > 0) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < customHeaderSize; i++) { sb.append("a"); } httpClient.setCustomHeader("User-Agent", sb.toString()); } try { TProtocol prot; prot = new TBinaryProtocol(httpClient); Hbase.Client client = new Hbase.Client(prot); if (!tableCreated){ TestThriftServer.createTestTables(client); tableCreated = true; } TestThriftServer.checkTableList(client); } finally { httpClient.close(); } }
private List<TRowResult> getRawRows(String tableName, Row startRow, int numberOfRows) { int scannerId; List<TRowResult> tRowResultList; try { synchronized (mutex) { List<ByteBuffer> columnNames=null; if (startRow!=null) { columnNames= startRow.getColumnNames(); } scannerId = client.scannerOpen( ByteBuffer.wrap(tableName.getBytes()), ByteBuffer.wrap(startRow==null?"".getBytes():startRow.getId()), columnNames, null); tRowResultList = client.scannerGetList(scannerId, numberOfRows); } } catch (IOError e) { throw new ReadTableException(EXCEPTION_DURING_FETCHING_ROWS, e); } catch (TException e) { throw new ReadTableException(EXCEPTION_DURING_FETCHING_ROWS, e); } return tRowResultList; }
private void talkToThriftServer() throws Exception { TSocket sock = new TSocket(InetAddress.getLocalHost().getHostName(), port); TTransport transport = sock; if (specifyFramed || implType.isAlwaysFramed) { transport = new TFramedTransport(transport); } sock.open(); try { TProtocol prot; if (specifyCompact) { prot = new TCompactProtocol(transport); } else { prot = new TBinaryProtocol(transport); } Hbase.Client client = new Hbase.Client(prot); if (!tableCreated){ TestThriftServer.createTestTables(client); tableCreated = true; } TestThriftServer.checkTableList(client); } finally { sock.close(); } }
@Override void talkToThriftServer(String url, int customHeaderSize) throws Exception { // Close httpClient and THttpClient automatically on any failures try ( CloseableHttpClient httpClient = createHttpClient(); THttpClient tHttpClient = new THttpClient(url, httpClient) ) { tHttpClient.open(); if (customHeaderSize > 0) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < customHeaderSize; i++) { sb.append("a"); } tHttpClient.setCustomHeader(HttpHeaders.USER_AGENT, sb.toString()); } TProtocol prot = new TBinaryProtocol(tHttpClient); Hbase.Client client = new Hbase.Client(prot); if (!tableCreated) { TestThriftServer.createTestTables(client); tableCreated = true; } TestThriftServer.checkTableList(client); } }
private int getScanner(String tableName, Row startRow) { int scannerId; try { synchronized (mutex) { List<ByteBuffer> columnNames=null; if (startRow!=null) { columnNames= startRow.getColumnNames(); } scannerId = client.scannerOpen( ByteBuffer.wrap(tableName.getBytes()), ByteBuffer.wrap(startRow==null?"".getBytes():startRow.getId()), columnNames, null); } } catch (IOError e) { throw new ScannerException(EXCEPTION_DURING_OPENNING_SCANNER, e); } catch (TException e) { throw new ScannerException(EXCEPTION_DURING_OPENNING_SCANNER, e); } return scannerId; }
private void talkToThriftServer() throws Exception { TSocket sock = new TSocket(InetAddress.getLocalHost().getHostName(), port); TTransport transport = sock; if (specifyFramed || implType.isAlwaysFramed) { transport = new TFramedTransport(transport); } sock.open(); try { TProtocol prot; if (specifyCompact) { prot = new TCompactProtocol(transport); } else { prot = new TBinaryProtocol(transport); } Hbase.Client client = new Hbase.Client(prot); if (!tableCreated){ TestThriftServer.createTestTables(client); tableCreated = true; } TestThriftServer.checkTableList(client); } finally { sock.close(); } }
@Test(timeout = TestConstants.ITEST_TIMEOUT) public void test() throws Exception { ArrayList<ColumnDescriptor> columns = new ArrayList<ColumnDescriptor>(); ColumnDescriptor cd = new ColumnDescriptor(); cd.name = FAMILY1; columns.add(cd); cd = new ColumnDescriptor(); cd.name = FAMILY2; columns.add(cd); Hbase.Client client = controller.getThriftClient(); client.createTable(TABLE, columns); ArrayList<Mutation> mutations = new ArrayList<Mutation>(); mutations.add(new Mutation(false, COLUMN, VALUE, true)); client.mutateRow(TABLE, ROW, mutations, null); int scan1 = client.scannerOpen(TABLE, FIRST, Lists.newArrayList(FAMILY1), null); List<TRowResult> rows = client.scannerGet(scan1); assertThat(rows.size(), is(1)); assertThat(Bytes.toString(rows.get(0).getRow()), is("testRow")); assertTrue("No more rows", client.scannerGet(scan1).isEmpty()); client.scannerClose(scan1); int scan2 = client.scannerOpen(TABLE, FIRST, Lists.newArrayList(FAMILY2), null); assertTrue("No more rows", client.scannerGet(scan2).isEmpty()); client.scannerClose(scan2); }
private void talkToThriftServer(int customHeaderSize) throws Exception { THttpClient httpClient = new THttpClient( "http://"+ HConstants.LOCALHOST + ":" + port); httpClient.open(); if (customHeaderSize > 0) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < customHeaderSize; i++) { sb.append("a"); } httpClient.setCustomHeader("User-Agent", sb.toString()); } try { TProtocol prot; prot = new TBinaryProtocol(httpClient); Hbase.Client client = new Hbase.Client(prot); if (!tableCreated){ TestThriftServer.createTestTables(client); tableCreated = true; } TestThriftServer.checkTableList(client); } finally { httpClient.close(); } }
private static boolean testThrift(String host) { boolean ret = false; TTransport transport = null; try { transport = new TSocket(host, 9090, 3000); Hbase.Client client = new Hbase.Client(new TBinaryProtocol(transport)); transport.open(); client.getColumnDescriptors(ByteBuffer.wrap(META_TABLE_NAME)); System.out.println(String.format("%s ThriftServer - [ ALIVE ]", new Object[] { host })); ret = true; } catch (TTransportException e) { System.out.println(String.format("%s ThriftServer - [ DEAD ] - %s", new Object[] { host, e.getMessage() })); } catch (IOError e) { System.out.println(String.format("%s ThriftServer - [ DEAD ] - %s", new Object[] { host, e.getMessage() })); } catch (TException e) { System.out.println(String.format("%s ThriftServer - [ DEAD ] - %s", new Object[] { host, e.getMessage() })); } finally { if (transport != null) { transport.close(); } } return ret; }
private void createTable(String tableName, List<ColumnDescriptor> columns) { try { synchronized (mutex) { client.createTable(ByteBuffer.wrap(tableName.getBytes()), columns); } } catch (IOError e) { throw new CreateTableException(e); } catch (IllegalArgument e) { throw new CreateTableException(e); } catch (AlreadyExists e) { throw new CreateTableException(e); } catch (TException e) { throw new CreateTableException(e); } }
private void getScanner(InetAddress thriftAddress) throws Exception { TTransport transport = new TSocket(thriftAddress.getHostName(), HBaseThriftServerClusterActionHandler.PORT); transport.open(); LOG.info("Connected to thrift server."); LOG.info("Waiting for .META. table..."); TProtocol protocol = new TBinaryProtocol(transport, true, true); Hbase.Client client = new Hbase.Client(protocol); int scannerId = client.scannerOpen(ByteBuffer.wrap(HConstants.META_TABLE_NAME), ByteBuffer.wrap(Bytes.toBytes("")), null, null); client.scannerClose(scannerId); thriftClient = client; }
public void deleteTable(String tableName) { try { synchronized (mutex) { client.disableTable(ByteBuffer.wrap(tableName.getBytes())); client.deleteTable(ByteBuffer.wrap(tableName.getBytes())); } } catch (IOError e) { throw new DeleteTableException(e); } catch (TException e) { throw new DeleteTableException(e); } }
private void closeScanner(int scannerId) throws IOException { try { synchronized (mutex) { client.scannerClose(scannerId); } } catch (IOError e) { throw new IOException(EXCEPTION_DURING_CLOSING_SCANNER, e); } catch (IllegalArgument e) { throw new IOException(EXCEPTION_DURING_CLOSING_SCANNER, e); } catch (TException e) { throw new IOException(EXCEPTION_DURING_CLOSING_SCANNER, e); } }
@Override public void deleteRow(String tableName, Row row) { try { synchronized (mutex) { client.deleteAllRow(ByteBuffer.wrap(tableName.getBytes()), ByteBuffer.wrap(row.getId()), null); } } catch (IOError e) { throw new ModifyTableException(e); } catch (TException e) { throw new ModifyTableException(e); } }
Hbase.Client client = new Hbase.Client(protocol); columns.add(cd); client.createTable(ByteBuffer.wrap(TABLE), columns); mutations.add(new Mutation(false, ByteBuffer.wrap(COLUMN2), ByteBuffer.wrap(VALUE), true)); client.mutateRow(ByteBuffer.wrap(TABLE), ByteBuffer.wrap(ROW), mutations, null); int scannerId = client.scannerOpenWithScan(ByteBuffer.wrap(TABLE), scan, null); for (TRowResult result : client.scannerGet(scannerId)) { System.out.println("No. columns: " + result.getColumnsSize()); for (Map.Entry<ByteBuffer, TCell> column : client.scannerClose(scannerId); scannerId = client.scannerOpen(ByteBuffer.wrap(TABLE), ByteBuffer.wrap(Bytes.toBytes("")), columnNames, null); for (TRowResult result : client.scannerGet(scannerId)) { System.out.println("No. columns: " + result.getColumnsSize()); for (Map.Entry<ByteBuffer, TCell> column : client.scannerClose(scannerId);