Skip to content

Commit c0c8c33

Browse files
authored
Make TransportMoveToStepAction project-aware (elastic#129252)
Future work is necessary to make the YAML tests pass in MP mode.
1 parent c689a60 commit c0c8c33

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ public void maybeRunAsyncAction(ClusterState clusterState, IndexMetadata indexMe
138138
* Resolve the given phase, action, and name into a real {@link StepKey}. The phase is always
139139
* required, but the action and name are optional. If a name is specified, an action is also required.
140140
*/
141-
public StepKey resolveStepKey(ClusterState state, Index index, String phase, @Nullable String action, @Nullable String name) {
141+
public StepKey resolveStepKey(ProjectMetadata project, Index index, String phase, @Nullable String action, @Nullable String name) {
142142
if (name == null) {
143143
if (action == null) {
144-
return this.policyRegistry.getFirstStepForPhase(state, index, phase);
144+
return this.policyRegistry.getFirstStepForPhase(project, index, phase);
145145
} else {
146-
return this.policyRegistry.getFirstStepForPhaseAndAction(state, index, phase, action);
146+
return this.policyRegistry.getFirstStepForPhaseAndAction(project, index, phase, action);
147147
}
148148
} else {
149149
assert action != null

x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistry.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
import org.apache.logging.log4j.Logger;
1111
import org.elasticsearch.ElasticsearchException;
1212
import org.elasticsearch.client.internal.Client;
13-
import org.elasticsearch.cluster.ClusterState;
1413
import org.elasticsearch.cluster.DiffableUtils;
1514
import org.elasticsearch.cluster.metadata.IndexMetadata;
16-
import org.elasticsearch.cluster.metadata.Metadata;
15+
import org.elasticsearch.cluster.metadata.ProjectMetadata;
1716
import org.elasticsearch.common.Strings;
1817
import org.elasticsearch.common.io.stream.StreamInput;
1918
import org.elasticsearch.common.io.stream.StreamOutput;
@@ -201,12 +200,11 @@ public void clear() {
201200
* Return all ordered steps for the current policy for the index. Does not
202201
* resolve steps using the phase caching, but only for the currently existing policy.
203202
*/
204-
private List<Step> getAllStepsForIndex(ClusterState state, Index index) {
205-
final Metadata metadata = state.metadata();
206-
if (metadata.getProject().hasIndex(index) == false) {
203+
private List<Step> getAllStepsForIndex(ProjectMetadata project, Index index) {
204+
if (project.hasIndex(index) == false) {
207205
throw new IllegalArgumentException("index " + index + " does not exist in the current cluster state");
208206
}
209-
final IndexMetadata indexMetadata = metadata.getProject().index(index);
207+
final IndexMetadata indexMetadata = project.index(index);
210208
final String policyName = indexMetadata.getLifecyclePolicyName();
211209
final LifecyclePolicyMetadata policyMetadata = lifecyclePolicyMap.get(policyName);
212210
if (policyMetadata == null) {
@@ -225,8 +223,8 @@ private List<Step> getAllStepsForIndex(ClusterState state, Index index) {
225223
* first step in that phase, if it exists, or null otherwise.
226224
*/
227225
@Nullable
228-
public Step.StepKey getFirstStepForPhase(ClusterState state, Index index, String phase) {
229-
return getAllStepsForIndex(state, index).stream()
226+
public Step.StepKey getFirstStepForPhase(ProjectMetadata project, Index index, String phase) {
227+
return getAllStepsForIndex(project, index).stream()
230228
.map(Step::getKey)
231229
.filter(stepKey -> phase.equals(stepKey.phase()))
232230
.findFirst()
@@ -238,8 +236,8 @@ public Step.StepKey getFirstStepForPhase(ClusterState state, Index index, String
238236
* for the first step in that phase, if it exists, or null otherwise.
239237
*/
240238
@Nullable
241-
public Step.StepKey getFirstStepForPhaseAndAction(ClusterState state, Index index, String phase, String action) {
242-
return getAllStepsForIndex(state, index).stream()
239+
public Step.StepKey getFirstStepForPhaseAndAction(ProjectMetadata project, Index index, String phase, String action) {
240+
return getAllStepsForIndex(project, index).stream()
243241
.map(Step::getKey)
244242
.filter(stepKey -> phase.equals(stepKey.phase()))
245243
.filter(stepKey -> action.equals(stepKey.action()))

x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportMoveToStepAction.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.elasticsearch.cluster.block.ClusterBlockException;
2323
import org.elasticsearch.cluster.block.ClusterBlockLevel;
2424
import org.elasticsearch.cluster.metadata.IndexMetadata;
25+
import org.elasticsearch.cluster.project.ProjectResolver;
2526
import org.elasticsearch.cluster.service.ClusterService;
2627
import org.elasticsearch.common.Strings;
2728
import org.elasticsearch.common.io.stream.StreamInput;
@@ -50,15 +51,17 @@
5051
public class TransportMoveToStepAction extends TransportMasterNodeAction<TransportMoveToStepAction.Request, AcknowledgedResponse> {
5152
private static final Logger logger = LogManager.getLogger(TransportMoveToStepAction.class);
5253

53-
IndexLifecycleService indexLifecycleService;
54+
private final IndexLifecycleService indexLifecycleService;
55+
private final ProjectResolver projectResolver;
5456

5557
@Inject
5658
public TransportMoveToStepAction(
5759
TransportService transportService,
5860
ClusterService clusterService,
5961
ThreadPool threadPool,
6062
ActionFilters actionFilters,
61-
IndexLifecycleService indexLifecycleService
63+
IndexLifecycleService indexLifecycleService,
64+
ProjectResolver projectResolver
6265
) {
6366
super(
6467
ILMActions.MOVE_TO_STEP.name(),
@@ -71,11 +74,13 @@ public TransportMoveToStepAction(
7174
EsExecutors.DIRECT_EXECUTOR_SERVICE
7275
);
7376
this.indexLifecycleService = indexLifecycleService;
77+
this.projectResolver = projectResolver;
7478
}
7579

7680
@Override
7781
protected void masterOperation(Task task, Request request, ClusterState state, ActionListener<AcknowledgedResponse> listener) {
78-
IndexMetadata indexMetadata = state.metadata().getProject().index(request.getIndex());
82+
final var project = projectResolver.getProjectMetadata(state);
83+
IndexMetadata indexMetadata = project.index(request.getIndex());
7984
if (indexMetadata == null) {
8085
listener.onFailure(new IllegalArgumentException("index [" + request.getIndex() + "] does not exist"));
8186
return;
@@ -95,7 +100,7 @@ protected void masterOperation(Task task, Request request, ClusterState state, A
95100
// Resolve the key that could have optional parts into one
96101
// that is totally concrete given the existing policy and index
97102
Step.StepKey concreteTargetStepKey = indexLifecycleService.resolveStepKey(
98-
state,
103+
project,
99104
indexMetadata.getIndex(),
100105
abstractTargetKey.getPhase(),
101106
abstractTargetKey.getAction(),
@@ -125,8 +130,9 @@ protected void masterOperation(Task task, Request request, ClusterState state, A
125130
public ClusterState execute(ClusterState currentState) {
126131
// Resolve the key that could have optional parts into one
127132
// that is totally concrete given the existing policy and index
133+
final var currentProject = currentState.metadata().getProject(project.id());
128134
Step.StepKey concreteTargetStepKey = indexLifecycleService.resolveStepKey(
129-
state,
135+
currentProject,
130136
indexMetadata.getIndex(),
131137
abstractTargetKey.getPhase(),
132138
abstractTargetKey.getAction(),
@@ -148,7 +154,7 @@ public ClusterState execute(ClusterState currentState) {
148154

149155
concreteTargetKey.set(concreteTargetStepKey);
150156
final var updatedProject = indexLifecycleService.moveIndexToStep(
151-
currentState.metadata().getProject(),
157+
currentProject,
152158
indexMetadata.getIndex(),
153159
request.getCurrentStepKey(),
154160
concreteTargetKey.get()
@@ -158,7 +164,8 @@ public ClusterState execute(ClusterState currentState) {
158164

159165
@Override
160166
public void clusterStateProcessed(ClusterState oldState, ClusterState newState) {
161-
IndexMetadata newIndexMetadata = newState.metadata().getProject().index(indexMetadata.getIndex());
167+
final var newProjectState = newState.projectState(project.id());
168+
IndexMetadata newIndexMetadata = newProjectState.metadata().index(indexMetadata.getIndex());
162169
if (newIndexMetadata == null) {
163170
// The index has somehow been deleted - there shouldn't be any opportunity for this to happen, but just in case.
164171
logger.debug(

0 commit comments

Comments
 (0)