Exemplo n.º 1
0
        public static int Main(string[] args)
        {
            _logger = new NLogLogger("spawner.logs.txt");

            if (args.Length > 1)
            {
                _logger.Error("Expecting at most one argument - the name of the config file (default when empty).");
                Console.ReadLine();
                return(1);
            }

            string configFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, args.Length == 1 ? args[0] : "spawner.json");
            string jsonText       = File.ReadAllText(configFileName);

            IJsonSerializer serializer    = new UnforgivingJsonSerializer();
            SpawnerConfig   spawnerConfig = serializer.Deserialize <SpawnerConfig>(jsonText);

            foreach ((string name, InitParams parameters) in spawnerConfig.Runners)
            {
                string serialized       = serializer.Serialize(parameters, true);
                string singleConfigPath = Path.Combine(Path.GetTempPath(), $"nethermind.runner.{name}.config.json");
                File.WriteAllText(singleConfigPath, serialized);

                CreateAppConsole(spawnerConfig.ReleasePath, name, new[] { singleConfigPath });
            }

            _logger.Info("Press ENTER to close all the spawned processes.");
            Console.ReadLine();
            foreach ((string name, Process process) in Processes)
            {
                _logger.Info($"Closing {name}...");
                if (!process.HasExited)
                {
                    process.Kill();
                    process.WaitForExit(5000);
                    if (process.HasExited)
                    {
                        _logger.Info($"{name} closed.");
                    }
                    else
                    {
                        _logger.Error($"{name} could not be closed.");
                    }
                }
                else
                {
                    _logger.Info($"{name} already exited.");
                }

                process.Close();
            }

            _logger.Info("Press ENTER to exit.");

            Console.ReadKey();
            return(0);
        }
Exemplo n.º 2
0
        public static int Main(string[] args)
        {
            _logger = new SimpleConsoleLogger();

            if (args.Length > 1)
            {
                _logger.Error("Expecting at most one argument - the name of the config file (default when empty).");
                Console.ReadLine();
                return(1);
            }

            string configFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, args.Length == 1 ? args[0] : "spawner_discovery_large.json");
            string jsonText       = File.ReadAllText(configFileName);

            IJsonSerializer serializer    = new UnforgivingJsonSerializer();
            SpawnerConfig   spawnerConfig = serializer.Deserialize <SpawnerConfig>(jsonText);

            var configTempDir = Path.Combine(Path.GetTempPath(), "SpawnerConfigs");

            if (!Directory.Exists(configTempDir))
            {
                Directory.CreateDirectory(configTempDir);
            }

            var files = Directory.GetFiles(configTempDir);

            foreach (var file in files)
            {
                File.Delete(file);
            }

            _logger.Info($"Storing all runner configs in: {configTempDir}");

            List <ProcessWrapper> wrappers = new List <ProcessWrapper>();

            foreach ((string name, JToken parameters) in spawnerConfig.Runners)
            {
                string serialized       = serializer.Serialize(parameters, true);
                string singleConfigPath = Path.Combine(configTempDir, $"nethermind.runner.{name}.cfg");
                File.WriteAllText(singleConfigPath, serialized);

                try
                {
                    wrappers.Add(CreateAppConsole(spawnerConfig.ReleasePath, spawnerConfig.DbBasePath, name, new[] { singleConfigPath }));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }

            ChaosMonkey chaosMonkey = new ChaosMonkey(_logger, new ChaosMonkey.ChaosMonkeyOptions {
                IntervalSeconds = 0, AllDownIntervalSeconds = 0
            }, wrappers.ToArray());

            chaosMonkey.Start();

            _logger.Info("Press ENTER to close all the spawned processes.");
            Console.ReadLine();

            chaosMonkey.Stop();

            _logger.Info("Press ENTER to exit.");

            Console.ReadKey();
            return(0);
        }