mirror of
https://gitee.com/BDWare/agent-backend
synced 2025-01-10 09:54:11 +00:00
Configure plug-in
This commit is contained in:
parent
db15d105be
commit
e1e0435589
5
cmconfig.readme.md
Normal file
5
cmconfig.readme.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# 配置项
|
||||||
|
## wsPluginActions: WS端,包括contractManagerFrameHandler和CMHttpHandler
|
||||||
|
## clientToAgentPlugins: client -> cluster 包括MasterClientFrameHandler
|
||||||
|
## clientToClusterPlugins:[], client -> NodeCenterClientHandler
|
||||||
|
## tcpPlugins:tcp 包括TcpserverFrameHandler
|
@ -35,6 +35,9 @@ import org.bdware.units.NetworkManager;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
@ -42,6 +45,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
public class CMHttpServer {
|
public class CMHttpServer {
|
||||||
private static final Logger LOGGER = LogManager.getLogger(CMHttpServer.class);
|
private static final Logger LOGGER = LogManager.getLogger(CMHttpServer.class);
|
||||||
private static final String CONFIG_PATH = "cmconfig.json";
|
private static final String CONFIG_PATH = "cmconfig.json";
|
||||||
|
public static CMDConf cmdConf;
|
||||||
public static EventLoopGroup workerGroup = new NioEventLoopGroup();
|
public static EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||||
public static MultiIndexTimeRocksDBUtil nodeLogDB =
|
public static MultiIndexTimeRocksDBUtil nodeLogDB =
|
||||||
new MultiIndexTimeRocksDBUtil(
|
new MultiIndexTimeRocksDBUtil(
|
||||||
@ -49,11 +53,6 @@ public class CMHttpServer {
|
|||||||
private static SslContext sslContext = null;
|
private static SslContext sslContext = null;
|
||||||
final String PATH = "/SCIDE/SCExecutor";
|
final String PATH = "/SCIDE/SCExecutor";
|
||||||
private final int port;
|
private final int port;
|
||||||
|
|
||||||
private CMHttpServer(int port) {
|
|
||||||
this.port = port;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void parseConf(CMDConf cmdConf) throws IOException {
|
private static void parseConf(CMDConf cmdConf) throws IOException {
|
||||||
if (cmdConf.disableDoRepo) {
|
if (cmdConf.disableDoRepo) {
|
||||||
DoConfig.callContractUsingDOI = false;
|
DoConfig.callContractUsingDOI = false;
|
||||||
@ -64,6 +63,7 @@ public class CMHttpServer {
|
|||||||
GlobalConfigurations.certPath = conf[0];
|
GlobalConfigurations.certPath = conf[0];
|
||||||
GlobalConfigurations.certPassword = conf[1];
|
GlobalConfigurations.certPassword = conf[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cmdConf.doipUserHandle.isEmpty()) {
|
if (!cmdConf.doipUserHandle.isEmpty()) {
|
||||||
GlobalConfigurations.User_Handle = cmdConf.doipUserHandle;
|
GlobalConfigurations.User_Handle = cmdConf.doipUserHandle;
|
||||||
}
|
}
|
||||||
@ -135,6 +135,12 @@ public class CMHttpServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static URLClassLoader pluginLoader;
|
||||||
|
|
||||||
|
private CMHttpServer(int port) {
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
|
||||||
private static void addDirToPath(String s) {
|
private static void addDirToPath(String s) {
|
||||||
try {
|
try {
|
||||||
LOGGER.info("add to path: " + s);
|
LOGGER.info("add to path: " + s);
|
||||||
@ -163,7 +169,8 @@ public class CMHttpServer {
|
|||||||
if (!confFile.exists() && confTemplate.exists()) {
|
if (!confFile.exists() && confTemplate.exists()) {
|
||||||
FileUtils.copyFile(confTemplate, confFile);
|
FileUtils.copyFile(confTemplate, confFile);
|
||||||
}
|
}
|
||||||
CMDConf cmdConf = CMDConf.parseConf(CONFIG_PATH);
|
cmdConf = CMDConf.parseConf(CONFIG_PATH);
|
||||||
|
|
||||||
// addDirToPath(new File("./dynamicLibrary").getAbsolutePath());
|
// addDirToPath(new File("./dynamicLibrary").getAbsolutePath());
|
||||||
|
|
||||||
// for compatibility
|
// for compatibility
|
||||||
@ -208,10 +215,10 @@ public class CMHttpServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
start(cmdConf.ip, cmdConf.servicePort, cmdConf.doipPort);
|
start(cmdConf.ip, cmdConf.servicePort, cmdConf.doipPort,cmdConf);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void start(String ip, int port, int doipPort) throws IOException {
|
public static void start(String ip, int port, int doipPort,CMDConf cmdConf) throws IOException {
|
||||||
if (DoConfig.callContractUsingDOI) {
|
if (DoConfig.callContractUsingDOI) {
|
||||||
ContractManager.threadPool.execute(
|
ContractManager.threadPool.execute(
|
||||||
() -> ContractRepositoryMain.start("tcp://" + ip + ":" + doipPort));
|
() -> ContractRepositoryMain.start("tcp://" + ip + ":" + doipPort));
|
||||||
@ -231,6 +238,22 @@ public class CMHttpServer {
|
|||||||
// EpollServerSocketChannel
|
// EpollServerSocketChannel
|
||||||
// ContractManager.reconnectPort = (port - 18000) * 30 + 1630;
|
// ContractManager.reconnectPort = (port - 18000) * 30 + 1630;
|
||||||
// if (ContractManager.reconnectPort < 0) ContractManager.reconnectPort = 1630;
|
// if (ContractManager.reconnectPort < 0) ContractManager.reconnectPort = 1630;
|
||||||
|
File[] pluginJar = new File("./pluginLib/").listFiles(new FileFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean accept(File pathname) {
|
||||||
|
return pathname.getName().endsWith(".jar");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
URL[] urls = new URL[pluginJar.length];
|
||||||
|
for (int i=0;i<pluginJar.length;i++){
|
||||||
|
try {
|
||||||
|
urls[i] = pluginJar[i].toURI().toURL();
|
||||||
|
LOGGER.info("add plugin:"+pluginJar[i].getName());
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pluginLoader = new URLClassLoader(urls,CMHttpServer.class.getClassLoader());
|
||||||
if (port >= 18000 && port < 18100) {
|
if (port >= 18000 && port < 18100) {
|
||||||
ContractManager.cPort = new ContractPort(1615 + (port - 18000) * 30);
|
ContractManager.cPort = new ContractPort(1615 + (port - 18000) * 30);
|
||||||
} else {
|
} else {
|
||||||
|
@ -18,6 +18,8 @@ import org.bdware.sc.db.KeyValueDBUtil;
|
|||||||
import org.bdware.sc.db.TimeDBUtil;
|
import org.bdware.sc.db.TimeDBUtil;
|
||||||
import org.bdware.sc.util.ExceptionUtil;
|
import org.bdware.sc.util.ExceptionUtil;
|
||||||
import org.bdware.sc.util.JsonUtil;
|
import org.bdware.sc.util.JsonUtil;
|
||||||
|
import org.bdware.server.CMDConf;
|
||||||
|
import org.bdware.server.CMHttpServer;
|
||||||
import org.bdware.server.GRPCPool;
|
import org.bdware.server.GRPCPool;
|
||||||
import org.bdware.server.action.*;
|
import org.bdware.server.action.*;
|
||||||
import org.bdware.server.permission.Role;
|
import org.bdware.server.permission.Role;
|
||||||
@ -34,6 +36,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
|
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
|
||||||
|
import static org.bdware.server.CMHttpServer.pluginLoader;
|
||||||
|
|
||||||
@Sharable
|
@Sharable
|
||||||
public class CMHttpHandler extends SimpleChannelInboundHandler<HttpObject> {
|
public class CMHttpHandler extends SimpleChannelInboundHandler<HttpObject> {
|
||||||
@ -113,6 +116,14 @@ public class CMHttpHandler extends SimpleChannelInboundHandler<HttpObject> {
|
|||||||
return flag && flag2;
|
return flag && flag2;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (CMHttpServer.cmdConf.wsPluginActions != null){
|
||||||
|
for (String str:CMHttpServer.cmdConf.wsPluginActions){
|
||||||
|
Object obj = createInstanceByClzName(str);
|
||||||
|
actionExecutor.appendHandler(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uriHandlers = new URIHandler();
|
uriHandlers = new URIHandler();
|
||||||
DOIPOverHttpHandler doipOverHttpHandler = new DOIPOverHttpHandler();
|
DOIPOverHttpHandler doipOverHttpHandler = new DOIPOverHttpHandler();
|
||||||
uriHandlers.register(this);
|
uriHandlers.register(this);
|
||||||
@ -122,7 +133,14 @@ public class CMHttpHandler extends SimpleChannelInboundHandler<HttpObject> {
|
|||||||
uriHandlers.register(FileActions.class);
|
uriHandlers.register(FileActions.class);
|
||||||
uriHandlers.printURIHandlers();
|
uriHandlers.printURIHandlers();
|
||||||
}
|
}
|
||||||
|
private Object createInstanceByClzName(String clzName){
|
||||||
|
try {
|
||||||
|
Class clz = Class.forName(clzName,true,pluginLoader);
|
||||||
|
return clz.newInstance();
|
||||||
|
}catch(Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public void channelReadComplete(ChannelHandlerContext ctx) {
|
public void channelReadComplete(ChannelHandlerContext ctx) {
|
||||||
ctx.flush();
|
ctx.flush();
|
||||||
|
@ -12,6 +12,8 @@ import org.apache.logging.log4j.LogManager;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bdware.sc.conn.ResultCallback;
|
import org.bdware.sc.conn.ResultCallback;
|
||||||
import org.bdware.sc.util.JsonUtil;
|
import org.bdware.sc.util.JsonUtil;
|
||||||
|
import org.bdware.server.CMDConf;
|
||||||
|
import org.bdware.server.CMHttpServer;
|
||||||
import org.bdware.server.GlobalConf;
|
import org.bdware.server.GlobalConf;
|
||||||
import org.bdware.server.action.ActionExecutor;
|
import org.bdware.server.action.ActionExecutor;
|
||||||
import org.bdware.server.ws.ContractManagerFrameHandler;
|
import org.bdware.server.ws.ContractManagerFrameHandler;
|
||||||
@ -22,6 +24,8 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import static org.bdware.server.CMHttpServer.pluginLoader;
|
||||||
|
|
||||||
@Sharable
|
@Sharable
|
||||||
public class NodeCenterClientHandler extends SimpleChannelInboundHandler<Object> {
|
public class NodeCenterClientHandler extends SimpleChannelInboundHandler<Object> {
|
||||||
private static final Logger LOGGER = LogManager.getLogger(NodeCenterClientHandler.class);
|
private static final Logger LOGGER = LogManager.getLogger(NodeCenterClientHandler.class);
|
||||||
@ -41,6 +45,21 @@ public class NodeCenterClientHandler extends SimpleChannelInboundHandler<Object>
|
|||||||
ae = new ActionExecutor<>(ContractManagerFrameHandler.executorService, controller);
|
ae = new ActionExecutor<>(ContractManagerFrameHandler.executorService, controller);
|
||||||
isConnected = false;
|
isConnected = false;
|
||||||
hasPermission = false;
|
hasPermission = false;
|
||||||
|
if (CMHttpServer.cmdConf.clientToClusterPlugins != null){
|
||||||
|
for (String str:CMHttpServer.cmdConf.clientToAgentPlugins){
|
||||||
|
Object obj = createInstanceByClzName(str);
|
||||||
|
ae.appendHandler(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object createInstanceByClzName(String clzName){
|
||||||
|
try {
|
||||||
|
Class clz = Class.forName(clzName,true,pluginLoader);
|
||||||
|
return clz.newInstance();
|
||||||
|
}catch(Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -13,6 +13,8 @@ import org.apache.logging.log4j.LogManager;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bdware.sc.conn.ResultCallback;
|
import org.bdware.sc.conn.ResultCallback;
|
||||||
import org.bdware.sc.util.JsonUtil;
|
import org.bdware.sc.util.JsonUtil;
|
||||||
|
import org.bdware.server.CMDConf;
|
||||||
|
import org.bdware.server.CMHttpServer;
|
||||||
import org.bdware.server.CongestionControl;
|
import org.bdware.server.CongestionControl;
|
||||||
import org.bdware.server.action.ActionExecutor;
|
import org.bdware.server.action.ActionExecutor;
|
||||||
import org.bdware.server.action.p2p.MasterClientRecoverMechAction;
|
import org.bdware.server.action.p2p.MasterClientRecoverMechAction;
|
||||||
@ -26,6 +28,8 @@ import java.io.PrintStream;
|
|||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
import static org.bdware.server.CMHttpServer.pluginLoader;
|
||||||
|
|
||||||
@ChannelHandler.Sharable
|
@ChannelHandler.Sharable
|
||||||
public class MasterClientFrameHandler extends SimpleChannelInboundHandler<Object> {
|
public class MasterClientFrameHandler extends SimpleChannelInboundHandler<Object> {
|
||||||
private static final Logger LOGGER = LogManager.getLogger(MasterClientFrameHandler.class);
|
private static final Logger LOGGER = LogManager.getLogger(MasterClientFrameHandler.class);
|
||||||
@ -48,8 +52,24 @@ public class MasterClientFrameHandler extends SimpleChannelInboundHandler<Object
|
|||||||
ae =
|
ae =
|
||||||
new ActionExecutor<ResultCallback, JsonObject>(
|
new ActionExecutor<ResultCallback, JsonObject>(
|
||||||
executorService, actions, recoverActions, transferActions);
|
executorService, actions, recoverActions, transferActions);
|
||||||
|
if (CMHttpServer.cmdConf.clientToAgentPlugins != null){
|
||||||
|
for (String str:CMHttpServer.cmdConf.clientToAgentPlugins){
|
||||||
|
Object obj = createInstanceByClzName(str);
|
||||||
|
ae.appendHandler(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Object createInstanceByClzName(String clzName){
|
||||||
|
try {
|
||||||
|
Class clz = Class.forName(clzName,true,pluginLoader);
|
||||||
|
return clz.newInstance();
|
||||||
|
}catch(Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void updateContractID2Client(String contract) {
|
public void updateContractID2Client(String contract) {
|
||||||
// 如果该合约正在和旧的master保持连接
|
// 如果该合约正在和旧的master保持连接
|
||||||
if (MasterClientTCPAction.contractID2MasterInfo.containsKey(contract)) {
|
if (MasterClientTCPAction.contractID2MasterInfo.containsKey(contract)) {
|
||||||
|
@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bdware.sc.conn.ResultCallback;
|
import org.bdware.sc.conn.ResultCallback;
|
||||||
import org.bdware.sc.util.JsonUtil;
|
import org.bdware.sc.util.JsonUtil;
|
||||||
|
import org.bdware.server.CMDConf;
|
||||||
import org.bdware.server.CMHttpServer;
|
import org.bdware.server.CMHttpServer;
|
||||||
import org.bdware.server.CongestionControl;
|
import org.bdware.server.CongestionControl;
|
||||||
import org.bdware.server.GRPCPool;
|
import org.bdware.server.GRPCPool;
|
||||||
@ -21,6 +22,8 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
import static org.bdware.server.CMHttpServer.pluginLoader;
|
||||||
|
|
||||||
public class ContractManagerFrameHandler extends SimpleChannelInboundHandler<WebSocketFrame> {
|
public class ContractManagerFrameHandler extends SimpleChannelInboundHandler<WebSocketFrame> {
|
||||||
private static final Logger LOGGER = LogManager.getLogger(ContractManagerFrameHandler.class);
|
private static final Logger LOGGER = LogManager.getLogger(ContractManagerFrameHandler.class);
|
||||||
public static ExecutorService executorService = Executors.newFixedThreadPool(10);
|
public static ExecutorService executorService = Executors.newFixedThreadPool(10);
|
||||||
@ -97,6 +100,21 @@ public class ContractManagerFrameHandler extends SimpleChannelInboundHandler<Web
|
|||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
if (CMHttpServer.cmdConf.wsPluginActions != null){
|
||||||
|
for (String str:CMHttpServer.cmdConf.wsPluginActions){
|
||||||
|
Object obj = createInstanceByClzName(str);
|
||||||
|
ae.appendHandler(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object createInstanceByClzName(String clzName){
|
||||||
|
try {
|
||||||
|
Class clz = Class.forName(clzName,true,pluginLoader);
|
||||||
|
return clz.newInstance();
|
||||||
|
}catch(Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPermission(long l) {
|
public void setPermission(long l) {
|
||||||
|
@ -10,11 +10,14 @@ import io.netty.handler.timeout.IdleStateEvent;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bdware.sc.conn.ResultCallback;
|
import org.bdware.sc.conn.ResultCallback;
|
||||||
|
import org.bdware.server.CMHttpServer;
|
||||||
import org.bdware.server.action.ActionExecutor;
|
import org.bdware.server.action.ActionExecutor;
|
||||||
import org.bdware.units.grpc.BDLedgerContract;
|
import org.bdware.units.grpc.BDLedgerContract;
|
||||||
import org.bdware.units.grpc.BDLedgerContract.UnitMessage;
|
import org.bdware.units.grpc.BDLedgerContract.UnitMessage;
|
||||||
import org.bdware.units.msghandler.UnitMessageHandler;
|
import org.bdware.units.msghandler.UnitMessageHandler;
|
||||||
|
|
||||||
|
import static org.bdware.server.CMHttpServer.pluginLoader;
|
||||||
|
|
||||||
@ChannelHandler.Sharable
|
@ChannelHandler.Sharable
|
||||||
public class TCPClientFrameHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
public class TCPClientFrameHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
||||||
private static final Logger LOGGER = LogManager.getLogger(TCPClientFrameHandler.class);
|
private static final Logger LOGGER = LogManager.getLogger(TCPClientFrameHandler.class);
|
||||||
@ -27,6 +30,21 @@ public class TCPClientFrameHandler extends SimpleChannelInboundHandler<ByteBuf>
|
|||||||
public TCPClientFrameHandler(String peerId) {
|
public TCPClientFrameHandler(String peerId) {
|
||||||
peer = peerId;
|
peer = peerId;
|
||||||
// heartBeat = new HeartBeatProtocol(peer);
|
// heartBeat = new HeartBeatProtocol(peer);
|
||||||
|
if (CMHttpServer.cmdConf.tcpPlugins != null){
|
||||||
|
for (String str:CMHttpServer.cmdConf.tcpPlugins){
|
||||||
|
Object obj = createInstanceByClzName(str);
|
||||||
|
ae.appendHandler(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object createInstanceByClzName(String clzName){
|
||||||
|
try {
|
||||||
|
Class clz = Class.forName(clzName,true,pluginLoader);
|
||||||
|
return clz.newInstance();
|
||||||
|
}catch(Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user