From c1c0f7f9c250f33ac1d24c560be937fbe02a806e Mon Sep 17 00:00:00 2001 From: Weibing Zhan Date: Mon, 25 Sep 2023 18:21:13 -0700 Subject: [PATCH] Add LocatorIds into the report page for asset analyzer command (#194) * Add LocatorIds into the report page for asset analyzer command Description: When reporting the result to HTML page, to help customers to figure out the mapping between streaing Url on input asset and the streaming URL of the generated output asset, this change adds a new column in the report page to include LocatorIds for each input asset, if the locatorIds (Guid) are available. One input can have zero or multiple locatorIds, when it has multiple locatorIds, the report page uses ";\n" as a separator line between two locators. Adjust the percentage of each column in the report page, use it as guideline, the column length is not guaranteed if the asset name contains a word with a long list of characters without separators like ',-' etc. Some minor fix to make it report correct number of assets without locators. * Update the AnalysisResult.LocatorIds property's type to List instead a plain string So that it is easier to work with both JSON and HTML report page. --- ams/AssetAnalyzer.cs | 13 ++++++++++++- ams/AssetStats.cs | 2 +- ams/ReportGenerator.cs | 23 ++++++++++++++++++----- transform/AnalyzeTransform.cs | 9 ++++++--- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/ams/AssetAnalyzer.cs b/ams/AssetAnalyzer.cs index 27adf7b..79fb102 100644 --- a/ams/AssetAnalyzer.cs +++ b/ams/AssetAnalyzer.cs @@ -32,7 +32,7 @@ public AssetAnalyzer( private async Task AnalyzeAsync(MediaAssetResource asset, BlobServiceClient storage, CancellationToken cancellationToken) { - var result = new AnalysisResult(asset.Data.Name, MigrationStatus.NotMigrated, 0); + var result = new AnalysisResult(asset.Data.Name, MigrationStatus.NotMigrated); _logger.LogDebug("Analyzing asset: {asset}, container: {container}", asset.Data.Name, asset.Data.Container); try { @@ -44,6 +44,17 @@ private async Task AnalyzeAsync(MediaAssetResource asset, BlobSe return result; } + // Get a list of LocatorIds if they exist. + var locators = asset.GetStreamingLocatorsAsync(); + + await foreach (var locator in locators) + { + if (locator.StreamingLocatorId != null && locator.StreamingLocatorId != Guid.Empty) + { + result.LocatorIds.Add(locator.StreamingLocatorId.Value.ToString("D")); + } + } + // The asset container exists, try to check the metadata list first. var migrateResult = await _tracker.GetMigrationStatusAsync(container, cancellationToken); diff --git a/ams/AssetStats.cs b/ams/AssetStats.cs index dbb95f3..c4b1550 100644 --- a/ams/AssetStats.cs +++ b/ams/AssetStats.cs @@ -35,7 +35,7 @@ public void Update(AnalysisResult result) Interlocked.Increment(ref _streamable); } - if (result.Locators == 0) + if (result.LocatorIds.Count == 0) { Interlocked.Increment(ref _noLocators); } diff --git a/ams/ReportGenerator.cs b/ams/ReportGenerator.cs index 7abd069..b44ef27 100644 --- a/ams/ReportGenerator.cs +++ b/ams/ReportGenerator.cs @@ -46,11 +46,12 @@ public void WriteHeader() - - - - + + + + "); @@ -69,7 +70,19 @@ public void WriteRow(AnalysisResult result) { lock (this) { - _writer.Write($"
Asset Name + Asset Name AssetTypeMigrateStatusOutputHlsUrlOutputDashUrlLocatorIdsMigrateStatusOutputHlsUrlOutputDashUrl
{result.AssetName}{result.AssetType}{result.Status}"); + string locatorIds = ""; + + foreach (var locId in result.LocatorIds) + { + if (!string.IsNullOrEmpty(locatorIds)) + { + locatorIds += ";\n"; + } + + locatorIds += locId; + } + + _writer.Write($"
{result.AssetName}{result.AssetType}{locatorIds}{result.Status}"); if (result.OutputHlsUrl != null) _writer.Write($"{result.OutputHlsUrl}"); diff --git a/transform/AnalyzeTransform.cs b/transform/AnalyzeTransform.cs index b296a26..21e193c 100644 --- a/transform/AnalyzeTransform.cs +++ b/transform/AnalyzeTransform.cs @@ -5,14 +5,17 @@ namespace AMSMigrate.Transform { class AnalysisResult : AssetMigrationResult { - public AnalysisResult(string assetName, MigrationStatus status, int locators, Uri? outputPath = null, string? assetType = null, string? manifestName = null) + public AnalysisResult(string assetName, MigrationStatus status, Uri? outputPath = null, string? assetType = null, string? manifestName = null) : base(status, outputPath, assetType, manifestName) { AssetName = assetName; - Locators = locators; + + LocatorIds = new List(); } - public int Locators { get; internal set; } + // A list of Locator Guids of the asset, + // it can have zero or multiple GUIDs. + public List LocatorIds { get; } public string AssetName { get; set; }