void PicksUpExistingConfiguration() => WithValidPreflightChecks(s => s
                                                                 .Elasticsearch(e => e
                                                                                .EsConfigMachineVariable(LocationsModel.DefaultConfigDirectory)
                                                                                )
                                                                 .FileSystem(fs =>
 {
     fs.AddDirectory(LocationsModel.DefaultConfigDirectory);
     var yaml = Path.Combine(LocationsModel.DefaultConfigDirectory, "elasticsearch.yml");
     fs.AddFile(yaml, new MockFileData(@"cluster.name: x"));
     return(fs);
 })
                                                                 )
 .AssertTask(
     (m, s, fs) => new EditElasticsearchYamlTask(m, s, fs),
     (m, t) =>
 {
     var dir          = m.LocationsModel.ConfigDirectory;
     var yaml         = Path.Combine(dir, "elasticsearch.yml");
     var yamlContents = t.FileSystem.File.ReadAllText(yaml);
     yamlContents.Should().NotBeEmpty().And.NotBe("cluster.name: x");
     var config = ElasticsearchYamlConfiguration.FromFolder(dir, t.FileSystem);
     var s      = config.Settings;
     s.ClusterName.Should().Be("x");
     s.NodeName.Should().Be(ConfigurationModel.DefaultNodeName);
 }
     );
        protected override bool ExecuteTask()
        {
            RestoreConfigDirectory();
            RestoreXPackDirectory();
            RestorePluginsDirectory();

            // only delete config, logs and data if they were created by this installer operation
            var configDirectoryExisted = this.Session.Get <bool>(LocationsModel.ConfigDirectoryExists);
            var logsDirectoryExisted   = this.Session.Get <bool>(LocationsModel.LogsDirectoryExists);
            var dataDirectoryExisted   = this.Session.Get <bool>(LocationsModel.DataDirectoryExists);
            var configDirectory        = this.InstallationModel.LocationsModel.ConfigDirectory;

            if (!this.FileSystem.Directory.Exists(configDirectory))
            {
                this.Session.Log($"Config directory does not exist. skipping {configDirectory}");
            }
            else
            {
                var yamlConfiguration = ElasticsearchYamlConfiguration.FromFolder(configDirectory, this.FileSystem);
                var dataDirectory     = yamlConfiguration?.Settings?.DataPath ?? this.InstallationModel.LocationsModel.DataDirectory;
                var logsDirectory     = yamlConfiguration?.Settings?.LogsPath ?? this.InstallationModel.LocationsModel.LogsDirectory;

                this.Session.SendActionStart(3000, ActionName, "Removing data, logs, and config directory, if created",
                                             "Removing directories: [1]");
                this.DeleteDirectoryIfExistsAndCreated(dataDirectory, !dataDirectoryExisted);
                this.DumpElasticsearchLogOnRollback(logsDirectory);
                this.DeleteDirectoryIfExistsAndCreated(logsDirectory, !logsDirectoryExisted);
                this.DeleteDirectoryIfExistsAndCreated(configDirectory, !configDirectoryExisted);
            }

            return(true);
        }
 void DefaultMaxLocalStorageNodesNotService() => WithValidPreflightChecks(s => s
                                                                          .Elasticsearch(es => es
                                                                                         .EsConfigMachineVariable(LocationsModel.DefaultConfigDirectory)
                                                                                         )
                                                                          .FileSystem(fs =>
 {
     fs.AddFile(Path.Combine(LocationsModel.DefaultConfigDirectory, "elasticsearch.yml"), new MockFileData(@""));
     return(fs);
 })
                                                                          )
 .OnStep(m => m.ServiceModel, s => s.InstallAsService = false)
 .AssertTask(
     (m, s, fs) => new EditElasticsearchYamlTask(m, s, fs),
     (m, t) =>
 {
     var dir          = m.LocationsModel.ConfigDirectory;
     var yaml         = Path.Combine(dir, "elasticsearch.yml");
     var yamlContents = t.FileSystem.File.ReadAllText(yaml);
     yamlContents.Should().NotBeEmpty().And.NotBe("cluster.name: x");
     var config = ElasticsearchYamlConfiguration.FromFolder(dir, t.FileSystem);
     var s      = config.Settings;
     //because we do not install as service
     s.MaxLocalStorageNodes.Should().NotHaveValue();
 }
     );
Esempio n. 4
0
 [Fact] void WritesExpectedDefauts() => WithValidPreflightChecks()
 .AssertTask(
     (m, s, fs) => new EditElasticsearchYamlTask(m, s, fs),
     (m, t) =>
 {
     var dir          = m.LocationsModel.ConfigDirectory;
     var yaml         = Path.Combine(dir, "elasticsearch.yml");
     var yamlContents = t.FileSystem.File.ReadAllText(yaml);
     yamlContents.Should().NotBeEmpty().And.NotBe("cluster.name: x");
     var config = ElasticsearchYamlConfiguration.FromFolder(dir, t.FileSystem);
     var s      = config.Settings;
     s.ClusterName.Should().Be(ConfigurationModel.DefaultClusterName);
     s.NodeName.Should().Be(ConfigurationModel.DefaultNodeName);
     s.MasterNode.Should().Be(ConfigurationModel.DefaultMasterNode);
     s.DataNode.Should().Be(ConfigurationModel.DefaultDataNode);
     s.IngestNode.Should().Be(ConfigurationModel.DefaultIngestNode);
     s.MemoryLock.Should().Be(ConfigurationModel.DefaultMemoryLock);
     s.LogsPath.Should().Be(LocationsModel.DefaultLogsDirectory);
     s.DataPath.Should().Be(LocationsModel.DefaultDataDirectory);
     //because install as service is enabled by default
     s.MaxLocalStorageNodes.Should().Be(1);
     s.NetworkHost.Should().BeNullOrEmpty();
     s.HttpPortString.Should().Be("9200");
     s.TransportTcpPortString.Should().Be("9300");
     s.UnicastHosts.Should().BeNullOrEmpty();
 }
     );
Esempio n. 5
0
        [Fact] void XPackSettingsAlreadyInPlaceAreNotOverwritten() => DefaultValidModelForTasks(s => s
                                                                                                .Elasticsearch(es => es
                                                                                                               .EsConfigMachineVariable(LocationsModel.DefaultConfigDirectory)
                                                                                                               )
                                                                                                .FileSystem(fs =>
        {
            var yaml = $@"bootstrap.memory_lock: true
xpack.security.enabled: false
xpack.license.self_generated.type: trial
xpack.random_setting: something
";
            fs.AddFile(Path.Combine(LocationsModel.DefaultConfigDirectory, "elasticsearch.yml"), yaml);
            return(fs);
        })
                                                                                                )
        .AssertTask(
            (m, s, fs) => new EditElasticsearchYamlTask(m, s, fs),
            (m, t) =>
        {
            var dir    = m.LocationsModel.ConfigDirectory;
            var yaml   = Path.Combine(dir, "elasticsearch.yml");
            var config = ElasticsearchYamlConfiguration.FromFolder(dir, t.FileSystem);
            var s      = config.Settings;
            s.MemoryLock.Should().BeTrue();
            s.XPackLicenseSelfGeneratedType.Should().Be("trial");
            s.XPackSecurityEnabled.Should().BeFalse();
            //unknown x-pack setting is preserved
            s.Keys.Where(k => k.StartsWith("xpack")).Should().HaveCount(1);
        }
            );
Esempio n. 6
0
 [Fact] void DeselectingSecurityWritesFalseToYamlFile() => DefaultValidModelForTasks(s => s
                                                                                     .Elasticsearch(es => es
                                                                                                    .EsConfigMachineVariable(LocationsModel.DefaultConfigDirectory)
                                                                                                    )
                                                                                     .FileSystem(fs =>
 {
     fs.AddFile(Path.Combine(LocationsModel.DefaultConfigDirectory, "elasticsearch.yml"), new MockFileData(""));
     return(fs);
 })
                                                                                     )
 .OnStep(m => m.XPackModel, s =>
 {
     s.XPackLicense         = XPackLicenseMode.Trial;
     s.XPackSecurityEnabled = false;
 })
 .AssertTask(
     (m, s, fs) => new EditElasticsearchYamlTask(m, s, fs),
     (m, t) =>
 {
     var dir          = m.LocationsModel.ConfigDirectory;
     var yaml         = Path.Combine(dir, "elasticsearch.yml");
     var yamlContents = t.FileSystem.File.ReadAllText(yaml);
     yamlContents.Should().NotBeEmpty().And.NotBe("cluster.name: x");
     var config = ElasticsearchYamlConfiguration.FromFolder(dir, t.FileSystem);
     var s      = config.Settings;
     s.XPackLicenseSelfGeneratedType.Should().Be("trial");
     s.XPackSecurityEnabled.Should().BeFalse();
 }
     );
Esempio n. 7
0
 [Fact] void SelectingTrialDoesNotWriteSecurityEnabled() => WithValidPreflightChecks(s => s
                                                                                     .Elasticsearch(es => es
                                                                                                    .EsConfigMachineVariable(LocationsModel.DefaultConfigDirectory)
                                                                                                    )
                                                                                     .FileSystem(fs =>
 {
     fs.AddFile(Path.Combine(LocationsModel.DefaultConfigDirectory, "elasticsearch.yml"), new MockFileData(@""));
     return(fs);
 })
                                                                                     )
 .OnStep(m => m.PluginsModel, s => s.ChangeXPackSelection(true))
 .OnStep(m => m.XPackModel, s => s.XPackLicense = XPackLicenseMode.Trial)
 .AssertTask(
     (m, s, fs) => new EditElasticsearchYamlTask(m, s, fs),
     (m, t) =>
 {
     var dir          = m.LocationsModel.ConfigDirectory;
     var yaml         = Path.Combine(dir, "elasticsearch.yml");
     var yamlContents = t.FileSystem.File.ReadAllText(yaml);
     yamlContents.Should().NotBeEmpty().And.NotBe("cluster.name: x");
     var config = ElasticsearchYamlConfiguration.FromFolder(dir, t.FileSystem);
     var s      = config.Settings;
     s.XPackLicenseSelfGeneratedType.Should().Be(nameof(XPackLicenseMode.Trial).ToLowerInvariant());
     s.XPackSecurityEnabled.Should().BeNull();
 }
     );
Esempio n. 8
0
        [Fact] void RemovesXPackSettingsIfXPackIsNotBeingInstalled() => WithValidPreflightChecks(s => s
                                                                                                 .Elasticsearch(es => es
                                                                                                                .EsConfigMachineVariable(LocationsModel.DefaultConfigDirectory)
                                                                                                                )
                                                                                                 .FileSystem(fs =>
        {
            var yaml = $@"bootstrap.memory_lock: true
xpack.security.enabled = false
xpack.license.self_generated.type = trial
xpack.random_setting = something
";
            fs.AddFile(Path.Combine(LocationsModel.DefaultConfigDirectory, "elasticsearch.yml"), new MockFileData(@""));
            return(fs);
        })
                                                                                                 )
        .OnStep(m => m.PluginsModel, s => s.ChangeXPackSelection(false))
        .AssertTask(
            (m, s, fs) => new EditElasticsearchYamlTask(m, s, fs),
            (m, t) =>
        {
            var dir          = m.LocationsModel.ConfigDirectory;
            var yaml         = Path.Combine(dir, "elasticsearch.yml");
            var yamlContents = t.FileSystem.File.ReadAllText(yaml);
            yamlContents.Should().NotBeEmpty().And.NotBe("cluster.name: x");
            var config = ElasticsearchYamlConfiguration.FromFolder(dir, t.FileSystem);
            var s      = config.Settings;
            s.XPackLicenseSelfGeneratedType.Should().BeNull();
            s.XPackSecurityEnabled.Should().BeNull();
            s.Keys.Where(k => k.StartsWith("xpack")).Should().HaveCount(0);
        }
            );
        public InstallationModelTester(
            MockWixStateProvider wixState,
            MockJavaEnvironmentStateProvider javaState,
            MockElasticsearchEnvironmentStateProvider esState,
            NoopServiceStateProvider serviceState,
            NoopPluginStateProvider pluginState,
            MockFileSystem fileSystem,
            NoopSession session,
            string[] args)
        {
            if (wixState == null)
            {
                throw new ArgumentNullException(nameof(wixState));
            }
            if (javaState == null)
            {
                throw new ArgumentNullException(nameof(javaState));
            }
            if (esState == null)
            {
                throw new ArgumentNullException(nameof(esState));
            }

            this.JavaState         = javaState;
            this.EsState           = esState;
            this.PluginState       = pluginState;
            this.JavaConfig        = new JavaConfiguration(javaState);
            this.EsConfig          = ElasticsearchYamlConfiguration.FromFolder(esState.ConfigDirectory, fileSystem);
            this.JvmConfig         = LocalJvmOptionsConfiguration.FromFolder(esState.ConfigDirectory, fileSystem);
            this.InstallationModel = new InstallationModel(
                wixState, JavaConfig, esState, serviceState, pluginState, EsConfig, JvmConfig, session, args);
            this.FileSystem = fileSystem;
        }
Esempio n. 10
0
        private void RecheckPrequisites()
        {
            var javaState  = new JavaEnvironmentStateProvider();
            var esState    = new ElasticsearchEnvironmentStateProvider();
            var javaConfig = new JavaConfiguration(javaState);
            var esConfig   = ElasticsearchYamlConfiguration.FromFolder(esState.ConfigDirectory);

            this.ViewModel.BadElasticsearchYamlFile = esConfig.FoundButNotValid;
            this.ViewModel.JavaInstalled            = javaConfig.JavaInstalled;
            this.ViewModel.JavaMisconfigured        = javaConfig.JavaMisconfigured;
        }
Esempio n. 11
0
        public static InstallationModel Create(IWixStateProvider wixState, ISession session, params string[] args)
        {
            var javaConfig   = JavaConfiguration.Default;
            var esState      = ElasticsearchEnvironmentStateProvider.Default;
            var serviceState = ServiceStateProvider.FromSession(session);
            var pluginState  = PluginStateProvider.Default;

            var esConfig  = ElasticsearchYamlConfiguration.FromFolder(esState.ConfigDirectory);
            var jvmConfig = LocalJvmOptionsConfiguration.FromFolder(esState.ConfigDirectory);

            return(new InstallationModel(wixState, javaConfig, esState, serviceState, pluginState, esConfig, jvmConfig, session, args));
        }
Esempio n. 12
0
 [Fact] void CustomConfigValues() => DefaultValidModelForTasks(s => s
                                                               .Elasticsearch(es => es
                                                                              .EsConfigMachineVariable(LocationsModel.DefaultConfigDirectory)
                                                                              )
                                                               .FileSystem(fs =>
 {
     fs.AddFile(Path.Combine(LocationsModel.DefaultConfigDirectory, "elasticsearch.yml"), new MockFileData(@""));
     return(fs);
 })
                                                               )
 .OnStep(m => m.ConfigurationModel, s =>
 {
     s.ClusterName   = "x";
     s.NodeName      = "x";
     s.MasterNode    = false;
     s.DataNode      = false;
     s.IngestNode    = false;
     s.LockMemory    = false;
     s.NetworkHost   = "xyz";
     s.HttpPort      = 80;
     s.TransportPort = 9300;
     s.SeedHosts     = new ReactiveUI.ReactiveList <string>
     {
         "localhost", "192.2.3.1:9301"
     };
 })
 .AssertTask(
     (m, s, fs) => new EditElasticsearchYamlTask(m, s, fs),
     (m, t) =>
 {
     var dir          = m.LocationsModel.ConfigDirectory;
     var yaml         = Path.Combine(dir, "elasticsearch.yml");
     var yamlContents = t.FileSystem.File.ReadAllText(yaml);
     yamlContents.Should().NotBeEmpty().And.NotBe("cluster.name: x");
     var config = ElasticsearchYamlConfiguration.FromFolder(dir, t.FileSystem);
     var s      = config.Settings;
     s.ClusterName.Should().Be("x");
     s.NodeName.Should().Be("x");
     s.MasterNode.Should().BeFalse();
     s.IngestNode.Should().BeFalse();
     s.MemoryLock.Should().BeFalse();
     s.NetworkHost.Should().Be("xyz");
     s.HttpPort.Should().Be(80);
     s.HttpPortString.Should().Be("80");
     s.TransportTcpPort.Should().Be(9300);
     s.TransportTcpPortString.Should().Be("9300");
     s.UnicastHosts.Should().BeNullOrEmpty();
     s.SeedHosts.Should().BeEquivalentTo(new List <string>
     {
         "localhost", "192.2.3.1:9301"
     });
 }
     );
        public static ElasticsearchInstallationModel Create(IWixStateProvider wixState, ISession session, params string[] args)
        {
            var javaConfig          = JavaConfiguration.Default;
            var esEnvironmentConfig = ElasticsearchEnvironmentConfiguration.Default;
            var serviceState        = ServiceStateProvider.FromSession(session, "Elasticsearch");
            var pluginState         = PluginStateProviderBase.ElasticsearchDefault(session);

            var esConfig      = ElasticsearchYamlConfiguration.FromFolder(esEnvironmentConfig.ConfigDirectory);
            var jvmConfig     = LocalJvmOptionsConfiguration.FromFolder(esEnvironmentConfig.ConfigDirectory);
            var tempDirConfig = new TempDirectoryConfiguration(session, ElasticsearchEnvironmentStateProvider.Default, null);

            return(new ElasticsearchInstallationModel(wixState,
                                                      javaConfig, esEnvironmentConfig, serviceState, pluginState, esConfig, jvmConfig, tempDirConfig,
                                                      session, args));
        }
Esempio n. 14
0
        protected override bool ExecuteTask()
        {
            this.Session.SendActionStart(TotalTicks, ActionName, "Configuring Elasticsearch", "Configuring Elasticsearch: [1]");
            var locations = this.InstallationModel.LocationsModel;

            this.Session.SendProgress(1000, "reading elasticsearch.yml from " + locations.ConfigDirectory);
            var yaml = ElasticsearchYamlConfiguration.FromFolder(locations.ConfigDirectory, this.FileSystem);

            var settings = yaml.Settings;

            this.ApplyConfigurationModel(settings);
            this.ApplyLocationsModel(settings, locations);
            this.ApplyServiceModel(settings);
            this.ApplyXPackModel(settings);
            yaml.Save();
            this.Session.SendProgress(1000, "elasticsearch.yml updated");
            return(true);
        }
 [Fact] void WritesSeedHostsFor7() =>
 DefaultValidModelForTasks(s => s
                           .Elasticsearch(es => es.EsConfigMachineVariable(LocationsModel.DefaultConfigDirectory))
                           .FileSystem(fs =>
 {
     var yamlLocation = Path.Combine(LocationsModel.DefaultConfigDirectory, "elasticsearch.yml");
     fs.AddFile(yamlLocation, new MockFileData(@"discovery.zen.ping.unicast.hosts: ['192.2.3.1:9200']"));
     return(fs);
 })
                           )
 .OnStep(m => m.ConfigurationModel, s =>
 {
     s.ClusterName = "x";
     s.NodeName    = "x";
     //we read unicast host from previous install into seed hosts
     s.SeedHosts.Should().NotBeEmpty().And.Contain(h => h.Contains("9200"));
     //simulate a user change
     s.SeedHosts = new ReactiveUI.ReactiveList <string> {
         "localhost", "192.2.3.1:9201"
     };
 })
 .AssertTask(
     (m, s, fs) => new EditElasticsearchYamlTask(m, s, fs),
     (m, t) =>
 {
     var dir          = m.LocationsModel.ConfigDirectory;
     var yaml         = Path.Combine(dir, "elasticsearch.yml");
     var yamlContents = t.FileSystem.File.ReadAllText(yaml);
     // validate we are writing the yaml file in 7.0 format
     yamlContents.Should().NotBeEmpty()
     .And.Contain("discovery.seed_hosts")
     .And.Contain("192.2.3.1:9201")
     .And.NotContain("discovery.zen.ping.unicast.hosts")
     .And.NotContain("192.2.3.1:9200");
     var config = ElasticsearchYamlConfiguration.FromFolder(dir, t.FileSystem);
     var s      = config.Settings;
     s.ClusterName.Should().Be("x");
     s.NodeName.Should().Be("x");
     s.SeedHosts.Should().BeEquivalentTo(new List <string>
     {
         "localhost", "192.2.3.1:9201"
     });
 }
     );
        [Fact] void InitialMaster7SetsInitialMasterNodesIfNotSetPrior() =>
        DefaultValidModelForTasks(s => s
                                  .Elasticsearch(es => es.EsConfigMachineVariable(LocationsModel.DefaultConfigDirectory))
                                  .FileSystem(fs =>
        {
            var yamlLocation = Path.Combine(LocationsModel.DefaultConfigDirectory, "elasticsearch.yml");
            fs.AddFile(yamlLocation, new MockFileData(@"discovery.zen.minimum_master_nodes: 20"));
            return(fs);
        })
                                  )
        .OnStep(m => m.ConfigurationModel, s =>
        {
            s.ClusterName = "x";
            s.NodeName    = "nodex";
            s.InitialMaster.Should().BeFalse();
            s.InitialMaster = true;
        })
        .AssertTask(
            (m, s, fs) =>
        {
            m.ToMsiParamsString().Should()
            .Contain($"{nameof(ConfigurationModel.InitialMaster).ToUpperInvariant()}=\"true\"");
            return(new EditElasticsearchYamlTask(m, s, fs));
        },

            (m, t) =>
        {
            var dir          = m.LocationsModel.ConfigDirectory;
            var yaml         = Path.Combine(dir, "elasticsearch.yml");
            var yamlContents = t.FileSystem.File.ReadAllText(yaml);
            // validate we are writing the yaml file in 7.0 format
            yamlContents.Should().NotBeEmpty()
            // don't carry over minimum_master_nodes
            .And.NotContain("discovery.zen.minimum_master_nodes")
            .And.Contain("cluster.initial_master_nodes");
            var config = ElasticsearchYamlConfiguration.FromFolder(dir, t.FileSystem);
            var s      = config.Settings;
            s.ClusterName.Should().Be("x");
            s.NodeName.Should().Be("nodex");
            s.InitialMasterNodes.Should().BeEquivalentTo(new List <string> {
                "nodex"
            });
        }
            );
Esempio n. 17
0
 [Fact] void CustomConfigValues() => WithValidPreflightChecks()
 .OnStep(m => m.ConfigurationModel, s =>
 {
     s.ClusterName   = "x";
     s.NodeName      = "x";
     s.MasterNode    = false;
     s.DataNode      = false;
     s.IngestNode    = false;
     s.LockMemory    = false;
     s.NetworkHost   = "xyz";
     s.HttpPort      = 80;
     s.TransportPort = 9300;
     s.UnicastNodes  = new ReactiveUI.ReactiveList <string>
     {
         "localhost", "192.2.3.1:9301"
     };
 })
 .AssertTask(
     (m, s, fs) => new EditElasticsearchYamlTask(m, s, fs),
     (m, t) =>
 {
     var dir          = m.LocationsModel.ConfigDirectory;
     var yaml         = Path.Combine(dir, "elasticsearch.yml");
     var yamlContents = t.FileSystem.File.ReadAllText(yaml);
     yamlContents.Should().NotBeEmpty().And.NotBe("cluster.name: x");
     var config = ElasticsearchYamlConfiguration.FromFolder(dir, t.FileSystem);
     var s      = config.Settings;
     s.ClusterName.Should().Be("x");
     s.NodeName.Should().Be("x");
     s.MasterNode.Should().BeFalse();
     s.IngestNode.Should().BeFalse();
     s.MemoryLock.Should().BeFalse();
     s.NetworkHost.Should().Be("xyz");
     s.HttpPort.Should().Be(80);
     s.HttpPortString.Should().Be("80");
     s.TransportTcpPort.Should().Be(9300);
     s.TransportTcpPortString.Should().Be("9300");
     s.UnicastHosts.Should().BeEquivalentTo(new List <string>
     {
         "localhost", "192.2.3.1:9301"
     });
 }
     );
Esempio n. 18
0
        protected override bool ExecuteTask()
        {
            this.Session.SendActionStart(TotalTicks, ActionName, "Configuring Elasticsearch", "Configuring Elasticsearch: [1]");
            var locations = this.InstallationModel.LocationsModel;
            var config    = this.InstallationModel.ConfigurationModel;

            this.Session.SendProgress(1000, "reading elasticsearch.yml from " + locations.ConfigDirectory);
            var yaml = ElasticsearchYamlConfiguration.FromFolder(locations.ConfigDirectory, this.FileSystem);

            this.Session.SendProgress(1000, "updating elasticsearch.yml");
            var settings = yaml.Settings;

            settings.ClusterName          = config.ClusterName;
            settings.NodeName             = config.NodeName;
            settings.MasterNode           = config.MasterNode;
            settings.DataNode             = config.DataNode;
            settings.IngestNode           = config.IngestNode;
            settings.MemoryLock           = config.LockMemory;
            settings.LogsPath             = locations.LogsDirectory;
            settings.DataPath             = locations.DataDirectory;
            settings.MaxLocalStorageNodes = this.InstallationModel.ServiceModel.InstallAsService ? (int?)1 : null;
            settings.NetworkHost          = !string.IsNullOrEmpty(config.NetworkHost) ? config.NetworkHost : null;
            if (config.HttpPort.HasValue)
            {
                settings.HttpPortString = config.HttpPort.Value.ToString(CultureInfo.InvariantCulture);
            }
            if (config.TransportPort.HasValue)
            {
                settings.TransportTcpPortString = config.TransportPort.Value.ToString(CultureInfo.InvariantCulture);
            }
            var hosts = config.UnicastNodes;

            settings.UnicastHosts = hosts.Any() ? hosts.ToList() : null;
            yaml.Save();
            this.Session.SendProgress(1000, "elasticsearch.yml updated");
            return(true);
        }
Esempio n. 19
0
        /// <summary>
        /// This action ensures we remove the Elasticsearch installation directory completely.
        /// We can't rely on the MSI RemoveFiles step to remove directories/files that were registered
        /// on a full uninstall because new files may have been introduced later on (e.g. plugins).
        /// </summary>
        protected override bool ExecuteTask()
        {
            if (this.Session.IsRollback && this.InstallationModel.NoticeModel.ExistingVersionInstalled)
            {
                this.Session.Log($"Skipping {nameof(DeleteDirectoriesTask)}: Already installed and rolling back.");
                RestoreConfigDirectory();
                RestorePluginsDirectory();
                return(true);
            }

            if (this.InstallationModel.NoticeModel.ExistingVersionInstalled && !this.Session.IsUninstalling)
            {
                this.Session.Log($"Skipping {nameof(DeleteDirectoriesTask)}: Already installed and not currently uninstalling");
                return(true);
            }
            this.Session.Log($"Executing {nameof(DeleteDirectoriesTask)}");

            var configDirectory = this.InstallationModel.LocationsModel.ConfigDirectory;

            if (!this.FileSystem.Directory.Exists(configDirectory))
            {
                this.Session.Log($"Config directory does not exist aborting {configDirectory}");
                return(true);
            }

            this.Session.SendActionStart(1000, ActionName, "Removing data, logs, and config directory",
                                         "Removing directories: [1]");

            var yamlConfiguration = ElasticsearchYamlConfiguration.FromFolder(configDirectory, this.FileSystem);
            var dataDirectory     = yamlConfiguration?.Settings?.DataPath ?? this.InstallationModel.LocationsModel.DataDirectory;
            var logsDirectory     = yamlConfiguration?.Settings?.LogsPath ?? this.InstallationModel.LocationsModel.LogsDirectory;

            if (this.FileSystem.Directory.Exists(dataDirectory))
            {
                this.DeleteDirectory(dataDirectory);
            }
            else
            {
                this.Session.Log($"Data Directory does not exist, skipping {dataDirectory}");
            }

            if (this.FileSystem.Directory.Exists(logsDirectory))
            {
                DumpElasticsearchLogOnRollback(logsDirectory);
                this.DeleteDirectory(logsDirectory);
            }
            else
            {
                this.Session.Log($"Logs Directory does not exist, skipping {logsDirectory}");
            }

            if (this.FileSystem.Directory.Exists(configDirectory))
            {
                this.DeleteDirectory(configDirectory);
            }
            else
            {
                this.Session.Log($"Config Directory does not exist, skipping {configDirectory}");
            }

            this.Session.SendProgress(1000, "data, logs, and config directories removed");
            this.Session.Log("data, logs, and config directories removed");

            var installDirectory = this.InstallationModel.LocationsModel.InstallDir;

            if (!this.FileSystem.Directory.Exists(installDirectory))
            {
                this.Session.Log($"Install directory does not exist. aborting {installDirectory}");
                return(true);
            }

            var directories = this.FileSystem.Directory.GetDirectories(installDirectory).ToList();

            this.Session.SendActionStart((directories.Count * 1000) + 1000, ActionName, "Removing Elasticsearch installation directory",
                                         "Removing directories: [1]");
            foreach (var directory in directories)
            {
                this.Session.Log($"Attemping to delete {directory}");
                this.FileSystem.Directory.Delete(directory, true);
                this.Session.SendProgress(1000, $"{directory} removed");
            }

            if (IsDirectoryEmpty(installDirectory))
            {
                this.Session.Log($"{installDirectory} exists and is empty. deleting");
                this.FileSystem.Directory.Delete(installDirectory, true);
            }

            if (IsDirectoryEmpty(LocationsModel.DefaultProductInstallationDirectory))
            {
                this.Session.Log($"{LocationsModel.DefaultProductInstallationDirectory} exists and is empty. deleting");
                this.FileSystem.Directory.Delete(LocationsModel.DefaultProductInstallationDirectory, true);
            }

            if (IsDirectoryEmpty(LocationsModel.DefaultCompanyInstallationDirectory))
            {
                this.Session.Log($"{LocationsModel.DefaultCompanyInstallationDirectory} exists and is empty. deleting");
                this.FileSystem.Directory.Delete(LocationsModel.DefaultCompanyInstallationDirectory, true);
            }

            if (IsDirectoryEmpty(LocationsModel.DefaultProductDataDirectory))
            {
                this.Session.Log($"{LocationsModel.DefaultProductDataDirectory} exists and is empty. deleting");
                this.FileSystem.Directory.Delete(LocationsModel.DefaultProductDataDirectory, true);
            }

            if (IsDirectoryEmpty(LocationsModel.DefaultCompanyDataDirectory))
            {
                this.Session.Log($"{LocationsModel.DefaultCompanyDataDirectory} exists and is empty. deleting");
                this.FileSystem.Directory.Delete(LocationsModel.DefaultCompanyDataDirectory, true);
            }

            this.Session.SendProgress(1000, "Elasticsearch installation directory removed");

            return(true);
        }
Esempio n. 20
0
        /// <summary>
        /// This action ensures we remove the Elasticsearch installation directory completely.
        /// We can't rely on the MSI RemoveFiles step to remove directories/files that were registered
        /// on a full uninstall because new files may have been introduced later on (e.g. plugins).
        /// </summary>
        protected override bool ExecuteTask()
        {
            if (this.InstallationModel.NoticeModel.AlreadyInstalled && !this.Session.Uninstalling)
            {
                return(true);
            }

            var configDirectory = this.InstallationModel.LocationsModel.ConfigDirectory;

            if (!this.FileSystem.Directory.Exists(configDirectory))
            {
                return(true);
            }

            this.Session.SendActionStart(1000, ActionName, "Removing data, logs, and config directory",
                                         "Removing directories: [1]");

            var yamlConfiguration = ElasticsearchYamlConfiguration.FromFolder(configDirectory);
            var dataDirectory     = yamlConfiguration?.Settings?.DataPath ?? string.Empty;
            var logsDirectory     = yamlConfiguration?.Settings?.LogsPath ?? string.Empty;

            if (this.FileSystem.Directory.Exists(dataDirectory))
            {
                this.DeleteDirectory(dataDirectory);
            }

            if (this.FileSystem.Directory.Exists(logsDirectory))
            {
                DumpElasticsearchLogOnRollback(logsDirectory);
                this.DeleteDirectory(logsDirectory);
            }

            if (this.FileSystem.Directory.Exists(configDirectory))
            {
                this.DeleteDirectory(configDirectory);
            }

            this.Session.SendProgress(1000, "Data, logs, and config directories removed");

            var installDirectory = this.InstallationModel.LocationsModel.InstallDir;

            if (!this.FileSystem.Directory.Exists(installDirectory))
            {
                return(true);
            }

            var directories = this.FileSystem.Directory.GetDirectories(installDirectory).ToList();

            this.Session.SendActionStart((directories.Count * 1000) + 1000, ActionName, "Removing Elasticsearch installation directory",
                                         "Removing directories: [1]");
            foreach (var directory in directories)
            {
                this.Session.Log($"Attemping to delete {directory}");
                this.FileSystem.Directory.Delete(directory, true);
                this.Session.SendProgress(1000, $"{directory} removed");
            }

            if (Empty(installDirectory))
            {
                this.Session.Log($"{installDirectory} exists and is empty. deleting");
                this.FileSystem.Directory.Delete(installDirectory, true);
            }

            if (Empty(LocationsModel.DefaultProductInstallationDirectory))
            {
                this.Session.Log($"{LocationsModel.DefaultProductInstallationDirectory} exists and is empty. deleting");
                this.FileSystem.Directory.Delete(LocationsModel.DefaultProductInstallationDirectory, true);
            }

            if (Empty(LocationsModel.DefaultCompanyInstallationDirectory))
            {
                this.Session.Log($"{LocationsModel.DefaultCompanyInstallationDirectory} exists and is empty. deleting");
                this.FileSystem.Directory.Delete(LocationsModel.DefaultCompanyInstallationDirectory, true);
            }

            if (Empty(LocationsModel.DefaultProductDataDirectory))
            {
                this.Session.Log($"{LocationsModel.DefaultProductDataDirectory} exists and is empty. deleting");
                this.FileSystem.Directory.Delete(LocationsModel.DefaultProductDataDirectory, true);
            }

            if (Empty(LocationsModel.DefaultCompanyDataDirectory))
            {
                this.Session.Log($"{LocationsModel.DefaultCompanyDataDirectory} exists and is empty. deleting");
                this.FileSystem.Directory.Delete(LocationsModel.DefaultCompanyDataDirectory, true);
            }

            this.Session.SendProgress(1000, "Elasticsearch installation directory removed");

            return(true);
        }