Skip to content

Commit c906a7a

Browse files
authored
Deprecate passing settings in restore requests (#53268)
Today we accept a `settings` field in snapshot restore requests, but this field is not used. This commit deprecates it.
1 parent e4f45db commit c906a7a

File tree

4 files changed

+16
-149
lines changed

4 files changed

+16
-149
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java

Lines changed: 14 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919

2020
package org.elasticsearch.action.admin.cluster.snapshots.restore;
2121

22+
import org.apache.logging.log4j.LogManager;
2223
import org.elasticsearch.ElasticsearchGenerationException;
24+
import org.elasticsearch.Version;
2325
import org.elasticsearch.action.ActionRequestValidationException;
2426
import org.elasticsearch.action.support.IndicesOptions;
2527
import org.elasticsearch.action.support.master.MasterNodeRequest;
2628
import org.elasticsearch.common.Strings;
2729
import org.elasticsearch.common.io.stream.StreamInput;
2830
import org.elasticsearch.common.io.stream.StreamOutput;
31+
import org.elasticsearch.common.logging.DeprecationLogger;
2932
import org.elasticsearch.common.settings.Settings;
3033
import org.elasticsearch.common.xcontent.ToXContentObject;
3134
import org.elasticsearch.common.xcontent.XContentBuilder;
@@ -50,6 +53,8 @@
5053
*/
5154
public class RestoreSnapshotRequest extends MasterNodeRequest<RestoreSnapshotRequest> implements ToXContentObject {
5255

56+
private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(LogManager.getLogger(RestoreSnapshotRequest.class));
57+
5358
private String snapshot;
5459
private String repository;
5560
private String[] indices = Strings.EMPTY_ARRAY;
@@ -60,7 +65,6 @@ public class RestoreSnapshotRequest extends MasterNodeRequest<RestoreSnapshotReq
6065
private boolean includeGlobalState = false;
6166
private boolean partial = false;
6267
private boolean includeAliases = true;
63-
private Settings settings = EMPTY_SETTINGS;
6468
private Settings indexSettings = EMPTY_SETTINGS;
6569
private String[] ignoreIndexSettings = Strings.EMPTY_ARRAY;
6670

@@ -90,7 +94,9 @@ public RestoreSnapshotRequest(StreamInput in) throws IOException {
9094
includeGlobalState = in.readBoolean();
9195
partial = in.readBoolean();
9296
includeAliases = in.readBoolean();
93-
settings = readSettingsFromStream(in);
97+
if (in.getVersion().before(Version.V_8_0_0)) {
98+
readSettingsFromStream(in); // formerly the unused settings field
99+
}
94100
indexSettings = readSettingsFromStream(in);
95101
ignoreIndexSettings = in.readStringArray();
96102
}
@@ -108,7 +114,9 @@ public void writeTo(StreamOutput out) throws IOException {
108114
out.writeBoolean(includeGlobalState);
109115
out.writeBoolean(partial);
110116
out.writeBoolean(includeAliases);
111-
writeSettingsToStream(settings, out);
117+
if (out.getVersion().before(Version.V_8_0_0)) {
118+
writeSettingsToStream(Settings.EMPTY, out); // formerly the unused settings field
119+
}
112120
writeSettingsToStream(indexSettings, out);
113121
out.writeStringArray(ignoreIndexSettings);
114122
}
@@ -128,9 +136,6 @@ public ActionRequestValidationException validate() {
128136
if (indicesOptions == null) {
129137
validationException = addValidationError("indicesOptions is missing", validationException);
130138
}
131-
if (settings == null) {
132-
validationException = addValidationError("settings are missing", validationException);
133-
}
134139
if (indexSettings == null) {
135140
validationException = addValidationError("indexSettings are missing", validationException);
136141
}
@@ -324,74 +329,6 @@ public RestoreSnapshotRequest partial(boolean partial) {
324329
return this;
325330
}
326331

327-
/**
328-
* Sets repository-specific restore settings.
329-
* <p>
330-
* See repository documentation for more information.
331-
*
332-
* @param settings repository-specific snapshot settings
333-
* @return this request
334-
*/
335-
public RestoreSnapshotRequest settings(Settings settings) {
336-
this.settings = settings;
337-
return this;
338-
}
339-
340-
/**
341-
* Sets repository-specific restore settings.
342-
* <p>
343-
* See repository documentation for more information.
344-
*
345-
* @param settings repository-specific snapshot settings
346-
* @return this request
347-
*/
348-
public RestoreSnapshotRequest settings(Settings.Builder settings) {
349-
this.settings = settings.build();
350-
return this;
351-
}
352-
353-
/**
354-
* Sets repository-specific restore settings in JSON or YAML format
355-
* <p>
356-
* See repository documentation for more information.
357-
*
358-
* @param source repository-specific snapshot settings
359-
* @param xContentType the content type of the source
360-
* @return this request
361-
*/
362-
public RestoreSnapshotRequest settings(String source, XContentType xContentType) {
363-
this.settings = Settings.builder().loadFromSource(source, xContentType).build();
364-
return this;
365-
}
366-
367-
/**
368-
* Sets repository-specific restore settings
369-
* <p>
370-
* See repository documentation for more information.
371-
*
372-
* @param source repository-specific snapshot settings
373-
* @return this request
374-
*/
375-
public RestoreSnapshotRequest settings(Map<String, Object> source) {
376-
try {
377-
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
378-
builder.map(source);
379-
settings(Strings.toString(builder), builder.contentType());
380-
} catch (IOException e) {
381-
throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
382-
}
383-
return this;
384-
}
385-
386-
/**
387-
* Returns repository-specific restore settings
388-
*
389-
* @return restore settings
390-
*/
391-
public Settings settings() {
392-
return this.settings;
393-
}
394-
395332
/**
396333
* Sets the list of index settings and index settings groups that shouldn't be restored from snapshot
397334
*/
@@ -526,7 +463,8 @@ public RestoreSnapshotRequest source(Map<String, Object> source) {
526463
if (!(entry.getValue() instanceof Map)) {
527464
throw new IllegalArgumentException("malformed settings section");
528465
}
529-
settings((Map<String, Object>) entry.getValue());
466+
DEPRECATION_LOGGER.deprecatedAndMaybeLog("RestoreSnapshotRequest#settings",
467+
"specifying [settings] when restoring a snapshot has no effect and will not be supported in a future version");
530468
} else if (name.equals("include_global_state")) {
531469
includeGlobalState = nodeBooleanValue(entry.getValue(), "include_global_state");
532470
} else if (name.equals("include_aliases")) {
@@ -586,13 +524,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
586524
builder.field("include_global_state", includeGlobalState);
587525
builder.field("partial", partial);
588526
builder.field("include_aliases", includeAliases);
589-
if (settings != null) {
590-
builder.startObject("settings");
591-
if (settings.isEmpty() == false) {
592-
settings.toXContent(builder, params);
593-
}
594-
builder.endObject();
595-
}
596527
if (indexSettings != null) {
597528
builder.startObject("index_settings");
598529
if (indexSettings.isEmpty() == false) {
@@ -629,15 +560,14 @@ public boolean equals(Object o) {
629560
Objects.equals(indicesOptions, that.indicesOptions) &&
630561
Objects.equals(renamePattern, that.renamePattern) &&
631562
Objects.equals(renameReplacement, that.renameReplacement) &&
632-
Objects.equals(settings, that.settings) &&
633563
Objects.equals(indexSettings, that.indexSettings) &&
634564
Arrays.equals(ignoreIndexSettings, that.ignoreIndexSettings);
635565
}
636566

637567
@Override
638568
public int hashCode() {
639569
int result = Objects.hash(snapshot, repository, indicesOptions, renamePattern, renameReplacement, waitForCompletion,
640-
includeGlobalState, partial, includeAliases, settings, indexSettings);
570+
includeGlobalState, partial, includeAliases, indexSettings);
641571
result = 31 * result + Arrays.hashCode(indices);
642572
result = 31 * result + Arrays.hashCode(ignoreIndexSettings);
643573
return result;

server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestBuilder.java

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -127,60 +127,6 @@ public RestoreSnapshotRequestBuilder setRenameReplacement(String renameReplaceme
127127
return this;
128128
}
129129

130-
131-
/**
132-
* Sets repository-specific restore settings.
133-
* <p>
134-
* See repository documentation for more information.
135-
*
136-
* @param settings repository-specific snapshot settings
137-
* @return this builder
138-
*/
139-
public RestoreSnapshotRequestBuilder setSettings(Settings settings) {
140-
request.settings(settings);
141-
return this;
142-
}
143-
144-
/**
145-
* Sets repository-specific restore settings.
146-
* <p>
147-
* See repository documentation for more information.
148-
*
149-
* @param settings repository-specific snapshot settings
150-
* @return this builder
151-
*/
152-
public RestoreSnapshotRequestBuilder setSettings(Settings.Builder settings) {
153-
request.settings(settings);
154-
return this;
155-
}
156-
157-
/**
158-
* Sets repository-specific restore settings in JSON or YAML format
159-
* <p>
160-
* See repository documentation for more information.
161-
*
162-
* @param source repository-specific snapshot settings
163-
* @param xContentType the content type of the source
164-
* @return this builder
165-
*/
166-
public RestoreSnapshotRequestBuilder setSettings(String source, XContentType xContentType) {
167-
request.settings(source, xContentType);
168-
return this;
169-
}
170-
171-
/**
172-
* Sets repository-specific restore settings
173-
* <p>
174-
* See repository documentation for more information.
175-
*
176-
* @param source repository-specific snapshot settings
177-
* @return this builder
178-
*/
179-
public RestoreSnapshotRequestBuilder setSettings(Map<String, Object> source) {
180-
request.settings(source);
181-
return this;
182-
}
183-
184130
/**
185131
* If this parameter is set to true the operation will wait for completion of restore process before returning.
186132
*

server/src/test/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestTests.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,6 @@ private RestoreSnapshotRequest randomState(RestoreSnapshotRequest instance) {
6161
instance.partial(randomBoolean());
6262
instance.includeAliases(randomBoolean());
6363

64-
if (randomBoolean()) {
65-
Map<String, Object> settings = new HashMap<>();
66-
int count = randomInt(3) + 1;
67-
68-
for (int i = 0; i < count; ++i) {
69-
settings.put(randomAlphaOfLengthBetween(2, 5), randomAlphaOfLengthBetween(2, 5));
70-
}
71-
72-
instance.settings(settings);
73-
}
7464
if (randomBoolean()) {
7565
Map<String, Object> indexSettings = new HashMap<>();
7666
int count = randomInt(3) + 1;

server/src/test/java/org/elasticsearch/snapshots/SnapshotRequestsTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,13 @@ public void testRestoreSnapshotRequestParsing() throws IOException {
9191
assertEquals("rename-from", request.renamePattern());
9292
assertEquals("rename-to", request.renameReplacement());
9393
assertEquals(partial, request.partial());
94-
assertEquals("val1", request.settings().get("set1"));
9594
assertArrayEquals(request.ignoreIndexSettings(), new String[]{"set2", "set3"});
9695
boolean expectedIgnoreAvailable = includeIgnoreUnavailable
9796
? indicesOptions.ignoreUnavailable()
9897
: IndicesOptions.strictExpandOpen().ignoreUnavailable();
9998
assertEquals(expectedIgnoreAvailable, request.indicesOptions().ignoreUnavailable());
99+
100+
assertWarnings("specifying [settings] when restoring a snapshot has no effect and will not be supported in a future version");
100101
}
101102

102103
public void testCreateSnapshotRequestParsing() throws IOException {

0 commit comments

Comments
 (0)