Skip to content

Commit 659e3f5

Browse files
committed
Revert "Use new HelixAPI /job/{job}/results endpoint (#15230)"
This reverts commit d90fc3c.
1 parent 3caf0c1 commit 659e3f5

12 files changed

Lines changed: 50 additions & 129 deletions

File tree

src/Microsoft.DotNet.Helix/Client/CSharp/generated-code/Job.cs

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public partial interface IJob
2020
Task<Models.JobCreationResult> NewAsync(
2121
Models.JobCreationRequest body,
2222
string idempotencyKey,
23-
bool? returnSas = default,
2423
CancellationToken cancellationToken = default
2524
);
2625

@@ -34,11 +33,6 @@ public partial interface IJob
3433
CancellationToken cancellationToken = default
3534
);
3635

37-
Task<Models.JobResultsUri> ResultsAsync(
38-
string job,
39-
CancellationToken cancellationToken = default
40-
);
41-
4236
Task<Models.JobPassFail> PassFailAsync(
4337
string job,
4438
CancellationToken cancellationToken = default
@@ -83,7 +77,6 @@ public Job(HelixApi client)
8377
public async Task<Models.JobCreationResult> NewAsync(
8478
Models.JobCreationRequest body,
8579
string idempotencyKey,
86-
bool? returnSas = default,
8780
CancellationToken cancellationToken = default
8881
)
8982
{
@@ -125,11 +118,6 @@ public Job(HelixApi client)
125118
_req.Headers.Add("Idempotency-Key", idempotencyKey);
126119
}
127120

128-
if (returnSas != default(bool?))
129-
{
130-
_req.Headers.Add("return-sas", returnSas.ToString());
131-
}
132-
133121
if (body != default(Models.JobCreationRequest))
134122
{
135123
_req.Content = RequestContent.Create(Encoding.UTF8.GetBytes(Client.Serialize(body)));
@@ -280,81 +268,6 @@ internal async Task OnListFailed(Request req, Response res)
280268
throw ex;
281269
}
282270

283-
partial void HandleFailedResultsRequest(RestApiException ex);
284-
285-
public async Task<Models.JobResultsUri> ResultsAsync(
286-
string job,
287-
CancellationToken cancellationToken = default
288-
)
289-
{
290-
291-
if (string.IsNullOrEmpty(job))
292-
{
293-
throw new ArgumentNullException(nameof(job));
294-
}
295-
296-
const string apiVersion = "2019-06-17";
297-
298-
var _baseUri = Client.Options.BaseUri;
299-
var _url = new RequestUriBuilder();
300-
_url.Reset(_baseUri);
301-
_url.AppendPath(
302-
"/api/jobs/{job}/results".Replace("{job}", Uri.EscapeDataString(Client.Serialize(job))),
303-
false);
304-
305-
_url.AppendQuery("api-version", Client.Serialize(apiVersion));
306-
307-
308-
using (var _req = Client.Pipeline.CreateRequest())
309-
{
310-
_req.Uri = _url;
311-
_req.Method = RequestMethod.Get;
312-
313-
using (var _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false))
314-
{
315-
if (_res.Status < 200 || _res.Status >= 300)
316-
{
317-
await OnResultsFailed(_req, _res).ConfigureAwait(false);
318-
}
319-
320-
if (_res.ContentStream == null)
321-
{
322-
await OnResultsFailed(_req, _res).ConfigureAwait(false);
323-
}
324-
325-
using (var _reader = new StreamReader(_res.ContentStream))
326-
{
327-
var _content = await _reader.ReadToEndAsync().ConfigureAwait(false);
328-
var _body = Client.Deserialize<Models.JobResultsUri>(_content);
329-
return _body;
330-
}
331-
}
332-
}
333-
}
334-
335-
internal async Task OnResultsFailed(Request req, Response res)
336-
{
337-
string content = null;
338-
if (res.ContentStream != null)
339-
{
340-
using (var reader = new StreamReader(res.ContentStream))
341-
{
342-
content = await reader.ReadToEndAsync().ConfigureAwait(false);
343-
}
344-
}
345-
346-
var ex = new RestApiException<Models.ApiError>(
347-
req,
348-
res,
349-
content,
350-
Client.Deserialize<Models.ApiError>(content)
351-
);
352-
HandleFailedResultsRequest(ex);
353-
HandleFailedRequest(ex);
354-
Client.OnFailedRequest(ex);
355-
throw ex;
356-
}
357-
358271
partial void HandleFailedPassFailRequest(RestApiException ex);
359272

360273
public async Task<Models.JobPassFail> PassFailAsync(

src/Microsoft.DotNet.Helix/Client/CSharp/generated-code/Models/JobCreationResult.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ public bool IsValid
4949
{
5050
return false;
5151
}
52+
if (string.IsNullOrEmpty(ResultsUriRSAS))
53+
{
54+
return false;
55+
}
5256
return true;
5357
}
5458
}

src/Microsoft.DotNet.Helix/Client/CSharp/generated-code/Models/JobResultsUri.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/Microsoft.DotNet.Helix/JobSender/ISentJob.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ public interface ISentJob
2323
/// </summary>
2424
string HelixCancellationToken { get; }
2525

26+
/// <summary>
27+
/// URI for blob storage container with the results.
28+
/// </summary>
29+
string ResultsContainerUri { get; }
30+
31+
/// <summary>
32+
/// Shared Access Signature for access to the container with results.
33+
/// Used for internal builds.
34+
/// </summary>
35+
string ResultsContainerReadSAS { get; }
36+
2637
/// <summary>
2738
/// Poll for the job to actually finish inside Helix.
2839
/// </summary>

src/Microsoft.DotNet.Helix/JobSender/JobDefinition.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,9 @@ public async Task<ISentJob> SendAsync(Action<string> log, CancellationToken canc
239239
}
240240

241241
string jobStartIdentifier = Guid.NewGuid().ToString("N");
242-
var newJob = await JobApi.NewAsync(creationRequest, jobStartIdentifier, cancellationToken: cancellationToken).ConfigureAwait(false);
242+
var newJob = await JobApi.NewAsync(creationRequest, jobStartIdentifier, cancellationToken).ConfigureAwait(false);
243243

244-
return new SentJob(JobApi, newJob);
244+
return new SentJob(JobApi, newJob, newJob.ResultsUri, newJob.ResultsUriRSAS);
245245
}
246246

247247
private void WarnForImpendingRemoval(Action<string> log, QueueInfo queueInfo)

src/Microsoft.DotNet.Helix/JobSender/SentJob.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@ namespace Microsoft.DotNet.Helix.Client
99
{
1010
internal class SentJob : ISentJob
1111
{
12-
public SentJob(IJob jobApi, JobCreationResult newJob)
12+
public SentJob(IJob jobApi, JobCreationResult newJob, string resultsContainerUri, string resultsContainerReadSAS)
1313
{
1414
JobApi = jobApi;
1515
CorrelationId = newJob.Name;
1616
HelixCancellationToken = newJob.CancellationToken;
17+
ResultsContainerUri = resultsContainerUri;
18+
ResultsContainerReadSAS = resultsContainerReadSAS;
1719
}
1820

1921
public IJob JobApi { get; }
2022
public string CorrelationId { get; }
2123
public string HelixCancellationToken { get; }
24+
public string ResultsContainerUri { get; }
25+
public string ResultsContainerReadSAS { get; }
2226

2327
public Task<JobPassFail> WaitAsync(int pollingIntervalMs = 10000, CancellationToken cancellationToken = default)
2428
{

src/Microsoft.DotNet.Helix/Sdk/DownloadFromResultsContainer.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class DownloadFromResultsContainer : HelixTask, ICancelableTask
2626
[Required]
2727
public ITaskItem[] MetadataToWrite { get; set; }
2828

29+
public string ResultsContainerReadSAS { get; set; }
30+
2931
private const string MetadataFile = "metadata.txt";
3032

3133
private readonly CancellationTokenSource _cancellationSource = new CancellationTokenSource();
@@ -72,7 +74,6 @@ private async Task DownloadFilesForWorkItem(ITaskItem workItem, string directory
7274

7375
// Use the Helix API to get the last possible iteration of the work item's execution
7476
var allAvailableFiles = await HelixApi.WorkItem.ListFilesAsync(workItemName, JobId, true, ct);
75-
var resultsUri = await HelixApi.Job.ResultsAsync(JobId, ct);
7677

7778
DirectoryInfo destinationDir = Directory.CreateDirectory(Path.Combine(directoryPath, workItemName));
7879
foreach (string file in filesToDownload)
@@ -108,14 +109,14 @@ private async Task DownloadFilesForWorkItem(ITaskItem workItem, string directory
108109
// If we have no read SAS token from the build, make a best-effort attempt using the URL from the Helix API.
109110
// For restricted queues, there will be no read SAS token available to use in the Helix API's result
110111
// (but hopefully the 'else' branch will be hit in this case)
111-
if (string.IsNullOrEmpty(resultsUri.ResultsUriRSAS))
112+
if (string.IsNullOrEmpty(ResultsContainerReadSAS))
112113
{
113114
blob = new BlobClient(new Uri(fileAvailableForDownload.Link), blobClientOptions);
114115
}
115116
else
116117
{
117118
var strippedFileUri = new Uri(fileAvailableForDownload.Link.Substring(0, fileAvailableForDownload.Link.LastIndexOf('?')));
118-
blob = new BlobClient(strippedFileUri, new AzureSasCredential(resultsUri.ResultsUriRSAS), blobClientOptions);
119+
blob = new BlobClient(strippedFileUri, new AzureSasCredential(ResultsContainerReadSAS), blobClientOptions);
119120
}
120121
await blob.DownloadToAsync(destinationFile);
121122
}

src/Microsoft.DotNet.Helix/Sdk/SendHelixJob.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ public static class MetadataNames
7878
[Output]
7979
public string JobCancellationToken { get; set; }
8080

81+
/// <summary>
82+
/// When the task finishes, the results container uri should be available in case we want to download files.
83+
/// </summary>
84+
[Output]
85+
public string ResultsContainerUri { get; set; }
86+
87+
/// <summary>
88+
/// If the job is internal, we need to give the DownloadFromResultsContainer task the Write SAS to download files.
89+
/// </summary>
90+
[Output]
91+
public string ResultsContainerReadSAS { get; set; }
92+
8193
/// <summary>
8294
/// A collection of commands that will run for each work item before any work item commands.
8395
/// Use a semicolon to delimit these and escape semicolons by percent coding them ('%3B').
@@ -258,6 +270,8 @@ protected override async Task ExecuteCore(CancellationToken cancellationToken)
258270
ISentJob job = await def.SendAsync(msg => Log.LogMessageFromText(msg, MessageImportance.Normal), cancellationToken);
259271
JobCorrelationId = job.CorrelationId;
260272
JobCancellationToken = job.HelixCancellationToken;
273+
ResultsContainerUri = job.ResultsContainerUri;
274+
ResultsContainerReadSAS = job.ResultsContainerReadSAS;
261275
cancellationToken.ThrowIfCancellationRequested();
262276
}
263277

src/Microsoft.DotNet.Helix/Sdk/tools/Microsoft.DotNet.Helix.Sdk.MonoQueue.targets

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,15 @@
5959
HelixProperties="@(HelixProperties)">
6060
<Output TaskParameter="JobCorrelationId" PropertyName="HelixJobId"/>
6161
<Output TaskParameter="JobCancellationToken" PropertyName="HelixJobCancellationToken"/>
62+
<Output TaskParameter="ResultsContainerUri" PropertyName="HelixResultsContainer"/>
63+
<Output TaskParameter="ResultsContainerReadSAS" PropertyName="HelixResultsContainerReadSAS"/>
6264
</SendHelixJob>
6365
<ItemGroup>
6466
<SentJob Include="$(HelixJobId)">
6567
<WorkItemCount>@(HelixWorkItem->Count())</WorkItemCount>
6668
<HelixTargetQueue>$(HelixTargetQueue)</HelixTargetQueue>
69+
<ResultsContainerUri>$(HelixResultsContainer)</ResultsContainerUri>
70+
<ResultsContainerReadSAS>$(HelixResultsContainerReadSAS)</ResultsContainerReadSAS>
6771
<HelixJobCancellationToken>$(HelixJobCancellationToken)</HelixJobCancellationToken>
6872
</SentJob>
6973
</ItemGroup>

src/Microsoft.DotNet.Helix/Sdk/tools/download-results/DownloadFromResultsContainer.targets

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@
2121
<_shouldDownloadResults Condition="'@(_workItemsWithDownloadMetadata)' != '' AND '$(HelixResultsDestinationDir)' != ''">true</_shouldDownloadResults>
2222
</PropertyGroup>
2323

24+
<Warning Text="DownloadFromResultsContainer will be skipped for job %(SentJob.Identity) because results container uri is empty" Condition="'%(SentJob.ResultsContainerUri)' == '' AND $(_shouldDownloadResults)" />
25+
2426
<DownloadFromResultsContainer
25-
Condition="$(_shouldDownloadResults)"
27+
Condition="$(_shouldDownloadResults) AND '%(SentJob.ResultsContainerUri)' != ''"
2628
AccessToken="$(HelixAccessToken)"
2729
WorkItems="@(_workItemsWithDownloadMetadata)"
2830
OutputDirectory="$(HelixResultsDestinationDir)"
2931
MetadataToWrite="@(HelixDownloadResultsMetadata)"
30-
JobId="%(SentJob.Identity)" />
32+
JobId="%(SentJob.Identity)"
33+
ResultsContainerReadSAS="%(SentJob.ResultsContainerReadSAS)" />
3134
</Target>
3235

3336
</Project>

0 commit comments

Comments
 (0)