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

Commit 6a34f74

Browse files
authored
Merge pull request #533 from NuGet/dev
[ReleasePrep][2018.08.13]RI of dev into master
2 parents 37a0839 + 71b2912 commit 6a34f74

143 files changed

Lines changed: 2703 additions & 954 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.

NuGet.Jobs.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Validation.Symbols.Tests",
151151
EndProject
152152
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Validation.Symbols.Core.Tests", "tests\Validation.Symbols.Core.Tests\Validation.Symbols.Core.Tests.csproj", "{9ED642DF-4623-4EB2-8B72-52C6489BF9D6}"
153153
EndProject
154+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NuGet.Jobs.Common.Tests", "tests\NuGet.Jobs.Common.Tests\NuGet.Jobs.Common.Tests.csproj", "{CE96428B-8138-4914-9999-2B391797FFF8}"
155+
EndProject
154156
Global
155157
GlobalSection(SolutionConfigurationPlatforms) = preSolution
156158
Debug|Any CPU = Debug|Any CPU
@@ -399,6 +401,10 @@ Global
399401
{9ED642DF-4623-4EB2-8B72-52C6489BF9D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
400402
{9ED642DF-4623-4EB2-8B72-52C6489BF9D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
401403
{9ED642DF-4623-4EB2-8B72-52C6489BF9D6}.Release|Any CPU.Build.0 = Release|Any CPU
404+
{CE96428B-8138-4914-9999-2B391797FFF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
405+
{CE96428B-8138-4914-9999-2B391797FFF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
406+
{CE96428B-8138-4914-9999-2B391797FFF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
407+
{CE96428B-8138-4914-9999-2B391797FFF8}.Release|Any CPU.Build.0 = Release|Any CPU
402408
EndGlobalSection
403409
GlobalSection(SolutionProperties) = preSolution
404410
HideSolutionNode = FALSE
@@ -464,6 +470,7 @@ Global
464470
{2DD07A73-8C88-4429-BB24-C2813586EF92} = {678D7B14-F8BC-4193-99AF-2EE8AA390A02}
465471
{640D29AB-4D1B-4FC7-AE67-AD12EE5AC503} = {6A776396-02B1-475D-A104-26940ADB04AB}
466472
{9ED642DF-4623-4EB2-8B72-52C6489BF9D6} = {6A776396-02B1-475D-A104-26940ADB04AB}
473+
{CE96428B-8138-4914-9999-2B391797FFF8} = {6A776396-02B1-475D-A104-26940ADB04AB}
467474
EndGlobalSection
468475
GlobalSection(ExtensibilityGlobals) = postSolution
469476
SolutionGuid = {284A7AC3-FB43-4F1F-9C9C-2AF0E1F46C2B}

src/ArchivePackages/ArchivePackages.Job.cs

Lines changed: 36 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@
44
using System;
55
using System.Collections.Generic;
66
using System.ComponentModel.Design;
7-
using System.Diagnostics.Tracing;
7+
using System.Data.SqlClient;
88
using System.Linq;
99
using System.Threading.Tasks;
10+
using Autofac;
1011
using Dapper;
12+
using Microsoft.Extensions.Configuration;
13+
using Microsoft.Extensions.DependencyInjection;
14+
using Microsoft.Extensions.Options;
1115
using Microsoft.WindowsAzure.Storage;
1216
using Microsoft.WindowsAzure.Storage.Blob;
1317
using Newtonsoft.Json.Linq;
1418
using NuGet.Jobs;
15-
using NuGet.Services.KeyVault;
16-
using NuGet.Services.Sql;
19+
using NuGet.Jobs.Configuration;
1720

1821
namespace ArchivePackages
1922
{
20-
public class Job : JobBase
23+
public class Job : JsonConfigurationJob
2124
{
2225
private readonly JobEventSource JobEventSourceLog = JobEventSource.Log;
2326
private const string ContentTypeJson = "application/json";
@@ -27,6 +30,8 @@ public class Job : JobBase
2730
private const string DefaultPackagesArchiveContainerName = "ng-backups";
2831
private const string DefaultCursorBlobName = "cursor.json";
2932

33+
private InitializationConfiguration Configuration { get; set; }
34+
3035
/// <summary>
3136
/// Gets or sets an Azure Storage Uri referring to a container to use as the source for package blobs
3237
/// </summary>
@@ -44,6 +49,7 @@ public class Job : JobBase
4449
/// DestinationContainerName should be same as the primary destination
4550
/// </summary>
4651
public CloudStorageAccount SecondaryDestination { get; set; }
52+
4753
/// <summary>
4854
/// Destination Container name for both Primary and Secondary destinations. Also, for the cursor blob
4955
/// </summary>
@@ -53,8 +59,11 @@ public class Job : JobBase
5359
/// Blob containing the cursor data. Cursor data comprises of cursorDateTime
5460
/// </summary>
5561
public string CursorBlobName { get; set; }
56-
57-
private ISqlConnectionFactory _packageDbConnectionFactory;
62+
63+
/// <summary>
64+
/// Gallery database registration, for diagnostics.
65+
/// </summary>
66+
private SqlConnectionStringBuilder GalleryDatabase { get; set; }
5867

5968
protected CloudBlobContainer SourceContainer { get; private set; }
6069

@@ -66,33 +75,34 @@ public Job() : base(JobEventSource.Log) { }
6675

6776
public override void Init(IServiceContainer serviceContainer, IDictionary<string, string> jobArgsDictionary)
6877
{
69-
var secretInjector = (ISecretInjector)serviceContainer.GetService(typeof(ISecretInjector));
70-
var packageDbConnectionString = JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.PackageDatabase);
71-
_packageDbConnectionFactory = new AzureSqlConnectionFactory(packageDbConnectionString, secretInjector);
78+
base.Init(serviceContainer, jobArgsDictionary);
7279

73-
Source = CloudStorageAccount.Parse(
74-
JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.Source));
80+
Configuration = _serviceProvider.GetRequiredService<IOptionsSnapshot<InitializationConfiguration>>().Value;
7581

76-
PrimaryDestination = CloudStorageAccount.Parse(
77-
JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.PrimaryDestination));
82+
GalleryDatabase = GetDatabaseRegistration<GalleryDbConfiguration>();
7883

79-
var secondaryDestinationCstr = JobConfigurationManager.TryGetArgument(jobArgsDictionary, JobArgumentNames.SecondaryDestination);
80-
SecondaryDestination = string.IsNullOrEmpty(secondaryDestinationCstr) ? null : CloudStorageAccount.Parse(secondaryDestinationCstr);
84+
Source = CloudStorageAccount.Parse(Configuration.Source);
8185

82-
SourceContainerName = JobConfigurationManager.TryGetArgument(jobArgsDictionary, JobArgumentNames.SourceContainerName) ?? DefaultPackagesContainerName;
86+
PrimaryDestination = CloudStorageAccount.Parse(Configuration.PrimaryDestination);
8387

84-
DestinationContainerName = JobConfigurationManager.TryGetArgument(jobArgsDictionary, JobArgumentNames.DestinationContainerName) ?? DefaultPackagesArchiveContainerName;
88+
if (!string.IsNullOrEmpty(Configuration.SecondaryDestination))
89+
{
90+
SecondaryDestination = CloudStorageAccount.Parse(Configuration.SecondaryDestination);
91+
}
92+
93+
SourceContainerName = Configuration.SourceContainerName ?? DefaultPackagesContainerName;
94+
DestinationContainerName = Configuration.DestinationContainerName ?? DefaultPackagesArchiveContainerName;
8595

8696
SourceContainer = Source.CreateCloudBlobClient().GetContainerReference(SourceContainerName);
8797
PrimaryDestinationContainer = PrimaryDestination.CreateCloudBlobClient().GetContainerReference(DestinationContainerName);
8898
SecondaryDestinationContainer = SecondaryDestination?.CreateCloudBlobClient().GetContainerReference(DestinationContainerName);
8999

90-
CursorBlobName = JobConfigurationManager.TryGetArgument(jobArgsDictionary, JobArgumentNames.CursorBlob) ?? DefaultCursorBlobName;
100+
CursorBlobName = Configuration.CursorBlob ?? DefaultCursorBlobName;
91101
}
92102

93103
public override async Task Run()
94104
{
95-
JobEventSourceLog.PreparingToArchive(Source.Credentials.AccountName, SourceContainer.Name, PrimaryDestination.Credentials.AccountName, PrimaryDestinationContainer.Name, _packageDbConnectionFactory.DataSource, _packageDbConnectionFactory.InitialCatalog);
105+
JobEventSourceLog.PreparingToArchive(Source.Credentials.AccountName, SourceContainer.Name, PrimaryDestination.Credentials.AccountName, PrimaryDestinationContainer.Name, GalleryDatabase.DataSource, GalleryDatabase.InitialCatalog);
96106
await Archive(PrimaryDestinationContainer);
97107

98108
// todo: consider reusing package query for primary and secondary archives
@@ -124,9 +134,9 @@ private async Task Archive(CloudBlobContainer destinationContainer)
124134

125135
JobEventSourceLog.CursorData(cursorDateTime.ToString(DateTimeFormatSpecifier));
126136

127-
JobEventSourceLog.GatheringPackagesToArchiveFromDb(_packageDbConnectionFactory.DataSource, _packageDbConnectionFactory.InitialCatalog);
137+
JobEventSourceLog.GatheringPackagesToArchiveFromDb(GalleryDatabase.DataSource, GalleryDatabase.InitialCatalog);
128138
List<PackageRef> packages;
129-
using (var connection = await _packageDbConnectionFactory.CreateAsync())
139+
using (var connection = await OpenSqlConnectionAsync<GalleryDbConfiguration>())
130140
{
131141
packages = (await connection.QueryAsync<PackageRef>(@"
132142
SELECT pr.Id, p.NormalizedVersion AS Version, p.Hash, p.LastEdited, p.Published
@@ -135,7 +145,7 @@ FROM Packages p
135145
WHERE Published > @cursorDateTime OR LastEdited > @cursorDateTime", new { cursorDateTime = cursorDateTime }))
136146
.ToList();
137147
}
138-
JobEventSourceLog.GatheredPackagesToArchiveFromDb(packages.Count, _packageDbConnectionFactory.DataSource, _packageDbConnectionFactory.InitialCatalog);
148+
JobEventSourceLog.GatheredPackagesToArchiveFromDb(packages.Count, GalleryDatabase.DataSource, GalleryDatabase.InitialCatalog);
139149

140150
var archiveSet = packages
141151
.AsParallel()
@@ -193,129 +203,14 @@ private async Task ArchivePackage(string sourceBlobName, string destinationBlobN
193203
JobEventSourceLog.StartedCopy(sourceBlob.Name, destBlob.Name);
194204
}
195205
}
196-
}
197206

198-
[EventSource(Name = "Outercurve-NuGet-Jobs-ArchivePackages")]
199-
public class JobEventSource : EventSource
200-
{
201-
public static readonly JobEventSource Log = new JobEventSource();
202-
203-
private JobEventSource() { }
204-
205-
[Event(
206-
eventId: 1,
207-
Level = EventLevel.Informational,
208-
Message = "Preparing to archive packages from {0}/{1} to primary destination {2}/{3} using package data from {4}/{5}")]
209-
public void PreparingToArchive(string sourceAccount, string sourceContainer, string destAccount, string destContainer, string dbServer, string dbName) { WriteEvent(1, sourceAccount, sourceContainer, destAccount, destContainer, dbServer, dbName); }
210-
211-
[Event(
212-
eventId: 2,
213-
Level = EventLevel.Informational,
214-
Message = "Preparing to archive packages to secondary destination {0}/{1}")]
215-
public void PreparingToArchive2(string destAccount, string destContainer) { WriteEvent(2, destAccount, destContainer); }
216-
217-
[Event(
218-
eventId: 3,
219-
Level = EventLevel.Informational,
220-
Message = "Cursor data: CursorDateTime is {0}")]
221-
public void CursorData(string cursorDateTime) { WriteEvent(3, cursorDateTime); }
222-
223-
[Event(
224-
eventId: 4,
225-
Level = EventLevel.Informational,
226-
Task = Tasks.GatheringDbPackages,
227-
Opcode = EventOpcode.Start,
228-
Message = "Gathering list of packages to archive from {0}/{1}")]
229-
public void GatheringPackagesToArchiveFromDb(string dbServer, string dbName) { WriteEvent(4, dbServer, dbName); }
230-
231-
[Event(
232-
eventId: 5,
233-
Level = EventLevel.Informational,
234-
Task = Tasks.GatheringDbPackages,
235-
Opcode = EventOpcode.Stop,
236-
Message = "Gathered {0} packages to archive from {1}/{2}")]
237-
public void GatheredPackagesToArchiveFromDb(int gathered, string dbServer, string dbName) { WriteEvent(5, gathered, dbServer, dbName); }
238-
239-
[Event(
240-
eventId: 6,
241-
Level = EventLevel.Informational,
242-
Task = Tasks.ArchivingPackages,
243-
Opcode = EventOpcode.Start,
244-
Message = "Starting archive of {0} packages.")]
245-
public void StartingArchive(int count) { WriteEvent(6, count); }
246-
247-
[Event(
248-
eventId: 7,
249-
Level = EventLevel.Informational,
250-
Task = Tasks.ArchivingPackages,
251-
Opcode = EventOpcode.Stop,
252-
Message = "Started archive.")]
253-
public void StartedArchive() { WriteEvent(7); }
254-
255-
[Event(
256-
eventId: 8,
257-
Level = EventLevel.Informational,
258-
Message = "Archive already exists: {0}")]
259-
public void ArchiveExists(string blobName) { WriteEvent(8, blobName); }
260-
261-
[Event(
262-
eventId: 9,
263-
Level = EventLevel.Warning,
264-
Message = "Source Blob does not exist: {0}")]
265-
public void SourceBlobMissing(string blobName) { WriteEvent(9, blobName); }
266-
267-
[Event(
268-
eventId: 12,
269-
Level = EventLevel.Informational,
270-
Task = Tasks.StartingPackageCopy,
271-
Opcode = EventOpcode.Start,
272-
Message = "Starting copy of {0} to {1}.")]
273-
public void StartingCopy(string source, string dest) { WriteEvent(12, source, dest); }
274-
275-
[Event(
276-
eventId: 13,
277-
Level = EventLevel.Informational,
278-
Task = Tasks.StartingPackageCopy,
279-
Opcode = EventOpcode.Stop,
280-
Message = "Started copy of {0} to {1}.")]
281-
public void StartedCopy(string source, string dest) { WriteEvent(13, source, dest); }
282-
283-
[Event(
284-
eventId: 14,
285-
Level = EventLevel.Informational,
286-
Message = "NewCursor data: CursorDateTime is {0}")]
287-
public void NewCursorData(string cursorDateTime) { WriteEvent(14, cursorDateTime); }
288-
}
289-
290-
public static class Tasks
291-
{
292-
public const EventTask GatheringDbPackages = (EventTask)0x1;
293-
public const EventTask ArchivingPackages = (EventTask)0x2;
294-
public const EventTask StartingPackageCopy = (EventTask)0x3;
295-
}
296-
297-
public class PackageRef
298-
{
299-
public PackageRef(string id, string version, string hash)
300-
{
301-
Id = id;
302-
Version = version;
303-
Hash = hash;
304-
}
305-
public PackageRef(string id, string version, string hash, DateTime lastEdited)
306-
: this(id, version, hash)
207+
protected override void ConfigureAutofacServices(ContainerBuilder containerBuilder)
307208
{
308-
LastEdited = lastEdited;
309209
}
310-
public PackageRef(string id, string version, string hash, DateTime lastEdited, DateTime published)
311-
: this(id, version, hash, lastEdited)
210+
211+
protected override void ConfigureJobServices(IServiceCollection services, IConfigurationRoot configurationRoot)
312212
{
313-
Published = published;
213+
ConfigureInitializationSection<InitializationConfiguration>(services, configurationRoot);
314214
}
315-
public string Id { get; set; }
316-
public string Version { get; set; }
317-
public string Hash { get; set; }
318-
public DateTime? LastEdited { get; set; }
319-
public DateTime? Published { get; set; }
320215
}
321216
}

src/ArchivePackages/ArchivePackages.csproj

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,19 @@
4444
<ItemGroup>
4545
<Compile Include="ArchivePackages.Job.cs" />
4646
<Compile Include="ArchivePackages.Program.cs" />
47+
<Compile Include="Configuration\InitializationConfiguration.cs" />
48+
<Compile Include="JobEventSource.cs" />
49+
<Compile Include="JobTasks.cs" />
50+
<Compile Include="PackageRef.cs" />
4751
<Compile Include="Properties\AssemblyInfo.cs" />
4852
</ItemGroup>
4953
<ItemGroup>
50-
<None Include="App.config">
51-
<SubType>Designer</SubType>
52-
</None>
54+
<None Include="App.config" />
5355
<None Include="Scripts\*" />
5456
<None Include="ArchivePackages.nuspec" />
57+
<None Include="Settings\dev.json" />
58+
<None Include="Settings\int.json" />
59+
<None Include="Settings\prod.json" />
5560
</ItemGroup>
5661
<ItemGroup>
5762
<ProjectReference Include="..\NuGet.Jobs.Common\NuGet.Jobs.Common.csproj">
@@ -75,16 +80,14 @@
7580
<PackageReference Include="Newtonsoft.Json">
7681
<Version>9.0.1</Version>
7782
</PackageReference>
78-
<PackageReference Include="NuGet.Services.Sql">
79-
<Version>2.25.0-master-30453</Version>
80-
</PackageReference>
8183
<PackageReference Include="System.Net.Http">
8284
<Version>4.3.3</Version>
8385
</PackageReference>
8486
<PackageReference Include="WindowsAzure.Storage">
8587
<Version>7.1.2</Version>
8688
</PackageReference>
8789
</ItemGroup>
90+
<ItemGroup />
8891
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
8992
<Import Project="..\..\build\sign.targets" Condition="Exists('..\..\build\sign.targets')" />
9093
</Project>

src/ArchivePackages/ArchivePackages.nuspec

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
</metadata>
1212
<files>
1313
<file src="bin\$configuration$\*.*" target="bin"/>
14-
14+
1515
<file src="Scripts\ArchivePackages.cmd" />
16-
16+
1717
<file src="Scripts\Functions.ps1" />
1818
<file src="Scripts\PreDeploy.ps1" />
1919
<file src="Scripts\PostDeploy.ps1" />
2020
<file src="Scripts\nssm.exe" />
21+
22+
<file src="Settings\*.json" target="bin" />
2123
</files>
2224
</package>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 ArchivePackages
5+
{
6+
public class InitializationConfiguration
7+
{
8+
/// <summary>
9+
/// Source storage account.
10+
/// </summary>
11+
public string Source { get; set; }
12+
13+
/// <summary>
14+
/// Source storage container name (defaults to "packages").
15+
/// </summary>
16+
public string SourceContainerName { get; set; }
17+
18+
/// <summary>
19+
/// Primary archive destination.
20+
/// </summary>
21+
public string PrimaryDestination { get; set; }
22+
23+
/// <summary>
24+
/// Secondary archive destination (optional).
25+
/// </summary>
26+
public string SecondaryDestination { get; set; }
27+
28+
/// <summary>
29+
/// Destination storage container name (defaults to "ng-backups").
30+
/// </summary>
31+
public string DestinationContainerName { get; set; }
32+
33+
/// <summary>
34+
/// Cursor blob name (defaults to "cursor.json").
35+
/// </summary>
36+
public string CursorBlob { get; set; }
37+
}
38+
}

0 commit comments

Comments
 (0)