@Before public void prepare(TestContext context) { vertx = Vertx.vertx(); JsonObject dbConf = new JsonObject() .put(WikiDatabaseVerticle.CONFIG_WIKIDB_JDBC_URL, "jdbc:hsqldb:mem:testdb;shutdown=true") .put(WikiDatabaseVerticle.CONFIG_WIKIDB_JDBC_MAX_POOL_SIZE, 4); vertx.deployVerticle(new WikiDatabaseVerticle(), new DeploymentOptions().setConfig(dbConf), context.asyncAssertSuccess()); vertx.deployVerticle(new HttpServerVerticle(), context.asyncAssertSuccess()); webClient = WebClient.create(vertx, new WebClientOptions() .setDefaultHost("localhost") .setDefaultPort(8080) .setSsl(true) .setTrustOptions(new JksOptions().setPath("server-keystore.jks").setPassword("secret"))); }
@Before public void prepare(TestContext context) { vertx = Vertx.vertx(); JsonObject dbConf = new JsonObject() .put(WikiDatabaseVerticle.CONFIG_WIKIDB_JDBC_URL, "jdbc:hsqldb:mem:testdb;shutdown=true") .put(WikiDatabaseVerticle.CONFIG_WIKIDB_JDBC_MAX_POOL_SIZE, 4); vertx.deployVerticle(new WikiDatabaseVerticle(), new DeploymentOptions().setConfig(dbConf), context.asyncAssertSuccess()); vertx.deployVerticle(new HttpServerVerticle(), context.asyncAssertSuccess()); // tag::test-https[] webClient = WebClient.create(vertx, new WebClientOptions() .setDefaultHost("localhost") .setDefaultPort(8080) .setSsl(true) // <1> .setTrustOptions(new JksOptions().setPath("server-keystore.jks").setPassword("secret"))); // <2> // end::test-https[] }
@Test public void testInit() { boolean status = false; try { new MockUp<VertxUtils>() { @Mock public Vertx init(VertxOptions vertxOptions) { return null; } @Mock public <VERTICLE extends AbstractVerticle> boolean blockDeploy(Vertx vertx, Class<VERTICLE> cls, DeploymentOptions options) throws InterruptedException { return true; } }; instance.init(); } catch (Exception e) { status = true; } Assert.assertFalse(status); }
@Override public void start(Future<Void> startFuture) throws Exception { Future<String> dbVerticleDeployment = Future.future(); vertx.deployVerticle(new WikiDatabaseVerticle(), dbVerticleDeployment.completer()); dbVerticleDeployment.compose(id -> { Future<String> httpVerticleDeployment = Future.future(); vertx.deployVerticle( "io.vertx.guides.wiki.http.HttpServerVerticle", new DeploymentOptions().setInstances(2), httpVerticleDeployment.completer()); return httpVerticleDeployment; }).setHandler(ar -> { if (ar.succeeded()) { startFuture.complete(); } else { startFuture.fail(ar.cause()); } }); }
public static void main(String... args) { //Note to self // run this demo in HA mode, deploy this verticle on a separate node and combine it with demo6 final JsonObject config = Config.fromFile("config/demo7.json"); VertxOptions opts = new VertxOptions().setClustered(true); Vertx.clusteredVertx(opts, result -> { if (result.succeeded()) { LOG.info("Cluster running"); Vertx vertx = result.result(); vertx.deployVerticle(BitcoinAdjustedData.class.getName(), new DeploymentOptions().setConfig(config).setWorker(false)); } else { LOG.error("Clusterin failed"); throw new RuntimeException(result.cause()); } }); }
public static void main(String... args) { final JsonObject config = Config.fromFile("config/demo6.json"); Vertx vertx = Vertx.vertx(); vertx.deployVerticle(new JSPercentilesDatasource(), new DeploymentOptions().setConfig(config)); /* Vertx vertx = Vertx.vertx(); vertx.deployVerticle(new JSAggregateDatasource(), new DeploymentOptions().setConfig(config)); */ VertxOptions opts = new VertxOptions().setClustered(true); Vertx.clusteredVertx(opts, result -> { if(result.succeeded()){ LOG.info("Cluster running"); Vertx cvertx = result.result(); cvertx.deployVerticle(new JSPercentilesDatasource(), new DeploymentOptions().setConfig(config)); } else { LOG.error("Clustering failed"); throw new RuntimeException(result.cause()); } }); }
public static void main(String... args) { final JsonObject config = Config.fromFile("config/demo6.json"); /* Vertx vertx = Vertx.vertx(); vertx.deployVerticle(new JSAggregateDatasource(), new DeploymentOptions().setConfig(config)); */ VertxOptions opts = new VertxOptions().setClustered(true); Vertx.clusteredVertx(opts, result -> { if(result.succeeded()){ LOG.info("Cluster running"); Vertx vertx = result.result(); vertx.deployVerticle(new JSAggregateDatasource(), new DeploymentOptions().setConfig(config)); } else { LOG.error("Clustering failed"); throw new RuntimeException(result.cause()); } }); }
@Override public void start() throws Exception { JsonObject config = Vertx.currentContext().config(); DeploymentOptions opts = new DeploymentOptions().setConfig(config); DeploymentOptions chunkOpts = new DeploymentOptions().setConfig(config.copy().put(ADDRESS, "/queryChunk")) //.setInstances(config.getInteger(PARALLELISM)) //.setWorker(true) ; vertx.deployVerticle("js:io/devcon5/metrics/demo6/AggregateTimeSeriesVerticle.js",chunkOpts, result -> { if (result.succeeded()) { LOG.info("JS Verticle successfully deployed {}", result.result()); } else { LOG.error("Failed to deploy JS Verticle", result.cause()); } }); vertx.deployVerticle(SplitMergeTimeSeriesVerticle.class.getName(), opts); vertx.deployVerticle(AnnotationVerticle.class.getName(), opts); vertx.deployVerticle(LabelVerticle.class.getName(), opts); vertx.deployVerticle(HttpServerVerticle.class.getName(), opts); }
@Override public void start() throws Exception { JsonObject config = Vertx.currentContext().config(); DeploymentOptions opts = new DeploymentOptions().setConfig(config); DeploymentOptions chunkOpts = new DeploymentOptions().setInstances(config.getInteger(PARALLELISM)) .setWorker(true) .setConfig(config.copy().put(ADDRESS, "/queryChunk")); //this verticle is doing the "post-processing" vertx.deployVerticle(PercentilesVerticle.class.getName(),chunkOpts); //the other verticles vertx.deployVerticle(SplitMergeTimeSeriesVerticle.class.getName(), opts); vertx.deployVerticle(AnnotationVerticle.class.getName(), opts); vertx.deployVerticle(LabelVerticle.class.getName(), opts); vertx.deployVerticle(HttpServerVerticle.class.getName(), opts); }
@Provides @Singleton public DeploymentOptions provideDeploymentOptions( ApplicationConfiguration applicationConfiguration) { // Vert.x is a non-blocking event-loop based framework; it does not follow the approach of 1 // connection -> 1 // thread instead since each request is handled in a request-calback-response fashion the event // loop is (or // should be) ~immediately available to handle the next request so want to accept the default // since this // indicates conformance with the Vert.x approach or to put it another way we want non // conformance to be made // obvious so that we can fix it rather than for it to be hidden behind tweaked thread pools // Note: since Guice is creating the verticles for us we cannot set instances > 1, this _may_ be // reconsidered later ... return new DeploymentOptions().setWorkerPoolName("vertx-worker").setInstances(1); }
@BeforeAll public static void start() { port = getFreePort(); httpDataProvider = mock(HttpDataProvider.class); logger.info("Starting embedded HTTP server on port: {}", port); vertx = Vertx.vertx(); DeploymentOptions options = new DeploymentOptions().setConfig(new JsonObject().put("http.port", port)).setInstances(1); CountDownLatch latch = new CountDownLatch(1); vertx.deployVerticle( new HttpServerSimulatorVerticle(httpDataProvider), options, result -> { logger.info("Started embedded HTTP server with result: {}", result); latch.countDown(); }); try { latch.await(); } catch (InterruptedException e) { logger.warn("Failed to wait for the embedded HTTP server to start!"); } }
private void redeployVerticles(DeploymentOptions options){ Future<String> future1 = undeployVerticles(); future1.compose(s1 -> { Future<String> future2 = deployVerticles(options); future2.setHandler(handler -> { if (handler.succeeded()) { System.out.println("Redployment successful!"); } else { System.err.println("Redeployment failed: " + handler.cause().getMessage()); } }); }, Future.future().setHandler(handler -> { System.err.println("Redeployment failed: " + handler.cause().getMessage()); })); }
private Future<String> deployPriceVerticle(DeploymentOptions options) { Future<String> future = Future.future(); vertx.deployVerticle(new BittrexPriceVerticle(service), options, res -> { if (res.succeeded()) { p_id = res.result(); System.out.println("PriceVerticle Deployment id is: " + res.result()); future.complete(); } else { System.err.println("PriceVerticle Deployment failed: " + res.cause().getMessage()); future.fail(res.cause()); } }); return future; }
/** * Populates this object with the information from the supplied JsonObject * @param json The JSON Object */ public void fromJson(JsonObject json) { Objects.requireNonNull(json, "json is required"); if (json.getValue("name") instanceof String) setName((String) json.getValue("name")); if (json.getValue("deploymentOptions") instanceof JsonObject) { setDeploymentOptions(new DeploymentOptions()); DeploymentOptionsConverter.fromJson((JsonObject) json.getValue("deploymentOptions"), this.getDeploymentOptions()); } if (json.getValue("dependents") instanceof JsonArray) { json.getJsonArray("dependents").forEach(item -> { if (item instanceof JsonObject) { DependentsDeployment deps = new DependentsDeployment(); deps.fromJson((JsonObject) item); getDependents().add(deps); } }); } }
@Override public void start(Future<Void> startFuture) throws Exception { // tag::rx-deploy-verticle[] Single<String> dbVerticleDeployment = vertx.rxDeployVerticle( "io.vertx.guides.wiki.database.WikiDatabaseVerticle"); // end::rx-deploy-verticle[] // tag::rx-sequential-composition[] dbVerticleDeployment .flatMap(id -> { // <1> Single<String> httpVerticleDeployment = vertx.rxDeployVerticle( "io.vertx.guides.wiki.http.HttpServerVerticle", new DeploymentOptions().setInstances(2)); return httpVerticleDeployment; }) .subscribe(id -> startFuture.complete(), startFuture::fail); // <2> // end::rx-sequential-composition[] }
@Override public void start(Future<Void> startFuture) throws Exception { Future<String> dbVerticleDeployment = Future.future(); // <1> vertx.deployVerticle(new WikiDatabaseVerticle(), dbVerticleDeployment.completer()); // <2> dbVerticleDeployment.compose(id -> { // <3> Future<String> httpVerticleDeployment = Future.future(); vertx.deployVerticle( "io.vertx.guides.wiki.HttpServerVerticle", // <4> new DeploymentOptions().setInstances(2), // <5> httpVerticleDeployment.completer()); return httpVerticleDeployment; // <6> }).setHandler(ar -> { // <7> if (ar.succeeded()) { startFuture.complete(); } else { startFuture.fail(ar.cause()); } }); }
/** * Name based loading of a Verticle with configured options * * @param verticleId * the full qualified name - can be any supported Verticel * language * @param options * The configuration object * @return a Future that resolves after loading */ private Future<Void> loadVerticle(final String verticleId, final DeploymentOptions options) { final Future<Void> result = Future.future(); this.getVertx().deployVerticle(verticleId, options, r -> { if (r.succeeded()) { final String vid = r.result(); this.logger.info(verticleId + " started as " + vid); this.loadedVerticles.add(vid); result.complete(); } else { this.logger.fatal(r.cause()); result.fail(r.cause()); } }); return result; }
@BeforeClass public static void setUp(TestContext ctx) throws Exception { vertx = Vertx.vertx(); config = getConfig().put(HTTP_PORT, PORT); initializeDatabase(vertx, config.getJsonObject("mysql")).rxSetHandler() .doOnSuccess(db -> localDatabase = db) .doOnError(ctx::fail) .flatMap(db -> Observable.just(DatabaseService.create(vertx, config)).toSingle()) .doOnSuccess(db -> database = db) .doOnError(ctx::fail) .toCompletable() .andThen(deployVerticle(vertx, new ServerVerticle() .setDatabase(database), new DeploymentOptions().setConfig(config))) .test() .awaitTerminalEvent(10, SECONDS) .assertCompleted(); }
@Override public void connect(final Vertx vertx) { /** 1.Find Agent for deploy **/ final ConcurrentMap<ServerType, Class<?>> agents = this.factor.agents(); final Extractor<DeploymentOptions> extractor = Instance.instance(AgentExtractor.class); /** 2.Record options**/ final ConcurrentMap<Class<?>, DeploymentOptions> options = new ConcurrentHashMap<>(); Fn.itMap(agents, (type, clazz) -> { // 3.1 Agent deployment options final DeploymentOptions option = extractor.extract(clazz); options.put(clazz, option); // 3.2 Agent deployment Verticles.deploy(vertx, clazz, option, LOGGER); }); // Runtime hooker Runtime.getRuntime().addShutdownHook(new Thread(() -> Fn.itMap(agents, (type, clazz) -> { // 4. Undeploy Agent. final DeploymentOptions opt = options.get(clazz); Verticles.undeploy(vertx, clazz, opt, LOGGER); }))); }
static void deploy(final Vertx vertx, final Class<?> clazz, final DeploymentOptions option, final Annal logger) { // Verticle deployment final String name = clazz.getName(); final String flag = option.isWorker() ? "Worker" : "Agent"; vertx.deployVerticle(name, option, (result) -> { // Success or Failed. if (result.succeeded()) { logger.info(Info.VTC_END, name, option.getInstances(), result.result(), flag); INSTANCES.put(clazz, result.result()); } else { logger.warn(Info.VTC_FAIL, name, option.getInstances(), result.result(), null == result.cause() ? null : result.cause().getMessage(), flag); } }); }
private DeploymentOptions transform(final Class<?> clazz) { final Annotation annotation = clazz.getDeclaredAnnotation(Worker.class); // 1. Instance final int instances = Instance.invoke(annotation, Key.INSTANCES); final boolean ha = Instance.invoke(annotation, Key.HA); final String group = Instance.invoke(annotation, Key.GROUP); // 2. Record Log information final DeploymentOptions options = new DeploymentOptions(); options.setHa(ha); options.setInstances(instances); options.setIsolationGroup(group); // 3. Disabled worker fetures. options.setWorker(true); LOGGER.info(Info.VTC_OPT, instances, group, ha, options.toJson()); return options; }
private DeploymentOptions transform(final Class<?> clazz) { final Annotation annotation = clazz.getDeclaredAnnotation(Agent.class); // 1. Instance final int instances = Instance.invoke(annotation, Key.INSTANCES); final boolean ha = Instance.invoke(annotation, Key.HA); final String group = Instance.invoke(annotation, Key.GROUP); // 2. Record Log information final DeploymentOptions options = new DeploymentOptions(); options.setHa(ha); options.setInstances(instances); options.setIsolationGroup(group); // 3. Disabled worker fetures. options.setWorker(false); LOGGER.info(Info.VTC_OPT, instances, group, ha, options.toJson()); return options; }
@Before public void prepare(TestContext context) { vertx = Vertx.vertx(); JsonObject dbConf = new JsonObject() .put(WikiDatabaseVerticle.CONFIG_WIKIDB_JDBC_URL, "jdbc:hsqldb:mem:testdb;shutdown=true") // <1> .put(WikiDatabaseVerticle.CONFIG_WIKIDB_JDBC_MAX_POOL_SIZE, 4); vertx.deployVerticle(new WikiDatabaseVerticle(), new DeploymentOptions().setConfig(dbConf), context.asyncAssertSuccess()); vertx.deployVerticle(new HttpServerVerticle(), context.asyncAssertSuccess()); webClient = WebClient.create(vertx, new WebClientOptions() .setDefaultHost("localhost") .setDefaultPort(8080)); }
@Override public void start(Future<Void> startFuture) throws Exception { Future<String> generatorFuture = future(); vertx.deployVerticle( GeneratorVerticle.class.getName(), new DeploymentOptions().setConfig(config().getJsonObject("generator")), generatorFuture ); Future<String> webFuture = future(); vertx.deployVerticle( WebVerticle.class.getName(), new DeploymentOptions().setConfig(config().getJsonObject("web")), webFuture ); CompositeFuture.all(asList(generatorFuture, webFuture)).setHandler(ar -> { if (ar.failed()) { log.error("Vertx forge failed to start: {}", ar.cause().getMessage()); ar.cause().printStackTrace(); } else { log.info("\n----------------------------------------------------------\n\t" + "{} is running!\n" + "----------------------------------------------------------", MainVerticle.class.getSimpleName()); startFuture.complete(); } }); }
public static void init(Vertx vertx) throws InterruptedException { RedisOptions redisOptions = new RedisOptions() .setHost(PerfConfiguration.redisHost) .setPort(PerfConfiguration.redisPort) .setAuth(PerfConfiguration.redisPassword); ClientPoolFactory<RedisClient> factory = () -> { return RedisClient.create(vertx, redisOptions); }; clientMgr = new ClientPoolManager<>(vertx, factory); DeploymentOptions deployOptions = VertxUtils.createClientDeployOptions(clientMgr, PerfConfiguration.redisClientCount); VertxUtils.blockDeploy(vertx, ClientVerticle.class, deployOptions); }
@Before public void setUp(TestContext context) throws IOException { vertx = Vertx.vertx(); // Pick an available and random ServerSocket socket = new ServerSocket(0); port = socket.getLocalPort(); socket.close(); DeploymentOptions options = new DeploymentOptions() .setConfig(new JsonObject().put("HTTP_PORT", port)); vertx.deployVerticle(MyFirstVerticle.class.getName(), options, context.asyncAssertSuccess()); }
@PostConstruct public void deployVerticles() { doWithConfiguration(config -> { vertx.deployVerticle(serviceVerticle, new DeploymentOptions().setConfig(config)); vertx.deployVerticle(restVerticle, new DeploymentOptions().setConfig(config)); }); }
public void create() { // 这里面是同步接口,且好像直接在事件线程中用,保险起见,先使用独立的vertx实例 Vertx vertx = VertxUtils.getOrCreateVertxByName("registry", null); HttpClientOptions httpClientOptions = createHttpClientOptions(); clientMgr = new ClientPoolManager<>(vertx, new HttpClientPoolFactory(httpClientOptions)); DeploymentOptions deployOptions = VertxUtils.createClientDeployOptions(this.clientMgr, ServiceRegistryConfig.INSTANCE.getWorkerPoolSize()); try { VertxUtils.blockDeploy(vertx, ClientVerticle.class, deployOptions); } catch (InterruptedException e) { LOGGER.error("deploy a registry verticle failed, {}", e.getMessage()); } }
@Override public boolean init() throws Exception { restClient = RestTransportClientManager.INSTANCE.getRestClient(); // 部署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); }