2323import java .util .NoSuchElementException ;
2424import javax .annotation .Nullable ;
2525
26- import com .amazonaws .services .s3 .AmazonS3 ;
27- import com .amazonaws .services .s3 .model .ListMultipartUploadsRequest ;
28- import com .amazonaws .services .s3 .model .MultipartUpload ;
29- import com .amazonaws .services .s3 .model .MultipartUploadListing ;
3026import org .slf4j .Logger ;
3127import org .slf4j .LoggerFactory ;
3228
29+ import software .amazon .awssdk .services .s3 .S3Client ;
30+ import software .amazon .awssdk .services .s3 .model .ListMultipartUploadsRequest ;
31+ import software .amazon .awssdk .services .s3 .model .ListMultipartUploadsResponse ;
32+ import software .amazon .awssdk .services .s3 .model .MultipartUpload ;
33+
3334import org .apache .hadoop .fs .RemoteIterator ;
3435import org .apache .hadoop .fs .s3a .api .RequestFactory ;
3536import org .apache .hadoop .fs .s3a .impl .StoreContext ;
4344 * MultipartUtils upload-specific functions for use by S3AFileSystem and Hadoop
4445 * CLI.
4546 * The Audit span active when
46- * {@link #listMultipartUploads(StoreContext, AmazonS3 , String, int)}
47+ * {@link #listMultipartUploads(StoreContext, S3Client , String, int)}
4748 * was invoked is retained for all subsequent operations.
4849 */
4950public final class MultipartUtils {
@@ -67,7 +68,7 @@ private MultipartUtils() { }
6768 */
6869 static MultipartUtils .UploadIterator listMultipartUploads (
6970 final StoreContext storeContext ,
70- AmazonS3 s3 ,
71+ S3Client s3 ,
7172 @ Nullable String prefix ,
7273 int maxKeys )
7374 throws IOException {
@@ -84,14 +85,14 @@ static MultipartUtils.UploadIterator listMultipartUploads(
8485 * at the time the iterator was constructed.
8586 */
8687 static class ListingIterator implements
87- RemoteIterator <MultipartUploadListing > {
88+ RemoteIterator <ListMultipartUploadsResponse > {
8889
8990 private final String prefix ;
9091
9192 private final RequestFactory requestFactory ;
9293
9394 private final int maxKeys ;
94- private final AmazonS3 s3 ;
95+ private final S3Client s3 ;
9596 private final Invoker invoker ;
9697
9798 private final AuditSpan auditSpan ;
@@ -101,7 +102,7 @@ static class ListingIterator implements
101102 /**
102103 * Most recent listing results.
103104 */
104- private MultipartUploadListing listing ;
105+ private ListMultipartUploadsResponse listing ;
105106
106107 /**
107108 * Indicator that this is the first listing.
@@ -114,7 +115,7 @@ static class ListingIterator implements
114115 private int listCount = 0 ;
115116
116117 ListingIterator (final StoreContext storeContext ,
117- AmazonS3 s3 ,
118+ S3Client s3 ,
118119 @ Nullable String prefix ,
119120 int maxKeys ) throws IOException {
120121 this .storeContext = storeContext ;
@@ -153,7 +154,7 @@ public boolean hasNext() throws IOException {
153154 */
154155 @ Override
155156 @ Retries .RetryTranslated
156- public MultipartUploadListing next () throws IOException {
157+ public ListMultipartUploadsResponse next () throws IOException {
157158 if (firstListing ) {
158159 firstListing = false ;
159160 } else {
@@ -171,32 +172,34 @@ public MultipartUploadListing next() throws IOException {
171172 public String toString () {
172173 return "Upload iterator: prefix " + prefix
173174 + "; list count " + listCount
174- + "; upload count " + listing .getMultipartUploads ().size ()
175+ + "; upload count " + listing .uploads ().size ()
175176 + "; isTruncated=" + listing .isTruncated ();
176177 }
177178
178179 @ Retries .RetryTranslated
179180 private void requestNextBatch () throws IOException {
180181 try (AuditSpan span = auditSpan .activate ()) {
181- ListMultipartUploadsRequest req = requestFactory
182- .newListMultipartUploadsRequest (prefix );
182+ ListMultipartUploadsRequest . Builder requestBuilder = requestFactory
183+ .newListMultipartUploadsRequestBuilder (prefix );
183184 if (!firstListing ) {
184- req . setKeyMarker (listing .getNextKeyMarker ());
185- req . setUploadIdMarker (listing .getNextUploadIdMarker ());
185+ requestBuilder . keyMarker (listing .nextKeyMarker ());
186+ requestBuilder . uploadIdMarker (listing .nextUploadIdMarker ());
186187 }
187- req .setMaxUploads (maxKeys );
188+ requestBuilder .maxUploads (maxKeys );
189+
190+ ListMultipartUploadsRequest request = requestBuilder .build ();
188191
189192 LOG .debug ("[{}], Requesting next {} uploads prefix {}, " +
190193 "next key {}, next upload id {}" , listCount , maxKeys , prefix ,
191- req . getKeyMarker (), req . getUploadIdMarker ());
194+ request . keyMarker (), request . uploadIdMarker ());
192195 listCount ++;
193196
194197 listing = invoker .retry ("listMultipartUploads" , prefix , true ,
195198 trackDurationOfOperation (storeContext .getInstrumentation (),
196199 MULTIPART_UPLOAD_LIST .getSymbol (),
197- () -> s3 .listMultipartUploads (req )));
200+ () -> s3 .listMultipartUploads (requestBuilder . build () )));
198201 LOG .debug ("Listing found {} upload(s)" ,
199- listing .getMultipartUploads ().size ());
202+ listing .uploads ().size ());
200203 LOG .debug ("New listing state: {}" , this );
201204 }
202205 }
@@ -216,14 +219,14 @@ public static class UploadIterator
216219 */
217220 private ListingIterator lister ;
218221 /** Current listing: the last upload listing we fetched. */
219- private MultipartUploadListing listing ;
222+ private ListMultipartUploadsResponse listing ;
220223 /** Iterator over the current listing. */
221224 private ListIterator <MultipartUpload > batchIterator ;
222225
223226 @ Retries .RetryTranslated
224227 public UploadIterator (
225228 final StoreContext storeContext ,
226- AmazonS3 s3 ,
229+ S3Client s3 ,
227230 int maxKeys ,
228231 @ Nullable String prefix )
229232 throws IOException {
@@ -249,7 +252,7 @@ public MultipartUpload next() throws IOException {
249252 private boolean requestNextBatch () throws IOException {
250253 if (lister .hasNext ()) {
251254 listing = lister .next ();
252- batchIterator = listing .getMultipartUploads ().listIterator ();
255+ batchIterator = listing .uploads ().listIterator ();
253256 return batchIterator .hasNext ();
254257 }
255258 return false ;
0 commit comments