🔨 添加执行超时.
This commit is contained in:
@@ -38,6 +38,11 @@ public enum ExecHostStatusEnum {
|
||||
*/
|
||||
FAILED(false),
|
||||
|
||||
/**
|
||||
* 执行超时
|
||||
*/
|
||||
TIMEOUT(false),
|
||||
|
||||
/**
|
||||
* 中断执行
|
||||
*/
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/**
|
||||
* 命令执行器
|
||||
@@ -93,7 +92,7 @@ public class ExecCommandHandler implements IExecCommandHandler {
|
||||
this.updateStatus(ExecHostStatusEnum.FAILED, ex);
|
||||
} else if (executor.isTimeout()) {
|
||||
// 更新执行超时
|
||||
this.updateStatus(ExecHostStatusEnum.FAILED, new TimeoutException());
|
||||
this.updateStatus(ExecHostStatusEnum.TIMEOUT, null);
|
||||
} else {
|
||||
// 更新执行完成
|
||||
this.updateStatus(ExecHostStatusEnum.COMPLETED, null);
|
||||
@@ -144,6 +143,9 @@ public class ExecCommandHandler implements IExecCommandHandler {
|
||||
// 失败
|
||||
update.setFinishTime(new Date());
|
||||
update.setErrorMessage(this.getErrorMessage(ex));
|
||||
} else if (ExecHostStatusEnum.TIMEOUT.equals(status)) {
|
||||
// 超时
|
||||
update.setFinishTime(new Date());
|
||||
} else if (ExecHostStatusEnum.INTERRUPTED.equals(status)) {
|
||||
// 中断
|
||||
update.setFinishTime(new Date());
|
||||
@@ -152,8 +154,6 @@ public class ExecCommandHandler implements IExecCommandHandler {
|
||||
log.info("ExecCommandHandler.updateStatus finish id: {}, effect: {}", id, effect);
|
||||
}
|
||||
|
||||
// TODO timeout
|
||||
|
||||
@Override
|
||||
public void write(String msg) {
|
||||
this.executor.write(msg);
|
||||
@@ -182,9 +182,7 @@ public class ExecCommandHandler implements IExecCommandHandler {
|
||||
Streams.close(executor);
|
||||
Streams.close(sessionStore);
|
||||
Streams.close(logOutputStream);
|
||||
// TODO TEST 异步关闭日志
|
||||
execLogManager.asyncCloseTailFile(execHostCommand.getLogPath());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,9 +193,7 @@ public class ExecCommandHandler implements IExecCommandHandler {
|
||||
*/
|
||||
private String getErrorMessage(Exception ex) {
|
||||
String message;
|
||||
if (ex instanceof TimeoutException) {
|
||||
message = "执行超时";
|
||||
} else if (ex instanceof InvalidArgumentException) {
|
||||
if (ex instanceof InvalidArgumentException) {
|
||||
message = ex.getMessage();
|
||||
} else if (ex instanceof ConnectionRuntimeException) {
|
||||
message = "连接失败";
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.orion.ops.framework.websocket.core.utils.WebSockets;
|
||||
import com.orion.ops.module.asset.define.AssetThreadPools;
|
||||
import com.orion.ops.module.asset.entity.dto.ExecHostLogTailDTO;
|
||||
import com.orion.ops.module.asset.entity.dto.ExecLogTailDTO;
|
||||
import com.orion.ops.module.asset.handler.host.exec.log.constant.LogConst;
|
||||
import com.orion.ops.module.asset.handler.host.exec.log.manager.ExecLogManager;
|
||||
import com.orion.ops.module.asset.handler.host.exec.log.tracker.ExecLogTracker;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -55,6 +56,11 @@ public class ExecLogTailHandler extends AbstractWebSocketHandler {
|
||||
|
||||
@Override
|
||||
protected void handleTextMessage(WebSocketSession session, TextMessage message) {
|
||||
String payload = message.getPayload();
|
||||
// ping
|
||||
if (LogConst.PING_PAYLOAD.equals(payload)) {
|
||||
WebSockets.sendText(session, LogConst.PONG_PAYLOAD);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -68,16 +74,12 @@ public class ExecLogTailHandler extends AbstractWebSocketHandler {
|
||||
log.info("ExecLogTailHandler-afterConnectionClosed id: {}, code: {}, reason: {}", id, status.getCode(), status.getReason());
|
||||
// 关闭会话
|
||||
ExecLogTailDTO info = WebSockets.getAttr(session, ExtraFieldConst.INFO);
|
||||
// 移除追踪器 TODO TEST
|
||||
// 移除追踪器
|
||||
for (ExecHostLogTailDTO host : info.getHosts()) {
|
||||
execLogManager.removeTracker(this.getTrackerId(id, info, host));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO ws://127.0.0.1:9200/orion/keep-alive/exec/log/ive0btemHxmEY0HyTm5
|
||||
// todo 首页元数据加载
|
||||
// todo 批量执行的 warn
|
||||
|
||||
/**
|
||||
* 获取追踪器 id
|
||||
*
|
||||
|
||||
@@ -9,6 +9,10 @@ package com.orion.ops.module.asset.handler.host.exec.log.constant;
|
||||
*/
|
||||
public interface LogConst {
|
||||
|
||||
String PING_PAYLOAD = "p";
|
||||
|
||||
String PONG_PAYLOAD = "p";
|
||||
|
||||
String SEPARATOR = "|";
|
||||
|
||||
int TRACKER_OFFSET_LINE = 200;
|
||||
|
||||
@@ -56,7 +56,6 @@ public class ExecLogTracker implements IExecLogTracker {
|
||||
// 开始监听文件
|
||||
tracker.run();
|
||||
// 监听完成回调
|
||||
// TODO test
|
||||
this.close = true;
|
||||
} catch (Exception e) {
|
||||
log.error("exec log tracker error path: {}", absolutePath, e);
|
||||
@@ -80,7 +79,6 @@ public class ExecLogTracker implements IExecLogTracker {
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
// TODO test
|
||||
log.info("ExecLogTracker.close path: {}", absolutePath);
|
||||
if (close) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user