diff --git a/src/NuGet.Services.Validation.Orchestrator/Job.cs b/src/NuGet.Services.Validation.Orchestrator/Job.cs index bd78d131c..48b1a31a6 100644 --- a/src/NuGet.Services.Validation.Orchestrator/Job.cs +++ b/src/NuGet.Services.Validation.Orchestrator/Job.cs @@ -3,10 +3,7 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Net; -using System.Net.Http; -using System.Reflection; using System.Threading.Tasks; using AnglicanGeek.MarkdownMailer; using Autofac; @@ -20,6 +17,7 @@ using Microsoft.WindowsAzure.Storage; using NuGet.Jobs; using NuGet.Jobs.Configuration; +using NuGet.Jobs.Validation; using NuGet.Jobs.Validation.Common; using NuGet.Jobs.Validation.PackageSigning.Messages; using NuGet.Jobs.Validation.PackageSigning.Storage; @@ -91,7 +89,7 @@ public override async Task Run() return; } - var runner = GetRequiredService(); + var runner = GetRequiredService(); await runner.RunOrchestrationAsync(); } @@ -217,6 +215,7 @@ private void ConfigureJobServices(IServiceCollection services, IConfigurationRoo services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddSingleton(new TelemetryClient()); } @@ -354,7 +353,6 @@ private static void ConfigurePackageSigningValidator(ContainerBuilder builder) private static void ConfigurePackageCompatibilityValidator(ContainerBuilder builder) { - // Configure the validator state service for the package compatibility validator. builder .RegisterType() @@ -373,7 +371,6 @@ private static void ConfigurePackageCompatibilityValidator(ContainerBuilder buil .RegisterType() .WithKeyedParameter(typeof(IValidatorStateService), PackageCompatibilityBindingKey) .As(); - } private static void ConfigurePackageCertificatesValidator(ContainerBuilder builder) diff --git a/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityValidator.cs b/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityValidator.cs index 57c87ddd9..9807d16fc 100644 --- a/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityValidator.cs +++ b/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityValidator.cs @@ -46,7 +46,6 @@ public async Task GetResultAsync(IValidationRequest request) public async Task StartValidationAsync(IValidationRequest request) { - // Try check the whole thing try { var validatorStatus = await _validatorStateService.GetStatusAsync(request); @@ -62,34 +61,33 @@ public async Task StartValidationAsync(IValidationRequest req return validatorStatus.ToValidationResult(); } - // Add the status, so subsequent calls don't try to reevaluate the same thing - await _validatorStateService.TryAddValidatorStatusAsync(request, validatorStatus, ValidationStatus.Incomplete); - - var message = new PackageCompatibilityValidationMessage( - request.PackageId, - request.PackageVersion, - new Uri(request.NupkgUrl), - request.ValidationId - ); - - // Do validation - await Validate(message, CancellationToken.None); + try + { + await Validate(request, CancellationToken.None); + } + catch (Exception e) + { + _logger.LogWarning(0, e, "Validation failed in the validator for the following request {request}", request.ValidationId); + } + // Treat every validation as succeeded, as we don't want to block validatorStatus.State = ValidationStatus.Succeeded; await _validatorStateService.SaveStatusAsync(validatorStatus); + return validatorStatus.ToValidationResult(); } catch (Exception e) { - _logger.LogWarning($"Validation failed for the validation request {0}.{Environment.NewLine}Exception: {1}", request.ToString(), e.ToString()); + _logger.LogWarning(0, e, "Validation failed for the following request {request}", request.ValidationId); } - return null; + + return new ValidationResult(ValidationStatus.Succeeded); } - private async Task Validate(PackageCompatibilityValidationMessage message, CancellationToken cancellationToken) + private async Task Validate(IValidationRequest request, CancellationToken cancellationToken) { - using (var packageStream = await _packageDownloader.DownloadAsync(message.NupkgUri, cancellationToken)) + using (var packageStream = await _packageDownloader.DownloadAsync(new Uri(request.NupkgUrl), cancellationToken)) using (var package = new Packaging.PackageArchiveReader(packageStream)) { var warnings = new List(); @@ -99,7 +97,7 @@ private async Task Validate(PackageCompatibilityValidationMessage message, Cance warnings.AddRange(rule.Validate(package)); } - await _packageCompatibilityService.SetPackageCompatibilityState(message.ValidationId, warnings); + await _packageCompatibilityService.SetPackageCompatibilityState(request.ValidationId, warnings); } } } diff --git a/src/NuGet.Services.Validation.Orchestrator/settings.json b/src/NuGet.Services.Validation.Orchestrator/settings.json index 927afc3ea..22d67caca 100644 --- a/src/NuGet.Services.Validation.Orchestrator/settings.json +++ b/src/NuGet.Services.Validation.Orchestrator/settings.json @@ -42,9 +42,9 @@ }, "PackageCompatibility": { "ServiceBus": { - "ConnectionString": "servicebus string", - "TopicPath": "validate-compatibility", - "SubscriptionName": "validate-compatibility" + "ConnectionString": "", + "TopicPath": "", + "SubscriptionName": "" } }, "RunnerConfiguration": { diff --git a/src/Validation.PackageCompatibility.Core/Messages/PackageCompatibilityValidationMessage.cs b/src/Validation.PackageCompatibility.Core/Messages/PackageCompatibilityValidationMessage.cs index 9e7765065..69dd4d451 100644 --- a/src/Validation.PackageCompatibility.Core/Messages/PackageCompatibilityValidationMessage.cs +++ b/src/Validation.PackageCompatibility.Core/Messages/PackageCompatibilityValidationMessage.cs @@ -9,10 +9,14 @@ public class PackageCompatibilityValidationMessage { public PackageCompatibilityValidationMessage(string packageId, string packageVersion, Uri nupkgUri, Guid validationId) { - PackageId = packageId; - PackageVersion = packageVersion; - NupkgUri = nupkgUri; + if (validationId == Guid.Empty) + { + throw new ArgumentOutOfRangeException(nameof(validationId)); + } ValidationId = validationId; + PackageId = packageId ?? throw new ArgumentNullException(nameof(packageId)); + PackageVersion = packageVersion ?? throw new ArgumentNullException(nameof(packageVersion)); + NupkgUri = nupkgUri ?? throw new ArgumentNullException(nameof(nupkgUri)); } public string PackageId { get; } diff --git a/src/Validation.PackageCompatibility.Core/Messages/PackageCompatibilityValidationMessageSerializer.cs b/src/Validation.PackageCompatibility.Core/Messages/PackageCompatibilityValidationMessageSerializer.cs deleted file mode 100644 index 706197b17..000000000 --- a/src/Validation.PackageCompatibility.Core/Messages/PackageCompatibilityValidationMessageSerializer.cs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using NuGet.Services.ServiceBus; -using System; - -namespace Validation.PackageCompatibility.Core.Messages -{ - public class PackageCompatibilityValidationMessageSerializer : IBrokeredMessageSerializer - { - private const string PackageCompatibilityValidationSchema = "PackageCompatibilityValidationMessageData"; - - private IBrokeredMessageSerializer _serializer = - new BrokeredMessageSerializer(); - - public IBrokeredMessage Serialize(PackageCompatibilityValidationMessage message) - { - return _serializer.Serialize(new PackageCompatibilityValidationMessageData - { - PackageId = message.PackageId, - PackageVersion = message.PackageVersion, - NupkgUri = message.NupkgUri, - ValidationId = message.ValidationId - }); - } - - public PackageCompatibilityValidationMessage Deserialize(IBrokeredMessage brokeredMessage) - { - var message = _serializer.Deserialize(brokeredMessage); - - return new PackageCompatibilityValidationMessage( - message.PackageId, - message.PackageVersion, - message.NupkgUri, - message.ValidationId); - } - - [Schema(Name = PackageCompatibilityValidationSchema, Version = 1)] - private struct PackageCompatibilityValidationMessageData - { - public string PackageId { get; set; } - public string PackageVersion { get; set; } - public Uri NupkgUri { get; set; } - public Guid ValidationId { get; set; } - } - } -} diff --git a/src/Validation.PackageCompatibility.Core/PackageCompatibilityService.cs b/src/Validation.PackageCompatibility.Core/PackageCompatibilityService.cs index e7646f164..0597e3a0c 100644 --- a/src/Validation.PackageCompatibility.Core/PackageCompatibilityService.cs +++ b/src/Validation.PackageCompatibility.Core/PackageCompatibilityService.cs @@ -5,7 +5,6 @@ using NuGet.Services.Validation; using System; using System.Collections.Generic; -using System.Data.Entity.Infrastructure; using System.Threading.Tasks; namespace Validation.PackageCompatibility.Core.Storage @@ -38,14 +37,7 @@ public class PackageCompatibilityService : IPackageCompatibilityService } ); } - try - { - await _validationContext.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException e) - { - _logger.LogWarning("trouble saving changes async - {0}", e.Message); - } + await _validationContext.SaveChangesAsync(); } } } diff --git a/src/Validation.PackageCompatibility.Core/Properties/AssemblyInfo.cs b/src/Validation.PackageCompatibility.Core/Properties/AssemblyInfo.cs index 3cd10cd44..b8580d9a5 100644 --- a/src/Validation.PackageCompatibility.Core/Properties/AssemblyInfo.cs +++ b/src/Validation.PackageCompatibility.Core/Properties/AssemblyInfo.cs @@ -8,9 +8,9 @@ [assembly: AssemblyTitle("Validation.PackageCompatibility.Core")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("HP Inc.")] +[assembly: AssemblyCompany(".NET Foundation")] [assembly: AssemblyProduct("Validation.PackageCompatibility.Core")] -[assembly: AssemblyCopyright("Copyright © HP Inc. 2018")] +[assembly: AssemblyCopyright("Copyright © .NET Foundation 2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/src/Validation.PackageCompatibility.Core/Validation.PackageCompatibility.Core.csproj b/src/Validation.PackageCompatibility.Core/Validation.PackageCompatibility.Core.csproj index 8883a12fe..3cd50f70c 100644 --- a/src/Validation.PackageCompatibility.Core/Validation.PackageCompatibility.Core.csproj +++ b/src/Validation.PackageCompatibility.Core/Validation.PackageCompatibility.Core.csproj @@ -41,27 +41,26 @@ - - - 2.3.0 - - - 2.3.0 - - - 2.3.0 - - - 7.1.2 - + + {fa87d075-a934-4443-8d0b-5db32640b6d7} + Validation.Common.Job + + + 4.7.0-preview1-4929 + + ..\..\build + $(BUILD_SOURCESDIRECTORY)\build + $(NuGetBuildPath) + + \ No newline at end of file