Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private void AnnotateDigest(EolDigestData digestData, DateOnly? globalEolDate)
}
}

private static EolAnnotationsData LoadEolAnnotationsData(string eolDigestsListPath)
public static EolAnnotationsData LoadEolAnnotationsData(string eolDigestsListPath)
{
string eolAnnotationsJson = File.ReadAllText(eolDigestsListPath);
EolAnnotationsData? eolAnnotations = JsonSerializer.Deserialize<EolAnnotationsData>(eolAnnotationsJson);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.CommandLine;
using static Microsoft.DotNet.ImageBuilder.Commands.CliHelper;

namespace Microsoft.DotNet.ImageBuilder.Commands;

#nullable enable
public class MarIngestionOptions
{
public TimeSpan WaitTimeout { get; set; }

public TimeSpan RequeryDelay { get; set; }
}

internal class MarIngestionOptionsBuilder
{
public IEnumerable<Option> GetCliOptions(TimeSpan defaultTimeout, TimeSpan defaultRequeryDelay) =>
[
CreateOption("timeout", nameof(MarIngestionOptions.WaitTimeout),
$"Maximum time to wait for ingestion",
val => TimeSpan.Parse(val), defaultTimeout),
CreateOption("requery-delay", nameof(MarIngestionOptions.RequeryDelay),
$"Amount of time to wait before requerying the status",
val => TimeSpan.Parse(val), defaultRequeryDelay)
];

public IEnumerable<Argument> GetCliArguments() => [];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.DotNet.ImageBuilder.Models.Annotations;

#nullable enable
namespace Microsoft.DotNet.ImageBuilder.Commands
{
[Export(typeof(ICommand))]
public class WaitForMarAnnotationIngestionCommand : Command<WaitForMarAnnotationIngestionOptions, WaitForMarAnnotationIngestionOptionsBuilder>
{
private readonly ILoggerService _loggerService;
private readonly IMarImageIngestionReporter _imageIngestionReporter;

[ImportingConstructor]
public WaitForMarAnnotationIngestionCommand(
ILoggerService loggerService, IMarImageIngestionReporter imageIngestionReporter)
{
_loggerService = loggerService ?? throw new ArgumentNullException(nameof(loggerService));
_imageIngestionReporter = imageIngestionReporter ?? throw new ArgumentNullException(nameof(imageIngestionReporter));
}

protected override string Description => "Waits for annotations to complete ingestion into MAR";

public override async Task ExecuteAsync()
{
_loggerService.WriteHeading("WAITING FOR ANNOTATION INGESTION");

EolAnnotationsData annotationsData = AnnotateEolDigestsCommand.LoadEolAnnotationsData(Options.EolDigestsListPath);
IEnumerable<DigestInfo> digests = annotationsData.EolDigests
.Select(annotation =>
{
ImageName name = ImageName.Parse(annotation.Digest);
if (name.Digest is null)
{
throw new Exception($"Could not parse digest SHA value from '{annotation.Digest}'.");
}
return new DigestInfo(name.Digest, name.Repo, tags: []);
});

if (!Options.IsDryRun)
{
await _imageIngestionReporter.ReportImageStatusesAsync(digests, Options.IngestionOptions.WaitTimeout, Options.IngestionOptions.RequeryDelay, minimumQueueTime: null);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.CommandLine;

#nullable enable
namespace Microsoft.DotNet.ImageBuilder.Commands
{
public class WaitForMarAnnotationIngestionOptions : Options
{
public string EolDigestsListPath { get; set; } = string.Empty;

public MarIngestionOptions IngestionOptions { get; set; } = new();
}

public class WaitForMarAnnotationIngestionOptionsBuilder : CliOptionsBuilder
{
private static readonly TimeSpan s_defaultWaitTimeout = TimeSpan.FromMinutes(20);
private static readonly TimeSpan s_defaultRequeryDelay = TimeSpan.FromSeconds(10);

private readonly MarIngestionOptionsBuilder _ingestionOptionsBuilder = new();

public override IEnumerable<Argument> GetCliArguments() =>
[
..base.GetCliArguments(),
.._ingestionOptionsBuilder.GetCliArguments(),
new Argument<string>(nameof(WaitForMarAnnotationIngestionOptions.EolDigestsListPath),
"EOL annotations digests list path")
];

public override IEnumerable<Option> GetCliOptions() =>
[
..base.GetCliOptions(),
.._ingestionOptionsBuilder.GetCliOptions(s_defaultWaitTimeout, s_defaultRequeryDelay)
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private async Task<CommitResult> WaitForIngestionAsync(IMcrStatusClient statusCl
{
case StageStatus.Processing:
case StageStatus.NotStarted:
await Task.Delay(Options.RequeryDelay);
await Task.Delay(Options.IngestionOptions.RequeryDelay);
break;
case StageStatus.Failed:
_loggerService.WriteError(await GetFailureResultsAsync(statusClient, commitStatus));
Expand All @@ -85,9 +85,9 @@ private async Task<CommitResult> WaitForIngestionAsync(IMcrStatusClient statusCl
_environmentService.Exit(1);
}

if (DateTime.Now - startTime >= Options.WaitTimeout)
if (DateTime.Now - startTime >= Options.IngestionOptions.WaitTimeout)
{
throw new TimeoutException($"Timed out after '{Options.WaitTimeout}' waiting for the docs to be ingested.");
throw new TimeoutException($"Timed out after '{Options.IngestionOptions.WaitTimeout}' waiting for the docs to be ingested.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.Linq;
using static Microsoft.DotNet.ImageBuilder.Commands.CliHelper;

#nullable enable
namespace Microsoft.DotNet.ImageBuilder.Commands
Expand All @@ -15,39 +13,29 @@ public class WaitForMcrDocIngestionOptions : Options
{
public string CommitDigest { get; set; } = string.Empty;

public TimeSpan WaitTimeout { get; set; }

public TimeSpan RequeryDelay { get; set; }
public MarIngestionOptions IngestionOptions { get; set; } = new();
}

public class WaitForMcrDocIngestionOptionsBuilder : CliOptionsBuilder
{
private static readonly TimeSpan DefaultTimeout = TimeSpan.FromMinutes(5);
private static readonly TimeSpan DefaultRequeryDelay = TimeSpan.FromSeconds(10);
private static readonly TimeSpan s_defaultTimeout = TimeSpan.FromMinutes(5);
private static readonly TimeSpan s_defaultRequeryDelay = TimeSpan.FromSeconds(10);

private readonly MarIngestionOptionsBuilder _ingestionOptionsBuilder = new();

public override IEnumerable<Argument> GetCliArguments() =>
base.GetCliArguments()
.Concat(
new Argument[]
{
new Argument<string>(nameof(WaitForMcrDocIngestionOptions.CommitDigest),
"Git commit digest of the readme changes")
}
);
[
..base.GetCliArguments(),
.._ingestionOptionsBuilder.GetCliArguments(),
new Argument<string>(nameof(WaitForMcrDocIngestionOptions.CommitDigest),
"Git commit digest of the readme changes")
];

public override IEnumerable<Option> GetCliOptions() =>
base.GetCliOptions()
.Concat(
new Option[]
{
CreateOption("timeout", nameof(WaitForMcrDocIngestionOptions.WaitTimeout),
$"Maximum time to wait for doc ingestion (default: {DefaultTimeout})",
val => TimeSpan.Parse(val), DefaultTimeout),
CreateOption("requery-delay", nameof(WaitForMcrDocIngestionOptions.RequeryDelay),
$"Amount of time to wait before requerying the status of the commit (default: {DefaultRequeryDelay})",
val => TimeSpan.Parse(val), DefaultRequeryDelay)
}
);
[
..base.GetCliOptions(),
.._ingestionOptionsBuilder.GetCliOptions(s_defaultTimeout, s_defaultRequeryDelay)
];
}
}
#nullable disable
Loading