diff --git a/docs/reference/commands/node-tool.asciidoc b/docs/reference/commands/node-tool.asciidoc index fb7008892e5a0..7ec51908b9df4 100644 --- a/docs/reference/commands/node-tool.asciidoc +++ b/docs/reference/commands/node-tool.asciidoc @@ -62,17 +62,16 @@ after repurposing it. The intended use is: * Stop the node -* Update `elasticsearch.yml` by setting `node.master` and `node.data` as - desired. +* Update `elasticsearch.yml` by setting `node.roles` as desired. * Run `elasticsearch-node repurpose` on the node * Start the node -If you run `elasticsearch-node repurpose` on a node with `node.data: false` and -`node.master: true` then it will delete any remaining shard data on that node, -but it will leave the index and cluster metadata alone. If you run -`elasticsearch-node repurpose` on a node with `node.data: false` and -`node.master: false` then it will delete any remaining shard data and index -metadata, but it will leave the cluster metadata alone. +If you run `elasticsearch-node repurpose` on a node without the `data` role and +with the `master` role then it will delete any remaining shard data on that +node, but it will leave the index and cluster metadata alone. If you run +`elasticsearch-node repurpose` on a node without the `data` and `master` roles +then it will delete any remaining shard data and index metadata, but it will +leave the cluster metadata alone. [WARNING] Running this command can lead to data loss for the indices mentioned if the @@ -351,12 +350,12 @@ from the on-disk cluster state. === Examples [float] -==== Repurposing a node as a dedicated master node (master: true, data: false) +==== Repurposing a node as a dedicated master node In this example, a former data node is repurposed as a dedicated master node. -First update the node's settings to `node.master: true` and `node.data: false` -in its `elasticsearch.yml` config file. Then run the `elasticsearch-node -repurpose` command to find and remove excess shard data: +First update the node's settings to `node.roles: [ "master" ]` in its +`elasticsearch.yml` config file. Then run the `elasticsearch-node repurpose` +command to find and remove excess shard data: [source,txt] ---- @@ -373,13 +372,13 @@ Node successfully repurposed to master and no-data. ---- [float] -==== Repurposing a node as a coordinating-only node (master: false, data: false) +==== Repurposing a node as a coordinating-only node In this example, a node that previously held data is repurposed as a -coordinating-only node. First update the node's settings to `node.master: -false` and `node.data: false` in its `elasticsearch.yml` config file. Then run -the `elasticsearch-node repurpose` command to find and remove excess shard data -and index metadata: +coordinating-only node. First update the node's settings to `node.roles: []` in +its `elasticsearch.yml` config file. Then run the `elasticsearch-node repurpose` +command to find and remove excess shard data and index metadata: + [source,txt] ---- diff --git a/docs/reference/modules/node.asciidoc b/docs/reference/modules/node.asciidoc index a82c07032df0d..0b0c7349d6af7 100644 --- a/docs/reference/modules/node.asciidoc +++ b/docs/reference/modules/node.asciidoc @@ -22,39 +22,37 @@ dedicated data nodes, {ml} nodes, and {transform} nodes. <>:: -A node that has `node.master` set to `true` (default), which makes it eligible -to be <>, which controls the -cluster. +A node that has the `master` role (default), which makes it eligible to be +<>, which controls the cluster. <>:: -A node that has `node.data` set to `true` (default). Data nodes hold data and -perform data related operations such as CRUD, search, and aggregations. +A node that has the `data` role (default). Data nodes hold data and perform data +related operations such as CRUD, search, and aggregations. <>:: -A node that has `node.ingest` set to `true` (default). Ingest nodes are able -to apply an <> to a document in order to transform -and enrich the document before indexing. With a heavy ingest load, it makes -sense to use dedicated ingest nodes and to mark the master and data nodes as -`node.ingest: false`. +A node that has the `ingest` role (default). Ingest nodes are able to apply an +<> to a document in order to transform and enrich the +document before indexing. With a heavy ingest load, it makes sense to use +dedicated ingest nodes and to not include the `ingest` role from nodes that have +the `master` or `data` roles. <>:: -A node that has `xpack.ml.enabled` and `node.ml` set to `true`, which is the -default behavior in the {es} {default-dist}. If you want to use {ml-features}, -there must be at least one {ml} node in your cluster. For more information about -{ml-features}, see -{ml-docs}/index.html[Machine learning in the {stack}]. +A node that has `xpack.ml.enabled` and the `ml` role, which is the default +behavior in the {es} {default-dist}. If you want to use {ml-features}, there +must be at least one {ml} node in your cluster. For more information about +{ml-features}, see {ml-docs}/index.html[Machine learning in the {stack}]. + -IMPORTANT: If you use the {oss-dist}, do not set `node.ml`. Otherwise, the node -fails to start. +IMPORTANT: If you use the {oss-dist}, do not add the `ml` role. Otherwise, the +node fails to start. <>:: -A node that has `node.transform` set to `true`. If you want to use {transforms}, -there must be at least one {transform} node in your cluster. For more -information, see <> and <>. +A node that has the `transform` role. If you want to use {transforms}, there +be at least one {transform} node in your cluster. For more information, see +<> and <>. [NOTE] [[coordinating-node]] @@ -73,10 +71,9 @@ coordinating node reduces each data node's results into a single global resultset. Every node is implicitly a coordinating node. This means that a node that has -all three `node.master`, `node.data` and `node.ingest` set to `false` will -only act as a coordinating node, which cannot be disabled. As a result, such -a node needs to have enough memory and CPU in order to deal with the gather -phase. +an explicit empty list of roles via `node.roles` will only act as a coordinating +node, which cannot be disabled. As a result, such a node needs to have enough +memory and CPU in order to deal with the gather phase. =============================================== @@ -112,41 +109,12 @@ focus on managing the cluster. While master nodes can also behave as from clients to data nodes, it is better _not_ to use dedicated master nodes for this purpose. -To create a dedicated master-eligible node in the {default-dist}, set: +To create a dedicated master-eligible node, set: [source,yaml] ------------------- -node.master: true <1> -node.voting_only: false <2> -node.data: false <3> -node.ingest: false <4> -node.ml: false <5> -xpack.ml.enabled: true <6> -node.transform: false <7> -node.remote_cluster_client: false <8> +node.roles: [ master ] ------------------- -<1> The `node.master` role is enabled by default. -<2> The `node.voting_only` role is disabled by default. -<3> Disable the `node.data` role (enabled by default). -<4> Disable the `node.ingest` role (enabled by default). -<5> Disable the `node.ml` role (enabled by default). -<6> The `xpack.ml.enabled` setting is enabled by default. -<7> Disable the `node.transform` role. -<8> Disable remote cluster connections (enabled by default). - -To create a dedicated master-eligible node in the {oss-dist}, set: - -[source,yaml] -------------------- -node.master: true <1> -node.data: false <2> -node.ingest: false <3> -node.remote_cluster_client: false <4> -------------------- -<1> The `node.master` role is enabled by default. -<2> Disable the `node.data` role (enabled by default). -<3> Disable the `node.ingest` role (enabled by default). -<4> Disable remote cluster connections (enabled by default). [[voting-only-node]] ===== Voting-only master-eligible node @@ -163,19 +131,19 @@ master-eligible nodes are those nodes that participate in elections and perform certain tasks during cluster state publications, and voting-only nodes have the same responsibilities even if they can never become the elected master. -To configure a master-eligible node as a voting-only node, set the following -setting: +To configure a master-eligible node as a voting-only node, include `master` and +`voting_only` in the list of roles. For example to create a voting-only data +node: [source,yaml] ------------------- -node.voting_only: true <1> +node.roles: [ data, master, voting_only ] ------------------- -<1> The default for `node.voting_only` is `false`. IMPORTANT: The `voting_only` role requires the {default-dist} of {es} and is not -supported in the {oss-dist}. If you use the {oss-dist} and set -`node.voting_only` then the node will fail to start. Also note that only -master-eligible nodes can be marked as voting-only. +supported in the {oss-dist}. If you use the {oss-dist} and add the `voting_only` +role then the node will fail to start. Also note that only nodes with the +`master` role can be marked as having the `voting_only` role. High availability (HA) clusters require at least three master-eligible nodes, at least two of which are not voting-only nodes. Such a cluster will be able to @@ -196,23 +164,8 @@ dedicated voting-only master-eligible node in the {default-dist}, set: [source,yaml] ------------------- -node.master: true <1> -node.voting_only: true <2> -node.data: false <3> -node.ingest: false <4> -node.ml: false <5> -xpack.ml.enabled: true <6> -node.transform: false <7> -node.remote_cluster_client: false <8> +node.roles: [ master, voting_only ] ------------------- -<1> The `node.master` role is enabled by default. -<2> Enable the `node.voting_only` role (disabled by default). -<3> Disable the `node.data` role (enabled by default). -<4> Disable the `node.ingest` role (enabled by default). -<5> Disable the `node.ml` role (enabled by default). -<6> The `xpack.ml.enabled` setting is enabled by default. -<7> Disable the `node.transform` role. -<8> Disable remote cluster connections (enabled by default). [[data-node]] ==== Data node @@ -225,37 +178,11 @@ monitor these resources and to add more data nodes if they are overloaded. The main benefit of having dedicated data nodes is the separation of the master and data roles. -To create a dedicated data node in the {default-dist}, set: +To create a dedicated data node, set: [source,yaml] ------------------- -node.master: false <1> -node.voting_only: false <2> -node.data: true <3> -node.ingest: false <4> -node.ml: false <5> -node.transform: false <6> -node.remote_cluster_client: false <7> +node.roles: [ data ] ------------------- -<1> Disable the `node.master` role (enabled by default). -<2> The `node.voting_only` role is disabled by default. -<3> The `node.data` role is enabled by default. -<4> Disable the `node.ingest` role (enabled by default). -<5> Disable the `node.ml` role (enabled by default). -<6> Disable the `node.transform` role. -<7> Disable remote cluster connections (enabled by default). - -To create a dedicated data node in the {oss-dist}, set: -[source,yaml] -------------------- -node.master: false <1> -node.data: true <2> -node.ingest: false <3> -node.remote_cluster_client: false <4> -------------------- -<1> Disable the `node.master` role (enabled by default). -<2> The `node.data` role is enabled by default. -<3> Disable the `node.ingest` role (enabled by default). -<4> Disable remote cluster connections (enabled by default). [[node-ingest-node]] ==== Ingest node @@ -265,39 +192,12 @@ ingest processors. Depending on the type of operations performed by the ingest processors and the required resources, it may make sense to have dedicated ingest nodes, that will only perform this specific task. -To create a dedicated ingest node in the {default-dist}, set: - -[source,yaml] -------------------- -node.master: false <1> -node.voting_only: false <2> -node.data: false <3> -node.ingest: true <4> -node.ml: false <5> -node.transform: false <6> -node.remote_cluster_client: false <7> -------------------- -<1> Disable the `node.master` role (enabled by default). -<2> The `node.voting_only` role is disabled by default. -<3> Disable the `node.data` role (enabled by default). -<4> The `node.ingest` role is enabled by default. -<5> Disable the `node.ml` role (enabled by default). -<6> Disable the `node.transform` role. -<7> Disable remote cluster connections (enabled by default). - -To create a dedicated ingest node in the {oss-dist}, set: +To create a dedicated ingest node, set: [source,yaml] ------------------- -node.master: false <1> -node.data: false <2> -node.ingest: true <3> -node.remote_cluster_client: false <4> +node.roles: [ ingest ] ------------------- -<1> Disable the `node.master` role (enabled by default). -<2> Disable the `node.data` role (enabled by default). -<3> The `node.ingest` role is enabled by default. -<4> Disable remote cluster connections (enabled by default). [[coordinating-only-node]] ==== Coordinating only node @@ -319,48 +219,19 @@ acknowledgement of cluster state updates from every node! The benefit of coordinating only nodes should not be overstated -- data nodes can happily serve the same purpose. -To create a dedicated coordinating node in the {default-dist}, set: - -[source,yaml] -------------------- -node.master: false <1> -node.voting_only: false <2> -node.data: false <3> -node.ingest: false <4> -node.ml: false <5> -xpack.ml.enabled: true <6> -node.transform: false <7> -node.remote_cluster_client: false <8> -------------------- -<1> Disable the `node.master` role (enabled by default). -<2> The `node.voting_only` role is disabled by default. -<3> Disable the `node.data` role (enabled by default). -<4> Disable the `node.ingest` role (enabled by default). -<5> Disable the `node.ml` role (enabled by default). -<6> The `xpack.ml.enabled` setting is enabled by default. -<7> Disable the `node.transform` role. -<8> Disable remote cluster connections (enabled by default). - -To create a dedicated coordinating node in the {oss-dist}, set: +To create a dedicated coordinating node, set: [source,yaml] ------------------- -node.master: false <1> -node.data: false <2> -node.ingest: false <3> -node.remote_cluster_client: false <4> +node.roles: [ ] ------------------- -<1> Disable the `node.master` role (enabled by default). -<2> Disable the `node.data` role (enabled by default). -<3> Disable the `node.ingest` role (enabled by default). -<4> Disable remote cluster connections (enabled by default). [[ml-node]] ==== [xpack]#Machine learning node# The {ml-features} provide {ml} nodes, which run jobs and handle {ml} API -requests. If `xpack.ml.enabled` is set to `true` and `node.ml` is set to `false`, -the node can service API requests but it cannot run jobs. +requests. If `xpack.ml.enabled` is set to `true` and the node does not have the +`ml` role, the node can service API requests but it cannot run jobs. If you want to use {ml-features} in your cluster, you must enable {ml} (set `xpack.ml.enabled` to `true`) on all master-eligible nodes. If you want to @@ -373,53 +244,27 @@ To create a dedicated {ml} node in the {default-dist}, set: [source,yaml] ------------------- -node.master: false <1> -node.voting_only: false <2> -node.data: false <3> -node.ingest: false <4> -node.ml: true <5> -xpack.ml.enabled: true <6> -node.transform: false <7> -node.remote_cluster_client: false <8> +node.roles: [ ml ] +xpack.ml.enabled: true <1> ------------------- -<1> Disable the `node.master` role (enabled by default). -<2> The `node.voting_only` role is disabled by default. -<3> Disable the `node.data` role (enabled by default). -<4> Disable the `node.ingest` role (enabled by default). -<5> The `node.ml` role is enabled by default. -<6> The `xpack.ml.enabled` setting is enabled by default. -<7> Disable the `node.transform` role. -<8> Disable remote cluster connections (enabled by default). +<1> The `xpack.ml.enabled` setting is enabled by default. [[transform-node]] ==== [xpack]#{transform-cap} node# {transform-cap} nodes run {transforms} and handle {transform} API requests. -If you want to use {transforms} in your cluster, you must have `node.transform` -set to `true` on at least one node. This is the default behavior. If you have -the {oss-dist}, do not use these settings. For more information, see -<>. +If you want to use {transforms} in clients (including {kib}), it must also be +enabled on all coordinating nodes. You must also have at least one node with the +`transform` role. This is the default behavior. If you have the {oss-dist}, do +not use these settings. For more information, see <>. To create a dedicated {transform} node in the {default-dist}, set: [source,yaml] ------------------- -node.master: false <1> -node.voting_only: false <2> -node.data: false <3> -node.ingest: false <4> -node.ml: false <5> -node.transform: true <6> -node.remote_cluster_client: false <7> +node.roles: [ transform ] ------------------- -<1> Disable the `node.master` role. -<2> Disable the `node.voting_only`. -<3> Disable the `node.data` role. -<4> Disable the `node.ingest` role. -<5> Disable the `node.ml` role. -<6> Enable the `node.transform` role. -<7> Disable remote cluster connections. [[change-node-role]] ==== Changing the role of a node @@ -438,26 +283,25 @@ Similarly, each master-eligible node maintains the following data on disk: Each node checks the contents of its data path at startup. If it discovers unexpected data then it will refuse to start. This is to avoid importing unwanted <> which can lead -to a red cluster health. To be more precise, nodes with `node.data: false` will +to a red cluster health. To be more precise, nodes without the `data` role will refuse to start if they find any shard data on disk at startup, and nodes with -both `node.master: false` and `node.data: false` will refuse to start if they -have any index metadata on disk at startup. +without both the `master` and `data` roles will refuse to start if they have any index metadata on disk at startup. It is possible to change the roles of a node by adjusting its `elasticsearch.yml` file and restarting it. This is known as _repurposing_ a node. In order to satisfy the checks for unexpected data described above, you -must perform some extra steps to prepare a node for repurposing when setting -its `node.data` or `node.master` roles to `false`: +must perform some extra steps to prepare a node for repurposing when starting +the node without the `data` or `master` roles. -* If you want to repurpose a data node by changing `node.data` to `false` then - you should first use an <> to safely +* If you want to repurpose a data node by removing the `data` role then you + should first use an <> to safely migrate all the shard data onto other nodes in the cluster. -* If you want to repurpose a node to have both `node.master: false` and - `node.data: false` then it is simplest to start a brand-new node with an - empty data path and the desired roles. You may find it safest to use an - <> to migrate the shard data - elsewhere in the cluster first. +* If you want to repurpose a node to have neither the `data` nor `master` roles + then it is simplest to start a brand-new node with an empty data path and the + desired roles. You may find it safest to use an + <> to migrate the shard data elsewhere + in the cluster first. If it is not possible to follow these extra steps then you may be able to use the <> tool to delete any diff --git a/modules/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpProcessorNonIngestNodeTests.java b/modules/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpProcessorNonIngestNodeTests.java index ee1a3c6fd4438..c79fdce16f346 100644 --- a/modules/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpProcessorNonIngestNodeTests.java +++ b/modules/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpProcessorNonIngestNodeTests.java @@ -33,6 +33,7 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.NodeRoles; import org.elasticsearch.test.StreamsUtils; import java.io.ByteArrayInputStream; @@ -45,6 +46,7 @@ import java.util.Collections; import java.util.List; +import static org.elasticsearch.test.NodeRoles.nonIngestNode; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; @@ -82,7 +84,7 @@ protected Settings nodeSettings(final int nodeOrdinal) { } return Settings.builder() .put("ingest.geoip.database_path", databasePath) - .put("node.ingest", false) + .put(nonIngestNode()) .put(super.nodeSettings(nodeOrdinal)) .build(); } @@ -145,7 +147,7 @@ public void testLazyLoading() throws IOException { Arrays.stream(internalCluster().getNodeNames()).forEach(node -> assertDatabaseLoadStatus(node, false)); // start an ingest node - final String ingestNode = internalCluster().startNode(Settings.builder().put("node.ingest", true).build()); + final String ingestNode = internalCluster().startNode(NodeRoles.ingestNode()); internalCluster().getInstance(IngestService.class, ingestNode); // the geo-IP database should not be loaded yet as we have no indexed any documents using a pipeline that has a geo-IP processor assertDatabaseLoadStatus(ingestNode, false); diff --git a/qa/multi-cluster-search/build.gradle b/qa/multi-cluster-search/build.gradle index 85211e38a7849..8544dd58aeaf4 100644 --- a/qa/multi-cluster-search/build.gradle +++ b/qa/multi-cluster-search/build.gradle @@ -35,7 +35,7 @@ task 'remote-cluster'(type: RestIntegTestTask) { testClusters.'remote-cluster' { numberOfNodes = 2 - setting 'node.remote_cluster_client', 'false' + setting 'node.roles', '[data,ingest,master]' } task mixedClusterTest(type: RestIntegTestTask) { @@ -50,7 +50,6 @@ testClusters.mixedClusterTest { setting 'cluster.remote.my_remote_cluster.seeds', { "\"${testClusters.'remote-cluster'.getAllTransportPortURI().get(0)}\"" } setting 'cluster.remote.connections_per_cluster', '1' - setting 'node.remote_cluster_client', 'true' } diff --git a/qa/smoke-test-ingest-disabled/build.gradle b/qa/smoke-test-ingest-disabled/build.gradle index dca3e705d78c7..6885dbb1dfd17 100644 --- a/qa/smoke-test-ingest-disabled/build.gradle +++ b/qa/smoke-test-ingest-disabled/build.gradle @@ -26,5 +26,5 @@ dependencies { } testClusters.integTest { - setting 'node.ingest', 'false' + setting 'node.roles', '[data,master,remote_cluster_client]' } diff --git a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java index 6e7454cd44b83..8b5cc046c57b3 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java @@ -30,7 +30,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.monitor.os.OsStats; -import org.elasticsearch.node.Node; +import org.elasticsearch.node.NodeRoleSettings; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; @@ -38,8 +38,11 @@ import java.io.IOException; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; @@ -75,14 +78,27 @@ public void testNodeCounts() { for (int i = 0; i < numNodes; i++) { boolean isDataNode = randomBoolean(); - boolean isMasterNode = randomBoolean(); boolean isIngestNode = randomBoolean(); - boolean isRemoteClusterClientNode = randomBoolean(); + boolean isMasterNode = randomBoolean(); + boolean isRemoteClusterClientNode = false; + final Set roles = new HashSet<>(); + if (isDataNode) { + roles.add(DiscoveryNodeRole.DATA_ROLE); + } + if (isIngestNode) { + roles.add(DiscoveryNodeRole.INGEST_ROLE); + } + if (isMasterNode) { + roles.add(DiscoveryNodeRole.MASTER_ROLE); + } + if (isRemoteClusterClientNode) { + roles.add(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE); + } Settings settings = Settings.builder() - .put(Node.NODE_DATA_SETTING.getKey(), isDataNode) - .put(Node.NODE_MASTER_SETTING.getKey(), isMasterNode) - .put(Node.NODE_INGEST_SETTING.getKey(), isIngestNode) - .put(Node.NODE_REMOTE_CLUSTER_CLIENT.getKey(), isRemoteClusterClientNode) + .putList( + NodeRoleSettings.NODE_ROLES_SETTING.getKey(), + roles.stream().map(DiscoveryNodeRole::roleName).collect(Collectors.toList()) + ) .build(); internalCluster().startNode(settings); total++; @@ -91,12 +107,12 @@ public void testNodeCounts() { if (isDataNode) { incrementCountForRole(DiscoveryNodeRole.DATA_ROLE.roleName(), expectedCounts); } - if (isMasterNode) { - incrementCountForRole(DiscoveryNodeRole.MASTER_ROLE.roleName(), expectedCounts); - } if (isIngestNode) { incrementCountForRole(DiscoveryNodeRole.INGEST_ROLE.roleName(), expectedCounts); } + if (isMasterNode) { + incrementCountForRole(DiscoveryNodeRole.MASTER_ROLE.roleName(), expectedCounts); + } if (isRemoteClusterClientNode) { incrementCountForRole(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), expectedCounts); } diff --git a/server/src/internalClusterTest/java/org/elasticsearch/cluster/SimpleDataNodesIT.java b/server/src/internalClusterTest/java/org/elasticsearch/cluster/SimpleDataNodesIT.java index 7d2274f2dbcc7..1cde76b58c8df 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/cluster/SimpleDataNodesIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/cluster/SimpleDataNodesIT.java @@ -29,13 +29,14 @@ import org.elasticsearch.common.Priority; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.node.Node; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; import static org.elasticsearch.client.Requests.createIndexRequest; import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds; +import static org.elasticsearch.test.NodeRoles.dataNode; +import static org.elasticsearch.test.NodeRoles.nonDataNode; import static org.hamcrest.Matchers.equalTo; @ClusterScope(scope = Scope.TEST, numDataNodes = 0) @@ -44,7 +45,7 @@ public class SimpleDataNodesIT extends ESIntegTestCase { private static final String SOURCE = "{\"type1\":{\"id\":\"1\",\"name\":\"test\"}}"; public void testIndexingBeforeAndAfterDataNodesStart() { - internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build()); + internalCluster().startNode(nonDataNode()); client().admin().indices().create(createIndexRequest("test").waitForActiveShards(ActiveShardCount.NONE)).actionGet(); try { client().index(Requests.indexRequest("test").id("1").source(SOURCE, XContentType.JSON) @@ -54,7 +55,7 @@ public void testIndexingBeforeAndAfterDataNodesStart() { // all is well } - internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build()); + internalCluster().startNode(nonDataNode()); assertThat(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNodes("2") .setLocal(true).execute().actionGet().isTimedOut(), equalTo(false)); @@ -68,7 +69,7 @@ public void testIndexingBeforeAndAfterDataNodesStart() { } // now, start a node data, and see that it gets with shards - internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), true).build()); + internalCluster().startNode(dataNode()); assertThat(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNodes("3") .setLocal(true).execute().actionGet().isTimedOut(), equalTo(false)); @@ -78,7 +79,7 @@ public void testIndexingBeforeAndAfterDataNodesStart() { } public void testShardsAllocatedAfterDataNodesStart() { - internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build()); + internalCluster().startNode(nonDataNode()); client().admin().indices().create(createIndexRequest("test") .settings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)).waitForActiveShards(ActiveShardCount.NONE)) .actionGet(); @@ -88,7 +89,7 @@ public void testShardsAllocatedAfterDataNodesStart() { assertThat(healthResponse1.getStatus(), equalTo(ClusterHealthStatus.RED)); assertThat(healthResponse1.getActiveShards(), equalTo(0)); - internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), true).build()); + internalCluster().startNode(dataNode()); assertThat(client().admin().cluster().prepareHealth() .setWaitForEvents(Priority.LANGUID).setWaitForNodes("2").setWaitForGreenStatus().execute().actionGet().isTimedOut(), @@ -96,7 +97,7 @@ public void testShardsAllocatedAfterDataNodesStart() { } public void testAutoExpandReplicasAdjustedWhenDataNodeJoins() { - internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build()); + internalCluster().startNode(nonDataNode()); client().admin().indices().create(createIndexRequest("test") .settings(Settings.builder().put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-all")) .waitForActiveShards(ActiveShardCount.NONE)) @@ -111,4 +112,5 @@ public void testAutoExpandReplicasAdjustedWhenDataNodeJoins() { internalCluster().startNode(); client().admin().cluster().prepareReroute().setRetryFailed(true).get(); } + } diff --git a/server/src/internalClusterTest/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java b/server/src/internalClusterTest/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java index fc457c890b19e..34b388069b18f 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.MasterNotDiscoveredException; import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.node.Node; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; @@ -33,6 +32,9 @@ import java.io.IOException; +import static org.elasticsearch.test.NodeRoles.dataOnlyNode; +import static org.elasticsearch.test.NodeRoles.masterNode; +import static org.elasticsearch.test.NodeRoles.nonDataNode; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.nullValue; @@ -43,9 +45,7 @@ public class SpecificMasterNodesIT extends ESIntegTestCase { public void testSimpleOnlyMasterNodeElection() throws IOException { internalCluster().setBootstrapMasterNodeIndex(0); logger.info("--> start data node / non master node"); - internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), true) - .put(Node.NODE_MASTER_SETTING.getKey(), false) - .put("discovery.initial_state_timeout", "1s")); + internalCluster().startNode(Settings.builder().put(dataOnlyNode()).put("discovery.initial_state_timeout", "1s")); try { assertThat(client().admin().cluster().prepareState().setMasterNodeTimeout("100ms") .execute().actionGet().getState().nodes().getMasterNodeId(), nullValue()); @@ -54,8 +54,7 @@ public void testSimpleOnlyMasterNodeElection() throws IOException { // all is well, no master elected } logger.info("--> start master node"); - final String masterNodeName = internalCluster() - .startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_MASTER_SETTING.getKey(), true)); + final String masterNodeName = internalCluster().startMasterOnlyNode(); assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState() .execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(masterNodeName)); assertThat(internalCluster().masterClient().admin().cluster().prepareState() @@ -75,8 +74,7 @@ public void testSimpleOnlyMasterNodeElection() throws IOException { logger.info("--> start previous master node again"); final String nextMasterEligibleNodeName = internalCluster() - .startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_MASTER_SETTING.getKey(), true) - .put(masterDataPathSettings)); + .startNode(Settings.builder().put(nonDataNode(masterNode())).put(masterDataPathSettings)); assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState() .execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(nextMasterEligibleNodeName)); assertThat(internalCluster().masterClient().admin().cluster().prepareState() @@ -86,8 +84,7 @@ public void testSimpleOnlyMasterNodeElection() throws IOException { public void testElectOnlyBetweenMasterNodes() throws Exception { internalCluster().setBootstrapMasterNodeIndex(0); logger.info("--> start data node / non master node"); - internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), true) - .put(Node.NODE_MASTER_SETTING.getKey(), false).put("discovery.initial_state_timeout", "1s")); + internalCluster().startNode(Settings.builder().put(dataOnlyNode()).put("discovery.initial_state_timeout", "1s")); try { assertThat(client().admin().cluster().prepareState().setMasterNodeTimeout("100ms") .execute().actionGet().getState().nodes().getMasterNodeId(), nullValue()); @@ -96,16 +93,14 @@ public void testElectOnlyBetweenMasterNodes() throws Exception { // all is well, no master elected } logger.info("--> start master node (1)"); - final String masterNodeName = internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false) - .put(Node.NODE_MASTER_SETTING.getKey(), true)); + final String masterNodeName = internalCluster().startMasterOnlyNode(); assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState() .execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(masterNodeName)); assertThat(internalCluster().masterClient().admin().cluster().prepareState() .execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(masterNodeName)); logger.info("--> start master node (2)"); - final String nextMasterEligableNodeName = internalCluster().startNode(Settings.builder() - .put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_MASTER_SETTING.getKey(), true)); + final String nextMasterEligableNodeName = internalCluster().startMasterOnlyNode(); assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState() .execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(masterNodeName)); assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState() @@ -132,12 +127,10 @@ public void testElectOnlyBetweenMasterNodes() throws Exception { public void testAliasFilterValidation() { internalCluster().setBootstrapMasterNodeIndex(0); logger.info("--> start master node / non data"); - internalCluster().startNode(Settings.builder() - .put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_MASTER_SETTING.getKey(), true)); + internalCluster().startMasterOnlyNode(); logger.info("--> start data node / non master node"); - internalCluster().startNode(Settings.builder() - .put(Node.NODE_DATA_SETTING.getKey(), true).put(Node.NODE_MASTER_SETTING.getKey(), false)); + internalCluster().startDataOnlyNode(); assertAcked(prepareCreate("test").setMapping( "{\"properties\" : {\"table_a\" : { \"type\" : \"nested\", " + @@ -145,4 +138,5 @@ public void testAliasFilterValidation() { client().admin().indices().prepareAliases().addAlias("test", "a_test", QueryBuilders.nestedQuery("table_a", QueryBuilders.termQuery("table_a.field_b", "y"), ScoreMode.Avg)).get(); } + } diff --git a/server/src/internalClusterTest/java/org/elasticsearch/cluster/UpdateSettingsValidationIT.java b/server/src/internalClusterTest/java/org/elasticsearch/cluster/UpdateSettingsValidationIT.java index 11cdb8afc4c41..912bc9e99b8e1 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/cluster/UpdateSettingsValidationIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/cluster/UpdateSettingsValidationIT.java @@ -22,21 +22,18 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.common.Priority; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.node.Node; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; +import static org.elasticsearch.test.NodeRoles.nonDataNode; +import static org.elasticsearch.test.NodeRoles.nonMasterNode; import static org.hamcrest.Matchers.equalTo; @ClusterScope(scope= Scope.TEST, numDataNodes =0) public class UpdateSettingsValidationIT extends ESIntegTestCase { public void testUpdateSettingsValidation() throws Exception { - internalCluster().startNodes( - Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build(), - Settings.builder().put(Node.NODE_MASTER_SETTING.getKey(), false).build(), - Settings.builder().put(Node.NODE_MASTER_SETTING.getKey(), false).build() - ); + internalCluster().startNodes(nonDataNode(), nonMasterNode(), nonMasterNode()); createIndex("test"); NumShards test = getNumShards("test"); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java b/server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java index e15d68bec1bf0..cb83a8833b109 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java @@ -44,6 +44,7 @@ import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.indices.recovery.RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING; +import static org.elasticsearch.test.NodeRoles.nonMasterNode; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; @@ -104,8 +105,7 @@ private void expectThrows(ThrowingRunnable runnable, String message) { public void testBootstrapNotMasterEligible() { final Environment environment = TestEnvironment.newEnvironment(Settings.builder() - .put(internalCluster().getDefaultSettings()) - .put(Node.NODE_MASTER_SETTING.getKey(), false) + .put(nonMasterNode(internalCluster().getDefaultSettings())) .build()); expectThrows(() -> unsafeBootstrap(environment), UnsafeBootstrapMasterCommand.NOT_MASTER_NODE_MSG); } diff --git a/server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/ZenDiscoveryIT.java b/server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/ZenDiscoveryIT.java index 2aa8ffd7e5a00..0c8d8c558d131 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/ZenDiscoveryIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/ZenDiscoveryIT.java @@ -34,7 +34,6 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.discovery.Discovery; import org.elasticsearch.discovery.DiscoveryStats; -import org.elasticsearch.node.Node; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.TestCustomMetadata; import org.elasticsearch.transport.RemoteTransportException; @@ -46,6 +45,8 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import static org.elasticsearch.test.NodeRoles.dataNode; +import static org.elasticsearch.test.NodeRoles.masterOnlyNode; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo; @@ -57,13 +58,9 @@ public class ZenDiscoveryIT extends ESIntegTestCase { public void testNoShardRelocationsOccurWhenElectedMasterNodeFails() throws Exception { - Settings masterNodeSettings = Settings.builder() - .put(Node.NODE_DATA_SETTING.getKey(), false) - .build(); + Settings masterNodeSettings = masterOnlyNode(); internalCluster().startNodes(2, masterNodeSettings); - Settings dateNodeSettings = Settings.builder() - .put(Node.NODE_MASTER_SETTING.getKey(), false) - .build(); + Settings dateNodeSettings = dataNode(); internalCluster().startNodes(2, dateNodeSettings); ClusterHealthResponse clusterHealthResponse = client().admin().cluster().prepareHealth() .setWaitForEvents(Priority.LANGUID) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleIT.java b/server/src/internalClusterTest/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleIT.java index 06c4b14cae417..b8c60cc81fdc0 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleIT.java @@ -21,6 +21,7 @@ import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.common.settings.Setting; +import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; @@ -30,6 +31,8 @@ import java.util.List; import java.util.Set; +import static org.elasticsearch.test.NodeRoles.addRoles; +import static org.elasticsearch.test.NodeRoles.removeRoles; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.not; @@ -43,12 +46,12 @@ public AdditionalRolePlugin() { } static final Setting NODE_ADDITIONAL_SETTING = - Setting.boolSetting("node.additional", true, Setting.Property.NodeScope); + Setting.boolSetting("node.additional", true, Property.Deprecated, Property.NodeScope); static DiscoveryNodeRole ADDITIONAL_ROLE = new DiscoveryNodeRole("additional", "a") { @Override - protected Setting roleSetting() { + public Setting legacySetting() { return NODE_ADDITIONAL_SETTING; } @@ -75,20 +78,28 @@ public void testDefaultHasAdditionalRole() { runTestNodeHasAdditionalRole(Settings.EMPTY); } - public void testExplicitlyHasAdditionalRole() { + public void testExplicitlyHasAdditionalRoleUsingLegacySetting() { runTestNodeHasAdditionalRole(Settings.builder().put(AdditionalRolePlugin.NODE_ADDITIONAL_SETTING.getKey(), true).build()); } - public void testDoesNotHaveAdditionalRole() { + public void testExplicitlyHasAdditionalRoles() { + runTestNodeHasAdditionalRole(addRoles(Set.of(AdditionalRolePlugin.ADDITIONAL_ROLE))); + } + + public void testDoesNotHaveAdditionalRoleUsingLegacySetting() { runTestNodeHasAdditionalRole(Settings.builder().put(AdditionalRolePlugin.NODE_ADDITIONAL_SETTING.getKey(), false).build()); } + public void testExplicitlyDoesNotHaveAdditionalRole() { + runTestNodeHasAdditionalRole(removeRoles(Set.of(AdditionalRolePlugin.ADDITIONAL_ROLE))); + } + private void runTestNodeHasAdditionalRole(final Settings settings) { final String name = internalCluster().startNode(settings); final NodesInfoResponse response = client().admin().cluster().prepareNodesInfo(name).get(); assertThat(response.getNodes(), hasSize(1)); final Matcher> matcher; - if (AdditionalRolePlugin.NODE_ADDITIONAL_SETTING.get(settings)) { + if (DiscoveryNode.hasRole(settings, AdditionalRolePlugin.ADDITIONAL_ROLE)) { matcher = hasItem(AdditionalRolePlugin.ADDITIONAL_ROLE); } else { matcher = not(hasItem(AdditionalRolePlugin.ADDITIONAL_ROLE)); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/cluster/shards/ClusterShardLimitIT.java b/server/src/internalClusterTest/java/org/elasticsearch/cluster/shards/ClusterShardLimitIT.java index 67535870d56be..be8130d59b1a8 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/cluster/shards/ClusterShardLimitIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/cluster/shards/ClusterShardLimitIT.java @@ -33,7 +33,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.indices.ShardLimitValidator; -import org.elasticsearch.node.Node; import org.elasticsearch.snapshots.SnapshotInfo; import org.elasticsearch.snapshots.SnapshotState; import org.elasticsearch.test.ESIntegTestCase; @@ -43,6 +42,7 @@ 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.test.NodeRoles.dataNode; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; @@ -329,7 +329,7 @@ public void testOpenIndexOverLimit() { private int ensureMultipleDataNodes(int dataNodes) { if (dataNodes == 1) { - internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), true).build()); + internalCluster().startNode(dataNode()); assertThat(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNodes(">=2").setLocal(true) .execute().actionGet().isTimedOut(), equalTo(false)); dataNodes = client().admin().cluster().prepareState().get().getState().getNodes().getDataNodes().size(); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/env/NodeEnvironmentIT.java b/server/src/internalClusterTest/java/org/elasticsearch/env/NodeEnvironmentIT.java index 17459bff4589d..fb8975d235538 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/env/NodeEnvironmentIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/env/NodeEnvironmentIT.java @@ -20,15 +20,16 @@ package org.elasticsearch.env; import org.elasticsearch.Version; +import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.CheckedConsumer; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.gateway.PersistedClusterStateService; import org.elasticsearch.indices.IndicesService; -import org.elasticsearch.node.Node; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.InternalTestCluster; +import org.elasticsearch.test.NodeRoles; import java.io.IOException; import java.io.UncheckedIOException; @@ -38,9 +39,11 @@ import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; +import static org.elasticsearch.test.NodeRoles.nonDataNode; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.containsString; @@ -69,54 +72,40 @@ public void testStartFailureOnDataForNonDataNode() throws Exception { indicesService -> assertTrue(indicesService.allPendingDanglingIndicesWritten()))); } - logger.info("--> restarting the node with node.data=false and node.master=false"); + logger.info("--> restarting the node without the data and master roles"); IllegalStateException ex = expectThrows(IllegalStateException.class, - "Node started with node.data=false and node.master=false while having existing index metadata must fail", + "node not having the data and master roles while having existing index metadata must fail", () -> internalCluster().restartRandomDataNode(new InternalTestCluster.RestartCallback() { @Override public Settings onNodeStopped(String nodeName) { - return Settings.builder() - .put(Node.NODE_DATA_SETTING.getKey(), false) - .put(Node.NODE_MASTER_SETTING.getKey(), false) - .build(); + return NodeRoles.removeRoles(Set.of(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.MASTER_ROLE)); } })); if (writeDanglingIndices) { - assertThat(ex.getMessage(), - startsWith("Node is started with " - + Node.NODE_DATA_SETTING.getKey() - + "=false and " - + Node.NODE_MASTER_SETTING.getKey() - + "=false, but has index metadata")); + assertThat(ex.getMessage(), startsWith("node does not have the data and master roles but has index metadata")); } else { - assertThat(ex.getMessage(), - startsWith("Node is started with " - + Node.NODE_DATA_SETTING.getKey() - + "=false, but has shard data")); + assertThat(ex.getMessage(), startsWith("node does not have the data role but has shard data")); } - logger.info("--> start the node again with node.data=true and node.master=true"); + logger.info("--> start the node again with data and master roles"); internalCluster().startNode(dataPathSettings); logger.info("--> indexing a simple document"); client().prepareIndex(indexName).setId("1").setSource("field1", "value1").get(); - logger.info("--> restarting the node with node.data=false"); + logger.info("--> restarting the node without the data role"); ex = expectThrows(IllegalStateException.class, - "Node started with node.data=false while having existing shard data must fail", + "node not having the data role while having existing shard data must fail", () -> internalCluster().restartRandomDataNode(new InternalTestCluster.RestartCallback() { @Override public Settings onNodeStopped(String nodeName) { - return Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build(); + return nonDataNode(); } })); assertThat(ex.getMessage(), containsString(indexUUID)); - assertThat(ex.getMessage(), - startsWith("Node is started with " - + Node.NODE_DATA_SETTING.getKey() - + "=false, but has shard data")); + assertThat(ex.getMessage(), startsWith("node does not have the data role but has shard data")); } private IllegalStateException expectThrowsOnRestart(CheckedConsumer onNodeStopped) { diff --git a/server/src/internalClusterTest/java/org/elasticsearch/env/NodeRepurposeCommandIT.java b/server/src/internalClusterTest/java/org/elasticsearch/env/NodeRepurposeCommandIT.java index 300191d3f2f3f..80ca00dc47a2c 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/env/NodeRepurposeCommandIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/env/NodeRepurposeCommandIT.java @@ -20,12 +20,15 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.NoShardAvailableActionException; +import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.IndicesService; -import org.elasticsearch.node.Node; import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.NodeRoles; import org.hamcrest.Matcher; +import java.util.Set; + import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.containsString; @@ -56,10 +59,7 @@ public void testRepurpose() throws Exception { final Settings masterNodeDataPathSettings = internalCluster().dataPathSettings(masterNode); final Settings dataNodeDataPathSettings = internalCluster().dataPathSettings(dataNode); - final Settings noMasterNoDataSettings = Settings.builder() - .put(Node.NODE_DATA_SETTING.getKey(), false) - .put(Node.NODE_MASTER_SETTING.getKey(), false) - .build(); + final Settings noMasterNoDataSettings = NodeRoles.removeRoles(Set.of(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.MASTER_ROLE)); final Settings noMasterNoDataSettingsForMasterNode = Settings.builder() .put(noMasterNoDataSettings) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/gateway/GatewayIndexStateIT.java b/server/src/internalClusterTest/java/org/elasticsearch/gateway/GatewayIndexStateIT.java index bcb7d84ba7043..00320e9539e7f 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/gateway/GatewayIndexStateIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/gateway/GatewayIndexStateIT.java @@ -47,7 +47,6 @@ import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.indices.IndexClosedException; import org.elasticsearch.indices.ShardLimitValidator; -import org.elasticsearch.node.Node; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; @@ -64,6 +63,7 @@ import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; +import static org.elasticsearch.test.NodeRoles.nonDataNode; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.hamcrest.Matchers.containsString; @@ -216,7 +216,7 @@ public void testJustMasterNode() throws Exception { logger.info("--> cleaning nodes"); logger.info("--> starting 1 master node non data"); - internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build()); + internalCluster().startNode(nonDataNode()); logger.info("--> create an index"); client().admin().indices().prepareCreate("test").setWaitForActiveShards(ActiveShardCount.NONE).execute().actionGet(); @@ -225,7 +225,7 @@ public void testJustMasterNode() throws Exception { internalCluster().fullRestart(new RestartCallback(){ @Override public Settings onNodeStopped(String nodeName) { - return Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build(); + return nonDataNode(); } }); @@ -243,8 +243,8 @@ public void testJustMasterNodeAndJustDataNode() { logger.info("--> cleaning nodes"); logger.info("--> starting 1 master node non data"); - internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build()); - internalCluster().startNode(Settings.builder().put(Node.NODE_MASTER_SETTING.getKey(), false).build()); + internalCluster().startMasterOnlyNode(); + internalCluster().startDataOnlyNode(); logger.info("--> create an index"); client().admin().indices().prepareCreate("test").execute().actionGet(); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/gateway/RecoverAfterNodesIT.java b/server/src/internalClusterTest/java/org/elasticsearch/gateway/RecoverAfterNodesIT.java index 84188f80aaed3..9a79b62de59af 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/gateway/RecoverAfterNodesIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/gateway/RecoverAfterNodesIT.java @@ -24,13 +24,14 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.node.Node; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; import java.util.Set; +import static org.elasticsearch.test.NodeRoles.dataOnlyNode; +import static org.elasticsearch.test.NodeRoles.masterOnlyNode; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasItem; @@ -84,17 +85,13 @@ public void testRecoverAfterNodes() throws Exception { public void testRecoverAfterMasterNodes() throws Exception { internalCluster().setBootstrapMasterNodeIndex(0); logger.info("--> start master_node (1)"); - Client master1 = startNode(Settings.builder() - .put("gateway.recover_after_master_nodes", 2).put(Node.NODE_DATA_SETTING.getKey(), false) - .put(Node.NODE_MASTER_SETTING.getKey(), true)); + Client master1 = startNode(Settings.builder().put("gateway.recover_after_master_nodes", 2).put(masterOnlyNode())); assertThat(master1.admin().cluster().prepareState().setLocal(true).execute().actionGet() .getState().blocks().global(ClusterBlockLevel.METADATA_WRITE), hasItem(GatewayService.STATE_NOT_RECOVERED_BLOCK)); logger.info("--> start data_node (1)"); - Client data1 = startNode(Settings.builder() - .put("gateway.recover_after_master_nodes", 2) - .put(Node.NODE_DATA_SETTING.getKey(), true).put(Node.NODE_MASTER_SETTING.getKey(), false)); + Client data1 = startNode(Settings.builder().put("gateway.recover_after_master_nodes", 2).put(dataOnlyNode())); assertThat(master1.admin().cluster().prepareState().setLocal(true).execute().actionGet() .getState().blocks().global(ClusterBlockLevel.METADATA_WRITE), hasItem(GatewayService.STATE_NOT_RECOVERED_BLOCK)); @@ -103,9 +100,7 @@ public void testRecoverAfterMasterNodes() throws Exception { hasItem(GatewayService.STATE_NOT_RECOVERED_BLOCK)); logger.info("--> start data_node (2)"); - Client data2 = startNode(Settings.builder() - .put("gateway.recover_after_master_nodes", 2).put(Node.NODE_DATA_SETTING.getKey(), true) - .put(Node.NODE_MASTER_SETTING.getKey(), false)); + Client data2 = startNode(Settings.builder().put("gateway.recover_after_master_nodes", 2).put(dataOnlyNode())); assertThat(master1.admin().cluster().prepareState().setLocal(true).execute().actionGet() .getState().blocks().global(ClusterBlockLevel.METADATA_WRITE), hasItem(GatewayService.STATE_NOT_RECOVERED_BLOCK)); @@ -117,10 +112,7 @@ public void testRecoverAfterMasterNodes() throws Exception { hasItem(GatewayService.STATE_NOT_RECOVERED_BLOCK)); logger.info("--> start master_node (2)"); - Client master2 = startNode(Settings.builder() - .put("gateway.recover_after_master_nodes", 2) - .put(Node.NODE_DATA_SETTING.getKey(), false) - .put(Node.NODE_MASTER_SETTING.getKey(), true)); + Client master2 = startNode(Settings.builder().put("gateway.recover_after_master_nodes", 2).put(masterOnlyNode())); assertThat(waitForNoBlocksOnNode(BLOCK_WAIT_TIMEOUT, master1).isEmpty(), equalTo(true)); assertThat(waitForNoBlocksOnNode(BLOCK_WAIT_TIMEOUT, master2).isEmpty(), equalTo(true)); assertThat(waitForNoBlocksOnNode(BLOCK_WAIT_TIMEOUT, data1).isEmpty(), equalTo(true)); @@ -130,19 +122,13 @@ public void testRecoverAfterMasterNodes() throws Exception { public void testRecoverAfterDataNodes() throws Exception { internalCluster().setBootstrapMasterNodeIndex(0); logger.info("--> start master_node (1)"); - Client master1 = startNode(Settings.builder() - .put("gateway.recover_after_data_nodes", 2) - .put(Node.NODE_DATA_SETTING.getKey(), false) - .put(Node.NODE_MASTER_SETTING.getKey(), true)); + Client master1 = startNode(Settings.builder().put("gateway.recover_after_data_nodes", 2).put(masterOnlyNode())); assertThat(master1.admin().cluster().prepareState().setLocal(true).execute().actionGet() .getState().blocks().global(ClusterBlockLevel.METADATA_WRITE), hasItem(GatewayService.STATE_NOT_RECOVERED_BLOCK)); logger.info("--> start data_node (1)"); - Client data1 = startNode(Settings.builder() - .put("gateway.recover_after_data_nodes", 2) - .put(Node.NODE_DATA_SETTING.getKey(), true) - .put(Node.NODE_MASTER_SETTING.getKey(), false)); + Client data1 = startNode(Settings.builder().put("gateway.recover_after_data_nodes", 2).put(dataOnlyNode())); assertThat(master1.admin().cluster().prepareState().setLocal(true).execute().actionGet() .getState().blocks().global(ClusterBlockLevel.METADATA_WRITE), hasItem(GatewayService.STATE_NOT_RECOVERED_BLOCK)); @@ -151,10 +137,7 @@ public void testRecoverAfterDataNodes() throws Exception { hasItem(GatewayService.STATE_NOT_RECOVERED_BLOCK)); logger.info("--> start master_node (2)"); - Client master2 = startNode(Settings.builder() - .put("gateway.recover_after_data_nodes", 2) - .put(Node.NODE_DATA_SETTING.getKey(), false) - .put(Node.NODE_MASTER_SETTING.getKey(), true)); + Client master2 = startNode(Settings.builder().put("gateway.recover_after_data_nodes", 2).put(masterOnlyNode())); assertThat(master2.admin().cluster().prepareState().setLocal(true).execute().actionGet() .getState().blocks().global(ClusterBlockLevel.METADATA_WRITE), hasItem(GatewayService.STATE_NOT_RECOVERED_BLOCK)); @@ -166,10 +149,7 @@ public void testRecoverAfterDataNodes() throws Exception { hasItem(GatewayService.STATE_NOT_RECOVERED_BLOCK)); logger.info("--> start data_node (2)"); - Client data2 = startNode(Settings.builder() - .put("gateway.recover_after_data_nodes", 2) - .put(Node.NODE_DATA_SETTING.getKey(), true) - .put(Node.NODE_MASTER_SETTING.getKey(), false)); + Client data2 = startNode(Settings.builder().put("gateway.recover_after_data_nodes", 2).put(dataOnlyNode())); assertThat(waitForNoBlocksOnNode(BLOCK_WAIT_TIMEOUT, master1).isEmpty(), equalTo(true)); assertThat(waitForNoBlocksOnNode(BLOCK_WAIT_TIMEOUT, master2).isEmpty(), equalTo(true)); assertThat(waitForNoBlocksOnNode(BLOCK_WAIT_TIMEOUT, data1).isEmpty(), equalTo(true)); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/index/store/CorruptedFileIT.java b/server/src/internalClusterTest/java/org/elasticsearch/index/store/CorruptedFileIT.java index 226698680e28f..dff307c1bed87 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/index/store/CorruptedFileIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/index/store/CorruptedFileIT.java @@ -65,7 +65,6 @@ import org.elasticsearch.indices.recovery.PeerRecoveryTargetService; import org.elasticsearch.indices.recovery.RecoveryFileChunkRequest; import org.elasticsearch.monitor.fs.FsInfo; -import org.elasticsearch.node.Node; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.snapshots.SnapshotState; import org.elasticsearch.test.CorruptionUtils; @@ -389,9 +388,7 @@ public void testCorruptionOnNetworkLayer() throws ExecutionException, Interrupte int numDocs = scaledRandomIntBetween(100, 1000); internalCluster().ensureAtLeastNumDataNodes(2); if (cluster().numDataNodes() < 3) { - internalCluster().startNode(Settings.builder() - .put(Node.NODE_DATA_SETTING.getKey(), true) - .put(Node.NODE_MASTER_SETTING.getKey(), false)); + internalCluster().startDataOnlyNode(); } NodesStatsResponse nodeStats = client().admin().cluster().prepareNodesStats().get(); List dataNodeStats = new ArrayList<>(); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/mapping/DedicatedMasterGetFieldMappingIT.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/mapping/DedicatedMasterGetFieldMappingIT.java index f8fe05bc97b8a..280aa5be8bf52 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/mapping/DedicatedMasterGetFieldMappingIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/mapping/DedicatedMasterGetFieldMappingIT.java @@ -19,8 +19,6 @@ package org.elasticsearch.indices.mapping; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.node.Node; import org.junit.Before; import static org.elasticsearch.test.ESIntegTestCase.ClusterScope; @@ -31,10 +29,8 @@ public class DedicatedMasterGetFieldMappingIT extends SimpleGetFieldMappingsIT { @Before public void before1() throws Exception { - Settings settings = Settings.builder() - .put(Node.NODE_DATA_SETTING.getKey(), false) - .build(); - internalCluster().startNodes(settings, Settings.EMPTY); + internalCluster().startMasterOnlyNode(); + internalCluster().startNode(); } } diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/store/IndicesStoreIntegrationIT.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/store/IndicesStoreIntegrationIT.java index a019bca76e859..4a3604e2a10fe 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/store/IndicesStoreIntegrationIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/store/IndicesStoreIntegrationIT.java @@ -45,7 +45,6 @@ import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.indices.recovery.PeerRecoveryTargetService; -import org.elasticsearch.node.Node; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; @@ -67,6 +66,8 @@ import java.util.concurrent.TimeUnit; import static java.lang.Thread.sleep; +import static org.elasticsearch.test.NodeRoles.nonDataNode; +import static org.elasticsearch.test.NodeRoles.nonMasterNode; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; @@ -94,9 +95,9 @@ protected void ensureClusterStateConsistency() throws IOException { } public void testIndexCleanup() throws Exception { - internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false)); - final String node_1 = internalCluster().startNode(Settings.builder().put(Node.NODE_MASTER_SETTING.getKey(), false)); - final String node_2 = internalCluster().startNode(Settings.builder().put(Node.NODE_MASTER_SETTING.getKey(), false)); + internalCluster().startNode(nonDataNode()); + final String node_1 = internalCluster().startNode(nonMasterNode()); + final String node_2 = internalCluster().startNode(nonMasterNode()); logger.info("--> creating index [test] with one shard and on replica"); assertAcked(prepareCreate("test").setSettings( Settings.builder().put(indexSettings()) @@ -114,7 +115,7 @@ public void testIndexCleanup() throws Exception { assertThat(Files.exists(indexDirectory(node_2, index)), equalTo(true)); logger.info("--> starting node server3"); - final String node_3 = internalCluster().startNode(Settings.builder().put(Node.NODE_MASTER_SETTING.getKey(), false)); + final String node_3 = internalCluster().startNode(nonMasterNode()); logger.info("--> running cluster_health"); ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth() .setWaitForNodes("4") diff --git a/server/src/internalClusterTest/java/org/elasticsearch/ingest/IngestClientIT.java b/server/src/internalClusterTest/java/org/elasticsearch/ingest/IngestClientIT.java index 9436dc8ecf538..2a7eab5b5d67e 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/ingest/IngestClientIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/ingest/IngestClientIT.java @@ -50,6 +50,7 @@ import java.util.Map; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.elasticsearch.test.NodeRoles.nonIngestNode; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.notNullValue; @@ -62,7 +63,7 @@ public class IngestClientIT extends ESIntegTestCase { @Override protected Settings nodeSettings(int nodeOrdinal) { if (nodeOrdinal % 2 == 0) { - return Settings.builder().put("node.ingest", false).put(super.nodeSettings(nodeOrdinal)).build(); + return Settings.builder().put(nonIngestNode()).put(super.nodeSettings(nodeOrdinal)).build(); } return super.nodeSettings(nodeOrdinal); } diff --git a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java index f4791283e4d44..49b89c803f66a 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java @@ -115,6 +115,7 @@ import java.util.function.Consumer; import static org.elasticsearch.index.seqno.RetentionLeaseActions.RETAIN_ALL; +import static org.elasticsearch.test.NodeRoles.nonMasterNode; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFutureThrows; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; @@ -734,7 +735,7 @@ public void testRegistrationFailure() { internalCluster().startNode(); logger.info("--> start second node"); // Make sure the first node is elected as master - internalCluster().startNode(Settings.builder().put(Node.NODE_MASTER_SETTING.getKey(), false)); + internalCluster().startNode(nonMasterNode()); // Register mock repositories for (int i = 0; i < 5; i++) { client().admin().cluster().preparePutRepository("test-repo" + i) diff --git a/server/src/main/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapMasterCommand.java b/server/src/main/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapMasterCommand.java index a43dd923975b5..7484270b6b8a8 100644 --- a/server/src/main/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapMasterCommand.java +++ b/server/src/main/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapMasterCommand.java @@ -25,6 +25,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.collect.Tuple; @@ -32,7 +33,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.gateway.PersistedClusterStateService; -import org.elasticsearch.node.Node; import java.io.IOException; import java.nio.file.Path; @@ -72,7 +72,7 @@ public class UnsafeBootstrapMasterCommand extends ElasticsearchNodeCommand { protected boolean validateBeforeLock(Terminal terminal, Environment env) { Settings settings = env.settings(); terminal.println(Terminal.Verbosity.VERBOSE, "Checking node.master setting"); - Boolean master = Node.NODE_MASTER_SETTING.get(settings); + Boolean master = DiscoveryNode.isMasterNode(settings); if (master == false) { throw new ElasticsearchException(NOT_MASTER_NODE_MSG); } diff --git a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java index dcf911618d7d7..44b78dad04e82 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -35,12 +35,16 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.elasticsearch.node.NodeRoleSettings.NODE_ROLES_SETTING; /** @@ -50,12 +54,35 @@ public class DiscoveryNode implements Writeable, ToXContentFragment { static final String COORDINATING_ONLY = "coordinating_only"; - public static boolean isMasterNode(Settings settings) { - return Node.NODE_MASTER_SETTING.get(settings); + public static boolean hasRole(final Settings settings, final DiscoveryNodeRole role) { + /* + * This method can be called before the o.e.n.NodeRoleSettings.NODE_ROLES_SETTING is initialized. We do not want to trigger + * initialization prematurely because that will bake the default roles before plugins have had a chance to register them. Therefore, + * to avoid initializing this setting prematurely, we avoid using the actual node roles setting instance here. + */ + if (settings.hasValue("node.roles")) { + return settings.getAsList("node.roles").contains(role.roleName()); + } else if (role.legacySetting() != null && settings.hasValue(role.legacySetting().getKey())) { + return role.legacySetting().get(settings); + } else { + return role.isEnabledByDefault(settings); + } + } + + public static boolean isMasterNode(final Settings settings) { + return hasRole(settings, DiscoveryNodeRole.MASTER_ROLE); + } + + public static boolean isDataNode(final Settings settings) { + return hasRole(settings, DiscoveryNodeRole.DATA_ROLE); + } + + public static boolean isIngestNode(final Settings settings) { + return hasRole(settings, DiscoveryNodeRole.INGEST_ROLE); } - public static boolean isDataNode(Settings settings) { - return Node.NODE_DATA_SETTING.get(settings); + public static boolean isRemoteClusterClient(final Settings settings) { + return hasRole(settings, DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE); } private final String nodeName; @@ -166,7 +193,7 @@ public DiscoveryNode(String nodeName, String nodeId, String ephemeralId, String //verify that no node roles are being provided as attributes Predicate> predicate = (attrs) -> { boolean success = true; - for (final DiscoveryNodeRole role : DiscoveryNode.roleNameToPossibleRoles.values()) { + for (final DiscoveryNodeRole role : DiscoveryNode.roleMap.values()) { success &= attrs.containsKey(role.roleName()) == false; assert success : role.roleName(); } @@ -185,7 +212,29 @@ public static DiscoveryNode createLocal(Settings settings, TransportAddress publ /** extract node roles from the given settings */ public static Set getRolesFromSettings(final Settings settings) { - return roleNameToPossibleRoles.values().stream().filter(s -> s.roleSetting().get(settings)).collect(Collectors.toUnmodifiableSet()); + if (NODE_ROLES_SETTING.exists(settings)) { + validateLegacySettings(settings, roleMap); + return Set.copyOf(NODE_ROLES_SETTING.get(settings)); + } else { + return roleMap.values() + .stream() + .filter(s -> s.legacySetting() != null && s.legacySetting().get(settings)) + .collect(Collectors.toUnmodifiableSet()); + } + } + + private static void validateLegacySettings(final Settings settings, final Map roleMap) { + for (final DiscoveryNodeRole role : roleMap.values()) { + if (role.legacySetting() != null && role.legacySetting().exists(settings)) { + final String message = String.format( + Locale.ROOT, + "can not explicitly configure node roles and use legacy role setting [%s]=[%s]", + role.legacySetting().getKey(), + role.legacySetting().get(settings) + ); + throw new IllegalArgumentException(message); + } + } } /** @@ -210,7 +259,7 @@ public DiscoveryNode(StreamInput in) throws IOException { for (int i = 0; i < rolesSize; i++) { final String roleName = in.readString(); final String roleNameAbbreviation = in.readString(); - final DiscoveryNodeRole role = roleNameToPossibleRoles.get(roleName); + final DiscoveryNodeRole role = roleMap.get(roleName); if (role == null) { roles.add(new DiscoveryNodeRole.UnknownRole(roleName, roleNameAbbreviation)); } else { @@ -397,21 +446,37 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws return builder; } - private static Map roleNameToPossibleRoles; + private static Map rolesToMap(final Stream roles) { + return roles.collect(Collectors.toUnmodifiableMap(DiscoveryNodeRole::roleName, Function.identity())); + } + + private static Map roleMap = rolesToMap(DiscoveryNodeRole.BUILT_IN_ROLES.stream()); + + public static DiscoveryNodeRole getRoleFromRoleName(final String roleName) { + if (roleMap.containsKey(roleName) == false) { + throw new IllegalArgumentException("unknown role [" + roleName + "]"); + } + return roleMap.get(roleName); + } + + public static Set getPossibleRoles() { + return Set.copyOf(roleMap.values()); + } - public static void setPossibleRoles(final Set possibleRoles) { + public static void setAdditionalRoles(final Set additionalRoles) { + assert additionalRoles.stream().allMatch(r -> r.legacySetting() == null || r.legacySetting().isDeprecated()) : additionalRoles; final Map roleNameToPossibleRoles = - possibleRoles.stream().collect(Collectors.toUnmodifiableMap(DiscoveryNodeRole::roleName, Function.identity())); + rolesToMap(Stream.concat(DiscoveryNodeRole.BUILT_IN_ROLES.stream(), additionalRoles.stream())); // collect the abbreviation names into a map to ensure that there are not any duplicate abbreviations final Map roleNameAbbreviationToPossibleRoles = roleNameToPossibleRoles.values() .stream() .collect(Collectors.toUnmodifiableMap(DiscoveryNodeRole::roleNameAbbreviation, Function.identity())); assert roleNameToPossibleRoles.size() == roleNameAbbreviationToPossibleRoles.size() : "roles by name [" + roleNameToPossibleRoles + "], roles by name abbreviation [" + roleNameAbbreviationToPossibleRoles + "]"; - DiscoveryNode.roleNameToPossibleRoles = roleNameToPossibleRoles; + roleMap = roleNameToPossibleRoles; } public static Set getPossibleRoleNames() { - return roleNameToPossibleRoles.keySet(); + return roleMap.keySet(); } } diff --git a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java index e418df6eb8b91..ce4f0b2c76769 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java @@ -20,8 +20,9 @@ package org.elasticsearch.cluster.node; import org.elasticsearch.common.settings.Setting; +import org.elasticsearch.common.settings.Setting.Property; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.set.Sets; -import org.elasticsearch.node.Node; import java.util.Objects; import java.util.Set; @@ -57,6 +58,10 @@ public final String roleNameAbbreviation() { private final boolean isKnownRole; + public boolean isEnabledByDefault(final Settings settings) { + return legacySetting() != null && legacySetting().get(settings); + } + protected DiscoveryNodeRole(final String roleName, final String roleNameAbbreviation) { this(true, roleName, roleNameAbbreviation); } @@ -67,7 +72,7 @@ private DiscoveryNodeRole(final boolean isKnownRole, final String roleName, fina this.roleNameAbbreviation = Objects.requireNonNull(roleNameAbbreviation); } - protected abstract Setting roleSetting(); + public abstract Setting legacySetting(); @Override public final boolean equals(Object o) { @@ -104,8 +109,9 @@ public final String toString() { public static final DiscoveryNodeRole DATA_ROLE = new DiscoveryNodeRole("data", "d") { @Override - protected Setting roleSetting() { - return Node.NODE_DATA_SETTING; + public Setting legacySetting() { + // copy the setting here so we can mark it private in org.elasticsearch.node.Node + return Setting.boolSetting("node.data", true, Property.Deprecated, Property.NodeScope); } }; @@ -116,8 +122,9 @@ protected Setting roleSetting() { public static final DiscoveryNodeRole INGEST_ROLE = new DiscoveryNodeRole("ingest", "i") { @Override - protected Setting roleSetting() { - return Node.NODE_INGEST_SETTING; + public Setting legacySetting() { + // copy the setting here so we can mark it private in org.elasticsearch.node.Node + return Setting.boolSetting("node.ingest", true, Property.Deprecated, Property.NodeScope); } }; @@ -128,8 +135,9 @@ protected Setting roleSetting() { public static final DiscoveryNodeRole MASTER_ROLE = new DiscoveryNodeRole("master", "m") { @Override - protected Setting roleSetting() { - return Node.NODE_MASTER_SETTING; + public Setting legacySetting() { + // copy the setting here so we can mark it private in org.elasticsearch.node.Node + return Setting.boolSetting("node.master", true, Property.Deprecated, Property.NodeScope); } }; @@ -137,8 +145,9 @@ protected Setting roleSetting() { public static final DiscoveryNodeRole REMOTE_CLUSTER_CLIENT_ROLE = new DiscoveryNodeRole("remote_cluster_client", "r") { @Override - protected Setting roleSetting() { - return Node.NODE_REMOTE_CLUSTER_CLIENT; + public Setting legacySetting() { + // copy the setting here so we can mark it private in org.elasticsearch.node.Node + return Setting.boolSetting("node.remote_cluster_client", true, Property.Deprecated, Property.NodeScope); } }; @@ -166,7 +175,7 @@ static class UnknownRole extends DiscoveryNodeRole { } @Override - protected Setting roleSetting() { + public Setting legacySetting() { // since this setting is not registered, it will always return false when testing if the local node has the role assert false; return Setting.boolSetting("node. " + roleName(), false, Setting.Property.NodeScope); 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 3dacd94afa64e..74a80076c98c8 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java @@ -96,6 +96,7 @@ import org.elasticsearch.monitor.os.OsService; import org.elasticsearch.monitor.process.ProcessService; import org.elasticsearch.node.Node; +import org.elasticsearch.node.NodeRoleSettings; import org.elasticsearch.persistent.PersistentTasksClusterService; import org.elasticsearch.persistent.decider.EnableAssignmentDecider; import org.elasticsearch.plugins.PluginsService; @@ -409,11 +410,8 @@ public void apply(Settings value, Settings current, Settings previous) { SearchService.MAX_OPEN_SCROLL_CONTEXT, Node.WRITE_PORTS_FILE_SETTING, Node.NODE_NAME_SETTING, - Node.NODE_DATA_SETTING, - Node.NODE_MASTER_SETTING, - Node.NODE_INGEST_SETTING, - Node.NODE_REMOTE_CLUSTER_CLIENT, Node.NODE_ATTRIBUTES, + NodeRoleSettings.NODE_ROLES_SETTING, AutoCreateIndex.AUTO_CREATE_INDEX_SETTING, BaseRestHandler.MULTI_ALLOW_EXPLICIT_INDEX, ClusterName.CLUSTER_NAME_SETTING, diff --git a/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java b/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java index c3cf5a5201c6d..e4da0885b4618 100644 --- a/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java +++ b/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java @@ -35,6 +35,7 @@ import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.CheckedFunction; import org.elasticsearch.common.CheckedRunnable; import org.elasticsearch.common.Randomness; @@ -60,7 +61,6 @@ import org.elasticsearch.monitor.fs.FsInfo; import org.elasticsearch.monitor.fs.FsProbe; import org.elasticsearch.monitor.jvm.JvmInfo; -import org.elasticsearch.node.Node; import java.io.Closeable; import java.io.IOException; @@ -1159,26 +1159,27 @@ private static void ensureAtomicMoveSupported(final NodePath[] nodePaths) throws private void ensureNoShardData(final NodePath[] nodePaths) throws IOException { List shardDataPaths = collectShardDataPaths(nodePaths); if (shardDataPaths.isEmpty() == false) { - throw new IllegalStateException("Node is started with " - + Node.NODE_DATA_SETTING.getKey() - + "=false, but has shard data: " - + shardDataPaths - + ". Use 'elasticsearch-node repurpose' tool to clean up" + final String message = String.format( + Locale.ROOT, + "node does not have the %s role but has shard data: %s. Use 'elasticsearch-node repurpose' tool to clean up", + DiscoveryNodeRole.DATA_ROLE.roleName(), + shardDataPaths ); + throw new IllegalStateException(message); } } private void ensureNoIndexMetadata(final NodePath[] nodePaths) throws IOException { List indexMetadataPaths = collectIndexMetadataPaths(nodePaths); if (indexMetadataPaths.isEmpty() == false) { - throw new IllegalStateException("Node is started with " - + Node.NODE_DATA_SETTING.getKey() - + "=false and " - + Node.NODE_MASTER_SETTING.getKey() - + "=false, but has index metadata: " - + indexMetadataPaths - + ". Use 'elasticsearch-node repurpose' tool to clean up" + final String message = String.format( + Locale.ROOT, + "node does not have the %s and %s roles but has index metadata: %s. Use 'elasticsearch-node repurpose' tool to clean up", + DiscoveryNodeRole.DATA_ROLE.roleName(), + DiscoveryNodeRole.MASTER_ROLE.roleName(), + indexMetadataPaths ); + throw new IllegalStateException(message); } } diff --git a/server/src/main/java/org/elasticsearch/node/Node.java b/server/src/main/java/org/elasticsearch/node/Node.java index 9d02ecc259902..6178975fef901 100644 --- a/server/src/main/java/org/elasticsearch/node/Node.java +++ b/server/src/main/java/org/elasticsearch/node/Node.java @@ -201,13 +201,14 @@ public class Node implements Closeable { public static final Setting WRITE_PORTS_FILE_SETTING = Setting.boolSetting("node.portsfile", false, Property.NodeScope); - public static final Setting NODE_DATA_SETTING = Setting.boolSetting("node.data", true, Property.NodeScope); - public static final Setting NODE_MASTER_SETTING = - Setting.boolSetting("node.master", true, Property.NodeScope); - public static final Setting NODE_INGEST_SETTING = - Setting.boolSetting("node.ingest", true, Property.NodeScope); - public static final Setting NODE_REMOTE_CLUSTER_CLIENT = - Setting.boolSetting("node.remote_cluster_client", true, Property.NodeScope); + private static final Setting NODE_DATA_SETTING = + Setting.boolSetting("node.data", true, Property.Deprecated, Property.NodeScope); + private static final Setting NODE_MASTER_SETTING = + Setting.boolSetting("node.master", true, Property.Deprecated, Property.NodeScope); + private static final Setting NODE_INGEST_SETTING = + Setting.boolSetting("node.ingest", true, Property.Deprecated, Property.NodeScope); + private static final Setting NODE_REMOTE_CLUSTER_CLIENT = + Setting.boolSetting("node.remote_cluster_client", true, Property.Deprecated, Property.NodeScope); public static final Setting NODE_NAME_SETTING = Setting.simpleString("node.name", Property.NodeScope); public static final Setting.AffixSetting NODE_ATTRIBUTES = Setting.prefixKeySetting("node.attr.", (key) -> @@ -313,14 +314,12 @@ protected Node(final Environment initialEnvironment, initialEnvironment.pluginsFile(), classpathPlugins); final Settings settings = pluginsService.updatedSettings(); - final Set possibleRoles = Stream.concat( - DiscoveryNodeRole.BUILT_IN_ROLES.stream(), - pluginsService.filterPlugins(Plugin.class) - .stream() - .map(Plugin::getRoles) - .flatMap(Set::stream)) - .collect(Collectors.toSet()); - DiscoveryNode.setPossibleRoles(possibleRoles); + final Set additionalRoles = pluginsService.filterPlugins(Plugin.class) + .stream() + .map(Plugin::getRoles) + .flatMap(Set::stream) + .collect(Collectors.toSet()); + DiscoveryNode.setAdditionalRoles(additionalRoles); /* * Create the environment based on the finalized view of the settings. This is to ensure that components get the same setting @@ -344,7 +343,13 @@ protected Node(final Environment initialEnvironment, HeaderWarning.setThreadContext(threadPool.getThreadContext()); resourcesToClose.add(() -> HeaderWarning.removeThreadContext(threadPool.getThreadContext())); - final List> additionalSettings = new ArrayList<>(pluginsService.getPluginSettings()); + final List> additionalSettings = new ArrayList<>(); + // register the node.data, node.ingest, node.master, node.remote_cluster_client settings here so we can mark them private + additionalSettings.add(NODE_DATA_SETTING); + additionalSettings.add(NODE_INGEST_SETTING); + additionalSettings.add(NODE_MASTER_SETTING); + additionalSettings.add(NODE_REMOTE_CLUSTER_CLIENT); + additionalSettings.addAll(pluginsService.getPluginSettings()); final List additionalSettingsFilter = new ArrayList<>(pluginsService.getPluginSettingsFilter()); for (final ExecutorBuilder builder : threadPool.builders()) { additionalSettings.addAll(builder.getRegisteredSettings()); diff --git a/server/src/main/java/org/elasticsearch/node/NodeRoleSettings.java b/server/src/main/java/org/elasticsearch/node/NodeRoleSettings.java new file mode 100644 index 0000000000000..f0af84772a64a --- /dev/null +++ b/server/src/main/java/org/elasticsearch/node/NodeRoleSettings.java @@ -0,0 +1,45 @@ +/* + * 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.node; + +import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodeRole; +import org.elasticsearch.common.settings.Setting; +import org.elasticsearch.common.settings.Setting.Property; + +import java.util.List; +import java.util.stream.Collectors; + +public class NodeRoleSettings { + + public static final Setting> NODE_ROLES_SETTING = Setting.listSetting( + "node.roles", + null, + DiscoveryNode::getRoleFromRoleName, + settings -> DiscoveryNode.getPossibleRoles() + .stream() + .filter(role -> role.isEnabledByDefault(settings)) + .map(DiscoveryNodeRole::roleName) + .collect(Collectors.toList()), + roles -> {}, + Property.NodeScope + ); + +} diff --git a/server/src/main/java/org/elasticsearch/transport/RemoteClusterService.java b/server/src/main/java/org/elasticsearch/transport/RemoteClusterService.java index 745496b98461d..7e09b5e7ceb3e 100644 --- a/server/src/main/java/org/elasticsearch/transport/RemoteClusterService.java +++ b/server/src/main/java/org/elasticsearch/transport/RemoteClusterService.java @@ -37,7 +37,6 @@ import org.elasticsearch.common.util.concurrent.ConcurrentCollections; import org.elasticsearch.common.util.concurrent.CountDown; import org.elasticsearch.core.internal.io.IOUtils; -import org.elasticsearch.node.Node; import org.elasticsearch.threadpool.ThreadPool; import java.io.Closeable; @@ -118,7 +117,7 @@ public boolean isEnabled() { RemoteClusterService(Settings settings, TransportService transportService) { super(settings); - this.enabled = Node.NODE_REMOTE_CLUSTER_CLIENT.get(settings); + this.enabled = DiscoveryNode.isRemoteClusterClient(settings); this.transportService = transportService; } diff --git a/server/src/main/java/org/elasticsearch/transport/TransportService.java b/server/src/main/java/org/elasticsearch/transport/TransportService.java index 7f42e175db774..797889680ee2b 100644 --- a/server/src/main/java/org/elasticsearch/transport/TransportService.java +++ b/server/src/main/java/org/elasticsearch/transport/TransportService.java @@ -45,7 +45,6 @@ import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.core.internal.io.IOUtils; -import org.elasticsearch.node.Node; import org.elasticsearch.node.NodeClosedException; import org.elasticsearch.node.ReportingService; import org.elasticsearch.tasks.Task; @@ -165,7 +164,7 @@ public TransportService(Settings settings, Transport transport, ThreadPool threa taskManager = createTaskManager(settings, threadPool, taskHeaders); this.interceptor = transportInterceptor; this.asyncSender = interceptor.interceptSender(this::sendRequestInternal); - this.remoteClusterClient = Node.NODE_REMOTE_CLUSTER_CLIENT.get(settings); + this.remoteClusterClient = DiscoveryNode.isRemoteClusterClient(settings); remoteClusterService = new RemoteClusterService(settings, this); responseHandlers = transport.getResponseHandlers(); if (clusterSettings != null) { 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 6a7562ab8038a..25d480498f1d2 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/ClusterBootstrapServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/ClusterBootstrapServiceTests.java @@ -24,7 +24,6 @@ import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.DiscoveryModule; -import org.elasticsearch.node.Node; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.transport.MockTransport; import org.elasticsearch.transport.TransportRequest; @@ -52,6 +51,7 @@ import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING; import static org.elasticsearch.discovery.SettingsBasedSeedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING; import static org.elasticsearch.node.Node.NODE_NAME_SETTING; +import static org.elasticsearch.test.NodeRoles.nonMasterNode; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; @@ -522,7 +522,7 @@ public void testFailBootstrapNonMasterEligibleNodeWithSingleNodeDiscovery() { final Settings.Builder settings = Settings.builder() .put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), DiscoveryModule.SINGLE_NODE_DISCOVERY_TYPE) .put(NODE_NAME_SETTING.getKey(), localNode.getName()) - .put(Node.NODE_MASTER_SETTING.getKey(), false); + .put(nonMasterNode()); assertThat(expectThrows(IllegalArgumentException.class, () -> new ClusterBootstrapService(settings.build(), transportService, () -> emptyList(), () -> false, vc -> fail())).getMessage(), 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 673d087c9507a..84e7d7cc6ff4c 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java @@ -44,7 +44,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.gateway.GatewayService; -import org.elasticsearch.node.Node; import org.elasticsearch.test.MockLogAppender; import java.io.IOException; @@ -74,6 +73,7 @@ import static org.elasticsearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_WRITES; import static org.elasticsearch.cluster.coordination.Reconfigurator.CLUSTER_AUTO_SHRINK_VOTING_CONFIGURATION; import static org.elasticsearch.discovery.PeerFinder.DISCOVERY_FIND_PEERS_INTERVAL_SETTING; +import static org.elasticsearch.test.NodeRoles.nonMasterNode; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; @@ -1395,8 +1395,9 @@ public void testReconfiguresToExcludeMasterIneligibleNodesInVotingConfig() { logger.info("--> restarting [{}] as a master-ineligible node", chosenNode); chosenNode.close(); - cluster.clusterNodes.replaceAll(cn -> cn == chosenNode ? cn.restartedNode(Function.identity(), Function.identity(), - Settings.builder().put(Node.NODE_MASTER_SETTING.getKey(), false).build()) : cn); + cluster.clusterNodes.replaceAll( + cn -> cn == chosenNode ? cn.restartedNode(Function.identity(), Function.identity(), nonMasterNode()) : cn + ); cluster.stabilise(); if (chosenNodeIsLeader == false) { diff --git a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleSettingTests.java b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleSettingTests.java new file mode 100644 index 0000000000000..7eb1319e99451 --- /dev/null +++ b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleSettingTests.java @@ -0,0 +1,82 @@ +/* + * 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.node; + +import org.elasticsearch.common.settings.Setting; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.test.ESTestCase; + +import java.util.Set; +import java.util.function.Predicate; + +import static org.elasticsearch.test.NodeRoles.onlyRole; +import static org.elasticsearch.test.NodeRoles.removeRoles; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.startsWith; + +public class DiscoveryNodeRoleSettingTests extends ESTestCase { + + public void testIsDataNode() { + runRoleTest(DiscoveryNode::isDataNode, DiscoveryNodeRole.DATA_ROLE); + } + + public void testIsIngestNode() { + runRoleTest(DiscoveryNode::isIngestNode, DiscoveryNodeRole.INGEST_ROLE); + } + + public void testIsMasterNode() { + runRoleTest(DiscoveryNode::isMasterNode, DiscoveryNodeRole.MASTER_ROLE); + } + + public void testIsRemoteClusterClient() { + runRoleTest(DiscoveryNode::isRemoteClusterClient, DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE); + } + + private void runRoleTest(final Predicate predicate, final DiscoveryNodeRole role) { + final Settings legacyTrue = Settings.builder().put(role.legacySetting().getKey(), true).build(); + + assertTrue(predicate.test(legacyTrue)); + assertSettingDeprecationsAndWarnings(new Setting[]{role.legacySetting()}); + + assertThat(DiscoveryNode.getRolesFromSettings(legacyTrue), hasItem(role)); + assertSettingDeprecationsAndWarnings(new Setting[]{role.legacySetting()}); + + final Settings legacyFalse = Settings.builder().put(role.legacySetting().getKey(), false).build(); + + assertFalse(predicate.test(legacyFalse)); + assertSettingDeprecationsAndWarnings(new Setting[]{role.legacySetting()}); + + assertThat(DiscoveryNode.getRolesFromSettings(legacyFalse), not(hasItem(role))); + assertSettingDeprecationsAndWarnings(new Setting[]{role.legacySetting()}); + + assertTrue(predicate.test(onlyRole(role))); + assertThat(DiscoveryNode.getRolesFromSettings(onlyRole(role)), hasItem(role)); + + assertFalse(predicate.test(removeRoles(Set.of(role)))); + assertThat(DiscoveryNode.getRolesFromSettings(removeRoles(Set.of(role))), not(hasItem(role))); + + final Settings settings = Settings.builder().put(onlyRole(role)).put(role.legacySetting().getKey(), randomBoolean()).build(); + final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> DiscoveryNode.getRolesFromSettings(settings)); + assertThat(e.getMessage(), startsWith("can not explicitly configure node roles and use legacy role setting")); + assertSettingDeprecationsAndWarnings(new Setting[]{role.legacySetting()}); + } + +} diff --git a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleTests.java b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleTests.java index 7e03a32b7b163..3797e91713e0b 100644 --- a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleTests.java @@ -33,11 +33,11 @@ public class DiscoveryNodeRoleTests extends ESTestCase { public void testDiscoveryNodeSetPossibleRolesRejectsDuplicateRoleNames() { final IllegalStateException e = expectThrows( IllegalStateException.class, - () -> DiscoveryNode.setPossibleRoles(Set.of( + () -> DiscoveryNode.setAdditionalRoles(Set.of( new DiscoveryNodeRole("foo", "f") { @Override - protected Setting roleSetting() { + public Setting legacySetting() { return null; } @@ -45,7 +45,7 @@ protected Setting roleSetting() { new DiscoveryNodeRole("foo", "f") { @Override - protected Setting roleSetting() { + public Setting legacySetting() { return null; } @@ -56,11 +56,11 @@ protected Setting roleSetting() { public void testDiscoveryNodeSetPossibleRolesRejectsDuplicateRoleNameAbbreviations() { final IllegalStateException e = expectThrows( IllegalStateException.class, - () -> DiscoveryNode.setPossibleRoles(Set.of( + () -> DiscoveryNode.setAdditionalRoles(Set.of( new DiscoveryNodeRole("foo_1", "f") { @Override - protected Setting roleSetting() { + public Setting legacySetting() { return null; } @@ -68,7 +68,7 @@ protected Setting roleSetting() { new DiscoveryNodeRole("foo_2", "f") { @Override - protected Setting roleSetting() { + public Setting legacySetting() { return null; } diff --git a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeTests.java b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeTests.java index 099365883dc9e..38168ef5e2ee7 100644 --- a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeTests.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; -import org.elasticsearch.node.Node; import org.elasticsearch.test.ESTestCase; import java.net.InetAddress; @@ -33,8 +32,12 @@ import static java.util.Collections.emptyMap; import static java.util.Collections.emptySet; +import static org.elasticsearch.test.NodeRoles.nonRemoteClusterClientNode; +import static org.elasticsearch.test.NodeRoles.remoteClusterClientNode; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.not; public class DiscoveryNodeTests extends ESTestCase { @@ -90,22 +93,20 @@ public void testDiscoveryNodeIsRemoteClusterClientDefault() { } public void testDiscoveryNodeIsRemoteClusterClientSet() { - runTestDiscoveryNodeIsRemoteClusterClient(Settings.builder().put(Node.NODE_REMOTE_CLUSTER_CLIENT.getKey(), true).build(), true); + runTestDiscoveryNodeIsRemoteClusterClient(remoteClusterClientNode(), true); } public void testDiscoveryNodeIsRemoteClusterClientUnset() { - runTestDiscoveryNodeIsRemoteClusterClient(Settings.builder().put(Node.NODE_REMOTE_CLUSTER_CLIENT.getKey(), false).build(), false); + runTestDiscoveryNodeIsRemoteClusterClient(nonRemoteClusterClientNode(), false); } private void runTestDiscoveryNodeIsRemoteClusterClient(final Settings settings, final boolean expected) { final DiscoveryNode node = DiscoveryNode.createLocal(settings, new TransportAddress(TransportAddress.META_ADDRESS, 9200), "node"); assertThat(node.isRemoteClusterClient(), equalTo(expected)); - final Set expectedRoles = new HashSet<>(DiscoveryNodeRole.BUILT_IN_ROLES); if (expected) { - assertThat(node.getRoles(), equalTo(expectedRoles)); + assertThat(node.getRoles(), hasItem(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE)); } else { - expectedRoles.remove(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE); - assertThat(node.getRoles(), equalTo(expectedRoles)); + assertThat(node.getRoles(), not(hasItem(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE))); } } diff --git a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java index d03c132eda096..14da84d49719a 100644 --- a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java @@ -274,10 +274,12 @@ private static List randomNodes(final int numNodes) { final Set roles = new HashSet<>(randomSubsetOf(DiscoveryNodeRole.BUILT_IN_ROLES)); if (frequently()) { roles.add(new DiscoveryNodeRole("custom_role", "cr") { + @Override - protected Setting roleSetting() { + public Setting legacySetting() { return null; } + }); } final DiscoveryNode node = newNode(idGenerator.getAndIncrement(), attributes, roles); diff --git a/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java b/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java index 890e9b0b7b273..223ad11739b51 100644 --- a/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java +++ b/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java @@ -20,6 +20,7 @@ import org.apache.lucene.index.SegmentInfos; import org.apache.lucene.util.LuceneTestCase; +import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.Settings; @@ -30,9 +31,9 @@ import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.ShardId; -import org.elasticsearch.node.Node; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.IndexSettingsModule; +import org.elasticsearch.test.NodeRoles; import java.io.IOException; import java.nio.file.Files; @@ -47,6 +48,8 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; +import static org.elasticsearch.test.NodeRoles.nonDataNode; +import static org.elasticsearch.test.NodeRoles.nonMasterNode; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.Matchers.arrayWithSize; import static org.hamcrest.Matchers.containsString; @@ -416,11 +419,10 @@ public void testEnsureNoShardDataOrIndexMetadata() throws IOException { Settings settings = buildEnvSettings(Settings.EMPTY); Index index = new Index("test", "testUUID"); - // build settings using same path.data as original but with node.data=false and node.master=false + // build settings using same path.data as original but without data and master roles Settings noDataNoMasterSettings = Settings.builder() .put(settings) - .put(Node.NODE_DATA_SETTING.getKey(), false) - .put(Node.NODE_MASTER_SETTING.getKey(), false) + .put(NodeRoles.removeRoles(settings, Set.of(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.MASTER_ROLE))) .build(); // test that we can create data=false and master=false with no meta information @@ -436,10 +438,8 @@ public void testEnsureNoShardDataOrIndexMetadata() throws IOException { verifyFailsOnMetadata(noDataNoMasterSettings, indexPath); - // build settings using same path.data as original but with node.data=false - Settings noDataSettings = Settings.builder() - .put(settings) - .put(Node.NODE_DATA_SETTING.getKey(), false).build(); + // build settings using same path.data as original but without data role + Settings noDataSettings = nonDataNode(settings); String shardDataDirName = Integer.toString(randomInt(10)); @@ -455,11 +455,8 @@ public void testEnsureNoShardDataOrIndexMetadata() throws IOException { // assert that we get the stricter message on meta-data when both conditions fail verifyFailsOnMetadata(noDataNoMasterSettings, indexPath); - // build settings using same path.data as original but with node.master=false - Settings noMasterSettings = Settings.builder() - .put(settings) - .put(Node.NODE_MASTER_SETTING.getKey(), false) - .build(); + // build settings using same path.data as original but without master role + Settings noMasterSettings = nonMasterNode(settings); // test that we can create master=false env regardless of data. newNodeEnvironment(noMasterSettings).close(); @@ -478,30 +475,22 @@ public void testEnsureNoShardDataOrIndexMetadata() throws IOException { private void verifyFailsOnShardData(Settings settings, Path indexPath, String shardDataDirName) { IllegalStateException ex = expectThrows(IllegalStateException.class, - "Must fail creating NodeEnvironment on a data path that has shard data if node.data=false", + "Must fail creating NodeEnvironment on a data path that has shard data if node does not have data role", () -> newNodeEnvironment(settings).close()); assertThat(ex.getMessage(), containsString(indexPath.resolve(shardDataDirName).toAbsolutePath().toString())); - assertThat(ex.getMessage(), - startsWith("Node is started with " - + Node.NODE_DATA_SETTING.getKey() - + "=false, but has shard data")); + assertThat(ex.getMessage(), startsWith("node does not have the data role but has shard data")); } private void verifyFailsOnMetadata(Settings settings, Path indexPath) { IllegalStateException ex = expectThrows(IllegalStateException.class, - "Must fail creating NodeEnvironment on a data path that has index meta-data if node.data=false and node.master=false", + "Must fail creating NodeEnvironment on a data path that has index metadata if node does not have data and master roles", () -> newNodeEnvironment(settings).close()); assertThat(ex.getMessage(), containsString(indexPath.resolve(MetadataStateFormat.STATE_DIR_NAME).toAbsolutePath().toString())); - assertThat(ex.getMessage(), - startsWith("Node is started with " - + Node.NODE_DATA_SETTING.getKey() - + "=false and " - + Node.NODE_MASTER_SETTING.getKey() - + "=false, but has index metadata")); + assertThat(ex.getMessage(), startsWith("node does not have the data and master roles but has index metadata")); } /** Converts an array of Strings to an array of Paths, adding an additional child if specified */ diff --git a/server/src/test/java/org/elasticsearch/env/NodeRepurposeCommandTests.java b/server/src/test/java/org/elasticsearch/env/NodeRepurposeCommandTests.java index 5e60b7b320b13..c0281a132e4ef 100644 --- a/server/src/test/java/org/elasticsearch/env/NodeRepurposeCommandTests.java +++ b/server/src/test/java/org/elasticsearch/env/NodeRepurposeCommandTests.java @@ -28,6 +28,7 @@ import org.elasticsearch.cluster.coordination.ElasticsearchNodeCommand; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.CheckedConsumer; import org.elasticsearch.common.CheckedRunnable; import org.elasticsearch.common.settings.ClusterSettings; @@ -35,7 +36,6 @@ import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.gateway.PersistedClusterStateService; import org.elasticsearch.index.Index; -import org.elasticsearch.node.Node; import org.elasticsearch.test.ESTestCase; import org.hamcrest.Matcher; import org.junit.Before; @@ -44,11 +44,16 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; +import java.util.Set; import java.util.stream.Stream; import static org.elasticsearch.env.NodeRepurposeCommand.NO_CLEANUP; import static org.elasticsearch.env.NodeRepurposeCommand.NO_DATA_TO_CLEAN_UP_FOUND; import static org.elasticsearch.env.NodeRepurposeCommand.NO_SHARD_DATA_TO_CLEAN_UP_FOUND; +import static org.elasticsearch.test.NodeRoles.masterNode; +import static org.elasticsearch.test.NodeRoles.nonDataNode; +import static org.elasticsearch.test.NodeRoles.nonMasterNode; +import static org.elasticsearch.test.NodeRoles.removeRoles; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; @@ -76,20 +81,10 @@ public void createNodePaths() throws IOException { writer.writeFullStateAndCommit(1L, ClusterState.EMPTY_STATE); } } - dataNoMasterSettings = Settings.builder() - .put(dataMasterSettings) - .put(Node.NODE_MASTER_SETTING.getKey(), false) - .build(); - noDataNoMasterSettings = Settings.builder() - .put(dataMasterSettings) - .put(Node.NODE_DATA_SETTING.getKey(), false) - .put(Node.NODE_MASTER_SETTING.getKey(), false) - .build(); - noDataMasterSettings = Settings.builder() - .put(dataMasterSettings) - .put(Node.NODE_DATA_SETTING.getKey(), false) - .put(Node.NODE_MASTER_SETTING.getKey(), true) - .build(); + dataNoMasterSettings = nonMasterNode(dataMasterSettings); + noDataNoMasterSettings = removeRoles(dataMasterSettings, Set.of(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.MASTER_ROLE)); + + noDataMasterSettings = masterNode(nonDataNode(dataMasterSettings)); } public void testEarlyExitNoCleanup() throws Exception { diff --git a/server/src/test/java/org/elasticsearch/gateway/GatewayMetaStatePersistedStateTests.java b/server/src/test/java/org/elasticsearch/gateway/GatewayMetaStatePersistedStateTests.java index c082c7871d3e4..a85f9309feb82 100644 --- a/server/src/test/java/org/elasticsearch/gateway/GatewayMetaStatePersistedStateTests.java +++ b/server/src/test/java/org/elasticsearch/gateway/GatewayMetaStatePersistedStateTests.java @@ -59,6 +59,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; +import static org.elasticsearch.test.NodeRoles.nonMasterNode; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.not; @@ -334,8 +335,11 @@ public void testDataOnlyNodePersistence() throws Exception { try { DiscoveryNode localNode = new DiscoveryNode("node1", buildNewFakeTransportAddress(), Collections.emptyMap(), Sets.newHashSet(DiscoveryNodeRole.DATA_ROLE), Version.CURRENT); - Settings settings = Settings.builder().put(ClusterName.CLUSTER_NAME_SETTING.getKey(), clusterName.value()).put( - Node.NODE_MASTER_SETTING.getKey(), false).put(Node.NODE_NAME_SETTING.getKey(), "test").build(); + Settings settings = Settings.builder() + .put(ClusterName.CLUSTER_NAME_SETTING.getKey(), clusterName.value()) + .put(nonMasterNode()) + .put(Node.NODE_NAME_SETTING.getKey(), "test") + .build(); final MockGatewayMetaState gateway = new MockGatewayMetaState(localNode); cleanup.add(gateway); final TransportService transportService = mock(TransportService.class); diff --git a/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java b/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java index 22c26aee07a24..436e0c85c9640 100644 --- a/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java +++ b/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java @@ -39,7 +39,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.node.Node; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.gateway.TestGatewayAllocator; import org.hamcrest.Matchers; @@ -48,6 +47,7 @@ import java.util.HashSet; import static org.elasticsearch.gateway.GatewayService.STATE_NOT_RECOVERED_BLOCK; +import static org.elasticsearch.test.NodeRoles.masterNode; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.Matchers.hasItem; @@ -101,9 +101,11 @@ public void testRecoverStateUpdateTask() throws Exception { GatewayService service = createService(Settings.builder()); ClusterStateUpdateTask clusterStateUpdateTask = service.new RecoverStateUpdateTask(); String nodeId = randomAlphaOfLength(10); - DiscoveryNode masterNode = DiscoveryNode.createLocal(settings(Version.CURRENT) - .put(Node.NODE_MASTER_SETTING.getKey(), true).build(), - new TransportAddress(TransportAddress.META_ADDRESS, 9300), nodeId); + DiscoveryNode masterNode = DiscoveryNode.createLocal( + settings(Version.CURRENT).put(masterNode()).build(), + new TransportAddress(TransportAddress.META_ADDRESS, 9300), + nodeId + ); ClusterState stateWithBlock = ClusterState.builder(ClusterName.DEFAULT) .nodes(DiscoveryNodes.builder().localNodeId(nodeId).masterNodeId(nodeId).add(masterNode).build()). blocks(ClusterBlocks.builder().addGlobalBlock(STATE_NOT_RECOVERED_BLOCK).build()).build(); diff --git a/server/src/test/java/org/elasticsearch/indices/IndicesServiceCloseTests.java b/server/src/test/java/org/elasticsearch/indices/IndicesServiceCloseTests.java index b6bebb7a9b80d..dca5b1e819651 100644 --- a/server/src/test/java/org/elasticsearch/indices/IndicesServiceCloseTests.java +++ b/server/src/test/java/org/elasticsearch/indices/IndicesServiceCloseTests.java @@ -55,6 +55,7 @@ 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.discovery.SettingsBasedSeedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING; +import static org.elasticsearch.test.NodeRoles.dataNode; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; public class IndicesServiceCloseTests extends ESTestCase { @@ -70,7 +71,7 @@ private Node startNode() throws NodeValidationException { .put(Node.NODE_NAME_SETTING.getKey(), nodeName) .put(EsExecutors.NODE_PROCESSORS_SETTING.getKey(), 1) // limit the number of threads created .put("transport.type", getTestTransportType()) - .put(Node.NODE_DATA_SETTING.getKey(), true) + .put(dataNode()) .put(NodeEnvironment.NODE_ID_SEED_SETTING.getKey(), random().nextLong()) // default the watermarks low values to prevent tests from failing on nodes without enough disk space .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(), "1b") diff --git a/server/src/test/java/org/elasticsearch/node/NodeTests.java b/server/src/test/java/org/elasticsearch/node/NodeTests.java index c04a8b7fe9a92..d298a5010366e 100644 --- a/server/src/test/java/org/elasticsearch/node/NodeTests.java +++ b/server/src/test/java/org/elasticsearch/node/NodeTests.java @@ -53,6 +53,7 @@ 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.test.NodeRoles.dataNode; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; @@ -155,7 +156,7 @@ private static Settings.Builder baseSettings() { .put(ClusterName.CLUSTER_NAME_SETTING.getKey(), InternalTestCluster.clusterName("single-node-cluster", randomLong())) .put(Environment.PATH_HOME_SETTING.getKey(), tempDir) .put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType()) - .put(Node.NODE_DATA_SETTING.getKey(), true); + .put(dataNode()); } public void testCloseOnOutstandingTask() throws Exception { diff --git a/server/src/test/java/org/elasticsearch/transport/ConnectionProfileTests.java b/server/src/test/java/org/elasticsearch/transport/ConnectionProfileTests.java index e26af6719e85f..383359c31af37 100644 --- a/server/src/test/java/org/elasticsearch/transport/ConnectionProfileTests.java +++ b/server/src/test/java/org/elasticsearch/transport/ConnectionProfileTests.java @@ -18,6 +18,7 @@ */ package org.elasticsearch.transport; +import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.test.ESTestCase; @@ -27,7 +28,11 @@ import java.util.Collections; import java.util.EnumSet; import java.util.List; +import java.util.Set; +import static org.elasticsearch.test.NodeRoles.nonDataNode; +import static org.elasticsearch.test.NodeRoles.nonMasterNode; +import static org.elasticsearch.test.NodeRoles.removeRoles; import static org.hamcrest.Matchers.equalTo; public class ConnectionProfileTests extends ESTestCase { @@ -209,7 +214,7 @@ public void testDefaultConnectionProfile() { assertEquals(TransportSettings.TRANSPORT_COMPRESS.get(Settings.EMPTY), profile.getCompressionEnabled()); assertEquals(TransportSettings.PING_SCHEDULE.get(Settings.EMPTY), profile.getPingInterval()); - profile = ConnectionProfile.buildDefaultConnectionProfile(Settings.builder().put("node.master", false).build()); + profile = ConnectionProfile.buildDefaultConnectionProfile(nonMasterNode()); assertEquals(12, profile.getNumConnections()); assertEquals(1, profile.getNumConnectionsPerType(TransportRequestOptions.Type.PING)); assertEquals(6, profile.getNumConnectionsPerType(TransportRequestOptions.Type.REG)); @@ -217,7 +222,7 @@ public void testDefaultConnectionProfile() { assertEquals(2, profile.getNumConnectionsPerType(TransportRequestOptions.Type.RECOVERY)); assertEquals(3, profile.getNumConnectionsPerType(TransportRequestOptions.Type.BULK)); - profile = ConnectionProfile.buildDefaultConnectionProfile(Settings.builder().put("node.data", false).build()); + profile = ConnectionProfile.buildDefaultConnectionProfile(nonDataNode()); assertEquals(11, profile.getNumConnections()); assertEquals(1, profile.getNumConnectionsPerType(TransportRequestOptions.Type.PING)); assertEquals(6, profile.getNumConnectionsPerType(TransportRequestOptions.Type.REG)); @@ -225,8 +230,9 @@ public void testDefaultConnectionProfile() { assertEquals(0, profile.getNumConnectionsPerType(TransportRequestOptions.Type.RECOVERY)); assertEquals(3, profile.getNumConnectionsPerType(TransportRequestOptions.Type.BULK)); - profile = ConnectionProfile.buildDefaultConnectionProfile(Settings.builder().put("node.data", false) - .put("node.master", false).build()); + profile = ConnectionProfile.buildDefaultConnectionProfile( + removeRoles(Set.of(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.MASTER_ROLE)) + ); assertEquals(10, profile.getNumConnections()); assertEquals(1, profile.getNumConnectionsPerType(TransportRequestOptions.Type.PING)); assertEquals(6, profile.getNumConnectionsPerType(TransportRequestOptions.Type.REG)); diff --git a/server/src/test/java/org/elasticsearch/transport/RemoteClusterClientTests.java b/server/src/test/java/org/elasticsearch/transport/RemoteClusterClientTests.java index 596a3ab70b371..aa442e9cecd2c 100644 --- a/server/src/test/java/org/elasticsearch/transport/RemoteClusterClientTests.java +++ b/server/src/test/java/org/elasticsearch/transport/RemoteClusterClientTests.java @@ -24,8 +24,8 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.node.Node; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.test.transport.MockTransportService; @@ -33,8 +33,11 @@ import org.elasticsearch.threadpool.ThreadPool; import java.util.Collections; +import java.util.Set; import java.util.concurrent.TimeUnit; +import static org.elasticsearch.test.NodeRoles.onlyRole; +import static org.elasticsearch.test.NodeRoles.removeRoles; import static org.elasticsearch.transport.RemoteClusterConnectionTests.startTransport; import static org.hamcrest.Matchers.equalTo; @@ -54,7 +57,7 @@ public void testConnectAndExecuteRequest() throws Exception { DiscoveryNode remoteNode = remoteTransport.getLocalDiscoNode(); Settings localSettings = Settings.builder() - .put(Node.NODE_REMOTE_CLUSTER_CLIENT.getKey(), true) + .put(onlyRole(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE)) .put("cluster.remote.test.seeds", remoteNode.getAddress().getAddress() + ":" + remoteNode.getAddress().getPort()).build(); try (MockTransportService service = MockTransportService.createNewService(localSettings, Version.CURRENT, threadPool, null)) { @@ -86,7 +89,7 @@ public void testEnsureWeReconnect() throws Exception { remoteSettings)) { DiscoveryNode remoteNode = remoteTransport.getLocalDiscoNode(); Settings localSettings = Settings.builder() - .put(Node.NODE_REMOTE_CLUSTER_CLIENT.getKey(), true) + .put(onlyRole(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE)) .put("cluster.remote.test.seeds", remoteNode.getAddress().getAddress() + ":" + remoteNode.getAddress().getPort()).build(); try (MockTransportService service = MockTransportService.createNewService(localSettings, Version.CURRENT, threadPool, null)) { @@ -117,7 +120,7 @@ public void testEnsureWeReconnect() throws Exception { } public void testRemoteClusterServiceNotEnabled() { - final Settings settings = Settings.builder().put(Node.NODE_REMOTE_CLUSTER_CLIENT.getKey(), false).build(); + final Settings settings = removeRoles(Set.of(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE)); try (MockTransportService service = MockTransportService.createNewService(settings, Version.CURRENT, threadPool, null)) { service.start(); service.acceptIncomingRequests(); diff --git a/server/src/test/java/org/elasticsearch/transport/RemoteClusterServiceTests.java b/server/src/test/java/org/elasticsearch/transport/RemoteClusterServiceTests.java index 185f7bebb974f..9283e433d3a69 100644 --- a/server/src/test/java/org/elasticsearch/transport/RemoteClusterServiceTests.java +++ b/server/src/test/java/org/elasticsearch/transport/RemoteClusterServiceTests.java @@ -24,13 +24,13 @@ import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.AbstractScopedSettings; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.core.internal.io.IOUtils; -import org.elasticsearch.node.Node; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.transport.MockTransportService; import org.elasticsearch.threadpool.TestThreadPool; @@ -50,6 +50,9 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.BiFunction; +import static org.elasticsearch.test.NodeRoles.masterOnlyNode; +import static org.elasticsearch.test.NodeRoles.nonMasterNode; +import static org.elasticsearch.test.NodeRoles.removeRoles; import static org.hamcrest.Matchers.either; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; @@ -448,8 +451,8 @@ public void testRemoteNodeAttribute() throws IOException, InterruptedException { public void testRemoteNodeRoles() throws IOException, InterruptedException { final Settings settings = Settings.EMPTY; final List knownNodes = new CopyOnWriteArrayList<>(); - final Settings data = Settings.builder().put("node.master", false).build(); - final Settings dedicatedMaster = Settings.builder().put("node.data", false).put("node.ingest", "false").build(); + final Settings data = nonMasterNode(); + final Settings dedicatedMaster = masterOnlyNode(); try (MockTransportService c1N1 = startTransport("cluster_1_node_1", knownNodes, Version.CURRENT, dedicatedMaster); MockTransportService c1N2 = @@ -847,7 +850,7 @@ public void testSkipUnavailable() { } public void testRemoteClusterServiceNotEnabledGetRemoteClusterConnection() { - final Settings settings = Settings.builder().put(Node.NODE_REMOTE_CLUSTER_CLIENT.getKey(), false).build(); + final Settings settings = removeRoles(Set.of(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE)); try (MockTransportService service = MockTransportService.createNewService(settings, Version.CURRENT, threadPool, null)) { service.start(); service.acceptIncomingRequests(); @@ -858,7 +861,7 @@ public void testRemoteClusterServiceNotEnabledGetRemoteClusterConnection() { } public void testRemoteClusterServiceNotEnabledGetCollectNodes() { - final Settings settings = Settings.builder().put(Node.NODE_REMOTE_CLUSTER_CLIENT.getKey(), false).build(); + final Settings settings = removeRoles(Set.of(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE)); try (MockTransportService service = MockTransportService.createNewService(settings, Version.CURRENT, threadPool, null)) { service.start(); service.acceptIncomingRequests(); diff --git a/server/src/test/java/org/elasticsearch/transport/RemoteClusterSettingsTests.java b/server/src/test/java/org/elasticsearch/transport/RemoteClusterSettingsTests.java index 0ff382fbd2f53..6166c544aa88c 100644 --- a/server/src/test/java/org/elasticsearch/transport/RemoteClusterSettingsTests.java +++ b/server/src/test/java/org/elasticsearch/transport/RemoteClusterSettingsTests.java @@ -19,13 +19,17 @@ package org.elasticsearch.transport; +import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.node.NodeRoleSettings; import org.elasticsearch.test.ESTestCase; import java.util.concurrent.TimeUnit; -import static org.elasticsearch.node.Node.NODE_REMOTE_CLUSTER_CLIENT; +import static org.elasticsearch.test.NodeRoles.nonRemoteClusterClientNode; +import static org.elasticsearch.test.NodeRoles.remoteClusterClientNode; import static org.elasticsearch.transport.RemoteClusterService.REMOTE_CLUSTER_SKIP_UNAVAILABLE; import static org.elasticsearch.transport.RemoteClusterService.REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING; import static org.elasticsearch.transport.RemoteClusterService.REMOTE_NODE_ATTRIBUTE; @@ -34,6 +38,8 @@ import static org.elasticsearch.transport.SniffConnectionStrategy.REMOTE_CONNECTIONS_PER_CLUSTER; import static org.hamcrest.Matchers.emptyCollectionOf; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.not; public class RemoteClusterSettingsTests extends ESTestCase { @@ -50,11 +56,20 @@ public void testRemoteNodeAttributeDefault() { } public void testRemoteClusterClientDefault() { - assertTrue(NODE_REMOTE_CLUSTER_CLIENT.get(Settings.EMPTY)); + assertTrue(DiscoveryNode.isRemoteClusterClient(Settings.EMPTY)); + assertThat(NodeRoleSettings.NODE_ROLES_SETTING.get(Settings.EMPTY), hasItem(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE)); } - public void testDisableRemoteClusterClient() { - assertFalse(NODE_REMOTE_CLUSTER_CLIENT.get(Settings.builder().put(NODE_REMOTE_CLUSTER_CLIENT.getKey(), false).build())); + public void testAddRemoteClusterClientRole() { + final Settings settings = remoteClusterClientNode(); + assertTrue(DiscoveryNode.isRemoteClusterClient(settings)); + assertThat(NodeRoleSettings.NODE_ROLES_SETTING.get(settings), hasItem(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE)); + } + + public void testRemoveRemoteClusterClientRole() { + final Settings settings = nonRemoteClusterClientNode(); + assertFalse(DiscoveryNode.isRemoteClusterClient(settings)); + assertThat(NodeRoleSettings.NODE_ROLES_SETTING.get(settings), not(hasItem(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE))); } public void testSkipUnavailableDefault() { diff --git a/test/framework/src/main/java/org/elasticsearch/cluster/coordination/AbstractCoordinatorTestCase.java b/test/framework/src/main/java/org/elasticsearch/cluster/coordination/AbstractCoordinatorTestCase.java index 9150226269a3d..7331c33decd9e 100644 --- a/test/framework/src/main/java/org/elasticsearch/cluster/coordination/AbstractCoordinatorTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/cluster/coordination/AbstractCoordinatorTestCase.java @@ -65,7 +65,6 @@ import org.elasticsearch.gateway.GatewayService; import org.elasticsearch.gateway.MockGatewayMetaState; import org.elasticsearch.gateway.PersistedClusterStateService; -import org.elasticsearch.node.Node; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.disruption.DisruptableMockTransport; import org.elasticsearch.test.disruption.DisruptableMockTransport.ConnectionStatus; @@ -982,7 +981,7 @@ ClusterNode restartedNode(Function adaptGlobalMetadata, Func final DiscoveryNode newLocalNode = new DiscoveryNode(localNode.getName(), localNode.getId(), UUIDs.randomBase64UUID(random()), // generated deterministically for repeatable tests address.address().getHostString(), address.getAddress(), address, Collections.emptyMap(), - localNode.isMasterNode() && Node.NODE_MASTER_SETTING.get(nodeSettings) + localNode.isMasterNode() && DiscoveryNode.isMasterNode(nodeSettings) ? DiscoveryNodeRole.BUILT_IN_ROLES : emptySet(), Version.CURRENT); return new ClusterNode(nodeIndex, newLocalNode, node -> new MockPersistedState(newLocalNode, persistedState, adaptGlobalMetadata, adaptCurrentTerm), nodeSettings); 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 d08a36ba4d9e6..4d00f33000990 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java @@ -66,6 +66,7 @@ import static org.elasticsearch.cluster.coordination.ClusterBootstrapService.INITIAL_MASTER_NODES_SETTING; import static org.elasticsearch.discovery.SettingsBasedSeedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING; +import static org.elasticsearch.test.NodeRoles.dataNode; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.lessThanOrEqualTo; @@ -205,7 +206,7 @@ private Node newNode() { .put(EsExecutors.NODE_PROCESSORS_SETTING.getKey(), 1) // limit the number of threads created .put("transport.type", getTestTransportType()) .put(TransportSettings.PORT.getKey(), ESTestCase.getPortRange()) - .put(Node.NODE_DATA_SETTING.getKey(), true) + .put(dataNode()) .put(NodeEnvironment.NODE_ID_SEED_SETTING.getKey(), random().nextLong()) // default the watermarks low values to prevent tests from failing on nodes without enough disk space .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(), "1b") diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java index af149a6c82fce..d0a800119925b 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -53,7 +53,6 @@ import org.elasticsearch.cluster.ClusterModule; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.CheckedRunnable; import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.common.bytes.BytesReference; @@ -345,14 +344,9 @@ public final void before() { } } - @BeforeClass - public static void setPossibleRoles() { - DiscoveryNode.setPossibleRoles(DiscoveryNodeRole.BUILT_IN_ROLES); - } - @AfterClass - public static void clearPossibleRoles() { - DiscoveryNode.setPossibleRoles(Set.of()); + public static void clearAdditionalRoles() { + DiscoveryNode.setAdditionalRoles(Set.of()); } /** @@ -1439,4 +1433,5 @@ protected static InetAddress randomIp(boolean v4) { throw new AssertionError(); } } + } diff --git a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java index fbb00b7863ce7..2b1057c88121f 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -150,6 +150,11 @@ import static org.elasticsearch.node.Node.INITIAL_STATE_TIMEOUT_SETTING; import static org.elasticsearch.test.ESTestCase.assertBusy; import static org.elasticsearch.test.ESTestCase.randomFrom; +import static org.elasticsearch.test.NodeRoles.dataOnlyNode; +import static org.elasticsearch.test.NodeRoles.masterOnlyNode; +import static org.elasticsearch.test.NodeRoles.noRoles; +import static org.elasticsearch.test.NodeRoles.onlyRole; +import static org.elasticsearch.test.NodeRoles.removeRoles; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThanOrEqualTo; @@ -707,16 +712,18 @@ private String buildNodeName(int id, Settings settings) { */ private static String getRoleSuffix(Settings settings) { String suffix = ""; - if (Node.NODE_MASTER_SETTING.exists(settings) && Node.NODE_MASTER_SETTING.get(settings)) { - suffix = suffix + DiscoveryNodeRole.MASTER_ROLE.roleNameAbbreviation(); - } - if (Node.NODE_DATA_SETTING.exists(settings) && Node.NODE_DATA_SETTING.get(settings)) { - suffix = suffix + DiscoveryNodeRole.DATA_ROLE.roleNameAbbreviation(); - } - if (Node.NODE_MASTER_SETTING.exists(settings) && Node.NODE_MASTER_SETTING.get(settings) == false && - Node.NODE_DATA_SETTING.exists(settings) && Node.NODE_DATA_SETTING.get(settings) == false - ) { - suffix = suffix + "c"; + // only add the suffixes if roles are explicitly defined + if (settings.hasValue("nodes.roles")) { + if (DiscoveryNode.hasRole(settings, DiscoveryNodeRole.MASTER_ROLE)) { + suffix = suffix + DiscoveryNodeRole.MASTER_ROLE.roleNameAbbreviation(); + } + if (DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE)) { + suffix = suffix + DiscoveryNodeRole.DATA_ROLE.roleNameAbbreviation(); + } + if (DiscoveryNode.hasRole(settings, DiscoveryNodeRole.MASTER_ROLE) == false + && DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE) == false) { + suffix = suffix + "c"; + } } return suffix; } @@ -777,9 +784,7 @@ public synchronized Client coordOnlyNodeClient() { public synchronized String startCoordinatingOnlyNode(Settings settings) { ensureOpen(); // currently unused - Builder builder = Settings.builder().put(settings).put(Node.NODE_MASTER_SETTING.getKey(), false) - .put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_INGEST_SETTING.getKey(), false); - return startNode(builder); + return startNode(noRoles(settings)); } /** @@ -852,7 +857,7 @@ public String getName() { } public boolean isMasterEligible() { - return Node.NODE_MASTER_SETTING.get(node.settings()); + return DiscoveryNode.isMasterNode(node.settings()); } Client client() { @@ -1045,30 +1050,27 @@ private synchronized void reset(boolean wipeData) throws IOException { final List settings = new ArrayList<>(); for (int i = 0; i < numSharedDedicatedMasterNodes; i++) { - final Settings.Builder extraSettings = Settings.builder(); - extraSettings.put(Node.NODE_MASTER_SETTING.getKey(), true); - extraSettings.put(Node.NODE_DATA_SETTING.getKey(), false); - settings.add(getNodeSettings(i, sharedNodesSeeds[i], extraSettings.build())); + final Settings nodeSettings = getNodeSettings(i, sharedNodesSeeds[i], Settings.EMPTY); + settings.add(removeRoles(nodeSettings, Set.of(DiscoveryNodeRole.DATA_ROLE))); } for (int i = numSharedDedicatedMasterNodes; i < numSharedDedicatedMasterNodes + numSharedDataNodes; i++) { - final Settings.Builder extraSettings = Settings.builder(); + final Settings nodeSettings = getNodeSettings(i, sharedNodesSeeds[i], Settings.EMPTY); if (numSharedDedicatedMasterNodes > 0) { + settings.add(removeRoles(nodeSettings, Set.of(DiscoveryNodeRole.MASTER_ROLE))); + } else { // if we don't have dedicated master nodes, keep things default - extraSettings.put(Node.NODE_MASTER_SETTING.getKey(), false).build(); - extraSettings.put(Node.NODE_DATA_SETTING.getKey(), true).build(); + settings.add(nodeSettings); } - settings.add(getNodeSettings(i, sharedNodesSeeds[i], extraSettings.build())); } for (int i = numSharedDedicatedMasterNodes + numSharedDataNodes; i < numSharedDedicatedMasterNodes + numSharedDataNodes + numSharedCoordOnlyNodes; i++) { - final Builder extraSettings = Settings.builder().put(Node.NODE_MASTER_SETTING.getKey(), false) - .put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_INGEST_SETTING.getKey(), false); + final Builder extraSettings = Settings.builder().put(noRoles()); settings.add(getNodeSettings(i, sharedNodesSeeds[i], extraSettings.build())); } int autoBootstrapMasterNodeIndex = -1; final List masterNodeNames = settings.stream() - .filter(Node.NODE_MASTER_SETTING::get) + .filter(DiscoveryNode::isMasterNode) .map(Node.NODE_NAME_SETTING::get) .collect(Collectors.toList()); @@ -1816,7 +1818,7 @@ private List bootstrapMasterNodeWithSpecifiedIndex(List allN List newSettings = new ArrayList<>(); for (Settings settings : allNodesSettings) { - if (Node.NODE_MASTER_SETTING.get(settings) == false) { + if (DiscoveryNode.isMasterNode(settings) == false) { newSettings.add(settings); } else { currentNodeId++; @@ -1826,13 +1828,13 @@ private List bootstrapMasterNodeWithSpecifiedIndex(List allN List nodeNames = new ArrayList<>(); for (Settings nodeSettings : getDataOrMasterNodeInstances(Settings.class)) { - if (Node.NODE_MASTER_SETTING.get(nodeSettings)) { + if (DiscoveryNode.isMasterNode(nodeSettings)) { nodeNames.add(Node.NODE_NAME_SETTING.get(nodeSettings)); } } for (Settings nodeSettings : allNodesSettings) { - if (Node.NODE_MASTER_SETTING.get(nodeSettings)) { + if (DiscoveryNode.isMasterNode(nodeSettings)) { nodeNames.add(Node.NODE_NAME_SETTING.get(nodeSettings)); } } @@ -1888,12 +1890,12 @@ public List startNodes(int numOfNodes, Settings settings) { * Starts multiple nodes with the given settings and returns their names */ public synchronized List startNodes(Settings... extraSettings) { - final int newMasterCount = Math.toIntExact(Stream.of(extraSettings).filter(Node.NODE_MASTER_SETTING::get).count()); + final int newMasterCount = Math.toIntExact(Stream.of(extraSettings).filter(DiscoveryNode::isMasterNode).count()); final List nodes = new ArrayList<>(); final int prevMasterCount = getMasterNodesCount(); int autoBootstrapMasterNodeIndex = autoManageMasterNodes && prevMasterCount == 0 && newMasterCount > 0 && Arrays.stream(extraSettings) - .allMatch(s -> Node.NODE_MASTER_SETTING.get(s) == false || ZEN2_DISCOVERY_TYPE.equals(DISCOVERY_TYPE_SETTING.get(s))) + .allMatch(s -> DiscoveryNode.isMasterNode(s) == false || ZEN2_DISCOVERY_TYPE.equals(DISCOVERY_TYPE_SETTING.get(s))) ? RandomNumbers.randomIntBetween(random, 0, newMasterCount - 1) : -1; final int numOfNodes = extraSettings.length; @@ -1905,7 +1907,7 @@ public synchronized List startNodes(Settings... extraSettings) { nextNodeId.set(firstNodeId + numOfNodes); final List initialMasterNodes = settings.stream() - .filter(Node.NODE_MASTER_SETTING::get) + .filter(DiscoveryNode::isMasterNode) .map(Node.NODE_NAME_SETTING::get) .collect(Collectors.toList()); @@ -1914,7 +1916,7 @@ public synchronized List startNodes(Settings... extraSettings) { for (int i = 0; i < numOfNodes; i++) { final Settings nodeSettings = updatedSettings.get(i); final Builder builder = Settings.builder(); - if (Node.NODE_MASTER_SETTING.get(nodeSettings)) { + if (DiscoveryNode.isMasterNode(nodeSettings)) { if (autoBootstrapMasterNodeIndex == 0) { builder.putList(INITIAL_MASTER_NODES_SETTING.getKey(), initialMasterNodes); } @@ -1937,12 +1939,11 @@ public List startMasterOnlyNodes(int numNodes) { } public List startMasterOnlyNodes(int numNodes, Settings settings) { - Settings settings1 = Settings.builder() - .put(settings) - .put(Node.NODE_MASTER_SETTING.getKey(), true) - .put(Node.NODE_DATA_SETTING.getKey(), false) - .build(); - return startNodes(numNodes, settings1); + return startNodes( + numNodes, + Settings.builder() + .put(onlyRole(settings, DiscoveryNodeRole.MASTER_ROLE)) + .build()); } public List startDataOnlyNodes(int numNodes) { @@ -1952,12 +1953,13 @@ public List startDataOnlyNodes(int numNodes) { public List startDataOnlyNodes(int numNodes, Settings settings) { return startNodes( numNodes, - Settings.builder().put(settings).put(Node.NODE_MASTER_SETTING.getKey(), false) - .put(Node.NODE_DATA_SETTING.getKey(), true).build()); + Settings.builder() + .put(onlyRole(settings, DiscoveryNodeRole.DATA_ROLE)) + .build()); } private int getMasterNodesCount() { - return (int) nodes.values().stream().filter(n -> Node.NODE_MASTER_SETTING.get(n.node().settings())).count(); + return (int) nodes.values().stream().filter(n -> DiscoveryNode.isMasterNode(n.node().settings())).count(); } public String startMasterOnlyNode() { @@ -1967,9 +1969,7 @@ public String startMasterOnlyNode() { public String startMasterOnlyNode(Settings settings) { Settings settings1 = Settings.builder() .put(settings) - .put(Node.NODE_MASTER_SETTING.getKey(), true) - .put(Node.NODE_DATA_SETTING.getKey(), false) - .put(Node.NODE_INGEST_SETTING.getKey(), false) + .put(masterOnlyNode(settings)) .build(); return startNode(settings1); } @@ -1981,8 +1981,7 @@ public String startDataOnlyNode() { public String startDataOnlyNode(Settings settings) { Settings settings1 = Settings.builder() .put(settings) - .put(Node.NODE_MASTER_SETTING.getKey(), false) - .put(Node.NODE_DATA_SETTING.getKey(), true) + .put(dataOnlyNode(settings)) .build(); return startNode(settings1); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java b/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java new file mode 100644 index 0000000000000..f3ec462743fb8 --- /dev/null +++ b/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java @@ -0,0 +1,187 @@ +/* + * 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.test; + +import org.elasticsearch.cluster.node.DiscoveryNodeRole; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.node.NodeRoleSettings; + +import java.util.List; +import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * Utility methods for creating {@link Settings} instances defining a set of {@link DiscoveryNodeRole}. + */ +public class NodeRoles { + + public static Settings onlyRole(final DiscoveryNodeRole role) { + return onlyRole(Settings.EMPTY, role); + } + + public static Settings onlyRole(final Settings settings, final DiscoveryNodeRole role) { + return onlyRoles(settings, Set.of(role)); + } + + public static Settings onlyRoles(final Set roles) { + return onlyRoles(Settings.EMPTY, roles); + } + + public static Settings onlyRoles(final Settings settings, final Set roles) { + return Settings.builder() + .put(settings) + .putList( + NodeRoleSettings.NODE_ROLES_SETTING.getKey(), + roles.stream().map(DiscoveryNodeRole::roleName).collect(Collectors.toUnmodifiableList())) + .build(); + } + + public static Settings removeRoles(final Set roles) { + return removeRoles(Settings.EMPTY, roles); + } + + public static Settings removeRoles(final Settings settings, final Set roles) { + final Settings.Builder builder = Settings.builder().put(settings); + builder.putList( + NodeRoleSettings.NODE_ROLES_SETTING.getKey(), + NodeRoleSettings.NODE_ROLES_SETTING.get(settings) + .stream() + .filter(Predicate.not(roles::contains)) + .map(DiscoveryNodeRole::roleName) + .collect(Collectors.toUnmodifiableList()) + ); + return builder.build(); + } + + public static Settings addRoles(final Set roles) { + return addRoles(Settings.EMPTY, roles); + } + + public static Settings addRoles(final Settings settings, final Set roles) { + final Settings.Builder builder = Settings.builder().put(settings); + builder.putList( + NodeRoleSettings.NODE_ROLES_SETTING.getKey(), + Stream.concat(NodeRoleSettings.NODE_ROLES_SETTING.get(settings).stream(), roles.stream()) + .map(DiscoveryNodeRole::roleName) + .distinct() + .collect(Collectors.toUnmodifiableList()) + ); + return builder.build(); + } + + public static Settings noRoles() { + return noRoles(Settings.EMPTY); + } + + public static Settings noRoles(final Settings settings) { + return Settings.builder().put(settings).putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), List.of()).build(); + } + + public static Settings dataNode() { + return dataNode(Settings.EMPTY); + } + + public static Settings dataNode(final Settings settings) { + return addRoles(settings, Set.of(DiscoveryNodeRole.DATA_ROLE)); + } + + public static Settings dataOnlyNode() { + return dataOnlyNode(Settings.EMPTY); + } + + public static Settings dataOnlyNode(final Settings settings) { + return onlyRole(settings, DiscoveryNodeRole.DATA_ROLE); + } + + public static Settings nonDataNode() { + return nonDataNode(Settings.EMPTY); + } + + public static Settings nonDataNode(final Settings settings) { + return removeRoles(settings, Set.of(DiscoveryNodeRole.DATA_ROLE)); + } + + public static Settings ingestNode() { + return ingestNode(Settings.EMPTY); + } + + public static Settings ingestNode(final Settings settings) { + return addRoles(settings, Set.of(DiscoveryNodeRole.INGEST_ROLE)); + } + + public static Settings ingestOnlyNode() { + return ingestOnlyNode(Settings.EMPTY); + } + + public static Settings ingestOnlyNode(final Settings settings) { + return onlyRole(settings, DiscoveryNodeRole.INGEST_ROLE); + } + + public static Settings nonIngestNode() { + return nonIngestNode(Settings.EMPTY); + } + + public static Settings nonIngestNode(final Settings settings) { + return removeRoles(settings, Set.of(DiscoveryNodeRole.INGEST_ROLE)); + } + + public static Settings masterNode() { + return masterNode(Settings.EMPTY); + } + + public static Settings masterNode(final Settings settings) { + return addRoles(settings, Set.of(DiscoveryNodeRole.MASTER_ROLE)); + } + + public static Settings masterOnlyNode() { + return masterOnlyNode(Settings.EMPTY); + } + + public static Settings masterOnlyNode(final Settings settings) { + return onlyRole(settings, DiscoveryNodeRole.MASTER_ROLE); + } + + public static Settings nonMasterNode() { + return nonMasterNode(Settings.EMPTY); + } + + public static Settings nonMasterNode(final Settings settings) { + return removeRoles(settings, Set.of(DiscoveryNodeRole.MASTER_ROLE)); + } + + public static Settings remoteClusterClientNode() { + return remoteClusterClientNode(Settings.EMPTY); + } + + public static Settings remoteClusterClientNode(final Settings settings) { + return addRoles(settings, Set.of(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE)); + } + + public static Settings nonRemoteClusterClientNode() { + return nonRemoteClusterClientNode(Settings.EMPTY); + } + + public static Settings nonRemoteClusterClientNode(final Settings settings) { + return removeRoles(settings, Set.of(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE)); + } + +} diff --git a/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/FollowerFailOverIT.java b/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/FollowerFailOverIT.java index dbc42d1589077..570281a43ac76 100644 --- a/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/FollowerFailOverIT.java +++ b/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/FollowerFailOverIT.java @@ -12,6 +12,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Strings; @@ -32,12 +33,14 @@ import org.hamcrest.Matchers; import java.util.Locale; +import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import static org.elasticsearch.test.NodeRoles.onlyRoles; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; @@ -243,7 +246,8 @@ public void testReadRequestsReturnLatestMappingVersion() throws Exception { .put("index.routing.allocation.require.box", "large")) .get() ); - getFollowerCluster().startDataOnlyNode(nodeAttributes); + getFollowerCluster().startNode( + onlyRoles(nodeAttributes, Set.of(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE))); followerClient().execute(PutFollowAction.INSTANCE, putFollow("leader-index", "follower-index")).get(); ensureFollowerGreen("follower-index"); ClusterService clusterService = leaderCluster.clusterService(dataNode); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseServiceClusterTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseServiceClusterTests.java index ad3e8a2670135..966bc694925a6 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseServiceClusterTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseServiceClusterTests.java @@ -6,6 +6,7 @@ package org.elasticsearch.license; import org.elasticsearch.analysis.common.CommonAnalysisPlugin; +import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.env.Environment; @@ -20,8 +21,10 @@ import java.nio.file.Path; import java.util.Arrays; import java.util.Collection; +import java.util.Set; import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST; +import static org.elasticsearch.test.NodeRoles.addRoles; import static org.hamcrest.CoreMatchers.equalTo; @ClusterScope(scope = TEST, numDataNodes = 0, numClientNodes = 0, maxNumDataNodes = 0) @@ -39,9 +42,8 @@ protected boolean addMockHttpTransport() { private Settings.Builder nodeSettingsBuilder(int nodeOrdinal) { return Settings.builder() - .put(super.nodeSettings(nodeOrdinal)) - .put("node.data", true) - .put("resource.reload.interval.high", "500ms"); // for license mode file watcher + .put(addRoles(super.nodeSettings(nodeOrdinal), Set.of(DiscoveryNodeRole.DATA_ROLE))) + .put("resource.reload.interval.high", "500ms"); // for license mode file watcher } @Override diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicensesTransportTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicensesTransportTests.java index 244c982bc21c1..1920e37b21886 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicensesTransportTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicensesTransportTests.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.node.Node; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.protocol.xpack.license.LicensesStatus; import org.elasticsearch.protocol.xpack.license.PutLicenseResponse; @@ -27,6 +26,7 @@ import static org.elasticsearch.license.TestUtils.dateMath; import static org.elasticsearch.license.TestUtils.generateExpiredNonBasicLicense; import static org.elasticsearch.license.TestUtils.generateSignedLicense; +import static org.elasticsearch.test.NodeRoles.dataNode; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.not; @@ -49,7 +49,7 @@ protected Settings nodeSettings() { newSettings.put(XPackSettings.SECURITY_ENABLED.getKey(), false); // newSettings.put(XPackSettings.MONITORING_ENABLED.getKey(), false); // newSettings.put(XPackSettings.WATCHER_ENABLED.getKey(), false); - newSettings.put(Node.NODE_DATA_SETTING.getKey(), true); + newSettings.put(dataNode()); return newSettings.build(); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/StartBasicLicenseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/StartBasicLicenseTests.java index aedff7694e13a..eec4a4c8676d2 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/StartBasicLicenseTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/StartBasicLicenseTests.java @@ -9,6 +9,7 @@ import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; import org.elasticsearch.client.RestClient; +import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -21,8 +22,10 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collection; +import java.util.Set; import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE; +import static org.elasticsearch.test.NodeRoles.addRoles; @ESIntegTestCase.ClusterScope(scope = SUITE) public class StartBasicLicenseTests extends AbstractLicensesIntegrationTestCase { @@ -35,9 +38,8 @@ protected boolean addMockHttpTransport() { @Override protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() - .put(super.nodeSettings(nodeOrdinal)) - .put("node.data", true) - .put(LicenseService.SELF_GENERATED_LICENSE_TYPE.getKey(), "basic").build(); + .put(addRoles(super.nodeSettings(nodeOrdinal), Set.of(DiscoveryNodeRole.DATA_ROLE))) + .put(LicenseService.SELF_GENERATED_LICENSE_TYPE.getKey(), "basic").build(); } @Override diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/StartTrialLicenseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/StartTrialLicenseTests.java index bc05ecf647c06..5684bf5ac77f6 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/StartTrialLicenseTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/StartTrialLicenseTests.java @@ -9,6 +9,7 @@ import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; import org.elasticsearch.client.RestClient; +import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugins.Plugin; @@ -20,8 +21,10 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collection; +import java.util.Set; import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE; +import static org.elasticsearch.test.NodeRoles.addRoles; import static org.hamcrest.Matchers.containsString; @ESIntegTestCase.ClusterScope(scope = SUITE) @@ -35,9 +38,9 @@ protected boolean addMockHttpTransport() { @Override protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() - .put(super.nodeSettings(nodeOrdinal)) - .put("node.data", true) - .put(LicenseService.SELF_GENERATED_LICENSE_TYPE.getKey(), "basic").build(); + .put(addRoles(super.nodeSettings(nodeOrdinal), Set.of(DiscoveryNodeRole.DATA_ROLE))) + .put(LicenseService.SELF_GENERATED_LICENSE_TYPE.getKey(), "basic") + .build(); } @Override diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrunkShardsAllocatedStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrunkShardsAllocatedStepTests.java index d0d52fa091f9e..31df71fac04c5 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrunkShardsAllocatedStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrunkShardsAllocatedStepTests.java @@ -19,7 +19,7 @@ import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; -import org.elasticsearch.node.Node; +import org.elasticsearch.test.NodeRoles; import org.elasticsearch.xpack.core.ilm.ClusterStateWaitStep.Result; import org.elasticsearch.xpack.core.ilm.Step.StepKey; @@ -82,9 +82,10 @@ public void testConditionMet() { Index shrinkIndex = shrunkIndexMetadata.getIndex(); String nodeId = randomAlphaOfLength(10); - DiscoveryNode masterNode = DiscoveryNode.createLocal(settings(Version.CURRENT) - .put(Node.NODE_MASTER_SETTING.getKey(), true).build(), - new TransportAddress(TransportAddress.META_ADDRESS, 9300), nodeId); + DiscoveryNode masterNode = DiscoveryNode.createLocal( + NodeRoles.masterNode(settings(Version.CURRENT).build()), + new TransportAddress(TransportAddress.META_ADDRESS, 9300), + nodeId); IndexRoutingTable.Builder builder = IndexRoutingTable.builder(shrinkIndex); for (int i = 0; i < shrinkNumberOfShards; i++) { @@ -122,9 +123,10 @@ public void testConditionNotMetBecauseOfActive() { Index shrinkIndex = shrunkIndexMetadata.getIndex(); String nodeId = randomAlphaOfLength(10); - DiscoveryNode masterNode = DiscoveryNode.createLocal(settings(Version.CURRENT) - .put(Node.NODE_MASTER_SETTING.getKey(), true).build(), - new TransportAddress(TransportAddress.META_ADDRESS, 9300), nodeId); + DiscoveryNode masterNode = DiscoveryNode.createLocal( + NodeRoles.masterNode(settings(Version.CURRENT).build()), + new TransportAddress(TransportAddress.META_ADDRESS, 9300), + nodeId); IndexRoutingTable.Builder builder = IndexRoutingTable.builder(shrinkIndex); for (int i = 0; i < shrinkNumberOfShards; i++) { @@ -156,9 +158,10 @@ public void testConditionNotMetBecauseOfShrunkIndexDoesntExistYet() { .build(); String nodeId = randomAlphaOfLength(10); - DiscoveryNode masterNode = DiscoveryNode.createLocal(settings(Version.CURRENT) - .put(Node.NODE_MASTER_SETTING.getKey(), true).build(), - new TransportAddress(TransportAddress.META_ADDRESS, 9300), nodeId); + DiscoveryNode masterNode = DiscoveryNode.createLocal( + NodeRoles.masterNode(settings(Version.CURRENT).build()), + new TransportAddress(TransportAddress.META_ADDRESS, 9300), + nodeId); ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT) .metadata(metadata) .nodes(DiscoveryNodes.builder().localNodeId(nodeId).masterNodeId(nodeId).add(masterNode).build()) diff --git a/x-pack/plugin/enrich/src/internalClusterTest/java/org/elasticsearch/xpack/enrich/EnrichMultiNodeIT.java b/x-pack/plugin/enrich/src/internalClusterTest/java/org/elasticsearch/xpack/enrich/EnrichMultiNodeIT.java index 63e713ae050d7..d5ccf7fee4dde 100644 --- a/x-pack/plugin/enrich/src/internalClusterTest/java/org/elasticsearch/xpack/enrich/EnrichMultiNodeIT.java +++ b/x-pack/plugin/enrich/src/internalClusterTest/java/org/elasticsearch/xpack/enrich/EnrichMultiNodeIT.java @@ -22,7 +22,6 @@ import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.reindex.ReindexPlugin; import org.elasticsearch.ingest.common.IngestCommonPlugin; -import org.elasticsearch.node.Node; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.xpack.core.enrich.EnrichPolicy; @@ -39,6 +38,8 @@ import java.util.Map; import java.util.Set; +import static org.elasticsearch.test.NodeRoles.ingestOnlyNode; +import static org.elasticsearch.test.NodeRoles.nonIngestNode; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.is; @@ -112,12 +113,7 @@ public void testEnrich() { public void testEnrichDedicatedIngestNode() { internalCluster().startNode(); - Settings settings = Settings.builder() - .put(Node.NODE_MASTER_SETTING.getKey(), false) - .put(Node.NODE_DATA_SETTING.getKey(), false) - .put(Node.NODE_INGEST_SETTING.getKey(), true) - .build(); - String ingestOnlyNode = internalCluster().startNode(settings); + String ingestOnlyNode = internalCluster().startNode(ingestOnlyNode()); List keys = createSourceIndex(64); createAndExecutePolicy(); @@ -126,11 +122,7 @@ public void testEnrichDedicatedIngestNode() { } public void testEnrichNoIngestNodes() { - Settings settings = Settings.builder() - .put(Node.NODE_MASTER_SETTING.getKey(), true) - .put(Node.NODE_DATA_SETTING.getKey(), true) - .put(Node.NODE_INGEST_SETTING.getKey(), false) - .build(); + Settings settings = Settings.builder().put(nonIngestNode()).build(); internalCluster().startNode(settings); createSourceIndex(64); diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/ExecuteStepsUpdateTaskTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/ExecuteStepsUpdateTaskTests.java index 220a657da1a4f..1dac63bd0aa02 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/ExecuteStepsUpdateTaskTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/ExecuteStepsUpdateTaskTests.java @@ -20,11 +20,11 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.index.Index; -import org.elasticsearch.node.Node; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.NodeRoles; import org.elasticsearch.xpack.core.ilm.ErrorStep; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; +import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyMetadata; import org.elasticsearch.xpack.core.ilm.LifecycleSettings; @@ -131,9 +131,10 @@ private IndexMetadata setupIndexPolicy(String policyName) { .put(IndexMetadata.builder(indexMetadata)) .build(); String nodeId = randomAlphaOfLength(10); - DiscoveryNode masterNode = DiscoveryNode.createLocal(settings(Version.CURRENT) - .put(Node.NODE_MASTER_SETTING.getKey(), true).build(), - new TransportAddress(TransportAddress.META_ADDRESS, 9300), nodeId); + DiscoveryNode masterNode = DiscoveryNode.createLocal( + NodeRoles.masterNode(settings(Version.CURRENT).build()), + new TransportAddress(TransportAddress.META_ADDRESS, 9300), + nodeId); clusterState = ClusterState.builder(ClusterName.DEFAULT) .metadata(metadata) .nodes(DiscoveryNodes.builder().localNodeId(nodeId).masterNodeId(nodeId).add(masterNode).build()) diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleServiceTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleServiceTests.java index 7ed9ba4ed2440..c4d3192eeb65a 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleServiceTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleServiceTests.java @@ -27,6 +27,7 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.Index; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.NodeRoles; import org.elasticsearch.threadpool.TestThreadPool; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; @@ -58,7 +59,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; -import static org.elasticsearch.node.Node.NODE_MASTER_SETTING; import static org.elasticsearch.xpack.core.ilm.AbstractStepTestCase.randomStepKey; import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; import static org.elasticsearch.xpack.core.ilm.LifecyclePolicyTestsUtils.newTestLifecyclePolicy; @@ -87,9 +87,10 @@ public void prepareServices() { nodeId = randomAlphaOfLength(10); ExecutorService executorService = mock(ExecutorService.class); clusterService = mock(ClusterService.class); - masterNode = DiscoveryNode.createLocal(settings(Version.CURRENT) - .put(NODE_MASTER_SETTING.getKey(), true).build(), - new TransportAddress(TransportAddress.META_ADDRESS, 9300), nodeId); + masterNode = DiscoveryNode.createLocal( + NodeRoles.masterNode(settings(Version.CURRENT).build()), + new TransportAddress(TransportAddress.META_ADDRESS, 9300), + nodeId); now = randomNonNegativeLong(); Clock clock = Clock.fixed(Instant.ofEpochMilli(now), ZoneId.of(randomFrom(ZoneId.getAvailableZoneIds()))); diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistryTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistryTests.java index 3db2f2a59d5cc..29b23e2d3ed18 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistryTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistryTests.java @@ -22,13 +22,13 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.index.Index; -import org.elasticsearch.node.Node; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.NodeRoles; import org.elasticsearch.xpack.core.ilm.ErrorStep; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; import org.elasticsearch.xpack.core.ilm.InitializePolicyContextStep; import org.elasticsearch.xpack.core.ilm.LifecycleAction; +import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyMetadata; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyTests; @@ -217,9 +217,10 @@ public void testUpdateFromNothingToSomethingToNothing() throws Exception { logger.info("--> metadata: {}", Strings.toString(builder)); } String nodeId = randomAlphaOfLength(10); - DiscoveryNode masterNode = DiscoveryNode.createLocal(settings(Version.CURRENT) - .put(Node.NODE_MASTER_SETTING.getKey(), true).build(), - new TransportAddress(TransportAddress.META_ADDRESS, 9300), nodeId); + DiscoveryNode masterNode = DiscoveryNode.createLocal( + NodeRoles.masterNode(settings(Version.CURRENT).build()), + new TransportAddress(TransportAddress.META_ADDRESS, 9300), + nodeId); ClusterState currentState = ClusterState.builder(ClusterName.DEFAULT) .metadata(metadata) .nodes(DiscoveryNodes.builder().localNodeId(nodeId).masterNodeId(nodeId).add(masterNode).build()) @@ -292,9 +293,10 @@ public void testUpdateChangedPolicy() { .putCustom(IndexLifecycleMetadata.TYPE, lifecycleMetadata) .build(); String nodeId = randomAlphaOfLength(10); - DiscoveryNode masterNode = DiscoveryNode.createLocal(settings(Version.CURRENT) - .put(Node.NODE_MASTER_SETTING.getKey(), true).build(), - new TransportAddress(TransportAddress.META_ADDRESS, 9300), nodeId); + DiscoveryNode masterNode = DiscoveryNode.createLocal( + NodeRoles.masterNode(settings(Version.CURRENT).build()), + new TransportAddress(TransportAddress.META_ADDRESS, 9300), + nodeId); ClusterState currentState = ClusterState.builder(ClusterName.DEFAULT) .metadata(metadata) .nodes(DiscoveryNodes.builder().localNodeId(nodeId).masterNodeId(nodeId).add(masterNode).build()) @@ -366,9 +368,10 @@ public void testUpdatePolicyButNoPhaseChangeIndexStepsDontChange() throws Except logger.info("--> metadata: {}", Strings.toString(builder)); } String nodeId = randomAlphaOfLength(10); - DiscoveryNode masterNode = DiscoveryNode.createLocal(settings(Version.CURRENT) - .put(Node.NODE_MASTER_SETTING.getKey(), true).build(), - new TransportAddress(TransportAddress.META_ADDRESS, 9300), nodeId); + DiscoveryNode masterNode = DiscoveryNode.createLocal( + NodeRoles.masterNode(settings(Version.CURRENT).build()), + new TransportAddress(TransportAddress.META_ADDRESS, 9300), + nodeId); ClusterState currentState = ClusterState.builder(ClusterName.DEFAULT) .metadata(metadata) .nodes(DiscoveryNodes.builder().localNodeId(nodeId).masterNodeId(nodeId).add(masterNode).build()) diff --git a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/BasicDistributedJobsIT.java b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/BasicDistributedJobsIT.java index 02ac38a18ef61..211af83ded2e0 100644 --- a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/BasicDistributedJobsIT.java +++ b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/BasicDistributedJobsIT.java @@ -9,6 +9,7 @@ import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.CheckedRunnable; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.settings.Settings; @@ -48,10 +49,14 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.TimeUnit; import static org.elasticsearch.persistent.PersistentTasksClusterService.needsReassignment; +import static org.elasticsearch.test.NodeRoles.addRoles; +import static org.elasticsearch.test.NodeRoles.onlyRole; +import static org.elasticsearch.test.NodeRoles.removeRoles; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasEntry; @@ -150,8 +155,8 @@ public void testFailOverBasics_withDataFeeder() throws Exception { public void testJobAutoClose() throws Exception { internalCluster().ensureAtMostNumDataNodes(0); - internalCluster().startNode(Settings.builder().put(MachineLearning.ML_ENABLED.getKey(), false)); - internalCluster().startNode(Settings.builder().put(MachineLearning.ML_ENABLED.getKey(), true)); + internalCluster().startNode(removeRoles(Set.of(MachineLearning.ML_ROLE))); + internalCluster().startNode(addRoles(Set.of(MachineLearning.ML_ROLE))); client().admin().indices().prepareCreate("data") .setMapping("time", "type=date") @@ -192,11 +197,11 @@ public void testJobAutoClose() throws Exception { public void testDedicatedMlNode() throws Exception { internalCluster().ensureAtMostNumDataNodes(0); // start 2 non ml node that will never get a job allocated. (but ml apis are accessible from this node) - internalCluster().startNode(Settings.builder().put(MachineLearning.ML_ENABLED.getKey(), false)); - internalCluster().startNode(Settings.builder().put(MachineLearning.ML_ENABLED.getKey(), false)); + internalCluster().startNode(removeRoles(Set.of(MachineLearning.ML_ROLE))); + internalCluster().startNode(removeRoles(Set.of(MachineLearning.ML_ROLE))); // start ml node if (randomBoolean()) { - internalCluster().startNode(Settings.builder().put(MachineLearning.ML_ENABLED.getKey(), true)); + internalCluster().startNode(addRoles(Set.of(MachineLearning.ML_ROLE))); } else { // the default is based on 'xpack.ml.enabled', which is enabled in base test class. internalCluster().startNode(); @@ -224,7 +229,7 @@ public void testDedicatedMlNode() throws Exception { }); logger.info("stop the only running ml node"); - internalCluster().stopRandomNode(settings -> settings.getAsBoolean(MachineLearning.ML_ENABLED.getKey(), true)); + internalCluster().stopRandomNode(settings -> DiscoveryNode.hasRole(settings, MachineLearning.ML_ROLE)); ensureStableCluster(2); assertBusy(() -> { // job should get and remain in a failed state and @@ -233,7 +238,7 @@ public void testDedicatedMlNode() throws Exception { }); logger.info("start ml node"); - internalCluster().startNode(Settings.builder().put(MachineLearning.ML_ENABLED.getKey(), true)); + internalCluster().startNode(addRoles(Set.of(MachineLearning.ML_ROLE))); ensureStableCluster(3); assertBusy(() -> { // job should be re-opened: @@ -246,13 +251,9 @@ public void testMaxConcurrentJobAllocations() throws Exception { internalCluster().ensureAtMostNumDataNodes(0); // start non ml node, but that will hold the indices logger.info("Start non ml node:"); - String nonMlNode = internalCluster().startNode(Settings.builder() - .put(MachineLearning.ML_ENABLED.getKey(), false)); + String nonMlNode = internalCluster().startNode(removeRoles(Set.of(MachineLearning.ML_ROLE))); logger.info("Starting ml nodes"); - internalCluster().startNodes(numMlNodes, Settings.builder() - .put("node.data", false) - .put("node.master", false) - .put(MachineLearning.ML_ENABLED.getKey(), true).build()); + internalCluster().startNodes(numMlNodes, onlyRole(MachineLearning.ML_ROLE)); ensureStableCluster(numMlNodes + 1); int maxConcurrentJobAllocations = randomIntBetween(1, 4); @@ -301,8 +302,7 @@ public void testMaxConcurrentJobAllocations() throws Exception { // fork so stopping all ml nodes proceeds quicker: Runnable r = () -> { try { - internalCluster() - .stopRandomNode(settings -> settings.getAsBoolean(MachineLearning.ML_ENABLED.getKey(), false)); + internalCluster().stopRandomNode(settings -> DiscoveryNode.hasRole(settings, MachineLearning.ML_ROLE)); } catch (IOException e) { logger.error("error stopping node", e); } @@ -320,10 +320,7 @@ public void testMaxConcurrentJobAllocations() throws Exception { }); logger.info("re-starting ml nodes"); - internalCluster().startNodes(numMlNodes, Settings.builder() - .put("node.data", false) - .put("node.master", false) - .put(MachineLearning.ML_ENABLED.getKey(), true).build()); + internalCluster().startNodes(numMlNodes, onlyRole(MachineLearning.ML_ROLE)); ensureStableCluster(1 + numMlNodes); assertBusy(checkAllJobsAreAssignedAndOpened(numJobs), 30, TimeUnit.SECONDS); @@ -340,16 +337,14 @@ public void testMlStateAndResultsIndicesNotAvailable() throws Exception { // start non ml node that will hold the state and results indices logger.info("Start non ml node:"); String nonMLNode = internalCluster().startNode(Settings.builder() - .put("node.data", true) .put("node.attr.ml-indices", "state-and-results") - .put(MachineLearning.ML_ENABLED.getKey(), false)); + .put(removeRoles(Set.of(MachineLearning.ML_ROLE)))); ensureStableCluster(1); // start an ml node for the config index logger.info("Starting ml node"); String mlNode = internalCluster().startNode(Settings.builder() - .put("node.data", true) .put("node.attr.ml-indices", "config") - .put(MachineLearning.ML_ENABLED.getKey(), true)); + .put(addRoles(Set.of(DiscoveryNodeRole.DATA_ROLE, MachineLearning.ML_ROLE)))); ensureStableCluster(2); // Create the indices (using installed templates) and set the routing to specific nodes @@ -416,8 +411,7 @@ public void testMlStateAndResultsIndicesNotAvailable() throws Exception { logger.info("Start data node"); String nonMlNode = internalCluster().startNode(Settings.builder() .put(nonMLNodeDataPathSettings) - .put("node.data", true) - .put(MachineLearning.ML_ENABLED.getKey(), false)); + .put(removeRoles(Set.of(MachineLearning.ML_ROLE)))); ensureStableCluster(2, mlNode); ensureStableCluster(2, nonMlNode); ensureYellow(); // at least the primary shards of the indices a job uses should be started diff --git a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java index 848136a203db0..76c895acb029a 100644 --- a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java +++ b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java @@ -12,6 +12,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.CheckedRunnable; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; @@ -57,10 +58,14 @@ import java.io.IOException; import java.util.Collections; import java.util.List; +import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import static org.elasticsearch.persistent.PersistentTasksClusterService.needsReassignment; +import static org.elasticsearch.test.NodeRoles.masterOnlyNode; +import static org.elasticsearch.test.NodeRoles.onlyRole; +import static org.elasticsearch.test.NodeRoles.onlyRoles; import static org.hamcrest.Matchers.arrayWithSize; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; @@ -89,15 +94,9 @@ public void testFailOver() throws Exception { public void testLoseDedicatedMasterNode() throws Exception { internalCluster().ensureAtMostNumDataNodes(0); logger.info("Starting dedicated master node..."); - internalCluster().startNode(Settings.builder() - .put("node.master", true) - .put("node.data", false) - .put("node.ml", false) - .build()); + internalCluster().startMasterOnlyNode(); logger.info("Starting ml and data node..."); - String mlAndDataNode = internalCluster().startNode(Settings.builder() - .put("node.master", false) - .build()); + String mlAndDataNode = internalCluster().startNode(onlyRoles(Set.of(DiscoveryNodeRole.DATA_ROLE, MachineLearning.ML_ROLE))); ensureStableClusterOnAllNodes(2); run("lose-dedicated-master-node-job", () -> { logger.info("Stopping dedicated master node"); @@ -111,9 +110,7 @@ public void testLoseDedicatedMasterNode() throws Exception { logger.info("Restarting dedicated master node"); internalCluster().startNode(Settings.builder() .put(masterDataPathSettings) - .put("node.master", true) - .put("node.data", false) - .put("node.ml", false) + .put(masterOnlyNode()) .build()); ensureStableClusterOnAllNodes(2); }); @@ -132,16 +129,10 @@ public void testFullClusterRestart() throws Exception { public void testCloseUnassignedJobAndDatafeed() throws Exception { internalCluster().ensureAtMostNumDataNodes(0); - logger.info("Starting dedicated master node..."); - internalCluster().startNode(Settings.builder() - .put("node.master", true) - .put("node.data", true) - .put("node.ml", false) - .build()); + logger.info("Starting data and master node..."); + internalCluster().startNode(onlyRoles(Set.of(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.MASTER_ROLE))); logger.info("Starting ml and data node..."); - internalCluster().startNode(Settings.builder() - .put("node.master", false) - .build()); + internalCluster().startNode(onlyRoles(Set.of(DiscoveryNodeRole.DATA_ROLE, MachineLearning.ML_ROLE))); ensureStableClusterOnAllNodes(2); // index some datafeed data @@ -215,18 +206,10 @@ public void testCloseUnassignedFailedJobAndStopUnassignedStoppingDatafeed() thro internalCluster().ensureAtMostNumDataNodes(0); logger.info("Starting master/data nodes..."); for (int count = 0; count < 3; ++count) { - internalCluster().startNode(Settings.builder() - .put("node.master", true) - .put("node.data", true) - .put("node.ml", false) - .build()); + internalCluster().startNode(onlyRoles(Set.of(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.MASTER_ROLE))); } logger.info("Starting dedicated ml node..."); - internalCluster().startNode(Settings.builder() - .put("node.master", false) - .put("node.data", false) - .put("node.ml", true) - .build()); + internalCluster().startNode(onlyRole(MachineLearning.ML_ROLE)); ensureStableClusterOnAllNodes(4); // index some datafeed data @@ -331,15 +314,9 @@ public void testCloseUnassignedFailedJobAndStopUnassignedStoppingDatafeed() thro public void testStopAndForceStopDatafeed() throws Exception { internalCluster().ensureAtMostNumDataNodes(0); logger.info("Starting dedicated master node..."); - internalCluster().startNode(Settings.builder() - .put("node.master", true) - .put("node.data", true) - .put("node.ml", false) - .build()); + internalCluster().startMasterOnlyNode(); logger.info("Starting ml and data node..."); - internalCluster().startNode(Settings.builder() - .put("node.master", false) - .build()); + internalCluster().startNode(onlyRoles(Set.of(DiscoveryNodeRole.DATA_ROLE, MachineLearning.ML_ROLE))); ensureStableClusterOnAllNodes(2); // index some datafeed data diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java index 2059ed9332b85..f694feb255c3f 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java @@ -364,13 +364,13 @@ public class MachineLearning extends Plugin implements SystemIndexPlugin, // Recompile if you want to compare performance with C++ tokenization. public static final boolean CATEGORIZATION_TOKENIZATION_IN_JAVA = true; - public static final Setting ML_ENABLED = - Setting.boolSetting("node.ml", XPackSettings.MACHINE_LEARNING_ENABLED, Property.NodeScope); + private static final Setting ML_ENABLED = + Setting.boolSetting("node.ml", XPackSettings.MACHINE_LEARNING_ENABLED, Property.Deprecated, Property.NodeScope); public static final DiscoveryNodeRole ML_ROLE = new DiscoveryNodeRole("ml", "l") { @Override - protected Setting roleSetting() { + public Setting legacySetting() { return ML_ENABLED; } @@ -515,7 +515,7 @@ public Settings additionalSettings() { } Settings.Builder additionalSettings = Settings.builder(); - Boolean allocationEnabled = ML_ENABLED.get(settings); + Boolean allocationEnabled = DiscoveryNode.hasRole(settings, MachineLearning.ML_ROLE); if (allocationEnabled != null && allocationEnabled) { // TODO: stop setting this attribute in 8.0.0 but disallow it (like mlEnabledNodeAttrName below) // The ML UI will need to be changed to check machineMemoryAttrName instead before this is done diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedAction.java index aa3f6c1c2790e..afe58901d9871 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedAction.java @@ -18,6 +18,7 @@ import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; @@ -29,7 +30,6 @@ import org.elasticsearch.license.LicenseUtils; import org.elasticsearch.license.RemoteClusterLicenseChecker; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.node.Node; import org.elasticsearch.persistent.AllocatedPersistentTask; import org.elasticsearch.persistent.PersistentTaskState; import org.elasticsearch.persistent.PersistentTasksCustomMetadata; @@ -110,7 +110,7 @@ public TransportStartDatafeedAction(Settings settings, TransportService transpor this.auditor = auditor; this.migrationEligibilityCheck = new MlConfigMigrationEligibilityCheck(settings, clusterService); this.xContentRegistry = xContentRegistry; - this.remoteClusterClient = Node.NODE_REMOTE_CLUSTER_CLIENT.get(settings); + this.remoteClusterClient = DiscoveryNode.isRemoteClusterClient(settings); } static void validate(Job job, diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobBuilder.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobBuilder.java index 6fb1c80a08601..5b29a822a9d5d 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobBuilder.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobBuilder.java @@ -9,11 +9,11 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.client.Client; import org.elasticsearch.client.ParentTaskAssigningClient; +import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.license.RemoteClusterLicenseChecker; -import org.elasticsearch.node.Node; import org.elasticsearch.tasks.TaskId; import org.elasticsearch.xpack.core.action.util.QueryPage; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig; @@ -72,7 +72,7 @@ public DatafeedJobBuilder(Client client, NamedXContentRegistry xContentRegistry, this.jobResultsProvider = Objects.requireNonNull(jobResultsProvider); this.datafeedConfigProvider = Objects.requireNonNull(datafeedConfigProvider); this.jobResultsPersister = Objects.requireNonNull(jobResultsPersister); - this.remoteClusterClient = Node.NODE_REMOTE_CLUSTER_CLIENT.get(settings); + this.remoteClusterClient = DiscoveryNode.isRemoteClusterClient(settings); this.nodeName = nodeName; } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobBuilderTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobBuilderTests.java index b951519ae3957..a8590dcd8e582 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobBuilderTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobBuilderTests.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.mock.orig.Mockito; -import org.elasticsearch.node.Node; import org.elasticsearch.tasks.TaskId; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; @@ -35,6 +34,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; +import static org.elasticsearch.test.NodeRoles.nonRemoteClusterClientNode; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; @@ -212,7 +212,6 @@ public void testBuild_GivenBucketsRequestFails() { } public void testBuildGivenRemoteIndicesButNoRemoteSearching() throws Exception { - Settings settings = Settings.builder().put(Node.NODE_REMOTE_CLUSTER_CLIENT.getKey(), false).build(); datafeedJobBuilder = new DatafeedJobBuilder( client, @@ -224,7 +223,7 @@ public void testBuildGivenRemoteIndicesButNoRemoteSearching() throws Exception { jobResultsProvider, datafeedConfigProvider, jobResultsPersister, - settings, + nonRemoteClusterClientNode(), "test_node"); DataDescription.Builder dataDescription = new DataDescription.Builder(); dataDescription.setTimeField("time"); diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/MultiNodesStatsTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/MultiNodesStatsTests.java index 3aef6dad5889f..67149f05932f7 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/MultiNodesStatsTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/MultiNodesStatsTests.java @@ -8,7 +8,6 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.node.Node; import org.elasticsearch.search.aggregations.Aggregation; import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.bucket.terms.StringTerms; @@ -18,7 +17,7 @@ import org.elasticsearch.xpack.monitoring.test.MonitoringIntegTestCase; import org.junit.After; - +import static org.elasticsearch.test.NodeRoles.noRoles; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo; @@ -54,11 +53,7 @@ public void testMultipleNodes() throws Exception { nodes += n; n = randomIntBetween(1, 2); - internalCluster().startNodes(n, - Settings.builder() - .put(Node.NODE_DATA_SETTING.getKey(), false) - .put(Node.NODE_MASTER_SETTING.getKey(), false) - .put(Node.NODE_INGEST_SETTING.getKey(), false).build()); + internalCluster().startNodes(n, noRoles()); nodes += n; n = randomIntBetween(1, 2); diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/Transform.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/Transform.java index 91577ca0d2693..1342ea117596f 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/Transform.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/Transform.java @@ -151,19 +151,25 @@ public class Transform extends Plugin implements SystemIndexPlugin, PersistentTa /** * Setting whether transform (the coordinator task) can run on this node. */ - public static final Setting TRANSFORM_ENABLED_NODE = Setting.boolSetting( + private static final Setting TRANSFORM_ENABLED_NODE = Setting.boolSetting( "node.transform", settings -> Boolean.toString(DiscoveryNode.isDataNode(settings)), + Property.Deprecated, Property.NodeScope ); public static final DiscoveryNodeRole TRANSFORM_ROLE = new DiscoveryNodeRole("transform", "t") { @Override - protected Setting roleSetting() { + public Setting legacySetting() { return TRANSFORM_ENABLED_NODE; } + @Override + public boolean isEnabledByDefault(final Settings settings) { + return super.isEnabledByDefault(settings) && DiscoveryNode.isDataNode(settings); + } + }; public Transform(Settings settings) { @@ -335,7 +341,7 @@ public Settings additionalSettings() { Settings.Builder additionalSettings = Settings.builder(); - additionalSettings.put(transformEnabledNodeAttribute, TRANSFORM_ENABLED_NODE.get(settings)); + additionalSettings.put(transformEnabledNodeAttribute, DiscoveryNode.hasRole(settings, Transform.TRANSFORM_ROLE)); return additionalSettings.build(); } diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportPreviewTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportPreviewTransformAction.java index 59982d60ea67b..d53da51981acf 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportPreviewTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportPreviewTransformAction.java @@ -20,6 +20,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.inject.Inject; @@ -34,7 +35,6 @@ import org.elasticsearch.license.LicenseUtils; import org.elasticsearch.license.RemoteClusterLicenseChecker; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.node.Node; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.search.aggregations.Aggregations; import org.elasticsearch.search.aggregations.bucket.composite.CompositeAggregation; @@ -121,7 +121,7 @@ protected TransportPreviewTransformAction( this.sourceDestValidator = new SourceDestValidator( indexNameExpressionResolver, transportService.getRemoteClusterService(), - Node.NODE_REMOTE_CLUSTER_CLIENT.get(settings) + DiscoveryNode.isRemoteClusterClient(settings) ? new RemoteClusterLicenseChecker(client, XPackLicenseState::isTransformAllowedForOperationMode) : null, clusterService.getNodeName(), diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportPutTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportPutTransformAction.java index 1942dfe830bbc..1f88ef1ca9fff 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportPutTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportPutTransformAction.java @@ -21,6 +21,7 @@ import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; @@ -31,7 +32,6 @@ import org.elasticsearch.license.LicenseUtils; import org.elasticsearch.license.RemoteClusterLicenseChecker; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.node.Node; import org.elasticsearch.persistent.PersistentTasksCustomMetadata; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.tasks.Task; @@ -138,7 +138,7 @@ protected TransportPutTransformAction( this.sourceDestValidator = new SourceDestValidator( indexNameExpressionResolver, transportService.getRemoteClusterService(), - Node.NODE_REMOTE_CLUSTER_CLIENT.get(settings) + DiscoveryNode.isRemoteClusterClient(settings) ? new RemoteClusterLicenseChecker(client, XPackLicenseState::isTransformAllowedForOperationMode) : null, clusterService.getNodeName(), diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportStartTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportStartTransformAction.java index 6430e6ecd88c8..69cc1254a093e 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportStartTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportStartTransformAction.java @@ -21,6 +21,7 @@ import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.stream.StreamInput; @@ -31,7 +32,6 @@ import org.elasticsearch.license.LicenseUtils; import org.elasticsearch.license.RemoteClusterLicenseChecker; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.node.Node; import org.elasticsearch.persistent.PersistentTasksCustomMetadata; import org.elasticsearch.persistent.PersistentTasksService; import org.elasticsearch.rest.RestStatus; @@ -137,7 +137,7 @@ protected TransportStartTransformAction( this.sourceDestValidator = new SourceDestValidator( indexNameExpressionResolver, transportService.getRemoteClusterService(), - Node.NODE_REMOTE_CLUSTER_CLIENT.get(settings) + DiscoveryNode.isRemoteClusterClient(settings) ? new RemoteClusterLicenseChecker(client, XPackLicenseState::isTransformAllowedForOperationMode) : null, clusterService.getNodeName(), diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportUpdateTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportUpdateTransformAction.java index 6667847829971..12916e74dacdb 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportUpdateTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportUpdateTransformAction.java @@ -20,6 +20,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; @@ -30,7 +31,6 @@ import org.elasticsearch.license.LicenseUtils; import org.elasticsearch.license.RemoteClusterLicenseChecker; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.node.Node; import org.elasticsearch.persistent.PersistentTasksCustomMetadata; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.tasks.Task; @@ -144,7 +144,7 @@ protected TransportUpdateTransformAction( this.sourceDestValidator = new SourceDestValidator( indexNameExpressionResolver, transportService.getRemoteClusterService(), - Node.NODE_REMOTE_CLUSTER_CLIENT.get(settings) + DiscoveryNode.isRemoteClusterClient(settings) ? new RemoteClusterLicenseChecker(client, XPackLicenseState::isTransformAllowedForOperationMode) : null, clusterService.getNodeName(), diff --git a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/TransformTests.java b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/TransformTests.java index 260370cdbcf49..5bcf8ad666aee 100644 --- a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/TransformTests.java +++ b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/TransformTests.java @@ -10,6 +10,10 @@ import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.test.ESTestCase; +import java.util.Set; + +import static org.elasticsearch.test.NodeRoles.addRoles; +import static org.elasticsearch.test.NodeRoles.removeRoles; import static org.hamcrest.Matchers.equalTo; import static org.mockito.Mockito.mock; @@ -19,10 +23,20 @@ public void testNodeAttributes() { Settings.Builder builder = Settings.builder(); boolean transformEnabled = randomBoolean(); boolean transformPluginEnabled = randomBoolean(); + boolean useExplicitSetting = (transformEnabled && randomBoolean()) == false; + boolean useLegacySetting = useExplicitSetting && randomBoolean(); // randomly use explicit or default setting - if ((transformEnabled && randomBoolean()) == false) { - builder.put("node.transform", transformEnabled); + if (useExplicitSetting) { + if (useLegacySetting) { + builder.put("node.transform", transformEnabled); + } else { + if (transformEnabled) { + builder.put(addRoles(Set.of(Transform.TRANSFORM_ROLE))); + } else { + builder.put(removeRoles(Set.of(Transform.TRANSFORM_ROLE))); + } + } } if (transformPluginEnabled == false) { @@ -36,6 +50,9 @@ public void testNodeAttributes() { transformEnabled, Boolean.parseBoolean(transform.additionalSettings().get("node.attr.transform.node")) ); + if (transformPluginEnabled && useExplicitSetting && useLegacySetting) { + assertSettingDeprecationsAndWarnings(new String[]{"node.transform"}); + } } public void testNodeAttributesDirectlyGiven() { diff --git a/x-pack/plugin/voting-only-node/src/main/java/org/elasticsearch/cluster/coordination/VotingOnlyNodePlugin.java b/x-pack/plugin/voting-only-node/src/main/java/org/elasticsearch/cluster/coordination/VotingOnlyNodePlugin.java index 424ff63f76ca1..e4695cbc94b98 100644 --- a/x-pack/plugin/voting-only-node/src/main/java/org/elasticsearch/cluster/coordination/VotingOnlyNodePlugin.java +++ b/x-pack/plugin/voting-only-node/src/main/java/org/elasticsearch/cluster/coordination/VotingOnlyNodePlugin.java @@ -3,6 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ + package org.elasticsearch.cluster.coordination; import org.apache.lucene.util.SetOnce; @@ -20,13 +21,13 @@ import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.settings.Setting; +import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.env.Environment; import org.elasticsearch.env.NodeEnvironment; -import org.elasticsearch.node.Node; import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.DiscoveryPlugin; import org.elasticsearch.plugins.NetworkPlugin; @@ -57,16 +58,23 @@ public class VotingOnlyNodePlugin extends Plugin implements DiscoveryPlugin, NetworkPlugin, ActionPlugin { - public static final Setting VOTING_ONLY_NODE_SETTING - = Setting.boolSetting("node.voting_only", false, Setting.Property.NodeScope); + private static final Setting VOTING_ONLY_NODE_SETTING + = Setting.boolSetting("node.voting_only", false, Property.Deprecated, Property.NodeScope); private static final String VOTING_ONLY_ELECTION_STRATEGY = "supports_voting_only"; static DiscoveryNodeRole VOTING_ONLY_NODE_ROLE = new DiscoveryNodeRole("voting_only", "v") { + @Override - protected Setting roleSetting() { + public Setting legacySetting() { return VOTING_ONLY_NODE_SETTING; } + + @Override + public boolean isEnabledByDefault(final Settings settings) { + return false; + } + }; private final Settings settings; @@ -77,7 +85,7 @@ protected Setting roleSetting() { public VotingOnlyNodePlugin(Settings settings) { this.settings = settings; threadPool = new SetOnce<>(); - isVotingOnlyNode = VOTING_ONLY_NODE_SETTING.get(settings); + isVotingOnlyNode = DiscoveryNode.hasRole(settings, VOTING_ONLY_NODE_ROLE); } public static boolean isVotingOnlyNode(DiscoveryNode discoveryNode) { @@ -95,7 +103,7 @@ public List> getSettings() { @Override public Set getRoles() { - if (isVotingOnlyNode && Node.NODE_MASTER_SETTING.get(settings) == false) { + if (isVotingOnlyNode && DiscoveryNode.isMasterNode(settings) == false) { throw new IllegalStateException("voting-only node must be master-eligible"); } return Collections.singleton(VOTING_ONLY_NODE_ROLE); diff --git a/x-pack/plugin/voting-only-node/src/test/java/org/elasticsearch/cluster/coordination/VotingOnlyNodeCoordinatorTests.java b/x-pack/plugin/voting-only-node/src/test/java/org/elasticsearch/cluster/coordination/VotingOnlyNodeCoordinatorTests.java index 7545c752d41e2..6bdaad4c60bac 100644 --- a/x-pack/plugin/voting-only-node/src/test/java/org/elasticsearch/cluster/coordination/VotingOnlyNodeCoordinatorTests.java +++ b/x-pack/plugin/voting-only-node/src/test/java/org/elasticsearch/cluster/coordination/VotingOnlyNodeCoordinatorTests.java @@ -11,10 +11,8 @@ import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; -import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportInterceptor; -import org.junit.BeforeClass; import java.util.Collections; import java.util.Set; @@ -23,12 +21,6 @@ public class VotingOnlyNodeCoordinatorTests extends AbstractCoordinatorTestCase { - @BeforeClass - public static void setPossibleRolesWithVotingOnly() { - DiscoveryNode.setPossibleRoles( - Sets.union(DiscoveryNodeRole.BUILT_IN_ROLES, Sets.newHashSet(VotingOnlyNodePlugin.VOTING_ONLY_NODE_ROLE))); - } - @Override protected TransportInterceptor getTransportInterceptor(DiscoveryNode localNode, ThreadPool threadPool) { if (VotingOnlyNodePlugin.isVotingOnlyNode(localNode)) { diff --git a/x-pack/plugin/voting-only-node/src/test/java/org/elasticsearch/cluster/coordination/VotingOnlyNodePluginTests.java b/x-pack/plugin/voting-only-node/src/test/java/org/elasticsearch/cluster/coordination/VotingOnlyNodePluginTests.java index ce3c60b5ffe90..289478904652d 100644 --- a/x-pack/plugin/voting-only-node/src/test/java/org/elasticsearch/cluster/coordination/VotingOnlyNodePluginTests.java +++ b/x-pack/plugin/voting-only-node/src/test/java/org/elasticsearch/cluster/coordination/VotingOnlyNodePluginTests.java @@ -15,7 +15,10 @@ import java.util.Collection; import java.util.Collections; +import java.util.Set; +import static org.elasticsearch.test.NodeRoles.addRoles; +import static org.elasticsearch.test.NodeRoles.onlyRole; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.Matchers.hasSize; @@ -32,8 +35,7 @@ protected Collection> nodePlugins() { public void testRequireVotingOnlyNodeToBeMasterEligible() { internalCluster().setBootstrapMasterNodeIndex(0); IllegalStateException ise = expectThrows(IllegalStateException.class, () -> internalCluster().startNode(Settings.builder() - .put(Node.NODE_MASTER_SETTING.getKey(), false) - .put(VotingOnlyNodePlugin.VOTING_ONLY_NODE_SETTING.getKey(), true) + .put(onlyRole(VotingOnlyNodePlugin.VOTING_ONLY_NODE_ROLE)) .build())); assertThat(ise.getMessage(), containsString("voting-only node must be master-eligible")); } @@ -41,7 +43,7 @@ public void testRequireVotingOnlyNodeToBeMasterEligible() { public void testVotingOnlyNodeStats() throws Exception { internalCluster().setBootstrapMasterNodeIndex(0); internalCluster().startNodes(2); - internalCluster().startNode(Settings.builder().put(VotingOnlyNodePlugin.VOTING_ONLY_NODE_SETTING.getKey(), true)); + internalCluster().startNode(addRoles(Set.of(VotingOnlyNodePlugin.VOTING_ONLY_NODE_ROLE))); assertBusy(() -> assertThat(client().admin().cluster().prepareState().get().getState().getLastCommittedConfiguration().getNodeIds(), hasSize(3))); assertThat(client().admin().cluster().prepareClusterStats().get().getNodesStats().getCounts().getRoles().get( @@ -53,7 +55,7 @@ public void testVotingOnlyNodeStats() throws Exception { public void testPreferFullMasterOverVotingOnlyNodes() throws Exception { internalCluster().setBootstrapMasterNodeIndex(0); internalCluster().startNodes(2); - internalCluster().startNode(Settings.builder().put(VotingOnlyNodePlugin.VOTING_ONLY_NODE_SETTING.getKey(), true).build()); + internalCluster().startNode(addRoles(Set.of(VotingOnlyNodePlugin.VOTING_ONLY_NODE_ROLE))); internalCluster().startDataOnlyNodes(randomInt(2)); assertBusy(() -> assertThat( client().admin().cluster().prepareState().get().getState().getLastCommittedConfiguration().getNodeIds().size(), @@ -70,7 +72,7 @@ public void testPreferFullMasterOverVotingOnlyNodes() throws Exception { public void testBootstrapOnlyVotingOnlyNodes() throws Exception { internalCluster().setBootstrapMasterNodeIndex(0); - internalCluster().startNodes(Settings.builder().put(VotingOnlyNodePlugin.VOTING_ONLY_NODE_SETTING.getKey(), true).build(), + internalCluster().startNodes(addRoles(Set.of(VotingOnlyNodePlugin.VOTING_ONLY_NODE_ROLE)), Settings.EMPTY, Settings.EMPTY); assertBusy(() -> assertThat( client().admin().cluster().prepareState().get().getState().getLastCommittedConfiguration().getNodeIds().size(), @@ -82,7 +84,7 @@ public void testBootstrapOnlyVotingOnlyNodes() throws Exception { public void testBootstrapOnlySingleVotingOnlyNode() throws Exception { internalCluster().setBootstrapMasterNodeIndex(0); - internalCluster().startNode(Settings.builder().put(VotingOnlyNodePlugin.VOTING_ONLY_NODE_SETTING.getKey(), true) + internalCluster().startNode(Settings.builder().put(addRoles(Set.of(VotingOnlyNodePlugin.VOTING_ONLY_NODE_ROLE))) .put(Node.INITIAL_STATE_TIMEOUT_SETTING.getKey(), "0s").build()); internalCluster().startNode(); assertBusy(() -> assertThat(client().admin().cluster().prepareState().get().getState().getNodes().getSize(), equalTo(2))); @@ -94,7 +96,7 @@ public void testBootstrapOnlySingleVotingOnlyNode() throws Exception { public void testVotingOnlyNodesCannotBeMasterWithoutFullMasterNodes() throws Exception { internalCluster().setBootstrapMasterNodeIndex(0); internalCluster().startNode(); - internalCluster().startNodes(2, Settings.builder().put(VotingOnlyNodePlugin.VOTING_ONLY_NODE_SETTING.getKey(), true).build()); + internalCluster().startNodes(2, addRoles(Set.of(VotingOnlyNodePlugin.VOTING_ONLY_NODE_ROLE))); internalCluster().startDataOnlyNodes(randomInt(2)); assertBusy(() -> assertThat( client().admin().cluster().prepareState().get().getState().getLastCommittedConfiguration().getNodeIds().size(), diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java index 2c147dbe3ae67..ab16e28207281 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java @@ -18,6 +18,7 @@ import org.elasticsearch.client.OriginSettingClient; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.IndexTemplateMetadata; +import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Booleans; @@ -41,7 +42,6 @@ import org.elasticsearch.index.IndexModule; import org.elasticsearch.indices.SystemIndexDescriptor; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.node.Node; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.ReloadablePlugin; import org.elasticsearch.plugins.ScriptPlugin; @@ -526,7 +526,7 @@ public List> getExecutorBuilders(final Settings settings) { * @return A number between 5 and the number of processors */ static int getWatcherThreadPoolSize(final Settings settings) { - return getWatcherThreadPoolSize(Node.NODE_DATA_SETTING.get(settings), EsExecutors.allocatedProcessors(settings)); + return getWatcherThreadPoolSize(DiscoveryNode.isDataNode(settings), EsExecutors.allocatedProcessors(settings)); } static int getWatcherThreadPoolSize(final boolean isDataNode, final int allocatedProcessors) { diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/trigger/schedule/engine/TickerScheduleTriggerEngine.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/trigger/schedule/engine/TickerScheduleTriggerEngine.java index af68324c7c80a..5efdf1c7a4d3a 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/trigger/schedule/engine/TickerScheduleTriggerEngine.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/trigger/schedule/engine/TickerScheduleTriggerEngine.java @@ -7,11 +7,11 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.elasticsearch.cluster.node.DiscoveryNode; 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.node.Node; import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent; import org.elasticsearch.xpack.core.watcher.watch.Watch; import org.elasticsearch.xpack.watcher.trigger.schedule.Schedule; @@ -49,7 +49,7 @@ public class TickerScheduleTriggerEngine extends ScheduleTriggerEngine { public TickerScheduleTriggerEngine(Settings settings, ScheduleRegistry scheduleRegistry, Clock clock) { super(scheduleRegistry, clock); this.tickInterval = TICKER_INTERVAL_SETTING.get(settings); - this.ticker = new Ticker(Node.NODE_DATA_SETTING.get(settings)); + this.ticker = new Ticker(DiscoveryNode.isDataNode(settings)); } @Override diff --git a/x-pack/qa/multi-cluster-search-security/build.gradle b/x-pack/qa/multi-cluster-search-security/build.gradle index c7a6407960571..9a5eab3147f4d 100644 --- a/x-pack/qa/multi-cluster-search-security/build.gradle +++ b/x-pack/qa/multi-cluster-search-security/build.gradle @@ -23,7 +23,7 @@ task 'remote-cluster'(type: RestIntegTestTask) { testClusters.'remote-cluster' { testDistribution = 'DEFAULT' numberOfNodes = 2 - setting 'node.remote_cluster_client', "false" + setting 'node.roles', '[data,ingest,master]' setting 'xpack.security.enabled', 'true' setting 'xpack.watcher.enabled', 'false' setting 'xpack.ml.enabled', 'false' @@ -50,7 +50,6 @@ testClusters.'mixed-cluster' { testClusters.'remote-cluster'.getAllTransportPortURI().collect { "\"$it\"" }.toString() } setting 'cluster.remote.connections_per_cluster', "1" - setting 'node.remote_cluster_client', "true" user username: "test_user", password: "x-pack-test-password" } diff --git a/x-pack/qa/multi-cluster-tests-with-security/build.gradle b/x-pack/qa/multi-cluster-tests-with-security/build.gradle index 5733952f52d25..dea3e914ab4ef 100644 --- a/x-pack/qa/multi-cluster-tests-with-security/build.gradle +++ b/x-pack/qa/multi-cluster-tests-with-security/build.gradle @@ -24,7 +24,7 @@ task 'remote-cluster'(type: RestIntegTestTask) { testClusters.'remote-cluster' { testDistribution = 'DEFAULT' numberOfNodes = 2 - setting 'node.remote_cluster_client', "false" + setting 'node.roles', '[data,ingest,master]' setting 'xpack.security.enabled', 'true' setting 'xpack.watcher.enabled', 'false' setting 'xpack.license.self_generated.type', 'trial' @@ -49,7 +49,6 @@ testClusters.'mixed-cluster' { testClusters.'remote-cluster'.getAllTransportPortURI().collect { "\"$it\"" }.toString() } setting 'cluster.remote.connections_per_cluster', "1" - setting 'node.remote_cluster_client', "true" user username: "test_user", password: "x-pack-test-password" }