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

GetStorageAccountAsync is making a Storage Account management API cal… #238

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 16 additions & 2 deletions migrationTool/ams/AssetMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Azure.Storage.Blobs;
using Microsoft.Extensions.Logging;
using Spectre.Console;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Threading.Channels;

Expand All @@ -16,6 +17,7 @@ internal class AssetMigrator : BaseMigrator
private readonly TransformFactory _transformFactory;
private readonly AssetOptions _options;
private readonly IMigrationTracker<BlobContainerClient, AssetMigrationResult> _tracker;
protected readonly TokenCredential _credentials;

public AssetMigrator(
GlobalOptions globalOptions,
Expand All @@ -30,6 +32,7 @@ public AssetMigrator(
_options = assetOptions;
_tracker = tracker;
_transformFactory = transformFactory;
_credentials = credential;
}

public override async Task MigrateAsync(CancellationToken cancellationToken)
Expand Down Expand Up @@ -83,11 +86,22 @@ public override async Task MigrateAsync(CancellationToken cancellationToken)
private async Task<AssetStats> MigrateAsync(MediaServicesAccountResource account, AsyncPageable<MediaAssetResource> assets, List<MediaAssetResource>? filteredList, ChannelWriter<double> writer, CancellationToken cancellationToken)
{
var stats = new AssetStats();

// Dictionary to restrict spawning of too many BlobServiceClients
var storageAccounts = new ConcurrentDictionary<string, BlobServiceClient>();

await MigrateInParallel(assets, filteredList, async (asset, cancellationToken) =>
{
var storage = await _resourceProvider.GetStorageAccountAsync(account, asset, cancellationToken);
var storageAccountName = asset.Data.StorageAccountName;
if (!storageAccounts.ContainsKey(storageAccountName))
{
BlobServiceClient newBlobServiceClient = new BlobServiceClient(new Uri($"https://{storageAccountName}.blob.core.windows.net"), _credentials);
srayan marked this conversation as resolved.
Show resolved Hide resolved
storageAccounts.TryAdd(storageAccountName, newBlobServiceClient);
}

BlobServiceClient blobServiceClient = storageAccounts[storageAccountName];

var result = await MigrateAsync(account, storage, asset, cancellationToken);
var result = await MigrateAsync(account, blobServiceClient, asset, cancellationToken);
stats.Update(result);
await writer.WriteAsync(stats.Total, cancellationToken);

Expand Down
Loading