Skip to content

Commit

Permalink
Use ArtifactHttpClientFactory to generate dedupStoreClient that inclu…
Browse files Browse the repository at this point in the history
…des ArtifactHttpRetryHandler (microsoft#2357)

* update clinet

* remove test code

* update to 50 secs
  • Loading branch information
jahsu-MSFT authored and TingluoHuang committed Jul 24, 2019
1 parent 55f07aa commit da523e8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Threading;
using Agent.Sdk;
using Microsoft.TeamFoundation.Build.WebApi;
using Microsoft.TeamFoundation.DistributedTask.WebApi;
using Microsoft.VisualStudio.Services.Agent.Util;
using Microsoft.VisualStudio.Services.BlobStore.Common;
using Microsoft.VisualStudio.Services.BlobStore.Common.Telemetry;
using Microsoft.VisualStudio.Services.BlobStore.WebApi;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.Content.Common.Tracing;
using Microsoft.VisualStudio.Services.WebApi;
using Newtonsoft.Json;
using Microsoft.VisualStudio.Services.Content.Common;
using Microsoft.VisualStudio.Services.Common;

namespace Agent.Plugins.PipelineArtifact
{
public static class DedupManifestArtifactClientFactory
{
public static DedupManifestArtifactClient CreateDedupManifestClient(AgentTaskPluginExecutionContext context, VssConnection connection, out BlobStoreClientTelemetry telemetry)
public static DedupManifestArtifactClient CreateDedupManifestClient(AgentTaskPluginExecutionContext context, VssConnection connection, CancellationToken cancellationToken, out BlobStoreClientTelemetry telemetry)
{
var dedupStoreHttpClient = connection.GetClient<DedupStoreHttpClient>();
var tracer = new CallbackAppTraceSource(str => context.Output(str), SourceLevels.Information);
dedupStoreHttpClient.SetTracer(tracer);

ArtifactHttpClientFactory factory = new ArtifactHttpClientFactory(
connection.Credentials,
TimeSpan.FromSeconds(50),
tracer,
cancellationToken);

var dedupStoreHttpClient = factory.CreateVssHttpClient<IDedupStoreHttpClient, DedupStoreHttpClient>(connection.GetClient<DedupStoreHttpClient>().BaseAddress);

var client = new DedupStoreClientWithDataport(dedupStoreHttpClient, PipelineArtifactProvider.GetDedupStoreClientMaxParallelism(context));
return new DedupManifestArtifactClient(telemetry = new BlobStoreClientTelemetry(tracer, dedupStoreHttpClient.BaseAddress), client, tracer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class PublishPipelineArtifactTaskV1 : PipelineArtifactTaskPluginBaseV1
protected override async Task ProcessCommandInternalAsync(
AgentTaskPluginExecutionContext context,
CancellationToken token)
{
{
string artifactName = context.GetInput(ArtifactEventProperties.ArtifactName, required: false);
string targetPath = context.GetInput(TargetPath, required: true);
string defaultWorkingDirectory = context.Variables.GetValueOrDefault("system.defaultworkingdirectory").Value;
Expand Down
5 changes: 3 additions & 2 deletions src/Agent.Plugins/PipelineArtifact/PipelineArtifactServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ internal async Task UploadAsync(
{
VssConnection connection = context.VssConnection;
BlobStoreClientTelemetry clientTelemetry;
DedupManifestArtifactClient dedupManifestClient = DedupManifestArtifactClientFactory.CreateDedupManifestClient(context, connection, out clientTelemetry);
DedupManifestArtifactClient dedupManifestClient = DedupManifestArtifactClientFactory.CreateDedupManifestClient(context, connection, cancellationToken, out clientTelemetry);

using (clientTelemetry)
{
//Upload the pipeline artifact.
PipelineArtifactActionRecord uploadRecord = clientTelemetry.CreateRecord<PipelineArtifactActionRecord>((level, uri, type) =>
new PipelineArtifactActionRecord(level, uri, type, nameof(UploadAsync), context));

PublishResult result = await clientTelemetry.MeasureActionAsync(
record: uploadRecord,
actionAsync: async () =>
Expand Down Expand Up @@ -88,7 +89,7 @@ internal async Task DownloadAsync(
{
VssConnection connection = context.VssConnection;
BlobStoreClientTelemetry clientTelemetry;
DedupManifestArtifactClient dedupManifestClient = DedupManifestArtifactClientFactory.CreateDedupManifestClient(context, connection, out clientTelemetry);
DedupManifestArtifactClient dedupManifestClient = DedupManifestArtifactClientFactory.CreateDedupManifestClient(context, connection, cancellationToken, out clientTelemetry);
BuildServer buildHelper = new BuildServer(connection);

using (clientTelemetry)
Expand Down
4 changes: 2 additions & 2 deletions src/Agent.Plugins/PipelineCache/PipelineCacheServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal async Task UploadAsync(
{
VssConnection connection = context.VssConnection;
BlobStoreClientTelemetry clientTelemetry;
DedupManifestArtifactClient dedupManifestClient = DedupManifestArtifactClientFactory.CreateDedupManifestClient(context, connection, out clientTelemetry);
DedupManifestArtifactClient dedupManifestClient = DedupManifestArtifactClientFactory.CreateDedupManifestClient(context, connection, cancellationToken, out clientTelemetry);
PipelineCacheClient pipelineCacheClient = this.CreateClient(clientTelemetry, context, connection);

using (clientTelemetry)
Expand Down Expand Up @@ -98,7 +98,7 @@ internal async Task DownloadAsync(
{
VssConnection connection = context.VssConnection;
BlobStoreClientTelemetry clientTelemetry;
DedupManifestArtifactClient dedupManifestClient = DedupManifestArtifactClientFactory.CreateDedupManifestClient(context, connection, out clientTelemetry);
DedupManifestArtifactClient dedupManifestClient = DedupManifestArtifactClientFactory.CreateDedupManifestClient(context, connection, cancellationToken, out clientTelemetry);
PipelineCacheClient pipelineCacheClient = this.CreateClient(clientTelemetry, context, connection);
GetPipelineCacheArtifactOptions options = new GetPipelineCacheArtifactOptions
{
Expand Down

0 comments on commit da523e8

Please sign in to comment.