mirror of
https://gitee.com/BDWare/router-backend
synced 2025-01-26 01:34:04 +00:00
feat: add sendProject progress
This commit is contained in:
parent
537ecbfc6c
commit
e94dfe3998
@ -48,7 +48,7 @@ public class DistributeCallback extends ResultCallback {
|
|||||||
if (ID.equals(sponsorPubkey))
|
if (ID.equals(sponsorPubkey))
|
||||||
continue;
|
continue;
|
||||||
CMNode node = NodeCenterActions.nodeInfos.get(ID);
|
CMNode node = NodeCenterActions.nodeInfos.get(ID);
|
||||||
node.connection.sendProject(filePath, isPrivate, pubKey, this);
|
node.connection.sendProject(filePath, isPrivate, pubKey, node.ipPort, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ public class DistributeCallback extends ResultCallback {
|
|||||||
res.onResult(JsonUtil.toJson(map));
|
res.onResult(JsonUtil.toJson(map));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDistribute(String progress) {
|
public void onDistribute(String progress, String nodeIP) {
|
||||||
Map<String, String> ret2 = new HashMap<>();
|
Map<String, String> ret2 = new HashMap<>();
|
||||||
ret2.put("action", "onDistributeContract");
|
ret2.put("action", "onDistributeContract");
|
||||||
ret2.put(
|
ret2.put(
|
||||||
@ -77,27 +77,25 @@ public class DistributeCallback extends ResultCallback {
|
|||||||
if (progress.equals("100.00")) index++;
|
if (progress.equals("100.00")) index++;
|
||||||
|
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
map.put("action", "onDistribute");
|
map.put("action", "onDistributeYPK");
|
||||||
map.put("distributeID", distributeID);
|
map.put("responseID", distributeID);
|
||||||
map.put("content", JsonUtil.toJson(ret2));
|
map.put("content", JsonUtil.toJson(ret2));
|
||||||
|
map.put("nodeIP", nodeIP);
|
||||||
|
map.put("progress", progress);
|
||||||
res.onResult(JsonUtil.toJson(map));
|
res.onResult(JsonUtil.toJson(map));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onReceive(Map<String, String> map) {
|
public void onReceive(Map<String, String> map) {
|
||||||
LOGGER.debug("[DistributeCallback] onReceive : position----9");
|
LOGGER.debug("[DistributeCallback] onReceive : position----9");
|
||||||
String progress = map.get("progress");
|
String progress = map.get("progress");
|
||||||
|
String nodeIP = map.get("ipPort");
|
||||||
if (progress.equals("100")) {
|
if (progress.equals("100")) {
|
||||||
Map<String, String> args = new HashMap<>();
|
Map<String, String> args = new HashMap<>();
|
||||||
|
|
||||||
args.put("fileName", fileName);
|
args.put("fileName", fileName);
|
||||||
args.put("pubKey", pubKey);
|
args.put("pubKey", pubKey);
|
||||||
args.put("signature", signature);
|
args.put("signature", signature);
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
LOGGER.debug(count + "个节点已收完成" + " 总共有" + nodes.size() + " 个节点");
|
LOGGER.debug(count + "个节点已收完成" + " 总共有" + nodes.size() + " 个节点");
|
||||||
|
|
||||||
if (count == nodes.size()) {
|
if (count == nodes.size()) {
|
||||||
// res返回给前端,合约分发完成
|
// res返回给前端,合约分发完成
|
||||||
Map<String, String> ret2 = new HashMap<>();
|
Map<String, String> ret2 = new HashMap<>();
|
||||||
@ -105,8 +103,9 @@ public class DistributeCallback extends ResultCallback {
|
|||||||
ret2.put("progress", "100%");
|
ret2.put("progress", "100%");
|
||||||
Map<String, String> map_send = new HashMap<>();
|
Map<String, String> map_send = new HashMap<>();
|
||||||
map_send.put("action", "onDistribute");
|
map_send.put("action", "onDistribute");
|
||||||
|
map_send.put("responseID", distributeID);
|
||||||
map_send.put("over", "true");
|
map_send.put("over", "true");
|
||||||
map_send.put("distributeID", distributeID);
|
map_send.put("nodeIP", nodeIP);
|
||||||
map_send.put("content", JsonUtil.toJson(ret2));
|
map_send.put("content", JsonUtil.toJson(ret2));
|
||||||
res.onResult(JsonUtil.toJson(map_send));
|
res.onResult(JsonUtil.toJson(map_send));
|
||||||
//NC delete file
|
//NC delete file
|
||||||
@ -136,7 +135,7 @@ public class DistributeCallback extends ResultCallback {
|
|||||||
distributeContractProject(map.get("receiveFileName"), map.get("isPrivate"));
|
distributeContractProject(map.get("receiveFileName"), map.get("isPrivate"));
|
||||||
break;
|
break;
|
||||||
case "onDistribute":
|
case "onDistribute":
|
||||||
onDistribute(map.get("progress"));
|
onDistribute(map.get("progress"), map.get("nodeIP"));
|
||||||
break;
|
break;
|
||||||
case "onReceive":
|
case "onReceive":
|
||||||
onReceive(map);
|
onReceive(map);
|
||||||
|
@ -176,6 +176,11 @@ public class NodeCenterActions {
|
|||||||
return node.peerID;
|
return node.peerID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getIpPortByNodeId(String id) {
|
||||||
|
CMNode node = nodeInfos.get(id);
|
||||||
|
return node.ipPort;
|
||||||
|
}
|
||||||
|
|
||||||
@Action(httpAccess = true)
|
@Action(httpAccess = true)
|
||||||
public void downloadUUID(JsonObject args, ResultCallback resultCallback) {
|
public void downloadUUID(JsonObject args, ResultCallback resultCallback) {
|
||||||
String pubKey = args.get("pubKey").getAsString();
|
String pubKey = args.get("pubKey").getAsString();
|
||||||
@ -973,7 +978,7 @@ public class NodeCenterActions {
|
|||||||
}
|
}
|
||||||
if (args.has("operation")) {
|
if (args.has("operation")) {
|
||||||
cr.setAction(args.get("operation").getAsString());
|
cr.setAction(args.get("operation").getAsString());
|
||||||
cr.setArg(args.get("arg"));
|
cr.setArg(args.get("arg").getAsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
final JsonObject ret = new JsonObject();
|
final JsonObject ret = new JsonObject();
|
||||||
@ -1109,7 +1114,7 @@ public class NodeCenterActions {
|
|||||||
// in its
|
// in its
|
||||||
// onResult
|
// onResult
|
||||||
public void sendProject(
|
public void sendProject(
|
||||||
String filePath, String isPrivate, String pubKey, ResultCallback result) {
|
String filePath, String isPrivate, String pubKey, String nodeIP, ResultCallback result) {
|
||||||
LOGGER.debug("sendProject : position----6" + filePath);
|
LOGGER.debug("sendProject : position----6" + filePath);
|
||||||
|
|
||||||
File project = new File(filePath);
|
File project = new File(filePath);
|
||||||
@ -1135,7 +1140,9 @@ public class NodeCenterActions {
|
|||||||
FileInputStream fin = new FileInputStream(project);
|
FileInputStream fin = new FileInputStream(project);
|
||||||
byte[] buff = new byte[30 * 1024];
|
byte[] buff = new byte[30 * 1024];
|
||||||
long count = 0;
|
long count = 0;
|
||||||
|
long preCount = 0;
|
||||||
long total = project.length();
|
long total = project.length();
|
||||||
|
long step = total / 10;
|
||||||
LOGGER.debug("ypk = " + total);
|
LOGGER.debug("ypk = " + total);
|
||||||
|
|
||||||
for (int len = 0; (len = (fin.read(buff))) > 0; ) {
|
for (int len = 0; (len = (fin.read(buff))) > 0; ) {
|
||||||
@ -1145,14 +1152,15 @@ public class NodeCenterActions {
|
|||||||
count += len;
|
count += len;
|
||||||
controller.sendMsg(JsonUtil.toJson(req));
|
controller.sendMsg(JsonUtil.toJson(req));
|
||||||
req.put("isAppend", "true");
|
req.put("isAppend", "true");
|
||||||
|
if (count - preCount > step || count == total) {
|
||||||
Map<String, String> req2 = new HashMap<>();
|
preCount = count;
|
||||||
req2.put("operation", "onDistribute");
|
Map<String, String> req2 = new HashMap<>();
|
||||||
req2.put("requestID", requestID);
|
req2.put("operation", "onDistribute");
|
||||||
req2.put("progress", String.format("%.2f", count * 100F / total));
|
req2.put("requestID", requestID);
|
||||||
sync.wakeUp(requestID, JsonUtil.toJson(req2));
|
req2.put("progress", String.format("%.2f", count * 100F / total));
|
||||||
|
req2.put("nodeIP", nodeIP);
|
||||||
Thread.sleep(300);
|
sync.wakeUp(requestID, JsonUtil.toJson(req2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fin.close();
|
fin.close();
|
||||||
|
|
||||||
@ -1162,7 +1170,7 @@ public class NodeCenterActions {
|
|||||||
|
|
||||||
// delete ypk_NC
|
// delete ypk_NC
|
||||||
LOGGER.debug("[NodeCenterActions] send project finish.");
|
LOGGER.debug("[NodeCenterActions] send project finish.");
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1176,6 +1184,7 @@ public class NodeCenterActions {
|
|||||||
Map<String, String> req = new HashMap<>();
|
Map<String, String> req = new HashMap<>();
|
||||||
req.put("operation", "onReceive");
|
req.put("operation", "onReceive");
|
||||||
req.put("peerID", NodeCenterActions.getPeerIdByNodeId(args.get("nodeID").getAsString()));
|
req.put("peerID", NodeCenterActions.getPeerIdByNodeId(args.get("nodeID").getAsString()));
|
||||||
|
req.put("ipPort", NodeCenterActions.getIpPortByNodeId(args.get("nodeID").getAsString()));
|
||||||
req.put("progress", args.get("progress").getAsString());
|
req.put("progress", args.get("progress").getAsString());
|
||||||
req.put("requestID", args.get("requestID").getAsString());
|
req.put("requestID", args.get("requestID").getAsString());
|
||||||
String requestID = args.get("requestID").getAsString();
|
String requestID = args.get("requestID").getAsString();
|
||||||
|
@ -9,6 +9,7 @@ import org.bdware.sc.conn.ResultCallback;
|
|||||||
import org.bdware.sc.db.KeyValueDBUtil;
|
import org.bdware.sc.db.KeyValueDBUtil;
|
||||||
import org.bdware.sc.util.JsonUtil;
|
import org.bdware.sc.util.JsonUtil;
|
||||||
import org.bdware.server.action.Action;
|
import org.bdware.server.action.Action;
|
||||||
|
import org.bdware.server.action.DistributeCallback;
|
||||||
import org.zz.gmhelper.SM2Util;
|
import org.zz.gmhelper.SM2Util;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -242,11 +243,11 @@ public class UnitActions {
|
|||||||
|
|
||||||
@Action(async = true)
|
@Action(async = true)
|
||||||
public void distributeYPK(JsonObject args, final ResultCallback rc) {
|
public void distributeYPK(JsonObject args, final ResultCallback rc) {
|
||||||
LOGGER.debug("[UnitActions] distributeYPK : -----------position1");
|
LOGGER.info("[UnitActions] distributeYPK : -----------position1");
|
||||||
|
|
||||||
String pubKey = args.get("pubKey").getAsString();
|
String pubKey = args.get("pubKey").getAsString();
|
||||||
String signature = args.get("signature").getAsString();
|
String signature = args.get("signature").getAsString();
|
||||||
String projectName = args.get("projectName").getAsString();
|
String projectName = args.get("projectName").getAsString();
|
||||||
|
String requestID = args.get("requestID").getAsString();
|
||||||
String[] strs = args.get("nodeIDs").getAsString().split(",");
|
String[] strs = args.get("nodeIDs").getAsString().split(",");
|
||||||
Set<String> nodePubKeys = new HashSet<>(); // nodes' pubkey
|
Set<String> nodePubKeys = new HashSet<>(); // nodes' pubkey
|
||||||
for (String str : strs) {
|
for (String str : strs) {
|
||||||
@ -256,33 +257,38 @@ public class UnitActions {
|
|||||||
for (CMNode node : NodeCenterActions.nodeInfos.values()) {
|
for (CMNode node : NodeCenterActions.nodeInfos.values()) {
|
||||||
if (nodePubKeys.contains(node.pubKey)) {
|
if (nodePubKeys.contains(node.pubKey)) {
|
||||||
nodes.put(node.pubKey, node.nodeName);
|
nodes.put(node.pubKey, node.nodeName);
|
||||||
LOGGER.debug("nodes add " + node.pubKey + " " + node.nodeName);
|
LOGGER.info("nodes add " + node.pubKey + " " + node.nodeName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (nodes.isEmpty()) {
|
||||||
|
simpleReply(rc, "onDistributeYPK", "empty nodes");
|
||||||
|
}
|
||||||
|
|
||||||
boolean result =
|
boolean result =
|
||||||
SM2Util.plainStrVerify(
|
SM2Util.plainStrVerify(
|
||||||
pubKey, "DistributeYPK|" + projectName + "|" + pubKey, signature);
|
pubKey, "DistributeYPK|" + projectName + "|" + pubKey, signature);
|
||||||
|
LOGGER.info("[UnitAcitons] 验签:" + result + " -> projectName:" + projectName);
|
||||||
|
|
||||||
LOGGER.debug("[UnitAcitons] 验签:" + result + " -> projectName:" + projectName);
|
String ypkType = projectName.split("_")[0];
|
||||||
|
String ypkPath = "./NodeCenterDB/NC_YPKs/" + ypkType;
|
||||||
String ypkPath = "./NodeCenterDB/NC_YPKs/";
|
|
||||||
File dir = new File(ypkPath);
|
File dir = new File(ypkPath);
|
||||||
if (!dir.exists()) {
|
if (!dir.exists()) {
|
||||||
dir.mkdirs();
|
dir.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
String filePath = new File(dir, projectName).getAbsolutePath();
|
String filePath = new File(dir, projectName).getAbsolutePath();
|
||||||
File f = new File(filePath);
|
File f = new File(filePath);
|
||||||
String fileName = null;
|
String fileName = null;
|
||||||
fileName = f.getName();
|
fileName = f.getName();
|
||||||
LOGGER.debug("[UnitActions] distributeYPK : fileName=" + fileName);
|
LOGGER.info("[UnitActions] distributeYPK : fileName=" + fileName);
|
||||||
LOGGER.debug("[UnitActions] nodeNames: " + JsonUtil.toJson(nodes));
|
LOGGER.info("[UnitActions] nodeNames: " + JsonUtil.toJson(nodes));
|
||||||
|
|
||||||
String isPrivate = "true";
|
String isPrivate = "true";
|
||||||
|
DistributeCallback dcb = new DistributeCallback(requestID, "", nodes, rc, signature, "s");
|
||||||
|
NodeCenterActions.sync.sleepWithTimeout(requestID, dcb, 60);
|
||||||
|
|
||||||
for (String ID : nodes.keySet()) {
|
for (String ID : nodes.keySet()) {
|
||||||
CMNode node = NodeCenterActions.nodeInfos.get(ID);
|
CMNode node = NodeCenterActions.nodeInfos.get(ID);
|
||||||
node.connection.sendProject(filePath, isPrivate, pubKey, rc);
|
node.connection.sendProject(filePath, isPrivate, pubKey, node.ipPort, dcb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,8 +7,12 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public class WordSegmentationTest {
|
public class WordSegmentationTest {
|
||||||
@Test
|
@Test
|
||||||
public void go() throws IOException {
|
public void go() {
|
||||||
MetaIndexAction i = new MetaIndexAction();
|
MetaIndexAction i = new MetaIndexAction();
|
||||||
i.segmentWord(null, null);
|
try {
|
||||||
|
i.segmentWord(null, null);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user