Skip to content
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

Add API for resetting state of a SystemIndexPlugin #69469

Merged
merged 33 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from 32 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 Jan 29, 2021
0a55d99
Add enough code to get an integration test working
williamrandolph Feb 2, 2021
51c8f8a
Improve unit test
williamrandolph Feb 2, 2021
581cd0a
Add rough version of callback to SystemIndexPlugin
williamrandolph Feb 3, 2021
d6fa39c
License changes
williamrandolph Feb 4, 2021
ca50e12
Use a HandledTransportAction for reset action
williamrandolph Feb 5, 2021
bf5c86a
Just use clusterService, client, and listener in callback
williamrandolph Feb 5, 2021
88ec70d
Add javadoc and update tests
williamrandolph Feb 5, 2021
eb03955
Fill out ResetFeatureStateResponse class
williamrandolph Feb 8, 2021
c5e82bc
Hook up response class in TransportAction
williamrandolph Feb 8, 2021
8cafd70
Rename inner class
williamrandolph Feb 9, 2021
e2af327
Add a second plugin to integration tests
williamrandolph Feb 10, 2021
1e4c3bd
Clean up code by using a GroupedActionListener
williamrandolph Feb 11, 2021
7b6c663
Merge branch 'master' into si/reset-features-api
williamrandolph Feb 23, 2021
237bc63
Add reset to list of non-operator actions
williamrandolph Feb 23, 2021
02a5937
Consolidate default deletion logic in SystemIndices.feature
williamrandolph Feb 24, 2021
83817e4
ML feature state cleaner
gwbrown Feb 23, 2021
5ea27d6
Implement Transform feature state reset
gwbrown Feb 25, 2021
b9b1833
Merge changes from master
williamrandolph Mar 2, 2021
1c7d174
Merge changes from master
williamrandolph Mar 2, 2021
db50f4d
Change endpoint to _feature/reset
williamrandolph Mar 2, 2021
6544c25
Add javadoc and cleanup java style
williamrandolph Mar 2, 2021
a61cf38
Merge branch 'si/reset-transforms' into si/reset-features-api
gwbrown Mar 2, 2021
44d0917
Add stub for API definition
williamrandolph Mar 3, 2021
76febcf
Merge branch 'si/reset-features-api' of github.com:williamrandolph/el…
williamrandolph Mar 4, 2021
3369131
Add stub for RHLC feature resetting
williamrandolph Mar 5, 2021
b18ff94
Implement client feature reset response parser
williamrandolph Mar 10, 2021
b316a91
Merge branch 'master' into si/reset-features-api
williamrandolph Mar 10, 2021
b05ec26
Merge branch 'master' into si/reset-features-api
williamrandolph Mar 15, 2021
d07d8c6
Respond to PR feedback
williamrandolph Mar 15, 2021
746f43c
Change _features/reset path to _features/_reset
williamrandolph Mar 15, 2021
8c97adb
Checkstyle fixes
williamrandolph Mar 15, 2021
71bd331
Merge branch 'master' into si/reset-features-api
elasticmachine Mar 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
package org.elasticsearch.client;

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.client.snapshots.GetFeaturesRequest;
import org.elasticsearch.client.snapshots.GetFeaturesResponse;
import org.elasticsearch.client.feature.GetFeaturesRequest;
import org.elasticsearch.client.feature.GetFeaturesResponse;
import org.elasticsearch.client.feature.ResetFeaturesRequest;
import org.elasticsearch.client.feature.ResetFeaturesResponse;

import java.io.IOException;

Expand Down Expand Up @@ -71,4 +73,50 @@ public Cancellable getFeaturesAsync(
emptySet()
);
}

/**
* Reset the state of Elasticsearch features, deleting system indices and performing other
* cleanup operations.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/reset-features-api.html"> Rest
* Features API on elastic.co</a>
*
* @param resetFeaturesRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response
* @throws IOException in case there is a problem sending the request or parsing back the response
*/
public ResetFeaturesResponse resetFeatures(ResetFeaturesRequest resetFeaturesRequest, RequestOptions options)
williamrandolph marked this conversation as resolved.
Show resolved Hide resolved
throws IOException {
return restHighLevelClient.performRequestAndParseEntity(
resetFeaturesRequest,
FeaturesRequestConverters::resetFeatures,
options,
ResetFeaturesResponse::parse,
emptySet()
);
}

/**
* Asynchronously reset the state of Elasticsearch features, deleting system indices and performing other
* cleanup operations.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/get-features-api.html"> Get Snapshottable
* Features API on elastic.co</a>
*
* @param resetFeaturesRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
* @return cancellable that may be used to cancel the request
*/
public Cancellable resetFeaturesAsync(
williamrandolph marked this conversation as resolved.
Show resolved Hide resolved
ResetFeaturesRequest resetFeaturesRequest, RequestOptions options,
ActionListener<ResetFeaturesResponse> listener) {
return restHighLevelClient.performRequestAsyncAndParseEntity(
resetFeaturesRequest,
FeaturesRequestConverters::resetFeatures,
options,
ResetFeaturesResponse::parse,
listener,
emptySet()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
package org.elasticsearch.client;

import org.apache.http.client.methods.HttpGet;
import org.elasticsearch.client.snapshots.GetFeaturesRequest;
import org.apache.http.client.methods.HttpPost;
import org.elasticsearch.client.feature.GetFeaturesRequest;
import org.elasticsearch.client.feature.ResetFeaturesRequest;

public class FeaturesRequestConverters {

Expand All @@ -23,4 +25,9 @@ static Request getFeatures(GetFeaturesRequest getFeaturesRequest) {
request.addParameters(parameters.asMap());
return request;
}

static Request resetFeatures(ResetFeaturesRequest resetFeaturesRequest) {
String endpoint = "/_features/_reset";
return new Request(HttpPost.METHOD_NAME, endpoint);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

package org.elasticsearch.client.snapshots;
package org.elasticsearch.client.feature;

import org.elasticsearch.client.TimedRequest;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

package org.elasticsearch.client.snapshots;
package org.elasticsearch.client.feature;

import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
Expand Down
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 {
}
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

package org.elasticsearch.client;

import org.elasticsearch.client.snapshots.GetFeaturesRequest;
import org.elasticsearch.client.snapshots.GetFeaturesResponse;
import org.elasticsearch.client.feature.GetFeaturesRequest;
import org.elasticsearch.client.feature.GetFeaturesResponse;
import org.elasticsearch.client.feature.ResetFeaturesRequest;
import org.elasticsearch.client.feature.ResetFeaturesResponse;

import java.io.IOException;

Expand All @@ -28,4 +30,17 @@ public void testGetFeatures() throws IOException {
assertThat(response.getFeatures().size(), greaterThan(1));
assertTrue(response.getFeatures().stream().anyMatch(feature -> "tasks".equals(feature.getFeatureName())));
}

public void testResetFeatures() throws IOException {
ResetFeaturesRequest request = new ResetFeaturesRequest();

ResetFeaturesResponse response = execute(request,
highLevelClient().features()::resetFeatures, highLevelClient().features()::resetFeaturesAsync);

assertThat(response, notNullValue());
assertThat(response.getFeatures(), notNullValue());
assertThat(response.getFeatures().size(), greaterThan(1));
assertTrue(response.getFeatures().stream().anyMatch(
feature -> "tasks".equals(feature.getFeatureName()) && "SUCCESS".equals(feature.getStatus())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.elasticsearch.client.snapshots;

import org.elasticsearch.client.AbstractResponseTestCase;
import org.elasticsearch.client.feature.GetFeaturesResponse;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;

Expand Down
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"
]
}
]
}
}
}
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'}}
Loading