Search in sources :

Example 51 with TableDescriptorBuilder

use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.

the class HBaseTestingUtility method createTable.

/**
 * Create a table.
 * @return A Table instance for the created table.
 */
public Table createTable(TableName tableName, byte[] family, byte[][] splitRows) throws IOException {
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
    ColumnFamilyDescriptorBuilder cfBuilder = ColumnFamilyDescriptorBuilder.newBuilder(family);
    if (isNewVersionBehaviorEnabled()) {
        cfBuilder.setNewVersionBehavior(true);
    }
    builder.setColumnFamily(cfBuilder.build());
    getAdmin().createTable(builder.build(), splitRows);
    // HBaseAdmin only waits for regions to appear in hbase:meta we should wait until they are
    // assigned
    waitUntilAllRegionsAssigned(tableName);
    return getConnection().getTable(tableName);
}
Also used : ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder)

Example 52 with TableDescriptorBuilder

use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.

the class HBaseFsck method fabricateTableInfo.

/**
 * To fabricate a .tableinfo file with following contents<br>
 * 1. the correct tablename <br>
 * 2. the correct colfamily list<br>
 * 3. the default properties for both {@link TableDescriptor} and {@link ColumnFamilyDescriptor}<br>
 * @throws IOException
 */
private boolean fabricateTableInfo(FSTableDescriptors fstd, TableName tableName, Set<String> columns) throws IOException {
    if (columns == null || columns.isEmpty())
        return false;
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
    for (String columnfamimly : columns) {
        builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(columnfamimly));
    }
    fstd.createTableDescriptor(builder.build(), true);
    return true;
}
Also used : TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder)

Example 53 with TableDescriptorBuilder

use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.

the class TestConstraint method testDisableConstraint.

/**
 * Check that if we just disable one constraint, then
 */
@Test
public void testDisableConstraint() throws Exception {
    // create the table
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
    // add a family to the table
    for (byte[] family : new byte[][] { dummy, test }) {
        builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(family));
    }
    // add a constraint to make sure it others get run
    Constraints.add(builder, CheckWasRunConstraint.class);
    // Add Constraint to check
    Constraints.add(builder, AllFailConstraint.class);
    // and then disable the failing constraint
    Constraints.disableConstraint(builder, AllFailConstraint.class);
    util.getAdmin().createTable(builder.build());
    Table table = util.getConnection().getTable(tableName);
    try {
        // test that we don't fail because its disabled
        Put put = new Put(row1);
        byte[] qualifier = new byte[0];
        put.addColumn(dummy, qualifier, Bytes.toBytes("pass"));
        table.put(put);
    } finally {
        table.close();
    }
    assertTrue(CheckWasRunConstraint.wasRun);
}
Also used : Table(org.apache.hadoop.hbase.client.Table) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 54 with TableDescriptorBuilder

use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.

the class TestConstraint method testConstraintPasses.

/**
 * Test that we run a passing constraint
 */
@Test
public void testConstraintPasses() throws Exception {
    // create the table
    // it would be nice if this was also a method on the util
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
    for (byte[] family : new byte[][] { dummy, test }) {
        builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(family));
    }
    // add a constraint
    Constraints.add(builder, CheckWasRunConstraint.class);
    util.getAdmin().createTable(builder.build());
    Table table = util.getConnection().getTable(tableName);
    try {
        // test that we don't fail on a valid put
        Put put = new Put(row1);
        byte[] value = Bytes.toBytes(Integer.toString(10));
        byte[] qualifier = new byte[0];
        put.addColumn(dummy, qualifier, value);
        table.put(put);
    } finally {
        table.close();
    }
    assertTrue(CheckWasRunConstraint.wasRun);
}
Also used : Table(org.apache.hadoop.hbase.client.Table) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 55 with TableDescriptorBuilder

use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.

the class TestConstraints method testRemoveUnsetConstraint.

/**
 * Test that if a constraint hasn't been set that there are no problems with attempting to remove
 * it.
 */
@Test
public void testRemoveUnsetConstraint() throws Exception {
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(name.getTableName());
    Constraints.remove(builder);
    Constraints.remove(builder, AlsoWorks.class);
}
Also used : TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) Test(org.junit.Test)

Aggregations

TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)190 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)76 Test (org.junit.Test)68 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)61 ColumnFamilyDescriptorBuilder (org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder)47 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)39 TableName (org.apache.hadoop.hbase.TableName)34 Path (org.apache.hadoop.fs.Path)31 Admin (org.apache.hadoop.hbase.client.Admin)29 Put (org.apache.hadoop.hbase.client.Put)25 IOException (java.io.IOException)24 Configuration (org.apache.hadoop.conf.Configuration)20 Table (org.apache.hadoop.hbase.client.Table)18 ArrayList (java.util.ArrayList)17 FileSystem (org.apache.hadoop.fs.FileSystem)15 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)15 Before (org.junit.Before)12 Cell (org.apache.hadoop.hbase.Cell)11 NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)10 HashMap (java.util.HashMap)9