public OrchestratorController(OrchestratorConfiguration config) { _config = config; Put("/register", @params => Orchestrator.Instance.RegisterTest( Uri.UnescapeDataString((string)Request.Query.testName), Uri.UnescapeDataString((string)Request.Query.testClassName), Uri.UnescapeDataString((string)Request.Query.author))); Put("/unregister", @params => { Orchestrator.Instance.UnregisterTest(Uri.UnescapeDataString((string)Request.Query.testName)); return(Empty); }); Post("/report", @params => Orchestrator.Instance.ReportEvent(Uri.UnescapeDataString((string)Request.Query.testName), this.Bind <EventInfo>())); //get latest test by name Get <dynamic>("/latest-tests", @params => Response.AsJson(Orchestrator.Instance.GetLastTestByName(Uri.UnescapeDataString((string)Request.Query.testName)))); Get <dynamic>("/config-selectors", _ => Response.AsJson(Orchestrator.Instance.ConfigSelectorStrategies.Select(x => new { x.Name, x.Description }))); //PUT http://localhost:5000/config-selectors?strategyName=FirstClusterSelector Put("/config-selectors", @params => { var isSucceeded = Orchestrator.Instance.TrySetConfigSelectorStrategy(Uri.UnescapeDataString((string)Request.Query.strategyName)); return(isSucceeded ? HttpStatusCode.OK : HttpStatusCode.NotFound); }); }
public void Configure(IApplicationBuilder app) { var appConfig = new OrchestratorConfiguration(); ConfigurationBinder.Bind(config, appConfig); app.UseOwin(x => x.UseNancy(opt => opt.Bootstrapper = new ConfigBootstrapper(appConfig))); }
public static OrchestratorConfiguration GetOrchestratorConfigurationCopy(OrchestratorConfiguration config) { var orchestratorConfig = new OrchestratorConfiguration { OrchestratorUrl = config.OrchestratorUrl, EmbeddedServerUrl = config.EmbeddedServerUrl, Databases = new string[config.Databases.Length] }; var i = 0; foreach (var db in config.Databases) { orchestratorConfig.Databases[i++] = db; } i = 0; orchestratorConfig.LocalRavenServers = new ServerInfo[config.LocalRavenServers?.Length ?? 0]; foreach (var local in config.LocalRavenServers ?? orchestratorConfig.LocalRavenServers) { orchestratorConfig.LocalRavenServers[i] = new ServerInfo { Path = local.Path, Port = local.Port }; orchestratorConfig.LocalRavenServers[i++].Url = local.Url; } i = 0; orchestratorConfig.Clusters = new ClusterInfo[config.Clusters.Length]; foreach (var clusterInfo in config.Clusters) { orchestratorConfig.Clusters[i] = new ClusterInfo { HasAuthentication = clusterInfo.HasAuthentication, Name = clusterInfo.Name, PfxFilePath = clusterInfo.PfxFilePath }; var j = 0; orchestratorConfig.Clusters[i].Urls = new string[clusterInfo.Urls.Length]; foreach (var url in clusterInfo.Urls) { orchestratorConfig.Clusters[i].Urls[j++] = url; } i++; } orchestratorConfig.NotifierConfig = new SlackNotifier.NotifierConfig { Uri = config.NotifierConfig.Uri, UserEmail = config.NotifierConfig.UserEmail, UserName = config.NotifierConfig.UserName }; return(orchestratorConfig); }
public OrchestratorController(OrchestratorConfiguration config) { _config = config; Put("/register", @params => Orchestrator.Instance.RegisterTest( Uri.UnescapeDataString((string)Request.Query.testName), Uri.UnescapeDataString((string)Request.Query.testClassName), Uri.UnescapeDataString((string)Request.Query.author), Uri.UnescapeDataString((string)Request.Query.round))); Put("/unregister", @params => { Orchestrator.Instance.UnregisterTest(Uri.UnescapeDataString((string)Request.Query.testName), Uri.UnescapeDataString((string)Request.Query.round)); return(Empty); }); // Due to bug in Nancy (cannot serialize Exception), we copy the EventInfo: Post("/report", @params => { return(Orchestrator.Instance.ReportEvent(Uri.UnescapeDataString((string)Request.Query.testName), Uri.UnescapeDataString((string)Request.Query.round), this.Bind <EventInfoWithExceptionAsString>())); }); //get latest test by name Get <dynamic>("/latest-tests", @params => Response.AsJson(Orchestrator.Instance.GetLastTestByName(Uri.UnescapeDataString((string)Request.Query.testName), Uri.UnescapeDataString((string)Request.Query.round)))); //non success tests Get <dynamic>("/failing-tests", @params => Response.AsJson(Orchestrator.Instance.GetFailingTests())); Get <dynamic>("/config-selectors", _ => Response.AsJson(Orchestrator.Instance.ConfigSelectorStrategies.Select(x => new { x.Name, x.Description }))); //PUT http://localhost:5000/config-selectors?strategyName=FirstClusterSelector Put("/config-selectors", @params => { return(Orchestrator.Instance.TrySetConfigSelectorStrategy(Uri.UnescapeDataString((string)Request.Query.strategyName), Uri.UnescapeDataString((string)Request.Query.dbIndex ?? ""))); }); Get <dynamic>("/get-round", _ => Response.AsJson(Orchestrator.Instance.GetRound())); //PUT http://localhost:5000/set-round?round=345 Put("/set-round", @params => Orchestrator.Instance.SetRound(Request.Query.round).ToString()); Get <dynamic>("/round-results", _ => Response.AsJson(Orchestrator.Instance.GetRoundResults((string)Request.Query.round))); }
public static void Main(string[] args) { var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .SetBasePath(Environment.CurrentDirectory); var config = builder.Build(); var appConfig = new OrchestratorConfiguration(); ConfigurationBinder.Bind(config, appConfig); Console.WriteLine("Running RavenDB Test Orchestrator"); Console.WriteLine("================================="); var _orch = Orchestrator.Instance; var strategy = "FirstClusterSelector"; if (_orch.TrySetConfigSelectorStrategy(strategy, "1")) { Console.WriteLine($"Set default strategy to: {strategy}"); } else { throw new InvalidOperationException($"Cannot set strategy to {strategy}"); } _appConfig = appConfig; var notifTask = new Task(LaunchReadAndNotify, _cts.Token, TaskCreationOptions.LongRunning); notifTask.Start(); CreateWebHostBuilder(appConfig.OrchestratorUrl).Build().Run(); Console.WriteLine("Exiting..."); _cts.Cancel(); _mre.WaitOne(TimeSpan.FromSeconds(30)); Console.WriteLine("Exited"); }
protected Orchestrator() { var configProvider = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .Build(); _config = new OrchestratorConfiguration(); ConfigurationBinder.Bind(configProvider, _config); if (_config.Databases?.Length == 0) { throw new InvalidOperationException("Must be at least one database configured!"); } foreach (var serverInfo in _config.LocalRavenServers ?? Enumerable.Empty <ServerInfo>()) { RaiseServer(serverInfo); } EmbeddedServer.Instance.StartServer(new ServerOptions { ServerUrl = "http://127.0.0.1:8090" }); _reportingDocumentStore = EmbeddedServer.Instance.GetDocumentStore(new DatabaseOptions(OrchestratorDatabaseName)); _reportingDocumentStore.Initialize(); new LatestTestByName().Execute(_reportingDocumentStore); if (_config.Clusters == null || _config.Clusters.Length == 0) { throw new InvalidOperationException("Must be at least one RavenDB cluster info configured!"); } _container.Register(Classes.FromAssembly(typeof(Orchestrator).Assembly) .BasedOn <ITestConfigSelectorStrategy>() .WithServiceAllInterfaces() .LifestyleSingleton()); _configSelectorStrategies = _container.ResolveAll <ITestConfigSelectorStrategy>(); if (_configSelectorStrategies.Length == 0) { throw new InvalidOperationException("Something really bad happened... there is no config selector strategies implemented!"); } foreach (var strategy in _configSelectorStrategies) { strategy.Initialize(_config); } //TODO: make this choice persistent? (via the embedded RavenDB instance) _currentConfigSelectorStrategy = _configSelectorStrategies[0]; foreach (var clusterInfo in _config.Clusters ?? Enumerable.Empty <ClusterInfo>()) { clusterInfo.Urls = clusterInfo.Urls.Select(PrepareUrlForDocumentStore).ToArray(); var store = new DocumentStore { Database = _config.Databases?[0], Urls = clusterInfo.Urls, //Certificate = TODO: finish this }; store.Initialize(); _clusterDocumentStores.Add(clusterInfo, store); foreach (var database in _config.Databases ?? Enumerable.Empty <string>()) { EnsureDatabaseExists(database, store); } } }
public ConfigBootstrapper(OrchestratorConfiguration configuration) { _configuration = configuration; }
protected Orchestrator() { var configProvider = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .Build(); _config = new OrchestratorConfiguration(); ConfigurationBinder.Bind(configProvider, _config); if (_config.Databases?.Length == 0) { throw new InvalidOperationException("Must be at least one database configured!"); } Console.WriteLine($"EmbeddedServerUrl:{_config.EmbeddedServerUrl}"); Console.WriteLine($"OrchestratorUrl:{_config.OrchestratorUrl}"); Console.Write("Starting Embedded RavenDB... "); foreach (var serverInfo in _config.LocalRavenServers ?? Enumerable.Empty <ServerInfo>()) { RaiseServer(serverInfo); } EmbeddedServer.Instance.StartServer(new ServerOptions { ServerUrl = _config.EmbeddedServerUrl, CommandLineArgs = new List <string> { " --Security.UnsecuredAccessAllowed=PublicNetwork ", " --Setup.Mode=None ", $" --PublicServerUrl={_config.EmbeddedServerUrl}" } }); _reportingDocumentStore = EmbeddedServer.Instance.GetDocumentStore(new DatabaseOptions(OrchestratorDatabaseName)); _reportingDocumentStore.Initialize(); new LatestTestByName().Execute(_reportingDocumentStore); new FailTests().Execute(_reportingDocumentStore); Console.WriteLine("Done."); if (_config.Clusters == null || _config.Clusters.Length == 0) { throw new InvalidOperationException("Must be at least one RavenDB cluster info configured!"); } _container.Register(Classes.FromAssembly(typeof(Orchestrator).Assembly) .BasedOn <ITestConfigSelectorStrategy>() .WithServiceAllInterfaces() .LifestyleSingleton()); _configSelectorStrategies = _container.ResolveAll <ITestConfigSelectorStrategy>(); if (_configSelectorStrategies.Length == 0) { throw new InvalidOperationException("Something really bad happened... there is no config selector strategies implemented!"); } foreach (var strategy in _configSelectorStrategies) { strategy.Initialize(_config); } //TODO: make this choice persistent? (via the embedded RavenDB instance) _currentConfigSelectorStrategy = _configSelectorStrategies[0]; foreach (var clusterInfo in _config.Clusters ?? Enumerable.Empty <ClusterInfo>()) { var cert = clusterInfo.PfxFilePath == null || clusterInfo.PfxFilePath.Equals("") ? null : new System.Security.Cryptography.X509Certificates.X509Certificate2(clusterInfo.PfxFilePath); var store = new DocumentStore { Database = _config.Databases?[0], Urls = clusterInfo.Urls, Certificate = cert }; store.Initialize(); _clusterDocumentStores.Add(clusterInfo, store); foreach (var database in _config.Databases ?? Enumerable.Empty <string>()) { EnsureDatabaseExists(database, store); } } }