use of org.apache.hadoop.ozone.om.helpers.WithParentObjectId in project ozone by apache.
the class PrefixParser method parse.
public void parse(String vol, String buck, String db, String file) throws Exception {
if (!Files.exists(Paths.get(db))) {
System.out.println("DB path not exist:" + db);
return;
}
System.out.println("FilePath is:" + file);
System.out.println("Db Path is:" + db);
OzoneConfiguration conf = new OzoneConfiguration();
conf.set(OMConfigKeys.OZONE_OM_DB_DIRS, db);
OmMetadataManagerImpl metadataManager = new OmMetadataManagerImpl(conf);
metadataManager.start(conf);
org.apache.hadoop.fs.Path effectivePath = new org.apache.hadoop.fs.Path("/");
Path p = Paths.get(file);
String volumeKey = metadataManager.getVolumeKey(vol);
if (!metadataManager.getVolumeTable().isExist(volumeKey)) {
System.out.println("Invalid Volume:" + vol);
metadataManager.stop();
return;
}
parserStats[Types.VOLUME.ordinal()]++;
// First get the info about the bucket
String bucketKey = metadataManager.getBucketKey(vol, buck);
OmBucketInfo info = metadataManager.getBucketTable().get(bucketKey);
if (info == null) {
System.out.println("Invalid Bucket:" + buck);
metadataManager.stop();
return;
}
BucketLayout bucketLayout = OzoneManagerUtils.resolveLinkBucketLayout(info, metadataManager, new HashSet<>()).getBucketLayout();
if (!bucketLayout.isFileSystemOptimized()) {
System.out.println("Prefix tool only works for FileSystem Optimized" + "bucket. Bucket Layout is:" + bucketLayout);
metadataManager.stop();
return;
}
long lastObjectId = info.getObjectID();
WithParentObjectId objectBucketId = new WithParentObjectId();
objectBucketId.setObjectID(lastObjectId);
dumpInfo(Types.BUCKET, effectivePath, objectBucketId, bucketKey);
Iterator<Path> pathIterator = p.iterator();
while (pathIterator.hasNext()) {
Path elem = pathIterator.next();
String path = metadataManager.getOzonePathKey(lastObjectId, elem.toString());
OmDirectoryInfo directoryInfo = metadataManager.getDirectoryTable().get(path);
org.apache.hadoop.fs.Path tmpPath = getEffectivePath(effectivePath, elem.toString());
if (directoryInfo == null) {
System.out.println("Given path contains a non-existent directory at:" + tmpPath);
System.out.println("Dumping files and dirs at level:" + tmpPath.getParent());
System.out.println();
parserStats[Types.NON_EXISTENT_DIRECTORY.ordinal()]++;
break;
}
effectivePath = tmpPath;
dumpInfo(Types.INTERMEDIATE_DIRECTORY, effectivePath, directoryInfo, path);
lastObjectId = directoryInfo.getObjectID();
}
// at the last level, now parse both file and dir table
dumpTableInfo(Types.DIRECTORY, effectivePath, metadataManager.getDirectoryTable(), lastObjectId);
dumpTableInfo(Types.FILE, effectivePath, metadataManager.getKeyTable(getBucketLayout()), lastObjectId);
metadataManager.stop();
}
Aggregations