コード例 #1
0
        public IList <WorkerConfig> GetConfigs()
        {
            BuildWorkerProviderDictionary();
            var result = new List <WorkerConfig>();

            foreach (var description in _workerDescripionDictionary.Values)
            {
                _logger.LogDebug($"Worker path for language worker {description.Language}: {description.WorkerDirectory}");

                if (IsHydrationNeeded(description.DefaultWorkerPath))
                {
                    description.DefaultWorkerPath = GetHydratedWorkerPath(description);
                }

                var arguments = new WorkerProcessArguments()
                {
                    ExecutablePath = description.DefaultExecutablePath,
                    WorkerPath     = description.DefaultWorkerPath
                };

                if (description.Language.Equals(LanguageWorkerConstants.JavaLanguageWorkerName))
                {
                    arguments.ExecutablePath = GetExecutablePathForJava(description.DefaultExecutablePath);
                }
                arguments.ExecutableArguments.AddRange(description.Arguments);
                var config = new WorkerConfig()
                {
                    Description = description,
                    Arguments   = arguments
                };
                result.Add(config);
            }

            return(result);
        }
コード例 #2
0
        public RpcWorkerContext(string requestId,
                                int maxMessageLength,
                                string workerId,
                                WorkerProcessArguments workerProcessArguments,
                                string workingDirectory,
                                Uri serverUri,
                                IDictionary <string, string> environmentVariables = null)
        {
            if (serverUri == null)
            {
                throw new ArgumentNullException(nameof(serverUri));
            }
            if (serverUri.Host == null)
            {
                throw new InvalidOperationException($"{nameof(ServerUri.Host)} is null");
            }

            RequestId        = requestId;
            MaxMessageLength = RpcWorkerConstants.DefaultMaxMessageLengthBytes;
            WorkerId         = workerId;
            Arguments        = workerProcessArguments;
            WorkingDirectory = workingDirectory;
            ServerUri        = serverUri;
            if (environmentVariables != null)
            {
                EnvironmentVariables = environmentVariables;
            }
        }
コード例 #3
0
        public IList <RpcWorkerConfig> GetConfigs()
        {
            using (_metricsLogger.LatencyEvent(MetricEventNames.GetConfigs))
            {
                BuildWorkerProviderDictionary();
                var result = new List <RpcWorkerConfig>();

                foreach (var description in _workerDescripionDictionary.Values)
                {
                    _logger.LogDebug($"Worker path for language worker {description.Language}: {description.WorkerDirectory}");

                    var arguments = new WorkerProcessArguments()
                    {
                        ExecutablePath = description.DefaultExecutablePath,
                        WorkerPath     = description.DefaultWorkerPath
                    };

                    arguments.ExecutableArguments.AddRange(description.Arguments);
                    var config = new RpcWorkerConfig()
                    {
                        Description = description,
                        Arguments   = arguments
                    };
                    result.Add(config);
                }

                return(result);
            }
        }
コード例 #4
0
        internal LanguageWorkerProcess(string runtime,
                                       string workerId,
                                       string rootScriptPath,
                                       Uri serverUri,
                                       WorkerProcessArguments workerProcessArguments,
                                       IScriptEventManager eventManager,
                                       IWorkerProcessFactory processFactory,
                                       IProcessRegistry processRegistry,
                                       ILogger workerProcessLogger,
                                       ILanguageWorkerConsoleLogSource consoleLogSource)
        {
            _runtime             = runtime;
            _workerId            = workerId;
            _processFactory      = processFactory;
            _processRegistry     = processRegistry;
            _workerProcessLogger = workerProcessLogger;
            _consoleLogSource    = consoleLogSource;
            _eventManager        = eventManager;

            var workerContext = new WorkerContext()
            {
                RequestId        = Guid.NewGuid().ToString(),
                MaxMessageLength = LanguageWorkerConstants.DefaultMaxMessageLengthBytes,
                WorkerId         = _workerId,
                Arguments        = workerProcessArguments,
                WorkingDirectory = rootScriptPath,
                ServerUri        = serverUri,
            };

            _process = _processFactory.CreateWorkerProcess(workerContext);
        }
コード例 #5
0
        public void Configure(HttpWorkerOptions options)
        {
            IConfigurationSection jobHostSection = _configuration.GetSection(ConfigurationSectionNames.JobHost);
            var httpInvokerSection = jobHostSection.GetSection(ConfigurationSectionNames.HttpInvoker);

            if (httpInvokerSection.Exists())
            {
                httpInvokerSection.Bind(options);
                HttpWorkerDescription httpInvokerDescription = options.Description;

                if (httpInvokerDescription == null)
                {
                    throw new HostConfigurationException($"Missing WorkerDescription for HttpInvoker");
                }
                httpInvokerDescription.ApplyDefaultsAndValidate();
                if (string.IsNullOrEmpty(httpInvokerDescription.DefaultWorkerPath))
                {
                    if (!Path.IsPathRooted(httpInvokerDescription.DefaultExecutablePath))
                    {
                        httpInvokerDescription.DefaultExecutablePath = Path.Combine(httpInvokerDescription.WorkerDirectory, httpInvokerDescription.DefaultExecutablePath);
                    }
                }
                var arguments = new WorkerProcessArguments()
                {
                    ExecutablePath = options.Description.DefaultExecutablePath,
                    WorkerPath     = options.Description.DefaultWorkerPath
                };

                arguments.ExecutableArguments.AddRange(options.Description.Arguments);
                _logger.LogDebug("Configured httpInvoker with {DefaultExecutablePath}: {exepath} with arguments {args}", nameof(options.Description.DefaultExecutablePath), options.Description.DefaultExecutablePath, options.Arguments);
            }
        }
コード例 #6
0
        public void TryConfigureArguments_ReturnsTrue()
        {
            var provider = new GenericWorkerProvider(new WorkerDescription(), string.Empty);
            var args     = new WorkerProcessArguments();

            Assert.True(provider.TryConfigureArguments(args, null, null));
        }
コード例 #7
0
        public IEnumerable <WorkerConfig> GetConfigs(IEnumerable <IWorkerProvider> providers)
        {
            foreach (var provider in providers)
            {
                var description = provider.GetDescription();
                _logger.LogTrace($"Worker path for language worker {description.Language}: {description.WorkerDirectory}");

                var arguments = new WorkerProcessArguments()
                {
                    ExecutablePath = description.DefaultExecutablePath,
                    WorkerPath     = description.GetWorkerPath()
                };

                if (description.Language.Equals(LanguageWorkerConstants.JavaLanguageWorkerName))
                {
                    arguments.ExecutablePath = GetExecutablePathForJava(description.DefaultExecutablePath);
                }

                if (provider.TryConfigureArguments(arguments, _config, _logger))
                {
                    yield return(new WorkerConfig()
                    {
                        Description = description,
                        Arguments = arguments
                    });
                }
                else
                {
                    _logger.LogError($"Could not configure language worker {description.Language}.");
                }
            }
        }
コード例 #8
0
        internal void AddProvider(string workerDir)
        {
            using (_metricsLogger.LatencyEvent(string.Format(MetricEventNames.AddProvider, workerDir)))
            {
                try
                {
                    string workerConfigPath = Path.Combine(workerDir, RpcWorkerConstants.WorkerConfigFileName);
                    if (!File.Exists(workerConfigPath))
                    {
                        _logger.LogDebug($"Did not find worker config file at: {workerConfigPath}");
                        return;
                    }
                    // Parse worker config file
                    _logger.LogDebug($"Found worker config: {workerConfigPath}");
                    string  json         = File.ReadAllText(workerConfigPath);
                    JObject workerConfig = JObject.Parse(json);
                    RpcWorkerDescription workerDescription = workerConfig.Property(WorkerConstants.WorkerDescription).Value.ToObject <RpcWorkerDescription>();
                    workerDescription.WorkerDirectory = workerDir;

                    // Check if any appsettings are provided for that langauge
                    var languageSection = _config.GetSection($"{RpcWorkerConstants.LanguageWorkersSectionName}:{workerDescription.Language}");
                    workerDescription.Arguments = workerDescription.Arguments ?? new List <string>();
                    GetWorkerDescriptionFromAppSettings(workerDescription, languageSection);
                    AddArgumentsFromAppSettings(workerDescription, languageSection);

                    // Validate workerDescription
                    workerDescription.ApplyDefaultsAndValidate(Directory.GetCurrentDirectory(), _logger);

                    if (ShouldAddWorkerConfig(workerDescription.Language))
                    {
                        workerDescription.FormatWorkerPathIfNeeded(_systemRuntimeInformation, _environment, _logger);
                        workerDescription.ThrowIfFileNotExists(workerDescription.DefaultWorkerPath, nameof(workerDescription.DefaultWorkerPath));
                        workerDescription.ExpandEnvironmentVariables();

                        WorkerProcessCountOptions workerProcessCount = GetWorkerProcessCount(workerConfig);

                        var arguments = new WorkerProcessArguments()
                        {
                            ExecutablePath = workerDescription.DefaultExecutablePath,
                            WorkerPath     = workerDescription.DefaultWorkerPath
                        };
                        arguments.ExecutableArguments.AddRange(workerDescription.Arguments);
                        var rpcWorkerConfig = new RpcWorkerConfig()
                        {
                            Description  = workerDescription,
                            Arguments    = arguments,
                            CountOptions = workerProcessCount,
                        };
                        _workerDescriptionDictionary[workerDescription.Language] = rpcWorkerConfig;
                        ReadLanguageWorkerFile(arguments.WorkerPath);
                        _logger.LogDebug($"Added WorkerConfig for language: {workerDescription.Language}");
                    }
                }
                catch (Exception ex)
                {
                    _logger?.LogError(ex, $"Failed to initialize worker provider for: {workerDir}");
                }
            }
        }
コード例 #9
0
 public bool TryConfigureArguments(WorkerProcessArguments args, IConfiguration config, ILogger logger)
 {
     if (_workerDescription.Arguments != null)
     {
         args.ExecutableArguments.AddRange(_workerDescription.Arguments);
     }
     return(true);
 }
コード例 #10
0
 internal HttpWorkerProcess(string workerId,
                            string rootScriptPath,
                            WorkerProcessArguments workerProcessArguments,
                            IScriptEventManager eventManager,
                            IWorkerProcessFactory processFactory,
                            IProcessRegistry processRegistry,
                            ILogger workerProcessLogger,
                            ILanguageWorkerConsoleLogSource consoleLogSource)
     : base(eventManager, processRegistry, workerProcessLogger, consoleLogSource)
 {
     _processFactory         = processFactory;
     _eventManager           = eventManager;
     _workerProcessLogger    = workerProcessLogger;
     _workerId               = workerId;
     _scriptRootPath         = rootScriptPath;
     _workerProcessArguments = workerProcessArguments;
 }
コード例 #11
0
        public void FailsIfNoJavaHome()
        {
            var config = new ConfigurationBuilder()
                         .AddInMemoryCollection(new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>($"{LanguageWorkerConstants.LanguageWorkersSectionName}:{LanguageWorkerConstants.JavaLanguageWorkerName}:debug", "1000")
            })
                         .Build();

            var testLogger    = new TestLogger("test");
            var configFactory = new WorkerConfigFactory(config, testLogger);
            var provider      = new JavaWorkerProvider(configFactory.WorkerDirPath);
            var args          = new WorkerProcessArguments();
            var result        = provider.TryConfigureArguments(args, config, testLogger);

            Assert.False(result);
        }
コード例 #12
0
        public void DisablesDebugIfNotConfigured()
        {
            var config = new ConfigurationBuilder()
                         .AddInMemoryCollection(new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("JAVA_HOME", "asdf"),
            })
                         .Build();

            var testLogger    = new TestLogger("test");
            var configFactory = new WorkerConfigFactory(config, testLogger);
            var provider      = new JavaWorkerProvider(configFactory.WorkerDirPath);
            var args          = new WorkerProcessArguments();
            var result        = provider.TryConfigureArguments(args, config, testLogger);

            Assert.True(result);
            Assert.DoesNotContain(args.ExecutableArguments, (exeArg) => exeArg.Contains("address="));
        }
コード例 #13
0
        public void SetsDebugAddress()
        {
            var config = new ConfigurationBuilder()
                         .AddInMemoryCollection(new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("JAVA_HOME", "asdf"),
                new KeyValuePair <string, string>($"{LanguageWorkerConstants.LanguageWorkersSectionName}:{LanguageWorkerConstants.JavaLanguageWorkerName}:debug", "localhost:1000")
            })
                         .Build();

            var testLogger    = new TestLogger("test");
            var configFactory = new WorkerConfigFactory(config, testLogger);

            var provider = new JavaWorkerProvider(configFactory.WorkerDirPath);
            var args     = new WorkerProcessArguments();
            var result   = provider.TryConfigureArguments(args, config, testLogger);

            Assert.True(result);
            Assert.Contains(args.ExecutableArguments, (exeArg) => exeArg.Contains("address=localhost:1000"));
        }
コード例 #14
0
 internal HttpWorkerProcess(string workerId,
                            string rootScriptPath,
                            HttpWorkerOptions httpWorkerOptions,
                            IScriptEventManager eventManager,
                            IWorkerProcessFactory processFactory,
                            IProcessRegistry processRegistry,
                            ILogger workerProcessLogger,
                            IWorkerConsoleLogSource consoleLogSource,
                            IEnvironment environment,
                            IMetricsLogger metricsLogger)
     : base(eventManager, processRegistry, workerProcessLogger, consoleLogSource, metricsLogger, httpWorkerOptions.Description.UseStdErrorStreamForErrorsOnly)
 {
     _processFactory         = processFactory;
     _eventManager           = eventManager;
     _workerProcessLogger    = workerProcessLogger;
     _workerId               = workerId;
     _scriptRootPath         = rootScriptPath;
     _httpWorkerOptions      = httpWorkerOptions;
     _workerProcessArguments = _httpWorkerOptions.Arguments;
     _environment            = environment;
 }
コード例 #15
0
 internal RpcWorkerProcess(string runtime,
                           string workerId,
                           string rootScriptPath,
                           Uri serverUri,
                           WorkerProcessArguments workerProcessArguments,
                           IScriptEventManager eventManager,
                           IWorkerProcessFactory processFactory,
                           IProcessRegistry processRegistry,
                           ILogger workerProcessLogger,
                           IWorkerConsoleLogSource consoleLogSource)
     : base(eventManager, processRegistry, workerProcessLogger, consoleLogSource)
 {
     _runtime                = runtime;
     _processFactory         = processFactory;
     _eventManager           = eventManager;
     _workerProcessLogger    = workerProcessLogger;
     _workerId               = workerId;
     _serverUri              = serverUri;
     _scriptRootPath         = rootScriptPath;
     _workerProcessArguments = workerProcessArguments;
 }
コード例 #16
0
        public void OverridesJavaHomeInAzure()
        {
            var config = new ConfigurationBuilder()
                         .AddInMemoryCollection(new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("JAVA_HOME", "d:/java/jdk1.7.0"),
                new KeyValuePair <string, string>("WEBSITE_INSTANCE_ID", "id"),
            })
                         .Build();

            var testLogger    = new TestLogger("test");
            var configFactory = new WorkerConfigFactory(config, testLogger);
            var provider      = new JavaWorkerProvider(configFactory.WorkerDirPath);
            var args          = new WorkerProcessArguments();
            var result        = provider.TryConfigureArguments(args, config, testLogger);

            Assert.True(result);
            var exePath = Path.GetFullPath("d:/java/zulu8.23.0.3-jdk8.0.144-win_x64/bin/java");

            Assert.Equal(exePath, args.ExecutablePath);
        }
コード例 #17
0
        public IList <WorkerConfig> GetConfigs()
        {
            BuildWorkerProviderDictionary();
            var result = new List <WorkerConfig>();

            foreach (var provider in WorkerProviders)
            {
                var description = provider.GetDescription();
                _logger.LogDebug($"Worker path for language worker {description.Language}: {description.WorkerDirectory}");

                var arguments = new WorkerProcessArguments()
                {
                    ExecutablePath = description.DefaultExecutablePath,
                    WorkerPath     = description.GetWorkerPath()
                };

                if (description.Language.Equals(LanguageWorkerConstants.JavaLanguageWorkerName))
                {
                    arguments.ExecutablePath = GetExecutablePathForJava(description.DefaultExecutablePath);
                }

                if (provider.TryConfigureArguments(arguments, _logger))
                {
                    var config = new WorkerConfig()
                    {
                        Description = description,
                        Arguments   = arguments
                    };
                    result.Add(config);
                }
                else
                {
                    _logger.LogError($"Could not configure language worker {description.Language}.");
                }
            }

            return(result);
        }
コード例 #18
0
 internal RpcWorkerProcess(string runtime,
                           string workerId,
                           string rootScriptPath,
                           Uri serverUri,
                           RpcWorkerConfig rpcWorkerConfig,
                           IScriptEventManager eventManager,
                           IWorkerProcessFactory processFactory,
                           IProcessRegistry processRegistry,
                           ILogger workerProcessLogger,
                           IWorkerConsoleLogSource consoleLogSource,
                           IMetricsLogger metricsLogger)
     : base(eventManager, processRegistry, workerProcessLogger, consoleLogSource, metricsLogger, rpcWorkerConfig.Description.UseStdErrorStreamForErrorsOnly)
 {
     _runtime                = runtime;
     _processFactory         = processFactory;
     _eventManager           = eventManager;
     _workerProcessLogger    = workerProcessLogger;
     _workerId               = workerId;
     _serverUri              = serverUri;
     _scriptRootPath         = rootScriptPath;
     _workerProcessArguments = rpcWorkerConfig.Arguments;
     _workerDirectory        = rpcWorkerConfig.Description.WorkerDirectory;
 }
コード例 #19
0
        public bool TryConfigureArguments(WorkerProcessArguments args, IConfiguration config, ILogger logger)
        {
            var options           = new DefaultWorkerOptions();
            var javaWorkerSection = $"{LanguageWorkerConstants.LanguageWorkersSectionName}:{LanguageWorkerConstants.JavaLanguageWorkerName}";

            config.GetSection(javaWorkerSection).Bind(options);
            var env = new JavaEnvironment();

            config.Bind(env);
            if (string.IsNullOrEmpty(env.JAVA_HOME))
            {
                logger.LogTrace("Unable to configure java worker. Could not find JAVA_HOME app setting.");
                return(false);
            }

            args.ExecutablePath = Path.GetFullPath(Path.Combine(env.ResolveJavaHome(), "bin", "java"));
            args.ExecutableArguments.Add("-jar");

            if (!string.IsNullOrWhiteSpace(options.Debug))
            {
                if (!env.HasJavaOpts)
                {
                    var debugOpts = $"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address={options.Debug}";
                    args.ExecutableArguments.Add(debugOpts);
                }
                else
                {
                    logger.LogWarning("Both JAVA_OPTS and debug address settings found. Defaulting to JAVA_OPTS.");
                }
            }

            if (env.HasJavaOpts)
            {
                args.ExecutableArguments.Add(env.JAVA_OPTS);
            }
            return(true);
        }
コード例 #20
0
        public ILanguageWorkerProcess Create(string workerId, string scriptRootPath, WorkerProcessArguments workerArgs)
        {
            ILogger workerProcessLogger = _loggerFactory.CreateLogger($"Worker.HttpInvokerProcess.{workerId}");

            return(new HttpWorkerProcess(workerId, scriptRootPath, workerArgs, _eventManager, _workerProcessFactory, _processRegistry, workerProcessLogger, _consoleLogSource));
        }