1919
2020package org .elasticsearch .action .admin .cluster .snapshots .restore ;
2121
22+ import org .apache .logging .log4j .LogManager ;
2223import org .elasticsearch .ElasticsearchGenerationException ;
24+ import org .elasticsearch .Version ;
2325import org .elasticsearch .action .ActionRequestValidationException ;
2426import org .elasticsearch .action .support .IndicesOptions ;
2527import org .elasticsearch .action .support .master .MasterNodeRequest ;
2628import org .elasticsearch .common .Strings ;
2729import org .elasticsearch .common .io .stream .StreamInput ;
2830import org .elasticsearch .common .io .stream .StreamOutput ;
31+ import org .elasticsearch .common .logging .DeprecationLogger ;
2932import org .elasticsearch .common .settings .Settings ;
3033import org .elasticsearch .common .xcontent .ToXContentObject ;
3134import org .elasticsearch .common .xcontent .XContentBuilder ;
5053 */
5154public 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 ;
0 commit comments