From e1bb90757b78502ea0eec9243cbb1d41af64a532 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 7 Apr 2020 22:43:00 -0400 Subject: [PATCH 01/31] Introduce node.roles setting Today we have individual settings for configuring node roles such as node.data and node.master. Additionally, roles are pluggable and we have used this to introduce roles such as node.ml and node.voting_only. As the number of roles is growing, managing these becomes harder for the user. For example, to create a master-only node, today a user has to configure: - node.data: false - node.ingest: false - node.remote_cluster_client: false - node.ml: false at a minimum if they are relying on defaults, but also add: - node.master: true - node.transform: false - node.voting_only: false If they want to be explicit. This is also challenging in cases where a user wants to have configure a coordinating-only node which requires disabling all roles, a list which we are adding to, requiring the user to keep checking whether a node has acquired any of these roles. This commit addresses this by adding a list setting node.roles for which a user has explicit control over the list of roles that a node has. If the setting is configured, the node has exactly the roles in the list, and not any additional roles. This means to configure a master-only node, the setting is merely 'node.roles: [master]', and to configure a coordinating-only node, the setting is merely: 'node.roles: []'. With this change we deprecate the existing 'node.*' settings such as 'node.data'. --- docs/reference/commands/node-tool.asciidoc | 33 ++-- .../GeoIpProcessorNonIngestNodeTests.java | 6 +- qa/multi-cluster-search/build.gradle | 3 +- qa/smoke-test-ingest-disabled/build.gradle | 2 +- .../cluster/node/DiscoveryNode.java | 88 +++++++-- .../cluster/node/DiscoveryNodeRole.java | 17 +- .../common/settings/ClusterSettings.java | 2 + .../elasticsearch/env/NodeEnvironment.java | 27 +-- .../java/org/elasticsearch/node/Node.java | 23 ++- .../elasticsearch/node/NodeRoleSettings.java | 45 +++++ .../transport/RemoteClusterService.java | 3 +- .../transport/TransportService.java | 2 +- .../admin/cluster/stats/ClusterStatsIT.java | 36 +++- .../cluster/SimpleDataNodesIT.java | 16 +- .../cluster/SpecificMasterNodesIT.java | 30 ++- .../cluster/UpdateSettingsValidationIT.java | 9 +- .../ClusterBootstrapServiceTests.java | 5 +- .../coordination/CoordinatorTests.java | 8 +- .../UnsafeBootstrapAndDetachCommandIT.java | 4 +- .../cluster/coordination/ZenDiscoveryIT.java | 11 +- .../cluster/node/DiscoveryNodeRoleIT.java | 2 +- .../node/DiscoveryNodeRoleSettingTests.java | 82 ++++++++ .../cluster/node/DiscoveryNodeRoleTests.java | 12 +- .../cluster/node/DiscoveryNodeTests.java | 15 +- .../cluster/node/DiscoveryNodesTests.java | 4 +- .../cluster/shards/ClusterShardLimitIT.java | 4 +- .../elasticsearch/env/NodeEnvironmentIT.java | 39 ++-- .../env/NodeEnvironmentTests.java | 39 ++-- .../env/NodeRepurposeCommandIT.java | 10 +- .../env/NodeRepurposeCommandTests.java | 25 +-- .../gateway/GatewayIndexStateIT.java | 10 +- .../GatewayMetaStatePersistedStateTests.java | 3 +- .../gateway/RecoverAfterNodesIT.java | 40 +--- .../index/store/CorruptedFileIT.java | 6 +- .../indices/IndicesServiceCloseTests.java | 3 +- .../DedicatedMasterGetFieldMappingIT.java | 7 +- .../store/IndicesStoreIntegrationIT.java | 11 +- .../org/elasticsearch/node/NodeTests.java | 3 +- .../DedicatedClusterSnapshotRestoreIT.java | 3 +- .../transport/ConnectionProfileTests.java | 14 +- .../transport/RemoteClusterClientTests.java | 11 +- .../transport/RemoteClusterServiceTests.java | 13 +- .../transport/RemoteClusterSettingsTests.java | 23 ++- .../AbstractCoordinatorTestCase.java | 2 +- .../test/ESSingleNodeTestCase.java | 3 +- .../org/elasticsearch/test/ESTestCase.java | 11 +- .../test/InternalTestCluster.java | 79 ++++---- .../org/elasticsearch/test/NodeRoles.java | 176 ++++++++++++++++++ .../license/LicenseServiceClusterTests.java | 8 +- .../license/LicensesTransportTests.java | 3 +- .../license/StartBasicLicenseTests.java | 8 +- .../license/StartTrialLicenseTests.java | 9 +- .../ilm/ShrunkShardsAllocatedStepTests.java | 23 ++- .../xpack/enrich/EnrichMultiNodeIT.java | 16 +- .../ilm/ExecuteStepsUpdateTaskTests.java | 11 +- .../xpack/ilm/IndexLifecycleServiceTests.java | 9 +- .../xpack/ilm/PolicyStepsRegistryTests.java | 25 +-- .../xpack/ml/MachineLearning.java | 4 +- .../action/TransportStartDatafeedAction.java | 4 +- .../xpack/ml/datafeed/DatafeedJobBuilder.java | 4 +- .../ml/datafeed/DatafeedJobBuilderTests.java | 5 +- .../integration/BasicDistributedJobsIT.java | 43 ++--- .../integration/MlDistributedFailureIT.java | 51 ++--- .../monitoring/MultiNodesStatsTests.java | 9 +- .../xpack/transform/Transform.java | 10 +- .../TransportPreviewTransformAction.java | 4 +- .../action/TransportPutTransformAction.java | 4 +- .../action/TransportStartTransformAction.java | 3 +- .../TransportUpdateTransformAction.java | 3 +- .../coordination/VotingOnlyNodePlugin.java | 16 +- .../VotingOnlyNodeCoordinatorTests.java | 2 +- .../VotingOnlyNodePluginTests.java | 16 +- .../elasticsearch/xpack/watcher/Watcher.java | 4 +- .../engine/TickerScheduleTriggerEngine.java | 4 +- .../build.gradle | 3 +- .../build.gradle | 3 +- 76 files changed, 835 insertions(+), 489 deletions(-) create mode 100644 server/src/main/java/org/elasticsearch/node/NodeRoleSettings.java create mode 100644 server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleSettingTests.java create mode 100644 test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java 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/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 125a341de6c11..06d03cd548741 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 7a818d542a76f..2f41823ea7256 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/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java index b2d45cd85fa91..57a271d341c4f 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -24,6 +24,8 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.settings.Setting; +import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.util.set.Sets; @@ -36,12 +38,16 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; +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; /** @@ -51,20 +57,26 @@ 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) { + final Setting> nodeRolesSetting = + Setting.listSetting("node.roles", List.of(role.roleName()), DiscoveryNode::getRoleFromRoleName, Property.NodeScope); + return getRolesFromSettings(settings, nodeRolesSetting, rolesToMap(DiscoveryNodeRole.BUILT_IN_ROLES.stream())).contains(role); + } + + public static boolean isMasterNode(final Settings settings) { + return hasRole(settings, DiscoveryNodeRole.MASTER_ROLE); } - public static boolean isDataNode(Settings settings) { - return Node.NODE_DATA_SETTING.get(settings); + public static boolean isDataNode(final Settings settings) { + return hasRole(settings, DiscoveryNodeRole.DATA_ROLE); } - public static boolean isIngestNode(Settings settings) { - return Node.NODE_INGEST_SETTING.get(settings); + public static boolean isIngestNode(final Settings settings) { + return hasRole(settings, DiscoveryNodeRole.INGEST_ROLE); } public static boolean isRemoteClusterClient(final Settings settings) { - return Node.NODE_REMOTE_CLUSTER_CLIENT.get(settings); + return hasRole(settings, DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE); } private final String nodeName; @@ -175,7 +187,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(); } @@ -194,7 +206,37 @@ 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()); + return getRolesFromSettings(settings, NODE_ROLES_SETTING, DiscoveryNode.roleMap); + } + + private static Set getRolesFromSettings( + final Settings settings, + final Setting> nodeRolesSetting, + final Map roleMap + ) { + if (nodeRolesSetting.exists(settings)) { + validateLegacySettings(settings, roleMap); + return Set.copyOf(nodeRolesSetting.get(settings)); + } else { + return roleMap.values() + .stream() + .filter(s -> 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().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); + } + } } /** @@ -220,7 +262,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 { @@ -442,22 +484,38 @@ 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().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; + DiscoveryNode.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 49e56100e7c9d..f746bbec13adf 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java @@ -20,6 +20,7 @@ package org.elasticsearch.cluster.node; import org.elasticsearch.common.settings.Setting; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.node.Node; @@ -64,6 +65,10 @@ public final boolean isKnownRole() { return isKnownRole; } + public boolean isEnabledByDefault(final Settings settings) { + return legacySetting().get(settings); + } + protected DiscoveryNodeRole(final String roleName, final String roleNameAbbreviation) { this(true, roleName, roleNameAbbreviation); } @@ -74,7 +79,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) { @@ -111,7 +116,7 @@ public final String toString() { public static final DiscoveryNodeRole DATA_ROLE = new DiscoveryNodeRole("data", "d") { @Override - protected Setting roleSetting() { + public Setting legacySetting() { return Node.NODE_DATA_SETTING; } @@ -123,7 +128,7 @@ protected Setting roleSetting() { public static final DiscoveryNodeRole INGEST_ROLE = new DiscoveryNodeRole("ingest", "i") { @Override - protected Setting roleSetting() { + public Setting legacySetting() { return Node.NODE_INGEST_SETTING; } @@ -135,7 +140,7 @@ protected Setting roleSetting() { public static final DiscoveryNodeRole MASTER_ROLE = new DiscoveryNodeRole("master", "m") { @Override - protected Setting roleSetting() { + public Setting legacySetting() { return Node.NODE_MASTER_SETTING; } @@ -144,7 +149,7 @@ protected Setting roleSetting() { public static final DiscoveryNodeRole REMOTE_CLUSTER_CLIENT_ROLE = new DiscoveryNodeRole("remote_cluster_client", "r") { @Override - protected Setting roleSetting() { + public Setting legacySetting() { return Node.NODE_REMOTE_CLUSTER_CLIENT; } @@ -176,7 +181,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 f31b311048e61..947ca38ed6ea6 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java @@ -92,6 +92,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; @@ -403,6 +404,7 @@ public void apply(Settings value, Settings current, Settings previous) { 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 d9d2109fd2104..0ce956f693f77 100644 --- a/server/src/main/java/org/elasticsearch/node/Node.java +++ b/server/src/main/java/org/elasticsearch/node/Node.java @@ -195,13 +195,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_DATA_SETTING = + Setting.boolSetting("node.data", true, Property.Deprecated, Property.NodeScope); public static final Setting NODE_MASTER_SETTING = - Setting.boolSetting("node.master", true, Property.NodeScope); + Setting.boolSetting("node.master", true, Property.Deprecated, Property.NodeScope); public static final Setting NODE_INGEST_SETTING = - Setting.boolSetting("node.ingest", true, Property.NodeScope); + Setting.boolSetting("node.ingest", true, Property.Deprecated, Property.NodeScope); public static final Setting NODE_REMOTE_CLUSTER_CLIENT = - Setting.boolSetting("node.remote_cluster_client", true, Property.NodeScope); + 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) -> @@ -307,14 +308,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 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 63c8cc80a46a9..f52cb0f8b597d 100644 --- a/server/src/main/java/org/elasticsearch/transport/TransportService.java +++ b/server/src/main/java/org/elasticsearch/transport/TransportService.java @@ -163,7 +163,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/action/admin/cluster/stats/ClusterStatsIT.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java index e5126203b988d..3af52b119ef36 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java +++ b/server/src/test/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/test/java/org/elasticsearch/cluster/SimpleDataNodesIT.java b/server/src/test/java/org/elasticsearch/cluster/SimpleDataNodesIT.java index 7d2274f2dbcc7..1cde76b58c8df 100644 --- a/server/src/test/java/org/elasticsearch/cluster/SimpleDataNodesIT.java +++ b/server/src/test/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/test/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java b/server/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java index 0e8f0f3f7e193..1ba5821fc90b7 100644 --- a/server/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java +++ b/server/src/test/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() @@ -133,12 +128,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\", " + @@ -146,4 +139,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/test/java/org/elasticsearch/cluster/UpdateSettingsValidationIT.java b/server/src/test/java/org/elasticsearch/cluster/UpdateSettingsValidationIT.java index 11cdb8afc4c41..912bc9e99b8e1 100644 --- a/server/src/test/java/org/elasticsearch/cluster/UpdateSettingsValidationIT.java +++ b/server/src/test/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/test/java/org/elasticsearch/cluster/coordination/ClusterBootstrapServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/coordination/ClusterBootstrapServiceTests.java index 6a7562ab8038a..1347aed2fadd6 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/ClusterBootstrapServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/ClusterBootstrapServiceTests.java @@ -24,8 +24,8 @@ 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.NodeRoles; import org.elasticsearch.test.transport.MockTransport; import org.elasticsearch.transport.TransportRequest; import org.elasticsearch.transport.TransportService; @@ -52,6 +52,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 +523,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 1a9efe189f4eb..2f7a42c9fdf2b 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java @@ -42,8 +42,8 @@ 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 org.elasticsearch.test.NodeRoles; import java.io.IOException; import java.util.Arrays; @@ -71,6 +71,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; @@ -1392,8 +1393,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/coordination/UnsafeBootstrapAndDetachCommandIT.java b/server/src/test/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java index 478305912395e..4c70f7fc681e4 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java @@ -34,6 +34,7 @@ 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.util.ArrayList; @@ -102,8 +103,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(NodeRoles.nonMasterNode(internalCluster().getDefaultSettings())) .build()); expectThrows(() -> unsafeBootstrap(environment), UnsafeBootstrapMasterCommand.NOT_MASTER_NODE_MSG); } diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/ZenDiscoveryIT.java b/server/src/test/java/org/elasticsearch/cluster/coordination/ZenDiscoveryIT.java index 2aa8ffd7e5a00..0c8d8c558d131 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/ZenDiscoveryIT.java +++ b/server/src/test/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/test/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleIT.java b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleIT.java index 06c4b14cae417..df921c7a56b1c 100644 --- a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleIT.java @@ -48,7 +48,7 @@ public AdditionalRolePlugin() { static DiscoveryNodeRole ADDITIONAL_ROLE = new DiscoveryNodeRole("additional", "a") { @Override - protected Setting roleSetting() { + public Setting legacySetting() { return NODE_ADDITIONAL_SETTING; } 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/cluster/shards/ClusterShardLimitIT.java b/server/src/test/java/org/elasticsearch/cluster/shards/ClusterShardLimitIT.java index c51f46457afff..7627d640017f7 100644 --- a/server/src/test/java/org/elasticsearch/cluster/shards/ClusterShardLimitIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/shards/ClusterShardLimitIT.java @@ -32,7 +32,6 @@ import org.elasticsearch.common.Priority; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; -import org.elasticsearch.node.Node; import org.elasticsearch.snapshots.SnapshotInfo; import org.elasticsearch.snapshots.SnapshotState; import org.elasticsearch.test.ESIntegTestCase; @@ -42,6 +41,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/test/java/org/elasticsearch/env/NodeEnvironmentIT.java b/server/src/test/java/org/elasticsearch/env/NodeEnvironmentIT.java index 17459bff4589d..fb8975d235538 100644 --- a/server/src/test/java/org/elasticsearch/env/NodeEnvironmentIT.java +++ b/server/src/test/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/test/java/org/elasticsearch/env/NodeEnvironmentTests.java b/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java index 890e9b0b7b273..24207f89e7986 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 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/NodeRepurposeCommandIT.java b/server/src/test/java/org/elasticsearch/env/NodeRepurposeCommandIT.java index 300191d3f2f3f..80ca00dc47a2c 100644 --- a/server/src/test/java/org/elasticsearch/env/NodeRepurposeCommandIT.java +++ b/server/src/test/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/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/GatewayIndexStateIT.java b/server/src/test/java/org/elasticsearch/gateway/GatewayIndexStateIT.java index 0a620a27a0f46..99c1e40efc50f 100644 --- a/server/src/test/java/org/elasticsearch/gateway/GatewayIndexStateIT.java +++ b/server/src/test/java/org/elasticsearch/gateway/GatewayIndexStateIT.java @@ -46,7 +46,6 @@ import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.indices.IndexClosedException; -import org.elasticsearch.node.Node; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; @@ -63,6 +62,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; @@ -215,7 +215,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(); @@ -224,7 +224,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(); } }); @@ -242,8 +242,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/test/java/org/elasticsearch/gateway/GatewayMetaStatePersistedStateTests.java b/server/src/test/java/org/elasticsearch/gateway/GatewayMetaStatePersistedStateTests.java index f85a36e5e887f..1c060e1693fba 100644 --- a/server/src/test/java/org/elasticsearch/gateway/GatewayMetaStatePersistedStateTests.java +++ b/server/src/test/java/org/elasticsearch/gateway/GatewayMetaStatePersistedStateTests.java @@ -58,6 +58,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; @@ -331,7 +332,7 @@ public void testDataOnlyNodePersistence() throws Exception { 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(); + nonMasterNode()).put(Node.NODE_NAME_SETTING.getKey(), "test").build(); final MockGatewayMetaState gateway = new MockGatewayMetaState(localNode); final TransportService transportService = mock(TransportService.class); TestThreadPool threadPool = new TestThreadPool("testMarkAcceptedConfigAsCommittedOnDataOnlyNode"); diff --git a/server/src/test/java/org/elasticsearch/gateway/RecoverAfterNodesIT.java b/server/src/test/java/org/elasticsearch/gateway/RecoverAfterNodesIT.java index 84188f80aaed3..d78fd5604c394 100644 --- a/server/src/test/java/org/elasticsearch/gateway/RecoverAfterNodesIT.java +++ b/server/src/test/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(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)); @@ -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(dataOnlyNode())); 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/test/java/org/elasticsearch/index/store/CorruptedFileIT.java b/server/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java index 8fe0b1db483a8..a40e4ab317c76 100644 --- a/server/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java +++ b/server/src/test/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; @@ -97,6 +96,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import static org.elasticsearch.common.util.CollectionUtils.iterableAsArrayList; +import static org.elasticsearch.test.NodeRoles.dataOnlyNode; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAllSuccessful; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; @@ -389,9 +389,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/test/java/org/elasticsearch/indices/IndicesServiceCloseTests.java b/server/src/test/java/org/elasticsearch/indices/IndicesServiceCloseTests.java index 2e270c2f5f5f6..d8624d04b5cd4 100644 --- a/server/src/test/java/org/elasticsearch/indices/IndicesServiceCloseTests.java +++ b/server/src/test/java/org/elasticsearch/indices/IndicesServiceCloseTests.java @@ -56,6 +56,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 { @@ -72,7 +73,7 @@ private Node startNode() throws NodeValidationException { .put(ScriptService.SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING.getKey(), "1000/1m") .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/indices/mapping/DedicatedMasterGetFieldMappingIT.java b/server/src/test/java/org/elasticsearch/indices/mapping/DedicatedMasterGetFieldMappingIT.java index f8fe05bc97b8a..b1c85d00cc77a 100644 --- a/server/src/test/java/org/elasticsearch/indices/mapping/DedicatedMasterGetFieldMappingIT.java +++ b/server/src/test/java/org/elasticsearch/indices/mapping/DedicatedMasterGetFieldMappingIT.java @@ -20,21 +20,18 @@ 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; import static org.elasticsearch.test.ESIntegTestCase.Scope; +import static org.elasticsearch.test.NodeRoles.nonDataNode; @ClusterScope(scope = Scope.TEST, numDataNodes = 0) 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().startNodes(nonDataNode(), Settings.EMPTY); } } diff --git a/server/src/test/java/org/elasticsearch/indices/store/IndicesStoreIntegrationIT.java b/server/src/test/java/org/elasticsearch/indices/store/IndicesStoreIntegrationIT.java index a019bca76e859..4a3604e2a10fe 100644 --- a/server/src/test/java/org/elasticsearch/indices/store/IndicesStoreIntegrationIT.java +++ b/server/src/test/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/test/java/org/elasticsearch/node/NodeTests.java b/server/src/test/java/org/elasticsearch/node/NodeTests.java index 3713dfdb52b9d..28e5a5356fd41 100644 --- a/server/src/test/java/org/elasticsearch/node/NodeTests.java +++ b/server/src/test/java/org/elasticsearch/node/NodeTests.java @@ -48,6 +48,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; @@ -146,7 +147,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/snapshots/DedicatedClusterSnapshotRestoreIT.java b/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java index 45ca1f0d545b5..87dd33d05f602 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java +++ b/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java @@ -105,6 +105,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; @@ -737,7 +738,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/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 9bea51ddfef5a..c9dd7a6a915d4 100644 --- a/server/src/test/java/org/elasticsearch/transport/RemoteClusterClientTests.java +++ b/server/src/test/java/org/elasticsearch/transport/RemoteClusterClientTests.java @@ -23,17 +23,20 @@ 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.transport.MockTransportService; import org.elasticsearch.threadpool.TestThreadPool; import org.elasticsearch.threadpool.ThreadPool; import java.util.Collections; +import java.util.Set; import java.util.concurrent.Semaphore; 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; @@ -53,7 +56,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)) { @@ -82,7 +85,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)) { @@ -123,7 +126,7 @@ public void onNodeDisconnected(DiscoveryNode node, Transport.Connection connecti } 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 633a668ecd2ae..3767226c3f7cf 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 = @@ -846,7 +849,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(); @@ -857,7 +860,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 b0bdfb9054c11..3af6721443da0 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 @@ -982,7 +982,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 2eb761af73ce5..05eedcd30238b 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()); } /** @@ -1430,4 +1424,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 19ea9ffdd3112..9856494d3cf7c 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -95,6 +95,7 @@ import org.elasticsearch.indices.recovery.RecoverySettings; import org.elasticsearch.node.MockNode; import org.elasticsearch.node.Node; +import org.elasticsearch.node.NodeRoleSettings; import org.elasticsearch.node.NodeService; import org.elasticsearch.node.NodeValidationException; import org.elasticsearch.plugins.Plugin; @@ -147,6 +148,13 @@ 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.dataNode; +import static org.elasticsearch.test.NodeRoles.dataOnlyNode; +import static org.elasticsearch.test.NodeRoles.masterNode; +import static org.elasticsearch.test.NodeRoles.masterOnlyNode; +import static org.elasticsearch.test.NodeRoles.noRoles; +import static org.elasticsearch.test.NodeRoles.nonDataNode; +import static org.elasticsearch.test.NodeRoles.nonMasterNode; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThanOrEqualTo; @@ -694,19 +702,17 @@ private String buildNodeName(int id, Settings settings) { * returns a suffix string based on the node role. If no explicit role is defined, the suffix will be empty */ 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 (NodeRoleSettings.NODE_ROLES_SETTING.exists(settings) == false) { + return ""; } - 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"; + + final List roles = NodeRoleSettings.NODE_ROLES_SETTING.get(settings); + + if (roles.isEmpty()) { + return "c"; } - return suffix; + + return roles.stream().sorted().map(DiscoveryNodeRole::roleNameAbbreviation).collect(Collectors.joining()); } @Override @@ -765,9 +771,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)); } /** @@ -840,7 +844,7 @@ public String getName() { } public boolean isMasterEligible() { - return Node.NODE_MASTER_SETTING.get(node.settings()); + return DiscoveryNode.isMasterNode(node.settings()); } Client client() { @@ -1034,29 +1038,26 @@ private synchronized void reset(boolean wipeData) throws IOException { 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); + extraSettings.put(masterOnlyNode()); settings.add(getNodeSettings(i, sharedNodesSeeds[i], extraSettings.build())); } for (int i = numSharedDedicatedMasterNodes; i < numSharedDedicatedMasterNodes + numSharedDataNodes; i++) { final Settings.Builder extraSettings = Settings.builder(); if (numSharedDedicatedMasterNodes > 0) { // 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(); + extraSettings.put(dataOnlyNode()); } 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()); @@ -1804,7 +1805,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++; @@ -1814,13 +1815,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)); } } @@ -1876,12 +1877,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; @@ -1893,7 +1894,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()); @@ -1902,7 +1903,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); } @@ -1927,8 +1928,8 @@ 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) + .put(masterNode(settings)) + .put(nonDataNode(settings)) .build(); return startNodes(numNodes, settings1); } @@ -1940,12 +1941,15 @@ 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(settings) + .put(nonMasterNode(settings)) + .put(dataNode(settings)) + .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() { @@ -1955,9 +1959,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); } @@ -1969,8 +1971,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..77ca158e368f8 --- /dev/null +++ b/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java @@ -0,0 +1,176 @@ +/* + * 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; + +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.toList())) + .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(), + NodeRoleSettings.NODE_ROLES_SETTING.get(settings).stream().filter(roles::contains).map(DiscoveryNodeRole::roleName).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.DATA_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/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..7fec4f1b155cd 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 @@ -27,6 +27,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 +50,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/test/java/org/elasticsearch/xpack/enrich/EnrichMultiNodeIT.java b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichMultiNodeIT.java index 63e713ae050d7..d5ccf7fee4dde 100644 --- a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichMultiNodeIT.java +++ b/x-pack/plugin/enrich/src/test/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/main/java/org/elasticsearch/xpack/ml/MachineLearning.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java index e5b80ec84ecda..967b2468446cd 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 @@ -346,12 +346,12 @@ public class MachineLearning extends Plugin implements SystemIndexPlugin, Analys 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); + 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; } 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 e49bb49604e54..84338fdf67f97 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 @@ -19,6 +19,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; @@ -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.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 9197633a37c34..50ff8c138e237 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 @@ -8,11 +8,11 @@ import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.client.Client; +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.xpack.core.action.util.QueryPage; import org.elasticsearch.xpack.core.ml.annotations.AnnotationPersister; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig; @@ -70,7 +70,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 48912da073c2e..58f8bce9f8400 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.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.action.util.QueryPage; @@ -34,6 +33,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; @@ -211,7 +211,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, @@ -223,7 +222,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/ml/src/test/java/org/elasticsearch/xpack/ml/integration/BasicDistributedJobsIT.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/BasicDistributedJobsIT.java index 02ac38a18ef61..1599b89251b58 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/BasicDistributedJobsIT.java +++ b/x-pack/plugin/ml/src/test/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); @@ -302,7 +303,7 @@ public void testMaxConcurrentJobAllocations() throws Exception { Runnable r = () -> { try { internalCluster() - .stopRandomNode(settings -> settings.getAsBoolean(MachineLearning.ML_ENABLED.getKey(), false)); + .stopRandomNode(settings -> DiscoveryNode.hasRole(settings, MachineLearning.ML_ROLE) == false); } catch (IOException e) { logger.error("error stopping node", e); } @@ -320,10 +321,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 +338,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 +412,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/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java index a855e207e360c..e0dab455c0133 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java @@ -11,6 +11,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; @@ -54,10 +55,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; public class MlDistributedFailureIT extends BaseMlIntegTestCase { @@ -83,15 +88,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, DiscoveryNodeRole.MASTER_ROLE))); ensureStableClusterOnAllNodes(2); run("lose-dedicated-master-node-job", () -> { logger.info("Stopping dedicated master node"); @@ -105,9 +104,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); }); @@ -127,15 +124,9 @@ 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()); + 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, DiscoveryNodeRole.MASTER_ROLE))); ensureStableClusterOnAllNodes(2); // index some datafeed data @@ -185,18 +176,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 @@ -301,15 +284,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, DiscoveryNodeRole.MASTER_ROLE))); ensureStableClusterOnAllNodes(2); // index some datafeed data 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 becbbe2e92ecc..f9fe591c9cfef 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 @@ -154,17 +154,23 @@ public class Transform extends Plugin implements SystemIndexPlugin, PersistentTa */ public static final Setting TRANSFORM_ENABLED_NODE = Setting.boolSetting( "node.transform", - settings -> Boolean.toString(XPackSettings.TRANSFORM_ENABLED.get(settings) && DiscoveryNode.isDataNode(settings)), + settings -> Boolean.toString(XPackSettings.TRANSFORM_ENABLED.get(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) { 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 9fef913443312..dc35d1d4fc148 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 e99ac52fae235..541bc8c4958ca 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 1dbafd387a9f7..746dbe80e2de7 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; @@ -137,7 +138,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 99710f1ab0309..df87144c53ed9 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 @@ -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.inject.Inject; import org.elasticsearch.common.io.stream.StreamInput; @@ -126,7 +127,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/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 85c9fd9f93622..99d3e46b57a40 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,15 +58,22 @@ 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); + = 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; @@ -94,7 +102,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..c013fe41e9d41 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 @@ -25,7 +25,7 @@ public class VotingOnlyNodeCoordinatorTests extends AbstractCoordinatorTestCase @BeforeClass public static void setPossibleRolesWithVotingOnly() { - DiscoveryNode.setPossibleRoles( + DiscoveryNode.setAdditionalRoles( Sets.union(DiscoveryNodeRole.BUILT_IN_ROLES, Sets.newHashSet(VotingOnlyNodePlugin.VOTING_ONLY_NODE_ROLE))); } 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 e6511f73b6a2d..f4dcf9c8d2ae4 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; @@ -521,7 +521,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.numberOfProcessors(settings)); + return getWatcherThreadPoolSize(DiscoveryNode.isDataNode(settings), EsExecutors.numberOfProcessors(settings)); } static int getWatcherThreadPoolSize(final boolean isDataNode, final int numberOfProcessors) { 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 75f8af8f44b65..3a99b563c8215 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.ilm.enabled', 'false' setting 'xpack.security.enabled', 'true' setting 'xpack.watcher.enabled', 'false' @@ -53,7 +53,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 7dc422447bd1a..a645054059cfc 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.ilm.enabled', 'false' setting 'xpack.security.enabled', 'true' setting 'xpack.watcher.enabled', 'false' @@ -52,7 +52,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" } From 254c5736c9ad1c366ff33a6cb5430f471cdd630b Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Thu, 9 Apr 2020 07:09:01 -0400 Subject: [PATCH 02/31] Checkstyle --- .../coordination/AbstractCoordinatorTestCase.java | 1 - .../java/org/elasticsearch/test/NodeRoles.java | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) 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 3af6721443da0..35a298b1e678e 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; diff --git a/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java b/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java index 77ca158e368f8..23838ab5c8b3d 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java +++ b/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java @@ -28,6 +28,9 @@ import java.util.function.Predicate; import java.util.stream.Collectors; +/** + * Utility methods for creating {@link Settings} instances defining a set of {@link DiscoveryNodeRole}. + */ public class NodeRoles { public static Settings onlyRole(final DiscoveryNodeRole role) { @@ -59,7 +62,11 @@ public static Settings removeRoles(final Settings settings, final Set Date: Thu, 9 Apr 2020 07:09:49 -0400 Subject: [PATCH 03/31] Fix test --- .../xpack/ml/integration/MlDistributedFailureIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java index e0dab455c0133..9a371b53a2a80 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java @@ -90,7 +90,7 @@ public void testLoseDedicatedMasterNode() throws Exception { logger.info("Starting dedicated master node..."); internalCluster().startMasterOnlyNode(); logger.info("Starting ml and data node..."); - String mlAndDataNode = internalCluster().startNode(onlyRoles(Set.of(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.MASTER_ROLE))); + 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"); From 7a78ed0ce0a6c5f3d78a1325321ae5728ff41556 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Thu, 9 Apr 2020 07:24:52 -0400 Subject: [PATCH 04/31] Remove imports --- .../xpack/transform/action/TransportStartTransformAction.java | 1 - .../xpack/transform/action/TransportUpdateTransformAction.java | 1 - 2 files changed, 2 deletions(-) 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 746dbe80e2de7..882f823c61b92 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 @@ -32,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; 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 df87144c53ed9..2e25889da1f64 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 @@ -28,7 +28,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; From bb82fb4e755c0c241193e7d53cd92793bcda4a2c Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Thu, 9 Apr 2020 07:27:42 -0400 Subject: [PATCH 05/31] Use constant --- .../java/org/elasticsearch/cluster/node/DiscoveryNode.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 57a271d341c4f..f73f495c5b2d9 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -58,8 +58,11 @@ public class DiscoveryNode implements Writeable, ToXContentFragment { static final String COORDINATING_ONLY = "coordinating_only"; public static boolean hasRole(final Settings settings, final DiscoveryNodeRole role) { - final Setting> nodeRolesSetting = - Setting.listSetting("node.roles", List.of(role.roleName()), DiscoveryNode::getRoleFromRoleName, Property.NodeScope); + final Setting> nodeRolesSetting = Setting.listSetting( + NODE_ROLES_SETTING.getKey(), + List.of(role.roleName()), + DiscoveryNode::getRoleFromRoleName, + Property.NodeScope); return getRolesFromSettings(settings, nodeRolesSetting, rolesToMap(DiscoveryNodeRole.BUILT_IN_ROLES.stream())).contains(role); } From 7fe22afd89651b8ab9613eb7c98572b67fc1f09d Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 13 Apr 2020 16:53:35 -0400 Subject: [PATCH 06/31] Fix test --- .../java/org/elasticsearch/cluster/node/DiscoveryNode.java | 2 +- .../indices/mapping/DedicatedMasterGetFieldMappingIT.java | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) 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 f73f495c5b2d9..65c23f1bd2d16 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -60,7 +60,7 @@ public class DiscoveryNode implements Writeable, ToXContentFragment { public static boolean hasRole(final Settings settings, final DiscoveryNodeRole role) { final Setting> nodeRolesSetting = Setting.listSetting( NODE_ROLES_SETTING.getKey(), - List.of(role.roleName()), + role.isEnabledByDefault(settings) ? List.of(role.roleName()) : List.of(), DiscoveryNode::getRoleFromRoleName, Property.NodeScope); return getRolesFromSettings(settings, nodeRolesSetting, rolesToMap(DiscoveryNodeRole.BUILT_IN_ROLES.stream())).contains(role); diff --git a/server/src/test/java/org/elasticsearch/indices/mapping/DedicatedMasterGetFieldMappingIT.java b/server/src/test/java/org/elasticsearch/indices/mapping/DedicatedMasterGetFieldMappingIT.java index b1c85d00cc77a..280aa5be8bf52 100644 --- a/server/src/test/java/org/elasticsearch/indices/mapping/DedicatedMasterGetFieldMappingIT.java +++ b/server/src/test/java/org/elasticsearch/indices/mapping/DedicatedMasterGetFieldMappingIT.java @@ -19,19 +19,18 @@ package org.elasticsearch.indices.mapping; -import org.elasticsearch.common.settings.Settings; import org.junit.Before; import static org.elasticsearch.test.ESIntegTestCase.ClusterScope; import static org.elasticsearch.test.ESIntegTestCase.Scope; -import static org.elasticsearch.test.NodeRoles.nonDataNode; @ClusterScope(scope = Scope.TEST, numDataNodes = 0) public class DedicatedMasterGetFieldMappingIT extends SimpleGetFieldMappingsIT { @Before public void before1() throws Exception { - internalCluster().startNodes(nonDataNode(), Settings.EMPTY); + internalCluster().startMasterOnlyNode(); + internalCluster().startNode(); } } From 86663e9a638838790139b0d3c40454a98c57f451 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 13 Apr 2020 16:55:10 -0400 Subject: [PATCH 07/31] Fix sorting order --- .../main/java/org/elasticsearch/test/InternalTestCluster.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9856494d3cf7c..9dc82349b97d6 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -712,7 +712,7 @@ private static String getRoleSuffix(Settings settings) { return "c"; } - return roles.stream().sorted().map(DiscoveryNodeRole::roleNameAbbreviation).collect(Collectors.joining()); + return roles.stream().map(DiscoveryNodeRole::roleNameAbbreviation).sorted().collect(Collectors.joining()); } @Override From 8fc5eb1ffbaf2baa71f8661cd3fde20e08408165 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 13 Apr 2020 16:58:19 -0400 Subject: [PATCH 08/31] Fix stopping ML nodes --- .../xpack/ml/integration/BasicDistributedJobsIT.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/BasicDistributedJobsIT.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/BasicDistributedJobsIT.java index 1599b89251b58..211af83ded2e0 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/BasicDistributedJobsIT.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/BasicDistributedJobsIT.java @@ -302,8 +302,7 @@ public void testMaxConcurrentJobAllocations() throws Exception { // fork so stopping all ml nodes proceeds quicker: Runnable r = () -> { try { - internalCluster() - .stopRandomNode(settings -> DiscoveryNode.hasRole(settings, MachineLearning.ML_ROLE) == false); + internalCluster().stopRandomNode(settings -> DiscoveryNode.hasRole(settings, MachineLearning.ML_ROLE)); } catch (IOException e) { logger.error("error stopping node", e); } From a6e899eb60bbbe6d08799a9bca45be02b97a6c11 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 13 Apr 2020 19:51:59 -0400 Subject: [PATCH 09/31] Fix ml test --- .../xpack/ml/integration/MlDistributedFailureIT.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java index 9a371b53a2a80..65d0ceb925bf6 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java @@ -123,10 +123,10 @@ public void testFullClusterRestart() throws Exception { public void testCloseUnassignedJobAndDatafeed() throws Exception { internalCluster().ensureAtMostNumDataNodes(0); - logger.info("Starting dedicated master node..."); - internalCluster().startMasterOnlyNode(); - logger.info("Starting ml and data node..."); + 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(onlyRoles(Set.of(DiscoveryNodeRole.DATA_ROLE, MachineLearning.ML_ROLE))); ensureStableClusterOnAllNodes(2); // index some datafeed data From 7c75d9bfcf4677ecc4dccaccdffc79ce6011d5e1 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 13 Apr 2020 19:57:06 -0400 Subject: [PATCH 10/31] Fix one more ML test --- .../xpack/ml/integration/MlDistributedFailureIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java index 65d0ceb925bf6..dc86f466ea915 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java @@ -286,7 +286,7 @@ public void testStopAndForceStopDatafeed() throws Exception { logger.info("Starting dedicated master node..."); internalCluster().startMasterOnlyNode(); logger.info("Starting ml and data node..."); - internalCluster().startNode(onlyRoles(Set.of(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.MASTER_ROLE))); + internalCluster().startNode(onlyRoles(Set.of(DiscoveryNodeRole.DATA_ROLE, MachineLearning.ML_ROLE))); ensureStableClusterOnAllNodes(2); // index some datafeed data From a431f370d0129cf2aa7c3930d6cefad66bb4ca5d Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 13 Apr 2020 20:12:43 -0400 Subject: [PATCH 11/31] Oh --- .../main/java/org/elasticsearch/cluster/node/DiscoveryNode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 65c23f1bd2d16..5476aea9afd6d 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -59,7 +59,7 @@ public class DiscoveryNode implements Writeable, ToXContentFragment { public static boolean hasRole(final Settings settings, final DiscoveryNodeRole role) { final Setting> nodeRolesSetting = Setting.listSetting( - NODE_ROLES_SETTING.getKey(), + "node.roles", // this can not refer to the initial setting or it could trigger initialization of the setting prematurely role.isEnabledByDefault(settings) ? List.of(role.roleName()) : List.of(), DiscoveryNode::getRoleFromRoleName, Property.NodeScope); From 7fea055176b43727ccdb44b9162e6c912385f700 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 13 Apr 2020 20:13:02 -0400 Subject: [PATCH 12/31] Fix typo --- .../main/java/org/elasticsearch/cluster/node/DiscoveryNode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5476aea9afd6d..88d2c7bc2682e 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -59,7 +59,7 @@ public class DiscoveryNode implements Writeable, ToXContentFragment { public static boolean hasRole(final Settings settings, final DiscoveryNodeRole role) { final Setting> nodeRolesSetting = Setting.listSetting( - "node.roles", // this can not refer to the initial setting or it could trigger initialization of the setting prematurely + "node.roles", // this can not refer to the official setting or it could trigger initialization of the setting prematurely role.isEnabledByDefault(settings) ? List.of(role.roleName()) : List.of(), DiscoveryNode::getRoleFromRoleName, Property.NodeScope); From e926535a9317d34b350083183a9c40d77cdc7efe Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 13 Apr 2020 20:15:50 -0400 Subject: [PATCH 13/31] Add comments --- .../java/org/elasticsearch/cluster/node/DiscoveryNode.java | 5 +++++ 1 file changed, 5 insertions(+) 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 88d2c7bc2682e..c923b0516c433 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -58,6 +58,11 @@ public class DiscoveryNode implements Writeable, ToXContentFragment { static final String COORDINATING_ONLY = "coordinating_only"; 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 use a fake version of the setting here. + */ final Setting> nodeRolesSetting = Setting.listSetting( "node.roles", // this can not refer to the official setting or it could trigger initialization of the setting prematurely role.isEnabledByDefault(settings) ? List.of(role.roleName()) : List.of(), From f7cef5c3ad4a64b021aa5ca521efbe076ce5b1a5 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 13 Apr 2020 21:13:52 -0400 Subject: [PATCH 14/31] Fix addRoles --- .../src/main/java/org/elasticsearch/test/NodeRoles.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java b/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java index 23838ab5c8b3d..f1aa957b6abb8 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java +++ b/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java @@ -27,6 +27,7 @@ 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}. @@ -79,9 +80,9 @@ public static Settings addRoles(final Settings settings, final Set Date: Tue, 14 Apr 2020 07:34:10 -0400 Subject: [PATCH 15/31] Fix imports --- .../main/java/org/elasticsearch/transport/TransportService.java | 1 - .../java/org/elasticsearch/license/LicensesTransportTests.java | 1 - 2 files changed, 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/transport/TransportService.java b/server/src/main/java/org/elasticsearch/transport/TransportService.java index f52cb0f8b597d..735445d54f660 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.tasks.Task; import org.elasticsearch.tasks.TaskManager; 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 7fec4f1b155cd..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; From c564977c4e0afde520f7ae2f2d1e1136650cb57f Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 14 Apr 2020 09:48:49 -0400 Subject: [PATCH 16/31] Fix imports --- .../cluster/coordination/ClusterBootstrapServiceTests.java | 1 - .../org/elasticsearch/cluster/coordination/CoordinatorTests.java | 1 - .../test/java/org/elasticsearch/index/store/CorruptedFileIT.java | 1 - 3 files changed, 3 deletions(-) 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 1347aed2fadd6..25d480498f1d2 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/ClusterBootstrapServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/ClusterBootstrapServiceTests.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.NodeRoles; import org.elasticsearch.test.transport.MockTransport; import org.elasticsearch.transport.TransportRequest; import org.elasticsearch.transport.TransportService; 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 2f7a42c9fdf2b..e0dcdb86a45a8 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java @@ -43,7 +43,6 @@ import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.gateway.GatewayService; import org.elasticsearch.test.MockLogAppender; -import org.elasticsearch.test.NodeRoles; import java.io.IOException; import java.util.Arrays; diff --git a/server/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java b/server/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java index a40e4ab317c76..0dce026b45e0a 100644 --- a/server/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java +++ b/server/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java @@ -96,7 +96,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import static org.elasticsearch.common.util.CollectionUtils.iterableAsArrayList; -import static org.elasticsearch.test.NodeRoles.dataOnlyNode; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAllSuccessful; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; From fed70b4dd6d2a7f781d3871d96246e7e468d061c Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 14 Apr 2020 10:22:34 -0400 Subject: [PATCH 17/31] Fix tests --- .../org/elasticsearch/test/InternalTestCluster.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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 9dc82349b97d6..de4a51463c82a 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -155,6 +155,7 @@ import static org.elasticsearch.test.NodeRoles.noRoles; 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; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThanOrEqualTo; @@ -1037,17 +1038,17 @@ 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(masterOnlyNode()); - 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(dataOnlyNode()); + settings.add(nodeSettings); } - settings.add(getNodeSettings(i, sharedNodesSeeds[i], extraSettings.build())); } for (int i = numSharedDedicatedMasterNodes + numSharedDataNodes; i < numSharedDedicatedMasterNodes + numSharedDataNodes + numSharedCoordOnlyNodes; i++) { From 29805900c6b41f16582e23ee517d5bc4523953c4 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 14 Apr 2020 11:07:19 -0400 Subject: [PATCH 18/31] Fix test bugs --- .../java/org/elasticsearch/cluster/node/DiscoveryNode.java | 6 +++--- .../org/elasticsearch/cluster/node/DiscoveryNodeRole.java | 2 +- .../java/org/elasticsearch/env/NodeEnvironmentTests.java | 2 +- .../src/main/java/org/elasticsearch/test/NodeRoles.java | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) 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 c923b0516c433..363e27d933818 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -228,14 +228,14 @@ private static Set getRolesFromSettings( } else { return roleMap.values() .stream() - .filter(s -> s.legacySetting().get(settings)) + .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().exists(settings)) { + 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]", @@ -510,7 +510,7 @@ public static Set getPossibleRoles() { } public static void setAdditionalRoles(final Set additionalRoles) { - assert additionalRoles.stream().allMatch(r -> r.legacySetting().isDeprecated()) : additionalRoles; + assert additionalRoles.stream().allMatch(r -> r.legacySetting() == null || r.legacySetting().isDeprecated()) : additionalRoles; final Map roleNameToPossibleRoles = 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 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 f746bbec13adf..c138228df58b8 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java @@ -66,7 +66,7 @@ public final boolean isKnownRole() { } public boolean isEnabledByDefault(final Settings settings) { - return legacySetting().get(settings); + return legacySetting() != null && legacySetting().get(settings); } protected DiscoveryNodeRole(final String roleName, final String roleNameAbbreviation) { diff --git a/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java b/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java index 24207f89e7986..223ad11739b51 100644 --- a/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java +++ b/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java @@ -490,7 +490,7 @@ private void verifyFailsOnMetadata(Settings settings, Path indexPath) { assertThat(ex.getMessage(), containsString(indexPath.resolve(MetadataStateFormat.STATE_DIR_NAME).toAbsolutePath().toString())); - assertThat(ex.getMessage(), startsWith("node does not have data and master roles 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/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java b/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java index f1aa957b6abb8..e05bd666e8775 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java +++ b/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java @@ -149,7 +149,7 @@ public static Settings masterNode() { } public static Settings masterNode(final Settings settings) { - return addRoles(settings, Set.of(DiscoveryNodeRole.DATA_ROLE)); + return addRoles(settings, Set.of(DiscoveryNodeRole.MASTER_ROLE)); } public static Settings masterOnlyNode() { From cf52fe8fe263edc2a0dfb52f0541f662a8a06cc8 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 14 Apr 2020 15:19:31 -0400 Subject: [PATCH 19/31] Fix more tests --- .../cluster/node/DiscoveryNode.java | 29 ++++--------- .../test/InternalTestCluster.java | 41 ++++++++----------- .../org/elasticsearch/test/NodeRoles.java | 2 +- .../xpack/transform/Transform.java | 2 +- .../xpack/transform/TransformTests.java | 21 +++++++++- .../coordination/VotingOnlyNodePlugin.java | 2 +- 6 files changed, 49 insertions(+), 48 deletions(-) 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 363e27d933818..7864c95c70618 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -24,8 +24,6 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.common.settings.Setting; -import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.util.set.Sets; @@ -61,14 +59,13 @@ public static boolean hasRole(final Settings settings, final DiscoveryNodeRole r /* * 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 use a fake version of the setting here. + * to avoid initializing this setting prematurely, we avoid using the actual node roles setting instance here. */ - final Setting> nodeRolesSetting = Setting.listSetting( - "node.roles", // this can not refer to the official setting or it could trigger initialization of the setting prematurely - role.isEnabledByDefault(settings) ? List.of(role.roleName()) : List.of(), - DiscoveryNode::getRoleFromRoleName, - Property.NodeScope); - return getRolesFromSettings(settings, nodeRolesSetting, rolesToMap(DiscoveryNodeRole.BUILT_IN_ROLES.stream())).contains(role); + if (settings.hasValue("node.roles")) { + return settings.getAsList("node.roles").contains(role.roleName()); + } else { + return role.legacySetting() != null && role.legacySetting().get(settings); + } } public static boolean isMasterNode(final Settings settings) { @@ -214,17 +211,9 @@ public static DiscoveryNode createLocal(Settings settings, TransportAddress publ /** extract node roles from the given settings */ public static Set getRolesFromSettings(final Settings settings) { - return getRolesFromSettings(settings, NODE_ROLES_SETTING, DiscoveryNode.roleMap); - } - - private static Set getRolesFromSettings( - final Settings settings, - final Setting> nodeRolesSetting, - final Map roleMap - ) { - if (nodeRolesSetting.exists(settings)) { + if (NODE_ROLES_SETTING.exists(settings)) { validateLegacySettings(settings, roleMap); - return Set.copyOf(nodeRolesSetting.get(settings)); + return Set.copyOf(NODE_ROLES_SETTING.get(settings)); } else { return roleMap.values() .stream() @@ -519,7 +508,7 @@ public static void setAdditionalRoles(final Set additionalRol .collect(Collectors.toUnmodifiableMap(DiscoveryNodeRole::roleNameAbbreviation, Function.identity())); assert roleNameToPossibleRoles.size() == roleNameAbbreviationToPossibleRoles.size() : "roles by name [" + roleNameToPossibleRoles + "], roles by name abbreviation [" + roleNameAbbreviationToPossibleRoles + "]"; - DiscoveryNode.roleMap = roleNameToPossibleRoles; + roleMap = roleNameToPossibleRoles; } public static Set getPossibleRoleNames() { 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 de4a51463c82a..64f3cfdfe0f8b 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -95,7 +95,6 @@ import org.elasticsearch.indices.recovery.RecoverySettings; import org.elasticsearch.node.MockNode; import org.elasticsearch.node.Node; -import org.elasticsearch.node.NodeRoleSettings; import org.elasticsearch.node.NodeService; import org.elasticsearch.node.NodeValidationException; import org.elasticsearch.plugins.Plugin; @@ -148,13 +147,10 @@ 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.dataNode; import static org.elasticsearch.test.NodeRoles.dataOnlyNode; -import static org.elasticsearch.test.NodeRoles.masterNode; import static org.elasticsearch.test.NodeRoles.masterOnlyNode; import static org.elasticsearch.test.NodeRoles.noRoles; -import static org.elasticsearch.test.NodeRoles.nonDataNode; -import static org.elasticsearch.test.NodeRoles.nonMasterNode; +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; @@ -703,17 +699,19 @@ private String buildNodeName(int id, Settings settings) { * returns a suffix string based on the node role. If no explicit role is defined, the suffix will be empty */ private static String getRoleSuffix(Settings settings) { - if (NodeRoleSettings.NODE_ROLES_SETTING.exists(settings) == false) { - return ""; + String suffix = ""; + if (settings.hasValue("node.roles") && DiscoveryNode.hasRole(settings, DiscoveryNodeRole.MASTER_ROLE)) { + suffix = suffix + DiscoveryNodeRole.MASTER_ROLE.roleNameAbbreviation(); } - - final List roles = NodeRoleSettings.NODE_ROLES_SETTING.get(settings); - - if (roles.isEmpty()) { - return "c"; + if (settings.hasValue("node.roles") && DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE)) { + suffix = suffix + DiscoveryNodeRole.DATA_ROLE.roleNameAbbreviation(); } - - return roles.stream().map(DiscoveryNodeRole::roleNameAbbreviation).sorted().collect(Collectors.joining()); + if (settings.hasValue("node.roles") + && DiscoveryNode.hasRole(settings, DiscoveryNodeRole.MASTER_ROLE) == false + && DiscoveryNode.hasRole(settings, DiscoveryNodeRole.MASTER_ROLE) == false) { + suffix = suffix + "c"; + } + return suffix; } @Override @@ -1927,12 +1925,11 @@ public List startMasterOnlyNodes(int numNodes) { } public List startMasterOnlyNodes(int numNodes, Settings settings) { - Settings settings1 = Settings.builder() - .put(settings) - .put(masterNode(settings)) - .put(nonDataNode(settings)) - .build(); - return startNodes(numNodes, settings1); + return startNodes( + numNodes, + Settings.builder() + .put(onlyRole(settings, DiscoveryNodeRole.MASTER_ROLE)) + .build()); } public List startDataOnlyNodes(int numNodes) { @@ -1943,9 +1940,7 @@ public List startDataOnlyNodes(int numNodes, Settings settings) { return startNodes( numNodes, Settings.builder() - .put(settings) - .put(nonMasterNode(settings)) - .put(dataNode(settings)) + .put(onlyRole(settings, DiscoveryNodeRole.DATA_ROLE)) .build()); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java b/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java index e05bd666e8775..f3ec462743fb8 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java +++ b/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java @@ -51,7 +51,7 @@ public static Settings onlyRoles(final Settings settings, final Set(); - isVotingOnlyNode = VOTING_ONLY_NODE_SETTING.get(settings); + isVotingOnlyNode = DiscoveryNode.hasRole(settings, VOTING_ONLY_NODE_ROLE); } public static boolean isVotingOnlyNode(DiscoveryNode discoveryNode) { From 6f26ea67dd33c8711c86ad27c6d781f50a9b110e Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 14 Apr 2020 21:54:02 -0400 Subject: [PATCH 20/31] Fix tests, make node.X settings private --- .../UnsafeBootstrapMasterCommand.java | 4 ++-- .../cluster/node/DiscoveryNodeRole.java | 14 +++++++++----- .../common/settings/ClusterSettings.java | 4 ---- .../java/org/elasticsearch/node/Node.java | 16 +++++++++++----- .../UnsafeBootstrapAndDetachCommandIT.java | 4 ++-- .../cluster/node/DiscoveryNodeRoleIT.java | 19 +++++++++++++++---- .../gateway/RecoverAfterNodesIT.java | 4 ++-- .../elasticsearch/ingest/IngestClientIT.java | 3 ++- .../test/InternalTestCluster.java | 2 +- .../xpack/ccr/FollowerFailOverIT.java | 6 +++++- .../xpack/ml/MachineLearning.java | 4 ++-- .../xpack/transform/Transform.java | 2 +- .../coordination/VotingOnlyNodePlugin.java | 2 +- 13 files changed, 53 insertions(+), 31 deletions(-) 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 a019f1478707e..3982dd7c71860 100644 --- a/server/src/main/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapMasterCommand.java +++ b/server/src/main/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapMasterCommand.java @@ -23,13 +23,13 @@ import org.elasticsearch.cli.Terminal; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.settings.Setting; 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; @@ -69,7 +69,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/DiscoveryNodeRole.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java index c138228df58b8..e79ecbfdf5a03 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java @@ -20,9 +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; @@ -117,7 +117,8 @@ public final String toString() { @Override public Setting legacySetting() { - return Node.NODE_DATA_SETTING; + // 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); } }; @@ -129,7 +130,8 @@ public Setting legacySetting() { @Override public Setting legacySetting() { - return Node.NODE_INGEST_SETTING; + // 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); } }; @@ -141,7 +143,8 @@ public Setting legacySetting() { @Override public Setting legacySetting() { - return Node.NODE_MASTER_SETTING; + // 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); } }; @@ -150,7 +153,8 @@ public Setting legacySetting() { @Override public Setting legacySetting() { - return Node.NODE_REMOTE_CLUSTER_CLIENT; + // 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); } }; 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 947ca38ed6ea6..f47da5d0d81a0 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java @@ -399,10 +399,6 @@ 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, diff --git a/server/src/main/java/org/elasticsearch/node/Node.java b/server/src/main/java/org/elasticsearch/node/Node.java index dbbcba4b1164c..67300ee2a3707 100644 --- a/server/src/main/java/org/elasticsearch/node/Node.java +++ b/server/src/main/java/org/elasticsearch/node/Node.java @@ -195,13 +195,13 @@ 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 = + private static final Setting NODE_DATA_SETTING = Setting.boolSetting("node.data", true, Property.Deprecated, Property.NodeScope); - public static final Setting NODE_MASTER_SETTING = + private static final Setting NODE_MASTER_SETTING = Setting.boolSetting("node.master", true, Property.Deprecated, Property.NodeScope); - public static final Setting NODE_INGEST_SETTING = + private static final Setting NODE_INGEST_SETTING = Setting.boolSetting("node.ingest", true, Property.Deprecated, Property.NodeScope); - public static final Setting NODE_REMOTE_CLUSTER_CLIENT = + 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); @@ -335,7 +335,13 @@ protected Node(final Environment initialEnvironment, DeprecationLogger.setThreadContext(threadPool.getThreadContext()); resourcesToClose.add(() -> DeprecationLogger.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/test/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java b/server/src/test/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java index 4c70f7fc681e4..4eac4d71ca671 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java @@ -34,7 +34,6 @@ 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.util.ArrayList; @@ -44,6 +43,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; @@ -103,7 +103,7 @@ private void expectThrows(ThrowingRunnable runnable, String message) { public void testBootstrapNotMasterEligible() { final Environment environment = TestEnvironment.newEnvironment(Settings.builder() - .put(NodeRoles.nonMasterNode(internalCluster().getDefaultSettings())) + .put(nonMasterNode(internalCluster().getDefaultSettings())) .build()); expectThrows(() -> unsafeBootstrap(environment), UnsafeBootstrapMasterCommand.NOT_MASTER_NODE_MSG); } diff --git a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleIT.java b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleIT.java index df921c7a56b1c..b8c60cc81fdc0 100644 --- a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleIT.java +++ b/server/src/test/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,7 +46,7 @@ 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") { @@ -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/test/java/org/elasticsearch/gateway/RecoverAfterNodesIT.java b/server/src/test/java/org/elasticsearch/gateway/RecoverAfterNodesIT.java index d78fd5604c394..9a79b62de59af 100644 --- a/server/src/test/java/org/elasticsearch/gateway/RecoverAfterNodesIT.java +++ b/server/src/test/java/org/elasticsearch/gateway/RecoverAfterNodesIT.java @@ -112,7 +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(dataOnlyNode())); + 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)); @@ -122,7 +122,7 @@ 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(dataOnlyNode())); + 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)); diff --git a/server/src/test/java/org/elasticsearch/ingest/IngestClientIT.java b/server/src/test/java/org/elasticsearch/ingest/IngestClientIT.java index 512962325a27c..36023ba1465c7 100644 --- a/server/src/test/java/org/elasticsearch/ingest/IngestClientIT.java +++ b/server/src/test/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/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java index 64f3cfdfe0f8b..e4664e397f5bf 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -708,7 +708,7 @@ private static String getRoleSuffix(Settings settings) { } if (settings.hasValue("node.roles") && DiscoveryNode.hasRole(settings, DiscoveryNodeRole.MASTER_ROLE) == false - && DiscoveryNode.hasRole(settings, DiscoveryNodeRole.MASTER_ROLE) == false) { + && DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE) == false) { suffix = suffix + "c"; } return suffix; diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/FollowerFailOverIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/FollowerFailOverIT.java index dbc42d1589077..570281a43ac76 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/FollowerFailOverIT.java +++ b/x-pack/plugin/ccr/src/test/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/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 eb07a38c21bc5..78c731c259d62 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 @@ -347,7 +347,7 @@ public class MachineLearning extends Plugin implements SystemIndexPlugin, Analys // 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 = + 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") { @@ -480,7 +480,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/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 a113a3c29d084..6c3c86eade025 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 @@ -152,7 +152,7 @@ public class Transform extends Plugin implements SystemIndexPlugin, PersistentTa * Setting whether transform (the coordinator task) can run on this node and REST API's are available, * respects xpack.transform.enabled (for the whole plugin) as fallback */ - public static final Setting TRANSFORM_ENABLED_NODE = Setting.boolSetting( + private static final Setting TRANSFORM_ENABLED_NODE = Setting.boolSetting( "node.transform", settings -> Boolean.toString(XPackSettings.TRANSFORM_ENABLED.get(settings)), Property.Deprecated, 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 e16daeee90dd3..3659212bcc35a 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 @@ -57,7 +57,7 @@ public class VotingOnlyNodePlugin extends Plugin implements DiscoveryPlugin, NetworkPlugin, ActionPlugin { - public static final Setting VOTING_ONLY_NODE_SETTING + 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"; From 3e8667438ebb9e5b653b04a41e2bbcab0a875d22 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 14 Apr 2020 22:58:53 -0400 Subject: [PATCH 21/31] Remove unneeded role setting --- .../coordination/VotingOnlyNodeCoordinatorTests.java | 8 -------- 1 file changed, 8 deletions(-) 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 c013fe41e9d41..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.setAdditionalRoles( - 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)) { From c260abdb0e899f77a1ac5c7127dd4d1a708b4afb Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Thu, 16 Apr 2020 10:43:31 -0400 Subject: [PATCH 22/31] Docs --- docs/reference/modules/node.asciidoc | 288 ++++++--------------------- 1 file changed, 61 insertions(+), 227 deletions(-) diff --git a/docs/reference/modules/node.asciidoc b/docs/reference/modules/node.asciidoc index bcc1f8021514d..fc3bf8610a0d7 100644 --- a/docs/reference/modules/node.asciidoc +++ b/docs/reference/modules/node.asciidoc @@ -22,40 +22,36 @@ 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 have the `ingest` role on master` and `data`. <>:: -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 `xpack.transform.enabled` and `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 `xpack.transform.enabled` and the `transform` role. If you want +to use {transforms}, there must be at least one {transform} node in your +cluster. For more information, see <> and <>. [NOTE] [[coordinating-node]] @@ -74,10 +70,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. =============================================== @@ -115,43 +110,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> -xpack.transform.enabled: true <8> -node.remote_client_client: false <9> +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> The `xpack.transform.enabled` setting is enabled by default. -<9> 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). [float] [[voting-only-node]] @@ -169,19 +133,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 @@ -202,25 +166,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> -xpack.transform.enabled: true <8> -node.remote_cluster_client: false <9> +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> The `xpack.transform.enabled` setting is enabled by default. -<9> Disable remote cluster connections (enabled by default). [float] [[data-node]] @@ -234,39 +181,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> -xpack.transform.enabled: true <7> -node.remote_cluster_client: false <8> +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> The `xpack.transform.enabled` setting is enabled by default. -<8> 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). [float] [[node-ingest-node]] @@ -277,39 +196,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). [float] [[coordinating-only-node]] @@ -332,51 +224,20 @@ 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> -xpack.transform.enabled: true <8> -node.remote_cluster_client: false <9> -------------------- -<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> The `xpack.transform.enabled` setting is enabled by default. -<9> 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). [float] [[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 @@ -389,25 +250,12 @@ 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> -xpack.transform.enabled: true <8> -node.remote_cluster_client: false <9> +node.roles: [ ml ] +xpack.ml.enabled: true <1> +xpack.transform.enabled: true <2> ------------------- -<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> The `xpack.transform.enabled` setting is enabled by default. -<9> Disable remote cluster connections (enabled by default). +<1> The `xpack.ml.enabled` setting is enabled by default. +<2> The `xpack.transform.enabled` setting is enabled by default. [discrete] [[transform-node]] @@ -418,32 +266,19 @@ node.remote_cluster_client: false <9> If you want to use {transforms} in your cluster, you must have `xpack.transform.enabled` set to `true` on all master-eligible nodes and all data nodes. If you want to use {transforms} in clients (including {kib}), it -must also be enabled on all coordinating nodes. You must also 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 <>. +must also be enabled on all coordinating nodes. You must also have at least one +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> -xpack.transform.enabled: true <7> -node.remote_cluster_client: false <8> +node.roles: [ transform ] +xpack.transform.enabled: true <1> ------------------- -<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> Enable the `xpack.transform.enabled` setting. -<8> Disable remote cluster connections. +<1> Enable the `xpack.transform.enabled` setting. [float] [[change-node-role]] @@ -463,26 +298,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 From f7ed0ea1b2eee6e456e7623ffc755344b3a5cf06 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Thu, 16 Apr 2020 12:00:43 -0400 Subject: [PATCH 23/31] Handle un-set roles and legacy setting --- .../java/org/elasticsearch/cluster/node/DiscoveryNode.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 7864c95c70618..495e0ba7dc4ec 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -63,8 +63,10 @@ public static boolean hasRole(final Settings settings, final DiscoveryNodeRole r */ 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.legacySetting() != null && role.legacySetting().get(settings); + return role.isEnabledByDefault(settings); } } From cf2bae942273427cf49b8340943b634b2de9c403 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 17 Jun 2020 22:55:09 -0400 Subject: [PATCH 24/31] Fix leftover merge conflicts --- docs/reference/modules/node.asciidoc | 156 +-------------------------- 1 file changed, 4 insertions(+), 152 deletions(-) diff --git a/docs/reference/modules/node.asciidoc b/docs/reference/modules/node.asciidoc index 5203729a547f6..c0d43ea3b826c 100644 --- a/docs/reference/modules/node.asciidoc +++ b/docs/reference/modules/node.asciidoc @@ -112,42 +112,8 @@ To create a dedicated master-eligible node, set: [source,yaml] ------------------- -<<<<<<< HEAD node.roles: [ master ] ------------------- -======= -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> -------------------- -<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). ->>>>>>> elastic [[voting-only-node]] ===== Voting-only master-eligible node @@ -197,28 +163,8 @@ dedicated voting-only master-eligible node in the {default-dist}, set: [source,yaml] ------------------- -<<<<<<< HEAD node.roles: [ master, voting_only ] ------------------- -======= -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> -------------------- -<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). ->>>>>>> elastic [[data-node]] ==== Data node @@ -234,25 +180,8 @@ and data roles. To create a dedicated data node, set: [source,yaml] ------------------- -<<<<<<< HEAD node.roles: [ data ] ------------------- -======= -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> -------------------- -<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] @@ -303,33 +232,7 @@ 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. -<<<<<<< HEAD To create a dedicated coordinating node, set: -======= -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: ->>>>>>> elastic [source,yaml] ------------------- @@ -354,78 +257,27 @@ To create a dedicated {ml} node in the {default-dist}, set: [source,yaml] ------------------- -<<<<<<< HEAD node.roles: [ ml ] xpack.ml.enabled: true <1> -xpack.transform.enabled: true <2> ------------------- <1> The `xpack.ml.enabled` setting is enabled by default. -<2> The `xpack.transform.enabled` setting is enabled by default. -======= -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> -------------------- -<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). ->>>>>>> elastic [[transform-node]] ==== [xpack]#{transform-cap} node# {transform-cap} nodes run {transforms} and handle {transform} API requests. -<<<<<<< HEAD -If you want to use {transforms} in your cluster, you must have -`xpack.transform.enabled` set to `true` on all master-eligible nodes and all -data nodes. 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 -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 -======= -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 ->>>>>>> elastic -<>. +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] ------------------- -<<<<<<< HEAD node.roles: [ transform ] -xpack.transform.enabled: true <1> ------------------- -<1> Enable the `xpack.transform.enabled` setting. -======= -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> -------------------- -<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. ->>>>>>> elastic [[change-node-role]] ==== Changing the role of a node From 1478a20c9812a80cf3865bb0897dde0a9db49b25 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 17 Jun 2020 23:00:04 -0400 Subject: [PATCH 25/31] Fix use of legacy settings --- x-pack/qa/multi-cluster-search-security/build.gradle | 1 - x-pack/qa/multi-cluster-tests-with-security/build.gradle | 1 - 2 files changed, 2 deletions(-) diff --git a/x-pack/qa/multi-cluster-search-security/build.gradle b/x-pack/qa/multi-cluster-search-security/build.gradle index 50b4dc2118d00..9a5eab3147f4d 100644 --- a/x-pack/qa/multi-cluster-search-security/build.gradle +++ b/x-pack/qa/multi-cluster-search-security/build.gradle @@ -24,7 +24,6 @@ testClusters.'remote-cluster' { testDistribution = 'DEFAULT' numberOfNodes = 2 setting 'node.roles', '[data,ingest,master]' - setting 'node.remote_cluster_client', "false" setting 'xpack.security.enabled', 'true' setting 'xpack.watcher.enabled', 'false' setting 'xpack.ml.enabled', 'false' 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 b4f6b2bb1cdeb..dea3e914ab4ef 100644 --- a/x-pack/qa/multi-cluster-tests-with-security/build.gradle +++ b/x-pack/qa/multi-cluster-tests-with-security/build.gradle @@ -25,7 +25,6 @@ testClusters.'remote-cluster' { testDistribution = 'DEFAULT' numberOfNodes = 2 setting 'node.roles', '[data,ingest,master]' - setting 'node.remote_cluster_client', "false" setting 'xpack.security.enabled', 'true' setting 'xpack.watcher.enabled', 'false' setting 'xpack.license.self_generated.type', 'trial' From 8e226d8d9159181843a8a7d7cd65e9fc28ad7ccf Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 17 Jun 2020 23:09:36 -0400 Subject: [PATCH 26/31] Fix compilation --- .../java/org/elasticsearch/gateway/GatewayServiceTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java b/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java index 22c26aee07a24..81d640e5f1b3d 100644 --- a/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java +++ b/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java @@ -48,6 +48,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,8 +102,7 @@ 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(), + 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()). From e2c6f004750129e72575760f5915ff71faf7e035 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 17 Jun 2020 23:21:01 -0400 Subject: [PATCH 27/31] Feedback --- .../org/elasticsearch/gateway/GatewayServiceTests.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java b/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java index 81d640e5f1b3d..d55977cdd2058 100644 --- a/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java +++ b/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java @@ -102,8 +102,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(masterNode()).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(); From 7d593f0228fb038d0d9a26a8b4b85c074143c299 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Thu, 18 Jun 2020 19:43:30 -0400 Subject: [PATCH 28/31] Fix imports --- .../test/java/org/elasticsearch/gateway/GatewayServiceTests.java | 1 - 1 file changed, 1 deletion(-) diff --git a/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java b/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java index d55977cdd2058..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; From 827b5250007112ec2df33c7b2d2375b4ed1c081e Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 24 Jun 2020 12:39:13 -0400 Subject: [PATCH 29/31] Fix merge conflict --- docs/reference/modules/node.asciidoc | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/docs/reference/modules/node.asciidoc b/docs/reference/modules/node.asciidoc index c0d43ea3b826c..903ad1edb31c3 100644 --- a/docs/reference/modules/node.asciidoc +++ b/docs/reference/modules/node.asciidoc @@ -183,20 +183,6 @@ To create a dedicated data node, set: node.roles: [ data ] ------------------- -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). ->>>>>>> elastic - [[node-ingest-node]] ==== Ingest node From b852f725ce20e8b3201000e2c3a56c5cde025646 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 24 Jun 2020 12:44:57 -0400 Subject: [PATCH 30/31] Reword --- docs/reference/modules/node.asciidoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/reference/modules/node.asciidoc b/docs/reference/modules/node.asciidoc index 903ad1edb31c3..0b0c7349d6af7 100644 --- a/docs/reference/modules/node.asciidoc +++ b/docs/reference/modules/node.asciidoc @@ -35,7 +35,8 @@ related operations such as CRUD, search, and aggregations. 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 have the `ingest` role on master` and `data`. +dedicated ingest nodes and to not include the `ingest` role from nodes that have +the `master` or `data` roles. <>:: From 6d9ef4f154758a6910100fe7ded83b4c44675bb9 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 24 Jun 2020 12:48:06 -0400 Subject: [PATCH 31/31] Simplify --- .../test/InternalTestCluster.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) 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 e77682eb39980..2b1057c88121f 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -712,16 +712,18 @@ private String buildNodeName(int id, Settings settings) { */ private static String getRoleSuffix(Settings settings) { String suffix = ""; - if (settings.hasValue("node.roles") && DiscoveryNode.hasRole(settings, DiscoveryNodeRole.MASTER_ROLE)) { - suffix = suffix + DiscoveryNodeRole.MASTER_ROLE.roleNameAbbreviation(); - } - if (settings.hasValue("node.roles") && DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE)) { - suffix = suffix + DiscoveryNodeRole.DATA_ROLE.roleNameAbbreviation(); - } - if (settings.hasValue("node.roles") - && DiscoveryNode.hasRole(settings, DiscoveryNodeRole.MASTER_ROLE) == false - && DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE) == 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; }