Skip to content

Commit 90438d3

Browse files
committed
Add legion host identifier
Backport #8617
1 parent 0f4efba commit 90438d3

27 files changed

+142
-63
lines changed

src/WebJobs.Script.WebHost/Configuration/CorsOptionsSetup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public CorsOptionsSetup(IEnvironment env, IOptions<HostCorsOptions> hostCorsOpti
2323

2424
public void Configure(CorsOptions options)
2525
{
26-
if (_env.IsLinuxConsumption())
26+
if (_env.IsAnyLinuxConsumption())
2727
{
2828
string[] allowedOrigins = _hostCorsOptions.Value.AllowedOrigins?.ToArray() ?? Array.Empty<string>();
2929
var policyBuilder = new CorsPolicyBuilder(allowedOrigins);

src/WebJobs.Script.WebHost/Configuration/ScriptApplicationHostOptionsSetup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private bool IsZipDeployment(out bool isScmRunFromPackage)
7676
Utility.IsValidZipSetting(_environment.GetEnvironmentVariable(AzureWebsiteAltZipDeployment)) ||
7777
Utility.IsValidZipSetting(_environment.GetEnvironmentVariable(AzureWebsiteRunFromPackage));
7878

79-
if (!_environment.IsLinuxConsumption())
79+
if (!_environment.IsAnyLinuxConsumption())
8080
{
8181
isScmRunFromPackage = false;
8282
// This check is strong enough for SKUs other than Linux Consumption.

src/WebJobs.Script.WebHost/ContainerManagement/LinuxContainerActivityPublisher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public LinuxContainerActivityPublisher(IOptionsMonitor<StandbyOptions> standbyOp
3838
IMeshServiceClient meshServiceClient, IEnvironment environment,
3939
ILogger<LinuxContainerActivityPublisher> logger, int flushIntervalMs = FlushIntervalMs, int initialFlushIntervalMs = InitialFlushIntervalMs)
4040
{
41-
if (!environment.IsLinuxConsumption())
41+
if (!environment.IsAnyLinuxConsumption())
4242
{
4343
throw new NotSupportedException(
4444
$"{nameof(LinuxContainerActivityPublisher)} is available in Linux consumption environment only");

src/WebJobs.Script.WebHost/ContainerManagement/LinuxContainerInitializationHostService.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ public async Task StartAsync(CancellationToken cancellationToken)
3636
_cancellationToken = cancellationToken;
3737

3838
// The service should be registered in Linux Consumption only, but do additional check here.
39-
if (_environment.IsLinuxConsumption())
39+
if (_environment.IsLinuxConsumptionOnAtlas())
4040
{
4141
await ApplyStartContextIfPresent();
4242
}
43+
else if (_environment.IsLinuxConsumptionOnLegion())
44+
{
45+
_logger.LogInformation("Container has (re)started. Waiting for specialization");
46+
}
4347
}
4448

4549
private async Task ApplyStartContextIfPresent()

src/WebJobs.Script.WebHost/Management/FunctionsSyncManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ internal static bool IsSyncTriggersEnvironment(IScriptWebHostEnvironment webHost
213213

214214
// Windows (Dedicated/Consumption)
215215
// Linux Consumption
216-
if ((environment.IsWindowsAzureManagedHosting() || environment.IsLinuxConsumption()) &&
216+
if ((environment.IsWindowsAzureManagedHosting() || environment.IsAnyLinuxConsumption()) &&
217217
!environment.IsContainerReady())
218218
{
219219
// container ready flag not set yet – site not fully specialized/initialized

src/WebJobs.Script.WebHost/Middleware/HostWarmupMiddleware.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public async Task WarmupInvoke(HttpContext httpContext)
5656
if (!_jitTraceHasRun)
5757
{
5858
PreJitPrepare(WarmUpConstants.JitTraceFileName);
59-
if (_environment.IsLinuxConsumption())
59+
if (_environment.IsAnyLinuxConsumption())
6060
{
6161
PreJitPrepare(WarmUpConstants.LinuxJitTraceFileName);
6262
}
@@ -146,7 +146,7 @@ public async Task WarmUp(HttpRequest request)
146146
public static bool IsWarmUpRequest(HttpRequest request, bool inStandbyMode, IEnvironment environment)
147147
{
148148
return inStandbyMode
149-
&& ((environment.IsAppService() && request.IsAppServiceInternalRequest(environment)) || environment.IsLinuxConsumption())
149+
&& ((environment.IsAppService() && request.IsAppServiceInternalRequest(environment)) || environment.IsAnyLinuxConsumption())
150150
&& (request.Path.StartsWithSegments(_warmupRoutePath) || request.Path.StartsWithSegments(_warmupRouteAlternatePath));
151151
}
152152
}

src/WebJobs.Script.WebHost/Program.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args = null)
6666
config.Add(new WebScriptHostConfigurationSource
6767
{
6868
IsAppServiceEnvironment = SystemEnvironment.Instance.IsAppService(),
69-
IsLinuxContainerEnvironment = SystemEnvironment.Instance.IsLinuxConsumption(),
69+
IsLinuxContainerEnvironment = SystemEnvironment.Instance.IsAnyLinuxConsumption(),
7070
IsLinuxAppServiceEnvironment = SystemEnvironment.Instance.IsLinuxAppService()
7171
});
7272
})
@@ -86,10 +86,15 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args = null)
8686
/// </summary>
8787
private static void InitializeProcess()
8888
{
89-
if (SystemEnvironment.Instance.IsLinuxConsumption())
89+
if (SystemEnvironment.Instance.IsLinuxConsumptionOnAtlas())
9090
{
9191
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledExceptionInLinuxConsumption;
9292
}
93+
else if (SystemEnvironment.Instance.IsLinuxConsumptionOnLegion())
94+
{
95+
//todo: Replace with legion specific logger.
96+
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledExceptionInLinuxConsumption;
97+
}
9398
else if (SystemEnvironment.Instance.IsLinuxAppService())
9499
{
95100
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledExceptionInLinuxAppService;

src/WebJobs.Script.WebHost/Security/KeyManagement/DefaultKeyValueConverterFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public DefaultKeyValueConverterFactory(bool allowEncryption)
2424
private static bool IsEncryptionSupported()
2525
{
2626
return SystemEnvironment.Instance.IsAppService() ||
27-
SystemEnvironment.Instance.IsLinuxConsumption() ||
27+
SystemEnvironment.Instance.IsAnyLinuxConsumption() ||
2828
SystemEnvironment.Instance.GetEnvironmentVariable(AzureWebsiteLocalEncryptionKey) != null;
2929
}
3030

src/WebJobs.Script.WebHost/WebHostServiceCollectionExtensions.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,15 @@ public static void AddWebJobsScriptHost(this IServiceCollection services, IConfi
9797
services.AddSingleton<IEventGenerator>(p =>
9898
{
9999
var environment = p.GetService<IEnvironment>();
100-
if (environment.IsLinuxConsumption())
100+
if (environment.IsLinuxConsumptionOnAtlas())
101101
{
102102
return new LinuxContainerEventGenerator(environment);
103103
}
104+
else if (environment.IsLinuxConsumptionOnLegion())
105+
{
106+
//todo: Replace with legion specific logger
107+
return new LinuxContainerEventGenerator(environment);
108+
}
104109
else if (SystemEnvironment.Instance.IsLinuxAppService())
105110
{
106111
var hostNameProvider = p.GetService<HostNameProvider>();
@@ -205,7 +210,8 @@ private static void AddLinuxContainerServices(this IServiceCollection services)
205210
services.AddSingleton<IHostedService>(s =>
206211
{
207212
var environment = s.GetService<IEnvironment>();
208-
if (environment.IsLinuxConsumption())
213+
//todo: Replace with legion specific service
214+
if (environment.IsAnyLinuxConsumption())
209215
{
210216
var instanceManager = s.GetService<IInstanceManager>();
211217
var logger = s.GetService<ILogger<LinuxContainerInitializationHostService>>();
@@ -233,7 +239,7 @@ private static void AddLinuxContainerServices(this IServiceCollection services)
233239
services.AddSingleton<IMeshServiceClient>(s =>
234240
{
235241
var environment = s.GetService<IEnvironment>();
236-
if (environment.IsLinuxConsumption())
242+
if (environment.IsAnyLinuxConsumption())
237243
{
238244
var httpClient = s.GetService<HttpClient>();
239245
var logger = s.GetService<ILogger<MeshServiceClient>>();
@@ -246,7 +252,7 @@ private static void AddLinuxContainerServices(this IServiceCollection services)
246252
services.AddSingleton<LinuxContainerActivityPublisher>(s =>
247253
{
248254
var environment = s.GetService<IEnvironment>();
249-
if (environment.IsLinuxConsumption())
255+
if (environment.IsAnyLinuxConsumption())
250256
{
251257
var logger = s.GetService<ILogger<LinuxContainerActivityPublisher>>();
252258
var meshInitServiceClient = s.GetService<IMeshServiceClient>();
@@ -260,7 +266,7 @@ private static void AddLinuxContainerServices(this IServiceCollection services)
260266
services.AddSingleton<IHostedService>(s =>
261267
{
262268
var environment = s.GetService<IEnvironment>();
263-
if (environment.IsLinuxConsumption())
269+
if (environment.IsAnyLinuxConsumption())
264270
{
265271
return s.GetRequiredService<LinuxContainerActivityPublisher>();
266272
}
@@ -271,7 +277,7 @@ private static void AddLinuxContainerServices(this IServiceCollection services)
271277
services.AddSingleton<ILinuxContainerActivityPublisher>(s =>
272278
{
273279
var environment = s.GetService<IEnvironment>();
274-
if (environment.IsLinuxConsumption())
280+
if (environment.IsAnyLinuxConsumption())
275281
{
276282
return s.GetRequiredService<LinuxContainerActivityPublisher>();
277283
}

src/WebJobs.Script.WebHost/WebJobsApplicationBuilderExtension.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static IApplicationBuilder UseWebJobsScriptHost(this IApplicationBuilder
3232
builder.UseMiddleware<HttpRequestBodySizeMiddleware>();
3333
builder.UseMiddleware<SystemTraceMiddleware>();
3434
builder.UseMiddleware<HostnameFixupMiddleware>();
35-
if (environment.IsLinuxConsumption())
35+
if (environment.IsAnyLinuxConsumption())
3636
{
3737
builder.UseMiddleware<EnvironmentReadyCheckMiddleware>();
3838
}
@@ -64,7 +64,7 @@ public static IApplicationBuilder UseWebJobsScriptHost(this IApplicationBuilder
6464
// JobHost/ScriptHost scoped services.
6565
builder.UseMiddleware<ScriptHostRequestServiceProviderMiddleware>();
6666

67-
if (environment.IsLinuxConsumption())
67+
if (environment.IsAnyLinuxConsumption())
6868
{
6969
builder.UseMiddleware<AppServiceHeaderFixupMiddleware>();
7070
}

0 commit comments

Comments
 (0)