21
21
22
22
import org .elasticsearch .ElasticsearchException ;
23
23
import org .elasticsearch .action .ActionListener ;
24
- import org .elasticsearch .action .FailedNodeException ;
25
24
import org .elasticsearch .action .LatchedActionListener ;
26
25
import org .elasticsearch .action .TaskOperationFailure ;
27
26
import org .elasticsearch .action .admin .cluster .node .tasks .list .ListTasksRequest ;
28
27
import org .elasticsearch .action .admin .cluster .node .tasks .list .ListTasksResponse ;
29
28
import org .elasticsearch .action .admin .cluster .node .tasks .list .TaskGroup ;
30
29
import org .elasticsearch .action .admin .cluster .settings .ClusterUpdateSettingsRequest ;
31
30
import org .elasticsearch .action .admin .cluster .settings .ClusterUpdateSettingsResponse ;
31
+ import org .elasticsearch .action .ingest .PutPipelineRequest ;
32
+ import org .elasticsearch .action .ingest .PutPipelineResponse ;
32
33
import org .elasticsearch .client .ESRestHighLevelClientTestCase ;
33
34
import org .elasticsearch .client .RestHighLevelClient ;
34
35
import org .elasticsearch .cluster .routing .allocation .decider .EnableAllocationDecider ;
36
+ import org .elasticsearch .common .bytes .BytesArray ;
35
37
import org .elasticsearch .common .settings .Settings ;
36
38
import org .elasticsearch .common .unit .ByteSizeUnit ;
37
39
import org .elasticsearch .common .unit .TimeValue ;
41
43
import org .elasticsearch .tasks .TaskInfo ;
42
44
43
45
import java .io .IOException ;
46
+ import java .nio .charset .StandardCharsets ;
44
47
import java .util .HashMap ;
45
48
import java .util .List ;
46
49
import java .util .Map ;
@@ -80,19 +83,19 @@ public void testClusterPutSettings() throws IOException {
80
83
// end::put-settings-request
81
84
82
85
// tag::put-settings-create-settings
83
- String transientSettingKey =
86
+ String transientSettingKey =
84
87
RecoverySettings .INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING .getKey ();
85
88
int transientSettingValue = 10 ;
86
- Settings transientSettings =
89
+ Settings transientSettings =
87
90
Settings .builder ()
88
91
.put (transientSettingKey , transientSettingValue , ByteSizeUnit .BYTES )
89
92
.build (); // <1>
90
93
91
- String persistentSettingKey =
94
+ String persistentSettingKey =
92
95
EnableAllocationDecider .CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING .getKey ();
93
- String persistentSettingValue =
96
+ String persistentSettingValue =
94
97
EnableAllocationDecider .Allocation .NONE .name ();
95
- Settings persistentSettings =
98
+ Settings persistentSettings =
96
99
Settings .builder ()
97
100
.put (persistentSettingKey , persistentSettingValue )
98
101
.build (); // <2>
@@ -105,9 +108,9 @@ public void testClusterPutSettings() throws IOException {
105
108
106
109
{
107
110
// tag::put-settings-settings-builder
108
- Settings .Builder transientSettingsBuilder =
111
+ Settings .Builder transientSettingsBuilder =
109
112
Settings .builder ()
110
- .put (transientSettingKey , transientSettingValue , ByteSizeUnit .BYTES );
113
+ .put (transientSettingKey , transientSettingValue , ByteSizeUnit .BYTES );
111
114
request .transientSettings (transientSettingsBuilder ); // <1>
112
115
// end::put-settings-settings-builder
113
116
}
@@ -164,7 +167,7 @@ public void testClusterUpdateSettingsAsync() throws Exception {
164
167
ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest ();
165
168
166
169
// tag::put-settings-execute-listener
167
- ActionListener <ClusterUpdateSettingsResponse > listener =
170
+ ActionListener <ClusterUpdateSettingsResponse > listener =
168
171
new ActionListener <ClusterUpdateSettingsResponse >() {
169
172
@ Override
170
173
public void onResponse (ClusterUpdateSettingsResponse response ) {
@@ -272,4 +275,80 @@ public void onFailure(Exception e) {
272
275
assertTrue (latch .await (30L , TimeUnit .SECONDS ));
273
276
}
274
277
}
278
+
279
+ public void testPutPipeline () throws IOException {
280
+ RestHighLevelClient client = highLevelClient ();
281
+
282
+ {
283
+ // tag::put-pipeline-request
284
+ String source =
285
+ "{\" description\" :\" my set of processors\" ," +
286
+ "\" processors\" :[{\" set\" :{\" field\" :\" foo\" ,\" value\" :\" bar\" }}]}" ;
287
+ PutPipelineRequest request = new PutPipelineRequest (
288
+ "my-pipeline-id" , // <1>
289
+ new BytesArray (source .getBytes (StandardCharsets .UTF_8 )), // <2>
290
+ XContentType .JSON // <3>
291
+ );
292
+ // end::put-pipeline-request
293
+
294
+ // tag::put-pipeline-request-timeout
295
+ request .timeout (TimeValue .timeValueMinutes (2 )); // <1>
296
+ request .timeout ("2m" ); // <2>
297
+ // end::put-pipeline-request-timeout
298
+
299
+ // tag::put-pipeline-request-masterTimeout
300
+ request .masterNodeTimeout (TimeValue .timeValueMinutes (1 )); // <1>
301
+ request .masterNodeTimeout ("1m" ); // <2>
302
+ // end::put-pipeline-request-masterTimeout
303
+
304
+ // tag::put-pipeline-execute
305
+ PutPipelineResponse response = client .cluster ().putPipeline (request ); // <1>
306
+ // end::put-pipeline-execute
307
+
308
+ // tag::put-pipeline-response
309
+ boolean acknowledged = response .isAcknowledged (); // <1>
310
+ // end::put-pipeline-response
311
+ assertTrue (acknowledged );
312
+ }
313
+ }
314
+
315
+ public void testPutPipelineAsync () throws Exception {
316
+ RestHighLevelClient client = highLevelClient ();
317
+
318
+ {
319
+ String source =
320
+ "{\" description\" :\" my set of processors\" ," +
321
+ "\" processors\" :[{\" set\" :{\" field\" :\" foo\" ,\" value\" :\" bar\" }}]}" ;
322
+ PutPipelineRequest request = new PutPipelineRequest (
323
+ "my-pipeline-id" ,
324
+ new BytesArray (source .getBytes (StandardCharsets .UTF_8 )),
325
+ XContentType .JSON
326
+ );
327
+
328
+ // tag::put-pipeline-execute-listener
329
+ ActionListener <PutPipelineResponse > listener =
330
+ new ActionListener <PutPipelineResponse >() {
331
+ @ Override
332
+ public void onResponse (PutPipelineResponse response ) {
333
+ // <1>
334
+ }
335
+
336
+ @ Override
337
+ public void onFailure (Exception e ) {
338
+ // <2>
339
+ }
340
+ };
341
+ // end::put-pipeline-execute-listener
342
+
343
+ // Replace the empty listener by a blocking listener in test
344
+ final CountDownLatch latch = new CountDownLatch (1 );
345
+ listener = new LatchedActionListener <>(listener , latch );
346
+
347
+ // tag::put-pipeline-execute-async
348
+ client .cluster ().putPipelineAsync (request , listener ); // <1>
349
+ // end::put-pipeline-execute-async
350
+
351
+ assertTrue (latch .await (30L , TimeUnit .SECONDS ));
352
+ }
353
+ }
275
354
}
0 commit comments