Search in sources :

Example 1 with GroupProxy

use of info.xiancloud.core.distribution.GroupProxy in project xian by happyyangyuan.

the class GroupRegistrationBridge method execute.

@Override
public UnitResponse execute(UnitRequest request) {
    GroupProxy groupProxy = request.get("group", GroupProxy.class);
    NodeStatus nodeStatus = request.get("nodeStatus", NodeStatus.class);
    try {
        GroupDiscovery.singleton.register(groupInstance(groupProxy, nodeStatus));
        return UnitResponse.success();
    } catch (Exception e) {
        LOG.error(e);
        return UnitResponse.failure(e, "failed to register group");
    }
}
Also used : GroupProxy(info.xiancloud.core.distribution.GroupProxy) NodeStatus(info.xiancloud.core.distribution.NodeStatus)

Example 2 with GroupProxy

use of info.xiancloud.core.distribution.GroupProxy in project xian by happyyangyuan.

the class ZkGroupDiscovery method instance.

@Override
public GroupInstance instance(String groupInstanceId) {
    String groupName = new GroupInstanceIdBean(groupInstanceId).getGroup();
    ServiceInstance<GroupProxy> instance = serviceProviders.getUnchecked(groupName).getInstance(groupInstanceId);
    if (instance == null)
        instance = nonCachedInstanceProviders.getUnchecked(groupName).getInstance(groupInstanceId);
    return ZkServiceInstanceAdaptor.groupInstance(instance);
}
Also used : GroupProxy(info.xiancloud.core.distribution.GroupProxy) GroupInstanceIdBean(info.xiancloud.core.distribution.service_discovery.GroupInstanceIdBean)

Example 3 with GroupProxy

use of info.xiancloud.core.distribution.GroupProxy in project xian by happyyangyuan.

the class UnitMdBuilderHandler method build.

@Override
public void build() {
    LOG.info("-----unit接口文档开始构建----");
    Multimap<String, UnitProxy> unitMultimap = filter.filter(buildUnits());
    if (unitMultimap == null || unitMultimap.isEmpty()) {
        LOG.info("-----unit接口没扫描到业务模块,退出构建");
        invokeCallback(null);
        return;
    }
    LOG.info(String.format("-----unit接口扫描到业务模块数量:%s", unitMultimap.size()));
    try {
        LOG.info("----unit接口开始生成API文档-----");
        // FileWriter fw = new FileWriter(storePath);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        Writer wout = new OutputStreamWriter(bos);
        BufferedWriter bw = new BufferedWriter(wout);
        bw.write(String.format("# %s", StringUtil.isEmpty(docName) ? EnvUtil.getShortEnvName() + "业务接口文档" : docName));
        // 自定义描述
        if (!StringUtil.isEmpty(subDec)) {
            bw.newLine();
            bw.write(subDec);
        }
        bw.newLine();
        for (String groupName : unitMultimap.keySet()) {
            GroupProxy groupProxy = GroupDiscovery.singleton.newestDefinition(groupName);
            // todo it recommended to use a template to generate this MD fragment.
            bw.write("## " + String.format("%s\r\n", StringUtil.isEmpty(groupProxy.getDescription()) ? groupProxy.getName() : groupProxy.getDescription()));
            bw.newLine();
            bw.write(" 接口列表\r\n");
            Collection<UnitProxy> unitProxies = unitMultimap.get(groupName);
            for (UnitProxy unitBean : unitProxies) {
                if (!unitBean.getMeta().isPublic()) {
                    LOG.info(String.format(" ---api-doc-unit接口:%s/%s非公开访问的,跳过生成", groupProxy.getName(), unitBean.getName()));
                    continue;
                }
                LOG.info(String.format(" ---api-doc-unit接口开始生成:%s/%s", groupProxy.getName(), unitBean.getName()));
                Input io = unitBean.getInput();
                bw.write(String.format("### /%s/%s", groupProxy.getName(), unitBean.getName()));
                bw.newLine();
                bw.write(String.format(" * 接口描述: %s\r\n", StringUtil.isEmpty(unitBean.getMeta().getDescription()) ? "暂无" : unitBean.getMeta().getDescription()));
                bw.newLine();
                bw.write(" * 调用方式: POST");
                bw.newLine();
                bw.write(" * 入参数据结构说明\r\n");
                bw.newLine();
                bw.write(" <table border='1' class='table table-bordered table-striped table-condensed'>");
                bw.newLine();
                bw.write("<tr><td>名称</td><td>数据类型</td><td>参数说明</td><td>必须</td></tr>");
                bw.newLine();
                // |\r\n");
                if (io != null) {
                    List<Obj> objList = io.getList();
                    for (Obj obj : objList) {
                        bw.write("<tr>");
                        bw.newLine();
                        bw.write(String.format("<td>%s</td><td>%s</td><td>%s</td><td>%s</td>", obj.getName(), obj.getClazz().getName(), StringUtil.isEmpty(obj.getDescription()) ? "暂无" : obj.getDescription(), obj.isRequired() ? "是" : "否"));
                        bw.newLine();
                        bw.write("</tr>");
                    }
                }
                bw.write("</table>\r\n");
                bw.newLine();
                bw.write(" * 返回数据格式\r\n");
                bw.newLine();
                bw.write(String.format("````json\r\n%s\r\n````\r\n", unitBean.getMeta().getSuccessfulUnitResponse() == null ? "暂无" : unitBean.getMeta().getSuccessfulUnitResponse().toVoJSONString(true)));
                bw.write("&nbsp;&nbsp;\r\n");
            }
        }
        bw.write("&nbsp;&nbsp;\r\n");
        bw.flush();
        invokeCallback(bos.toByteArray());
        LOG.info("-----unit接口文档构建完成----");
    } catch (Exception e) {
        LOG.error(e);
    }
}
Also used : GroupProxy(info.xiancloud.core.distribution.GroupProxy) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedWriter(java.io.BufferedWriter) Input(info.xiancloud.core.Input) Obj(info.xiancloud.core.Input.Obj) OutputStreamWriter(java.io.OutputStreamWriter) UnitProxy(info.xiancloud.core.distribution.UnitProxy) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 4 with GroupProxy

use of info.xiancloud.core.distribution.GroupProxy in project xian by happyyangyuan.

the class GroupUnregistrationBridge method execute.

@Override
public UnitResponse execute(UnitRequest request) {
    GroupProxy groupProxy = request.get("group", GroupProxy.class);
    NodeStatus nodeStatus = request.get("nodeStatus", NodeStatus.class);
    GroupInstance groupInstance = GroupRegistrationBridge.groupInstance(groupProxy, nodeStatus);
    try {
        GroupDiscovery.singleton.unregister(groupInstance);
        return UnitResponse.success();
    } catch (Exception e) {
        return UnitResponse.failure(e, "group注销失败.");
    }
}
Also used : GroupProxy(info.xiancloud.core.distribution.GroupProxy) GroupInstance(info.xiancloud.core.distribution.service_discovery.GroupInstance) NodeStatus(info.xiancloud.core.distribution.NodeStatus)

Aggregations

GroupProxy (info.xiancloud.core.distribution.GroupProxy)4 NodeStatus (info.xiancloud.core.distribution.NodeStatus)2 Input (info.xiancloud.core.Input)1 Obj (info.xiancloud.core.Input.Obj)1 UnitProxy (info.xiancloud.core.distribution.UnitProxy)1 GroupInstance (info.xiancloud.core.distribution.service_discovery.GroupInstance)1 GroupInstanceIdBean (info.xiancloud.core.distribution.service_discovery.GroupInstanceIdBean)1 BufferedWriter (java.io.BufferedWriter)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1