Make xpack.ilm.enabled setting a no-op (#55592) (#55980)

* Make xpack.ilm.enabled setting a no-op

* Add watcher setting to not use ILM

* Update documentation for no-op setting

* Remove NO_ILM ml index templates

* Remove unneeded setting from test setup

* Inline variable definitions for ML templates

* Use identical parameter names in templates

* New ILM/watcher setting falls back to old setting

* Add fallback unit test for watcher/ilm setting
This commit is contained in:
William Brafford 2020-04-30 09:50:18 -04:00 committed by GitHub
parent 83828af7ef
commit 273ff6a105
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 150 additions and 210 deletions

View File

@ -292,11 +292,22 @@ greater than `Integer.MAX_VALUE`. This leniency has been removed.
[float] [float]
==== Option to disable basic license features is deprecated ==== Option to disable basic license features is deprecated
In Elasticsearch 7.8.0, the following settings have been deprecated: In Elasticsearch 7.8.0, the following settings no longer have any effect, and
have been deprecated:
* `xpack.ilm.enabled`
In other words, even if `xpack.ilm.enabled` is set to `false`, the ILM APIs
will be available.
If you have disabled ILM so that you can use another tool to manage Watcher
indices, the newly introduced `xpack.watcher.use_ilm_index_management` setting
may be set to false.
Additionally, the following settings have been deprecated:
* `xpack.enrich.enabled` * `xpack.enrich.enabled`
* `xpack.flattened.enabled` * `xpack.flattened.enabled`
* `xpack.ilm.enabled`
* `xpack.monitoring.enabled` * `xpack.monitoring.enabled`
* `xpack.rollup.enabled` * `xpack.rollup.enabled`
* `xpack.slm.enabled` * `xpack.slm.enabled`
@ -305,4 +316,4 @@ In Elasticsearch 7.8.0, the following settings have been deprecated:
* `xpack.vectors.enabled` * `xpack.vectors.enabled`
In future releases, it will not be possible to disable the APIs for Enrichment, In future releases, it will not be possible to disable the APIs for Enrichment,
Flattened mappings, ILM, Monitoring, Rollup, SLM, SQL, Transforms, and Vectors. Flattened mappings, Monitoring, Rollup, SLM, SQL, Transforms, and Vectors.

View File

@ -7,9 +7,8 @@ These are the settings available for configuring Index Lifecycle Management
==== Cluster level settings ==== Cluster level settings
`xpack.ilm.enabled`:: `xpack.ilm.enabled`::
deprecated:[7.8.0,Basic License features should always be enabled] + deprecated:[7.8.0,Basic License features are always enabled] +
Whether ILM is enabled or disabled, setting this to `false` disables any ILM This deprecated setting has no effect and will be removed in Elasticsearch 8.0.
REST API endpoints and functionality. Defaults to `true`.
`indices.lifecycle.poll_interval`:: `indices.lifecycle.poll_interval`::
(<<time-units, time units>>) How often {ilm} checks for indices that meet policy (<<time-units, time units>>) How often {ilm} checks for indices that meet policy

View File

@ -93,7 +93,10 @@ public class XPackSettings {
/** /**
* Setting for enabling or disabling the index lifecycle extension. Defaults to true. * Setting for enabling or disabling the index lifecycle extension. Defaults to true.
* <p>
* This setting is now a no-op: setting it to false is permitted, but does nothing.
*/ */
@Deprecated // since 7.8.0
public static final Setting<Boolean> INDEX_LIFECYCLE_ENABLED = Setting.boolSetting("xpack.ilm.enabled", true, public static final Setting<Boolean> INDEX_LIFECYCLE_ENABLED = Setting.boolSetting("xpack.ilm.enabled", true,
Property.NodeScope, Property.Deprecated); Property.NodeScope, Property.Deprecated);

View File

@ -49,12 +49,12 @@ public class IndexLifecycleFeatureSetUsage extends XPackFeatureSet.Usage {
} }
} }
public IndexLifecycleFeatureSetUsage(boolean available, boolean enabled) { public IndexLifecycleFeatureSetUsage(boolean available) {
this(available, enabled, null); this(available, null);
} }
public IndexLifecycleFeatureSetUsage(boolean available, boolean enabled, List<PolicyStats> policyStats) { public IndexLifecycleFeatureSetUsage(boolean available, List<PolicyStats> policyStats) {
super(XPackField.INDEX_LIFECYCLE, available, enabled); super(XPackField.INDEX_LIFECYCLE, available, true);
this.policyStats = policyStats; this.policyStats = policyStats;
} }

View File

@ -26,7 +26,6 @@ import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.gateway.GatewayService; import org.elasticsearch.gateway.GatewayService;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.XPackClient; import org.elasticsearch.xpack.core.XPackClient;
import org.elasticsearch.xpack.core.XPackSettings;
import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata;
import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy;
import org.elasticsearch.xpack.core.ilm.action.PutLifecycleAction; import org.elasticsearch.xpack.core.ilm.action.PutLifecycleAction;
@ -203,9 +202,7 @@ public abstract class IndexTemplateRegistry implements ClusterStateListener {
} }
private void addIndexLifecyclePoliciesIfMissing(ClusterState state) { private void addIndexLifecyclePoliciesIfMissing(ClusterState state) {
boolean ilmSupported = XPackSettings.INDEX_LIFECYCLE_ENABLED.get(settings);
if (ilmSupported) {
Optional<IndexLifecycleMetadata> maybeMeta = Optional.ofNullable(state.metadata().custom(IndexLifecycleMetadata.TYPE)); Optional<IndexLifecycleMetadata> maybeMeta = Optional.ofNullable(state.metadata().custom(IndexLifecycleMetadata.TYPE));
List<LifecyclePolicy> policies = getPolicyConfigs().stream() List<LifecyclePolicy> policies = getPolicyConfigs().stream()
.map(policyConfig -> policyConfig.load(xContentRegistry)) .map(policyConfig -> policyConfig.load(xContentRegistry))
@ -229,7 +226,6 @@ public abstract class IndexTemplateRegistry implements ClusterStateListener {
} }
} }
} }
}
private void putPolicy(final LifecyclePolicy policy, final AtomicBoolean creationCheck) { private void putPolicy(final LifecyclePolicy policy, final AtomicBoolean creationCheck) {
final Executor executor = threadPool.generic(); final Executor executor = threadPool.generic();

View File

@ -8,8 +8,9 @@
"index" : { "index" : {
"auto_expand_replicas" : "0-1", "auto_expand_replicas" : "0-1",
"hidden": true "hidden": true
} },
${xpack.ml.index.lifecycle.settings} "index.lifecycle.name": "${xpack.ml.index.lifecycle.name}",
"index.lifecycle.rollover_alias": "${xpack.ml.index.lifecycle.rollover_alias}"
}, },
"mappings" : { "mappings" : {
"_doc": { "_doc": {

View File

@ -9,8 +9,9 @@
"number_of_shards" : "1", "number_of_shards" : "1",
"auto_expand_replicas" : "0-1", "auto_expand_replicas" : "0-1",
"hidden": true "hidden": true
} },
${xpack.ml.index.lifecycle.settings} "index.lifecycle.name": "${xpack.ml.index.lifecycle.name}",
"index.lifecycle.rollover_alias": "${xpack.ml.index.lifecycle.rollover_alias}"
}, },
"mappings" : ${xpack.ml.stats.mappings}, "mappings" : ${xpack.ml.stats.mappings},
"aliases" : {} "aliases" : {}

View File

@ -28,22 +28,18 @@ public class IndexLifecycleFeatureSetUsageTests extends AbstractWireSerializingT
policyStats.add(PolicyStatsTests.createRandomInstance()); policyStats.add(PolicyStatsTests.createRandomInstance());
} }
} }
return new IndexLifecycleFeatureSetUsage(available, enabled, policyStats); return new IndexLifecycleFeatureSetUsage(available, policyStats);
} }
@Override @Override
protected IndexLifecycleFeatureSetUsage mutateInstance(IndexLifecycleFeatureSetUsage instance) throws IOException { protected IndexLifecycleFeatureSetUsage mutateInstance(IndexLifecycleFeatureSetUsage instance) throws IOException {
boolean available = instance.available(); boolean available = instance.available();
boolean enabled = instance.enabled();
List<PolicyStats> policyStats = instance.getPolicyStats(); List<PolicyStats> policyStats = instance.getPolicyStats();
switch (between(0, 2)) { switch (between(0, 1)) {
case 0: case 0:
available = available == false; available = available == false;
break; break;
case 1: case 1:
enabled = enabled == false;
break;
case 2:
if (policyStats == null) { if (policyStats == null) {
policyStats = new ArrayList<>(); policyStats = new ArrayList<>();
policyStats.add(PolicyStatsTests.createRandomInstance()); policyStats.add(PolicyStatsTests.createRandomInstance());
@ -57,7 +53,7 @@ public class IndexLifecycleFeatureSetUsageTests extends AbstractWireSerializingT
default: default:
throw new AssertionError("Illegal randomisation branch"); throw new AssertionError("Illegal randomisation branch");
} }
return new IndexLifecycleFeatureSetUsage(available, enabled, policyStats); return new IndexLifecycleFeatureSetUsage(available, policyStats);
} }
@Override @Override

View File

@ -141,13 +141,11 @@ public class IndexLifecycle extends Plugin implements ActionPlugin {
private final SetOnce<SnapshotRetentionService> snapshotRetentionService = new SetOnce<>(); private final SetOnce<SnapshotRetentionService> snapshotRetentionService = new SetOnce<>();
private final SetOnce<SnapshotHistoryStore> snapshotHistoryStore = new SetOnce<>(); private final SetOnce<SnapshotHistoryStore> snapshotHistoryStore = new SetOnce<>();
private Settings settings; private Settings settings;
private boolean ilmEnabled;
private boolean slmEnabled; private boolean slmEnabled;
private boolean transportClientMode; private boolean transportClientMode;
public IndexLifecycle(Settings settings) { public IndexLifecycle(Settings settings) {
this.settings = settings; this.settings = settings;
this.ilmEnabled = XPackSettings.INDEX_LIFECYCLE_ENABLED.get(settings);
this.slmEnabled = XPackSettings.SNAPSHOT_LIFECYCLE_ENABLED.get(settings); this.slmEnabled = XPackSettings.SNAPSHOT_LIFECYCLE_ENABLED.get(settings);
this.transportClientMode = XPackPlugin.transportClientMode(settings); this.transportClientMode = XPackPlugin.transportClientMode(settings);
} }
@ -197,7 +195,6 @@ public class IndexLifecycle extends Plugin implements ActionPlugin {
return Collections.emptyList(); return Collections.emptyList();
} }
final List<Object> components = new ArrayList<>(); final List<Object> components = new ArrayList<>();
if (ilmEnabled) {
// This registers a cluster state listener, so appears unused but is not. // This registers a cluster state listener, so appears unused but is not.
@SuppressWarnings("unused") @SuppressWarnings("unused")
ILMHistoryTemplateRegistry ilmTemplateRegistry = ILMHistoryTemplateRegistry ilmTemplateRegistry =
@ -207,7 +204,6 @@ public class IndexLifecycle extends Plugin implements ActionPlugin {
indexLifecycleInitialisationService.set(new IndexLifecycleService(settings, client, clusterService, threadPool, indexLifecycleInitialisationService.set(new IndexLifecycleService(settings, client, clusterService, threadPool,
getClock(), System::currentTimeMillis, xContentRegistry, ilmHistoryStore.get())); getClock(), System::currentTimeMillis, xContentRegistry, ilmHistoryStore.get()));
components.add(indexLifecycleInitialisationService.get()); components.add(indexLifecycleInitialisationService.get());
}
if (slmEnabled) { if (slmEnabled) {
// the template registry is a cluster state listener // the template registry is a cluster state listener
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -263,7 +259,7 @@ public class IndexLifecycle extends Plugin implements ActionPlugin {
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster) { Supplier<DiscoveryNodes> nodesInCluster) {
List<RestHandler> handlers = new ArrayList<>(); List<RestHandler> handlers = new ArrayList<>();
if (ilmEnabled) { // add ILM rest handlers
handlers.addAll(Arrays.asList( handlers.addAll(Arrays.asList(
new RestPutLifecycleAction(), new RestPutLifecycleAction(),
new RestGetLifecycleAction(), new RestGetLifecycleAction(),
@ -276,7 +272,6 @@ public class IndexLifecycle extends Plugin implements ActionPlugin {
new RestStartILMAction(), new RestStartILMAction(),
new RestGetStatusAction() new RestGetStatusAction()
)); ));
}
if (slmEnabled) { if (slmEnabled) {
handlers.addAll(Arrays.asList( handlers.addAll(Arrays.asList(
new RestPutSnapshotLifecycleAction(), new RestPutSnapshotLifecycleAction(),
@ -296,7 +291,7 @@ public class IndexLifecycle extends Plugin implements ActionPlugin {
@Override @Override
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() { public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> actions = new ArrayList<>(); List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> actions = new ArrayList<>();
if (ilmEnabled) { // add ILM actions
actions.addAll(Arrays.asList( actions.addAll(Arrays.asList(
new ActionHandler<>(PutLifecycleAction.INSTANCE, TransportPutLifecycleAction.class), new ActionHandler<>(PutLifecycleAction.INSTANCE, TransportPutLifecycleAction.class),
new ActionHandler<>(GetLifecycleAction.INSTANCE, TransportGetLifecycleAction.class), new ActionHandler<>(GetLifecycleAction.INSTANCE, TransportGetLifecycleAction.class),
@ -309,7 +304,6 @@ public class IndexLifecycle extends Plugin implements ActionPlugin {
new ActionHandler<>(StopILMAction.INSTANCE, TransportStopILMAction.class), new ActionHandler<>(StopILMAction.INSTANCE, TransportStopILMAction.class),
new ActionHandler<>(GetStatusAction.INSTANCE, TransportGetStatusAction.class) new ActionHandler<>(GetStatusAction.INSTANCE, TransportGetStatusAction.class)
)); ));
}
if (slmEnabled) { if (slmEnabled) {
actions.addAll(Arrays.asList( actions.addAll(Arrays.asList(
new ActionHandler<>(PutSnapshotLifecycleAction.INSTANCE, TransportPutSnapshotLifecycleAction.class), new ActionHandler<>(PutSnapshotLifecycleAction.INSTANCE, TransportPutSnapshotLifecycleAction.class),
@ -328,11 +322,9 @@ public class IndexLifecycle extends Plugin implements ActionPlugin {
@Override @Override
public void onIndexModule(IndexModule indexModule) { public void onIndexModule(IndexModule indexModule) {
if (ilmEnabled) {
assert indexLifecycleInitialisationService.get() != null; assert indexLifecycleInitialisationService.get() != null;
indexModule.addIndexEventListener(indexLifecycleInitialisationService.get()); indexModule.addIndexEventListener(indexLifecycleInitialisationService.get());
} }
}
@Override @Override
public void close() { public void close() {

View File

@ -11,11 +11,9 @@ import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.xpack.core.XPackFeatureSet; import org.elasticsearch.xpack.core.XPackFeatureSet;
import org.elasticsearch.xpack.core.XPackField; import org.elasticsearch.xpack.core.XPackField;
import org.elasticsearch.xpack.core.XPackSettings;
import org.elasticsearch.xpack.core.ilm.IndexLifecycleFeatureSetUsage; import org.elasticsearch.xpack.core.ilm.IndexLifecycleFeatureSetUsage;
import org.elasticsearch.xpack.core.ilm.IndexLifecycleFeatureSetUsage.PhaseStats; import org.elasticsearch.xpack.core.ilm.IndexLifecycleFeatureSetUsage.PhaseStats;
import org.elasticsearch.xpack.core.ilm.IndexLifecycleFeatureSetUsage.PolicyStats; import org.elasticsearch.xpack.core.ilm.IndexLifecycleFeatureSetUsage.PolicyStats;
@ -29,14 +27,12 @@ import java.util.stream.Collectors;
public class IndexLifecycleFeatureSet implements XPackFeatureSet { public class IndexLifecycleFeatureSet implements XPackFeatureSet {
private final boolean enabled;
private final XPackLicenseState licenseState; private final XPackLicenseState licenseState;
private ClusterService clusterService; private ClusterService clusterService;
@Inject @Inject
public IndexLifecycleFeatureSet(Settings settings, @Nullable XPackLicenseState licenseState, ClusterService clusterService) { public IndexLifecycleFeatureSet(@Nullable XPackLicenseState licenseState, ClusterService clusterService) {
this.clusterService = clusterService; this.clusterService = clusterService;
this.enabled = XPackSettings.INDEX_LIFECYCLE_ENABLED.get(settings);
this.licenseState = licenseState; this.licenseState = licenseState;
} }
@ -52,7 +48,7 @@ public class IndexLifecycleFeatureSet implements XPackFeatureSet {
@Override @Override
public boolean enabled() { public boolean enabled() {
return enabled; return true;
} }
@Override @Override
@ -83,9 +79,9 @@ public class IndexLifecycleFeatureSet implements XPackFeatureSet {
}).collect(Collectors.toMap(Tuple::v1, Tuple::v2)); }).collect(Collectors.toMap(Tuple::v1, Tuple::v2));
return new PolicyStats(phaseStats, policyUsage.getOrDefault(policy.getName(), 0)); return new PolicyStats(phaseStats, policyUsage.getOrDefault(policy.getName(), 0));
}).collect(Collectors.toList()); }).collect(Collectors.toList());
listener.onResponse(new IndexLifecycleFeatureSetUsage(available(), enabled(), policyStats)); listener.onResponse(new IndexLifecycleFeatureSetUsage(available(), policyStats));
} else { } else {
listener.onResponse(new IndexLifecycleFeatureSetUsage(available(), enabled())); listener.onResponse(new IndexLifecycleFeatureSetUsage(available()));
} }
} }

View File

@ -13,11 +13,9 @@ import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.core.XPackSettings;
import org.elasticsearch.xpack.core.ilm.IndexLifecycleFeatureSetUsage; import org.elasticsearch.xpack.core.ilm.IndexLifecycleFeatureSetUsage;
import org.elasticsearch.xpack.core.ilm.IndexLifecycleFeatureSetUsage.PolicyStats; import org.elasticsearch.xpack.core.ilm.IndexLifecycleFeatureSetUsage.PolicyStats;
import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata;
@ -53,7 +51,7 @@ public class IndexLifecycleFeatureSetTests extends ESTestCase {
} }
public void testAvailable() { public void testAvailable() {
IndexLifecycleFeatureSet featureSet = new IndexLifecycleFeatureSet(Settings.EMPTY, licenseState, clusterService); IndexLifecycleFeatureSet featureSet = new IndexLifecycleFeatureSet(licenseState, clusterService);
when(licenseState.isIndexLifecycleAllowed()).thenReturn(false); when(licenseState.isIndexLifecycleAllowed()).thenReturn(false);
assertThat(featureSet.available(), equalTo(false)); assertThat(featureSet.available(), equalTo(false));
@ -61,28 +59,17 @@ public class IndexLifecycleFeatureSetTests extends ESTestCase {
when(licenseState.isIndexLifecycleAllowed()).thenReturn(true); when(licenseState.isIndexLifecycleAllowed()).thenReturn(true);
assertThat(featureSet.available(), equalTo(true)); assertThat(featureSet.available(), equalTo(true));
featureSet = new IndexLifecycleFeatureSet(Settings.EMPTY, null, clusterService); featureSet = new IndexLifecycleFeatureSet(null, clusterService);
assertThat(featureSet.available(), equalTo(false)); assertThat(featureSet.available(), equalTo(false));
} }
public void testEnabled() {
Settings.Builder settings = Settings.builder().put("xpack.ilm.enabled", false);
IndexLifecycleFeatureSet featureSet = new IndexLifecycleFeatureSet(settings.build(), licenseState, clusterService);
assertThat(featureSet.enabled(), equalTo(false));
settings = Settings.builder().put("xpack.ilm.enabled", true);
featureSet = new IndexLifecycleFeatureSet(settings.build(), licenseState, clusterService);
assertThat(featureSet.enabled(), equalTo(true));
assertSettingDeprecationsAndWarnings(new Setting<?>[] { XPackSettings.INDEX_LIFECYCLE_ENABLED } );
}
public void testName() { public void testName() {
IndexLifecycleFeatureSet featureSet = new IndexLifecycleFeatureSet(Settings.EMPTY, licenseState, clusterService); IndexLifecycleFeatureSet featureSet = new IndexLifecycleFeatureSet(licenseState, clusterService);
assertThat(featureSet.name(), equalTo("ilm")); assertThat(featureSet.name(), equalTo("ilm"));
} }
public void testNativeCodeInfo() { public void testNativeCodeInfo() {
IndexLifecycleFeatureSet featureSet = new IndexLifecycleFeatureSet(Settings.EMPTY, licenseState, clusterService); IndexLifecycleFeatureSet featureSet = new IndexLifecycleFeatureSet(licenseState, clusterService);
assertNull(featureSet.nativeCodeInfo()); assertNull(featureSet.nativeCodeInfo());
} }
@ -114,7 +101,7 @@ public class IndexLifecycleFeatureSetTests extends ESTestCase {
Mockito.when(clusterService.state()).thenReturn(clusterState); Mockito.when(clusterService.state()).thenReturn(clusterState);
PlainActionFuture<IndexLifecycleFeatureSet.Usage> future = new PlainActionFuture<>(); PlainActionFuture<IndexLifecycleFeatureSet.Usage> future = new PlainActionFuture<>();
IndexLifecycleFeatureSet ilmFeatureSet = new IndexLifecycleFeatureSet(Settings.EMPTY, licenseState, clusterService); IndexLifecycleFeatureSet ilmFeatureSet = new IndexLifecycleFeatureSet(licenseState, clusterService);
ilmFeatureSet.usage(future); ilmFeatureSet.usage(future);
IndexLifecycleFeatureSetUsage ilmUsage = (IndexLifecycleFeatureSetUsage) future.get(); IndexLifecycleFeatureSetUsage ilmUsage = (IndexLifecycleFeatureSetUsage) future.get();
assertThat(ilmUsage.enabled(), equalTo(ilmFeatureSet.enabled())); assertThat(ilmUsage.enabled(), equalTo(ilmFeatureSet.enabled()));

View File

@ -20,35 +20,30 @@ public class IndexLifecycleFeatureSetUsageTests extends AbstractWireSerializingT
@Override @Override
protected IndexLifecycleFeatureSetUsage createTestInstance() { protected IndexLifecycleFeatureSetUsage createTestInstance() {
boolean available = randomBoolean(); boolean available = randomBoolean();
boolean enabled = randomBoolean();
List<PolicyStats> policyStats = new ArrayList<>(); List<PolicyStats> policyStats = new ArrayList<>();
int size = randomIntBetween(0, 10); int size = randomIntBetween(0, 10);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
policyStats.add(PolicyStatsTests.randomPolicyStats()); policyStats.add(PolicyStatsTests.randomPolicyStats());
} }
return new IndexLifecycleFeatureSetUsage(available, enabled, policyStats); return new IndexLifecycleFeatureSetUsage(available, policyStats);
} }
@Override @Override
protected IndexLifecycleFeatureSetUsage mutateInstance(IndexLifecycleFeatureSetUsage instance) throws IOException { protected IndexLifecycleFeatureSetUsage mutateInstance(IndexLifecycleFeatureSetUsage instance) throws IOException {
boolean available = instance.available(); boolean available = instance.available();
boolean enabled = instance.enabled();
List<PolicyStats> policyStats = instance.getPolicyStats(); List<PolicyStats> policyStats = instance.getPolicyStats();
switch (between(0, 2)) { switch (between(0, 1)) {
case 0: case 0:
available = available == false; available = available == false;
break; break;
case 1: case 1:
enabled = enabled == false;
break;
case 2:
policyStats = new ArrayList<>(policyStats); policyStats = new ArrayList<>(policyStats);
policyStats.add(PolicyStatsTests.randomPolicyStats()); policyStats.add(PolicyStatsTests.randomPolicyStats());
break; break;
default: default:
throw new AssertionError("Illegal randomisation branch"); throw new AssertionError("Illegal randomisation branch");
} }
return new IndexLifecycleFeatureSetUsage(available, enabled, policyStats); return new IndexLifecycleFeatureSetUsage(available, policyStats);
} }
@Override @Override

View File

@ -116,7 +116,6 @@ public class IndexLifecycleInitialisationTests extends ESIntegTestCase {
@Override @Override
protected Settings transportClientSettings() { protected Settings transportClientSettings() {
Settings.Builder settings = Settings.builder().put(super.transportClientSettings()); Settings.Builder settings = Settings.builder().put(super.transportClientSettings());
settings.put(XPackSettings.INDEX_LIFECYCLE_ENABLED.getKey(), true);
settings.put(XPackSettings.MACHINE_LEARNING_ENABLED.getKey(), false); settings.put(XPackSettings.MACHINE_LEARNING_ENABLED.getKey(), false);
settings.put(XPackSettings.SECURITY_ENABLED.getKey(), false); settings.put(XPackSettings.SECURITY_ENABLED.getKey(), false);
settings.put(XPackSettings.WATCHER_ENABLED.getKey(), false); settings.put(XPackSettings.WATCHER_ENABLED.getKey(), false);

View File

@ -87,7 +87,6 @@ public class SLMSnapshotBlockingIntegTests extends ESIntegTestCase {
@Override @Override
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
Settings.Builder settings = Settings.builder().put(super.nodeSettings(nodeOrdinal)); Settings.Builder settings = Settings.builder().put(super.nodeSettings(nodeOrdinal));
settings.put(XPackSettings.INDEX_LIFECYCLE_ENABLED.getKey(), true);
settings.put(XPackSettings.MACHINE_LEARNING_ENABLED.getKey(), false); settings.put(XPackSettings.MACHINE_LEARNING_ENABLED.getKey(), false);
settings.put(XPackSettings.SECURITY_ENABLED.getKey(), false); settings.put(XPackSettings.SECURITY_ENABLED.getKey(), false);
settings.put(XPackSettings.WATCHER_ENABLED.getKey(), false); settings.put(XPackSettings.WATCHER_ENABLED.getKey(), false);
@ -106,7 +105,6 @@ public class SLMSnapshotBlockingIntegTests extends ESIntegTestCase {
@Override @Override
protected Settings transportClientSettings() { protected Settings transportClientSettings() {
Settings.Builder settings = Settings.builder().put(super.transportClientSettings()); Settings.Builder settings = Settings.builder().put(super.transportClientSettings());
settings.put(XPackSettings.INDEX_LIFECYCLE_ENABLED.getKey(), true);
settings.put(XPackSettings.MACHINE_LEARNING_ENABLED.getKey(), false); settings.put(XPackSettings.MACHINE_LEARNING_ENABLED.getKey(), false);
settings.put(XPackSettings.SECURITY_ENABLED.getKey(), false); settings.put(XPackSettings.SECURITY_ENABLED.getKey(), false);
settings.put(XPackSettings.WATCHER_ENABLED.getKey(), false); settings.put(XPackSettings.WATCHER_ENABLED.getKey(), false);

View File

@ -44,7 +44,6 @@ public class SnapshotLifecycleInitialisationTests extends ESSingleNodeTestCase {
@Override @Override
protected Settings nodeSettings() { protected Settings nodeSettings() {
Settings.Builder settings = Settings.builder().put(super.nodeSettings()); Settings.Builder settings = Settings.builder().put(super.nodeSettings());
settings.put(XPackSettings.INDEX_LIFECYCLE_ENABLED.getKey(), false);
settings.put(XPackSettings.MACHINE_LEARNING_ENABLED.getKey(), false); settings.put(XPackSettings.MACHINE_LEARNING_ENABLED.getKey(), false);
settings.put(XPackSettings.SECURITY_ENABLED.getKey(), false); settings.put(XPackSettings.SECURITY_ENABLED.getKey(), false);
settings.put(XPackSettings.WATCHER_ENABLED.getKey(), false); settings.put(XPackSettings.WATCHER_ENABLED.getKey(), false);

View File

@ -12,7 +12,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ClientHelper; import org.elasticsearch.xpack.core.ClientHelper;
import org.elasticsearch.xpack.core.XPackSettings;
import org.elasticsearch.xpack.core.ml.MlConfigIndex; import org.elasticsearch.xpack.core.ml.MlConfigIndex;
import org.elasticsearch.xpack.core.ml.MlMetaIndex; import org.elasticsearch.xpack.core.ml.MlMetaIndex;
import org.elasticsearch.xpack.core.ml.MlStatsIndex; import org.elasticsearch.xpack.core.ml.MlStatsIndex;
@ -36,11 +35,12 @@ public class MlIndexTemplateRegistry extends IndexTemplateRegistry {
private static final String ANOMALY_DETECTION_PATH = ROOT_RESOURCE_PATH + "anomalydetection/"; private static final String ANOMALY_DETECTION_PATH = ROOT_RESOURCE_PATH + "anomalydetection/";
private static final String VERSION_PATTERN = "xpack.ml.version"; private static final String VERSION_PATTERN = "xpack.ml.version";
private static final String VERSION_ID_PATTERN = "xpack.ml.version.id"; private static final String VERSION_ID_PATTERN = "xpack.ml.version.id";
private static final String INDEX_LIFECYCLE_NAME = "xpack.ml.index.lifecycle.name";
private static final String INDEX_LIFECYCLE_ROLLOVER_ALIAS = "xpack.ml.index.lifecycle.rollover_alias";
private static final IndexTemplateConfig ANOMALY_DETECTION_RESULTS_TEMPLATE = anomalyDetectionResultsTemplate(); private static final IndexTemplateConfig ANOMALY_DETECTION_RESULTS_TEMPLATE = anomalyDetectionResultsTemplate();
private static final IndexTemplateConfig ANOMALY_DETECTION_STATE_TEMPLATE = stateTemplate(true); private static final IndexTemplateConfig ANOMALY_DETECTION_STATE_TEMPLATE = stateTemplate();
private static final IndexTemplateConfig ANOMALY_DETECTION_STATE_TEMPLATE_NO_ILM = stateTemplate(false);
private static final IndexTemplateConfig META_TEMPLATE = new IndexTemplateConfig(MlMetaIndex.INDEX_NAME, private static final IndexTemplateConfig META_TEMPLATE = new IndexTemplateConfig(MlMetaIndex.INDEX_NAME,
ROOT_RESOURCE_PATH + "meta_index_template.json", Version.CURRENT.id, VERSION_PATTERN, ROOT_RESOURCE_PATH + "meta_index_template.json", Version.CURRENT.id, VERSION_PATTERN,
@ -56,8 +56,7 @@ public class MlIndexTemplateRegistry extends IndexTemplateRegistry {
ROOT_RESOURCE_PATH + "inference_index_template.json", Version.CURRENT.id, VERSION_PATTERN, ROOT_RESOURCE_PATH + "inference_index_template.json", Version.CURRENT.id, VERSION_PATTERN,
Collections.singletonMap(VERSION_ID_PATTERN, String.valueOf(Version.CURRENT.id))); Collections.singletonMap(VERSION_ID_PATTERN, String.valueOf(Version.CURRENT.id)));
private static final IndexTemplateConfig STATS_TEMPLATE = statsTemplate(true); private static final IndexTemplateConfig STATS_TEMPLATE = statsTemplate();
private static final IndexTemplateConfig STATS_TEMPLATE_NO_ILM = statsTemplate(false);
private static final String ML_SIZE_BASED_ILM_POLICY_NAME = "ml-size-based-ilm-policy"; private static final String ML_SIZE_BASED_ILM_POLICY_NAME = "ml-size-based-ilm-policy";
private static final LifecyclePolicyConfig ML_SIZE_BASED_ILM_POLICY = private static final LifecyclePolicyConfig ML_SIZE_BASED_ILM_POLICY =
@ -76,15 +75,11 @@ public class MlIndexTemplateRegistry extends IndexTemplateRegistry {
variables); variables);
} }
private static IndexTemplateConfig stateTemplate(boolean ilmEnabled) { private static IndexTemplateConfig stateTemplate() {
Map<String, String> variables = new HashMap<>(); Map<String, String> variables = new HashMap<>();
variables.put(VERSION_ID_PATTERN, String.valueOf(Version.CURRENT.id)); variables.put(VERSION_ID_PATTERN, String.valueOf(Version.CURRENT.id));
variables.put( variables.put(INDEX_LIFECYCLE_NAME, ML_SIZE_BASED_ILM_POLICY_NAME);
"xpack.ml.index.lifecycle.settings", variables.put(INDEX_LIFECYCLE_ROLLOVER_ALIAS, AnomalyDetectorsIndex.jobStateIndexWriteAlias());
ilmEnabled
? ",\"index.lifecycle.name\": \"" + ML_SIZE_BASED_ILM_POLICY_NAME + "\"\n" +
",\"index.lifecycle.rollover_alias\": \"" + AnomalyDetectorsIndex.jobStateIndexWriteAlias() + "\"\n"
: "");
return new IndexTemplateConfig(AnomalyDetectorsIndexFields.STATE_INDEX_PREFIX, return new IndexTemplateConfig(AnomalyDetectorsIndexFields.STATE_INDEX_PREFIX,
ANOMALY_DETECTION_PATH + "state_index_template.json", ANOMALY_DETECTION_PATH + "state_index_template.json",
@ -103,16 +98,12 @@ public class MlIndexTemplateRegistry extends IndexTemplateRegistry {
variables); variables);
} }
private static IndexTemplateConfig statsTemplate(boolean ilmEnabled) { private static IndexTemplateConfig statsTemplate() {
Map<String, String> variables = new HashMap<>(); Map<String, String> variables = new HashMap<>();
variables.put(VERSION_ID_PATTERN, String.valueOf(Version.CURRENT.id)); variables.put(VERSION_ID_PATTERN, String.valueOf(Version.CURRENT.id));
variables.put("xpack.ml.stats.mappings", MlStatsIndex.mapping()); variables.put("xpack.ml.stats.mappings", MlStatsIndex.mapping());
variables.put( variables.put(INDEX_LIFECYCLE_NAME, ML_SIZE_BASED_ILM_POLICY_NAME);
"xpack.ml.index.lifecycle.settings", variables.put(INDEX_LIFECYCLE_ROLLOVER_ALIAS, MlStatsIndex.writeAlias());
ilmEnabled
? ",\"index.lifecycle.name\": \"" + ML_SIZE_BASED_ILM_POLICY_NAME + "\"\n" +
",\"index.lifecycle.rollover_alias\": \"" + MlStatsIndex.writeAlias() + "\"\n"
: "");
return new IndexTemplateConfig(MlStatsIndex.TEMPLATE_NAME, return new IndexTemplateConfig(MlStatsIndex.TEMPLATE_NAME,
ROOT_RESOURCE_PATH + "stats_index_template.json", ROOT_RESOURCE_PATH + "stats_index_template.json",
@ -125,15 +116,14 @@ public class MlIndexTemplateRegistry extends IndexTemplateRegistry {
public MlIndexTemplateRegistry(Settings nodeSettings, ClusterService clusterService, ThreadPool threadPool, Client client, public MlIndexTemplateRegistry(Settings nodeSettings, ClusterService clusterService, ThreadPool threadPool, Client client,
NamedXContentRegistry xContentRegistry) { NamedXContentRegistry xContentRegistry) {
super(nodeSettings, clusterService, threadPool, client, xContentRegistry); super(nodeSettings, clusterService, threadPool, client, xContentRegistry);
boolean ilmEnabled = XPackSettings.INDEX_LIFECYCLE_ENABLED.get(settings);
templatesToUse = Arrays.asList( templatesToUse = Arrays.asList(
ANOMALY_DETECTION_RESULTS_TEMPLATE, ANOMALY_DETECTION_RESULTS_TEMPLATE,
ilmEnabled ? ANOMALY_DETECTION_STATE_TEMPLATE : ANOMALY_DETECTION_STATE_TEMPLATE_NO_ILM, ANOMALY_DETECTION_STATE_TEMPLATE,
CONFIG_TEMPLATE, CONFIG_TEMPLATE,
INFERENCE_TEMPLATE, INFERENCE_TEMPLATE,
META_TEMPLATE, META_TEMPLATE,
NOTIFICATIONS_TEMPLATE, NOTIFICATIONS_TEMPLATE,
ilmEnabled ? STATS_TEMPLATE : STATS_TEMPLATE_NO_ILM); STATS_TEMPLATE);
} }
@Override @Override

View File

@ -20,14 +20,12 @@ import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.XPackSettings;
import org.elasticsearch.xpack.core.ilm.LifecycleAction; import org.elasticsearch.xpack.core.ilm.LifecycleAction;
import org.elasticsearch.xpack.core.ilm.RolloverAction; import org.elasticsearch.xpack.core.ilm.RolloverAction;
import org.elasticsearch.xpack.core.ml.MlStatsIndex; import org.elasticsearch.xpack.core.ml.MlStatsIndex;
@ -42,8 +40,6 @@ import java.util.List;
import static org.elasticsearch.mock.orig.Mockito.verify; import static org.elasticsearch.mock.orig.Mockito.verify;
import static org.elasticsearch.mock.orig.Mockito.when; import static org.elasticsearch.mock.orig.Mockito.when;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
@ -84,7 +80,7 @@ public class MlIndexTemplateRegistryTests extends ESTestCase {
putIndexTemplateRequestCaptor = ArgumentCaptor.forClass(PutIndexTemplateRequest.class); putIndexTemplateRequestCaptor = ArgumentCaptor.forClass(PutIndexTemplateRequest.class);
} }
public void testStateTemplateWithIlm() { public void testStateTemplate() {
MlIndexTemplateRegistry registry = MlIndexTemplateRegistry registry =
new MlIndexTemplateRegistry(Settings.EMPTY, clusterService, threadPool, client, xContentRegistry); new MlIndexTemplateRegistry(Settings.EMPTY, clusterService, threadPool, client, xContentRegistry);
@ -100,29 +96,7 @@ public class MlIndexTemplateRegistryTests extends ESTestCase {
assertThat(req.settings().get("index.lifecycle.rollover_alias"), equalTo(".ml-state-write")); assertThat(req.settings().get("index.lifecycle.rollover_alias"), equalTo(".ml-state-write"));
} }
public void testStateTemplateWithNoIlm() { public void testStatsTemplate() {
MlIndexTemplateRegistry registry =
new MlIndexTemplateRegistry(
Settings.builder()
.put(XPackSettings.INDEX_LIFECYCLE_ENABLED.getKey(), false)
.build(),
clusterService, threadPool, client, xContentRegistry);
registry.clusterChanged(createClusterChangedEvent(nodes));
verify(client.admin().indices(), times(7)).putTemplate(putIndexTemplateRequestCaptor.capture(), anyObject());
PutIndexTemplateRequest req = putIndexTemplateRequestCaptor.getAllValues().stream()
.filter(r -> r.name().equals(AnomalyDetectorsIndexFields.STATE_INDEX_PREFIX))
.findFirst()
.orElseThrow(() -> new AssertionError("expected the ml state index template to be put"));
assertThat(req.settings().get("index.lifecycle.name"), is(nullValue()));
assertThat(req.settings().get("index.lifecycle.rollover_alias"), is(nullValue()));
assertSettingDeprecationsAndWarnings(new Setting<?>[] { XPackSettings.INDEX_LIFECYCLE_ENABLED } );
}
public void testStatsTemplateWithIlm() {
MlIndexTemplateRegistry registry = MlIndexTemplateRegistry registry =
new MlIndexTemplateRegistry(Settings.EMPTY, clusterService, threadPool, client, xContentRegistry); new MlIndexTemplateRegistry(Settings.EMPTY, clusterService, threadPool, client, xContentRegistry);
@ -138,28 +112,6 @@ public class MlIndexTemplateRegistryTests extends ESTestCase {
assertThat(req.settings().get("index.lifecycle.rollover_alias"), equalTo(".ml-stats-write")); assertThat(req.settings().get("index.lifecycle.rollover_alias"), equalTo(".ml-stats-write"));
} }
public void testStatsTemplateWithNoIlm() {
MlIndexTemplateRegistry registry =
new MlIndexTemplateRegistry(
Settings.builder()
.put(XPackSettings.INDEX_LIFECYCLE_ENABLED.getKey(), false)
.build(),
clusterService, threadPool, client, xContentRegistry);
registry.clusterChanged(createClusterChangedEvent(nodes));
verify(client.admin().indices(), times(7)).putTemplate(putIndexTemplateRequestCaptor.capture(), anyObject());
PutIndexTemplateRequest req = putIndexTemplateRequestCaptor.getAllValues().stream()
.filter(r -> r.name().equals(MlStatsIndex.TEMPLATE_NAME))
.findFirst()
.orElseThrow(() -> new AssertionError("expected the ml stats index template to be put"));
assertThat(req.settings().get("index.lifecycle.name"), is(nullValue()));
assertThat(req.settings().get("index.lifecycle.rollover_alias"), is(nullValue()));
assertSettingDeprecationsAndWarnings(new Setting<?>[] { XPackSettings.INDEX_LIFECYCLE_ENABLED } );
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) { private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> { return invocationOnMock -> {

View File

@ -212,6 +212,8 @@ public class Watcher extends Plugin implements SystemIndexPlugin, ScriptPlugin,
Setting.boolSetting("xpack.watcher.encrypt_sensitive_data", false, Setting.Property.NodeScope); Setting.boolSetting("xpack.watcher.encrypt_sensitive_data", false, Setting.Property.NodeScope);
public static final Setting<TimeValue> MAX_STOP_TIMEOUT_SETTING = public static final Setting<TimeValue> MAX_STOP_TIMEOUT_SETTING =
Setting.timeSetting("xpack.watcher.stop.timeout", TimeValue.timeValueSeconds(30), Setting.Property.NodeScope); Setting.timeSetting("xpack.watcher.stop.timeout", TimeValue.timeValueSeconds(30), Setting.Property.NodeScope);
public static final Setting<Boolean> USE_ILM_INDEX_MANAGEMENT =
Setting.boolSetting("xpack.watcher.use_ilm_index_management", XPackSettings.INDEX_LIFECYCLE_ENABLED, NodeScope);
private static final Setting<Integer> SETTING_BULK_ACTIONS = private static final Setting<Integer> SETTING_BULK_ACTIONS =
Setting.intSetting("xpack.watcher.bulk.actions", 1, 1, 10000, NodeScope); Setting.intSetting("xpack.watcher.bulk.actions", 1, 1, 10000, NodeScope);
private static final Setting<Integer> SETTING_BULK_CONCURRENT_REQUESTS = private static final Setting<Integer> SETTING_BULK_CONCURRENT_REQUESTS =
@ -470,6 +472,7 @@ public class Watcher extends Plugin implements SystemIndexPlugin, ScriptPlugin,
settings.add(Setting.intSetting("xpack.watcher.watch.scroll.size", 0, Setting.Property.NodeScope)); settings.add(Setting.intSetting("xpack.watcher.watch.scroll.size", 0, Setting.Property.NodeScope));
settings.add(ENCRYPT_SENSITIVE_DATA_SETTING); settings.add(ENCRYPT_SENSITIVE_DATA_SETTING);
settings.add(WatcherField.ENCRYPTION_KEY_SETTING); settings.add(WatcherField.ENCRYPTION_KEY_SETTING);
settings.add(USE_ILM_INDEX_MANAGEMENT);
settings.add(Setting.simpleString("xpack.watcher.internal.ops.search.default_timeout", Setting.Property.NodeScope)); settings.add(Setting.simpleString("xpack.watcher.internal.ops.search.default_timeout", Setting.Property.NodeScope));
settings.add(Setting.simpleString("xpack.watcher.internal.ops.bulk.default_timeout", Setting.Property.NodeScope)); settings.add(Setting.simpleString("xpack.watcher.internal.ops.bulk.default_timeout", Setting.Property.NodeScope));

View File

@ -12,11 +12,11 @@ import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.XPackSettings;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig; import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.elasticsearch.xpack.core.template.IndexTemplateRegistry; import org.elasticsearch.xpack.core.template.IndexTemplateRegistry;
import org.elasticsearch.xpack.core.template.LifecyclePolicyConfig; import org.elasticsearch.xpack.core.template.LifecyclePolicyConfig;
import org.elasticsearch.xpack.core.watcher.support.WatcherIndexTemplateRegistryField; import org.elasticsearch.xpack.core.watcher.support.WatcherIndexTemplateRegistryField;
import org.elasticsearch.xpack.watcher.Watcher;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -61,33 +61,39 @@ public class WatcherIndexTemplateRegistry extends IndexTemplateRegistry {
public static final LifecyclePolicyConfig POLICY_WATCH_HISTORY = new LifecyclePolicyConfig("watch-history-ilm-policy", public static final LifecyclePolicyConfig POLICY_WATCH_HISTORY = new LifecyclePolicyConfig("watch-history-ilm-policy",
"/watch-history-ilm-policy.json"); "/watch-history-ilm-policy.json");
private final boolean ilmEnabled; private final boolean ilmManagementEnabled;
public WatcherIndexTemplateRegistry(Settings nodeSettings, ClusterService clusterService, ThreadPool threadPool, Client client, public WatcherIndexTemplateRegistry(Settings nodeSettings, ClusterService clusterService, ThreadPool threadPool, Client client,
NamedXContentRegistry xContentRegistry) { NamedXContentRegistry xContentRegistry) {
super(nodeSettings, clusterService, threadPool, client, xContentRegistry); super(nodeSettings, clusterService, threadPool, client, xContentRegistry);
this.ilmEnabled = XPackSettings.INDEX_LIFECYCLE_ENABLED.get(settings); ilmManagementEnabled = Watcher.USE_ILM_INDEX_MANAGEMENT.get(nodeSettings);
} }
@Override @Override
protected List<IndexTemplateConfig> getTemplateConfigs() { protected List<IndexTemplateConfig> getTemplateConfigs() {
if (clusterService.state().nodes().getMinNodeVersion().onOrAfter(Version.V_7_7_0)) { if (clusterService.state().nodes().getMinNodeVersion().onOrAfter(Version.V_7_7_0)) {
return Arrays.asList( return Arrays.asList(
ilmEnabled ? TEMPLATE_CONFIG_WATCH_HISTORY : TEMPLATE_CONFIG_WATCH_HISTORY_NO_ILM, ilmManagementEnabled ? TEMPLATE_CONFIG_WATCH_HISTORY : TEMPLATE_CONFIG_WATCH_HISTORY_NO_ILM,
TEMPLATE_CONFIG_TRIGGERED_WATCHES, TEMPLATE_CONFIG_TRIGGERED_WATCHES,
TEMPLATE_CONFIG_WATCHES TEMPLATE_CONFIG_WATCHES
); );
} else { } else {
return Arrays.asList( return Arrays.asList(
ilmEnabled ? TEMPLATE_CONFIG_WATCH_HISTORY_10 : TEMPLATE_CONFIG_WATCH_HISTORY_NO_ILM_10, ilmManagementEnabled ? TEMPLATE_CONFIG_WATCH_HISTORY_10 : TEMPLATE_CONFIG_WATCH_HISTORY_NO_ILM_10,
TEMPLATE_CONFIG_TRIGGERED_WATCHES, TEMPLATE_CONFIG_TRIGGERED_WATCHES,
TEMPLATE_CONFIG_WATCHES TEMPLATE_CONFIG_WATCHES
); );
} }
} }
/**
* If Watcher is configured not to use ILM, we don't return a policy.
*/
@Override @Override
protected List<LifecyclePolicyConfig> getPolicyConfigs() { protected List<LifecyclePolicyConfig> getPolicyConfigs() {
if (Watcher.USE_ILM_INDEX_MANAGEMENT.get(settings) == false) {
return Collections.emptyList();
}
return Collections.singletonList(POLICY_WATCH_HISTORY); return Collections.singletonList(POLICY_WATCH_HISTORY);
} }

View File

@ -6,6 +6,7 @@
package org.elasticsearch.xpack.watcher; package org.elasticsearch.xpack.watcher;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.TestEnvironment; import org.elasticsearch.env.TestEnvironment;
import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexModule;
@ -15,6 +16,7 @@ import org.elasticsearch.index.engine.InternalEngineFactory;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.IndexSettingsModule; import org.elasticsearch.test.IndexSettingsModule;
import org.elasticsearch.threadpool.ExecutorBuilder; import org.elasticsearch.threadpool.ExecutorBuilder;
import org.elasticsearch.xpack.core.XPackSettings;
import org.elasticsearch.xpack.core.watcher.watch.Watch; import org.elasticsearch.xpack.core.watcher.watch.Watch;
import org.elasticsearch.xpack.watcher.notification.NotificationService; import org.elasticsearch.xpack.watcher.notification.NotificationService;
@ -87,6 +89,23 @@ public class WatcherPluginTests extends ESTestCase {
watcher.close(); watcher.close();
} }
public void testWatcherUseIlmFallsBackToIlmEnabled() throws Exception {
boolean ilmEnabled = randomBoolean();
Settings settingsWithoutWatcherUseIlm = Settings.builder()
.put(XPackSettings.INDEX_LIFECYCLE_ENABLED.getKey(), ilmEnabled)
.build();
assertThat(Watcher.USE_ILM_INDEX_MANAGEMENT.get(settingsWithoutWatcherUseIlm), is(ilmEnabled));
boolean watcherUseIlmEnabled = randomBoolean();
Settings settingsWithWatcherUseIlm = Settings.builder()
.put(XPackSettings.INDEX_LIFECYCLE_ENABLED.getKey(), ilmEnabled)
.put(Watcher.USE_ILM_INDEX_MANAGEMENT.getKey(), watcherUseIlmEnabled)
.build();
assertThat(Watcher.USE_ILM_INDEX_MANAGEMENT.get(settingsWithWatcherUseIlm), is(watcherUseIlmEnabled));
assertSettingDeprecationsAndWarnings(new Setting<?>[] { XPackSettings.INDEX_LIFECYCLE_ENABLED } );
}
public void testThreadPoolSize() { public void testThreadPoolSize() {
// old calculation was 5 * number of processors // old calculation was 5 * number of processors
assertThat(Watcher.getWatcherThreadPoolSize(true, 1), is(5)); assertThat(Watcher.getWatcherThreadPoolSize(true, 1), is(5));

View File

@ -24,7 +24,6 @@ import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.concurrent.ThreadContext;
@ -34,7 +33,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.XPackSettings;
import org.elasticsearch.xpack.core.ilm.DeleteAction; import org.elasticsearch.xpack.core.ilm.DeleteAction;
import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata;
import org.elasticsearch.xpack.core.ilm.LifecycleAction; import org.elasticsearch.xpack.core.ilm.LifecycleAction;
@ -45,6 +43,7 @@ import org.elasticsearch.xpack.core.ilm.OperationMode;
import org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType; import org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType;
import org.elasticsearch.xpack.core.ilm.action.PutLifecycleAction; import org.elasticsearch.xpack.core.ilm.action.PutLifecycleAction;
import org.elasticsearch.xpack.core.watcher.support.WatcherIndexTemplateRegistryField; import org.elasticsearch.xpack.core.watcher.support.WatcherIndexTemplateRegistryField;
import org.elasticsearch.xpack.watcher.Watcher;
import org.junit.Before; import org.junit.Before;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
@ -133,12 +132,12 @@ public class WatcherIndexTemplateRegistryTests extends ESTestCase {
assertThat(req.settings().get("index.lifecycle.name"), equalTo("watch-history-ilm-policy")); assertThat(req.settings().get("index.lifecycle.name"), equalTo("watch-history-ilm-policy"));
} }
public void testThatNonExistingTemplatesAreAddedEvenWithILMDisabled() { public void testThatNonExistingTemplatesAreAddedEvenWithILMUsageDisabled() {
DiscoveryNode node = new DiscoveryNode("node", ESTestCase.buildNewFakeTransportAddress(), Version.CURRENT); DiscoveryNode node = new DiscoveryNode("node", ESTestCase.buildNewFakeTransportAddress(), Version.CURRENT);
DiscoveryNodes nodes = DiscoveryNodes.builder().localNodeId("node").masterNodeId("node").add(node).build(); DiscoveryNodes nodes = DiscoveryNodes.builder().localNodeId("node").masterNodeId("node").add(node).build();
registry = new WatcherIndexTemplateRegistry(Settings.builder() registry = new WatcherIndexTemplateRegistry(Settings.builder()
.put(XPackSettings.INDEX_LIFECYCLE_ENABLED.getKey(), false).build(), .put(Watcher.USE_ILM_INDEX_MANAGEMENT.getKey(), false).build(),
clusterService, threadPool, client, xContentRegistry); clusterService, threadPool, client, xContentRegistry);
ClusterChangedEvent event = createClusterChangedEvent(Settings.EMPTY, Collections.emptyMap(), Collections.emptyMap(), nodes); ClusterChangedEvent event = createClusterChangedEvent(Settings.EMPTY, Collections.emptyMap(), Collections.emptyMap(), nodes);
registry.clusterChanged(event); registry.clusterChanged(event);
@ -155,7 +154,6 @@ public class WatcherIndexTemplateRegistryTests extends ESTestCase {
verify(client.admin().indices(), times(5)).putTemplate(captor.capture(), anyObject()); verify(client.admin().indices(), times(5)).putTemplate(captor.capture(), anyObject());
captor.getAllValues().forEach(req -> assertNull(req.settings().get("index.lifecycle.name"))); captor.getAllValues().forEach(req -> assertNull(req.settings().get("index.lifecycle.name")));
verify(client, times(0)).execute(eq(PutLifecycleAction.INSTANCE), anyObject(), anyObject()); verify(client, times(0)).execute(eq(PutLifecycleAction.INSTANCE), anyObject(), anyObject());
assertSettingDeprecationsAndWarnings(new Setting[]{XPackSettings.INDEX_LIFECYCLE_ENABLED});
} }
public void testThatNonExistingPoliciesAreAddedImmediately() { public void testThatNonExistingPoliciesAreAddedImmediately() {
@ -188,12 +186,11 @@ public class WatcherIndexTemplateRegistryTests extends ESTestCase {
DiscoveryNodes nodes = DiscoveryNodes.builder().localNodeId("node").masterNodeId("node").add(node).build(); DiscoveryNodes nodes = DiscoveryNodes.builder().localNodeId("node").masterNodeId("node").add(node).build();
registry = new WatcherIndexTemplateRegistry(Settings.builder() registry = new WatcherIndexTemplateRegistry(Settings.builder()
.put(XPackSettings.INDEX_LIFECYCLE_ENABLED.getKey(), false).build(), .put(Watcher.USE_ILM_INDEX_MANAGEMENT.getKey(), false).build(),
clusterService, threadPool, client, xContentRegistry); clusterService, threadPool, client, xContentRegistry);
ClusterChangedEvent event = createClusterChangedEvent(Settings.EMPTY, Collections.emptyMap(), Collections.emptyMap(), nodes); ClusterChangedEvent event = createClusterChangedEvent(Settings.EMPTY, Collections.emptyMap(), Collections.emptyMap(), nodes);
registry.clusterChanged(event); registry.clusterChanged(event);
verify(client, times(0)).execute(eq(PutLifecycleAction.INSTANCE), anyObject(), anyObject()); verify(client, times(0)).execute(eq(PutLifecycleAction.INSTANCE), anyObject(), anyObject());
assertSettingDeprecationsAndWarnings(new Setting<?>[]{XPackSettings.INDEX_LIFECYCLE_ENABLED});
} }
public void testPolicyAlreadyExistsButDiffers() throws IOException { public void testPolicyAlreadyExistsButDiffers() throws IOException {