Search in sources :

Example 6 with UnitProxy

use of info.xiancloud.core.distribution.UnitProxy 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 7 with UnitProxy

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

the class UnitUnregistrationBridge method execute.

@Override
public UnitResponse execute(UnitRequest msg) {
    UnitProxy unitProxy = msg.get("unit", UnitProxy.class);
    NodeStatus nodeStatus = msg.get("nodeStatus", NodeStatus.class);
    UnitInstance unitInstance = UnitRegistrationBridge.unitInstance(unitProxy, nodeStatus);
    try {
        UnitDiscovery.singleton.unregister(unitInstance);
        return UnitResponse.success();
    } catch (Exception e) {
        LOG.error(e);
        return UnitResponse.failure(e, "unit un registration failure.");
    }
}
Also used : UnitInstance(info.xiancloud.core.distribution.service_discovery.UnitInstance) UnitProxy(info.xiancloud.core.distribution.UnitProxy) NodeStatus(info.xiancloud.core.distribution.NodeStatus)

Aggregations

UnitProxy (info.xiancloud.core.distribution.UnitProxy)7 JSONObject (com.alibaba.fastjson.JSONObject)2 NodeStatus (info.xiancloud.core.distribution.NodeStatus)2 UnitInstance (info.xiancloud.core.distribution.service_discovery.UnitInstance)2 Test (org.junit.Test)2 Input (info.xiancloud.core.Input)1 Obj (info.xiancloud.core.Input.Obj)1 Unit (info.xiancloud.core.Unit)1 GroupProxy (info.xiancloud.core.distribution.GroupProxy)1 UnitInstanceIdBean (info.xiancloud.core.distribution.service_discovery.UnitInstanceIdBean)1 UnitRequest (info.xiancloud.core.message.UnitRequest)1 UnitResponseTestUnit (info.xiancloud.core.test.output_test.UnitResponseTestUnit)1 BufferedWriter (java.io.BufferedWriter)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1