use of org.apache.hadoop.hbase.thrift2.generated.TTableDescriptor in project hbase by apache.
the class TestThrift2ServerCmdLine method talkToThriftServer.
@Override
protected void talkToThriftServer(int port) throws Exception {
TSocket sock = new TSocket(InetAddress.getLoopbackAddress().getHostName(), port);
TTransport transport = sock;
if (specifyFramed || implType.isAlwaysFramed()) {
transport = new TFramedTransport(transport);
}
sock.open();
try {
TProtocol tProtocol;
if (specifyCompact) {
tProtocol = new TCompactProtocol(transport);
} else {
tProtocol = new TBinaryProtocol(transport);
}
THBaseService.Client client = new THBaseService.Client(tProtocol);
TTableName tTableName = new TTableName();
tTableName.setNs(Bytes.toBytes(""));
tTableName.setQualifier(Bytes.toBytes(TABLENAME));
if (!tableCreated) {
Assert.assertTrue(!client.tableExists(tTableName));
TTableDescriptor tTableDescriptor = new TTableDescriptor();
tTableDescriptor.setTableName(tTableName);
TColumnFamilyDescriptor columnFamilyDescriptor = new TColumnFamilyDescriptor();
columnFamilyDescriptor.setName(Bytes.toBytes(TABLENAME));
tTableDescriptor.addToColumns(columnFamilyDescriptor);
client.createTable(tTableDescriptor, new ArrayList<>());
tableCreated = true;
}
Assert.assertTrue("tableCreated " + tableCreated, client.tableExists(tTableName));
} finally {
sock.close();
}
}
use of org.apache.hadoop.hbase.thrift2.generated.TTableDescriptor in project hbase by apache.
the class TestThriftHBaseServiceHandler method testDDLOpertions.
@Test
public void testDDLOpertions() throws Exception {
String namespace = "testDDLOpertionsNamespace";
String table = "testDDLOpertionsTable";
TTableName tTableName = new TTableName();
tTableName.setNs(Bytes.toBytes(namespace));
tTableName.setQualifier(Bytes.toBytes(table));
ThriftHBaseServiceHandler handler = createHandler();
// create name space
TNamespaceDescriptor namespaceDescriptor = new TNamespaceDescriptor();
namespaceDescriptor.setName(namespace);
namespaceDescriptor.putToConfiguration("key1", "value1");
namespaceDescriptor.putToConfiguration("key2", "value2");
handler.createNamespace(namespaceDescriptor);
// list namespace
List<TNamespaceDescriptor> namespaceDescriptors = handler.listNamespaceDescriptors();
// should have 3 namespace, default hbase and testDDLOpertionsNamespace
assertTrue(namespaceDescriptors.size() == 3);
// modify namesapce
namespaceDescriptor.putToConfiguration("kye3", "value3");
handler.modifyNamespace(namespaceDescriptor);
// get namespace
TNamespaceDescriptor namespaceDescriptorReturned = handler.getNamespaceDescriptor(namespace);
assertTrue(namespaceDescriptorReturned.getConfiguration().size() == 3);
// create table
TTableDescriptor tableDescriptor = new TTableDescriptor();
tableDescriptor.setTableName(tTableName);
TColumnFamilyDescriptor columnFamilyDescriptor1 = new TColumnFamilyDescriptor();
columnFamilyDescriptor1.setName(familyAname);
columnFamilyDescriptor1.setDataBlockEncoding(TDataBlockEncoding.DIFF);
tableDescriptor.addToColumns(columnFamilyDescriptor1);
List<ByteBuffer> splitKeys = new ArrayList<>();
splitKeys.add(ByteBuffer.wrap(Bytes.toBytes(5)));
handler.createTable(tableDescriptor, splitKeys);
// modify table
tableDescriptor.setDurability(TDurability.ASYNC_WAL);
handler.modifyTable(tableDescriptor);
// modify column family
columnFamilyDescriptor1.setInMemory(true);
handler.modifyColumnFamily(tTableName, columnFamilyDescriptor1);
// add column family
TColumnFamilyDescriptor columnFamilyDescriptor2 = new TColumnFamilyDescriptor();
columnFamilyDescriptor2.setName(familyBname);
columnFamilyDescriptor2.setDataBlockEncoding(TDataBlockEncoding.PREFIX);
handler.addColumnFamily(tTableName, columnFamilyDescriptor2);
// get table descriptor
TTableDescriptor tableDescriptorReturned = handler.getTableDescriptor(tTableName);
assertTrue(tableDescriptorReturned.getColumns().size() == 2);
assertTrue(tableDescriptorReturned.getDurability() == TDurability.ASYNC_WAL);
TColumnFamilyDescriptor columnFamilyDescriptor1Returned = tableDescriptorReturned.getColumns().stream().filter(desc -> Bytes.equals(desc.getName(), familyAname)).findFirst().get();
assertTrue(columnFamilyDescriptor1Returned.isInMemory() == true);
// delete column family
handler.deleteColumnFamily(tTableName, ByteBuffer.wrap(familyBname));
tableDescriptorReturned = handler.getTableDescriptor(tTableName);
assertTrue(tableDescriptorReturned.getColumns().size() == 1);
// disable table
handler.disableTable(tTableName);
assertTrue(handler.isTableDisabled(tTableName));
// enable table
handler.enableTable(tTableName);
assertTrue(handler.isTableEnabled(tTableName));
assertTrue(handler.isTableAvailable(tTableName));
// truncate table
handler.disableTable(tTableName);
handler.truncateTable(tTableName, true);
assertTrue(handler.isTableAvailable(tTableName));
// delete table
handler.disableTable(tTableName);
handler.deleteTable(tTableName);
assertFalse(handler.tableExists(tTableName));
// delete namespace
handler.deleteNamespace(namespace);
namespaceDescriptors = handler.listNamespaceDescriptors();
// should have 2 namespace, default and hbase
assertTrue(namespaceDescriptors.size() == 2);
}
use of org.apache.hadoop.hbase.thrift2.generated.TTableDescriptor in project hbase by apache.
the class TestThriftHBaseServiceHandler method testGetTableDescriptor.
@Test
public void testGetTableDescriptor() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
TTableDescriptor tableDescriptor = handler.getTableDescriptor(ThriftUtilities.tableNameFromHBase(TableName.valueOf(tableAname)));
TableDescriptor table = ThriftUtilities.tableDescriptorFromThrift(tableDescriptor);
assertTrue(table.getTableName().equals(TableName.valueOf(tableAname)));
assertTrue(table.getColumnFamilies().length == 2);
assertTrue(table.getColumnFamily(familyAname).getMaxVersions() == 3);
assertTrue(table.getColumnFamily(familyBname).getMaxVersions() == 2);
}
use of org.apache.hadoop.hbase.thrift2.generated.TTableDescriptor in project hbase by apache.
the class ThriftAdmin method listTableDescriptors.
@Override
public List<TableDescriptor> listTableDescriptors(Pattern pattern, boolean includeSysTables) throws IOException {
try {
String regex = (pattern == null ? null : pattern.toString());
List<TTableDescriptor> tTableDescriptors = client.getTableDescriptorsByPattern(regex, includeSysTables);
return ThriftUtilities.tableDescriptorsFromThrift(tTableDescriptors);
} catch (TException e) {
throw new IOException(e);
}
}
use of org.apache.hadoop.hbase.thrift2.generated.TTableDescriptor in project hbase by apache.
the class ThriftHBaseServiceHandler method getTableDescriptorsByPattern.
@Override
public List<TTableDescriptor> getTableDescriptorsByPattern(String regex, boolean includeSysTables) throws TIOError, TException {
try {
Pattern pattern = (regex == null ? null : Pattern.compile(regex));
List<TableDescriptor> tableDescriptors = connectionCache.getAdmin().listTableDescriptors(pattern, includeSysTables);
return tableDescriptorsFromHBase(tableDescriptors);
} catch (IOException e) {
throw getTIOError(e);
}
}
Aggregations