-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only allow x-pack metadata if all nodes are ready #30743
Merged
ywelsch
merged 10 commits into
elastic:master
from
ywelsch:only-activate-xpack-if-all-nodes-x-pack
May 23, 2018
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
12110b9
Only activate x-pack if all nodes ready for it
ywelsch ba94bdd
add comment about node setting
ywelsch 5f25ea3
refactor checkReadyForXPackCustomMetadata into two methods and add ja…
ywelsch 8911179
Merge remote-tracking branch 'elastic/master' into only-activate-xpac…
ywelsch e1437e8
move note about removal of InitialClusterStateCustomSupplier to top-l…
ywelsch 87ad80f
simplify installTokenMetadata
ywelsch cec9704
add unit test for isReadyForXPackCustomMetadata
ywelsch ed235a5
Merge remote-tracking branch 'elastic/master' into only-activate-xpac…
ywelsch 1b6ae1d
Simplify node attributes check
ywelsch a70ea64
Fix ML tests
ywelsch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/XPackPluginTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* 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.xpack.core; | ||
|
||
import org.elasticsearch.Version; | ||
import org.elasticsearch.client.Client; | ||
import org.elasticsearch.cluster.ClusterName; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.cluster.node.DiscoveryNodes; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.license.XPackLicenseState; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.test.VersionUtils; | ||
import org.elasticsearch.xpack.core.security.authc.TokenMetaData; | ||
import org.elasticsearch.xpack.core.ssl.SSLService; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
|
||
public class XPackPluginTests extends ESTestCase { | ||
|
||
public void testXPackInstalledAttrClash() throws Exception { | ||
Settings.Builder builder = Settings.builder(); | ||
builder.put("node.attr." + XPackPlugin.XPACK_INSTALLED_NODE_ATTR, randomBoolean()); | ||
if (randomBoolean()) { | ||
builder.put(Client.CLIENT_TYPE_SETTING_S.getKey(), "transport"); | ||
} | ||
XPackPlugin xpackPlugin = createXPackPlugin(builder.put("path.home", createTempDir()).build()); | ||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, xpackPlugin::additionalSettings); | ||
assertThat(e.getMessage(), | ||
containsString("Directly setting [node.attr." + XPackPlugin.XPACK_INSTALLED_NODE_ATTR + "] is not permitted")); | ||
} | ||
|
||
public void testXPackInstalledAttrExists() throws Exception { | ||
XPackPlugin xpackPlugin = createXPackPlugin(Settings.builder().put("path.home", createTempDir()).build()); | ||
assertEquals("true", xpackPlugin.additionalSettings().get("node.attr." + XPackPlugin.XPACK_INSTALLED_NODE_ATTR)); | ||
} | ||
|
||
public void testNodesNotReadyForXPackCustomMetadata() { | ||
boolean compatible; | ||
boolean nodesCompatible = true; | ||
DiscoveryNodes.Builder discoveryNodes = DiscoveryNodes.builder(); | ||
|
||
for (int i = 0; i < randomInt(3); i++) { | ||
final Version version = VersionUtils.randomVersion(random()); | ||
final Map<String, String> attributes; | ||
if (randomBoolean() && version.onOrAfter(Version.V_6_3_0)) { | ||
attributes = Collections.singletonMap(XPackPlugin.XPACK_INSTALLED_NODE_ATTR, "true"); | ||
} else { | ||
nodesCompatible = false; | ||
attributes = Collections.emptyMap(); | ||
} | ||
|
||
discoveryNodes.add(new DiscoveryNode("node_" + i, buildNewFakeTransportAddress(), attributes, Collections.emptySet(), | ||
Version.CURRENT)); | ||
} | ||
ClusterState.Builder clusterStateBuilder = ClusterState.builder(ClusterName.DEFAULT); | ||
|
||
if (randomBoolean()) { | ||
clusterStateBuilder.putCustom(TokenMetaData.TYPE, new TokenMetaData(Collections.emptyList(), new byte[0])); | ||
compatible = true; | ||
} else { | ||
compatible = nodesCompatible; | ||
} | ||
|
||
ClusterState clusterState = clusterStateBuilder.nodes(discoveryNodes.build()).build(); | ||
|
||
assertEquals(XPackPlugin.nodesNotReadyForXPackCustomMetadata(clusterState).isEmpty(), nodesCompatible); | ||
assertEquals(XPackPlugin.isReadyForXPackCustomMetadata(clusterState), compatible); | ||
|
||
if (compatible == false) { | ||
IllegalStateException e = expectThrows(IllegalStateException.class, | ||
() -> XPackPlugin.checkReadyForXPackCustomMetadata(clusterState)); | ||
assertThat(e.getMessage(), containsString("The following nodes are not ready yet for enabling x-pack custom metadata:")); | ||
} | ||
} | ||
|
||
private XPackPlugin createXPackPlugin(Settings settings) throws Exception { | ||
return new XPackPlugin(settings, null){ | ||
|
||
@Override | ||
protected void setSslService(SSLService sslService) { | ||
// disable | ||
} | ||
|
||
@Override | ||
protected void setLicenseState(XPackLicenseState licenseState) { | ||
// disable | ||
} | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you document that if the cluster state already contains xpack metadata it is always considered "ready"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pushed 5f25ea3