通用大文件上传组件.

This commit is contained in:
lijiahang
2024-05-07 19:12:37 +08:00
parent 1379150369
commit f416e63b66
21 changed files with 711 additions and 32 deletions

View File

@@ -41,7 +41,7 @@
<artifactId>orion-ops-spring-boot-starter-web</artifactId>
</dependency>
<!-- web-socket -->
<!-- websocket -->
<dependency>
<groupId>com.orion.ops</groupId>
<artifactId>orion-ops-spring-boot-starter-websocket</artifactId>

View File

@@ -4,7 +4,6 @@ import com.orion.lang.support.timeout.TimeoutChecker;
import com.orion.lang.support.timeout.TimeoutEndpoint;
import com.orion.lang.utils.Booleans;
import com.orion.lang.utils.ansi.AnsiAppender;
import com.orion.lang.utils.ansi.style.AnsiFont;
import com.orion.lang.utils.ansi.style.color.AnsiForeground;
import com.orion.lang.utils.time.Dates;
import com.orion.net.host.ssh.ExitCode;
@@ -31,16 +30,16 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
super.initLogOutputStream();
// 拼接启动日志
AnsiAppender appender = AnsiAppender.create()
.append(AnsiForeground.GREEN.and(AnsiFont.BOLD), "> 准备执行命令 ")
.append(AnsiForeground.BRIGHT_GREEN, "> 准备执行命令 ")
.append(Dates.current())
.newLine()
.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "执行记录: ")
.append(AnsiForeground.BRIGHT_BLUE, "执行记录: ")
.append(execCommand.getLogId())
.newLine()
.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "执行描述: ")
.append(AnsiForeground.BRIGHT_BLUE, "执行描述: ")
.append(execCommand.getDescription())
.newLine()
.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "执行用户: ")
.append(AnsiForeground.BRIGHT_BLUE, "执行用户: ")
.append(execCommand.getUsername());
// 非系统用户执行添加 userId
if (Const.SYSTEM_USER_ID.equals(execCommand.getUserId())) {
@@ -53,35 +52,35 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
}
// 执行序列
if (execCommand.getExecSeq() != null) {
appender.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "执行序列: ")
appender.append(AnsiForeground.BRIGHT_BLUE, "执行序列: ")
.append('#')
.append(execCommand.getExecSeq())
.newLine();
}
appender.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "执行主机: ")
appender.append(AnsiForeground.BRIGHT_BLUE, "执行主机: ")
.append(execHostCommand.getHostName())
.append(" (")
.append(execHostCommand.getHostId())
.append(")")
.newLine()
.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "主机地址: ")
.append(AnsiForeground.BRIGHT_BLUE, "主机地址: ")
.append(execHostCommand.getHostAddress())
.newLine()
.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "超时时间: ")
.append(AnsiForeground.BRIGHT_BLUE, "超时时间: ")
.append(execCommand.getTimeout())
.newLine()
.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "脚本执行: ")
.append(AnsiForeground.BRIGHT_BLUE, "脚本执行: ")
.append(execCommand.getScriptExec())
.newLine()
.newLine()
.append(AnsiForeground.GREEN.and(AnsiFont.BOLD), "> 执行命令 ")
.append(AnsiForeground.BRIGHT_GREEN, "> 执行命令 ")
.newLine()
.append(execHostCommand.getCommand())
.newLine()
.newLine();
// 非脚本执行拼接开始执行日志
if (!Booleans.isTrue(execCommand.getScriptExec())) {
appender.append(AnsiForeground.GREEN.and(AnsiFont.BOLD), "> 开始执行命令 ")
appender.append(AnsiForeground.BRIGHT_GREEN, "> 开始执行命令 ")
.append(Dates.current())
.newLine();
}
@@ -94,10 +93,10 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
// 拼接上传日志
AnsiAppender startAppender = AnsiAppender.create()
.newLine()
.append(AnsiForeground.GREEN.and(AnsiFont.BOLD), "> 准备上传脚本 ")
.append(AnsiForeground.BRIGHT_GREEN, "> 准备上传脚本 ")
.append(Dates.current())
.newLine()
.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "文件路径: ")
.append(AnsiForeground.BRIGHT_BLUE, "文件路径: ")
.append(execHostCommand.getScriptPath())
.newLine();
this.appendLog(startAppender);
@@ -105,18 +104,18 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
super.uploadScriptFile();
// 拼接完成日志
AnsiAppender finishAppender = AnsiAppender.create()
.append(AnsiForeground.GREEN.and(AnsiFont.BOLD), "< 脚本上传成功 ")
.append(AnsiForeground.BRIGHT_GREEN, "< 脚本上传成功 ")
.append(Dates.current())
.newLine()
.newLine()
.append(AnsiForeground.GREEN.and(AnsiFont.BOLD), "> 开始执行脚本 ")
.append(AnsiForeground.BRIGHT_GREEN, "> 开始执行脚本 ")
.append(Dates.current())
.newLine();
this.appendLog(finishAppender);
} catch (Exception e) {
// 拼接失败日志
AnsiAppender errorAppender = AnsiAppender.create()
.append(AnsiForeground.RED.and(AnsiFont.BOLD), "< 脚本上传失败 ")
.append(AnsiForeground.BRIGHT_RED, "< 脚本上传失败 ")
.append(Dates.current())
.newLine();
this.appendLog(errorAppender);
@@ -133,37 +132,37 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
.newLine();
if (this.status == ExecHostStatusEnum.INTERRUPTED) {
// 中断执行
appender.append(AnsiForeground.YELLOW.and(AnsiFont.BOLD), "< 命令执行中断 ")
appender.append(AnsiForeground.BRIGHT_YELLOW, "< 命令执行中断 ")
.append(Dates.current())
.newLine();
} else if (this.status == ExecHostStatusEnum.FAILED) {
// 执行失败
appender.append(AnsiForeground.RED.and(AnsiFont.BOLD), "< 命令执行失败 ")
appender.append(AnsiForeground.BRIGHT_RED, "< 命令执行失败 ")
.append(Dates.current())
.newLine()
.append(AnsiForeground.RED.and(AnsiFont.BOLD), "错误原因: ")
.append(AnsiForeground.BRIGHT_RED, "错误原因: ")
.append(this.getErrorMessage(e))
.newLine();
} else if (this.status == ExecHostStatusEnum.TIMEOUT) {
// 更新执行超时
appender.append(AnsiForeground.YELLOW.and(AnsiFont.BOLD), "< 命令执行超时 ")
appender.append(AnsiForeground.BRIGHT_YELLOW, "< 命令执行超时 ")
.append(Dates.current())
.newLine();
} else {
long ms = this.updateRecord.getFinishTime().getTime() - this.updateRecord.getStartTime().getTime();
Integer exitStatus = this.updateRecord.getExitStatus();
// 执行完成
appender.append(AnsiForeground.GREEN.and(AnsiFont.BOLD), "< 命令执行完成 ")
appender.append(AnsiForeground.BRIGHT_GREEN, "< 命令执行完成 ")
.append(Dates.current())
.newLine()
.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "exit: ");
.append(AnsiForeground.BRIGHT_BLUE, "exit: ");
if (ExitCode.isSuccess(exitStatus)) {
appender.append(AnsiForeground.GREEN.and(AnsiFont.BOLD), exitStatus);
appender.append(AnsiForeground.BRIGHT_GREEN, exitStatus);
} else {
appender.append(AnsiForeground.RED.and(AnsiFont.BOLD), exitStatus);
appender.append(AnsiForeground.BRIGHT_RED, exitStatus);
}
appender.newLine()
.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "used: ")
.append(AnsiForeground.BRIGHT_BLUE, "used: ")
.append(Dates.interval(ms, false, "d ", "h ", "m ", "s"))
.append(" (")
.append(ms)

View File

@@ -2,9 +2,9 @@ package com.orion.ops.module.asset.handler.host.transfer.model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* 文件操作请求 实体对象
@@ -14,7 +14,7 @@ import lombok.experimental.SuperBuilder;
* @since 2024/2/21 21:01
*/
@Data
@SuperBuilder
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "FileOperatorRequest", description = "文件操作请求 实体对象")

View File

@@ -2,9 +2,9 @@ package com.orion.ops.module.asset.handler.host.transfer.model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* 文件操作响应 实体对象
@@ -14,7 +14,7 @@ import lombok.experimental.SuperBuilder;
* @since 2024/2/21 22:38
*/
@Data
@SuperBuilder
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "FileOperatorResponse", description = "文件操作响应 实体对象")