use of org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup in project ozone by apache.
the class BasicRootedOzoneClientAdapterImpl method getBlockLocations.
/**
* Helper method to get List of BlockLocation from OM Key info.
* @param fileStatus Ozone key file status.
* @return list of block locations.
*/
private BlockLocation[] getBlockLocations(OzoneFileStatus fileStatus) {
if (fileStatus == null) {
return new BlockLocation[0];
}
OmKeyInfo keyInfo = fileStatus.getKeyInfo();
if (keyInfo == null || CollectionUtils.isEmpty(keyInfo.getKeyLocationVersions())) {
return new BlockLocation[0];
}
List<OmKeyLocationInfoGroup> omKeyLocationInfoGroups = keyInfo.getKeyLocationVersions();
if (CollectionUtils.isEmpty(omKeyLocationInfoGroups)) {
return new BlockLocation[0];
}
OmKeyLocationInfoGroup omKeyLocationInfoGroup = keyInfo.getLatestVersionLocations();
BlockLocation[] blockLocations = new BlockLocation[omKeyLocationInfoGroup.getBlocksLatestVersionOnly().size()];
int i = 0;
long offsetOfBlockInFile = 0L;
for (OmKeyLocationInfo omKeyLocationInfo : omKeyLocationInfoGroup.getBlocksLatestVersionOnly()) {
List<String> hostList = new ArrayList<>();
List<String> nameList = new ArrayList<>();
omKeyLocationInfo.getPipeline().getNodes().forEach(dn -> {
hostList.add(dn.getHostName());
int port = dn.getPort(DatanodeDetails.Port.Name.STANDALONE).getValue();
if (port == 0) {
port = configuredDnPort;
}
nameList.add(dn.getHostName() + ":" + port);
});
String[] hosts = hostList.toArray(new String[hostList.size()]);
String[] names = nameList.toArray(new String[nameList.size()]);
BlockLocation blockLocation = new BlockLocation(names, hosts, offsetOfBlockInFile, omKeyLocationInfo.getLength());
offsetOfBlockInFile += omKeyLocationInfo.getLength();
blockLocations[i++] = blockLocation;
}
return blockLocations;
}
Aggregations