Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataMovement StorageResource construction refactor | Part 2 #38221

Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 7 additions & 1 deletion sdk/storage/Azure.Storage.Blobs/src/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@
"012ea67d2479751a0b8c087a4185541b851bd8b16f8d91b840e51b1cb0ba6fe647997e57429265" +
"e85ef62d565db50a69ae1647d54d7bd855e4db3d8a91510e5bcbd0edfbbecaa20a7bd9ae74593d" +
"aa7b11b4")]
[assembly: InternalsVisibleTo("Azure.Storage.DataMovement.Blobs.Tests, PublicKey=" +
"0024000004800000940000000602000000240000525341310004000001000100d15ddcb2968829" +
"5338af4b7686603fe614abd555e09efba8fb88ee09e1f7b1ccaeed2e8f823fa9eef3fdd60217fc" +
"012ea67d2479751a0b8c087a4185541b851bd8b16f8d91b840e51b1cb0ba6fe647997e57429265" +
"e85ef62d565db50a69ae1647d54d7bd855e4db3d8a91510e5bcbd0edfbbecaa20a7bd9ae74593d" +
"aa7b11b4")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
[assembly: Azure.Core.AzureResourceProviderNamespace("Microsoft.Storage")]
[assembly: Azure.Core.AzureResourceProviderNamespace("Microsoft.Storage")]
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System;
using System.Text;

namespace Azure.Storage.Tests
{
Expand All @@ -18,5 +19,19 @@ public static string NextString(this Random random, int length)
}
return new string(buffer);
}

public static Span<byte> NextBytesInline(this Random random, int length)
{
var buffer = new byte[length];
random.NextBytes(buffer);
return new Span<byte>(buffer);
}

public static string NextBase64(this Random random, int length)
{
var buffer = new byte[length];
random.NextBytes(buffer);
return Convert.ToBase64String(buffer);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ namespace Azure.Storage.DataMovement.Blobs
/// </summary>
public class BlobStorageResourceContainer : StorageResourceContainer
{
private BlobContainerClient _blobContainerClient;
private string _directoryPrefix;
internal BlobContainerClient BlobContainerClient { get; }
internal string DirectoryPrefix { get; }
private BlobStorageResourceContainerOptions _options;

private bool IsDirectory => _directoryPrefix != null;
private bool IsDirectory => DirectoryPrefix != null;

/// <summary>
/// The constructor to create an instance of the BlobStorageResourceContainer.
Expand All @@ -34,16 +34,16 @@ public class BlobStorageResourceContainer : StorageResourceContainer
/// <param name="options">Options for the storage resource. See <see cref="BlobStorageResourceContainerOptions"/>.</param>
public BlobStorageResourceContainer(BlobContainerClient blobContainerClient, BlobStorageResourceContainerOptions options = default)
{
_blobContainerClient = blobContainerClient;
BlobContainerClient = blobContainerClient;
_options = options;
_directoryPrefix = _options?.BlobDirectoryPrefix;
DirectoryPrefix = _options?.BlobDirectoryPrefix;

Uri = _directoryPrefix != null
? new BlobUriBuilder(_blobContainerClient.Uri)
Uri = DirectoryPrefix != null
? new BlobUriBuilder(BlobContainerClient.Uri)
{
BlobName = _directoryPrefix,
BlobName = DirectoryPrefix,
}.ToUri()
: _blobContainerClient.Uri;
: BlobContainerClient.Uri;
}

/// <summary>
Expand All @@ -55,7 +55,7 @@ public BlobStorageResourceContainer(BlobContainerClient blobContainerClient, Blo
/// Gets the path of the storage resource.
/// Return empty string since we are using the root of the container.
/// </summary>
public override string Path => _directoryPrefix ?? string.Empty;
public override string Path => DirectoryPrefix ?? string.Empty;

/// <summary>
/// Gets the URL of the storage resource.
Expand Down Expand Up @@ -89,7 +89,7 @@ private StorageResourceItem GetBlobAsStorageResource(
// Recreate the blobName using the existing parent directory path
if (type == BlobType.Append)
{
AppendBlobClient client = _blobContainerClient.GetAppendBlobClient(blobName);
AppendBlobClient client = BlobContainerClient.GetAppendBlobClient(blobName);
return new AppendBlobStorageResource(
client,
length,
Expand All @@ -98,7 +98,7 @@ private StorageResourceItem GetBlobAsStorageResource(
}
else if (type == BlobType.Page)
{
PageBlobClient client = _blobContainerClient.GetPageBlobClient(blobName);
PageBlobClient client = BlobContainerClient.GetPageBlobClient(blobName);
return new PageBlobStorageResource(
client,
length,
Expand All @@ -107,7 +107,7 @@ private StorageResourceItem GetBlobAsStorageResource(
}
else // (type == BlobType.Block)
{
BlockBlobClient client = _blobContainerClient.GetBlockBlobClient(blobName);
BlockBlobClient client = BlobContainerClient.GetBlockBlobClient(blobName);
return new BlockBlobStorageResource(
client,
length,
Expand All @@ -125,8 +125,8 @@ private StorageResourceItem GetBlobAsStorageResource(
protected override async IAsyncEnumerable<StorageResource> GetStorageResourcesAsync(
[EnumeratorCancellation] CancellationToken cancellationToken = default)
{
AsyncPageable<BlobItem> pages = _blobContainerClient.GetBlobsAsync(
prefix: _directoryPrefix,
AsyncPageable<BlobItem> pages = BlobContainerClient.GetBlobsAsync(
prefix: DirectoryPrefix,
cancellationToken: cancellationToken);
await foreach (BlobItem blobItem in pages.ConfigureAwait(false))
{
Expand Down Expand Up @@ -320,7 +320,7 @@ await checkpointer.GetBlobContainerOptionsAsync(

private string ApplyOptionalPrefix(string path)
=> IsDirectory
? string.Join("/", _directoryPrefix, path)
? string.Join("/", DirectoryPrefix, path)
: path;
}
}
Loading