Search in sources :

Example 16 with TResult

use of org.apache.hadoop.hbase.thrift2.generated.TResult in project hbase by apache.

the class TestThriftHBaseServiceHandlerWithLabels method testGetsWithLabels.

@Test
public void testGetsWithLabels() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    byte[] rowName = "testPutGet".getBytes();
    ByteBuffer table = wrap(tableAname);
    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);
    put.setCellVisibility(new TCellVisibility().setExpression("(" + SECRET + "|" + CONFIDENTIAL + ")" + "&" + "!" + TOPSECRET));
    handler.put(table, put);
    TGet get = new TGet(wrap(rowName));
    TAuthorization tauth = new TAuthorization();
    List<String> labels = new ArrayList<>(2);
    labels.add(SECRET);
    labels.add(PRIVATE);
    tauth.setLabels(labels);
    get.setAuthorizations(tauth);
    TResult result = handler.get(table, get);
    assertArrayEquals(rowName, result.getRow());
    List<TColumnValue> returnedColumnValues = result.getColumnValues();
    assertTColumnValuesEqual(columnValues, returnedColumnValues);
}
Also used : TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) ArrayList(java.util.ArrayList) TAuthorization(org.apache.hadoop.hbase.thrift2.generated.TAuthorization) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) ByteBuffer(java.nio.ByteBuffer) TResult(org.apache.hadoop.hbase.thrift2.generated.TResult) TCellVisibility(org.apache.hadoop.hbase.thrift2.generated.TCellVisibility) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) Test(org.junit.Test)

Example 17 with TResult

use of org.apache.hadoop.hbase.thrift2.generated.TResult in project hbase by apache.

the class ThriftHBaseServiceHandler method getScannerRows.

@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);
    }
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) TIllegalArgument(org.apache.hadoop.hbase.thrift2.generated.TIllegalArgument) IOException(java.io.IOException)

Example 18 with TResult

use of org.apache.hadoop.hbase.thrift2.generated.TResult in project hbase by apache.

the class DemoClient method run.

public void run() throws Exception {
    int timeout = 10000;
    boolean framed = false;
    TTransport transport = new TSocket(host, port, timeout);
    if (framed) {
        transport = new TFramedTransport(transport);
    } else if (secure) {
        /**
       * The Thrift server the DemoClient is trying to connect to
       * must have a matching principal, and support authentication.
       *
       * The HBase cluster must be secure, allow proxy user.
       */
        Map<String, String> saslProperties = new HashMap<>();
        saslProperties.put(Sasl.QOP, "auth-conf,auth-int,auth");
        transport = new TSaslClientTransport("GSSAPI", null, // Thrift server user name, should be an authorized proxy user
        user != null ? user : "hbase", // Thrift server domain
        host, saslProperties, null, transport);
    }
    TProtocol protocol = new TBinaryProtocol(transport);
    // This is our thrift client.
    THBaseService.Iface client = new THBaseService.Client(protocol);
    // open the transport
    transport.open();
    ByteBuffer table = ByteBuffer.wrap("example".getBytes());
    TPut put = new TPut();
    put.setRow("row1".getBytes());
    TColumnValue columnValue = new TColumnValue();
    columnValue.setFamily("family1".getBytes());
    columnValue.setQualifier("qualifier1".getBytes());
    columnValue.setValue("value1".getBytes());
    List<TColumnValue> columnValues = new ArrayList<>(1);
    columnValues.add(columnValue);
    put.setColumnValues(columnValues);
    client.put(table, put);
    TGet get = new TGet();
    get.setRow("row1".getBytes());
    TResult result = client.get(table, get);
    System.out.print("row = " + new String(result.getRow()));
    for (TColumnValue resultColumnValue : result.getColumnValues()) {
        System.out.print("family = " + new String(resultColumnValue.getFamily()));
        System.out.print("qualifier = " + new String(resultColumnValue.getFamily()));
        System.out.print("value = " + new String(resultColumnValue.getValue()));
        System.out.print("timestamp = " + resultColumnValue.getTimestamp());
    }
    transport.close();
}
Also used : TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) ArrayList(java.util.ArrayList) TSaslClientTransport(org.apache.thrift.transport.TSaslClientTransport) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) ByteBuffer(java.nio.ByteBuffer) TResult(org.apache.hadoop.hbase.thrift2.generated.TResult) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransport(org.apache.thrift.transport.TTransport) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) HashMap(java.util.HashMap) Map(java.util.Map) TSocket(org.apache.thrift.transport.TSocket) THBaseService(org.apache.hadoop.hbase.thrift2.generated.THBaseService)

Example 19 with TResult

use of org.apache.hadoop.hbase.thrift2.generated.TResult in project hbase by apache.

the class TestThriftHBaseServiceHandler method testCheckAndPut.

/**
   * check that checkAndPut fails if the cell does not exist, then put in the cell, then check
   * that the checkAndPut succeeds.
   *
   * @throws Exception
   */
@Test
public void testCheckAndPut() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    byte[] rowName = "testCheckAndPut".getBytes();
    ByteBuffer table = wrap(tableAname);
    List<TColumnValue> columnValuesA = new ArrayList<>(1);
    TColumnValue columnValueA = new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname));
    columnValuesA.add(columnValueA);
    TPut putA = new TPut(wrap(rowName), columnValuesA);
    putA.setColumnValues(columnValuesA);
    List<TColumnValue> columnValuesB = new ArrayList<>(1);
    TColumnValue columnValueB = new TColumnValue(wrap(familyBname), wrap(qualifierBname), wrap(valueBname));
    columnValuesB.add(columnValueB);
    TPut putB = new TPut(wrap(rowName), columnValuesB);
    putB.setColumnValues(columnValuesB);
    assertFalse(handler.checkAndPut(table, wrap(rowName), wrap(familyAname), wrap(qualifierAname), wrap(valueAname), putB));
    TGet get = new TGet(wrap(rowName));
    TResult result = handler.get(table, get);
    assertEquals(0, result.getColumnValuesSize());
    handler.put(table, putA);
    assertTrue(handler.checkAndPut(table, wrap(rowName), wrap(familyAname), wrap(qualifierAname), wrap(valueAname), putB));
    result = handler.get(table, get);
    assertArrayEquals(rowName, result.getRow());
    List<TColumnValue> returnedColumnValues = result.getColumnValues();
    List<TColumnValue> expectedColumnValues = new ArrayList<>(2);
    expectedColumnValues.add(columnValueA);
    expectedColumnValues.add(columnValueB);
    assertTColumnValuesEqual(expectedColumnValues, returnedColumnValues);
}
Also used : TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) ArrayList(java.util.ArrayList) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) ByteBuffer(java.nio.ByteBuffer) TResult(org.apache.hadoop.hbase.thrift2.generated.TResult) Test(org.junit.Test)

Example 20 with TResult

use of org.apache.hadoop.hbase.thrift2.generated.TResult in project hbase by apache.

the class TestThriftHBaseServiceHandler method testLongLivedScan.

/**
   * Tests keeping a HBase scanner alive for long periods of time. Each call to getScannerRow()
   * should reset the ConnectionCache timeout for the scanner's connection
   * @throws Exception
   */
@Test
public void testLongLivedScan() throws Exception {
    int numTrials = 6;
    int trialPause = 1000;
    int cleanUpInterval = 100;
    Configuration conf = new Configuration(UTIL.getConfiguration());
    // Set the ConnectionCache timeout to trigger halfway through the trials
    conf.setInt(ThriftHBaseServiceHandler.MAX_IDLETIME, (numTrials / 2) * trialPause);
    conf.setInt(ThriftHBaseServiceHandler.CLEANUP_INTERVAL, cleanUpInterval);
    ThriftHBaseServiceHandler handler = new ThriftHBaseServiceHandler(conf, UserProvider.instantiate(conf));
    ByteBuffer table = wrap(tableAname);
    // insert data
    TColumnValue columnValue = new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname));
    List<TColumnValue> columnValues = new ArrayList<>(1);
    columnValues.add(columnValue);
    for (int i = 0; i < numTrials; i++) {
        TPut put = new TPut(wrap(("testScan" + i).getBytes()), columnValues);
        handler.put(table, put);
    }
    // create scan instance
    TScan scan = new TScan();
    List<TColumn> columns = new ArrayList<>(1);
    TColumn column = new TColumn();
    column.setFamily(familyAname);
    column.setQualifier(qualifierAname);
    columns.add(column);
    scan.setColumns(columns);
    scan.setStartRow("testScan".getBytes());
    scan.setStopRow("testScan￿".getBytes());
    // Prevent the scanner from caching results
    scan.setCaching(1);
    // get scanner and rows
    int scanId = handler.openScanner(table, scan);
    for (int i = 0; i < numTrials; i++) {
        // Make sure that the Scanner doesn't throw an exception after the ConnectionCache timeout
        List<TResult> results = handler.getScannerRows(scanId, 1);
        assertArrayEquals(("testScan" + i).getBytes(), results.get(0).getRow());
        Thread.sleep(trialPause);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) TColumn(org.apache.hadoop.hbase.thrift2.generated.TColumn) ArrayList(java.util.ArrayList) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) ByteBuffer(java.nio.ByteBuffer) TResult(org.apache.hadoop.hbase.thrift2.generated.TResult) TScan(org.apache.hadoop.hbase.thrift2.generated.TScan) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) Test(org.junit.Test)

Aggregations

TResult (org.apache.hadoop.hbase.thrift2.generated.TResult)31 ByteBuffer (java.nio.ByteBuffer)29 TColumnValue (org.apache.hadoop.hbase.thrift2.generated.TColumnValue)29 TPut (org.apache.hadoop.hbase.thrift2.generated.TPut)28 ArrayList (java.util.ArrayList)27 Test (org.junit.Test)27 TGet (org.apache.hadoop.hbase.thrift2.generated.TGet)20 TColumn (org.apache.hadoop.hbase.thrift2.generated.TColumn)12 TScan (org.apache.hadoop.hbase.thrift2.generated.TScan)9 TIllegalArgument (org.apache.hadoop.hbase.thrift2.generated.TIllegalArgument)7 TAuthorization (org.apache.hadoop.hbase.thrift2.generated.TAuthorization)6 TCellVisibility (org.apache.hadoop.hbase.thrift2.generated.TCellVisibility)6 TDelete (org.apache.hadoop.hbase.thrift2.generated.TDelete)5 HashMap (java.util.HashMap)4 IOException (java.io.IOException)3 Table (org.apache.hadoop.hbase.client.Table)3 TColumnIncrement (org.apache.hadoop.hbase.thrift2.generated.TColumnIncrement)3 THBaseService (org.apache.hadoop.hbase.thrift2.generated.THBaseService)3 TIncrement (org.apache.hadoop.hbase.thrift2.generated.TIncrement)3 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)2