From 374989b28036e27980791f18adb124182db2d009 Mon Sep 17 00:00:00 2001 From: Balaga Gayatri Date: Thu, 10 Feb 2022 01:12:13 +0530 Subject: [PATCH] Pass `jobId` to the actionsDownloadInfo controller (#1639) * Update JobServer.cs * Update ActionManager.cs * Update TaskHttpClientBase.cs * Update ActionManagerL0.cs * Update ActionManager.cs * :nit changes * Update ActionManager.cs * :nit changes * Code formatting * Update JobServer.cs * Update JobServer.cs * Update TaskHttpClientBase.cs * Update ActionManagerL0.cs * :nit changes * passing `jobId` as queryparameter to the controller * :nit changes * Update src/Sdk/DTGenerated/Generated/TaskHttpClientBase.cs Co-authored-by: Lokesh Gopu Co-authored-by: Tingluo Huang Co-authored-by: Lokesh Gopu --- src/Runner.Common/JobServer.cs | 10 +++++----- src/Runner.Worker/ActionManager.cs | 2 +- src/Sdk/DTGenerated/Generated/TaskHttpClientBase.cs | 9 +++++++-- src/Test/L0/Worker/ActionManagerL0.cs | 7 ++++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/Runner.Common/JobServer.cs b/src/Runner.Common/JobServer.cs index bdebce6da..7d483c7e8 100644 --- a/src/Runner.Common/JobServer.cs +++ b/src/Runner.Common/JobServer.cs @@ -1,4 +1,4 @@ -using GitHub.DistributedTask.WebApi; +using GitHub.DistributedTask.WebApi; using System; using System.Collections.Generic; using System.IO; @@ -26,7 +26,7 @@ namespace GitHub.Runner.Common Task> UpdateTimelineRecordsAsync(Guid scopeIdentifier, string hubName, Guid planId, Guid timelineId, IEnumerable records, CancellationToken cancellationToken); Task RaisePlanEventAsync(Guid scopeIdentifier, string hubName, Guid planId, T eventData, CancellationToken cancellationToken) where T : JobEvent; Task GetTimelineAsync(Guid scopeIdentifier, string hubName, Guid planId, Guid timelineId, CancellationToken cancellationToken); - Task ResolveActionDownloadInfoAsync(Guid scopeIdentifier, string hubName, Guid planId, ActionReferenceList actions, CancellationToken cancellationToken); + Task ResolveActionDownloadInfoAsync(Guid scopeIdentifier, string hubName, Guid planId, Guid jobId, ActionReferenceList actions, CancellationToken cancellationToken); } public sealed class JobServer : RunnerService, IJobServer @@ -42,7 +42,7 @@ namespace GitHub.Runner.Common int attemptCount = totalAttempts; var configurationStore = HostContext.GetService(); var runnerSettings = configurationStore.GetSettings(); - + while (!_connection.HasAuthenticated && attemptCount-- > 0) { try @@ -186,10 +186,10 @@ namespace GitHub.Runner.Common //----------------------------------------------------------------- // Action download info //----------------------------------------------------------------- - public Task ResolveActionDownloadInfoAsync(Guid scopeIdentifier, string hubName, Guid planId, ActionReferenceList actions, CancellationToken cancellationToken) + public Task ResolveActionDownloadInfoAsync(Guid scopeIdentifier, string hubName, Guid planId, Guid jobId, ActionReferenceList actions, CancellationToken cancellationToken) { CheckConnection(); - return _taskClient.ResolveActionDownloadInfoAsync(scopeIdentifier, hubName, planId, actions, cancellationToken: cancellationToken); + return _taskClient.ResolveActionDownloadInfoAsync(scopeIdentifier, hubName, planId, jobId, actions, cancellationToken: cancellationToken); } } } diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index 76b087a4b..1a89bca00 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -651,7 +651,7 @@ namespace GitHub.Runner.Worker { try { - actionDownloadInfos = await jobServer.ResolveActionDownloadInfoAsync(executionContext.Global.Plan.ScopeIdentifier, executionContext.Global.Plan.PlanType, executionContext.Global.Plan.PlanId, new WebApi.ActionReferenceList { Actions = actionReferences }, executionContext.CancellationToken); + actionDownloadInfos = await jobServer.ResolveActionDownloadInfoAsync(executionContext.Global.Plan.ScopeIdentifier, executionContext.Global.Plan.PlanType, executionContext.Global.Plan.PlanId, executionContext.Root.Id, new WebApi.ActionReferenceList { Actions = actionReferences }, executionContext.CancellationToken); break; } catch (Exception ex) when (!executionContext.CancellationToken.IsCancellationRequested) // Do not retry if the run is canceled. diff --git a/src/Sdk/DTGenerated/Generated/TaskHttpClientBase.cs b/src/Sdk/DTGenerated/Generated/TaskHttpClientBase.cs index 91adde925..6d5a2fdc8 100644 --- a/src/Sdk/DTGenerated/Generated/TaskHttpClientBase.cs +++ b/src/Sdk/DTGenerated/Generated/TaskHttpClientBase.cs @@ -1,4 +1,4 @@ -/* +/* * --------------------------------------------------------- * Copyright(C) Microsoft Corporation. All rights reserved. * --------------------------------------------------------- @@ -324,6 +324,7 @@ namespace GitHub.DistributedTask.WebApi /// The project GUID to scope the request /// The name of the server hub: "build" for the Build server or "rm" for the Release Management server /// + /// /// /// /// The cancellation token to cancel operation. @@ -331,6 +332,7 @@ namespace GitHub.DistributedTask.WebApi Guid scopeIdentifier, string hubName, Guid planId, + Guid jobId, ActionReferenceList actionReferenceList, object userState = null, CancellationToken cancellationToken = default) @@ -339,12 +341,15 @@ namespace GitHub.DistributedTask.WebApi Guid locationId = new Guid("27d7f831-88c1-4719-8ca1-6a061dad90eb"); object routeValues = new { scopeIdentifier = scopeIdentifier, hubName = hubName, planId = planId }; HttpContent content = new ObjectContent(actionReferenceList, new VssJsonMediaTypeFormatter(true)); - + + List> queryParams = new List>(); + queryParams.Add("jobId", jobId); return SendAsync( httpMethod, locationId, routeValues: routeValues, version: new ApiResourceVersion(6.0, 1), + queryParameters: queryParams, userState: userState, cancellationToken: cancellationToken, content: content); diff --git a/src/Test/L0/Worker/ActionManagerL0.cs b/src/Test/L0/Worker/ActionManagerL0.cs index 5334b236f..971d051ca 100644 --- a/src/Test/L0/Worker/ActionManagerL0.cs +++ b/src/Test/L0/Worker/ActionManagerL0.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; @@ -2135,6 +2135,7 @@ runs: _ec = new Mock(); _ec.Setup(x => x.Global).Returns(new GlobalContext()); _ec.Setup(x => x.CancellationToken).Returns(_ecTokenSource.Token); + _ec.Setup(x => x.Root).Returns(new GitHub.Runner.Worker.ExecutionContext()); var variables = new Dictionary(); if (enableComposite) { @@ -2156,8 +2157,8 @@ runs: _dockerManager.Setup(x => x.DockerBuild(_ec.Object, It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).Returns(Task.FromResult(0)); _jobServer = new Mock(); - _jobServer.Setup(x => x.ResolveActionDownloadInfoAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Returns((Guid scopeIdentifier, string hubName, Guid planId, ActionReferenceList actions, CancellationToken cancellationToken) => + _jobServer.Setup(x => x.ResolveActionDownloadInfoAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Returns((Guid scopeIdentifier, string hubName, Guid planId, Guid jobId, ActionReferenceList actions, CancellationToken cancellationToken) => { var result = new ActionDownloadInfoCollection { Actions = new Dictionary() }; foreach (var action in actions.Actions)