|
|
@ -40,8 +40,6 @@ public class LogClientService implements NettyRequestProcessor { |
|
|
|
|
|
|
|
|
|
|
|
private final NettyRemotingClient client; |
|
|
|
private final NettyRemotingClient client; |
|
|
|
|
|
|
|
|
|
|
|
private final Address address; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* request time out |
|
|
|
* request time out |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -49,18 +47,14 @@ public class LogClientService implements NettyRequestProcessor { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* construct client |
|
|
|
* construct client |
|
|
|
* @param host host |
|
|
|
|
|
|
|
* @param port port |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public LogClientService(String host, int port) { |
|
|
|
public LogClientService() { |
|
|
|
this.address = new Address(host, port); |
|
|
|
|
|
|
|
this.clientConfig = new NettyClientConfig(); |
|
|
|
this.clientConfig = new NettyClientConfig(); |
|
|
|
this.clientConfig.setWorkerThreads(1); |
|
|
|
this.clientConfig.setWorkerThreads(4); |
|
|
|
this.client = new NettyRemotingClient(clientConfig); |
|
|
|
this.client = new NettyRemotingClient(clientConfig); |
|
|
|
this.client.registerProcessor(CommandType.ROLL_VIEW_LOG_RESPONSE,this); |
|
|
|
this.client.registerProcessor(CommandType.ROLL_VIEW_LOG_RESPONSE,this); |
|
|
|
this.client.registerProcessor(CommandType.VIEW_WHOLE_LOG_RESPONSE, this); |
|
|
|
this.client.registerProcessor(CommandType.VIEW_WHOLE_LOG_RESPONSE, this); |
|
|
|
this.client.registerProcessor(CommandType.GET_LOG_BYTES_RESPONSE, this); |
|
|
|
this.client.registerProcessor(CommandType.GET_LOG_BYTES_RESPONSE, this); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -73,15 +67,18 @@ public class LogClientService implements NettyRequestProcessor { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* roll view log |
|
|
|
* roll view log |
|
|
|
|
|
|
|
* @param host host |
|
|
|
|
|
|
|
* @param port port |
|
|
|
* @param path path |
|
|
|
* @param path path |
|
|
|
* @param skipLineNum skip line number |
|
|
|
* @param skipLineNum skip line number |
|
|
|
* @param limit limit |
|
|
|
* @param limit limit |
|
|
|
* @return log content |
|
|
|
* @return log content |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String rollViewLog(String path,int skipLineNum,int limit) { |
|
|
|
public String rollViewLog(String host, int port, String path,int skipLineNum,int limit) { |
|
|
|
logger.info("roll view log, path {}, skipLineNum {} ,limit {}", path, skipLineNum, limit); |
|
|
|
logger.info("roll view log, host : {}, port : {}, path {}, skipLineNum {} ,limit {}", host, port, path, skipLineNum, limit); |
|
|
|
RollViewLogRequestCommand request = new RollViewLogRequestCommand(path, skipLineNum, limit); |
|
|
|
RollViewLogRequestCommand request = new RollViewLogRequestCommand(path, skipLineNum, limit); |
|
|
|
String result = ""; |
|
|
|
String result = ""; |
|
|
|
|
|
|
|
final Address address = new Address(host, port); |
|
|
|
try { |
|
|
|
try { |
|
|
|
Command command = request.convert2Command(); |
|
|
|
Command command = request.convert2Command(); |
|
|
|
this.client.send(address, command); |
|
|
|
this.client.send(address, command); |
|
|
@ -89,19 +86,24 @@ public class LogClientService implements NettyRequestProcessor { |
|
|
|
result = ((String)promise.getResult()); |
|
|
|
result = ((String)promise.getResult()); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("roll view log error", e); |
|
|
|
logger.error("roll view log error", e); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
this.client.closeChannel(address); |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* view log |
|
|
|
* view log |
|
|
|
|
|
|
|
* @param host host |
|
|
|
|
|
|
|
* @param port port |
|
|
|
* @param path path |
|
|
|
* @param path path |
|
|
|
* @return log content |
|
|
|
* @return log content |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String viewLog(String path) { |
|
|
|
public String viewLog(String host, int port, String path) { |
|
|
|
logger.info("view log path {}", path); |
|
|
|
logger.info("view log path {}", path); |
|
|
|
ViewLogRequestCommand request = new ViewLogRequestCommand(path); |
|
|
|
ViewLogRequestCommand request = new ViewLogRequestCommand(path); |
|
|
|
String result = ""; |
|
|
|
String result = ""; |
|
|
|
|
|
|
|
final Address address = new Address(host, port); |
|
|
|
try { |
|
|
|
try { |
|
|
|
Command command = request.convert2Command(); |
|
|
|
Command command = request.convert2Command(); |
|
|
|
this.client.send(address, command); |
|
|
|
this.client.send(address, command); |
|
|
@ -109,19 +111,24 @@ public class LogClientService implements NettyRequestProcessor { |
|
|
|
result = ((String)promise.getResult()); |
|
|
|
result = ((String)promise.getResult()); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("view log error", e); |
|
|
|
logger.error("view log error", e); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
this.client.closeChannel(address); |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* get log size |
|
|
|
* get log size |
|
|
|
|
|
|
|
* @param host host |
|
|
|
|
|
|
|
* @param port port |
|
|
|
* @param path log path |
|
|
|
* @param path log path |
|
|
|
* @return log content bytes |
|
|
|
* @return log content bytes |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public byte[] getLogBytes(String path) { |
|
|
|
public byte[] getLogBytes(String host, int port, String path) { |
|
|
|
logger.info("log path {}", path); |
|
|
|
logger.info("log path {}", path); |
|
|
|
GetLogBytesRequestCommand request = new GetLogBytesRequestCommand(path); |
|
|
|
GetLogBytesRequestCommand request = new GetLogBytesRequestCommand(path); |
|
|
|
byte[] result = null; |
|
|
|
byte[] result = null; |
|
|
|
|
|
|
|
final Address address = new Address(host, port); |
|
|
|
try { |
|
|
|
try { |
|
|
|
Command command = request.convert2Command(); |
|
|
|
Command command = request.convert2Command(); |
|
|
|
this.client.send(address, command); |
|
|
|
this.client.send(address, command); |
|
|
@ -129,6 +136,8 @@ public class LogClientService implements NettyRequestProcessor { |
|
|
|
result = (byte[])promise.getResult(); |
|
|
|
result = (byte[])promise.getResult(); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("get log size error", e); |
|
|
|
logger.error("get log size error", e); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
this.client.closeChannel(address); |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
@ -156,11 +165,4 @@ public class LogClientService implements NettyRequestProcessor { |
|
|
|
throw new UnsupportedOperationException(String.format("command type : %s is not supported ", command.getType())); |
|
|
|
throw new UnsupportedOperationException(String.format("command type : %s is not supported ", command.getType())); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception{ |
|
|
|
|
|
|
|
LogClientService logClient = new LogClientService("192.168.220.247", 50051); |
|
|
|
|
|
|
|
byte[] logBytes = logClient.getLogBytes("/opt/program/incubator-dolphinscheduler/logs/1/463/540.log"); |
|
|
|
|
|
|
|
System.out.println(new String(logBytes)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |