fix: fix bugs

fix bugs in cmconfig.json.template; fix bugs of JsonUtil's usage in TCPClientFrameHandler; update usage of JsonUtil
This commit is contained in:
Frank.R.Wu 2021-11-17 14:42:47 +08:00
parent 8c86d4e767
commit 5c19c1570d
9 changed files with 25 additions and 26 deletions

View File

@ -11,9 +11,9 @@
"withBdledgerClient": "", "withBdledgerClient": "",
"enableEventPersistence": false, "enableEventPersistence": false,
"enableSsl": "./ssl/chained.pem:./ssl/domain.pem", "enableSsl": "./ssl/chained.pem:./ssl/domain.pem",
"textFileSuffixes": ".yjs,.json,.txt,.css,.js,.html,.md,.conf,.csv" "textFileSuffixes": ".yjs,.json,.txt,.css,.js,.html,.md,.conf,.csv",
"wsPluginActions": "org.bdware.metering.MeteringAction" "wsPluginActions": "org.bdware.metering.MeteringAction",
"clientToAgentPlugins": "" "clientToAgentPlugins": "",
"clientToClusterPlugins": "" "clientToClusterPlugins": "",
"tcpPlugins": "" "tcpPlugins": ""
} }

View File

@ -34,9 +34,9 @@ import java.util.*;
public class CMActions implements OnHashCallback { public class CMActions implements OnHashCallback {
private static final String PARAM_ACTION = "action"; private static final String PARAM_ACTION = "action";
private static final JsonObject MISSING_ARGUMENT = JsonUtil.parseString("{\"action\":\"onExecuteResult\",\"executeTime\":-1," private static final JsonObject MISSING_ARGUMENT = JsonUtil.parseStringAsJsonObject("{\"action\":\"onExecuteResult\",\"executeTime\":-1,"
+ "\"status\":\"Error\",\"result\":\"missing arguments\"}"); + "\"status\":\"Error\",\"result\":\"missing arguments\"}");
private static final JsonObject INVALID_DOI = JsonUtil.parseString( private static final JsonObject INVALID_DOI = JsonUtil.parseStringAsJsonObject(
"{\"action\":\"onExecuteResult\",\"executeTime\":-1," "{\"action\":\"onExecuteResult\",\"executeTime\":-1,"
+ "\"status\":\"Error\",\"result\":\"invalid contract doi\"}"); + "\"status\":\"Error\",\"result\":\"invalid contract doi\"}");
private static final Logger LOGGER = LogManager.getLogger(CMActions.class); private static final Logger LOGGER = LogManager.getLogger(CMActions.class);
@ -247,7 +247,7 @@ public class CMActions implements OnHashCallback {
} }
// JsonObject jo = // JsonObject jo =
// JsonParser.parseString(args.get("arg").getAsString()).getAsJsonObject(); // JsonParser.parseStringAsJsonObject(args.get("arg").getAsString()).getAsJsonObject();
// if (!jo.has("action")) { // if (!jo.has("action")) {
// resultCallback.onResult(MISSING_ARGUMENT); // resultCallback.onResult(MISSING_ARGUMENT);
// return; // return;
@ -475,7 +475,7 @@ public class CMActions implements OnHashCallback {
String data = "failed"; String data = "failed";
String contractID = ""; String contractID = "";
String operation = ""; String operation = "";
//JsonElement mask = JsonParser.parseString(""); //JsonElement mask = JsonParser.parseStringAsJsonObject("");
if (args.has("contractID") && args.has("operation") && args.has("arg")) { if (args.has("contractID") && args.has("operation") && args.has("arg")) {
contractID = args.get("contractID").getAsString(); contractID = args.get("contractID").getAsString();
System.out.println(contractID); System.out.println(contractID);
@ -1852,7 +1852,7 @@ public class CMActions implements OnHashCallback {
LOGGER.debug("startContractConfig"); LOGGER.debug("startContractConfig");
// TODO private contract // TODO private contract
// if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) { // if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) {
// args.add("pubkey", JsonParser.parseString(handler.getPubKey())); // args.add("pubkey", JsonParser.parseStringAsJsonObject(handler.getPubKey()));
// } // }
boolean type = args.get("type").getAsString().equalsIgnoreCase("TCP"); boolean type = args.get("type").getAsString().equalsIgnoreCase("TCP");
String contract = args.get("contractName").getAsString(); String contract = args.get("contractName").getAsString();

View File

@ -1607,7 +1607,7 @@ public class FileActions {
ret.put("ypk", new File(ypkPath).getName()); ret.put("ypk", new File(ypkPath).getName());
ret.put( ret.put(
"permissions", "permissions",
JsonUtil.parseString(CMActions.manager.parseYpkPermissions(ypkPath))); JsonUtil.parseStringAsJsonObject(CMActions.manager.parseYpkPermissions(ypkPath)));
} catch (Exception e) { } catch (Exception e) {
ByteArrayOutputStream bo = new ByteArrayOutputStream(); ByteArrayOutputStream bo = new ByteArrayOutputStream();
e.printStackTrace(new PrintStream(bo)); e.printStackTrace(new PrintStream(bo));

View File

@ -175,7 +175,7 @@ public class MasterWSAction {
requestConnect.put("connectAll", true); requestConnect.put("connectAll", true);
} }
NetworkManager.instance.sendToNodeCenter(JsonUtil.toJson(requestConnect)); // 向NC发 NetworkManager.instance.sendToNodeCenter(JsonUtil.toJson(requestConnect)); // 向NC发
LOGGER.debug(JsonUtil.toJson(requestConnect)); LOGGER.debug(JsonUtil.toPrettyJson(requestConnect));
boolean isSuccess = waitForConnection(nodeNames); boolean isSuccess = waitForConnection(nodeNames);
if (!isSuccess) { if (!isSuccess) {
return; return;

View File

@ -173,7 +173,7 @@ public class TemporyTestAction {
c.setScript(args.get("script").getAsString()); c.setScript(args.get("script").getAsString());
c.setOwner(args.get("owner").getAsString()); c.setOwner(args.get("owner").getAsString());
ContractManager.instance.allocateKeyIfNotExists(c); ContractManager.instance.allocateKeyIfNotExists(c);
JsonObject jo = JsonUtil.parseObject(c); JsonObject jo = JsonUtil.parseObjectAsJsonObject(c);
jo.addProperty("action", "onAllocateKeyPair"); jo.addProperty("action", "onAllocateKeyPair");
resultCallback.onResult(jo.toString()); resultCallback.onResult(jo.toString());
} }

View File

@ -203,18 +203,17 @@ public class MasterClientTCPAction {
} }
public void run1() { public void run1() {
// logger.info( LOGGER.debug(
// "f " String.format(
// + new "f %s",
// SimpleDateFormat("yyyy-MM-dd.HH:mm:ss") new SimpleDateFormat("yyyy-MM-dd.HH:mm:ss")
// .format(System.currentTimeMillis())));
// .format(System.currentTimeMillis()));
Map<String, String> ping = new HashMap<>(); Map<String, String> ping = new HashMap<>();
ping.put("action", "masterPing"); ping.put("action", "masterPing");
handler.sendMsg(JsonUtil.toJson(ping)); handler.sendMsg(JsonUtil.toJson(ping));
} }
}; };
if (checkAliveTask == null) if (null == checkAliveTask)
checkAliveTask = checkAliveTask =
new TimerTask() { new TimerTask() {
@Override @Override

View File

@ -112,7 +112,7 @@ public class TCPClientFrameHandler extends SimpleChannelInboundHandler<Object> {
ByteBuf bb = (ByteBuf) frame; ByteBuf bb = (ByteBuf) frame;
JsonObject arg; JsonObject arg;
try { try {
arg = JsonUtil.parseObject(new InputStreamReader(new ByteBufInputStream(bb))); arg = JsonUtil.parseReaderAsJsonObject(new InputStreamReader(new ByteBufInputStream(bb)));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
Response response = new Response(); Response response = new Response();
@ -180,10 +180,10 @@ public class TCPClientFrameHandler extends SimpleChannelInboundHandler<Object> {
} }
if (isOpen()) { if (isOpen()) {
try { try {
JsonObject jo = JsonUtil.parseObject(json); JsonObject jo = JsonUtil.parseStringAsJsonObject(json);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
System.out.println("============[MasterClientFrameHandler]JsonParse Error:" + json); LOGGER.warn("JsonParse Error: " + e.getMessage() + "\n\t" + json);
} }
ByteBuf buf = Unpooled.wrappedBuffer(json.getBytes()); ByteBuf buf = Unpooled.wrappedBuffer(json.getBytes());
ctx.channel().writeAndFlush(buf); ctx.channel().writeAndFlush(buf);

View File

@ -78,7 +78,7 @@ public class MasterProxy implements MasterStub {
new ResultCallback() { new ResultCallback() {
@Override @Override
public void onResult(String ret) { public void onResult(String ret) {
JsonObject result = JsonUtil.parseString(ret); JsonObject result = JsonUtil.parseStringAsJsonObject(ret);
ContractManager.instance.extractEventsFromContractResult( ContractManager.instance.extractEventsFromContractResult(
null, result, client, request, start); null, result, client, request, start);
LOGGER.debug( LOGGER.debug(
@ -105,7 +105,7 @@ public class MasterProxy implements MasterStub {
new ContractResult( new ContractResult(
ContractResult.Status.Error, ContractResult.Status.Error,
new JsonPrimitive("canceled because of queue too long")); new JsonPrimitive("canceled because of queue too long"));
cb.onResult(JsonUtil.parseObject(cr)); cb.onResult(JsonUtil.parseObjectAsJsonObject(cr));
CongestionControl.masterProxyLoad.decrementAndGet(); CongestionControl.masterProxyLoad.decrementAndGet();
return; return;
} }
@ -114,7 +114,7 @@ public class MasterProxy implements MasterStub {
new ResultCallback() { new ResultCallback() {
@Override @Override
public void onResult(String str) { public void onResult(String str) {
cb.onResult(JsonUtil.parseString(str)); cb.onResult(JsonUtil.parseStringAsJsonObject(str));
CongestionControl.masterProxyLoad.decrementAndGet(); CongestionControl.masterProxyLoad.decrementAndGet();
} }
}); });

View File

@ -81,7 +81,7 @@ public class CommunicationManager extends BaseFunctionManager {
} }
public void handle(String str, String sender) { public void handle(String str, String sender) {
// JsonObject jsonObject = (JsonObject) JsonParser.parseString(str); // JsonObject jsonObject = (JsonObject) JsonParser.parseStringAsJsonObject(str);
// if(jsonObject.has("action")) { // if(jsonObject.has("action")) {
// String action = jsonObject.get("action").getAsString(); // String action = jsonObject.get("action").getAsString();
// switch (action) { // switch (action) {