1
1
package io .neonbee ;
2
2
3
+ import static io .neonbee .config .NeonBeeConfig .BootDeploymentHandling .FAIL_ON_ERROR ;
4
+ import static io .neonbee .config .NeonBeeConfig .BootDeploymentHandling .KEEP_PARTIAL ;
3
5
import static io .neonbee .internal .deploy .DeployableModule .fromJar ;
4
6
import static io .neonbee .internal .deploy .DeployableVerticle .fromClass ;
5
7
import static io .neonbee .internal .deploy .DeployableVerticle .fromVerticle ;
44
46
import io .neonbee .cluster .ClusterManagerFactory ;
45
47
import io .neonbee .config .HealthConfig ;
46
48
import io .neonbee .config .NeonBeeConfig ;
49
+ import io .neonbee .config .NeonBeeConfig .BootDeploymentHandling ;
47
50
import io .neonbee .config .ServerConfig ;
48
51
import io .neonbee .data .DataException ;
49
52
import io .neonbee .data .DataQuery ;
@@ -566,21 +569,25 @@ private Future<Void> deploySystemVerticles() {
566
569
List <Future <? extends Deployable >> requiredVerticles = new ArrayList <>();
567
570
requiredVerticles .add (fromClass (vertx , ConsolidationVerticle .class , new JsonObject ().put ("instances" , 1 )));
568
571
requiredVerticles .add (fromClass (vertx , LoggerManagerVerticle .class ));
569
-
570
- List <Future <Optional <? extends Deployable >>> optionalVerticles = new ArrayList <>();
571
572
if (Optional .ofNullable (config .getHealthConfig ()).map (HealthConfig ::isEnabled ).orElse (true )) {
572
573
requiredVerticles .add (fromClass (vertx , HealthCheckVerticle .class ));
573
574
}
575
+
576
+ List <Future <Optional <? extends Deployable >>> optionalVerticles = new ArrayList <>();
574
577
optionalVerticles .add (deployableWatchVerticle (options .getModelsDirectory (), ModelRefreshVerticle ::new ));
575
578
optionalVerticles .add (deployableWatchVerticle (options .getModulesDirectory (), DeployerVerticle ::new ));
576
579
optionalVerticles .add (deployableRedeployEntitiesJobVerticle (options ));
577
580
578
581
LOGGER .info ("Deploying system verticles ..." );
579
- return all (List .of (fromDeployables (requiredVerticles ).compose (allTo (this )),
580
- all (optionalVerticles ).map (CompositeFuture ::list ).map (optionals -> {
581
- return optionals .stream ().map (Optional .class ::cast ).filter (Optional ::isPresent ).map (Optional ::get )
582
- .map (Deployable .class ::cast ).toList ();
583
- }).map (Deployables ::new ).compose (anyTo (this )))).mapEmpty ();
582
+ return all (fromDeployables (requiredVerticles ).compose (allTo (this )).onFailure (throwable -> {
583
+ LOGGER .error ("Failed to deploy (some / all) required system verticle(s)" , throwable );
584
+ }), all (optionalVerticles ).map (CompositeFuture ::list ).map (optionals -> {
585
+ return optionals .stream ().map (Optional .class ::cast ).filter (Optional ::isPresent ).map (Optional ::get )
586
+ .map (Deployable .class ::cast ).toList ();
587
+ }).map (Deployables ::new ).compose (anyTo (this )).onFailure (throwable -> {
588
+ LOGGER .error ("Failed to deploy (some / all) optional system verticle(s), bootstrap will continue" ,
589
+ throwable );
590
+ }).otherwiseEmpty ()).mapEmpty ();
584
591
}
585
592
586
593
private Future <Optional <? extends Deployable >> deployableWatchVerticle (
@@ -621,7 +628,9 @@ private Future<Optional<? extends Deployable>> deployableRedeployEntitiesJobVert
621
628
private Future <Void > deployServerVerticle () {
622
629
LOGGER .info ("Deploying server verticle ..." );
623
630
return fromClass (vertx , ServerVerticle .class , new JsonObject ().put ("instances" , NUMBER_DEFAULT_INSTANCES ))
624
- .compose (deployable -> deployable .deploy (this )).mapEmpty ();
631
+ .compose (deployable -> deployable .deploy (this )).onFailure (throwable -> {
632
+ LOGGER .error ("Failed to deploy server verticle" , throwable );
633
+ }).mapEmpty ();
625
634
}
626
635
627
636
/**
@@ -638,11 +647,7 @@ private Future<Void> deployClassPathVerticles() {
638
647
return scanForDeployableClasses (vertx ).compose (deployableClasses -> fromDeployables (deployableClasses .stream ()
639
648
.filter (verticleClass -> filterByAutoDeployAndProfiles (verticleClass , options .getActiveProfiles ()))
640
649
.map (verticleClass -> fromClass (vertx , verticleClass )).collect (Collectors .toList ())))
641
- .onSuccess (deployables -> {
642
- if (LOGGER .isInfoEnabled ()) {
643
- LOGGER .info ("Deploy class path verticle(s) {}." , deployables .getIdentifier ());
644
- }
645
- }).compose (allTo (this )).mapEmpty ();
650
+ .compose (handleBootDeployment ("class path verticle(s)" ));
646
651
}
647
652
648
653
@ VisibleForTesting
@@ -665,7 +670,39 @@ private Future<Void> deployModules() {
665
670
666
671
LOGGER .info ("Deploying module(s) ..." );
667
672
return fromDeployables (moduleJarPaths .stream ().map (moduleJarPath -> fromJar (vertx , moduleJarPath ))
668
- .collect (Collectors .toList ())).compose (allTo (this )).mapEmpty ();
673
+ .collect (Collectors .toList ())).compose (handleBootDeployment ("module(s)" ));
674
+ }
675
+
676
+ private Function <Deployables , Future <Void >> handleBootDeployment (String deploymentType ) {
677
+ BootDeploymentHandling handling = config .getBootDeploymentHandling ();
678
+ return deployables -> {
679
+ // in case we should keep partial deployments, for every deployable that we are about to deploy
680
+ // set the keep partial deployment flag, so that in case there is an error we don't undeploy
681
+ if (handling == KEEP_PARTIAL ) {
682
+ for (Deployable deployable : deployables .getDeployables ()) {
683
+ if (deployable instanceof Deployables ) {
684
+ ((Deployables ) deployable ).keepPartialDeployment ();
685
+ }
686
+ }
687
+ }
688
+
689
+ return (handling == FAIL_ON_ERROR ? allTo (this ) : anyTo (this )).apply (deployables )
690
+ .onSuccess (deployments -> {
691
+ if (LOGGER .isInfoEnabled ()) {
692
+ LOGGER .info ("Successfully deployed all {} {}" ,
693
+ deploymentType , deployments .getDeploymentId ());
694
+ }
695
+ }).recover (throwable -> {
696
+ if (LOGGER .isErrorEnabled ()) {
697
+ LOGGER .error ("Failed to deploy (some / all) {}{}" ,
698
+ deploymentType , handling == FAIL_ON_ERROR ? "" : ", bootstrap will continue" ,
699
+ throwable );
700
+ }
701
+
702
+ // abort the boot process if any class path verticle failed to deploy
703
+ return handling == FAIL_ON_ERROR ? failedFuture (throwable ) : succeededFuture ();
704
+ }).mapEmpty ();
705
+ };
669
706
}
670
707
671
708
@ VisibleForTesting
0 commit comments