Example usage for io.vertx.core DeploymentOptions DeploymentOptions

List of usage examples for io.vertx.core DeploymentOptions DeploymentOptions

Introduction

In this page you can find the example usage for io.vertx.core DeploymentOptions DeploymentOptions.

Prototype

public DeploymentOptions(JsonObject json) 

Source Link

Document

Constructor for creating a instance from JSON

Usage

From source file:co.runrightfast.vertx.core.verticles.verticleManager.RunRightFastVerticleManager.java

License:Apache License

/**
 * The verticle is deployed asynchronously
 *
 * @param deployment config/*  w  w w .  jav a 2s .  c  o  m*/
 */
private void deployVerticle(@NonNull final RunRightFastVerticleDeployment deployment) {
    if (deployment.getDeploymentOptions().getInstances() == 1) {
        deployVerticleInstance(deployment, deployment.getVerticleInstance(), deployment.getDeploymentOptions());
    } else {
        // when more than 1 instance needs to be deployed, we need to manage that because we want to ensure each verticle instance is
        // indeed a new instance and there is no shared state. The reason we need to do this is because we create the verticle instance and not Vertx.
        final DeploymentOptions deploymentOptions = new DeploymentOptions(deployment.getDeploymentOptions())
                .setInstances(1);
        for (int i = 0; i < deployment.getDeploymentOptions().getInstances(); i++) {
            if (i == 0) {
                // resuse the original instance
                deployVerticleInstance(deployment, deployment.getVerticleInstance(), deploymentOptions);
            } else {
                // this creates a new instance of the verticle
                final RunRightFastVerticleDeployment deploymentInstance = deployment.withNewVerticleInstance();
                deployVerticleInstance(deploymentInstance, deploymentInstance.getVerticleInstance(),
                        deploymentOptions);
            }
        }
    }
}

From source file:com.deblox.Boot.java

License:Apache License

@Override
public void start(final Future<Void> startedResult) {

    logger.info("\n"
            + "                       ?                       \n"
            + "                                                            \n"
            + "                                     ?                              \n"
            + "                                                           \n"
            + "                                                          \n"
            + "                                  ?                                     \n"
            + "                                                                   \n"
            + "                                      1.0\n"
            + "                                                         https://github.com/unixunion/deblox-vertx-template                  \n");

    config = config();/*from  ww  w .  j av  a2s  .  c o m*/

    eb = vertx.eventBus();

    // warn a brother!
    if (config.equals(new JsonObject())) {
        logger.warn("you have no config here!");
    } else {
        logger.info("config: " + config);
    }

    // Start each class mentioned in services
    for (final Object serviceClassName : config.getJsonArray("services", new JsonArray())) {

        logger.info("deploying service: " + serviceClassName);

        // get the config for the named service
        JsonObject serviceConfigJson = config.getJsonObject(serviceClassName.toString(), new JsonObject());
        logger.info("serviceConfigJson: " + serviceConfigJson);

        // See DeploymentOptions.fromJson for all the possible configurables
        DeploymentOptions serviceConfig = new DeploymentOptions(serviceConfigJson);

        vertx.deployVerticle(serviceClassName.toString(), serviceConfig, res -> {

            if (res.succeeded()) {
                logger.info("successfully deployed service: " + serviceClassName);

            } else {
                logger.error("failure while deploying service: " + serviceClassName);
                res.cause().printStackTrace();
            }

        });

    }

    // for testing purposes, we need a litte delay since its less code than wait implement all verticles to boot.
    vertx.setTimer(1000, event -> {
        startedResult.complete();
        logger.info("startup complete");
    });

}

From source file:com.deblox.DebloxRunner.java

License:Apache License

public static void run(String runDir, String verticleID, VertxOptions options, String confFile) {
    logger.info("Booting");
    //    System.setProperty("vertx.cwd", runDir + "/");
    Consumer<Vertx> runner = vertx -> {
        try {/*  ww w  .  jav  a  2  s. co m*/
            JsonObject config = Util.loadConfig(confFile);
            // put config inside a config tag to solve issue between running as fatJar and running main[]
            DeploymentOptions deploymentOptions = new DeploymentOptions(new JsonObject().put("config", config));
            vertx.deployVerticle(verticleID, deploymentOptions);
        } catch (Throwable t) {
            t.printStackTrace();
        }
    };
    if (options.isClustered()) {
        Vertx.clusteredVertx(options, res -> {
            if (res.succeeded()) {
                Vertx vertx = res.result();
                runner.accept(vertx);
            } else {
                res.cause().printStackTrace();
            }
        });
    } else {
        Vertx vertx = Vertx.vertx(options);
        runner.accept(vertx);
    }
}

From source file:com.hpe.sw.cms.verticle.Boot.java

License:Apache License

public static void main(String... args) throws IOException {
    String file = args[0];//from   w  w  w  .ja v  a  2 s . co  m
    //    String file="dockerWeb/startup.json";
    String confStr = FileUtils.readFileToString(new File(file));
    JsonObject jsonConf = new JsonObject(confStr);
    DeploymentOptions deploymentOptions = new DeploymentOptions(jsonConf);
    VertxOptions options = new VertxOptions();
    options.setMaxEventLoopExecuteTime(Long.MAX_VALUE);
    Vertx vertx = Vertx.vertx(options);
    vertx.deployVerticle(new Boot(), deploymentOptions, r -> {
        if (r.succeeded()) {
            LOG.info("Successfully deployed");
        } else {
            throw new RuntimeException(r.cause());
        }
    });
}

From source file:de.neofonie.deployer.DeployerVerticle.java

License:Open Source License

/**
 * Iterate and deploy verticles/*from  w  ww .j  av a2 s .  c om*/
 */
private void deployVerticle(final Message<JsonObject> event) {

    // iterate over all candidates to be deployed
    Set<String> candidates = this.workingCopy.fieldNames();

    // detach from underlying json
    Map<String, JsonObject> initiants = new HashMap<>();
    candidates.forEach(id -> {
        JsonObject info = this.workingCopy.getJsonObject(id);
        JsonArray dependsOn = info.getJsonArray("dependsOn");
        if (dependsOn != null && deployed.getList().containsAll(dependsOn.getList()) || dependsOn == null
                || dependsOn.isEmpty()) {
            initiants.put(id, info);
        }
    });

    // remove the initiants
    initiants.keySet().forEach(id -> this.workingCopy.remove(id));

    // setup latch for the reply
    CountDownLatch latch = new CountDownLatch(initiants.size());
    if (initiants.isEmpty()) {
        event.reply(Boolean.TRUE);
        return;
    }

    // run over all dependencies
    initiants.forEach((id, info) -> {

        // get the name of the verticle
        String name = info.getString("name");
        final JsonObject localConfig = new JsonObject();
        localConfig.mergeIn(globalConfig);
        localConfig.mergeIn(info.getJsonObject("config", new JsonObject()));

        Handler<AsyncResult<String>> handler = innerEvent -> {
            if (innerEvent.succeeded()) {
                // add service to deployed-list
                deployed.add(id);

                // re-emit
                vertx.eventBus().send(LOOPBACK, workingCopy, (AsyncResult<Message<Boolean>> recursiveReply) -> {
                    // always decrease latch
                    latch.countDown();

                    if (recursiveReply.succeeded() && recursiveReply.result().body()) {
                        if (latch.getCount() == 0) {
                            event.reply(recursiveReply.result().body() & Boolean.TRUE);
                        }
                    } else {
                        event.fail(500, this.getFailure(id, recursiveReply));
                    }
                });

            } else {
                event.fail(500, id + " >> " + innerEvent.cause().getMessage());
            }
        };

        LOG.log(Level.INFO, "Deploying: ''{0}''", new Object[] { id });
        DeploymentOptions deploymentOptions = new DeploymentOptions(info);
        vertx.deployVerticle(name, deploymentOptions.setConfig(localConfig), handler);
    });
}

From source file:io.apiman.gateway.platforms.vertx3.verticles.InitVerticle.java

License:Apache License

private void deploy(String canonicalName, VerticleType verticleType,
        @SuppressWarnings("rawtypes") List<Future> deployList) {
    log.info("Will deploy {0} of type {1}", apimanConfig.getVerticleCount(verticleType), verticleType); //$NON-NLS-1$

    if (apimanConfig.getVerticleCount(verticleType) <= 0) {
        return;//from   www.  ja  v a2  s  .com
    }

    DeploymentOptions deploymentOptions = new DeploymentOptions(base)
            .setInstances(apimanConfig.getVerticleCount(verticleType));
    // Future for this deployment.
    Future<String> future = Future.future();
    // Do deployment
    vertx.deployVerticle(canonicalName, deploymentOptions, future.completer());
    // Set the future associated with the deployment so #all can wait for it.
    deployList.add(future);
}