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

Commit

Permalink
Merge pull request #248 from NuGet/dev
Browse files Browse the repository at this point in the history
[RI]: dev to master
  • Loading branch information
agr committed Nov 17, 2017
2 parents 8e86e57 + 1ab205a commit 9722ac9
Show file tree
Hide file tree
Showing 49 changed files with 2,893 additions and 94 deletions.
7 changes: 6 additions & 1 deletion src/NuGet.Jobs.Common/NuGet.Jobs.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,12 @@
<EmbeddedResource Include="Strings.resx" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\build\sign.targets" Condition="Exists('..\..\build\sign.targets')" />
<PropertyGroup>
<SignPath>..\..\build</SignPath>
<SignPath Condition="'$(BUILD_SOURCESDIRECTORY)' != ''">$(BUILD_SOURCESDIRECTORY)\build</SignPath>
<SignPath Condition="'$(NuGetBuildPath)' != ''">$(NuGetBuildPath)</SignPath>
</PropertyGroup>
<Import Project="$(SignPath)\sign.targets" Condition="Exists('$(SignPath)\sign.targets')" />
<Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand Down
11 changes: 8 additions & 3 deletions src/NuGet.Services.Validation.Orchestrator/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<entityFramework codeConfigurationType="NuGetGallery.EntitiesConfiguration, NuGetGallery.Core">
</entityFramework>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,32 @@ namespace NuGet.Services.Validation.Orchestrator
/// </summary>
public class ConfigurationValidator
{
private readonly ValidationConfiguration configuration;
private readonly ValidationConfiguration _configuration;

public ConfigurationValidator(IOptions<ValidationConfiguration> optionsAccessor)
public ConfigurationValidator(IOptionsSnapshot<ValidationConfiguration> optionsAccessor)
{
if (optionsAccessor == null)
{
throw new ArgumentNullException(nameof(optionsAccessor));
}

this.configuration = optionsAccessor.Value ?? throw new ArgumentException("Value property cannot be null", nameof(optionsAccessor));
_configuration = optionsAccessor.Value ?? throw new ArgumentException("Value property cannot be null", nameof(optionsAccessor));
}

/// <summary>
/// Checks if configuration object is valid
/// </summary>
public void Validate()
{
CheckValidationsNumber(configuration.Validations);
CheckValidationsNumber(_configuration.Validations);

CheckPropertyValues(configuration);
CheckPropertyValues(_configuration);

CheckDuplicateValidations(configuration);
CheckDuplicateValidations(_configuration);

CheckUnknownPrerequisites(configuration);
CheckUnknownPrerequisites(_configuration);

CheckPrerequisitesLoops(configuration);
CheckPrerequisitesLoops(_configuration);
}

private static void CheckValidationsNumber(List<ValidationConfigurationItem> validations)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// 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 Autofac;
using Autofac.Builder;

namespace NuGet.Services.Validation.Orchestrator
{
public static class ContainerBuilderExtensions
{
/// <summary>
/// Adds type registration parameter that instructs Autofac to use keyed resolution for a certain constructor parameter type.
/// </summary>
/// <param name="registrationBuilder">Registration builder object returned by <see cref="Autofac.RegistrationExtensions.RegisterType{TImplementer}(ContainerBuilder)"/> call</param>
/// <param name="parameterType">The type of the constructor parameter to use keyed resolution for.</param>
/// <param name="key">The key to use</param>
/// <returns>Registration builder object passed as <paramref name="registrationBuilder"/> to support fluent API</returns>
public static IRegistrationBuilder<TLimit, TReflectionActivatorData, TStyle>
WithKeyedParameter<TLimit, TReflectionActivatorData, TStyle>(this IRegistrationBuilder<TLimit, TReflectionActivatorData, TStyle> registrationBuilder, Type parameterType, string key)
where TReflectionActivatorData : ReflectionActivatorData
{
return registrationBuilder.WithParameter(
(pi, ctx) => pi.ParameterType == parameterType,
(pi, ctx) => ctx.ResolveKeyed(key, parameterType));
}

/// <summary>
/// Registers type with one keyed parameter
/// </summary>
/// <typeparam name="TService">The type to register as</typeparam>
/// <typeparam name="TImplementer">The implementation to register</typeparam>
/// <typeparam name="TKeyedParameter">Keyed parameter type</typeparam>
/// <param name="containerBuilder"><see cref="ContainerBuilder"/> instance</param>
/// <param name="parameterKey">The key to use for keyed parameter</param>
/// <returns>Registration builder object</returns>
public static IRegistrationBuilder<TImplementer, ConcreteReflectionActivatorData, SingleRegistrationStyle>
RegisterTypeWithKeyedParameter<TService, TImplementer, TKeyedParameter>(this ContainerBuilder containerBuilder, string parameterKey)
{
return containerBuilder
.RegisterType<TImplementer>()
.WithKeyedParameter(typeof(TKeyedParameter), parameterKey)
.As<TService>();
}

/// <summary>
/// Registers *keyed* type with one keyed parameter
/// </summary>
/// <typeparam name="TService">The type to register as</typeparam>
/// <typeparam name="TImplementer">The implementation to register</typeparam>
/// <typeparam name="TKeyedParameter">Keyed parameter type</typeparam>
/// <param name="containerBuilder"><see cref="ContainerBuilder"/> instance</param>
/// <param name="typeKey">The key to register type with.</param>
/// <param name="parameterKey">The key to use for keyed parameter</param>
/// <returns>Registration builder object</returns>
public static IRegistrationBuilder<TImplementer, ConcreteReflectionActivatorData, SingleRegistrationStyle>
RegisterKeyedTypeWithKeyedParameter<TService, TImplementer, TKeyedParameter>(this ContainerBuilder containerBuilder, string typeKey, string parameterKey)
{
return containerBuilder
.RegisterType<TImplementer>()
.WithKeyedParameter(typeof(TKeyedParameter), parameterKey)
.Keyed<TService>(typeKey);
}
}
}
2 changes: 2 additions & 0 deletions src/NuGet.Services.Validation.Orchestrator/Error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public static class Error
public static EventId VcsValidationAlreadyStarted = new EventId(3, "VCS validation already started");
public static EventId VcsValidationFailureAuditFound = new EventId(4, "VCS validation failure audit found");
public static EventId VcsValidationUnexpectedAuditFound = new EventId(5, "VCS validation unexpected audit found");
public static EventId OrchestratorOnMessageException = new EventId(6, "Failed to process orchestrator message");
public static EventId UpdatingPackageDbStatusFailed = new EventId(7, "Failed to update package status in DB");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// 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.

namespace NuGet.Services.Validation.Orchestrator
{
public class GalleryDbConfiguration
{
public string ConnectionString { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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;
using NuGetGallery;

namespace NuGet.Services.Validation.Orchestrator
{
/// <summary>
/// Interface for the code that deals with any changes that happened in the validation set
/// </summary>
public interface IValidationOutcomeProcessor
{
/// <summary>
/// Processes the changes in validation statuses:
/// * If there are failed vailidations, marks package as failed;
/// * If all validations succeeded, copies package to public container and marks package as validated;
/// * Otherwise, queues another check for the package
/// </summary>
/// <param name="validationSet">Current state of validation set</param>
/// <param name="package">Package information from Gallery DB</param>
/// <returns>A task that completes when the outcome has been processed</returns>
Task ProcessValidationOutcomeAsync(PackageValidationSet validationSet, Package package);
}
}
Original file line number Diff line number Diff line change
@@ -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;
using NuGetGallery;

namespace NuGet.Services.Validation.Orchestrator
{
/// <summary>
/// Interface for the implementation that resolves the validation dependencies and runs them in proper order
/// </summary>
public interface IValidationSetProcessor
{
/// <summary>
/// Checks the status of all incomplete validations, starts the ones that can be started (due to dependency changes).
/// Persists all validation status changes.
/// </summary>
/// <param name="validationSet">Validation set to work with. Any validation updates would be reflected in that object upon return.</param>
/// <param name="package">Gallery DB package information</param>
/// <returns>Task object representing async operation</returns>
Task ProcessValidationsAsync(PackageValidationSet validationSet, Package package);
}
}
Original file line number Diff line number Diff line change
@@ -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;
using System.Threading.Tasks;
using NuGetGallery;

namespace NuGet.Services.Validation.Orchestrator
{
/// <summary>
/// Provides <see cref="PackageValidationSet"/> instances.
/// </summary>
public interface IValidationSetProvider
{
/// <summary>
/// Reads validation set data from storage, creates one if did not exist in storage
/// </summary>
/// <param name="validationTrackingId">Validation tracking id</param>
/// <param name="package">Package details from Gallery DB</param>
/// <returns><see cref="PackageValidationSet"/> object with information about requested <paramref name="validationTrackingId"/></returns>
Task<PackageValidationSet> GetOrCreateValidationSetAsync(Guid validationTrackingId, Package package);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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;

namespace NuGet.Services.Validation.Orchestrator
{
/// <summary>
/// Abstracts the validation persistence layer
/// </summary>
public interface IValidationStorageService
{
/// <summary>
/// Persists the passed validation set in the storage
/// </summary>
/// <param name="packageValidationSet"><see cref="PackageValidationSet"/> instance to persist.</param>
/// <returns>Persisted object with any default values set by storage and tracked if storage provides change tracking.</returns>
Task<PackageValidationSet> CreateValidationSetAsync(PackageValidationSet packageValidationSet);

/// <summary>
/// Tries to read <see cref="PackageValidationSet"/> from storage by <paramref name="validationTrackingId"/>.
/// </summary>
/// <param name="validationTrackingId">Tracking id of the validation set to read.</param>
/// <returns>Validation set instance if found, null otherwise.</returns>
Task<PackageValidationSet> GetValidationSetAsync(Guid validationTrackingId);

/// <summary>
/// Updates the passed <see cref="PackageValidation"/> with specified validation status,
/// updates the <see cref="PackageValidation.ValidationStatusTimestamp"/>
/// and <see cref="PackageValidation.Started"/> properties to current timestamp, persists changes in the storage.
/// </summary>
/// <param name="packageValidation">Validation object to update, must be an object from the <see cref="PackageValidationSet.PackageValidations"/> collection
/// from an <see cref="PackageValidationSet"/> previously returned by either <see cref="CreateValidationSetAsync(PackageValidationSet)"/>
/// or <see cref="GetValidationSetAsync(Guid)"/> calls.</param>
/// <param name="startedStatus">Validation status to set. Cannot be <see cref="ValidationStatus.NotStarted"/></param>
/// <returns>Task object tracking the async operation status.</returns>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="startedStatus"/> is <see cref="ValidationStatus.NotStarted"/></exception>
Task MarkValidationStartedAsync(PackageValidation packageValidation, ValidationStatus startedStatus);

/// <summary>
/// Updates the passed <see cref="PackageValidation"/> object with specified validation status,
/// updates the <see cref="PackageValidation.ValidationStatusTimestamp"/>
/// property to current timestamp, persists changes in the storage.
/// </summary>
/// <param name="packageValidation">Validation object to update, must be an object from the <see cref="PackageValidationSet.PackageValidations"/> collection
/// from an <see cref="PackageValidationSet"/> previously returned by either <see cref="CreateValidationSetAsync(PackageValidationSet)"/>
/// or <see cref="GetValidationSetAsync(Guid)"/> calls.</param>
/// <param name="validationStatus">Validation status to set.</param>
/// <returns>Task object tracking the async operation status.</returns>
Task UpdateValidationStatusAsync(PackageValidation packageValidation, ValidationStatus validationStatus);
}
}
13 changes: 13 additions & 0 deletions src/NuGet.Services.Validation.Orchestrator/IValidatorProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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.

namespace NuGet.Services.Validation.Orchestrator
{
/// <summary>
/// Interface for the class that provides validator instances by their name
/// </summary>
public interface IValidatorProvider
{
IValidator GetValidator(string validatorName);
}
}
Loading

0 comments on commit 9722ac9

Please sign in to comment.