Search in sources :

Example 6 with ColumnFamilyDescriptorBuilder

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

the class IntegrationTestMTTR method setupTables.

private static void setupTables() throws IOException {
    // Get the table name.
    tableName = TableName.valueOf(util.getConfiguration().get("hbase.IntegrationTestMTTR.tableName", "IntegrationTestMTTR"));
    loadTableName = TableName.valueOf(util.getConfiguration().get("hbase.IntegrationTestMTTR.loadTableName", "IntegrationTestMTTRLoadTestTool"));
    if (util.getAdmin().tableExists(tableName)) {
        util.deleteTable(tableName);
    }
    if (util.getAdmin().tableExists(loadTableName)) {
        util.deleteTable(loadTableName);
    }
    // Create the table.  If this fails then fail everything.
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
    // Make the max file size huge so that splits don't happen during the test.
    builder.setMaxFileSize(Long.MAX_VALUE);
    ColumnFamilyDescriptorBuilder colDescriptorBldr = ColumnFamilyDescriptorBuilder.newBuilder(FAMILY);
    colDescriptorBldr.setMaxVersions(1);
    builder.setColumnFamily(colDescriptorBldr.build());
    util.getAdmin().createTable(builder.build());
    // Setup the table for LoadTestTool
    int ret = loadTool.run(new String[] { "-tn", loadTableName.getNameAsString(), "-init_only" });
    assertEquals("Failed to initialize LoadTestTool", 0, ret);
}
Also used : ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder)

Example 7 with ColumnFamilyDescriptorBuilder

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

the class TestEncryptionDisabled method testNonEncryptedTableShouldBeCreatedWhenEncryptionDisabled.

@Test
public void testNonEncryptedTableShouldBeCreatedWhenEncryptionDisabled() throws Exception {
    // Create the table schema
    tdb = TableDescriptorBuilder.newBuilder(TableName.valueOf("default", "TestEncryptionDisabledSuccess"));
    ColumnFamilyDescriptorBuilder columnFamilyDescriptorBuilder = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf"));
    tdb.setColumnFamily(columnFamilyDescriptorBuilder.build());
    // Create the test table, this should succeed, as we don't use encryption
    TEST_UTIL.getAdmin().createTable(tdb.build());
    TEST_UTIL.waitTableAvailable(tdb.build().getTableName(), 5000);
}
Also used : ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) Test(org.junit.Test)

Example 8 with ColumnFamilyDescriptorBuilder

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

the class TestEncryptionDisabled method testEncryptedTableShouldNotBeCreatedWhenEncryptionDisabled.

@Test
public void testEncryptedTableShouldNotBeCreatedWhenEncryptionDisabled() throws Exception {
    // Create the table schema
    // Specify an encryption algorithm without a key (normally HBase would generate a random key)
    tdb = TableDescriptorBuilder.newBuilder(TableName.valueOf("default", "TestEncryptionDisabledFail"));
    ColumnFamilyDescriptorBuilder columnFamilyDescriptorBuilder = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf"));
    String algorithm = conf.get(HConstants.CRYPTO_KEY_ALGORITHM_CONF_KEY, HConstants.CIPHER_AES);
    columnFamilyDescriptorBuilder.setEncryptionType(algorithm);
    tdb.setColumnFamily(columnFamilyDescriptorBuilder.build());
    // Create the test table, we expect to get back an exception
    exception.expect(DoNotRetryIOException.class);
    exception.expectMessage("encryption is disabled on the cluster");
    TEST_UTIL.getAdmin().createTable(tdb.build());
}
Also used : ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) Test(org.junit.Test)

Example 9 with ColumnFamilyDescriptorBuilder

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

the class TestEncryptionKeyRotation method testCFKeyRotation.

@Test
public void testCFKeyRotation() throws Exception {
    // Create the table schema
    TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(TableName.valueOf("default", name.getMethodName()));
    ColumnFamilyDescriptorBuilder columnFamilyDescriptorBuilder = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf"));
    String algorithm = conf.get(HConstants.CRYPTO_KEY_ALGORITHM_CONF_KEY, HConstants.CIPHER_AES);
    columnFamilyDescriptorBuilder.setEncryptionType(algorithm);
    columnFamilyDescriptorBuilder.setEncryptionKey(EncryptionUtil.wrapKey(conf, "hbase", initialCFKey));
    tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptorBuilder.build());
    TableDescriptor tableDescriptor = tableDescriptorBuilder.build();
    // Create the table and some on disk files
    createTableAndFlush(tableDescriptor);
    // Verify we have store file(s) with the initial key
    final List<Path> initialPaths = findStorefilePaths(tableDescriptor.getTableName());
    assertTrue(initialPaths.size() > 0);
    for (Path path : initialPaths) {
        assertTrue("Store file " + path + " has incorrect key", Bytes.equals(initialCFKey.getEncoded(), extractHFileKey(path)));
    }
    // Update the schema with a new encryption key
    columnFamilyDescriptorBuilder.setEncryptionKey(EncryptionUtil.wrapKey(conf, conf.get(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY, User.getCurrent().getShortName()), secondCFKey));
    TEST_UTIL.getAdmin().modifyColumnFamily(tableDescriptor.getTableName(), columnFamilyDescriptorBuilder.build());
    // Need a predicate for online schema change
    Thread.sleep(5000);
    // And major compact
    TEST_UTIL.getAdmin().majorCompact(tableDescriptor.getTableName());
    // waiting for the major compaction to complete
    TEST_UTIL.waitFor(30000, new Waiter.Predicate<IOException>() {

        @Override
        public boolean evaluate() throws IOException {
            return TEST_UTIL.getAdmin().getCompactionState(tableDescriptor.getTableName()) == CompactionState.NONE;
        }
    });
    List<Path> pathsAfterCompaction = findStorefilePaths(tableDescriptor.getTableName());
    assertTrue(pathsAfterCompaction.size() > 0);
    for (Path path : pathsAfterCompaction) {
        assertTrue("Store file " + path + " has incorrect key", Bytes.equals(secondCFKey.getEncoded(), extractHFileKey(path)));
    }
    List<Path> compactedPaths = findCompactedStorefilePaths(tableDescriptor.getTableName());
    assertTrue(compactedPaths.size() > 0);
    for (Path path : compactedPaths) {
        assertTrue("Store file " + path + " retains initial key", Bytes.equals(initialCFKey.getEncoded(), extractHFileKey(path)));
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) IOException(java.io.IOException) Waiter(org.apache.hadoop.hbase.Waiter) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Test(org.junit.Test)

Example 10 with ColumnFamilyDescriptorBuilder

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

the class TestEncryptionRandomKeying method setUp.

@BeforeClass
public static void setUp() throws Exception {
    conf.setInt("hfile.format.version", 3);
    conf.set(HConstants.CRYPTO_KEYPROVIDER_CONF_KEY, KeyProviderForTesting.class.getName());
    conf.set(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY, "hbase");
    // Create the table schema
    // Specify an encryption algorithm without a key
    tdb = TableDescriptorBuilder.newBuilder(TableName.valueOf("default", "TestEncryptionRandomKeying"));
    ColumnFamilyDescriptorBuilder columnFamilyDescriptorBuilder = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf"));
    String algorithm = conf.get(HConstants.CRYPTO_KEY_ALGORITHM_CONF_KEY, HConstants.CIPHER_AES);
    columnFamilyDescriptorBuilder.setEncryptionType(algorithm);
    tdb.setColumnFamily(columnFamilyDescriptorBuilder.build());
    // Start the minicluster
    TEST_UTIL.startMiniCluster(1);
    // Create the test table
    TEST_UTIL.getAdmin().createTable(tdb.build());
    TEST_UTIL.waitTableAvailable(tdb.build().getTableName(), 5000);
    // Create a store file
    Table table = TEST_UTIL.getConnection().getTable(tdb.build().getTableName());
    try {
        table.put(new Put(Bytes.toBytes("testrow")).addColumn(columnFamilyDescriptorBuilder.build().getName(), Bytes.toBytes("q"), Bytes.toBytes("value")));
    } finally {
        table.close();
    }
    TEST_UTIL.getAdmin().flush(tdb.build().getTableName());
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) KeyProviderForTesting(org.apache.hadoop.hbase.io.crypto.KeyProviderForTesting) Put(org.apache.hadoop.hbase.client.Put) BeforeClass(org.junit.BeforeClass)

Aggregations

ColumnFamilyDescriptorBuilder (org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder)61 TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)43 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)19 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)16 Test (org.junit.Test)9 Table (org.apache.hadoop.hbase.client.Table)7 Admin (org.apache.hadoop.hbase.client.Admin)6 Put (org.apache.hadoop.hbase.client.Put)6 IOException (java.io.IOException)5 Configuration (org.apache.hadoop.conf.Configuration)5 Path (org.apache.hadoop.fs.Path)5 TableName (org.apache.hadoop.hbase.TableName)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 QName (javax.xml.namespace.QName)3 TableNotEnabledException (org.apache.hadoop.hbase.TableNotEnabledException)3 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)3 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)3 FileStatus (org.apache.hadoop.fs.FileStatus)2 FileSystem (org.apache.hadoop.fs.FileSystem)2