private static bool ParseAndSetBrokerWorkerSettings(string[] args) { void SetBrokerWorkerConfiguration(BrokerWorkerStartOption option) { if (option.ConfigureLogging) { ConfigureLogging = true; Trace.TraceInformation("Set configureLogging true"); } if (!string.IsNullOrEmpty(option.JsonFilePath)) { string[] argsInJson = JSONFileParser.parse(option.JsonFilePath); var parserResult = new Parser( s => { s.CaseSensitive = false; s.HelpWriter = Console.Error; }).ParseArguments <BrokerWorkerStartOption>(argsInJson).WithParsed(SetBrokerWorkerConfiguration); if (parserResult.Tag != ParserResultType.Parsed) { TraceHelper.TraceEvent(TraceEventType.Critical, "[BrokerWorker] Parse arguments error."); throw new ArgumentException("Parse arguments error in BrokerWorker."); } } else { if (!string.IsNullOrEmpty(option.Logging)) { try { LogHelper.SetLoggingConfig(option, $"{Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location)}/HpcBrokerWorker.exe.config", "BrokerWorker"); } catch (Exception e) { Trace.TraceError("Exception occurs when configure logging in BrokerWorker - " + e); } } } } var result = new Parser( s => { s.CaseSensitive = false; s.HelpWriter = Console.Error; }).ParseArguments <BrokerWorkerStartOption>(args).WithParsed(SetBrokerWorkerConfiguration); return(result.Tag == ParserResultType.Parsed); }
private static bool ParseAndSetBrokerLauncherSettings(string[] args, BrokerLauncherSettings settings) { void SetBrokerLauncherSettings(StartOption option) { if (option.AsConsole) { settings.AsConsole = true; Trace.TraceInformation("Starting as console"); } if (option.ConfigureLogging) { ConfigureLogging = true; Trace.TraceInformation("Set configureLogging true"); } if (!string.IsNullOrEmpty(option.JsonFilePath)) { string[] argsInJson = JSONFileParser.parse(option.JsonFilePath); var parserResult = new Parser( s => { s.CaseSensitive = false; s.HelpWriter = Console.Error; }).ParseArguments <StartOption>(argsInJson).WithParsed(SetBrokerLauncherSettings); if (parserResult.Tag != ParserResultType.Parsed) { TraceHelper.TraceEvent(TraceEventType.Critical, "[BrokerWorker] Parse arguments error."); throw new ArgumentException("Parse arguments error in BrokerWorker."); } } else { if (bool.TryParse(option.EnableAzureStorageQueueEndpoint, out var res)) { settings.EnableAzureStorageQueueEndpoint = res; Trace.TraceInformation($"{nameof(settings.EnableAzureStorageQueueEndpoint)} set to {res}."); } if (!option.ReadSvcHostFromEnv && option.SvcHostList != null && option.SvcHostList.Any()) { var collection = new StringCollection(); collection.AddRange(option.SvcHostList.ToArray()); settings.SvcHostList = collection; Trace.TraceInformation($"{nameof(settings.SvcHostList)} set to {string.Join(",", option.SvcHostList)}."); } if (option.ReadSvcHostFromEnv) { var nodeListVar = Environment.GetEnvironmentVariable(AzureBatchNodeListEnvVarName); string[] nodes = nodeListVar?.Split(';'); if (nodes == null || !nodes.Any()) { throw new ArgumentException($"Environment {AzureBatchNodeListEnvVarName} is empty"); } var collection = new StringCollection(); collection.AddRange(nodes); settings.SvcHostList = collection; Trace.TraceInformation($"{nameof(settings.SvcHostList)} set to {string.Join(",", nodes)} from env var {AzureBatchNodeListEnvVarName}={nodeListVar}."); } if (!string.IsNullOrEmpty(option.ServiceRegistrationPath)) { settings.CCP_SERVICEREGISTRATION_PATH = option.ServiceRegistrationPath; Trace.TraceInformation($"{nameof(settings.CCP_SERVICEREGISTRATION_PATH)} set to {option.ServiceRegistrationPath}."); } else { settings.CCP_SERVICEREGISTRATION_PATH = $"%{TelepathyConstants.ServiceWorkingDirEnvVar}%"; } if (!string.IsNullOrEmpty(option.AzureStorageConnectionString)) { settings.AzureStorageConnectionString = option.AzureStorageConnectionString; Trace.TraceInformation($"{nameof(settings.AzureStorageConnectionString)} changed by cmd args."); } if (!string.IsNullOrEmpty(option.SessionAddress)) { settings.SessionAddress = option.SessionAddress; Trace.TraceInformation($"{nameof(settings.SessionAddress)} set to {option.SessionAddress}."); } if (!string.IsNullOrEmpty(option.Logging)) { try { LogHelper.SetLoggingConfig(option, $"{Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location)}/HpcBroker.exe.config", "BrokerLauncher"); } catch (Exception e) { Trace.TraceError("Exception occurs when configure logging - " + e); } } } } var result = new Parser(s => { s.CaseSensitive = false; s.HelpWriter = Console.Error; }).ParseArguments <StartOption>(args).WithParsed(SetBrokerLauncherSettings); return(result.Tag == ParserResultType.Parsed); }
private static bool ParseAndSetGlobalConfiguration(string[] args) { void SetGlobalConfiguration(SessionLauncherStartOption option) { if (option.AsConsole) { SessionLauncherRuntimeConfiguration.AsConsole = true; } if (option.ConfigureLogging) { SessionLauncherRuntimeConfiguration.ConfigureLogging = true; Trace.TraceInformation("Set configureLogging true"); } if (!string.IsNullOrEmpty(option.JsonFilePath)) { string[] argsInJson = JSONFileParser.parse(option.JsonFilePath); var parserResult = new Parser( s => { s.CaseSensitive = false; s.HelpWriter = Console.Error; }).ParseArguments <SessionLauncherStartOption>(argsInJson).WithParsed(SetGlobalConfiguration); if (parserResult.Tag != ParserResultType.Parsed) { TraceHelper.TraceEvent(TraceEventType.Critical, "[SessionLauncher] Parse arguments error."); throw new ArgumentException("Parse arguments error."); } } else { if (!string.IsNullOrEmpty(option.AzureBatchServiceUrl)) { SessionLauncherRuntimeConfiguration.SchedulerType = SchedulerType.AzureBatch; AzureBatchConfiguration.BatchServiceUrl = option.AzureBatchServiceUrl; AzureBatchConfiguration.BatchAccountName = option.AzureBatchAccountName; AzureBatchConfiguration.BatchAccountKey = option.AzureBatchAccountKey; AzureBatchConfiguration.SoaBrokerStorageConnectionString = option.AzureBatchBrokerStorageConnectionString; AzureBatchConfiguration.BrokerLauncherPath = option.BrokerLauncherExePath; } else if (!string.IsNullOrEmpty(option.HpcPackSchedulerAddress)) { SessionLauncherRuntimeConfiguration.SchedulerType = SchedulerType.HpcPack; } else if (!string.IsNullOrEmpty(option.ServiceHostExePath)) { SessionLauncherRuntimeConfiguration.SchedulerType = SchedulerType.Local; LocalSessionConfiguration.BrokerLauncherExePath = option.BrokerLauncherExePath; LocalSessionConfiguration.ServiceHostExePath = option.ServiceHostExePath; LocalSessionConfiguration.ServiceRegistrationPath = option.ServiceRegistrationPath; LocalSessionConfiguration.BrokerStorageConnectionString = option.LocalBrokerStorageConnectionString; } if (!string.IsNullOrEmpty(option.AzureBatchPoolName)) { AzureBatchConfiguration.BatchPoolName = option.AzureBatchPoolName; } if (!string.IsNullOrEmpty(option.AzureBatchBrokerStorageConnectionString)) { SessionLauncherRuntimeConfiguration.SessionLauncherStorageConnectionString = option.AzureBatchBrokerStorageConnectionString; } if (!string.IsNullOrEmpty(option.Logging)) { try { LogHelper.SetLoggingConfig(option, $"{Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location)}/HpcSession.exe.config", "SessionLauncher"); } catch (Exception e) { Trace.TraceError("Exception occurs when configure logging - " + e); } } } } var result = new Parser( s => { s.CaseSensitive = false; s.HelpWriter = Console.Error; }).ParseArguments <SessionLauncherStartOption>(args).WithParsed(SetGlobalConfiguration); return(result.Tag == ParserResultType.Parsed); }