diff --git a/backend/.gitignore b/backend/.gitignore index 2643730..c509fcf 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -2,6 +2,8 @@ /build/ /cplibs/ cplibs +deploy +contractDB # Compiled class file *.class diff --git a/backend/build.gradle b/backend/build.gradle index a952179..d52ef5a 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -1,6 +1,12 @@ buildscript { + repositories { + mavenCentral() + mavenLocal() + } dependencies { - classpath files("buildlibs/simple-ypk-packer-0.2.0.jar") + classpath "org.bdware.bdcontract:simple-ypk-packer:0.5.0" + classpath "org.bdware.bdcontract:ypk-deploy-tool:0.5.2" + } } @@ -8,6 +14,8 @@ plugins { id 'java' id 'java-library' } +version = "1.2.0" +group = 'org.bdware.sc.controlproxy' tasks.withType(JavaCompile) { options.compilerArgs << '-Xlint:none' @@ -34,19 +42,20 @@ sourceSets { } dependencies { - api 'org.apache.logging.log4j:log4j-core:2.14.1' - api 'org.apache.logging.log4j:log4j-api:2.14.1' + api 'org.apache.logging.log4j:log4j-core:2.17.2' + api 'org.apache.logging.log4j:log4j-api:2.17.2' api 'com.google.code.gson:gson:2.8.8' - - implementation fileTree(dir: 'cplibs', include: '*.jar') - implementation fileTree(dir: 'cplibs/lib/', include: '*.jar') - implementation 'org.bdware.doip:doip-audit-tool:0.9.0' + implementation 'org.bdware.sc:cp:1.5.7' + implementation 'org.bdware.doip:doip-audit-tool:0.9.4' + implementation 'org.bdware.bdcontract:sdk-java:1.0.0' testImplementation 'junit:junit:4.13.2' + testImplementation 'org.bdware.bdcontract:ypk-deploy-tool:0.4.0' } task copyLibs(type: Copy) { from configurations.runtimeClasspath into "./build/output/libs/" + } task copyYJS(type: Copy) { @@ -69,17 +78,30 @@ task copyJar(type: Copy, dependsOn: [":backend:jar", ":backend:copyLibs"]) { doFirst { println "copyJar start" } + +} +task grepCP(dependsOn: [":backend:copyJar"]) { + doLast { + org.bdware.datanet.YPKPacker.grepJarByCPVersion("./backend/build/output/libs", org.bdware.datanet.CPVersion.cp_1_5_3) + // org.bdware.datanet.YPKPacker.grepCPLibWithFilter("./backend/cplibs/libs/", "./backend/build/output/libs", "./backend/grepcp.list") + } } -task buildZip(type: Zip, dependsOn: ["copyAssets", "copyJar", "copyYJS"]) { +task buildZip(type: Zip, dependsOn: ["copyAssets", "grepCP", "copyJar", "copyYJS"]) { from './build/output/' duplicatesStrategy = DuplicatesStrategy.INCLUDE archiveFileName = 'ControlProxy.zip' destinationDirectory = file('build/') } -task buildYPK(dependsOn: ["buildZip"]) { +task buildYPK(dependsOn: ["buildZip", "grepCP"]) { doLast { org.bdware.datanet.YPKPacker.staticPack("./backend/build/ControlProxy.zip", "./backend/build/ControlProxy-${project.version}.ypk") } } + +task deploy(dependsOn: ["buildYPK"]) { + doLast { + org.bdware.ypkdeploy.HTTPTool.batchRun("./backend/deployconfig.json", true) + } +} \ No newline at end of file diff --git a/backend/buildlibs/simple-ypk-packer-0.2.0.jar b/backend/buildlibs/simple-ypk-packer-0.2.0.jar deleted file mode 100644 index c959b1f..0000000 Binary files a/backend/buildlibs/simple-ypk-packer-0.2.0.jar and /dev/null differ diff --git a/backend/debugconf.json b/backend/debugconf.json index 925fd00..6592100 100644 --- a/backend/debugconf.json +++ b/backend/debugconf.json @@ -1,14 +1,15 @@ { - "agentHttpAddr": "127.0.0.1:18000", + "agentHttpAddr": "127.0.0.1:18010", "createParam": { "privateKey": "4616ff0e2a4f982364914f9be30b51c6bc6ccb6602114a9ee8792f2ccf67465b", "publicKey": "04f9b9b8f324908464f78a6235e2dd93e4dfdaf045e9b1b5cfd57374516cc61a79a86fc2b42d3321a5b49a0f25381a7bed61901b40b729f72354e716673d551e98", - "prefix": "macjw.ab", + "prefix": "bdtest", "router": "GlobalRouter", - "routerURI": "tcp://localhost:2042", + "routerURI": "tcp://127.0.0.1:18041", "auditType": "OnlyHash" }, - "script": "/Users/huaqiancai/BDWare/datanet/ControlProxy/backend/build/ControlProxy-0.8.7.ypk", + + "script": "/Users/huaqiancai/BDWare/datanet/ControlProxy/backend/build/ControlProxy-0.9.8.ypk", "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd", - "privKey": "589d94ee5688358a1c5c18430dd9c75097ddddebf7repodetail.yjs69f139da36a807911d20f8" + "privKey": "589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8" } \ No newline at end of file diff --git a/backend/deployconfig.json b/backend/deployconfig.json new file mode 100644 index 0000000..a920cf3 --- /dev/null +++ b/backend/deployconfig.json @@ -0,0 +1,16 @@ +{ + "host": "127.0.0.1", + "privateKey": "d675782acf011dbc01a73c7967ccff9564486f7c3a9f5d5de151caffaa18936", + "publicKey": "04303718771b9323c204e607639f14469f9a94e55b0964a408ad3b3864b0493b645d7070da0d550f0c54b934275a8e88dedc3024467b0566db5c1108b1baeaae27", + "ypkPath": "/Users/huaqiancai/BDWare/datanet/ControlProxy/backend/build/ControlProxy-0.9.6.ypk", + "killBeforeStart": "ControlProxy", + "createParam": { + "privateKey": "4616ff0e2a4f982364914f9be30b51c6bc6ccb6602114a9ee8792f2ccf67465b", + "publicKey": "04f9b9b8f324908464f78a6235e2dd93e4dfdaf045e9b1b5cfd57374516cc61a79a86fc2b42d3321a5b49a0f25381a7bed61901b40b729f72354e716673d551e98", + "prefix": "bdtest", + "router": "GlobalRouter", + "routerURI": "tcp://127.0.0.1:18041", + "auditType": "OnlyHash" + }, + "agentPort": 18010 +} \ No newline at end of file diff --git a/backend/grepcp.list b/backend/grepcp.list new file mode 100644 index 0000000..a481ccb --- /dev/null +++ b/backend/grepcp.list @@ -0,0 +1 @@ +yjs.jar \ No newline at end of file diff --git a/backend/src/main/java/org/bdware/sc/controlproxy/RepoProxy.java b/backend/src/main/java/org/bdware/sc/controlproxy/RepoProxy.java index 8a352c4..ccf3ec1 100644 --- a/backend/src/main/java/org/bdware/sc/controlproxy/RepoProxy.java +++ b/backend/src/main/java/org/bdware/sc/controlproxy/RepoProxy.java @@ -4,6 +4,7 @@ import com.google.gson.*; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.bdware.doip.audit.EndpointConfig; +import org.bdware.doip.audit.SM2Signer; import org.bdware.doip.audit.client.AuditDoipClient; import org.bdware.doip.audit.client.AuditIrpClient; import org.bdware.doip.audit.config.TempConfigStorage; @@ -24,6 +25,7 @@ public class RepoProxy { } static String prefix; + public static String router; static EndpointConfig endpointConfig; public static void init(Object obj) { @@ -37,11 +39,15 @@ public class RepoProxy { TempConfigStorage storage = new TempConfigStorage((String) obj); endpointConfig = storage.loadAsEndpointConfig(); prefix = storage.load().get("prefix").getAsString(); + router = storage.load().get("router").getAsString(); } else { JsonElement je = JSONTool.convertMirrorToJson(obj); TempConfigStorage storage = new TempConfigStorage(je.toString()); endpointConfig = storage.loadAsEndpointConfig(); prefix = storage.load().get("prefix").getAsString(); + + router = storage.load().get("router").getAsString(); + } } @@ -59,13 +65,12 @@ public class RepoProxy { if (!doId.contains("/")) { doId = prefix + "/" + doId; } - ClientConfig config = null; AuditType type = null; try { AuditIrpClient irpClient = new AuditIrpClient(endpointConfig); AuditConfig auditConfig = irpClient.getAuditConfig(); - AuditDoipClient client = new AuditDoipClient(auditConfig); + AuditDoipClient client = new AuditDoipClient(auditConfig, new SM2Signer(null)); StateInfoBase result = irpClient.resolve(doId); config = new ClientConfig(result.getValues("address")); client.connect(config); diff --git a/backend/src/main/java/org/bdware/sc/controlproxy/TopologyCollector.java b/backend/src/main/java/org/bdware/sc/controlproxy/TopologyCollector.java new file mode 100644 index 0000000..f202502 --- /dev/null +++ b/backend/src/main/java/org/bdware/sc/controlproxy/TopologyCollector.java @@ -0,0 +1,130 @@ +package org.bdware.sc.controlproxy; + +import com.google.gson.*; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.bdware.client.SmartContractHttpClient; +import org.bdware.sc.ContractResult; +import org.bdware.sc.bean.ContractRequest; +import org.bdware.sc.boundry.JavaScriptEntry; +import org.bdware.sc.engine.JSONTool; +import org.bdware.sc.util.JsonUtil; +import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.*; + +public class TopologyCollector { + + static Logger LOGGER = LogManager.getLogger(TopologyCollector.class); + + public static List getCurrentTopology() { + TopologyGraph graph = new TopologyGraph(); + //通过SearchEngine,可拿到本级的Repo(或下组的SE)与SearchEngine的关系。 + //通过Router,可拿到本级的Repo列表,也可拿到下组Router列表。 + JsonPrimitive arg = new JsonPrimitive("a"); + ContractResult currentRouters = executeContract(RepoProxy.router, "getRouterInfo", arg); + //--------构建Router网 + JsonObject root = JsonUtil.parseStringAsJsonObject(currentRouters.result.getAsJsonObject().get("data").getAsString()); + JsonObject rootNode = new JsonObject(); + rootNode.add("name", root.get("name")); + rootNode.add("doId", root.get("doId")); + rootNode.addProperty("type", "Router"); + rootNode.add("previousNode", new JsonArray()); + graph.addNode(rootNode); + ContractResult nextRouters = executeContract(RepoProxy.router, "listLRS", arg); + JsonArray routersArray = nextRouters.result.getAsJsonObject().get("data").getAsJsonArray(); + for (JsonElement je : routersArray) { + JsonObject node = new JsonObject(); + JsonObject from = je.getAsJsonObject(); + node.add("name", from.get("name")); + node.add("doId", from.get("doId")); + node.addProperty("type", "Router"); + graph.addNode(node); + graph.addEdge(node.get("doId").getAsString(), root.get("doId").getAsString()); + } + //--------Router网构建完毕 + //--------构建SearchEngine网----- + JsonObject searchEngine = new JsonObject(); + searchEngine.addProperty("doId", root.get("doId").getAsString() + "/SearchEngine"); + searchEngine.addProperty("type", "SearchEngine"); + searchEngine.addProperty("name", root.get("name").getAsString() + "搜索引擎"); + graph.addNode(searchEngine); + //下级SearchEngine同步至上级 + for (JsonElement je : routersArray) { + JsonObject node = new JsonObject(); + JsonObject from = je.getAsJsonObject(); + node.addProperty("doId", from.get("doId").getAsString() + "/SearchEngine"); + node.addProperty("type", "SearchEngine"); + node.addProperty("name", from.get("name").getAsString() + "搜索引擎"); + graph.addNode(node); + graph.addEdge(node.get("doId").getAsString(), searchEngine.get("doId").getAsString()); + } + + JsonObject gateway = new JsonObject(); + gateway.addProperty("doId", root.get("doId").getAsString() + "/GateWay"); + gateway.addProperty("type", "GateWay"); + gateway.addProperty("name", root.get("name").getAsString() + "网关"); + graph.addNode(gateway); + //TODO 通过SearchEngine把Repo的关系给弄上 + //----------------- + ContractResult currentRepos = executeContract(RepoProxy.router, "listRepo", arg); + JsonArray repos = currentRepos.result.getAsJsonObject().get("data").getAsJsonArray(); + for (JsonElement je : repos) { + JsonObject from = je.getAsJsonObject(); + String name = from.get("name").getAsString(); + if (name.equals("AuditProxy") || name.equals("ControlProxy")) + continue; + if (name.equals("SearchEngine") || name.equals("GateWay")) + continue; + JsonObject node = new JsonObject(); + node.add("name", from.get("name")); + node.add("doId", from.get("doId")); + node.addProperty("type", "Repo"); + graph.addNode(node); + graph.addEdge(node.get("doId").getAsString(), searchEngine.get("doId").getAsString()); + graph.addEdge(node.get("doId").getAsString(), gateway.get("doId").getAsString()); + } + graph.pruneEdges(); + return graph.ret; + } + + private static ContractResult executeContract(String contractName, String operation, JsonElement arg) { + Object jsobj = JavaScriptEntry.executeContract(contractName, operation, arg); + Object som = ScriptObjectMirror.wrap(jsobj, JavaScriptEntry.getEngineGlobal()); + JsonElement je = JSONTool.convertMirrorToJson(som); + LOGGER.info(je.toString()); + ContractResult contractResult = new Gson().fromJson(je, ContractResult.class); + return contractResult; + } + //{ + // "name":"小店区仓库","doId":"bdware.ss.ab/Repo1","type":"Repo","previousNode":["bdware.ss/Gateway1","bdware.ss/Gateway2","bdware.ss.ab/Repo2","bdware.ss.zz/SearchEngine"]} + // + + public static List getLevelTopology(int arg) { + List points = getCurrentTopology(); + TopologyGraph graph = new TopologyGraph(); + graph.addGraph(points); + if (arg > 0) { + ContractResult nextRouters = executeContract(RepoProxy.router, "listLRS", new JsonPrimitive("a")); + JsonArray routersArray = nextRouters.result.getAsJsonObject().get("data").getAsJsonArray(); + for (JsonElement je : routersArray) { + try { + String nextControlProxy = je.getAsJsonObject().get("doId").getAsString() + "/ControlProxy"; + ContractResult cr = executeContract(RepoProxy.router, "resolveTest", new JsonPrimitive(nextControlProxy)); + URI uri = null; + uri = new URI(JsonUtil.parseStringAsJsonObject(cr.result.getAsString()).get("address").getAsString()); + SmartContractHttpClient client = new SmartContractHttpClient(JavaScriptEntry.getKeyPair(), uri.getHost(), uri.getPort()); + String url = client.getExecuteUrl("ControlProxy", "getLevelTopology", (arg - 1) + ""); + LOGGER.info(url); + JsonObject result = client.executeContract("ControlProxy", "getLevelTopology", (arg - 1) + ""); + graph.addGraph(result.get("result").getAsJsonArray()); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + return graph.ret; + } +} diff --git a/backend/src/main/java/org/bdware/sc/controlproxy/TopologyGraph.java b/backend/src/main/java/org/bdware/sc/controlproxy/TopologyGraph.java new file mode 100644 index 0000000..f238d49 --- /dev/null +++ b/backend/src/main/java/org/bdware/sc/controlproxy/TopologyGraph.java @@ -0,0 +1,89 @@ +package org.bdware.sc.controlproxy; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +import java.util.*; + +public class TopologyGraph { + List ret = new ArrayList<>(); + Map doIdToNode = new HashMap<>(); + + public void addNode(JsonObject jsonObject) { + String doId = jsonObject.get("doId").getAsString(); + if (doIdToNode.containsKey(doId)) { + JsonObject already = doIdToNode.get(doId); + mergeNode(already, jsonObject); + } else { + ret.add(jsonObject); + doIdToNode.put(doId, jsonObject); + } + } + + public void addGraph(TopologyGraph g) { + addGraph(g.ret); + } + + public void addGraph(List points) { + for (JsonObject jo : points) { + addNode(jo); + } + } + + public void addGraph(JsonArray points) { + for (JsonElement jo : points) { + addNode(jo.getAsJsonObject()); + } + } + + private void mergeNode(JsonObject already, JsonObject jsonObject) { + for (String key : jsonObject.keySet()) { + if (!already.has(key)) + already.add(key, jsonObject.get(key)); + else { + if (key.equals("previousNode")) { + JsonArray current = already.get("previousNode").getAsJsonArray(); + current.addAll(jsonObject.get("previousNode").getAsJsonArray()); + } + } + } + } + + public void pruneEdges() { + for (JsonObject node : ret) { + if (node.has("previousNode")) { + JsonArray array = node.get("previousNode").getAsJsonArray(); + Set dedup = new HashSet<>(); + for (JsonElement je : array) { + dedup.add(je.getAsString()); + } + JsonArray deduped = new JsonArray(); + for (String str : dedup) { + deduped.add(str); + } + node.add("previousNode", deduped); + } + } + } + + public void addEdge(String from, String to) { + JsonObject fromJO = getOrCreateNode(from); + JsonObject toJo = getOrCreateNode(to); + if (!fromJO.has("previousNode")) { + fromJO.add("previousNode", new JsonArray()); + } + fromJO.get("previousNode").getAsJsonArray().add(to); + } + + private JsonObject getOrCreateNode(String from) { + if (!doIdToNode.containsKey(from)) { + JsonObject jo = new JsonObject(); + jo.addProperty("doId", from); + addNode(jo); + } + return doIdToNode.get(from); + } + + +} \ No newline at end of file diff --git a/backend/src/test/java/DeployTestNet.java b/backend/src/test/java/DeployTestNet.java new file mode 100644 index 0000000..c7e2642 --- /dev/null +++ b/backend/src/test/java/DeployTestNet.java @@ -0,0 +1,10 @@ +import org.junit.Test; +import org.bdware.ypkdeploy.HTTPTool; +public class DeployTestNet { + @Test + public void deployControlProxy() { + HTTPTool.batchRun("./deploy/CP_bdtest.json", true); + HTTPTool.batchRun("./deploy/CP_bdtest_eg.json", true); + HTTPTool.batchRun("./deploy/CP_bdtest_rs.json", true); + } +} diff --git a/backend/yjs/ControlProxy.yjs b/backend/yjs/ControlProxy.yjs index f111386..6b7c9ba 100755 --- a/backend/yjs/ControlProxy.yjs +++ b/backend/yjs/ControlProxy.yjs @@ -1,140 +1,192 @@ -import "repodetail.yjs" -import "search.yjs" -import "audit.yjs" -import "networking.yjs" -import "DAC.yjs" +import "repodetail.yjs"; +import "search.yjs"; +import "audit.yjs"; +import "networking.yjs"; +import "DAC.yjs"; +import "union.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" - }; +contract ControlProxy { + function convertArgToJson(arg) { + if (typeof(arg)=='string' && !arg.startsWith("{")) return arg; + if (typeof(arg)=='string') return JSON.parse(arg); + return arg; } - 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}; + 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); } - 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){ + function isString(arg) { + return typeof(arg)=='string'; + } + + export function getControlProxyConfig() { + return org.bdware.sc.controlproxy.RepoProxy.getConfig(); + } + + 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 + }; + } + +//网关的接口 + @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}; + ret = executeContract(Global.router, "listRepo", ""); + //ret=executeContract("Gateway","listLocalRepo",""); + //var list = ret.result + return ret.result; } - - 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总体情况概览 + //使用以下参数获取DO数量变化趋势 + // interval=1周/1月/1年。。 eventPrefix的数组里为"irp_register" + //使用以下参数获取操作数量统计 + // interavl= endTime-startTime, eventPrefix的数组里为"" + // 使用以下参数数字对象操作统计 + //eventPrefix为["doip","irp"] 已完成√ + // 使用以下参数获取doip操作统计 + //exentPrefix为["doip_create","doip_update","doip_delete","doip_retrieve","doip_hello","doip_list_operations","doip_search"] 已完成√ + // 使用以下参数获取irp操作统计 + //exentPrefix为["irp_create","irp_delete","irp_update","irp_batch_create","irp_resolution"] 已完成√ + // 使用以下参数获取doip、irp的成功率 + //exentPrefix为["irp_op_success","irp_op_failed"] + //exentPrefix为["doip_op_success","doip_op_failed"] + //======在全领监管->总体情况概览 + @Description("{\"doId\":\"86.20.100/repo4/bcrs\",\"startTime\":1644390000000, \"endTime\":1644404400000,\"interval\":3600000, \"eventPrefix\":[\"doip_retrieve\", \"doip_update\", \"doip_search\", \"doip_delete\"]}") + export function countRecordByDate(arg){ + arg=convertArgToJson(arg); + return executeContract("AutoAudit","countRecordByDate",arg).result; + } + + export function queryByHash(arg){ + arg=convertArgToJson(arg); + var ret = executeContract("AutoAudit","queryByHash",arg.hash).result; + if (typeof(ret)=='string'){ + var ret2={}; + ret2.code = 1; + ret2.msg = ret; + ret = ret2; + } else { + ret.code = 0; + } + return ret; + } + + export function queryByHashOriginal(arg){ + arg=convertArgToJson(arg); + return executeContract("AutoAudit","queryByHashOriginal",arg.hash).result; + } + - } \ No newline at end of file diff --git a/backend/yjs/main.yjs b/backend/yjs/main.yjs deleted file mode 100644 index d798434..0000000 --- a/backend/yjs/main.yjs +++ /dev/null @@ -1,12 +0,0 @@ - -oracle ContractExample { - function onCreate(){ - Global.owner = requester; - } - export function callHello(arg){ - return Hello.call()+requester; - } - export function getOwner(){ - return Global.owner; - } -} \ No newline at end of file diff --git a/backend/yjs/manifest.json b/backend/yjs/manifest.json index 9864a82..ec0a2c2 100755 --- a/backend/yjs/manifest.json +++ b/backend/yjs/manifest.json @@ -4,6 +4,6 @@ "insnLimit": 0, "buildTime": 1650245588814, "builder": "04da01345770b7e09d4774bf6c0395399b18814aa0b7b158f64b634b8f3d628d9964af6523835225af11e467271f4969d67bf90b32eaa09f517c79b2d1f9b8a926", - "startAtUnpack": true, + "startAtUnpack": false, "sourcePath": "04da01345770b7e09d4774bf6c0395399b18814aa0b7b158f64b634b8f3d628d9964af6523835225af11e467271f4969d67bf90b32eaa09f517c79b2d1f9b8a926/ControlProxy" } \ No newline at end of file diff --git a/backend/yjs/networking.yjs b/backend/yjs/networking.yjs index 03ba352..a78eac8 100755 --- a/backend/yjs/networking.yjs +++ b/backend/yjs/networking.yjs @@ -287,21 +287,16 @@ module networking{ } @ArgSchema({"!doId": "string","!address":"string"}) export function resolveDoId(arg){ - var ret=executeContract(Global.router,"resolveDoId",arg); - var obj = ret.result; - var obj1 = obj.data; - var obj2 = JSON.parse(obj1); - if (obj.result=="success" || obj.result == undefined) { - if (obj2.name != "NotFound") { - obj.result=undefined; - obj.code=0; - } else { - YancloudUtil.exceptionReturn({"msg":obj.data,"code":1}); - } + arg = convertArgToJson(arg); + var ret = executeContract(Global.router,"resolveTest",arg.doId); + var retObj = {}; + if (ret.status == "Success" && ret.result != undefined) { + retObj.data = ret.result; + retObj.code = 0; } else { - YancloudUtil.exceptionReturn({"msg":obj.data,"code":1}); + YancloudUtil.exceptionReturn({"msg":obj1,"code":1}); } - return obj; + return retObj; } } diff --git a/backend/yjs/repodetail.yjs b/backend/yjs/repodetail.yjs index ef361e4..e747ff1 100755 --- a/backend/yjs/repodetail.yjs +++ b/backend/yjs/repodetail.yjs @@ -1,37 +1,4 @@ module RepoDetail{ - - - export function getControlProxyConfig(){ - return org.bdware.sc.controlproxy.RepoProxy.getConfig(); - - } - //@wyq 通过DOIP请求 - export function getAuditRule(arg){ - // {"repoId":"xxx"} - var ret = []; - ret.push({"displayName":"原始数据存证","desc":"原始数据存证到指定数据库,哈希数据存证","type":2}); - ret.push({"displayName":"哈希数据存证","desc":"仅哈希数据存证","type":1}); - ret.push({"displayName":"不存证","desc":"不存证","type":0 }); - return ret; - } - //@wyq TODO TODO - // 这个通过DOIPUtil,去调用 - // DOIP的接口。 - @Description("{\"doId\":\"macjw.ab/repofile\"}"); - export function getDoAuditRule(arg){ - arg = convertArgToJson(arg); - if(arg.count==undefined) arg.count=10; - if(arg.offset==undefined) arg.offset=0; - return org.bdware.sc.controlproxy.RepoProxy.getDoAuditRule(arg); - } - //@wyq - export function setDoAuditRule(arg){ - ///arg={"doIdList":["dd","ddd.xx/xxx",...],"type":1} - arg = convertArgToJson(arg); - if(arg.count==undefined) arg.count=10; - if(arg.offset==undefined) arg.offset=0; - return {"msg":"success","code":0}; - } //宏伟 //如果有指定repo,那就是指定repo的DOlist。 //如果没指定repo,那就是全部的。 @@ -99,8 +66,6 @@ module RepoDetail{ //比如,查询总搜索次数,参数格式为:eventPrefix:["doip_search"] //查询调用统计,参数格式为eventPrefix:[""],然后interval/startTime/fromTime传对了就行。 //索引统计,暂时还没有。 - - export function getStaticIndex(arg){ arg = convertArgToJson(arg); if (arg.from==undefined) diff --git a/backend/yjs/search.yjs b/backend/yjs/search.yjs index 7718dbe..2c4fdf3 100755 --- a/backend/yjs/search.yjs +++ b/backend/yjs/search.yjs @@ -42,28 +42,7 @@ module SearchModule{ // "doId":"bdware.txte/Repo2","count":12} // ]}; } - //通过AuditProxy实现 @董瑞 需实现支持多标签索引的put接口。 - //======在全领监管->总体情况概览 - //使用以下参数获取DO数量变化趋势 - // interval=1周/1月/1年。。 eventPrefix的数组里为"irp_register" - //使用以下参数获取操作数量统计 - // interavl= endTime-startTime, eventPrefix的数组里为"" - // 使用以下参数数字对象操作统计 - //eventPrefix为["doip","irp"] 已完成√ - // 使用以下参数获取doip操作统计 - //exentPrefix为["doip_create","doip_update","doip_delete","doip_retrieve","doip_hello","doip_list_operations","doip_search"] 已完成√ - // 使用以下参数获取irp操作统计 - //exentPrefix为["irp_create","irp_delete","irp_update","irp_batch_create","irp_resolution"] 已完成√ - // 使用以下参数获取doip、irp的成功率 - //exentPrefix为["irp_op_success","irp_op_failed"] - //exentPrefix为["doip_op_success","doip_op_failed"] - //======在全领监管->总体情况概览 - @Description("{\"doId\":\"86.20.100/repo4/bcrs\",\"startTime\":1644390000000, \"endTime\":1644404400000,\"interval\":3600000, \"eventPrefix\":[\"doip_retrieve\", \"doip_update\", \"doip_search\", \"doip_delete\"]}") - export function countRecordByDate(arg){ - arg=convertArgToJson(arg); - return executeContract("AutoAudit","countRecordByDate",arg).result; - } - + export function testCount(arg){ return {"data":"key"}; } @@ -101,6 +80,7 @@ module SearchModule{ var res=executeContract("SearchEngine","searchByRange",arg); return res.result; } + //支持模糊查询、按创建时间查询。 //输入参数: //type:要查询的字段 @@ -127,14 +107,4 @@ module SearchModule{ // ); //return {"data":ret,"total":3}; } - export function queryByHash(arg){ - arg=convertArgToJson(arg); - return executeContract("AutoAudit","queryByHash",arg.hash).result; - } - - export function queryByHashOriginal(arg){ - arg=convertArgToJson(arg); - return executeContract("AutoAudit","queryByHashOriginal",arg.hash).result; - } - } \ No newline at end of file diff --git a/backend/yjs/union.yjs b/backend/yjs/union.yjs new file mode 100755 index 0000000..e40cdc9 --- /dev/null +++ b/backend/yjs/union.yjs @@ -0,0 +1,73 @@ +module unions { + @Descripton("无参数") + export function getUnionMembers(arg) { + if (!checkPermission(requester)) { + YancloudUtil.exceptionReturn({ + "msg":"no permission", "code":1 + }); + } + var ret = { + }; + ret.code = 0; + if (Global.unions==undefined){ + ret.data = []; + } else { + ret.data = Global.unions; + } + return ret; + } + export function resetUnionConfig() { + Global.unions = null; + } + + @Descripton("参数为,{\"date\": 1642467459759,\"name\": \"Repo1\",\"doId\": \"bdwaretest.loccall/Repo1\",\"version\": \"2.1\",\"address\": \"tcp://127.0.0.1:21042\",\"status\": \"已审核\",\"protocol\": \"DOIP\",\"pubKey\": \"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}") + @ArgSchema({ + "!unionName": "string", "!orgName":"string", "!email": "string", "!contact":"string" + }) + export function createUnion(arg) { + if (!checkPermission(requester)) { + YancloudUtil.exceptionReturn({ + "msg":"no permission", "code":1 + }); + } + Global.unions = []; + Global.unions.push({ + "name":"北大", "address":"ws://39.106.6.6:18010", "status":"在线", "contact":"网管1号", "email":"abc@pku.edu.cn" + }); + Global.unions.push({ + "name":"南大大", "address":"ws://39.106.6.9:18010", "status":"在线", "contact":"网管1号", "email":"abc@pku.edu.cn" + }); + return { + "code":0 + }; + } + export function getUnionConfig() { + if (!checkPermission(requester)) { + YancloudUtil.exceptionReturn({ + "msg":"no permission", "code":1 + }); + } + var ret = { + }; + ret.controlAddress = "ws://192.168.1.1:18000"; + ret.apiKey = "dafdsafdsa"; + ret.unionName = "高校联盟"; + return ret; + } + @ArgSchema({ + "!controlAddress": "string", "!apiKey": "string" + }) + export function joinUnion(arg) { + if (!checkPermission(requester)) { + YancloudUtil.exceptionReturn({ + "msg":"no permission", "code":1 + }); + } + var ret = { + }; + ret.controlAddress = "ws://192.168.1.1:18000"; + ret.apiKey = "dafdsafdsa"; + ret.unionName = "高校联盟"; + return ret; + } +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index f085821..ccebf68 100644 --- a/build.gradle +++ b/build.gradle @@ -2,8 +2,6 @@ plugins { id 'java' id 'idea' } -def currVersion = "0.8.8" -ext.projectIds = ['group': 'org.bdware.sc.controlproxy', 'version': currVersion] tasks.withType(JavaCompile) { options.compilerArgs << '-Xlint:none' @@ -15,10 +13,9 @@ repositories { } project(':backend') { - group = "org.bdware.sc.controlproxy" - version = projectIds.version repositories { - maven { url 'https://maven.aliyun.com/repository/public' } mavenLocal() + mavenCentral() + maven { url 'https://maven.aliyun.com/repository/public' } } }