|
@@ -106,13 +106,13 @@ import org.elasticsearch.xpack.slm.action.TransportPutSnapshotLifecycleAction;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.time.Clock;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
-import static java.util.Collections.emptyList;
|
|
|
import static org.elasticsearch.xpack.core.ClientHelper.INDEX_LIFECYCLE_ORIGIN;
|
|
|
|
|
|
public class IndexLifecycle extends Plugin implements ActionPlugin {
|
|
@@ -121,11 +121,13 @@ public class IndexLifecycle extends Plugin implements ActionPlugin {
|
|
|
private final SetOnce<SnapshotRetentionService> snapshotRetentionService = new SetOnce<>();
|
|
|
private final SetOnce<SnapshotHistoryStore> snapshotHistoryStore = new SetOnce<>();
|
|
|
private Settings settings;
|
|
|
- private boolean enabled;
|
|
|
+ private boolean ilmEnabled;
|
|
|
+ private boolean slmEnabled;
|
|
|
|
|
|
public IndexLifecycle(Settings settings) {
|
|
|
this.settings = settings;
|
|
|
- this.enabled = XPackSettings.INDEX_LIFECYCLE_ENABLED.get(settings);
|
|
|
+ this.ilmEnabled = XPackSettings.INDEX_LIFECYCLE_ENABLED.get(settings);
|
|
|
+ this.slmEnabled = XPackSettings.SNAPSHOT_LIFECYCLE_ENABLED.get(settings);
|
|
|
}
|
|
|
|
|
|
// overridable by tests
|
|
@@ -150,22 +152,25 @@ public class IndexLifecycle extends Plugin implements ActionPlugin {
|
|
|
ResourceWatcherService resourceWatcherService, ScriptService scriptService,
|
|
|
NamedXContentRegistry xContentRegistry, Environment environment,
|
|
|
NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry) {
|
|
|
- if (enabled == false) {
|
|
|
- return emptyList();
|
|
|
- }
|
|
|
- indexLifecycleInitialisationService.set(new IndexLifecycleService(settings, client, clusterService, threadPool,
|
|
|
+ final List<Object> components = new ArrayList<>();
|
|
|
+ if (ilmEnabled) {
|
|
|
+ indexLifecycleInitialisationService.set(new IndexLifecycleService(settings, client, clusterService, threadPool,
|
|
|
getClock(), System::currentTimeMillis, xContentRegistry));
|
|
|
- SnapshotLifecycleTemplateRegistry templateRegistry = new SnapshotLifecycleTemplateRegistry(settings, clusterService, threadPool,
|
|
|
- client, xContentRegistry);
|
|
|
- snapshotHistoryStore.set(new SnapshotHistoryStore(settings, new OriginSettingClient(client, INDEX_LIFECYCLE_ORIGIN), clusterService
|
|
|
- ));
|
|
|
- snapshotLifecycleService.set(new SnapshotLifecycleService(settings,
|
|
|
- () -> new SnapshotLifecycleTask(client, clusterService, snapshotHistoryStore.get()), clusterService, getClock()));
|
|
|
- snapshotRetentionService.set(new SnapshotRetentionService(settings,
|
|
|
- () -> new SnapshotRetentionTask(client, clusterService, System::nanoTime, snapshotHistoryStore.get(), threadPool),
|
|
|
- clusterService, getClock()));
|
|
|
- return Arrays.asList(indexLifecycleInitialisationService.get(), snapshotLifecycleService.get(), snapshotHistoryStore.get(),
|
|
|
- snapshotRetentionService.get());
|
|
|
+ components.add(indexLifecycleInitialisationService.get());
|
|
|
+ }
|
|
|
+ if (slmEnabled) {
|
|
|
+ SnapshotLifecycleTemplateRegistry templateRegistry = new SnapshotLifecycleTemplateRegistry(settings, clusterService, threadPool,
|
|
|
+ client, xContentRegistry);
|
|
|
+ snapshotHistoryStore.set(new SnapshotHistoryStore(settings, new OriginSettingClient(client, INDEX_LIFECYCLE_ORIGIN),
|
|
|
+ clusterService));
|
|
|
+ snapshotLifecycleService.set(new SnapshotLifecycleService(settings,
|
|
|
+ () -> new SnapshotLifecycleTask(client, clusterService, snapshotHistoryStore.get()), clusterService, getClock()));
|
|
|
+ snapshotRetentionService.set(new SnapshotRetentionService(settings,
|
|
|
+ () -> new SnapshotRetentionTask(client, clusterService, System::nanoTime, snapshotHistoryStore.get(), threadPool),
|
|
|
+ clusterService, getClock()));
|
|
|
+ components.addAll(Arrays.asList(snapshotLifecycleService.get(), snapshotHistoryStore.get(), snapshotRetentionService.get()));
|
|
|
+ }
|
|
|
+ return components;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -201,10 +206,9 @@ public class IndexLifecycle extends Plugin implements ActionPlugin {
|
|
|
public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
|
|
|
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver,
|
|
|
Supplier<DiscoveryNodes> nodesInCluster) {
|
|
|
- if (enabled == false) {
|
|
|
- return emptyList();
|
|
|
- }
|
|
|
- return Arrays.asList(
|
|
|
+ List<RestHandler> handlers = new ArrayList<>();
|
|
|
+ if (ilmEnabled) {
|
|
|
+ handlers.addAll(Arrays.asList(
|
|
|
new RestPutLifecycleAction(restController),
|
|
|
new RestGetLifecycleAction(restController),
|
|
|
new RestDeleteLifecycleAction(restController),
|
|
@@ -214,14 +218,19 @@ public class IndexLifecycle extends Plugin implements ActionPlugin {
|
|
|
new RestRetryAction(restController),
|
|
|
new RestStopAction(restController),
|
|
|
new RestStartILMAction(restController),
|
|
|
- new RestGetStatusAction(restController),
|
|
|
- // Snapshot lifecycle actions
|
|
|
+ new RestGetStatusAction(restController)
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ if (slmEnabled) {
|
|
|
+ handlers.addAll(Arrays.asList(
|
|
|
new RestPutSnapshotLifecycleAction(restController),
|
|
|
new RestDeleteSnapshotLifecycleAction(restController),
|
|
|
new RestGetSnapshotLifecycleAction(restController),
|
|
|
new RestExecuteSnapshotLifecycleAction(restController),
|
|
|
new RestGetSnapshotLifecycleStatsAction(restController)
|
|
|
- );
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ return handlers;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -230,10 +239,11 @@ public class IndexLifecycle extends Plugin implements ActionPlugin {
|
|
|
new ActionHandler<>(XPackUsageFeatureAction.INDEX_LIFECYCLE, IndexLifecycleUsageTransportAction.class);
|
|
|
var infoAction =
|
|
|
new ActionHandler<>(XPackInfoFeatureAction.INDEX_LIFECYCLE, IndexLifecycleInfoTransportAction.class);
|
|
|
- if (enabled == false) {
|
|
|
- return Arrays.asList(usageAction, infoAction);
|
|
|
- }
|
|
|
- return Arrays.asList(
|
|
|
+ List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> actions = new ArrayList<>();
|
|
|
+ actions.add(usageAction);
|
|
|
+ actions.add(infoAction);
|
|
|
+ if (ilmEnabled) {
|
|
|
+ actions.addAll(Arrays.asList(
|
|
|
new ActionHandler<>(PutLifecycleAction.INSTANCE, TransportPutLifecycleAction.class),
|
|
|
new ActionHandler<>(GetLifecycleAction.INSTANCE, TransportGetLifecycleAction.class),
|
|
|
new ActionHandler<>(DeleteLifecycleAction.INSTANCE, TransportDeleteLifecycleAction.class),
|
|
@@ -243,15 +253,19 @@ public class IndexLifecycle extends Plugin implements ActionPlugin {
|
|
|
new ActionHandler<>(RetryAction.INSTANCE, TransportRetryAction.class),
|
|
|
new ActionHandler<>(StartILMAction.INSTANCE, TransportStartILMAction.class),
|
|
|
new ActionHandler<>(StopILMAction.INSTANCE, TransportStopILMAction.class),
|
|
|
- new ActionHandler<>(GetStatusAction.INSTANCE, TransportGetStatusAction.class),
|
|
|
- // Snapshot lifecycle actions
|
|
|
+ new ActionHandler<>(GetStatusAction.INSTANCE, TransportGetStatusAction.class)
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ if (slmEnabled) {
|
|
|
+ actions.addAll(Arrays.asList(
|
|
|
new ActionHandler<>(PutSnapshotLifecycleAction.INSTANCE, TransportPutSnapshotLifecycleAction.class),
|
|
|
new ActionHandler<>(DeleteSnapshotLifecycleAction.INSTANCE, TransportDeleteSnapshotLifecycleAction.class),
|
|
|
new ActionHandler<>(GetSnapshotLifecycleAction.INSTANCE, TransportGetSnapshotLifecycleAction.class),
|
|
|
new ActionHandler<>(ExecuteSnapshotLifecycleAction.INSTANCE, TransportExecuteSnapshotLifecycleAction.class),
|
|
|
- new ActionHandler<>(GetSnapshotLifecycleStatsAction.INSTANCE, TransportGetSnapshotLifecycleStatsAction.class),
|
|
|
- usageAction,
|
|
|
- infoAction);
|
|
|
+ new ActionHandler<>(GetSnapshotLifecycleStatsAction.INSTANCE, TransportGetSnapshotLifecycleStatsAction.class)
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ return actions;
|
|
|
}
|
|
|
|
|
|
@Override
|