Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions generator/.DevConfigs/77d980ad-8f58-4f2e-97f8-d2c8c5ba3732.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"services": [
{
"serviceName": "S3",
"type": "minor",
"changeLogMessages": [
"Create new UploadWithResponse API that returns response metadata information for transfer utility."
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

namespace Amazon.S3.Transfer.Internal
{
internal partial class AbortMultipartUploadsCommand : BaseCommand
internal partial class AbortMultipartUploadsCommand : BaseCommand<TransferUtilityAbortMultipartUploadsResponse>
{
IAmazonS3 _s3Client;
TransferUtilityAbortMultipartUploadRequest _request;
Expand Down
11 changes: 5 additions & 6 deletions sdk/src/Services/S3/Custom/Transfer/Internal/BaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@

namespace Amazon.S3.Transfer.Internal
{
internal abstract partial class BaseCommand
/// <summary>
/// Generic base command that returns a typed response
/// </summary>
/// <typeparam name="TResponse">Type of response returned by the command</typeparam>
internal abstract partial class BaseCommand<TResponse> where TResponse : class
{
public virtual object Return
{
get { return null; }
}

internal GetObjectRequest ConvertToGetObjectRequest(BaseDownloadRequest request)
{
GetObjectRequest getRequest = new GetObjectRequest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

namespace Amazon.S3.Transfer.Internal
{
internal partial class DownloadCommand : BaseCommand
internal partial class DownloadCommand : BaseCommand<TransferUtilityDownloadResponse>
{
static int MAX_BACKOFF_IN_MILLISECONDS = (int)TimeSpan.FromSeconds(30).TotalMilliseconds;

Expand Down Expand Up @@ -176,4 +176,3 @@ static ByteRange ByteRangeRemainingForDownload(string filepath)
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

namespace Amazon.S3.Transfer.Internal
{
internal partial class DownloadDirectoryCommand : BaseCommand
internal partial class DownloadDirectoryCommand : BaseCommand<TransferUtilityDownloadDirectoryResponse>
{
private readonly IAmazonS3 _s3Client;
private readonly TransferUtilityDownloadDirectoryRequest _request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Amazon.S3.Transfer.Internal
/// <summary>
/// The command to manage an upload using the S3 multipart API.
/// </summary>
internal partial class MultipartUploadCommand : BaseCommand
internal partial class MultipartUploadCommand : BaseCommand<TransferUtilityUploadResponse>
{
IAmazonS3 _s3Client;
long _partSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

namespace Amazon.S3.Transfer.Internal
{
internal partial class OpenStreamCommand : BaseCommand
internal partial class OpenStreamCommand : BaseCommand<TransferUtilityOpenStreamResponse>
{
IAmazonS3 _s3Client;
TransferUtilityOpenStreamRequest _request;
Expand Down Expand Up @@ -59,10 +59,5 @@ internal Stream ResponseStream
{
get { return this._responseStream; }
}

public override object Return
{
get { return this.ResponseStream; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Amazon.S3.Transfer.Internal
/// <summary>
/// This command is for doing regular PutObject requests.
/// </summary>
internal partial class SimpleUploadCommand : BaseCommand
internal partial class SimpleUploadCommand : BaseCommand<TransferUtilityUploadResponse>
{
IAmazonS3 _s3Client;
TransferUtilityConfig _config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Amazon.S3.Transfer.Internal
/// This command files all the files that meets the criteria specified in the TransferUtilityUploadDirectoryRequest request
/// and uploads them.
/// </summary>
internal partial class UploadDirectoryCommand : BaseCommand
internal partial class UploadDirectoryCommand : BaseCommand<TransferUtilityUploadDirectoryResponse>
{
TransferUtilityUploadDirectoryRequest _request;
TransferUtility _utility;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

namespace Amazon.S3.Transfer.Internal
{
internal partial class AbortMultipartUploadsCommand : BaseCommand
internal partial class AbortMultipartUploadsCommand : BaseCommand<TransferUtilityAbortMultipartUploadsResponse>
{

public override async Task ExecuteAsync(CancellationToken cancellationToken)
public override async Task<TransferUtilityAbortMultipartUploadsResponse> ExecuteAsync(CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(this._request.BucketName))
{
Expand Down Expand Up @@ -84,6 +84,8 @@ await asyncThrottler.WaitAsync(cancellationToken)

await WhenAllOrFirstExceptionAsync(pendingTasks,cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);

return new TransferUtilityAbortMultipartUploadsResponse();
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@

namespace Amazon.S3.Transfer.Internal
{
internal abstract partial class BaseCommand
internal abstract partial class BaseCommand<TResponse> where TResponse : class
{
public abstract Task ExecuteAsync(CancellationToken cancellationToken);
/// <summary>
/// Executes the command and returns a typed response
/// </summary>
public abstract Task<TResponse> ExecuteAsync(CancellationToken cancellationToken);

/// <summary>
/// Waits for all of the tasks to complete or till any task fails or is canceled.
Expand Down Expand Up @@ -80,7 +83,7 @@ await completedTask
}
}

protected static async Task ExecuteCommandAsync(BaseCommand command, CancellationTokenSource internalCts, SemaphoreSlim throttler)
protected static async Task ExecuteCommandAsync<T>(BaseCommand<T> command, CancellationTokenSource internalCts, SemaphoreSlim throttler) where T : class
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@

namespace Amazon.S3.Transfer.Internal
{
internal partial class DownloadCommand : BaseCommand
internal partial class DownloadCommand : BaseCommand<TransferUtilityDownloadResponse>
{
public override async Task ExecuteAsync(CancellationToken cancellationToken)
public override async Task<TransferUtilityDownloadResponse> ExecuteAsync(CancellationToken cancellationToken)
{
ValidateRequest();
GetObjectRequest getRequest = ConvertToGetObjectRequest(this._request);
Expand Down Expand Up @@ -130,6 +130,9 @@ await response.WriteResponseStreamToFileAsync(this._request.FilePath, true, canc
}
WaitBeforeRetry(retries);
} while (shouldRetry);

// TODO map and return response
return new TransferUtilityDownloadResponse();
}

private static bool HandleExceptionForHttpClient(Exception exception, int retries, int maxRetries)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@

namespace Amazon.S3.Transfer.Internal
{
internal partial class MultipartUploadCommand : BaseCommand
internal partial class MultipartUploadCommand : BaseCommand<TransferUtilityUploadResponse>
{
public SemaphoreSlim AsyncThrottler { get; set; }

Dictionary<int, ExpectedUploadPart> _expectedUploadParts = new Dictionary<int, ExpectedUploadPart>();

public override async Task ExecuteAsync(CancellationToken cancellationToken)
public override async Task<TransferUtilityUploadResponse> ExecuteAsync(CancellationToken cancellationToken)
{
// Fire transfer initiated event FIRST, before choosing path
FireTransferInitiatedEvent();

if ( (this._fileTransporterRequest.InputStream != null && !this._fileTransporterRequest.InputStream.CanSeek) || this._fileTransporterRequest.ContentLength == -1)
{
await UploadUnseekableStreamAsync(this._fileTransporterRequest, cancellationToken).ConfigureAwait(false);
return await UploadUnseekableStreamAsync(this._fileTransporterRequest, cancellationToken).ConfigureAwait(false);
}
else
{
Expand Down Expand Up @@ -144,6 +144,7 @@ await localThrottler.WaitAsync(cancellationToken)

var mappedResponse = ResponseMapper.MapCompleteMultipartUploadResponse(completeResponse);
FireTransferCompletedEvent(mappedResponse);
return mappedResponse;
}
catch (Exception e)
{
Expand Down Expand Up @@ -275,7 +276,7 @@ private void AbortMultipartUpload(string uploadId)
Logger.InfoFormat("Error attempting to abort multipart for key {0}: {1}", this._fileTransporterRequest.Key, e.Message);
}
}
private async Task UploadUnseekableStreamAsync(TransferUtilityUploadRequest request, CancellationToken cancellationToken = default(CancellationToken))
private async Task<TransferUtilityUploadResponse> UploadUnseekableStreamAsync(TransferUtilityUploadRequest request, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();

Expand Down Expand Up @@ -376,6 +377,7 @@ private void AbortMultipartUpload(string uploadId)

var mappedResponse = ResponseMapper.MapCompleteMultipartUploadResponse(completeResponse);
FireTransferCompletedEvent(mappedResponse);
return mappedResponse;
}
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@

namespace Amazon.S3.Transfer.Internal
{
internal partial class OpenStreamCommand : BaseCommand
internal partial class OpenStreamCommand : BaseCommand<TransferUtilityOpenStreamResponse>
{
public override async Task ExecuteAsync(CancellationToken cancellationToken)
public override async Task<TransferUtilityOpenStreamResponse> ExecuteAsync(CancellationToken cancellationToken)
{
var getRequest = ConstructRequest();
var response = await _s3Client.GetObjectAsync(getRequest, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);
_responseStream = response.ResponseStream;
// TODO map and return response
return new TransferUtilityOpenStreamResponse();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

namespace Amazon.S3.Transfer.Internal
{
internal partial class SimpleUploadCommand : BaseCommand
internal partial class SimpleUploadCommand : BaseCommand<TransferUtilityUploadResponse>
{
public SemaphoreSlim AsyncThrottler { get; set; }

public override async Task ExecuteAsync(CancellationToken cancellationToken)
public override async Task<TransferUtilityUploadResponse> ExecuteAsync(CancellationToken cancellationToken)
{
try
{
Expand All @@ -47,6 +47,8 @@ await this.AsyncThrottler.WaitAsync(cancellationToken)
var mappedResponse = ResponseMapper.MapPutObjectResponse(response);

FireTransferCompletedEvent(mappedResponse);

return mappedResponse;
}
catch (Exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

namespace Amazon.S3.Transfer.Internal
{
internal partial class DownloadDirectoryCommand : BaseCommand
internal partial class DownloadDirectoryCommand : BaseCommand<TransferUtilityDownloadDirectoryResponse>
{

TransferUtilityConfig _config;
Expand All @@ -38,7 +38,7 @@ internal DownloadDirectoryCommand(IAmazonS3 s3Client, TransferUtilityDownloadDir
this._config = config;
}

public override async Task ExecuteAsync(CancellationToken cancellationToken)
public override async Task<TransferUtilityDownloadDirectoryResponse> ExecuteAsync(CancellationToken cancellationToken)
{
ValidateRequest();
EnsureDirectoryExists(new DirectoryInfo(this._request.LocalDirectory));
Expand Down Expand Up @@ -112,6 +112,8 @@ await asyncThrottler.WaitAsync(cancellationToken)
}
await WhenAllOrFirstExceptionAsync(pendingTasks, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);

return new TransferUtilityDownloadDirectoryResponse();
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

namespace Amazon.S3.Transfer.Internal
{
internal partial class UploadDirectoryCommand : BaseCommand
internal partial class UploadDirectoryCommand : BaseCommand<TransferUtilityUploadDirectoryResponse>
{
public bool UploadFilesConcurrently { get; set; }

public override async Task ExecuteAsync(CancellationToken cancellationToken)
public override async Task<TransferUtilityUploadDirectoryResponse> ExecuteAsync(CancellationToken cancellationToken)
{
string prefix = GetKeyPrefix();

Expand Down Expand Up @@ -87,6 +87,8 @@ await WhenAllOrFirstExceptionAsync(pendingTasks, cancellationToken)
if (asyncThrottler != null)
asyncThrottler.Dispose();
}

return new TransferUtilityUploadDirectoryResponse();
}

private Task<string[]> GetFiles(string path, string searchPattern, SearchOption searchOption, CancellationToken cancellationToken)
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/Services/S3/Custom/Transfer/TransferUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ private static TransferUtilityUploadRequest ConstructUploadRequest(Stream stream
};
}

internal BaseCommand GetUploadCommand(TransferUtilityUploadRequest request)
internal BaseCommand<TransferUtilityUploadResponse> GetUploadCommand(TransferUtilityUploadRequest request)
{
validate(request);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file.
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* *****************************************************************************
* __ _ _ ___
* ( )( \/\/ )/ __)
* /__\ \ / \__ \
* (_)(_) \/\/ (___/
*
* AWS SDK for .NET
* API Version: 2006-03-01
*
*/

using Amazon.Runtime;

namespace Amazon.S3.Transfer
{
/// <summary>
/// Response object for Transfer Utility abort multipart uploads operations.
/// Contains response metadata from abort multipart uploads operations.
/// </summary>
public class TransferUtilityAbortMultipartUploadsResponse
{
// Empty placeholder class - properties will be added in future iterations
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

using Amazon.Runtime;

namespace Amazon.S3.Transfer
{
/// <summary>
/// Contains the details returned from a Transfer Utility download directory operation.
/// </summary>
public class TransferUtilityDownloadDirectoryResponse
{
}
}
Loading