19
19
20
20
package org .elasticsearch .action .admin .cluster .snapshots .restore ;
21
21
22
+ import org .apache .logging .log4j .LogManager ;
22
23
import org .elasticsearch .ElasticsearchGenerationException ;
24
+ import org .elasticsearch .Version ;
23
25
import org .elasticsearch .action .ActionRequestValidationException ;
24
26
import org .elasticsearch .action .support .IndicesOptions ;
25
27
import org .elasticsearch .action .support .master .MasterNodeRequest ;
26
28
import org .elasticsearch .common .Strings ;
27
29
import org .elasticsearch .common .io .stream .StreamInput ;
28
30
import org .elasticsearch .common .io .stream .StreamOutput ;
31
+ import org .elasticsearch .common .logging .DeprecationLogger ;
29
32
import org .elasticsearch .common .settings .Settings ;
30
33
import org .elasticsearch .common .xcontent .ToXContentObject ;
31
34
import org .elasticsearch .common .xcontent .XContentBuilder ;
50
53
*/
51
54
public class RestoreSnapshotRequest extends MasterNodeRequest <RestoreSnapshotRequest > implements ToXContentObject {
52
55
56
+ private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger (LogManager .getLogger (RestoreSnapshotRequest .class ));
57
+
53
58
private String snapshot ;
54
59
private String repository ;
55
60
private String [] indices = Strings .EMPTY_ARRAY ;
@@ -60,7 +65,6 @@ public class RestoreSnapshotRequest extends MasterNodeRequest<RestoreSnapshotReq
60
65
private boolean includeGlobalState = false ;
61
66
private boolean partial = false ;
62
67
private boolean includeAliases = true ;
63
- private Settings settings = EMPTY_SETTINGS ;
64
68
private Settings indexSettings = EMPTY_SETTINGS ;
65
69
private String [] ignoreIndexSettings = Strings .EMPTY_ARRAY ;
66
70
@@ -90,7 +94,9 @@ public RestoreSnapshotRequest(StreamInput in) throws IOException {
90
94
includeGlobalState = in .readBoolean ();
91
95
partial = in .readBoolean ();
92
96
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
+ }
94
100
indexSettings = readSettingsFromStream (in );
95
101
ignoreIndexSettings = in .readStringArray ();
96
102
}
@@ -108,7 +114,9 @@ public void writeTo(StreamOutput out) throws IOException {
108
114
out .writeBoolean (includeGlobalState );
109
115
out .writeBoolean (partial );
110
116
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
+ }
112
120
writeSettingsToStream (indexSettings , out );
113
121
out .writeStringArray (ignoreIndexSettings );
114
122
}
@@ -128,9 +136,6 @@ public ActionRequestValidationException validate() {
128
136
if (indicesOptions == null ) {
129
137
validationException = addValidationError ("indicesOptions is missing" , validationException );
130
138
}
131
- if (settings == null ) {
132
- validationException = addValidationError ("settings are missing" , validationException );
133
- }
134
139
if (indexSettings == null ) {
135
140
validationException = addValidationError ("indexSettings are missing" , validationException );
136
141
}
@@ -324,74 +329,6 @@ public RestoreSnapshotRequest partial(boolean partial) {
324
329
return this ;
325
330
}
326
331
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
-
395
332
/**
396
333
* Sets the list of index settings and index settings groups that shouldn't be restored from snapshot
397
334
*/
@@ -526,7 +463,8 @@ public RestoreSnapshotRequest source(Map<String, Object> source) {
526
463
if (!(entry .getValue () instanceof Map )) {
527
464
throw new IllegalArgumentException ("malformed settings section" );
528
465
}
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" );
530
468
} else if (name .equals ("include_global_state" )) {
531
469
includeGlobalState = nodeBooleanValue (entry .getValue (), "include_global_state" );
532
470
} else if (name .equals ("include_aliases" )) {
@@ -586,13 +524,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
586
524
builder .field ("include_global_state" , includeGlobalState );
587
525
builder .field ("partial" , partial );
588
526
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
- }
596
527
if (indexSettings != null ) {
597
528
builder .startObject ("index_settings" );
598
529
if (indexSettings .isEmpty () == false ) {
@@ -629,15 +560,14 @@ public boolean equals(Object o) {
629
560
Objects .equals (indicesOptions , that .indicesOptions ) &&
630
561
Objects .equals (renamePattern , that .renamePattern ) &&
631
562
Objects .equals (renameReplacement , that .renameReplacement ) &&
632
- Objects .equals (settings , that .settings ) &&
633
563
Objects .equals (indexSettings , that .indexSettings ) &&
634
564
Arrays .equals (ignoreIndexSettings , that .ignoreIndexSettings );
635
565
}
636
566
637
567
@ Override
638
568
public int hashCode () {
639
569
int result = Objects .hash (snapshot , repository , indicesOptions , renamePattern , renameReplacement , waitForCompletion ,
640
- includeGlobalState , partial , includeAliases , settings , indexSettings );
570
+ includeGlobalState , partial , includeAliases , indexSettings );
641
571
result = 31 * result + Arrays .hashCode (indices );
642
572
result = 31 * result + Arrays .hashCode (ignoreIndexSettings );
643
573
return result ;
0 commit comments