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 #586 from NuGet/dev
Browse files Browse the repository at this point in the history
[ReleasePrep][2018.10.15]RI of dev into master
  • Loading branch information
chenriksson authored Oct 16, 2018
2 parents 373495c + 6a65f27 commit 899fb8d
Show file tree
Hide file tree
Showing 182 changed files with 8,734 additions and 1,549 deletions.
2 changes: 1 addition & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ param (
[string]$SemanticVersion = '1.0.0-zlocal',
[string]$Branch = 'zlocal',
[string]$CommitSHA,
[string]$BuildBranch = 'c35bbc228717720bdbc610f3285259391635e90e'
[string]$BuildBranch = '80b8f1b4a1cfe57367881e59fca063866dcaaa42'
)

$msBuildVersion = 15;
Expand Down
26 changes: 14 additions & 12 deletions src/Gallery.Maintenance/DeleteExpiredVerificationKeysTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,21 @@ public override async Task RunAsync(Job job)
if (expectedRowCount > 0)
{
using (var connection = await job.OpenSqlConnectionAsync<GalleryDbConfiguration>())
using (var transaction = connection.BeginTransaction())
using (var command = connection.CreateCommand())
{
using (var transaction = connection.BeginTransaction())
{
var numKeys = 0;
var parameters = credentialKeys.Select(c => new SqlParameter("@Key" + numKeys++, SqlDbType.Int) { Value = c }).ToArray();

rowCount = await connection.ExecuteAsync(
string.Format(DeleteQuery, string.Join(",", parameters.Select(p => p.ParameterName))),
parameters,
transaction, _commandTimeout);

transaction.Commit();
}
var numKeys = 0;
var parameters = credentialKeys.Select(c => new SqlParameter("@Key" + numKeys++, SqlDbType.Int) { Value = c }).ToArray();
command.Parameters.AddRange(parameters);

command.CommandText = string.Format(DeleteQuery, string.Join(",", parameters.Select(p => p.ParameterName)));
command.CommandType = CommandType.Text;
command.CommandTimeout = (int)_commandTimeout.TotalSeconds;
command.Transaction = transaction;

rowCount = await command.ExecuteNonQueryAsync();

transaction.Commit();
}
}

Expand Down
24 changes: 0 additions & 24 deletions src/NuGet.Jobs.Common/Extensions/DapperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,6 @@ namespace System.Data.SqlClient
{
public static class DapperExtensions
{
public static Task<int> ExecuteAsync(this SqlConnection connection, string sql, SqlParameter[] parameters = null, SqlTransaction transaction = null, TimeSpan? commandTimeout = null)
{
SqlCommand cmd = connection.CreateCommand();
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;

if (parameters != null)
{
cmd.Parameters.AddRange(parameters);
}

if (commandTimeout.HasValue)
{
cmd.CommandTimeout = (int)commandTimeout.Value.TotalSeconds;
}

if (transaction != null)
{
cmd.Transaction = transaction;
}

return cmd.ExecuteNonQueryAsync();
}

public static async Task<IEnumerable<T>> QueryWithRetryAsync<T>(
this SqlConnection connection,
string sql,
Expand Down
4 changes: 2 additions & 2 deletions src/NuGet.Jobs.Common/NuGet.Jobs.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@
<Version>2.27.0</Version>
</PackageReference>
<PackageReference Include="NuGet.Services.KeyVault">
<Version>2.28.0</Version>
<Version>2.29.0</Version>
</PackageReference>
<PackageReference Include="NuGet.Services.Logging">
<Version>2.27.0</Version>
</PackageReference>
<PackageReference Include="NuGet.Services.Sql">
<Version>2.28.0</Version>
<Version>2.29.0</Version>
</PackageReference>
<PackageReference Include="System.Net.Http">
<Version>4.3.3</Version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="NuGet.Services.Status">
<Version>2.27.0</Version>
<Version>2.29.0</Version>
</PackageReference>
<PackageReference Include="NuGet.Services.Storage">
<Version>2.27.0</Version>
<Version>2.29.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
10 changes: 5 additions & 5 deletions src/NuGet.Services.Validation.Orchestrator/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ private static void ConfigureOrchestratorSymbolTypes(IServiceCollection services
services.AddTransient<IValidationSetProvider<SymbolPackage>, ValidationSetProvider<SymbolPackage>>();
services.AddTransient<IMessageService<SymbolPackage>, SymbolsPackageMessageService>();
services.AddTransient<IBrokeredMessageSerializer<SymbolsValidatorMessage>, SymbolsValidatorMessageSerializer>();
services.AddTransient<IBrokeredMessageSerializer<SymbolsIngesterMessage>, SymbolsIngesterMessageSerializer>();
services.AddTransient<ISymbolsValidationEntitiesService, SymbolsValidationEntitiesService>();
}

Expand Down Expand Up @@ -653,25 +654,24 @@ private static void ConfigureSymbolsIngester(ContainerBuilder builder)
.Keyed<ITopicClient>(SymbolsIngesterBindingKey);

builder
.RegisterType<SymbolsMessageEnqueuer>()
.RegisterType<SymbolsIngesterMessageEnqueuer>()
.WithKeyedParameter(typeof(ITopicClient), SymbolsIngesterBindingKey)
.WithParameter(
(pi, ctx) => pi.ParameterType == typeof(TimeSpan?),
(pi, ctx) => ctx.Resolve<IOptionsSnapshot<SymbolsIngesterConfiguration>>().Value.MessageDelay)
.Keyed<ISymbolsMessageEnqueuer>(SymbolsIngesterBindingKey)
.As<ISymbolsMessageEnqueuer>();
.Keyed<ISymbolsIngesterMessageEnqueuer>(SymbolsIngesterBindingKey)
.As<ISymbolsIngesterMessageEnqueuer>();

builder
.RegisterType<SymbolsIngester>()
.WithKeyedParameter(typeof(IValidatorStateService), SymbolsIngesterBindingKey)
.WithKeyedParameter(typeof(ISymbolsMessageEnqueuer), SymbolsIngesterBindingKey)
.WithKeyedParameter(typeof(ISymbolsIngesterMessageEnqueuer), SymbolsIngesterBindingKey)
.AsSelf();
}

private T GetRequiredService<T>()
{
return _serviceProvider.GetRequiredService<T>();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<Compile Include="Error.cs" />
<Compile Include="Services\MessageServiceConfiguration.cs" />
<Compile Include="Services\SymbolsMessageService.cs" />
<Compile Include="Symbols\ISymbolsIngesterMessageEnqueuer.cs" />
<Compile Include="Symbols\SymbolScanOnlyConfiguration.cs" />
<Compile Include="Symbols\SymbolCriteriaEvaluator.cs" />
<Compile Include="Symbols\SymbolScanValidator.cs" />
Expand All @@ -62,6 +63,7 @@
<Compile Include="IPackageStatusProcessor.cs" />
<Compile Include="Services\SymbolEntityService.cs" />
<Compile Include="Symbols\ISymbolsMessageEnqueuer.cs" />
<Compile Include="Symbols\SymbolsIngesterMessageEnqueuer.cs" />
<Compile Include="Symbols\SymbolsMessageEnqueuer.cs" />
<Compile Include="Symbols\SymbolsIngesterConfiguration.cs" />
<Compile Include="Symbols\SymbolsIngester.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -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 System.Threading.Tasks;
using NuGet.Jobs.Validation.Symbols.Core;

namespace NuGet.Services.Validation.Symbols
{
public interface ISymbolsIngesterMessageEnqueuer
{
/// <summary>
/// Enqueues a message to one of the topics used by the Symbol Ingester.
/// </summary>
/// <param name="request">The validation request.</param>
/// <returns>A <see cref="Task"/> that will be completed when the execution is completed.</returns>
Task<SymbolsIngesterMessage> EnqueueSymbolsIngestionMessageAsync(IValidationRequest request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ namespace NuGet.Services.Validation.Symbols
public class SymbolsIngester : BaseValidator, IValidator
{
private readonly ISymbolsValidationEntitiesService _symbolsValidationEntitiesService;
private readonly ISymbolsMessageEnqueuer _symbolMessageEnqueuer;
private readonly ISymbolsIngesterMessageEnqueuer _symbolMessageEnqueuer;
private readonly ITelemetryService _telemetryService;
private readonly ILogger<SymbolsIngester> _logger;

public SymbolsIngester(
ISymbolsValidationEntitiesService symbolsValidationEntitiesService,
ISymbolsMessageEnqueuer symbolMessageEnqueuer,
ISymbolsIngesterMessageEnqueuer symbolMessageEnqueuer,
ITelemetryService telemetryService,
ILogger<SymbolsIngester> logger)
{
Expand All @@ -40,11 +40,12 @@ public async Task<IValidationResult> GetResultAsync(IValidationRequest request)

var result = SymbolsValidationEntitiesService.ConvertToIValidationResult(await _symbolsValidationEntitiesService.GetSymbolsServerRequestAsync(request));
_logger.LogInformation(
"Symbols status {Status} for PackageId: {PackageId}, PackageNormalizedVersion {PackageNormalizedVersion}, SymbolsPackageKey {SymbolsPackageKey} ",
"Symbols status {Status} for PackageId: {PackageId}, PackageNormalizedVersion {PackageNormalizedVersion}, SymbolsPackageKey {SymbolsPackageKey} ValidationId {ValidationId}",
result.Status,
request.PackageId,
request.PackageVersion,
request.PackageKey);
request.PackageKey,
request.ValidationId);

return result;
}
Expand Down Expand Up @@ -78,9 +79,9 @@ public async Task<IValidationResult> StartAsync(IValidationRequest request)
}

_telemetryService.TrackSymbolsMessageEnqueued(ValidatorName.SymbolsIngester, request.ValidationId);
await _symbolMessageEnqueuer.EnqueueSymbolsValidationMessageAsync(request);
var message = await _symbolMessageEnqueuer.EnqueueSymbolsIngestionMessageAsync(request);

var newSymbolsRequest = SymbolsValidationEntitiesService.CreateFromValidationRequest(request, SymbolsPackageIngestRequestStatus.Ingesting);
var newSymbolsRequest = SymbolsValidationEntitiesService.CreateFromValidationRequest(request, SymbolsPackageIngestRequestStatus.Ingesting, message.RequestName);
var savedSymbolRequest = await _symbolsValidationEntitiesService.AddSymbolsServerRequestAsync(newSymbolsRequest);

if(savedSymbolRequest.RequestStatusKey != SymbolsPackageIngestRequestStatus.Ingesting)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 Microsoft.Extensions.Options;
using NuGet.Jobs.Validation.Symbols.Core;
using NuGet.Services.ServiceBus;

namespace NuGet.Services.Validation.Symbols
{
public class SymbolsIngesterMessageEnqueuer : ISymbolsIngesterMessageEnqueuer
{
private readonly ITopicClient _topicClient;
private readonly TimeSpan? _messageDelay;
private readonly IBrokeredMessageSerializer<SymbolsIngesterMessage> _serializer;

public SymbolsIngesterMessageEnqueuer(
ITopicClient topicClient,
IBrokeredMessageSerializer<SymbolsIngesterMessage> serializer,
TimeSpan? messageDelay)
{
_topicClient = topicClient ?? throw new ArgumentNullException(nameof(topicClient));
_serializer = serializer ?? throw new ArgumentNullException(nameof(serializer));
_messageDelay = messageDelay;
}

public async Task<SymbolsIngesterMessage> EnqueueSymbolsIngestionMessageAsync(IValidationRequest request)
{
var message = new SymbolsIngesterMessage(validationId: request.ValidationId,
symbolPackageKey: request.PackageKey,
packageId: request.PackageId,
packageNormalizedVersion: request.PackageVersion,
snupkgUrl: request.NupkgUrl,
requestName : SymbolsValidationEntitiesService.CreateSymbolServerRequestNameFromValidationRequest(request));
var brokeredMessage = _serializer.Serialize(message);

var visibleAt = DateTimeOffset.UtcNow + (_messageDelay ?? TimeSpan.Zero);
brokeredMessage.ScheduledEnqueueTimeUtc = visibleAt;

await _topicClient.SendAsync(brokeredMessage);
return message;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ internal abstract class SupportRequestsNotificationScheduledTask<TNotification>
: IScheduledTask
where TNotification : INotification
{
private InitializationConfiguration _configuration;

private readonly SupportRequestRepository _supportRequestRepository;
private readonly MessagingService _messagingService;

Expand Down
6 changes: 6 additions & 0 deletions src/NuGetCDNRedirect/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// 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.Diagnostics.CodeAnalysis;

[module: SuppressMessage("Microsoft.Security.Web.Configuration", "CA3103:EnableFormsRequireSSL", Justification = "Forms authentication is not used, and this project is obsolete (Engineering#1737).")]
1 change: 1 addition & 0 deletions src/NuGetCDNRedirect/NuGetCDNRedirect.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\AssemblyInfo.*.cs" />
</ItemGroup>
Expand Down
4 changes: 1 addition & 3 deletions src/Search.GenerateAuxiliaryData/NestedJArrayExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -34,8 +33,7 @@ public NestedJArrayExporter(

protected override JContainer GetResultOfQuery(SqlConnection connection)
{
var command = new SqlCommand(GetEmbeddedSqlScript(SqlScript), connection);
command.CommandType = CommandType.Text;
var command = GetEmbeddedSqlCommand(connection, SqlScript);

return SqlDataReaderToNestedJArrays(command.ExecuteReader(), Col0, Col1);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Search.GenerateAuxiliaryData/RankingsExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public RankingsExporter(

protected override JContainer GetResultOfQuery(SqlConnection connection)
{
var rankingsTotalCommand = new SqlCommand(GetEmbeddedSqlScript(_rankingsTotalScript), connection);
rankingsTotalCommand.CommandType = CommandType.Text;
var rankingsTotalCommand = GetEmbeddedSqlCommand(connection, _rankingsTotalScript);
rankingsTotalCommand.Parameters.AddWithValue(_rankingCountParameterName, _rankingCount);
rankingsTotalCommand.CommandTimeout = 60;

Expand Down
15 changes: 12 additions & 3 deletions src/Search.GenerateAuxiliaryData/SqlExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
Expand Down Expand Up @@ -34,10 +35,18 @@ public SqlExporter(
OpenSqlConnectionAsync = openSqlConnectionAsync;
}

protected static string GetEmbeddedSqlScript(string resourceName)
[SuppressMessage("Microsoft.Security", "CA2100", Justification = "Query string comes from embedded resource, not user input.")]
protected static SqlCommand GetEmbeddedSqlCommand(SqlConnection connection, string resourceName)
{
var stream = _executingAssembly.GetManifestResourceStream(_assemblyName + "." + resourceName);
return new StreamReader(stream).ReadToEnd();
using (var reader = new StreamReader(_executingAssembly.GetManifestResourceStream(_assemblyName + "." + resourceName)))
{
var commandText = reader.ReadToEnd();

return new SqlCommand(commandText, connection)
{
CommandType = CommandType.Text
};
}
}

public override async Task ExportAsync()
Expand Down
3 changes: 1 addition & 2 deletions src/Search.GenerateAuxiliaryData/VerifiedPackagesExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public VerifiedPackagesExporter(

protected override JContainer GetResultOfQuery(SqlConnection connection)
{
var verifiedPackagesCommand = new SqlCommand(GetEmbeddedSqlScript(_verifiedPackagesScript), connection);
verifiedPackagesCommand.CommandType = CommandType.Text;
var verifiedPackagesCommand = GetEmbeddedSqlCommand(connection, _verifiedPackagesScript);
verifiedPackagesCommand.CommandTimeout = 60;

SqlDataReader reader = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,14 @@ private async Task ProcessBatch(List<IPackageIdGroup> batch, SqlConnection desti
{
// Create a temporary table
Logger.LogDebug("Creating temporary table...");
await destinationDatabase.ExecuteAsync(_createTempTable);

using (var cmd = destinationDatabase.CreateCommand())
{
cmd.CommandText = _createTempTable;
cmd.CommandType = CommandType.Text;

await cmd.ExecuteNonQueryAsync();
}

// Load temporary table
var aggregateCdnDownloadsInGalleryTable = new DataTable();
Expand Down Expand Up @@ -206,8 +213,14 @@ private async Task ProcessBatch(List<IPackageIdGroup> batch, SqlConnection desti
Logger.LogInformation("Updating destination database Download Counts... ({RecordCount} package registrations to process).", batch.Count());
stopwatch.Restart();

await destinationDatabase.ExecuteAsync(_updateFromTempTable,
commandTimeout: TimeSpan.FromMinutes(30));
using (var cmd = destinationDatabase.CreateCommand())
{
cmd.CommandText = _updateFromTempTable;
cmd.CommandType = CommandType.Text;
cmd.CommandTimeout = (int)TimeSpan.FromMinutes(30).TotalSeconds;

await cmd.ExecuteNonQueryAsync();
}

Logger.LogInformation(
"Updated destination database Download Counts (took {DurationSeconds} seconds).",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<Version>9.0.1</Version>
</PackageReference>
<PackageReference Include="NuGet.Services.Sql">
<Version>2.28.0</Version>
<Version>2.29.0</Version>
</PackageReference>
<PackageReference Include="UAParser">
<Version>1.2.0</Version>
Expand Down
Loading

0 comments on commit 899fb8d

Please sign in to comment.