Beispiel #1
0
        private void InstallPlugins()
        {
            foreach (var plugin in ElasticsearchPlugins.Supported)
            {
                var installCommand   = plugin.Value;
                var installParameter = installCommand.InstallParameter != null?installCommand.InstallParameter(this.Version) : installCommand.Moniker;

                var folder       = installCommand.FolderName ?? installCommand.Moniker;
                var pluginFolder = Path.Combine(this.ElasticsearchHome, "plugins", folder);

                if (!Directory.Exists(this.ElasticsearchHome))
                {
                    continue;
                }

                // assume plugin already installed
                if (Directory.Exists(pluginFolder))
                {
                    continue;
                }

                Console.WriteLine($"Installing elasticsearch plugin: {installCommand.Moniker} ...");
                var timeout = TimeSpan.FromSeconds(120);
                var handle  = new ManualResetEvent(false);
                Task.Run(() =>
                {
                    using (var p = new ObservableProcess(this.PluginBinary, "install", installParameter))
                    {
                        var o = p.Start();
                        Console.WriteLine($"Calling: {this.PluginBinary} install {installParameter}");
                        o.Subscribe(c => Console.WriteLine(c.Data),
                                    (e) =>
                        {
                            Console.WriteLine($"Failed installing elasticsearch plugin: {installCommand.Moniker}");
                            handle.Set();
                            throw e;
                        },
                                    () =>
                        {
                            Console.WriteLine($"Finished installing elasticsearch plugin: {installCommand.Moniker} exit code: {p.ExitCode}");
                            handle.Set();
                        });
                        if (!handle.WaitOne(timeout, true))
                        {
                            throw new Exception($"Could not install {installCommand.Moniker} within {timeout}");
                        }
                    }
                });
                if (!handle.WaitOne(timeout, true))
                {
                    throw new Exception($"Could not install {installCommand.Moniker} within {timeout}");
                }
            }
        }
Beispiel #2
0
        private void InstallPlugins()
        {
            var pluginBat = Path.Combine(this.RoamingClusterFolder, "bin", "plugin") + ".bat";

            foreach (var plugin in SupportedPlugins)
            {
                var installPath  = plugin.Key;
                var localPath    = plugin.Value;
                var pluginFolder = Path.Combine(this.RoamingClusterFolder, "plugins", localPath);

                if (!Directory.Exists(this.RoamingClusterFolder))
                {
                    continue;
                }

                // assume plugin already installed
                if (Directory.Exists(pluginFolder))
                {
                    continue;
                }

                Console.WriteLine($"Installing elasticsearch plugin: {localPath} ...");
                var timeout = TimeSpan.FromSeconds(60);
                var handle  = new ManualResetEvent(false);
                Task.Run(() =>
                {
                    using (var p = new ObservableProcess(pluginBat, "install", installPath))
                    {
                        var o = p.Start();
                        Console.WriteLine($"Calling: {pluginBat} install {installPath}");
                        o.Subscribe(e => Console.WriteLine(e),
                                    (e) =>
                        {
                            Console.WriteLine($"Failed installing elasticsearch plugin: {localPath} ");
                            handle.Set();
                            throw e;
                        },
                                    () => {
                            Console.WriteLine($"Finished installing elasticsearch plugin: {localPath} exit code: {p.ExitCode}");
                            handle.Set();
                        });
                        if (!handle.WaitOne(timeout, true))
                        {
                            throw new ApplicationException($"Could not install ${installPath} within {timeout}");
                        }
                    }
                });
                if (!handle.WaitOne(timeout, true))
                {
                    throw new ApplicationException($"Could not install ${installPath} within {timeout}");
                }
            }
        }
        private void EnsureShieldAdmin()
        {
            if (!this._config.XPackEnabled)
            {
                return;
            }


            var folder = this.Version.Major >= 5 ? "x-pack" : "shield";
            var plugin = this.Version.Major >= 5 ? "users" : "esusers";

            EnsureRoles(folder);
            var timeout = TimeSpan.FromMinutes(1);

            var pluginBat = Path.Combine(this.ElasticsearchHome, "bin", folder, plugin) + ".bat";

            foreach (var cred in ShieldInformation.AllUsers)
            {
                var handle = new ManualResetEvent(false);
                Task.Run(() =>
                {
                    using (var p = new ObservableProcess(pluginBat, $"useradd {cred.Username} -p {cred.Password} -r {cred.Role}"))
                    {
                        var o = p.Start();
                        Console.WriteLine($"Calling: {pluginBat} useradd {cred.Username}");
                        o.Subscribe(
                            //c=>Console.WriteLine(c.Data),
                            c => { },
                            (e) =>
                        {
                            handle.Set();
                            throw e;
                        },
                            () =>
                        {
                            handle.Set();
                        });
                        if (!handle.WaitOne(timeout, true))
                        {
                            throw new Exception($"Could not add user {cred.Username} within {timeout}");
                        }
                    }
                });
                if (!handle.WaitOne(timeout, true))
                {
                    throw new Exception($"Could not add user {cred.Username} within {timeout}");
                }
            }
        }
        private void InstallPlugins()
        {
            var pluginBat = Path.Combine(this.RoamingClusterFolder, "bin", "plugin") + ".bat";

            foreach (var plugin in SupportedPlugins)
            {
                var installPath  = plugin.Key;
                var localPath    = plugin.Value;
                var pluginFolder = Path.Combine(this.RoamingClusterFolder, "bin", "plugins", localPath);
                if (!Directory.Exists(this.RoamingClusterFolder))
                {
                    continue;
                }

                var timeout = TimeSpan.FromSeconds(60);
                var handle  = new ManualResetEvent(false);
                Task.Factory.StartNew(() =>
                {
                    using (var p = new ObservableProcess(pluginBat, "install", installPath))
                    {
                        var o = p.Start();
                        o.Subscribe(Console.WriteLine,
                                    (e) =>
                        {
                            handle.Set();
                            throw e;
                        },
                                    () => handle.Set()
                                    );
                    }
                });
                if (!handle.WaitOne(timeout, true))
                {
                    throw new ApplicationException($"Could not install ${installPath} within {timeout}");
                }
            }
        }
		private void InstallPlugins()
		{
			var pluginBat = Path.Combine(this.RoamingClusterFolder, "bin", "plugin") + ".bat";
			foreach (var plugin in SupportedPlugins)
			{
				var installPath = plugin.Key;
				var localPath = plugin.Value;
				var pluginFolder = Path.Combine(this.RoamingClusterFolder, "plugins", localPath);

                if (!Directory.Exists(this.RoamingClusterFolder)) continue;

                // assume plugin already installed
			    if (Directory.Exists(pluginFolder)) continue;

				var timeout = TimeSpan.FromSeconds(60);
				var handle = new ManualResetEvent(false);
				Task.Run(() =>
				{
					using (var p = new ObservableProcess(pluginBat, "install", installPath))
					{
						var o = p.Start();
						o.Subscribe(Console.WriteLine,
							(e) =>
							{
								handle.Set();
								throw e;
							},
							() => handle.Set()
							);
					}
				});
				if (!handle.WaitOne(timeout, true))
					throw new ApplicationException($"Could not install ${installPath} within {timeout}");
			}
		}
		private void EnsureShieldAdmin()
		{
			if (!this._config.XPackEnabled) return;


			var folder = this.Version.Major >= 5 ? "x-pack" : "shield";
			var plugin = this.Version.Major >= 5 ? "users" : "esusers";

			EnsureRoles(folder);
			var timeout = TimeSpan.FromMinutes(1);

			var pluginBat = Path.Combine(this.ElasticsearchHome, "bin", folder, plugin) + ".bat";
			foreach (var cred in ShieldInformation.AllUsers)
			{
				var handle = new ManualResetEvent(false);
				Task.Run(() =>
				{
					using (var p = new ObservableProcess(pluginBat, $"useradd {cred.Username} -p {cred.Password} -r {cred.Role}"))
					{
						var o = p.Start();
						Console.WriteLine($"Calling: {pluginBat} useradd {cred.Username}");
						o.Subscribe(
							//c=>Console.WriteLine(c.Data),
							c => { },
							(e) =>
							{
								handle.Set();
								throw e;
							},
							() =>
							{
								handle.Set();
							});
						if (!handle.WaitOne(timeout, true))
							throw new Exception($"Could not add user {cred.Username} within {timeout}");
					}
				});
				if (!handle.WaitOne(timeout, true))
					throw new Exception($"Could not add user {cred.Username} within {timeout}");
			}
		}
		private void InstallPlugins()
		{
			foreach (var plugin in ElasticsearchPluginCollection.Supported.Where(plugin => plugin.IsValid(this.Version)))
			{
				var installParameter = plugin.InstallParamater(this.Version);
				var folder = plugin.FolderName;
				var pluginFolder = Path.Combine(this.ElasticsearchHome, "plugins", folder);

				if (!Directory.Exists(this.ElasticsearchHome)) continue;

				// assume plugin already installed
				if (Directory.Exists(pluginFolder)) continue;

				Console.WriteLine($"Installing elasticsearch plugin: {plugin.Moniker} ...");
				var timeout = TimeSpan.FromSeconds(120);
				var handle = new ManualResetEvent(false);
				Task.Run(() =>
				{
					using (var p = new ObservableProcess(this.PluginBinary, "install", installParameter))
					{
						var o = p.Start();
						Console.WriteLine($"Calling: {this.PluginBinary} install {installParameter}");
						o.Subscribe(c=>Console.WriteLine(c.Data),
							(e) =>
							{
								Console.WriteLine($"Failed installing elasticsearch plugin: {plugin.Moniker}");
								handle.Set();
								throw e;
							},
							() =>
							{
								Console.WriteLine($"Finished installing elasticsearch plugin: {plugin.Moniker} exit code: {p.ExitCode}");
								handle.Set();
							});
						if (!handle.WaitOne(timeout, true))
							throw new Exception($"Could not install {plugin.Moniker} within {timeout}");
					}
				});
				if (!handle.WaitOne(timeout, true))
					throw new Exception($"Could not install {plugin.Moniker} within {timeout}");
			}
		}