forked from iod/ControlProxy
141 lines
4.0 KiB
Plaintext
Executable File
141 lines
4.0 KiB
Plaintext
Executable File
import "repodetail.yjs"
|
||
import "search.yjs"
|
||
import "audit.yjs"
|
||
import "networking.yjs"
|
||
import "DAC.yjs"
|
||
//网关为Gateway
|
||
//路由器改名为Resolver,中文名为标识解析系统
|
||
//搜索引擎改名为为Registry,中文名为注册表系统
|
||
//本文接口由李智负责对接。
|
||
contract ControlProxy{
|
||
|
||
function convertArgToJson(arg){
|
||
if (typeof(arg)=='string' && !arg.startsWith("{")) return arg;
|
||
if (typeof(arg)=='string') return JSON.parse(arg);
|
||
return arg;
|
||
}
|
||
|
||
function onCreate(arg){
|
||
if (arg==null|| typeof(arg)=='string'){
|
||
arg={"prefix":"test.ab.cd",
|
||
"router":"GlobalRouter"
|
||
};
|
||
}
|
||
arg = convertArgToJson(arg);
|
||
Global.router = "GlobalRouter";
|
||
|
||
Global.prefix = arg.prefix;
|
||
Global.router = arg.router;
|
||
initDAC(requester);
|
||
org.bdware.sc.controlproxy.RepoProxy.init(arg);
|
||
|
||
}
|
||
|
||
function isString(arg){
|
||
return typeof(arg)=='string';
|
||
}
|
||
|
||
export function isOwner(){
|
||
return checkPermission(requester);
|
||
}
|
||
@Descripton("参数为,{\"doId\":\"bdware.ss/Repox\"}")
|
||
export function addRepo(arg){
|
||
arg = convertArgToJson(arg);
|
||
if (arg.doId ==undefined ){
|
||
return {
|
||
"msg":"missing arguments repoId ","code":1};
|
||
}
|
||
executeContract("Gateway","addLocalRepo",arg);
|
||
return {
|
||
"msg":"success","rrt":"110ms","code":0};
|
||
}
|
||
//网关需新增的接口
|
||
@Descripton("参数为,{\"doId\":\"bdware.ss/Repox\"}")
|
||
export function pingRepo(arg){
|
||
arg = convertArgToJson(arg);
|
||
if (arg.doId ==undefined ){
|
||
return {
|
||
"msg":"missing arguments repoId ","code":1};
|
||
}
|
||
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};
|
||
}
|
||
|
||
//网关的接口
|
||
export function getCCCCCCCCCCCCConfInfo(){
|
||
|
||
return Global;
|
||
}
|
||
@Descripton("无参数")
|
||
export function getRepoList(arg){
|
||
//use configed arg.routerId;
|
||
//TODO!!
|
||
ret = executeContract(Global.router,"listRepo","");
|
||
//ret=executeContract("Gateway","listLocalRepo","");
|
||
//var list = ret.result
|
||
return ret.result;
|
||
}
|
||
//网关的接口
|
||
@Descripton("参数为 {\"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};
|
||
}
|
||
//网关的接口 需新增
|
||
@Descripton("参数为 [{\"doId\":\"bdware.ss/Repox\"},{\"doId\":\"bdware.ss/Repoy\"}]")
|
||
export function deleteRepoList(arg){
|
||
arg = convertArgToJson(arg);
|
||
var ret = [];
|
||
for (var i=0;i<arg.length;i++){
|
||
ret.push(deleteRepo(arg[i]));
|
||
}
|
||
return ret;
|
||
}
|
||
//网关的接口
|
||
@Descripton("参数为 {\"doId\":..., \"address\":..., \"owner\":..., }")
|
||
export function updateRepo(arg){
|
||
arg = convertArgToJson(arg);
|
||
if (arg.doId!=null){
|
||
executeContract("Gateway","addLocalRepo",arg);
|
||
return {
|
||
"msg":"success","code":0};
|
||
}
|
||
return {
|
||
"msg":"missing arguments","code":1};
|
||
}
|
||
//总体拓扑图
|
||
//@范博
|
||
export function getAllTopology(){
|
||
var nodeList = [];
|
||
nodeList.push({
|
||
"name":"小店区仓库","doId":"bdware.ss.ab/Repo1","previousNode":["bdware.ss/Gateway1","bdware.ss/Gateway2"]}
|
||
);
|
||
nodeList.push({
|
||
"name":"太原内部共享网关","doId":"bdware.ss/Gateway1","previousNode":["bdware/Gateway1", "bdware/Gateway2"]}
|
||
);
|
||
nodeList.push({
|
||
"name":"太原对外开放网关","doId":"bdware.ss/Gateway2", "previousNode":["bdware/Gateway1"]}
|
||
);
|
||
nodeList.push({
|
||
"name":"山西内部共享网关","doId":"bdware/Gateway1"}
|
||
);
|
||
nodeList.push({
|
||
"name":"山西内部共享网关2","doId":"bdware/Gateway2"}
|
||
);
|
||
return nodeList;
|
||
}
|
||
}
|