Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit 06fda5d

Browse files
author
Scott Bommarito
authored
Merge pull request #552 from NuGet/dev
Status Aggregator Geo-Redundancy Improvements: FI of master into dev
2 parents 23a4ef9 + 241e1c7 commit 06fda5d

60 files changed

Lines changed: 1653 additions & 203 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/NuGet.Jobs.Common/Configuration/JobArgumentNames.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public static class JobArgumentNames
120120

121121
// Arguments specific to StatusAggregator
122122
public const string StatusStorageAccount = "StatusStorageAccount";
123+
public const string StatusStorageAccountSecondary = "StatusStorageAccountSecondary";
123124
public const string StatusContainerName = "StatusContainerName";
124125
public const string StatusTableName = "StatusTableName";
125126
public const string StatusEnvironment = "StatusEnvironment";
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
namespace NuGet.Jobs.Configuration
5+
{
6+
public class SupportRequestDbConfiguration : IDbConfiguration
7+
{
8+
public string ConnectionString { get; set; }
9+
}
10+
}

src/NuGet.Jobs.Common/JsonConfigurationJob.cs

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public abstract class JsonConfigurationJob : JobBase
2626
private const string InitializationConfigurationSectionName = "Initialization";
2727
private const string GalleryDbConfigurationSectionName = "GalleryDb";
2828
private const string StatisticsDbConfigurationSectionName = "StatisticsDb";
29+
private const string SupportRequestDbConfigurationSectionName = "SupportRequestDb";
2930
private const string ValidationDbConfigurationSectionName = "ValidationDb";
3031
private const string ServiceBusConfigurationSectionName = "ServiceBus";
3132
private const string ValidationStorageConfigurationSectionName = "ValidationStorage";
@@ -111,32 +112,28 @@ protected virtual void ConfigureDefaultJobServices(IServiceCollection services,
111112
{
112113
services.Configure<GalleryDbConfiguration>(configurationRoot.GetSection(GalleryDbConfigurationSectionName));
113114
services.Configure<StatisticsDbConfiguration>(configurationRoot.GetSection(StatisticsDbConfigurationSectionName));
115+
services.Configure<SupportRequestDbConfiguration>(configurationRoot.GetSection(SupportRequestDbConfigurationSectionName));
114116
services.Configure<ValidationDbConfiguration>(configurationRoot.GetSection(ValidationDbConfigurationSectionName));
115117
services.Configure<ServiceBusConfiguration>(configurationRoot.GetSection(ServiceBusConfigurationSectionName));
116118
services.Configure<ValidationStorageConfiguration>(configurationRoot.GetSection(ValidationStorageConfigurationSectionName));
117119

118120
services.AddSingleton(new TelemetryClient());
119121
services.AddTransient<ITelemetryClient, TelemetryClientWrapper>();
120122

121-
services.AddScoped<ISqlConnectionFactory<GalleryDbConfiguration>>(p =>
122-
{
123-
return new DelegateSqlConnectionFactory<GalleryDbConfiguration>(
124-
CreateSqlConnectionAsync<GalleryDbConfiguration>,
125-
p.GetRequiredService<ILogger<DelegateSqlConnectionFactory<GalleryDbConfiguration>>>());
126-
});
127-
128-
services.AddScoped<ISqlConnectionFactory<StatisticsDbConfiguration>>(p =>
129-
{
130-
return new DelegateSqlConnectionFactory<StatisticsDbConfiguration>(
131-
CreateSqlConnectionAsync<StatisticsDbConfiguration>,
132-
p.GetRequiredService<ILogger<DelegateSqlConnectionFactory<StatisticsDbConfiguration>>>());
133-
});
123+
AddScopedSqlConnectionFactory<GalleryDbConfiguration>(services);
124+
AddScopedSqlConnectionFactory<StatisticsDbConfiguration>(services);
125+
AddScopedSqlConnectionFactory<SupportRequestDbConfiguration>(services);
126+
AddScopedSqlConnectionFactory<ValidationDbConfiguration>(services);
127+
}
134128

135-
services.AddScoped<ISqlConnectionFactory<ValidationDbConfiguration>>(p =>
129+
private void AddScopedSqlConnectionFactory<TDbConfiguration>(IServiceCollection services)
130+
where TDbConfiguration : IDbConfiguration
131+
{
132+
services.AddScoped<ISqlConnectionFactory<TDbConfiguration>>(p =>
136133
{
137-
return new DelegateSqlConnectionFactory<ValidationDbConfiguration>(
138-
CreateSqlConnectionAsync<ValidationDbConfiguration>,
139-
p.GetRequiredService<ILogger<DelegateSqlConnectionFactory<ValidationDbConfiguration>>>());
134+
return new DelegateSqlConnectionFactory<TDbConfiguration>(
135+
CreateSqlConnectionAsync<TDbConfiguration>,
136+
p.GetRequiredService<ILogger<DelegateSqlConnectionFactory<TDbConfiguration>>>());
140137
});
141138
}
142139

@@ -150,22 +147,19 @@ private void ConfigureLibraries(IServiceCollection services)
150147

151148
protected virtual void RegisterDatabases(IServiceProvider serviceProvider)
152149
{
153-
var galleryDb = serviceProvider.GetRequiredService<IOptionsSnapshot<GalleryDbConfiguration>>();
154-
if (!string.IsNullOrEmpty(galleryDb.Value?.ConnectionString))
155-
{
156-
RegisterDatabase<GalleryDbConfiguration>(serviceProvider);
157-
}
158-
159-
var statisticsDb = serviceProvider.GetRequiredService<IOptionsSnapshot<StatisticsDbConfiguration>>();
160-
if (!string.IsNullOrEmpty(statisticsDb.Value?.ConnectionString))
161-
{
162-
RegisterDatabase<StatisticsDbConfiguration>(serviceProvider);
163-
}
150+
RegisterDatabaseIfConfigured<GalleryDbConfiguration>(serviceProvider);
151+
RegisterDatabaseIfConfigured<StatisticsDbConfiguration>(serviceProvider);
152+
RegisterDatabaseIfConfigured<SupportRequestDbConfiguration>(serviceProvider);
153+
RegisterDatabaseIfConfigured<ValidationDbConfiguration>(serviceProvider);
154+
}
164155

165-
var validationDb = serviceProvider.GetRequiredService<IOptionsSnapshot<ValidationDbConfiguration>>();
166-
if (!string.IsNullOrEmpty(validationDb.Value?.ConnectionString))
156+
private void RegisterDatabaseIfConfigured<TDbConfiguration>(IServiceProvider serviceProvider)
157+
where TDbConfiguration : IDbConfiguration
158+
{
159+
var dbConfiguration = serviceProvider.GetRequiredService<IOptionsSnapshot<TDbConfiguration>>();
160+
if (!string.IsNullOrEmpty(dbConfiguration.Value?.ConnectionString))
167161
{
168-
RegisterDatabase<ValidationDbConfiguration>(serviceProvider);
162+
RegisterDatabase<TDbConfiguration>(serviceProvider);
169163
}
170164
}
171165

src/NuGet.Jobs.Common/NuGet.Jobs.Common.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<Compile Include="Configuration\JobArgumentNames.cs" />
4949
<Compile Include="Configuration\ServiceBusConfiguration.cs" />
5050
<Compile Include="Configuration\StatisticsDbConfiguration.cs" />
51+
<Compile Include="Configuration\SupportRequestDbConfiguration.cs" />
5152
<Compile Include="Configuration\ValidationDbConfiguration.cs" />
5253
<Compile Include="Configuration\ValidationStorageConfiguration.cs" />
5354
<Compile Include="DelegateSqlConnectionFactory.cs" />
@@ -93,13 +94,13 @@
9394
<Version>2.27.0</Version>
9495
</PackageReference>
9596
<PackageReference Include="NuGet.Services.KeyVault">
96-
<Version>2.27.0</Version>
97+
<Version>2.28.0</Version>
9798
</PackageReference>
9899
<PackageReference Include="NuGet.Services.Logging">
99100
<Version>2.27.0</Version>
100101
</PackageReference>
101102
<PackageReference Include="NuGet.Services.Sql">
102-
<Version>2.27.0</Version>
103+
<Version>2.28.0</Version>
103104
</PackageReference>
104105
<PackageReference Include="System.Net.Http">
105106
<Version>4.3.3</Version>

src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,6 @@
137137
<PackageReference Include="AnglicanGeek.MarkdownMailer.StrongName">
138138
<Version>1.2.0</Version>
139139
</PackageReference>
140-
<PackageReference Include="NuGet.Services.Sql">
141-
<Version>2.27.0</Version>
142-
</PackageReference>
143140
<PackageReference Include="NuGet.Services.Validation.Issues">
144141
<Version>2.27.0-master-35351</Version>
145142
</PackageReference>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
namespace NuGet.SupportRequests.Notifications
5+
{
6+
public class InitializationConfiguration
7+
{
8+
/// <summary>
9+
/// Obsolete: replace with IcM configuration
10+
/// </summary>
11+
public string PagerDutyAccountName { get; set; }
12+
13+
/// <summary>
14+
/// Obsolete: replace with IcM configuration
15+
/// </summary>
16+
public string PagerDutyApiKey { get; set; }
17+
18+
/// <summary>
19+
/// SMTP configuration.
20+
/// </summary>
21+
public string SmtpUri { get; set; }
22+
23+
/// <summary>
24+
/// Email address to which the weekly report is sent.
25+
/// </summary>
26+
public string TargetEmailAddress { get; set; }
27+
}
28+
}
Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,50 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using System;
54
using System.Collections.Generic;
65
using System.ComponentModel.Design;
76
using System.Threading.Tasks;
7+
using Autofac;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.DependencyInjection;
10+
using Microsoft.Extensions.Options;
811
using NuGet.Jobs;
12+
using NuGet.Jobs.Configuration;
913

1014
namespace NuGet.SupportRequests.Notifications
1115
{
1216
internal class Job
13-
: JobBase
17+
: JsonConfigurationJob
1418
{
15-
private IServiceContainer _serviceContainer;
16-
private IDictionary<string, string> _jobArgsDictionary;
19+
private InitializationConfiguration _configuration;
20+
private string _taskName;
1721

1822
public override void Init(IServiceContainer serviceContainer, IDictionary<string, string> jobArgsDictionary)
1923
{
20-
if (!jobArgsDictionary.ContainsKey(JobArgumentNames.ScheduledTask))
21-
{
22-
throw new NotSupportedException("The required argument -Task is missing.");
23-
}
24+
base.Init(serviceContainer, jobArgsDictionary);
2425

25-
_serviceContainer = serviceContainer ?? throw new ArgumentNullException(nameof(serviceContainer));
26-
_jobArgsDictionary = jobArgsDictionary;
26+
_taskName = jobArgsDictionary[JobArgumentNames.ScheduledTask];
27+
_configuration = _serviceProvider.GetRequiredService<IOptionsSnapshot<InitializationConfiguration>>().Value;
2728
}
2829

2930
public override async Task Run()
3031
{
31-
var scheduledTask = ScheduledTaskFactory.Create(_serviceContainer, _jobArgsDictionary, LoggerFactory);
32+
var scheduledTask = ScheduledTaskFactory.Create(
33+
_taskName,
34+
_configuration,
35+
OpenSqlConnectionAsync<SupportRequestDbConfiguration>,
36+
LoggerFactory);
3237

3338
await scheduledTask.RunAsync();
3439
}
40+
41+
protected override void ConfigureAutofacServices(ContainerBuilder containerBuilder)
42+
{
43+
}
44+
45+
protected override void ConfigureJobServices(IServiceCollection services, IConfigurationRoot configurationRoot)
46+
{
47+
ConfigureInitializationSection<InitializationConfiguration>(services, configurationRoot);
48+
}
3549
}
3650
}

src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.csproj

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<Reference Include="Microsoft.CSharp" />
4545
</ItemGroup>
4646
<ItemGroup>
47+
<Compile Include="Configuration\InitializationConfiguration.cs" />
4748
<Compile Include="Images.Designer.cs">
4849
<AutoGen>True</AutoGen>
4950
<DesignTime>True</DesignTime>
@@ -95,20 +96,17 @@
9596
</None>
9697
<None Include="Scripts\*" />
9798
<None Include="NuGet.SupportRequests.Notifications.nuspec" />
99+
<None Include="Settings\dev.json" />
100+
<None Include="Settings\int.json" />
101+
<None Include="Settings\prod.json" />
98102
</ItemGroup>
99103
<ItemGroup>
100-
<PackageReference Include="Microsoft.Extensions.Logging">
101-
<Version>1.0.0</Version>
102-
</PackageReference>
103104
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions">
104105
<Version>1.0.0</Version>
105106
</PackageReference>
106107
<PackageReference Include="Newtonsoft.Json">
107108
<Version>9.0.1</Version>
108109
</PackageReference>
109-
<PackageReference Include="NuGet.Services.Sql">
110-
<Version>2.27.0</Version>
111-
</PackageReference>
112110
</ItemGroup>
113111
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
114112
<Import Project="..\..\build\sign.targets" Condition="Exists('..\..\build\sign.targets')" />

src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.nuspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@
1414

1515
<file src="Scripts\OnCallDailyNotification.cmd" />
1616
<file src="Scripts\WeeklySummaryNotification.cmd" />
17+
18+
<file src="Settings\*.json" target="bin" />
1719
</files>
1820
</package>

src/NuGet.SupportRequests.Notifications/ScheduledTaskFactory.cs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using System.Collections.Generic;
6-
using System.ComponentModel.Design;
5+
using System.Data.SqlClient;
6+
using System.Threading.Tasks;
77
using Microsoft.Extensions.Logging;
88

99
namespace NuGet.SupportRequests.Notifications
@@ -12,28 +12,35 @@ internal class ScheduledTaskFactory
1212
{
1313
private const string _tasksNamespace = "NuGet.SupportRequests.Notifications.Tasks";
1414

15-
public static IScheduledTask Create(IServiceContainer serviceContainer, IDictionary<string, string> jobArgsDictionary, ILoggerFactory loggerFactory)
15+
public static IScheduledTask Create(
16+
string scheduledTaskName,
17+
InitializationConfiguration configuration,
18+
Func<Task<SqlConnection>> openSupportRequestSqlConnectionAsync,
19+
ILoggerFactory loggerFactory)
1620
{
17-
if (jobArgsDictionary == null)
21+
if (configuration == null)
1822
{
19-
throw new ArgumentNullException(nameof(jobArgsDictionary));
23+
throw new ArgumentNullException(nameof(configuration));
2024
}
2125

2226
if (loggerFactory == null)
2327
{
2428
throw new ArgumentNullException(nameof(loggerFactory));
2529
}
2630

27-
var scheduledTaskName = jobArgsDictionary[JobArgumentNames.ScheduledTask];
28-
var scheduledTask = GetTaskOfType(scheduledTaskName, serviceContainer, jobArgsDictionary, loggerFactory);
31+
var scheduledTask = GetTaskOfType(
32+
scheduledTaskName,
33+
configuration,
34+
openSupportRequestSqlConnectionAsync,
35+
loggerFactory);
2936

3037
return scheduledTask;
3138
}
3239

3340
private static IScheduledTask GetTaskOfType(
3441
string taskName,
35-
IServiceContainer serviceContainer,
36-
IDictionary<string, string> jobArgsDictionary,
42+
InitializationConfiguration configuration,
43+
Func<Task<SqlConnection>> openSupportRequestSqlConnectionAsync,
3744
ILoggerFactory loggerFactory)
3845
{
3946
if (string.IsNullOrEmpty(taskName))
@@ -51,7 +58,12 @@ private static IScheduledTask GetTaskOfType(
5158
IScheduledTask scheduledTask;
5259
if (scheduledTaskType != null && typeof(IScheduledTask).IsAssignableFrom(scheduledTaskType))
5360
{
54-
var args = new object[] { serviceContainer, jobArgsDictionary, loggerFactory };
61+
var args = new object[] {
62+
configuration,
63+
openSupportRequestSqlConnectionAsync,
64+
loggerFactory
65+
};
66+
5567
scheduledTask = (IScheduledTask)Activator.CreateInstance(scheduledTaskType, args);
5668
}
5769
else

0 commit comments

Comments
 (0)