Skip to content

Commit 84abcee

Browse files
dakroneelasticsearchmachine
authored andcommitted
Flip node shutdown feature flag to default to true on snapshot builds (elastic#75962)
* Flip node shutdown feature flag to default to true on snapshot builds It previously defaulted to false. The setting can still only be set to 'true' on a non-release (snapshot) build of Elasticsearch. Relates to elastic#70338 * Handle case where operator privileges are enabled
1 parent 302a99b commit 84abcee

File tree

8 files changed

+41
-17
lines changed

8 files changed

+41
-17
lines changed

build-tools-internal/src/main/groovy/elasticsearch.run.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ testClusters {
2727
throw new IllegalArgumentException("Unsupported self-generated license type: [" + licenseType + "[basic] or [trial].")
2828
}
2929
setting 'xpack.security.enabled', 'true'
30-
if (VersionProperties.elasticsearch.toString().endsWith('-SNAPSHOT')) {
31-
setting 'es.shutdown_feature_flag_enabled', 'true'
32-
}
3330
keystore 'bootstrap.password', 'password'
3431
user username: 'elastic-admin', password: 'elastic-password', role: 'superuser'
3532
}

docs/build.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ testClusters.matching { it.name == "integTest"}.configureEach {
6262
setting 'xpack.license.self_generated.type', 'trial'
6363
setting 'indices.lifecycle.history_index_enabled', 'false'
6464
setting 'ingest.geoip.downloader.enabled', 'false'
65-
if (VersionProperties.elasticsearch.toString().endsWith('-SNAPSHOT')) {
66-
setting 'es.shutdown_feature_flag_enabled', 'true'
67-
}
6865
systemProperty 'es.geoip_v2_feature_flag_enabled', 'true'
6966
keystorePassword 'keystore-password'
7067
}

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ private void wipeCluster() throws Exception {
762762
* If any nodes are registered for shutdown, removes their metadata.
763763
*/
764764
@SuppressWarnings("unchecked")
765-
private static void deleteAllNodeShutdownMetadata() throws IOException {
765+
protected void deleteAllNodeShutdownMetadata() throws IOException {
766766
Request getShutdownStatus = new Request("GET", "_nodes/shutdown");
767767
Map<String, Object> statusResponse = responseAsMap(adminClient().performRequest(getShutdownStatus));
768768
if (statusResponse.containsKey("_nodes") && statusResponse.containsKey("cluster_name")) {

x-pack/plugin/security/qa/operator-privileges-tests/src/javaRestTest/java/org/elasticsearch/xpack/security/operator/OperatorPrivilegesIT.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.List;
2828
import java.util.Map;
2929
import java.util.Set;
30+
import java.util.stream.Collectors;
3031

3132
import static org.hamcrest.Matchers.containsString;
3233
import static org.hamcrest.Matchers.equalTo;
@@ -42,6 +43,29 @@ protected Settings restClientSettings() {
4243
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
4344
}
4445

46+
@SuppressWarnings("unchecked")
47+
@Override
48+
protected void deleteAllNodeShutdownMetadata() throws IOException {
49+
Request getShutdownStatus = new Request("GET", "_nodes/shutdown");
50+
getShutdownStatus.setOptions(RequestOptions.DEFAULT.toBuilder().addHeader("Authorization", OPERATOR_AUTH_HEADER));
51+
Map<String, Object> statusResponse = responseAsMap(adminClient().performRequest(getShutdownStatus));
52+
if (statusResponse.containsKey("_nodes") && statusResponse.containsKey("cluster_name")) {
53+
// If the response contains these two keys, the feature flag isn't enabled on this cluster, so skip out now.
54+
// We can't check the system property directly because it only gets set for the cluster under test's JVM, not for the test
55+
// runner's JVM.
56+
return;
57+
}
58+
List<Map<String, Object>> nodesArray = (List<Map<String, Object>>) statusResponse.get("nodes");
59+
List<String> nodeIds = nodesArray.stream()
60+
.map(nodeShutdownMetadata -> (String) nodeShutdownMetadata.get("node_id"))
61+
.collect(Collectors.toUnmodifiableList());
62+
for (String nodeId : nodeIds) {
63+
Request deleteRequest = new Request("DELETE", "_nodes/" + nodeId + "/shutdown");
64+
deleteRequest.setOptions(RequestOptions.DEFAULT.toBuilder().addHeader("Authorization", OPERATOR_AUTH_HEADER));
65+
assertOK(adminClient().performRequest(deleteRequest));
66+
}
67+
}
68+
4569
public void testNonOperatorSuperuserWillFailToCallOperatorOnlyApiWhenOperatorPrivilegesIsEnabled() throws IOException {
4670
final Request postVotingConfigExclusionsRequest = new Request("POST", "_cluster/voting_config_exclusions?node_names=foo");
4771
final ResponseException responseException = expectThrows(

x-pack/plugin/security/qa/operator-privileges-tests/src/javaRestTest/resources/roles.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ limited_operator:
44
- "monitor"
55
- "cluster:admin/settings/update"
66
- "cluster:admin/snapshot/restore"
7+
- "cluster:admin/shutdown/*"

x-pack/plugin/shutdown/build.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ testClusters.all {
2222
testDistribution = 'default'
2323
setting 'xpack.security.enabled', 'true'
2424
setting 'xpack.license.self_generated.type', 'trial'
25-
if (VersionProperties.elasticsearch.toString().endsWith('-SNAPSHOT')) {
26-
setting 'es.shutdown_feature_flag_enabled', 'true'
27-
}
2825
keystore 'bootstrap.password', 'x-pack-test-password'
2926
user username: "x_pack_rest_user", password: "x-pack-test-password"
3027
}

x-pack/plugin/shutdown/qa/multi-node/build.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ testClusters.all {
1818
testDistribution = 'DEFAULT'
1919
numberOfNodes = 4
2020

21-
if (VersionProperties.elasticsearch.toString().endsWith('-SNAPSHOT')) {
22-
setting 'es.shutdown_feature_flag_enabled', 'true'
23-
}
2421
setting 'xpack.security.enabled', 'true'
2522
user username: clusterCredentials.username, password: clusterCredentials.password, role: 'superuser'
2623
}

x-pack/plugin/shutdown/src/main/java/org/elasticsearch/xpack/shutdown/ShutdownPlugin.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,21 @@ public class ShutdownPlugin extends Plugin implements ActionPlugin {
3232
public static final String SHUTDOWN_FEATURE_ENABLED_FLAG = "es.shutdown_feature_flag_enabled";
3333
public static final Setting<Boolean> SHUTDOWN_FEATURE_ENABLED_FLAG_SETTING = Setting.boolSetting(
3434
SHUTDOWN_FEATURE_ENABLED_FLAG,
35-
false,
36-
enabled -> {
37-
if (enabled != null && enabled && Build.CURRENT.isSnapshot() == false) {
38-
throw new IllegalArgumentException("shutdown plugin may not be enabled on a non-snapshot build");
35+
(settings) -> {
36+
final String enabled = settings.get(SHUTDOWN_FEATURE_ENABLED_FLAG);
37+
// Enabled by default on snapshot builds, disabled on release builds
38+
if (Build.CURRENT.isSnapshot()) {
39+
if (enabled != null && enabled.equalsIgnoreCase("false")) {
40+
return "false";
41+
} else {
42+
return "true";
43+
}
44+
} else {
45+
if (enabled != null && enabled.equalsIgnoreCase("true")) {
46+
throw new IllegalArgumentException("shutdown plugin may not be enabled on a non-snapshot build");
47+
} else {
48+
return "false";
49+
}
3950
}
4051
},
4152
Setting.Property.NodeScope

0 commit comments

Comments
 (0)