Search in sources :

Example 1 with OmPartInfo

use of org.apache.hadoop.ozone.om.helpers.OmPartInfo in project ozone by apache.

the class RpcClient method listParts.

@Override
public OzoneMultipartUploadPartListParts listParts(String volumeName, String bucketName, String keyName, String uploadID, int partNumberMarker, int maxParts) throws IOException {
    verifyVolumeName(volumeName);
    verifyBucketName(bucketName);
    HddsClientUtils.checkNotNull(uploadID);
    Preconditions.checkArgument(maxParts > 0, "Max Parts Should be greater " + "than zero");
    Preconditions.checkArgument(partNumberMarker >= 0, "Part Number Marker " + "Should be greater than or equal to zero, as part numbers starts from" + " 1 and ranges till 10000");
    OmMultipartUploadListParts omMultipartUploadListParts = ozoneManagerClient.listParts(volumeName, bucketName, keyName, uploadID, partNumberMarker, maxParts);
    OzoneMultipartUploadPartListParts ozoneMultipartUploadPartListParts = new OzoneMultipartUploadPartListParts(omMultipartUploadListParts.getReplicationConfig(), omMultipartUploadListParts.getNextPartNumberMarker(), omMultipartUploadListParts.isTruncated());
    for (OmPartInfo omPartInfo : omMultipartUploadListParts.getPartInfoList()) {
        ozoneMultipartUploadPartListParts.addPart(new OzoneMultipartUploadPartListParts.PartInfo(omPartInfo.getPartNumber(), omPartInfo.getPartName(), omPartInfo.getModificationTime(), omPartInfo.getSize()));
    }
    return ozoneMultipartUploadPartListParts;
}
Also used : OzoneMultipartUploadPartListParts(org.apache.hadoop.ozone.client.OzoneMultipartUploadPartListParts) OmMultipartUploadListParts(org.apache.hadoop.ozone.om.helpers.OmMultipartUploadListParts) OmPartInfo(org.apache.hadoop.ozone.om.helpers.OmPartInfo)

Example 2 with OmPartInfo

use of org.apache.hadoop.ozone.om.helpers.OmPartInfo in project ozone by apache.

the class OzoneManagerRequestHandler method listParts.

private MultipartUploadListPartsResponse listParts(MultipartUploadListPartsRequest multipartUploadListPartsRequest) throws IOException {
    MultipartUploadListPartsResponse.Builder response = MultipartUploadListPartsResponse.newBuilder();
    OmMultipartUploadListParts omMultipartUploadListParts = impl.listParts(multipartUploadListPartsRequest.getVolume(), multipartUploadListPartsRequest.getBucket(), multipartUploadListPartsRequest.getKey(), multipartUploadListPartsRequest.getUploadID(), multipartUploadListPartsRequest.getPartNumbermarker(), multipartUploadListPartsRequest.getMaxParts());
    List<OmPartInfo> omPartInfoList = omMultipartUploadListParts.getPartInfoList();
    List<PartInfo> partInfoList = new ArrayList<>();
    omPartInfoList.forEach(partInfo -> partInfoList.add(partInfo.getProto()));
    response.setType(omMultipartUploadListParts.getReplicationConfig().getReplicationType());
    response.setFactor(ReplicationConfig.getLegacyFactor(omMultipartUploadListParts.getReplicationConfig()));
    response.setNextPartNumberMarker(omMultipartUploadListParts.getNextPartNumberMarker());
    response.setIsTruncated(omMultipartUploadListParts.isTruncated());
    return response.addAllPartsList(partInfoList).build();
}
Also used : OmMultipartUploadListParts(org.apache.hadoop.ozone.om.helpers.OmMultipartUploadListParts) ArrayList(java.util.ArrayList) MultipartUploadListPartsResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartUploadListPartsResponse) PartInfo(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PartInfo) OmPartInfo(org.apache.hadoop.ozone.om.helpers.OmPartInfo) OmPartInfo(org.apache.hadoop.ozone.om.helpers.OmPartInfo)

Example 3 with OmPartInfo

use of org.apache.hadoop.ozone.om.helpers.OmPartInfo in project ozone by apache.

the class KeyManagerImpl method listParts.

@Override
public OmMultipartUploadListParts listParts(String volumeName, String bucketName, String keyName, String uploadID, int partNumberMarker, int maxParts) throws IOException {
    Preconditions.checkNotNull(volumeName);
    Preconditions.checkNotNull(bucketName);
    Preconditions.checkNotNull(keyName);
    Preconditions.checkNotNull(uploadID);
    boolean isTruncated = false;
    int nextPartNumberMarker = 0;
    BucketLayout bucketLayout = BucketLayout.DEFAULT;
    if (ozoneManager != null) {
        String buckKey = ozoneManager.getMetadataManager().getBucketKey(volumeName, bucketName);
        OmBucketInfo buckInfo = ozoneManager.getMetadataManager().getBucketTable().get(buckKey);
        bucketLayout = buckInfo.getBucketLayout();
    }
    metadataManager.getLock().acquireReadLock(BUCKET_LOCK, volumeName, bucketName);
    try {
        String multipartKey = metadataManager.getMultipartKey(volumeName, bucketName, keyName, uploadID);
        OmMultipartKeyInfo multipartKeyInfo = metadataManager.getMultipartInfoTable().get(multipartKey);
        if (multipartKeyInfo == null) {
            throw new OMException("No Such Multipart upload exists for this key.", ResultCodes.NO_SUCH_MULTIPART_UPLOAD_ERROR);
        } else {
            TreeMap<Integer, PartKeyInfo> partKeyInfoMap = multipartKeyInfo.getPartKeyInfoMap();
            Iterator<Map.Entry<Integer, PartKeyInfo>> partKeyInfoMapIterator = partKeyInfoMap.entrySet().iterator();
            ReplicationConfig replicationConfig = null;
            int count = 0;
            List<OmPartInfo> omPartInfoList = new ArrayList<>();
            while (count < maxParts && partKeyInfoMapIterator.hasNext()) {
                Map.Entry<Integer, PartKeyInfo> partKeyInfoEntry = partKeyInfoMapIterator.next();
                nextPartNumberMarker = partKeyInfoEntry.getKey();
                // than part number marker
                if (partKeyInfoEntry.getKey() > partNumberMarker) {
                    PartKeyInfo partKeyInfo = partKeyInfoEntry.getValue();
                    String partName = getPartName(partKeyInfo, volumeName, bucketName, keyName);
                    OmPartInfo omPartInfo = new OmPartInfo(partKeyInfo.getPartNumber(), partName, partKeyInfo.getPartKeyInfo().getModificationTime(), partKeyInfo.getPartKeyInfo().getDataSize());
                    omPartInfoList.add(omPartInfo);
                    // if there are parts, use replication type from one of the parts
                    replicationConfig = ReplicationConfig.fromProtoTypeAndFactor(partKeyInfo.getPartKeyInfo().getType(), partKeyInfo.getPartKeyInfo().getFactor());
                    count++;
                }
            }
            if (replicationConfig == null) {
                // if there are no parts, use the replicationType from the open key.
                if (isBucketFSOptimized(volumeName, bucketName)) {
                    multipartKey = getMultipartOpenKeyFSO(volumeName, bucketName, keyName, uploadID);
                }
                OmKeyInfo omKeyInfo = metadataManager.getOpenKeyTable(bucketLayout).get(multipartKey);
                if (omKeyInfo == null) {
                    throw new IllegalStateException("Open key is missing for multipart upload " + multipartKey);
                }
                replicationConfig = omKeyInfo.getReplicationConfig();
            }
            Preconditions.checkNotNull(replicationConfig, "ReplicationConfig can't be identified");
            if (partKeyInfoMapIterator.hasNext()) {
                Map.Entry<Integer, PartKeyInfo> partKeyInfoEntry = partKeyInfoMapIterator.next();
                isTruncated = true;
            } else {
                isTruncated = false;
                nextPartNumberMarker = 0;
            }
            OmMultipartUploadListParts omMultipartUploadListParts = new OmMultipartUploadListParts(replicationConfig, nextPartNumberMarker, isTruncated);
            omMultipartUploadListParts.addPartList(omPartInfoList);
            return omMultipartUploadListParts;
        }
    } catch (OMException ex) {
        throw ex;
    } catch (IOException ex) {
        LOG.error("List Multipart Upload Parts Failed: volume: {}, bucket: {}, ,key: " + "{} ", volumeName, bucketName, keyName, ex);
        throw new OMException(ex.getMessage(), ResultCodes.LIST_MULTIPART_UPLOAD_PARTS_FAILED);
    } finally {
        metadataManager.getLock().releaseReadLock(BUCKET_LOCK, volumeName, bucketName);
    }
}
Also used : OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) ReplicationConfig(org.apache.hadoop.hdds.client.ReplicationConfig) RatisReplicationConfig(org.apache.hadoop.hdds.client.RatisReplicationConfig) OmMultipartUploadListParts(org.apache.hadoop.ozone.om.helpers.OmMultipartUploadListParts) BucketLayout(org.apache.hadoop.ozone.om.helpers.BucketLayout) ArrayList(java.util.ArrayList) OmPartInfo(org.apache.hadoop.ozone.om.helpers.OmPartInfo) IOException(java.io.IOException) OmMultipartKeyInfo(org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) RepeatedOmKeyInfo(org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo) PartKeyInfo(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PartKeyInfo) OMException(org.apache.hadoop.ozone.om.exceptions.OMException) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Aggregations

OmMultipartUploadListParts (org.apache.hadoop.ozone.om.helpers.OmMultipartUploadListParts)3 OmPartInfo (org.apache.hadoop.ozone.om.helpers.OmPartInfo)3 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 RatisReplicationConfig (org.apache.hadoop.hdds.client.RatisReplicationConfig)1 ReplicationConfig (org.apache.hadoop.hdds.client.ReplicationConfig)1 OzoneMultipartUploadPartListParts (org.apache.hadoop.ozone.client.OzoneMultipartUploadPartListParts)1 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)1 BucketLayout (org.apache.hadoop.ozone.om.helpers.BucketLayout)1 OmBucketInfo (org.apache.hadoop.ozone.om.helpers.OmBucketInfo)1 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)1 OmMultipartKeyInfo (org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo)1 RepeatedOmKeyInfo (org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo)1 MultipartUploadListPartsResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartUploadListPartsResponse)1 PartInfo (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PartInfo)1 PartKeyInfo (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PartKeyInfo)1