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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 12.0.0-beta.2 (Unreleased)
- This release contains bug fixes to improve quality.
- Added option to `BlobStorageResourceContainerOptions` to choose `BlobType` when uploading blobs.

## 12.0.0-beta.1 (2022-12-15)
- This preview is the first release of a ground-up rewrite of our client data movement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public BlobStorageResourceContainer(Azure.Storage.Blobs.BlobContainerClient blob
public partial class BlobStorageResourceContainerOptions
{
public BlobStorageResourceContainerOptions() { }
public Azure.Storage.Blobs.Models.BlobType BlobType { get { throw null; } set { } }
public Azure.Storage.DataMovement.Models.TransferCopyMethod CopyMethod { get { throw null; } set { } }
public Azure.Storage.Blobs.Models.BlobStates States { get { throw null; } set { } }
public Azure.Storage.Blobs.Models.BlobTraits Traits { get { throw null; } set { } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using Azure.Storage.Blobs.Specialized;
using Azure.Storage.DataMovement;
using Azure.Storage.DataMovement.Models;

namespace Azure.Storage.DataMovement.Blobs
{
Expand Down Expand Up @@ -85,9 +80,23 @@ public BlobDirectoryStorageResourceContainer(
public override StorageResource GetChildStorageResource(string path)
{
// Recreate the blobName using the existing parent directory path
return new BlockBlobStorageResource(
_blobContainerClient.GetBlockBlobClient(System.IO.Path.Combine(_directoryPrefix, path)),
_options.ToBlockBlobStorageResourceOptions());
switch (_options.BlobType)
{
case BlobType.Block:
return new BlockBlobStorageResource(
_blobContainerClient.GetBlockBlobClient(System.IO.Path.Combine(_directoryPrefix, path)),
_options.ToBlockBlobStorageResourceOptions());
case BlobType.Append:
return new AppendBlobStorageResource(
_blobContainerClient.GetAppendBlobClient(System.IO.Path.Combine(_directoryPrefix, path)),
_options.ToAppendBlobStorageResourceOptions());
case BlobType.Page:
return new PageBlobStorageResource(
_blobContainerClient.GetPageBlobClient(System.IO.Path.Combine(_directoryPrefix, path)),
_options.ToPageBlobStorageResourceOptions());
default:
throw new ArgumentException("Invalid BlobType.");
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using Azure.Storage.Blobs.Specialized;
using Azure.Storage.DataMovement.Models;

namespace Azure.Storage.DataMovement.Blobs
{
Expand Down Expand Up @@ -58,7 +57,23 @@ public BlobStorageResourceContainer(BlobContainerClient blobContainerClient, Blo
/// <param name="path">The path to the storage resource.</param>
public override StorageResource GetChildStorageResource(string path)
{
return new BlockBlobStorageResource(_blobContainerClient.GetBlockBlobClient(string.Join("/", path)));
switch (_options.BlobType)
{
case BlobType.Block:
return new BlockBlobStorageResource(
_blobContainerClient.GetBlockBlobClient(string.Join("/", path)),
_options.ToBlockBlobStorageResourceOptions());
case BlobType.Append:
return new AppendBlobStorageResource(
_blobContainerClient.GetAppendBlobClient(string.Join("/", path)),
_options.ToAppendBlobStorageResourceOptions());
case BlobType.Page:
return new PageBlobStorageResource(
_blobContainerClient.GetPageBlobClient(string.Join("/", path)),
_options.ToPageBlobStorageResourceOptions());
default:
throw new ArgumentException("Invalid BlobType.");
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using Azure.Storage.DataMovement;
using Azure.Storage.Blobs.Models;
using Azure.Storage.DataMovement.Models;

Expand Down Expand Up @@ -34,5 +31,12 @@ public class BlobStorageResourceContainerOptions
/// Only applies when calling <see cref="BlockBlobStorageResource.CopyBlockFromUriAsync(StorageResource, HttpRange, bool, long, StorageResourceCopyFromUriOptions, System.Threading.CancellationToken)"/>.
/// </summary>
public TransferCopyMethod CopyMethod { get; set; }

/// <summary>
/// The <see cref="BlobType"/> that will be used when uploading blobs to the destination.
///
/// Defaults to <see cref="BlobType.Block"/>.
/// </summary>
public BlobType BlobType { get; set; } = BlobType.Block;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,58 @@ await UploadBlobDirectoryAndVerify(
Directory.Delete(folder, true);
}
}

[Test]
[LiveOnly]
[TestCase(BlobType.Block)]
[TestCase(BlobType.Append)]
[TestCase(BlobType.Page)]
public async Task DirectoryUpload_BlobType(BlobType blobType)
{
// Arrange
await using DisposingBlobContainer test = await GetTestContainerAsync();

string dirName = GetNewBlobName();
string folder = CreateRandomDirectory(Path.GetTempPath());
try
{
string file1 = await CreateRandomFileAsync(folder);
string openSubfolder = CreateRandomDirectory(folder);
string file2 = await CreateRandomFileAsync(openSubfolder);
string destinationPrefix = "foo";

TransferManager transferManager = new TransferManager();

StorageResourceContainer sourceResource = new LocalDirectoryStorageResourceContainer(folder);
BlobStorageResourceContainerOptions options = new BlobStorageResourceContainerOptions()
{
BlobType = blobType
};
StorageResourceContainer destinationResource = new BlobDirectoryStorageResourceContainer(
test.Container,
destinationPrefix,
options);

// Act
DataTransfer transfer = await transferManager.StartTransferAsync(sourceResource, destinationResource);
await transfer.AwaitCompletion();

// Assert
AsyncPageable<BlobItem> blobs = test.Container.GetBlobsAsync(prefix: destinationPrefix);
await foreach (BlobItem blob in blobs)
{
Assert.AreEqual(blob.Properties.BlobType, blobType);
}
}
catch (Exception ex)
{
Assert.Fail(ex.StackTrace);
}
finally
{
Directory.Delete(folder, true);
}
}
#endregion DirectoryUploadTests

#region Single Concurrency
Expand Down