Skip to content

Commit 5908df7

Browse files
DataMovement Resource Providers (Azure#37273)
* ResourceProviders from static rehydrate methods * fix sample * another sample fix * await transfers * update to rehydrate apis from main * revert sample * fields -> properties * tests and bugfix * exportapi * testing * test work * test fixes * fix tests and rerecord * docstrings * rename classes
1 parent 13e0ff5 commit 5908df7

File tree

90 files changed

+894
-94
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+894
-94
lines changed

sdk/storage/Azure.Storage.DataMovement.Blobs/api/Azure.Storage.DataMovement.Blobs.net6.0.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ public BlobStorageResourceOptions() { }
7171
public System.Collections.Generic.IDictionary<string, string> Tags { get { throw null; } set { } }
7272
public Azure.Storage.UploadTransferValidationOptions UploadTransferValidationOptions { get { throw null; } set { } }
7373
}
74+
public partial class BlobStorageResourceProvider
75+
{
76+
internal BlobStorageResourceProvider() { }
77+
public System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> MakeResourceAsync(Azure.AzureSasCredential credential, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
78+
public System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> MakeResourceAsync(Azure.Core.TokenCredential credential, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
79+
public System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> MakeResourceAsync(Azure.Storage.StorageSharedKeyCredential credential, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
80+
public System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> MakeResourceAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
81+
}
82+
public static partial class BlobStorageResources
83+
{
84+
public static bool TryGetResourceProviders(Azure.Storage.DataMovement.Models.DataTransferProperties info, out Azure.Storage.DataMovement.Blobs.BlobStorageResourceProvider sourceProvider, out Azure.Storage.DataMovement.Blobs.BlobStorageResourceProvider destinationProvider) { throw null; }
85+
}
7486
public partial class BlockBlobStorageResource : Azure.Storage.DataMovement.StorageResourceSingle
7587
{
7688
public BlockBlobStorageResource(Azure.Storage.Blobs.Specialized.BlockBlobClient blobClient, Azure.Storage.DataMovement.Blobs.BlockBlobStorageResourceOptions options = null) { }

sdk/storage/Azure.Storage.DataMovement.Blobs/api/Azure.Storage.DataMovement.Blobs.netstandard2.0.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ public BlobStorageResourceOptions() { }
7171
public System.Collections.Generic.IDictionary<string, string> Tags { get { throw null; } set { } }
7272
public Azure.Storage.UploadTransferValidationOptions UploadTransferValidationOptions { get { throw null; } set { } }
7373
}
74+
public partial class BlobStorageResourceProvider
75+
{
76+
internal BlobStorageResourceProvider() { }
77+
public System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> MakeResourceAsync(Azure.AzureSasCredential credential, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
78+
public System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> MakeResourceAsync(Azure.Core.TokenCredential credential, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
79+
public System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> MakeResourceAsync(Azure.Storage.StorageSharedKeyCredential credential, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
80+
public System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> MakeResourceAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
81+
}
82+
public static partial class BlobStorageResources
83+
{
84+
public static bool TryGetResourceProviders(Azure.Storage.DataMovement.Models.DataTransferProperties info, out Azure.Storage.DataMovement.Blobs.BlobStorageResourceProvider sourceProvider, out Azure.Storage.DataMovement.Blobs.BlobStorageResourceProvider destinationProvider) { throw null; }
85+
}
7486
public partial class BlockBlobStorageResource : Azure.Storage.DataMovement.StorageResourceSingle
7587
{
7688
public BlockBlobStorageResource(Azure.Storage.Blobs.Specialized.BlockBlobClient blobClient, Azure.Storage.DataMovement.Blobs.BlockBlobStorageResourceOptions options = null) { }

sdk/storage/Azure.Storage.DataMovement.Blobs/api/Azure.Storage.DataMovement.Blobs.netstandard2.1.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ public BlobStorageResourceOptions() { }
7171
public System.Collections.Generic.IDictionary<string, string> Tags { get { throw null; } set { } }
7272
public Azure.Storage.UploadTransferValidationOptions UploadTransferValidationOptions { get { throw null; } set { } }
7373
}
74+
public partial class BlobStorageResourceProvider
75+
{
76+
internal BlobStorageResourceProvider() { }
77+
public System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> MakeResourceAsync(Azure.AzureSasCredential credential, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
78+
public System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> MakeResourceAsync(Azure.Core.TokenCredential credential, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
79+
public System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> MakeResourceAsync(Azure.Storage.StorageSharedKeyCredential credential, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
80+
public System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> MakeResourceAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
81+
}
82+
public static partial class BlobStorageResources
83+
{
84+
public static bool TryGetResourceProviders(Azure.Storage.DataMovement.Models.DataTransferProperties info, out Azure.Storage.DataMovement.Blobs.BlobStorageResourceProvider sourceProvider, out Azure.Storage.DataMovement.Blobs.BlobStorageResourceProvider destinationProvider) { throw null; }
85+
}
7486
public partial class BlockBlobStorageResource : Azure.Storage.DataMovement.StorageResourceSingle
7587
{
7688
public BlockBlobStorageResource(Azure.Storage.Blobs.Specialized.BlockBlobClient blobClient, Azure.Storage.DataMovement.Blobs.BlockBlobStorageResourceOptions options = null) { }
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
using Azure.Core;
8+
using Azure.Storage.DataMovement.Models;
9+
10+
namespace Azure.Storage.DataMovement.Blobs
11+
{
12+
/// <summary>
13+
/// Provider for a <see cref="StorageResource"/> configured for an Azure Blob Storage resource.
14+
/// </summary>
15+
public class BlobStorageResourceProvider
16+
{
17+
internal DataTransferProperties Properties { get; }
18+
internal bool MakesSource { get; }
19+
internal BlobStorageResources.ResourceType ResourceType { get; }
20+
21+
internal BlobStorageResourceProvider(
22+
DataTransferProperties properties,
23+
bool asSource,
24+
BlobStorageResources.ResourceType resourceType)
25+
{
26+
Argument.AssertNotNull(properties, nameof(properties));
27+
if (resourceType == BlobStorageResources.ResourceType.Unknown)
28+
{
29+
throw BadResourceTypeException(resourceType);
30+
}
31+
32+
Properties = properties;
33+
MakesSource = asSource;
34+
ResourceType = resourceType;
35+
}
36+
37+
/// <summary>
38+
/// Creates the configured <see cref="StorageResource"/> instance using the given <see cref="StorageSharedKeyCredential"/>.
39+
/// </summary>
40+
/// <returns></returns>
41+
public async Task<StorageResource> MakeResourceAsync(StorageSharedKeyCredential credential, CancellationToken cancellationToken = default)
42+
{
43+
return ResourceType switch
44+
{
45+
BlobStorageResources.ResourceType.BlockBlob => await BlockBlobStorageResource
46+
.RehydrateResourceAsync(Properties, MakesSource, credential, cancellationToken)
47+
.ConfigureAwait(false),
48+
BlobStorageResources.ResourceType.PageBlob => await PageBlobStorageResource
49+
.RehydrateResourceAsync(Properties, MakesSource, credential, cancellationToken)
50+
.ConfigureAwait(false),
51+
BlobStorageResources.ResourceType.AppendBlob => await AppendBlobStorageResource
52+
.RehydrateResourceAsync(Properties, MakesSource, credential, cancellationToken)
53+
.ConfigureAwait(false),
54+
BlobStorageResources.ResourceType.BlobContainer => await BlobStorageResourceContainer
55+
.RehydrateResourceAsync(Properties, MakesSource, credential, cancellationToken)
56+
.ConfigureAwait(false),
57+
_ => throw BadResourceTypeException(ResourceType)
58+
};
59+
}
60+
61+
/// <summary>
62+
/// Creates the configured <see cref="StorageResource"/> instance using the given <see cref="AzureSasCredential"/>.
63+
/// </summary>
64+
/// <returns></returns>
65+
public async Task<StorageResource> MakeResourceAsync(AzureSasCredential credential, CancellationToken cancellationToken = default)
66+
{
67+
return ResourceType switch
68+
{
69+
BlobStorageResources.ResourceType.BlockBlob => await BlockBlobStorageResource
70+
.RehydrateResourceAsync(Properties, MakesSource, credential, cancellationToken)
71+
.ConfigureAwait(false),
72+
BlobStorageResources.ResourceType.PageBlob => await PageBlobStorageResource
73+
.RehydrateResourceAsync(Properties, MakesSource, credential, cancellationToken)
74+
.ConfigureAwait(false),
75+
BlobStorageResources.ResourceType.AppendBlob => await AppendBlobStorageResource
76+
.RehydrateResourceAsync(Properties, MakesSource, credential, cancellationToken)
77+
.ConfigureAwait(false),
78+
BlobStorageResources.ResourceType.BlobContainer => await BlobStorageResourceContainer
79+
.RehydrateResourceAsync(Properties, MakesSource, credential, cancellationToken)
80+
.ConfigureAwait(false),
81+
_ => throw BadResourceTypeException(ResourceType)
82+
};
83+
}
84+
85+
/// <summary>
86+
/// Creates the configured <see cref="StorageResource"/> instance using the given <see cref="TokenCredential"/>.
87+
/// </summary>
88+
/// <returns></returns>
89+
public async Task<StorageResource> MakeResourceAsync(TokenCredential credential, CancellationToken cancellationToken = default)
90+
{
91+
return ResourceType switch
92+
{
93+
BlobStorageResources.ResourceType.BlockBlob => await BlockBlobStorageResource
94+
.RehydrateResourceAsync(Properties, MakesSource, credential, cancellationToken)
95+
.ConfigureAwait(false),
96+
BlobStorageResources.ResourceType.PageBlob => await PageBlobStorageResource
97+
.RehydrateResourceAsync(Properties, MakesSource, credential, cancellationToken)
98+
.ConfigureAwait(false),
99+
BlobStorageResources.ResourceType.AppendBlob => await AppendBlobStorageResource
100+
.RehydrateResourceAsync(Properties, MakesSource, credential, cancellationToken)
101+
.ConfigureAwait(false),
102+
BlobStorageResources.ResourceType.BlobContainer => await BlobStorageResourceContainer
103+
.RehydrateResourceAsync(Properties, MakesSource, credential, cancellationToken)
104+
.ConfigureAwait(false),
105+
_ => throw BadResourceTypeException(ResourceType)
106+
};
107+
}
108+
109+
/// <summary>
110+
/// Creates the configured <see cref="StorageResource"/> instance using no credential.
111+
/// </summary>
112+
/// <returns></returns>
113+
public async Task<StorageResource> MakeResourceAsync(CancellationToken cancellationToken = default)
114+
{
115+
return ResourceType switch
116+
{
117+
BlobStorageResources.ResourceType.BlockBlob => await BlockBlobStorageResource
118+
.RehydrateResourceAsync(Properties, MakesSource, cancellationToken)
119+
.ConfigureAwait(false),
120+
BlobStorageResources.ResourceType.PageBlob => await PageBlobStorageResource
121+
.RehydrateResourceAsync(Properties, MakesSource, cancellationToken)
122+
.ConfigureAwait(false),
123+
BlobStorageResources.ResourceType.AppendBlob => await AppendBlobStorageResource
124+
.RehydrateResourceAsync(Properties, MakesSource, cancellationToken)
125+
.ConfigureAwait(false),
126+
BlobStorageResources.ResourceType.BlobContainer => await BlobStorageResourceContainer
127+
.RehydrateResourceAsync(Properties, MakesSource, cancellationToken)
128+
.ConfigureAwait(false),
129+
_ => throw BadResourceTypeException(ResourceType)
130+
};
131+
}
132+
133+
private static ArgumentException BadResourceTypeException(BlobStorageResources.ResourceType resourceType)
134+
=> new ArgumentException(
135+
$"No support for resource type {Enum.GetName(typeof(BlobStorageResources.ResourceType), resourceType)}.");
136+
}
137+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using Azure.Core;
6+
using Azure.Storage.DataMovement.Models;
7+
8+
namespace Azure.Storage.DataMovement.Blobs
9+
{
10+
/// <summary>
11+
/// Utilities for storage resources with Azure Blob Storage.
12+
/// </summary>
13+
public static class BlobStorageResources
14+
{
15+
internal enum ResourceType
16+
{
17+
Unknown = 0,
18+
BlockBlob = 1,
19+
PageBlob = 2,
20+
AppendBlob = 3,
21+
BlobContainer = 4,
22+
}
23+
24+
/// <summary>
25+
/// Attempts to get Azure Blob Storage resource providers for the source and destination of a given transfer, if applicable.
26+
/// </summary>
27+
/// <param name="info">Information on a transfer.</param>
28+
/// <param name="sourceProvider">Provider of the source resource for a transfer, if found.</param>
29+
/// <param name="destinationProvider">Provider of the destination resource for a transfer, if found.</param>
30+
/// <returns>Whether either source or destination provider was found.</returns>
31+
public static bool TryGetResourceProviders(
32+
DataTransferProperties info,
33+
out BlobStorageResourceProvider sourceProvider,
34+
out BlobStorageResourceProvider destinationProvider)
35+
{
36+
bool result = false;
37+
(ResourceType sourceType, ResourceType destinationType) = GetTypes(info);
38+
39+
if (sourceType != ResourceType.Unknown)
40+
{
41+
sourceProvider = new BlobStorageResourceProvider(info, asSource: true, sourceType);
42+
result = true;
43+
}
44+
else
45+
{
46+
sourceProvider = default;
47+
}
48+
49+
if (destinationType != ResourceType.Unknown)
50+
{
51+
destinationProvider = new BlobStorageResourceProvider(info, asSource: false, destinationType);
52+
result = true;
53+
}
54+
else
55+
{
56+
destinationProvider = default;
57+
}
58+
59+
return result;
60+
}
61+
62+
private static (ResourceType SourceType, ResourceType DestinationType) GetTypes(DataTransferProperties info)
63+
{
64+
Argument.AssertNotNull(info, nameof(info));
65+
66+
ResourceType GetType(string scheme)
67+
{
68+
return scheme switch
69+
{
70+
// TODO figure out actual strings
71+
"BlockBlob" => info.IsContainer ? ResourceType.BlobContainer : ResourceType.BlockBlob,
72+
"PageBlob" => info.IsContainer ? ResourceType.BlobContainer : ResourceType.PageBlob,
73+
"AppendBlob" => info.IsContainer ? ResourceType.BlobContainer : ResourceType.AppendBlob,
74+
_ => ResourceType.Unknown
75+
};
76+
}
77+
78+
return (GetType(info.SourceScheme), GetType(info.DestinationScheme));
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)