Skip to content

Commit 7b828af

Browse files
committed
Add legion host identifier
Subsequent PRs will customize different services as required. Scope of this PR is to add a way to check if container is running on a Legion host.
1 parent 91e0d11 commit 7b828af

27 files changed

+135
-62
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
@@ -37,10 +37,14 @@ public async Task StartAsync(CancellationToken cancellationToken)
3737
_cancellationToken = cancellationToken;
3838

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

4650
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
@@ -214,7 +214,7 @@ internal static bool IsSyncTriggersEnvironment(IScriptWebHostEnvironment webHost
214214

215215
// Windows (Dedicated/Consumption)
216216
// Linux Consumption
217-
if ((environment.IsWindowsAzureManagedHosting() || environment.IsLinuxConsumption()) &&
217+
if ((environment.IsWindowsAzureManagedHosting() || environment.IsAnyLinuxConsumption()) &&
218218
!environment.IsContainerReady())
219219
{
220220
// 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
}
@@ -147,7 +147,7 @@ public async Task WarmUp(HttpRequest request)
147147
public static bool IsWarmUpRequest(HttpRequest request, bool inStandbyMode, IEnvironment environment)
148148
{
149149
return inStandbyMode
150-
&& ((environment.IsAppService() && request.IsAppServiceInternalRequest(environment)) || environment.IsLinuxConsumption())
150+
&& ((environment.IsAppService() && request.IsAppServiceInternalRequest(environment)) || environment.IsAnyLinuxConsumption())
151151
&& (request.Path.StartsWithSegments(_warmupRoutePath) || request.Path.StartsWithSegments(_warmupRouteAlternatePath));
152152
}
153153
}

src/WebJobs.Script.WebHost/Program.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args = null)
6767
config.Add(new WebScriptHostConfigurationSource
6868
{
6969
IsAppServiceEnvironment = SystemEnvironment.Instance.IsAppService(),
70-
IsLinuxContainerEnvironment = SystemEnvironment.Instance.IsLinuxConsumption(),
70+
IsLinuxContainerEnvironment = SystemEnvironment.Instance.IsAnyLinuxConsumption(),
7171
IsLinuxAppServiceEnvironment = SystemEnvironment.Instance.IsLinuxAppService()
7272
});
7373
})
@@ -87,10 +87,15 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args = null)
8787
/// </summary>
8888
private static void InitializeProcess()
8989
{
90-
if (SystemEnvironment.Instance.IsLinuxConsumption())
90+
if (SystemEnvironment.Instance.IsLinuxConsumptionOnAtlas())
9191
{
9292
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledExceptionInLinuxConsumption;
9393
}
94+
else if (SystemEnvironment.Instance.IsLinuxConsumptionOnLegion())
95+
{
96+
//todo: Replace with legion specific logger.
97+
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledExceptionInLinuxConsumption;
98+
}
9499
else if (SystemEnvironment.Instance.IsLinuxAppService())
95100
{
96101
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
@@ -99,10 +99,15 @@ public static void AddWebJobsScriptHost(this IServiceCollection services, IConfi
9999
services.AddSingleton<IEventGenerator>(p =>
100100
{
101101
var environment = p.GetService<IEnvironment>();
102-
if (environment.IsLinuxConsumption())
102+
if (environment.IsLinuxConsumptionOnAtlas())
103103
{
104104
return new LinuxContainerEventGenerator(environment);
105105
}
106+
else if (environment.IsLinuxConsumptionOnLegion())
107+
{
108+
//todo: Replace with legion specific logger
109+
return new LinuxContainerEventGenerator(environment);
110+
}
106111
else if (SystemEnvironment.Instance.IsLinuxAppService())
107112
{
108113
var hostNameProvider = p.GetService<HostNameProvider>();
@@ -214,7 +219,8 @@ private static void AddLinuxContainerServices(this IServiceCollection services)
214219
services.AddSingleton<IHostedService>(s =>
215220
{
216221
var environment = s.GetService<IEnvironment>();
217-
if (environment.IsLinuxConsumption())
222+
//todo: Replace with legion specific service
223+
if (environment.IsAnyLinuxConsumption())
218224
{
219225
var instanceManager = s.GetService<IInstanceManager>();
220226
var logger = s.GetService<ILogger<LinuxContainerInitializationHostService>>();
@@ -242,7 +248,7 @@ private static void AddLinuxContainerServices(this IServiceCollection services)
242248
services.AddSingleton<IMeshServiceClient>(s =>
243249
{
244250
var environment = s.GetService<IEnvironment>();
245-
if (environment.IsLinuxConsumption())
251+
if (environment.IsAnyLinuxConsumption())
246252
{
247253
var httpClientFactory = s.GetService<IHttpClientFactory>();
248254
var logger = s.GetService<ILogger<MeshServiceClient>>();
@@ -255,7 +261,7 @@ private static void AddLinuxContainerServices(this IServiceCollection services)
255261
services.AddSingleton<LinuxContainerActivityPublisher>(s =>
256262
{
257263
var environment = s.GetService<IEnvironment>();
258-
if (environment.IsLinuxConsumption())
264+
if (environment.IsAnyLinuxConsumption())
259265
{
260266
var logger = s.GetService<ILogger<LinuxContainerActivityPublisher>>();
261267
var meshInitServiceClient = s.GetService<IMeshServiceClient>();
@@ -269,7 +275,7 @@ private static void AddLinuxContainerServices(this IServiceCollection services)
269275
services.AddSingleton<IHostedService>(s =>
270276
{
271277
var environment = s.GetService<IEnvironment>();
272-
if (environment.IsLinuxConsumption())
278+
if (environment.IsAnyLinuxConsumption())
273279
{
274280
return s.GetRequiredService<LinuxContainerActivityPublisher>();
275281
}
@@ -280,7 +286,7 @@ private static void AddLinuxContainerServices(this IServiceCollection services)
280286
services.AddSingleton<ILinuxContainerActivityPublisher>(s =>
281287
{
282288
var environment = s.GetService<IEnvironment>();
283-
if (environment.IsLinuxConsumption())
289+
if (environment.IsAnyLinuxConsumption())
284290
{
285291
return s.GetRequiredService<LinuxContainerActivityPublisher>();
286292
}

src/WebJobs.Script.WebHost/WebJobsApplicationBuilderExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static IApplicationBuilder UseWebJobsScriptHost(this IApplicationBuilder
3838
builder.UseMiddleware<HttpRequestBodySizeMiddleware>();
3939
builder.UseMiddleware<SystemTraceMiddleware>();
4040
builder.UseMiddleware<HostnameFixupMiddleware>();
41-
if (environment.IsLinuxConsumption() || environment.IsKubernetesManagedHosting())
41+
if (environment.IsAnyLinuxConsumption() || environment.IsKubernetesManagedHosting())
4242
{
4343
builder.UseMiddleware<EnvironmentReadyCheckMiddleware>();
4444
}

0 commit comments

Comments
 (0)