-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Add API for resetting state of a SystemIndexPlugin
#69469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
williamrandolph
merged 33 commits into
elastic:master
from
williamrandolph:si/reset-features-api
Mar 17, 2021
Merged
Changes from 25 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
77adad6
Stub out classes for reset feature states API
williamrandolph 0a55d99
Add enough code to get an integration test working
williamrandolph 51c8f8a
Improve unit test
williamrandolph 581cd0a
Add rough version of callback to SystemIndexPlugin
williamrandolph d6fa39c
License changes
williamrandolph ca50e12
Use a HandledTransportAction for reset action
williamrandolph bf5c86a
Just use clusterService, client, and listener in callback
williamrandolph 88ec70d
Add javadoc and update tests
williamrandolph eb03955
Fill out ResetFeatureStateResponse class
williamrandolph c5e82bc
Hook up response class in TransportAction
williamrandolph 8cafd70
Rename inner class
williamrandolph e2af327
Add a second plugin to integration tests
williamrandolph 1e4c3bd
Clean up code by using a GroupedActionListener
williamrandolph 7b6c663
Merge branch 'master' into si/reset-features-api
williamrandolph 237bc63
Add reset to list of non-operator actions
williamrandolph 02a5937
Consolidate default deletion logic in SystemIndices.feature
williamrandolph 83817e4
ML feature state cleaner
gwbrown 5ea27d6
Implement Transform feature state reset
gwbrown b9b1833
Merge changes from master
williamrandolph 1c7d174
Merge changes from master
williamrandolph db50f4d
Change endpoint to _feature/reset
williamrandolph 6544c25
Add javadoc and cleanup java style
williamrandolph a61cf38
Merge branch 'si/reset-transforms' into si/reset-features-api
gwbrown 44d0917
Add stub for API definition
williamrandolph 76febcf
Merge branch 'si/reset-features-api' of github.com:williamrandolph/el…
williamrandolph 3369131
Add stub for RHLC feature resetting
williamrandolph b18ff94
Implement client feature reset response parser
williamrandolph b316a91
Merge branch 'master' into si/reset-features-api
williamrandolph b05ec26
Merge branch 'master' into si/reset-features-api
williamrandolph d07d8c6
Respond to PR feedback
williamrandolph 746f43c
Change _features/reset path to _features/_reset
williamrandolph 8c97adb
Checkstyle fixes
williamrandolph 71bd331
Merge branch 'master' into si/reset-features-api
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
rest-api-spec/src/main/resources/rest-api-spec/api/features.reset_features.json
This file contains hidden or 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,29 @@ | ||
{ | ||
"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" | ||
] | ||
} | ||
] | ||
}, | ||
"params":{ | ||
"master_timeout":{ | ||
"type":"time", | ||
"description":"Explicit operation timeout for connection to master node" | ||
} | ||
} | ||
} | ||
} |
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 hidden or 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'}} |
148 changes: 148 additions & 0 deletions
148
server/src/internalClusterTest/java/org/elasticsearch/snapshots/FeatureStateResetApiIT.java
This file contains hidden or 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,148 @@ | ||
/* | ||
* 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.snapshots; | ||
|
||
import org.elasticsearch.action.admin.cluster.snapshots.features.ResetFeatureStateAction; | ||
import org.elasticsearch.action.admin.cluster.snapshots.features.ResetFeatureStateRequest; | ||
import org.elasticsearch.action.admin.cluster.snapshots.features.ResetFeatureStateResponse; | ||
import org.elasticsearch.action.admin.indices.get.GetIndexResponse; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.IndexNotFoundException; | ||
import org.elasticsearch.indices.SystemIndexDescriptor; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.plugins.SystemIndexPlugin; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.Matchers.arrayContaining; | ||
import static org.hamcrest.Matchers.containsInAnyOrder; | ||
import static org.hamcrest.Matchers.containsString; | ||
|
||
public class FeatureStateResetApiIT extends ESIntegTestCase { | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
List<Class<? extends Plugin>> plugins = new ArrayList<>(super.nodePlugins()); | ||
plugins.add(SystemIndexTestPlugin.class); | ||
plugins.add(SecondSystemIndexTestPlugin.class); | ||
return plugins; | ||
} | ||
|
||
/** Check that the reset method cleans up a feature */ | ||
public void testResetSystemIndices() throws Exception { | ||
String systemIndex1 = ".test-system-idx-1"; | ||
String systemIndex2 = ".second-test-system-idx-1"; | ||
String associatedIndex = ".associated-idx-1"; | ||
|
||
// put a document in a system index | ||
indexDoc(systemIndex1, "1", "purpose", "system index doc"); | ||
refresh(systemIndex1); | ||
|
||
// put a document in a second system index | ||
indexDoc(systemIndex2, "1", "purpose", "second system index doc"); | ||
refresh(systemIndex2); | ||
|
||
// put a document in associated index | ||
indexDoc(associatedIndex, "1", "purpose", "associated index doc"); | ||
refresh(associatedIndex); | ||
|
||
// put a document in a normal index | ||
indexDoc("my_index", "1", "purpose", "normal index doc"); | ||
refresh("my_index"); | ||
|
||
// call the reset API | ||
ResetFeatureStateResponse apiResponse = client().execute(ResetFeatureStateAction.INSTANCE, new ResetFeatureStateRequest()).get(); | ||
assertThat(apiResponse.getItemList(), containsInAnyOrder( | ||
new ResetFeatureStateResponse.ResetFeatureStateStatus("SystemIndexTestPlugin", "SUCCESS"), | ||
new ResetFeatureStateResponse.ResetFeatureStateStatus("SecondSystemIndexTestPlugin", "SUCCESS"), | ||
new ResetFeatureStateResponse.ResetFeatureStateStatus("tasks", "SUCCESS") | ||
)); | ||
|
||
// verify that both indices are gone | ||
Exception e1 = expectThrows(IndexNotFoundException.class, () -> client().admin().indices().prepareGetIndex() | ||
.addIndices(systemIndex1) | ||
.get()); | ||
|
||
assertThat(e1.getMessage(), containsString("no such index")); | ||
|
||
Exception e2 = expectThrows(IndexNotFoundException.class, () -> client().admin().indices().prepareGetIndex() | ||
.addIndices(associatedIndex) | ||
.get()); | ||
|
||
assertThat(e2.getMessage(), containsString("no such index")); | ||
|
||
Exception e3 = expectThrows(IndexNotFoundException.class, () -> client().admin().indices().prepareGetIndex() | ||
.addIndices(systemIndex2) | ||
.get()); | ||
|
||
assertThat(e3.getMessage(), containsString("no such index")); | ||
|
||
GetIndexResponse response = client().admin().indices().prepareGetIndex() | ||
.addIndices("my_index") | ||
.get(); | ||
|
||
assertThat(response.getIndices(), arrayContaining("my_index")); | ||
} | ||
|
||
/** | ||
* A test plugin with patterns for system indices and associated indices. | ||
*/ | ||
public static class SystemIndexTestPlugin extends Plugin implements SystemIndexPlugin { | ||
|
||
public static final String SYSTEM_INDEX_PATTERN = ".test-system-idx*"; | ||
public static final String ASSOCIATED_INDEX_PATTERN = ".associated-idx*"; | ||
|
||
@Override | ||
public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings settings) { | ||
return Collections.singletonList(new SystemIndexDescriptor(SYSTEM_INDEX_PATTERN, "System indices for tests")); | ||
} | ||
|
||
@Override | ||
public Collection<String> getAssociatedIndexPatterns() { | ||
return Collections.singletonList(ASSOCIATED_INDEX_PATTERN); | ||
} | ||
|
||
@Override | ||
public String getFeatureName() { | ||
return SystemIndexTestPlugin.class.getSimpleName(); | ||
} | ||
|
||
@Override | ||
public String getFeatureDescription() { | ||
return "A simple test plugin"; | ||
} | ||
} | ||
|
||
/** | ||
* A second test plugin with a patterns for system indices. | ||
*/ | ||
public static class SecondSystemIndexTestPlugin extends Plugin implements SystemIndexPlugin { | ||
|
||
public static final String SYSTEM_INDEX_PATTERN = ".second-test-system-idx*"; | ||
|
||
@Override | ||
public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings settings) { | ||
return Collections.singletonList(new SystemIndexDescriptor(SYSTEM_INDEX_PATTERN, "System indices for tests")); | ||
} | ||
|
||
@Override | ||
public String getFeatureName() { | ||
return SecondSystemIndexTestPlugin.class.getSimpleName(); | ||
} | ||
|
||
@Override | ||
public String getFeatureDescription() { | ||
return "A second test plugin"; | ||
} | ||
} | ||
} |
This file contains hidden or 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
22 changes: 22 additions & 0 deletions
22
...va/org/elasticsearch/action/admin/cluster/snapshots/features/ResetFeatureStateAction.java
This file contains hidden or 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,22 @@ | ||
/* | ||
* 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.action.admin.cluster.snapshots.features; | ||
|
||
import org.elasticsearch.action.ActionType; | ||
|
||
/** Action for resetting feature states, mostly meaning system indices */ | ||
public class ResetFeatureStateAction extends ActionType<ResetFeatureStateResponse> { | ||
|
||
public static final ResetFeatureStateAction INSTANCE = new ResetFeatureStateAction(); | ||
public static final String NAME = "cluster:admin/features/reset"; | ||
|
||
private ResetFeatureStateAction() { | ||
super(NAME, ResetFeatureStateResponse::new); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...a/org/elasticsearch/action/admin/cluster/snapshots/features/ResetFeatureStateRequest.java
This file contains hidden or 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,39 @@ | ||
/* | ||
* 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.action.admin.cluster.snapshots.features; | ||
|
||
import org.elasticsearch.action.ActionRequest; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
|
||
/** Request for resetting feature state */ | ||
public class ResetFeatureStateRequest extends ActionRequest { | ||
|
||
public ResetFeatureStateRequest() { | ||
// TODO[wrb] - We might need to let this request take a list of | ||
// feature state names, but not for the initial implementation | ||
} | ||
|
||
public ResetFeatureStateRequest(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.