コード例 #1
0
        private void EnsureInitialized(WebHostSettings settings)
        {
            // standby mode can only change from true to false
            // When standby mode changes, we reset all instances
            var standbyMode = WebScriptHostManager.InStandbyMode;

            if (!standbyMode)
            {
                if (_activeHostManager == null)
                {
                    _activeScriptHostConfig = CreateScriptHostConfiguration(settings);

                    _activeHostManager     = new WebScriptHostManager(_activeScriptHostConfig, _secretManagerFactory, _eventManager, _settingsManager, settings);
                    _activeReceiverManager = new WebHookReceiverManager(_activeHostManager.SecretManager);

                    _standbyHostManager?.Dispose();
                    _standbyReceiverManager?.Dispose();

                    _standbyScriptHostConfig = null;
                    _standbyHostManager      = null;
                    _standbyReceiverManager  = null;
                    _settingsManager.Reset();
                }
            }
            else
            {
                if (_standbyHostManager == null)
                {
                    _standbyScriptHostConfig = CreateScriptHostConfiguration(settings);

                    _standbyHostManager     = new WebScriptHostManager(_standbyScriptHostConfig, _secretManagerFactory, _eventManager, _settingsManager, settings);
                    _standbyReceiverManager = new WebHookReceiverManager(_standbyHostManager.SecretManager);
                }
            }
        }
コード例 #2
0
        // TODO: FACAVAL (WEBHOOKS)
        //public WebHookReceiverManager GetWebHookReceiverManager(WebHostSettings settings)
        //{
        //    if (_activeReceiverManager != null)
        //    {
        //        return _activeReceiverManager;
        //    }

        //    lock (_syncLock)
        //    {
        //        EnsureInitialized(settings);

        //        return _activeReceiverManager ?? _standbyReceiverManager;
        //    }
        //}

        internal void EnsureInitialized(WebHostSettings settings)
        {
            if (!WebScriptHostManager.InStandbyMode)
            {
                // standby mode can only change from true to false
                // when standby mode changes, we reset all instances
                if (_activeHostManager == null)
                {
                    _settingsManager.Reset();

                    _activeScriptHostConfig = CreateScriptHostConfiguration(settings);
                    _activeHostManager      = new WebScriptHostManager(_activeScriptHostConfig, _secretManagerFactory, _eventManager, _settingsManager, settings, _router, _loggerFactoryBuilder);
                    //_activeReceiverManager = new WebHookReceiverManager(_activeHostManager.SecretManager);
                    InitializeFileSystem();

                    if (_standbyHostManager != null)
                    {
                        // we're starting the one and only one
                        // standby mode specialization
                        _activeScriptHostConfig.TraceWriter.Info(Resources.HostSpecializationTrace);

                        // After specialization, we need to ensure that custom timezone
                        // settings configured by the user (WEBSITE_TIME_ZONE) are honored.
                        // DateTime caches timezone information, so we need to clear the cache.
                        TimeZoneInfo.ClearCachedData();
                    }

                    if (_standbyHostManager != null)
                    {
                        _standbyHostManager.Stop();
                        _standbyHostManager.Dispose();
                    }
                    //_standbyReceiverManager?.Dispose();
                    _standbyScriptHostConfig = null;
                    _standbyHostManager      = null;
                    //_standbyReceiverManager = null;
                }
            }
            else
            {
                if (_standbyHostManager == null)
                {
                    var standbySettings = CreateStandbySettings(settings);
                    _standbyScriptHostConfig = CreateScriptHostConfiguration(standbySettings, true);
                    _standbyHostManager      = new WebScriptHostManager(_standbyScriptHostConfig, _secretManagerFactory, _eventManager, _settingsManager, standbySettings, _router, _loggerFactoryBuilder);
                    // _standbyReceiverManager = new WebHookReceiverManager(_standbyHostManager.SecretManager);

                    InitializeFileSystem();
                    StandbyManager.Initialize(_standbyScriptHostConfig);
                }
            }
        }
コード例 #3
0
        protected ScriptHostEndToEndTestFixture(string rootPath, string testId, ProxyClientExecutor proxyClient = null, bool startHost = true)
        {
            _settingsManager = ScriptSettingsManager.Instance;
            FixtureId        = testId;
            string connectionString            = AmbientConnectionStringProvider.Instance.GetConnectionString(ConnectionStringNames.Storage);
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

            QueueClient = storageAccount.CreateCloudQueueClient();
            BlobClient  = storageAccount.CreateCloudBlobClient();
            TableClient = storageAccount.CreateCloudTableClient();

            CreateTestStorageEntities().Wait();

            // ApiHubTestHelper.SetDefaultConnectionFactory();

            ScriptHostConfiguration config = new ScriptHostConfiguration()
            {
                RootScriptPath  = rootPath,
                FileLoggingMode = FileLoggingMode.Always
            };

            RequestConfiguration = new HttpConfiguration();

            EventManager = new ScriptEventManager();
            ScriptHostEnvironmentMock = new Mock <IScriptHostEnvironment>();
            LoggerProvider            = new TestLoggerProvider();
            ILoggerProviderFactory loggerProviderFactory = new TestLoggerProviderFactory(LoggerProvider);

            // Reset the timer logs first, since one of the tests will
            // be checking them
            TestHelpers.ClearFunctionLogs("TimerTrigger");
            TestHelpers.ClearFunctionLogs("ListenerStartupException");

            InitializeConfig(config);
            Func <string, FunctionDescriptor> funcLookup = (name) => this.Host.GetFunctionOrNull(name);
            var fastLogger = new FunctionInstanceLogger(funcLookup, new MetricsLogger());

            config.HostConfig.AddService <IAsyncCollector <FunctionInstanceLogEntry> >(fastLogger);
            _settingsManager.Reset();
            Host = new ScriptHost(ScriptHostEnvironmentMock.Object, EventManager, config, _settingsManager,
                                  proxyClient: proxyClient, loggerProviderFactory: loggerProviderFactory);
            Host.Initialize();

            if (startHost)
            {
                Host.HostStarted += (s, e) => _hostStartedEvent.Set();
                Host.Start();
                _hostStartedEvent.Wait(TimeSpan.FromSeconds(30));
            }
        }
コード例 #4
0
        public FunctionDescriptorProviderTests()
        {
            string rootPath = Path.Combine(Environment.CurrentDirectory, @"TestScripts\Node");
            ScriptHostConfiguration config = new ScriptHostConfiguration
            {
                RootScriptPath = rootPath
            };

            var environment = new Mock<IScriptHostEnvironment>();
            var eventManager = new Mock<IScriptEventManager>();
            _settingsManager = ScriptSettingsManager.Instance;
            _settingsManager.Reset();
            _host = new ScriptHost(environment.Object, eventManager.Object, config, _settingsManager);
            _host.Initialize();
            _provider = new TestDescriptorProvider(_host, config);
        }
        public ProxyFunctionDescriptorProviderTests()
        {
            string rootPath = Path.Combine(Environment.CurrentDirectory, @"TestScripts\Proxies");

            _config = new ScriptHostConfiguration
            {
                RootScriptPath = rootPath
            };

            var environment  = new Mock <IScriptHostEnvironment>();
            var eventManager = new Mock <IScriptEventManager>();

            _proxyClient     = GetMockProxyClient();
            _settingsManager = ScriptSettingsManager.Instance;
            _settingsManager.Reset();
            _host = ScriptHost.Create(environment.Object, eventManager.Object, _config, _settingsManager, proxyClient: _proxyClient);
            _metadataCollection = _host.ReadProxyMetadata(_config, _settingsManager);
        }
コード例 #6
0
        private void EnsureInitialized(WebHostSettings settings)
        {
            // standby mode can only change from true to false
            // When standby mode changes, we reset all instances
            var standbyMode = WebScriptHostManager.InStandbyMode;

            if (!standbyMode)
            {
                if (_activeHostManager == null)
                {
                    if (_standbyHostManager != null)
                    {
                        // reintialize app settings if we were in standby
                        ReinitializeAppSettings();
                    }

                    _activeScriptHostConfig = GetScriptHostConfiguration(settings.ScriptPath, settings.LogPath);
                    _activeSecretManager    = GetSecretManager(_settingsManager, settings.SecretsPath);
                    _activeReceiverManager  = new WebHookReceiverManager(_activeSecretManager);
                    _activeHostManager      = new WebScriptHostManager(_activeScriptHostConfig, _activeSecretManager, _settingsManager, settings);

                    (_standbySecretManager as IDisposable)?.Dispose();
                    _standbyHostManager?.Dispose();
                    _standbyReceiverManager?.Dispose();

                    _standbyScriptHostConfig = null;
                    _standbySecretManager    = null;
                    _standbyHostManager      = null;
                    _standbyReceiverManager  = null;
                    _settingsManager.Reset();
                }
            }
            else
            {
                if (_standbyHostManager == null)
                {
                    _standbyScriptHostConfig = GetScriptHostConfiguration(settings.ScriptPath, settings.LogPath);
                    _standbySecretManager    = GetSecretManager(_settingsManager, settings.SecretsPath);
                    _standbyReceiverManager  = new WebHookReceiverManager(_standbySecretManager);
                    _standbyHostManager      = new WebScriptHostManager(_standbyScriptHostConfig, _standbySecretManager, _settingsManager, settings);
                }
            }
        }
コード例 #7
0
        internal void EnsureInitialized(WebHostSettings settings)
        {
            if (!WebScriptHostManager.InStandbyMode)
            {
                // standby mode can only change from true to false
                // When standby mode changes, we reset all instances
                if (_activeHostManager == null)
                {
                    _activeScriptHostConfig = CreateScriptHostConfiguration(settings);
                    _activeHostManager      = new WebScriptHostManager(_activeScriptHostConfig, _secretManagerFactory, _eventManager, _settingsManager, settings);
                    _activeReceiverManager  = new WebHookReceiverManager(_activeHostManager.SecretManager);
                    InitializeFileSystem();

                    if (_standbyHostManager != null)
                    {
                        // we're undergoing the one and only one
                        // standby mode specialization
                        _activeScriptHostConfig.TraceWriter.Info(Resources.HostSpecializationTrace);
                    }

                    _standbyHostManager?.Dispose();
                    _standbyReceiverManager?.Dispose();
                    _standbyScriptHostConfig = null;
                    _standbyHostManager      = null;
                    _standbyReceiverManager  = null;
                    _settingsManager.Reset();
                }
            }
            else
            {
                if (_standbyHostManager == null)
                {
                    _standbyScriptHostConfig = CreateScriptHostConfiguration(settings, true);
                    _standbyHostManager      = new WebScriptHostManager(_standbyScriptHostConfig, _secretManagerFactory, _eventManager, _settingsManager, settings);
                    _standbyReceiverManager  = new WebHookReceiverManager(_standbyHostManager.SecretManager);

                    InitializeFileSystem();
                    StandbyManager.Initialize(_standbyScriptHostConfig);
                }
            }
        }
コード例 #8
0
        /// <summary>
        /// This method ensures that all services managed by this class are initialized
        /// correctly taking into account specialization state transitions.
        /// </summary>
        internal void EnsureInitialized(WebHostSettings settings)
        {
            // Create a logger that we can use when the host isn't yet initialized.
            ILogger logger = _loggerFactory.CreateLogger(LogCategories.Startup);

            lock (_syncLock)
            {
                // Determine whether we should do normal or standby initialization
                if (!WebScriptHostManager.InStandbyMode)
                {
                    // We're not in standby mode. There are two cases to consider:
                    // 1) We _were_ in standby mode and now we're ready to specialize
                    // 2) We're doing non-specialization normal initialization
                    if (_activeHostManager == null &&
                        (_standbyHostManager == null || _settingsManager.ContainerReady))
                    {
                        _settingsManager.Reset();
                        _specializationTimer?.Dispose();
                        _specializationTimer = null;

                        _activeScriptHostConfig = CreateScriptHostConfiguration(settings);
                        _activeHostManager      = new WebScriptHostManager(_activeScriptHostConfig, _secretManagerFactory, _eventManager, _settingsManager, settings,
                                                                           _router, loggerProviderFactory: _loggerProviderFactory, loggerFactory: _loggerFactory);
                        //_activeReceiverManager = new WebHookReceiverManager(_activeHostManager.SecretManager);
                        InitializeFileSystem(settings, _settingsManager.FileSystemIsReadOnly);

                        if (_standbyHostManager != null)
                        {
                            // we're starting the one and only one
                            // standby mode specialization
                            logger.LogInformation(Resources.HostSpecializationTrace);

                            // After specialization, we need to ensure that custom timezone
                            // settings configured by the user (WEBSITE_TIME_ZONE) are honored.
                            // DateTime caches timezone information, so we need to clear the cache.
                            TimeZoneInfo.ClearCachedData();
                        }

                        if (_standbyHostManager != null)
                        {
                            _standbyHostManager.Stop();
                            _standbyHostManager.Dispose();
                        }
                        //_standbyReceiverManager?.Dispose();
                        _standbyScriptHostConfig = null;
                        _standbyHostManager      = null;
                        //_standbyReceiverManager = null;
                    }
                }
                else
                {
                    // We're in standby (placeholder) mode. Initialize the standby services.
                    if (_standbyHostManager == null)
                    {
                        var standbySettings = CreateStandbySettings(settings);
                        _standbyScriptHostConfig = CreateScriptHostConfiguration(standbySettings, true);
                        _standbyHostManager      = new WebScriptHostManager(_standbyScriptHostConfig, _secretManagerFactory, _eventManager, _settingsManager, standbySettings,
                                                                            _router, loggerProviderFactory: _loggerProviderFactory, loggerFactory: _loggerFactory);
                        // _standbyReceiverManager = new WebHookReceiverManager(_standbyHostManager.SecretManager);

                        InitializeFileSystem(settings, _settingsManager.FileSystemIsReadOnly);
                        StandbyManager.Initialize(_standbyScriptHostConfig, logger);

                        // start a background timer to identify when specialization happens
                        // specialization usually happens via an http request (e.g. scale controller
                        // ping) but this timer is started as well to handle cases where we
                        // might not receive a request
                        _specializationTimer = new Timer(OnSpecializationTimerTick, settings, 1000, 1000);
                    }
                }
            }
        }