|
@@ -12,10 +12,12 @@ import org.elasticsearch.client.internal.Client;
|
|
|
import org.elasticsearch.cluster.ClusterStateObserver;
|
|
|
import org.elasticsearch.cluster.ProjectState;
|
|
|
import org.elasticsearch.cluster.metadata.IndexMetadata;
|
|
|
+import org.elasticsearch.cluster.metadata.LifecycleExecutionState;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.core.TimeValue;
|
|
|
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.function.BiFunction;
|
|
|
+import java.util.function.Function;
|
|
|
|
|
|
/**
|
|
|
* Updates the settings for an index.
|
|
@@ -23,11 +25,32 @@ import java.util.Objects;
|
|
|
public class UpdateSettingsStep extends AsyncActionStep {
|
|
|
public static final String NAME = "update-settings";
|
|
|
|
|
|
- private final Settings settings;
|
|
|
+ private static final BiFunction<String, LifecycleExecutionState, String> DEFAULT_TARGET_INDEX_NAME_SUPPLIER = (index, state) -> index;
|
|
|
|
|
|
+ private final BiFunction<String, LifecycleExecutionState, String> targetIndexNameSupplier;
|
|
|
+ private final Function<IndexMetadata, Settings> settingsSupplier;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Use this constructor when you want to update the index that ILM runs on with <i>constant</i> settings.
|
|
|
+ */
|
|
|
public UpdateSettingsStep(StepKey key, StepKey nextStepKey, Client client, Settings settings) {
|
|
|
+ this(key, nextStepKey, client, DEFAULT_TARGET_INDEX_NAME_SUPPLIER, indexMetadata -> settings);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Use this constructor when you want to update an index other than the one ILM runs on, and/or when you have non-constant settings
|
|
|
+ * (i.e., settings that depend on the index metadata).
|
|
|
+ */
|
|
|
+ public UpdateSettingsStep(
|
|
|
+ StepKey key,
|
|
|
+ StepKey nextStepKey,
|
|
|
+ Client client,
|
|
|
+ BiFunction<String, LifecycleExecutionState, String> targetIndexNameSupplier,
|
|
|
+ Function<IndexMetadata, Settings> settingsSupplier
|
|
|
+ ) {
|
|
|
super(key, nextStepKey, client);
|
|
|
- this.settings = settings;
|
|
|
+ this.targetIndexNameSupplier = targetIndexNameSupplier;
|
|
|
+ this.settingsSupplier = settingsSupplier;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -42,32 +65,16 @@ public class UpdateSettingsStep extends AsyncActionStep {
|
|
|
ClusterStateObserver observer,
|
|
|
ActionListener<Void> listener
|
|
|
) {
|
|
|
- UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest(indexMetadata.getIndex().getName()).masterNodeTimeout(
|
|
|
- TimeValue.MAX_VALUE
|
|
|
- ).settings(settings);
|
|
|
+ String indexName = targetIndexNameSupplier.apply(indexMetadata.getIndex().getName(), indexMetadata.getLifecycleExecutionState());
|
|
|
+ Settings settings = settingsSupplier.apply(indexMetadata);
|
|
|
+ UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest(indexName).masterNodeTimeout(TimeValue.MAX_VALUE)
|
|
|
+ .settings(settings);
|
|
|
getClient(currentState.projectId()).admin()
|
|
|
.indices()
|
|
|
.updateSettings(updateSettingsRequest, listener.delegateFailureAndWrap((l, r) -> l.onResponse(null)));
|
|
|
}
|
|
|
|
|
|
- public Settings getSettings() {
|
|
|
- return settings;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int hashCode() {
|
|
|
- return Objects.hash(super.hashCode(), settings);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean equals(Object obj) {
|
|
|
- if (obj == null) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- if (getClass() != obj.getClass()) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- UpdateSettingsStep other = (UpdateSettingsStep) obj;
|
|
|
- return super.equals(obj) && Objects.equals(settings, other.settings);
|
|
|
+ public Function<IndexMetadata, Settings> getSettingsSupplier() {
|
|
|
+ return settingsSupplier;
|
|
|
}
|
|
|
}
|