108
108
import java .util .List ;
109
109
import java .util .function .Supplier ;
110
110
111
- import static java .util .Collections .emptyList ;
112
111
import static org .elasticsearch .xpack .core .ClientHelper .INDEX_LIFECYCLE_ORIGIN ;
113
112
114
113
public class IndexLifecycle extends Plugin implements ActionPlugin {
115
114
private final SetOnce <IndexLifecycleService > indexLifecycleInitialisationService = new SetOnce <>();
116
115
private final SetOnce <SnapshotLifecycleService > snapshotLifecycleService = new SetOnce <>();
117
116
private final SetOnce <SnapshotHistoryStore > snapshotHistoryStore = new SetOnce <>();
118
117
private Settings settings ;
119
- private boolean enabled ;
118
+ private boolean ilmEnabled ;
119
+ private boolean slmEnabled ;
120
120
private boolean transportClientMode ;
121
121
122
122
public IndexLifecycle (Settings settings ) {
123
123
this .settings = settings ;
124
- this .enabled = XPackSettings .INDEX_LIFECYCLE_ENABLED .get (settings );
124
+ this .ilmEnabled = XPackSettings .INDEX_LIFECYCLE_ENABLED .get (settings );
125
+ this .slmEnabled = XPackSettings .SNAPSHOT_LIFECYCLE_ENABLED .get (settings );
125
126
this .transportClientMode = XPackPlugin .transportClientMode (settings );
126
127
}
127
128
@@ -157,18 +158,25 @@ public Collection<Object> createComponents(Client client, ClusterService cluster
157
158
ResourceWatcherService resourceWatcherService , ScriptService scriptService ,
158
159
NamedXContentRegistry xContentRegistry , Environment environment ,
159
160
NodeEnvironment nodeEnvironment , NamedWriteableRegistry namedWriteableRegistry ) {
160
- if (enabled == false || transportClientMode ) {
161
- return emptyList ();
161
+ if (transportClientMode ) {
162
+ return Collections . emptyList ();
162
163
}
163
- indexLifecycleInitialisationService .set (new IndexLifecycleService (settings , client , clusterService , threadPool ,
164
+ final List <Object > components = new ArrayList <>();
165
+ if (ilmEnabled ) {
166
+ indexLifecycleInitialisationService .set (new IndexLifecycleService (settings , client , clusterService , threadPool ,
164
167
getClock (), System ::currentTimeMillis , xContentRegistry ));
165
- SnapshotLifecycleTemplateRegistry templateRegistry = new SnapshotLifecycleTemplateRegistry (settings , clusterService , threadPool ,
166
- client , xContentRegistry );
167
- snapshotHistoryStore .set (new SnapshotHistoryStore (settings , new OriginSettingClient (client , INDEX_LIFECYCLE_ORIGIN ), clusterService
168
- ));
169
- snapshotLifecycleService .set (new SnapshotLifecycleService (settings ,
170
- () -> new SnapshotLifecycleTask (client , clusterService , snapshotHistoryStore .get ()), clusterService , getClock ()));
171
- return Arrays .asList (indexLifecycleInitialisationService .get (), snapshotLifecycleService .get (), snapshotHistoryStore .get ());
168
+ components .add (indexLifecycleInitialisationService .get ());
169
+ }
170
+ if (slmEnabled ) {
171
+ SnapshotLifecycleTemplateRegistry templateRegistry = new SnapshotLifecycleTemplateRegistry (settings , clusterService , threadPool ,
172
+ client , xContentRegistry );
173
+ snapshotHistoryStore .set (new SnapshotHistoryStore (settings , new OriginSettingClient (client , INDEX_LIFECYCLE_ORIGIN ),
174
+ clusterService ));
175
+ snapshotLifecycleService .set (new SnapshotLifecycleService (settings ,
176
+ () -> new SnapshotLifecycleTask (client , clusterService , snapshotHistoryStore .get ()), clusterService , getClock ()));
177
+ components .addAll (Arrays .asList (snapshotLifecycleService .get (), snapshotHistoryStore .get ()));
178
+ }
179
+ return components ;
172
180
}
173
181
174
182
@ Override
@@ -204,10 +212,9 @@ public List<org.elasticsearch.common.xcontent.NamedXContentRegistry.Entry> getNa
204
212
public List <RestHandler > getRestHandlers (Settings settings , RestController restController , ClusterSettings clusterSettings ,
205
213
IndexScopedSettings indexScopedSettings , SettingsFilter settingsFilter , IndexNameExpressionResolver indexNameExpressionResolver ,
206
214
Supplier <DiscoveryNodes > nodesInCluster ) {
207
- if (enabled == false ) {
208
- return emptyList ();
209
- }
210
- return Arrays .asList (
215
+ List <RestHandler > handlers = new ArrayList <>();
216
+ if (ilmEnabled ) {
217
+ handlers .addAll (Arrays .asList (
211
218
new RestPutLifecycleAction (restController ),
212
219
new RestGetLifecycleAction (restController ),
213
220
new RestDeleteLifecycleAction (restController ),
@@ -217,21 +224,25 @@ public List<RestHandler> getRestHandlers(Settings settings, RestController restC
217
224
new RestRetryAction (restController ),
218
225
new RestStopAction (restController ),
219
226
new RestStartILMAction (restController ),
220
- new RestGetStatusAction (restController ),
221
- // Snapshot lifecycle actions
227
+ new RestGetStatusAction (restController )
228
+ ));
229
+ }
230
+ if (slmEnabled ) {
231
+ handlers .addAll (Arrays .asList (
222
232
new RestPutSnapshotLifecycleAction (restController ),
223
233
new RestDeleteSnapshotLifecycleAction (restController ),
224
234
new RestGetSnapshotLifecycleAction (restController ),
225
235
new RestExecuteSnapshotLifecycleAction (restController )
226
- );
236
+ ));
237
+ }
238
+ return handlers ;
227
239
}
228
240
229
241
@ Override
230
242
public List <ActionHandler <? extends ActionRequest , ? extends ActionResponse >> getActions () {
231
- if (enabled == false ) {
232
- return emptyList ();
233
- }
234
- return Arrays .asList (
243
+ List <ActionHandler <? extends ActionRequest , ? extends ActionResponse >> actions = new ArrayList <>();
244
+ if (ilmEnabled ) {
245
+ actions .addAll (Arrays .asList (
235
246
new ActionHandler <>(PutLifecycleAction .INSTANCE , TransportPutLifecycleAction .class ),
236
247
new ActionHandler <>(GetLifecycleAction .INSTANCE , TransportGetLifecycleAction .class ),
237
248
new ActionHandler <>(DeleteLifecycleAction .INSTANCE , TransportDeleteLifecycleAction .class ),
@@ -241,12 +252,18 @@ public List<RestHandler> getRestHandlers(Settings settings, RestController restC
241
252
new ActionHandler <>(RetryAction .INSTANCE , TransportRetryAction .class ),
242
253
new ActionHandler <>(StartILMAction .INSTANCE , TransportStartILMAction .class ),
243
254
new ActionHandler <>(StopILMAction .INSTANCE , TransportStopILMAction .class ),
244
- new ActionHandler <>(GetStatusAction .INSTANCE , TransportGetStatusAction .class ),
245
- // Snapshot lifecycle actions
255
+ new ActionHandler <>(GetStatusAction .INSTANCE , TransportGetStatusAction .class )
256
+ ));
257
+ }
258
+ if (slmEnabled ) {
259
+ actions .addAll (Arrays .asList (
246
260
new ActionHandler <>(PutSnapshotLifecycleAction .INSTANCE , TransportPutSnapshotLifecycleAction .class ),
247
261
new ActionHandler <>(DeleteSnapshotLifecycleAction .INSTANCE , TransportDeleteSnapshotLifecycleAction .class ),
248
262
new ActionHandler <>(GetSnapshotLifecycleAction .INSTANCE , TransportGetSnapshotLifecycleAction .class ),
249
- new ActionHandler <>(ExecuteSnapshotLifecycleAction .INSTANCE , TransportExecuteSnapshotLifecycleAction .class ));
263
+ new ActionHandler <>(ExecuteSnapshotLifecycleAction .INSTANCE , TransportExecuteSnapshotLifecycleAction .class )
264
+ ));
265
+ }
266
+ return actions ;
250
267
}
251
268
252
269
@ Override
0 commit comments