Skip to content

Commit

Permalink
Have VotingOnlyNodePlugin always enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
ywelsch committed Jun 21, 2019
1 parent e284426 commit bcd6ec2
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ private XPackSettings() {
/** Setting for enabling or disabling vectors. Defaults to true. */
public static final Setting<Boolean> VECTORS_ENABLED = Setting.boolSetting("xpack.vectors.enabled", true, Setting.Property.NodeScope);

/** Setting for enabling or disabling the voting-only-node functionality. Needs to be enabled on both voting-only nodes and regular
* master-eligible nodes for the voting-only functionality to work correctly. Defaults to true. */
public static final Setting<Boolean> VOTING_ONLY_ENABLED = Setting.boolSetting("xpack.voting_only.enabled", true,
Setting.Property.NodeScope);

/*
* SSL settings. These are the settings that are specifically registered for SSL. Many are private as we do not explicitly use them
* but instead parse based on a prefix (eg *.ssl.*)
Expand Down Expand Up @@ -213,7 +208,6 @@ public static List<Setting<?>> getAllSettings() {
settings.add(INDEX_LIFECYCLE_ENABLED);
settings.add(DATA_FRAME_ENABLED);
settings.add(VECTORS_ENABLED);
settings.add(VOTING_ONLY_ENABLED);
return Collections.unmodifiableList(settings);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public VotingOnlyNodeFeatureSetUsage(StreamInput input) throws IOException {
super(input);
}

public VotingOnlyNodeFeatureSetUsage(boolean available, boolean enabled) {
super(XPackField.VOTING_ONLY, available, enabled);
public VotingOnlyNodeFeatureSetUsage(boolean available) {
super(XPackField.VOTING_ONLY, available, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,23 @@
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.protocol.xpack.XPackUsageRequest;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.core.XPackFeatureSet;
import org.elasticsearch.xpack.core.XPackField;
import org.elasticsearch.xpack.core.XPackSettings;
import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction;
import org.elasticsearch.xpack.core.action.XPackUsageFeatureResponse;
import org.elasticsearch.xpack.core.action.XPackUsageFeatureTransportAction;
import org.elasticsearch.xpack.core.votingonly.VotingOnlyNodeFeatureSetUsage;

public class VotingOnlyNodeFeatureSet implements XPackFeatureSet {

private final boolean enabled;
private final XPackLicenseState licenseState;

@Inject
public VotingOnlyNodeFeatureSet(Settings settings, @Nullable XPackLicenseState licenseState) {
this.enabled = XPackSettings.VOTING_ONLY_ENABLED.get(settings);
public VotingOnlyNodeFeatureSet(@Nullable XPackLicenseState licenseState) {
this.licenseState = licenseState;
}

Expand All @@ -48,29 +44,27 @@ public boolean available() {

@Override
public boolean enabled() {
return enabled;
return true;
}

public static class UsageTransportAction extends XPackUsageFeatureTransportAction {

private final Settings settings;
private final XPackLicenseState licenseState;

@Inject
public UsageTransportAction(TransportService transportService, ClusterService clusterService, ThreadPool threadPool,
ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
Settings settings, XPackLicenseState licenseState) {
XPackLicenseState licenseState) {
super(XPackUsageFeatureAction.VOTING_ONLY_NODE.name(), transportService, clusterService,
threadPool, actionFilters, indexNameExpressionResolver);
this.settings = settings;
this.licenseState = licenseState;
}

@Override
protected void masterOperation(XPackUsageRequest request, ClusterState state, ActionListener<XPackUsageFeatureResponse> listener) {
final boolean available = licenseState.isVotingOnlyAllowed();
final VotingOnlyNodeFeatureSetUsage usage =
new VotingOnlyNodeFeatureSetUsage(available, XPackSettings.VOTING_ONLY_ENABLED.get(settings));
new VotingOnlyNodeFeatureSetUsage(available);
listener.onResponse(new XPackUsageFeatureResponse(usage));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.elasticsearch.transport.TransportResponseHandler;
import org.elasticsearch.watcher.ResourceWatcherService;
import org.elasticsearch.xpack.core.XPackPlugin;
import org.elasticsearch.xpack.core.XPackSettings;
import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction;

import java.io.IOException;
Expand Down Expand Up @@ -96,10 +95,6 @@ public List<Setting<?>> getSettings() {

@Override
public Set<DiscoveryNodeRole> getRoles() {
if (VOTING_ONLY_NODE_SETTING.exists(settings) && XPackSettings.VOTING_ONLY_ENABLED.get(settings) == false) {
throw new IllegalStateException(XPackSettings.VOTING_ONLY_ENABLED.getKey() + " must be set to true to use the " +
VOTING_ONLY_NODE_SETTING.getKey() + " setting");
}
if (isVotingOnlyNode && Node.NODE_MASTER_SETTING.get(settings) == false) {
throw new IllegalStateException("voting-only node must be master-eligible");
}
Expand Down Expand Up @@ -129,9 +124,6 @@ public Collection<Module> createGuiceModules() {

@Override
public Map<String, ElectionStrategy> getElectionStrategies() {
if (XPackSettings.VOTING_ONLY_ENABLED.get(settings) == false) {
return Collections.emptyMap();
}
return Collections.singletonMap(VOTING_ONLY_ELECTION_STRATEGY, new VotingOnlyNodeElectionStrategy());
}

Expand All @@ -151,9 +143,6 @@ public AsyncSender interceptSender(AsyncSender sender) {

@Override
public Settings additionalSettings() {
if (XPackSettings.VOTING_ONLY_ENABLED.get(settings) == false) {
return Settings.EMPTY;
}
return Settings.builder().put(DiscoveryModule.ELECTION_STRATEGY_SETTING.getKey(), VOTING_ONLY_ELECTION_STRATEGY).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@ public void testRequireVotingOnlyNodeToBeMasterEligible() {
assertThat(ise.getMessage(), containsString("voting-only node must be master-eligible"));
}

public void testRequireVotingOnlyNodeToHaveXPackSettingEnabled() {
internalCluster().setBootstrapMasterNodeIndex(0);
IllegalStateException ise = expectThrows(IllegalStateException.class, () -> internalCluster().startNode(Settings.builder()
.put(VotingOnlyNodePlugin.VOTING_ONLY_NODE_SETTING.getKey(), true)
.put(XPackSettings.VOTING_ONLY_ENABLED.getKey(), false)
.build()));
assertThat(ise.getMessage(), containsString(XPackSettings.VOTING_ONLY_ENABLED.getKey() + " must be set to true to use the " +
VotingOnlyNodePlugin.VOTING_ONLY_NODE_SETTING.getKey() + " setting"));
}

public void testVotingOnlyNodeStats() throws Exception {
internalCluster().setBootstrapMasterNodeIndex(0);
internalCluster().startNodes(2);
Expand Down

0 comments on commit bcd6ec2

Please sign in to comment.