Search in sources :

Example 1 with VxApiServerOptions

use of com.szmirren.vxApi.core.options.VxApiServerOptions in project VX-API-Gateway by EliMirren.

the class DeploymentVerticle method deploymentAPP.

/**
 * 部署应用程序
 *
 * @param msg
 */
public void deploymentAPP(Message<JsonObject> msg) {
    JsonObject body = new JsonObject();
    if (vertx.isClustered()) {
        if (thisVertxName.equals(body.getString("thisVertxName"))) {
            return;
        }
    }
    String name = msg.body().getString("appName");
    JsonObject application = msg.body().getJsonObject("app");
    body.put("appConfig", application);
    // 获得全局黑名单并部署应用
    vertx.eventBus().<JsonArray>send(thisVertxName + VxApiEventBusAddressConstant.SYSTEM_BLACK_IP_FIND, null, iplist -> {
        if (iplist.succeeded()) {
            // 添加到加载配置
            body.put("blackIpSet", iplist.result().body());
            DeploymentOptions options = new DeploymentOptions(config());
            options.setIsolationGroup(name);
            options.setConfig(body);
            vertx.deployVerticle(VxApiApplication.class.getName(), options, res -> {
                if (res.succeeded()) {
                    LOG.info("启动应用程序:" + name + "-->成功!");
                    // 记录部署信息
                    VxApiServerOptions serverOptions = VxApiServerOptions.fromJson(application.getJsonObject("serverOptions"));
                    VxApiDeployInfos infos = new VxApiDeployInfos(name, res.result(), serverOptions);
                    applicationMaps.put(name, infos);
                    applicationApiMaps.put(name, new HashSet<>());
                    // 设置端口服务号代理
                    // http端口号
                    Integer httpPort = infos.getHttpPort();
                    if (httpPort != null) {
                        if (portProxyMap.get(httpPort) == null) {
                            portProxyMap.put(httpPort, infos);
                        } else {
                            List<VxApiDeployInfos> item = portStandbyProxyMap.get(httpPort) == null ? new ArrayList<VxApiDeployInfos>() : portStandbyProxyMap.get(httpPort);
                            item.add(infos);
                            portStandbyProxyMap.put(httpPort, item);
                        }
                    }
                    // https端口号
                    Integer httpsPort = infos.getHttpsPort();
                    if (httpsPort != null) {
                        if (portProxyMap.get(httpsPort) == null) {
                            portProxyMap.put(httpsPort, infos);
                        } else {
                            List<VxApiDeployInfos> item = portStandbyProxyMap.get(httpsPort) == null ? new ArrayList<VxApiDeployInfos>() : portStandbyProxyMap.get(httpsPort);
                            item.add(infos);
                            portStandbyProxyMap.put(httpsPort, item);
                        }
                    }
                    msg.reply("ok");
                } else {
                    LOG.error("启动应用程序:" + name + "-->失败:" + res.cause());
                    int code = 500;
                    if (res.cause() != null && res.cause().toString().indexOf("Address already in use: bind") > -1) {
                        code = 1111;
                    }
                    msg.fail(code, res.cause().toString());
                }
            });
        } else {
            msg.fail(500, iplist.cause().toString());
        }
    });
}
Also used : JsonArray(io.vertx.core.json.JsonArray) DeploymentOptions(io.vertx.core.DeploymentOptions) JsonObject(io.vertx.core.json.JsonObject) VxApiServerOptions(com.szmirren.vxApi.core.options.VxApiServerOptions) VxApiDeployInfos(com.szmirren.vxApi.core.entity.VxApiDeployInfos)

Aggregations

VxApiDeployInfos (com.szmirren.vxApi.core.entity.VxApiDeployInfos)1 VxApiServerOptions (com.szmirren.vxApi.core.options.VxApiServerOptions)1 DeploymentOptions (io.vertx.core.DeploymentOptions)1 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1