Search in sources :

Example 41 with OmKeyLocationInfoGroup

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;
}
Also used : OmKeyLocationInfoGroup(org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) ArrayList(java.util.ArrayList) BlockLocation(org.apache.hadoop.fs.BlockLocation) OmKeyLocationInfo(org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo)

Aggregations

OmKeyLocationInfoGroup (org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup)41 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)31 OmKeyLocationInfo (org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo)27 ArrayList (java.util.ArrayList)23 BlockID (org.apache.hadoop.hdds.client.BlockID)14 RepeatedOmKeyInfo (org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo)13 Pipeline (org.apache.hadoop.hdds.scm.pipeline.Pipeline)11 Test (org.junit.Test)11 OmKeyArgs (org.apache.hadoop.ozone.om.helpers.OmKeyArgs)9 IOException (java.io.IOException)6 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)6 HashMap (java.util.HashMap)5 List (java.util.List)5 ContainerWithPipeline (org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline)5 OzoneBucket (org.apache.hadoop.ozone.client.OzoneBucket)5 OmBucketInfo (org.apache.hadoop.ozone.om.helpers.OmBucketInfo)5 OmMultipartKeyInfo (org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo)5 Map (java.util.Map)4 OzoneVolume (org.apache.hadoop.ozone.client.OzoneVolume)4 OMResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)4