@Test (timeout = 300000) public void testACLTableMigration() throws IOException { Path rootDir = TEST_UTIL.getDataTestDirOnTestFS("testACLTable"); FileSystem fs = TEST_UTIL.getTestFileSystem(); Configuration conf = TEST_UTIL.getConfiguration(); byte[] FAMILY = Bytes.toBytes("l"); byte[] QUALIFIER = Bytes.toBytes("testUser"); byte[] VALUE = Bytes.toBytes("RWCA"); HTableDescriptor aclTable = new HTableDescriptor(TableName.valueOf("testACLTable")); aclTable.addFamily(new HColumnDescriptor(FAMILY)); FSTableDescriptors fstd = new FSTableDescriptors(fs, rootDir); fstd.createTableDescriptor(aclTable); HRegionInfo hriAcl = new HRegionInfo(aclTable.getTableName(), null, null); HRegion region = HRegion.createHRegion(hriAcl, rootDir, conf, aclTable); try { Put p = new Put(Bytes.toBytes("-ROOT-")); p.addImmutable(FAMILY, QUALIFIER, VALUE); region.put(p); p = new Put(Bytes.toBytes(".META.")); p.addImmutable(FAMILY, QUALIFIER, VALUE); region.put(p); p = new Put(Bytes.toBytes("_acl_")); p.addImmutable(FAMILY, QUALIFIER, VALUE); region.put(p); NamespaceUpgrade upgrade = new NamespaceUpgrade(); upgrade.updateAcls(region); Get g = new Get(Bytes.toBytes("-ROOT-")); Result r = region.get(g); assertTrue(r == null || r.size() == 0); g = new Get(AccessControlLists.ACL_TABLE_NAME.toBytes()); r = region.get(g); assertTrue(r != null && r.size() == 1); assertTrue(Bytes.compareTo(VALUE, r.getValue(FAMILY, QUALIFIER)) == 0); g = new Get(TableName.META_TABLE_NAME.toBytes()); r = region.get(g); assertTrue(r != null && r.size() == 1); assertTrue(Bytes.compareTo(VALUE, r.getValue(FAMILY, QUALIFIER)) == 0); } finally { region.close(); HRegionFileSystem.deleteRegionFromFileSystem(conf, fs, FSUtils.getTableDir(rootDir, hriAcl.getTable()), hriAcl); } }
void updateAcls(HRegion region) throws IOException { byte[] rowKey = Bytes.toBytes(NamespaceUpgrade.OLD_ACL); Get g = new Get(rowKey); Result r = region.get(g); if (r != null && r.size() > 0) { Put p = new Put(AccessControlLists.ACL_GLOBAL_NAME); for (Cell c : r.rawCells()) { p.addImmutable(CellUtil.cloneFamily(c), CellUtil.cloneQualifier(c), CellUtil.cloneValue(c)); } region.put(p); Delete del = new Delete(rowKey); region.delete(del); } rowKey = Bytes.toBytes(TableName.OLD_ROOT_STR); Delete del = new Delete(rowKey); region.delete(del); rowKey = Bytes.toBytes(TableName.OLD_META_STR); g = new Get(rowKey); r = region.get(g); if (r != null && r.size() > 0) { Put p = new Put(TableName.META_TABLE_NAME.getName()); for (Cell c : r.rawCells()) { p.addImmutable(CellUtil.cloneFamily(c), CellUtil.cloneQualifier(c), CellUtil.cloneValue(c)); } region.put(p); del = new Delete(rowKey); region.delete(del); } }
NamespaceUpgrade implements Tool { void updateAcls(HRegion region) throws IOException { byte[] rowKey = Bytes.toBytes(NamespaceUpgrade.OLD_ACL); Get g = new Get(rowKey); Result r = region.get(g); if (r != null && r.size() > 0) { Put p = new Put(AccessControlLists.ACL_GLOBAL_NAME); for (Cell c : r.rawCells()) { p.addImmutable(CellUtil.cloneFamily(c), CellUtil.cloneQualifier(c), CellUtil.cloneValue(c)); } region.put(p); Delete del = new Delete(rowKey); region.delete(del); } rowKey = Bytes.toBytes(TableName.OLD_ROOT_STR); Delete del = new Delete(rowKey); region.delete(del); rowKey = Bytes.toBytes(TableName.OLD_META_STR); g = new Get(rowKey); r = region.get(g); if (r != null && r.size() > 0) { Put p = new Put(TableName.META_TABLE_NAME.getName()); for (Cell c : r.rawCells()) { p.addImmutable(CellUtil.cloneFamily(c), CellUtil.cloneQualifier(c), CellUtil.cloneValue(c)); } region.put(p); del = new Delete(rowKey); region.delete(del); } } }
NamespaceUpgrade implements Tool { void updateAcls(HRegion region) throws IOException { byte[] rowKey = Bytes.toBytes(NamespaceUpgrade.OLD_ACL); Get g = new Get(rowKey); Result r = region.get(g); if (r != null && r.size() > 0) { Put p = new Put(AccessControlLists.ACL_GLOBAL_NAME); for (Cell c : r.rawCells()) { p.addImmutable(CellUtil.cloneFamily(c), CellUtil.cloneQualifier(c), CellUtil.cloneValue(c)); } region.put(p); Delete del = new Delete(rowKey); region.delete(del); } rowKey = Bytes.toBytes(TableName.OLD_ROOT_STR); Delete del = new Delete(rowKey); region.delete(del); rowKey = Bytes.toBytes(TableName.OLD_META_STR); g = new Get(rowKey); r = region.get(g); if (r != null && r.size() > 0) { Put p = new Put(TableName.META_TABLE_NAME.getName()); for (Cell c : r.rawCells()) { p.addImmutable(CellUtil.cloneFamily(c), CellUtil.cloneQualifier(c), CellUtil.cloneValue(c)); } region.put(p); del = new Delete(rowKey); region.delete(del); } } NamespaceUpgrade(); }
NamespaceUpgrade implements Tool { void updateAcls(HRegion region) throws IOException { byte[] rowKey = Bytes.toBytes(NamespaceUpgrade.OLD_ACL); Get g = new Get(rowKey); Result r = region.get(g); if (r != null && r.size() > 0) { Put p = new Put(AccessControlLists.ACL_GLOBAL_NAME); for (Cell c : r.rawCells()) { p.addImmutable(CellUtil.cloneFamily(c), CellUtil.cloneQualifier(c), CellUtil.cloneValue(c)); } region.put(p); Delete del = new Delete(rowKey); region.delete(del); } rowKey = Bytes.toBytes(TableName.OLD_ROOT_STR); Delete del = new Delete(rowKey); region.delete(del); rowKey = Bytes.toBytes(TableName.OLD_META_STR); g = new Get(rowKey); r = region.get(g); if (r != null && r.size() > 0) { Put p = new Put(TableName.META_TABLE_NAME.getName()); for (Cell c : r.rawCells()) { p.addImmutable(CellUtil.cloneFamily(c), CellUtil.cloneQualifier(c), CellUtil.cloneValue(c)); } region.put(p); del = new Delete(rowKey); region.delete(del); } } NamespaceUpgrade(); void init(); void upgradeTableDirs(); void deleteRoot(); void migrateDotDirs(); void makeNamespaceDirs(); void migrateTables(); void migrateSnapshots(); void migrateMeta(); void migrateACL(); static boolean verifyNSUpgrade(FileSystem fs, Path rootDir); @Override int run(String[] args); @Override void setConf(Configuration conf); @Override Configuration getConf(); }
NamespaceUpgrade implements Tool { void updateAcls(HRegion region) throws IOException { byte[] rowKey = Bytes.toBytes(NamespaceUpgrade.OLD_ACL); Get g = new Get(rowKey); Result r = region.get(g); if (r != null && r.size() > 0) { Put p = new Put(AccessControlLists.ACL_GLOBAL_NAME); for (Cell c : r.rawCells()) { p.addImmutable(CellUtil.cloneFamily(c), CellUtil.cloneQualifier(c), CellUtil.cloneValue(c)); } region.put(p); Delete del = new Delete(rowKey); region.delete(del); } rowKey = Bytes.toBytes(TableName.OLD_ROOT_STR); Delete del = new Delete(rowKey); region.delete(del); rowKey = Bytes.toBytes(TableName.OLD_META_STR); g = new Get(rowKey); r = region.get(g); if (r != null && r.size() > 0) { Put p = new Put(TableName.META_TABLE_NAME.getName()); for (Cell c : r.rawCells()) { p.addImmutable(CellUtil.cloneFamily(c), CellUtil.cloneQualifier(c), CellUtil.cloneValue(c)); } region.put(p); del = new Delete(rowKey); region.delete(del); } } NamespaceUpgrade(); void init(); void upgradeTableDirs(); void deleteRoot(); void migrateDotDirs(); void makeNamespaceDirs(); void migrateTables(); void migrateSnapshots(); void migrateMeta(); void migrateACL(); static boolean verifyNSUpgrade(FileSystem fs, Path rootDir); @Override int run(String[] args); @Override void setConf(Configuration conf); @Override Configuration getConf();  }