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
Move auxiliary file client to a shared location (#583)
Browse files Browse the repository at this point in the history
AuxiliaryFileClient is currently only used by search service. Now it will be used by Auxiliary2AzureSearch as well.
Progress on NuGet/NuGetGallery#6447
  • Loading branch information
joelverhagen committed Jul 10, 2019
1 parent 0a2bcec commit 728578d
Show file tree
Hide file tree
Showing 20 changed files with 50 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/NuGet.Jobs.Auxiliary2AzureSearch/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
using Autofac;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using NuGet.Services.AzureSearch;
using NuGet.Services.AzureSearch.Auxiliary2AzureSearch;
using NuGet.Services.AzureSearch.AuxiliaryFiles;

namespace NuGet.Jobs
{
Expand Down Expand Up @@ -35,6 +37,8 @@ protected override void ConfigureJobServices(IServiceCollection services, IConfi
services.AddAzureSearch();

services.Configure<Auxiliary2AzureSearchConfiguration>(configurationRoot.GetSection(ConfigurationSectionName));
services.AddTransient<IOptionsSnapshot<IAuxiliaryDataStorageConfiguration>>(
p => p.GetRequiredService<IOptionsSnapshot<Auxiliary2AzureSearchConfiguration>>());
services.Configure<AzureSearchJobConfiguration>(configurationRoot.GetSection(ConfigurationSectionName));
services.Configure<AzureSearchConfiguration>(configurationRoot.GetSection(ConfigurationSectionName));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// 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 NuGet.Services.AzureSearch.AuxiliaryFiles;

namespace NuGet.Services.AzureSearch.Auxiliary2AzureSearch
{
public class Auxiliary2AzureSearchConfiguration : AzureSearchJobConfiguration
public class Auxiliary2AzureSearchConfiguration : AzureSearchJobConfiguration, IAuxiliaryDataStorageConfiguration
{
public string AuxiliaryDataStorageConnectionString { get; set; }
public string AuxiliaryDataStorageContainer { get; set; }
public string AuxiliaryDataStorageDownloadsPath { get; set; }
public string AuxiliaryDataStorageVerifiedPackagesPath { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
using NuGet.Indexing;
using NuGetGallery;

namespace NuGet.Services.AzureSearch.SearchService
namespace NuGet.Services.AzureSearch.AuxiliaryFiles
{
public class AuxiliaryFileClient : IAuxiliaryFileClient
{
private readonly ICloudBlobClient _cloudBlobClient;
private readonly IOptionsSnapshot<SearchServiceConfiguration> _options;
private readonly IOptionsSnapshot<IAuxiliaryDataStorageConfiguration> _options;
private readonly IAzureSearchTelemetryService _telemetryService;
private readonly ILogger<AuxiliaryFileClient> _logger;
private readonly Lazy<ICloudBlobContainer> _lazyContainer;

public AuxiliaryFileClient(
ICloudBlobClient cloudBlobClient,
IOptionsSnapshot<SearchServiceConfiguration> options,
IOptionsSnapshot<IAuxiliaryDataStorageConfiguration> options,
IAzureSearchTelemetryService telemetryService,
ILogger<AuxiliaryFileClient> logger)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using Newtonsoft.Json;

namespace NuGet.Services.AzureSearch.SearchService
namespace NuGet.Services.AzureSearch.AuxiliaryFiles
{
public class AuxiliaryFileMetadata
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;

namespace NuGet.Services.AzureSearch.SearchService
namespace NuGet.Services.AzureSearch.AuxiliaryFiles
{
public class AuxiliaryFileResult<T> where T : class
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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.

namespace NuGet.Services.AzureSearch.AuxiliaryFiles
{
public interface IAuxiliaryDataStorageConfiguration
{
string AuxiliaryDataStorageConnectionString { get; }
string AuxiliaryDataStorageContainer { get; }
string AuxiliaryDataStorageDownloadsPath { get; }
string AuxiliaryDataStorageVerifiedPackagesPath { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Threading.Tasks;
using NuGet.Indexing;

namespace NuGet.Services.AzureSearch.SearchService
namespace NuGet.Services.AzureSearch.AuxiliaryFiles
{
public interface IAuxiliaryFileClient
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using NuGet.Protocol.Catalog;
using NuGet.Protocol.Registration;
using NuGet.Services.AzureSearch.Auxiliary2AzureSearch;
using NuGet.Services.AzureSearch.AuxiliaryFiles;
using NuGet.Services.AzureSearch.Catalog2AzureSearch;
using NuGet.Services.AzureSearch.Db2AzureSearch;
using NuGet.Services.AzureSearch.Owners2AzureSearch;
Expand Down Expand Up @@ -181,7 +182,7 @@ private static void RegisterAuxiliaryDataStorageServices(ContainerBuilder contai
containerBuilder
.Register<ICloudBlobClient>(c =>
{
var options = c.Resolve<IOptionsSnapshot<SearchServiceConfiguration>>();
var options = c.Resolve<IOptionsSnapshot<IAuxiliaryDataStorageConfiguration>>();
return new CloudBlobClientWrapper(
options.Value.AuxiliaryDataStorageConnectionString,
readAccessGeoRedundant: true);
Expand All @@ -191,7 +192,7 @@ private static void RegisterAuxiliaryDataStorageServices(ContainerBuilder contai
containerBuilder
.Register<IAuxiliaryFileClient>(c => new AuxiliaryFileClient(
c.ResolveKeyed<ICloudBlobClient>(key),
c.Resolve<IOptionsSnapshot<SearchServiceConfiguration>>(),
c.Resolve<IOptionsSnapshot<IAuxiliaryDataStorageConfiguration>>(),
c.Resolve<IAzureSearchTelemetryService>(),
c.Resolve<ILogger<AuxiliaryFileClient>>()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<Compile Include="Analysis\PackageIdCustomTokenizer.cs" />
<Compile Include="Auxiliary2AzureSearch\Auxiliary2AzureSearchCommand.cs" />
<Compile Include="Auxiliary2AzureSearch\Auxiliary2AzureSearchConfiguration.cs" />
<Compile Include="AuxiliaryFiles\IAuxiliaryDataStorageConfiguration.cs" />
<Compile Include="AzureSearchScoringConfiguration.cs" />
<Compile Include="BaseDocumentBuilder.cs" />
<Compile Include="DatabaseOwnerFetcher.cs" />
Expand All @@ -71,7 +72,7 @@
<Compile Include="DurationMeasurement.cs" />
<Compile Include="Analysis\ExactMatchCustomAnalyzer.cs" />
<Compile Include="SearchService\AuxiliaryDataCache.cs" />
<Compile Include="SearchService\AuxiliaryFileClient.cs" />
<Compile Include="AuxiliaryFiles\AuxiliaryFileClient.cs" />
<Compile Include="SearchService\AuxiliaryFileReloader.cs" />
<Compile Include="AzureSearchConfiguration.cs" />
<Compile Include="AzureSearchJobConfiguration.cs" />
Expand Down Expand Up @@ -127,9 +128,9 @@
<Compile Include="Registration\RegistrationUrlBuilder.cs" />
<Compile Include="SearchDocumentBuilder.cs" />
<Compile Include="SearchService\AuxiliaryData.cs" />
<Compile Include="SearchService\AuxiliaryFileResult.cs" />
<Compile Include="AuxiliaryFiles\AuxiliaryFileResult.cs" />
<Compile Include="SearchService\IAuxiliaryDataCache.cs" />
<Compile Include="SearchService\IAuxiliaryFileClient.cs" />
<Compile Include="AuxiliaryFiles\IAuxiliaryFileClient.cs" />
<Compile Include="SearchService\IAuxiliaryFileReloader.cs" />
<Compile Include="SearchService\ISearchStatusService.cs" />
<Compile Include="SearchService\ISearchTextBuilder.cs" />
Expand All @@ -138,7 +139,7 @@
<Compile Include="SearchService\Models\AutocompleteRequest.cs" />
<Compile Include="SearchService\Models\AutocompleteResponse.cs" />
<Compile Include="SearchService\Models\AutocompleteRequestType.cs" />
<Compile Include="SearchService\Models\AuxiliaryFileMetadata.cs" />
<Compile Include="AuxiliaryFiles\AuxiliaryFileMetadata.cs" />
<Compile Include="SearchService\Models\AuxiliaryFilesMetadata.cs" />
<Compile Include="SearchService\AzureSearchService.cs" />
<Compile Include="SearchService\IAuxiliaryData.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using NuGet.Indexing;
using NuGet.Services.AzureSearch.AuxiliaryFiles;

namespace NuGet.Services.AzureSearch.SearchService
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using NuGet.Services.AzureSearch.AuxiliaryFiles;

namespace NuGet.Services.AzureSearch.SearchService
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using Newtonsoft.Json;
using NuGet.Services.AzureSearch.AuxiliaryFiles;

namespace NuGet.Services.AzureSearch.SearchService
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using NuGet.Services.AzureSearch.AuxiliaryFiles;

namespace NuGet.Services.AzureSearch.SearchService
{
public class SearchServiceConfiguration : AzureSearchConfiguration
public class SearchServiceConfiguration : AzureSearchConfiguration, IAuxiliaryDataStorageConfiguration
{
public string SemVer1RegistrationsBaseUrl { get; set; }
public string SemVer2RegistrationsBaseUrl { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions src/NuGet.Services.SearchService/App_Start/WebApiConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using NuGet.Services.AzureSearch;
using NuGet.Services.AzureSearch.AuxiliaryFiles;
using NuGet.Services.AzureSearch.SearchService;
using NuGet.Services.Configuration;
using NuGet.Services.KeyVault;
Expand Down Expand Up @@ -139,6 +140,8 @@ private static AutofacWebApiDependencyResolver GetDependencyResolver(HttpConfigu
services.Add(ServiceDescriptor.Scoped(typeof(IOptionsSnapshot<>), typeof(NonCachingOptionsSnapshot<>)));
services.Configure<AzureSearchConfiguration>(configurationRoot.GetSection(ConfigurationSectionName));
services.Configure<SearchServiceConfiguration>(configurationRoot.GetSection(ConfigurationSectionName));
services.AddScoped<IOptionsSnapshot<IAuxiliaryDataStorageConfiguration>>(
p => p.GetRequiredService<IOptionsSnapshot<SearchServiceConfiguration>>());
services.AddAzureSearch();
services.AddSingleton(new TelemetryClient());
services.AddTransient<ITelemetryClient, TelemetryClientWrapper>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Moq;
using NuGet.Services.AzureSearch.SearchService;
using NuGet.Services.AzureSearch.Support;
using NuGetGallery;
using Xunit;
using Xunit.Abstractions;

namespace NuGet.Services.AzureSearch.SearchService
namespace NuGet.Services.AzureSearch.AuxiliaryFiles
{
public class AuxiliaryFileClientFacts
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<Compile Include="Registration\RegistrationClientFacts.cs" />
<Compile Include="SearchService\AuxiliaryDataCacheFacts.cs" />
<Compile Include="SearchService\AuxiliaryDataFacts.cs" />
<Compile Include="SearchService\AuxiliaryFileClientFacts.cs" />
<Compile Include="AuxiliaryFiles\AuxiliaryFileClientFacts.cs" />
<Compile Include="SearchService\AuxiliaryFileReloaderFacts.cs" />
<Compile Include="SearchService\AzureSearchServiceFacts.cs" />
<Compile Include="SearchService\SearchParametersBuilderFacts.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using Moq;
using NuGet.Indexing;
using NuGet.Services.AzureSearch.AuxiliaryFiles;
using NuGet.Services.AzureSearch.Support;
using Xunit;
using Xunit.Abstractions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using NuGet.Indexing;
using NuGet.Services.AzureSearch.AuxiliaryFiles;
using Xunit;

namespace NuGet.Services.AzureSearch.SearchService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Moq;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using NuGet.Services.AzureSearch.AuxiliaryFiles;
using NuGet.Services.AzureSearch.Support;
using NuGet.Versioning;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.Azure.Search.Models;
using Microsoft.Extensions.Options;
using Moq;
using NuGet.Services.AzureSearch.AuxiliaryFiles;
using NuGet.Services.AzureSearch.Support;
using NuGet.Services.AzureSearch.Wrappers;
using Xunit;
Expand Down

0 comments on commit 728578d

Please sign in to comment.