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

Migrate Gallery.Maintenance to JsonConfig #516

Merged
merged 2 commits into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Gallery.Maintenance/DeleteExpiredVerificationKeysTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading.Tasks;
using Gallery.Maintenance.Models;
using Microsoft.Extensions.Logging;
using NuGet.Jobs.Configuration;

namespace Gallery.Maintenance
{
Expand Down Expand Up @@ -37,7 +38,7 @@ public override async Task RunAsync(Job job)
{
IEnumerable<PackageVerificationKey> expiredKeys;

using (var connection = await job.GalleryDatabase.CreateAsync())
using (var connection = await job.OpenSqlConnectionAsync<GalleryDbConfiguration>())
{
expiredKeys = await connection.QueryWithRetryAsync<PackageVerificationKey>(
SelectQuery,
Expand All @@ -59,7 +60,7 @@ public override async Task RunAsync(Job job)

if (expectedRowCount > 0)
{
using (var connection = await job.GalleryDatabase.CreateAsync())
using (var connection = await job.OpenSqlConnectionAsync<GalleryDbConfiguration>())
{
using (var transaction = connection.BeginTransaction())
{
Expand Down
6 changes: 3 additions & 3 deletions src/Gallery.Maintenance/Gallery.Maintenance.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
<SubType>Designer</SubType>
</None>
<None Include="Scripts\*" />
<None Include="Settings\dev.json" />
<None Include="Settings\int.json" />
<None Include="Settings\prod.json" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NuGet.Jobs.Common\NuGet.Jobs.Common.csproj">
Expand All @@ -67,9 +70,6 @@
<PackageReference Include="Newtonsoft.Json">
<Version>9.0.1</Version>
</PackageReference>
<PackageReference Include="NuGet.Services.Sql">
<Version>2.27.0</Version>
</PackageReference>
<PackageReference Include="System.Net.Http">
<Version>4.3.3</Version>
</PackageReference>
Expand Down
2 changes: 2 additions & 0 deletions src/Gallery.Maintenance/Gallery.Maintenance.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@
<file src="Scripts\PreDeploy.ps1" />
<file src="Scripts\PostDeploy.ps1" />
<file src="Scripts\nssm.exe" />

<file src="Settings\*.json" target="bin" />
</files>
</package>
28 changes: 12 additions & 16 deletions src/Gallery.Maintenance/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,21 @@

using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using Autofac;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NuGet.Jobs;
using NuGet.Services.KeyVault;
using NuGet.Services.Sql;

namespace Gallery.Maintenance
{
/// <summary>
/// Runs all <see cref="MaintenanceTask"/>s against the Gallery database.
/// </summary>
public class Job : JobBase
public class Job : JsonConfigurationJob
{

public ISqlConnectionFactory GalleryDatabase { get; private set; }

public override void Init(IServiceContainer serviceContainer, IDictionary<string, string> jobArgsDictionary)
{
var secretInjector = (ISecretInjector)serviceContainer.GetService(typeof(ISecretInjector));
var databaseConnectionString = JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.GalleryDatabase);

GalleryDatabase = new AzureSqlConnectionFactory(databaseConnectionString, secretInjector);
}

public override async Task Run()
{
var failedTasks = new List<string>();
Expand Down Expand Up @@ -88,5 +76,13 @@ public ILogger CreateTypedLogger(Type type)
.MakeGenericMethod(type)
.Invoke(null, new object[] { LoggerFactory }) as ILogger;
}

protected override void ConfigureAutofacServices(ContainerBuilder containerBuilder)
{
}

protected override void ConfigureJobServices(IServiceCollection services, IConfigurationRoot configurationRoot)
{
}
}
}
2 changes: 1 addition & 1 deletion src/Gallery.Maintenance/Scripts/Gallery.Maintenance.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cd bin

title #{Jobs.Gallery.Maintenance.Title}

start /w Gallery.Maintenance.exe -VaultName "#{Deployment.Azure.KeyVault.VaultName}" -ClientId "#{Deployment.Azure.KeyVault.ClientId}" -CertificateThumbprint "#{Deployment.Azure.KeyVault.CertificateThumbprint}" -GalleryDatabase "#{Jobs.Gallery.Maintenance.GalleryDatabase}" -InstrumentationKey "#{Jobs.Gallery.Maintenance.InstrumentationKey}" -verbose true -Interval #{Jobs.Gallery.Maintenance.Interval}
start /w Gallery.Maintenance.exe -Configuration "#{Jobs.gallery.maintenance.Configuration}" -InstrumentationKey "#{Jobs.gallery.maintenance.InstrumentationKey}" -Interval #{Jobs.gallery.maintenance.Interval}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move everything but -Configuration to the JSON?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As part of the SQL work, the only requirement is to get connection strings into source control... to allow testing from private branch and easy rollback w/ history. Since I'm touching the job, I chose to also move job configuration to the JSON config.

I've left JobRunner configuration as-is for now. I can tackle it when I start working on job deployment updates.


echo "Finished #{Jobs.Gallery.Maintenance.Title}"

Expand Down
12 changes: 12 additions & 0 deletions src/Gallery.Maintenance/Settings/dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"GalleryDb": {
"ConnectionString": "Data Source=tcp:#{Deployment.Azure.Sql.GalleryDatabaseAddress};Initial Catalog=nuget-dev-0-v2gallery;User ID=$$Dev-GalleryDBWriter-UserName$$;Password=$$Dev-GalleryDBWriter-Password$$;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
},

"KeyVault_VaultName": "#{Deployment.Azure.KeyVault.VaultName}",
"KeyVault_ClientId": "#{Deployment.Azure.KeyVault.ClientId}",
"KeyVault_CertificateThumbprint": "#{Deployment.Azure.KeyVault.CertificateThumbprint}",
"KeyVault_ValidateCertificate": true,
"KeyVault_StoreName": "My",
"KeyVault_StoreLocation": "LocalMachine"
}
12 changes: 12 additions & 0 deletions src/Gallery.Maintenance/Settings/int.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"GalleryDb": {
"ConnectionString": "Data Source=tcp:#{Deployment.Azure.Sql.GalleryDatabaseAddress};Initial Catalog=nuget-int-0-v2gallery;User ID=$$Int-GalleryDBWriter-UserName$$;Password=$$Int-GalleryDBWriter-Password$$;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
},

"KeyVault_VaultName": "#{Deployment.Azure.KeyVault.VaultName}",
"KeyVault_ClientId": "#{Deployment.Azure.KeyVault.ClientId}",
"KeyVault_CertificateThumbprint": "#{Deployment.Azure.KeyVault.CertificateThumbprint}",
"KeyVault_ValidateCertificate": true,
"KeyVault_StoreName": "My",
"KeyVault_StoreLocation": "LocalMachine"
}
12 changes: 12 additions & 0 deletions src/Gallery.Maintenance/Settings/prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"GalleryDb": {
"ConnectionString": "Data Source=tcp:#{Deployment.Azure.Sql.GalleryDatabaseAddress};Initial Catalog=NuGetGallery;User ID=$$Prod-GalleryDBWriter-UserName$$;Password=$$Prod-GalleryDBWriter-Password$$;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
},

"KeyVault_VaultName": "#{Deployment.Azure.KeyVault.VaultName}",
"KeyVault_ClientId": "#{Deployment.Azure.KeyVault.ClientId}",
"KeyVault_CertificateThumbprint": "#{Deployment.Azure.KeyVault.CertificateThumbprint}",
"KeyVault_ValidateCertificate": true,
"KeyVault_StoreName": "My",
"KeyVault_StoreLocation": "LocalMachine"
}