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(" \r\n");
}
}
bw.write(" \r\n");
bw.flush();
invokeCallback(bos.toByteArray());
LOG.info("-----unit接口文档构建完成----");
} catch (Exception e) {
LOG.error(e);
}
}
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.");
}
}
Aggregations