Deploy a bunch of verticles at once

94 views
Skip to first unread message

Uday T

unread,
Apr 29, 2015, 12:43:28 PM4/29/15
to ve...@googlegroups.com
How can I deploy a bunch of verticles and wait for all of them to start successfully? And what should I do if one or more verticles fail to deploy?
This is what I have so far:

private void deployVerticles(Stack<String> verticles, Future<Void> future) {
vertx.deployVerticle(verticles.pop(), v -> {
if (v.succeeded()) {
if (verticles.empty()) {
future.complete();
}
else {
deployVerticles(verticles, future);
}
}
else {
future.fail("Unable to deploy all verticles");
}
});
}

Stack<String> verticles = new Stack<String>();
verticles.push("js:Verticle1.js");
verticles.push("js:Verticle2.js");
verticles.push("js:Verticle3.js");

Future<Void> future = Future.future();
future.setHandler(r -> {
// Proceed with whatever
});

deployVerticles(verticles, future);


I'm not sure how to implement this in a clean way. The example code above doesn't seem to be a good way to achieve this.

Your help much appreciated!

mathias

unread,
Apr 29, 2015, 12:58:37 PM4/29/15
to ve...@googlegroups.com
I use a verticle that handles the deployment of all other verticles:
public void start(Future<Void> startFuture) {
   
AtomicInteger counter = new AtomicInteger(0);
   
List<VerticleDeployment> deployments = DeployConfig.getDeployments();
   
for (VerticleDeployment verticleDeployment : deployments) {
     
String name = verticleDeployment.getName();
      logger
.info("Deploy verticle " + name);
      vertx
.deployVerticle(name, verticleDeployment.getOptions(), res -> {
       
if (res.succeeded()) {
         
if (counter.incrementAndGet() == deployments.size()) {
            logger
.info("All verticles (" + counter + ") have been deployed.");
            startFuture
.complete();
         
}
       
} else {
         
String cause = "";
         
if (res.cause() != null) {
            cause
= res.cause().getMessage();
         
}
         
String error = "Deployment of verticle " + name + " failed: " + cause;
          logger
.info(error);
         
if (!startFuture.failed()) {
            startFuture
.fail(error);
         
}
       
}
     
});
   
}
 
}


Uday T

unread,
Apr 29, 2015, 1:14:04 PM4/29/15
to ve...@googlegroups.com
Nice! I assume you continue deploying other verticles on purpose. What if I need a fail fast version - stop other verticles from deploying if one of them fails? I like that your code quickly loops through and starts deploying all verticles and asynchronously captures the results. I guess, it is no big deal to fail fast. Maybe I can add some logic to undeploy successfully deployed verticles, if one or more of the verticles from the list fail to deploy.

What I'm trying to say is that I want to either deploy all verticles successfully or deploy none.

Thanks for the sample code. 

Asher Tarnopolski

unread,
Apr 29, 2015, 3:43:21 PM4/29/15
to ve...@googlegroups.com
we are also using a recursive method deploying next verticle after a previous one's deployment is completed successfully. this way you also have control on the deployment order, which might be important. you can also store all deployment ids to roll all already deployed verticles back in case of deployment failure.
Reply all
Reply to author
Forward
0 new messages