21
21
22
22
import org .apache .http .Header ;
23
23
import org .apache .http .HttpHost ;
24
- import org .apache .http .client .methods .HttpGet ;
25
- import org .apache .http .client .methods .HttpHead ;
26
- import org .apache .http .client .methods .HttpPost ;
27
- import org .apache .http .client .methods .HttpPut ;
28
- import org .apache .http .entity .ContentType ;
29
- import org .apache .http .entity .StringEntity ;
30
24
import org .apache .http .message .BasicHeader ;
31
25
import org .apache .http .nio .conn .ssl .SSLIOSessionStrategy ;
32
26
import org .apache .http .ssl .SSLContexts ;
68
62
import java .security .NoSuchAlgorithmException ;
69
63
import java .security .cert .CertificateException ;
70
64
import java .util .ArrayList ;
71
- import java .util .Collections ;
72
- import java .util .HashMap ;
73
65
import java .util .HashSet ;
74
66
import java .util .List ;
75
67
import java .util .Map ;
76
68
import java .util .Set ;
77
69
import java .util .concurrent .TimeUnit ;
78
70
79
- import static java .util .Collections .emptyMap ;
80
- import static java .util .Collections .singletonMap ;
81
71
import static java .util .Collections .sort ;
82
72
import static java .util .Collections .unmodifiableList ;
83
73
import static org .hamcrest .Matchers .anyOf ;
@@ -307,25 +297,25 @@ private void wipeCluster() throws IOException {
307
297
* the snapshots intact in the repository.
308
298
*/
309
299
private void wipeSnapshots () throws IOException {
310
- for (Map .Entry <String , ?> repo : entityAsMap (adminClient .performRequest ("GET" , "_snapshot/_all" )).entrySet ()) {
300
+ for (Map .Entry <String , ?> repo : entityAsMap (adminClient .performRequest (new Request ( "GET" , "/ _snapshot/_all" ) )).entrySet ()) {
311
301
String repoName = repo .getKey ();
312
302
Map <?, ?> repoSpec = (Map <?, ?>) repo .getValue ();
313
303
String repoType = (String ) repoSpec .get ("type" );
314
304
if (false == preserveSnapshotsUponCompletion () && repoType .equals ("fs" )) {
315
305
// All other repo types we really don't have a chance of being able to iterate properly, sadly.
316
- String url = " _snapshot/" + repoName + "/_all" ;
317
- Map < String , String > params = singletonMap ("ignore_unavailable" , "true" );
318
- List <?> snapshots = (List <?>) entityAsMap (adminClient .performRequest ("GET" , url , params )).get ("snapshots" );
306
+ Request listRequest = new Request ( "GET" , "/ _snapshot/" + repoName + "/_all" ) ;
307
+ listRequest . addParameter ("ignore_unavailable" , "true" );
308
+ List <?> snapshots = (List <?>) entityAsMap (adminClient .performRequest (listRequest )).get ("snapshots" );
319
309
for (Object snapshot : snapshots ) {
320
310
Map <?, ?> snapshotInfo = (Map <?, ?>) snapshot ;
321
311
String name = (String ) snapshotInfo .get ("snapshot" );
322
312
logger .debug ("wiping snapshot [{}/{}]" , repoName , name );
323
- adminClient ().performRequest ("DELETE" , "_snapshot/" + repoName + "/" + name );
313
+ adminClient ().performRequest (new Request ( "DELETE" , "/ _snapshot/" + repoName + "/" + name ) );
324
314
}
325
315
}
326
316
if (preserveReposUponCompletion () == false ) {
327
317
logger .debug ("wiping snapshot repository [{}]" , repoName );
328
- adminClient ().performRequest ("DELETE" , "_snapshot/" + repoName );
318
+ adminClient ().performRequest (new Request ( "DELETE" , "_snapshot/" + repoName ) );
329
319
}
330
320
}
331
321
}
@@ -334,7 +324,7 @@ private void wipeSnapshots() throws IOException {
334
324
* Remove any cluster settings.
335
325
*/
336
326
private void wipeClusterSettings () throws IOException {
337
- Map <?, ?> getResponse = entityAsMap (adminClient ().performRequest ("GET" , "/_cluster/settings" ));
327
+ Map <?, ?> getResponse = entityAsMap (adminClient ().performRequest (new Request ( "GET" , "/_cluster/settings" ) ));
338
328
339
329
boolean mustClear = false ;
340
330
XContentBuilder clearCommand = JsonXContent .contentBuilder ();
@@ -355,8 +345,9 @@ private void wipeClusterSettings() throws IOException {
355
345
clearCommand .endObject ();
356
346
357
347
if (mustClear ) {
358
- adminClient ().performRequest ("PUT" , "/_cluster/settings" , emptyMap (), new StringEntity (
359
- Strings .toString (clearCommand ), ContentType .APPLICATION_JSON ));
348
+ Request request = new Request ("PUT" , "/_cluster/settings" );
349
+ request .setJsonEntity (Strings .toString (clearCommand ));
350
+ adminClient ().performRequest (request );
360
351
}
361
352
}
362
353
@@ -365,7 +356,7 @@ private void wipeClusterSettings() throws IOException {
365
356
* other tests.
366
357
*/
367
358
private void logIfThereAreRunningTasks () throws InterruptedException , IOException {
368
- Set <String > runningTasks = runningTasks (adminClient ().performRequest ("GET" , "_tasks" ));
359
+ Set <String > runningTasks = runningTasks (adminClient ().performRequest (new Request ( "GET" , "/ _tasks" ) ));
369
360
// Ignore the task list API - it doesn't count against us
370
361
runningTasks .remove (ListTasksAction .NAME );
371
362
runningTasks .remove (ListTasksAction .NAME + "[n]" );
@@ -389,7 +380,7 @@ private void logIfThereAreRunningTasks() throws InterruptedException, IOExceptio
389
380
private void waitForClusterStateUpdatesToFinish () throws Exception {
390
381
assertBusy (() -> {
391
382
try {
392
- Response response = adminClient ().performRequest ("GET" , "_cluster/pending_tasks" );
383
+ Response response = adminClient ().performRequest (new Request ( "GET" , "/ _cluster/pending_tasks" ) );
393
384
List <?> tasks = (List <?>) entityAsMap (response ).get ("tasks" );
394
385
if (false == tasks .isEmpty ()) {
395
386
StringBuilder message = new StringBuilder ("there are still running tasks:" );
@@ -514,77 +505,78 @@ protected static void assertOK(Response response) {
514
505
* @param index index to test for
515
506
**/
516
507
protected static void ensureGreen (String index ) throws IOException {
517
- Map < String , String > params = new HashMap <>( );
518
- params . put ("wait_for_status" , "green" );
519
- params . put ("wait_for_no_relocating_shards" , "true" );
520
- params . put ("timeout" , "70s" );
521
- params . put ("level" , "shards" );
522
- assertOK ( client ().performRequest ("GET" , "_cluster/health/" + index , params ) );
508
+ Request request = new Request ( "GET" , "/_cluster/health/" + index );
509
+ request . addParameter ("wait_for_status" , "green" );
510
+ request . addParameter ("wait_for_no_relocating_shards" , "true" );
511
+ request . addParameter ("timeout" , "70s" );
512
+ request . addParameter ("level" , "shards" );
513
+ client ().performRequest (request );
523
514
}
524
515
525
516
/**
526
517
* waits until all shard initialization is completed. This is a handy alternative to ensureGreen as it relates to all shards
527
518
* in the cluster and doesn't require to know how many nodes/replica there are.
528
519
*/
529
520
protected static void ensureNoInitializingShards () throws IOException {
530
- Map < String , String > params = new HashMap <>( );
531
- params . put ("wait_for_no_initializing_shards" , "true" );
532
- params . put ("timeout" , "70s" );
533
- params . put ("level" , "shards" );
534
- assertOK ( client ().performRequest ("GET" , "_cluster/health/" , params ) );
521
+ Request request = new Request ( "GET" , "/_cluster/health" );
522
+ request . addParameter ("wait_for_no_initializing_shards" , "true" );
523
+ request . addParameter ("timeout" , "70s" );
524
+ request . addParameter ("level" , "shards" );
525
+ client ().performRequest (request );
535
526
}
536
527
537
528
protected static void createIndex (String name , Settings settings ) throws IOException {
538
529
createIndex (name , settings , "" );
539
530
}
540
531
541
532
protected static void createIndex (String name , Settings settings , String mapping ) throws IOException {
542
- assertOK (client ().performRequest (HttpPut .METHOD_NAME , name , Collections .emptyMap (),
543
- new StringEntity ("{ \" settings\" : " + Strings .toString (settings )
544
- + ", \" mappings\" : {" + mapping + "} }" , ContentType .APPLICATION_JSON )));
533
+ Request request = new Request ("PUT" , "/" + name );
534
+ request .setJsonEntity ("{\n \" settings\" : " + Strings .toString (settings )
535
+ + ", \" mappings\" : {" + mapping + "} }" );
536
+ client ().performRequest (request );
545
537
}
546
538
547
539
protected static void updateIndexSettings (String index , Settings .Builder settings ) throws IOException {
548
540
updateIndexSettings (index , settings .build ());
549
541
}
550
542
551
543
private static void updateIndexSettings (String index , Settings settings ) throws IOException {
552
- assertOK (client ().performRequest ("PUT" , index + "/_settings" , Collections .emptyMap (),
553
- new StringEntity (Strings .toString (settings ), ContentType .APPLICATION_JSON )));
544
+ Request request = new Request ("PUT" , "/" + index + "/_settings" );
545
+ request .setJsonEntity (Strings .toString (settings ));
546
+ client ().performRequest (request );
554
547
}
555
548
556
549
protected static Map <String , Object > getIndexSettings (String index ) throws IOException {
557
- Map <String , String > params = new HashMap <>();
558
- params .put ("flat_settings" , "true" );
559
- Response response = client ().performRequest (HttpGet .METHOD_NAME , index + "/_settings" , params );
560
- assertOK (response );
550
+ Request request = new Request ("GET" , "/" + index + "/_settings" );
551
+ request .addParameter ("flat_settings" , "true" );
552
+ Response response = client ().performRequest (request );
561
553
try (InputStream is = response .getEntity ().getContent ()) {
562
554
return XContentHelper .convertToMap (XContentType .JSON .xContent (), is , true );
563
555
}
564
556
}
565
557
566
558
protected static boolean indexExists (String index ) throws IOException {
567
- Response response = client ().performRequest (HttpHead . METHOD_NAME , index );
559
+ Response response = client ().performRequest (new Request ( "HEAD" , "/" + index ) );
568
560
return RestStatus .OK .getStatus () == response .getStatusLine ().getStatusCode ();
569
561
}
570
562
571
563
protected static void closeIndex (String index ) throws IOException {
572
- Response response = client ().performRequest (HttpPost . METHOD_NAME , index + "/_close" );
564
+ Response response = client ().performRequest (new Request ( "POST" , "/" + index + "/_close" ) );
573
565
assertThat (response .getStatusLine ().getStatusCode (), equalTo (RestStatus .OK .getStatus ()));
574
566
}
575
567
576
568
protected static void openIndex (String index ) throws IOException {
577
- Response response = client ().performRequest (HttpPost . METHOD_NAME , index + "/_open" );
569
+ Response response = client ().performRequest (new Request ( "POST" , "/" + index + "/_open" ) );
578
570
assertThat (response .getStatusLine ().getStatusCode (), equalTo (RestStatus .OK .getStatus ()));
579
571
}
580
572
581
573
protected static boolean aliasExists (String alias ) throws IOException {
582
- Response response = client ().performRequest (HttpHead . METHOD_NAME , "/_alias/" + alias );
574
+ Response response = client ().performRequest (new Request ( "HEAD" , "/_alias/" + alias ) );
583
575
return RestStatus .OK .getStatus () == response .getStatusLine ().getStatusCode ();
584
576
}
585
577
586
578
protected static boolean aliasExists (String index , String alias ) throws IOException {
587
- Response response = client ().performRequest (HttpHead . METHOD_NAME , "/" + index + "/_alias/" + alias );
579
+ Response response = client ().performRequest (new Request ( "HEAD" , "/" + index + "/_alias/" + alias ) );
588
580
return RestStatus .OK .getStatus () == response .getStatusLine ().getStatusCode ();
589
581
}
590
582
@@ -602,7 +594,7 @@ protected static Map<String, Object> getAlias(final String index, final String a
602
594
}
603
595
604
596
protected static Map <String , Object > getAsMap (final String endpoint ) throws IOException {
605
- Response response = client ().performRequest (HttpGet . METHOD_NAME , endpoint );
597
+ Response response = client ().performRequest (new Request ( "GET" , endpoint ) );
606
598
XContentType entityContentType = XContentType .fromMediaTypeOrFormat (response .getEntity ().getContentType ().getValue ());
607
599
Map <String , Object > responseEntity = XContentHelper .convertToMap (entityContentType .xContent (),
608
600
response .getEntity ().getContent (), false );
0 commit comments