forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce "Feature States" for managing snapshots of system indices (e…
…lastic#63513) This PR expands the meaning of `include_global_state` for snapshots to include system indices. If `include_global_state` is `true` on creation, system indices will be included in the snapshot regardless of the contents of the `indices` field. If `include_global_state` is `true` on restoration, system indices will be restored (if included in the snapshot), regardless of the contents of the `indices` field. Index renaming is not applied to system indices, as system indices rely on their names matching certain patterns. If restored system indices are already present, they are automatically deleted prior to restoration from the snapshot to avoid conflicts. This behavior can be overridden to an extent by including a new field in the snapshot creation or restoration call, `feature_states`, which contains an array of strings indicating the "feature" for which system indices should be snapshotted or restored. For example, this call will only restore the `watcher` and `security` system indices (in addition to `index_1`): ``` POST /_snapshot/my_repository/snapshot_2/_restore { "indices": "index_1", "include_global_state": true, "feature_states": ["watcher", "security"] } ``` If `feature_states` is present, the system indices associated with those features will be snapshotted or restored regardless of the value of `include_global_state`. All system indices can be omitted by providing a special value of `none` (`"feature_states": ["none"]`), or included by omitting the field or explicitly providing an empty array (`"feature_states": []`), similar to the `indices` field. The list of currently available features can be retrieved via a new "Get Snapshottable Features" API: ``` GET /_snapshottable_features ``` which returns a response of the form: ``` { "features": [ { "name": "tasks", "description": "Manages task results" }, { "name": "kibana", "description": "Manages Kibana configuration and reports" } ] } ``` Features currently map one-to-one with `SystemIndexPlugin`s, but this should be considered an implementation detail. The Get Snapshottable Features API and snapshot creation rely upon all relevant plugins being installed on the master node. Further, the list of feature states included in a given snapshot is exposed by the Get Snapshot API, which now includes a new field, `feature_states`, which contains a list of the feature states and their associated system indices which are included in the snapshot. All system indices in feature states are also included in the `indices` array for backwards compatibility, although explicitly requesting system indices included in a feature state is deprecated. For example, an excerpt from the Get Snapshot API showing `feature_states`: ``` "feature_states": [ { "feature_name": "tasks", "indices": [ ".tasks" ] } ], "indices": [ ".tasks", "test1", "test2" ] ``` Co-authored-by: William Brafford <william.brafford@elastic.co>
- Loading branch information
1 parent
721b4d3
commit 7fb5c52
Showing
100 changed files
with
3,193 additions
and
331 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
17 changes: 17 additions & 0 deletions
17
...vel/src/main/java/org/elasticsearch/client/snapshots/GetSnapshottableFeaturesRequest.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,17 @@ | ||
/* | ||
* 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.snapshots; | ||
|
||
import org.elasticsearch.client.TimedRequest; | ||
|
||
/** | ||
* A {@link TimedRequest} to get the list of features available to be included in snapshots in the cluster. | ||
*/ | ||
public class GetSnapshottableFeaturesRequest extends TimedRequest { | ||
} |
108 changes: 108 additions & 0 deletions
108
...el/src/main/java/org/elasticsearch/client/snapshots/GetSnapshottableFeaturesResponse.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,108 @@ | ||
/* | ||
* 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.snapshots; | ||
|
||
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; | ||
import java.util.Objects; | ||
|
||
public class GetSnapshottableFeaturesResponse { | ||
|
||
private final List<SnapshottableFeature> features; | ||
|
||
private static final ParseField FEATURES = new ParseField("features"); | ||
|
||
@SuppressWarnings("unchecked") | ||
private static final ConstructingObjectParser<GetSnapshottableFeaturesResponse, Void> PARSER = new ConstructingObjectParser<>( | ||
"snapshottable_features_response", true, (a, ctx) -> new GetSnapshottableFeaturesResponse((List<SnapshottableFeature>) a[0]) | ||
); | ||
|
||
static { | ||
PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(), SnapshottableFeature::parse, FEATURES); | ||
} | ||
|
||
public GetSnapshottableFeaturesResponse(List<SnapshottableFeature> features) { | ||
this.features = features; | ||
} | ||
|
||
public List<SnapshottableFeature> getFeatures() { | ||
return features; | ||
} | ||
|
||
public static GetSnapshottableFeaturesResponse parse(XContentParser parser) { | ||
return PARSER.apply(parser, null); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if ((o instanceof GetSnapshottableFeaturesResponse) == false) return false; | ||
GetSnapshottableFeaturesResponse that = (GetSnapshottableFeaturesResponse) o; | ||
return getFeatures().equals(that.getFeatures()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getFeatures()); | ||
} | ||
|
||
public static class SnapshottableFeature { | ||
|
||
private final String featureName; | ||
private final String description; | ||
|
||
private static final ParseField FEATURE_NAME = new ParseField("name"); | ||
private static final ParseField DESCRIPTION = new ParseField("description"); | ||
|
||
private static final ConstructingObjectParser<SnapshottableFeature, Void> PARSER = new ConstructingObjectParser<>( | ||
"feature", true, (a, ctx) -> new SnapshottableFeature((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(), DESCRIPTION, ObjectParser.ValueType.STRING); | ||
} | ||
|
||
public SnapshottableFeature(String featureName, String description) { | ||
this.featureName = featureName; | ||
this.description = description; | ||
} | ||
|
||
public static SnapshottableFeature parse(XContentParser parser, Void ctx) { | ||
return PARSER.apply(parser, ctx); | ||
} | ||
|
||
public String getFeatureName() { | ||
return featureName; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if ((o instanceof SnapshottableFeature) == false) return false; | ||
SnapshottableFeature feature = (SnapshottableFeature) o; | ||
return Objects.equals(getFeatureName(), feature.getFeatureName()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getFeatureName()); | ||
} | ||
} | ||
} |
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
67 changes: 67 additions & 0 deletions
67
...c/test/java/org/elasticsearch/client/snapshots/GetSnapshottableFeaturesResponseTests.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,67 @@ | ||
/* | ||
* 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.snapshots; | ||
|
||
import org.elasticsearch.client.AbstractResponseTestCase; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.common.xcontent.XContentType; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.hamcrest.Matchers.everyItem; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.Matchers.in; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
public class GetSnapshottableFeaturesResponseTests extends AbstractResponseTestCase< | ||
org.elasticsearch.action.admin.cluster.snapshots.features.GetSnapshottableFeaturesResponse, | ||
GetSnapshottableFeaturesResponse> { | ||
|
||
@Override | ||
protected org.elasticsearch.action.admin.cluster.snapshots.features.GetSnapshottableFeaturesResponse createServerTestInstance( | ||
XContentType xContentType | ||
) { | ||
return new org.elasticsearch.action.admin.cluster.snapshots.features.GetSnapshottableFeaturesResponse( | ||
randomList( | ||
10, | ||
() -> new org.elasticsearch.action.admin.cluster.snapshots.features.GetSnapshottableFeaturesResponse.SnapshottableFeature( | ||
randomAlphaOfLengthBetween(4, 10), | ||
randomAlphaOfLengthBetween(5, 10) | ||
) | ||
) | ||
); | ||
} | ||
|
||
@Override | ||
protected GetSnapshottableFeaturesResponse doParseToClientInstance(XContentParser parser) throws IOException { | ||
return GetSnapshottableFeaturesResponse.parse(parser); | ||
} | ||
|
||
@Override | ||
protected void assertInstances( | ||
org.elasticsearch.action.admin.cluster.snapshots.features.GetSnapshottableFeaturesResponse serverTestInstance, | ||
GetSnapshottableFeaturesResponse clientInstance | ||
) { | ||
assertNotNull(serverTestInstance.getSnapshottableFeatures()); | ||
assertNotNull(serverTestInstance.getSnapshottableFeatures()); | ||
|
||
assertThat(clientInstance.getFeatures(), hasSize(serverTestInstance.getSnapshottableFeatures().size())); | ||
|
||
Map<String, String> clientFeatures = clientInstance.getFeatures() | ||
.stream() | ||
.collect(Collectors.toMap(f -> f.getFeatureName(), f -> f.getDescription())); | ||
Map<String, String> serverFeatures = serverTestInstance.getSnapshottableFeatures() | ||
.stream() | ||
.collect(Collectors.toMap(f -> f.getFeatureName(), f -> f.getDescription())); | ||
|
||
assertThat(clientFeatures.entrySet(), everyItem(is(in(serverFeatures.entrySet())))); | ||
} | ||
} |
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
Oops, something went wrong.