Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
/ NuGet.Jobs Public archive

Commit

Permalink
Integrate public symbols etag. (#592)
Browse files Browse the repository at this point in the history
Add the etag support for symbols and update the email services to align with the gallery changes.
  • Loading branch information
cristinamanum authored Oct 24, 2018
1 parent ab3301b commit 79c8107
Show file tree
Hide file tree
Showing 21 changed files with 457 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
using System;
using System.Net.Mail;
using Microsoft.Extensions.Options;
using NuGetGallery.Services;
using NuGetGallery.Infrastructure.Mail;

namespace NuGet.Services.Validation.Orchestrator
{
public class CoreMessageServiceConfiguration : ICoreMessageServiceConfiguration
public class CoreMessageServiceConfiguration : IMessageServiceConfiguration
{
public CoreMessageServiceConfiguration(IOptionsSnapshot<EmailConfiguration> emailConfigurationAccessor)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,13 @@ Task CopyValidationSetPackageToPackageFileAsync(
/// <exception cref="Microsoft.WindowsAzure.Storage.StorageException">Thrown if the blob has changed between
/// successive read and write operations.</exception>
Task<PackageStreamMetadata> UpdatePackageBlobMetadataAsync(PackageValidationSet validationSet);

/// <summary>
/// Reads the ETag for the package in the public container.
/// </summary>
/// <param name="validationSet">A validationSet that will identify the package that will have its blob metadata updated.</param>
/// <returns>A task that represents the asynchronous operation.
/// The result is the etag of the package blob or null if the package does not exists.</returns>
Task<string> GetPublicPackageBlobETagOrNullAsync(PackageValidationSet validationSet);
}
}
10 changes: 5 additions & 5 deletions src/NuGet.Services.Validation.Orchestrator/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
using NuGet.Services.Validation.PackageSigning.ValidateCertificate;
using NuGet.Services.Validation.Vcs;
using NuGetGallery.Diagnostics;
using NuGetGallery.Services;
using NuGetGallery.Infrastructure.Mail;

namespace NuGet.Services.Validation.Orchestrator
{
Expand Down Expand Up @@ -280,8 +280,8 @@ private void ConfigureJobServices(IServiceCollection services, IConfigurationRoo
? (IMailSender)new DiskMailSender()
: (IMailSender)new MailSender(mailSenderConfiguration);
});
services.AddTransient<ICoreMessageServiceConfiguration, CoreMessageServiceConfiguration>();
services.AddTransient<ICoreMessageService, CoreMessageService>();
services.AddTransient<IMessageServiceConfiguration, CoreMessageServiceConfiguration>();
services.AddTransient<IMessageService, CoreMarkdownMessageService>();
services.AddTransient<IMessageService<Package>, PackageMessageService>();
services.AddTransient<ICommonTelemetryService, CommonTelemetryService>();
services.AddTransient<ITelemetryService, TelemetryService>();
Expand Down Expand Up @@ -581,7 +581,7 @@ private static void ConfigureFileServices(IServiceCollection services, IConfigur
break;
case ValidatingType.SymbolPackage:
services.AddTransient<IFileMetadataService, SymbolPackageFileMetadataService>();
services.AddTransient<IValidationFileService, ValidationSymbolFileService>();
services.AddTransient<IValidationFileService, ValidationFileService>();
break;
default:
throw new NotImplementedException($"Unknown type: {validatingType}");
Expand All @@ -595,7 +595,7 @@ private static void ConfigureOrchestratorSymbolTypes(IServiceCollection services
services.AddTransient<ICoreSymbolPackageService, CoreSymbolPackageService>();
services.AddTransient<ICriteriaEvaluator<SymbolPackage>, SymbolCriteriaEvaluator>();
services.AddTransient<IValidationOutcomeProcessor<SymbolPackage>, ValidationOutcomeProcessor<SymbolPackage>>();
services.AddTransient<IStatusProcessor<SymbolPackage>, EntityStatusProcessor<SymbolPackage>>();
services.AddTransient<IStatusProcessor<SymbolPackage>, SymbolsStatusProcessor>();
services.AddTransient<IValidationSetProvider<SymbolPackage>, ValidationSetProvider<SymbolPackage>>();
services.AddTransient<IMessageService<SymbolPackage>, SymbolsPackageMessageService>();
services.AddTransient<IBrokeredMessageSerializer<SymbolsValidatorMessage>, SymbolsValidatorMessageSerializer>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<Compile Include="Error.cs" />
<Compile Include="Services\MessageServiceConfiguration.cs" />
<Compile Include="Services\SymbolsMessageService.cs" />
<Compile Include="SymbolsStatusProcessor.cs" />
<Compile Include="Symbols\ISymbolsIngesterMessageEnqueuer.cs" />
<Compile Include="Symbols\SymbolScanOnlyConfiguration.cs" />
<Compile Include="Symbols\SymbolCriteriaEvaluator.cs" />
Expand Down Expand Up @@ -107,7 +108,6 @@
<Compile Include="ValidatingEntitites\PackageValidatingEntity.cs" />
<Compile Include="ValidationFailureBehavior.cs" />
<Compile Include="SymbolValidationMessageHandler.cs" />
<Compile Include="ValidationSymbolFileService.cs" />
<Compile Include="ValidationPackageFileService.cs" />
<Compile Include="ValidationSetProcessorResult.cs" />
<Compile Include="Vcs\IPackageCriteria.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ namespace NuGet.Services.Validation.Orchestrator
{
public class EntityStatusProcessor<T> : IStatusProcessor<T> where T : class, IEntity
{
private readonly IEntityService<T> _galleryPackageService;
private readonly IValidationFileService _packageFileService;
private readonly IValidatorProvider _validatorProvider;
private readonly ITelemetryService _telemetryService;
private readonly ILogger<EntityStatusProcessor<T>> _logger;
protected readonly IEntityService<T> _galleryPackageService;
protected readonly IValidationFileService _packageFileService;
protected readonly IValidatorProvider _validatorProvider;
protected readonly ITelemetryService _telemetryService;
protected readonly ILogger<EntityStatusProcessor<T>> _logger;

public EntityStatusProcessor(
IEntityService<T> galleryPackageService,
Expand Down Expand Up @@ -76,7 +76,7 @@ public Task SetStatusAsync(
}
}

private async Task MakePackageFailedValidationAsync(IValidatingEntity<T> validatingEntity, PackageValidationSet validationSet)
protected virtual async Task MakePackageFailedValidationAsync(IValidatingEntity<T> validatingEntity, PackageValidationSet validationSet)
{
var fromStatus = validatingEntity.Status;

Expand All @@ -88,7 +88,7 @@ private async Task MakePackageFailedValidationAsync(IValidatingEntity<T> validat
}
}

private async Task MakePackageAvailableAsync(IValidatingEntity<T> validatingEntity, PackageValidationSet validationSet)
protected virtual async Task MakePackageAvailableAsync(IValidatingEntity<T> validatingEntity, PackageValidationSet validationSet)
{
// 1) Operate on blob storage.
var copied = await UpdatePublicPackageAsync(validationSet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Net.Mail;
using Microsoft.Extensions.Options;
using NuGetGallery.Infrastructure.Mail;

namespace NuGet.Services.Validation.Orchestrator
{
public class MessageServiceConfiguration
public class MessageServiceConfiguration : IMessageServiceConfiguration
{
public EmailConfiguration EmailConfiguration { get; }

Expand All @@ -17,6 +19,7 @@ public MessageServiceConfiguration(IOptionsSnapshot<EmailConfiguration> emailCon
throw new ArgumentNullException(nameof(emailConfigurationAccessor));
}
EmailConfiguration = emailConfigurationAccessor.Value ?? throw new ArgumentException("Value cannot be null", nameof(emailConfigurationAccessor));

if (string.IsNullOrWhiteSpace(EmailConfiguration.PackageUrlTemplate))
{
throw new ArgumentException($"{nameof(emailConfigurationAccessor.Value)}.{nameof(EmailConfiguration.PackageUrlTemplate)} cannot be empty", nameof(emailConfigurationAccessor));
Expand All @@ -33,9 +36,19 @@ public MessageServiceConfiguration(IOptionsSnapshot<EmailConfiguration> emailCon
{
throw new ArgumentException($"{nameof(emailConfigurationAccessor.Value)}.{nameof(EmailConfiguration.EmailSettingsUrl)} must be an absolute Url", nameof(emailConfigurationAccessor));
}

GalleryOwner = new MailAddress(EmailConfiguration.GalleryOwner);
GalleryNoReplyAddress = new MailAddress(EmailConfiguration.GalleryNoReplyAddress);
}

public string GalleryPackageUrl(string packageId, string packageNormalizedVersion) => string.Format(EmailConfiguration.PackageUrlTemplate, packageId, packageNormalizedVersion);
public string PackageSupportUrl(string packageId, string packageNormalizedVersion) => string.Format(EmailConfiguration.PackageSupportTemplate, packageId, packageNormalizedVersion);

public MailAddress GalleryOwner { get; set; }

/// <summary>
/// Gets the gallery e-mail from name and email address
/// </summary>
public MailAddress GalleryNoReplyAddress { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NuGetGallery;
using NuGetGallery.Services;
using NuGetGallery.Infrastructure.Mail;
using NuGetGallery.Infrastructure.Mail.Messages;

namespace NuGet.Services.Validation.Orchestrator
{
public class PackageMessageService : IMessageService<Package>
{
private readonly ICoreMessageService _coreMessageService;
private readonly IMessageService _messageService;
private readonly ILogger<PackageMessageService> _logger;
private readonly MessageServiceConfiguration _serviceConfiguration;

public PackageMessageService(
ICoreMessageService coreMessageService,
IMessageService messageService,
IOptionsSnapshot<EmailConfiguration> emailConfigurationAccessor,
ILogger<PackageMessageService> logger)
{
_serviceConfiguration = new MessageServiceConfiguration(emailConfigurationAccessor);
_coreMessageService = coreMessageService ?? throw new ArgumentNullException(nameof(coreMessageService));
_messageService = messageService ?? throw new ArgumentNullException(nameof(messageService));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}

Expand All @@ -32,8 +33,15 @@ public async Task SendPublishedMessageAsync(Package package)

var galleryPackageUrl = _serviceConfiguration.GalleryPackageUrl(package.PackageRegistration.Id, package.NormalizedVersion);
var packageSupportUrl = _serviceConfiguration.PackageSupportUrl(package.PackageRegistration.Id, package.NormalizedVersion);

await _coreMessageService.SendPackageAddedNoticeAsync(package, galleryPackageUrl, packageSupportUrl, _serviceConfiguration.EmailConfiguration.EmailSettingsUrl);
var packageAddedMessage = new PackageAddedMessage(
_serviceConfiguration,
package,
galleryPackageUrl,
packageSupportUrl,
_serviceConfiguration.EmailConfiguration.EmailSettingsUrl,
Array.Empty<string>());

await _messageService.SendMessageAsync(packageAddedMessage);
}

public async Task SendValidationFailedMessageAsync(Package package, PackageValidationSet validationSet)
Expand All @@ -44,14 +52,28 @@ public async Task SendValidationFailedMessageAsync(Package package, PackageValid
var galleryPackageUrl = _serviceConfiguration.GalleryPackageUrl(package.PackageRegistration.Id, package.NormalizedVersion);
var packageSupportUrl = _serviceConfiguration.PackageSupportUrl(package.PackageRegistration.Id, package.NormalizedVersion);

await _coreMessageService.SendPackageValidationFailedNoticeAsync(package, validationSet, galleryPackageUrl, packageSupportUrl, _serviceConfiguration.EmailConfiguration.AnnouncementsUrl, _serviceConfiguration.EmailConfiguration.TwitterUrl);
var packageValidationFailedMessage = new PackageValidationFailedMessage(
_serviceConfiguration,
package,
validationSet,
galleryPackageUrl,
packageSupportUrl,
_serviceConfiguration.EmailConfiguration.AnnouncementsUrl,
_serviceConfiguration.EmailConfiguration.TwitterUrl);

await _messageService.SendMessageAsync(packageValidationFailedMessage);
}

public async Task SendValidationTakingTooLongMessageAsync(Package package)
{
package = package ?? throw new ArgumentNullException(nameof(package));

await _coreMessageService.SendValidationTakingTooLongNoticeAsync(package, _serviceConfiguration.GalleryPackageUrl(package.PackageRegistration.Id, package.NormalizedVersion));
var packageValidationTakingTooLongMessage = new PackageValidationTakingTooLongMessage(
_serviceConfiguration,
package,
_serviceConfiguration.GalleryPackageUrl(package.PackageRegistration.Id, package.NormalizedVersion));

await _messageService.SendMessageAsync(packageValidationTakingTooLongMessage);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NuGetGallery;
using NuGetGallery.Services;
using NuGetGallery.Infrastructure.Mail;
using NuGetGallery.Infrastructure.Mail.Messages;

namespace NuGet.Services.Validation.Orchestrator
{
public class SymbolsPackageMessageService : IMessageService<SymbolPackage>
{
private readonly ICoreMessageService _coreMessageService;
private readonly IMessageService _messageService;
private readonly ILogger<SymbolsPackageMessageService> _logger;
private readonly MessageServiceConfiguration _serviceConfiguration;

public SymbolsPackageMessageService(
ICoreMessageService coreMessageService,
IMessageService messageService,
IOptionsSnapshot<EmailConfiguration> emailConfigurationAccessor,
ILogger<SymbolsPackageMessageService> logger)
{
_serviceConfiguration = new MessageServiceConfiguration(emailConfigurationAccessor);
_coreMessageService = coreMessageService ?? throw new ArgumentNullException(nameof(coreMessageService));
_messageService = messageService ?? throw new ArgumentNullException(nameof(messageService));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}

Expand All @@ -35,8 +36,14 @@ public async Task SendPublishedMessageAsync(SymbolPackage symbolPackage)

var galleryPackageUrl = _serviceConfiguration.GalleryPackageUrl(symbolPackage.Id, symbolPackage.Package.NormalizedVersion);
var packageSupportUrl = _serviceConfiguration.PackageSupportUrl(symbolPackage.Id, symbolPackage.Package.NormalizedVersion);

await _coreMessageService.SendSymbolPackageAddedNoticeAsync(symbolPackage, galleryPackageUrl, packageSupportUrl, _serviceConfiguration.EmailConfiguration.EmailSettingsUrl);
var symbolPackageAddedMessage = new SymbolPackageAddedMessage(
_serviceConfiguration,
symbolPackage,
galleryPackageUrl,
packageSupportUrl,
_serviceConfiguration.EmailConfiguration.EmailSettingsUrl,
Array.Empty<string>());
await _messageService.SendMessageAsync(symbolPackageAddedMessage);
}

public async Task SendValidationFailedMessageAsync(SymbolPackage symbolPackage, PackageValidationSet validationSet)
Expand All @@ -50,7 +57,16 @@ public async Task SendValidationFailedMessageAsync(SymbolPackage symbolPackage,
var galleryPackageUrl = _serviceConfiguration.GalleryPackageUrl(symbolPackage.Id, symbolPackage.Package.NormalizedVersion);
var packageSupportUrl = _serviceConfiguration.PackageSupportUrl(symbolPackage.Id, symbolPackage.Package.NormalizedVersion);

await _coreMessageService.SendSymbolPackageValidationFailedNoticeAsync(symbolPackage, validationSet, galleryPackageUrl, packageSupportUrl, _serviceConfiguration.EmailConfiguration.AnnouncementsUrl, _serviceConfiguration.EmailConfiguration.TwitterUrl);
var symbolPackageValidationFailedMessage = new SymbolPackageValidationFailedMessage(
_serviceConfiguration,
symbolPackage,
validationSet,
galleryPackageUrl,
packageSupportUrl,
_serviceConfiguration.EmailConfiguration.AnnouncementsUrl,
_serviceConfiguration.EmailConfiguration.TwitterUrl);

await _messageService.SendMessageAsync(symbolPackageValidationFailedMessage);
}

public async Task SendValidationTakingTooLongMessageAsync(SymbolPackage symbolPackage)
Expand All @@ -59,8 +75,12 @@ public async Task SendValidationTakingTooLongMessageAsync(SymbolPackage symbolPa
{
throw new ArgumentNullException(nameof(symbolPackage));
}
var symbolPackageValidationTakingTooLongMessage = new SymbolPackageValidationTakingTooLongMessage(
_serviceConfiguration,
symbolPackage,
_serviceConfiguration.GalleryPackageUrl(symbolPackage.Package.PackageRegistration.Id, symbolPackage.Package.NormalizedVersion));

await _coreMessageService.SendValidationTakingTooLongNoticeAsync(symbolPackage, _serviceConfiguration.GalleryPackageUrl(symbolPackage.Id, symbolPackage.Package.NormalizedVersion));
await _messageService.SendMessageAsync(symbolPackageValidationTakingTooLongMessage);
}
}
}
Loading

0 comments on commit 79c8107

Please sign in to comment.