Skip to content

Commit 05bed12

Browse files
authored
Revert "[pack] Reacting to ScriptHost configuration changes for AzureStorageProvider (#7424)" (#7467)
This reverts commit 80061a7.
1 parent f0a5002 commit 05bed12

File tree

9 files changed

+27
-52
lines changed

9 files changed

+27
-52
lines changed

src/WebJobs.Script/ScriptHostBuilderExtensions.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -454,15 +454,10 @@ private static void AddProcessRegistry(IServiceCollection services)
454454
private static IDistributedLockManager GetBlobLockManager(IServiceProvider provider)
455455
{
456456
var azureStorageProvider = provider.GetRequiredService<IAzureStorageProvider>();
457-
var configuration = provider.GetRequiredService<IConfiguration>();
458457
var loggerFactory = provider.GetRequiredService<ILoggerFactory>();
459458
try
460459
{
461-
// BlobLeaseDistributedLockManager is created during ScriptHost service registration since it is
462-
// conditioned on having a valid storage connection. The configuration should be from the IServiceProvider
463-
// that registers the IDistributedLockManager.
464-
// The configuration used by AzureStorageProvider will be updated through the IScriptHostManager.HostInitializing event handler
465-
var container = azureStorageProvider.GetBlobContainerClient(configuration);
460+
var container = azureStorageProvider.GetBlobContainerClient();
466461
return new BlobLeaseDistributedLockManager(loggerFactory, azureStorageProvider);
467462
}
468463
catch (InvalidOperationException)

src/WebJobs.Script/StorageProvider/AzureStorageProvider.cs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using Azure.Storage.Blobs;
66
using Microsoft.Azure.WebJobs.Script.StorageProvider;
77
using Microsoft.Extensions.Configuration;
8-
using Microsoft.Extensions.DependencyInjection;
98
using Microsoft.Extensions.Logging;
109
using Microsoft.Extensions.Options;
1110

@@ -19,23 +18,16 @@ namespace Microsoft.Azure.WebJobs.Script
1918
internal class AzureStorageProvider : IAzureStorageProvider
2019
{
2120
private readonly BlobServiceClientProvider _blobServiceClientProvider;
22-
private readonly IServiceProvider _serviceProvider;
21+
private readonly IConfiguration _configuration;
22+
private readonly ILogger _logger;
2323
private IOptionsMonitor<JobHostInternalStorageOptions> _storageOptions;
24-
private IConfiguration _configuration;
2524

26-
public AzureStorageProvider(IScriptHostManager scriptHostManager, IConfiguration configuration, BlobServiceClientProvider blobServiceClientProvider, IOptionsMonitor<JobHostInternalStorageOptions> options)
25+
public AzureStorageProvider(IConfiguration configuration, BlobServiceClientProvider blobServiceClientProvider, IOptionsMonitor<JobHostInternalStorageOptions> options, ILogger<AzureStorageProvider> logger)
2726
{
2827
_blobServiceClientProvider = blobServiceClientProvider;
2928
_configuration = configuration;
30-
_serviceProvider = scriptHostManager as IServiceProvider;
3129
_storageOptions = options;
32-
33-
// Every time script host is re-intializing, we also need to re-initialize
34-
// services that change with the scope of the script host.
35-
scriptHostManager.HostInitializing += (s, e) =>
36-
{
37-
InitializeServices();
38-
};
30+
_logger = logger;
3931
}
4032

4133
/// <summary>
@@ -57,30 +49,25 @@ public virtual bool TryGetBlobServiceClientFromConnectionString(out BlobServiceC
5749
/// <param name="client">client to instantiate</param>
5850
/// <param name="connection">Name of the connection to use</param>
5951
/// <returns>successful client creation</returns>
60-
public virtual bool TryGetBlobServiceClientFromConnection(out BlobServiceClient client, string connection = null, IConfiguration configurationOverride = null)
52+
public virtual bool TryGetBlobServiceClientFromConnection(out BlobServiceClient client, string connection = null)
6153
{
6254
var connectionToUse = connection ?? ConnectionStringNames.Storage;
63-
return _blobServiceClientProvider.TryGet(connectionToUse, configurationOverride ?? _configuration, out client);
55+
return _blobServiceClientProvider.TryGet(connectionToUse, out client);
6456
}
6557

66-
public virtual BlobContainerClient GetBlobContainerClient(IConfiguration configurationOverride = null)
58+
public virtual BlobContainerClient GetBlobContainerClient()
6759
{
6860
if (_storageOptions?.CurrentValue.InternalSasBlobContainer != null)
6961
{
7062
return new BlobContainerClient(new Uri(_storageOptions.CurrentValue.InternalSasBlobContainer));
7163
}
7264

73-
if (!TryGetBlobServiceClientFromConnection(out BlobServiceClient blobServiceClient, ConnectionStringNames.Storage, configurationOverride))
65+
if (!TryGetBlobServiceClientFromConnection(out BlobServiceClient blobServiceClient, ConnectionStringNames.Storage))
7466
{
7567
throw new InvalidOperationException($"Could not create BlobServiceClient to obtain the BlobContainerClient using Connection: {ConnectionStringNames.Storage}");
7668
}
7769

7870
return blobServiceClient.GetBlobContainerClient(ScriptConstants.AzureWebJobsHostsContainerName);
7971
}
80-
81-
private void InitializeServices()
82-
{
83-
_configuration = _serviceProvider.GetService<IConfiguration>();
84-
}
8572
}
8673
}

src/WebJobs.Script/StorageProvider/BlobServiceClientProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ namespace Microsoft.Azure.WebJobs.Script.StorageProvider
1616
/// </summary>
1717
internal class BlobServiceClientProvider : StorageClientProvider<BlobServiceClient, BlobClientOptions>
1818
{
19-
public BlobServiceClientProvider(AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder, ILogger<BlobServiceClient> logger)
20-
: base(componentFactory, logForwarder, logger) { }
19+
public BlobServiceClientProvider(IConfiguration configuration, AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder, ILogger<BlobServiceClient> logger)
20+
: base(configuration, componentFactory, logForwarder, logger) { }
2121

2222
/// <inheritdoc/>
2323
protected override string ServiceUriSubDomain

src/WebJobs.Script/StorageProvider/IAzureStorageProvider.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using Azure.Storage.Blobs;
5-
using Microsoft.Extensions.Configuration;
65

76
namespace Microsoft.Azure.WebJobs.Script
87
{
@@ -14,8 +13,8 @@ public interface IAzureStorageProvider
1413
{
1514
bool TryGetBlobServiceClientFromConnectionString(out BlobServiceClient client, string connectionString);
1615

17-
bool TryGetBlobServiceClientFromConnection(out BlobServiceClient client, string connection, IConfiguration configurationOverride = null);
16+
bool TryGetBlobServiceClientFromConnection(out BlobServiceClient client, string connection);
1817

19-
BlobContainerClient GetBlobContainerClient(IConfiguration configurationOverride = null);
18+
BlobContainerClient GetBlobContainerClient();
2019
}
2120
}

src/WebJobs.Script/StorageProvider/StorageClientProvider.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace Microsoft.Azure.WebJobs.Script.StorageProvider
2121
/// </summary>
2222
internal abstract class StorageClientProvider<TClient, TClientOptions> where TClientOptions : ClientOptions
2323
{
24+
private readonly IConfiguration _configuration;
2425
private readonly AzureComponentFactory _componentFactory;
2526
private readonly AzureEventSourceLogForwarder _logForwarder;
2627
private readonly ILogger _logger;
@@ -31,8 +32,9 @@ internal abstract class StorageClientProvider<TClient, TClientOptions> where TCl
3132
/// <param name="configuration">The configuration to use when creating Client-specific objects. <see cref="IConfiguration"/></param>
3233
/// <param name="componentFactory">The Azure factory responsible for creating clients. <see cref="AzureComponentFactory"/></param>
3334
/// <param name="logForwarder">Log forwarder that forwards events to ILogger. <see cref="AzureEventSourceLogForwarder"/></param>
34-
public StorageClientProvider(AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder, ILogger<TClient> logger)
35+
public StorageClientProvider(IConfiguration configuration, AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder, ILogger<TClient> logger)
3536
{
37+
_configuration = configuration;
3638
_componentFactory = componentFactory;
3739
_logForwarder = logForwarder;
3840
_logger = logger;
@@ -51,14 +53,13 @@ public StorageClientProvider(AzureComponentFactory componentFactory, AzureEventS
5153
/// Gets the storage client specified by <paramref name="name"/>
5254
/// </summary>
5355
/// <param name="name">Name of the connection to use</param>
54-
/// <param name="configuration">Configuration to use</param>
5556
/// <param name="client">Client that was created if the connection was valid; otherwise, the default value for the type of <paramref name="client"/>.</param>
5657
/// <returns>true if the client could be created; false otherwise</returns>
57-
public virtual bool TryGet(string name, IConfiguration configuration, out TClient client)
58+
public virtual bool TryGet(string name, out TClient client)
5859
{
5960
try
6061
{
61-
client = Get(name, configuration);
62+
client = Get(name);
6263
return true;
6364
}
6465
catch (Exception ex)
@@ -95,29 +96,27 @@ public virtual bool TryGetFromConnectionString(string connectionString, out TCli
9596
/// </summary>
9697
/// <param name="name">Name of the connection to use</param>
9798
/// <param name="resolver">A resolver to interpret the provided connection <paramref name="name"/>.</param>
98-
/// <param name="configuration">Configuration to use</param>
9999
/// <returns>Client that was created.</returns>
100-
public virtual TClient Get(string name, INameResolver resolver, IConfiguration configuration)
100+
public virtual TClient Get(string name, INameResolver resolver)
101101
{
102102
var resolvedName = resolver.ResolveWholeString(name);
103-
return this.Get(resolvedName, configuration);
103+
return this.Get(resolvedName);
104104
}
105105

106106
/// <summary>
107107
/// Gets the storage client specified by <paramref name="name"/>
108108
/// </summary>
109109
/// <param name="name">Name of the connection to use</param>
110-
/// <param name="configuration">Configuration to use</param>
111110
/// <returns>Client that was created.</returns>
112-
public virtual TClient Get(string name, IConfiguration configuration)
111+
public virtual TClient Get(string name)
113112
{
114113
if (string.IsNullOrWhiteSpace(name))
115114
{
116115
name = ConnectionStringNames.Storage; // default
117116
}
118117

119118
// $$$ Where does validation happen?
120-
IConfigurationSection connectionSection = configuration.GetWebJobsConnectionStringSection(name);
119+
IConfigurationSection connectionSection = _configuration.GetWebJobsConnectionStringSection(name);
121120
if (!connectionSection.Exists())
122121
{
123122
// Not found
@@ -149,7 +148,7 @@ protected virtual TClient CreateClient(IConfiguration configuration, TokenCreden
149148
/// <returns>Storage client</returns>
150149
public virtual TClient GetHost()
151150
{
152-
return this.Get(null, null);
151+
return this.Get(null);
153152
}
154153

155154
/// <summary>

test/WebJobs.Script.Tests.Integration/Host/SingletonTests/SingletonEndToEndTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
using Newtonsoft.Json.Linq;
2626
using Xunit;
2727
using Microsoft.Azure.WebJobs.Host;
28-
using Microsoft.WebJobs.Script.Tests;
2928

3029
namespace Microsoft.Azure.WebJobs.Script.Tests.Integration.Host.SingletonTests
3130
{
@@ -656,7 +655,6 @@ private IHost CreateTestJobHost<TProg>(int hostId, Action<IHostBuilder> extraCon
656655
});
657656

658657
services.AddSingleton<IDistributedLockManager, BlobLeaseDistributedLockManager>();
659-
TestHostBuilderExtensions.AddMockedSingleton<IScriptHostManager>(services);
660658
services.AddAzureStorageProvider();
661659
});
662660

test/WebJobs.Script.Tests.Integration/ScriptHostEndToEnd/FunctionGeneratorEndToEndTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using Microsoft.Extensions.DependencyInjection;
1212
using Microsoft.Extensions.Hosting;
1313
using Microsoft.Extensions.Logging;
14-
using Microsoft.WebJobs.Script.Tests;
1514
using Xunit;
1615

1716
namespace Microsoft.Azure.WebJobs.Script.Tests
@@ -70,7 +69,7 @@ public async Task Generate_EndToEnd()
7069
{
7170
s.AddSingleton<ITypeLocator>(new TestTypeLocator(functionType));
7271
s.AddSingleton<ILoggerFactory>(new LoggerFactory());
73-
TestHostBuilderExtensions.AddMockedSingleton<IScriptHostManager>(s);
72+
7473
s.AddAzureStorageProvider();
7574
});
7675

test/WebJobs.Script.Tests.Integration/Storage/BlobStorageProviderTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ public BlobStorageProviderTests()
3636
[Fact]
3737
public async Task TestBlobStorageProvider_TryConnectionName()
3838
{
39-
Assert.True(_blobServiceClientProvider.TryGet(StorageConnection, _configuration, out BlobServiceClient client));
39+
Assert.True(_blobServiceClientProvider.TryGet(StorageConnection, out BlobServiceClient client));
4040
await VerifyServiceAvailable(client);
4141
}
4242

4343
[Fact]
4444
public async Task TestBlobStorageProvider_ConnectionName()
4545
{
46-
BlobServiceClient client = _blobServiceClientProvider.Get(StorageConnection, _configuration);
46+
BlobServiceClient client = _blobServiceClientProvider.Get(StorageConnection);
4747
await VerifyServiceAvailable(client);
4848
}
4949

@@ -52,7 +52,7 @@ public async Task TestBlobStorageProvider_ConnectionNameWithResolver()
5252
{
5353
var resolver = new DefaultNameResolver(_configuration);
5454

55-
BlobServiceClient client = _blobServiceClientProvider.Get(StorageConnection, resolver, _configuration);
55+
BlobServiceClient client = _blobServiceClientProvider.Get(StorageConnection, resolver);
5656
await VerifyServiceAvailable(client);
5757
}
5858

test/WebJobs.Script.Tests.Shared/TestHelpers.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
using Microsoft.Extensions.DependencyInjection;
2121
using Microsoft.Extensions.Hosting;
2222
using Microsoft.Extensions.Options;
23-
using Microsoft.WebJobs.Script.Tests;
2423

2524
namespace Microsoft.Azure.WebJobs.Script.Tests
2625
{
@@ -408,7 +407,6 @@ public static IAzureStorageProvider GetAzureStorageProvider(IConfiguration confi
408407
{
409408
// Override configuration
410409
services.AddSingleton(configuration);
411-
TestHostBuilderExtensions.AddMockedSingleton<IScriptHostManager>(services);
412410
services.AddAzureStorageProvider();
413411
if (storageOptions != null)
414412
{

0 commit comments

Comments
 (0)