|
13 | 13 | import org.elasticsearch.cluster.ProjectState; |
14 | 14 | import org.elasticsearch.cluster.metadata.IndexMetadata; |
15 | 15 | import org.elasticsearch.cluster.metadata.LifecycleExecutionState; |
| 16 | +import org.elasticsearch.cluster.metadata.ProjectMetadata; |
| 17 | +import org.elasticsearch.common.settings.Settings; |
16 | 18 | import org.elasticsearch.core.Tuple; |
17 | 19 | import org.elasticsearch.index.Index; |
18 | 20 |
|
19 | 21 | import java.util.Objects; |
20 | 22 | import java.util.function.BiFunction; |
21 | 23 |
|
| 24 | +import static org.elasticsearch.cluster.metadata.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; |
| 25 | + |
22 | 26 | /** |
23 | 27 | * Copies the execution state data from one index to another, typically after a |
24 | 28 | * new index has been created. As part of the execution state copy it will set the target index |
@@ -101,8 +105,20 @@ public ProjectState performAction(Index index, ProjectState projectState) { |
101 | 105 | newLifecycleState.setAction(action); |
102 | 106 | newLifecycleState.setStep(step); |
103 | 107 |
|
| 108 | + // Build a new index metadata with the version incremented and the new lifecycle state. |
| 109 | + IndexMetadata.Builder indexMetadataBuilder = IndexMetadata.builder(targetIndexMetadata) |
| 110 | + .version(targetIndexMetadata.getVersion() + 1) |
| 111 | + .putCustom(ILM_CUSTOM_METADATA_KEY, newLifecycleState.build().asMap()); |
| 112 | + |
| 113 | + // Remove the skip setting if it's present. |
| 114 | + if (targetIndexMetadata.getSettings().hasValue(LifecycleSettings.LIFECYCLE_SKIP)) { |
| 115 | + final var newSettings = Settings.builder().put(targetIndexMetadata.getSettings()); |
| 116 | + newSettings.remove(LifecycleSettings.LIFECYCLE_SKIP); |
| 117 | + indexMetadataBuilder.settingsVersion(targetIndexMetadata.getSettingsVersion() + 1).settings(newSettings); |
| 118 | + } |
| 119 | + |
104 | 120 | return projectState.updateProject( |
105 | | - projectState.metadata().withLifecycleState(targetIndexMetadata.getIndex(), newLifecycleState.build()) |
| 121 | + ProjectMetadata.builder(projectState.metadata()).put(indexMetadataBuilder.build(), false).build() |
106 | 122 | ); |
107 | 123 | } |
108 | 124 |
|
|
0 commit comments