Skip to content

Commit

Permalink
Flip node shutdown feature flag to default to true on snapshot builds (
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
dakrone authored and Adam Locke committed Aug 3, 2021
1 parent c0addfb commit 9c6f1f6
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 17 deletions.
3 changes: 0 additions & 3 deletions build-tools-internal/src/main/groovy/elasticsearch.run.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ testClusters {
throw new IllegalArgumentException("Unsupported self-generated license type: [" + licenseType + "[basic] or [trial].")
}
setting 'xpack.security.enabled', 'true'
if (VersionProperties.elasticsearch.toString().endsWith('-SNAPSHOT')) {
setting 'es.shutdown_feature_flag_enabled', 'true'
}
keystore 'bootstrap.password', 'password'
user username: 'elastic-admin', password: 'elastic-password', role: 'superuser'
}
Expand Down
3 changes: 0 additions & 3 deletions docs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ testClusters.matching { it.name == "integTest"}.configureEach {
setting 'xpack.license.self_generated.type', 'trial'
setting 'indices.lifecycle.history_index_enabled', 'false'
setting 'ingest.geoip.downloader.enabled', 'false'
if (VersionProperties.elasticsearch.toString().endsWith('-SNAPSHOT')) {
setting 'es.shutdown_feature_flag_enabled', 'true'
}
systemProperty 'es.geoip_v2_feature_flag_enabled', 'true'
keystorePassword 'keystore-password'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ private void wipeCluster() throws Exception {
* If any nodes are registered for shutdown, removes their metadata.
*/
@SuppressWarnings("unchecked")
private static void deleteAllNodeShutdownMetadata() throws IOException {
protected void deleteAllNodeShutdownMetadata() throws IOException {
Request getShutdownStatus = new Request("GET", "_nodes/shutdown");
Map<String, Object> statusResponse = responseAsMap(adminClient().performRequest(getShutdownStatus));
if (statusResponse.containsKey("_nodes") && statusResponse.containsKey("cluster_name")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

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

@SuppressWarnings("unchecked")
@Override
protected void deleteAllNodeShutdownMetadata() throws IOException {
Request getShutdownStatus = new Request("GET", "_nodes/shutdown");
getShutdownStatus.setOptions(RequestOptions.DEFAULT.toBuilder().addHeader("Authorization", OPERATOR_AUTH_HEADER));
Map<String, Object> statusResponse = responseAsMap(adminClient().performRequest(getShutdownStatus));
if (statusResponse.containsKey("_nodes") && statusResponse.containsKey("cluster_name")) {
// If the response contains these two keys, the feature flag isn't enabled on this cluster, so skip out now.
// We can't check the system property directly because it only gets set for the cluster under test's JVM, not for the test
// runner's JVM.
return;
}
List<Map<String, Object>> nodesArray = (List<Map<String, Object>>) statusResponse.get("nodes");
List<String> nodeIds = nodesArray.stream()
.map(nodeShutdownMetadata -> (String) nodeShutdownMetadata.get("node_id"))
.collect(Collectors.toUnmodifiableList());
for (String nodeId : nodeIds) {
Request deleteRequest = new Request("DELETE", "_nodes/" + nodeId + "/shutdown");
deleteRequest.setOptions(RequestOptions.DEFAULT.toBuilder().addHeader("Authorization", OPERATOR_AUTH_HEADER));
assertOK(adminClient().performRequest(deleteRequest));
}
}

public void testNonOperatorSuperuserWillFailToCallOperatorOnlyApiWhenOperatorPrivilegesIsEnabled() throws IOException {
final Request postVotingConfigExclusionsRequest = new Request("POST", "_cluster/voting_config_exclusions?node_names=foo");
final ResponseException responseException = expectThrows(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ limited_operator:
- "monitor"
- "cluster:admin/settings/update"
- "cluster:admin/snapshot/restore"
- "cluster:admin/shutdown/*"
3 changes: 0 additions & 3 deletions x-pack/plugin/shutdown/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ testClusters.all {
testDistribution = 'default'
setting 'xpack.security.enabled', 'true'
setting 'xpack.license.self_generated.type', 'trial'
if (VersionProperties.elasticsearch.toString().endsWith('-SNAPSHOT')) {
setting 'es.shutdown_feature_flag_enabled', 'true'
}
keystore 'bootstrap.password', 'x-pack-test-password'
user username: "x_pack_rest_user", password: "x-pack-test-password"
}
3 changes: 0 additions & 3 deletions x-pack/plugin/shutdown/qa/multi-node/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ testClusters.all {
testDistribution = 'DEFAULT'
numberOfNodes = 4

if (VersionProperties.elasticsearch.toString().endsWith('-SNAPSHOT')) {
setting 'es.shutdown_feature_flag_enabled', 'true'
}
setting 'xpack.security.enabled', 'true'
user username: clusterCredentials.username, password: clusterCredentials.password, role: 'superuser'
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,21 @@ public class ShutdownPlugin extends Plugin implements ActionPlugin {
public static final String SHUTDOWN_FEATURE_ENABLED_FLAG = "es.shutdown_feature_flag_enabled";
public static final Setting<Boolean> SHUTDOWN_FEATURE_ENABLED_FLAG_SETTING = Setting.boolSetting(
SHUTDOWN_FEATURE_ENABLED_FLAG,
false,
enabled -> {
if (enabled != null && enabled && Build.CURRENT.isSnapshot() == false) {
throw new IllegalArgumentException("shutdown plugin may not be enabled on a non-snapshot build");
(settings) -> {
final String enabled = settings.get(SHUTDOWN_FEATURE_ENABLED_FLAG);
// Enabled by default on snapshot builds, disabled on release builds
if (Build.CURRENT.isSnapshot()) {
if (enabled != null && enabled.equalsIgnoreCase("false")) {
return "false";
} else {
return "true";
}
} else {
if (enabled != null && enabled.equalsIgnoreCase("true")) {
throw new IllegalArgumentException("shutdown plugin may not be enabled on a non-snapshot build");
} else {
return "false";
}
}
},
Setting.Property.NodeScope
Expand Down

0 comments on commit 9c6f1f6

Please sign in to comment.