|
@@ -6,6 +6,7 @@
|
|
|
*/
|
|
|
package org.elasticsearch.xpack.shutdown;
|
|
|
|
|
|
+import org.elasticsearch.Build;
|
|
|
import org.elasticsearch.action.ActionRequest;
|
|
|
import org.elasticsearch.action.ActionResponse;
|
|
|
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
|
@@ -13,6 +14,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
|
|
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
|
|
import org.elasticsearch.common.settings.ClusterSettings;
|
|
|
import org.elasticsearch.common.settings.IndexScopedSettings;
|
|
|
+import org.elasticsearch.common.settings.Setting;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.common.settings.SettingsFilter;
|
|
|
import org.elasticsearch.plugins.ActionPlugin;
|
|
@@ -27,17 +29,24 @@ import java.util.function.Supplier;
|
|
|
|
|
|
public class ShutdownPlugin extends Plugin implements ActionPlugin {
|
|
|
|
|
|
- public static final boolean SHUTDOWN_FEATURE_FLAG_ENABLED = "true".equals(System.getProperty("es.shutdown_feature_flag_enabled"));
|
|
|
+ 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");
|
|
|
+ }
|
|
|
+ },
|
|
|
+ Setting.Property.NodeScope
|
|
|
+ );
|
|
|
|
|
|
- public boolean isEnabled() {
|
|
|
- return SHUTDOWN_FEATURE_FLAG_ENABLED;
|
|
|
+ public boolean isEnabled(Settings settings) {
|
|
|
+ return SHUTDOWN_FEATURE_ENABLED_FLAG_SETTING.get(settings);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
|
|
|
- if (isEnabled() == false) {
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
ActionHandler<PutShutdownNodeAction.Request, AcknowledgedResponse> putShutdown = new ActionHandler<>(
|
|
|
PutShutdownNodeAction.INSTANCE,
|
|
|
TransportPutShutdownNodeAction.class
|
|
@@ -63,9 +72,14 @@ public class ShutdownPlugin extends Plugin implements ActionPlugin {
|
|
|
IndexNameExpressionResolver indexNameExpressionResolver,
|
|
|
Supplier<DiscoveryNodes> nodesInCluster
|
|
|
) {
|
|
|
- if (isEnabled() == false) {
|
|
|
+ if (isEnabled(settings) == false) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
return Arrays.asList(new RestPutShutdownNodeAction(), new RestDeleteShutdownNodeAction(), new RestGetShutdownStatusAction());
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Setting<?>> getSettings() {
|
|
|
+ return Collections.singletonList(SHUTDOWN_FEATURE_ENABLED_FLAG_SETTING);
|
|
|
+ }
|
|
|
}
|