public HttpWorkerChannelFactory(IEnvironment environment, ILoggerFactory loggerFactory, IOptions <HttpWorkerOptions> httpWorkerOptions, IScriptEventManager eventManager,
                                 IOptionsMonitor <ScriptApplicationHostOptions> applicationHostOptions, IHttpWorkerProcessFactory httpWorkerProcessFactory, IHttpWorkerService httpWorkerService)
 {
     _eventManager             = eventManager ?? throw new ArgumentNullException(nameof(eventManager));
     _loggerFactory            = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
     _httpWorkerOptions        = httpWorkerOptions.Value ?? throw new ArgumentNullException(nameof(httpWorkerOptions.Value));
     _httpWorkerProcessFactory = httpWorkerProcessFactory ?? throw new ArgumentNullException(nameof(httpWorkerProcessFactory));
     _httpWorkerService        = httpWorkerService ?? throw new ArgumentNullException(nameof(httpWorkerService));
 }
        public FileMonitoringService(IOptions <ScriptJobHostOptions> scriptOptions, ILoggerFactory loggerFactory, IScriptEventManager eventManager, IScriptJobHostEnvironment scriptEnvironment)
        {
            _scriptOptions     = scriptOptions.Value;
            _eventManager      = eventManager;
            _scriptEnvironment = scriptEnvironment;
            _hostLogPath       = Path.Combine(_scriptOptions.RootLogPath, "Host");
            _logger            = loggerFactory.CreateLogger(LogCategories.Startup);

            // If a file change should result in a restart, we debounce the event to
            // ensure that only a single restart is triggered within a specific time window.
            // This allows us to deal with a large set of file change events that might
            // result from a bulk copy/unzip operation. In such cases, we only want to
            // restart after ALL the operations are complete and there is a quiet period.
            _restart = RestartAsync;
            _restart = _restart.Debounce(500);

            _shutdown = Shutdown;
            _shutdown = _shutdown.Debounce(500);
        }
 protected SystemLoggerProvider(string hostInstanceId, IEventGenerator eventGenerator, IEnvironment environment, IDebugStateProvider debugStateProvider, IScriptEventManager eventManager)
 {
     _eventGenerator     = eventGenerator;
     _environment        = environment;
     _hostInstanceId     = hostInstanceId;
     _debugStateProvider = debugStateProvider;
     _eventManager       = eventManager;
 }
Ejemplo n.º 4
0
 public RpcInitializationService(IRpcServer rpcServer, IFunctionDispatcher functionDispatcher, IScriptEventManager eventManager)
 {
     _rpcServer          = rpcServer;
     _eventManager       = eventManager;
     _functionDispatcher = functionDispatcher;
 }
Ejemplo n.º 5
0
 public FunctionRpcService(IScriptEventManager scriptEventManager)
 {
     _eventManager = scriptEventManager;
     Environment.SetEnvironmentVariable("GRPC_EXPERIMENTAL_DISABLE_FLOW_CONTROL", "1");
     Environment.SetEnvironmentVariable("GRPC_CLIENT_CHANNEL_BACKUP_POLL_INTERVAL_MS Default", "0");
 }
        public ProxyMetadataManager(IOptions <ScriptJobHostOptions> scriptOptions, IEnvironment environment, IScriptEventManager eventManager, ILoggerFactory loggerFactory)
        {
            _scriptOptions = scriptOptions;
            _environment   = environment;
            _logger        = loggerFactory.CreateLogger(LogCategories.Startup);
            _metadata      = new Lazy <ProxyMetadataInfo>(LoadFunctionMetadata);

            _fileChangeSubscription = eventManager.OfType <FileEvent>()
                                      .Where(f => string.Equals(f.Source, EventSources.ScriptFiles, StringComparison.Ordinal) &&
                                             string.Equals(Path.GetFileName(f.FileChangeArguments.Name), ScriptConstants.ProxyMetadataFileName, StringComparison.OrdinalIgnoreCase))
                                      .Subscribe(e => HandleProxyFileChange());
        }
        public static void WarmUp(WebHostSettings settings, IScriptEventManager eventManager)
        {
            var        traceWriter = new FileTraceWriter(Path.Combine(settings.LogPath, "Host"), TraceLevel.Info);
            ScriptHost host        = null;

            try
            {
                traceWriter.Info("Warm up started");

                string rootPath = settings.ScriptPath;
                if (Directory.Exists(rootPath))
                {
                    Directory.Delete(rootPath, true);
                }
                Directory.CreateDirectory(rootPath);

                string content = ReadResourceString("Functions.host.json");
                File.WriteAllText(Path.Combine(rootPath, "host.json"), content);

                // read in the C# function
                string functionPath = Path.Combine(rootPath, "Test-CSharp");
                Directory.CreateDirectory(functionPath);
                content = ReadResourceString("Functions.Test_CSharp.function.json");
                File.WriteAllText(Path.Combine(functionPath, "function.json"), content);
                content = ReadResourceString("Functions.Test_CSharp.run.csx");
                File.WriteAllText(Path.Combine(functionPath, "run.csx"), content);

                // read in the F# function
                functionPath = Path.Combine(rootPath, "Test-FSharp");
                Directory.CreateDirectory(functionPath);
                content = ReadResourceString("Functions.Test_FSharp.function.json");
                File.WriteAllText(Path.Combine(functionPath, "function.json"), content);
                content = ReadResourceString("Functions.Test_FSharp.run.fsx");
                File.WriteAllText(Path.Combine(functionPath, "run.fsx"), content);

                traceWriter.Info("Warm up functions deployed");

                ScriptHostConfiguration config = new ScriptHostConfiguration
                {
                    RootScriptPath      = rootPath,
                    FileLoggingMode     = FileLoggingMode.Never,
                    RootLogPath         = settings.LogPath,
                    TraceWriter         = traceWriter,
                    FileWatchingEnabled = false
                };
                config.HostConfig.StorageConnectionString   = null;
                config.HostConfig.DashboardConnectionString = null;

                host = ScriptHost.Create(new NullScriptHostEnvironment(), eventManager, config, ScriptSettingsManager.Instance);
                traceWriter.Info(string.Format("Starting Host (Id={0})", host.ScriptConfig.HostConfig.HostId));

                host.Start();

                var arguments = new Dictionary <string, object>
                {
                    { "input", "{}" }
                };
                host.CallAsync("Test-CSharp", arguments).Wait();
                host.CallAsync("Test-FSharp", arguments).Wait();
                host.Stop();

                traceWriter.Info("Warm up succeeded");
            }
            catch (Exception ex)
            {
                traceWriter.Error(string.Format("Warm up failed: {0}", ex));
            }
            finally
            {
                host?.Dispose();
                traceWriter.Dispose();
            }
        }
 public TestLanguageWorkerChannelFactory(IScriptEventManager eventManager, ILogger testLogger, string scriptRootPath)
 {
     _eventManager   = eventManager;
     _testLogger     = testLogger;
     _scriptRootPath = scriptRootPath;
 }
Ejemplo n.º 9
0
 protected SystemLoggerProvider(string hostInstanceId, IEventGenerator eventGenerator, IEnvironment environment, IDebugStateProvider debugStateProvider, IScriptEventManager eventManager, IOptionsMonitor <AppServiceOptions> appServiceOptions)
 {
     _eventGenerator     = eventGenerator;
     _environment        = environment;
     _hostInstanceId     = hostInstanceId;
     _debugStateProvider = debugStateProvider;
     _eventManager       = eventManager;
     _appServiceOptions  = appServiceOptions;
 }
 public MockScriptHostManager(ScriptHostConfiguration config, IScriptEventManager eventManager)
     : base(config, eventManager)
 {
 }
Ejemplo n.º 11
0
 public TestScriptEventManager()
 {
     _scriptEventManager = new ScriptEventManager();
 }
Ejemplo n.º 12
0
        public static IHostBuilder CreateHostBuilder(FunctionRpc.FunctionRpcBase service, IScriptEventManager scriptEventManager, int port) =>
        new HostBuilder().ConfigureWebHost(webBuilder =>
        {
            webBuilder.UseKestrel(options =>
            {
                options.Listen(IPAddress.Parse(WorkerConstants.HostName), port, listenOptions =>
                {
                    listenOptions.Protocols = HttpProtocols.Http2;
                });
            });

            webBuilder.ConfigureServices(services =>
            {
                services.AddSingleton(scriptEventManager);
                services.AddSingleton(service);
            });

            webBuilder.UseStartup <Startup>();
        });
 public FunctionRpcService(IScriptEventManager eventManager, ILoggerFactory loggerFactory)
 {
     _eventManager = eventManager;
     _logger       = loggerFactory.CreateLogger(ScriptConstants.LogCategoryFunctionRpcService);
 }
Ejemplo n.º 14
0
        public DebugStateProvider(IOptionsMonitor <ScriptApplicationHostOptions> scriptOptions, IScriptEventManager eventManager)
        {
            _event = eventManager.OfType <DebugNotification>()
                     .Subscribe(evt => LastDebugNotify = evt.NotificationTime);

            _scriptOptions = scriptOptions;

            InitializeLastDebugNotify();

            // If these settings changes, we need to refresh our LastDebugNotify value
            _scriptOptions.OnChange(_ => InitializeLastDebugNotify());
        }
Ejemplo n.º 15
0
        public WebJobsScriptHostService(IOptionsMonitor <ScriptApplicationHostOptions> applicationHostOptions, IScriptHostBuilder scriptHostBuilder, ILoggerFactory loggerFactory,
                                        IScriptWebHostEnvironment scriptWebHostEnvironment, IEnvironment environment,
                                        HostPerformanceManager hostPerformanceManager, IOptions <HostHealthMonitorOptions> healthMonitorOptions,
                                        IMetricsLogger metricsLogger, IApplicationLifetime applicationLifetime, IConfiguration config, IScriptEventManager eventManager)
        {
            ArgumentNullException.ThrowIfNull(loggerFactory);

            // This will no-op if already initialized.
            InitializeApplicationInsightsRequestTracking();

            _applicationLifetime = applicationLifetime;
            RegisterApplicationLifetimeEvents();

            _metricsLogger            = metricsLogger;
            _applicationHostOptions   = applicationHostOptions ?? throw new ArgumentNullException(nameof(applicationHostOptions));
            _scriptWebHostEnvironment = scriptWebHostEnvironment ?? throw new ArgumentNullException(nameof(scriptWebHostEnvironment));
            _scriptHostBuilder        = scriptHostBuilder ?? throw new ArgumentNullException(nameof(scriptHostBuilder));
            _environment          = environment ?? throw new ArgumentNullException(nameof(environment));
            _performanceManager   = hostPerformanceManager ?? throw new ArgumentNullException(nameof(hostPerformanceManager));
            _healthMonitorOptions = healthMonitorOptions ?? throw new ArgumentNullException(nameof(healthMonitorOptions));
            _logger       = loggerFactory.CreateLogger(ScriptConstants.LogCategoryHostGeneral);
            _config       = config ?? throw new ArgumentNullException(nameof(config));
            _eventManager = eventManager;

            _hostStarted = _hostStartedSource.Task;

            State = ScriptHostState.Default;

            if (ShouldMonitorHostHealth)
            {
                _healthCheckWindow    = new SlidingWindow <bool>(_healthMonitorOptions.Value.HealthCheckWindow);
                _hostHealthCheckTimer = new Timer(OnHostHealthCheckTimer, null, TimeSpan.Zero, _healthMonitorOptions.Value.HealthCheckInterval);
            }
        }
 public FunctionRpcService(IScriptEventManager eventManager)
 {
     _eventManager = eventManager;
 }
Ejemplo n.º 17
0
 public SystemLogger(string hostInstanceId, string categoryName, IEventGenerator eventGenerator, IEnvironment environment, IDebugStateProvider debugStateProvider, IScriptEventManager eventManager)
 {
     _environment        = environment;
     _eventGenerator     = eventGenerator;
     _categoryName       = categoryName ?? string.Empty;
     _logLevel           = LogLevel.Debug;
     _functionName       = LogCategories.IsFunctionCategory(_categoryName) ? _categoryName.Split('.')[1] : string.Empty;
     _isUserFunction     = LogCategories.IsFunctionUserCategory(_categoryName);
     _hostInstanceId     = hostInstanceId;
     _debugStateProvider = debugStateProvider;
     _eventManager       = eventManager;
 }
 public FunctionRpcService(IScriptEventManager eventManager, ILogger logger)
 {
     _eventManager = eventManager;
     _logger       = logger;
 }
Ejemplo n.º 19
0
 public WebHostSystemLoggerProvider(IEventGenerator eventGenerator, IEnvironment environment, IDebugStateProvider debugStateProvider, IScriptEventManager eventManager, IOptionsMonitor <AppServiceOptions> appServiceOptions)
     : base(string.Empty, eventGenerator, environment, debugStateProvider, eventManager, appServiceOptions)
 {
 }
 internal TestWorkerProcess(IScriptEventManager eventManager, IProcessRegistry processRegistry, ILogger workerProcessLogger, IWorkerConsoleLogSource consoleLogSource, IMetricsLogger metricsLogger, IServiceProvider serviceProvider, bool useStdErrStreamForErrorsOnly = false)
     : base(eventManager, processRegistry, workerProcessLogger, consoleLogSource, metricsLogger, serviceProvider, useStdErrStreamForErrorsOnly)
 {
 }
Ejemplo n.º 21
0
        public DebugStateProvider(IOptionsMonitor <ScriptApplicationHostOptions> scriptOptions, IScriptEventManager eventManager)
        {
            _debugModeEvent = eventManager.OfType <DebugNotification>()
                              .Subscribe(evt => LastDebugNotify = evt.NotificationTime);
            _diagnosticModeEvent = eventManager.OfType <DiagnosticNotification>()
                                   .Subscribe(evt => LastDiagnosticNotify = evt.NotificationTime);

            _scriptOptions = scriptOptions;
            _scriptOptions.OnChange(_ => InitializeLastNotificationTimes());

            InitializeLastNotificationTimes();
        }
 public SystemLoggerProvider(IOptions <ScriptJobHostOptions> scriptOptions, IEventGenerator eventGenerator, IEnvironment environment, IDebugStateProvider debugStateProvider, IScriptEventManager eventManager)
     : this(scriptOptions.Value.InstanceId, eventGenerator, environment, debugStateProvider, eventManager)
 {
 }
 public WebHostSystemLoggerProvider(IEventGenerator eventGenerator, IEnvironment environment, IDebugStateProvider debugStateProvider, IScriptEventManager eventManager)
     : base(string.Empty, eventGenerator, environment, debugStateProvider, eventManager)
 {
 }
Ejemplo n.º 24
0
        // Specify the "builtin binding types". These are types that are directly accesible without needing an explicit load gesture.
        // This is the set of bindings we shipped prior to binding extensibility.
        // Map from BindingType to the Assembly Qualified Type name for its IExtensionConfigProvider object.

        public ScriptHost(IOptions <JobHostOptions> options,
                          IOptions <HttpWorkerOptions> httpWorkerOptions,
                          IEnvironment environment,
                          IJobHostContextFactory jobHostContextFactory,
                          IConfiguration configuration,
                          IDistributedLockManager distributedLockManager,
                          IScriptEventManager eventManager,
                          ILoggerFactory loggerFactory,
                          IFunctionInvocationDispatcherFactory functionDispatcherFactory,
                          IFunctionMetadataManager functionMetadataManager,
                          IFileLoggingStatusManager fileLoggingStatusManager,
                          IMetricsLogger metricsLogger,
                          IOptions <ScriptJobHostOptions> scriptHostOptions,
                          ITypeLocator typeLocator,
                          IScriptHostManager scriptHostManager,
                          IDebugStateProvider debugManager,
                          IEnumerable <IScriptBindingProvider> bindingProviders,
                          IPrimaryHostStateProvider primaryHostStateProvider,
                          IJobHostMetadataProvider metadataProvider,
                          IHostIdProvider hostIdProvider,
                          IHttpRoutesManager httpRoutesManager,
                          IApplicationLifetime applicationLifetime,
                          IExtensionBundleManager extensionBundleManager,
                          ScriptSettingsManager settingsManager = null)
            : base(options, jobHostContextFactory)
        {
            _environment = environment;
            _typeLocator = typeLocator as ScriptTypeLocator
                           ?? throw new ArgumentException(nameof(typeLocator), $"A {nameof(ScriptTypeLocator)} instance is required.");

            _instanceId               = Guid.NewGuid().ToString();
            _hostOptions              = options;
            _configuration            = configuration;
            _storageConnectionString  = configuration.GetWebJobsConnectionString(ConnectionStringNames.Storage);
            _distributedLockManager   = distributedLockManager;
            _functionMetadataManager  = functionMetadataManager;
            _fileLoggingStatusManager = fileLoggingStatusManager;
            _applicationLifetime      = applicationLifetime;
            _hostIdProvider           = hostIdProvider;
            _httpRoutesManager        = httpRoutesManager;
            _isHttpWorker             = httpWorkerOptions.Value.Description != null;
            ScriptOptions             = scriptHostOptions.Value;
            _scriptHostManager        = scriptHostManager;
            FunctionErrors            = new Dictionary <string, ICollection <string> >(StringComparer.OrdinalIgnoreCase);
            EventManager              = eventManager;
            _functionDispatcher       = functionDispatcherFactory.GetFunctionDispatcher();
            _settingsManager          = settingsManager ?? ScriptSettingsManager.Instance;
            ExtensionBundleManager    = extensionBundleManager;

            _metricsLogger = metricsLogger;

            _hostLogPath = Path.Combine(ScriptOptions.RootLogPath, "Host");

            _workerRuntime = _environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName);

            _loggerFactory = loggerFactory;
            _logger        = loggerFactory.CreateLogger(LogCategories.Startup);
            Logger         = _logger;

            _debugManager             = debugManager;
            _primaryHostStateProvider = primaryHostStateProvider;
            _bindingProviders         = new List <IScriptBindingProvider>(bindingProviders);
            _metadataProvider         = metadataProvider;
            _eventSubscriptions.Add(EventManager.OfType <FunctionIndexingEvent>()
                                    .Subscribe(evt =>
            {
                HandleHostError(evt.Exception);
            }));
        }
 public WebHostResolver(ScriptSettingsManager settingsManager, ISecretManagerFactory secretManagerFactory, IScriptEventManager eventManager)
 {
     _settingsManager      = settingsManager;
     _secretManagerFactory = secretManagerFactory;
     _eventManager         = eventManager;
 }
Ejemplo n.º 26
0
        public FileMonitoringService(IOptions <ScriptJobHostOptions> scriptOptions, ILoggerFactory loggerFactory, IScriptEventManager eventManager, IApplicationLifetime applicationLifetime, IScriptHostManager scriptHostManager, IEnvironment environment)
        {
            _scriptOptions       = scriptOptions.Value;
            _eventManager        = eventManager;
            _applicationLifetime = applicationLifetime;
            _scriptHostManager   = scriptHostManager;
            _hostLogPath         = Path.Combine(_scriptOptions.RootLogPath, "Host");
            _logger      = loggerFactory.CreateLogger(LogCategories.Startup);
            _environment = environment;

            // Use this for newer logs as we can't change existing categories of log messages
            _typedLogger = loggerFactory.CreateLogger <FileMonitoringService>();

            // If a file change should result in a restart, we debounce the event to
            // ensure that only a single restart is triggered within a specific time window.
            // This allows us to deal with a large set of file change events that might
            // result from a bulk copy/unzip operation. In such cases, we only want to
            // restart after ALL the operations are complete and there is a quiet period.
            _restart = RestartAsync;
            _restart = _restart.Debounce(500);

            _shutdown = Shutdown;
            _shutdown = _shutdown.Debounce(milliseconds: 500);
            _rootDirectorySnapshot = GetDirectorySnapshot();
        }
Ejemplo n.º 27
0
 public ScriptHost Create(IScriptHostEnvironment environment, IScriptEventManager eventManager, ScriptSettingsManager settingsManager, ScriptHostConfiguration config)
 {
     return(ScriptHost.Create(environment, eventManager, config, settingsManager));
 }