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