1
1
package org .testcontainers .containers ;
2
2
3
3
import com .github .dockerjava .api .command .InspectContainerResponse ;
4
- import io .tarantool .driver .exceptions .TarantoolConnectionException ;
5
4
import org .testcontainers .images .builder .ImageFromDockerfile ;
6
5
7
6
import java .net .URL ;
8
7
import java .util .Arrays ;
9
8
import java .util .Collections ;
10
9
import java .util .HashMap ;
11
- import java .util .List ;
12
10
import java .util .Map ;
13
- import java .util .concurrent .CompletableFuture ;
14
11
import java .util .concurrent .ExecutionException ;
15
12
import java .util .concurrent .TimeoutException ;
16
13
import java .util .function .Supplier ;
80
77
* specified in the http_port options, will be exposed.
81
78
*
82
79
* @author Alexey Kuzin
80
+ * @author Ivan Dneprov
83
81
*/
84
82
public class TarantoolCartridgeContainer extends GenericContainer <TarantoolCartridgeContainer >
85
83
implements TarantoolContainerOperations <TarantoolCartridgeContainer > {
@@ -117,6 +115,9 @@ public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartr
117
115
private String directoryResourcePath = SCRIPT_RESOURCE_DIRECTORY ;
118
116
private String instanceDir = INSTANCE_DIR ;
119
117
private String topologyConfigurationFile ;
118
+ private Boolean sslIsActive = false ;
119
+ private String keyFile = "" ;
120
+ private String certFile = "" ;
120
121
121
122
/**
122
123
* Create a container with default image and specified instances file from the classpath resources. Assumes that
@@ -244,6 +245,33 @@ private static ImageFromDockerfile buildImage(String dockerFile, String buildIma
244
245
return new ImageFromDockerfile ().withFileFromClasspath ("Dockerfile" , dockerFile );
245
246
}
246
247
248
+ /**
249
+ * Specify SSL as connection transport.
250
+ * Warning! SSL must be set as default transport on your tarantool cluster.
251
+ * Supported only in Tarantool Enterprise
252
+ *
253
+ * @return this container instance
254
+ */
255
+ public TarantoolCartridgeContainer withSsl () {
256
+ checkNotRunning ();
257
+ this .sslIsActive = true ;
258
+ return this ;
259
+ }
260
+
261
+ /**
262
+ * Specify path to key and cert files inside your container for SSL connection.
263
+ * Warning! SSL must be set as default transport on your tarantool cluster.
264
+ * Supported only in Tarantool Enterprise
265
+ *
266
+ * @return this container instance
267
+ */
268
+ public TarantoolCartridgeContainer withKeyAndCertFiles (String keyFile , String certFile ) {
269
+ checkNotRunning ();
270
+ this .keyFile = keyFile ;
271
+ this .certFile = certFile ;
272
+ return this ;
273
+ }
274
+
247
275
/**
248
276
* Get the router host
249
277
*
@@ -326,6 +354,11 @@ public String getInstanceDir() {
326
354
return instanceDir ;
327
355
}
328
356
357
+ @ Override
358
+ public int getInternalPort () {
359
+ return routerPort ;
360
+ }
361
+
329
362
/**
330
363
* Get Cartridge router HTTP API hostname
331
364
*
@@ -487,17 +520,13 @@ private boolean setupTopology() {
487
520
488
521
} else {
489
522
try {
490
- executeScript (topologyConfigurationFile ). get () ;
523
+ executeScript (topologyConfigurationFile );
491
524
// The client connection will be closed after that command
492
525
} catch (Exception e ) {
493
526
if (e instanceof ExecutionException ) {
494
527
if (e .getCause () instanceof TimeoutException ) {
495
528
return true ;
496
529
// Do nothing, the cluster is reloading
497
- } else if (e .getCause () instanceof TarantoolConnectionException ) {
498
- // Probably cluster is not ready
499
- logger ().error ("Failed to setup topology: {}" , e .getMessage ());
500
- return false ;
501
530
}
502
531
} else {
503
532
throw new RuntimeException ("Failed to change the app topology" , e );
@@ -523,7 +552,7 @@ private void retryingSetupTopology() {
523
552
524
553
private void bootstrapVshard () {
525
554
try {
526
- executeCommand (VSHARD_BOOTSTRAP_COMMAND ). get () ;
555
+ executeCommand (VSHARD_BOOTSTRAP_COMMAND );
527
556
} catch (Exception e ) {
528
557
logger ().error ("Failed to bootstrap vshard cluster" , e );
529
558
throw new RuntimeException (e );
@@ -573,8 +602,8 @@ private boolean routerIsUp() {
573
602
String healthyCmd = " local cartridge = package.loaded['cartridge']" +
574
603
" return assert(cartridge ~= nil)" ;
575
604
try {
576
- List <?> result = executeCommand (healthyCmd ). get ( );
577
- return ( Boolean ) result . get ( 0 );
605
+ Container . ExecResult result = executeCommand (healthyCmd );
606
+ return result . getStdout (). equals ( "--- \n - true \n ... \n \n " );
578
607
} catch (Exception e ) {
579
608
logger ().warn ("Error while waiting for router instance to be up: " + e .getMessage ());
580
609
return false ;
@@ -585,21 +614,31 @@ private boolean isCartridgeHealthy() {
585
614
String healthyCmd = " local cartridge = package.loaded['cartridge']" +
586
615
" return assert(cartridge) and assert(cartridge.is_healthy())" ;
587
616
try {
588
- List <?> result = executeCommand (healthyCmd ). get ( );
589
- return ( Boolean ) result . get ( 0 );
617
+ Container . ExecResult result = executeCommand (healthyCmd );
618
+ return result . getStdout (). equals ( "--- \n - true \n ... \n \n " );
590
619
} catch (Exception e ) {
591
620
logger ().warn ("Error while waiting for cartridge healthy state: " + e .getMessage ());
592
621
return false ;
593
622
}
594
623
}
595
624
596
625
@ Override
597
- public CompletableFuture <List <?>> executeScript (String scriptResourcePath ) throws Exception {
598
- return clientHelper .executeScript (scriptResourcePath );
626
+ public Container .ExecResult executeScript (String scriptResourcePath ) throws Exception {
627
+ return clientHelper .executeScript (scriptResourcePath , this .sslIsActive , this .keyFile , this .certFile );
628
+ }
629
+
630
+ @ Override
631
+ public <T > T executeScriptDecoded (String scriptResourcePath ) throws Exception {
632
+ return clientHelper .executeScriptDecoded (scriptResourcePath , this .sslIsActive , this .keyFile , this .certFile );
633
+ }
634
+
635
+ @ Override
636
+ public Container .ExecResult executeCommand (String command ) throws Exception {
637
+ return clientHelper .executeCommand (command , this .sslIsActive , this .keyFile , this .certFile );
599
638
}
600
639
601
640
@ Override
602
- public CompletableFuture < List <?>> executeCommand (String command , Object ... arguments ) throws Exception {
603
- return clientHelper .executeCommand (command , arguments );
641
+ public < T > T executeCommandDecoded (String command ) throws Exception {
642
+ return clientHelper .executeCommandDecoded (command , this . sslIsActive , this . keyFile , this . certFile );
604
643
}
605
644
}
0 commit comments