@@ -120,6 +120,7 @@ public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartr
120120 private String directoryResourcePath = SCRIPT_RESOURCE_DIRECTORY ;
121121 private String instanceDir = INSTANCE_DIR ;
122122 private String topologyConfigurationFile ;
123+ private String instancesFile ;
123124 private SslContext sslContext ;
124125
125126 /**
@@ -205,6 +206,7 @@ private TarantoolCartridgeContainer(ImageFromDockerfile image, String instancesF
205206 if (topologyConfigurationFile == null || topologyConfigurationFile .isEmpty ()) {
206207 throw new IllegalArgumentException ("Topology configuration file must not be null or empty" );
207208 }
209+ this .instancesFile = instancesFile ;
208210 this .topologyConfigurationFile = topologyConfigurationFile ;
209211 this .instanceFileParser = new CartridgeConfigParser (instancesFile );
210212 this .clientHelper = new TarantoolContainerClientHelper (this );
@@ -494,17 +496,23 @@ protected void containerIsStarting(InspectContainerResponse containerInfo) {
494496 }
495497
496498 private boolean setupTopology () {
497- String fileType = topologyConfigurationFile . substring ( topologyConfigurationFile . lastIndexOf ( '.' ) + 1 );
498-
499+ String fileType = topologyConfigurationFile
500+ . substring ( topologyConfigurationFile . lastIndexOf ( '.' ) + 1 );
499501 if (fileType .equals ("yml" )) {
500502 String replicasetsFileName = topologyConfigurationFile
501- .substring (topologyConfigurationFile .lastIndexOf ('/' ) + 1 );
502-
503+ .substring (topologyConfigurationFile .lastIndexOf ('/' ) + 1 );
504+ String instancesFileName = instancesFile
505+ .substring (instancesFile .lastIndexOf ('/' ) + 1 );
503506 try {
504- ExecResult result = execInContainer ("cartridge" ,
505- "replicasets" ,
506- "--run-dir=" + TARANTOOL_RUN_DIR ,
507- "--file=" + replicasetsFileName , "setup" , "--bootstrap-vshard" );
507+ ExecResult result = execInContainer (
508+ "cartridge" ,
509+ "replicasets" ,
510+ "--run-dir=" + TARANTOOL_RUN_DIR ,
511+ "--file=" + replicasetsFileName ,
512+ "--cfg=" + instancesFileName ,
513+ "setup" ,
514+ "--bootstrap-vshard"
515+ );
508516 if (result .getExitCode () != 0 ) {
509517 throw new CartridgeTopologyException ("Failed to change the app topology via cartridge CLI: "
510518 + result .getStdout ());
@@ -540,7 +548,7 @@ private void retryingSetupTopology() {
540548 if (!setupTopology ()) {
541549 try {
542550 logger ().info ("Retrying setup topology in 10 seconds" );
543- Thread .sleep (10000 );
551+ Thread .sleep (1_000 );
544552 } catch (InterruptedException e ) {
545553 throw new RuntimeException (e );
546554 }
@@ -563,10 +571,10 @@ private void bootstrapVshard() {
563571 protected void containerIsStarted (InspectContainerResponse containerInfo , boolean reused ) {
564572 super .containerIsStarted (containerInfo , reused );
565573
566- waitUntilRouterIsUp (60 );
574+ waitUntilRouterIsUp (120 );
567575 retryingSetupTopology ();
568576 // wait until Roles are configured
569- waitUntilCartridgeIsHealthy (10 );
577+ waitUntilCartridgeIsHealthy (120 );
570578 bootstrapVshard ();
571579
572580 logger ().info ("Tarantool Cartridge cluster is started" );
@@ -575,49 +583,79 @@ protected void containerIsStarted(InspectContainerResponse containerInfo, boolea
575583 }
576584
577585 private void waitUntilRouterIsUp (int secondsToWait ) {
578- waitUntilTrue (secondsToWait , this ::routerIsUp );
586+ if (!waitUntilTrue (secondsToWait , this ::routerIsUp )) {
587+ throw new RuntimeException ("Timeout exceeded during router upping stage." +
588+ " See the specific error in logs." );
589+ }
579590 }
580591
581592 private void waitUntilCartridgeIsHealthy (int secondsToWait ) {
582- waitUntilTrue (secondsToWait , this ::isCartridgeHealthy );
593+ if (!waitUntilTrue (secondsToWait , this ::isCartridgeHealthy )) {
594+ throw new RuntimeException ("Timeout exceeded during cartridge topology applying stage." +
595+ " See the specific error in logs." );
596+ }
583597 }
584598
585- private void waitUntilTrue (int secondsToWait , Supplier <Boolean > waitFunc ) {
599+ private boolean waitUntilTrue (int secondsToWait , Supplier <Boolean > waitFunc ) {
586600 int secondsPassed = 0 ;
587601 boolean result = waitFunc .get ();
588602 while (!result && secondsPassed < secondsToWait ) {
589603 result = waitFunc .get ();
590604 try {
591- Thread .sleep (1000 );
605+ Thread .sleep (1_000 );
606+ secondsPassed ++;
592607 } catch (InterruptedException e ) {
593608 break ;
594609 }
595610 }
596- if (!result ) {
597- throw new RuntimeException ("Failed to change the app topology after retry" );
598- }
611+ return result ;
599612 }
600613
601614 private boolean routerIsUp () {
602- String healthyCmd = " local cartridge = package.loaded['cartridge']" +
603- " return cartridge ~= nil" ;
615+ // String healthyCmd = " local cartridge = package.loaded['cartridge']" +
616+ // " return cartridge ~= nil";
617+ String healthyCmd = "return require('cartridge').is_healthy()" ;
618+ ExecResult result ;
619+
604620 try {
605- List <?> result = executeCommandDecoded (healthyCmd );
606- return result .get (0 ).getClass () == Boolean .class && (Boolean ) result .get (0 );
607- } catch (Exception e ) {
608- logger ().warn ("Error while waiting for router instance to be up: " + e .getMessage ());
621+ result = executeCommand (healthyCmd );
622+ if (result .getExitCode () != 0 && result .getStderr ().contains ("Connection refused" ) &&
623+ result .getStdout ().isEmpty ()) {
624+ return false ;
625+ } else if (result .getExitCode () != 0 ) {
626+ logger ().error ("exit code: {}, stdout: {}, stderr: {}" ,result .getExitCode (), result .getStdout (),
627+ result .getStderr ());
628+ return false ;
629+ } else {
630+ return true ;
631+ }
632+ }catch (Exception e ) {
633+ logger ().error (e .getMessage ());
609634 return false ;
610635 }
636+
611637 }
612638
613639 private boolean isCartridgeHealthy () {
614- String healthyCmd = " local cartridge = package.loaded[ 'cartridge']" +
615- " return cartridge ~= nil and cartridge.is_healthy()" ;
640+ String healthyCmd = " return require( 'cartridge').is_healthy()" ;
641+ ExecResult result ;
616642 try {
617- List <?> result = executeCommandDecoded (healthyCmd );
618- return result .get (0 ).getClass () == Boolean .class && (Boolean ) result .get (0 );
643+ result = executeCommand (healthyCmd );
644+ if (result .getExitCode () != 0 ) {
645+ logger ().error ("exitCode: {}, stdout: {}, stderr: {}" , result .getExitCode (), result .getStdout (),
646+ result .getStderr ());
647+ return false ;
648+ } else if (result .getStdout ().startsWith ("---\n - null\n " )){
649+ return false ;
650+ } else if (result .getStdout ().contains ("true" )) {
651+ return true ;
652+ } else {
653+ logger ().warn ("exitCode: {}, stdout: {}, stderr: {}" , result .getExitCode (), result .getStdout (),
654+ result .getStderr ());
655+ return false ;
656+ }
619657 } catch (Exception e ) {
620- logger ().warn ("Error while waiting for cartridge healthy state: " + e .getMessage ());
658+ logger ().error ("Error while waiting for cartridge healthy state: " + e .getMessage ());
621659 return false ;
622660 }
623661 }
0 commit comments