@@ -139,6 +139,72 @@ private static void setHAConfigs(Configuration conf) {
139
139
conf .setInt (ConfVars .HIVE_ZOOKEEPER_CONNECTION_MAX_RETRIES .varname , 1 );
140
140
}
141
141
142
+ @ Test (timeout = 60000 )
143
+ public void testHealthCheckHA () throws Exception {
144
+ String instanceId1 = UUID .randomUUID ().toString ();
145
+ miniHS2_1 .start (getConfOverlay (instanceId1 ));
146
+
147
+ String leaderURL = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_WEBUI_PORT .varname ) + "/leader" ;
148
+ String healthCheckURL = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_HEALTH_HA_PORT .varname ) + "/health-ha/leader" ;
149
+
150
+ String leaderURLHealthCheckPort = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_HEALTH_HA_PORT .varname ) + "/leader" ;
151
+ String healthCheckURLWebUIPort = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_WEBUI_PORT .varname ) + "/health-ha/leader" ;
152
+
153
+ assertEquals (true , miniHS2_1 .getIsLeaderTestFuture ().get ());
154
+ assertEquals (true , miniHS2_1 .isLeader ());
155
+
156
+ assertEquals ("true" , sendGet (leaderURL ));
157
+ assertEquals ("true" , sendGet (healthCheckURL ));
158
+
159
+ assertEquals ("Not Found" , sendGet (leaderURLHealthCheckPort ));
160
+ assertEquals ("Not Found" , sendGet (healthCheckURLWebUIPort ));
161
+ }
162
+
163
+ @ Test (timeout = 60000 )
164
+ public void testHealthCheckHAAuth () throws Exception {
165
+ hiveConf1 .setBoolVar (ConfVars .HIVE_SERVER2_WEBUI_ENABLE_CORS , true );
166
+ setPamConfs (hiveConf1 );
167
+ PamAuthenticator pamAuthenticator = new TestHS2HttpServerPam .TestPamAuthenticator (hiveConf1 );
168
+ String instanceId1 = UUID .randomUUID ().toString ();
169
+ miniHS2_1 .setPamAuthenticator (pamAuthenticator );
170
+ miniHS2_1 .start (getSecureConfOverlay (instanceId1 ));
171
+
172
+ String leaderURL = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_WEBUI_PORT .varname ) + "/leader" ;
173
+ String healthCheckURL = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_HEALTH_HA_PORT .varname ) + "/health-ha/leader" ;
174
+
175
+ String leaderURLHealthCheckPort = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_HEALTH_HA_PORT .varname ) + "/leader" ;
176
+ String healthCheckURLWebUIPort = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_WEBUI_PORT .varname ) + "/health-ha/leader" ;
177
+
178
+ assertEquals (true , miniHS2_1 .getIsLeaderTestFuture ().get ());
179
+ assertEquals (true , miniHS2_1 .isLeader ());
180
+
181
+ assertEquals ("true" , sendGet (leaderURL , true , true ));
182
+ assertEquals ("true" , sendGet (healthCheckURL , true , true ));
183
+
184
+ try {
185
+ sendGet (leaderURLHealthCheckPort , true , true );
186
+ } catch (AssertionError e ) {
187
+ assertTrue (e .getMessage ().contains ("Not Found" ));
188
+ } catch (Exception e ) {
189
+ fail ("Expected AssertionError" );
190
+ }
191
+
192
+ assertEquals ("Not Found" , sendGet (healthCheckURLWebUIPort , true , true ));
193
+ assertEquals ("Method Not Allowed" , sendDelete (healthCheckURL , true , true ));
194
+ assertEquals ("Method Not Allowed" , sendDelete (healthCheckURLWebUIPort , true , true ));
195
+
196
+ try {
197
+ sendDelete (leaderURLHealthCheckPort , true , true );
198
+ } catch (AssertionError e ) {
199
+ assertTrue (e .getMessage ().contains ("Not Found" ));
200
+ } catch (Exception e ) {
201
+ fail ("Expected AssertionError" );
202
+ }
203
+
204
+ String resp = sendDelete (leaderURL , true , true );
205
+ assertTrue (resp .contains ("Failover successful!" ));
206
+ }
207
+
142
208
@ Test (timeout = 60000 )
143
209
public void testActivePassiveHA () throws Exception {
144
210
String instanceId1 = UUID .randomUUID ().toString ();
@@ -150,10 +216,14 @@ public void testActivePassiveHA() throws Exception {
150
216
assertEquals (true , miniHS2_1 .isLeader ());
151
217
String url = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_WEBUI_PORT .varname ) + "/leader" ;
152
218
assertEquals ("true" , sendGet (url ));
219
+ String healthCheckURL = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_HEALTH_HA_PORT .varname ) + "/health-ha/leader" ;
220
+ assertEquals ("true" , sendGet (healthCheckURL ));
153
221
154
222
assertEquals (false , miniHS2_2 .isLeader ());
155
223
url = "http://localhost:" + hiveConf2 .get (ConfVars .HIVE_SERVER2_WEBUI_PORT .varname ) + "/leader" ;
156
224
assertEquals ("false" , sendGet (url ));
225
+ healthCheckURL = "http://localhost:" + hiveConf2 .get (ConfVars .HIVE_SERVER2_HEALTH_HA_PORT .varname ) + "/health-ha/leader" ;
226
+ assertEquals ("false" , sendGet (healthCheckURL ));
157
227
158
228
url = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_WEBUI_PORT .varname ) + "/peers" ;
159
229
String resp = sendGet (url );
@@ -192,6 +262,8 @@ public void testActivePassiveHA() throws Exception {
192
262
assertEquals (true , miniHS2_2 .isLeader ());
193
263
url = "http://localhost:" + hiveConf2 .get (ConfVars .HIVE_SERVER2_WEBUI_PORT .varname ) + "/leader" ;
194
264
assertEquals ("true" , sendGet (url ));
265
+ healthCheckURL = "http://localhost:" + hiveConf2 .get (ConfVars .HIVE_SERVER2_HEALTH_HA_PORT .varname ) + "/health-ha/leader" ;
266
+ assertEquals ("true" , sendGet (healthCheckURL ));
195
267
196
268
while (client .getAll ().size () != 1 ) {
197
269
Thread .sleep (100 );
@@ -233,6 +305,8 @@ public void testActivePassiveHA() throws Exception {
233
305
assertEquals (false , miniHS2_1 .isLeader ());
234
306
url = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_WEBUI_PORT .varname ) + "/leader" ;
235
307
assertEquals ("false" , sendGet (url ));
308
+ healthCheckURL = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_HEALTH_HA_PORT .varname ) + "/health-ha/leader" ;
309
+ assertEquals ("false" , sendGet (healthCheckURL ));
236
310
237
311
while (client .getAll ().size () != 2 ) {
238
312
Thread .sleep (100 );
@@ -282,10 +356,14 @@ public void testConnectionActivePassiveHAServiceDiscovery() throws Exception {
282
356
assertEquals (true , miniHS2_1 .isLeader ());
283
357
String url = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_WEBUI_PORT .varname ) + "/leader" ;
284
358
assertEquals ("true" , sendGet (url ));
359
+ String healthCheckURL = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_HEALTH_HA_PORT .varname ) + "/health-ha/leader" ;
360
+ assertEquals ("true" , sendGet (healthCheckURL ));
285
361
286
362
assertEquals (false , miniHS2_2 .isLeader ());
287
363
url = "http://localhost:" + hiveConf2 .get (ConfVars .HIVE_SERVER2_WEBUI_PORT .varname ) + "/leader" ;
288
364
assertEquals ("false" , sendGet (url ));
365
+ healthCheckURL = "http://localhost:" + hiveConf2 .get (ConfVars .HIVE_SERVER2_HEALTH_HA_PORT .varname ) + "/health-ha/leader" ;
366
+ assertEquals ("false" , sendGet (healthCheckURL ));
289
367
290
368
// miniHS2_1 will be leader
291
369
String zkConnectString = zkServer .getConnectString ();
@@ -347,11 +425,14 @@ public void testManualFailover() throws Exception {
347
425
miniHS2_2 .start (confOverlay );
348
426
String url1 = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_WEBUI_PORT .varname ) + "/leader" ;
349
427
String url2 = "http://localhost:" + hiveConf2 .get (ConfVars .HIVE_SERVER2_WEBUI_PORT .varname ) + "/leader" ;
428
+ String healthCheckURL1 = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_HEALTH_HA_PORT .varname ) + "/health-ha/leader" ;
429
+ String healthCheckURL2 = "http://localhost:" + hiveConf2 .get (ConfVars .HIVE_SERVER2_HEALTH_HA_PORT .varname ) + "/health-ha/leader" ;
350
430
351
431
// when we start miniHS2_1 will be leader (sequential start)
352
432
assertEquals (true , miniHS2_1 .getIsLeaderTestFuture ().get ());
353
433
assertEquals (true , miniHS2_1 .isLeader ());
354
434
assertEquals ("true" , sendGet (url1 , true , true ));
435
+ assertEquals ("true" , sendGet (healthCheckURL1 , true , true ));
355
436
356
437
// trigger failover on miniHS2_1
357
438
String resp = sendDelete (url1 , true , true );
@@ -361,11 +442,13 @@ public void testManualFailover() throws Exception {
361
442
assertEquals (true , miniHS2_1 .getNotLeaderTestFuture ().get ());
362
443
assertEquals (false , miniHS2_1 .isLeader ());
363
444
assertEquals ("false" , sendGet (url1 , true , true ));
445
+ assertEquals ("false" , sendGet (healthCheckURL1 , true , true ));
364
446
365
447
// make sure miniHS2_2 is the new leader
366
448
assertEquals (true , miniHS2_2 .getIsLeaderTestFuture ().get ());
367
449
assertEquals (true , miniHS2_2 .isLeader ());
368
450
assertEquals ("true" , sendGet (url2 , true , true ));
451
+ assertEquals ("true" , sendGet (healthCheckURL2 , true , true ));
369
452
370
453
// send failover request again to miniHS2_1 and get a failure
371
454
resp = sendDelete (url1 , true , true );
@@ -379,8 +462,10 @@ public void testManualFailover() throws Exception {
379
462
assertEquals (true , miniHS2_1 .getIsLeaderTestFuture ().get ());
380
463
assertEquals (true , miniHS2_1 .isLeader ());
381
464
assertEquals ("true" , sendGet (url1 , true , true ));
465
+ assertEquals ("true" , sendGet (healthCheckURL1 , true , true ));
382
466
assertEquals (true , miniHS2_2 .getNotLeaderTestFuture ().get ());
383
467
assertEquals ("false" , sendGet (url2 , true , true ));
468
+ assertEquals ("false" , sendGet (healthCheckURL2 , true , true ));
384
469
assertEquals (false , miniHS2_2 .isLeader ());
385
470
} finally {
386
471
resetFailoverConfs ();
@@ -404,10 +489,12 @@ public void testManualFailoverUnauthorized() throws Exception {
404
489
miniHS2_2 .start (confOverlay );
405
490
406
491
String url1 = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_WEBUI_PORT .varname ) + "/leader" ;
492
+ String healthCheckURL1 = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_HEALTH_HA_PORT .varname ) + "/health-ha/leader" ;
407
493
// when we start miniHS2_1 will be leader (sequential start)
408
494
assertEquals (true , miniHS2_1 .getIsLeaderTestFuture ().get ());
409
495
assertEquals (true , miniHS2_1 .isLeader ());
410
496
assertEquals ("true" , sendGet (url1 , true ));
497
+ assertEquals ("true" , sendGet (healthCheckURL1 , true ));
411
498
412
499
// trigger failover on miniHS2_1 without authorization header
413
500
assertTrue (sendDelete (url1 , false ).contains ("Unauthorized" ));
@@ -439,6 +526,7 @@ public void testNoConnectionOnPassive() throws Exception {
439
526
miniHS2_2 .setPamAuthenticator (pamAuthenticator2 );
440
527
miniHS2_2 .start (confOverlay );
441
528
String url1 = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_WEBUI_PORT .varname ) + "/leader" ;
529
+ String healthCheckURL1 = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_HEALTH_HA_PORT .varname ) + "/health-ha/leader" ;
442
530
assertEquals (true , miniHS2_1 .getIsLeaderTestFuture ().get ());
443
531
assertEquals (true , miniHS2_1 .isLeader ());
444
532
@@ -454,6 +542,9 @@ public void testNoConnectionOnPassive() throws Exception {
454
542
Thread .sleep (100 );
455
543
}
456
544
545
+ resp = sendDelete (healthCheckURL1 , true );
546
+ assertTrue (resp , resp .contains ("Method Not Allowed" ));
547
+
457
548
assertEquals (true , miniHS2_2 .getIsLeaderTestFuture ().get ());
458
549
assertEquals (true , miniHS2_2 .isLeader ());
459
550
@@ -496,6 +587,8 @@ public void testClientConnectionsOnFailover() throws Exception {
496
587
miniHS2_2 .start (confOverlay );
497
588
String url1 = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_WEBUI_PORT .varname ) + "/leader" ;
498
589
String url2 = "http://localhost:" + hiveConf2 .get (ConfVars .HIVE_SERVER2_WEBUI_PORT .varname ) + "/leader" ;
590
+ String healthCheckUrl1 = "http://localhost:" + hiveConf1 .get (ConfVars .HIVE_SERVER2_HEALTH_HA_PORT .varname ) + "/health-ha/leader" ;
591
+ String healthCheckUrl2 = "http://localhost:" + hiveConf2 .get (ConfVars .HIVE_SERVER2_HEALTH_HA_PORT .varname ) + "/health-ha/leader" ;
499
592
String zkJdbcUrl = miniHS2_1 .getJdbcURL ();
500
593
String zkConnectString = zkServer .getConnectString ();
501
594
assertTrue (zkJdbcUrl .contains (zkConnectString ));
@@ -504,6 +597,7 @@ public void testClientConnectionsOnFailover() throws Exception {
504
597
assertEquals (true , miniHS2_1 .getIsLeaderTestFuture ().get ());
505
598
assertEquals (true , miniHS2_1 .isLeader ());
506
599
assertEquals ("true" , sendGet (url1 , true ));
600
+ assertEquals ("true" , sendGet (healthCheckUrl1 , true ));
507
601
508
602
// before failover, check if we are getting connection from miniHS2_1
509
603
String hs2_1_directUrl = "jdbc:hive2://" + miniHS2_1 .getHost () + ":" + miniHS2_1 .getBinaryPort () +
@@ -523,15 +617,20 @@ public void testClientConnectionsOnFailover() throws Exception {
523
617
Thread .sleep (100 );
524
618
}
525
619
620
+ resp = sendDelete (healthCheckUrl1 , true );
621
+ assertTrue (resp .contains ("Method Not Allowed" ));
622
+
526
623
// make sure miniHS2_1 is not leader
527
624
assertEquals (true , miniHS2_1 .getNotLeaderTestFuture ().get ());
528
625
assertEquals (false , miniHS2_1 .isLeader ());
529
626
assertEquals ("false" , sendGet (url1 , true ));
627
+ assertEquals ("false" , sendGet (healthCheckUrl1 , true ));
530
628
531
629
// make sure miniHS2_2 is the new leader
532
630
assertEquals (true , miniHS2_2 .getIsLeaderTestFuture ().get ());
533
631
assertEquals (true , miniHS2_2 .isLeader ());
534
632
assertEquals ("true" , sendGet (url2 , true ));
633
+ assertEquals ("true" , sendGet (healthCheckUrl2 , true ));
535
634
536
635
// when we make a new connection we should get it from miniHS2_2 this time
537
636
String hs2_2_directUrl = "jdbc:hive2://" + miniHS2_2 .getHost () + ":" + miniHS2_2 .getHttpPort () +
@@ -555,8 +654,10 @@ public void testClientConnectionsOnFailover() throws Exception {
555
654
assertEquals (true , miniHS2_1 .getIsLeaderTestFuture ().get ());
556
655
assertEquals (true , miniHS2_1 .isLeader ());
557
656
assertEquals ("true" , sendGet (url1 , true ));
657
+ assertEquals ("true" , sendGet (healthCheckUrl1 , true ));
558
658
assertEquals (true , miniHS2_2 .getNotLeaderTestFuture ().get ());
559
659
assertEquals ("false" , sendGet (url2 , true ));
660
+ assertEquals ("false" , sendGet (healthCheckUrl2 , true ));
560
661
assertEquals (false , miniHS2_2 .isLeader ());
561
662
// make sure miniHS2_2 closes all its connections
562
663
while (miniHS2_2 .getOpenSessionsCount () != 0 ) {
0 commit comments