@@ -41,15 +41,26 @@ internal async Task UploadAsync(
4141 IDictionary < string , string > properties ,
4242 CancellationToken cancellationToken )
4343 {
44+ // Get the client settings, if any.
45+ var tracer = DedupManifestArtifactClientFactory . CreateArtifactsTracer ( verbose : false , ( str ) => context . Output ( str ) ) ;
4446 VssConnection connection = context . VssConnection ;
45- var ( dedupManifestClient , clientTelemetry ) = await DedupManifestArtifactClientFactory . Instance
46- . CreateDedupManifestClientAsync (
47+ var clientSettings = await DedupManifestArtifactClientFactory . GetClientSettingsAsync (
48+ connection ,
49+ Microsoft . VisualStudio . Services . BlobStore . WebApi . Contracts . Client . PipelineArtifact ,
50+ tracer ,
51+ cancellationToken ) ;
52+
53+ // Get the default domain to use:
54+ IDomainId domainId = DedupManifestArtifactClientFactory . GetDefaultDomainId ( clientSettings , tracer ) ;
55+
56+ var ( dedupManifestClient , clientTelemetry ) = DedupManifestArtifactClientFactory . Instance
57+ . CreateDedupManifestClient (
4758 context . IsSystemDebugTrue ( ) ,
4859 ( str ) => context . Output ( str ) ,
4960 connection ,
5061 DedupManifestArtifactClientFactory . Instance . GetDedupStoreClientMaxParallelism ( context ) ,
51- WellKnownDomainIds . DefaultDomainId ,
52- Microsoft . VisualStudio . Services . BlobStore . WebApi . Contracts . Client . PipelineArtifact ,
62+ domainId ,
63+ clientSettings ,
5364 context ,
5465 cancellationToken ) ;
5566
@@ -84,7 +95,8 @@ internal async Task UploadAsync(
8495 { PipelineArtifactConstants . RootId , result . RootId . ValueString } ,
8596 { PipelineArtifactConstants . ProofNodes , StringUtil . ConvertToJson ( result . ProofNodes . ToArray ( ) ) } ,
8697 { PipelineArtifactConstants . ArtifactSize , result . ContentSize . ToString ( ) } ,
87- { PipelineArtifactConstants . HashType , dedupManifestClient . HashType . Serialize ( ) }
98+ { PipelineArtifactConstants . HashType , dedupManifestClient . HashType . Serialize ( ) } ,
99+ { PipelineArtifactConstants . DomainId , domainId . Serialize ( ) }
88100 } ;
89101
90102 BuildArtifact buildArtifact = await AsyncHttpRetryHelper . InvokeAsync (
@@ -140,22 +152,11 @@ internal async Task DownloadAsync(
140152 CancellationToken cancellationToken )
141153 {
142154 VssConnection connection = context . VssConnection ;
143- var ( dedupManifestClient , clientTelemetry ) = await DedupManifestArtifactClientFactory . Instance
144- . CreateDedupManifestClientAsync (
145- context . IsSystemDebugTrue ( ) ,
146- ( str ) => context . Output ( str ) ,
147- connection ,
148- DedupManifestArtifactClientFactory . Instance . GetDedupStoreClientMaxParallelism ( context ) ,
149- WellKnownDomainIds . DefaultDomainId ,
150- Microsoft . VisualStudio . Services . BlobStore . WebApi . Contracts . Client . PipelineArtifact ,
151- context ,
152- cancellationToken ) ;
155+ PipelineArtifactProvider provider = new PipelineArtifactProvider ( context , connection , tracer ) ;
153156
154157 BuildServer buildServer = new ( connection ) ;
155158
156- using ( clientTelemetry )
157159 // download all pipeline artifacts if artifact name is missing
158- {
159160 if ( downloadOptions == DownloadOptions . MultiDownload )
160161 {
161162 List < BuildArtifact > artifacts ;
@@ -187,40 +188,7 @@ internal async Task DownloadAsync(
187188 else
188189 {
189190 context . Output ( StringUtil . Loc ( "DownloadingMultiplePipelineArtifacts" , pipelineArtifacts . Count ( ) ) ) ;
190-
191- var artifactNameAndManifestIds = pipelineArtifacts . ToDictionary (
192- keySelector : ( a ) => a . Name , // keys should be unique, if not something is really wrong
193- elementSelector : ( a ) => DedupIdentifier . Create ( a . Resource . Data ) ) ;
194- // 2) download to the target path
195- var options = DownloadDedupManifestArtifactOptions . CreateWithMultiManifestIds (
196- artifactNameAndManifestIds ,
197- downloadParameters . TargetDirectory ,
198- proxyUri : null ,
199- minimatchPatterns : downloadParameters . MinimatchFilters ,
200- minimatchFilterWithArtifactName : downloadParameters . MinimatchFilterWithArtifactName ,
201- customMinimatchOptions : downloadParameters . CustomMinimatchOptions ) ;
202-
203- PipelineArtifactActionRecord downloadRecord = clientTelemetry . CreateRecord < PipelineArtifactActionRecord > ( ( level , uri , type ) =>
204- new PipelineArtifactActionRecord ( level , uri , type , nameof ( DownloadAsync ) , context ) ) ;
205- await clientTelemetry . MeasureActionAsync (
206- record : downloadRecord ,
207- actionAsync : async ( ) =>
208- {
209- await AsyncHttpRetryHelper . InvokeVoidAsync (
210- async ( ) =>
211- {
212- await dedupManifestClient . DownloadAsync ( options , cancellationToken ) ;
213- } ,
214- maxRetries : 3 ,
215- tracer : tracer ,
216- canRetryDelegate : e => true ,
217- context : nameof ( DownloadAsync ) ,
218- cancellationToken : cancellationToken ,
219- continueOnCapturedContext : false ) ;
220- } ) ;
221-
222- // Send results to CustomerIntelligence
223- context . PublishTelemetry ( area : PipelineArtifactConstants . AzurePipelinesAgent , feature : PipelineArtifactConstants . PipelineArtifact , record : downloadRecord ) ;
191+ await provider . DownloadMultipleArtifactsAsync ( downloadParameters , artifacts , cancellationToken , context ) ;
224192 }
225193 }
226194 else if ( downloadOptions == DownloadOptions . SingleDownload )
@@ -246,42 +214,12 @@ await AsyncHttpRetryHelper.InvokeVoidAsync(
246214 {
247215 throw new InvalidOperationException ( $ "Invalid { nameof ( downloadParameters . ProjectRetrievalOptions ) } !") ;
248216 }
249-
250- var manifestId = DedupIdentifier . Create ( buildArtifact . Resource . Data ) ;
251- var options = DownloadDedupManifestArtifactOptions . CreateWithManifestId (
252- manifestId ,
253- downloadParameters . TargetDirectory ,
254- proxyUri : null ,
255- minimatchPatterns : downloadParameters . MinimatchFilters ,
256- customMinimatchOptions : downloadParameters . CustomMinimatchOptions ) ;
257-
258- PipelineArtifactActionRecord downloadRecord = clientTelemetry . CreateRecord < PipelineArtifactActionRecord > ( ( level , uri , type ) =>
259- new PipelineArtifactActionRecord ( level , uri , type , nameof ( DownloadAsync ) , context ) ) ;
260- await clientTelemetry . MeasureActionAsync (
261- record : downloadRecord ,
262- actionAsync : async ( ) =>
263- {
264- await AsyncHttpRetryHelper . InvokeVoidAsync (
265- async ( ) =>
266- {
267- await dedupManifestClient . DownloadAsync ( options , cancellationToken ) ;
268- } ,
269- maxRetries : 3 ,
270- tracer : tracer ,
271- canRetryDelegate : e => true ,
272- context : nameof ( DownloadAsync ) ,
273- cancellationToken : cancellationToken ,
274- continueOnCapturedContext : false ) ;
275- } ) ;
276-
277- // Send results to CustomerIntelligence
278- context . PublishTelemetry ( area : PipelineArtifactConstants . AzurePipelinesAgent , feature : PipelineArtifactConstants . PipelineArtifact , record : downloadRecord ) ;
217+ await provider . DownloadSingleArtifactAsync ( downloadParameters , buildArtifact , cancellationToken , context ) ;
279218 }
280219 else
281220 {
282221 throw new InvalidOperationException ( $ "Invalid { nameof ( downloadOptions ) } !") ;
283222 }
284- }
285223 }
286224
287225 // Download for version 2. This decision was made because version 1 is sealed and we didn't want to break any existing customers.
0 commit comments