Skip to content

Commit c0d26e8

Browse files
prdoyleelasticsearchmachine
andauthored
[8.19] Reserved state removal hooks (elastic#136721) (elastic#137919)
* Reserved state removal hooks (elastic#136721) * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]>
1 parent f523798 commit c0d26e8

File tree

11 files changed

+69
-1
lines changed

11 files changed

+69
-1
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/repositories/reservedstate/ReservedRepositoryAction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ public TransformState transform(Object source, TransformState prevState) throws
9191

9292
}
9393

94+
@Override
95+
public ClusterState remove(TransformState prevState) throws Exception {
96+
return transform(List.of(), prevState).state();
97+
}
98+
9499
@Override
95100
public List<PutRepositoryRequest> fromXContent(XContentParser parser) throws IOException {
96101
List<PutRepositoryRequest> result = new ArrayList<>();

server/src/main/java/org/elasticsearch/action/admin/indices/template/reservedstate/ReservedComposableIndexTemplateAction.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ public TransformState transform(Object source, TransformState prevState) throws
195195
return new TransformState(state, Sets.union(componentEntities, composableEntities));
196196
}
197197

198+
@Override
199+
public ClusterState remove(TransformState prevState) throws Exception {
200+
return transform(ComponentsAndComposables.EMPTY, prevState).state();
201+
}
202+
198203
@Override
199204
public ComponentsAndComposables fromXContent(XContentParser parser) throws IOException {
200205
List<PutComponentTemplateAction.Request> componentTemplates = new ArrayList<>();
@@ -237,5 +242,7 @@ public ComponentsAndComposables fromXContent(XContentParser parser) throws IOExc
237242
record ComponentsAndComposables(
238243
List<PutComponentTemplateAction.Request> componentTemplates,
239244
List<TransportPutComposableIndexTemplateAction.Request> composableTemplates
240-
) {}
245+
) {
246+
static final ComponentsAndComposables EMPTY = new ComponentsAndComposables(List.of(), List.of());
247+
}
241248
}

server/src/main/java/org/elasticsearch/action/ingest/ReservedPipelineAction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ public TransformState transform(Object source, TransformState prevState) throws
108108
return new TransformState(state, entities);
109109
}
110110

111+
@Override
112+
public ClusterState remove(TransformState prevState) throws Exception {
113+
return transform(List.of(), prevState).state();
114+
}
115+
111116
@Override
112117
public List<PutPipelineRequest> fromXContent(XContentParser parser) throws IOException {
113118
List<PutPipelineRequest> result = new ArrayList<>();

server/src/main/java/org/elasticsearch/reservedstate/ReservedClusterStateHandler.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import org.elasticsearch.action.ActionRequestValidationException;
1313
import org.elasticsearch.action.support.master.MasterNodeRequest;
14+
import org.elasticsearch.cluster.ClusterState;
1415
import org.elasticsearch.core.TimeValue;
1516
import org.elasticsearch.xcontent.XContentParser;
1617

@@ -62,6 +63,19 @@ public interface ReservedClusterStateHandler<T> {
6263
*/
6364
TransformState transform(Object source, TransformState prevState) throws Exception;
6465

66+
/**
67+
* Called when the source no longer contains a section corresponding to {@link #name}.
68+
* A bit like {@link #transform}, but with no {@code source} because the "source" has disappeared,
69+
* and no {@link TransformState#keys() keys} in the return value because there aren't any.
70+
*
71+
* <p>
72+
* The intent is to "cancel the reservation" and return the configuration to the state
73+
* it would have had if the section had never existed.
74+
*
75+
* @throws IOException
76+
*/
77+
ClusterState remove(TransformState prevState) throws Exception;
78+
6579
/**
6680
* List of dependent handler names for this handler.
6781
*

server/src/main/java/org/elasticsearch/reservedstate/action/ReservedClusterSettingsAction.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.apache.logging.log4j.LogManager;
1313
import org.apache.logging.log4j.Logger;
1414
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
15+
import org.elasticsearch.cluster.ClusterState;
1516
import org.elasticsearch.common.settings.ClusterSettings;
1617
import org.elasticsearch.common.settings.Settings;
1718
import org.elasticsearch.common.settings.SettingsUpdater;
@@ -94,6 +95,11 @@ public TransformState transform(Object input, TransformState prevState) {
9495
return new TransformState(state, currentKeys);
9596
}
9697

98+
@Override
99+
public ClusterState remove(TransformState prevState) throws Exception {
100+
return transform(Map.of(), prevState).state();
101+
}
102+
97103
@Override
98104
public Map<String, Object> fromXContent(XContentParser parser) throws IOException {
99105
return parser.map();

server/src/test/java/org/elasticsearch/reservedstate/ReservedClusterStateHandlerTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import org.elasticsearch.action.ActionRequestValidationException;
1313
import org.elasticsearch.action.support.master.MasterNodeRequest;
14+
import org.elasticsearch.cluster.ClusterState;
1415
import org.elasticsearch.indices.settings.InternalOrPrivateSettingsPlugin;
1516
import org.elasticsearch.test.ESTestCase;
1617
import org.elasticsearch.xcontent.XContentParser;
@@ -32,6 +33,11 @@ public TransformState transform(Object source, TransformState prevState) throws
3233
return prevState;
3334
}
3435

36+
@Override
37+
public ClusterState remove(TransformState prevState) throws Exception {
38+
return prevState.state();
39+
}
40+
3541
@Override
3642
public ValidRequest fromXContent(XContentParser parser) throws IOException {
3743
return new ValidRequest();

server/src/test/java/org/elasticsearch/reservedstate/service/ReservedClusterStateServiceTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ public TransformState transform(Object source, TransformState prevState) throws
129129
return new TransformState(newState, prevState.keys());
130130
}
131131

132+
@Override
133+
public ClusterState remove(TransformState prevState) throws Exception {
134+
return transform(null, prevState).state();
135+
}
136+
132137
@Override
133138
public Map<String, Object> fromXContent(XContentParser parser) throws IOException {
134139
return parser.map();

x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyAction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ public TransformState transform(Object source, TransformState prevState) throws
8282

8383
}
8484

85+
@Override
86+
public ClusterState remove(TransformState prevState) throws Exception {
87+
return transform(List.of(), prevState).state();
88+
}
89+
8590
@Override
8691
public List<PutAutoscalingPolicyAction.Request> fromXContent(XContentParser parser) throws IOException {
8792
List<PutAutoscalingPolicyAction.Request> result = new ArrayList<>();

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ public TransformState transform(Object source, TransformState prevState) throws
107107
return new TransformState(state, entities);
108108
}
109109

110+
@Override
111+
public ClusterState remove(TransformState prevState) throws Exception {
112+
return transform(List.of(), prevState).state();
113+
}
114+
110115
@Override
111116
public List<LifecyclePolicy> fromXContent(XContentParser parser) throws IOException {
112117
List<LifecyclePolicy> result = new ArrayList<>();

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/rolemapping/ReservedRoleMappingAction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public TransformState transform(Object source, TransformState prevState) throws
5757
}
5858
}
5959

60+
@Override
61+
public ClusterState remove(TransformState prevState) throws Exception {
62+
return transform(List.of(), prevState).state();
63+
}
64+
6065
@Override
6166
public List<PutRoleMappingRequest> fromXContent(XContentParser parser) throws IOException {
6267
List<PutRoleMappingRequest> result = new ArrayList<>();

0 commit comments

Comments
 (0)