Search in sources :

Example 1 with ColumnDescriptor

use of org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor in project hbase by apache.

the class HttpDoAsClient method run.

private void run() throws Exception {
    TTransport transport = new TSocket(host, port);
    transport.open();
    String url = "http://" + host + ":" + port;
    THttpClient httpClient = new THttpClient(url);
    httpClient.open();
    TProtocol protocol = new TBinaryProtocol(httpClient);
    Hbase.Client client = new Hbase.Client(protocol);
    byte[] t = bytes("demo_table");
    // 
    // Scan all tables, look for the demo table and delete it.
    // 
    System.out.println("scanning tables...");
    for (ByteBuffer name : refresh(client, httpClient).getTableNames()) {
        System.out.println("  found: " + ClientUtils.utf8(name.array()));
        if (ClientUtils.utf8(name.array()).equals(ClientUtils.utf8(t))) {
            if (refresh(client, httpClient).isTableEnabled(name)) {
                System.out.println("    disabling table: " + ClientUtils.utf8(name.array()));
                refresh(client, httpClient).disableTable(name);
            }
            System.out.println("    deleting table: " + ClientUtils.utf8(name.array()));
            refresh(client, httpClient).deleteTable(name);
        }
    }
    // 
    // Create the demo table with two column families, entry: and unused:
    // 
    ArrayList<ColumnDescriptor> columns = new ArrayList<>(2);
    ColumnDescriptor col;
    col = new ColumnDescriptor();
    col.name = ByteBuffer.wrap(bytes("entry:"));
    col.timeToLive = Integer.MAX_VALUE;
    col.maxVersions = 10;
    columns.add(col);
    col = new ColumnDescriptor();
    col.name = ByteBuffer.wrap(bytes("unused:"));
    col.timeToLive = Integer.MAX_VALUE;
    columns.add(col);
    System.out.println("creating table: " + ClientUtils.utf8(t));
    try {
        refresh(client, httpClient).createTable(ByteBuffer.wrap(t), columns);
    } catch (AlreadyExists ae) {
        System.out.println("WARN: " + ae.message);
    }
    System.out.println("column families in " + ClientUtils.utf8(t) + ": ");
    Map<ByteBuffer, ColumnDescriptor> columnMap = refresh(client, httpClient).getColumnDescriptors(ByteBuffer.wrap(t));
    for (ColumnDescriptor col2 : columnMap.values()) {
        System.out.println("  column: " + ClientUtils.utf8(col2.name.array()) + ", maxVer: " + col2.maxVersions);
    }
    transport.close();
    httpClient.close();
}
Also used : ColumnDescriptor(org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor) ArrayList(java.util.ArrayList) THttpClient(org.apache.thrift.transport.THttpClient) ByteBuffer(java.nio.ByteBuffer) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TTransport(org.apache.thrift.transport.TTransport) THttpClient(org.apache.thrift.transport.THttpClient) AlreadyExists(org.apache.hadoop.hbase.thrift.generated.AlreadyExists) Hbase(org.apache.hadoop.hbase.thrift.generated.Hbase) TSocket(org.apache.thrift.transport.TSocket)

Example 2 with ColumnDescriptor

use of org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor in project whirr by apache.

the class Cdh3HBaseServiceTest method test.

@Test
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));
    client.mutateRow(TABLE, ROW, mutations);
    int scan1 = client.scannerOpen(TABLE, FIRST, Lists.newArrayList(FAMILY1));
    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));
    assertTrue("No more rows", client.scannerGet(scan2).isEmpty());
    client.scannerClose(scan2);
}
Also used : ColumnDescriptor(org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor) ArrayList(java.util.ArrayList) Mutation(org.apache.hadoop.hbase.thrift.generated.Mutation) TRowResult(org.apache.hadoop.hbase.thrift.generated.TRowResult) Hbase(org.apache.hadoop.hbase.thrift.generated.Hbase) Test(org.junit.Test)

Example 3 with ColumnDescriptor

use of org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor in project whirr by apache.

the class CdhHBaseServiceTest method test.

@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));
    client.mutateRow(TABLE, ROW, mutations);
    int scan1 = client.scannerOpen(TABLE, FIRST, Lists.newArrayList(FAMILY1));
    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));
    assertTrue("No more rows", client.scannerGet(scan2).isEmpty());
    client.scannerClose(scan2);
}
Also used : ColumnDescriptor(org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor) ArrayList(java.util.ArrayList) Mutation(org.apache.hadoop.hbase.thrift.generated.Mutation) TRowResult(org.apache.hadoop.hbase.thrift.generated.TRowResult) Hbase(org.apache.hadoop.hbase.thrift.generated.Hbase) Test(org.junit.Test)

Example 4 with ColumnDescriptor

use of org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor in project whirr by apache.

the class AbstractHBaseServiceTest method test.

@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);
}
Also used : ColumnDescriptor(org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor) ArrayList(java.util.ArrayList) Mutation(org.apache.hadoop.hbase.thrift.generated.Mutation) TRowResult(org.apache.hadoop.hbase.thrift.generated.TRowResult) Hbase(org.apache.hadoop.hbase.thrift.generated.Hbase) Test(org.junit.Test)

Example 5 with ColumnDescriptor

use of org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor in project hbase by apache.

the class TestThriftServer method getColumnDescriptors.

/**
 * @return a List of ColumnDescriptors for use in creating a table.  Has one
 *         default ColumnDescriptor and one ColumnDescriptor with fewer versions
 */
private static List<ColumnDescriptor> getColumnDescriptors() {
    ArrayList<ColumnDescriptor> cDescriptors = new ArrayList<>(2);
    // A default ColumnDescriptor
    ColumnDescriptor cDescA = new ColumnDescriptor();
    cDescA.name = columnAname;
    cDescriptors.add(cDescA);
    // A slightly customized ColumnDescriptor (only 2 versions)
    ColumnDescriptor cDescB = new ColumnDescriptor(columnBname, 2, "NONE", false, "NONE", 0, 0, false, -1);
    cDescriptors.add(cDescB);
    return cDescriptors;
}
Also used : ColumnDescriptor(org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor) ArrayList(java.util.ArrayList)

Aggregations

ColumnDescriptor (org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor)11 ArrayList (java.util.ArrayList)7 Hbase (org.apache.hadoop.hbase.thrift.generated.Hbase)6 Mutation (org.apache.hadoop.hbase.thrift.generated.Mutation)5 TRowResult (org.apache.hadoop.hbase.thrift.generated.TRowResult)5 Test (org.junit.Test)4 ByteBuffer (java.nio.ByteBuffer)3 AlreadyExists (org.apache.hadoop.hbase.thrift.generated.AlreadyExists)3 IOException (java.io.IOException)2 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)2 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)2 TProtocol (org.apache.thrift.protocol.TProtocol)2 TSocket (org.apache.thrift.transport.TSocket)2 TTransport (org.apache.thrift.transport.TTransport)2 NumberFormat (java.text.NumberFormat)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)1 TableName (org.apache.hadoop.hbase.TableName)1