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

Commit f1e4630

Browse files
author
Christy Henriksson
authored
Update Stats.AggregateCdnDownloads to use ISqlConnectionFactory (#424)
1 parent 3c96a78 commit f1e4630

6 files changed

Lines changed: 55 additions & 132 deletions

File tree

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,26 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
55
</startup>
66
<runtime>
77
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
88
<dependentAssembly>
9-
<assemblyIdentity name="Microsoft.ApplicationInsights" publicKeyToken="31bf3856ad364e35" culture="neutral" />
10-
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
9+
<assemblyIdentity name="Microsoft.ApplicationInsights" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
10+
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0"/>
1111
</dependentAssembly>
1212
<dependentAssembly>
13-
<assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
14-
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
13+
<assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
14+
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0"/>
1515
</dependentAssembly>
1616
<dependentAssembly>
17-
<assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
18-
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
17+
<assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
18+
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0"/>
1919
</dependentAssembly>
2020
<dependentAssembly>
21-
<assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
22-
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
23-
</dependentAssembly>
24-
<dependentAssembly>
25-
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
26-
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
27-
</dependentAssembly>
28-
<dependentAssembly>
29-
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory.Platform" publicKeyToken="31bf3856ad364e35" culture="neutral" />
30-
<bindingRedirect oldVersion="0.0.0.0-3.13.4.878" newVersion="3.13.4.878" />
31-
</dependentAssembly>
32-
<dependentAssembly>
33-
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" />
34-
<bindingRedirect oldVersion="0.0.0.0-3.13.4.878" newVersion="3.13.4.878" />
35-
</dependentAssembly>
36-
<dependentAssembly>
37-
<assemblyIdentity name="NuGet.Services.KeyVault" publicKeyToken="31bf3856ad364e35" culture="neutral" />
38-
<bindingRedirect oldVersion="0.0.0.0-2.2.3.0" newVersion="2.2.3.0" />
21+
<assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
22+
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0"/>
3923
</dependentAssembly>
4024
</assemblyBinding>
4125
</runtime>
42-
</configuration>
26+
</configuration>

src/Stats.AggregateCdnDownloadsInGallery/Job.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
using System.Threading.Tasks;
1212
using Microsoft.Extensions.Logging;
1313
using NuGet.Jobs;
14+
using NuGet.Services.KeyVault;
15+
using NuGet.Services.Sql;
1416
using IPackageIdGroup = System.Linq.IGrouping<string, Stats.AggregateCdnDownloadsInGallery.DownloadCountData>;
1517

1618
namespace Stats.AggregateCdnDownloadsInGallery
@@ -53,18 +55,20 @@ GROUP BY Stats.[PackageRegistrationKey]
5355
DROP TABLE #AggregateCdnDownloadsInGallery";
5456

5557
private const string _storedProcedureName = "[dbo].[SelectTotalDownloadCountsPerPackageVersion]";
56-
private SqlConnectionStringBuilder _statisticsDatabase;
57-
private SqlConnectionStringBuilder _destinationDatabase;
58+
private ISqlConnectionFactory _statisticsDbConnectionFactory;
59+
private ISqlConnectionFactory _galleryDbConnectionFactory;
5860
private int _batchSize;
5961
private int _batchSleepSeconds;
6062

6163
public override void Init(IServiceContainer serviceContainer, IDictionary<string, string> jobArgsDictionary)
6264
{
63-
var statisticsDatabaseConnectionString = JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.StatisticsDatabase);
64-
_statisticsDatabase = new SqlConnectionStringBuilder(statisticsDatabaseConnectionString);
65+
var secretInjector = (ISecretInjector)serviceContainer.GetService(typeof(ISecretInjector));
6566

66-
var destinationDatabaseConnectionString = JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.DestinationDatabase);
67-
_destinationDatabase = new SqlConnectionStringBuilder(destinationDatabaseConnectionString);
67+
var statisticsDbConnectionString = JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.StatisticsDatabase);
68+
_statisticsDbConnectionFactory = new AzureSqlConnectionFactory(statisticsDbConnectionString, secretInjector);
69+
70+
var galleryDbConnectionString = JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.DestinationDatabase);
71+
_galleryDbConnectionFactory = new AzureSqlConnectionFactory(galleryDbConnectionString, secretInjector);
6872

6973
_batchSize = JobConfigurationManager.TryGetIntArgument(jobArgsDictionary, JobArgumentNames.BatchSize) ?? _defaultBatchSize;
7074
_batchSleepSeconds = JobConfigurationManager.TryGetIntArgument(jobArgsDictionary, JobArgumentNames.BatchSleepSeconds) ?? _defaultBatchSleepSeconds;
@@ -75,10 +79,10 @@ public override async Task Run()
7579
// Gather download counts data from statistics warehouse
7680
IReadOnlyList<DownloadCountData> downloadData;
7781
Logger.LogInformation("Using batch size {BatchSize} and batch sleep seconds {BatchSleepSeconds}.", _batchSize, _batchSleepSeconds);
78-
Logger.LogInformation("Gathering Download Counts from {DataSource}/{InitialCatalog}...", _statisticsDatabase.DataSource, _statisticsDatabase.InitialCatalog);
82+
Logger.LogInformation("Gathering Download Counts from {DataSource}/{InitialCatalog}...", _statisticsDbConnectionFactory.DataSource, _statisticsDbConnectionFactory.InitialCatalog);
7983
var stopwatch = Stopwatch.StartNew();
8084

81-
using (var statisticsDatabase = await _statisticsDatabase.ConnectTo())
85+
using (var statisticsDatabase = await _statisticsDbConnectionFactory.CreateAsync())
8286
using (var statisticsDatabaseTransaction = statisticsDatabase.BeginTransaction(IsolationLevel.Snapshot))
8387
{
8488
downloadData = (
@@ -102,7 +106,7 @@ await statisticsDatabase.QueryWithRetryAsync<DownloadCountData>(
102106
return;
103107
}
104108

105-
using (var destinationDatabase = await _destinationDatabase.ConnectTo())
109+
using (var destinationDatabase = await _galleryDbConnectionFactory.CreateAsync())
106110
{
107111
// Fetch package registrations so we can match package ID to package registration key.
108112
var packageRegistrationLookup = await GetPackageRegistrations(destinationDatabase);
Lines changed: 23 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -9,8 +9,9 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>Stats.AggregateCdnDownloadsInGallery</RootNamespace>
1111
<AssemblyName>Stats.AggregateCdnDownloadsInGallery</AssemblyName>
12-
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
1415
<TargetFrameworkProfile />
1516
<NuGetPackageImportStamp>
1617
</NuGetPackageImportStamp>
@@ -35,59 +36,14 @@
3536
<WarningLevel>4</WarningLevel>
3637
</PropertyGroup>
3738
<ItemGroup>
38-
<Reference Include="Microsoft.Azure.KeyVault.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
39-
<HintPath>..\..\packages\Microsoft.Azure.KeyVault.Core.1.0.0\lib\net40\Microsoft.Azure.KeyVault.Core.dll</HintPath>
40-
</Reference>
41-
<Reference Include="Microsoft.Data.Edm, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
42-
<HintPath>..\..\packages\Microsoft.Data.Edm.5.7.0\lib\net40\Microsoft.Data.Edm.dll</HintPath>
43-
</Reference>
44-
<Reference Include="Microsoft.Data.OData, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
45-
<HintPath>..\..\packages\Microsoft.Data.OData.5.7.0\lib\net40\Microsoft.Data.OData.dll</HintPath>
46-
</Reference>
47-
<Reference Include="Microsoft.Data.Services.Client, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
48-
<HintPath>..\..\packages\Microsoft.Data.Services.Client.5.7.0\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
49-
</Reference>
50-
<Reference Include="Microsoft.Diagnostics.Tracing.EventSource, Version=1.1.28.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
51-
<HintPath>..\..\packages\Microsoft.Diagnostics.Tracing.EventSource.Redist.1.1.28\lib\net40\Microsoft.Diagnostics.Tracing.EventSource.dll</HintPath>
52-
</Reference>
53-
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
54-
<HintPath>..\..\packages\Microsoft.Extensions.Logging.Abstractions.1.0.0\lib\netstandard1.1\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
55-
</Reference>
56-
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
57-
<HintPath>..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
58-
</Reference>
59-
<Reference Include="Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
60-
<HintPath>..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
61-
</Reference>
62-
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop, Version=1.0.168.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
63-
<HintPath>..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
64-
</Reference>
65-
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
66-
<HintPath>..\..\packages\Microsoft.WindowsAzure.ConfigurationManager.3.2.1\lib\net40\Microsoft.WindowsAzure.Configuration.dll</HintPath>
67-
</Reference>
68-
<Reference Include="Microsoft.WindowsAzure.Storage, Version=7.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
69-
<HintPath>..\..\packages\WindowsAzure.Storage.7.1.2\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
70-
</Reference>
71-
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
72-
<HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
73-
</Reference>
7439
<Reference Include="System" />
7540
<Reference Include="System.ComponentModel.Composition" />
7641
<Reference Include="System.Core" />
7742
<Reference Include="Microsoft.CSharp" />
7843
<Reference Include="System.Data" />
7944
<Reference Include="System.Net" />
8045
<Reference Include="System.Net.Http" />
81-
<Reference Include="System.Net.Http.Extensions, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
82-
<HintPath>..\..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll</HintPath>
83-
</Reference>
84-
<Reference Include="System.Net.Http.Primitives, Version=4.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
85-
<HintPath>..\..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll</HintPath>
86-
</Reference>
8746
<Reference Include="System.Net.Http.WebRequest" />
88-
<Reference Include="System.Spatial, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
89-
<HintPath>..\..\packages\System.Spatial.5.7.0\lib\net40\System.Spatial.dll</HintPath>
90-
</Reference>
9147
<Reference Include="System.Xml" />
9248
</ItemGroup>
9349
<ItemGroup>
@@ -99,7 +55,6 @@
9955
</ItemGroup>
10056
<ItemGroup>
10157
<None Include="App.config" />
102-
<None Include="packages.config" />
10358
<None Include="Scripts\*" />
10459
<None Include="Stats.AggregateCdnDownloadsInGallery.nuspec" />
10560
</ItemGroup>
@@ -109,20 +64,26 @@
10964
<Name>NuGet.Jobs.Common</Name>
11065
</ProjectReference>
11166
</ItemGroup>
67+
<ItemGroup>
68+
<PackageReference Include="Microsoft.Data.Edm">
69+
<Version>5.7.0</Version>
70+
</PackageReference>
71+
<PackageReference Include="Microsoft.Data.OData">
72+
<Version>5.7.0</Version>
73+
</PackageReference>
74+
<PackageReference Include="Microsoft.Data.Services.Client">
75+
<Version>5.7.0</Version>
76+
</PackageReference>
77+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions">
78+
<Version>1.0.0</Version>
79+
</PackageReference>
80+
<PackageReference Include="Newtonsoft.Json">
81+
<Version>9.0.1</Version>
82+
</PackageReference>
83+
<PackageReference Include="NuGet.Services.Sql">
84+
<Version>2.25.0-master-30453</Version>
85+
</PackageReference>
86+
</ItemGroup>
11287
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
11388
<Import Project="..\..\build\sign.targets" Condition="Exists('..\..\build\sign.targets')" />
114-
<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')" />
115-
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
116-
<PropertyGroup>
117-
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
118-
</PropertyGroup>
119-
<Error Condition="!Exists('..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
120-
</Target>
121-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
122-
Other similar extension points exist, see Microsoft.Common.targets.
123-
<Target Name="BeforeBuild">
124-
</Target>
125-
<Target Name="AfterBuild">
126-
</Target>
127-
-->
12889
</Project>

src/Stats.AggregateCdnDownloadsInGallery/packages.config

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
55
</startup>
6-
</configuration>
6+
</configuration>

tests/Tests.Stats.AggregateCdnDownloadsInGallery/Tests.Stats.AggregateCdnDownloadsInGallery.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
<OutputType>Library</OutputType>
99
<RootNamespace>Stats.AggregateCdnDownloadsInGallery</RootNamespace>
1010
<AssemblyName>Tests.Stats.AggregateCdnDownloadsInGallery</AssemblyName>
11-
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
11+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
1212
<FileAlignment>512</FileAlignment>
1313
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<TargetFrameworkProfile />
1415
</PropertyGroup>
1516
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1617
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -55,6 +56,9 @@
5556
<PackageReference Include="xunit">
5657
<Version>2.3.1</Version>
5758
</PackageReference>
59+
<PackageReference Include="xunit.runner.visualstudio">
60+
<Version>2.3.1</Version>
61+
</PackageReference>
5862
</ItemGroup>
5963
<ItemGroup>
6064
<ProjectReference Include="..\..\src\NuGet.Jobs.Common\NuGet.Jobs.Common.csproj">

0 commit comments

Comments
 (0)