mirror of
https://gitee.com/BDWare/agent-backend
synced 2025-01-10 01:44:14 +00:00
refactor: update ContractManagerFrameHandler
use JsonUtil to optimize ContractManagerFrameHandler.channelRead0
This commit is contained in:
parent
bb9e5f9b4f
commit
40a638be5b
@ -164,7 +164,7 @@ public class CMActions implements OnHashCallback {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cReq.setAction(jo.get("action").getAsString());
|
cReq.setAction(jo.get("action").getAsString());
|
||||||
cReq.setArg(jo.get("arg").getAsString());
|
cReq.setArg(jo.get("arg"));
|
||||||
if (cReq.withEvaluatesAnalysis) {
|
if (cReq.withEvaluatesAnalysis) {
|
||||||
cReq.setValue(jo.get("hasValue").getAsLong());
|
cReq.setValue(jo.get("hasValue").getAsLong());
|
||||||
}
|
}
|
||||||
@ -1391,6 +1391,59 @@ public class CMActions implements OnHashCallback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Action(userPermission = 1L << 26, async = true, httpAccess = false)
|
||||||
|
public void killAllContract(JsonObject args, ResultCallback resultCallback) {
|
||||||
|
if (args.has("verifiedPubKey")) {
|
||||||
|
if (ContractManager.checkNodeManager(args.get(("verifiedPubKey")).getAsString())) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("Kill:");
|
||||||
|
try {
|
||||||
|
// TODO too many opend files
|
||||||
|
ProcessBuilder builder = new ProcessBuilder("ps", "-ef");
|
||||||
|
Process process = builder.start();
|
||||||
|
Scanner sc = new Scanner(process.getInputStream());
|
||||||
|
while (sc.hasNextLine()) {
|
||||||
|
String line = sc.nextLine();
|
||||||
|
if (line.contains("java")
|
||||||
|
&& (line.contains("ContractProcess") || line.contains("yjs.jar"))) {
|
||||||
|
LOGGER.debug(line);
|
||||||
|
{
|
||||||
|
Scanner sc2 =
|
||||||
|
new Scanner(new ByteArrayInputStream(line.getBytes()));
|
||||||
|
String pid = null;
|
||||||
|
|
||||||
|
if (sc2.hasNext()) {
|
||||||
|
sc2.next();
|
||||||
|
if (sc2.hasNextInt()) pid = sc2.nextInt() + "";
|
||||||
|
}
|
||||||
|
sc2.close();
|
||||||
|
|
||||||
|
if (pid != null) {
|
||||||
|
ProcessBuilder subProcess =
|
||||||
|
new ProcessBuilder("kill", "-9", pid);
|
||||||
|
sb.append(pid);
|
||||||
|
sb.append(",");
|
||||||
|
subProcess.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sc.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
ExecutionManager.instance.updateLocalContractToNodeCenter();
|
||||||
|
ReplyUtil.simpleReply(resultCallback, "onKillAllContract", sb.toString());
|
||||||
|
manager.stopAllContracts();
|
||||||
|
} else {
|
||||||
|
manager.stopAllContractsWithOwner(args.get(("verifiedPubKey")).getAsString());
|
||||||
|
ReplyUtil.simpleReply(resultCallback, "onKillAllContract", "Success");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ReplyUtil.simpleReply(resultCallback, "onKillAllContract", "Failed: Illegal user");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// @Action(userPermission = 1L << 26, async = true)
|
// @Action(userPermission = 1L << 26, async = true)
|
||||||
// public void queryContractInstanceInfoByDOI(JsonObject args, ResultCallback resultCallback)
|
// public void queryContractInstanceInfoByDOI(JsonObject args, ResultCallback resultCallback)
|
||||||
// {
|
// {
|
||||||
@ -1482,59 +1535,6 @@ public class CMActions implements OnHashCallback {
|
|||||||
* resultCallback.onResult(gson.toJson(r)); }
|
* resultCallback.onResult(gson.toJson(r)); }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Action(userPermission = 1L << 26, async = true, httpAccess = false)
|
|
||||||
public void killAllContract(JsonObject args, ResultCallback resultCallback) {
|
|
||||||
if (args.has("verifiedPubKey")) {
|
|
||||||
if (ContractManager.checkNodeManager(args.get(("verifiedPubKey")).getAsString())) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("Kill:");
|
|
||||||
try {
|
|
||||||
// TODO too many opend files
|
|
||||||
ProcessBuilder builder = new ProcessBuilder("ps", "-ef");
|
|
||||||
Process process = builder.start();
|
|
||||||
Scanner sc = new Scanner(process.getInputStream());
|
|
||||||
while (sc.hasNextLine()) {
|
|
||||||
String line = sc.nextLine();
|
|
||||||
if (line.contains("java")
|
|
||||||
&& (line.contains("ContractProcess") || line.contains("yjs.jar"))) {
|
|
||||||
LOGGER.debug(line);
|
|
||||||
{
|
|
||||||
Scanner sc2 =
|
|
||||||
new Scanner(new ByteArrayInputStream(line.getBytes()));
|
|
||||||
String pid = null;
|
|
||||||
|
|
||||||
if (sc2.hasNext()) {
|
|
||||||
sc2.next();
|
|
||||||
if (sc2.hasNextInt()) pid = sc2.nextInt() + "";
|
|
||||||
}
|
|
||||||
sc2.close();
|
|
||||||
|
|
||||||
if (pid != null) {
|
|
||||||
ProcessBuilder subProcess =
|
|
||||||
new ProcessBuilder("kill", "-9", pid);
|
|
||||||
sb.append(pid);
|
|
||||||
sb.append(",");
|
|
||||||
subProcess.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sc.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
ExecutionManager.instance.updateLocalContractToNodeCenter();
|
|
||||||
ReplyUtil.simpleReply(resultCallback, "onKillAllContract", sb.toString());
|
|
||||||
manager.stopAllContracts();
|
|
||||||
} else {
|
|
||||||
manager.stopAllContractsWithOwner(args.get(("verifiedPubKey")).getAsString());
|
|
||||||
ReplyUtil.simpleReply(resultCallback, "onKillAllContract", "Success");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ReplyUtil.simpleReply(resultCallback, "onKillAllContract", "Failed: Illegal user");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Action(userPermission = 1L << 26, async = true, httpAccess = false)
|
@Action(userPermission = 1L << 26, async = true, httpAccess = false)
|
||||||
public void setPermission(JsonObject json, ResultCallback resultCallback) {
|
public void setPermission(JsonObject json, ResultCallback resultCallback) {
|
||||||
String closePermission = json.get("closePer").getAsString();
|
String closePermission = json.get("closePer").getAsString();
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package org.bdware.server.ws;
|
package org.bdware.server.ws;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||||
@ -138,7 +137,7 @@ public class ContractManagerFrameHandler extends SimpleChannelInboundHandler<Web
|
|||||||
// logger.debug("[WebSocket receive] " + request);
|
// logger.debug("[WebSocket receive] " + request);
|
||||||
JsonObject map;
|
JsonObject map;
|
||||||
try {
|
try {
|
||||||
map = JsonParser.parseString(request).getAsJsonObject();
|
map = JsonUtil.parseStringAsJsonObject(request);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Response response = new Response();
|
Response response = new Response();
|
||||||
response.action = "onException";
|
response.action = "onException";
|
||||||
@ -165,7 +164,7 @@ public class ContractManagerFrameHandler extends SimpleChannelInboundHandler<Web
|
|||||||
dataCache.append(map.get("data").getAsString());
|
dataCache.append(map.get("data").getAsString());
|
||||||
String dataStr = dataCache.toString();
|
String dataStr = dataCache.toString();
|
||||||
LOGGER.debug("[WebSocketFrame] DataString:" + dataStr);
|
LOGGER.debug("[WebSocketFrame] DataString:" + dataStr);
|
||||||
map = JsonParser.parseString(dataStr).getAsJsonObject();
|
map = JsonUtil.parseStringAsJsonObject(dataStr);
|
||||||
dataCache = new StringBuilder();
|
dataCache = new StringBuilder();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user