⚡ 修改 websocket 连接逻辑.
This commit is contained in:
@@ -97,7 +97,7 @@ public class CodeGeneratorEngine extends VelocityTemplateEngine {
|
||||
// http 注释标识
|
||||
objectMap.put("httpComment", "###");
|
||||
// 版本
|
||||
objectMap.put("since", OrionOpsProConst.VERSION);
|
||||
objectMap.put("version", OrionOpsProConst.VERSION);
|
||||
// api 注释
|
||||
Map<String, String> apiComment = new HashMap<>(12);
|
||||
String comment = tableInfo.getComment();
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.math.*;
|
||||
* $!{table.comment} 缓存对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Data
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.concurrent.TimeUnit;
|
||||
* $!{table.comment}缓存 key
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
public interface ${type}CacheKeyDefine {
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.util.List;
|
||||
* $!{table.comment} api
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Tag(name = "${package.ModuleName} - $!{table.comment}服务")
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.List;
|
||||
* $!{table.comment} 内部对象转换器
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Mapper
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.math.*;
|
||||
* $!{table.comment} 实体对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Data
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.math.*;
|
||||
* $!{table.comment} 导出对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Data
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.math.*;
|
||||
* $!{table.comment} 创建请求对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Data
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.math.*;
|
||||
* $!{table.comment} 查询请求对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Data
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.math.*;
|
||||
* $!{table.comment} 更新请求对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Data
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.math.*;
|
||||
* $!{table.comment} 视图响应对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Data
|
||||
|
||||
@@ -11,7 +11,7 @@ import ${mapperAnnotationClass.name};
|
||||
* $!{table.comment} Mapper 接口
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
#if(${mapperAnnotationClass})
|
||||
|
||||
@@ -10,7 +10,7 @@ import static com.orion.ops.framework.biz.operator.log.core.enums.OperatorRiskLe
|
||||
* $!{table.comment} 操作日志类型
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Module("${package.ModuleName}:${typeHyphen}")
|
||||
|
||||
@@ -43,7 +43,7 @@ import java.util.stream.Collectors;
|
||||
* $!{table.comment} 服务实现类
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Slf4j
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.List;
|
||||
* $!{table.comment} 服务类
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
public interface ${table.serviceName} {
|
||||
|
||||
@@ -26,7 +26,7 @@ import java.util.stream.Collectors;
|
||||
* $!{table.comment} 对外服务实现类
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Slf4j
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
* $!{table.comment} 对外服务类
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
public interface ${type}Api {
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.util.List;
|
||||
* $!{table.comment} 对外服务对象转换器
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Mapper
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.math.*;
|
||||
* $!{table.comment} 创建请求业务对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Data
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.math.*;
|
||||
* $!{table.comment} 查询请求业务对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Data
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.math.*;
|
||||
* $!{table.comment} 更新请求业务对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Data
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.math.*;
|
||||
* $!{table.comment} 业务对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Data
|
||||
|
||||
@@ -20,9 +20,9 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
/**
|
||||
* $!{table.comment} 对外服务单元测试
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/8/23 10:36
|
||||
* @author ${author}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Slf4j
|
||||
@Import({${type}ApiImpl.class, ${type}ServiceImpl.class})
|
||||
|
||||
@@ -21,9 +21,9 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
/**
|
||||
* $!{table.comment} 服务单元测试
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/8/23 10:36
|
||||
* @author ${author}
|
||||
* @version ${version}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Slf4j
|
||||
@Import(${type}ServiceImpl.class)
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.orion.ops.module.asset.controller;
|
||||
|
||||
import com.orion.lang.define.wrapper.HttpWrapper;
|
||||
import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog;
|
||||
import com.orion.ops.framework.biz.operator.log.core.enums.ReturnType;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.framework.web.core.annotation.RestWrapper;
|
||||
import com.orion.ops.module.asset.define.operator.ExecOperatorType;
|
||||
@@ -40,7 +41,7 @@ public class ExecController {
|
||||
@Resource
|
||||
private ExecService execService;
|
||||
|
||||
@OperatorLog(ExecOperatorType.EXEC_COMMAND)
|
||||
@OperatorLog(value = ExecOperatorType.EXEC_COMMAND, ret = ReturnType.IGNORE)
|
||||
@PostMapping("/exec-command")
|
||||
@Operation(summary = "批量执行命令")
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec:exec-command')")
|
||||
@@ -48,7 +49,7 @@ public class ExecController {
|
||||
return execService.execCommand(request);
|
||||
}
|
||||
|
||||
@OperatorLog(ExecOperatorType.EXEC_COMMAND)
|
||||
@OperatorLog(value = ExecOperatorType.EXEC_COMMAND, ret = ReturnType.IGNORE)
|
||||
@PostMapping("/re-exec-command")
|
||||
@Operation(summary = "重新执行命令")
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec:exec-command')")
|
||||
|
||||
@@ -35,11 +35,11 @@ public class ExecOperatorType extends InitializingOperatorTypes {
|
||||
return new OperatorType[]{
|
||||
new OperatorType(M, EXEC_COMMAND, "执行主机命令"),
|
||||
new OperatorType(M, INTERRUPT_EXEC, "中断执行命令"),
|
||||
new OperatorType(M, INTERRUPT_HOST, "中断主机执行命令 ${logId} ${hostName}"),
|
||||
new OperatorType(H, DELETE_LOG, "删除执行记录 ${count} 条"),
|
||||
new OperatorType(H, CLEAR_LOG, "清理执行记录 ${count} 条"),
|
||||
new OperatorType(H, DELETE_HOST_LOG, "删除主机执行记录 ${logId} ${hostName}"),
|
||||
new OperatorType(L, DOWNLOAD_HOST_LOG, "下载主机执行日志 ${logId} ${hostName}"),
|
||||
new OperatorType(M, INTERRUPT_HOST, "中断主机执行命令 <sb>${logId}</sb> <sb>${hostName}</sb>"),
|
||||
new OperatorType(H, DELETE_LOG, "删除执行记录 <sb>${count}</sb> 条"),
|
||||
new OperatorType(H, CLEAR_LOG, "清理执行记录 <sb>${count}</sb> 条"),
|
||||
new OperatorType(H, DELETE_HOST_LOG, "删除主机执行记录 <sb>${logId}</sb> <sb>${hostName}</sb>"),
|
||||
new OperatorType(L, DOWNLOAD_HOST_LOG, "下载主机执行日志 <sb>${logId}</sb> <sb>${hostName}</sb>"),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -124,11 +124,13 @@ export default class LogAppender implements ILogAppender {
|
||||
// 获取 token
|
||||
const { data } = await getExecLogTailToken(this.config);
|
||||
// 打开会话
|
||||
this.client = await createWebSocket(`${webSocketBaseUrl}/exec/log/${data}`);
|
||||
this.client.onerror = event => {
|
||||
try {
|
||||
this.client = await createWebSocket(`${webSocketBaseUrl}/exec/log/${data}`);
|
||||
} catch (e) {
|
||||
Message.error('连接失败');
|
||||
console.error('log error', event);
|
||||
};
|
||||
console.error('log error', e);
|
||||
return;
|
||||
}
|
||||
this.client.onclose = event => {
|
||||
console.warn('log close', event);
|
||||
};
|
||||
|
||||
@@ -191,7 +191,7 @@ export const resetObject = (obj: any, ignore: string[] = []) => {
|
||||
export const objectTruthKeyCount = (obj: any, ignore: string[] = []) => {
|
||||
return Object.keys(obj)
|
||||
.filter(s => !ignore.includes(s))
|
||||
.reduce(function(acc, curr) {
|
||||
.reduce(function (acc, curr) {
|
||||
const currVal = obj[curr];
|
||||
return acc + ~~(currVal !== undefined && currVal !== null && currVal?.length !== 0 && currVal !== '');
|
||||
}, 0);
|
||||
@@ -204,13 +204,13 @@ export const createWebSocket = async (url: string) => {
|
||||
return new Promise<WebSocket>((resolve, reject) => {
|
||||
const socket = new WebSocket(url);
|
||||
|
||||
socket.addEventListener('open', () => {
|
||||
socket.onopen = () => {
|
||||
resolve(socket);
|
||||
});
|
||||
};
|
||||
|
||||
socket.addEventListener('error', (error) => {
|
||||
reject(error);
|
||||
});
|
||||
socket.onerror = e => {
|
||||
reject(e);
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
@@ -241,7 +241,7 @@ export function detectZoom() {
|
||||
* 获取唯一的 UUID
|
||||
*/
|
||||
export function getUUID() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||
const r = Math.random() * 16 | 0;
|
||||
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
<!-- 表头 -->
|
||||
<div class="panel-header">
|
||||
<h3>执行命令</h3>
|
||||
<span class="span-blue usn pointer" @click="openTemplate">从模板中选择</span>
|
||||
<span v-permission="['asset:exec-template:query']"
|
||||
class="span-blue usn pointer"
|
||||
@click="openTemplate">
|
||||
从模板中选择
|
||||
</span>
|
||||
</div>
|
||||
<!-- 命令编辑器 -->
|
||||
<div class="editor-wrapper">
|
||||
|
||||
@@ -98,11 +98,12 @@ export default class SftpTransferManager implements ISftpTransferManager {
|
||||
// 获取 access
|
||||
const { data: accessToken } = await getTerminalAccessToken();
|
||||
// 打开会话
|
||||
this.client = await createWebSocket(`${webSocketBaseUrl}/host/transfer/${accessToken}`);
|
||||
this.client.onerror = event => {
|
||||
try {
|
||||
this.client = await createWebSocket(`${webSocketBaseUrl}/host/transfer/${accessToken}`);
|
||||
} catch (e) {
|
||||
// 打开失败将传输列表置为失效
|
||||
Message.error('会话打开失败');
|
||||
console.error('transfer error', event);
|
||||
console.error('transfer error', e);
|
||||
// 将等待中和传输中任务修改为失败状态
|
||||
this.transferList.filter(s => {
|
||||
return s.status === TransferStatus.WAITING
|
||||
@@ -110,17 +111,18 @@ export default class SftpTransferManager implements ISftpTransferManager {
|
||||
}).forEach(s => {
|
||||
s.status = TransferStatus.ERROR;
|
||||
});
|
||||
};
|
||||
// 关闭会话重置 run
|
||||
this.run = false;
|
||||
return;
|
||||
}
|
||||
this.client.onclose = event => {
|
||||
// 关闭会话重置 run
|
||||
this.run = false;
|
||||
console.warn('transfer close', event);
|
||||
};
|
||||
this.client.onopen = () => {
|
||||
// 打开后自动传输下一个任务
|
||||
this.transferNextItem();
|
||||
};
|
||||
this.client.onmessage = this.resolveMessage.bind(this);
|
||||
// 打开后自动传输下一个任务
|
||||
this.transferNextItem();
|
||||
}
|
||||
|
||||
// 传输下一条任务
|
||||
|
||||
@@ -22,11 +22,13 @@ export default class TerminalChannel implements ITerminalChannel {
|
||||
// 获取 access
|
||||
const { data: accessToken } = await getTerminalAccessToken();
|
||||
// 打开会话
|
||||
this.client = await createWebSocket(`${webSocketBaseUrl}/host/terminal/${accessToken}`);
|
||||
this.client.onerror = event => {
|
||||
try {
|
||||
this.client = await createWebSocket(`${webSocketBaseUrl}/host/terminal/${accessToken}`);
|
||||
} catch (e) {
|
||||
Message.error('无法连接至服务器');
|
||||
console.error('terminal error', event);
|
||||
};
|
||||
console.error('terminal error', e);
|
||||
throw e;
|
||||
}
|
||||
this.client.onclose = event => {
|
||||
console.warn('terminal close', event);
|
||||
};
|
||||
|
||||
@@ -65,12 +65,15 @@
|
||||
<!-- 颜色 -->
|
||||
<template v-else-if="ValueType.COLOR === type">
|
||||
<a-input v-model="extraValue[name]"
|
||||
class="item-color-input"
|
||||
:placeholder="`请输入 ${name}`"
|
||||
allow-clear
|
||||
hide-button />
|
||||
<span class="item-extra-block" :style="{
|
||||
background: extraValue[name] === '#' ? undefined : (extraValue[name] || undefined)
|
||||
}" />
|
||||
<div class="item-color-block-wrapper">
|
||||
<span class="item-color-block" :style="{
|
||||
background: extraValue[name] === '#' ? undefined : (extraValue[name] || undefined)
|
||||
}" />
|
||||
</div>
|
||||
</template>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
@@ -223,12 +226,22 @@
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.item-extra-block {
|
||||
width: 38px;
|
||||
.item-color-input {
|
||||
width: calc(100% - 40px);
|
||||
}
|
||||
|
||||
.item-color-block-wrapper {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
padding: 4px;
|
||||
margin-left: 8px;
|
||||
border-radius: 4px;
|
||||
background: var(--color-fill-2);
|
||||
}
|
||||
|
||||
.item-color-block {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
Reference in New Issue
Block a user