From 52ff341814f6b840c780902e706071fea80dadf7 Mon Sep 17 00:00:00 2001 From: David Turner Date: Mon, 9 Mar 2020 10:11:17 +0000 Subject: [PATCH] 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. --- .../restore/RestoreSnapshotRequest.java | 98 +++---------------- .../RestoreSnapshotRequestBuilder.java | 54 ---------- .../restore/RestoreSnapshotRequestTests.java | 10 -- .../snapshots/SnapshotRequestsTests.java | 3 +- 4 files changed, 16 insertions(+), 149 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java index 0d2cac9b401..1c6d72c948b 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java @@ -19,13 +19,16 @@ package org.elasticsearch.action.admin.cluster.snapshots.restore; +import org.apache.logging.log4j.LogManager; import org.elasticsearch.ElasticsearchGenerationException; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.master.MasterNodeRequest; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -50,6 +53,8 @@ import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBo */ public class RestoreSnapshotRequest extends MasterNodeRequest implements ToXContentObject { + private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(LogManager.getLogger(RestoreSnapshotRequest.class)); + private String snapshot; private String repository; private String[] indices = Strings.EMPTY_ARRAY; @@ -60,7 +65,6 @@ public class RestoreSnapshotRequest extends MasterNodeRequest - * See repository documentation for more information. - * - * @param settings repository-specific snapshot settings - * @return this request - */ - public RestoreSnapshotRequest settings(Settings settings) { - this.settings = settings; - return this; - } - - /** - * Sets repository-specific restore settings. - *

- * See repository documentation for more information. - * - * @param settings repository-specific snapshot settings - * @return this request - */ - public RestoreSnapshotRequest settings(Settings.Builder settings) { - this.settings = settings.build(); - return this; - } - - /** - * Sets repository-specific restore settings in JSON or YAML format - *

- * See repository documentation for more information. - * - * @param source repository-specific snapshot settings - * @param xContentType the content type of the source - * @return this request - */ - public RestoreSnapshotRequest settings(String source, XContentType xContentType) { - this.settings = Settings.builder().loadFromSource(source, xContentType).build(); - return this; - } - - /** - * Sets repository-specific restore settings - *

- * See repository documentation for more information. - * - * @param source repository-specific snapshot settings - * @return this request - */ - public RestoreSnapshotRequest settings(Map source) { - try { - XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); - builder.map(source); - settings(Strings.toString(builder), builder.contentType()); - } catch (IOException e) { - throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); - } - return this; - } - - /** - * Returns repository-specific restore settings - * - * @return restore settings - */ - public Settings settings() { - return this.settings; - } - /** * Sets the list of index settings and index settings groups that shouldn't be restored from snapshot */ @@ -526,7 +463,8 @@ public class RestoreSnapshotRequest extends MasterNodeRequest) entry.getValue()); + DEPRECATION_LOGGER.deprecatedAndMaybeLog("RestoreSnapshotRequest#settings", + "specifying [settings] when restoring a snapshot has no effect and will not be supported in a future version"); } else if (name.equals("include_global_state")) { includeGlobalState = nodeBooleanValue(entry.getValue(), "include_global_state"); } else if (name.equals("include_aliases")) { @@ -586,13 +524,6 @@ public class RestoreSnapshotRequest extends MasterNodeRequest - * See repository documentation for more information. - * - * @param settings repository-specific snapshot settings - * @return this builder - */ - public RestoreSnapshotRequestBuilder setSettings(Settings settings) { - request.settings(settings); - return this; - } - - /** - * Sets repository-specific restore settings. - *

- * See repository documentation for more information. - * - * @param settings repository-specific snapshot settings - * @return this builder - */ - public RestoreSnapshotRequestBuilder setSettings(Settings.Builder settings) { - request.settings(settings); - return this; - } - - /** - * Sets repository-specific restore settings in JSON or YAML format - *

- * See repository documentation for more information. - * - * @param source repository-specific snapshot settings - * @param xContentType the content type of the source - * @return this builder - */ - public RestoreSnapshotRequestBuilder setSettings(String source, XContentType xContentType) { - request.settings(source, xContentType); - return this; - } - - /** - * Sets repository-specific restore settings - *

- * See repository documentation for more information. - * - * @param source repository-specific snapshot settings - * @return this builder - */ - public RestoreSnapshotRequestBuilder setSettings(Map source) { - request.settings(source); - return this; - } - /** * If this parameter is set to true the operation will wait for completion of restore process before returning. * diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestTests.java index 59518b6e996..2254c6ba103 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestTests.java @@ -61,16 +61,6 @@ public class RestoreSnapshotRequestTests extends AbstractWireSerializingTestCase instance.partial(randomBoolean()); instance.includeAliases(randomBoolean()); - if (randomBoolean()) { - Map settings = new HashMap<>(); - int count = randomInt(3) + 1; - - for (int i = 0; i < count; ++i) { - settings.put(randomAlphaOfLengthBetween(2, 5), randomAlphaOfLengthBetween(2, 5)); - } - - instance.settings(settings); - } if (randomBoolean()) { Map indexSettings = new HashMap<>(); int count = randomInt(3) + 1; diff --git a/server/src/test/java/org/elasticsearch/snapshots/SnapshotRequestsTests.java b/server/src/test/java/org/elasticsearch/snapshots/SnapshotRequestsTests.java index 44fe0d4dd5c..f70bfdcae40 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/SnapshotRequestsTests.java +++ b/server/src/test/java/org/elasticsearch/snapshots/SnapshotRequestsTests.java @@ -91,12 +91,13 @@ public class SnapshotRequestsTests extends ESTestCase { assertEquals("rename-from", request.renamePattern()); assertEquals("rename-to", request.renameReplacement()); assertEquals(partial, request.partial()); - assertEquals("val1", request.settings().get("set1")); assertArrayEquals(request.ignoreIndexSettings(), new String[]{"set2", "set3"}); boolean expectedIgnoreAvailable = includeIgnoreUnavailable ? indicesOptions.ignoreUnavailable() : IndicesOptions.strictExpandOpen().ignoreUnavailable(); assertEquals(expectedIgnoreAvailable, request.indicesOptions().ignoreUnavailable()); + + assertWarnings("specifying [settings] when restoring a snapshot has no effect and will not be supported in a future version"); } public void testCreateSnapshotRequestParsing() throws IOException {