Example usage for io.vertx.core DeploymentOptions setConfig

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

Introduction

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

Prototype

public DeploymentOptions setConfig(JsonObject config) 

Source Link

Document

Set the JSON configuration that will be passed to the verticle(s) when it's deployed

Usage

From source file:com.waves_rsp.ikb4stream.communication.web.WebCommunication.java

License:Open Source License

/**
 * Starts the server, implemented by vertx.
 *
 * @param databaseReader {@link IDatabaseReader} is the connection to database to get Event
 * @throws NullPointerException if databaseReader is null
 * @see WebCommunication#PROPERTIES_MANAGER
 * @see WebCommunication#server/*w  ww .ja  v a  2 s .com*/
 */
@Override
public void start(IDatabaseReader databaseReader) {
    Objects.requireNonNull(databaseReader);
    configureDatabaseReader(databaseReader);
    LOGGER.info("Starting WebCommunication module");
    server = Vertx.vertx();
    DeploymentOptions deploymentOptions = new DeploymentOptions();
    int port = 8081;
    try {
        PROPERTIES_MANAGER.getProperty("communications.web.port");
        port = Integer.parseInt(PROPERTIES_MANAGER.getProperty("communications.web.port"));
        LOGGER.info("WebCommunication Server set on port {}", port);
    } catch (NumberFormatException e) {
        LOGGER.error("Invalid 'communications.web.port' value");
        return;
    } catch (IllegalArgumentException e) {
        LOGGER.info("Property 'communications.web.port' not set. Use default value for score.target");
    }
    JsonObject jsonObject = new JsonObject();
    jsonObject.put("http.port", port);
    deploymentOptions.setConfig(jsonObject);
    server.deployVerticle(VertxServer.class.getName(), deploymentOptions);
}

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

License:Open Source License

/**
 * Iterate and deploy verticles//from w w w.  ja  v a 2s . co m
 */
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.junit.resttest.Vertx3GatewayTestServer.java

License:Apache License

@Override
public void start() {
    try {/*from   ww w .ja  va 2 s  .c om*/
        resetter.reset();

        vertx = Vertx.vertx();
        echoServer.start();

        startLatch = new CountDownLatch(1);

        DeploymentOptions options = new DeploymentOptions();
        options.setConfig(vertxConf);

        vertx.deployVerticle(InitVerticle.class.getCanonicalName(), options,
                new Handler<AsyncResult<String>>() {

                    @Override
                    public void handle(AsyncResult<String> event) {
                        System.out.println("Deployed init verticle!");
                        startLatch.countDown();
                    }
                });

        startLatch.await();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:io.apiman.gateway.test.junit.vertx3.Vertx3GatewayTestServer.java

License:Apache License

@Override
public void start() {
    try {/*w  w  w .j  av  a  2s. c om*/
        resetter.reset();

        if (clustered) {
            CountDownLatch clusteredStart = new CountDownLatch(1);
            Vertx.clusteredVertx(new VertxOptions().setClustered(clustered).setClusterHost("localhost")
                    .setBlockedThreadCheckInterval(9999999), result -> {
                        if (result.succeeded()) {
                            System.out.println("**** Clustered Vert.x started up successfully! ****");
                            this.vertx = result.result();
                            clusteredStart.countDown();
                        } else {
                            throw new RuntimeException(result.cause());
                        }
                    });
            clusteredStart.await();
        } else {
            vertx = Vertx.vertx(new VertxOptions().setBlockedThreadCheckInterval(9999999));
        }
        echoServer.start();

        startLatch = new CountDownLatch(1);

        DeploymentOptions options = new DeploymentOptions();
        options.setConfig(vertxConf);

        vertx.deployVerticle(InitVerticle.class.getCanonicalName(), options,
                new Handler<AsyncResult<String>>() {

                    @Override
                    public void handle(AsyncResult<String> event) {
                        System.out.println("Deployed init verticle!");
                        startLatch.countDown();
                    }
                });

        startLatch.await();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:io.nitor.api.backend.PropertiesLauncher.java

License:Apache License

@Override
public void beforeDeployingVerticle(DeploymentOptions deploymentOptions) {
    JsonObject conf = readDefaultsConf();
    JsonObject inputConf = deploymentOptions.getConfig();
    if (inputConf != null) {
        conf.mergeIn(inputConf);/*from   www  . j a  va 2  s  .  com*/
    }

    override(conf, "");
    deploymentOptions.setConfig(conf);
}

From source file:io.servicecomb.foundation.vertx.VertxUtils.java

License:Apache License

public static <CLIENT_POOL, CLIENT_OPTIONS> DeploymentOptions createClientDeployOptions(
        ClientPoolManager<CLIENT_POOL> clientMgr, int instanceCount, int poolCountPerVerticle,
        CLIENT_OPTIONS clientOptions) {/*from   w w  w.ja  v  a 2 s.c  om*/
    DeploymentOptions options = new DeploymentOptions().setInstances(instanceCount);
    SimpleJsonObject config = new SimpleJsonObject();
    config.put(AbstractClientVerticle.CLIENT_MGR, clientMgr);
    config.put(AbstractClientVerticle.POOL_COUNT, poolCountPerVerticle);
    config.put(AbstractClientVerticle.CLIENT_OPTIONS, clientOptions);
    options.setConfig(config);

    return options;
}

From source file:io.servicecomb.transport.highway.HighwayTransport.java

License:Apache License

public boolean init() throws Exception {
    HighwayCodec.setHighwayTransport(this);

    DeploymentOptions deployOptions = new DeploymentOptions()
            .setInstances(HighwayConfig.getServerThreadCount());
    setListenAddressWithoutSchema(HighwayConfig.getAddress(), Collections.singletonMap(TcpConst.LOGIN, "true"));
    SimpleJsonObject json = new SimpleJsonObject();
    json.put(ENDPOINT_KEY, getEndpoint());
    deployOptions.setConfig(json);
    return VertxUtils.blockDeploy(transportVertx, HighwayServerVerticle.class, deployOptions) && deployClient();
}

From source file:io.servicecomb.transport.rest.vertx.VertxRestTransport.java

License:Apache License

@Override
public boolean init() throws Exception {
    // transport server
    DeploymentOptions options = new DeploymentOptions().setInstances(TransportConfig.getThreadCount());
    SimpleJsonObject json = new SimpleJsonObject();
    json.put(ENDPOINT_KEY, getEndpoint());
    options.setConfig(json);
    return VertxUtils.blockDeploy(transportVertx, RestServerVerticle.class, options) && deployClient();
}

From source file:io.silverware.microservices.utils.VertxUtils.java

License:Apache License

/**
 * Extracts the {@link DeploymentOptions} from {@link Deployment} annotation
 *
 * @param deploymentAnnotation {@link Deployment} annotation
 * @return {@link DeploymentOptions} for the given annotation
 *//*from   w  ww  . j av a 2s  .com*/
public static DeploymentOptions getDeploymentOptionsFromAnnotation(final Deployment deploymentAnnotation) {

    DeploymentOptions result = new DeploymentOptions();

    //if no deployment annotation is present return the default settings
    if (deploymentAnnotation == null) {
        return result;
    }

    //verticle type
    if (deploymentAnnotation.type() == VerticleType.WORKER) {
        result.setWorker(true);
    } else if (deploymentAnnotation.type() == VerticleType.MULTI_THREADED_WORKER) {
        result.setMultiThreaded(true);
    }

    //number of instances
    if (deploymentAnnotation.instances() > 1) {
        result.setInstances(deploymentAnnotation.instances());
    }

    //verticle isolation group
    if (!deploymentAnnotation.isolationGroup().isEmpty()) {
        result.setIsolationGroup(deploymentAnnotation.isolationGroup());
    }

    //verticle isolated classes
    if (deploymentAnnotation.isolatedClasses().length != 0) {
        result.setIsolatedClasses(Arrays.asList(deploymentAnnotation.isolatedClasses()));
    }

    //verticle extra classpath
    if (deploymentAnnotation.extraClasspath().length != 0) {
        result.setExtraClasspath(Arrays.asList(deploymentAnnotation.extraClasspath()));
    }

    //verticle high availability
    if (deploymentAnnotation.ha()) {
        result.setHa(true);
    }

    //verticle JSON config
    String jsonFileName = deploymentAnnotation.config();

    if (!jsonFileName.isEmpty()) {
        try (FileReader fileReader = new FileReader(jsonFileName)) {
            String jsonContent = IOUtils.toString(fileReader);
            result.setConfig(new JsonObject(jsonContent));
        } catch (Exception ex) {
            log.error("Invalid json config file: ", ex);
        }
    }

    return result;
}

From source file:io.silverware.microservices.utils.VertxUtils.java

License:Apache License

/**
 * Extracts the {@link DeploymentOptions} from the xml element
 *
 * @param verticleElement verticle element
 * @return the {@link DeploymentOptions} for the given verticle element
 *//*from   w w  w .j a v  a 2s.c  om*/
public static DeploymentOptions getDeploymentOptionsFromXml(final Node verticleElement) {

    DeploymentOptions result = new DeploymentOptions();
    NamedNodeMap attributes = verticleElement.getAttributes();

    for (int i = 0; i < attributes.getLength(); i++) {

        //verticle type
        if (attributes.getNamedItem(VertxConstants.TYPE) != null) {
            if (attributes.getNamedItem(VertxConstants.TYPE).getNodeValue()
                    .equals(VertxConstants.TYPE_WORKER)) {
                result.setWorker(true);
            } else if (attributes.getNamedItem(VertxConstants.TYPE).getNodeValue()
                    .equals(VertxConstants.TYPE_MULTI_THREADED_WORKER)) {
                result.setMultiThreaded(true);
            }
        }

        //number of instances
        if (attributes.getNamedItem(VertxConstants.INSTANCES) != null) {
            result.setInstances(
                    Integer.parseInt(attributes.getNamedItem(VertxConstants.INSTANCES).getNodeValue()));
        }

        //verticle isolation group
        if (attributes.getNamedItem(VertxConstants.ISOLATION_GROUP) != null) {
            result.setIsolationGroup(attributes.getNamedItem(VertxConstants.ISOLATION_GROUP).getNodeValue());
        }

        //verticle isolated classes
        if (attributes.getNamedItem(VertxConstants.ISOLATED_CLASSES) != null) {
            result.setIsolatedClasses(Arrays.asList(
                    attributes.getNamedItem(VertxConstants.ISOLATED_CLASSES).getNodeValue().split(" ")));
        }

        //verticle extra classpath
        if (attributes.getNamedItem(VertxConstants.EXTRA_CLASSPATH) != null) {
            result.setExtraClasspath(Arrays
                    .asList(attributes.getNamedItem(VertxConstants.EXTRA_CLASSPATH).getNodeValue().split(" ")));
        }

        //verticle high availability
        if (attributes.getNamedItem(VertxConstants.HA) != null) {
            result.setHa(Boolean.valueOf(attributes.getNamedItem(VertxConstants.HA).getNodeValue()));
        }

        //verticle JSON config
        if (attributes.getNamedItem(VertxConstants.CONFIG) != null) {
            try (FileReader fileReader = new FileReader(
                    attributes.getNamedItem(VertxConstants.CONFIG).getNodeValue())) {
                String jsonContent = IOUtils.toString(fileReader);
                result.setConfig(new JsonObject(jsonContent));
            } catch (Exception ex) {
                log.error("Invalid json config file: ", ex);
            }
        }
    }

    return result;
}