From 64ff75f04e88e2441a275e3c207a251fe66d94a7 Mon Sep 17 00:00:00 2001 From: Brandon Kobel Date: Mon, 4 Feb 2019 21:45:28 -0800 Subject: [PATCH 1/7] Add apm_user reserved role (#38206) * Adding apm_user * Fixing SecurityDocumentationIT testGetRoles test * Adding access to .ml-anomalies-* * Fixing APM test, we don't have access to the ML state index --- .../documentation/SecurityDocumentationIT.java | 4 ++-- .../authz/store/ReservedRolesStore.java | 7 +++++++ .../authz/store/ReservedRolesStoreTests.java | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SecurityDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SecurityDocumentationIT.java index ea070868c6821..d041fa5d65d92 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SecurityDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SecurityDocumentationIT.java @@ -654,8 +654,8 @@ public void testGetRoles() throws Exception { List roles = response.getRoles(); assertNotNull(response); - // 24 system roles plus the three we created - assertThat(roles.size(), equalTo(27)); + // 25 system roles plus the three we created + assertThat(roles.size(), equalTo(28)); } { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/store/ReservedRolesStore.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/store/ReservedRolesStore.java index 9cb25f6a221d0..31f9883e2ffa2 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/store/ReservedRolesStore.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/store/ReservedRolesStore.java @@ -132,6 +132,13 @@ private static Map initializeReservedRoles() { new String[] { "monitor", MonitoringBulkAction.NAME}, null, null, MetadataUtils.DEFAULT_RESERVED_METADATA)) .put(UsernamesField.APM_ROLE, new RoleDescriptor(UsernamesField.APM_ROLE, new String[] { "monitor", MonitoringBulkAction.NAME}, null, null, MetadataUtils.DEFAULT_RESERVED_METADATA)) + .put("apm_user", new RoleDescriptor("apm_user", + null, new RoleDescriptor.IndicesPrivileges[] { + RoleDescriptor.IndicesPrivileges.builder().indices("apm-*") + .privileges("read", "view_index_metadata").build(), + RoleDescriptor.IndicesPrivileges.builder().indices(".ml-anomalies*") + .privileges("view_index_metadata", "read").build(), + }, null, MetadataUtils.DEFAULT_RESERVED_METADATA)) .put("machine_learning_user", new RoleDescriptor("machine_learning_user", new String[] { "monitor_ml" }, new RoleDescriptor.IndicesPrivileges[] { RoleDescriptor.IndicesPrivileges.builder().indices(".ml-anomalies*", ".ml-notifications*") diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/store/ReservedRolesStoreTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/store/ReservedRolesStoreTests.java index bda5304a26141..195ec3973f8f3 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/store/ReservedRolesStoreTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/store/ReservedRolesStoreTests.java @@ -849,6 +849,23 @@ public void testAPMSystemRole() { assertNoAccessAllowed(APMSystemRole, RestrictedIndicesNames.NAMES_SET); } + public void testAPMUserRole() { + final TransportRequest request = mock(TransportRequest.class); + + final RoleDescriptor roleDescriptor = new ReservedRolesStore().roleDescriptor("apm_user"); + assertNotNull(roleDescriptor); + assertThat(roleDescriptor.getMetadata(), hasEntry("_reserved", true)); + + Role role = Role.builder(roleDescriptor, null).build(); + + assertThat(role.runAs().check(randomAlphaOfLengthBetween(1, 12)), is(false)); + + assertNoAccessAllowed(role, "foo"); + + assertOnlyReadAllowed(role, "apm-" + randomIntBetween(0, 5)); + assertOnlyReadAllowed(role, AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + AnomalyDetectorsIndexFields.RESULTS_INDEX_DEFAULT); + } + public void testMachineLearningAdminRole() { final TransportRequest request = mock(TransportRequest.class); From 89feaa0e23ee4638668bbfcca11465d959c5bea9 Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Tue, 5 Feb 2019 09:09:15 +0100 Subject: [PATCH 2/7] Migration doc for audit json log file (#38165) The migration documentation for an audit logging changes. Removal of plaintext logs and rename of json log file relates #32850 --- docs/reference/migration/migrate_7_0/logging.asciidoc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/reference/migration/migrate_7_0/logging.asciidoc b/docs/reference/migration/migrate_7_0/logging.asciidoc index 0385397b31619..1329def9a1878 100644 --- a/docs/reference/migration/migrate_7_0/logging.asciidoc +++ b/docs/reference/migration/migrate_7_0/logging.asciidoc @@ -31,3 +31,12 @@ Note: GC logs which are written to the file `gc.log` will not be changed. ==== Docker output in JSON format All Docker console logs are now in JSON format. You can distinguish logs streams with the `type` field. + +[float] +==== Audit plaintext log file removed, JSON file renamed + +Elasticsearch no longer produces the `${cluster_name}_access.log` plaintext +audit log file. The `${cluster_name}_audit.log` files also no longer exist; they +are replaced by `${cluster_name}_audit.json` files. When auditing is enabled, +auditing events are stored in these dedicated JSON log files on each node. + From 2d114a02fffb75c3088561c9ec6ab6fb67e8d980 Mon Sep 17 00:00:00 2001 From: David Turner Date: Tue, 5 Feb 2019 08:46:52 +0000 Subject: [PATCH 3/7] Rename static Zen1 settings (#38333) Renames the following settings to remove the mention of `zen` in their names: - `discovery.zen.hosts_provider` -> `discovery.seed_providers` - `discovery.zen.ping.unicast.concurrent_connects` -> `discovery.seed_resolver.max_concurrent_resolvers` - `discovery.zen.ping.unicast.hosts.resolve_timeout` -> `discovery.seed_resolver.timeout` - `discovery.zen.ping.unicast.hosts` -> `discovery.seed_addresses` --- .../gradle/test/ClusterFormationTasks.groovy | 8 +- distribution/src/config/elasticsearch.yml | 4 +- docs/plugins/discovery-azure-classic.asciidoc | 2 +- docs/plugins/discovery-ec2.asciidoc | 2 +- docs/plugins/discovery-gce.asciidoc | 10 +- .../migration/migrate_7_0/discovery.asciidoc | 4 +- .../modules/discovery/bootstrapping.asciidoc | 4 +- .../discovery/discovery-settings.asciidoc | 20 ++-- .../modules/discovery/discovery.asciidoc | 28 +++--- docs/reference/modules/network.asciidoc | 15 ++- .../configuring-tls-docker.asciidoc | 2 +- .../reference/setup/bootstrap-checks.asciidoc | 4 +- .../discovery-settings.asciidoc | 8 +- docs/reference/setup/install/docker.asciidoc | 2 +- .../AbstractAzureComputeServiceTestCase.java | 3 +- .../AzureDiscoveryClusterFormationTests.java | 2 +- .../discovery-ec2/qa/amazon-ec2/build.gradle | 2 +- .../ec2/Ec2DiscoveryUpdateSettingsTests.java | 2 +- plugins/discovery-gce/qa/gce/build.gradle | 2 +- .../discovery/gce/GceDiscoverTests.java | 3 +- .../bootstrap/BootstrapChecks.java | 6 +- .../coordination/ClusterBootstrapService.java | 11 ++- .../common/settings/ClusterSettings.java | 12 ++- .../discovery/DiscoveryModule.java | 27 ++++-- .../UnicastConfiguredHostsResolver.java | 9 +- .../zen/SettingsBasedHostsProvider.java | 29 ++++-- .../discovery/zen/UnicastZenPing.java | 46 +++++++-- .../plugins/DiscoveryPlugin.java | 2 +- .../bootstrap/BootstrapChecksTests.java | 9 +- .../ClusterBootstrapServiceTests.java | 8 +- .../discovery/DiscoveryModuleTests.java | 33 +++++-- .../zen/SettingsBasedHostsProviderIT.java | 12 +-- .../zen/SettingsBasedHostsProviderTests.java | 94 +++++++++++++++++++ .../discovery/zen/UnicastZenPingTests.java | 11 ++- .../elasticsearch/test/ESIntegTestCase.java | 8 +- .../test/ESSingleNodeTestCase.java | 4 +- .../test/discovery/TestZenDiscovery.java | 6 +- .../test/test/InternalTestClusterTests.java | 18 ++-- .../elasticsearch/xpack/CcrIntegTestCase.java | 8 +- .../elasticsearch/license/LicensingTests.java | 6 +- ...ServerTransportFilterIntegrationTests.java | 5 +- .../netty4/IPHostnameVerificationTests.java | 5 +- .../WatcherExecutorServiceBenchmark.java | 3 +- .../resources/packaging/tests/certgen.bash | 4 +- 44 files changed, 348 insertions(+), 155 deletions(-) create mode 100644 server/src/test/java/org/elasticsearch/discovery/zen/SettingsBasedHostsProviderTests.java diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy index f32d0d858f81f..7a0a7d9436ee2 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy @@ -131,10 +131,12 @@ class ClusterFormationTasks { writeConfigSetup = { Map esConfig -> if (config.getAutoSetHostsProvider()) { // Don't force discovery provider if one is set by the test cluster specs already - if (esConfig.containsKey('discovery.zen.hosts_provider') == false) { - esConfig['discovery.zen.hosts_provider'] = 'file' + final String seedProvidersSettingName = + node.nodeVersion.onOrAfter("7.0.0") ? "discovery.seed_providers" : "discovery.zen.hosts_provider"; + if (esConfig.containsKey(seedProvidersSettingName) == false) { + esConfig[seedProvidersSettingName] = 'file' } - esConfig['discovery.zen.ping.unicast.hosts'] = [] + esConfig[node.nodeVersion.onOrAfter("7.0.0") ? "discovery.seed_hosts" : "discovery.zen.ping.unicast.hosts"] = [] } boolean supportsInitialMasterNodes = hasBwcNodes == false || config.bwcVersion.onOrAfter("7.0.0") if (esConfig['discovery.type'] == null && config.getAutoSetInitialMasterNodes() && supportsInitialMasterNodes) { diff --git a/distribution/src/config/elasticsearch.yml b/distribution/src/config/elasticsearch.yml index ceb1fc078648f..a87d7f70825ed 100644 --- a/distribution/src/config/elasticsearch.yml +++ b/distribution/src/config/elasticsearch.yml @@ -62,10 +62,10 @@ ${path.logs} # # --------------------------------- Discovery ---------------------------------- # -# Pass an initial list of hosts to perform discovery when new node is started: +# Pass an initial list of hosts to perform discovery when this node is started: # The default list of hosts is ["127.0.0.1", "[::1]"] # -#discovery.zen.ping.unicast.hosts: ["host1", "host2"] +#discovery.seed_hosts: ["host1", "host2"] # # Bootstrap the cluster using an initial set of master-eligible nodes: # diff --git a/docs/plugins/discovery-azure-classic.asciidoc b/docs/plugins/discovery-azure-classic.asciidoc index 30a8ee9c43df8..0e93d065a42fe 100644 --- a/docs/plugins/discovery-azure-classic.asciidoc +++ b/docs/plugins/discovery-azure-classic.asciidoc @@ -30,7 +30,7 @@ cloud: type: pkcs12 discovery: - zen.hosts_provider: azure + seed_providers: azure ---- [IMPORTANT] diff --git a/docs/plugins/discovery-ec2.asciidoc b/docs/plugins/discovery-ec2.asciidoc index 57b5b8468fafb..fbf24a9463bb1 100644 --- a/docs/plugins/discovery-ec2.asciidoc +++ b/docs/plugins/discovery-ec2.asciidoc @@ -20,7 +20,7 @@ provider for Zen discovery to `ec2`: [source,yaml] ---- -discovery.zen.hosts_provider: ec2 +discovery.seed_providers: ec2 ---- ==== Settings diff --git a/docs/plugins/discovery-gce.asciidoc b/docs/plugins/discovery-gce.asciidoc index 633b136bc7186..0324a8ff559a0 100644 --- a/docs/plugins/discovery-gce.asciidoc +++ b/docs/plugins/discovery-gce.asciidoc @@ -19,7 +19,7 @@ cloud: project_id: zone: discovery: - zen.hosts_provider: gce + seed_providers: gce -------------------------------------------------- The following gce settings (prefixed with `cloud.gce`) are supported: @@ -232,7 +232,7 @@ cloud: project_id: es-cloud zone: europe-west1-a discovery: - zen.hosts_provider: gce + seed_providers: gce -------------------------------------------------- @@ -346,7 +346,7 @@ cloud: project_id: zone: ["", ""] discovery: - zen.hosts_provider: gce + seed_providers: gce -------------------------------------------------- @@ -382,7 +382,7 @@ cloud: project_id: es-cloud zone: europe-west1-a discovery: - zen.hosts_provider: gce + seed_providers: gce gce: tags: elasticsearch, dev -------------------------------------------------- @@ -497,7 +497,7 @@ cloud: project_id: es-cloud zone: europe-west1-a discovery: - zen.hosts_provider: gce + seed_providers: gce -------------------------------------------------- Replaces `project_id` and `zone` with your settings. diff --git a/docs/reference/migration/migrate_7_0/discovery.asciidoc b/docs/reference/migration/migrate_7_0/discovery.asciidoc index 193f6bdd86a6f..d7e2a494206a0 100644 --- a/docs/reference/migration/migrate_7_0/discovery.asciidoc +++ b/docs/reference/migration/migrate_7_0/discovery.asciidoc @@ -35,6 +35,6 @@ Production deployments of Elasticsearch now require at least one of the following settings to be specified in the `elasticsearch.yml` configuration file: -- `discovery.zen.ping.unicast.hosts` -- `discovery.zen.hosts_provider` +- `discovery.seed_hosts` +- `discovery.seed_providers` - `cluster.initial_master_nodes` diff --git a/docs/reference/modules/discovery/bootstrapping.asciidoc b/docs/reference/modules/discovery/bootstrapping.asciidoc index ee77dca342533..5be2e170cc3b6 100644 --- a/docs/reference/modules/discovery/bootstrapping.asciidoc +++ b/docs/reference/modules/discovery/bootstrapping.asciidoc @@ -94,6 +94,6 @@ If any of the following settings are configured then auto-bootstrapping will not take place, and you must configure `cluster.initial_master_nodes` as described in the <>: -* `discovery.zen.hosts_provider` -* `discovery.zen.ping.unicast.hosts` +* `discovery.seed_providers` +* `discovery.seed_hosts` * `cluster.initial_master_nodes` diff --git a/docs/reference/modules/discovery/discovery-settings.asciidoc b/docs/reference/modules/discovery/discovery-settings.asciidoc index 4d6301fe1a9f5..517712c513f86 100644 --- a/docs/reference/modules/discovery/discovery-settings.asciidoc +++ b/docs/reference/modules/discovery/discovery-settings.asciidoc @@ -105,9 +105,10 @@ Discovery and cluster formation are affected by the following settings: `discovery.cluster_formation_warning_timeout`:: Sets how long a node will try to form a cluster before logging a warning - that the cluster did not form. Defaults to `10s`. If a cluster has not + that the cluster did not form. Defaults to `10s`. If a cluster has not formed after `discovery.cluster_formation_warning_timeout` has elapsed then - the node will log a warning message that starts with the phrase `master not discovered` which describes the current state of the discovery process. + the node will log a warning message that starts with the phrase `master not + discovered` which describes the current state of the discovery process. `discovery.find_peers_interval`:: @@ -128,9 +129,9 @@ Discovery and cluster formation are affected by the following settings: Sets how long a node will wait after asking its peers again before considering the request to have failed. Defaults to `3s`. -`discovery.zen.hosts_provider`:: - Specifies which type of <> provides - the list of seed nodes. By default, it is the +`discovery.seed_providers`:: + Specifies which types of <> provide + the addresses of seed nodes. By default, it is the <>. [[no-master-block]]`discovery.zen.no_master_block`:: @@ -157,7 +158,7 @@ APIs are not be blocked and can run on any available node. =============================== -- -`discovery.zen.ping.unicast.hosts`:: +`discovery.seed_hosts`:: Provides a list of master-eligible nodes in the cluster. The list contains either an array of hosts or a comma-delimited string. Each value has the @@ -165,7 +166,12 @@ APIs are not be blocked and can run on any available node. `transport.profiles.default.port`. Note that IPv6 hosts must be bracketed. The default value is `127.0.0.1, [::1]`. See <>. -`discovery.zen.ping.unicast.hosts.resolve_timeout`:: +`discovery.seed_resolver.timeout`:: Sets the amount of time to wait for DNS lookups on each round of discovery. This is specified as a <> and defaults to `5s`. + +`discovery.seed_resolver.max_concurrent_resolvers`:: + + Sets the number of threads with which to perform DNS lookups for seed nodes. + This defaults to `10`. diff --git a/docs/reference/modules/discovery/discovery.asciidoc b/docs/reference/modules/discovery/discovery.asciidoc index 737f8718113f1..daf60831818e9 100644 --- a/docs/reference/modules/discovery/discovery.asciidoc +++ b/docs/reference/modules/discovery/discovery.asciidoc @@ -34,7 +34,7 @@ By default the cluster formation module offers two hosts providers to configure the list of seed nodes: a _settings_-based and a _file_-based hosts provider. It can be extended to support cloud environments and other forms of hosts providers via {plugins}/discovery.html[discovery plugins]. Hosts providers are -configured using the `discovery.zen.hosts_provider` setting, which defaults to +configured using the `discovery.seed_providers` setting, which defaults to the _settings_-based hosts provider. Multiple hosts providers can be specified as a list. @@ -49,12 +49,12 @@ round of discovery. Note that if you are in an environment where DNS resolutions vary with time, you might need to adjust your <>. -The list of hosts is set using the <> static +The list of hosts is set using the <> static setting. For example: [source,yaml] -------------------------------------------------- -discovery.zen.ping.unicast.hosts: +discovery.seed_hosts: - 192.168.1.10:9300 - 192.168.1.11 <1> - seeds.mydomain.com <2> @@ -64,9 +64,9 @@ discovery.zen.ping.unicast.hosts: <2> A hostname that resolves to multiple IP addresses will try all resolved addresses. -Additionally, the `discovery.zen.ping.unicast.hosts.resolve_timeout` configures -the amount of time to wait for DNS lookups on each round of discovery. This is -specified as a <> and defaults to 5s. +Additionally, the `discovery.seed_resolver.timeout` configures the amount of +time to wait for DNS lookups on each round of discovery. This is specified as a +<> and defaults to 5s. Unicast discovery uses the <> module to perform the discovery. @@ -87,7 +87,7 @@ in the `elasticsearch.yml` file: [source,yml] ---------------------------------------------------------------- -discovery.zen.hosts_provider: file +discovery.seed_providers: file ---------------------------------------------------------------- Then create a file at `$ES_PATH_CONF/unicast_hosts.txt` in the format described @@ -95,13 +95,13 @@ below. Any time a change is made to the `unicast_hosts.txt` file the new changes will be picked up by Elasticsearch and the new hosts list will be used. Note that the file-based discovery plugin augments the unicast hosts list in -`elasticsearch.yml`. If there are valid unicast host entries in -`discovery.zen.ping.unicast.hosts`, they are used in addition to those -supplied in `unicast_hosts.txt`. +`elasticsearch.yml`. If there are valid seed addresses in +`discovery.seed_hosts` then they are used in addition to those supplied in +`unicast_hosts.txt`. -The `discovery.zen.ping.unicast.hosts.resolve_timeout` setting also applies to -DNS lookups for nodes specified by address via file-based discovery. This is -specified as a <> and defaults to 5s. +The `discovery.seed_resolver.timeout` setting also applies to DNS lookups for +seed addresses given via file-based discovery. This is specified as a +<> and defaults to 5s. The format of the file is to specify one node entry per line. Each node entry consists of the host (host name or IP address) and an optional transport port @@ -123,7 +123,7 @@ the default port: ---------------------------------------------------------------- Host names are allowed instead of IP addresses (similar to -`discovery.zen.ping.unicast.hosts`), and IPv6 addresses must be specified in +`discovery.seed_hosts`), and IPv6 addresses must be specified in brackets with the port coming after the brackets. You can also add comments to this file. All comments must appear on diff --git a/docs/reference/modules/network.asciidoc b/docs/reference/modules/network.asciidoc index e8dd3adef6ed7..5806b4a1034a5 100644 --- a/docs/reference/modules/network.asciidoc +++ b/docs/reference/modules/network.asciidoc @@ -28,19 +28,18 @@ because `:` is a special character in YAML. + Defaults to `_local_`. -`discovery.zen.ping.unicast.hosts`:: +`discovery.seed_hosts`:: In order to join a cluster, a node needs to know the hostname or IP address of at least some of the other nodes in the cluster. This setting provides the -initial list of other nodes that this node will try to contact. Accepts IP -addresses or hostnames. If a hostname lookup resolves to multiple IP -addresses then each IP address will be used for discovery. +initial list of addresses this node will try to contact. Accepts IP addresses +or hostnames. If a hostname lookup resolves to multiple IP addresses then each +IP address will be used for discovery. https://en.wikipedia.org/wiki/Round-robin_DNS[Round robin DNS] -- returning a different IP from a list on each lookup -- can be used for discovery; non- -existent IP addresses will throw exceptions and cause another DNS lookup -on the next round of pinging (subject to JVM DNS caching). -+ -Defaults to `["127.0.0.1", "[::1]"]`. +existent IP addresses will throw exceptions and cause another DNS lookup on the +next round of pinging (subject to JVM DNS caching). + Defaults to +`["127.0.0.1", "[::1]"]`. `http.port`:: diff --git a/docs/reference/security/securing-communications/configuring-tls-docker.asciidoc b/docs/reference/security/securing-communications/configuring-tls-docker.asciidoc index 50c63de4b4fef..2588a49fc72b9 100644 --- a/docs/reference/security/securing-communications/configuring-tls-docker.asciidoc +++ b/docs/reference/security/securing-communications/configuring-tls-docker.asciidoc @@ -136,7 +136,7 @@ services: image: {docker-image} environment: - node.name=es02 - - discovery.zen.ping.unicast.hosts=es01 + - discovery.seed_hosts=es01 - cluster.initial_master_nodes=es01,es02 - ELASTIC_PASSWORD=$ELASTIC_PASSWORD - "ES_JAVA_OPTS=-Xms512m -Xmx512m" diff --git a/docs/reference/setup/bootstrap-checks.asciidoc b/docs/reference/setup/bootstrap-checks.asciidoc index d9b540d39ceb3..83209cbf3b853 100644 --- a/docs/reference/setup/bootstrap-checks.asciidoc +++ b/docs/reference/setup/bootstrap-checks.asciidoc @@ -252,6 +252,6 @@ This bootstrap check ensures that discovery is not running with the default configuration. It can be satisfied by setting at least one of the following properties: -- `discovery.zen.ping.unicast.hosts` -- `discovery.zen.hosts_provider` +- `discovery.seed_hosts` +- `discovery.seed_providers` - `cluster.initial_master_nodes` diff --git a/docs/reference/setup/important-settings/discovery-settings.asciidoc b/docs/reference/setup/important-settings/discovery-settings.asciidoc index 6f40289f902ff..5bc07382039cb 100644 --- a/docs/reference/setup/important-settings/discovery-settings.asciidoc +++ b/docs/reference/setup/important-settings/discovery-settings.asciidoc @@ -10,7 +10,7 @@ each other and elect a master node. [float] [[unicast.hosts]] -==== `discovery.zen.ping.unicast.hosts` +==== `discovery.seed_hosts` Out of the box, without any network configuration, Elasticsearch will bind to the available loopback addresses and will scan local ports 9300 to 9305 to try @@ -18,7 +18,7 @@ to connect to other nodes running on the same server. This provides an auto- clustering experience without having to do any configuration. When the moment comes to form a cluster with nodes on other servers, you must -use the `discovery.zen.ping.unicast.hosts` setting to provide a seed list of +use the `discovery.seed_hosts` setting to provide a seed list of other nodes in the cluster that are master-eligible and likely to be live and contactable. This setting should normally contain the addresses of all the master-eligible nodes in the cluster. @@ -44,7 +44,7 @@ This list is set using the `cluster.initial_master_nodes` setting. [source,yaml] -------------------------------------------------- -discovery.zen.ping.unicast.hosts: +discovery.seed_hosts: - 192.168.1.10:9300 - 192.168.1.11 <1> - seeds.mydomain.com <2> @@ -62,4 +62,4 @@ cluster.initial_master_nodes: <5> If multiple master nodes share an IP address then the port must be used to disambiguate them. -For more information, see <>. \ No newline at end of file +For more information, see <>. diff --git a/docs/reference/setup/install/docker.asciidoc b/docs/reference/setup/install/docker.asciidoc index 92710f4429f8a..b64b15703b215 100644 --- a/docs/reference/setup/install/docker.asciidoc +++ b/docs/reference/setup/install/docker.asciidoc @@ -187,7 +187,7 @@ services: container_name: es02 environment: - node.name=es02 - - discovery.zen.ping.unicast.hosts=es01 + - discovery.seed_hosts=es01 - cluster.initial_master_nodes=es01,es02 - cluster.name=docker-cluster - bootstrap.memory_lock=true diff --git a/plugins/discovery-azure-classic/src/test/java/org/elasticsearch/cloud/azure/classic/AbstractAzureComputeServiceTestCase.java b/plugins/discovery-azure-classic/src/test/java/org/elasticsearch/cloud/azure/classic/AbstractAzureComputeServiceTestCase.java index 7d77b9994d589..131099dd1e7e9 100644 --- a/plugins/discovery-azure-classic/src/test/java/org/elasticsearch/cloud/azure/classic/AbstractAzureComputeServiceTestCase.java +++ b/plugins/discovery-azure-classic/src/test/java/org/elasticsearch/cloud/azure/classic/AbstractAzureComputeServiceTestCase.java @@ -49,6 +49,7 @@ import java.util.concurrent.ConcurrentHashMap; import static org.elasticsearch.common.util.CollectionUtils.newSingletonArrayList; +import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING; public abstract class AbstractAzureComputeServiceTestCase extends ESIntegTestCase { @@ -63,7 +64,7 @@ public void clearAzureNodes() { protected Settings nodeSettings(int nodeOrdinal) { Settings.Builder builder = Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put("discovery.zen.hosts_provider", "azure"); + .put(DISCOVERY_SEED_PROVIDERS_SETTING.getKey(), "azure"); // We add a fake subscription_id to start mock compute service builder.put(Management.SUBSCRIPTION_ID_SETTING.getKey(), "fake") diff --git a/plugins/discovery-azure-classic/src/test/java/org/elasticsearch/discovery/azure/classic/AzureDiscoveryClusterFormationTests.java b/plugins/discovery-azure-classic/src/test/java/org/elasticsearch/discovery/azure/classic/AzureDiscoveryClusterFormationTests.java index a833d196ed502..45540ca5d8f05 100644 --- a/plugins/discovery-azure-classic/src/test/java/org/elasticsearch/discovery/azure/classic/AzureDiscoveryClusterFormationTests.java +++ b/plugins/discovery-azure-classic/src/test/java/org/elasticsearch/discovery/azure/classic/AzureDiscoveryClusterFormationTests.java @@ -116,7 +116,7 @@ protected Settings nodeSettings(int nodeOrdinal) { throw new RuntimeException(e); } return Settings.builder().put(super.nodeSettings(nodeOrdinal)) - .put(DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING.getKey(), AzureDiscoveryPlugin.AZURE) + .put(DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING.getKey(), AzureDiscoveryPlugin.AZURE) .put(Environment.PATH_LOGS_SETTING.getKey(), resolve) .put(TransportSettings.PORT.getKey(), 0) .put(Node.WRITE_PORTS_FILE_SETTING.getKey(), "true") diff --git a/plugins/discovery-ec2/qa/amazon-ec2/build.gradle b/plugins/discovery-ec2/qa/amazon-ec2/build.gradle index 898a31192ffb0..b5a6d1bb7d41c 100644 --- a/plugins/discovery-ec2/qa/amazon-ec2/build.gradle +++ b/plugins/discovery-ec2/qa/amazon-ec2/build.gradle @@ -54,7 +54,7 @@ integTestCluster { plugin ':plugins:discovery-ec2' keystoreSetting 'discovery.ec2.access_key', 'ec2_integration_test_access_key' keystoreSetting 'discovery.ec2.secret_key', 'ec2_integration_test_secret_key' - setting 'discovery.zen.hosts_provider', 'ec2' + setting 'discovery.seed_providers', 'ec2' setting 'network.host', '_ec2_' setting 'discovery.ec2.endpoint', "http://${-> ec2Fixture.addressAndPort}" systemProperty "com.amazonaws.sdk.ec2MetadataServiceEndpointOverride", "http://${-> ec2Fixture.addressAndPort}" diff --git a/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryUpdateSettingsTests.java b/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryUpdateSettingsTests.java index f11bd539fba7d..9802479fe84d3 100644 --- a/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryUpdateSettingsTests.java +++ b/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryUpdateSettingsTests.java @@ -38,7 +38,7 @@ public class Ec2DiscoveryUpdateSettingsTests extends AbstractAwsTestCase { public void testMinimumMasterNodesStart() { Settings nodeSettings = Settings.builder() - .put(DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING.getKey(), "ec2") + .put(DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING.getKey(), "ec2") .build(); internalCluster().startNode(nodeSettings); diff --git a/plugins/discovery-gce/qa/gce/build.gradle b/plugins/discovery-gce/qa/gce/build.gradle index 9b496207c5619..c02aecc27ed53 100644 --- a/plugins/discovery-gce/qa/gce/build.gradle +++ b/plugins/discovery-gce/qa/gce/build.gradle @@ -51,7 +51,7 @@ integTestCluster { dependsOn gceFixture numNodes = gceNumberOfNodes plugin ':plugins:discovery-gce' - setting 'discovery.zen.hosts_provider', 'gce' + setting 'discovery.seed_providers', 'gce' // use gce fixture for Auth calls instead of http://metadata.google.internal integTestCluster.environment 'GCE_METADATA_HOST', "http://${-> gceFixture.addressAndPort}" diff --git a/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoverTests.java b/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoverTests.java index 078a21ee842b6..bec65908d95da 100644 --- a/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoverTests.java +++ b/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoverTests.java @@ -40,6 +40,7 @@ import java.util.concurrent.ConcurrentHashMap; import static java.util.Collections.singletonList; +import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout; @ESIntegTestCase.ClusterScope(supportsDedicatedMasters = false, numDataNodes = 0, numClientNodes = 0) @@ -62,7 +63,7 @@ protected Collection> nodePlugins() { protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put("discovery.zen.hosts_provider", "gce") + .put(DISCOVERY_SEED_PROVIDERS_SETTING.getKey(), "gce") .put("cloud.gce.project_id", "test") .put("cloud.gce.zone", "test") .build(); diff --git a/server/src/main/java/org/elasticsearch/bootstrap/BootstrapChecks.java b/server/src/main/java/org/elasticsearch/bootstrap/BootstrapChecks.java index ebda7df66dc09..89d4e1bcece57 100644 --- a/server/src/main/java/org/elasticsearch/bootstrap/BootstrapChecks.java +++ b/server/src/main/java/org/elasticsearch/bootstrap/BootstrapChecks.java @@ -52,8 +52,8 @@ import java.util.stream.Stream; import static org.elasticsearch.cluster.coordination.ClusterBootstrapService.INITIAL_MASTER_NODES_SETTING; -import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING; -import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING; +import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING; +import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING; /** * We enforce bootstrap checks once a node has the transport protocol bound to a non-loopback interface or if the system property {@code @@ -735,7 +735,7 @@ public BootstrapCheckResult check(BootstrapContext context) { return BootstrapCheckResult.failure(String.format( Locale.ROOT, "the default discovery settings are unsuitable for production use; at least one of [%s] must be configured", - Stream.of(DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING, DISCOVERY_HOSTS_PROVIDER_SETTING, INITIAL_MASTER_NODES_SETTING) + Stream.of(DISCOVERY_SEED_HOSTS_SETTING, DISCOVERY_SEED_PROVIDERS_SETTING, INITIAL_MASTER_NODES_SETTING) .map(Setting::getKey).collect(Collectors.joining(", ")))); } } diff --git a/server/src/main/java/org/elasticsearch/cluster/coordination/ClusterBootstrapService.java b/server/src/main/java/org/elasticsearch/cluster/coordination/ClusterBootstrapService.java index cdbf6b6691077..78009b002cb71 100644 --- a/server/src/main/java/org/elasticsearch/cluster/coordination/ClusterBootstrapService.java +++ b/server/src/main/java/org/elasticsearch/cluster/coordination/ClusterBootstrapService.java @@ -48,8 +48,10 @@ import static java.util.Collections.emptyList; import static java.util.Collections.unmodifiableSet; -import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING; -import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING; +import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING; +import static org.elasticsearch.discovery.DiscoveryModule.LEGACY_DISCOVERY_HOSTS_PROVIDER_SETTING; +import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING; +import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.LEGACY_DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING; public class ClusterBootstrapService { @@ -91,8 +93,9 @@ public ClusterBootstrapService(Settings settings, TransportService transportServ } public static boolean discoveryIsConfigured(Settings settings) { - return Stream.of(DISCOVERY_HOSTS_PROVIDER_SETTING, DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING, INITIAL_MASTER_NODES_SETTING) - .anyMatch(s -> s.exists(settings)); + return Stream.of(DISCOVERY_SEED_PROVIDERS_SETTING, LEGACY_DISCOVERY_HOSTS_PROVIDER_SETTING, + DISCOVERY_SEED_HOSTS_SETTING, LEGACY_DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING, + INITIAL_MASTER_NODES_SETTING).anyMatch(s -> s.exists(settings)); } void onFoundPeersUpdated() { diff --git a/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java b/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java index f0331ad2e30b2..758b6532a61a1 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java @@ -387,7 +387,8 @@ public void apply(Settings value, Settings current, Settings previous) { NodeEnvironment.NODE_ID_SEED_SETTING, DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING, DiscoveryModule.DISCOVERY_TYPE_SETTING, - DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING, + DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING, + DiscoveryModule.LEGACY_DISCOVERY_HOSTS_PROVIDER_SETTING, FaultDetection.PING_RETRIES_SETTING, FaultDetection.PING_TIMEOUT_SETTING, FaultDetection.REGISTER_CONNECTION_LISTENER_SETTING, @@ -402,9 +403,12 @@ public void apply(Settings value, Settings current, Settings previous) { ZenDiscovery.MASTER_ELECTION_WAIT_FOR_JOINS_TIMEOUT_SETTING, ZenDiscovery.MASTER_ELECTION_IGNORE_NON_MASTER_PINGS_SETTING, ZenDiscovery.MAX_PENDING_CLUSTER_STATES_SETTING, - SettingsBasedHostsProvider.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING, - UnicastZenPing.DISCOVERY_ZEN_PING_UNICAST_CONCURRENT_CONNECTS_SETTING, - UnicastZenPing.DISCOVERY_ZEN_PING_UNICAST_HOSTS_RESOLVE_TIMEOUT, + SettingsBasedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING, + SettingsBasedHostsProvider.LEGACY_DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING, + UnicastZenPing.DISCOVERY_SEED_RESOLVER_MAX_CONCURRENT_RESOLVERS_SETTING, + UnicastZenPing.DISCOVERY_SEED_RESOLVER_TIMEOUT_SETTING, + UnicastZenPing.LEGACY_DISCOVERY_ZEN_PING_UNICAST_CONCURRENT_CONNECTS_SETTING, + UnicastZenPing.LEGACY_DISCOVERY_ZEN_PING_UNICAST_HOSTS_RESOLVE_TIMEOUT, SearchService.DEFAULT_KEEPALIVE_SETTING, SearchService.KEEPALIVE_INTERVAL_SETTING, SearchService.MAX_KEEPALIVE_SETTING, diff --git a/server/src/main/java/org/elasticsearch/discovery/DiscoveryModule.java b/server/src/main/java/org/elasticsearch/discovery/DiscoveryModule.java index 042eb9daa0d9d..5db6cd3ee0fc3 100644 --- a/server/src/main/java/org/elasticsearch/discovery/DiscoveryModule.java +++ b/server/src/main/java/org/elasticsearch/discovery/DiscoveryModule.java @@ -74,8 +74,12 @@ public class DiscoveryModule { public static final Setting DISCOVERY_TYPE_SETTING = new Setting<>("discovery.type", ZEN2_DISCOVERY_TYPE, Function.identity(), Property.NodeScope); - public static final Setting> DISCOVERY_HOSTS_PROVIDER_SETTING = - Setting.listSetting("discovery.zen.hosts_provider", Collections.emptyList(), Function.identity(), Property.NodeScope); + public static final Setting> LEGACY_DISCOVERY_HOSTS_PROVIDER_SETTING = + Setting.listSetting("discovery.zen.hosts_provider", Collections.emptyList(), Function.identity(), + Property.NodeScope, Property.Deprecated); + public static final Setting> DISCOVERY_SEED_PROVIDERS_SETTING = + Setting.listSetting("discovery.seed_providers", Collections.emptyList(), Function.identity(), + Property.NodeScope); private final Discovery discovery; @@ -90,7 +94,7 @@ public DiscoveryModule(Settings settings, ThreadPool threadPool, TransportServic for (DiscoveryPlugin plugin : plugins) { plugin.getZenHostsProviders(transportService, networkService).forEach((key, value) -> { if (hostProviders.put(key, value) != null) { - throw new IllegalArgumentException("Cannot register zen hosts provider [" + key + "] twice"); + throw new IllegalArgumentException("Cannot register seed provider [" + key + "] twice"); } }); BiConsumer joinValidator = plugin.getJoinValidator(); @@ -98,7 +102,8 @@ public DiscoveryModule(Settings settings, ThreadPool threadPool, TransportServic joinValidators.add(joinValidator); } } - List hostsProviderNames = DISCOVERY_HOSTS_PROVIDER_SETTING.get(settings); + + List hostsProviderNames = getSeedProviderNames(settings); // for bwc purposes, add settings provider even if not explicitly specified if (hostsProviderNames.contains("settings") == false) { List extendedHostsProviderNames = new ArrayList<>(); @@ -110,7 +115,7 @@ public DiscoveryModule(Settings settings, ThreadPool threadPool, TransportServic final Set missingProviderNames = new HashSet<>(hostsProviderNames); missingProviderNames.removeAll(hostProviders.keySet()); if (missingProviderNames.isEmpty() == false) { - throw new IllegalArgumentException("Unknown zen hosts providers " + missingProviderNames); + throw new IllegalArgumentException("Unknown seed providers " + missingProviderNames); } List filteredHostsProviders = hostsProviderNames.stream() @@ -151,8 +156,18 @@ public DiscoveryModule(Settings settings, ThreadPool threadPool, TransportServic discovery = Objects.requireNonNull(discoverySupplier.get()); } + private List getSeedProviderNames(Settings settings) { + if (LEGACY_DISCOVERY_HOSTS_PROVIDER_SETTING.exists(settings)) { + if (DISCOVERY_SEED_PROVIDERS_SETTING.exists(settings)) { + throw new IllegalArgumentException("it is forbidden to set both [" + DISCOVERY_SEED_PROVIDERS_SETTING.getKey() + "] and [" + + LEGACY_DISCOVERY_HOSTS_PROVIDER_SETTING.getKey() + "]"); + } + return LEGACY_DISCOVERY_HOSTS_PROVIDER_SETTING.get(settings); + } + return DISCOVERY_SEED_PROVIDERS_SETTING.get(settings); + } + public Discovery getDiscovery() { return discovery; } - } diff --git a/server/src/main/java/org/elasticsearch/discovery/UnicastConfiguredHostsResolver.java b/server/src/main/java/org/elasticsearch/discovery/UnicastConfiguredHostsResolver.java index fcc716a7785a4..87fc411a938b3 100644 --- a/server/src/main/java/org/elasticsearch/discovery/UnicastConfiguredHostsResolver.java +++ b/server/src/main/java/org/elasticsearch/discovery/UnicastConfiguredHostsResolver.java @@ -41,8 +41,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; -import static org.elasticsearch.discovery.zen.UnicastZenPing.DISCOVERY_ZEN_PING_UNICAST_CONCURRENT_CONNECTS_SETTING; - public class UnicastConfiguredHostsResolver extends AbstractLifecycleComponent implements ConfiguredHostsResolver { private static final Logger logger = LogManager.getLogger(UnicastConfiguredHostsResolver.class); @@ -53,6 +51,7 @@ public class UnicastConfiguredHostsResolver extends AbstractLifecycleComponent i private final SetOnce executorService = new SetOnce<>(); private final TimeValue resolveTimeout; private final String nodeName; + private final int concurrentConnects; public UnicastConfiguredHostsResolver(String nodeName, Settings settings, TransportService transportService, UnicastHostsProvider hostsProvider) { @@ -60,13 +59,13 @@ public UnicastConfiguredHostsResolver(String nodeName, Settings settings, Transp this.nodeName = nodeName; this.transportService = transportService; this.hostsProvider = hostsProvider; - resolveTimeout = UnicastZenPing.DISCOVERY_ZEN_PING_UNICAST_HOSTS_RESOLVE_TIMEOUT.get(settings); + resolveTimeout = UnicastZenPing.getResolveTimeout(settings); + concurrentConnects = UnicastZenPing.getMaxConcurrentResolvers(settings); } @Override protected void doStart() { - final int concurrentConnects = DISCOVERY_ZEN_PING_UNICAST_CONCURRENT_CONNECTS_SETTING.get(settings); - logger.debug("using concurrent_connects [{}], resolve_timeout [{}]", concurrentConnects, resolveTimeout); + logger.debug("using max_concurrent_resolvers [{}], resolver timeout [{}]", concurrentConnects, resolveTimeout); final ThreadFactory threadFactory = EsExecutors.daemonThreadFactory(settings, "[unicast_configured_hosts_resolver]"); executorService.set(EsExecutors.newScaling(nodeName + "/" + "unicast_configured_hosts_resolver", 0, concurrentConnects, 60, TimeUnit.SECONDS, threadFactory, transportService.getThreadPool().getThreadContext())); diff --git a/server/src/main/java/org/elasticsearch/discovery/zen/SettingsBasedHostsProvider.java b/server/src/main/java/org/elasticsearch/discovery/zen/SettingsBasedHostsProvider.java index 3b16c3734156f..b23d07cb68818 100644 --- a/server/src/main/java/org/elasticsearch/discovery/zen/SettingsBasedHostsProvider.java +++ b/server/src/main/java/org/elasticsearch/discovery/zen/SettingsBasedHostsProvider.java @@ -22,6 +22,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.common.settings.Setting; +import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.transport.TransportService; @@ -33,7 +34,7 @@ /** * An implementation of {@link UnicastHostsProvider} that reads hosts/ports - * from the "discovery.zen.ping.unicast.hosts" node setting. If the port is + * from the "discovery.seed_hosts" node setting. If the port is * left off an entry, a default port of 9300 is assumed. * * An example unicast hosts setting might look as follows: @@ -43,20 +44,31 @@ public class SettingsBasedHostsProvider implements UnicastHostsProvider { private static final Logger logger = LogManager.getLogger(SettingsBasedHostsProvider.class); - public static final Setting> DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING = - Setting.listSetting("discovery.zen.ping.unicast.hosts", emptyList(), Function.identity(), Setting.Property.NodeScope); + public static final Setting> LEGACY_DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING = + Setting.listSetting("discovery.zen.ping.unicast.hosts", emptyList(), Function.identity(), Property.NodeScope, Property.Deprecated); + + public static final Setting> DISCOVERY_SEED_HOSTS_SETTING = + Setting.listSetting("discovery.seed_hosts", emptyList(), Function.identity(), Property.NodeScope); // these limits are per-address - public static final int LIMIT_FOREIGN_PORTS_COUNT = 1; - public static final int LIMIT_LOCAL_PORTS_COUNT = 5; + private static final int LIMIT_FOREIGN_PORTS_COUNT = 1; + private static final int LIMIT_LOCAL_PORTS_COUNT = 5; private final List configuredHosts; - private final int limitPortCounts; public SettingsBasedHostsProvider(Settings settings, TransportService transportService) { - if (DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.exists(settings)) { - configuredHosts = DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.get(settings); + if (LEGACY_DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.exists(settings)) { + if (DISCOVERY_SEED_HOSTS_SETTING.exists(settings)) { + throw new IllegalArgumentException("it is forbidden to set both [" + + DISCOVERY_SEED_HOSTS_SETTING.getKey() + "] and [" + + LEGACY_DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey() + "]"); + } + configuredHosts = LEGACY_DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.get(settings); + // we only limit to 1 address, makes no sense to ping 100 ports + limitPortCounts = LIMIT_FOREIGN_PORTS_COUNT; + } else if (DISCOVERY_SEED_HOSTS_SETTING.exists(settings)) { + configuredHosts = DISCOVERY_SEED_HOSTS_SETTING.get(settings); // we only limit to 1 address, makes no sense to ping 100 ports limitPortCounts = LIMIT_FOREIGN_PORTS_COUNT; } else { @@ -72,5 +84,4 @@ public SettingsBasedHostsProvider(Settings settings, TransportService transportS public List buildDynamicHosts(HostsResolver hostsResolver) { return hostsResolver.resolveHosts(configuredHosts, limitPortCounts); } - } diff --git a/server/src/main/java/org/elasticsearch/discovery/zen/UnicastZenPing.java b/server/src/main/java/org/elasticsearch/discovery/zen/UnicastZenPing.java index e1261b3d322a3..a9b0f4e941dec 100644 --- a/server/src/main/java/org/elasticsearch/discovery/zen/UnicastZenPing.java +++ b/server/src/main/java/org/elasticsearch/discovery/zen/UnicastZenPing.java @@ -96,10 +96,17 @@ public class UnicastZenPing implements ZenPing { private static final Logger logger = LogManager.getLogger(UnicastZenPing.class); public static final String ACTION_NAME = "internal:discovery/zen/unicast"; - public static final Setting DISCOVERY_ZEN_PING_UNICAST_CONCURRENT_CONNECTS_SETTING = - Setting.intSetting("discovery.zen.ping.unicast.concurrent_connects", 10, 0, Property.NodeScope); - public static final Setting DISCOVERY_ZEN_PING_UNICAST_HOSTS_RESOLVE_TIMEOUT = - Setting.positiveTimeSetting("discovery.zen.ping.unicast.hosts.resolve_timeout", TimeValue.timeValueSeconds(5), Property.NodeScope); + + public static final Setting LEGACY_DISCOVERY_ZEN_PING_UNICAST_CONCURRENT_CONNECTS_SETTING = + Setting.intSetting("discovery.zen.ping.unicast.concurrent_connects", 10, 0, Property.NodeScope, Property.Deprecated); + public static final Setting LEGACY_DISCOVERY_ZEN_PING_UNICAST_HOSTS_RESOLVE_TIMEOUT = + Setting.positiveTimeSetting("discovery.zen.ping.unicast.hosts.resolve_timeout", TimeValue.timeValueSeconds(5), + Property.NodeScope, Property.Deprecated); + + public static final Setting DISCOVERY_SEED_RESOLVER_MAX_CONCURRENT_RESOLVERS_SETTING = + Setting.intSetting("discovery.seed_resolver.max_concurrent_resolvers", 10, 0, Property.NodeScope); + public static final Setting DISCOVERY_SEED_RESOLVER_TIMEOUT_SETTING = + Setting.positiveTimeSetting("discovery.seed_resolver.timeout", TimeValue.timeValueSeconds(5), Property.NodeScope); private final ThreadPool threadPool; private final TransportService transportService; @@ -132,12 +139,11 @@ public UnicastZenPing(Settings settings, ThreadPool threadPool, TransportService this.hostsProvider = unicastHostsProvider; this.contextProvider = contextProvider; - final int concurrentConnects = DISCOVERY_ZEN_PING_UNICAST_CONCURRENT_CONNECTS_SETTING.get(settings); - - resolveTimeout = DISCOVERY_ZEN_PING_UNICAST_HOSTS_RESOLVE_TIMEOUT.get(settings); + final int concurrentConnects = getMaxConcurrentResolvers(settings); + resolveTimeout = getResolveTimeout(settings); nodeName = Node.NODE_NAME_SETTING.get(settings); logger.debug( - "using concurrent_connects [{}], resolve_timeout [{}]", + "using max_concurrent_resolvers [{}], resolver timeout [{}]", concurrentConnects, resolveTimeout); @@ -663,4 +669,28 @@ public void writeTo(StreamOutput out) throws IOException { protected Version getVersion() { return Version.CURRENT; // for tests } + + public static int getMaxConcurrentResolvers(Settings settings) { + if (LEGACY_DISCOVERY_ZEN_PING_UNICAST_CONCURRENT_CONNECTS_SETTING.exists(settings)) { + if (DISCOVERY_SEED_RESOLVER_MAX_CONCURRENT_RESOLVERS_SETTING.exists(settings)) { + throw new IllegalArgumentException("it is forbidden to set both [" + + DISCOVERY_SEED_RESOLVER_MAX_CONCURRENT_RESOLVERS_SETTING.getKey() + "] and [" + + LEGACY_DISCOVERY_ZEN_PING_UNICAST_CONCURRENT_CONNECTS_SETTING.getKey() + "]"); + } + return LEGACY_DISCOVERY_ZEN_PING_UNICAST_CONCURRENT_CONNECTS_SETTING.get(settings); + } + return DISCOVERY_SEED_RESOLVER_MAX_CONCURRENT_RESOLVERS_SETTING.get(settings); + } + + public static TimeValue getResolveTimeout(Settings settings) { + if (LEGACY_DISCOVERY_ZEN_PING_UNICAST_HOSTS_RESOLVE_TIMEOUT.exists(settings)) { + if (DISCOVERY_SEED_RESOLVER_TIMEOUT_SETTING.exists(settings)) { + throw new IllegalArgumentException("it is forbidden to set both [" + + DISCOVERY_SEED_RESOLVER_TIMEOUT_SETTING.getKey() + "] and [" + + LEGACY_DISCOVERY_ZEN_PING_UNICAST_HOSTS_RESOLVE_TIMEOUT.getKey() + "]"); + } + return LEGACY_DISCOVERY_ZEN_PING_UNICAST_HOSTS_RESOLVE_TIMEOUT.get(settings); + } + return DISCOVERY_SEED_RESOLVER_TIMEOUT_SETTING.get(settings); + } } diff --git a/server/src/main/java/org/elasticsearch/plugins/DiscoveryPlugin.java b/server/src/main/java/org/elasticsearch/plugins/DiscoveryPlugin.java index 90afaa8b70062..994607a9c97f7 100644 --- a/server/src/main/java/org/elasticsearch/plugins/DiscoveryPlugin.java +++ b/server/src/main/java/org/elasticsearch/plugins/DiscoveryPlugin.java @@ -100,7 +100,7 @@ default NetworkService.CustomNameResolver getCustomNameResolver(Settings setting * Returns providers of unicast host lists for zen discovery. * * The key of the returned map is the name of the host provider - * (see {@link org.elasticsearch.discovery.DiscoveryModule#DISCOVERY_HOSTS_PROVIDER_SETTING}), and + * (see {@link org.elasticsearch.discovery.DiscoveryModule#DISCOVERY_SEED_PROVIDERS_SETTING}), and * the value is a supplier to construct the host provider when it is selected for use. * * @param transportService Use to form the {@link org.elasticsearch.common.transport.TransportAddress} portion diff --git a/server/src/test/java/org/elasticsearch/bootstrap/BootstrapChecksTests.java b/server/src/test/java/org/elasticsearch/bootstrap/BootstrapChecksTests.java index 33a3aea37b4c5..9af7357717f5b 100644 --- a/server/src/test/java/org/elasticsearch/bootstrap/BootstrapChecksTests.java +++ b/server/src/test/java/org/elasticsearch/bootstrap/BootstrapChecksTests.java @@ -718,7 +718,7 @@ public void testDiscoveryConfiguredCheck() throws NodeValidationException { final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(zen2Context, true, checks)); assertThat(e, hasToString(containsString("the default discovery settings are unsuitable for production use; at least one " + - "of [discovery.zen.ping.unicast.hosts, discovery.zen.hosts_provider, cluster.initial_master_nodes] must be configured"))); + "of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured"))); CheckedConsumer ensureChecksPass = b -> { @@ -727,8 +727,11 @@ public void testDiscoveryConfiguredCheck() throws NodeValidationException { BootstrapChecks.check(context, true, checks); }; - ensureChecksPass.accept(Settings.builder().putList(DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING.getKey())); - ensureChecksPass.accept(Settings.builder().putList(SettingsBasedHostsProvider.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey())); ensureChecksPass.accept(Settings.builder().putList(ClusterBootstrapService.INITIAL_MASTER_NODES_SETTING.getKey())); + ensureChecksPass.accept(Settings.builder().putList(DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING.getKey())); + ensureChecksPass.accept(Settings.builder().putList(SettingsBasedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING.getKey())); + ensureChecksPass.accept(Settings.builder().putList(DiscoveryModule.LEGACY_DISCOVERY_HOSTS_PROVIDER_SETTING.getKey())); + ensureChecksPass.accept(Settings.builder().putList(SettingsBasedHostsProvider.LEGACY_DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING + .getKey())); } } diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/ClusterBootstrapServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/coordination/ClusterBootstrapServiceTests.java index c9ebdf278c71d..633a532cbd5b3 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/ClusterBootstrapServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/ClusterBootstrapServiceTests.java @@ -48,8 +48,8 @@ import static org.elasticsearch.cluster.coordination.ClusterBootstrapService.INITIAL_MASTER_NODES_SETTING; import static org.elasticsearch.cluster.coordination.ClusterBootstrapService.UNCONFIGURED_BOOTSTRAP_TIMEOUT_SETTING; import static org.elasticsearch.common.settings.Settings.builder; -import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING; -import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING; +import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING; +import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING; import static org.elasticsearch.node.Node.NODE_NAME_SETTING; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.containsInAnyOrder; @@ -125,11 +125,11 @@ public void testBootstrapsAutomaticallyWithDefaultConfiguration() { } public void testDoesNothingByDefaultIfHostsProviderConfigured() { - testDoesNothingWithSettings(builder().putList(DISCOVERY_HOSTS_PROVIDER_SETTING.getKey())); + testDoesNothingWithSettings(builder().putList(DISCOVERY_SEED_PROVIDERS_SETTING.getKey())); } public void testDoesNothingByDefaultIfUnicastHostsConfigured() { - testDoesNothingWithSettings(builder().putList(DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey())); + testDoesNothingWithSettings(builder().putList(DISCOVERY_SEED_HOSTS_SETTING.getKey())); } public void testDoesNothingByDefaultIfMasterNodesConfigured() { diff --git a/server/src/test/java/org/elasticsearch/discovery/DiscoveryModuleTests.java b/server/src/test/java/org/elasticsearch/discovery/DiscoveryModuleTests.java index e237415a9c60e..f44f33e71ee06 100644 --- a/server/src/test/java/org/elasticsearch/discovery/DiscoveryModuleTests.java +++ b/server/src/test/java/org/elasticsearch/discovery/DiscoveryModuleTests.java @@ -143,7 +143,7 @@ public void testDuplicateDiscovery() { } public void testHostsProvider() { - Settings settings = Settings.builder().put(DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING.getKey(), "custom").build(); + Settings settings = Settings.builder().put(DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING.getKey(), "custom").build(); AtomicBoolean created = new AtomicBoolean(false); DummyHostsProviderPlugin plugin = () -> Collections.singletonMap("custom", () -> { created.set(true); @@ -153,11 +153,32 @@ public void testHostsProvider() { assertTrue(created.get()); } + public void testLegacyHostsProvider() { + Settings settings = Settings.builder().put(DiscoveryModule.LEGACY_DISCOVERY_HOSTS_PROVIDER_SETTING.getKey(), "custom").build(); + AtomicBoolean created = new AtomicBoolean(false); + DummyHostsProviderPlugin plugin = () -> Collections.singletonMap("custom", () -> { + created.set(true); + return hostsResolver -> Collections.emptyList(); + }); + newModule(settings, Collections.singletonList(plugin)); + assertTrue(created.get()); + assertWarnings("[discovery.zen.hosts_provider] setting was deprecated in Elasticsearch and will be removed in a future release! " + + "See the breaking changes documentation for the next major version."); + } + + public void testLegacyAndNonLegacyProvidersRejected() { + Settings settings = Settings.builder().putList(DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING.getKey()) + .putList(DiscoveryModule.LEGACY_DISCOVERY_HOSTS_PROVIDER_SETTING.getKey()).build(); + IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> + newModule(settings, Collections.emptyList())); + assertEquals("it is forbidden to set both [discovery.seed_providers] and [discovery.zen.hosts_provider]", e.getMessage()); + } + public void testUnknownHostsProvider() { - Settings settings = Settings.builder().put(DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING.getKey(), "dne").build(); + Settings settings = Settings.builder().put(DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING.getKey(), "dne").build(); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> newModule(settings, Collections.emptyList())); - assertEquals("Unknown zen hosts providers [dne]", e.getMessage()); + assertEquals("Unknown seed providers [dne]", e.getMessage()); } public void testDuplicateHostsProvider() { @@ -165,14 +186,14 @@ public void testDuplicateHostsProvider() { DummyHostsProviderPlugin plugin2 = () -> Collections.singletonMap("dup", () -> null); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> newModule(Settings.EMPTY, Arrays.asList(plugin1, plugin2))); - assertEquals("Cannot register zen hosts provider [dup] twice", e.getMessage()); + assertEquals("Cannot register seed provider [dup] twice", e.getMessage()); } public void testSettingsHostsProvider() { DummyHostsProviderPlugin plugin = () -> Collections.singletonMap("settings", () -> null); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> newModule(Settings.EMPTY, Arrays.asList(plugin))); - assertEquals("Cannot register zen hosts provider [settings] twice", e.getMessage()); + assertEquals("Cannot register seed provider [settings] twice", e.getMessage()); } public void testMultiHostsProvider() { @@ -191,7 +212,7 @@ public void testMultiHostsProvider() { created3.set(true); return hostsResolver -> Collections.emptyList(); }); - Settings settings = Settings.builder().putList(DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING.getKey(), + Settings settings = Settings.builder().putList(DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING.getKey(), "provider1", "provider3").build(); newModule(settings, Arrays.asList(plugin1, plugin2, plugin3)); assertTrue(created1.get()); diff --git a/server/src/test/java/org/elasticsearch/discovery/zen/SettingsBasedHostsProviderIT.java b/server/src/test/java/org/elasticsearch/discovery/zen/SettingsBasedHostsProviderIT.java index b79fb05d40111..59c66a7d4f9c7 100644 --- a/server/src/test/java/org/elasticsearch/discovery/zen/SettingsBasedHostsProviderIT.java +++ b/server/src/test/java/org/elasticsearch/discovery/zen/SettingsBasedHostsProviderIT.java @@ -24,8 +24,8 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ESIntegTestCase; -import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING; -import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING; +import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING; +import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING; @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, numClientNodes = 0) public class SettingsBasedHostsProviderIT extends ESIntegTestCase { @@ -36,13 +36,13 @@ protected Settings nodeSettings(int nodeOrdinal) { // super.nodeSettings enables file-based discovery, but here we disable it again so we can test the static list: if (randomBoolean()) { - builder.putList(DISCOVERY_HOSTS_PROVIDER_SETTING.getKey()); + builder.putList(DISCOVERY_SEED_PROVIDERS_SETTING.getKey()); } else { - builder.remove(DISCOVERY_HOSTS_PROVIDER_SETTING.getKey()); + builder.remove(DISCOVERY_SEED_PROVIDERS_SETTING.getKey()); } // super.nodeSettings sets this to an empty list, which disables any search for other nodes, but here we want this to happen: - builder.remove(DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey()); + builder.remove(DISCOVERY_SEED_HOSTS_SETTING.getKey()); return builder.build(); } @@ -56,7 +56,7 @@ public void testClusterFormsWithSingleSeedHostInSettings() { int extraNodes = randomIntBetween(1, 5); internalCluster().startNodes(extraNodes, - Settings.builder().putList(DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey(), seedNodeAddress).build()); + Settings.builder().putList(DISCOVERY_SEED_HOSTS_SETTING.getKey(), seedNodeAddress).build()); ensureStableCluster(extraNodes + 1); } diff --git a/server/src/test/java/org/elasticsearch/discovery/zen/SettingsBasedHostsProviderTests.java b/server/src/test/java/org/elasticsearch/discovery/zen/SettingsBasedHostsProviderTests.java new file mode 100644 index 0000000000000..c08b5514de700 --- /dev/null +++ b/server/src/test/java/org/elasticsearch/discovery/zen/SettingsBasedHostsProviderTests.java @@ -0,0 +1,94 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.elasticsearch.discovery.zen; + +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.transport.TransportAddress; +import org.elasticsearch.common.util.set.Sets; +import org.elasticsearch.discovery.zen.UnicastHostsProvider.HostsResolver; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.transport.TransportService; + +import java.util.Arrays; +import java.util.List; +import java.util.Set; + +import static java.util.Collections.emptyList; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class SettingsBasedHostsProviderTests extends ESTestCase { + + private class AssertingHostsResolver implements HostsResolver { + private final Set expectedHosts; + private final int expectedPortCount; + + private boolean resolvedHosts; + + AssertingHostsResolver(int expectedPortCount, String... expectedHosts) { + this.expectedPortCount = expectedPortCount; + this.expectedHosts = Sets.newHashSet(expectedHosts); + } + + @Override + public List resolveHosts(List hosts, int limitPortCounts) { + assertEquals(expectedPortCount, limitPortCounts); + assertEquals(expectedHosts, Sets.newHashSet(hosts)); + resolvedHosts = true; + return emptyList(); + } + + boolean getResolvedHosts() { + return resolvedHosts; + } + } + + public void testScansPortsByDefault() { + final AssertingHostsResolver hostsResolver = new AssertingHostsResolver(5, "::1", "127.0.0.1"); + final TransportService transportService = mock(TransportService.class); + when(transportService.getLocalAddresses()).thenReturn(Arrays.asList("::1", "127.0.0.1")); + new SettingsBasedHostsProvider(Settings.EMPTY, transportService).buildDynamicHosts(hostsResolver); + assertTrue(hostsResolver.getResolvedHosts()); + } + + public void testGetsHostsFromSetting() { + final AssertingHostsResolver hostsResolver = new AssertingHostsResolver(1, "bar", "foo"); + new SettingsBasedHostsProvider(Settings.builder() + .putList(SettingsBasedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING.getKey(), "foo", "bar") + .build(), null).buildDynamicHosts(hostsResolver); + assertTrue(hostsResolver.getResolvedHosts()); + } + + public void testGetsHostsFromLegacySetting() { + final AssertingHostsResolver hostsResolver = new AssertingHostsResolver(1, "bar", "foo"); + new SettingsBasedHostsProvider(Settings.builder() + .putList(SettingsBasedHostsProvider.LEGACY_DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey(), "foo", "bar") + .build(), null).buildDynamicHosts(hostsResolver); + assertTrue(hostsResolver.getResolvedHosts()); + assertWarnings("[discovery.zen.ping.unicast.hosts] setting was deprecated in Elasticsearch and will be removed in a future " + + "release! See the breaking changes documentation for the next major version."); + } + + public void testForbidsBothSettingsAtTheSameTime() { + expectThrows(IllegalArgumentException.class, () -> new SettingsBasedHostsProvider(Settings.builder() + .putList(SettingsBasedHostsProvider.LEGACY_DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey()) + .putList(SettingsBasedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING.getKey()) + .build(), null)); + } +} diff --git a/server/src/test/java/org/elasticsearch/discovery/zen/UnicastZenPingTests.java b/server/src/test/java/org/elasticsearch/discovery/zen/UnicastZenPingTests.java index f06ef3e72808a..f7047abf721ce 100644 --- a/server/src/test/java/org/elasticsearch/discovery/zen/UnicastZenPingTests.java +++ b/server/src/test/java/org/elasticsearch/discovery/zen/UnicastZenPingTests.java @@ -90,6 +90,7 @@ import static java.util.Collections.emptyMap; import static java.util.Collections.emptySet; +import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING; import static org.elasticsearch.gateway.GatewayService.STATE_NOT_RECOVERED_BLOCK; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; @@ -172,7 +173,7 @@ public void testSimplePings() throws IOException, InterruptedException, Executio final ClusterState stateMismatch = ClusterState.builder(new ClusterName("mismatch")).version(randomNonNegativeLong()).build(); final Settings hostsSettings = Settings.builder() - .putList("discovery.zen.ping.unicast.hosts", + .putList(DISCOVERY_SEED_HOSTS_SETTING.getKey(), NetworkAddress.format(new InetSocketAddress(handleA.address.address().getAddress(), handleA.address.address().getPort())), NetworkAddress.format(new InetSocketAddress(handleB.address.address().getAddress(), handleB.address.address().getPort())), NetworkAddress.format(new InetSocketAddress(handleC.address.address().getAddress(), handleC.address.address().getPort())), @@ -306,7 +307,7 @@ public TransportAddress[] addressesFromString(String address, int perAddressLimi new InetSocketAddress(handleC.address.address().getAddress(), handleC.address.address().getPort()))}); final Settings hostsSettings = Settings.builder() - .putList("discovery.zen.ping.unicast.hosts", "UZP_A", "UZP_B", "UZP_C") + .putList(DISCOVERY_SEED_HOSTS_SETTING.getKey(), "UZP_A", "UZP_B", "UZP_C") .put("cluster.name", "test") .build(); @@ -590,11 +591,11 @@ public void testResolveReuseExistingNodeConnections() throws ExecutionException, final boolean useHosts = randomBoolean(); final Settings.Builder hostsSettingsBuilder = Settings.builder().put("cluster.name", "test"); if (useHosts) { - hostsSettingsBuilder.putList("discovery.zen.ping.unicast.hosts", + hostsSettingsBuilder.putList(DISCOVERY_SEED_HOSTS_SETTING.getKey(), NetworkAddress.format(new InetSocketAddress(handleB.address.address().getAddress(), handleB.address.address().getPort())) ); } else { - hostsSettingsBuilder.put("discovery.zen.ping.unicast.hosts", (String) null); + hostsSettingsBuilder.put(DISCOVERY_SEED_HOSTS_SETTING.getKey(), (String) null); } final Settings hostsSettings = hostsSettingsBuilder.build(); @@ -655,7 +656,7 @@ public void testPingingTemporalPings() throws ExecutionException, InterruptedExc final Settings hostsSettings = Settings.builder() .put("cluster.name", "test") - .put("discovery.zen.ping.unicast.hosts", (String) null) // use nodes for simplicity + .put(DISCOVERY_SEED_HOSTS_SETTING.getKey(), (String) null) // use nodes for simplicity .build(); final ClusterState state = ClusterState.builder(new ClusterName("test")).version(randomNonNegativeLong()).build(); diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java index 0dfdd2505235a..363050fde26cb 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java @@ -195,8 +195,8 @@ import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS; import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS; import static org.elasticsearch.common.util.CollectionUtils.eagerPartition; -import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING; -import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING; +import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING; +import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.test.XContentTestUtils.convertToMap; import static org.elasticsearch.test.XContentTestUtils.differenceBetweenMapsIgnoringArrayOrder; @@ -1816,8 +1816,8 @@ protected Settings nodeSettings(int nodeOrdinal) { .put(IndicesStore.INDICES_STORE_DELETE_SHARD_TIMEOUT.getKey(), new TimeValue(1, TimeUnit.SECONDS)) // randomly enable low-level search cancellation to make sure it does not alter results .put(SearchService.LOW_LEVEL_CANCELLATION_SETTING.getKey(), randomBoolean()) - .putList(DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey()) // empty list disables a port scan for other nodes - .putList(DISCOVERY_HOSTS_PROVIDER_SETTING.getKey(), "file"); + .putList(DISCOVERY_SEED_HOSTS_SETTING.getKey()) // empty list disables a port scan for other nodes + .putList(DISCOVERY_SEED_PROVIDERS_SETTING.getKey(), "file"); if (rarely()) { // Sometimes adjust the minimum search thread pool size, causing // QueueResizingEsThreadPoolExecutor to be used instead of a regular diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java index 32aa1c2107d5a..e2d21043282ae 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java @@ -63,7 +63,7 @@ import java.util.Collections; import static org.elasticsearch.cluster.coordination.ClusterBootstrapService.INITIAL_MASTER_NODES_SETTING; -import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING; +import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.lessThanOrEqualTo; @@ -202,7 +202,7 @@ private Node newNode() { // turning on the real memory circuit breaker leads to spurious test failures. As have no full control over heap usage, we // turn it off for these tests. .put(HierarchyCircuitBreakerService.USE_REAL_MEMORY_USAGE_SETTING.getKey(), false) - .putList(DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey()) // empty list disables a port scan for other nodes + .putList(DISCOVERY_SEED_HOSTS_SETTING.getKey()) // empty list disables a port scan for other nodes .putList(INITIAL_MASTER_NODES_SETTING.getKey(), nodeName) .put(nodeSettings()) // allow test cases to provide their own settings or override these .build(); diff --git a/test/framework/src/main/java/org/elasticsearch/test/discovery/TestZenDiscovery.java b/test/framework/src/main/java/org/elasticsearch/test/discovery/TestZenDiscovery.java index 56e6c24571715..43976b9dfc76f 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/discovery/TestZenDiscovery.java +++ b/test/framework/src/main/java/org/elasticsearch/test/discovery/TestZenDiscovery.java @@ -47,7 +47,7 @@ import java.util.Random; import java.util.function.Supplier; -import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING; +import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING; /** * A alternative zen discovery which allows using mocks for things like pings, as well as @@ -76,7 +76,7 @@ public Map> getDiscoveryTypes(ThreadPool threadPool, ClusterSettings clusterSettings, UnicastHostsProvider hostsProvider, AllocationService allocationService, GatewayMetaState gatewayMetaState) { // we don't get the latest setting which were updated by the extra settings for the plugin. TODO: fix. - Settings fixedSettings = Settings.builder().put(settings).putList(DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey()).build(); + Settings fixedSettings = Settings.builder().put(settings).putList(DISCOVERY_SEED_HOSTS_SETTING.getKey()).build(); return Collections.singletonMap("test-zen", () -> { if (USE_ZEN2.get(settings)) { return new Coordinator("test_node", fixedSettings, clusterSettings, transportService, namedWriteableRegistry, @@ -99,7 +99,7 @@ public List> getSettings() { public Settings additionalSettings() { return Settings.builder() .put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), TEST_ZEN_DISCOVERY_TYPE) - .putList(DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey()) + .putList(DISCOVERY_SEED_HOSTS_SETTING.getKey()) .build(); } } diff --git a/test/framework/src/test/java/org/elasticsearch/test/test/InternalTestClusterTests.java b/test/framework/src/test/java/org/elasticsearch/test/test/InternalTestClusterTests.java index e75d7eab626a8..f1028322754a5 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/test/InternalTestClusterTests.java +++ b/test/framework/src/test/java/org/elasticsearch/test/test/InternalTestClusterTests.java @@ -58,7 +58,7 @@ import static org.elasticsearch.cluster.node.DiscoveryNode.Role.DATA; import static org.elasticsearch.cluster.node.DiscoveryNode.Role.INGEST; import static org.elasticsearch.cluster.node.DiscoveryNode.Role.MASTER; -import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING; +import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFileExists; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFileNotExists; import static org.hamcrest.Matchers.equalTo; @@ -162,8 +162,8 @@ public Settings nodeSettings(int nodeOrdinal) { .put( NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING.getKey(), 2 * ((masterNodes ? InternalTestCluster.DEFAULT_HIGH_NUM_MASTER_NODES : 0) + maxNumDataNodes + numClientNodes)) - .put(DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING.getKey(), "file") - .putList(SettingsBasedHostsProvider.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey()) + .put(DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING.getKey(), "file") + .putList(SettingsBasedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING.getKey()) .put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType()); if (autoManageMinMasterNodes == false) { assert minNumDataNodes == maxNumDataNodes; @@ -239,8 +239,8 @@ public Settings nodeSettings(int nodeOrdinal) { NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING.getKey(), 2 + (masterNodes ? InternalTestCluster.DEFAULT_HIGH_NUM_MASTER_NODES : 0) + maxNumDataNodes + numClientNodes) .put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType()) - .putList(DISCOVERY_HOSTS_PROVIDER_SETTING.getKey(), "file") - .putList(SettingsBasedHostsProvider.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey()) + .putList(DISCOVERY_SEED_PROVIDERS_SETTING.getKey(), "file") + .putList(SettingsBasedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING.getKey()) .build(); } @@ -337,8 +337,8 @@ public Settings nodeSettings(int nodeOrdinal) { .put(NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING.getKey(), numNodes) .put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType()) .put(DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.getKey(), 0) - .putList(DISCOVERY_HOSTS_PROVIDER_SETTING.getKey(), "file") - .putList(SettingsBasedHostsProvider.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey()) + .putList(DISCOVERY_SEED_PROVIDERS_SETTING.getKey(), "file") + .putList(SettingsBasedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING.getKey()) .build(); } @@ -420,8 +420,8 @@ public Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING.getKey(), 2) .put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType()) - .putList(DISCOVERY_HOSTS_PROVIDER_SETTING.getKey(), "file") - .putList(SettingsBasedHostsProvider.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey()) + .putList(DISCOVERY_SEED_PROVIDERS_SETTING.getKey(), "file") + .putList(SettingsBasedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING.getKey()) .build(); } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java index 2f34315b46e69..d28969bc10c8e 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java @@ -98,8 +98,8 @@ import java.util.stream.Collectors; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; -import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING; -import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING; +import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING; +import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; import static org.hamcrest.Matchers.empty; @@ -194,8 +194,8 @@ private NodeConfigurationSource createNodeConfigurationSource(String leaderSeedA builder.put(ScriptService.SCRIPT_MAX_COMPILATIONS_RATE.getKey(), "2048/1m"); // wait short time for other active shards before actually deleting, default 30s not needed in tests builder.put(IndicesStore.INDICES_STORE_DELETE_SHARD_TIMEOUT.getKey(), new TimeValue(1, TimeUnit.SECONDS)); - builder.putList(DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey()); // empty list disables a port scan for other nodes - builder.putList(DISCOVERY_HOSTS_PROVIDER_SETTING.getKey(), "file"); + builder.putList(DISCOVERY_SEED_HOSTS_SETTING.getKey()); // empty list disables a port scan for other nodes + builder.putList(DISCOVERY_SEED_PROVIDERS_SETTING.getKey(), "file"); builder.put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType()); builder.put(XPackSettings.SECURITY_ENABLED.getKey(), false); builder.put(XPackSettings.MONITORING_ENABLED.getKey(), false); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/license/LicensingTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/license/LicensingTests.java index f146f12245e1f..3d19568772128 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/license/LicensingTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/license/LicensingTests.java @@ -59,7 +59,7 @@ import java.util.stream.Collectors; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; -import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING; +import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.greaterThanOrEqualTo; @@ -300,8 +300,8 @@ public void testNodeJoinWithoutSecurityExplicitlyEnabled() throws Exception { .put(TestZenDiscovery.USE_MOCK_PINGS.getKey(), false) .put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), "test-zen") .put(TestZenDiscovery.USE_ZEN2.getKey(), getUseZen2()) - .putList(DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING.getKey()) - .putList(DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey(), unicastHostsList); + .putList(DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING.getKey()) + .putList(DISCOVERY_SEED_HOSTS_SETTING.getKey(), unicastHostsList); if (getUseZen2() == false) { nodeSettings.put(ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey(), ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.get(internalCluster().getInstance(Settings.class))); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/ServerTransportFilterIntegrationTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/ServerTransportFilterIntegrationTests.java index 83640d9e931b5..5dcb48173969b 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/ServerTransportFilterIntegrationTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/ServerTransportFilterIntegrationTests.java @@ -44,6 +44,7 @@ import java.util.Collections; import java.util.concurrent.CountDownLatch; +import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING; import static org.elasticsearch.test.SecuritySettingsSource.addSSLSettingsForNodePEMFiles; import static org.elasticsearch.test.SecuritySettingsSource.addSSLSettingsForPEMFiles; import static org.elasticsearch.xpack.security.test.SecurityTestUtils.writeFile; @@ -101,7 +102,7 @@ public void testThatConnectionToServerTypeConnectionWorks() throws IOException, .put("node.name", "my-test-node") .put("network.host", "localhost") .put("cluster.name", internalCluster().getClusterName()) - .put("discovery.zen.ping.unicast.hosts", unicastHost) + .put(DISCOVERY_SEED_HOSTS_SETTING.getKey(), unicastHost) .put("xpack.security.enabled", true) .put("xpack.security.audit.enabled", false) .put("xpack.security.transport.ssl.enabled", true) @@ -146,7 +147,7 @@ public void testThatConnectionToClientTypeConnectionIsRejected() throws IOExcept .put("node.name", "my-test-node") .put(SecurityField.USER_SETTING.getKey(), "test_user:" + SecuritySettingsSourceField.TEST_PASSWORD) .put("cluster.name", internalCluster().getClusterName()) - .put("discovery.zen.ping.unicast.hosts", unicastHost) + .put(DISCOVERY_SEED_HOSTS_SETTING.getKey(), unicastHost) .put("xpack.security.enabled", true) .put("xpack.security.audit.enabled", false) .put("xpack.security.transport.ssl.enabled", true) diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/IPHostnameVerificationTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/IPHostnameVerificationTests.java index b1ecad0e4b4a5..fd9213965a975 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/IPHostnameVerificationTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/IPHostnameVerificationTests.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.List; +import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING; import static org.hamcrest.CoreMatchers.is; // TODO delete this test? @@ -38,13 +39,13 @@ protected Settings nodeSettings(int nodeOrdinal) { // The default Unicast test behavior is to use 'localhost' with the port number. For this test we need to use IP List newUnicastAddresses = new ArrayList<>(); - for (String address : settings.getAsList("discovery.zen.ping.unicast.hosts")) { + for (String address : settings.getAsList(DISCOVERY_SEED_HOSTS_SETTING.getKey())) { newUnicastAddresses.add(address.replace("localhost", "127.0.0.1")); } Settings.Builder settingsBuilder = Settings.builder() .put(settings) - .putList("discovery.zen.ping.unicast.hosts", newUnicastAddresses); + .putList(DISCOVERY_SEED_HOSTS_SETTING.getKey(), newUnicastAddresses); try { //Use a cert with a CN of "Elasticsearch Test Node" and IPv4+IPv6 ip addresses as SubjectAlternativeNames diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherExecutorServiceBenchmark.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherExecutorServiceBenchmark.java index 81a2911be28d6..7a8512f17c988 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherExecutorServiceBenchmark.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherExecutorServiceBenchmark.java @@ -28,6 +28,7 @@ import java.util.Arrays; import static java.util.Collections.emptyMap; +import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING; import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.indexAction; import static org.elasticsearch.xpack.watcher.input.InputBuilders.httpInput; import static org.elasticsearch.xpack.watcher.input.InputBuilders.searchInput; @@ -48,7 +49,7 @@ public class WatcherExecutorServiceBenchmark { .put("cluster.name", "bench") .put("network.host", "localhost") .put("script.disable_dynamic", false) - .put("discovery.zen.ping.unicast.hosts", "localhost") + .put(DISCOVERY_SEED_HOSTS_SETTING.getKey(), "localhost") .put("http.cors.enabled", true) .put("cluster.routing.allocation.disk.threshold_enabled", false) // .put("recycler.page.limit.heap", "60%") diff --git a/x-pack/qa/vagrant/src/test/resources/packaging/tests/certgen.bash b/x-pack/qa/vagrant/src/test/resources/packaging/tests/certgen.bash index 83f967c39891b..c0ae9aac4db30 100644 --- a/x-pack/qa/vagrant/src/test/resources/packaging/tests/certgen.bash +++ b/x-pack/qa/vagrant/src/test/resources/packaging/tests/certgen.bash @@ -248,7 +248,7 @@ cat >> $ESCONFIG/elasticsearch.yml <<- EOF node.name: "node-master" node.master: true node.data: false -discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301"] +discovery.seed_hosts: ["127.0.0.1:9301"] cluster.initial_master_nodes: ["node-master"] xpack.security.transport.ssl.key: $ESCONFIG/certs/node-master/node-master.key @@ -335,7 +335,7 @@ cat >> $ESCONFIG/elasticsearch.yml <<- EOF node.name: "node-data" node.master: false node.data: true -discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300"] +discovery.seed_hosts: ["127.0.0.1:9300"] xpack.security.transport.ssl.key: $ESCONFIG/certs/node-data/node-data.key xpack.security.transport.ssl.certificate: $ESCONFIG/certs/node-data/node-data.crt From 3b2a0d79597c8769d04e8f8cf7e44e59397bf6b3 Mon Sep 17 00:00:00 2001 From: David Turner Date: Tue, 5 Feb 2019 08:47:56 +0000 Subject: [PATCH 4/7] Rename no-master-block setting (#38350) Replaces `discovery.zen.no_master_block` with `cluster.no_master_block`. Any value set for the old setting is now ignored. --- .../migration/migrate_7_0/discovery.asciidoc | 8 ++ .../discovery/discovery-settings.asciidoc | 8 +- .../index/rankeval/RankEvalResponseTests.java | 4 +- .../cluster/coordination/Coordinator.java | 11 +- .../coordination/JoinTaskExecutor.java | 3 +- .../coordination/NoMasterBlockService.java | 73 +++++++++++++ .../common/settings/ClusterSettings.java | 4 +- .../discovery/DiscoverySettings.java | 34 ------ .../discovery/zen/ZenDiscovery.java | 13 ++- .../ElasticsearchExceptionTests.java | 10 +- .../ExceptionSerializationTests.java | 6 +- ...TransportResyncReplicationActionTests.java | 4 +- .../cluster/ClusterStateDiffIT.java | 6 +- .../cluster/MinimumMasterNodesIT.java | 26 ++--- .../elasticsearch/cluster/NoMasterNodeIT.java | 10 +- .../coordination/CoordinatorTests.java | 8 +- .../ElasticsearchNodeCommandIT.java | 10 +- .../NoMasterBlockServiceTests.java | 101 ++++++++++++++++++ .../service/ClusterApplierServiceTests.java | 4 +- .../discovery/MasterDisruptionIT.java | 9 +- ...ClusterStateServiceRandomUpdatesTests.java | 12 +-- .../org/elasticsearch/test/RandomObjects.java | 4 +- .../TransportMonitoringBulkActionTests.java | 4 +- .../watcher/WatcherIndexingListenerTests.java | 4 +- .../watcher/WatcherLifeCycleServiceTests.java | 4 +- 25 files changed, 268 insertions(+), 112 deletions(-) create mode 100644 server/src/main/java/org/elasticsearch/cluster/coordination/NoMasterBlockService.java create mode 100644 server/src/test/java/org/elasticsearch/cluster/coordination/NoMasterBlockServiceTests.java diff --git a/docs/reference/migration/migrate_7_0/discovery.asciidoc b/docs/reference/migration/migrate_7_0/discovery.asciidoc index d7e2a494206a0..56449625246cd 100644 --- a/docs/reference/migration/migrate_7_0/discovery.asciidoc +++ b/docs/reference/migration/migrate_7_0/discovery.asciidoc @@ -38,3 +38,11 @@ file: - `discovery.seed_hosts` - `discovery.seed_providers` - `cluster.initial_master_nodes` + +[float] +==== New name for `no_master_block` setting + +The `discovery.zen.no_master_block` setting is now known as +`cluster.no_master_block`. Any value set for `discovery.zen.no_master_block` is +now ignored. You should remove this setting and, if needed, set +`cluster.no_master_block` appropriately after the upgrade. diff --git a/docs/reference/modules/discovery/discovery-settings.asciidoc b/docs/reference/modules/discovery/discovery-settings.asciidoc index 517712c513f86..53eb4274c6c4c 100644 --- a/docs/reference/modules/discovery/discovery-settings.asciidoc +++ b/docs/reference/modules/discovery/discovery-settings.asciidoc @@ -134,7 +134,7 @@ Discovery and cluster formation are affected by the following settings: the addresses of seed nodes. By default, it is the <>. -[[no-master-block]]`discovery.zen.no_master_block`:: +[[no-master-block]]`cluster.no_master_block`:: Specifies which operations are rejected when there is no active master in a cluster. This setting has two valid values: + @@ -150,12 +150,16 @@ cluster. [NOTE] =============================== -* The `discovery.zen.no_master_block` setting doesn't apply to nodes-based APIs +* The `cluster.no_master_block` setting doesn't apply to nodes-based APIs (for example, cluster stats, node info, and node stats APIs). Requests to these APIs are not be blocked and can run on any available node. * For the cluster to be fully operational, it must have an active master. =============================== + +WARNING: This setting replaces the `discovery.zen.no_master_block` setting in +earlier versions. The `discovery.zen.no_master_block` setting is ignored. + -- `discovery.seed_hosts`:: diff --git a/modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/RankEvalResponseTests.java b/modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/RankEvalResponseTests.java index 070b2439e53cb..4c50ba44c990e 100644 --- a/modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/RankEvalResponseTests.java +++ b/modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/RankEvalResponseTests.java @@ -24,6 +24,7 @@ import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.elasticsearch.action.search.ShardSearchFailure; import org.elasticsearch.cluster.block.ClusterBlockException; +import org.elasticsearch.cluster.coordination.NoMasterBlockService; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.breaker.CircuitBreaker; import org.elasticsearch.common.breaker.CircuitBreakingException; @@ -37,7 +38,6 @@ import org.elasticsearch.common.xcontent.XContentLocation; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchParseException; @@ -64,7 +64,7 @@ public class RankEvalResponseTests extends ESTestCase { private static final Exception[] RANDOM_EXCEPTIONS = new Exception[] { - new ClusterBlockException(singleton(DiscoverySettings.NO_MASTER_BLOCK_WRITES)), + new ClusterBlockException(singleton(NoMasterBlockService.NO_MASTER_BLOCK_WRITES)), new CircuitBreakingException("Data too large", 123, 456, CircuitBreaker.Durability.PERMANENT), new SearchParseException(new TestSearchContext(null), "Parse failure", new XContentLocation(12, 98)), new IllegalArgumentException("Closed resource", new RuntimeException("Resource")), diff --git a/server/src/main/java/org/elasticsearch/cluster/coordination/Coordinator.java b/server/src/main/java/org/elasticsearch/cluster/coordination/Coordinator.java index f6e2e1e958884..db094638ae6bd 100644 --- a/server/src/main/java/org/elasticsearch/cluster/coordination/Coordinator.java +++ b/server/src/main/java/org/elasticsearch/cluster/coordination/Coordinator.java @@ -58,7 +58,6 @@ import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.discovery.Discovery; -import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.discovery.DiscoveryStats; import org.elasticsearch.discovery.HandshakingTransportAddressConnector; import org.elasticsearch.discovery.PeerFinder; @@ -82,7 +81,7 @@ import java.util.stream.Collectors; import java.util.stream.StreamSupport; -import static org.elasticsearch.discovery.DiscoverySettings.NO_MASTER_BLOCK_ID; +import static org.elasticsearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_ID; import static org.elasticsearch.gateway.ClusterStateUpdaters.hideStateIfNotRecovered; import static org.elasticsearch.gateway.GatewayService.STATE_NOT_RECOVERED_BLOCK; @@ -103,7 +102,7 @@ public class Coordinator extends AbstractLifecycleComponent implements Discovery private final JoinHelper joinHelper; private final NodeRemovalClusterStateTaskExecutor nodeRemovalExecutor; private final Supplier persistedStateSupplier; - private final DiscoverySettings discoverySettings; + private final NoMasterBlockService noMasterBlockService; // TODO: the following field is package-private as some tests require access to it // These tests can be rewritten to use public methods once Coordinator is more feature-complete final Object mutex = new Object(); @@ -149,7 +148,7 @@ public Coordinator(String nodeName, Settings settings, ClusterSettings clusterSe this.joinHelper = new JoinHelper(settings, allocationService, masterService, transportService, this::getCurrentTerm, this::getStateForMasterService, this::handleJoinRequest, this::joinLeaderInTerm, this.onJoinValidators); this.persistedStateSupplier = persistedStateSupplier; - this.discoverySettings = new DiscoverySettings(settings, clusterSettings); + this.noMasterBlockService = new NoMasterBlockService(settings, clusterSettings); this.lastKnownLeader = Optional.empty(); this.lastJoin = Optional.empty(); this.joinAccumulator = new InitialJoinAccumulator(); @@ -632,7 +631,7 @@ protected void doStart() { ClusterState initialState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(settings)) .blocks(ClusterBlocks.builder() .addGlobalBlock(STATE_NOT_RECOVERED_BLOCK) - .addGlobalBlock(discoverySettings.getNoMasterBlock())) + .addGlobalBlock(noMasterBlockService.getNoMasterBlock())) .nodes(DiscoveryNodes.builder().add(getLocalNode()).localNodeId(getLocalNode().getId())) .build(); applierState = initialState; @@ -934,7 +933,7 @@ private ClusterState clusterStateWithNoMasterBlock(ClusterState clusterState) { assert clusterState.blocks().hasGlobalBlockWithId(NO_MASTER_BLOCK_ID) == false : "NO_MASTER_BLOCK should only be added by Coordinator"; final ClusterBlocks clusterBlocks = ClusterBlocks.builder().blocks(clusterState.blocks()).addGlobalBlock( - discoverySettings.getNoMasterBlock()).build(); + noMasterBlockService.getNoMasterBlock()).build(); final DiscoveryNodes discoveryNodes = new DiscoveryNodes.Builder(clusterState.nodes()).masterNodeId(null).build(); return ClusterState.builder(clusterState).blocks(clusterBlocks).nodes(discoveryNodes).build(); } else { diff --git a/server/src/main/java/org/elasticsearch/cluster/coordination/JoinTaskExecutor.java b/server/src/main/java/org/elasticsearch/cluster/coordination/JoinTaskExecutor.java index 2dcc1022f8d46..a360ea1ab60b8 100644 --- a/server/src/main/java/org/elasticsearch/cluster/coordination/JoinTaskExecutor.java +++ b/server/src/main/java/org/elasticsearch/cluster/coordination/JoinTaskExecutor.java @@ -30,7 +30,6 @@ import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.discovery.zen.ElectMasterService; import org.elasticsearch.persistent.PersistentTasksCustomMetaData; @@ -191,7 +190,7 @@ protected ClusterState.Builder becomeMasterAndTrimConflictingNodes(ClusterState // or removed by us above ClusterState tmpState = ClusterState.builder(currentState).nodes(nodesBuilder).blocks(ClusterBlocks.builder() .blocks(currentState.blocks()) - .removeGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID)) + .removeGlobalBlock(NoMasterBlockService.NO_MASTER_BLOCK_ID)) .minimumMasterNodesOnPublishingMaster(minimumMasterNodesOnLocalNode) .build(); logger.trace("becomeMasterAndTrimConflictingNodes: {}", tmpState.nodes()); diff --git a/server/src/main/java/org/elasticsearch/cluster/coordination/NoMasterBlockService.java b/server/src/main/java/org/elasticsearch/cluster/coordination/NoMasterBlockService.java new file mode 100644 index 0000000000000..2944c3bb23283 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/cluster/coordination/NoMasterBlockService.java @@ -0,0 +1,73 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.elasticsearch.cluster.coordination; + +import org.elasticsearch.cluster.block.ClusterBlock; +import org.elasticsearch.cluster.block.ClusterBlockLevel; +import org.elasticsearch.common.settings.ClusterSettings; +import org.elasticsearch.common.settings.Setting; +import org.elasticsearch.common.settings.Setting.Property; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.rest.RestStatus; + +import java.util.EnumSet; + +public class NoMasterBlockService { + public static final int NO_MASTER_BLOCK_ID = 2; + public static final ClusterBlock NO_MASTER_BLOCK_WRITES = new ClusterBlock(NO_MASTER_BLOCK_ID, "no master", true, false, false, + RestStatus.SERVICE_UNAVAILABLE, EnumSet.of(ClusterBlockLevel.WRITE, ClusterBlockLevel.METADATA_WRITE)); + public static final ClusterBlock NO_MASTER_BLOCK_ALL = new ClusterBlock(NO_MASTER_BLOCK_ID, "no master", true, true, false, + RestStatus.SERVICE_UNAVAILABLE, ClusterBlockLevel.ALL); + + public static final Setting LEGACY_NO_MASTER_BLOCK_SETTING = + new Setting<>("discovery.zen.no_master_block", "write", NoMasterBlockService::parseNoMasterBlock, + Property.Dynamic, Property.NodeScope, Property.Deprecated); + public static final Setting NO_MASTER_BLOCK_SETTING = + new Setting<>("cluster.no_master_block", "write", NoMasterBlockService::parseNoMasterBlock, + Property.Dynamic, Property.NodeScope); + + private volatile ClusterBlock noMasterBlock; + + public NoMasterBlockService(Settings settings, ClusterSettings clusterSettings) { + this.noMasterBlock = NO_MASTER_BLOCK_SETTING.get(settings); + clusterSettings.addSettingsUpdateConsumer(NO_MASTER_BLOCK_SETTING, this::setNoMasterBlock); + + LEGACY_NO_MASTER_BLOCK_SETTING.get(settings); // for deprecation warnings + clusterSettings.addSettingsUpdateConsumer(LEGACY_NO_MASTER_BLOCK_SETTING, b -> {}); // for deprecation warnings + } + + private static ClusterBlock parseNoMasterBlock(String value) { + switch (value) { + case "all": + return NO_MASTER_BLOCK_ALL; + case "write": + return NO_MASTER_BLOCK_WRITES; + default: + throw new IllegalArgumentException("invalid no-master block [" + value + "], must be one of [all, write]"); + } + } + + public ClusterBlock getNoMasterBlock() { + return noMasterBlock; + } + + private void setNoMasterBlock(ClusterBlock noMasterBlock) { + this.noMasterBlock = noMasterBlock; + } +} diff --git a/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java b/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java index 758b6532a61a1..058ce8f2d02db 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java @@ -41,6 +41,7 @@ import org.elasticsearch.cluster.coordination.JoinHelper; import org.elasticsearch.cluster.coordination.LagDetector; import org.elasticsearch.cluster.coordination.LeaderChecker; +import org.elasticsearch.cluster.coordination.NoMasterBlockService; import org.elasticsearch.cluster.coordination.Reconfigurator; import org.elasticsearch.cluster.metadata.IndexGraveyard; import org.elasticsearch.cluster.metadata.MetaData; @@ -232,7 +233,8 @@ public void apply(Settings value, Settings current, Settings previous) { DiscoverySettings.PUBLISH_TIMEOUT_SETTING, DiscoverySettings.PUBLISH_DIFF_ENABLE_SETTING, DiscoverySettings.COMMIT_TIMEOUT_SETTING, - DiscoverySettings.NO_MASTER_BLOCK_SETTING, + NoMasterBlockService.NO_MASTER_BLOCK_SETTING, + NoMasterBlockService.LEGACY_NO_MASTER_BLOCK_SETTING, GatewayService.EXPECTED_DATA_NODES_SETTING, GatewayService.EXPECTED_MASTER_NODES_SETTING, GatewayService.EXPECTED_NODES_SETTING, diff --git a/server/src/main/java/org/elasticsearch/discovery/DiscoverySettings.java b/server/src/main/java/org/elasticsearch/discovery/DiscoverySettings.java index 1e99fdc3702df..e1a0c20864ea3 100644 --- a/server/src/main/java/org/elasticsearch/discovery/DiscoverySettings.java +++ b/server/src/main/java/org/elasticsearch/discovery/DiscoverySettings.java @@ -19,27 +19,17 @@ package org.elasticsearch.discovery; -import org.elasticsearch.cluster.block.ClusterBlock; -import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.rest.RestStatus; - -import java.util.EnumSet; /** * Exposes common discovery settings that may be supported by all the different discovery implementations */ public class DiscoverySettings { - public static final int NO_MASTER_BLOCK_ID = 2; - public static final ClusterBlock NO_MASTER_BLOCK_ALL = new ClusterBlock(NO_MASTER_BLOCK_ID, "no master", true, true, false, - RestStatus.SERVICE_UNAVAILABLE, ClusterBlockLevel.ALL); - public static final ClusterBlock NO_MASTER_BLOCK_WRITES = new ClusterBlock(NO_MASTER_BLOCK_ID, "no master", true, false, false, - RestStatus.SERVICE_UNAVAILABLE, EnumSet.of(ClusterBlockLevel.WRITE, ClusterBlockLevel.METADATA_WRITE)); /** * sets the timeout for a complete publishing cycle, including both sending and committing. the master * will continue to process the next cluster state update after this time has elapsed @@ -56,26 +46,20 @@ public class DiscoverySettings { new Setting<>("discovery.zen.commit_timeout", PUBLISH_TIMEOUT_SETTING::getRaw, (s) -> TimeValue.parseTimeValue(s, TimeValue.timeValueSeconds(30), "discovery.zen.commit_timeout"), Property.Dynamic, Property.NodeScope, Property.Deprecated); - public static final Setting NO_MASTER_BLOCK_SETTING = - new Setting<>("discovery.zen.no_master_block", "write", DiscoverySettings::parseNoMasterBlock, - Property.Dynamic, Property.NodeScope); public static final Setting PUBLISH_DIFF_ENABLE_SETTING = Setting.boolSetting("discovery.zen.publish_diff.enable", true, Property.Dynamic, Property.NodeScope, Property.Deprecated); public static final Setting INITIAL_STATE_TIMEOUT_SETTING = Setting.positiveTimeSetting("discovery.initial_state_timeout", TimeValue.timeValueSeconds(30), Property.NodeScope); - private volatile ClusterBlock noMasterBlock; private volatile TimeValue publishTimeout; private volatile TimeValue commitTimeout; private volatile boolean publishDiff; public DiscoverySettings(Settings settings, ClusterSettings clusterSettings) { - clusterSettings.addSettingsUpdateConsumer(NO_MASTER_BLOCK_SETTING, this::setNoMasterBlock); clusterSettings.addSettingsUpdateConsumer(PUBLISH_DIFF_ENABLE_SETTING, this::setPublishDiff); clusterSettings.addSettingsUpdateConsumer(COMMIT_TIMEOUT_SETTING, this::setCommitTimeout); clusterSettings.addSettingsUpdateConsumer(PUBLISH_TIMEOUT_SETTING, this::setPublishTimeout); - this.noMasterBlock = NO_MASTER_BLOCK_SETTING.get(settings); this.publishTimeout = PUBLISH_TIMEOUT_SETTING.get(settings); this.commitTimeout = COMMIT_TIMEOUT_SETTING.get(settings); this.publishDiff = PUBLISH_DIFF_ENABLE_SETTING.get(settings); @@ -92,14 +76,6 @@ public TimeValue getCommitTimeout() { return commitTimeout; } - public ClusterBlock getNoMasterBlock() { - return noMasterBlock; - } - - private void setNoMasterBlock(ClusterBlock noMasterBlock) { - this.noMasterBlock = noMasterBlock; - } - private void setPublishDiff(boolean publishDiff) { this.publishDiff = publishDiff; } @@ -114,14 +90,4 @@ private void setCommitTimeout(TimeValue commitTimeout) { public boolean getPublishDiff() { return publishDiff;} - private static ClusterBlock parseNoMasterBlock(String value) { - switch (value) { - case "all": - return NO_MASTER_BLOCK_ALL; - case "write": - return NO_MASTER_BLOCK_WRITES; - default: - throw new IllegalArgumentException("invalid master block [" + value + "]"); - } - } } diff --git a/server/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java b/server/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java index 9c85217f17804..6d6b9b438f614 100644 --- a/server/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java +++ b/server/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java @@ -32,6 +32,7 @@ import org.elasticsearch.cluster.NotMasterException; import org.elasticsearch.cluster.block.ClusterBlocks; import org.elasticsearch.cluster.coordination.JoinTaskExecutor; +import org.elasticsearch.cluster.coordination.NoMasterBlockService; import org.elasticsearch.cluster.coordination.NodeRemovalClusterStateTaskExecutor; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; @@ -120,6 +121,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent implements Discover private final TransportService transportService; private final MasterService masterService; private final DiscoverySettings discoverySettings; + private final NoMasterBlockService noMasterBlockService; protected final ZenPing zenPing; // protected to allow tests access private final MasterFaultDetection masterFD; private final NodesFaultDetection nodesFD; @@ -167,6 +169,7 @@ public ZenDiscovery(Settings settings, ThreadPool threadPool, TransportService t this.clusterApplier = clusterApplier; this.transportService = transportService; this.discoverySettings = new DiscoverySettings(settings, clusterSettings); + this.noMasterBlockService = new NoMasterBlockService(settings, clusterSettings); this.zenPing = newZenPing(settings, threadPool, transportService, hostsProvider); this.electMaster = new ElectMasterService(settings); this.pingTimeout = PING_TIMEOUT_SETTING.get(settings); @@ -252,7 +255,7 @@ protected void doStart() { ClusterState initialState = builder .blocks(ClusterBlocks.builder() .addGlobalBlock(STATE_NOT_RECOVERED_BLOCK) - .addGlobalBlock(discoverySettings.getNoMasterBlock())) + .addGlobalBlock(noMasterBlockService.getNoMasterBlock())) .nodes(DiscoveryNodes.builder().add(localNode).localNodeId(localNode.getId())) .build(); committedState.set(initialState); @@ -640,7 +643,7 @@ boolean processNextCommittedClusterState(String reason) { } assert newClusterState.nodes().getMasterNode() != null : "received a cluster state without a master"; - assert !newClusterState.blocks().hasGlobalBlock(discoverySettings.getNoMasterBlock()) : + assert !newClusterState.blocks().hasGlobalBlock(noMasterBlockService.getNoMasterBlock()) : "received a cluster state with a master block"; if (currentState.nodes().isLocalNodeElectedMaster() && newClusterState.nodes().isLocalNodeElectedMaster() == false) { @@ -670,7 +673,7 @@ boolean processNextCommittedClusterState(String reason) { return false; } - if (currentState.blocks().hasGlobalBlock(discoverySettings.getNoMasterBlock())) { + if (currentState.blocks().hasGlobalBlock(noMasterBlockService.getNoMasterBlock())) { // its a fresh update from the master as we transition from a start of not having a master to having one logger.debug("got first state from fresh master [{}]", newClusterState.nodes().getMasterNodeId()); } @@ -898,10 +901,10 @@ protected void rejoin(String reason) { if (clusterState.nodes().getMasterNodeId() != null) { // remove block if it already exists before adding new one - assert clusterState.blocks().hasGlobalBlockWithId(discoverySettings.getNoMasterBlock().id()) == false : + assert clusterState.blocks().hasGlobalBlockWithId(noMasterBlockService.getNoMasterBlock().id()) == false : "NO_MASTER_BLOCK should only be added by ZenDiscovery"; ClusterBlocks clusterBlocks = ClusterBlocks.builder().blocks(clusterState.blocks()) - .addGlobalBlock(discoverySettings.getNoMasterBlock()) + .addGlobalBlock(noMasterBlockService.getNoMasterBlock()) .build(); DiscoveryNodes discoveryNodes = new DiscoveryNodes.Builder(clusterState.nodes()).masterNodeId(null).build(); diff --git a/server/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java b/server/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java index 21ee15d01cf81..2706e14a361e1 100644 --- a/server/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java +++ b/server/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java @@ -28,6 +28,7 @@ import org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException; import org.elasticsearch.client.transport.NoNodeAvailableException; import org.elasticsearch.cluster.block.ClusterBlockException; +import org.elasticsearch.cluster.coordination.NoMasterBlockService; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Strings; @@ -43,7 +44,6 @@ import org.elasticsearch.common.xcontent.XContentParseException; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.query.QueryShardException; @@ -378,9 +378,9 @@ public void testGenerateThrowableToXContent() throws IOException { public void testToXContentWithHeadersAndMetadata() throws IOException { ElasticsearchException e = new ElasticsearchException("foo", - new ElasticsearchException("bar", - new ElasticsearchException("baz", - new ClusterBlockException(singleton(DiscoverySettings.NO_MASTER_BLOCK_WRITES))))); + new ElasticsearchException("bar", + new ElasticsearchException("baz", + new ClusterBlockException(singleton(NoMasterBlockService.NO_MASTER_BLOCK_WRITES))))); e.addHeader("foo_0", "0"); e.addHeader("foo_1", "1"); e.addMetadata("es.metadata_foo_0", "foo_0"); @@ -911,7 +911,7 @@ public static Tuple randomExceptions() { int type = randomIntBetween(0, 5); switch (type) { case 0: - actual = new ClusterBlockException(singleton(DiscoverySettings.NO_MASTER_BLOCK_WRITES)); + actual = new ClusterBlockException(singleton(NoMasterBlockService.NO_MASTER_BLOCK_WRITES)); expected = new ElasticsearchException("Elasticsearch exception [type=cluster_block_exception, " + "reason=blocked by: [SERVICE_UNAVAILABLE/2/no master];]"); break; diff --git a/server/src/test/java/org/elasticsearch/ExceptionSerializationTests.java b/server/src/test/java/org/elasticsearch/ExceptionSerializationTests.java index 901a4c3df018a..8ac056aa41c2a 100644 --- a/server/src/test/java/org/elasticsearch/ExceptionSerializationTests.java +++ b/server/src/test/java/org/elasticsearch/ExceptionSerializationTests.java @@ -34,6 +34,7 @@ import org.elasticsearch.cluster.action.shard.ShardStateAction; import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.coordination.CoordinationStateRejectedException; +import org.elasticsearch.cluster.coordination.NoMasterBlockService; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.IllegalShardRoutingStateException; import org.elasticsearch.cluster.routing.ShardRouting; @@ -56,7 +57,6 @@ import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.xcontent.UnknownNamedObjectException; import org.elasticsearch.common.xcontent.XContentLocation; -import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.env.ShardLockObtainFailedException; import org.elasticsearch.index.Index; import org.elasticsearch.index.engine.RecoveryEngineException; @@ -485,9 +485,9 @@ public void testFailedNodeException() throws IOException { } public void testClusterBlockException() throws IOException { - ClusterBlockException ex = serialize(new ClusterBlockException(singleton(DiscoverySettings.NO_MASTER_BLOCK_WRITES))); + ClusterBlockException ex = serialize(new ClusterBlockException(singleton(NoMasterBlockService.NO_MASTER_BLOCK_WRITES))); assertEquals("blocked by: [SERVICE_UNAVAILABLE/2/no master];", ex.getMessage()); - assertTrue(ex.blocks().contains(DiscoverySettings.NO_MASTER_BLOCK_WRITES)); + assertTrue(ex.blocks().contains(NoMasterBlockService.NO_MASTER_BLOCK_WRITES)); assertEquals(1, ex.blocks().size()); } diff --git a/server/src/test/java/org/elasticsearch/action/resync/TransportResyncReplicationActionTests.java b/server/src/test/java/org/elasticsearch/action/resync/TransportResyncReplicationActionTests.java index 0ca4be52504da..ed3663ed18d2c 100644 --- a/server/src/test/java/org/elasticsearch/action/resync/TransportResyncReplicationActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/resync/TransportResyncReplicationActionTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.action.shard.ShardStateAction; import org.elasticsearch.cluster.block.ClusterBlocks; +import org.elasticsearch.cluster.coordination.NoMasterBlockService; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; @@ -36,7 +37,6 @@ import org.elasticsearch.common.network.NetworkService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.PageCacheRecycler; -import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.shard.IndexShard; @@ -97,7 +97,7 @@ public void testResyncDoesNotBlockOnPrimaryAction() throws Exception { setState(clusterService, ClusterState.builder(clusterService.state()).blocks(ClusterBlocks.builder() - .addGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ALL) + .addGlobalBlock(NoMasterBlockService.NO_MASTER_BLOCK_ALL) .addIndexBlock(indexName, IndexMetaData.INDEX_WRITE_BLOCK))); try (MockNioTransport transport = new MockNioTransport(Settings.EMPTY, Version.CURRENT, threadPool, diff --git a/server/src/test/java/org/elasticsearch/cluster/ClusterStateDiffIT.java b/server/src/test/java/org/elasticsearch/cluster/ClusterStateDiffIT.java index d795971ac125e..313bf1d47c771 100644 --- a/server/src/test/java/org/elasticsearch/cluster/ClusterStateDiffIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/ClusterStateDiffIT.java @@ -24,6 +24,7 @@ import org.elasticsearch.cluster.block.ClusterBlocks; import org.elasticsearch.cluster.coordination.CoordinationMetaData; import org.elasticsearch.cluster.coordination.CoordinationMetaData.VotingConfigExclusion; +import org.elasticsearch.cluster.coordination.NoMasterBlockService; import org.elasticsearch.cluster.metadata.AliasMetaData; import org.elasticsearch.cluster.metadata.IndexGraveyard; import org.elasticsearch.cluster.metadata.IndexGraveyardTests; @@ -50,7 +51,6 @@ import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.gateway.GatewayService; import org.elasticsearch.index.Index; import org.elasticsearch.index.query.QueryBuilders; @@ -347,9 +347,9 @@ private ClusterState.Builder randomBlocks(ClusterState clusterState) { private ClusterBlock randomGlobalBlock() { switch (randomInt(2)) { case 0: - return DiscoverySettings.NO_MASTER_BLOCK_ALL; + return NoMasterBlockService.NO_MASTER_BLOCK_ALL; case 1: - return DiscoverySettings.NO_MASTER_BLOCK_WRITES; + return NoMasterBlockService.NO_MASTER_BLOCK_WRITES; default: return GatewayService.STATE_NOT_RECOVERED_BLOCK; } diff --git a/server/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java b/server/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java index 03fa2407685d8..ad1a0516e4430 100644 --- a/server/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java @@ -26,12 +26,12 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.coordination.FailedToCommitClusterStateException; +import org.elasticsearch.cluster.coordination.NoMasterBlockService; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Priority; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; @@ -82,7 +82,7 @@ public void testTwoNodesNoMasterBlock() throws Exception { logger.info("--> should be blocked, no master..."); ClusterState state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState(); - assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(true)); + assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(true)); assertThat(state.nodes().getSize(), equalTo(1)); // verify that we still see the local node in the cluster state logger.info("--> start second node, cluster should be formed"); @@ -93,9 +93,9 @@ public void testTwoNodesNoMasterBlock() throws Exception { assertThat(clusterHealthResponse.isTimedOut(), equalTo(false)); state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState(); - assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false)); + assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false)); state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState(); - assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false)); + assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false)); state = client().admin().cluster().prepareState().execute().actionGet().getState(); assertThat(state.nodes().getSize(), equalTo(2)); @@ -128,10 +128,10 @@ public void testTwoNodesNoMasterBlock() throws Exception { awaitBusy(() -> { ClusterState clusterState = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState(); - return clusterState.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID); + return clusterState.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID); }); state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState(); - assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(true)); + assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(true)); // verify that both nodes are still in the cluster state but there is no master assertThat(state.nodes().getSize(), equalTo(2)); assertThat(state.nodes().getMasterNode(), equalTo(null)); @@ -144,9 +144,9 @@ public void testTwoNodesNoMasterBlock() throws Exception { assertThat(clusterHealthResponse.isTimedOut(), equalTo(false)); state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState(); - assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false)); + assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false)); state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState(); - assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false)); + assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false)); state = client().admin().cluster().prepareState().execute().actionGet().getState(); assertThat(state.nodes().getSize(), equalTo(2)); @@ -173,7 +173,7 @@ public void testTwoNodesNoMasterBlock() throws Exception { assertBusy(() -> { ClusterState state1 = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState(); - assertThat(state1.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(true)); + assertThat(state1.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(true)); }); logger.info("--> starting the previous master node again..."); @@ -185,9 +185,9 @@ public void testTwoNodesNoMasterBlock() throws Exception { assertThat(clusterHealthResponse.isTimedOut(), equalTo(false)); state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState(); - assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false)); + assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false)); state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState(); - assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false)); + assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false)); state = client().admin().cluster().prepareState().execute().actionGet().getState(); assertThat(state.nodes().getSize(), equalTo(2)); @@ -217,7 +217,7 @@ public void testThreeNodesNoMasterBlock() throws Exception { assertBusy(() -> { for (Client client : clients()) { ClusterState state1 = client.admin().cluster().prepareState().setLocal(true).execute().actionGet().getState(); - assertThat(state1.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(true)); + assertThat(state1.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(true)); } }); @@ -258,7 +258,7 @@ public void testThreeNodesNoMasterBlock() throws Exception { // spin here to wait till the state is set assertBusy(() -> { ClusterState st = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState(); - assertThat(st.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(true)); + assertThat(st.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(true)); }); logger.info("--> start back the 2 nodes "); diff --git a/server/src/test/java/org/elasticsearch/cluster/NoMasterNodeIT.java b/server/src/test/java/org/elasticsearch/cluster/NoMasterNodeIT.java index 60c3bbee87a7a..15b5b72205392 100644 --- a/server/src/test/java/org/elasticsearch/cluster/NoMasterNodeIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/NoMasterNodeIT.java @@ -28,11 +28,11 @@ import org.elasticsearch.client.Client; import org.elasticsearch.client.Requests; import org.elasticsearch.cluster.block.ClusterBlockException; +import org.elasticsearch.cluster.coordination.NoMasterBlockService; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.discovery.MasterNotDiscoveredException; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.rest.RestStatus; @@ -73,7 +73,7 @@ protected Collection> nodePlugins() { public void testNoMasterActions() throws Exception { Settings settings = Settings.builder() .put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), true) - .put(DiscoverySettings.NO_MASTER_BLOCK_SETTING.getKey(), "all") + .put(NoMasterBlockService.NO_MASTER_BLOCK_SETTING.getKey(), "all") .build(); final TimeValue timeout = TimeValue.timeValueMillis(10); @@ -93,7 +93,7 @@ public void testNoMasterActions() throws Exception { assertBusy(() -> { ClusterState state = clientToMasterlessNode.admin().cluster().prepareState().setLocal(true) .execute().actionGet().getState(); - assertTrue(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID)); + assertTrue(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID)); }); assertThrows(clientToMasterlessNode.prepareGet("test", "type1", "1"), @@ -195,7 +195,7 @@ void checkWriteAction(ActionRequestBuilder builder) { public void testNoMasterActionsWriteMasterBlock() throws Exception { Settings settings = Settings.builder() .put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), false) - .put(DiscoverySettings.NO_MASTER_BLOCK_SETTING.getKey(), "write") + .put(NoMasterBlockService.NO_MASTER_BLOCK_SETTING.getKey(), "write") .build(); final List nodes = internalCluster().startNodes(3, settings); @@ -223,7 +223,7 @@ public void testNoMasterActionsWriteMasterBlock() throws Exception { assertTrue(awaitBusy(() -> { ClusterState state = clientToMasterlessNode.admin().cluster().prepareState().setLocal(true).get().getState(); - return state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID); + return state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID); } )); diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java b/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java index 333e6c5a3e7b1..6b344c93e1c7d 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java @@ -120,10 +120,10 @@ import static org.elasticsearch.cluster.coordination.LeaderChecker.LEADER_CHECK_RETRY_COUNT_SETTING; import static org.elasticsearch.cluster.coordination.LeaderChecker.LEADER_CHECK_TIMEOUT_SETTING; import static org.elasticsearch.cluster.coordination.Reconfigurator.CLUSTER_AUTO_SHRINK_VOTING_CONFIGURATION; -import static org.elasticsearch.discovery.DiscoverySettings.NO_MASTER_BLOCK_ALL; -import static org.elasticsearch.discovery.DiscoverySettings.NO_MASTER_BLOCK_ID; -import static org.elasticsearch.discovery.DiscoverySettings.NO_MASTER_BLOCK_SETTING; -import static org.elasticsearch.discovery.DiscoverySettings.NO_MASTER_BLOCK_WRITES; +import static org.elasticsearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_ALL; +import static org.elasticsearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_ID; +import static org.elasticsearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_SETTING; +import static org.elasticsearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_WRITES; import static org.elasticsearch.discovery.PeerFinder.DISCOVERY_FIND_PEERS_INTERVAL_SETTING; import static org.elasticsearch.node.Node.NODE_NAME_SETTING; import static org.elasticsearch.transport.TransportService.NOOP_TRANSPORT_INTERCEPTOR; diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/ElasticsearchNodeCommandIT.java b/server/src/test/java/org/elasticsearch/cluster/coordination/ElasticsearchNodeCommandIT.java index 4ea9cc87dd89a..f6d67ed73a433 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/ElasticsearchNodeCommandIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/ElasticsearchNodeCommandIT.java @@ -154,7 +154,7 @@ public void testBootstrapNotBootstrappedCluster() throws Exception { assertBusy(() -> { ClusterState state = client().admin().cluster().prepareState().setLocal(true) .execute().actionGet().getState(); - assertTrue(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID)); + assertTrue(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID)); }); internalCluster().stopRandomDataNode(); @@ -171,7 +171,7 @@ public void testDetachNotBootstrappedCluster() throws Exception { assertBusy(() -> { ClusterState state = client().admin().cluster().prepareState().setLocal(true) .execute().actionGet().getState(); - assertTrue(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID)); + assertTrue(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID)); }); internalCluster().stopRandomDataNode(); @@ -278,7 +278,7 @@ public void test3MasterNodes2Failed() throws Exception { assertBusy(() -> { ClusterState state = internalCluster().client(dataNode).admin().cluster().prepareState().setLocal(true) .execute().actionGet().getState(); - assertTrue(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID)); + assertTrue(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID)); }); logger.info("--> try to unsafely bootstrap 1st master-eligible node, while node lock is held"); @@ -310,7 +310,7 @@ public void test3MasterNodes2Failed() throws Exception { assertBusy(() -> { ClusterState state = internalCluster().client(dataNode2).admin().cluster().prepareState().setLocal(true) .execute().actionGet().getState(); - assertFalse(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID)); + assertFalse(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID)); assertTrue(state.metaData().persistentSettings().getAsBoolean(UnsafeBootstrapMasterCommand.UNSAFE_BOOTSTRAP.getKey(), false)); }); @@ -386,7 +386,7 @@ public void testNoInitialBootstrapAfterDetach() throws Exception { ClusterState state = internalCluster().client().admin().cluster().prepareState().setLocal(true) .execute().actionGet().getState(); - assertTrue(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID)); + assertTrue(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID)); internalCluster().stopRandomNode(InternalTestCluster.nameFilter(node)); } diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/NoMasterBlockServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/coordination/NoMasterBlockServiceTests.java new file mode 100644 index 0000000000000..990fd8a01469d --- /dev/null +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/NoMasterBlockServiceTests.java @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.elasticsearch.cluster.coordination; + +import org.elasticsearch.common.settings.ClusterSettings; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.test.ESTestCase; + +import static org.elasticsearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_ALL; +import static org.elasticsearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_SETTING; +import static org.elasticsearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_WRITES; +import static org.elasticsearch.cluster.coordination.NoMasterBlockService.LEGACY_NO_MASTER_BLOCK_SETTING; +import static org.elasticsearch.common.settings.ClusterSettings.BUILT_IN_CLUSTER_SETTINGS; +import static org.hamcrest.Matchers.sameInstance; + +public class NoMasterBlockServiceTests extends ESTestCase { + + private NoMasterBlockService noMasterBlockService; + private ClusterSettings clusterSettings; + + private void createService(Settings settings) { + clusterSettings = new ClusterSettings(settings, BUILT_IN_CLUSTER_SETTINGS); + noMasterBlockService = new NoMasterBlockService(settings, clusterSettings); + } + + private void assertDeprecatedWarningEmitted() { + assertWarnings("[discovery.zen.no_master_block] setting was deprecated in Elasticsearch and will be removed in a future release! " + + "See the breaking changes documentation for the next major version."); + } + + public void testBlocksWritesByDefault() { + createService(Settings.EMPTY); + assertThat(noMasterBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_WRITES)); + } + + public void testIgnoresLegacySettingBlockingWrites() { + createService(Settings.builder().put(LEGACY_NO_MASTER_BLOCK_SETTING.getKey(), "write").build()); + assertThat(noMasterBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_WRITES)); + assertDeprecatedWarningEmitted(); + } + + public void testBlocksWritesIfConfiguredBySetting() { + createService(Settings.builder().put(NO_MASTER_BLOCK_SETTING.getKey(), "write").build()); + assertThat(noMasterBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_WRITES)); + } + + public void testIgnoresLegacySettingBlockingAll() { + createService(Settings.builder().put(LEGACY_NO_MASTER_BLOCK_SETTING.getKey(), "all").build()); + assertThat(noMasterBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_WRITES)); + assertDeprecatedWarningEmitted(); + } + + public void testBlocksAllIfConfiguredBySetting() { + createService(Settings.builder().put(NO_MASTER_BLOCK_SETTING.getKey(), "all").build()); + assertThat(noMasterBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_ALL)); + } + + public void testRejectsInvalidSetting() { + expectThrows(IllegalArgumentException.class, () -> + createService(Settings.builder().put(NO_MASTER_BLOCK_SETTING.getKey(), "unknown").build())); + } + + public void testRejectsInvalidLegacySetting() { + expectThrows(IllegalArgumentException.class, () -> + createService(Settings.builder().put(LEGACY_NO_MASTER_BLOCK_SETTING.getKey(), "unknown").build())); + assertDeprecatedWarningEmitted(); + } + + public void testSettingCanBeUpdated() { + createService(Settings.builder().put(NO_MASTER_BLOCK_SETTING.getKey(), "all").build()); + assertThat(noMasterBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_ALL)); + + clusterSettings.applySettings(Settings.builder().put(NO_MASTER_BLOCK_SETTING.getKey(), "write").build()); + assertThat(noMasterBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_WRITES)); + } + + public void testIgnoresUpdatesToLegacySetting() { + createService(Settings.builder().put(NO_MASTER_BLOCK_SETTING.getKey(), "all").build()); + assertThat(noMasterBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_ALL)); + + clusterSettings.applySettings(Settings.builder().put(LEGACY_NO_MASTER_BLOCK_SETTING.getKey(), "write").build()); + assertThat(noMasterBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_ALL)); + assertDeprecatedWarningEmitted(); + } +} diff --git a/server/src/test/java/org/elasticsearch/cluster/service/ClusterApplierServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/service/ClusterApplierServiceTests.java index 0d0ed96bf12aa..7f91513e3439a 100644 --- a/server/src/test/java/org/elasticsearch/cluster/service/ClusterApplierServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/service/ClusterApplierServiceTests.java @@ -28,6 +28,7 @@ import org.elasticsearch.cluster.LocalNodeMasterListener; import org.elasticsearch.cluster.NodeConnectionsService; import org.elasticsearch.cluster.block.ClusterBlocks; +import org.elasticsearch.cluster.coordination.NoMasterBlockService; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; @@ -37,7 +38,6 @@ import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.MockLogAppender; import org.elasticsearch.test.junit.annotations.TestLogging; @@ -312,7 +312,7 @@ public String executorName() { nodes = state.nodes(); nodesBuilder = DiscoveryNodes.builder(nodes).masterNodeId(null); - state = ClusterState.builder(state).blocks(ClusterBlocks.builder().addGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_WRITES)) + state = ClusterState.builder(state).blocks(ClusterBlocks.builder().addGlobalBlock(NoMasterBlockService.NO_MASTER_BLOCK_WRITES)) .nodes(nodesBuilder).build(); setState(timedClusterApplierService, state); assertThat(isMaster.get(), is(false)); diff --git a/server/src/test/java/org/elasticsearch/discovery/MasterDisruptionIT.java b/server/src/test/java/org/elasticsearch/discovery/MasterDisruptionIT.java index fc9450e982636..4ac924bb25569 100644 --- a/server/src/test/java/org/elasticsearch/discovery/MasterDisruptionIT.java +++ b/server/src/test/java/org/elasticsearch/discovery/MasterDisruptionIT.java @@ -26,6 +26,7 @@ import org.elasticsearch.action.bulk.BulkResponse; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateUpdateTask; +import org.elasticsearch.cluster.coordination.NoMasterBlockService; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; @@ -331,7 +332,7 @@ public void testVerifyApiBlocksDuringPartition() throws Exception { // continuously ping until network failures have been resolved. However // It may a take a bit before the node detects it has been cut off from the elected master logger.info("waiting for isolated node [{}] to have no master", isolatedNode); - assertNoMaster(isolatedNode, DiscoverySettings.NO_MASTER_BLOCK_WRITES, TimeValue.timeValueSeconds(10)); + assertNoMaster(isolatedNode, NoMasterBlockService.NO_MASTER_BLOCK_WRITES, TimeValue.timeValueSeconds(10)); logger.info("wait until elected master has been removed and a new 2 node cluster was from (via [{}])", isolatedNode); @@ -358,9 +359,9 @@ public void testVerifyApiBlocksDuringPartition() throws Exception { // Wait until the master node sees al 3 nodes again. ensureStableCluster(3, new TimeValue(DISRUPTION_HEALING_OVERHEAD.millis() + networkDisruption.expectedTimeToHeal().millis())); - logger.info("Verify no master block with {} set to {}", DiscoverySettings.NO_MASTER_BLOCK_SETTING.getKey(), "all"); + logger.info("Verify no master block with {} set to {}", NoMasterBlockService.NO_MASTER_BLOCK_SETTING.getKey(), "all"); client().admin().cluster().prepareUpdateSettings() - .setTransientSettings(Settings.builder().put(DiscoverySettings.NO_MASTER_BLOCK_SETTING.getKey(), "all")) + .setTransientSettings(Settings.builder().put(NoMasterBlockService.NO_MASTER_BLOCK_SETTING.getKey(), "all")) .get(); networkDisruption.startDisrupting(); @@ -370,7 +371,7 @@ public void testVerifyApiBlocksDuringPartition() throws Exception { // continuously ping until network failures have been resolved. However // It may a take a bit before the node detects it has been cut off from the elected master logger.info("waiting for isolated node [{}] to have no master", isolatedNode); - assertNoMaster(isolatedNode, DiscoverySettings.NO_MASTER_BLOCK_ALL, TimeValue.timeValueSeconds(10)); + assertNoMaster(isolatedNode, NoMasterBlockService.NO_MASTER_BLOCK_ALL, TimeValue.timeValueSeconds(10)); // make sure we have stable cluster & cross partition recoveries are canceled by the removal of the missing node // the unresponsive partition causes recoveries to only time out after 15m (default) and these will cause diff --git a/server/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java b/server/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java index ef0464d94cd7d..9fd7f24db024b 100644 --- a/server/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java +++ b/server/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java @@ -34,6 +34,7 @@ import org.elasticsearch.cluster.action.shard.ShardStateAction; import org.elasticsearch.cluster.block.ClusterBlock; import org.elasticsearch.cluster.block.ClusterBlocks; +import org.elasticsearch.cluster.coordination.NoMasterBlockService; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -46,7 +47,6 @@ import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.set.Sets; -import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.index.Index; import org.elasticsearch.index.seqno.RetentionLeaseSyncer; import org.elasticsearch.index.shard.PrimaryReplicaSyncer; @@ -293,19 +293,19 @@ public ClusterState randomlyUpdateClusterState(ClusterState state, Map clusterStateServiceMap, Supplier indicesServiceSupplier) { // randomly remove no_master blocks - if (randomBoolean() && state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID)) { + if (randomBoolean() && state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID)) { state = ClusterState.builder(state).blocks( - ClusterBlocks.builder().blocks(state.blocks()).removeGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID)).build(); + ClusterBlocks.builder().blocks(state.blocks()).removeGlobalBlock(NoMasterBlockService.NO_MASTER_BLOCK_ID)).build(); } // randomly add no_master blocks - if (rarely() && state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID) == false) { - ClusterBlock block = randomBoolean() ? DiscoverySettings.NO_MASTER_BLOCK_ALL : DiscoverySettings.NO_MASTER_BLOCK_WRITES; + if (rarely() && state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID) == false) { + ClusterBlock block = randomBoolean() ? NoMasterBlockService.NO_MASTER_BLOCK_ALL : NoMasterBlockService.NO_MASTER_BLOCK_WRITES; state = ClusterState.builder(state).blocks(ClusterBlocks.builder().blocks(state.blocks()).addGlobalBlock(block)).build(); } // if no_master block is in place, make no other cluster state changes - if (state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID)) { + if (state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID)) { return state; } diff --git a/test/framework/src/main/java/org/elasticsearch/test/RandomObjects.java b/test/framework/src/main/java/org/elasticsearch/test/RandomObjects.java index 4669284685c11..2af37bc238bdb 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/RandomObjects.java +++ b/test/framework/src/main/java/org/elasticsearch/test/RandomObjects.java @@ -25,6 +25,7 @@ import org.elasticsearch.action.support.replication.ReplicationResponse.ShardInfo; import org.elasticsearch.action.support.replication.ReplicationResponse.ShardInfo.Failure; import org.elasticsearch.cluster.block.ClusterBlockException; +import org.elasticsearch.cluster.coordination.NoMasterBlockService; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.collect.Tuple; @@ -33,7 +34,6 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.index.shard.IndexShardRecoveringException; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardNotFoundException; @@ -310,7 +310,7 @@ private static Tuple randomShardInfoFailure(Random random) { int type = randomIntBetween(random, 0, 3); switch (type) { case 0: - actualException = new ClusterBlockException(singleton(DiscoverySettings.NO_MASTER_BLOCK_WRITES)); + actualException = new ClusterBlockException(singleton(NoMasterBlockService.NO_MASTER_BLOCK_WRITES)); expectedException = new ElasticsearchException("Elasticsearch exception [type=cluster_block_exception, " + "reason=blocked by: [SERVICE_UNAVAILABLE/2/no master];]"); break; diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringBulkActionTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringBulkActionTests.java index bf6c77d30ea70..9df959ead1a45 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringBulkActionTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringBulkActionTests.java @@ -14,6 +14,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlocks; +import org.elasticsearch.cluster.coordination.NoMasterBlockService; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; @@ -24,7 +25,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.tasks.Task; import org.elasticsearch.tasks.TaskAwareRequest; @@ -110,7 +110,7 @@ public void setUpMocks() { } public void testExecuteWithGlobalBlock() throws Exception { - final ClusterBlocks.Builder clusterBlock = ClusterBlocks.builder().addGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ALL); + final ClusterBlocks.Builder clusterBlock = ClusterBlocks.builder().addGlobalBlock(NoMasterBlockService.NO_MASTER_BLOCK_ALL); when(clusterService.state()).thenReturn(ClusterState.builder(ClusterName.DEFAULT).blocks(clusterBlock).build()); final TransportMonitoringBulkAction action = new TransportMonitoringBulkAction(threadPool, clusterService, diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherIndexingListenerTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherIndexingListenerTests.java index b6e5e53e2483d..5bc441bfa289a 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherIndexingListenerTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherIndexingListenerTests.java @@ -11,6 +11,7 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlocks; +import org.elasticsearch.cluster.coordination.NoMasterBlockService; import org.elasticsearch.cluster.metadata.AliasMetaData; import org.elasticsearch.cluster.metadata.AliasOrIndex; import org.elasticsearch.cluster.metadata.IndexMetaData; @@ -26,7 +27,6 @@ import org.elasticsearch.cluster.routing.TestShardRouting; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.index.Index; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.shard.ShardId; @@ -670,7 +670,7 @@ public void testThatIndexingListenerBecomesInactiveWithoutMasterNode() { public void testThatIndexingListenerBecomesInactiveOnClusterBlock() { ClusterState clusterState = mockClusterState(Watch.INDEX); ClusterState clusterStateWriteBlock = mockClusterState(Watch.INDEX); - ClusterBlocks clusterBlocks = ClusterBlocks.builder().addGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_WRITES).build(); + ClusterBlocks clusterBlocks = ClusterBlocks.builder().addGlobalBlock(NoMasterBlockService.NO_MASTER_BLOCK_WRITES).build(); when(clusterStateWriteBlock.getBlocks()).thenReturn(clusterBlocks); assertThat(listener.getConfiguration(), is(not(INACTIVE))); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherLifeCycleServiceTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherLifeCycleServiceTests.java index 467966e96fdbf..19e2a13487123 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherLifeCycleServiceTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherLifeCycleServiceTests.java @@ -12,6 +12,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateUpdateTask; import org.elasticsearch.cluster.block.ClusterBlocks; +import org.elasticsearch.cluster.coordination.NoMasterBlockService; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexTemplateMetaData; import org.elasticsearch.cluster.metadata.MetaData; @@ -24,7 +25,6 @@ import org.elasticsearch.cluster.routing.TestShardRouting; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.gateway.GatewayService; import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; @@ -458,7 +458,7 @@ public void testWatcherStopsOnClusterLevelBlock() { .masterNodeId("node_1") .add(newNode("node_1")) .build(); - ClusterBlocks clusterBlocks = ClusterBlocks.builder().addGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_WRITES).build(); + ClusterBlocks clusterBlocks = ClusterBlocks.builder().addGlobalBlock(NoMasterBlockService.NO_MASTER_BLOCK_WRITES).build(); ClusterState state = ClusterState.builder(new ClusterName("my-cluster")).nodes(nodes).blocks(clusterBlocks).build(); lifeCycleService.clusterChanged(new ClusterChangedEvent("any", state, state)); verify(watcherService, times(1)).pauseExecution(eq("write level cluster block")); From 8e2eb39cef53f762e78b3d4b90755996da97120b Mon Sep 17 00:00:00 2001 From: Albert Zaharovits Date: Tue, 5 Feb 2019 10:49:08 +0200 Subject: [PATCH 5/7] SecuritySettingsSource license.self_generated: trial (#38233) Authn is enabled only if `license_type` is non `basic`, but `basic` is what the `LicenseService` generates implicitly. This commit explicitly sets license type to `trial`, which allows for authn, in the `SecuritySettingsSource` which is the settings configuration parameter for `InternalTestCluster`s. The real problem, that had created tests failures like #31028 and #32685, is that the check `licenseState.isAuthAllowed()` can change sporadically. If it were to return `true` or `false` during the whole test there would be no problem. The problem manifests when it turns from `true` to `false` right before `Realms.asList()`. There are other license checks before this one (request filter, token service, etc) that would not cause a problem if they would suddenly see the check as `false`. But switching to `false` before `Realms.asList()` makes it appear that no installed realms could have handled the authn token which is an authentication error, as can be seen in the failing tests. Closes #31028 #32685 --- .../java/org/elasticsearch/test/SecuritySettingsSource.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecuritySettingsSource.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecuritySettingsSource.java index d72130db2f571..a8ad2fbd4aad3 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecuritySettingsSource.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecuritySettingsSource.java @@ -137,7 +137,8 @@ public Settings nodeSettings(int nodeOrdinal) { .put(LoggingAuditTrail.EMIT_NODE_NAME_SETTING.getKey(), randomBoolean()) .put(LoggingAuditTrail.EMIT_NODE_ID_SETTING.getKey(), randomBoolean()) .put("xpack.security.authc.realms." + FileRealmSettings.TYPE + ".file.order", 0) - .put("xpack.security.authc.realms." + NativeRealmSettings.TYPE + ".index.order", "1"); + .put("xpack.security.authc.realms." + NativeRealmSettings.TYPE + ".index.order", "1") + .put("xpack.license.self_generated.type", "trial"); addNodeSSLSettings(builder); return builder.build(); } From cea81b199dcb92bf80fb42a87fb4817a4f63d890 Mon Sep 17 00:00:00 2001 From: Andrei Stefan Date: Tue, 5 Feb 2019 12:00:49 +0200 Subject: [PATCH 6/7] Change the milliseconds precision to 3 digits for intervals. (#38297) --- .../xpack/sql/expression/literal/Intervals.java | 2 +- .../xpack/sql/expression/literal/IntervalsTests.java | 12 ++++++------ .../xpack/sql/parser/ExpressionTests.java | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/literal/Intervals.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/literal/Intervals.java index d5d13429e15af..d67ec8b2d68be 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/literal/Intervals.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/literal/Intervals.java @@ -332,7 +332,7 @@ public static TemporalAmount negate(TemporalAmount interval) { int MAX_HOUR = 23; int MAX_MINUTE = 59; int MAX_SECOND = 59; - int MAX_MILLI = 999999999; + int MAX_MILLI = 999; char DOT = '.'; char SPACE = ' '; diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/expression/literal/IntervalsTests.java b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/expression/literal/IntervalsTests.java index a54d902c69578..2140e27c8c2ff 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/expression/literal/IntervalsTests.java +++ b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/expression/literal/IntervalsTests.java @@ -83,7 +83,7 @@ public void testMinuteInterval() throws Exception { public void testSecondInterval() throws Exception { int randomSeconds = randomNonNegativeInt(); - int randomMillis = randomBoolean() ? (randomBoolean() ? 0 : 999999999) : randomInt(999999999); + int randomMillis = randomBoolean() ? (randomBoolean() ? 0 : 999) : randomInt(999); String value = format(Locale.ROOT, "%s%d.%d", sign, randomSeconds, randomMillis); TemporalAmount amount = parseInterval(EMPTY, value, INTERVAL_SECOND); assertEquals(maybeNegate(sign, Duration.ofSeconds(randomSeconds).plusMillis(randomMillis)), amount); @@ -128,7 +128,7 @@ public void testDayToSecond() throws Exception { int randomSecond = randomInt(59); boolean withMillis = randomBoolean(); - int randomMilli = withMillis ? randomInt(999999999) : 0; + int randomMilli = withMillis ? randomInt(999) : 0; String millisString = withMillis ? "." + randomMilli : ""; String value = format(Locale.ROOT, "%s%d %d:%d:%d%s", sign, randomDay, randomHour, randomMinute, randomSecond, millisString); @@ -151,7 +151,7 @@ public void testHourToSecond() throws Exception { int randomSecond = randomInt(59); boolean withMillis = randomBoolean(); - int randomMilli = withMillis ? randomInt(999999999) : 0; + int randomMilli = withMillis ? randomInt(999) : 0; String millisString = withMillis ? "." + randomMilli : ""; String value = format(Locale.ROOT, "%s%d:%d:%d%s", sign, randomHour, randomMinute, randomSecond, millisString); @@ -165,7 +165,7 @@ public void testMinuteToSecond() throws Exception { int randomSecond = randomInt(59); boolean withMillis = randomBoolean(); - int randomMilli = withMillis ? randomInt(999999999) : 0; + int randomMilli = withMillis ? randomInt(999) : 0; String millisString = withMillis ? "." + randomMilli : ""; String value = format(Locale.ROOT, "%s%d:%d%s", sign, randomMinute, randomSecond, millisString); @@ -186,11 +186,11 @@ public void testYearToMonthTooBig() throws Exception { public void testMillisTooBig() throws Exception { int randomSeconds = randomNonNegativeInt(); - int millisTooLarge = 1234567890; + int millisTooLarge = 1234; String value = format(Locale.ROOT, "%s%d.%d", sign, randomSeconds, millisTooLarge); ParsingException pe = expectThrows(ParsingException.class, () -> parseInterval(EMPTY, value, INTERVAL_SECOND)); assertEquals("line -1:0: Invalid [INTERVAL SECOND] value [" + value + "]: [MILLISECOND] unit has illegal value [" + millisTooLarge - + "], expected a positive number up to [999999999]", pe.getMessage()); + + "], expected a positive number up to [999]", pe.getMessage()); } public void testDayToMinuteTooBig() throws Exception { diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/parser/ExpressionTests.java b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/parser/ExpressionTests.java index 2e34e947944d4..2926f380ec237 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/parser/ExpressionTests.java +++ b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/parser/ExpressionTests.java @@ -150,7 +150,7 @@ public void testStringInterval() throws Exception { int randomHour = randomInt(23); int randomMinute = randomInt(59); int randomSecond = randomInt(59); - int randomMilli = randomInt(999999999); + int randomMilli = randomInt(999); String value = format(Locale.ROOT, "INTERVAL '%d %d:%d:%d.%d' DAY TO SECOND", randomDay, randomHour, randomMinute, randomSecond, randomMilli); @@ -163,7 +163,7 @@ public void testNegativeStringInterval() throws Exception { int randomHour = randomInt(23); int randomMinute = randomInt(59); int randomSecond = randomInt(59); - int randomMilli = randomInt(999999999); + int randomMilli = randomInt(999); String value = format(Locale.ROOT, "INTERVAL -'%d %d:%d:%d.%d' DAY TO SECOND", randomDay, randomHour, randomMinute, randomSecond, randomMilli); From 638ba4a59a6663ebfd4fd56a7544283e7a51ca7f Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 5 Feb 2019 06:08:03 -0500 Subject: [PATCH 7/7] Mute failing API key integration test (#38409) This commit mutes the test testGetAndInvalidateApiKeysWithExpiredAndInvalidatedApiKey as it failed during a PR build. --- .../org/elasticsearch/xpack/security/authc/ApiKeyIntegTests.java | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ApiKeyIntegTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ApiKeyIntegTests.java index 3450b713781c6..499578e9cd3ae 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ApiKeyIntegTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ApiKeyIntegTests.java @@ -232,6 +232,7 @@ public void testInvalidateApiKeysForApiKeyName() throws InterruptedException, Ex verifyInvalidateResponse(1, responses, invalidateResponse); } + @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/38408") public void testGetAndInvalidateApiKeysWithExpiredAndInvalidatedApiKey() throws Exception { List responses = createApiKeys(1, null); Instant created = Instant.now();