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();
}
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);
}
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);
}
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);
}
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;
}
Aggregations