public override void Run(IEphemeralCluster <EphemeralClusterConfiguration> cluster)
        {
            if (cluster.CachingAndCachedHomeExists())
            {
                return;
            }

            var config = cluster.ClusterConfiguration;

            if (config.Version < "6.2.0" || config.Version >= "6.3.0")
            {
                return;
            }

            var batFile = cluster.FileSystem.Binary;

            cluster.Writer.WriteDiagnostic($"{{{nameof(EnsureElasticsearchBatWorksAcrossDrives)}}} patching {batFile} according to elastic/elasticsearch#29057");
            var contents = File.ReadAllLines(batFile);

            for (var i = 0; i < contents.Length; i++)
            {
                if (contents[i] != "cd \"%ES_HOME%\"")
                {
                    continue;
                }

                contents[i] = "cd /d \"%ES_HOME%\"";
                break;
            }

            File.WriteAllLines(batFile, contents);
        }
Exemplo n.º 2
0
        public override void Run(IEphemeralCluster <EphemeralClusterConfiguration> cluster)
        {
            if (!cluster.ClusterConfiguration.XPackInstalled)
            {
                return;
            }
            if (cluster.CachingAndCachedHomeExists())
            {
                return;
            }

            var config = cluster.ClusterConfiguration;
            var v      = config.Version;

            var envBinary = Path.Combine(config.FileSystem.ElasticsearchHome, "bin", "x-pack", "x-pack-env") + BinarySuffix;

            if (v.Major != 6 || File.Exists(envBinary))
            {
                return;
            }
            if (v >= "6.3.0")
            {
                return;
            }

            cluster.Writer.WriteDiagnostic($"{{{nameof(EnsureSecurityUsersInDefaultRealmAreAdded)}}} {envBinary} does not exist, patching now.");
            File.WriteAllText(envBinary, "set ES_CLASSPATH=!ES_CLASSPATH!;!ES_HOME!/plugins/x-pack/*");
        }
Exemplo n.º 3
0
        public override void Run(IEphemeralCluster <EphemeralClusterConfiguration> cluster)
        {
            if (cluster.CachingAndCachedHomeExists())
            {
                return;
            }

            var fs   = cluster.FileSystem;
            var v    = cluster.ClusterConfiguration.Version;
            var a    = cluster.ClusterConfiguration.Artifact;
            var from = v.Artifact(Product.Elasticsearch).DownloadUrl;
            var to   = Path.Combine(fs.LocalFolder, a.Archive);

            if (File.Exists(to))
            {
                cluster.Writer?.WriteDiagnostic(
                    $"{{{nameof(DownloadElasticsearchVersion)}}} {v} was already downloaded");
                return;
            }

            cluster.Writer?.WriteDiagnostic(
                $"{{{nameof(DownloadElasticsearchVersion)}}} downloading Elasticsearch [{v}] from {{{from}}} {{{to}}}");
            DownloadFile(from, to);
            cluster.Writer?.WriteDiagnostic(
                $"{{{nameof(DownloadElasticsearchVersion)}}} downloaded Elasticsearch [{v}] from {{{from}}} {{{to}}}");
        }
        public override void Run(IEphemeralCluster <EphemeralClusterConfiguration> cluster)
        {
            if (cluster.CachingAndCachedHomeExists())
            {
                return;
            }

            var fs = cluster.FileSystem;
            var v  = cluster.ClusterConfiguration.Version;

            if (Directory.Exists(fs.ElasticsearchHome))
            {
                cluster.Writer?.WriteDiagnostic($"{{{nameof(UnzipElasticsearch)}}} skipping [{fs.ElasticsearchHome}] already exists");
                return;
            }

            var from            = Path.Combine(fs.LocalFolder, v.Zip);
            var extractedFolder = Path.Combine(fs.LocalFolder, v.FolderInZip);

            if (!Directory.Exists(extractedFolder))
            {
                cluster.Writer?.WriteDiagnostic($"{{{nameof(UnzipElasticsearch)}}} unzipping version [{v}] {{{from}}}");
                ZipFile.ExtractToDirectory(from, fs.LocalFolder);
                cluster.Writer?.WriteDiagnostic($"{{{nameof(UnzipElasticsearch)}}} extracted version [{v}] to {{{fs.LocalFolder}}}");
            }

            if (extractedFolder == fs.ElasticsearchHome)
            {
                return;
            }

            cluster.Writer?.WriteDiagnostic($"{{{nameof(UnzipElasticsearch)}}} Copying extracted folder {{{extractedFolder}}} => {fs.ElasticsearchHome}");
            CopyFolder(extractedFolder, fs.ElasticsearchHome);
        }
Exemplo n.º 5
0
        public override void Run(IEphemeralCluster <EphemeralClusterConfiguration> cluster)
        {
            if (cluster.CachingAndCachedHomeExists())
            {
                return;
            }

            var v = cluster.ClusterConfiguration.Version;

            //on 2.x we do not support tests requiring plugins for 2.x since we can not reliably install them
            if (v.Major == 2)
            {
                cluster.Writer?.WriteDiagnostic($"{{{nameof(InstallPlugins)}}} skipping install plugins on {{2.x}} version: [{v}]");
                return;
            }

            var fs = cluster.FileSystem;
            var requiredPlugins = cluster.ClusterConfiguration.Plugins;
            var invalidPlugins  = requiredPlugins
                                  .Where(p => !p.IsValid(v))
                                  .Where(p => p.Moniker != "x-pack") //x-pack is already installed OOTB since 6.3.0 NOT an error condition though to specify the plugin
                                  .Select(p => p.Moniker).ToList();

            if (invalidPlugins.Any())
            {
                throw new CleanExitException($"Can not install the following plugins for version {v}: {string.Join(", ", invalidPlugins)} ");
            }

            var plugins =
                from plugin in requiredPlugins
                let validForCurrentVersion = plugin.IsValid(v)
                                             let alreadyInstalled = AlreadyInstalled(fs, plugin.FolderName)
                                                                    where !alreadyInstalled && validForCurrentVersion
                                                                    select plugin;

            foreach (var plugin in plugins)
            {
                //var installParameter = v.ReleaseState == ReleaseState.Released ? plugin.Moniker : UseHttpPluginLocation(cluster.Writer, fs, plugin, v);
                var installParameter = UseHttpPluginLocation(cluster.Writer, fs, plugin, v);
                ExecuteBinary(cluster.ClusterConfiguration, cluster.Writer, "cmd", $"install elasticsearch plugin: {plugin.Moniker}", $"/c CALL {fs.PluginBinary} install --batch", installParameter);
                CopyConfigDirectoryToHomeCacheConfigDirectory(cluster, plugin);
            }
        }
        public override void Run(IEphemeralCluster <EphemeralClusterConfiguration> cluster)
        {
            if (cluster.CachingAndCachedHomeExists())
            {
                return;
            }

            var v = cluster.ClusterConfiguration.Version;

            //on 2.x we do not support tests requiring plugins for 2.x since we can not reliably install them
            if (v.Major == 2)
            {
                cluster.Writer?.WriteDiagnostic($"{{{nameof(InstallPlugins)}}} skipping install plugins on {{2.x}} version: [{v}]");
                return;
            }
            if (v.Major < 7 && v.ArtifactBuildState == ArtifactBuildState.Snapshot)
            {
                cluster.Writer?.WriteDiagnostic($"{{{nameof(InstallPlugins)}}} skipping install SNAPSHOT plugins on < {{7.x}} version: [{v}]");
                return;
            }

            var fs = cluster.FileSystem;
            var requiredPlugins = cluster.ClusterConfiguration.Plugins;

            if (cluster.ClusterConfiguration.ValidatePluginsToInstall)
            {
                var invalidPlugins = requiredPlugins
                                     .Where(p => !p.IsValid(v))
                                     .Select(p => p.SubProductName).ToList();
                if (invalidPlugins.Any())
                {
                    throw new ElasticsearchCleanExitException(
                              $"Can not install the following plugins for version {v}: {string.Join(", ", invalidPlugins)} ");
                }
            }

            foreach (var plugin in requiredPlugins)
            {
                var includedByDefault = plugin.IsIncludedOutOfTheBox(v);
                if (includedByDefault)
                {
                    cluster.Writer?.WriteDiagnostic($"{{{nameof(Run)}}} SKIP plugin [{plugin.SubProductName}] shipped OOTB as of: {{{plugin.ShippedByDefaultAsOf}}}");
                    continue;
                }
                var validForCurrentVersion = plugin.IsValid(v);
                if (!validForCurrentVersion)
                {
                    cluster.Writer?.WriteDiagnostic($"{{{nameof(Run)}}} SKIP plugin [{plugin.SubProductName}] not valid for version: {{{v}}}");
                    continue;
                }
                var alreadyInstalled = AlreadyInstalled(fs, plugin.SubProductName);
                if (alreadyInstalled)
                {
                    cluster.Writer?.WriteDiagnostic($"{{{nameof(Run)}}} SKIP plugin [{plugin.SubProductName}] already installed");
                    continue;
                }

                cluster.Writer?.WriteDiagnostic($"{{{nameof(Run)}}} attempting install [{plugin.SubProductName}] as it's not OOTB: {{{plugin.ShippedByDefaultAsOf}}} and valid for {v}: {{{plugin.IsValid(v)}}}");
                //var installParameter = v.ReleaseState == ReleaseState.Released ? plugin.Moniker : UseHttpPluginLocation(cluster.Writer, fs, plugin, v);
                var installParameter = UseHttpPluginLocation(cluster.Writer, fs, plugin, v);
                if (!Directory.Exists(fs.ConfigPath))
                {
                    Directory.CreateDirectory(fs.ConfigPath);
                }
                ExecuteBinary(
                    cluster.ClusterConfiguration,
                    cluster.Writer,
                    fs.PluginBinary,
                    $"install elasticsearch plugin: {plugin.SubProductName}",
                    "install --batch", installParameter);

                CopyConfigDirectoryToHomeCacheConfigDirectory(cluster, plugin);
            }
        }