ControlProxy/backend/yjs/ControlProxy.yjs

221 lines
7.8 KiB
Plaintext
Raw Normal View History

2022-06-25 03:11:03 +00:00
import "repodetail.yjs";
import "search.yjs";
import "audit.yjs";
import "networking.yjs";
import "DAC.yjs";
import "union.yjs";
2022-04-19 01:26:59 +00:00
//网关为Gateway
//路由器改名为Resolver中文名为标识解析系统
//搜索引擎改名为为Registry中文名为注册表系统
//本文接口由李智负责对接。
2022-06-25 03:11:03 +00:00
contract ControlProxy {
function convertArgToJson(arg) {
2023-10-24 10:07:14 +00:00
if (typeof(arg) == 'string' && ! arg.startsWith("{") && !arg.startsWith("[")) return arg;
if (typeof(arg) == 'string') return JSON.parse(arg);
2022-06-25 03:11:03 +00:00
return arg;
}
2022-04-19 01:26:59 +00:00
2022-06-25 03:11:03 +00:00
function onCreate(arg) {
2023-10-24 10:07:14 +00:00
if (arg == null || typeof(arg) == 'string'){
2022-06-25 03:11:03 +00:00
arg = {
2023-10-24 10:07:14 +00:00
"prefix" : "test.ab.cd", "router" : "GlobalRouter"
2022-06-25 03:11:03 +00:00
};
}
arg = convertArgToJson(arg);
Global.router = "GlobalRouter";
Global.prefix = arg.prefix;
Global.router = arg.router;
2023-10-24 10:07:14 +00:00
if (arg.reqPublicKey != undefined)
YancloudUtil.setSM2KeyPair(arg.reqPublicKey, arg.reqPrivateKey);
2022-06-25 03:11:03 +00:00
initDAC(requester);
org.bdware.sc.controlproxy.RepoProxy.init(arg);
2022-04-19 01:26:59 +00:00
}
2022-06-25 03:11:03 +00:00
function isString(arg) {
2023-10-24 10:07:14 +00:00
return typeof(arg) == 'string';
2022-06-25 03:11:03 +00:00
}
2022-04-19 01:26:59 +00:00
2022-06-25 03:11:03 +00:00
export function getControlProxyConfig() {
return org.bdware.sc.controlproxy.RepoProxy.getConfig();
}
2022-04-19 01:26:59 +00:00
2022-06-25 03:11:03 +00:00
export function isOwner() {
return checkPermission(requester);
}
@Description("参数为,{\"doId\":\"bdware.ss/Repox\"}")
2022-06-25 03:11:03 +00:00
export function addRepo(arg) {
arg = convertArgToJson(arg);
2023-10-24 10:07:14 +00:00
if (arg.doId == undefined ){
2022-06-25 03:11:03 +00:00
return {
2023-10-24 10:07:14 +00:00
"msg" : "missing arguments repoId ", "code" : 1
2022-06-25 03:11:03 +00:00
};
}
executeContract("Gateway", "addLocalRepo", arg);
return {
2023-10-24 10:07:14 +00:00
"msg" : "success", "rrt" : "110ms", "code" : 0
2022-06-25 03:11:03 +00:00
};
2022-04-19 01:26:59 +00:00
}
2022-06-25 03:11:03 +00:00
//网关需新增的接口
@Description("参数为,{\"doId\":\"bdware.ss/Repox\"}")
2022-06-25 03:11:03 +00:00
export function pingRepo(arg) {
2023-10-24 10:07:14 +00:00
return executeContract("ShanxiControlProxy", "pingRepo", arg).result;
// arg = convertArgToJson(arg);
// if (arg.doId == undefined ){
// return {
// "msg" : "missing arguments repoId ", "code" : 1
// };
// }
2022-06-30 16:46:10 +00:00
// var ret = executeContract("Gateway", "pingRepo", arg.doId);
// ret = ret.result;
// if (ret.rrt > 0)
// return {
// "msg":"success", "rrt":ret.rrt, "code":0, "repoInfo":JSON.parse(ret.repoInfo)
// }; else return {
// "msg":"repo is unconnected", "code":1
// };
2023-10-24 10:07:14 +00:00
// return org.bdware.sc.controlproxy.RepoProxy.pingRepo(arg.doId);
2022-04-19 01:26:59 +00:00
}
2022-06-30 16:46:10 +00:00
@Description("shanxi/TestLocal shanxi/Repository")
export function testPingRepo(arg) {
return org.bdware.sc.controlproxy.RepoProxy.pingRepo(arg);
}
2022-04-19 01:26:59 +00:00
@Description("shanxi/TestLocal shanxi/Repository")
export function testRepoStatistics(arg) {
return org.bdware.sc.controlproxy.RepoProxy.getRepoStatistics(arg);
}
2022-06-25 03:11:03 +00:00
//网关的接口
@Description("无参数")
2022-06-25 03:11:03 +00:00
export function getRepoList(arg) {
2022-04-19 01:26:59 +00:00
//use configed arg.routerId;
2022-06-25 03:11:03 +00:00
ret = executeContract(Global.router, "listRepo", "");
//ret=executeContract("Gateway","listLocalRepo","");
//var list = ret.result
2023-10-24 10:07:14 +00:00
for (var i=0;i<ret.result.data.length;i++){
ret.result.data[i].status="online";
ret.result.data[i].check = "success";
ret.result.data[i].owner = "张*_"+i;
ret.result.data[i].description = "本仓库暂无描述";
ret.result.data[i].operator = "李*_"+i;
ret.result.data[i].enableIndex = true;
}
2022-06-25 03:11:03 +00:00
return ret.result;
}
//网关的接口
2023-10-24 10:07:14 +00:00
// @Description("参数为 {\"doId\":\"bdware.ss/Repox\"}")
// export function deleteRepo(arg) {
// arg = convertArgToJson(arg);
// if (arg.doId != null && arg.doId.indexOf(Global.prefix) != - 1){
// executeContract("Gateway", "deleteLocalRepo", arg.doId);
// return {
// "status" : "success", "code" : 0
// };
// }
// return {
// "msg" : "can not found repo", "code" : 1
// };
// }
2022-06-25 03:11:03 +00:00
//网关的接口 需新增
@Description("参数为 [{\"doId\":\"bdware.ss/Repox\"},{\"doId\":\"bdware.ss/Repoy\"}]")
2022-06-25 03:11:03 +00:00
export function deleteRepoList(arg) {
2023-10-24 10:07:14 +00:00
return {"code":0};
// arg = convertArgToJson(arg);
// var ret = [];
// for (var i = 0; i < arg.length; i ++){
// ret.push(deleteRepo(arg[i]));
// }
// return ret;
2022-06-25 03:11:03 +00:00
}
//网关的接口
@Description("参数为 {\"doId\":..., \"address\":..., \"owner\":..., }")
2022-06-25 03:11:03 +00:00
export function updateRepo(arg) {
arg = convertArgToJson(arg);
2023-10-24 10:07:14 +00:00
if (arg.doId != null){
2022-06-25 03:11:03 +00:00
executeContract("Gateway", "addLocalRepo", arg);
return {
2023-10-24 10:07:14 +00:00
"msg" : "success", "code" : 0
2022-06-25 03:11:03 +00:00
};
}
return {
2023-10-24 10:07:14 +00:00
"msg" : "missing arguments", "code" : 1
2022-06-25 03:11:03 +00:00
};
}
export function getLevelTopology(arg) {
2023-10-24 10:07:14 +00:00
return org.bdware.sc.controlproxy.TopologyCollector.getLevelTopology(arg / 1.0);
2022-06-25 03:11:03 +00:00
}
export function getAllTopology(arg) {
2023-10-24 10:07:14 +00:00
if (arg == null || arg.length == 0) {
2022-06-25 03:11:03 +00:00
return org.bdware.sc.controlproxy.TopologyCollector.getLevelTopology(2);
2023-10-24 10:07:14 +00:00
} else return org.bdware.sc.controlproxy.TopologyCollector.getLevelTopology(arg / 1.0);
2022-04-19 01:26:59 +00:00
}
2022-06-25 03:11:03 +00:00
//总体拓扑图
//@范博
2023-02-15 16:17:58 +00:00
export function setTopologyLevel(arg) {
2023-10-24 10:07:14 +00:00
Global.level = arg / 1.0;
2023-02-15 16:17:58 +00:00
return Global;
}
2022-06-25 03:11:03 +00:00
export function getAllTopology2() {
2023-10-24 10:07:14 +00:00
if (Global.level == null)
2023-02-15 16:17:58 +00:00
Global.level = 0;
return getAllTopology(Global.level);
// var nodeList = [];
// nodeList.push({
// "name":"小店区仓库", "doId":"bdware.ss.ab/Repo1", "type":"Repo", "previousNode":["bdware.ss/Gateway1", "bdware.ss/Gateway2", "bdware.ss.ab/Repo2", "bdware.ss.zz/SearchEngine"]
// }
// );
// nodeList.push({
// "name":"小山区仓库", "doId":"bdware.ss.ab/Repo2", "type":"Repo", "previousNode":["bdware.ss/Gateway1", "bdware.ss/Gateway2", "bdware.ss.ab/SearchEngine"]
// }
// );
// nodeList.push({
// "name":"太原内部共享网关", "doId":"bdware.ss/Gateway1", "type":"Gateway", "previousNode":["bdware/Gateway1", "bdware/Gateway2"]
// }
// );
// nodeList.push({
// "name":"太原对外开放网关", "doId":"bdware.ss/Gateway2", "type":"Gateway", "previousNode":["bdware/Gateway1"]
// }
// );
// nodeList.push({
// "name":"山西内部共享网关", "doId":"bdware/Gateway1", "type":"Gateway"
// }
// );
// nodeList.push({
// "name":"山西内部共享网关2", "doId":"bdware/Gateway2", "type":"Gateway"
// }
// );
// nodeList.push({
// "name":"xxx搜索引擎", "doId":"bdware.ss/SearchEngine", "type":"SearchEngine", "previousNode":["bdware.ss.cc/SearchEngine"]
// }
// );
// nodeList.push({
// "name":"山西内部共享搜索引擎2", "doId":"bdware.ss.ab/SearchEngine", "type":"SearchEngine", "previousNode":["bdware.ss/SearchEngine"]
// }
// );
// nodeList.push({
// "name":"yyy搜索引擎", "doId":"bdware.ss.cc/SearchEngine", "type":"SearchEngine"
// }
// );
// nodeList.push({
// "name":"zzz搜索引擎", "doId":"bdware.ss.zz/SearchEngine", "type":"SearchEngine", "previousNode":["bdware.ss.cc/SearchEngine"]
// }
// );
// nodeList.push({
// "name":"贵州省域路由器", "doId":"bdware.ss.ab", "type":"Router", "previousNode":["bdware"]
// }
// );
// nodeList.push({
// "name":"山西省域路由器", "doId":"bdware.ss", "type":"Router", "previousNode":["bdware"]
// }
// );
// nodeList.push({
// "name":"数瑞测试网", "doId":"bdware", "type":"Router"
// }
// );
// return nodeList;
2022-04-19 01:26:59 +00:00
}
}