@Override public boolean checkAndDelete(ByteBuffer table, ByteBuffer row, ByteBuffer family, ByteBuffer qualifier, ByteBuffer value, TDelete deleteSingle) throws TIOError, TException { Table htable = getTable(table); try { if (value == null) { return htable.checkAndDelete(byteBufferToByteArray(row), byteBufferToByteArray(family), byteBufferToByteArray(qualifier), null, deleteFromThrift(deleteSingle)); } else { return htable.checkAndDelete(byteBufferToByteArray(row), byteBufferToByteArray(family), byteBufferToByteArray(qualifier), byteBufferToByteArray(value), deleteFromThrift(deleteSingle)); } } catch (IOException e) { throw getTIOError(e); } finally { closeTable(htable); } }
@Override public List<TResult> getScannerRows(int scannerId, int numRows) throws TIOError, TIllegalArgument, TException { ResultScanner scanner = getScanner(scannerId); if (scanner == null) { TIllegalArgument ex = new TIllegalArgument(); ex.setMessage("Invalid scanner Id"); throw ex; } try { return resultsFromHBase(scanner.next(numRows)); } catch (IOException e) { throw getTIOError(e); } }
@Override public List<TResult> getScannerResults(ByteBuffer table, TScan scan, int numRows) throws TIOError, TException { Table htable = getTable(table); List<TResult> results = null; ResultScanner scanner = null; try { scanner = htable.getScanner(scanFromThrift(scan)); results = resultsFromHBase(scanner.next(numRows)); } catch (IOException e) { throw getTIOError(e); } finally { if (scanner != null) { scanner.close(); } closeTable(htable); } return results; }
@Test public void testExists() throws TIOError, TException { ThriftHBaseServiceHandler handler = createHandler(); byte[] rowName = "testExists".getBytes(); ByteBuffer table = wrap(tableAname); TGet get = new TGet(wrap(rowName)); assertFalse(handler.exists(table, get)); List<TColumnValue> columnValues = new ArrayList<TColumnValue>(); columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname))); columnValues.add(new TColumnValue(wrap(familyBname), wrap(qualifierBname), wrap(valueBname))); TPut put = new TPut(wrap(rowName), columnValues); put.setColumnValues(columnValues); handler.put(table, put); assertTrue(handler.exists(table, get)); }
@Override public boolean checkAndDelete(ByteBuffer table, ByteBuffer row, ByteBuffer family, ByteBuffer qualifier, ByteBuffer value, TDelete deleteSingle) throws TIOError, TException { HTableInterface htable = getTable(table); try { if (value == null) { return htable.checkAndDelete(byteBufferToByteArray(row), byteBufferToByteArray(family), byteBufferToByteArray(qualifier), null, deleteFromThrift(deleteSingle)); } else { return htable.checkAndDelete(byteBufferToByteArray(row), byteBufferToByteArray(family), byteBufferToByteArray(qualifier), byteBufferToByteArray(value), deleteFromThrift(deleteSingle)); } } catch (IOException e) { throw getTIOError(e); } finally { closeTable(htable); } }
@Override public List<TResult> getScannerResults(ByteBuffer table, TScan scan, int numRows) throws TIOError, TException { HTableInterface htable = getTable(table); List<TResult> results = null; ResultScanner scanner = null; try { scanner = htable.getScanner(scanFromThrift(scan)); results = resultsFromHBase(scanner.next(numRows)); } catch (IOException e) { throw getTIOError(e); } finally { if (scanner != null) { scanner.close(); } closeTable(htable); } return results; }
@Override public List<Boolean> existsAll(ByteBuffer table, List<TGet> gets) throws TIOError, TException { Table htable = getTable(table); try { boolean[] exists = htable.existsAll(getsFromThrift(gets)); List<Boolean> result = new ArrayList<>(exists.length); for (boolean exist : exists) { result.add(exist); } return result; } catch (IOException e) { throw getTIOError(e); } finally { closeTable(htable); } }
@Override public boolean checkAndPut(ByteBuffer table, ByteBuffer row, ByteBuffer family, ByteBuffer qualifier, ByteBuffer value, TPut put) throws TIOError, TException { checkReadOnlyMode(); Table htable = getTable(table); try { Table.CheckAndMutateBuilder builder = htable.checkAndMutate(byteBufferToByteArray(row), byteBufferToByteArray(family)).qualifier(byteBufferToByteArray(qualifier)); if (value == null) { return builder.ifNotExists().thenPut(putFromThrift(put)); } else { return builder.ifEquals(byteBufferToByteArray(value)).thenPut(putFromThrift(put)); } } catch (IOException e) { throw getTIOError(e); } finally { closeTable(htable); } }
@Override public boolean checkAndDelete(ByteBuffer table, ByteBuffer row, ByteBuffer family, ByteBuffer qualifier, ByteBuffer value, TDelete deleteSingle) throws TIOError, TException { checkReadOnlyMode(); Table htable = getTable(table); try { Table.CheckAndMutateBuilder mutateBuilder = htable.checkAndMutate(byteBufferToByteArray(row), byteBufferToByteArray(family)) .qualifier(byteBufferToByteArray(qualifier)); if (value == null) { return mutateBuilder.ifNotExists().thenDelete(deleteFromThrift(deleteSingle)); } else { return mutateBuilder.ifEquals(byteBufferToByteArray(value)) .thenDelete(deleteFromThrift(deleteSingle)); } } catch (IOException e) { throw getTIOError(e); } finally { closeTable(htable); } }
@Override public List<TResult> getScannerRows(int scannerId, int numRows) throws TIOError, TIllegalArgument, TException { ResultScanner scanner = getScanner(scannerId); if (scanner == null) { TIllegalArgument ex = new TIllegalArgument(); ex.setMessage("Invalid scanner Id"); throw ex; } try { connectionCache.updateConnectionAccessTime(); return resultsFromHBase(scanner.next(numRows)); } catch (IOException e) { throw getTIOError(e); } }
@Test public void testExistsWithReadOnly() throws TException { ThriftHBaseServiceHandler handler = createHandler(); byte[] rowName = Bytes.toBytes("testExists"); ByteBuffer table = wrap(tableAname); TGet get = new TGet(wrap(rowName)); boolean exceptionCaught = false; try { handler.exists(table, get); } catch (TIOError e) { exceptionCaught = true; } finally { assertFalse(exceptionCaught); } }
@Test public void testExistsAllWithReadOnly() throws TException { ThriftHBaseServiceHandler handler = createHandler(); byte[] rowName1 = Bytes.toBytes("testExistsAll1"); byte[] rowName2 = Bytes.toBytes("testExistsAll2"); ByteBuffer table = wrap(tableAname); List<TGet> gets = new ArrayList<>(); gets.add(new TGet(wrap(rowName1))); gets.add(new TGet(wrap(rowName2))); boolean exceptionCaught = false; try { handler.existsAll(table, gets); } catch (TIOError e) { exceptionCaught = true; } finally { assertFalse(exceptionCaught); } }
@Test public void testGetWithReadOnly() throws Exception { ThriftHBaseServiceHandler handler = createHandler(); byte[] rowName = Bytes.toBytes("testGet"); ByteBuffer table = wrap(tableAname); TGet get = new TGet(wrap(rowName)); boolean exceptionCaught = false; try { handler.get(table, get); } catch (TIOError e) { exceptionCaught = true; } finally { assertFalse(exceptionCaught); } }
@Test public void testGetMultipleWithReadOnly() throws Exception { ThriftHBaseServiceHandler handler = createHandler(); ByteBuffer table = wrap(tableAname); byte[] rowName1 = Bytes.toBytes("testGetMultiple1"); byte[] rowName2 = Bytes.toBytes("testGetMultiple2"); List<TGet> gets = new ArrayList<>(2); gets.add(new TGet(wrap(rowName1))); gets.add(new TGet(wrap(rowName2))); boolean exceptionCaught = false; try { handler.getMultiple(table, gets); } catch (TIOError e) { exceptionCaught = true; } finally { assertFalse(exceptionCaught); } }
@Test public void testPutWithReadOnly() throws Exception { ThriftHBaseServiceHandler handler = createHandler(); ByteBuffer table = wrap(tableAname); byte[] rowName = Bytes.toBytes("testPut"); List<TColumnValue> columnValues = new ArrayList<>(2); columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname))); columnValues.add(new TColumnValue(wrap(familyBname), wrap(qualifierBname), wrap(valueBname))); TPut put = new TPut(wrap(rowName), columnValues); boolean exceptionCaught = false; try { handler.put(table, put); } catch (TIOError e) { exceptionCaught = true; assertTrue(e.getCause() instanceof DoNotRetryIOException); assertEquals("Thrift Server is in Read-only mode.", e.getMessage()); } finally { assertTrue(exceptionCaught); } }
@Test public void testPutMultipleWithReadOnly() throws Exception { ThriftHBaseServiceHandler handler = createHandler(); ByteBuffer table = wrap(tableAname); byte[] rowName1 = Bytes.toBytes("testPutMultiple1"); byte[] rowName2 = Bytes.toBytes("testPutMultiple2"); List<TColumnValue> columnValues = new ArrayList<>(2); columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname))); columnValues.add(new TColumnValue(wrap(familyBname), wrap(qualifierBname), wrap(valueBname))); List<TPut> puts = new ArrayList<>(2); puts.add(new TPut(wrap(rowName1), columnValues)); puts.add(new TPut(wrap(rowName2), columnValues)); boolean exceptionCaught = false; try { handler.putMultiple(table, puts); } catch (TIOError e) { exceptionCaught = true; assertTrue(e.getCause() instanceof DoNotRetryIOException); assertEquals("Thrift Server is in Read-only mode.", e.getMessage()); } finally { assertTrue(exceptionCaught); } }
@Test public void testDeleteWithReadOnly() throws Exception { ThriftHBaseServiceHandler handler = createHandler(); byte[] rowName = Bytes.toBytes("testDelete"); ByteBuffer table = wrap(tableAname); TDelete delete = new TDelete(wrap(rowName)); boolean exceptionCaught = false; try { handler.deleteSingle(table, delete); } catch (TIOError e) { exceptionCaught = true; assertTrue(e.getCause() instanceof DoNotRetryIOException); assertEquals("Thrift Server is in Read-only mode.", e.getMessage()); } finally { assertTrue(exceptionCaught); } }
@Test public void testDeleteMultipleWithReadOnly() throws Exception { ThriftHBaseServiceHandler handler = createHandler(); ByteBuffer table = wrap(tableAname); byte[] rowName1 = Bytes.toBytes("testDeleteMultiple1"); byte[] rowName2 = Bytes.toBytes("testDeleteMultiple2"); List<TDelete> deletes = new ArrayList<>(2); deletes.add(new TDelete(wrap(rowName1))); deletes.add(new TDelete(wrap(rowName2))); boolean exceptionCaught = false; try { handler.deleteMultiple(table, deletes); } catch (TIOError e) { exceptionCaught = true; assertTrue(e.getCause() instanceof DoNotRetryIOException); assertEquals("Thrift Server is in Read-only mode.", e.getMessage()); } finally { assertTrue(exceptionCaught); } }
@Test public void testCheckAndDeleteWithReadOnly() throws Exception { ThriftHBaseServiceHandler handler = createHandler(); byte[] rowName = Bytes.toBytes("testCheckAndDelete"); ByteBuffer table = wrap(tableAname); TDelete delete = new TDelete(wrap(rowName)); boolean exceptionCaught = false; try { handler.checkAndDelete(table, wrap(rowName), wrap(familyAname), wrap(qualifierAname), wrap(valueAname), delete); } catch (TIOError e) { exceptionCaught = true; assertTrue(e.getCause() instanceof DoNotRetryIOException); assertEquals("Thrift Server is in Read-only mode.", e.getMessage()); } finally { assertTrue(exceptionCaught); } }
@Test public void testIncrementWithReadOnly() throws Exception { ThriftHBaseServiceHandler handler = createHandler(); byte[] rowName = Bytes.toBytes("testIncrement"); ByteBuffer table = wrap(tableAname); List<TColumnIncrement> incrementColumns = new ArrayList<>(1); incrementColumns.add(new TColumnIncrement(wrap(familyAname), wrap(qualifierAname))); TIncrement increment = new TIncrement(wrap(rowName), incrementColumns); boolean exceptionCaught = false; try { handler.increment(table, increment); } catch (TIOError e) { exceptionCaught = true; assertTrue(e.getCause() instanceof DoNotRetryIOException); assertEquals("Thrift Server is in Read-only mode.", e.getMessage()); } finally { assertTrue(exceptionCaught); } }
@Test public void testAppendWithReadOnly() throws Exception { ThriftHBaseServiceHandler handler = createHandler(); byte[] rowName = Bytes.toBytes("testAppend"); ByteBuffer table = wrap(tableAname); byte[] v1 = Bytes.toBytes("42"); List<TColumnValue> appendColumns = new ArrayList<>(1); appendColumns.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(v1))); TAppend append = new TAppend(wrap(rowName), appendColumns); boolean exceptionCaught = false; try { handler.append(table, append); } catch (TIOError e) { exceptionCaught = true; assertTrue(e.getCause() instanceof DoNotRetryIOException); assertEquals("Thrift Server is in Read-only mode.", e.getMessage()); } finally { assertTrue(exceptionCaught); } }
@Test public void testScanWithReadOnly() throws Exception { ThriftHBaseServiceHandler handler = createHandler(); ByteBuffer table = wrap(tableAname); TScan scan = new TScan(); boolean exceptionCaught = false; try { int scanId = handler.openScanner(table, scan); handler.getScannerRows(scanId, 10); handler.closeScanner(scanId); } catch (TIOError e) { exceptionCaught = true; } finally { assertFalse(exceptionCaught); } }
@Test public void testExists() throws TIOError, TException { ThriftHBaseServiceHandler handler = createHandler(); byte[] rowName = Bytes.toBytes("testExists"); ByteBuffer table = wrap(tableAname); TGet get = new TGet(wrap(rowName)); assertFalse(handler.exists(table, get)); List<TColumnValue> columnValues = new ArrayList<>(2); columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname))); columnValues.add(new TColumnValue(wrap(familyBname), wrap(qualifierBname), wrap(valueBname))); TPut put = new TPut(wrap(rowName), columnValues); put.setColumnValues(columnValues); handler.put(table, put); assertTrue(handler.exists(table, get)); }
@Override public boolean checkAndDelete(ByteBuffer table, ByteBuffer row, ByteBuffer family, ByteBuffer qualifier, ByteBuffer value, TDelete deleteSingle) throws TIOError, TException { HTableInterface htable = getTable(table.array()); try { if (value == null) { return htable.checkAndDelete(row.array(), family.array(), qualifier.array(), null, deleteFromThrift(deleteSingle)); } else { return htable.checkAndDelete(row.array(), family.array(), qualifier.array(), value.array(), deleteFromThrift(deleteSingle)); } } catch (IOException e) { throw getTIOError(e); } finally { closeTable(htable); } }
@Test public void testExists() throws TIOError, TException { ThriftHBaseServiceHandler handler = createHandler(); byte[] rowName = "testExists".getBytes(); ByteBuffer table = ByteBuffer.wrap(tableAname); TGet get = new TGet(ByteBuffer.wrap(rowName)); assertFalse(handler.exists(table, get)); List<TColumnValue> columnValues = new ArrayList<TColumnValue>(); columnValues.add(new TColumnValue(ByteBuffer.wrap(familyAname), ByteBuffer.wrap(qualifierAname), ByteBuffer .wrap(valueAname))); columnValues.add(new TColumnValue(ByteBuffer.wrap(familyBname), ByteBuffer.wrap(qualifierBname), ByteBuffer .wrap(valueBname))); TPut put = new TPut(ByteBuffer.wrap(rowName), columnValues); put.setColumnValues(columnValues); handler.put(table, put); assertTrue(handler.exists(table, get)); }