-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API for resetting state of a
SystemIndexPlugin
(#69469)
When we disable access to system indices, plugins will still need a way to erase their state. The obvious and most pressing use case for this is in tests, which need to be able to clean up the state of a cluster in between groups of tests. * Use a HandledTransportAction for reset action My initial cut used a TransportMasterNodeAction, which requires code that carefully manipulates cluster state. At least for the first cut and testing, it seems like it will be much easier to use a client within a HandledTransportAction, which effectively makes the TransportResetFeatureStateAction a class that dispatches other transport actions to do the real work. * Clean up code by using a GroupedActionListener * ML feature state cleaner * Implement Transform feature state reset * Change _features/reset path to _features/_reset Out of an abundance of caution, I think the "reset" part of this path should have a leading underscore, so that if there's ever a reason to implement "GET _features/<feature_id>" we won't have to worry about distinguishing "reset" from a feature name. Co-authored-by: Gordon Brown <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
7f31977
commit 624ee45
Showing
31 changed files
with
983 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
.../rest-high-level/src/main/java/org/elasticsearch/client/feature/ResetFeaturesRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.client.feature; | ||
|
||
import org.elasticsearch.client.TimedRequest; | ||
|
||
public class ResetFeaturesRequest extends TimedRequest { | ||
} |
82 changes: 82 additions & 0 deletions
82
...rest-high-level/src/main/java/org/elasticsearch/client/feature/ResetFeaturesResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.client.feature; | ||
|
||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.ObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.util.List; | ||
|
||
public class ResetFeaturesResponse { | ||
private final List<ResetFeatureStateStatus> features; | ||
|
||
private static final ParseField FEATURES = new ParseField("features"); | ||
|
||
@SuppressWarnings("unchecked") | ||
private static final ConstructingObjectParser<ResetFeaturesResponse, Void> PARSER = new ConstructingObjectParser<>( | ||
"snapshottable_features_response", true, | ||
(a, ctx) -> new ResetFeaturesResponse((List<ResetFeatureStateStatus>) a[0]) | ||
); | ||
|
||
static { | ||
PARSER.declareObjectArray( | ||
ConstructingObjectParser.constructorArg(), | ||
ResetFeaturesResponse.ResetFeatureStateStatus::parse, FEATURES); | ||
} | ||
|
||
public ResetFeaturesResponse(List<ResetFeatureStateStatus> features) { | ||
this.features = features; | ||
} | ||
|
||
public List<ResetFeatureStateStatus> getFeatures() { | ||
return features; | ||
} | ||
|
||
public static ResetFeaturesResponse parse(XContentParser parser) { | ||
return PARSER.apply(parser, null); | ||
} | ||
|
||
public static class ResetFeatureStateStatus { | ||
private final String featureName; | ||
private final String status; | ||
|
||
private static final ParseField FEATURE_NAME = new ParseField("feature_name"); | ||
private static final ParseField STATUS = new ParseField("status"); | ||
|
||
private static final ConstructingObjectParser<ResetFeatureStateStatus, Void> PARSER = new ConstructingObjectParser<>( | ||
"features", true, (a, ctx) -> new ResetFeatureStateStatus((String) a[0], (String) a[1]) | ||
); | ||
|
||
static { | ||
PARSER.declareField(ConstructingObjectParser.constructorArg(), | ||
(p, c) -> p.text(), FEATURE_NAME, ObjectParser.ValueType.STRING); | ||
PARSER.declareField(ConstructingObjectParser.constructorArg(), | ||
(p, c) -> p.text(), STATUS, ObjectParser.ValueType.STRING); | ||
} | ||
|
||
ResetFeatureStateStatus(String featureName, String status) { | ||
this.featureName = featureName; | ||
this.status = status; | ||
} | ||
|
||
public static ResetFeatureStateStatus parse(XContentParser parser, Void ctx) { | ||
return PARSER.apply(parser, ctx); | ||
} | ||
|
||
public String getFeatureName() { | ||
return featureName; | ||
} | ||
|
||
public String getStatus() { | ||
return status; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
rest-api-spec/src/main/resources/rest-api-spec/api/features.reset_features.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"features.reset_features":{ | ||
"documentation":{ | ||
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html", | ||
"description":"Resets the internal state of features, usually by deleting system indices" | ||
}, | ||
"stability":"experimental", | ||
"visibility":"public", | ||
"headers":{ | ||
"accept": [ "application/json"] | ||
}, | ||
"url":{ | ||
"paths":[ | ||
{ | ||
"path":"/_features/_reset", | ||
"methods":[ | ||
"POST" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
rest-api-spec/src/main/resources/rest-api-spec/test/features.reset_features/10_basic.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"Get Features": | ||
- skip: | ||
features: contains | ||
version: " - 7.99.99" # Adjust this after backport | ||
reason: "This API was added in 7.13.0" | ||
- do: { features.get_features: {}} | ||
- contains: {'features': {'name': 'tasks'}} |
Oops, something went wrong.