33
44using Agent . Sdk . Knob ;
55using Agent . Sdk . Util ;
6+ using BuildXL . Cache . ContentStore . Hashing ;
7+ using Microsoft . TeamFoundation . DistributedTask . WebApi ;
68using Microsoft . VisualStudio . Services . Agent . Blob ;
79using Microsoft . VisualStudio . Services . Agent . Util ;
10+ using Microsoft . VisualStudio . Services . BlobStore . WebApi ;
11+ using Microsoft . VisualStudio . Services . BlobStore . Common ;
12+ using Microsoft . VisualStudio . Services . BlobStore . WebApi . Contracts ;
813using Microsoft . VisualStudio . Services . FileContainer . Client ;
914using System ;
1015using System . Collections . Concurrent ;
1823using System . Net . Http ;
1924using System . Net ;
2025using System . Net . Sockets ;
21- using Microsoft . TeamFoundation . DistributedTask . WebApi ;
22- using Microsoft . VisualStudio . Services . BlobStore . WebApi ;
2326
2427
2528namespace Microsoft . VisualStudio . Services . Agent . Worker . Build
@@ -326,6 +329,16 @@ private async Task<UploadResult> UploadAsync(IAsyncCommandContext context, int u
326329
327330 return new UploadResult ( failedFiles , uploadedSize ) ;
328331 }
332+ public static string CreateDomainHash ( IDomainId domainId , DedupIdentifier dedupId )
333+ {
334+ if ( domainId != WellKnownDomainIds . DefaultDomainId )
335+ {
336+ // Only use the new format domainId,dedupId if we aren't going to the default domain as this is a breaking change:
337+ return $ "{ domainId . Serialize ( ) } ,{ dedupId . ValueString } ";
338+ }
339+ // We are still uploading to the default domain so use the don't use the new format:
340+ return dedupId . ValueString ;
341+ }
329342
330343 private async Task < UploadResult > BlobUploadAsync ( IAsyncCommandContext context , IReadOnlyList < string > files , int concurrentUploads , CancellationToken token )
331344 {
@@ -342,20 +355,33 @@ private async Task<UploadResult> BlobUploadAsync(IAsyncCommandContext context, I
342355 BlobStoreClientTelemetryTfs clientTelemetry = null ;
343356 try
344357 {
358+
345359 var verbose = String . Equals ( context . GetVariableValueOrDefault ( "system.debug" ) , "true" , StringComparison . InvariantCultureIgnoreCase ) ;
346- int maxParallelism = context . GetHostContext ( ) . GetService < IConfigurationStore > ( ) . GetSettings ( ) . MaxDedupParallelism ;
347- ( dedupClient , clientTelemetry ) = await DedupManifestArtifactClientFactory . Instance
348- . CreateDedupClientAsync (
360+ Action < string > tracer = ( str ) => context . Output ( str ) ;
361+
362+ var clientSettings = await BlobstoreClientSettings . GetClientSettingsAsync (
363+ _connection ,
364+ Microsoft . VisualStudio . Services . BlobStore . WebApi . Contracts . Client . BuildArtifact ,
365+ DedupManifestArtifactClientFactory . CreateArtifactsTracer ( verbose , tracer ) ,
366+ token ) ;
367+
368+ // Check if the pipeline has an override domain set, if not, use the default domain from the client settings.
369+ string overrideDomain = AgentKnobs . SendBuildArtifactsToBlobstoreDomain . GetValue ( context ) . AsString ( ) ;
370+ IDomainId domainId = String . IsNullOrWhiteSpace ( overrideDomain ) ? clientSettings . GetDefaultDomainId ( ) : DomainIdFactory . Create ( overrideDomain ) ;
371+
372+ ( dedupClient , clientTelemetry ) = DedupManifestArtifactClientFactory . Instance
373+ . CreateDedupClient (
374+ _connection ,
375+ domainId ,
376+ context . GetHostContext ( ) . GetService < IConfigurationStore > ( ) . GetSettings ( ) . MaxDedupParallelism ,
377+ clientSettings . GetRedirectTimeout ( ) ,
349378 verbose ,
350- ( str ) => context . Output ( str ) ,
351- this . _connection ,
352- maxParallelism ,
353- BlobStore . WebApi . Contracts . Client . BuildArtifact ,
379+ tracer ,
354380 token ) ;
355381
356382 // Upload to blobstore
357383 var results = await BlobStoreUtils . UploadBatchToBlobstore ( verbose , files , ( level , uri , type ) =>
358- new BuildArtifactActionRecord ( level , uri , type , nameof ( BlobUploadAsync ) , context ) , ( str ) => context . Output ( str ) , dedupClient , clientTelemetry , token , enableReporting : true ) ;
384+ new BuildArtifactActionRecord ( level , uri , type , nameof ( BlobUploadAsync ) , context ) , tracer , dedupClient , clientTelemetry , token , enableReporting : true ) ;
359385
360386 // Associate with TFS
361387 context . Output ( StringUtil . Loc ( "AssociateFiles" ) ) ;
@@ -373,7 +399,7 @@ private async Task<UploadResult> BlobUploadAsync(IAsyncCommandContext context, I
373399 var parallelAssociateTasks = new List < Task < UploadResult > > ( ) ;
374400 for ( int uploader = 0 ; uploader < concurrentUploads ; uploader ++ )
375401 {
376- parallelAssociateTasks . Add ( AssociateAsync ( context , queue , token ) ) ;
402+ parallelAssociateTasks . Add ( AssociateAsync ( context , domainId , queue , token ) ) ;
377403 }
378404
379405 // Wait for parallel associate tasks to finish.
@@ -419,7 +445,7 @@ private async Task<UploadResult> BlobUploadAsync(IAsyncCommandContext context, I
419445 return uploadResult ;
420446 }
421447
422- private async Task < UploadResult > AssociateAsync ( IAsyncCommandContext context , ConcurrentQueue < BlobFileInfo > associateQueue , CancellationToken token )
448+ private async Task < UploadResult > AssociateAsync ( IAsyncCommandContext context , IDomainId domainId , ConcurrentQueue < BlobFileInfo > associateQueue , CancellationToken token )
423449 {
424450 var uploadResult = new UploadResult ( ) ;
425451
@@ -443,7 +469,7 @@ private async Task<UploadResult> AssociateAsync(IAsyncCommandContext context, Co
443469 {
444470 var length = ( long ) file . Node . TransitiveContentBytes ;
445471 response = await retryHelper . Retry ( async ( ) => await _fileContainerHttpClient . CreateItemForArtifactUpload ( _containerId , itemPath , _projectId ,
446- file . DedupId . ValueString , length , token ) ,
472+ CreateDomainHash ( domainId , file . DedupId ) , length , token ) ,
447473 ( retryCounter ) => ( int ) Math . Pow ( retryCounter , 2 ) * 5 ,
448474 ( exception ) => true ) ;
449475 uploadResult . TotalFileSizeUploaded += length ;
0 commit comments