private void ServiceConfigurationChanged()
        {
            try {
                // Update runspace provider configuration. Users can update
                // service settings runspace provider configuration is updated
                // before creating new runspaces.
                var providerSettings = new RunspaceProviderSettings();
                Configuration.Bind("RunspaceProviderSettings", providerSettings);
                if (!providerSettings.IsDefault())
                {
                    _logger.LogDebug("RunspaceProviderSettings update:");
                    _logger.LogDebug($"    K8sRunspaceImageName: {providerSettings.K8sRunspaceImageName}");
                    _logger.LogDebug($"    MaxNumberOfRunspaces: {providerSettings.MaxNumberOfRunspaces}");
                    _logger.LogDebug($"    MaxRunspaceActiveTimeMinutes: {providerSettings.MaxRunspaceActiveTimeMinutes}");
                    _logger.LogDebug($"    MaxRunspaceIdleTimeMinutes: {providerSettings.MaxRunspaceIdleTimeMinutes}");
                    RunspaceProviderSingleton.Instance.RunspaceProvider.UpdateConfiguration(providerSettings);
                }
            } catch (Exception configUpdateException) {
                _logger.LogError(configUpdateException, "An error occured on updating runspace provider settings");
            }

            try {
                // Update scripts storage configuration. Users can update
                // service settings for persisting scripts. We update the
                // scripts store settings on run script request.
                var scriptStorageSettings = new ScriptExecutionStorageSettings();
                Configuration.Bind("ScriptExecutionStorageSettings", scriptStorageSettings);
                if (!scriptStorageSettings.IsDefault())
                {
                    ScriptExecutionMediatorSingleton.Instance.ScriptExecutionMediator.UpdateConfiguration(scriptStorageSettings);
                }
            } catch (Exception configUpdateException) {
                _logger.LogError(configUpdateException, "An error occured on updating script storage settings");
            }
        }
Пример #2
0
        public void UpdateConfiguration(RunspaceProviderSettings runspaceProviderSettings)
        {
            _logger.LogInformation($"UpdateConfiguration");
            if (runspaceProviderSettings != null)
            {
                if (_runspaceProvider is K8sRunspaceProvider.K8sRunspaceProvider)
                {
                    var newSettings = new K8sRunspaceProviderSettings {
                        ImagePullSecret   = runspaceProviderSettings.K8sImagePullSecret,
                        RunspaceImageName = runspaceProviderSettings.K8sRunspaceImageName,
                        RunspacePort      = runspaceProviderSettings.K8sRunspacePort,
                        VerifyRunspaceApiIsAccessibleOnCreate = runspaceProviderSettings.K8sVerifyRunspaceApiIsAccessibleOnCreate
                    };
                    _runspaceProvider.UpdateConfiguration(newSettings);
                }

                if (_runspacesStatsMonitor is RunspacesStatsMonitor rsMonitor)
                {
                    rsMonitor.UpdateConfiguration(
                        runspaceProviderSettings.MaxNumberOfRunspaces,
                        runspaceProviderSettings.MaxRunspaceIdleTimeMinutes,
                        runspaceProviderSettings.MaxRunspaceActiveTimeMinutes);
                }
            }
        }
Пример #3
0
        internal void CreateRunspaceProvider(ILoggerFactory loggerFactory, RunspaceProviderSettings runspaceProviderSettings)
        {
            var logger = loggerFactory.CreateLogger(typeof(RunspaceProviderSingleton));

            logger.LogDebug("RunspaceProvider Settings:");
            logger.LogDebug($"  LocalhostDebug: {runspaceProviderSettings.LocalhostDebug}");
            logger.LogDebug($"  DockerApiEndpoint: {runspaceProviderSettings.DockerApiEndpoint}");
            logger.LogDebug($"  K8sClusterEndpoint: {runspaceProviderSettings.K8sClusterEndpoint}");
            logger.LogDebug($"  K8sImagePullSecret: {runspaceProviderSettings.K8sImagePullSecret}");
            logger.LogDebug($"  K8sNamespace: {runspaceProviderSettings.K8sNamespace}");
            logger.LogDebug($"  K8sRunspaceImageName: {runspaceProviderSettings.K8sRunspaceImageName}");
            logger.LogDebug($"  K8sRunspacePort: {runspaceProviderSettings.K8sRunspacePort}");
            logger.LogDebug($"  K8sVerifyRunspaceApiIsAccessibleOnCreate: {runspaceProviderSettings.K8sVerifyRunspaceApiIsAccessibleOnCreate}");
            logger.LogDebug($"  MaxNumberOfRunspaces: {runspaceProviderSettings.MaxNumberOfRunspaces}");
            logger.LogDebug($"  MaxRunspaceActiveTimeMinutes: {runspaceProviderSettings.MaxRunspaceActiveTimeMinutes}");
            logger.LogDebug($"  MaxRunspaceIdleTimeMinutes: {runspaceProviderSettings.MaxRunspaceIdleTimeMinutes}");
            logger.LogDebug($"  RunspaceContainerMemoryLimitMB: {runspaceProviderSettings.RunspaceContainerMemoryLimitMB}");
            logger.LogDebug($"  RunspaceContainerName: {runspaceProviderSettings.RunspaceContainerName}");
            logger.LogDebug($"  RunspaceContainerNetworkName: {runspaceProviderSettings.RunspaceContainerNetworkName}");
            logger.LogDebug($"  RunspaceTrustedCertsConfigMapName: {runspaceProviderSettings.RunspaceTrustedCertsConfigMapName}");

            if (runspaceProviderSettings.LocalhostDebug)
            {
                logger.LogInformation($"Creating {typeof(DebugRunspaceProvider).Name} runspace provider");
                RunspaceProvider = new MultiTenantRunspaceProvider(loggerFactory, new DebugRunspaceProvider());
            }
            else if (!string.IsNullOrEmpty(runspaceProviderSettings.DockerApiEndpoint))
            {
                logger.LogInformation($"Creating {typeof(DockerRunspaceProvider.DockerRunspaceProvider).Name} runspace provider");
                RunspaceProvider = new MultiTenantRunspaceProvider(
                    loggerFactory,
                    new DockerRunspaceProvider.DockerRunspaceProvider(
                        new RunspaceContainerCreateSpec()
                {
                    ImageName   = runspaceProviderSettings.RunspaceContainerName,
                    NetworkName = runspaceProviderSettings.RunspaceContainerNetworkName,
                    RunspaceContainerMemoryLimitMB = runspaceProviderSettings.RunspaceContainerMemoryLimitMB
                },
                        runspaceProviderSettings.DockerApiEndpoint),
                    runspaceProviderSettings.MaxNumberOfRunspaces,
                    runspaceProviderSettings.MaxRunspaceIdleTimeMinutes,
                    runspaceProviderSettings.MaxRunspaceActiveTimeMinutes);
            }
            else if (!string.IsNullOrEmpty(runspaceProviderSettings.K8sRunspaceImageName))
            {
                logger.LogInformation($"Creating {typeof(K8sRunspaceProvider.K8sRunspaceProvider).Name} runspace provider");
                RunspaceProvider = new MultiTenantRunspaceProvider(
                    loggerFactory,
                    new K8sRunspaceProvider.K8sRunspaceProvider(
                        loggerFactory,
                        runspaceProviderSettings.K8sClusterEndpoint,
                        runspaceProviderSettings.K8sClusterAccessToken,
                        runspaceProviderSettings.K8sNamespace,
                        runspaceProviderSettings.K8sRunspaceImageName,
                        runspaceProviderSettings.K8sRunspacePort,
                        runspaceProviderSettings.K8sImagePullSecret,
                        runspaceProviderSettings.K8sVerifyRunspaceApiIsAccessibleOnCreate,
                        runspaceProviderSettings.RunspaceTrustedCertsConfigMapName
                        ),
                    runspaceProviderSettings.MaxNumberOfRunspaces,
                    runspaceProviderSettings.MaxRunspaceIdleTimeMinutes,
                    runspaceProviderSettings.MaxRunspaceActiveTimeMinutes);
            }
        }