Search in sources :

Example 1 with Progress

use of software.amazon.awssdk.services.s3.model.Progress in project aws-doc-sdk-examples by awsdocs.

the class ListMultipartUploads method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    <bucketName> \n\n" + "Where:\n" + "    bucketName - the name of the Amazon S3 bucket where an in-progress multipart upload is occurring.\n\n";
    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String bucketName = args[0];
    Region region = Region.US_WEST_2;
    S3Client s3 = S3Client.builder().region(region).build();
    listUploads(s3, bucketName);
    s3.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) S3Client(software.amazon.awssdk.services.s3.S3Client)

Example 2 with Progress

use of software.amazon.awssdk.services.s3.model.Progress in project djl by deepjavalibrary.

the class S3Repository method download.

/**
 * {@inheritDoc}
 */
@Override
protected void download(Path tmp, URI baseUri, Artifact.Item item, Progress progress) throws IOException {
    String key = item.getUri();
    logger.debug("Downloading artifact from: s3://{}/{} ...", bucket, key);
    GetObjectRequest req = GetObjectRequest.builder().bucket(bucket).key(key).build();
    try (ResponseInputStream<GetObjectResponse> is = client.getObject(req)) {
        save(is, tmp, item, progress);
    }
}
Also used : GetObjectResponse(software.amazon.awssdk.services.s3.model.GetObjectResponse) GetObjectRequest(software.amazon.awssdk.services.s3.model.GetObjectRequest)

Example 3 with Progress

use of software.amazon.awssdk.services.s3.model.Progress in project datarouter by hotpads.

the class BaseDatarouterS3Client method handleTransfer.

private void handleTransfer(Transfer transfer, Runnable heartbeat) {
    TransferProgress progress = transfer.getProgress();
    long totalBytesToTransfer = progress.getTotalBytesToTransfer();
    while (!transfer.isDone()) {
        try {
            heartbeat.run();
        } catch (Exception e) {
            logger.error("couldn't heartbeat", e);
        }
        logger.warn("{} / {} pct={} bytesTransferred={} totalBytesToTransfer={}", ByteUnitTool.byteCountToDisplaySize(progress.getBytesTransferred()), ByteUnitTool.byteCountToDisplaySize(totalBytesToTransfer), NumberFormatter.format(progress.getPercentTransferred(), 2), progress.getBytesTransferred(), totalBytesToTransfer);
        ThreadTool.sleepUnchecked(1000L);
    }
}
Also used : S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) NoSuchBucketException(software.amazon.awssdk.services.s3.model.NoSuchBucketException) NoSuchKeyException(software.amazon.awssdk.services.s3.model.NoSuchKeyException) IOException(java.io.IOException) TransferProgress(com.amazonaws.services.s3.transfer.TransferProgress)

Example 4 with Progress

use of software.amazon.awssdk.services.s3.model.Progress in project aws-doc-sdk-examples by awsdocs.

the class ListMultipartUploads method listUploads.

// snippet-start:[s3.java2.list_multi_uploads.main]
public static void listUploads(S3Client s3, String bucketName) {
    try {
        ListMultipartUploadsRequest listMultipartUploadsRequest = ListMultipartUploadsRequest.builder().bucket(bucketName).build();
        ListMultipartUploadsResponse response = s3.listMultipartUploads(listMultipartUploadsRequest);
        List<MultipartUpload> uploads = response.uploads();
        for (MultipartUpload upload : uploads) {
            System.out.println("Upload in progress: Key = \"" + upload.key() + "\", id = " + upload.uploadId());
        }
    } catch (S3Exception e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
}
Also used : ListMultipartUploadsResponse(software.amazon.awssdk.services.s3.model.ListMultipartUploadsResponse) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) MultipartUpload(software.amazon.awssdk.services.s3.model.MultipartUpload) ListMultipartUploadsRequest(software.amazon.awssdk.services.s3.model.ListMultipartUploadsRequest)

Example 5 with Progress

use of software.amazon.awssdk.services.s3.model.Progress in project aws-sdk-java-v2 by aws.

the class UploadMultiplePartTestBase method uploadMultiplePart_abort.

@Test
public void uploadMultiplePart_abort() throws Exception {
    String key = "uploadMultiplePart_abort";
    // 1. Initiate multipartUpload request
    String uploadId = initiateMultipartUpload(key);
    int partCount = 3;
    // 2. Upload each part
    List<String> contentsToUpload = new ArrayList<>();
    List<UploadPartResponse> uploadPartResponses = uploadParts(key, uploadId, partCount, contentsToUpload);
    // 3. abort the multipart upload
    AbortMultipartUploadResponse abortMultipartUploadResponse = abortMultipartUploadResponseCallable(AbortMultipartUploadRequest.builder().bucket(BUCKET).key(key).uploadId(uploadId).build()).call();
    // Verify no in-progress multipart uploads
    ListMultipartUploadsResponse listMultipartUploadsResponse = listMultipartUploads(BUCKET).call();
    List<MultipartUpload> uploads = listMultipartUploadsResponse.uploads();
    assertThat(uploads).isEmpty();
}
Also used : ListMultipartUploadsResponse(software.amazon.awssdk.services.s3.model.ListMultipartUploadsResponse) AbortMultipartUploadResponse(software.amazon.awssdk.services.s3.model.AbortMultipartUploadResponse) ArrayList(java.util.ArrayList) UploadPartResponse(software.amazon.awssdk.services.s3.model.UploadPartResponse) MultipartUpload(software.amazon.awssdk.services.s3.model.MultipartUpload) CompletedMultipartUpload(software.amazon.awssdk.services.s3.model.CompletedMultipartUpload) Test(org.junit.Test)

Aggregations

ListMultipartUploadsResponse (software.amazon.awssdk.services.s3.model.ListMultipartUploadsResponse)2 MultipartUpload (software.amazon.awssdk.services.s3.model.MultipartUpload)2 S3Exception (software.amazon.awssdk.services.s3.model.S3Exception)2 TransferProgress (com.amazonaws.services.s3.transfer.TransferProgress)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 Region (software.amazon.awssdk.regions.Region)1 S3Client (software.amazon.awssdk.services.s3.S3Client)1 AbortMultipartUploadResponse (software.amazon.awssdk.services.s3.model.AbortMultipartUploadResponse)1 CompletedMultipartUpload (software.amazon.awssdk.services.s3.model.CompletedMultipartUpload)1 GetObjectRequest (software.amazon.awssdk.services.s3.model.GetObjectRequest)1 GetObjectResponse (software.amazon.awssdk.services.s3.model.GetObjectResponse)1 ListMultipartUploadsRequest (software.amazon.awssdk.services.s3.model.ListMultipartUploadsRequest)1 NoSuchBucketException (software.amazon.awssdk.services.s3.model.NoSuchBucketException)1 NoSuchKeyException (software.amazon.awssdk.services.s3.model.NoSuchKeyException)1 UploadPartResponse (software.amazon.awssdk.services.s3.model.UploadPartResponse)1