Skip to content

Commit

Permalink
Additional test fixes
Browse files Browse the repository at this point in the history
Co-authored-by: Brett Samblanet <[email protected]>
Co-authored-by: Fabio Cavalcante <[email protected]>
  • Loading branch information
fabiocav and brettsam committed Aug 6, 2018
1 parent 2ccc909 commit f95f2ec
Show file tree
Hide file tree
Showing 50 changed files with 866 additions and 552 deletions.
31 changes: 31 additions & 0 deletions src/WebJobs.Script.WebHost/Configuration/JobHostOptionsSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;

namespace Microsoft.Azure.WebJobs.Script.WebHost.Configuration
{
/// <summary>
/// Setup that sets <see cref="JobHostOptions"/> properties based
/// on script host configuration conventions.
/// </summary>
public class JobHostOptionsSetup : IConfigureOptions<JobHostOptions>
{
private readonly IConfiguration _configuration;

public JobHostOptionsSetup(IConfiguration configuration)
{
_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
}

public void Configure(JobHostOptions options)
{
IConfigurationSection jobHostSection = _configuration.GetSection(ConfigurationSectionNames.JobHost);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO.Abstractions;
using System.IO.Compression;
using System.Linq;
Expand Down Expand Up @@ -124,7 +123,7 @@ public IActionResult Invoke(string name, [FromBody] FunctionInvocation invocatio
[Route("admin/functions/{name}/status")]
[Authorize(Policy = PolicyNames.AdminAuthLevel)]
[RequiresRunningHost]
public IActionResult GetFunctionStatus(string name, IScriptJobHost scriptHost)
public IActionResult GetFunctionStatus(string name, [FromServices] IScriptJobHost scriptHost)
{
FunctionStatus status = new FunctionStatus();

Expand Down
21 changes: 14 additions & 7 deletions src/WebJobs.Script.WebHost/Management/InstanceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,25 @@ public class InstanceManager : IInstanceManager

private readonly ScriptWebHostOptions _webHostSettings;
private readonly ILogger _logger;
private readonly ScriptSettingsManager _settingsManager;
private readonly HttpClient _client;
private readonly IScriptWebHostEnvironment _webHostEnvironment;

public InstanceManager(ScriptSettingsManager settingsManager, IOptions<ScriptWebHostOptions> webHostSettings, ILoggerFactory loggerFactory, HttpClient client, IScriptWebHostEnvironment webHostEnvironment)
public InstanceManager(IOptions<ScriptWebHostOptions> webHostSettings, ILoggerFactory loggerFactory, HttpClient client, IScriptWebHostEnvironment webHostEnvironment)
{
_settingsManager = settingsManager;
if (webHostSettings == null)
{
throw new ArgumentNullException(nameof(webHostSettings));
}

if (loggerFactory == null)
{
throw new ArgumentNullException(nameof(loggerFactory));
}

_client = client ?? throw new ArgumentNullException(nameof(client));
_webHostEnvironment = webHostEnvironment ?? throw new ArgumentNullException(nameof(webHostEnvironment));
_webHostSettings = webHostSettings.Value;
_logger = loggerFactory.CreateLogger(LogCategories.Startup);
_client = client;
_webHostEnvironment = webHostEnvironment;
}

public bool StartAssignment(HostAssignmentContext context)
Expand Down Expand Up @@ -107,8 +115,7 @@ private async Task Assign(HostAssignmentContext assignmentContext)
// all assignment settings/files have been applied so we can flip
// the switch now on specialization
_logger.LogInformation("Triggering specialization");
_settingsManager.SetSetting(EnvironmentSettingNames.AzureWebsitePlaceholderMode, "0");
_settingsManager.SetSetting(EnvironmentSettingNames.AzureWebsiteContainerReady, "1");
_webHostEnvironment.FlagAsSpecializedAndReady();
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ public FunctionInvocationMiddleware(RequestDelegate next)
_next = next;
}

public async Task Invoke(HttpContext context, IScriptJobHost scriptHost = null)
public async Task Invoke(HttpContext context)
{
if (scriptHost != null)
{
// flow required context through the request pipeline
// downstream middleware and filters rely on this
context.Items[ScriptConstants.AzureFunctionsHostKey] = scriptHost;
}
// TODO: DI Need to make sure downstream services are getting what they need
// that includes proxies.
//if (scriptHost != null)
//{
// // flow required context through the request pipeline
// // downstream middleware and filters rely on this
// context.Items[ScriptConstants.AzureFunctionsHostKey] = scriptHost;
//}
SetRequestId(context.Request);

if (_next != null)
Expand Down
2 changes: 1 addition & 1 deletion src/WebJobs.Script.WebHost/Proxy/ProxyFunctionExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public async Task<IActionResult> ExecuteFuncAsync(string functionName, Dictionar
httpContext.Items[ScriptConstants.AzureFunctionsNestedProxyCount] = (int)nestedProxiesCount + 1;
}

await functionInvocationMiddleware.Invoke(httpContext, _scriptHost);
await functionInvocationMiddleware.Invoke(httpContext);

var result = (IActionResult)httpContext.Items[ScriptConstants.AzureFunctionsProxyResult];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,13 @@ public interface IScriptWebHostEnvironment
/// Flags that requests under this environment should be resumed.
/// </summary>
void ResumeRequests();

/// <summary>
/// Flags the current environment as ready and specialized.
/// This sets <see cref="EnvironmentSettingNames.AzureWebsitePlaceholderMode"/> to "0"
/// and <see cref="EnvironmentSettingNames.AzureWebsiteContainerReady"/> to "1" against
/// the current environment.
/// </summary>
void FlagAsSpecializedAndReady();
}
}
15 changes: 14 additions & 1 deletion src/WebJobs.Script.WebHost/WebHost/ScriptWebHostEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ namespace Microsoft.Azure.WebJobs.Script.WebHost
public class ScriptWebHostEnvironment : IScriptWebHostEnvironment
{
private readonly ReaderWriterLockSlim _delayLock = new ReaderWriterLockSlim();
private readonly IEnvironment _environment;
private TaskCompletionSource<object> _delayTaskCompletionSource;
private bool? _standbyMode;

public ScriptWebHostEnvironment()
: this(SystemEnvironment.Instance)
{
}

public ScriptWebHostEnvironment(IEnvironment environment)
{
_environment = environment ?? throw new ArgumentNullException(nameof(environment));
_delayTaskCompletionSource = new TaskCompletionSource<object>();
_delayTaskCompletionSource.SetResult(null);
}
Expand Down Expand Up @@ -48,7 +55,7 @@ public bool InStandbyMode
{
return _standbyMode.Value;
}
if (Environment.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsitePlaceholderMode) == "1")
if (_environment.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsitePlaceholderMode) == "1")
{
return true;
}
Expand Down Expand Up @@ -96,5 +103,11 @@ public void ResumeRequests()
_delayLock.ExitReadLock();
}
}

public void FlagAsSpecializedAndReady()
{
_environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsitePlaceholderMode, "0");
_environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteContainerReady, "1");
}
}
}
10 changes: 1 addition & 9 deletions src/WebJobs.Script/Binding/WebJobsCoreScriptBindingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@

using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Script.Extensibility;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq;

namespace Microsoft.Azure.WebJobs.Script.Binding
Expand All @@ -28,13 +26,7 @@ public override bool TryCreate(ScriptBindingContext context, out ScriptBinding b
{
binding = null;

if (string.Compare(context.Type, "blobTrigger", StringComparison.OrdinalIgnoreCase) == 0 ||
string.Compare(context.Type, "blob", StringComparison.OrdinalIgnoreCase) == 0)
{
// TODO: DI (FACAVAL) Load storage extensions dynamically
//binding = new BlobScriptBinding(context);
}
else if (string.Compare(context.Type, "httpTrigger", StringComparison.OrdinalIgnoreCase) == 0)
if (string.Compare(context.Type, "httpTrigger", StringComparison.OrdinalIgnoreCase) == 0)
{
binding = new HttpScriptBinding(context);
}
Expand Down
3 changes: 1 addition & 2 deletions src/WebJobs.Script/BindingExtensions/ExtensionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
Expand All @@ -29,7 +28,7 @@ public class ExtensionsManager : IExtensionsManager
private readonly ILogger _logger;
private string _nugetFallbackPath;

public ExtensionsManager(IOptions<ScriptHostOptions> hostOptions, ILogger logger)
public ExtensionsManager(IOptions<ScriptHostOptions> hostOptions, ILogger<ExtensionsManager> logger)
{
_scriptRootPath = hostOptions.Value.RootScriptPath;
_nugetFallbackPath = hostOptions.Value.NugetFallBackPath;
Expand Down
5 changes: 0 additions & 5 deletions src/WebJobs.Script/Config/ScriptHostOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ public ImmutableArray<string> RootScriptDirectorySnapshot
/// </summary>
public SamplingPercentageEstimatorSettings ApplicationInsightsSamplingSettings { get; set; }

/// <summary>
/// Gets or sets a test hook for modifying the configuration after host.json has been processed.
/// </summary>
internal Action<ScriptHostOptions> OnConfigurationApplied { get; set; }

/// <summary>
/// Gets the <see cref="HostHealthMonitorConfiguration"/> to use.
/// </summary>
Expand Down
52 changes: 0 additions & 52 deletions src/WebJobs.Script/Diagnostics/HostErrorLogger.cs

This file was deleted.

27 changes: 0 additions & 27 deletions src/WebJobs.Script/Diagnostics/HostErrorLoggerProvider.cs

This file was deleted.

7 changes: 7 additions & 0 deletions src/WebJobs.Script/Environment/IEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,12 @@ public interface IEnvironment
/// <param name="name">The environment variable name.</param>
/// <returns>The value of the environment variable specified by <paramref name="name"/>, or <see cref="null"/> if the environment variable is not found.</returns>
string GetEnvironmentVariable(string name);

/// <summary>
/// Creates, modifies, or deletes an environment variable stored in the current <see cref="IEnvironment"/>
/// </summary>
/// <param name="name">The environment variable name.</param>
/// <param name="value">The value to assign to the variable.</param>
void SetEnvironmentVariable(string name, string value);
}
}
7 changes: 6 additions & 1 deletion src/WebJobs.Script/Environment/SystemEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ private static SystemEnvironment CreateInstance()

public string GetEnvironmentVariable(string name)
{
return System.Environment.GetEnvironmentVariable(name);
return Environment.GetEnvironmentVariable(name);
}

public void SetEnvironmentVariable(string name, string value)
{
Environment.SetEnvironmentVariable(name, value);
}
}
}
Loading

0 comments on commit f95f2ec

Please sign in to comment.