From ee229c90e8692aade95a1a1a1beec2d460bdcf64 Mon Sep 17 00:00:00 2001 From: Nikolche Kolev Date: Tue, 20 Feb 2018 22:36:13 -0800 Subject: [PATCH 1/5] add package compatibility skeleton --- .vs/config/applicationhost.config | 10 +- NuGet.Jobs.sln | 15 +- SnapshotAzureBlob/App.config | 2 +- src/ArchivePackages/App.config | 2 +- src/CopyAzureContainer/App.config | 2 +- src/Gallery.CredentialExpiration/App.config | 2 +- src/Gallery.Maintenance/project.json | 2 +- .../NuGet.Jobs.Common.csproj | 16 +- src/NuGet.Jobs.Common/app.config | 2 +- src/NuGet.Jobs.Common/packages.config | 6 +- .../Job.cs | 65 ++++++++- ...et.Services.Validation.Orchestrator.csproj | 13 ++ ...ackageCompatibilityVerificationEnqueuer.cs | 23 +++ .../PackageCompatibilityConfiguration.cs | 19 +++ .../PackageCompatibilityValidator.cs | 96 ++++++++++++ ...ackageCompatibilityVerificationEnqueuer.cs | 43 ++++++ .../settings.json | 7 + ...NuGet.SupportRequests.Notifications.csproj | 8 +- .../app.config | 2 +- .../packages.config | 4 +- src/NuGetCDNRedirect/NuGetCDNRedirect.csproj | 4 +- src/NuGetCDNRedirect/packages.config | 2 +- src/Search.GenerateAuxiliaryData/App.config | 2 +- .../App.config | 2 +- src/Stats.CollectAzureCdnLogs/App.config | 2 +- .../App.config | 2 +- ...tats.CreateAzureCdnWarehouseReports.csproj | 4 +- .../packages.config | 2 +- src/Stats.ImportAzureCdnStatistics/App.config | 2 +- .../Stats.ImportAzureCdnStatistics.csproj | 4 +- .../packages.config | 2 +- src/Stats.RefreshClientDimension/App.config | 2 +- src/Stats.RollUpDownloadFacts/App.config | 2 +- .../Stats.RollUpDownloadFacts.csproj | 4 +- src/Stats.RollUpDownloadFacts/packages.config | 2 +- src/UpdateLicenseReports/App.config | 2 +- src/Validation.Callback.Vcs/Web.config | 2 +- .../Validation.Common.csproj | 8 +- src/Validation.Common/app.config | 4 +- src/Validation.Common/packages.config | 4 +- .../App.config | 6 + ...eCompatibilityPackageReferenceValidator.cs | 19 +++ .../Job.cs | 138 ++++++++++++++++++ ...eCompatibilityPackageReferenceValidator.cs | 48 ++++++ ...geCompatibilityValidationMessageHandler.cs | 29 ++++ .../PackageCompatibilityValidatorResult.cs | 35 +++++ .../Program.cs | 16 ++ .../Properties/AssemblyInfo.cs | 36 +++++ ...tibility.PackageReferenceValidation.csproj | 129 ++++++++++++++++ .../IPackageCompatibilityService.cs | 18 +++ .../PackageCompatibilityValidationMessage.cs | 23 +++ ...ompatibilityValidationMessageSerializer.cs | 47 ++++++ .../PackageCompatibilityService.cs | 50 +++++++ .../Properties/AssemblyInfo.cs | 36 +++++ .../IPackageCompatibilityStateService.cs | 12 ++ .../PackageCompatibilityStateService.cs | 58 ++++++++ ...alidation.PackageCompatibility.Core.csproj | 67 +++++++++ ...Signing.ExtractAndValidateSignature.csproj | 5 + src/Validation.Runner/App.config | 2 +- .../app.config | 2 +- .../app.config | 2 +- 61 files changed, 1117 insertions(+), 58 deletions(-) create mode 100644 src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/IPackageCompatibilityVerificationEnqueuer.cs create mode 100644 src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityConfiguration.cs create mode 100644 src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityValidator.cs create mode 100644 src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityVerificationEnqueuer.cs create mode 100644 src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/App.config create mode 100644 src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/IPackageCompatibilityPackageReferenceValidator.cs create mode 100644 src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Job.cs create mode 100644 src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityPackageReferenceValidator.cs create mode 100644 src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityValidationMessageHandler.cs create mode 100644 src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityValidatorResult.cs create mode 100644 src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Program.cs create mode 100644 src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Properties/AssemblyInfo.cs create mode 100644 src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Validation.PackageCompatibility.PackageReferenceValidation.csproj create mode 100644 src/Validation.PackageCompatibility.Core/IPackageCompatibilityService.cs create mode 100644 src/Validation.PackageCompatibility.Core/Messages/PackageCompatibilityValidationMessage.cs create mode 100644 src/Validation.PackageCompatibility.Core/Messages/PackageCompatibilityValidationMessageSerializer.cs create mode 100644 src/Validation.PackageCompatibility.Core/PackageCompatibilityService.cs create mode 100644 src/Validation.PackageCompatibility.Core/Properties/AssemblyInfo.cs create mode 100644 src/Validation.PackageCompatibility.Core/Storage/IPackageCompatibilityStateService.cs create mode 100644 src/Validation.PackageCompatibility.Core/Storage/PackageCompatibilityStateService.cs create mode 100644 src/Validation.PackageCompatibility.Core/Validation.PackageCompatibility.Core.csproj diff --git a/.vs/config/applicationhost.config b/.vs/config/applicationhost.config index 582b1211a..7d4a25522 100644 --- a/.vs/config/applicationhost.config +++ b/.vs/config/applicationhost.config @@ -163,12 +163,20 @@ - + + + + + + + + + diff --git a/NuGet.Jobs.sln b/NuGet.Jobs.sln index 66daf9b57..81ee9564d 100644 --- a/NuGet.Jobs.sln +++ b/NuGet.Jobs.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.27121.1 +VisualStudioVersion = 15.0.27130.2027 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NuGet.Jobs.Common", "src\NuGet.Jobs.Common\NuGet.Jobs.Common.csproj", "{4B4B1EFB-8F33-42E6-B79F-54E7F3293D31}" EndProject @@ -112,6 +112,9 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Validation.Common.Job", "src\Validation.Common.Job\Validation.Common.Job.csproj", "{FA87D075-A934-4443-8D0B-5DB32640B6D7}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PackageHash", "src\PackageHash\PackageHash.csproj", "{40843020-6F0A-48F0-AC28-42FFE3A5C21E}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Validation.PackageCompatibility.PackageReferenceValidation", "src\Validation.PackageAuthoring.ValidatePackageReferenceCompatibility\Validation.PackageCompatibility.PackageReferenceValidation.csproj", "{1B16DF51-90BB-4AC3-B269-8ADE5FB4FB0B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Validation.PackageCompatibility.Core", "src\Validation.PackageCompatibility.Core\Validation.PackageCompatibility.Core.csproj", "{3958ECDD-DE42-401B-8BC6-553E49F2D42A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -289,6 +292,14 @@ Global {40843020-6F0A-48F0-AC28-42FFE3A5C21E}.Debug|Any CPU.Build.0 = Debug|Any CPU {40843020-6F0A-48F0-AC28-42FFE3A5C21E}.Release|Any CPU.ActiveCfg = Release|Any CPU {40843020-6F0A-48F0-AC28-42FFE3A5C21E}.Release|Any CPU.Build.0 = Release|Any CPU + {1B16DF51-90BB-4AC3-B269-8ADE5FB4FB0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1B16DF51-90BB-4AC3-B269-8ADE5FB4FB0B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1B16DF51-90BB-4AC3-B269-8ADE5FB4FB0B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1B16DF51-90BB-4AC3-B269-8ADE5FB4FB0B}.Release|Any CPU.Build.0 = Release|Any CPU + {3958ECDD-DE42-401B-8BC6-553E49F2D42A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3958ECDD-DE42-401B-8BC6-553E49F2D42A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3958ECDD-DE42-401B-8BC6-553E49F2D42A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3958ECDD-DE42-401B-8BC6-553E49F2D42A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -336,6 +347,8 @@ Global {B4B7564A-965B-447B-927F-6749E2C08880} = {6A776396-02B1-475D-A104-26940ADB04AB} {FA87D075-A934-4443-8D0B-5DB32640B6D7} = {678D7B14-F8BC-4193-99AF-2EE8AA390A02} {40843020-6F0A-48F0-AC28-42FFE3A5C21E} = {FA5644B5-4F08-43F6-86B3-039374312A47} + {1B16DF51-90BB-4AC3-B269-8ADE5FB4FB0B} = {678D7B14-F8BC-4193-99AF-2EE8AA390A02} + {3958ECDD-DE42-401B-8BC6-553E49F2D42A} = {678D7B14-F8BC-4193-99AF-2EE8AA390A02} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {284A7AC3-FB43-4F1F-9C9C-2AF0E1F46C2B} diff --git a/SnapshotAzureBlob/App.config b/SnapshotAzureBlob/App.config index d995f6b91..ec31780c1 100644 --- a/SnapshotAzureBlob/App.config +++ b/SnapshotAzureBlob/App.config @@ -15,7 +15,7 @@ - + diff --git a/src/ArchivePackages/App.config b/src/ArchivePackages/App.config index 30285b038..94df12e7f 100644 --- a/src/ArchivePackages/App.config +++ b/src/ArchivePackages/App.config @@ -35,7 +35,7 @@ - + diff --git a/src/CopyAzureContainer/App.config b/src/CopyAzureContainer/App.config index dbc89f8b0..df5f8c925 100644 --- a/src/CopyAzureContainer/App.config +++ b/src/CopyAzureContainer/App.config @@ -15,7 +15,7 @@ - + diff --git a/src/Gallery.CredentialExpiration/App.config b/src/Gallery.CredentialExpiration/App.config index 20005b32d..5d695d1f6 100644 --- a/src/Gallery.CredentialExpiration/App.config +++ b/src/Gallery.CredentialExpiration/App.config @@ -43,7 +43,7 @@ - + diff --git a/src/Gallery.Maintenance/project.json b/src/Gallery.Maintenance/project.json index 3c20f7dae..2719cbdba 100644 --- a/src/Gallery.Maintenance/project.json +++ b/src/Gallery.Maintenance/project.json @@ -1,7 +1,7 @@ { "dependencies": { "Microsoft.Extensions.Logging.Abstractions": "1.0.0", - "NuGet.Services.Logging": "2.2.3" + "NuGet.Services.Logging": "2.3.0" }, "frameworks": { "net452": {} diff --git a/src/NuGet.Jobs.Common/NuGet.Jobs.Common.csproj b/src/NuGet.Jobs.Common/NuGet.Jobs.Common.csproj index 863da3bb8..68a6fdd8b 100644 --- a/src/NuGet.Jobs.Common/NuGet.Jobs.Common.csproj +++ b/src/NuGet.Jobs.Common/NuGet.Jobs.Common.csproj @@ -133,14 +133,14 @@ ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - - ..\..\packages\NuGet.Services.Configuration.2.2.3\lib\net452\NuGet.Services.Configuration.dll + + ..\..\packages\NuGet.Services.Configuration.2.3.0\lib\net452\NuGet.Services.Configuration.dll - - ..\..\packages\NuGet.Services.KeyVault.2.2.3\lib\net45\NuGet.Services.KeyVault.dll + + ..\..\packages\NuGet.Services.KeyVault.2.3.0\lib\net45\NuGet.Services.KeyVault.dll - - ..\..\packages\NuGet.Services.Logging.2.2.3\lib\net452\NuGet.Services.Logging.dll + + ..\..\packages\NuGet.Services.Logging.2.3.0\lib\net452\NuGet.Services.Logging.dll ..\..\packages\Serilog.2.0.0\lib\net45\Serilog.dll @@ -205,7 +205,9 @@ - + + Designer + Designer diff --git a/src/NuGet.Jobs.Common/app.config b/src/NuGet.Jobs.Common/app.config index d2dea252b..e4974f6cf 100644 --- a/src/NuGet.Jobs.Common/app.config +++ b/src/NuGet.Jobs.Common/app.config @@ -32,7 +32,7 @@ - + diff --git a/src/NuGet.Jobs.Common/packages.config b/src/NuGet.Jobs.Common/packages.config index 31643d606..4ce6acdb2 100644 --- a/src/NuGet.Jobs.Common/packages.config +++ b/src/NuGet.Jobs.Common/packages.config @@ -31,9 +31,9 @@ - - - + + + diff --git a/src/NuGet.Services.Validation.Orchestrator/Job.cs b/src/NuGet.Services.Validation.Orchestrator/Job.cs index cc5fea3ae..2b523ba5d 100644 --- a/src/NuGet.Services.Validation.Orchestrator/Job.cs +++ b/src/NuGet.Services.Validation.Orchestrator/Job.cs @@ -5,6 +5,8 @@ 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; @@ -25,11 +27,15 @@ using NuGet.Services.KeyVault; using NuGet.Services.Logging; using NuGet.Services.ServiceBus; +using NuGet.Services.Validation.Orchestrator.PackageCompatibility; using NuGet.Services.Validation.Orchestrator.Telemetry; using NuGet.Services.Validation.PackageCertificates; +using NuGet.Services.Validation.PackageCompatibility; using NuGet.Services.Validation.PackageSigning; using NuGet.Services.Validation.Vcs; using NuGetGallery.Services; +using Validation.PackageCompatibility.Core.Messages; +using Validation.PackageCompatibility.Core.Storage; namespace NuGet.Services.Validation.Orchestrator { @@ -42,6 +48,7 @@ public class Job : JobBase private const string VcsSectionName = "Vcs"; private const string PackageSigningSectionName = "PackageSigning"; private const string PackageCertificatesSectionName = "PackageCertificates"; + private const string PackageCompatibilitySectionName = "PackageCompatibility"; private const string RunnerConfigurationSectionName = "RunnerConfiguration"; private const string GalleryDbConfigurationSectionName = "GalleryDb"; private const string ValidationDbConfigurationSectionName = "ValidationDb"; @@ -53,6 +60,7 @@ public class Job : JobBase private const string PackageVerificationTopicClientBindingKey = "PackageVerificationTopicClient"; private const string PackageSigningBindingKey = PackageSigningSectionName; private const string PackageCertificatesBindingKey = PackageCertificatesSectionName; + private const string PackageCompatibilityBindingKey = PackageCompatibilitySectionName; private const string ValidationStorageBindingKey = "ValidationStorage"; private const string OrchestratorBindingKey = "Orchestrator"; @@ -87,6 +95,7 @@ public override async Task Run() } var runner = GetRequiredService(); + await runner.RunOrchestrationAsync(); } @@ -142,6 +151,7 @@ private void ConfigureJobServices(IServiceCollection services, IConfigurationRoo services.Configure(configurationRoot.GetSection(VcsSectionName)); services.Configure(configurationRoot.GetSection(PackageSigningSectionName)); services.Configure(configurationRoot.GetSection(PackageCertificatesSectionName)); + services.Configure(configurationRoot.GetSection(PackageCompatibilitySectionName)); services.Configure(configurationRoot.GetSection(RunnerConfigurationSectionName)); services.Configure(configurationRoot.GetSection(GalleryDbConfigurationSectionName)); services.Configure(configurationRoot.GetSection(ValidationDbConfigurationSectionName)); @@ -182,8 +192,11 @@ private void ConfigureJobServices(IServiceCollection services, IConfigurationRoo services.AddTransient, PackageValidationMessageDataSerializationAdapter>(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient, SignatureValidationMessageSerializer>(); + services.AddTransient(); + services.AddTransient, PackageCompatibilityValidationMessageSerializer>(); services.AddTransient(); services.AddTransient(); services.AddTransient(serviceProvider => @@ -218,7 +231,6 @@ private static IServiceProvider CreateProvider(IServiceCollection services) { var containerBuilder = new ContainerBuilder(); containerBuilder.Populate(services); - /// Initialize dependencies for the . There is some additional complexity here /// because the implementations require ambiguous types (such as a and a /// which there may be more than one configuration of). @@ -309,6 +321,7 @@ private static IServiceProvider CreateProvider(IServiceCollection services) ConfigurePackageSigningValidator(containerBuilder); ConfigurePackageCertificatesValidator(containerBuilder); + ConfigurePackageCompatibilityValidator(containerBuilder); return new AutofacServiceProvider(containerBuilder.Build()); } @@ -345,6 +358,56 @@ private static void ConfigurePackageSigningValidator(ContainerBuilder builder) .As(); } + + private static void ConfigurePackageCompatibilityValidator(ContainerBuilder builder) + { + + // Configure the validator state service for the package compatibility validator. + builder + .RegisterType() + .WithParameter( + (pi, ctx) => pi.ParameterType == typeof(Type), + (pi, ctx) => typeof(PackageCompatibilityValidator)) + .Keyed(PackageCompatibilityBindingKey); + + // Configure the package compatibility service + builder + .RegisterType() + .As(); + + //builder + // .Register(c => + // { + // var configuration = c.Resolve>().Value.ServiceBus; + // return new TopicClientWrapper(configuration.ConnectionString, configuration.TopicPath); + // }) + // .Keyed(PackageCompatibilityBindingKey); + + //// Configure the package compatibility verification enqueuer. + //builder + // .RegisterType() + // .WithParameter(new ResolvedParameter( + // (pi, ctx) => pi.ParameterType == typeof(ITopicClient), + // (pi, ctx) => ctx.ResolveKeyed(PackageVerificationTopicClientBindingKey))) + // .WithParameter(new ResolvedParameter( + // (pi, ctx) => pi.ParameterType == typeof(IBrokeredMessageSerializer), + // (pi, ctx) => ctx.Resolve() + // )) + // .As(); + + //builder + // .RegisterType() + // .WithKeyedParameter(typeof(ITopicClient), PackageCompatibilityBindingKey) + // .As(); + + // Configure the package compatibility validator + builder + .RegisterType() + .WithKeyedParameter(typeof(IValidatorStateService), PackageCompatibilityBindingKey) + .As(); + + } + private static void ConfigurePackageCertificatesValidator(ContainerBuilder builder) { // Configure the validator state service for the package certificates validator. diff --git a/src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj b/src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj index 526832518..14cf84741 100644 --- a/src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj +++ b/src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj @@ -60,11 +60,19 @@ +<<<<<<< HEAD +======= + + + + +>>>>>>> add package compatibility skeleton + @@ -120,11 +128,16 @@ {2539ddf3-0cc5-4a03-b5f9-39b47744a7bd} Validation.Common + + {3958ECDD-DE42-401B-8BC6-553E49F2D42A} + Validation.PackageCompatibility.Core + {91C060DA-736F-4DA9-A57F-CB3AC0E6CB10} Validation.PackageSigning.Core + ..\..\build diff --git a/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/IPackageCompatibilityVerificationEnqueuer.cs b/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/IPackageCompatibilityVerificationEnqueuer.cs new file mode 100644 index 000000000..9b983d682 --- /dev/null +++ b/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/IPackageCompatibilityVerificationEnqueuer.cs @@ -0,0 +1,23 @@ +// 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 System.Threading.Tasks; + +namespace NuGet.Services.Validation.PackageCompatibility +{ + /// + /// Kicks off package compatibility verification. + /// + public interface IPackageCompatibilityVerificationEnqueuer + { + /// + /// Kicks off the package verification process for the given request. Verification will begin when the + /// has a that matches the + /// 's validationId. Once verification completes, the 's + /// State will be updated to "Succeeded" or "Failed". + /// + /// The request that details the package to be verified. + /// A task that will complete when the verification process has been queued. + Task EnqueueVerificationAsync(IValidationRequest request); + } +} diff --git a/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityConfiguration.cs b/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityConfiguration.cs new file mode 100644 index 000000000..36829903b --- /dev/null +++ b/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityConfiguration.cs @@ -0,0 +1,19 @@ +// 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.Jobs.Configuration; + +namespace NuGet.Services.Validation.Orchestrator.PackageCompatibility +{ + /// + /// Configuration for initializing the . + /// + public class PackageCompatibilityConfiguration + { + /// + /// The Service Bus configuration used to enqueue package compatibility validations. + /// + public ServiceBusConfiguration ServiceBus { get; set; } + } + +} + diff --git a/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityValidator.cs b/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityValidator.cs new file mode 100644 index 000000000..310866d71 --- /dev/null +++ b/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityValidator.cs @@ -0,0 +1,96 @@ +// 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 System; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using NuGet.Jobs.Validation.PackageSigning.Storage; +using Validation.PackageCompatibility.Core.Messages; +using Validation.PackageCompatibility.Core.Storage; + +namespace NuGet.Services.Validation.PackageCompatibility +{ + /// + /// Configuration for initializing the . + /// + public class PackageCompatibilityValidator : IValidator + { + private IValidatorStateService _validatorStateService; + private IPackageCompatibilityService _packageCompatibilityService; + private readonly ILogger _logger; + + private readonly HttpClient _httpClient; + + public PackageCompatibilityValidator( + IValidatorStateService validatorStateService, + IPackageCompatibilityService packageCompatibilityService, + HttpClient httpClient, + ILogger logger) + { + _validatorStateService = validatorStateService; + _packageCompatibilityService = packageCompatibilityService; + _httpClient = httpClient; + _logger = logger; + } + + public async Task GetResultAsync(IValidationRequest request) + { + var validatorStatus = await _validatorStateService.GetStatusAsync(request); + + return validatorStatus.ToValidationResult(); + } + + public async Task StartValidationAsync(IValidationRequest request) + { + var validatorStatus = await _validatorStateService.GetStatusAsync(request); + + if (validatorStatus.State != ValidationStatus.NotStarted) + { + _logger.LogWarning( + "Package Compatibility validation with validationId {ValidationId} ({PackageId} {PackageVersion}) has already started.", + request.ValidationId, + request.PackageId, + request.PackageVersion); + + 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); + + validatorStatus.State = ValidationStatus.Succeeded; + await _validatorStateService.SaveStatusAsync(validatorStatus); + + return validatorStatus.ToValidationResult(); + } + + private async Task Validate(PackageCompatibilityValidationMessage message, CancellationToken cancellationToken) + { + // Validate package // TODO NK - Use the utility to download packages + //using (var packageStream = await PackageValidationUtility.DownloadPackageAsync(_httpClient, message.NupkgUri, _logger, cancellationToken)) + //using (var package = new PackageArchiveReader(packageStream)) + //{ + // var warnings = new List(); + + // foreach(var rule in Packaging.Rules.DefaultPackageRuleSet.Rules) + // { + // warnings.AddRange(rule.Validate(package)); + // } + + // await _packageCompatibilityService.SetPackageCompatibilityState(message.ValidationId, warnings); + //} + + } + } +} diff --git a/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityVerificationEnqueuer.cs b/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityVerificationEnqueuer.cs new file mode 100644 index 000000000..9f071d491 --- /dev/null +++ b/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityVerificationEnqueuer.cs @@ -0,0 +1,43 @@ +// 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 System; +using System.Threading.Tasks; +using NuGet.Services.ServiceBus; +using Validation.PackageCompatibility.Core.Messages; + +namespace NuGet.Services.Validation.PackageCompatibility +{ + /// + /// Kicks off package compatibility verifications. + /// + public class PackageCompatibilityVerificationEnqueuer : IPackageCompatibilityVerificationEnqueuer + { + private readonly ITopicClient _topicClient; + private readonly IBrokeredMessageSerializer _packageCompatibilityVerificationSerializer; + + public PackageCompatibilityVerificationEnqueuer( + ITopicClient topicClient, + IBrokeredMessageSerializer packageCompatibilityVerificationSerializer) + { + _topicClient = topicClient ?? throw new ArgumentNullException(nameof(topicClient)); + _packageCompatibilityVerificationSerializer = packageCompatibilityVerificationSerializer ?? throw new ArgumentNullException(nameof(packageCompatibilityVerificationSerializer)); + } + + /// + /// Kicks off the package verification process for the given request. Verification will begin when the + /// has a that matches the + /// 's validationId. Once verification completes, the 's + /// State will be updated to "Succeeded" or "Failed". + /// + /// The request that details the package to be verified. + /// A task that will complete when the verification process has been queued. + public Task EnqueueVerificationAsync(IValidationRequest request) + { + var brokeredMessage = _packageCompatibilityVerificationSerializer.Serialize( + new PackageCompatibilityValidationMessage(request.PackageId, request.PackageVersion, new Uri(request.NupkgUrl), request.ValidationId)); + + return _topicClient.SendAsync(brokeredMessage); + } + } +} diff --git a/src/NuGet.Services.Validation.Orchestrator/settings.json b/src/NuGet.Services.Validation.Orchestrator/settings.json index 22c9c2f70..80d6bb3ac 100644 --- a/src/NuGet.Services.Validation.Orchestrator/settings.json +++ b/src/NuGet.Services.Validation.Orchestrator/settings.json @@ -55,6 +55,13 @@ "SubscriptionName": "" } }, + "PackageCompatibility": { + "ServiceBus": { + "ConnectionString": "servicebus string", + "TopicPath": "validate-compatibility", + "SubscriptionName": "validate-compatibility" + } + }, "RunnerConfiguration": { "ProcessRecycleInterval": "1:00:00:00", "ShutdownWaitInterval": "00:01:00" diff --git a/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.csproj b/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.csproj index dc52dedd9..dac3f988b 100644 --- a/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.csproj +++ b/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.csproj @@ -96,11 +96,11 @@ ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - - ..\..\packages\NuGet.Services.Configuration.2.2.3\lib\net452\NuGet.Services.Configuration.dll + + ..\..\packages\NuGet.Services.Configuration.2.3.0\lib\net452\NuGet.Services.Configuration.dll - - ..\..\packages\NuGet.Services.KeyVault.2.2.3\lib\net45\NuGet.Services.KeyVault.dll + + ..\..\packages\NuGet.Services.KeyVault.2.3.0\lib\net45\NuGet.Services.KeyVault.dll diff --git a/src/NuGet.SupportRequests.Notifications/app.config b/src/NuGet.SupportRequests.Notifications/app.config index 518a160f1..b229ccea1 100644 --- a/src/NuGet.SupportRequests.Notifications/app.config +++ b/src/NuGet.SupportRequests.Notifications/app.config @@ -24,7 +24,7 @@ - + diff --git a/src/NuGet.SupportRequests.Notifications/packages.config b/src/NuGet.SupportRequests.Notifications/packages.config index bd4e51b98..6f4e9e256 100644 --- a/src/NuGet.SupportRequests.Notifications/packages.config +++ b/src/NuGet.SupportRequests.Notifications/packages.config @@ -19,8 +19,8 @@ - - + + diff --git a/src/NuGetCDNRedirect/NuGetCDNRedirect.csproj b/src/NuGetCDNRedirect/NuGetCDNRedirect.csproj index d8277d141..fc1085b73 100644 --- a/src/NuGetCDNRedirect/NuGetCDNRedirect.csproj +++ b/src/NuGetCDNRedirect/NuGetCDNRedirect.csproj @@ -86,8 +86,8 @@ ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - - ..\..\packages\NuGet.Services.Logging.2.2.3\lib\net452\NuGet.Services.Logging.dll + + ..\..\packages\NuGet.Services.Logging.2.3.0\lib\net452\NuGet.Services.Logging.dll ..\..\packages\Serilog.2.0.0\lib\net45\Serilog.dll diff --git a/src/NuGetCDNRedirect/packages.config b/src/NuGetCDNRedirect/packages.config index 0f1a8926c..5e7390fb1 100644 --- a/src/NuGetCDNRedirect/packages.config +++ b/src/NuGetCDNRedirect/packages.config @@ -20,7 +20,7 @@ - + diff --git a/src/Search.GenerateAuxiliaryData/App.config b/src/Search.GenerateAuxiliaryData/App.config index 3e840a1a3..bc6b153ca 100644 --- a/src/Search.GenerateAuxiliaryData/App.config +++ b/src/Search.GenerateAuxiliaryData/App.config @@ -35,7 +35,7 @@ - + diff --git a/src/Stats.AggregateCdnDownloadsInGallery/App.config b/src/Stats.AggregateCdnDownloadsInGallery/App.config index 7d12a6d35..272e8fbbb 100644 --- a/src/Stats.AggregateCdnDownloadsInGallery/App.config +++ b/src/Stats.AggregateCdnDownloadsInGallery/App.config @@ -35,7 +35,7 @@ - + diff --git a/src/Stats.CollectAzureCdnLogs/App.config b/src/Stats.CollectAzureCdnLogs/App.config index 531b6132f..90132dfb5 100644 --- a/src/Stats.CollectAzureCdnLogs/App.config +++ b/src/Stats.CollectAzureCdnLogs/App.config @@ -52,7 +52,7 @@ - + diff --git a/src/Stats.CreateAzureCdnWarehouseReports/App.config b/src/Stats.CreateAzureCdnWarehouseReports/App.config index 36efa1e87..e45a8fe14 100644 --- a/src/Stats.CreateAzureCdnWarehouseReports/App.config +++ b/src/Stats.CreateAzureCdnWarehouseReports/App.config @@ -47,7 +47,7 @@ - + diff --git a/src/Stats.CreateAzureCdnWarehouseReports/Stats.CreateAzureCdnWarehouseReports.csproj b/src/Stats.CreateAzureCdnWarehouseReports/Stats.CreateAzureCdnWarehouseReports.csproj index 646cc1652..58591f277 100644 --- a/src/Stats.CreateAzureCdnWarehouseReports/Stats.CreateAzureCdnWarehouseReports.csproj +++ b/src/Stats.CreateAzureCdnWarehouseReports/Stats.CreateAzureCdnWarehouseReports.csproj @@ -80,8 +80,8 @@ ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - - ..\..\packages\NuGet.Services.Logging.2.2.3\lib\net452\NuGet.Services.Logging.dll + + ..\..\packages\NuGet.Services.Logging.2.3.0\lib\net452\NuGet.Services.Logging.dll ..\..\packages\NuGet.Versioning.4.3.0-preview1-2524\lib\net45\NuGet.Versioning.dll diff --git a/src/Stats.CreateAzureCdnWarehouseReports/packages.config b/src/Stats.CreateAzureCdnWarehouseReports/packages.config index f013b1f20..b0f55dc1f 100644 --- a/src/Stats.CreateAzureCdnWarehouseReports/packages.config +++ b/src/Stats.CreateAzureCdnWarehouseReports/packages.config @@ -15,7 +15,7 @@ - + diff --git a/src/Stats.ImportAzureCdnStatistics/App.config b/src/Stats.ImportAzureCdnStatistics/App.config index 20005b32d..5d695d1f6 100644 --- a/src/Stats.ImportAzureCdnStatistics/App.config +++ b/src/Stats.ImportAzureCdnStatistics/App.config @@ -43,7 +43,7 @@ - + diff --git a/src/Stats.ImportAzureCdnStatistics/Stats.ImportAzureCdnStatistics.csproj b/src/Stats.ImportAzureCdnStatistics/Stats.ImportAzureCdnStatistics.csproj index 0567b6e66..d6fa89883 100644 --- a/src/Stats.ImportAzureCdnStatistics/Stats.ImportAzureCdnStatistics.csproj +++ b/src/Stats.ImportAzureCdnStatistics/Stats.ImportAzureCdnStatistics.csproj @@ -83,8 +83,8 @@ ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - - ..\..\packages\NuGet.Services.Logging.2.2.3\lib\net452\NuGet.Services.Logging.dll + + ..\..\packages\NuGet.Services.Logging.2.3.0\lib\net452\NuGet.Services.Logging.dll ..\..\packages\NuGet.Versioning.4.3.0-preview1-2524\lib\net45\NuGet.Versioning.dll diff --git a/src/Stats.ImportAzureCdnStatistics/packages.config b/src/Stats.ImportAzureCdnStatistics/packages.config index ff65ae1b2..9fbdd2f32 100644 --- a/src/Stats.ImportAzureCdnStatistics/packages.config +++ b/src/Stats.ImportAzureCdnStatistics/packages.config @@ -15,7 +15,7 @@ - + diff --git a/src/Stats.RefreshClientDimension/App.config b/src/Stats.RefreshClientDimension/App.config index 4a9dfc692..f92447b67 100644 --- a/src/Stats.RefreshClientDimension/App.config +++ b/src/Stats.RefreshClientDimension/App.config @@ -35,7 +35,7 @@ - + diff --git a/src/Stats.RollUpDownloadFacts/App.config b/src/Stats.RollUpDownloadFacts/App.config index cfa6f76c3..83ae2269d 100644 --- a/src/Stats.RollUpDownloadFacts/App.config +++ b/src/Stats.RollUpDownloadFacts/App.config @@ -43,7 +43,7 @@ - + diff --git a/src/Stats.RollUpDownloadFacts/Stats.RollUpDownloadFacts.csproj b/src/Stats.RollUpDownloadFacts/Stats.RollUpDownloadFacts.csproj index 015e40a11..39457b9dd 100644 --- a/src/Stats.RollUpDownloadFacts/Stats.RollUpDownloadFacts.csproj +++ b/src/Stats.RollUpDownloadFacts/Stats.RollUpDownloadFacts.csproj @@ -59,8 +59,8 @@ ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - - ..\..\packages\NuGet.Services.Logging.2.2.3\lib\net452\NuGet.Services.Logging.dll + + ..\..\packages\NuGet.Services.Logging.2.3.0\lib\net452\NuGet.Services.Logging.dll ..\..\packages\Serilog.2.2.1\lib\net45\Serilog.dll diff --git a/src/Stats.RollUpDownloadFacts/packages.config b/src/Stats.RollUpDownloadFacts/packages.config index 5561124a9..983bf97ef 100644 --- a/src/Stats.RollUpDownloadFacts/packages.config +++ b/src/Stats.RollUpDownloadFacts/packages.config @@ -9,7 +9,7 @@ - + diff --git a/src/UpdateLicenseReports/App.config b/src/UpdateLicenseReports/App.config index 9dcee3ac3..44d83fe73 100644 --- a/src/UpdateLicenseReports/App.config +++ b/src/UpdateLicenseReports/App.config @@ -35,7 +35,7 @@ - + diff --git a/src/Validation.Callback.Vcs/Web.config b/src/Validation.Callback.Vcs/Web.config index cd64b34a7..0693c43b4 100644 --- a/src/Validation.Callback.Vcs/Web.config +++ b/src/Validation.Callback.Vcs/Web.config @@ -70,7 +70,7 @@ - + diff --git a/src/Validation.Common/Validation.Common.csproj b/src/Validation.Common/Validation.Common.csproj index c8a5e8c79..ab8bdf32a 100644 --- a/src/Validation.Common/Validation.Common.csproj +++ b/src/Validation.Common/Validation.Common.csproj @@ -105,11 +105,11 @@ ..\..\packages\NuGet.ApplicationInsights.Owin.4.1.0\lib\net452\NuGet.ApplicationInsights.Owin.dll - - ..\..\packages\NuGet.Services.KeyVault.2.13.0\lib\net45\NuGet.Services.KeyVault.dll + + ..\..\packages\NuGet.Services.KeyVault.2.3.0\lib\net45\NuGet.Services.KeyVault.dll - - ..\..\packages\NuGet.Services.Logging.2.13.0\lib\net452\NuGet.Services.Logging.dll + + ..\..\packages\NuGet.Services.Logging.2.3.0\lib\net452\NuGet.Services.Logging.dll ..\..\packages\NuGet.Services.VirusScanning.Vcs.3.2.0\lib\net452\NuGet.Services.VirusScanning.Core.dll diff --git a/src/Validation.Common/app.config b/src/Validation.Common/app.config index b13a21e9e..45066e8a2 100644 --- a/src/Validation.Common/app.config +++ b/src/Validation.Common/app.config @@ -4,7 +4,7 @@ - + @@ -40,7 +40,7 @@ - + diff --git a/src/Validation.Common/packages.config b/src/Validation.Common/packages.config index b31ab07fa..4987c7300 100644 --- a/src/Validation.Common/packages.config +++ b/src/Validation.Common/packages.config @@ -22,8 +22,8 @@ - - + + diff --git a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/App.config b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/App.config new file mode 100644 index 000000000..731f6de6c --- /dev/null +++ b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/IPackageCompatibilityPackageReferenceValidator.cs b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/IPackageCompatibilityPackageReferenceValidator.cs new file mode 100644 index 000000000..a28cf96cf --- /dev/null +++ b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/IPackageCompatibilityPackageReferenceValidator.cs @@ -0,0 +1,19 @@ +// 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.Packaging; +using System.Threading; +using System.Threading.Tasks; +using Validation.PackageCompatibility.Core.Messages; + +namespace Validation.PackageAuthoring.ValidatePackageReferenceCompatibility +{ + interface IPackageCompatibilityPackageReferenceValidator + { + Task ValidateAsync( + int packageKey, + PackageArchiveReader package, + PackageCompatibilityValidationMessage message, + CancellationToken cancellationToken); + } +} diff --git a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Job.cs b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Job.cs new file mode 100644 index 000000000..cba994dbe --- /dev/null +++ b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Job.cs @@ -0,0 +1,138 @@ +// 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 System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NuGet.Jobs; +using NuGet.Jobs.Configuration; +using NuGet.Services.Configuration; +using NuGet.Services.KeyVault; +using NuGet.Services.ServiceBus; +using Validation.PackageCompatibility.Core.Messages; + +namespace Validation.PackageCompatibility.PackageReferenceValidation +{ + internal class Job : JobBase + { + /// + /// The argument this job uses to determine the configuration file's path. + /// + private const string ConfigurationArgument = "Configuration"; + + private const string ValidationDbConfigurationSectionName = "ValidationDb"; + private const string ServiceBusConfigurationSectionName = "ServiceBus"; + + /// + /// The maximum time that a KeyVault secret will be cached for. + /// + private static readonly TimeSpan KeyVaultSecretCachingTimeout = TimeSpan.FromDays(1); + + /// + /// The maximum amount of time that graceful shutdown can take before the job will + /// forcefully end itself. + /// + private static readonly TimeSpan MaxShutdownTime = TimeSpan.FromMinutes(1); + + /// + /// The configured service provider, used to instiate the services this job depends on. + /// + private IServiceProvider _serviceProvider; + + public override void Init(IDictionary jobArgsDictionary) + { + var configurationFilename = JobConfigurationManager.GetArgument(jobArgsDictionary, ConfigurationArgument); + _serviceProvider = GetServiceProvider(GetConfigurationRoot(configurationFilename)); + + } + + public async override Task Run() + { + // I am understanding this correctly? + // All these run get triggered on a validation message? + // If that true, this message would need serialization code, sent by someone etc. + var processor = _serviceProvider.GetRequiredService>(); + + processor.Start(); + + // Wait a day, and then shutdown this process so that it is restarted. + await Task.Delay(TimeSpan.FromDays(1)); + + if (!await processor.ShutdownAsync(MaxShutdownTime)) + { + Logger.LogWarning( + "Failed to gracefully shutdown Service Bus subscription processor. {MessagesInProgress} messages left", + processor.NumberOfMessagesInProgress); + } + } + + private IServiceProvider GetServiceProvider(IConfigurationRoot configurationRoot) + { + var services = new ServiceCollection(); + + ConfigureLibraries(services); + ConfigureJobServices(services, configurationRoot); + + return CreateProvider(services); + } + + // TODO NK - Why are these configuration root methods all the same, yet not common? DRY + // This loooks pretty generic + private IConfigurationRoot GetConfigurationRoot(string configurationFilename) + { + Logger.LogInformation("Using the {ConfigurationFilename} configuration file", configurationFilename); + + var builder = new ConfigurationBuilder() + .SetBasePath(Environment.CurrentDirectory) + .AddJsonFile(configurationFilename, optional: false, reloadOnChange: true); + + var uninjectedConfiguration = builder.Build(); + + var secretReaderFactory = new ConfigurationRootSecretReaderFactory(uninjectedConfiguration); + var cachingSecretReaderFactory = new CachingSecretReaderFactory(secretReaderFactory, KeyVaultSecretCachingTimeout); + var secretInjector = cachingSecretReaderFactory.CreateSecretInjector(cachingSecretReaderFactory.CreateSecretReader()); + + builder = new ConfigurationBuilder() + .SetBasePath(Environment.CurrentDirectory) + .AddInjectedJsonFile(configurationFilename, secretInjector); + + return builder.Build(); + } + + private void ConfigureLibraries(IServiceCollection services) + { + // Use the custom NonCachingOptionsSnapshot so that KeyVault secret injection works properly. + //services.Add(ServiceDescriptor.Scoped(typeof(IOptionsSnapshot<>), typeof(NonCachingOptionsSnapshot<>))); + //services.AddSingleton(LoggerFactory); + //services.AddLogging(); + } + + private void ConfigureJobServices(IServiceCollection services, IConfigurationRoot configurationRoot) + { + services.Configure(configurationRoot.GetSection(ValidationDbConfigurationSectionName)); + services.Configure(configurationRoot.GetSection(ServiceBusConfigurationSectionName)); + + //services.AddScoped(p => + //{ + // var config = p.GetRequiredService>().Value; + + // return new ValidationEntitiesContext(config.ConnectionString); + //}); + + //services.AddTransient(p => + //{ + // var config = p.GetRequiredService>().Value; + + // return new SubscriptionClientWrapper(config.ConnectionString, config.TopicPath, config.SubscriptionName); + //}); + } + + private static IServiceProvider CreateProvider(IServiceCollection services) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityPackageReferenceValidator.cs b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityPackageReferenceValidator.cs new file mode 100644 index 000000000..4762226ae --- /dev/null +++ b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityPackageReferenceValidator.cs @@ -0,0 +1,48 @@ +// 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 System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using NuGet.Packaging; +using NuGet.Services.Validation; +using Validation.PackageCompatibility.Core.Messages; +using NuGet.Services.Validation.Issues; + +namespace Validation.PackageAuthoring.ValidatePackageReferenceCompatibility +{ + public class PackageCompatibilityPackageReferenceValidator : IPackageCompatibilityPackageReferenceValidator + { + public async Task ValidateAsync(int packageKey, PackageArchiveReader package, PackageCompatibilityValidationMessage message, CancellationToken cancellationToken) + { + try + { + if (message.PackageId.Equals("newtosoft.json", StringComparison.InvariantCultureIgnoreCase)){ + var issue = new ClientPackageCompatibilityVerificationIssue("NU1500", "This package is invalid, because we said so."); + return AcceptWithIssues(packageKey, message, new IValidationIssue[] { issue }); + } + } + catch(Exception e) + { + var issue = new ClientPackageCompatibilityVerificationIssue("NU9999", e.Message); + return AcceptWithIssues(packageKey, message, new IValidationIssue[] { issue }); + } + + return AcceptWithoutErrorsAsync(packageKey, message); + } + + private PackageCompatibilityValidatorResult AcceptWithIssues(int packageKey, + PackageCompatibilityValidationMessage message, IReadOnlyList issues) + { + return new PackageCompatibilityValidatorResult(ValidationStatus.Succeeded, issues); + } + + private PackageCompatibilityValidatorResult AcceptWithoutErrorsAsync( + int packageKey, + PackageCompatibilityValidationMessage message) + { + return new PackageCompatibilityValidatorResult(ValidationStatus.Succeeded); + } + } +} diff --git a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityValidationMessageHandler.cs b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityValidationMessageHandler.cs new file mode 100644 index 000000000..a98e97a5b --- /dev/null +++ b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityValidationMessageHandler.cs @@ -0,0 +1,29 @@ +// 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 Microsoft.Extensions.Logging; +using NuGet.Jobs.Validation.PackageSigning.Storage; +using NuGet.Services.ServiceBus; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using Validation.PackageCompatibility.Core.Messages; + +namespace Validation.PackageAuthoring.ValidatePackageReferenceCompatibility +{ + class PackageCompatibilityValidationMessageHandler : IMessageHandler + { + private readonly HttpClient _httpClient; + private readonly IValidatorStateService _validatorStateService; + private readonly IPackageCompatibilityPackageReferenceValidator _packageCompatibilityPackageReferenceValidator; + private readonly ILogger _logger; + + public Task HandleAsync(PackageCompatibilityValidationMessage message) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityValidatorResult.cs b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityValidatorResult.cs new file mode 100644 index 000000000..aa9b868c1 --- /dev/null +++ b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityValidatorResult.cs @@ -0,0 +1,35 @@ +// 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 System; +using System.Collections.Generic; +using System.Linq; +using NuGet.Services.Validation; + + +namespace Validation.PackageAuthoring.ValidatePackageReferenceCompatibility +{ + public class PackageCompatibilityValidatorResult + { + public PackageCompatibilityValidatorResult(ValidationStatus state) + : this(state, new IValidationIssue[0]) + { + } + + public PackageCompatibilityValidatorResult(ValidationStatus state, IReadOnlyList issues) + { + State = state; + Issues = issues ?? throw new ArgumentNullException(nameof(issues)); + + if (state != ValidationStatus.Failed + && state != ValidationStatus.Succeeded + && issues.Any()) + { + throw new ArgumentException("Issues are only allowed for terminal states.", nameof(issues)); + } + } + + public ValidationStatus State { get; } + public IReadOnlyList Issues { get; } + } +} \ No newline at end of file diff --git a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Program.cs b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Program.cs new file mode 100644 index 000000000..2222ec457 --- /dev/null +++ b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Program.cs @@ -0,0 +1,16 @@ +// 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.Jobs; + +namespace Validation.PackageCompatibility.PackageReferenceValidation +{ + class Program + { + static void Main(string[] args) + { + var job = new Job(); + JobRunner.Run(job, args).GetAwaiter().GetResult(); + } + } +} diff --git a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Properties/AssemblyInfo.cs b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..1770e0ac8 --- /dev/null +++ b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Validation.PackageAuthoring.ValidatePackageReferenceCompatibility")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("HP Inc.")] +[assembly: AssemblyProduct("Validation.PackageAuthoring.ValidatePackageReferenceCompatibility")] +[assembly: AssemblyCopyright("Copyright © HP Inc. 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("1b16df51-90bb-4ac3-b269-8ade5fb4fb0b")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Validation.PackageCompatibility.PackageReferenceValidation.csproj b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Validation.PackageCompatibility.PackageReferenceValidation.csproj new file mode 100644 index 000000000..bb9df9ca8 --- /dev/null +++ b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Validation.PackageCompatibility.PackageReferenceValidation.csproj @@ -0,0 +1,129 @@ + + + + + Debug + AnyCPU + {1B16DF51-90BB-4AC3-B269-8ADE5FB4FB0B} + Exe + Validation.PackageAuthoring.ValidatePackageReferenceCompatibility + Validation.PackageAuthoring.ValidatePackageReferenceCompatibility + v4.6 + 512 + true + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + 4.6.2 + + + 4.2.0 + + + 2.2.0 + + + 1.1.2 + + + 1.1.2 + + + 1.1.2 + + + 1.1.1 + + + 1.1.2 + + + 2.3.0 + + + 2.3.0 + + + 2.3.0 + + + 2.3.0 + + + 4.3.3 + + + + + {b4b7564a-965b-447b-927f-6749e2c08880} + Validation.PackageSigning.Core.Tests + + + {4b4b1efb-8f33-42e6-b79f-54e7f3293d31} + NuGet.Jobs.Common + + + {e6d094fb-9068-4578-b176-116f97e7506b} + NuGet.Services.Validation.Orchestrator + + + {fa87d075-a934-4443-8d0b-5db32640b6d7} + Validation.Common.Job + + + {2539DDF3-0CC5-4A03-B5F9-39B47744A7BD} + Validation.Common + + + {3958ecdd-de42-401b-8bc6-553e49f2d42a} + Validation.PackageCompatibility.Core + + + {91C060DA-736F-4DA9-A57F-CB3AC0E6CB10} + Validation.PackageSigning.Core + + + + \ No newline at end of file diff --git a/src/Validation.PackageCompatibility.Core/IPackageCompatibilityService.cs b/src/Validation.PackageCompatibility.Core/IPackageCompatibilityService.cs new file mode 100644 index 000000000..f057ef8cf --- /dev/null +++ b/src/Validation.PackageCompatibility.Core/IPackageCompatibilityService.cs @@ -0,0 +1,18 @@ +// 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.Common; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Validation.PackageCompatibility.Core.Storage +{ + public interface IPackageCompatibilityService + { + Task SetPackageCompatibilityState( + Guid validationId, + IEnumerable messages); + } +} diff --git a/src/Validation.PackageCompatibility.Core/Messages/PackageCompatibilityValidationMessage.cs b/src/Validation.PackageCompatibility.Core/Messages/PackageCompatibilityValidationMessage.cs new file mode 100644 index 000000000..9e7765065 --- /dev/null +++ b/src/Validation.PackageCompatibility.Core/Messages/PackageCompatibilityValidationMessage.cs @@ -0,0 +1,23 @@ +// 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 System; + +namespace Validation.PackageCompatibility.Core.Messages +{ + public class PackageCompatibilityValidationMessage + { + public PackageCompatibilityValidationMessage(string packageId, string packageVersion, Uri nupkgUri, Guid validationId) + { + PackageId = packageId; + PackageVersion = packageVersion; + NupkgUri = nupkgUri; + ValidationId = validationId; + } + + public string PackageId { get; } + public string PackageVersion { get; } + public Uri NupkgUri { get; } + public Guid ValidationId { get; } + } +} diff --git a/src/Validation.PackageCompatibility.Core/Messages/PackageCompatibilityValidationMessageSerializer.cs b/src/Validation.PackageCompatibility.Core/Messages/PackageCompatibilityValidationMessageSerializer.cs new file mode 100644 index 000000000..706197b17 --- /dev/null +++ b/src/Validation.PackageCompatibility.Core/Messages/PackageCompatibilityValidationMessageSerializer.cs @@ -0,0 +1,47 @@ +// 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 new file mode 100644 index 000000000..0dc6f01d5 --- /dev/null +++ b/src/Validation.PackageCompatibility.Core/PackageCompatibilityService.cs @@ -0,0 +1,50 @@ +// 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 Microsoft.Extensions.Logging; +using NuGet.Common; +using NuGet.Services.Validation; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Validation.PackageCompatibility.Core.Storage +{ + public class PackageCompatibilityService : IPackageCompatibilityService + { + private readonly IValidationEntitiesContext _validationContext; + private readonly ILogger _logger; + + public PackageCompatibilityService( + IValidationEntitiesContext validationContext, + ILogger logger) + { + _validationContext = validationContext ?? throw new ArgumentNullException(nameof(validationContext)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + } + + public async Task SetPackageCompatibilityState( + Guid validationId, + IEnumerable messages) + { + foreach (var log in messages) + { + _validationContext.PackageCompatibilityIssues.Add( + new PackageCompatibilityIssue() + { + ClientIssueCode = log.Code.ToString(), + Message = log.Message, + PackageValidationKey = validationId + } + ); + } + try { + await _validationContext.SaveChangesAsync(); // TODO - my savings needs to catch database consistency + } catch(Exception e) + { + _logger.LogWarning("trouble saving changes async - {0}", e.Message); + } + } + } +} diff --git a/src/Validation.PackageCompatibility.Core/Properties/AssemblyInfo.cs b/src/Validation.PackageCompatibility.Core/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..3cd10cd44 --- /dev/null +++ b/src/Validation.PackageCompatibility.Core/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Validation.PackageCompatibility.Core")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("HP Inc.")] +[assembly: AssemblyProduct("Validation.PackageCompatibility.Core")] +[assembly: AssemblyCopyright("Copyright © HP Inc. 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("3958ecdd-de42-401b-8bc6-553e49f2d42a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Validation.PackageCompatibility.Core/Storage/IPackageCompatibilityStateService.cs b/src/Validation.PackageCompatibility.Core/Storage/IPackageCompatibilityStateService.cs new file mode 100644 index 000000000..ef8208158 --- /dev/null +++ b/src/Validation.PackageCompatibility.Core/Storage/IPackageCompatibilityStateService.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Validation.PackageCompatibility.Core.Storage +{ + interface IPackageCompatibilityService + { + } +} diff --git a/src/Validation.PackageCompatibility.Core/Storage/PackageCompatibilityStateService.cs b/src/Validation.PackageCompatibility.Core/Storage/PackageCompatibilityStateService.cs new file mode 100644 index 000000000..b94b34ad1 --- /dev/null +++ b/src/Validation.PackageCompatibility.Core/Storage/PackageCompatibilityStateService.cs @@ -0,0 +1,58 @@ +using Microsoft.Extensions.Logging; +using NuGet.Common; +using NuGet.Services.Validation; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Validation.PackageCompatibility.Core.Storage +{ + public class PackageCompatibilityStateService : IPackageCompatibilityService + { + private readonly IValidationEntitiesContext _validationContext; + private readonly ILogger _logger; + + public PackageCompatibilityStateService( + IValidationEntitiesContext validationContext, + ILogger logger) + { + _validationContext = validationContext ?? throw new ArgumentNullException(nameof(validationContext)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + } + + public async Task SetPackageCompatibilityState( + Guid validationId, + IReadOnlyList messages) + { + + foreach (var log in messages) + { + warnings.Add( + new PackageCompatibilityIssue() + { + // Key - will the DB apply is + ClientIssueCode = log.Code.ToString(), + Data = log.Message, + PackageValidationKey = message.ValidationId + } + ); + + if (string.IsNullOrEmpty(packageId)) + { + throw new ArgumentException(nameof(packageId)); + } + if (string.IsNullOrEmpty(packageVersion)) + { + throw new ArgumentException(nameof(packageVersion)); + } + + // It is possible this package has already been validated. If so, the package's state will already exist + // in the database. Updates to this state should only be requested on explicit revalidation gestures. However, + // this invariant may be broken due to message duplication. + await _validationContext.PackageCom.FirstOrDefaultAsync(s => s.PackageKey == packageKey); +{ } + } + } +} diff --git a/src/Validation.PackageCompatibility.Core/Validation.PackageCompatibility.Core.csproj b/src/Validation.PackageCompatibility.Core/Validation.PackageCompatibility.Core.csproj new file mode 100644 index 000000000..8883a12fe --- /dev/null +++ b/src/Validation.PackageCompatibility.Core/Validation.PackageCompatibility.Core.csproj @@ -0,0 +1,67 @@ + + + + + Debug + AnyCPU + {3958ECDD-DE42-401B-8BC6-553E49F2D42A} + Library + Properties + Validation.PackageCompatibility.Core + Validation.PackageCompatibility.Core + v4.6 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + 2.3.0 + + + 2.3.0 + + + 2.3.0 + + + 7.1.2 + + + 4.7.0-preview1-4929 + + + + \ No newline at end of file diff --git a/src/Validation.PackageSigning.ExtractAndValidateSignature/Validation.PackageSigning.ExtractAndValidateSignature.csproj b/src/Validation.PackageSigning.ExtractAndValidateSignature/Validation.PackageSigning.ExtractAndValidateSignature.csproj index f172679ef..72e05e9c9 100644 --- a/src/Validation.PackageSigning.ExtractAndValidateSignature/Validation.PackageSigning.ExtractAndValidateSignature.csproj +++ b/src/Validation.PackageSigning.ExtractAndValidateSignature/Validation.PackageSigning.ExtractAndValidateSignature.csproj @@ -85,6 +85,11 @@ Validation.PackageSigning.Core + + + 4.7.0-preview1-4886 + + ..\..\build diff --git a/src/Validation.Runner/App.config b/src/Validation.Runner/App.config index 09d428570..660ca9bdd 100644 --- a/src/Validation.Runner/App.config +++ b/src/Validation.Runner/App.config @@ -47,7 +47,7 @@ - + diff --git a/tests/Tests.Stats.CollectAzureCdnLogs/app.config b/tests/Tests.Stats.CollectAzureCdnLogs/app.config index a3c70b969..e2afa76c2 100644 --- a/tests/Tests.Stats.CollectAzureCdnLogs/app.config +++ b/tests/Tests.Stats.CollectAzureCdnLogs/app.config @@ -40,7 +40,7 @@ - + diff --git a/tests/Tests.Stats.ImportAzureCdnStatistics/app.config b/tests/Tests.Stats.ImportAzureCdnStatistics/app.config index 6ec24bf7a..d1304b781 100644 --- a/tests/Tests.Stats.ImportAzureCdnStatistics/app.config +++ b/tests/Tests.Stats.ImportAzureCdnStatistics/app.config @@ -48,7 +48,7 @@ - + From a4990b5689b7a261e747e846041bb3fd4fee07bc Mon Sep 17 00:00:00 2001 From: Nikolche Kolev Date: Tue, 20 Feb 2018 23:32:55 -0800 Subject: [PATCH 2/5] Cleanup redundant code --- NuGet.Jobs.sln | 6 - .../Job.cs | 34 +---- ...et.Services.Validation.Orchestrator.csproj | 4 - ...ackageCompatibilityVerificationEnqueuer.cs | 23 --- .../PackageCompatibilityConfiguration.cs | 19 --- .../PackageCompatibilityValidator.cs | 90 +++++++----- ...ackageCompatibilityVerificationEnqueuer.cs | 43 ------ .../App.config | 6 - ...eCompatibilityPackageReferenceValidator.cs | 19 --- .../Job.cs | 138 ------------------ ...eCompatibilityPackageReferenceValidator.cs | 48 ------ ...geCompatibilityValidationMessageHandler.cs | 29 ---- .../PackageCompatibilityValidatorResult.cs | 35 ----- .../Program.cs | 16 -- .../Properties/AssemblyInfo.cs | 36 ----- ...tibility.PackageReferenceValidation.csproj | 129 ---------------- .../PackageCompatibilityService.cs | 11 +- .../IPackageCompatibilityStateService.cs | 12 -- .../PackageCompatibilityStateService.cs | 58 -------- 19 files changed, 57 insertions(+), 699 deletions(-) delete mode 100644 src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/IPackageCompatibilityVerificationEnqueuer.cs delete mode 100644 src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityConfiguration.cs delete mode 100644 src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityVerificationEnqueuer.cs delete mode 100644 src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/App.config delete mode 100644 src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/IPackageCompatibilityPackageReferenceValidator.cs delete mode 100644 src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Job.cs delete mode 100644 src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityPackageReferenceValidator.cs delete mode 100644 src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityValidationMessageHandler.cs delete mode 100644 src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityValidatorResult.cs delete mode 100644 src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Program.cs delete mode 100644 src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Properties/AssemblyInfo.cs delete mode 100644 src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Validation.PackageCompatibility.PackageReferenceValidation.csproj delete mode 100644 src/Validation.PackageCompatibility.Core/Storage/IPackageCompatibilityStateService.cs delete mode 100644 src/Validation.PackageCompatibility.Core/Storage/PackageCompatibilityStateService.cs diff --git a/NuGet.Jobs.sln b/NuGet.Jobs.sln index 81ee9564d..7bdf0c011 100644 --- a/NuGet.Jobs.sln +++ b/NuGet.Jobs.sln @@ -112,7 +112,6 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Validation.Common.Job", "src\Validation.Common.Job\Validation.Common.Job.csproj", "{FA87D075-A934-4443-8D0B-5DB32640B6D7}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PackageHash", "src\PackageHash\PackageHash.csproj", "{40843020-6F0A-48F0-AC28-42FFE3A5C21E}" -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Validation.PackageCompatibility.PackageReferenceValidation", "src\Validation.PackageAuthoring.ValidatePackageReferenceCompatibility\Validation.PackageCompatibility.PackageReferenceValidation.csproj", "{1B16DF51-90BB-4AC3-B269-8ADE5FB4FB0B}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Validation.PackageCompatibility.Core", "src\Validation.PackageCompatibility.Core\Validation.PackageCompatibility.Core.csproj", "{3958ECDD-DE42-401B-8BC6-553E49F2D42A}" EndProject @@ -292,10 +291,6 @@ Global {40843020-6F0A-48F0-AC28-42FFE3A5C21E}.Debug|Any CPU.Build.0 = Debug|Any CPU {40843020-6F0A-48F0-AC28-42FFE3A5C21E}.Release|Any CPU.ActiveCfg = Release|Any CPU {40843020-6F0A-48F0-AC28-42FFE3A5C21E}.Release|Any CPU.Build.0 = Release|Any CPU - {1B16DF51-90BB-4AC3-B269-8ADE5FB4FB0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1B16DF51-90BB-4AC3-B269-8ADE5FB4FB0B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1B16DF51-90BB-4AC3-B269-8ADE5FB4FB0B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1B16DF51-90BB-4AC3-B269-8ADE5FB4FB0B}.Release|Any CPU.Build.0 = Release|Any CPU {3958ECDD-DE42-401B-8BC6-553E49F2D42A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3958ECDD-DE42-401B-8BC6-553E49F2D42A}.Debug|Any CPU.Build.0 = Debug|Any CPU {3958ECDD-DE42-401B-8BC6-553E49F2D42A}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -347,7 +342,6 @@ Global {B4B7564A-965B-447B-927F-6749E2C08880} = {6A776396-02B1-475D-A104-26940ADB04AB} {FA87D075-A934-4443-8D0B-5DB32640B6D7} = {678D7B14-F8BC-4193-99AF-2EE8AA390A02} {40843020-6F0A-48F0-AC28-42FFE3A5C21E} = {FA5644B5-4F08-43F6-86B3-039374312A47} - {1B16DF51-90BB-4AC3-B269-8ADE5FB4FB0B} = {678D7B14-F8BC-4193-99AF-2EE8AA390A02} {3958ECDD-DE42-401B-8BC6-553E49F2D42A} = {678D7B14-F8BC-4193-99AF-2EE8AA390A02} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution diff --git a/src/NuGet.Services.Validation.Orchestrator/Job.cs b/src/NuGet.Services.Validation.Orchestrator/Job.cs index 2b523ba5d..bd78d131c 100644 --- a/src/NuGet.Services.Validation.Orchestrator/Job.cs +++ b/src/NuGet.Services.Validation.Orchestrator/Job.cs @@ -25,16 +25,13 @@ using NuGet.Jobs.Validation.PackageSigning.Storage; using NuGet.Services.Configuration; using NuGet.Services.KeyVault; -using NuGet.Services.Logging; using NuGet.Services.ServiceBus; -using NuGet.Services.Validation.Orchestrator.PackageCompatibility; using NuGet.Services.Validation.Orchestrator.Telemetry; using NuGet.Services.Validation.PackageCertificates; using NuGet.Services.Validation.PackageCompatibility; using NuGet.Services.Validation.PackageSigning; using NuGet.Services.Validation.Vcs; using NuGetGallery.Services; -using Validation.PackageCompatibility.Core.Messages; using Validation.PackageCompatibility.Core.Storage; namespace NuGet.Services.Validation.Orchestrator @@ -94,8 +91,7 @@ public override async Task Run() return; } - var runner = GetRequiredService(); - + var runner = GetRequiredService(); await runner.RunOrchestrationAsync(); } @@ -151,7 +147,6 @@ private void ConfigureJobServices(IServiceCollection services, IConfigurationRoo services.Configure(configurationRoot.GetSection(VcsSectionName)); services.Configure(configurationRoot.GetSection(PackageSigningSectionName)); services.Configure(configurationRoot.GetSection(PackageCertificatesSectionName)); - services.Configure(configurationRoot.GetSection(PackageCompatibilitySectionName)); services.Configure(configurationRoot.GetSection(RunnerConfigurationSectionName)); services.Configure(configurationRoot.GetSection(GalleryDbConfigurationSectionName)); services.Configure(configurationRoot.GetSection(ValidationDbConfigurationSectionName)); @@ -195,8 +190,6 @@ private void ConfigureJobServices(IServiceCollection services, IConfigurationRoo services.AddTransient(); services.AddTransient(); services.AddTransient, SignatureValidationMessageSerializer>(); - services.AddTransient(); - services.AddTransient, PackageCompatibilityValidationMessageSerializer>(); services.AddTransient(); services.AddTransient(); services.AddTransient(serviceProvider => @@ -375,31 +368,6 @@ private static void ConfigurePackageCompatibilityValidator(ContainerBuilder buil .RegisterType() .As(); - //builder - // .Register(c => - // { - // var configuration = c.Resolve>().Value.ServiceBus; - // return new TopicClientWrapper(configuration.ConnectionString, configuration.TopicPath); - // }) - // .Keyed(PackageCompatibilityBindingKey); - - //// Configure the package compatibility verification enqueuer. - //builder - // .RegisterType() - // .WithParameter(new ResolvedParameter( - // (pi, ctx) => pi.ParameterType == typeof(ITopicClient), - // (pi, ctx) => ctx.ResolveKeyed(PackageVerificationTopicClientBindingKey))) - // .WithParameter(new ResolvedParameter( - // (pi, ctx) => pi.ParameterType == typeof(IBrokeredMessageSerializer), - // (pi, ctx) => ctx.Resolve() - // )) - // .As(); - - //builder - // .RegisterType() - // .WithKeyedParameter(typeof(ITopicClient), PackageCompatibilityBindingKey) - // .As(); - // Configure the package compatibility validator builder .RegisterType() diff --git a/src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj b/src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj index 14cf84741..fcc4745a6 100644 --- a/src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj +++ b/src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj @@ -64,15 +64,12 @@ ======= - - >>>>>>> add package compatibility skeleton - @@ -137,7 +134,6 @@ Validation.PackageSigning.Core - ..\..\build diff --git a/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/IPackageCompatibilityVerificationEnqueuer.cs b/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/IPackageCompatibilityVerificationEnqueuer.cs deleted file mode 100644 index 9b983d682..000000000 --- a/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/IPackageCompatibilityVerificationEnqueuer.cs +++ /dev/null @@ -1,23 +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 System.Threading.Tasks; - -namespace NuGet.Services.Validation.PackageCompatibility -{ - /// - /// Kicks off package compatibility verification. - /// - public interface IPackageCompatibilityVerificationEnqueuer - { - /// - /// Kicks off the package verification process for the given request. Verification will begin when the - /// has a that matches the - /// 's validationId. Once verification completes, the 's - /// State will be updated to "Succeeded" or "Failed". - /// - /// The request that details the package to be verified. - /// A task that will complete when the verification process has been queued. - Task EnqueueVerificationAsync(IValidationRequest request); - } -} diff --git a/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityConfiguration.cs b/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityConfiguration.cs deleted file mode 100644 index 36829903b..000000000 --- a/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityConfiguration.cs +++ /dev/null @@ -1,19 +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.Jobs.Configuration; - -namespace NuGet.Services.Validation.Orchestrator.PackageCompatibility -{ - /// - /// Configuration for initializing the . - /// - public class PackageCompatibilityConfiguration - { - /// - /// The Service Bus configuration used to enqueue package compatibility validations. - /// - public ServiceBusConfiguration ServiceBus { get; set; } - } - -} - diff --git a/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityValidator.cs b/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityValidator.cs index 310866d71..57c87ddd9 100644 --- a/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityValidator.cs +++ b/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityValidator.cs @@ -2,10 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Net.Http; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; +using NuGet.Common; +using NuGet.Jobs.Validation; using NuGet.Jobs.Validation.PackageSigning.Storage; using Validation.PackageCompatibility.Core.Messages; using Validation.PackageCompatibility.Core.Storage; @@ -21,17 +23,17 @@ public class PackageCompatibilityValidator : IValidator private IPackageCompatibilityService _packageCompatibilityService; private readonly ILogger _logger; - private readonly HttpClient _httpClient; + private IPackageDownloader _packageDownloader; public PackageCompatibilityValidator( IValidatorStateService validatorStateService, IPackageCompatibilityService packageCompatibilityService, - HttpClient httpClient, + IPackageDownloader packageDownloader, ILogger logger) { _validatorStateService = validatorStateService; _packageCompatibilityService = packageCompatibilityService; - _httpClient = httpClient; + _packageDownloader = packageDownloader; _logger = logger; } @@ -44,53 +46,61 @@ public async Task GetResultAsync(IValidationRequest request) public async Task StartValidationAsync(IValidationRequest request) { - var validatorStatus = await _validatorStateService.GetStatusAsync(request); - - if (validatorStatus.State != ValidationStatus.NotStarted) + // Try check the whole thing + try { - _logger.LogWarning( - "Package Compatibility validation with validationId {ValidationId} ({PackageId} {PackageVersion}) has already started.", - request.ValidationId, - request.PackageId, - request.PackageVersion); + var validatorStatus = await _validatorStateService.GetStatusAsync(request); - return validatorStatus.ToValidationResult(); - } - // Add the status, so subsequent calls don't try to reevaluate the same thing - await _validatorStateService.TryAddValidatorStatusAsync(request, validatorStatus, ValidationStatus.Incomplete); + if (validatorStatus.State != ValidationStatus.NotStarted) + { + _logger.LogWarning( + "Package Compatibility validation with validationId {ValidationId} ({PackageId} {PackageVersion}) has already started.", + request.ValidationId, + request.PackageId, + request.PackageVersion); - var message = new PackageCompatibilityValidationMessage( - request.PackageId, - request.PackageVersion, - new Uri(request.NupkgUrl), - request.ValidationId - ); + return validatorStatus.ToValidationResult(); + } - // Do validation - await Validate(message, CancellationToken.None); + // Add the status, so subsequent calls don't try to reevaluate the same thing + await _validatorStateService.TryAddValidatorStatusAsync(request, validatorStatus, ValidationStatus.Incomplete); - validatorStatus.State = ValidationStatus.Succeeded; - await _validatorStateService.SaveStatusAsync(validatorStatus); + var message = new PackageCompatibilityValidationMessage( + request.PackageId, + request.PackageVersion, + new Uri(request.NupkgUrl), + request.ValidationId + ); - return validatorStatus.ToValidationResult(); + // Do validation + await Validate(message, CancellationToken.None); + + 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()); + } + return null; } private async Task Validate(PackageCompatibilityValidationMessage message, CancellationToken cancellationToken) { - // Validate package // TODO NK - Use the utility to download packages - //using (var packageStream = await PackageValidationUtility.DownloadPackageAsync(_httpClient, message.NupkgUri, _logger, cancellationToken)) - //using (var package = new PackageArchiveReader(packageStream)) - //{ - // var warnings = new List(); - - // foreach(var rule in Packaging.Rules.DefaultPackageRuleSet.Rules) - // { - // warnings.AddRange(rule.Validate(package)); - // } - - // await _packageCompatibilityService.SetPackageCompatibilityState(message.ValidationId, warnings); - //} + using (var packageStream = await _packageDownloader.DownloadAsync(message.NupkgUri, cancellationToken)) + using (var package = new Packaging.PackageArchiveReader(packageStream)) + { + var warnings = new List(); + + foreach (var rule in Packaging.Rules.DefaultPackageRuleSet.Rules) + { + warnings.AddRange(rule.Validate(package)); + } + await _packageCompatibilityService.SetPackageCompatibilityState(message.ValidationId, warnings); + } } } } diff --git a/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityVerificationEnqueuer.cs b/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityVerificationEnqueuer.cs deleted file mode 100644 index 9f071d491..000000000 --- a/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityVerificationEnqueuer.cs +++ /dev/null @@ -1,43 +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 System; -using System.Threading.Tasks; -using NuGet.Services.ServiceBus; -using Validation.PackageCompatibility.Core.Messages; - -namespace NuGet.Services.Validation.PackageCompatibility -{ - /// - /// Kicks off package compatibility verifications. - /// - public class PackageCompatibilityVerificationEnqueuer : IPackageCompatibilityVerificationEnqueuer - { - private readonly ITopicClient _topicClient; - private readonly IBrokeredMessageSerializer _packageCompatibilityVerificationSerializer; - - public PackageCompatibilityVerificationEnqueuer( - ITopicClient topicClient, - IBrokeredMessageSerializer packageCompatibilityVerificationSerializer) - { - _topicClient = topicClient ?? throw new ArgumentNullException(nameof(topicClient)); - _packageCompatibilityVerificationSerializer = packageCompatibilityVerificationSerializer ?? throw new ArgumentNullException(nameof(packageCompatibilityVerificationSerializer)); - } - - /// - /// Kicks off the package verification process for the given request. Verification will begin when the - /// has a that matches the - /// 's validationId. Once verification completes, the 's - /// State will be updated to "Succeeded" or "Failed". - /// - /// The request that details the package to be verified. - /// A task that will complete when the verification process has been queued. - public Task EnqueueVerificationAsync(IValidationRequest request) - { - var brokeredMessage = _packageCompatibilityVerificationSerializer.Serialize( - new PackageCompatibilityValidationMessage(request.PackageId, request.PackageVersion, new Uri(request.NupkgUrl), request.ValidationId)); - - return _topicClient.SendAsync(brokeredMessage); - } - } -} diff --git a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/App.config b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/App.config deleted file mode 100644 index 731f6de6c..000000000 --- a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/IPackageCompatibilityPackageReferenceValidator.cs b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/IPackageCompatibilityPackageReferenceValidator.cs deleted file mode 100644 index a28cf96cf..000000000 --- a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/IPackageCompatibilityPackageReferenceValidator.cs +++ /dev/null @@ -1,19 +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.Packaging; -using System.Threading; -using System.Threading.Tasks; -using Validation.PackageCompatibility.Core.Messages; - -namespace Validation.PackageAuthoring.ValidatePackageReferenceCompatibility -{ - interface IPackageCompatibilityPackageReferenceValidator - { - Task ValidateAsync( - int packageKey, - PackageArchiveReader package, - PackageCompatibilityValidationMessage message, - CancellationToken cancellationToken); - } -} diff --git a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Job.cs b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Job.cs deleted file mode 100644 index cba994dbe..000000000 --- a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Job.cs +++ /dev/null @@ -1,138 +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 System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using NuGet.Jobs; -using NuGet.Jobs.Configuration; -using NuGet.Services.Configuration; -using NuGet.Services.KeyVault; -using NuGet.Services.ServiceBus; -using Validation.PackageCompatibility.Core.Messages; - -namespace Validation.PackageCompatibility.PackageReferenceValidation -{ - internal class Job : JobBase - { - /// - /// The argument this job uses to determine the configuration file's path. - /// - private const string ConfigurationArgument = "Configuration"; - - private const string ValidationDbConfigurationSectionName = "ValidationDb"; - private const string ServiceBusConfigurationSectionName = "ServiceBus"; - - /// - /// The maximum time that a KeyVault secret will be cached for. - /// - private static readonly TimeSpan KeyVaultSecretCachingTimeout = TimeSpan.FromDays(1); - - /// - /// The maximum amount of time that graceful shutdown can take before the job will - /// forcefully end itself. - /// - private static readonly TimeSpan MaxShutdownTime = TimeSpan.FromMinutes(1); - - /// - /// The configured service provider, used to instiate the services this job depends on. - /// - private IServiceProvider _serviceProvider; - - public override void Init(IDictionary jobArgsDictionary) - { - var configurationFilename = JobConfigurationManager.GetArgument(jobArgsDictionary, ConfigurationArgument); - _serviceProvider = GetServiceProvider(GetConfigurationRoot(configurationFilename)); - - } - - public async override Task Run() - { - // I am understanding this correctly? - // All these run get triggered on a validation message? - // If that true, this message would need serialization code, sent by someone etc. - var processor = _serviceProvider.GetRequiredService>(); - - processor.Start(); - - // Wait a day, and then shutdown this process so that it is restarted. - await Task.Delay(TimeSpan.FromDays(1)); - - if (!await processor.ShutdownAsync(MaxShutdownTime)) - { - Logger.LogWarning( - "Failed to gracefully shutdown Service Bus subscription processor. {MessagesInProgress} messages left", - processor.NumberOfMessagesInProgress); - } - } - - private IServiceProvider GetServiceProvider(IConfigurationRoot configurationRoot) - { - var services = new ServiceCollection(); - - ConfigureLibraries(services); - ConfigureJobServices(services, configurationRoot); - - return CreateProvider(services); - } - - // TODO NK - Why are these configuration root methods all the same, yet not common? DRY - // This loooks pretty generic - private IConfigurationRoot GetConfigurationRoot(string configurationFilename) - { - Logger.LogInformation("Using the {ConfigurationFilename} configuration file", configurationFilename); - - var builder = new ConfigurationBuilder() - .SetBasePath(Environment.CurrentDirectory) - .AddJsonFile(configurationFilename, optional: false, reloadOnChange: true); - - var uninjectedConfiguration = builder.Build(); - - var secretReaderFactory = new ConfigurationRootSecretReaderFactory(uninjectedConfiguration); - var cachingSecretReaderFactory = new CachingSecretReaderFactory(secretReaderFactory, KeyVaultSecretCachingTimeout); - var secretInjector = cachingSecretReaderFactory.CreateSecretInjector(cachingSecretReaderFactory.CreateSecretReader()); - - builder = new ConfigurationBuilder() - .SetBasePath(Environment.CurrentDirectory) - .AddInjectedJsonFile(configurationFilename, secretInjector); - - return builder.Build(); - } - - private void ConfigureLibraries(IServiceCollection services) - { - // Use the custom NonCachingOptionsSnapshot so that KeyVault secret injection works properly. - //services.Add(ServiceDescriptor.Scoped(typeof(IOptionsSnapshot<>), typeof(NonCachingOptionsSnapshot<>))); - //services.AddSingleton(LoggerFactory); - //services.AddLogging(); - } - - private void ConfigureJobServices(IServiceCollection services, IConfigurationRoot configurationRoot) - { - services.Configure(configurationRoot.GetSection(ValidationDbConfigurationSectionName)); - services.Configure(configurationRoot.GetSection(ServiceBusConfigurationSectionName)); - - //services.AddScoped(p => - //{ - // var config = p.GetRequiredService>().Value; - - // return new ValidationEntitiesContext(config.ConnectionString); - //}); - - //services.AddTransient(p => - //{ - // var config = p.GetRequiredService>().Value; - - // return new SubscriptionClientWrapper(config.ConnectionString, config.TopicPath, config.SubscriptionName); - //}); - } - - private static IServiceProvider CreateProvider(IServiceCollection services) - { - throw new NotImplementedException(); - } - } -} diff --git a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityPackageReferenceValidator.cs b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityPackageReferenceValidator.cs deleted file mode 100644 index 4762226ae..000000000 --- a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityPackageReferenceValidator.cs +++ /dev/null @@ -1,48 +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 System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using NuGet.Packaging; -using NuGet.Services.Validation; -using Validation.PackageCompatibility.Core.Messages; -using NuGet.Services.Validation.Issues; - -namespace Validation.PackageAuthoring.ValidatePackageReferenceCompatibility -{ - public class PackageCompatibilityPackageReferenceValidator : IPackageCompatibilityPackageReferenceValidator - { - public async Task ValidateAsync(int packageKey, PackageArchiveReader package, PackageCompatibilityValidationMessage message, CancellationToken cancellationToken) - { - try - { - if (message.PackageId.Equals("newtosoft.json", StringComparison.InvariantCultureIgnoreCase)){ - var issue = new ClientPackageCompatibilityVerificationIssue("NU1500", "This package is invalid, because we said so."); - return AcceptWithIssues(packageKey, message, new IValidationIssue[] { issue }); - } - } - catch(Exception e) - { - var issue = new ClientPackageCompatibilityVerificationIssue("NU9999", e.Message); - return AcceptWithIssues(packageKey, message, new IValidationIssue[] { issue }); - } - - return AcceptWithoutErrorsAsync(packageKey, message); - } - - private PackageCompatibilityValidatorResult AcceptWithIssues(int packageKey, - PackageCompatibilityValidationMessage message, IReadOnlyList issues) - { - return new PackageCompatibilityValidatorResult(ValidationStatus.Succeeded, issues); - } - - private PackageCompatibilityValidatorResult AcceptWithoutErrorsAsync( - int packageKey, - PackageCompatibilityValidationMessage message) - { - return new PackageCompatibilityValidatorResult(ValidationStatus.Succeeded); - } - } -} diff --git a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityValidationMessageHandler.cs b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityValidationMessageHandler.cs deleted file mode 100644 index a98e97a5b..000000000 --- a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityValidationMessageHandler.cs +++ /dev/null @@ -1,29 +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 Microsoft.Extensions.Logging; -using NuGet.Jobs.Validation.PackageSigning.Storage; -using NuGet.Services.ServiceBus; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; -using Validation.PackageCompatibility.Core.Messages; - -namespace Validation.PackageAuthoring.ValidatePackageReferenceCompatibility -{ - class PackageCompatibilityValidationMessageHandler : IMessageHandler - { - private readonly HttpClient _httpClient; - private readonly IValidatorStateService _validatorStateService; - private readonly IPackageCompatibilityPackageReferenceValidator _packageCompatibilityPackageReferenceValidator; - private readonly ILogger _logger; - - public Task HandleAsync(PackageCompatibilityValidationMessage message) - { - throw new NotImplementedException(); - } - } -} diff --git a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityValidatorResult.cs b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityValidatorResult.cs deleted file mode 100644 index aa9b868c1..000000000 --- a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/PackageCompatibilityValidatorResult.cs +++ /dev/null @@ -1,35 +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 System; -using System.Collections.Generic; -using System.Linq; -using NuGet.Services.Validation; - - -namespace Validation.PackageAuthoring.ValidatePackageReferenceCompatibility -{ - public class PackageCompatibilityValidatorResult - { - public PackageCompatibilityValidatorResult(ValidationStatus state) - : this(state, new IValidationIssue[0]) - { - } - - public PackageCompatibilityValidatorResult(ValidationStatus state, IReadOnlyList issues) - { - State = state; - Issues = issues ?? throw new ArgumentNullException(nameof(issues)); - - if (state != ValidationStatus.Failed - && state != ValidationStatus.Succeeded - && issues.Any()) - { - throw new ArgumentException("Issues are only allowed for terminal states.", nameof(issues)); - } - } - - public ValidationStatus State { get; } - public IReadOnlyList Issues { get; } - } -} \ No newline at end of file diff --git a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Program.cs b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Program.cs deleted file mode 100644 index 2222ec457..000000000 --- a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Program.cs +++ /dev/null @@ -1,16 +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.Jobs; - -namespace Validation.PackageCompatibility.PackageReferenceValidation -{ - class Program - { - static void Main(string[] args) - { - var job = new Job(); - JobRunner.Run(job, args).GetAwaiter().GetResult(); - } - } -} diff --git a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Properties/AssemblyInfo.cs b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Properties/AssemblyInfo.cs deleted file mode 100644 index 1770e0ac8..000000000 --- a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Validation.PackageAuthoring.ValidatePackageReferenceCompatibility")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("HP Inc.")] -[assembly: AssemblyProduct("Validation.PackageAuthoring.ValidatePackageReferenceCompatibility")] -[assembly: AssemblyCopyright("Copyright © HP Inc. 2018")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("1b16df51-90bb-4ac3-b269-8ade5fb4fb0b")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Validation.PackageCompatibility.PackageReferenceValidation.csproj b/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Validation.PackageCompatibility.PackageReferenceValidation.csproj deleted file mode 100644 index bb9df9ca8..000000000 --- a/src/Validation.PackageAuthoring.ValidatePackageReferenceCompatibility/Validation.PackageCompatibility.PackageReferenceValidation.csproj +++ /dev/null @@ -1,129 +0,0 @@ - - - - - Debug - AnyCPU - {1B16DF51-90BB-4AC3-B269-8ADE5FB4FB0B} - Exe - Validation.PackageAuthoring.ValidatePackageReferenceCompatibility - Validation.PackageAuthoring.ValidatePackageReferenceCompatibility - v4.6 - 512 - true - - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - - - - - - 4.6.2 - - - 4.2.0 - - - 2.2.0 - - - 1.1.2 - - - 1.1.2 - - - 1.1.2 - - - 1.1.1 - - - 1.1.2 - - - 2.3.0 - - - 2.3.0 - - - 2.3.0 - - - 2.3.0 - - - 4.3.3 - - - - - {b4b7564a-965b-447b-927f-6749e2c08880} - Validation.PackageSigning.Core.Tests - - - {4b4b1efb-8f33-42e6-b79f-54e7f3293d31} - NuGet.Jobs.Common - - - {e6d094fb-9068-4578-b176-116f97e7506b} - NuGet.Services.Validation.Orchestrator - - - {fa87d075-a934-4443-8d0b-5db32640b6d7} - Validation.Common.Job - - - {2539DDF3-0CC5-4A03-B5F9-39B47744A7BD} - Validation.Common - - - {3958ecdd-de42-401b-8bc6-553e49f2d42a} - Validation.PackageCompatibility.Core - - - {91C060DA-736F-4DA9-A57F-CB3AC0E6CB10} - Validation.PackageSigning.Core - - - - \ No newline at end of file diff --git a/src/Validation.PackageCompatibility.Core/PackageCompatibilityService.cs b/src/Validation.PackageCompatibility.Core/PackageCompatibilityService.cs index 0dc6f01d5..e7646f164 100644 --- a/src/Validation.PackageCompatibility.Core/PackageCompatibilityService.cs +++ b/src/Validation.PackageCompatibility.Core/PackageCompatibilityService.cs @@ -5,8 +5,7 @@ using NuGet.Services.Validation; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Data.Entity.Infrastructure; using System.Threading.Tasks; namespace Validation.PackageCompatibility.Core.Storage @@ -39,9 +38,11 @@ public class PackageCompatibilityService : IPackageCompatibilityService } ); } - try { - await _validationContext.SaveChangesAsync(); // TODO - my savings needs to catch database consistency - } catch(Exception e) + try + { + await _validationContext.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException e) { _logger.LogWarning("trouble saving changes async - {0}", e.Message); } diff --git a/src/Validation.PackageCompatibility.Core/Storage/IPackageCompatibilityStateService.cs b/src/Validation.PackageCompatibility.Core/Storage/IPackageCompatibilityStateService.cs deleted file mode 100644 index ef8208158..000000000 --- a/src/Validation.PackageCompatibility.Core/Storage/IPackageCompatibilityStateService.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Validation.PackageCompatibility.Core.Storage -{ - interface IPackageCompatibilityService - { - } -} diff --git a/src/Validation.PackageCompatibility.Core/Storage/PackageCompatibilityStateService.cs b/src/Validation.PackageCompatibility.Core/Storage/PackageCompatibilityStateService.cs deleted file mode 100644 index b94b34ad1..000000000 --- a/src/Validation.PackageCompatibility.Core/Storage/PackageCompatibilityStateService.cs +++ /dev/null @@ -1,58 +0,0 @@ -using Microsoft.Extensions.Logging; -using NuGet.Common; -using NuGet.Services.Validation; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Validation.PackageCompatibility.Core.Storage -{ - public class PackageCompatibilityStateService : IPackageCompatibilityService - { - private readonly IValidationEntitiesContext _validationContext; - private readonly ILogger _logger; - - public PackageCompatibilityStateService( - IValidationEntitiesContext validationContext, - ILogger logger) - { - _validationContext = validationContext ?? throw new ArgumentNullException(nameof(validationContext)); - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - } - - public async Task SetPackageCompatibilityState( - Guid validationId, - IReadOnlyList messages) - { - - foreach (var log in messages) - { - warnings.Add( - new PackageCompatibilityIssue() - { - // Key - will the DB apply is - ClientIssueCode = log.Code.ToString(), - Data = log.Message, - PackageValidationKey = message.ValidationId - } - ); - - if (string.IsNullOrEmpty(packageId)) - { - throw new ArgumentException(nameof(packageId)); - } - if (string.IsNullOrEmpty(packageVersion)) - { - throw new ArgumentException(nameof(packageVersion)); - } - - // It is possible this package has already been validated. If so, the package's state will already exist - // in the database. Updates to this state should only be requested on explicit revalidation gestures. However, - // this invariant may be broken due to message duplication. - await _validationContext.PackageCom.FirstOrDefaultAsync(s => s.PackageKey == packageKey); -{ } - } - } -} From a415a12c185f2859ecc119b79645dc1133165f7a Mon Sep 17 00:00:00 2001 From: Nikolche Kolev Date: Tue, 20 Feb 2018 23:44:01 -0800 Subject: [PATCH 3/5] Remove changes in dependencies for local development --- .vs/config/applicationhost.config | 10 +--------- SnapshotAzureBlob/App.config | 2 +- src/ArchivePackages/App.config | 2 +- src/CopyAzureContainer/App.config | 2 +- src/Gallery.CredentialExpiration/App.config | 2 +- src/Gallery.Maintenance/project.json | 2 +- src/NuGet.Jobs.Common/NuGet.Jobs.Common.csproj | 16 +++++++--------- src/NuGet.Jobs.Common/app.config | 2 +- src/NuGet.Jobs.Common/packages.config | 6 +++--- ...NuGet.Services.Validation.Orchestrator.csproj | 4 ---- .../NuGet.SupportRequests.Notifications.csproj | 8 ++++---- .../app.config | 2 +- .../packages.config | 4 ++-- src/NuGetCDNRedirect/NuGetCDNRedirect.csproj | 4 ++-- src/NuGetCDNRedirect/packages.config | 2 +- src/Search.GenerateAuxiliaryData/App.config | 2 +- .../App.config | 2 +- src/Stats.CollectAzureCdnLogs/App.config | 2 +- .../App.config | 2 +- .../Stats.CreateAzureCdnWarehouseReports.csproj | 4 ++-- .../packages.config | 2 +- src/Stats.ImportAzureCdnStatistics/App.config | 2 +- .../Stats.ImportAzureCdnStatistics.csproj | 4 ++-- .../packages.config | 2 +- src/Stats.RefreshClientDimension/App.config | 2 +- src/Stats.RollUpDownloadFacts/App.config | 2 +- .../Stats.RollUpDownloadFacts.csproj | 4 ++-- src/Stats.RollUpDownloadFacts/packages.config | 2 +- src/UpdateLicenseReports/App.config | 2 +- src/Validation.Callback.Vcs/Web.config | 2 +- src/Validation.Common/Validation.Common.csproj | 8 ++++---- src/Validation.Common/app.config | 4 ++-- src/Validation.Common/packages.config | 4 ++-- src/Validation.Runner/App.config | 2 +- tests/Tests.Stats.CollectAzureCdnLogs/app.config | 2 +- .../app.config | 2 +- 36 files changed, 56 insertions(+), 70 deletions(-) diff --git a/.vs/config/applicationhost.config b/.vs/config/applicationhost.config index 7d4a25522..582b1211a 100644 --- a/.vs/config/applicationhost.config +++ b/.vs/config/applicationhost.config @@ -163,20 +163,12 @@ - + - - - - - - - - diff --git a/SnapshotAzureBlob/App.config b/SnapshotAzureBlob/App.config index ec31780c1..d995f6b91 100644 --- a/SnapshotAzureBlob/App.config +++ b/SnapshotAzureBlob/App.config @@ -15,7 +15,7 @@ - + diff --git a/src/ArchivePackages/App.config b/src/ArchivePackages/App.config index 94df12e7f..30285b038 100644 --- a/src/ArchivePackages/App.config +++ b/src/ArchivePackages/App.config @@ -35,7 +35,7 @@ - + diff --git a/src/CopyAzureContainer/App.config b/src/CopyAzureContainer/App.config index df5f8c925..dbc89f8b0 100644 --- a/src/CopyAzureContainer/App.config +++ b/src/CopyAzureContainer/App.config @@ -15,7 +15,7 @@ - + diff --git a/src/Gallery.CredentialExpiration/App.config b/src/Gallery.CredentialExpiration/App.config index 5d695d1f6..20005b32d 100644 --- a/src/Gallery.CredentialExpiration/App.config +++ b/src/Gallery.CredentialExpiration/App.config @@ -43,7 +43,7 @@ - + diff --git a/src/Gallery.Maintenance/project.json b/src/Gallery.Maintenance/project.json index 2719cbdba..3c20f7dae 100644 --- a/src/Gallery.Maintenance/project.json +++ b/src/Gallery.Maintenance/project.json @@ -1,7 +1,7 @@ { "dependencies": { "Microsoft.Extensions.Logging.Abstractions": "1.0.0", - "NuGet.Services.Logging": "2.3.0" + "NuGet.Services.Logging": "2.2.3" }, "frameworks": { "net452": {} diff --git a/src/NuGet.Jobs.Common/NuGet.Jobs.Common.csproj b/src/NuGet.Jobs.Common/NuGet.Jobs.Common.csproj index 68a6fdd8b..863da3bb8 100644 --- a/src/NuGet.Jobs.Common/NuGet.Jobs.Common.csproj +++ b/src/NuGet.Jobs.Common/NuGet.Jobs.Common.csproj @@ -133,14 +133,14 @@ ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - - ..\..\packages\NuGet.Services.Configuration.2.3.0\lib\net452\NuGet.Services.Configuration.dll + + ..\..\packages\NuGet.Services.Configuration.2.2.3\lib\net452\NuGet.Services.Configuration.dll - - ..\..\packages\NuGet.Services.KeyVault.2.3.0\lib\net45\NuGet.Services.KeyVault.dll + + ..\..\packages\NuGet.Services.KeyVault.2.2.3\lib\net45\NuGet.Services.KeyVault.dll - - ..\..\packages\NuGet.Services.Logging.2.3.0\lib\net452\NuGet.Services.Logging.dll + + ..\..\packages\NuGet.Services.Logging.2.2.3\lib\net452\NuGet.Services.Logging.dll ..\..\packages\Serilog.2.0.0\lib\net45\Serilog.dll @@ -205,9 +205,7 @@ - - Designer - + Designer diff --git a/src/NuGet.Jobs.Common/app.config b/src/NuGet.Jobs.Common/app.config index e4974f6cf..d2dea252b 100644 --- a/src/NuGet.Jobs.Common/app.config +++ b/src/NuGet.Jobs.Common/app.config @@ -32,7 +32,7 @@ - + diff --git a/src/NuGet.Jobs.Common/packages.config b/src/NuGet.Jobs.Common/packages.config index 4ce6acdb2..31643d606 100644 --- a/src/NuGet.Jobs.Common/packages.config +++ b/src/NuGet.Jobs.Common/packages.config @@ -31,9 +31,9 @@ - - - + + + diff --git a/src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj b/src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj index fcc4745a6..b46178d25 100644 --- a/src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj +++ b/src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj @@ -60,12 +60,8 @@ -<<<<<<< HEAD -======= - ->>>>>>> add package compatibility skeleton diff --git a/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.csproj b/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.csproj index dac3f988b..dc52dedd9 100644 --- a/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.csproj +++ b/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.csproj @@ -96,11 +96,11 @@ ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - - ..\..\packages\NuGet.Services.Configuration.2.3.0\lib\net452\NuGet.Services.Configuration.dll + + ..\..\packages\NuGet.Services.Configuration.2.2.3\lib\net452\NuGet.Services.Configuration.dll - - ..\..\packages\NuGet.Services.KeyVault.2.3.0\lib\net45\NuGet.Services.KeyVault.dll + + ..\..\packages\NuGet.Services.KeyVault.2.2.3\lib\net45\NuGet.Services.KeyVault.dll diff --git a/src/NuGet.SupportRequests.Notifications/app.config b/src/NuGet.SupportRequests.Notifications/app.config index b229ccea1..518a160f1 100644 --- a/src/NuGet.SupportRequests.Notifications/app.config +++ b/src/NuGet.SupportRequests.Notifications/app.config @@ -24,7 +24,7 @@ - + diff --git a/src/NuGet.SupportRequests.Notifications/packages.config b/src/NuGet.SupportRequests.Notifications/packages.config index 6f4e9e256..bd4e51b98 100644 --- a/src/NuGet.SupportRequests.Notifications/packages.config +++ b/src/NuGet.SupportRequests.Notifications/packages.config @@ -19,8 +19,8 @@ - - + + diff --git a/src/NuGetCDNRedirect/NuGetCDNRedirect.csproj b/src/NuGetCDNRedirect/NuGetCDNRedirect.csproj index fc1085b73..d8277d141 100644 --- a/src/NuGetCDNRedirect/NuGetCDNRedirect.csproj +++ b/src/NuGetCDNRedirect/NuGetCDNRedirect.csproj @@ -86,8 +86,8 @@ ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - - ..\..\packages\NuGet.Services.Logging.2.3.0\lib\net452\NuGet.Services.Logging.dll + + ..\..\packages\NuGet.Services.Logging.2.2.3\lib\net452\NuGet.Services.Logging.dll ..\..\packages\Serilog.2.0.0\lib\net45\Serilog.dll diff --git a/src/NuGetCDNRedirect/packages.config b/src/NuGetCDNRedirect/packages.config index 5e7390fb1..0f1a8926c 100644 --- a/src/NuGetCDNRedirect/packages.config +++ b/src/NuGetCDNRedirect/packages.config @@ -20,7 +20,7 @@ - + diff --git a/src/Search.GenerateAuxiliaryData/App.config b/src/Search.GenerateAuxiliaryData/App.config index bc6b153ca..3e840a1a3 100644 --- a/src/Search.GenerateAuxiliaryData/App.config +++ b/src/Search.GenerateAuxiliaryData/App.config @@ -35,7 +35,7 @@ - + diff --git a/src/Stats.AggregateCdnDownloadsInGallery/App.config b/src/Stats.AggregateCdnDownloadsInGallery/App.config index 272e8fbbb..7d12a6d35 100644 --- a/src/Stats.AggregateCdnDownloadsInGallery/App.config +++ b/src/Stats.AggregateCdnDownloadsInGallery/App.config @@ -35,7 +35,7 @@ - + diff --git a/src/Stats.CollectAzureCdnLogs/App.config b/src/Stats.CollectAzureCdnLogs/App.config index 90132dfb5..531b6132f 100644 --- a/src/Stats.CollectAzureCdnLogs/App.config +++ b/src/Stats.CollectAzureCdnLogs/App.config @@ -52,7 +52,7 @@ - + diff --git a/src/Stats.CreateAzureCdnWarehouseReports/App.config b/src/Stats.CreateAzureCdnWarehouseReports/App.config index e45a8fe14..36efa1e87 100644 --- a/src/Stats.CreateAzureCdnWarehouseReports/App.config +++ b/src/Stats.CreateAzureCdnWarehouseReports/App.config @@ -47,7 +47,7 @@ - + diff --git a/src/Stats.CreateAzureCdnWarehouseReports/Stats.CreateAzureCdnWarehouseReports.csproj b/src/Stats.CreateAzureCdnWarehouseReports/Stats.CreateAzureCdnWarehouseReports.csproj index 58591f277..646cc1652 100644 --- a/src/Stats.CreateAzureCdnWarehouseReports/Stats.CreateAzureCdnWarehouseReports.csproj +++ b/src/Stats.CreateAzureCdnWarehouseReports/Stats.CreateAzureCdnWarehouseReports.csproj @@ -80,8 +80,8 @@ ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - - ..\..\packages\NuGet.Services.Logging.2.3.0\lib\net452\NuGet.Services.Logging.dll + + ..\..\packages\NuGet.Services.Logging.2.2.3\lib\net452\NuGet.Services.Logging.dll ..\..\packages\NuGet.Versioning.4.3.0-preview1-2524\lib\net45\NuGet.Versioning.dll diff --git a/src/Stats.CreateAzureCdnWarehouseReports/packages.config b/src/Stats.CreateAzureCdnWarehouseReports/packages.config index b0f55dc1f..f013b1f20 100644 --- a/src/Stats.CreateAzureCdnWarehouseReports/packages.config +++ b/src/Stats.CreateAzureCdnWarehouseReports/packages.config @@ -15,7 +15,7 @@ - + diff --git a/src/Stats.ImportAzureCdnStatistics/App.config b/src/Stats.ImportAzureCdnStatistics/App.config index 5d695d1f6..20005b32d 100644 --- a/src/Stats.ImportAzureCdnStatistics/App.config +++ b/src/Stats.ImportAzureCdnStatistics/App.config @@ -43,7 +43,7 @@ - + diff --git a/src/Stats.ImportAzureCdnStatistics/Stats.ImportAzureCdnStatistics.csproj b/src/Stats.ImportAzureCdnStatistics/Stats.ImportAzureCdnStatistics.csproj index d6fa89883..0567b6e66 100644 --- a/src/Stats.ImportAzureCdnStatistics/Stats.ImportAzureCdnStatistics.csproj +++ b/src/Stats.ImportAzureCdnStatistics/Stats.ImportAzureCdnStatistics.csproj @@ -83,8 +83,8 @@ ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - - ..\..\packages\NuGet.Services.Logging.2.3.0\lib\net452\NuGet.Services.Logging.dll + + ..\..\packages\NuGet.Services.Logging.2.2.3\lib\net452\NuGet.Services.Logging.dll ..\..\packages\NuGet.Versioning.4.3.0-preview1-2524\lib\net45\NuGet.Versioning.dll diff --git a/src/Stats.ImportAzureCdnStatistics/packages.config b/src/Stats.ImportAzureCdnStatistics/packages.config index 9fbdd2f32..ff65ae1b2 100644 --- a/src/Stats.ImportAzureCdnStatistics/packages.config +++ b/src/Stats.ImportAzureCdnStatistics/packages.config @@ -15,7 +15,7 @@ - + diff --git a/src/Stats.RefreshClientDimension/App.config b/src/Stats.RefreshClientDimension/App.config index f92447b67..4a9dfc692 100644 --- a/src/Stats.RefreshClientDimension/App.config +++ b/src/Stats.RefreshClientDimension/App.config @@ -35,7 +35,7 @@ - + diff --git a/src/Stats.RollUpDownloadFacts/App.config b/src/Stats.RollUpDownloadFacts/App.config index 83ae2269d..cfa6f76c3 100644 --- a/src/Stats.RollUpDownloadFacts/App.config +++ b/src/Stats.RollUpDownloadFacts/App.config @@ -43,7 +43,7 @@ - + diff --git a/src/Stats.RollUpDownloadFacts/Stats.RollUpDownloadFacts.csproj b/src/Stats.RollUpDownloadFacts/Stats.RollUpDownloadFacts.csproj index 39457b9dd..015e40a11 100644 --- a/src/Stats.RollUpDownloadFacts/Stats.RollUpDownloadFacts.csproj +++ b/src/Stats.RollUpDownloadFacts/Stats.RollUpDownloadFacts.csproj @@ -59,8 +59,8 @@ ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - - ..\..\packages\NuGet.Services.Logging.2.3.0\lib\net452\NuGet.Services.Logging.dll + + ..\..\packages\NuGet.Services.Logging.2.2.3\lib\net452\NuGet.Services.Logging.dll ..\..\packages\Serilog.2.2.1\lib\net45\Serilog.dll diff --git a/src/Stats.RollUpDownloadFacts/packages.config b/src/Stats.RollUpDownloadFacts/packages.config index 983bf97ef..5561124a9 100644 --- a/src/Stats.RollUpDownloadFacts/packages.config +++ b/src/Stats.RollUpDownloadFacts/packages.config @@ -9,7 +9,7 @@ - + diff --git a/src/UpdateLicenseReports/App.config b/src/UpdateLicenseReports/App.config index 44d83fe73..9dcee3ac3 100644 --- a/src/UpdateLicenseReports/App.config +++ b/src/UpdateLicenseReports/App.config @@ -35,7 +35,7 @@ - + diff --git a/src/Validation.Callback.Vcs/Web.config b/src/Validation.Callback.Vcs/Web.config index 0693c43b4..cd64b34a7 100644 --- a/src/Validation.Callback.Vcs/Web.config +++ b/src/Validation.Callback.Vcs/Web.config @@ -70,7 +70,7 @@ - + diff --git a/src/Validation.Common/Validation.Common.csproj b/src/Validation.Common/Validation.Common.csproj index ab8bdf32a..c8a5e8c79 100644 --- a/src/Validation.Common/Validation.Common.csproj +++ b/src/Validation.Common/Validation.Common.csproj @@ -105,11 +105,11 @@ ..\..\packages\NuGet.ApplicationInsights.Owin.4.1.0\lib\net452\NuGet.ApplicationInsights.Owin.dll - - ..\..\packages\NuGet.Services.KeyVault.2.3.0\lib\net45\NuGet.Services.KeyVault.dll + + ..\..\packages\NuGet.Services.KeyVault.2.13.0\lib\net45\NuGet.Services.KeyVault.dll - - ..\..\packages\NuGet.Services.Logging.2.3.0\lib\net452\NuGet.Services.Logging.dll + + ..\..\packages\NuGet.Services.Logging.2.13.0\lib\net452\NuGet.Services.Logging.dll ..\..\packages\NuGet.Services.VirusScanning.Vcs.3.2.0\lib\net452\NuGet.Services.VirusScanning.Core.dll diff --git a/src/Validation.Common/app.config b/src/Validation.Common/app.config index 45066e8a2..b13a21e9e 100644 --- a/src/Validation.Common/app.config +++ b/src/Validation.Common/app.config @@ -4,7 +4,7 @@ - + @@ -40,7 +40,7 @@ - + diff --git a/src/Validation.Common/packages.config b/src/Validation.Common/packages.config index 4987c7300..b31ab07fa 100644 --- a/src/Validation.Common/packages.config +++ b/src/Validation.Common/packages.config @@ -22,8 +22,8 @@ - - + + diff --git a/src/Validation.Runner/App.config b/src/Validation.Runner/App.config index 660ca9bdd..09d428570 100644 --- a/src/Validation.Runner/App.config +++ b/src/Validation.Runner/App.config @@ -47,7 +47,7 @@ - + diff --git a/tests/Tests.Stats.CollectAzureCdnLogs/app.config b/tests/Tests.Stats.CollectAzureCdnLogs/app.config index e2afa76c2..a3c70b969 100644 --- a/tests/Tests.Stats.CollectAzureCdnLogs/app.config +++ b/tests/Tests.Stats.CollectAzureCdnLogs/app.config @@ -40,7 +40,7 @@ - + diff --git a/tests/Tests.Stats.ImportAzureCdnStatistics/app.config b/tests/Tests.Stats.ImportAzureCdnStatistics/app.config index d1304b781..6ec24bf7a 100644 --- a/tests/Tests.Stats.ImportAzureCdnStatistics/app.config +++ b/tests/Tests.Stats.ImportAzureCdnStatistics/app.config @@ -48,7 +48,7 @@ - + From e7931a02dc65d7117f577d963403fa1f57fa31a0 Mon Sep 17 00:00:00 2001 From: Nikolche Kolev Date: Wed, 21 Feb 2018 17:22:58 -0800 Subject: [PATCH 4/5] Refactor the validator so it doesn't get stuck in a weird state --- .../Job.cs | 26 ++++++++-- .../PackageCompatibilityValidator.cs | 34 +++++++------- .../settings.json | 7 +-- .../PackageCompatibilityValidationMessage.cs | 10 ++-- ...ompatibilityValidationMessageSerializer.cs | 47 ------------------- .../PackageCompatibilityService.cs | 10 +--- .../Properties/AssemblyInfo.cs | 4 +- ...alidation.PackageCompatibility.Core.csproj | 25 +++++----- 8 files changed, 64 insertions(+), 99 deletions(-) delete mode 100644 src/Validation.PackageCompatibility.Core/Messages/PackageCompatibilityValidationMessageSerializer.cs diff --git a/src/NuGet.Services.Validation.Orchestrator/Job.cs b/src/NuGet.Services.Validation.Orchestrator/Job.cs index bd78d131c..e81f36d57 100644 --- a/src/NuGet.Services.Validation.Orchestrator/Job.cs +++ b/src/NuGet.Services.Validation.Orchestrator/Job.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Net; using System.Net.Http; using System.Reflection; @@ -20,6 +19,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; @@ -52,6 +52,7 @@ public class Job : JobBase private const string ServiceBusConfigurationSectionName = "ServiceBus"; private const string SmtpConfigurationSectionName = "Smtp"; private const string EmailConfigurationSectionName = "Email"; + private const string PackageDownloadTimeoutName = "PackageDownloadTimeout"; private const string VcsBindingKey = VcsSectionName; private const string PackageVerificationTopicClientBindingKey = "PackageVerificationTopicClient"; @@ -91,7 +92,7 @@ public override async Task Run() return; } - var runner = GetRequiredService(); + var runner = GetRequiredService(); await runner.RunOrchestrationAsync(); } @@ -213,10 +214,29 @@ private void ConfigureJobServices(IServiceCollection services, IConfigurationRoo ? (IMailSender)new DiskMailSender() : (IMailSender)new MailSender(mailSenderConfiguration); }); + + services.AddSingleton(p => + { + var assembly = Assembly.GetEntryAssembly(); + var assemblyName = assembly.GetName().Name; + var assemblyVersion = assembly.GetCustomAttribute()?.InformationalVersion ?? "0.0.0"; + + var client = new HttpClient(new WebRequestHandler + { + AllowPipelining = true, + AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate), + }); + + client.Timeout = configurationRoot.GetValue(PackageDownloadTimeoutName); + client.DefaultRequestHeaders.Add("User-Agent", $"{assemblyName}/{assemblyVersion}"); + + return client; + }); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddSingleton(new TelemetryClient()); } @@ -354,7 +374,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 +392,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..c8f8d1756 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 ValidationId {ValidationId}", 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 ValidationId {ValidationId}", 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 80d6bb3ac..ed02e2c1e 100644 --- a/src/NuGet.Services.Validation.Orchestrator/settings.json +++ b/src/NuGet.Services.Validation.Orchestrator/settings.json @@ -57,9 +57,9 @@ }, "PackageCompatibility": { "ServiceBus": { - "ConnectionString": "servicebus string", - "TopicPath": "validate-compatibility", - "SubscriptionName": "validate-compatibility" + "ConnectionString": "", + "TopicPath": "", + "SubscriptionName": "" } }, "RunnerConfiguration": { @@ -93,6 +93,7 @@ "AnnouncementsUrl": "https://github.com/NuGet/Announcements/issues", "TwitterUrl": "https://twitter.com/nuget" }, + "PackageDownloadTimeout": "10:00", "KeyVault_VaultName": "", "KeyVault_ClientId": "", "KeyVault_CertificateThumbprint": "", 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 From 11438160f2e9f02466e75b52a2cc2c4bdb2a6ac9 Mon Sep 17 00:00:00 2001 From: Nikolche Kolev Date: Wed, 7 Mar 2018 23:19:24 -0800 Subject: [PATCH 5/5] cleanup the validator to amtch the ew API --- .../PackageCompatibility/PackageCompatibilityValidator.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityValidator.cs b/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityValidator.cs index c8f8d1756..bf5e677a0 100644 --- a/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityValidator.cs +++ b/src/NuGet.Services.Validation.Orchestrator/PackageCompatibility/PackageCompatibilityValidator.cs @@ -44,7 +44,7 @@ public async Task GetResultAsync(IValidationRequest request) return validatorStatus.ToValidationResult(); } - public async Task StartValidationAsync(IValidationRequest request) + public async Task StartAsync(IValidationRequest request) { try { @@ -100,5 +100,10 @@ private async Task Validate(IValidationRequest request, CancellationToken cancel await _packageCompatibilityService.SetPackageCompatibilityState(request.ValidationId, warnings); } } + + public Task CleanUpAsync(IValidationRequest request) + { + return Task.CompletedTask; + } } }