Beispiel #1
0
        public bool TrySetConfigSelectorStrategy(string strategyName)
        {
            var strategy = _configSelectorStrategies.FirstOrDefault(x =>
                                                                    x.Name.Equals(strategyName, StringComparison.InvariantCultureIgnoreCase));

            if (strategy == null)
            {
                return(false);
            }

            _currentConfigSelectorStrategy = strategy;
            return(true);
        }
        public bool TrySetConfigSelectorStrategy(string strategyName, string dbIndexStr)
        {
            var strategy = _configSelectorStrategies.FirstOrDefault(x =>
                                                                    x.Name.Equals(strategyName, StringComparison.InvariantCultureIgnoreCase));

            if (strategy == null)
            {
                return(false);
            }

            if (dbIndexStr != null &&
                dbIndexStr.Equals("") == false &&
                int.TryParse(dbIndexStr, out var dbIndex))
            {
                // re-init strategy with single database
                var newConfig = GetOrchestratorConfigurationCopy(_config);
                newConfig.Databases = new[] { _config.Databases[dbIndex] };
                strategy.Initialize(newConfig);
            }

            _currentConfigSelectorStrategy = strategy;
            return(true);
        }
Beispiel #3
0
        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);
                }
            }
        }
        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);
                }
            }
        }