Search in sources :

Example 1 with TNamespaceDescriptor

use of org.apache.hadoop.hbase.thrift2.generated.TNamespaceDescriptor 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);
}
Also used : TTableName(org.apache.hadoop.hbase.thrift2.generated.TTableName) TColumnFamilyDescriptor(org.apache.hadoop.hbase.thrift2.generated.TColumnFamilyDescriptor) ArrayList(java.util.ArrayList) TTableDescriptor(org.apache.hadoop.hbase.thrift2.generated.TTableDescriptor) TNamespaceDescriptor(org.apache.hadoop.hbase.thrift2.generated.TNamespaceDescriptor) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 2 with TNamespaceDescriptor

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

the class ThriftHBaseServiceHandler method createNamespace.

@Override
public void createNamespace(TNamespaceDescriptor namespaceDesc) throws TIOError, TException {
    try {
        NamespaceDescriptor descriptor = namespaceDescriptorFromThrift(namespaceDesc);
        connectionCache.getAdmin().createNamespace(descriptor);
    } catch (IOException e) {
        throw getTIOError(e);
    }
}
Also used : TNamespaceDescriptor(org.apache.hadoop.hbase.thrift2.generated.TNamespaceDescriptor) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException)

Example 3 with TNamespaceDescriptor

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

the class ThriftUtilities method namespaceDescriptorsFromThrift.

public static NamespaceDescriptor[] namespaceDescriptorsFromThrift(List<TNamespaceDescriptor> in) {
    NamespaceDescriptor[] out = new NamespaceDescriptor[in.size()];
    int index = 0;
    for (TNamespaceDescriptor descriptor : in) {
        out[index++] = namespaceDescriptorFromThrift(descriptor);
    }
    return out;
}
Also used : TNamespaceDescriptor(org.apache.hadoop.hbase.thrift2.generated.TNamespaceDescriptor) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) TNamespaceDescriptor(org.apache.hadoop.hbase.thrift2.generated.TNamespaceDescriptor)

Example 4 with TNamespaceDescriptor

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

the class ThriftHBaseServiceHandler method modifyNamespace.

@Override
public void modifyNamespace(TNamespaceDescriptor namespaceDesc) throws TIOError, TException {
    try {
        NamespaceDescriptor descriptor = namespaceDescriptorFromThrift(namespaceDesc);
        connectionCache.getAdmin().modifyNamespace(descriptor);
    } catch (IOException e) {
        throw getTIOError(e);
    }
}
Also used : TNamespaceDescriptor(org.apache.hadoop.hbase.thrift2.generated.TNamespaceDescriptor) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException)

Example 5 with TNamespaceDescriptor

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

the class ThriftUtilities method namespaceDescriptorFromHBase.

public static TNamespaceDescriptor namespaceDescriptorFromHBase(NamespaceDescriptor in) {
    TNamespaceDescriptor out = new TNamespaceDescriptor();
    out.setName(in.getName());
    for (Map.Entry<String, String> conf : in.getConfiguration().entrySet()) {
        out.putToConfiguration(conf.getKey(), conf.getValue());
    }
    return out;
}
Also used : TNamespaceDescriptor(org.apache.hadoop.hbase.thrift2.generated.TNamespaceDescriptor) Map(java.util.Map)

Aggregations

TNamespaceDescriptor (org.apache.hadoop.hbase.thrift2.generated.TNamespaceDescriptor)5 NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)3 IOException (java.io.IOException)2 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)2 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 TColumnFamilyDescriptor (org.apache.hadoop.hbase.thrift2.generated.TColumnFamilyDescriptor)1 TTableDescriptor (org.apache.hadoop.hbase.thrift2.generated.TTableDescriptor)1 TTableName (org.apache.hadoop.hbase.thrift2.generated.TTableName)1 Test (org.junit.Test)1