Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af99abab71 | ||
|
|
2224bc7ae7 | ||
|
|
d3fe012501 | ||
|
|
38f64eb3bb | ||
|
|
c880065e39 | ||
|
|
714940bdcf | ||
|
|
33cfb13342 | ||
|
|
83ceb0e1e5 | ||
|
|
fe4b87927e | ||
|
|
1034ba4896 | ||
|
|
256e54ffd8 | ||
|
|
339d86fc87 | ||
|
|
bc8e04b908 | ||
|
|
7f1f286a7d | ||
|
|
a3e354cea9 | ||
|
|
e3fd75e570 | ||
|
|
73537d8671 | ||
|
|
4150ab0666 | ||
|
|
07977124fe |
@@ -14,4 +14,4 @@
|
||||
7. 任何单位或个人不得在未经本人书面授权的情况下对本项目本身申请相关的知识产权。
|
||||
8. 如果本声明的任何部分被认为无效或不可执行,则该部分将被解释为反映本人的初衷,其余部分仍具有完全效力。不可执行的部分声明,并不构成我们放弃执行该声明的权利。
|
||||
9. 本人有权随时对本声明条款及附件内容进行单方面的变更,并以消息推送、网页公告等方式予以公布,公布后立即自动生效,无需另行单独通知;若您在本声明内容公告变更后继续使用的,表示您已充分阅读、理解并接受修改后的声明内容。
|
||||
10. 本人对本声明拥有最终解释权。
|
||||
10. 本人保留对本声明的最终解释权。
|
||||
|
||||
82
README.md
@@ -3,8 +3,7 @@
|
||||
</h1>
|
||||
|
||||
`orion-ops-pro`
|
||||
是一款现代化、高颜值的一站式智能运维管理平台,集资产管理、资产授权、批量执行、计划任务、Web终端、WebSftp、角色管理、系统管理等功能于一体,致力于简化运维团队的治理工作。它是基于 `orion-ops`
|
||||
的产品思路进行重构,技术架构升级,并优化了交互逻辑,让操作更快捷更友好。
|
||||
是一款现代化、高颜值的一站式智能运维管理平台,集资产管理、资产授权、批量执行、计划任务、WebShell、WebSftp、角色管理、系统管理等功能于一体,致力于简化运维团队的治理工作。
|
||||
|
||||
<p style="text-align: left">
|
||||
<a target="_blank" style="text-decoration: none" href="https://app.codacy.com/gh/lijiahangmax/orion-ops-pro/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade">
|
||||
@@ -22,45 +21,43 @@
|
||||
<a target="_blank" style="text-decoration: none" href="https://gitee.com/lijiahangmax/orion-ops-pro/members">
|
||||
<img src="https://gitee.com/lijiahangmax/orion-ops-pro/badge/fork.svg?theme=dark" alt="fork"/>
|
||||
</a>
|
||||
<!-- <a target="_blank" style="text-decoration: none" href="https://github.com/lijiahangmax/orion-ops-pro">
|
||||
<a target="_blank" style="text-decoration: none" href="https://github.com/lijiahangmax/orion-ops-pro">
|
||||
<img src="https://img.shields.io/github/stars/lijiahangmax/orion-ops-pro.svg?style=social" alt="star"/>
|
||||
</a> -->
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<br/>
|
||||
当前版本: **1.0.5**
|
||||
|
||||
当前版本: **1.0.4**
|
||||
github: https://github.com/lijiahangmax/orion-ops-pro
|
||||
gitee: https://gitee.com/lijiahangmax/orion-ops-pro
|
||||
文档: https://lijiahangmax.gitee.io/orion-ops-pro/#/
|
||||
demo: http://101.43.254.243:1081/
|
||||
**github:** https://github.com/lijiahangmax/orion-ops-pro
|
||||
**gitee:** https://gitee.com/lijiahangmax/orion-ops-pro
|
||||
**文档:** https://lijiahangmax.gitee.io/orion-ops-pro/#/
|
||||
**demo:** http://101.43.254.243:1081/
|
||||
|
||||
演示账号: `admin`
|
||||
演示密码: `admin`
|
||||
⭐ 体验后可以点一下 `star` 这对我很重要
|
||||
📞 合作/功能定制请联系底部 备注: '定制'
|
||||
⭐ 体验后可以点一下 `star` 这对我很重要!
|
||||
🌈 如果本项目对你有帮助请帮忙推广一下 让更多的人知道此项目!
|
||||
📞 合作/功能定制请联系底部 备注: '合作'
|
||||
|
||||
## 特性
|
||||
|
||||
* 易用便捷: 极简配置, 开箱即用, 支持 Docker 部署方式。
|
||||
* 资产管理: 支持灵活配置主机分组, 实现对主机、秘钥和身份的统一管理。
|
||||
* 资产授权: 可将资产数据授权给指定角色和用户, 确保数据安全性。
|
||||
* 权限控制: 全面管理用户角色, 支持动态菜单配置和强制下线等功能。
|
||||
* 在线终端: 提供便捷的在线 Web 终端服务, 支持快捷命令、自定义快捷键和主题风格。
|
||||
* 文件管理: 实现远程主机大文件的批量上传、下载和在线编辑等操作。
|
||||
* 批量操作: 支持远程主机批量执行 shell 命令。
|
||||
* 计划任务: 支持配置 cron 表达式, 定时执行主机 shell 命令。
|
||||
* 操作日志: 记录用户操作日志,确保操作可追溯, 提高系统安全性。
|
||||
* 可扩展性: 前后端代码规范统一、代码质量高、健壮且易于阅读和扩展。
|
||||
* **快速稳定**: 使用全新的系统架构, 提高系统性能以及稳定性。
|
||||
* **交互友好**: 对与用户的交互进行了细致化的打磨, 操作更加方便快捷。
|
||||
* **资产管理**: 支持对资产进行分组, 实现对主机、秘钥和身份的统一管理和授权。
|
||||
* **权限控制**: 全面管理用户角色, 支持动态菜单配置和强制下线等功能。
|
||||
* **在线终端**: 提供便捷的在线 Web 终端服务, 支持快捷命令、自定义快捷键和主题风格。
|
||||
* **文件管理**: 实现远程主机大文件的批量上传、下载和在线编辑等操作。
|
||||
* **批量操作**: 支持远程主机批量执行主机命令。
|
||||
* **计划任务**: 支持配置 cron 表达式, 定时执行主机命令。
|
||||
* **操作审计**: 记录用户操作日志,确保操作可追溯, 提高系统安全性。
|
||||
|
||||
## 快速开始
|
||||
|
||||
docker安装: https://lijiahangmax.gitee.io/orion-ops-pro/#/quickstart/docker-install
|
||||
安装文档: https://lijiahangmax.gitee.io/orion-ops-pro/#/quickstart/install
|
||||
开发文档: https://lijiahangmax.gitee.io/orion-ops-pro/#/advance/dev
|
||||
操作手册: https://lijiahangmax.gitee.io/orion-ops-pro/#/operator/asset
|
||||
常见问题: https://lijiahangmax.gitee.io/orion-ops-pro/#/quickstart/faq
|
||||
roadmap: https://lijiahangmax.gitee.io/orion-ops-pro/#/about/roadmap
|
||||
* [docker安装](https://lijiahangmax.gitee.io/orion-ops-pro/#/quickstart/docker-install)
|
||||
* [普通安装](https://lijiahangmax.gitee.io/orion-ops-pro/#/quickstart/install)
|
||||
* [更新日志](https://lijiahangmax.gitee.io/orion-ops-pro/#/about/change-log)
|
||||
* [操作手册](https://lijiahangmax.gitee.io/orion-ops-pro/#/operator/asset)
|
||||
* [常见问题](https://lijiahangmax.gitee.io/orion-ops-pro/#/quickstart/faq)
|
||||
|
||||
## 技术栈
|
||||
|
||||
@@ -71,49 +68,32 @@ roadmap: https://lijiahangmax.gitee.io/orion-ops-pro/#/about/roadmap
|
||||
* Vue3
|
||||
* Arco Design
|
||||
|
||||
## 功能预览
|
||||
|
||||
> 工作台
|
||||
|
||||

|
||||
|
||||
> 资产管理
|
||||
|
||||

|
||||

|
||||
## 主要功能预览
|
||||
|
||||
> 主机终端
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
> 批量执行
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
> 计划任务
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
> 用户管理
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
> 系统管理
|
||||
|
||||

|
||||

|
||||
|
||||
## 联系我
|
||||
|
||||
<div style="display: flex;">
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
version: '3.3'
|
||||
services:
|
||||
orion-ops-pro:
|
||||
image: registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-ops-pro:1.0.4
|
||||
image: registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-ops-pro:1.0.5
|
||||
ports:
|
||||
- 1081:80
|
||||
environment:
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
mv ../../orion-ops-launch/target/orion-ops-launch.jar ./
|
||||
mv ../../orion-ops-ui/dist ./dist
|
||||
docker build -t orion-ops-pro:1.0.4 .
|
||||
docker build -t orion-ops-pro:1.0.5 .
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
7. 任何单位或个人不得在未经本人书面授权的情况下对本项目本身申请相关的知识产权。
|
||||
8. 如果本声明的任何部分被认为无效或不可执行,则该部分将被解释为反映本人的初衷,其余部分仍具有完全效力。不可执行的部分声明,并不构成我们放弃执行该声明的权利。
|
||||
9. 本人有权随时对本声明条款及附件内容进行单方面的变更,并以消息推送、网页公告等方式予以公布,公布后立即自动生效,无需另行单独通知;若您在本声明内容公告变更后继续使用的,表示您已充分阅读、理解并接受修改后的声明内容。
|
||||
10. 本人对本声明拥有最终解释权。
|
||||
10. 本人保留对本声明的最终解释权。
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
</h1>
|
||||
|
||||
`orion-ops-pro`
|
||||
是一款现代化、高颜值的一站式智能运维管理平台,集资产管理、资产授权、批量执行、计划任务、Web终端、WebSftp、角色管理、系统管理等功能于一体,致力于简化运维团队的治理工作。它是基于 `orion-ops`
|
||||
的产品思路进行重构,技术架构升级,并优化了交互逻辑,让操作更快捷更友好。
|
||||
是一款现代化、高颜值的一站式智能运维管理平台,集资产管理、资产授权、批量执行、计划任务、WebShell、WebSftp、角色管理、系统管理等功能于一体,致力于简化运维团队的治理工作。
|
||||
|
||||
<p style="text-align: left">
|
||||
<a target="_blank" style="text-decoration: none" href="https://app.codacy.com/gh/lijiahangmax/orion-ops-pro/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade">
|
||||
@@ -22,45 +21,43 @@
|
||||
<a target="_blank" style="text-decoration: none" href="https://gitee.com/lijiahangmax/orion-ops-pro/members">
|
||||
<img src="https://gitee.com/lijiahangmax/orion-ops-pro/badge/fork.svg?theme=dark" alt="fork"/>
|
||||
</a>
|
||||
<!-- <a target="_blank" style="text-decoration: none" href="https://github.com/lijiahangmax/orion-ops-pro">
|
||||
<a target="_blank" style="text-decoration: none" href="https://github.com/lijiahangmax/orion-ops-pro">
|
||||
<img src="https://img.shields.io/github/stars/lijiahangmax/orion-ops-pro.svg?style=social" alt="star"/>
|
||||
</a> -->
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<br/>
|
||||
当前版本: **1.0.5**
|
||||
|
||||
当前版本: **1.0.4**
|
||||
github: https://github.com/lijiahangmax/orion-ops-pro
|
||||
gitee: https://gitee.com/lijiahangmax/orion-ops-pro
|
||||
文档: https://lijiahangmax.gitee.io/orion-ops-pro/#/
|
||||
demo: http://101.43.254.243:1081/
|
||||
**github:** https://github.com/lijiahangmax/orion-ops-pro
|
||||
**gitee:** https://gitee.com/lijiahangmax/orion-ops-pro
|
||||
**文档:** https://lijiahangmax.gitee.io/orion-ops-pro/#/
|
||||
**demo:** http://101.43.254.243:1081/
|
||||
|
||||
演示账号: `admin`
|
||||
演示密码: `admin`
|
||||
⭐ 体验后可以点一下 `star` 这对我很重要
|
||||
⭐ 体验后可以点一下 `star` 这对我很重要!
|
||||
🌈 如果本项目对你有帮助请帮忙推广一下 让更多的人知道此项目!
|
||||
📞 合作/功能定制请联系底部 备注: '合作'
|
||||
|
||||
## 特性
|
||||
|
||||
* 易用便捷: 极简配置, 开箱即用, 支持 Docker 部署方式。
|
||||
* 资产管理: 支持灵活配置主机分组, 实现对主机、秘钥和身份的统一管理。
|
||||
* 资产授权: 可将资产数据授权给指定角色和用户, 确保数据安全性。
|
||||
* 权限控制: 全面管理用户角色, 支持动态菜单配置和强制下线等功能。
|
||||
* 在线终端: 提供便捷的在线 Web 终端服务, 支持快捷命令、自定义快捷键和主题风格。
|
||||
* 文件管理: 实现远程主机大文件的批量上传、下载和在线编辑等操作。
|
||||
* 批量操作: 支持远程主机批量执行 shell 命令。
|
||||
* 计划任务: 支持配置 cron 表达式, 定时执行主机 shell 命令。
|
||||
* 操作日志: 记录用户操作日志,确保操作可追溯, 提高系统安全性。
|
||||
* 可扩展性: 前后端代码规范统一、代码质量高、健壮且易于阅读和扩展。
|
||||
* **快速稳定**: 使用全新的系统架构, 提高系统性能以及稳定性。
|
||||
* **交互友好**: 对与用户的交互进行了细致化的打磨, 操作更加方便快捷。
|
||||
* **资产管理**: 支持对资产进行分组, 实现对主机、秘钥和身份的统一管理和授权。
|
||||
* **权限控制**: 全面管理用户角色, 支持动态菜单配置和强制下线等功能。
|
||||
* **在线终端**: 提供便捷的在线 Web 终端服务, 支持快捷命令、自定义快捷键和主题风格。
|
||||
* **文件管理**: 实现远程主机大文件的批量上传、下载和在线编辑等操作。
|
||||
* **批量操作**: 支持远程主机批量执行主机命令。
|
||||
* **计划任务**: 支持配置 cron 表达式, 定时执行主机命令。
|
||||
* **操作审计**: 记录用户操作日志,确保操作可追溯, 提高系统安全性。
|
||||
|
||||
## 快速开始
|
||||
|
||||
docker安装: https://lijiahangmax.gitee.io/orion-ops-pro/#/quickstart/docker-install
|
||||
安装文档: https://lijiahangmax.gitee.io/orion-ops-pro/#/quickstart/install
|
||||
开发文档: https://lijiahangmax.gitee.io/orion-ops-pro/#/advance/dev
|
||||
操作手册: https://lijiahangmax.gitee.io/orion-ops-pro/#/operator/asset
|
||||
常见问题: https://lijiahangmax.gitee.io/orion-ops-pro/#/quickstart/faq
|
||||
roadmap: https://lijiahangmax.gitee.io/orion-ops-pro/#/about/roadmap
|
||||
* [docker安装](https://lijiahangmax.gitee.io/orion-ops-pro/#/quickstart/docker-install)
|
||||
* [普通安装](https://lijiahangmax.gitee.io/orion-ops-pro/#/quickstart/install)
|
||||
* [更新日志](https://lijiahangmax.gitee.io/orion-ops-pro/#/about/change-log)
|
||||
* [操作手册](https://lijiahangmax.gitee.io/orion-ops-pro/#/operator/asset)
|
||||
* [常见问题](https://lijiahangmax.gitee.io/orion-ops-pro/#/quickstart/faq)
|
||||
|
||||
## 技术栈
|
||||
|
||||
@@ -71,25 +68,15 @@ roadmap: https://lijiahangmax.gitee.io/orion-ops-pro/#/about/roadmap
|
||||
* Vue3
|
||||
* Arco Design
|
||||
|
||||
## 功能预览
|
||||
|
||||
> 工作台
|
||||
|
||||

|
||||
|
||||
> 资产管理
|
||||
|
||||

|
||||

|
||||
## 主要功能预览
|
||||
|
||||
> 主机终端
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
> 批量执行
|
||||
|
||||
@@ -101,19 +88,12 @@ roadmap: https://lijiahangmax.gitee.io/orion-ops-pro/#/about/roadmap
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
> 用户管理
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
> 系统管理
|
||||
|
||||

|
||||

|
||||
|
||||
## 联系我
|
||||
|
||||
<div style="display: flex;">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# orion-ops-pro <small>1.0.4</small>
|
||||
# orion-ops-pro <small>1.0.5</small>
|
||||
|
||||
> 一款开箱即用的运维平台。
|
||||
|
||||
|
||||
@@ -1,6 +1,32 @@
|
||||
> 版本号严格遵循 Semver 规范。
|
||||
|
||||
⚡ 注意: 应用不支持跨版本升级, 可以进行多次升级
|
||||
* ⚡ **sql 脚本可以在 adminer 中执行。**
|
||||
* ⚡ **应用不支持跨版本升级, 可以进行多次升级。**
|
||||
|
||||
## v1.0.5
|
||||
|
||||
`2024-04-22` `release`
|
||||
|
||||
* 🐞 修复 用户列表用户名显示错误
|
||||
* 🐞 修复 主机分组页面无法编辑的问题
|
||||
* 🐞 修复 资产授权时提示数据发生变更的问题
|
||||
* 🐞 修复 删除资产时授权记录未删除的问题
|
||||
* 🐞 修复 命令执行权限控制失效的问题
|
||||
* 🌈 新增 定时删除未引用的 `tag`
|
||||
* 🌈 新增 执行命令时可使用脚本文件执行
|
||||
* 🌈 新增 主机身份添加类型字段
|
||||
* 🔨 优化 文件传输列表进度显示
|
||||
* 🔨 优化 命令执行日志持续时间
|
||||
* 🔨 优化 命令执行添加内置参数
|
||||
* 🔨 优化 tracker 监听文件可配置 `app.tracker`
|
||||
* 🔨 优化 sftp 上传文件重复处理可配置 `app.sftp`
|
||||
* 🔨 优化 用户状态调整交互逻辑
|
||||
* 🔨 优化 角色状态调整交互逻辑
|
||||
* 🔨 优化 优化资产授权交互逻辑
|
||||
* 🔨 优化 SFTP 交互逻辑
|
||||
* 🧹 删除 用户锁定状态
|
||||
|
||||
[如何升级](/update/v1.0.5.md)
|
||||
|
||||
## v1.0.4
|
||||
|
||||
@@ -69,7 +95,7 @@
|
||||
* 🌈 新增 主机连接日志删除/清理
|
||||
* 🌈 新增 用户操作日志日志删除/清理
|
||||
* 🌈 新增 用户操作日志日志删除/清理
|
||||
* 🔨 优化 用户锁定次数/时间可配置
|
||||
* 🔨 优化 用户锁定次数/时间可配置 `app.authentication`
|
||||
|
||||
[如何升级](/update/v1.0.1.md)
|
||||
|
||||
|
||||
@@ -1,24 +1,18 @@
|
||||
## 功能排期 ⏳
|
||||
## 功能排期
|
||||
|
||||
* tracker 使用配置文件
|
||||
* 文件重复删除/重命名 可配置
|
||||
* 定时删除未引用的 tag
|
||||
* 管理员也需要自行授权资产
|
||||
* 使用文件执行命令
|
||||
* 主机身份类型
|
||||
* 文件夹书签
|
||||
* 默认主机
|
||||
* 批量上传
|
||||
* 优化文件传输列表进度显示
|
||||
* 终端断开连接后回车重新连接
|
||||
* 文件夹书签
|
||||
* 站内消息
|
||||
* 终端背景图片
|
||||
* 资产授权 UI 改版
|
||||
* RDP 远程桌面
|
||||
* 接入 config 后端动态配置
|
||||
* 文档中巡检模板
|
||||
* 批量执行 模板 定时任务 配置是否使用文件执行
|
||||
* 导入快捷命令
|
||||
* 导入命令模板
|
||||
* 使用 vite press 开发文档
|
||||
|
||||
## 已知问题 🐞
|
||||
## 已知问题
|
||||
|
||||
* 顶部菜单折叠宽度计算有问题 (arco 框架内问题)
|
||||
|
||||
|
Before Width: | Height: | Size: 106 KiB |
|
Before Width: | Height: | Size: 100 KiB |
|
Before Width: | Height: | Size: 120 KiB After Width: | Height: | Size: 131 KiB |
|
Before Width: | Height: | Size: 111 KiB After Width: | Height: | Size: 120 KiB |
|
Before Width: | Height: | Size: 127 KiB |
|
Before Width: | Height: | Size: 156 KiB |
BIN
docs/assert/img/terminal_collections.png
Normal file
|
After Width: | Height: | Size: 73 KiB |
|
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 148 KiB |
|
Before Width: | Height: | Size: 106 KiB |
|
Before Width: | Height: | Size: 94 KiB After Width: | Height: | Size: 88 KiB |
|
Before Width: | Height: | Size: 91 KiB |
|
Before Width: | Height: | Size: 158 KiB |
|
Before Width: | Height: | Size: 88 KiB |
|
Before Width: | Height: | Size: 136 KiB |
@@ -75,13 +75,19 @@
|
||||
| source | 执行来源 (BATCH/JOB) |
|
||||
| sourceId | 执行来源id (JOB特有) |
|
||||
| seq | 执行序列 (JOB特有) |
|
||||
| userId | 执行用户id |
|
||||
| username | 执行用户名 |
|
||||
| execId | 执行记录id |
|
||||
| hostId | 执行主机id |
|
||||
| hostName | 执行主机名称 |
|
||||
| hostCode | 执行主机编码 |
|
||||
| hostAddress | 执行主机地址 |
|
||||
| userId | 执行用户id |
|
||||
| username | 执行用户名 |
|
||||
| hostUsername | 执行主机用户名 |
|
||||
| osType | 执行主机系统版本 |
|
||||
| port | SSH 端口 |
|
||||
| charset | SSH 编码集 |
|
||||
| scriptExec | 是否使用脚本执行 |
|
||||
| scriptPath | 脚本文件路径 |
|
||||
| uuid | 生成任务维度 uuid |
|
||||
| uuidShort | 生成任务维度 uuid 无 '-' |
|
||||
| hostUuid | 生成机器维度 uuid |
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
> ##### 2. 是否支持维护 Windows 主机?
|
||||
|
||||
支持, 但是 Windows 的 ssh 命令兼容性不好, 一切需要执行ssh命令的地方都不友好
|
||||
如: 批量执行, 调度任务兼容性非常不友好
|
||||
|
||||
> ##### 3. 执行命令时为什么会找不到环境变量?
|
||||
|
||||
|
||||
@@ -3,9 +3,55 @@
|
||||
> sql 脚本 - DDL
|
||||
|
||||
```sql
|
||||
ALTER TABLE `system_user`
|
||||
MODIFY COLUMN `status` tinyint(0) NULL DEFAULT 1 COMMENT '用户状态 0停用 1启用' AFTER `email`;
|
||||
|
||||
ALTER TABLE `host_identity`
|
||||
ADD COLUMN `type` char(12) NULL COMMENT '类型' AFTER `name`;
|
||||
|
||||
ALTER TABLE `exec_log`
|
||||
ADD COLUMN `script_exec` tinyint(0) NULL DEFAULT 0 COMMENT '是否使用脚本执行' AFTER `timeout`;
|
||||
|
||||
ALTER TABLE `exec_job`
|
||||
ADD COLUMN `script_exec` tinyint(0) NULL DEFAULT 0 COMMENT '是否使用脚本执行' AFTER `timeout`;
|
||||
|
||||
ALTER TABLE `exec_template`
|
||||
ADD COLUMN `script_exec` tinyint(0) NULL DEFAULT 0 COMMENT '是否使用脚本执行' AFTER `timeout`;
|
||||
|
||||
ALTER TABLE `exec_host_log`
|
||||
ADD COLUMN `script_path` varchar(512) NULL COMMENT '脚本路径' AFTER `log_path`;
|
||||
```
|
||||
|
||||
> sql 脚本 - DML
|
||||
|
||||
```sql
|
||||
-- 初始化主机身份类型
|
||||
UPDATE `host_identity` SET type = IF(key_id IS NOT NULL, 'KEY', 'PASSWORD');
|
||||
-- 重新设置用户状态
|
||||
UPDATE `system_user` SET status = 0 WHERE status = 2;
|
||||
DELETE FROM `dict_value` WHERE id = 19;
|
||||
-- 设置主机配置中的 osType
|
||||
UPDATE host_config SET config = JSON_SET(config, '$.osType', 'LINUX') WHERE type = 'ssh' AND deleted = 0;
|
||||
-- 重新设置额外数据
|
||||
UPDATE data_extra alias
|
||||
LEFT JOIN data_extra color
|
||||
ON alias.user_id = color.user_id
|
||||
AND alias.rel_id = color.rel_id
|
||||
AND alias.type= color.type
|
||||
AND color.item = 'color'
|
||||
SET alias.item = 'label',
|
||||
alias.value = JSON_OBJECT('alias', JSON_EXTRACT(alias.value, '$.value'), 'color', JSON_EXTRACT(color.value, '$.color'))
|
||||
WHERE alias.item = 'alias';
|
||||
-- 删除 color 数据
|
||||
DELETE FROM data_extra WHERE type = 'HOST' AND item = 'color';
|
||||
-- 初始化字典项
|
||||
DELETE FROM dict_key WHERE id >= 37;
|
||||
INSERT INTO `dict_key` VALUES (37, 'hostIdentityType', 'STRING', '[{\"name\": \"color\", \"type\": \"COLOR\"}]', '主机身份类型', '2024-04-16 17:15:31', '2024-04-16 17:15:31', '2', '2', 0);
|
||||
INSERT INTO `dict_key` VALUES (38, 'hostSshOsType', 'STRING', '[]', '主机系统类型', '2024-04-16 22:18:59', '2024-04-16 22:30:59', '1', '1', 0);
|
||||
-- 初始化字典值
|
||||
DELETE FROM dict_value WHERE id >= 270;
|
||||
INSERT INTO `dict_value` VALUES (270, 37, 'hostIdentityType', 'PASSWORD', '密码', '{\"color\": \"purple\"}', 10, '2024-04-16 17:17:49', '2024-04-16 17:17:49', '2', '2', 0);
|
||||
INSERT INTO `dict_value` VALUES (271, 37, 'hostIdentityType', 'KEY', '秘钥', '{\"color\": \"arcoblue\"}', 20, '2024-04-16 17:18:12', '2024-04-16 17:18:12', '2', '2', 0);
|
||||
INSERT INTO `dict_value` VALUES (272, 38, 'hostSshOsType', 'LINUX', 'linux', '{}', 10, '2024-04-16 22:19:25', '2024-04-16 22:30:59', '1', '1', 0);
|
||||
INSERT INTO `dict_value` VALUES (273, 38, 'hostSshOsType', 'WINDOWS', 'windows', '{}', 20, '2024-04-16 22:19:39', '2024-04-16 22:30:59', '1', '1', 0);
|
||||
```
|
||||
|
||||
11
docs/update/v1.0.6.md
Normal file
@@ -0,0 +1,11 @@
|
||||
## v1.0.6
|
||||
|
||||
> sql 脚本 - DDL
|
||||
|
||||
```sql
|
||||
```
|
||||
|
||||
> sql 脚本 - DML
|
||||
|
||||
```sql
|
||||
```
|
||||
@@ -14,7 +14,7 @@
|
||||
<url>https://github.com/lijiahangmax/orion-ops-pro</url>
|
||||
|
||||
<properties>
|
||||
<revision>1.0.4</revision>
|
||||
<revision>1.0.5</revision>
|
||||
<spring.boot.version>2.7.17</spring.boot.version>
|
||||
<spring.boot.admin.version>2.7.15</spring.boot.admin.version>
|
||||
<flatten.maven.plugin.version>1.5.0</flatten.maven.plugin.version>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.orion.ops.framework.common.constant;
|
||||
|
||||
import com.orion.lang.constant.OrionConst;
|
||||
|
||||
/**
|
||||
* 项目常量
|
||||
*
|
||||
@@ -7,12 +9,14 @@ package com.orion.ops.framework.common.constant;
|
||||
* @version 1.0.0
|
||||
* @since 2023/6/19 18:56
|
||||
*/
|
||||
public interface OrionOpsProConst {
|
||||
public interface AppConst extends OrionConst {
|
||||
|
||||
/**
|
||||
* 同 ${orion.version} 迭代时候需要手动更改
|
||||
*/
|
||||
String VERSION = "1.0.4";
|
||||
String VERSION = "1.0.5";
|
||||
|
||||
String ORION_OPS_PRO = "orion-ops-pro";
|
||||
|
||||
String GITHUB = "https://github.com/lijiahangmax/orion-ops-pro";
|
||||
|
||||
@@ -35,6 +35,4 @@ public interface Const extends com.orion.lang.constant.Const, FieldConst, CnCons
|
||||
|
||||
String SYSTEM_USERNAME = "system";
|
||||
|
||||
String ERROR_LOG = "error.log";
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public enum ErrorCode implements CodeInfo {
|
||||
|
||||
PAYLOAD_TOO_LARGE(413, "请求过大"),
|
||||
|
||||
LOCKED(423, "当前已被锁定"),
|
||||
LOCKED(423, "当前操作已被锁定"),
|
||||
|
||||
TOO_MANY_REQUESTS(429, "请求过快"),
|
||||
|
||||
@@ -48,11 +48,9 @@ public enum ErrorCode implements CodeInfo {
|
||||
|
||||
USER_DISABLED(700, "当前用户已禁用"),
|
||||
|
||||
USER_LOCKED(701, "当前用户已被锁定"),
|
||||
USER_OTHER_DEVICE_LOGIN(701, "该账号于 {} 已在其他设备登录 {}({})"),
|
||||
|
||||
OTHER_DEVICE_LOGIN(702, "该账号于 {} 已在其他设备登录 {}({})"),
|
||||
|
||||
SESSION_OFFLINE(703, "该账号于 {} 已被强制下线 {}({})"),
|
||||
USER_OFFLINE(702, "该账号于 {} 已被强制下线 {}({})"),
|
||||
|
||||
// -------------------- 自定义 - 通用 --------------------
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.orion.ops.framework.common.constant;
|
||||
|
||||
/**
|
||||
* 路径常量
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/4/17 10:35
|
||||
*/
|
||||
public interface PathConst {
|
||||
|
||||
String ERROR_LOG = "error.log";
|
||||
|
||||
String EXEC = "exec";
|
||||
|
||||
String SCRIPT = "script";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.orion.ops.framework.common.utils;
|
||||
|
||||
import com.orion.lang.utils.Objects1;
|
||||
import com.orion.ops.framework.common.constant.AppConst;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
|
||||
/**
|
||||
* 路径工具类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/4/17 10:28
|
||||
*/
|
||||
public class PathUtils {
|
||||
|
||||
private PathUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户根目录
|
||||
*
|
||||
* @param isWindows isWindows
|
||||
* @param username 用户名
|
||||
* @return 用户目录
|
||||
*/
|
||||
public static String getHomePath(boolean isWindows, String username) {
|
||||
if (isWindows) {
|
||||
// windows
|
||||
return "C:/Users/" + username;
|
||||
} else {
|
||||
// linux
|
||||
if (Const.ROOT.equals(username)) {
|
||||
return "/" + Const.ROOT;
|
||||
} else {
|
||||
return "/home/" + username;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取应用路径
|
||||
*
|
||||
* @param isWindows isWindows
|
||||
* @param username username
|
||||
* @return path
|
||||
*/
|
||||
public static String getAppPath(boolean isWindows, String username) {
|
||||
return getHomePath(isWindows, username)
|
||||
+ "/" + AppConst.ORION
|
||||
+ "/" + AppConst.ORION_OPS_PRO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建应用路径
|
||||
*
|
||||
* @param isWindows isWindows,
|
||||
* @param username username
|
||||
* @param paths paths
|
||||
* @return path
|
||||
*/
|
||||
public static String buildAppPath(boolean isWindows, String username, Object... paths) {
|
||||
StringBuilder path = new StringBuilder(getAppPath(isWindows, username));
|
||||
for (Object o : paths) {
|
||||
path.append("/").append(Objects1.toString(o));
|
||||
}
|
||||
return path.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import com.orion.lang.utils.io.Files1;
|
||||
import com.orion.lang.utils.reflect.BeanMap;
|
||||
import com.orion.lang.utils.reflect.Fields;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
import com.orion.ops.framework.common.constant.OrionOpsProConst;
|
||||
import com.orion.ops.framework.common.constant.AppConst;
|
||||
import com.orion.ops.framework.mybatis.core.generator.template.Table;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -97,7 +97,7 @@ public class CodeGeneratorEngine extends VelocityTemplateEngine {
|
||||
// http 注释标识
|
||||
objectMap.put("httpComment", "###");
|
||||
// 版本
|
||||
objectMap.put("version", OrionOpsProConst.VERSION);
|
||||
objectMap.put("version", AppConst.VERSION);
|
||||
// api 注释
|
||||
Map<String, String> apiComment = new HashMap<>(12);
|
||||
String comment = tableInfo.getComment();
|
||||
|
||||
@@ -20,8 +20,7 @@
|
||||
size="small"
|
||||
ref="formRef"
|
||||
label-align="right"
|
||||
:label-col-props="{ span: 6 }"
|
||||
:wrapper-col-props="{ span: 18 }"
|
||||
:auto-label-width="true"
|
||||
@keyup.enter="() => fetchCardData()">
|
||||
#foreach($field in ${table.fields})
|
||||
<!-- $field.comment -->
|
||||
|
||||
@@ -8,12 +8,11 @@
|
||||
:cancel-button-props="{ disabled: loading }"
|
||||
:on-before-ok="handlerOk"
|
||||
@cancel="handleClose">
|
||||
<a-spin class="full modal-form" :loading="loading">
|
||||
<a-spin class="full modal-form-small" :loading="loading">
|
||||
<a-form :model="formModel"
|
||||
ref="formRef"
|
||||
label-align="right"
|
||||
:label-col-props="{ span: 5 }"
|
||||
:wrapper-col-props="{ span: 18 }"
|
||||
:auto-label-width="true"
|
||||
:rules="formRules">
|
||||
#foreach($field in ${table.fields})
|
||||
#if("$field.propertyName" != "id")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<a-modal v-model:visible="visible"
|
||||
body-class="modal-form"
|
||||
body-class="modal-form-large"
|
||||
title-align="start"
|
||||
:title="title"
|
||||
:top="80"
|
||||
@@ -16,8 +16,7 @@
|
||||
<a-form :model="formModel"
|
||||
ref="formRef"
|
||||
label-align="right"
|
||||
:label-col-props="{ span: 5 }"
|
||||
:wrapper-col-props="{ span: 18 }"
|
||||
:auto-label-width="true"
|
||||
:rules="formRules">
|
||||
#foreach($field in ${table.fields})
|
||||
#if("$field.propertyName" != "id")
|
||||
|
||||
@@ -84,8 +84,7 @@ spring:
|
||||
tablePrefix: QRTZ_
|
||||
misfireThreshold: 60000
|
||||
clusterCheckinInterval: 5000
|
||||
# 打开群集功能
|
||||
isClustered: false
|
||||
isClustered: true
|
||||
#连接池
|
||||
threadPool:
|
||||
class: org.quartz.simpl.SimpleThreadPool
|
||||
@@ -152,6 +151,7 @@ logging:
|
||||
|
||||
# 应用配置
|
||||
app:
|
||||
# 认证配置
|
||||
authentication:
|
||||
# 是否允许多端登录
|
||||
allow-multi-device: true
|
||||
@@ -163,6 +163,20 @@ app:
|
||||
login-failed-lock-count: 5
|
||||
# 登录失败锁定时间 (分)
|
||||
login-failed-lock-time: 30
|
||||
# tracker 配置
|
||||
tracker:
|
||||
# 加载偏移量 (行)
|
||||
offset: 300
|
||||
# 延迟时间 (ms)
|
||||
delay: 100
|
||||
# 文件未找到等待次数
|
||||
wait-times: 100
|
||||
# sftp 配置
|
||||
sftp:
|
||||
# 上传文件时 文件存在是否备份
|
||||
upload-present-backup: true
|
||||
# 备份文件名称
|
||||
backup-file-name: bk_${fileName}_${timestamp}
|
||||
|
||||
# orion framework config
|
||||
orion:
|
||||
|
||||
@@ -6,6 +6,7 @@ Authorization: {{token}}
|
||||
{
|
||||
"description": 1,
|
||||
"timeout": 10,
|
||||
"scriptExec": 0,
|
||||
"command": "echo 这是日志@{{ hostAddress }}\nsleep 1\necho @{{ hostName }}",
|
||||
"parameterSchema": "[]",
|
||||
"hostIdList": [1]
|
||||
|
||||
@@ -6,7 +6,8 @@ Authorization: {{token}}
|
||||
{
|
||||
"name": "测试 1",
|
||||
"expression": "0 */3 * * * ?",
|
||||
"timeout": "0",
|
||||
"timeout": 0,
|
||||
"scriptExec": 0,
|
||||
"command": "echo 123",
|
||||
"parameterSchema": "[]",
|
||||
"hostIdList": [1]
|
||||
@@ -22,7 +23,8 @@ Authorization: {{token}}
|
||||
"id": 5,
|
||||
"name": "测试 1",
|
||||
"expression": "0 */10 * * * ?",
|
||||
"timeout": "0",
|
||||
"timeout": 0,
|
||||
"scriptExec": 0,
|
||||
"command": "echo 123",
|
||||
"parameterSchema": "[]",
|
||||
"hostIdList": [
|
||||
|
||||
@@ -6,7 +6,8 @@ Authorization: {{token}}
|
||||
{
|
||||
"name": "",
|
||||
"command": "",
|
||||
"timeout": "",
|
||||
"timeout": 0,
|
||||
"scriptExec": 0,
|
||||
"parameterSchema": ""
|
||||
}
|
||||
|
||||
@@ -20,7 +21,8 @@ Authorization: {{token}}
|
||||
"id": "",
|
||||
"name": "",
|
||||
"command": "",
|
||||
"timeout": "",
|
||||
"timeout": 0,
|
||||
"scriptExec": 0,
|
||||
"parameterSchema": ""
|
||||
}
|
||||
|
||||
@@ -47,7 +49,8 @@ Authorization: {{token}}
|
||||
"id": "",
|
||||
"name": "",
|
||||
"command": "",
|
||||
"timeout": "",
|
||||
"timeout": 0,
|
||||
"scriptExec": 0,
|
||||
"parameterSchema": ""
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,3 @@
|
||||
### 修改主机别名
|
||||
PUT {{baseUrl}}/asset/host-extra/update-alias
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
"id": 1,
|
||||
"name": "alias"
|
||||
}
|
||||
|
||||
### 获取主机拓展信息
|
||||
GET {{baseUrl}}/asset/host-extra/get?hostId=1&item=ssh
|
||||
Authorization: {{token}}
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.orion.ops.module.asset.controller;
|
||||
import com.orion.ops.framework.log.core.annotation.IgnoreLog;
|
||||
import com.orion.ops.framework.log.core.enums.IgnoreLogMode;
|
||||
import com.orion.ops.framework.web.core.annotation.RestWrapper;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostAliasUpdateRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostExtraQueryRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostExtraUpdateRequest;
|
||||
import com.orion.ops.module.asset.service.HostExtraService;
|
||||
@@ -36,12 +35,6 @@ public class HostExtraController {
|
||||
@Resource
|
||||
private HostExtraService hostExtraService;
|
||||
|
||||
@PutMapping("/update-alias")
|
||||
@Operation(summary = "修改主机别名")
|
||||
public Integer updateHostAlias(@Validated @RequestBody HostAliasUpdateRequest request) {
|
||||
return hostExtraService.updateHostAlias(request);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获取主机拓展信息")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.orion.ops.module.asset.convert;
|
||||
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecCommandExecRequest;
|
||||
import com.orion.ops.module.asset.entity.dto.ExecCommandExecDTO;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecCommandRequest;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
@@ -17,6 +17,6 @@ public interface ExecConvert {
|
||||
|
||||
ExecConvert MAPPER = Mappers.getMapper(ExecConvert.class);
|
||||
|
||||
ExecCommandExecRequest to(ExecCommandRequest request);
|
||||
ExecCommandExecDTO to(ExecCommandRequest request);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.orion.ops.module.asset.define.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 应用 sftp 配置
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/4/15 22:00
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "app.sftp")
|
||||
public class AppSftpConfig {
|
||||
|
||||
/**
|
||||
* 上传文件时 文件存在是否备份
|
||||
*/
|
||||
private Boolean uploadPresentBackup;
|
||||
|
||||
/**
|
||||
* 备份文件名称
|
||||
*/
|
||||
private String backupFileName;
|
||||
|
||||
public AppSftpConfig() {
|
||||
this.uploadPresentBackup = true;
|
||||
this.backupFileName = "bk_${fileName}_${timestamp}";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.orion.ops.module.asset.define.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 应用 tracker 配置
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/4/15 22:00
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "app.tracker")
|
||||
public class AppTrackerConfig {
|
||||
|
||||
/**
|
||||
* 加载偏移量 (行)
|
||||
*/
|
||||
private Integer offset;
|
||||
|
||||
/**
|
||||
* 延迟时间 (ms)
|
||||
*/
|
||||
private Integer delay;
|
||||
|
||||
/**
|
||||
* 文件未找到等待次数
|
||||
*/
|
||||
private Integer waitTimes;
|
||||
|
||||
public AppTrackerConfig() {
|
||||
this.offset = 300;
|
||||
this.delay = 100;
|
||||
this.waitTimes = 100;
|
||||
}
|
||||
}
|
||||
@@ -25,9 +25,9 @@ public class ExecTemplateOperatorType extends InitializingOperatorTypes {
|
||||
@Override
|
||||
public OperatorType[] types() {
|
||||
return new OperatorType[]{
|
||||
new OperatorType(L, CREATE, "创建执行模板 ${name}"),
|
||||
new OperatorType(M, UPDATE, "更新执行模板 ${name}"),
|
||||
new OperatorType(H, DELETE, "删除执行模板 ${name}"),
|
||||
new OperatorType(L, CREATE, "创建执行模板 <sb>${name}</sb>"),
|
||||
new OperatorType(M, UPDATE, "更新执行模板 <sb>${name}</sb>"),
|
||||
new OperatorType(H, DELETE, "删除执行模板 <sb>${name}</sb>"),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,10 @@ public class ExecHostLogDO extends BaseDO {
|
||||
@TableField("log_path")
|
||||
private String logPath;
|
||||
|
||||
@Schema(description = "脚本路径")
|
||||
@TableField("script_path")
|
||||
private String scriptPath;
|
||||
|
||||
@Schema(description = "错误信息")
|
||||
@TableField("error_message")
|
||||
private String errorMessage;
|
||||
|
||||
@@ -46,6 +46,10 @@ public class ExecJobDO extends BaseDO {
|
||||
@TableField("timeout")
|
||||
private Integer timeout;
|
||||
|
||||
@Schema(description = "是否使用脚本执行")
|
||||
@TableField("script_exec")
|
||||
private Integer scriptExec;
|
||||
|
||||
@Schema(description = "执行命令")
|
||||
@TableField("command")
|
||||
private String command;
|
||||
|
||||
@@ -68,6 +68,10 @@ public class ExecLogDO extends BaseDO {
|
||||
@TableField("timeout")
|
||||
private Integer timeout;
|
||||
|
||||
@Schema(description = "是否使用脚本执行")
|
||||
@TableField("script_exec")
|
||||
private Integer scriptExec;
|
||||
|
||||
@Schema(description = "执行状态")
|
||||
@TableField("status")
|
||||
private String status;
|
||||
|
||||
@@ -42,6 +42,10 @@ public class ExecTemplateDO extends BaseDO {
|
||||
@TableField("timeout")
|
||||
private Integer timeout;
|
||||
|
||||
@Schema(description = "是否使用脚本执行")
|
||||
@TableField("script_exec")
|
||||
private Integer scriptExec;
|
||||
|
||||
@Schema(description = "参数定义")
|
||||
@TableField("parameter_schema")
|
||||
private String parameterSchema;
|
||||
|
||||
@@ -31,6 +31,10 @@ public class HostIdentityDO extends BaseDO {
|
||||
@TableField("name")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "类型")
|
||||
@TableField("type")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "用户名")
|
||||
@TableField("username")
|
||||
private String username;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.orion.ops.module.asset.entity.request.exec;
|
||||
package com.orion.ops.module.asset.entity.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -19,8 +19,8 @@ import java.util.List;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "ExecCommandExecRequest", description = "批量执行命令 请求对象")
|
||||
public class ExecCommandExecRequest {
|
||||
@Schema(name = "ExecCommandExecDTO", description = "批量执行命令对象")
|
||||
public class ExecCommandExecDTO {
|
||||
|
||||
@Schema(description = "执行用户id")
|
||||
private Long userId;
|
||||
@@ -43,6 +43,9 @@ public class ExecCommandExecRequest {
|
||||
@Schema(description = "超时时间")
|
||||
private Integer timeout;
|
||||
|
||||
@Schema(description = "是否使用脚本执行")
|
||||
private Integer scriptExec;
|
||||
|
||||
@Schema(description = "执行命令")
|
||||
private String command;
|
||||
|
||||
@@ -30,6 +30,9 @@ public class HostIdentityCacheDTO implements LongCacheIdModel, Serializable {
|
||||
@Schema(description = "名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "类型")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "用户名")
|
||||
private String username;
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.orion.ops.module.asset.entity.request.exec;
|
||||
|
||||
import com.orion.ops.framework.desensitize.core.annotation.Desensitize;
|
||||
import com.orion.ops.framework.desensitize.core.annotation.DesensitizeObject;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
@@ -19,6 +21,7 @@ import java.util.List;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@DesensitizeObject
|
||||
@Schema(name = "ExecCommandRequest", description = "批量执行命令 请求对象")
|
||||
public class ExecCommandRequest {
|
||||
|
||||
@@ -30,7 +33,12 @@ public class ExecCommandRequest {
|
||||
@Schema(description = "超时时间")
|
||||
private Integer timeout;
|
||||
|
||||
@NonNull
|
||||
@Schema(description = "是否使用脚本执行")
|
||||
private Integer scriptExec;
|
||||
|
||||
@NotBlank
|
||||
@Desensitize(toEmpty = true)
|
||||
@Schema(description = "执行命令")
|
||||
private String command;
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package com.orion.ops.module.asset.entity.request.exec;
|
||||
|
||||
import com.orion.ops.framework.desensitize.core.annotation.Desensitize;
|
||||
import com.orion.ops.framework.desensitize.core.annotation.DesensitizeObject;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.*;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
@@ -24,6 +23,7 @@ import java.util.List;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@DesensitizeObject
|
||||
@Schema(name = "ExecJobCreateRequest", description = "计划任务 创建请求对象")
|
||||
public class ExecJobCreateRequest implements Serializable {
|
||||
|
||||
@@ -43,7 +43,12 @@ public class ExecJobCreateRequest implements Serializable {
|
||||
@Schema(description = "超时时间")
|
||||
private Integer timeout;
|
||||
|
||||
@NonNull
|
||||
@Schema(description = "是否使用脚本执行")
|
||||
private Integer scriptExec;
|
||||
|
||||
@NotBlank
|
||||
@Desensitize(toEmpty = true)
|
||||
@Schema(description = "执行命令")
|
||||
private String command;
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package com.orion.ops.module.asset.entity.request.exec;
|
||||
|
||||
import com.orion.ops.framework.desensitize.core.annotation.Desensitize;
|
||||
import com.orion.ops.framework.desensitize.core.annotation.DesensitizeObject;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.*;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
@@ -24,6 +23,7 @@ import java.util.List;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@DesensitizeObject
|
||||
@Schema(name = "ExecJobUpdateRequest", description = "计划任务 更新请求对象")
|
||||
public class ExecJobUpdateRequest implements Serializable {
|
||||
|
||||
@@ -47,7 +47,12 @@ public class ExecJobUpdateRequest implements Serializable {
|
||||
@Schema(description = "超时时间")
|
||||
private Integer timeout;
|
||||
|
||||
@NonNull
|
||||
@Schema(description = "是否使用脚本执行")
|
||||
private Integer scriptExec;
|
||||
|
||||
@NotBlank
|
||||
@Desensitize(toEmpty = true)
|
||||
@Schema(description = "执行命令")
|
||||
private String command;
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.orion.ops.module.asset.entity.request.exec;
|
||||
|
||||
import com.orion.ops.framework.desensitize.core.annotation.Desensitize;
|
||||
import com.orion.ops.framework.desensitize.core.annotation.DesensitizeObject;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -22,6 +24,7 @@ import java.io.Serializable;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@DesensitizeObject
|
||||
@Schema(name = "ExecTemplateCreateRequest", description = "执行模板 创建请求对象")
|
||||
public class ExecTemplateCreateRequest implements Serializable {
|
||||
|
||||
@@ -33,6 +36,7 @@ public class ExecTemplateCreateRequest implements Serializable {
|
||||
private String name;
|
||||
|
||||
@NotBlank
|
||||
@Desensitize(toEmpty = true)
|
||||
@Schema(description = "命令")
|
||||
private String command;
|
||||
|
||||
@@ -40,6 +44,10 @@ public class ExecTemplateCreateRequest implements Serializable {
|
||||
@Schema(description = "超时时间秒 0不超时")
|
||||
private Integer timeout;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "是否使用脚本执行")
|
||||
private Integer scriptExec;
|
||||
|
||||
@Schema(description = "参数定义")
|
||||
private String parameterSchema;
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.orion.ops.module.asset.entity.request.exec;
|
||||
|
||||
import com.orion.ops.framework.desensitize.core.annotation.Desensitize;
|
||||
import com.orion.ops.framework.desensitize.core.annotation.DesensitizeObject;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -22,6 +24,7 @@ import java.io.Serializable;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@DesensitizeObject
|
||||
@Schema(name = "ExecTemplateUpdateRequest", description = "执行模板 更新请求对象")
|
||||
public class ExecTemplateUpdateRequest implements Serializable {
|
||||
|
||||
@@ -38,12 +41,17 @@ public class ExecTemplateUpdateRequest implements Serializable {
|
||||
|
||||
@NotBlank
|
||||
@Schema(description = "命令")
|
||||
@Desensitize(toEmpty = true)
|
||||
private String command;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "超时时间秒 0不超时")
|
||||
private Integer timeout;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "是否使用脚本执行")
|
||||
private Integer scriptExec;
|
||||
|
||||
@Schema(description = "参数定义")
|
||||
private String parameterSchema;
|
||||
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
package com.orion.ops.module.asset.entity.request.host;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 主机别名 更新请求对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-9-13 14:31
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "HostAliasUpdateRequest", description = "主机别名 更新请求对象")
|
||||
public class HostAliasUpdateRequest implements Serializable {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@Size(max = 32)
|
||||
@Schema(description = "别名")
|
||||
private String name;
|
||||
|
||||
}
|
||||
@@ -29,6 +29,11 @@ public class HostIdentityCreateRequest implements Serializable {
|
||||
@Schema(description = "名称")
|
||||
private String name;
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 12)
|
||||
@Schema(description = "类型")
|
||||
private String type;
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 128)
|
||||
@Schema(description = "用户名")
|
||||
|
||||
@@ -31,6 +31,10 @@ public class HostIdentityQueryRequest extends PageRequest {
|
||||
@Schema(description = "名称")
|
||||
private String name;
|
||||
|
||||
@Size(max = 12)
|
||||
@Schema(description = "类型")
|
||||
private String type;
|
||||
|
||||
@Size(max = 128)
|
||||
@Schema(description = "用户名")
|
||||
private String username;
|
||||
|
||||
@@ -34,6 +34,11 @@ public class HostIdentityUpdateRequest implements UpdatePasswordAction {
|
||||
@Schema(description = "名称")
|
||||
private String name;
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 12)
|
||||
@Schema(description = "类型")
|
||||
private String type;
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 128)
|
||||
@Schema(description = "用户名")
|
||||
|
||||
@@ -38,6 +38,9 @@ public class ExecJobVO implements Serializable {
|
||||
@Schema(description = "超时时间")
|
||||
private Integer timeout;
|
||||
|
||||
@Schema(description = "是否使用脚本执行")
|
||||
private Integer scriptExec;
|
||||
|
||||
@Schema(description = "执行命令")
|
||||
private String command;
|
||||
|
||||
|
||||
@@ -50,6 +50,9 @@ public class ExecLogVO implements Serializable {
|
||||
@Schema(description = "超时时间")
|
||||
private Integer timeout;
|
||||
|
||||
@Schema(description = "是否使用脚本执行")
|
||||
private Integer scriptExec;
|
||||
|
||||
@Schema(description = "执行状态")
|
||||
private String status;
|
||||
|
||||
|
||||
@@ -37,6 +37,9 @@ public class ExecTemplateVO implements Serializable {
|
||||
@Schema(description = "超时时间秒 0不超时")
|
||||
private Integer timeout;
|
||||
|
||||
@Schema(description = "是否使用脚本执行")
|
||||
private Integer scriptExec;
|
||||
|
||||
@Schema(description = "参数定义")
|
||||
private String parameterSchema;
|
||||
|
||||
|
||||
@@ -31,6 +31,9 @@ public class HostIdentityVO implements Serializable {
|
||||
@Schema(description = "名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "类型")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "用户名")
|
||||
private String username;
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ package com.orion.ops.module.asset.enums;
|
||||
import com.orion.ops.framework.common.handler.data.GenericsDataDefinition;
|
||||
import com.orion.ops.framework.common.handler.data.model.GenericsDataModel;
|
||||
import com.orion.ops.framework.common.handler.data.strategy.MapDataStrategy;
|
||||
import com.orion.ops.module.asset.handler.host.extra.model.HostColorExtraModel;
|
||||
import com.orion.ops.module.asset.handler.host.extra.model.HostLabelExtraModel;
|
||||
import com.orion.ops.module.asset.handler.host.extra.model.HostSshExtraModel;
|
||||
import com.orion.ops.module.asset.handler.host.extra.strategy.HostColorExtraStrategy;
|
||||
import com.orion.ops.module.asset.handler.host.extra.strategy.HostLabelExtraStrategy;
|
||||
import com.orion.ops.module.asset.handler.host.extra.strategy.HostSshExtraStrategy;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -27,9 +27,9 @@ public enum HostExtraItemEnum implements GenericsDataDefinition {
|
||||
SSH("ssh", HostSshExtraModel.class, HostSshExtraStrategy.class),
|
||||
|
||||
/**
|
||||
* 颜色额外配置
|
||||
* 标签额外配置
|
||||
*/
|
||||
COLOR("color", HostColorExtraModel.class, HostColorExtraStrategy.class),
|
||||
LABEL("label", HostLabelExtraModel.class, HostLabelExtraStrategy.class),
|
||||
|
||||
;
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.orion.ops.module.asset.enums;
|
||||
|
||||
/**
|
||||
* 主机身份类型
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/9/21 19:01
|
||||
*/
|
||||
public enum HostIdentityTypeEnum {
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
PASSWORD,
|
||||
|
||||
/**
|
||||
* 秘钥
|
||||
*/
|
||||
KEY,
|
||||
|
||||
;
|
||||
|
||||
public static HostIdentityTypeEnum of(String type) {
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
for (HostIdentityTypeEnum value : values()) {
|
||||
if (value.name().equals(type)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.orion.ops.module.asset.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 主机系统类型
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/4/16 21:58
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum HostSshOsTypeEnum {
|
||||
|
||||
/**
|
||||
* linux
|
||||
*/
|
||||
LINUX(".sh"),
|
||||
|
||||
/**
|
||||
* windows
|
||||
*/
|
||||
WINDOWS(".cmd"),
|
||||
|
||||
;
|
||||
|
||||
private final String scriptSuffix;
|
||||
|
||||
public static HostSshOsTypeEnum of(String type) {
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
for (HostSshOsTypeEnum value : values()) {
|
||||
if (value.name().equals(type)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.orion.ops.module.asset.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 脚本执行枚举
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/4/17 10:17
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ScriptExecEnum {
|
||||
|
||||
/**
|
||||
* 不使用
|
||||
*/
|
||||
DISABLED(0),
|
||||
|
||||
/**
|
||||
* 使用
|
||||
*/
|
||||
ENABLED(1),
|
||||
|
||||
;
|
||||
|
||||
private final Integer value;
|
||||
|
||||
public static ScriptExecEnum of(Integer value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
for (ScriptExecEnum val : values()) {
|
||||
if (val.value.equals(value)) {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否启用
|
||||
*
|
||||
* @param value value
|
||||
* @return 是否启用
|
||||
*/
|
||||
public static boolean isEnabled(Integer value) {
|
||||
return ENABLED.value.equals(value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -38,8 +38,14 @@ public class HostSshConfigModel implements GenericsDataModel, UpdatePasswordActi
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 12)
|
||||
@Schema(description = "认证方式")
|
||||
private String authType;
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 12)
|
||||
@Schema(description = "系统类型")
|
||||
private String osType;
|
||||
|
||||
@Schema(description = "密码")
|
||||
private String password;
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.orion.ops.framework.common.security.PasswordModifier;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.module.asset.dao.HostIdentityDAO;
|
||||
import com.orion.ops.module.asset.dao.HostKeyDAO;
|
||||
import com.orion.ops.module.asset.enums.HostSshOsTypeEnum;
|
||||
import com.orion.ops.module.asset.enums.HostSshAuthTypeEnum;
|
||||
import com.orion.ops.module.asset.handler.host.config.model.HostSshConfigModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -45,6 +46,7 @@ public class HostSshConfigStrategy implements MapDataStrategy<HostSshConfigModel
|
||||
.port(SSH_PORT)
|
||||
.username(USERNAME)
|
||||
.authType(HostSshAuthTypeEnum.PASSWORD.name())
|
||||
.osType(HostSshOsTypeEnum.LINUX.name())
|
||||
.connectTimeout(Const.MS_S_10)
|
||||
.charset(Const.UTF_8)
|
||||
.fileNameCharset(Const.UTF_8)
|
||||
@@ -56,6 +58,8 @@ public class HostSshConfigStrategy implements MapDataStrategy<HostSshConfigModel
|
||||
public void preValid(HostSshConfigModel model) {
|
||||
// 验证认证类型
|
||||
Valid.valid(HostSshAuthTypeEnum::of, model.getAuthType());
|
||||
// 验证系统版本
|
||||
Valid.valid(HostSshOsTypeEnum::of, model.getOsType());
|
||||
// 验证编码格式
|
||||
this.validCharset(model.getCharset());
|
||||
this.validCharset(model.getFileNameCharset());
|
||||
|
||||
@@ -28,6 +28,9 @@ public class ExecCommandDTO {
|
||||
@Schema(description = "超时时间")
|
||||
private Integer timeout;
|
||||
|
||||
@Schema(description = "是否使用脚本执行")
|
||||
private Boolean scriptExec;
|
||||
|
||||
@Schema(description = "主机")
|
||||
private List<ExecCommandHostDTO> hosts;
|
||||
|
||||
|
||||
@@ -29,10 +29,19 @@ public class ExecCommandHostDTO {
|
||||
@Schema(description = "日志文件路径")
|
||||
private String logPath;
|
||||
|
||||
@Schema(description = "脚本路径")
|
||||
private String scriptPath;
|
||||
|
||||
@Schema(description = "执行命令")
|
||||
private String command;
|
||||
|
||||
@Schema(description = "超时时间")
|
||||
private Integer timeout;
|
||||
@Schema(description = "命令编码")
|
||||
private String charset;
|
||||
|
||||
@Schema(description = "文件名称编码")
|
||||
private String fileNameCharset;
|
||||
|
||||
@Schema(description = "文件内容编码")
|
||||
private String fileContentCharset;
|
||||
|
||||
}
|
||||
|
||||
@@ -3,16 +3,21 @@ package com.orion.ops.module.asset.handler.host.exec.command.handler;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.orion.lang.exception.AuthenticationException;
|
||||
import com.orion.lang.exception.ConnectionRuntimeException;
|
||||
import com.orion.lang.exception.SftpException;
|
||||
import com.orion.lang.exception.argument.InvalidArgumentException;
|
||||
import com.orion.lang.support.timeout.TimeoutChecker;
|
||||
import com.orion.lang.utils.Booleans;
|
||||
import com.orion.lang.utils.Exceptions;
|
||||
import com.orion.lang.utils.Strings;
|
||||
import com.orion.lang.utils.io.Streams;
|
||||
import com.orion.net.host.SessionStore;
|
||||
import com.orion.net.host.sftp.SftpExecutor;
|
||||
import com.orion.net.host.ssh.command.CommandExecutor;
|
||||
import com.orion.ops.framework.common.file.FileClient;
|
||||
import com.orion.ops.module.asset.dao.ExecHostLogDAO;
|
||||
import com.orion.ops.module.asset.entity.domain.ExecHostLogDO;
|
||||
import com.orion.ops.module.asset.enums.ExecHostStatusEnum;
|
||||
import com.orion.ops.module.asset.handler.host.exec.command.dto.ExecCommandDTO;
|
||||
import com.orion.ops.module.asset.handler.host.exec.command.dto.ExecCommandHostDTO;
|
||||
import com.orion.ops.module.asset.handler.host.exec.log.manager.ExecLogManager;
|
||||
import com.orion.ops.module.asset.service.HostTerminalService;
|
||||
@@ -43,6 +48,8 @@ public class ExecCommandHandler implements IExecCommandHandler {
|
||||
|
||||
private final ExecHostLogDAO execHostLogDAO = SpringHolder.getBean(ExecHostLogDAO.class);
|
||||
|
||||
private final ExecCommandDTO execCommand;
|
||||
|
||||
private final ExecCommandHostDTO execHostCommand;
|
||||
|
||||
private final TimeoutChecker timeoutChecker;
|
||||
@@ -60,8 +67,11 @@ public class ExecCommandHandler implements IExecCommandHandler {
|
||||
|
||||
private volatile boolean interrupted;
|
||||
|
||||
public ExecCommandHandler(ExecCommandHostDTO execHostCommand, TimeoutChecker timeoutChecker) {
|
||||
public ExecCommandHandler(ExecCommandDTO execCommand,
|
||||
ExecCommandHostDTO execHostCommand,
|
||||
TimeoutChecker timeoutChecker) {
|
||||
this.status = ExecHostStatusEnum.WAITING;
|
||||
this.execCommand = execCommand;
|
||||
this.execHostCommand = execHostCommand;
|
||||
this.timeoutChecker = timeoutChecker;
|
||||
}
|
||||
@@ -109,15 +119,52 @@ public class ExecCommandHandler implements IExecCommandHandler {
|
||||
this.logOutputStream = fileClient.getContentOutputStream(execHostCommand.getLogPath());
|
||||
// 打开会话
|
||||
this.sessionStore = hostTerminalService.openSessionStore(execHostCommand.getHostId());
|
||||
this.executor = sessionStore.getCommandExecutor(Strings.replaceCRLF(execHostCommand.getCommand()));
|
||||
if (Booleans.isTrue(execCommand.getScriptExec())) {
|
||||
// 上传脚本文件
|
||||
this.uploadScriptFile();
|
||||
// 执行脚本文件
|
||||
this.executor = sessionStore.getCommandExecutor(execHostCommand.getScriptPath());
|
||||
} else {
|
||||
// 执行命令
|
||||
byte[] command = Strings.replaceCRLF(execHostCommand.getCommand()).getBytes(execHostCommand.getCharset());
|
||||
this.executor = sessionStore.getCommandExecutor(command);
|
||||
}
|
||||
// 执行命令
|
||||
executor.timeout(execHostCommand.getTimeout(), TimeUnit.SECONDS, timeoutChecker);
|
||||
executor.timeout(execCommand.getTimeout(), TimeUnit.SECONDS, timeoutChecker);
|
||||
executor.merge();
|
||||
executor.transfer(logOutputStream);
|
||||
executor.connect();
|
||||
executor.exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传脚本文件
|
||||
*/
|
||||
private void uploadScriptFile() {
|
||||
SftpExecutor sftpExecutor = null;
|
||||
try {
|
||||
// 打开 sftp
|
||||
sftpExecutor = sessionStore.getSftpExecutor(execHostCommand.getFileNameCharset());
|
||||
sftpExecutor.connect();
|
||||
// 必须要以 / 开头
|
||||
String scriptPath = execHostCommand.getScriptPath();
|
||||
if (!scriptPath.startsWith("/")) {
|
||||
scriptPath = "/" + scriptPath;
|
||||
}
|
||||
// 创建文件
|
||||
sftpExecutor.touch(scriptPath);
|
||||
// 写入命令
|
||||
byte[] command = Strings.replaceCRLF(execHostCommand.getCommand()).getBytes(execHostCommand.getFileContentCharset());
|
||||
sftpExecutor.write(scriptPath, command);
|
||||
// 修改权限
|
||||
sftpExecutor.changeMode(scriptPath, 777);
|
||||
} catch (Exception e) {
|
||||
throw Exceptions.sftp(e);
|
||||
} finally {
|
||||
Streams.close(sftpExecutor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新状态
|
||||
*
|
||||
@@ -199,6 +246,8 @@ public class ExecCommandHandler implements IExecCommandHandler {
|
||||
message = "连接失败";
|
||||
} else if (ex instanceof AuthenticationException) {
|
||||
message = "认证失败";
|
||||
} else if (ex instanceof SftpException) {
|
||||
message = "脚本上传失败";
|
||||
} else {
|
||||
message = "执行失败";
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class ExecTaskHandler implements IExecTaskHandler {
|
||||
this.updateStatus(ExecStatusEnum.RUNNING);
|
||||
try {
|
||||
// 执行命令
|
||||
this.runHostCommand(execCommand.getHosts());
|
||||
this.runHostCommand();
|
||||
// 更新状态-执行完成
|
||||
log.info("ExecTaskHandler.run completed id: {}", id);
|
||||
this.updateStatus(ExecStatusEnum.COMPLETED);
|
||||
@@ -81,23 +81,24 @@ public class ExecTaskHandler implements IExecTaskHandler {
|
||||
/**
|
||||
* 执行主机命令
|
||||
*
|
||||
* @param hosts hosts
|
||||
* @throws Exception Exception
|
||||
*/
|
||||
private void runHostCommand(List<ExecCommandHostDTO> hosts) throws Exception {
|
||||
private void runHostCommand() throws Exception {
|
||||
// 超时检查
|
||||
if (execCommand.getTimeout() != 0) {
|
||||
this.timeoutChecker = TimeoutCheckers.create();
|
||||
AssetThreadPools.TIMEOUT_CHECK.execute(this.timeoutChecker);
|
||||
}
|
||||
// 执行命令
|
||||
List<ExecCommandHostDTO> hosts = execCommand.getHosts();
|
||||
if (hosts.size() == 1) {
|
||||
// 单个主机直接执行
|
||||
ExecCommandHandler handler = new ExecCommandHandler(hosts.get(0), timeoutChecker);
|
||||
ExecCommandHandler handler = new ExecCommandHandler(execCommand, hosts.get(0), timeoutChecker);
|
||||
handlers.add(handler);
|
||||
handler.run();
|
||||
} else {
|
||||
hosts.stream()
|
||||
.map(s -> new ExecCommandHandler(s, timeoutChecker))
|
||||
.map(s -> new ExecCommandHandler(execCommand, s, timeoutChecker))
|
||||
.forEach(handlers::add);
|
||||
// 多个主机异步阻塞执行
|
||||
Threads.blockRun(handlers, AssetThreadPools.EXEC_HOST);
|
||||
|
||||
@@ -15,10 +15,4 @@ public interface LogConst {
|
||||
|
||||
String SEPARATOR = "|";
|
||||
|
||||
int TRACKER_OFFSET_LINE = 200;
|
||||
|
||||
int TRACKER_DELAY_MS = 200;
|
||||
|
||||
int TRACKER_WAIT_TIMES = 100;
|
||||
|
||||
}
|
||||
|
||||
@@ -5,8 +5,10 @@ import com.orion.ext.tail.delay.DelayTrackerListener;
|
||||
import com.orion.ext.tail.mode.FileNotFoundMode;
|
||||
import com.orion.ext.tail.mode.FileOffsetMode;
|
||||
import com.orion.ops.framework.websocket.core.utils.WebSockets;
|
||||
import com.orion.ops.module.asset.define.config.AppTrackerConfig;
|
||||
import com.orion.ops.module.asset.entity.dto.ExecHostLogTailDTO;
|
||||
import com.orion.ops.module.asset.handler.host.exec.log.constant.LogConst;
|
||||
import com.orion.spring.SpringHolder;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
@@ -21,6 +23,8 @@ import org.springframework.web.socket.WebSocketSession;
|
||||
@Slf4j
|
||||
public class ExecLogTracker implements IExecLogTracker {
|
||||
|
||||
private static final AppTrackerConfig TRACKER_CONFIG = SpringHolder.getBean(AppTrackerConfig.class);
|
||||
|
||||
private final WebSocketSession session;
|
||||
|
||||
private final ExecHostLogTailDTO config;
|
||||
@@ -50,9 +54,9 @@ public class ExecLogTracker implements IExecLogTracker {
|
||||
try {
|
||||
this.tracker = new DelayTrackerListener(absolutePath, this);
|
||||
tracker.charset(config.getCharset());
|
||||
tracker.delayMillis(LogConst.TRACKER_DELAY_MS);
|
||||
tracker.offset(FileOffsetMode.LINE, LogConst.TRACKER_OFFSET_LINE);
|
||||
tracker.notFoundMode(FileNotFoundMode.WAIT_COUNT, LogConst.TRACKER_WAIT_TIMES);
|
||||
tracker.delayMillis(TRACKER_CONFIG.getDelay());
|
||||
tracker.offset(FileOffsetMode.LINE, TRACKER_CONFIG.getOffset());
|
||||
tracker.notFoundMode(FileNotFoundMode.WAIT_COUNT, TRACKER_CONFIG.getWaitTimes());
|
||||
// 开始监听文件
|
||||
tracker.run();
|
||||
} catch (Exception e) {
|
||||
@@ -80,7 +84,7 @@ public class ExecLogTracker implements IExecLogTracker {
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
log.info("ExecLogTracker.close path: {}", absolutePath);
|
||||
log.info("ExecLogTracker.close path: {}, closed: {}", absolutePath, close);
|
||||
if (close) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 主机拓展信息 - color 模型
|
||||
* 主机拓展信息 - 标签模型
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
@@ -18,8 +18,11 @@ import lombok.NoArgsConstructor;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "HostExtraSshModel", description = "主机拓展信息 - color 模型")
|
||||
public class HostColorExtraModel implements GenericsDataModel {
|
||||
@Schema(name = "HostLabelExtraModel", description = "主机拓展信息 - 标签模型")
|
||||
public class HostLabelExtraModel implements GenericsDataModel {
|
||||
|
||||
@Schema(description = "别名")
|
||||
private String alias;
|
||||
|
||||
@Schema(description = "颜色")
|
||||
private String color;
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.orion.ops.module.asset.handler.host.extra.strategy;
|
||||
|
||||
import com.orion.ops.framework.common.handler.data.strategy.MapDataStrategy;
|
||||
import com.orion.ops.module.asset.handler.host.extra.model.HostColorExtraModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 主机拓展信息 - 颜色 模型处理策略
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/2/29 23:16
|
||||
*/
|
||||
@Component
|
||||
public class HostColorExtraStrategy implements MapDataStrategy<HostColorExtraModel> {
|
||||
|
||||
@Override
|
||||
public HostColorExtraModel getDefault() {
|
||||
return HostColorExtraModel.builder()
|
||||
// 默认透明
|
||||
.color("")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFill(HostColorExtraModel beforeModel, HostColorExtraModel afterModel) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preValid(HostColorExtraModel model) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void valid(HostColorExtraModel model) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.orion.ops.module.asset.handler.host.extra.strategy;
|
||||
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
import com.orion.ops.framework.common.handler.data.strategy.MapDataStrategy;
|
||||
import com.orion.ops.module.asset.handler.host.extra.model.HostLabelExtraModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 主机拓展信息 - 标签模型处理策略
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/2/29 23:16
|
||||
*/
|
||||
@Component
|
||||
public class HostLabelExtraStrategy implements MapDataStrategy<HostLabelExtraModel> {
|
||||
|
||||
@Override
|
||||
public HostLabelExtraModel getDefault() {
|
||||
return HostLabelExtraModel.builder()
|
||||
// 透明
|
||||
.color(Const.EMPTY)
|
||||
// 无别名
|
||||
.alias(Const.EMPTY)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFill(HostLabelExtraModel beforeModel, HostLabelExtraModel afterModel) {
|
||||
// 为空则覆盖
|
||||
if (afterModel.getAlias() == null) {
|
||||
afterModel.setAlias(beforeModel.getAlias());
|
||||
}
|
||||
if (afterModel.getColor() == null) {
|
||||
afterModel.setColor(beforeModel.getColor());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preValid(HostLabelExtraModel model) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void valid(HostLabelExtraModel model) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import com.orion.ops.module.asset.dao.HostKeyDAO;
|
||||
import com.orion.ops.module.asset.enums.HostExtraSshAuthTypeEnum;
|
||||
import com.orion.ops.module.asset.handler.host.extra.model.HostSshExtraModel;
|
||||
import com.orion.ops.module.infra.api.DataPermissionApi;
|
||||
import com.orion.ops.module.infra.api.SystemUserApi;
|
||||
import com.orion.ops.module.infra.enums.DataPermissionTypeEnum;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -31,9 +30,6 @@ public class HostSshExtraStrategy implements MapDataStrategy<HostSshExtraModel>
|
||||
@Resource
|
||||
private HostIdentityDAO hostIdentityDAO;
|
||||
|
||||
@Resource
|
||||
private SystemUserApi systemUserApi;
|
||||
|
||||
@Resource
|
||||
private DataPermissionApi dataPermissionApi;
|
||||
|
||||
@@ -68,21 +64,18 @@ public class HostSshExtraStrategy implements MapDataStrategy<HostSshExtraModel>
|
||||
if (identityId != null) {
|
||||
Valid.notNull(hostIdentityDAO.selectById(identityId), ErrorMessage.IDENTITY_ABSENT);
|
||||
}
|
||||
// 非管理员验证权限
|
||||
Long userId = SecurityUtils.getLoginUserId();
|
||||
if (!systemUserApi.isAdminUser(userId)) {
|
||||
// 验证主机秘钥是否有权限
|
||||
if (keyId != null) {
|
||||
Valid.isTrue(dataPermissionApi.hasPermission(DataPermissionTypeEnum.HOST_KEY, userId, keyId),
|
||||
ErrorMessage.ANY_NO_PERMISSION,
|
||||
DataPermissionTypeEnum.HOST_KEY.getPermissionName());
|
||||
}
|
||||
// 验证主机身份是否有权限
|
||||
if (identityId != null) {
|
||||
Valid.isTrue(dataPermissionApi.hasPermission(DataPermissionTypeEnum.HOST_IDENTITY, userId, identityId),
|
||||
ErrorMessage.ANY_NO_PERMISSION,
|
||||
DataPermissionTypeEnum.HOST_IDENTITY.getPermissionName());
|
||||
}
|
||||
// 验证主机秘钥是否有权限
|
||||
if (keyId != null) {
|
||||
Valid.isTrue(dataPermissionApi.hasPermission(DataPermissionTypeEnum.HOST_KEY, userId, keyId),
|
||||
ErrorMessage.ANY_NO_PERMISSION,
|
||||
DataPermissionTypeEnum.HOST_KEY.getPermissionName());
|
||||
}
|
||||
// 验证主机身份是否有权限
|
||||
if (identityId != null) {
|
||||
Valid.isTrue(dataPermissionApi.hasPermission(DataPermissionTypeEnum.HOST_IDENTITY, userId, identityId),
|
||||
ErrorMessage.ANY_NO_PERMISSION,
|
||||
DataPermissionTypeEnum.HOST_IDENTITY.getPermissionName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public class TransferMessageDispatcher extends AbstractWebSocketHandler {
|
||||
String id = session.getId();
|
||||
log.info("TransferMessageHandler-afterConnectionClosed id: {}, code: {}, reason: {}", id, status.getCode(), status.getReason());
|
||||
// 关闭会话
|
||||
Streams.close(handlers.get(id));
|
||||
Streams.close(handlers.remove(id));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* sftp 文件备份参数
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/4/15 23:13
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "SftpFileBackupParams", description = "sftp 文件备份参数")
|
||||
public class SftpFileBackupParams {
|
||||
|
||||
@Schema(description = "文件名称")
|
||||
private String fileName;
|
||||
|
||||
@Schema(description = "时间戳")
|
||||
private Long timestamp;
|
||||
|
||||
}
|
||||
@@ -1,14 +1,20 @@
|
||||
package com.orion.ops.module.asset.handler.host.transfer.session;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.orion.lang.utils.Booleans;
|
||||
import com.orion.lang.utils.Strings;
|
||||
import com.orion.lang.utils.collect.Maps;
|
||||
import com.orion.lang.utils.io.Streams;
|
||||
import com.orion.net.host.SessionStore;
|
||||
import com.orion.net.host.sftp.SftpExecutor;
|
||||
import com.orion.net.host.sftp.SftpFile;
|
||||
import com.orion.ops.framework.biz.operator.log.core.model.OperatorLogModel;
|
||||
import com.orion.ops.framework.biz.operator.log.core.service.OperatorLogFrameworkService;
|
||||
import com.orion.ops.framework.biz.operator.log.core.utils.OperatorLogs;
|
||||
import com.orion.ops.module.asset.define.config.AppSftpConfig;
|
||||
import com.orion.ops.module.asset.entity.dto.HostTerminalConnectDTO;
|
||||
import com.orion.ops.module.asset.handler.host.terminal.utils.TerminalUtils;
|
||||
import com.orion.ops.module.asset.handler.host.transfer.model.SftpFileBackupParams;
|
||||
import com.orion.spring.SpringHolder;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
|
||||
@@ -23,6 +29,8 @@ import java.util.Map;
|
||||
*/
|
||||
public abstract class TransferHostSession implements ITransferHostSession {
|
||||
|
||||
protected static final AppSftpConfig SFTP_CONFIG = SpringHolder.getBean(AppSftpConfig.class);
|
||||
|
||||
protected final HostTerminalConnectDTO connectInfo;
|
||||
|
||||
protected final SessionStore sessionStore;
|
||||
@@ -51,6 +59,27 @@ public abstract class TransferHostSession implements ITransferHostSession {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查文件是否存在 并且执行响应策略
|
||||
*
|
||||
* @param path path
|
||||
*/
|
||||
protected void doCheckFilePresent(String path) {
|
||||
// 重复不备份
|
||||
if (!Booleans.isTrue(SFTP_CONFIG.getUploadPresentBackup())) {
|
||||
return;
|
||||
}
|
||||
// 检查文件是否存在
|
||||
SftpFile file = executor.getFile(path);
|
||||
if (file != null) {
|
||||
// 文件存在则备份
|
||||
SftpFileBackupParams backupParams = new SftpFileBackupParams(file.getName(), System.currentTimeMillis());
|
||||
String target = Strings.format(SFTP_CONFIG.getBackupFileName(), JSON.parseObject(JSON.toJSONString(backupParams)));
|
||||
// 移动
|
||||
executor.move(path, target);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存操作日志
|
||||
*
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.orion.ops.module.asset.handler.host.transfer.session;
|
||||
import com.orion.lang.exception.argument.InvalidArgumentException;
|
||||
import com.orion.lang.utils.io.Streams;
|
||||
import com.orion.net.host.SessionStore;
|
||||
import com.orion.net.host.sftp.SftpFile;
|
||||
import com.orion.ops.module.asset.define.operator.HostTerminalOperatorType;
|
||||
import com.orion.ops.module.asset.entity.dto.HostTerminalConnectDTO;
|
||||
import com.orion.ops.module.asset.handler.host.transfer.enums.TransferReceiverType;
|
||||
@@ -40,11 +39,7 @@ public class UploadSession extends TransferHostSession implements IUploadSession
|
||||
// 检查连接
|
||||
this.init();
|
||||
// 检查文件是否存在
|
||||
SftpFile file = executor.getFile(path);
|
||||
if (file != null) {
|
||||
// 文件存在则重命名
|
||||
executor.move(path, file.getName() + "_bk_" + System.currentTimeMillis());
|
||||
}
|
||||
this.doCheckFilePresent(path);
|
||||
// 打开输出流
|
||||
this.outputStream = executor.openOutputStream(path);
|
||||
// 响应结果
|
||||
|
||||
@@ -28,13 +28,21 @@ public interface AssetAuthorizedDataService {
|
||||
List<Long> getAuthorizedDataRelId(DataPermissionTypeEnum type, AssetAuthorizedDataQueryRequest request);
|
||||
|
||||
/**
|
||||
* 查询用户已授权的主机
|
||||
* 获取用户已授权的主机id 查询角色
|
||||
*
|
||||
* @param userId userId
|
||||
* @return hostId
|
||||
*/
|
||||
List<Long> getUserAuthorizedHostId(Long userId);
|
||||
|
||||
/**
|
||||
* 获取用户已授权&配置已启用的主机id 查询角色
|
||||
*
|
||||
* @param userId userId
|
||||
* @param type type
|
||||
* @return hostId
|
||||
*/
|
||||
List<Long> getUserAuthorizedHostId(Long userId, HostConfigTypeEnum type);
|
||||
List<Long> getUserAuthorizedHostIdWithEnabledConfig(Long userId, HostConfigTypeEnum type);
|
||||
|
||||
/**
|
||||
* 查询用户已授权的主机
|
||||
@@ -45,14 +53,6 @@ public interface AssetAuthorizedDataService {
|
||||
*/
|
||||
AuthorizedHostWrapperVO getUserAuthorizedHost(Long userId, String type);
|
||||
|
||||
/**
|
||||
* 获取用户已授权的主机id 不查询角色
|
||||
*
|
||||
* @param userId userId
|
||||
* @return hostId
|
||||
*/
|
||||
List<Long> getUserAuthorizedHostId(Long userId);
|
||||
|
||||
/**
|
||||
* 查询用户已授权的主机秘钥
|
||||
*
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.orion.ops.module.asset.service;
|
||||
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecCommandExecRequest;
|
||||
import com.orion.ops.module.asset.entity.dto.ExecCommandExecDTO;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecCommandRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecLogVO;
|
||||
|
||||
@@ -27,7 +27,7 @@ public interface ExecCommandService {
|
||||
* @param request request
|
||||
* @return result
|
||||
*/
|
||||
ExecLogVO execCommandWithSource(ExecCommandExecRequest request);
|
||||
ExecLogVO execCommandWithSource(ExecCommandExecDTO request);
|
||||
|
||||
/**
|
||||
* 重新执行命令
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.orion.ops.module.asset.entity.vo.HostConfigVO;
|
||||
import com.orion.ops.module.asset.enums.HostConfigTypeEnum;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 主机配置 服务类
|
||||
@@ -27,10 +28,11 @@ public interface HostConfigService {
|
||||
HostConfigVO getHostConfig(Long hostId, String type);
|
||||
|
||||
/**
|
||||
* 获取配置
|
||||
* 获取配置 配置未启用会报错
|
||||
*
|
||||
* @param hostId hostId
|
||||
* @param type type
|
||||
* @param <T> T
|
||||
* @return config
|
||||
*/
|
||||
<T extends GenericsDataModel> T getHostConfig(Long hostId, HostConfigTypeEnum type);
|
||||
@@ -52,6 +54,16 @@ public interface HostConfigService {
|
||||
*/
|
||||
List<HostConfigVO> getHostConfigList(List<Long> hostIdList, String type);
|
||||
|
||||
/**
|
||||
* 获取配置
|
||||
*
|
||||
* @param hostIdList hostIdList
|
||||
* @param type type
|
||||
* @param <T> T
|
||||
* @return config
|
||||
*/
|
||||
<T extends GenericsDataModel> Map<Long, T> getHostConfigMap(List<Long> hostIdList, HostConfigTypeEnum type);
|
||||
|
||||
/**
|
||||
* 更新配置
|
||||
*
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.orion.ops.module.asset.service;
|
||||
|
||||
import com.orion.ops.framework.common.handler.data.model.GenericsDataModel;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostAliasUpdateRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostExtraQueryRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostExtraUpdateRequest;
|
||||
import com.orion.ops.module.asset.enums.HostExtraItemEnum;
|
||||
@@ -17,14 +16,6 @@ import java.util.Map;
|
||||
*/
|
||||
public interface HostExtraService {
|
||||
|
||||
/**
|
||||
* 修改主机别名
|
||||
*
|
||||
* @param request request
|
||||
* @return effect
|
||||
*/
|
||||
Integer updateHostAlias(HostAliasUpdateRequest request);
|
||||
|
||||
/**
|
||||
* 获取主机额外配置
|
||||
*
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package com.orion.ops.module.asset.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.orion.lang.function.Functions;
|
||||
import com.orion.lang.utils.Refs;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.lang.utils.collect.Maps;
|
||||
import com.orion.lang.utils.collect.Sets;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
import com.orion.ops.framework.common.utils.TreeUtils;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
@@ -13,10 +12,10 @@ import com.orion.ops.module.asset.entity.request.asset.AssetAuthorizedDataQueryR
|
||||
import com.orion.ops.module.asset.entity.vo.*;
|
||||
import com.orion.ops.module.asset.enums.HostConfigTypeEnum;
|
||||
import com.orion.ops.module.asset.enums.HostConnectTypeEnum;
|
||||
import com.orion.ops.module.asset.handler.host.extra.model.HostColorExtraModel;
|
||||
import com.orion.ops.module.asset.enums.HostExtraItemEnum;
|
||||
import com.orion.ops.module.asset.handler.host.extra.model.HostLabelExtraModel;
|
||||
import com.orion.ops.module.asset.service.*;
|
||||
import com.orion.ops.module.infra.api.*;
|
||||
import com.orion.ops.module.infra.constant.DataExtraItems;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.tag.TagDTO;
|
||||
import com.orion.ops.module.infra.enums.*;
|
||||
@@ -50,9 +49,6 @@ public class AssetAuthorizedDataServiceImpl implements AssetAuthorizedDataServic
|
||||
@Resource
|
||||
private DataPermissionApi dataPermissionApi;
|
||||
|
||||
@Resource
|
||||
private SystemUserApi systemUserApi;
|
||||
|
||||
@Resource
|
||||
private HostService hostService;
|
||||
|
||||
@@ -91,39 +87,6 @@ public class AssetAuthorizedDataServiceImpl implements AssetAuthorizedDataServic
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getUserAuthorizedHostId(Long userId, HostConfigTypeEnum type) {
|
||||
final boolean allData = systemUserApi.isAdminUser(userId);
|
||||
if (allData) {
|
||||
// 管理员查询所有
|
||||
return this.getEnabledConfigHostId(true, Maps.empty(), type.name());
|
||||
} else {
|
||||
// 其他用户 查询授权的数据
|
||||
Map<Long, Set<Long>> dataGroupRel = dataGroupRelApi.getGroupRelList(DataGroupTypeEnum.HOST);
|
||||
// 查询配置启用的主机
|
||||
return this.getEnabledConfigHostId(false, dataGroupRel, type.name());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthorizedHostWrapperVO getUserAuthorizedHost(Long userId, String type) {
|
||||
if (systemUserApi.isAdminUser(userId)) {
|
||||
// 管理员查询所有
|
||||
return this.buildUserAuthorizedHost(userId, null, type);
|
||||
} else {
|
||||
// 其他用户 查询授权的数据
|
||||
List<Long> authorizedIdList = dataPermissionApi.getUserAuthorizedRelIdList(DataPermissionTypeEnum.HOST_GROUP, userId);
|
||||
if (authorizedIdList.isEmpty()) {
|
||||
// 无数据
|
||||
return AuthorizedHostWrapperVO.builder()
|
||||
.groupTree(Lists.empty())
|
||||
.hostList(Lists.empty())
|
||||
.build();
|
||||
}
|
||||
return this.buildUserAuthorizedHost(userId, authorizedIdList, type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getUserAuthorizedHostId(Long userId) {
|
||||
// 查询授权的分组
|
||||
@@ -143,132 +106,117 @@ public class AssetAuthorizedDataServiceImpl implements AssetAuthorizedDataServic
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HostKeyVO> getUserAuthorizedHostKey(Long userId) {
|
||||
if (systemUserApi.isAdminUser(userId)) {
|
||||
// 管理员查询所有
|
||||
return hostKeyService.getHostKeyList();
|
||||
} else {
|
||||
// 其他用户 查询授权的数据
|
||||
List<Long> authorizedIdList = dataPermissionApi.getUserAuthorizedRelIdList(DataPermissionTypeEnum.HOST_KEY, userId);
|
||||
if (authorizedIdList.isEmpty()) {
|
||||
return Lists.empty();
|
||||
}
|
||||
// 映射数据
|
||||
Map<Long, HostKeyVO> keys = hostKeyService.getHostKeyList()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(HostKeyVO::getId, Function.identity(), Functions.right()));
|
||||
return authorizedIdList.stream()
|
||||
.map(keys::get)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
public List<Long> getUserAuthorizedHostIdWithEnabledConfig(Long userId, HostConfigTypeEnum type) {
|
||||
// 获取启用的主机
|
||||
List<Long> hostIdList = this.getUserAuthorizedHostId(userId);
|
||||
if (hostIdList.isEmpty()) {
|
||||
return hostIdList;
|
||||
}
|
||||
// 获取启用配置的主机
|
||||
return hostConfigService.getEnabledConfigHostId(type.name(), hostIdList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HostIdentityVO> getUserAuthorizedHostIdentity(Long userId) {
|
||||
if (systemUserApi.isAdminUser(userId)) {
|
||||
// 管理员查询所有
|
||||
return hostIdentityService.getHostIdentityList();
|
||||
} else {
|
||||
// 其他用户 查询授权的数据
|
||||
List<Long> authorizedIdList = dataPermissionApi.getUserAuthorizedRelIdList(DataPermissionTypeEnum.HOST_IDENTITY, userId);
|
||||
if (authorizedIdList.isEmpty()) {
|
||||
return Lists.empty();
|
||||
}
|
||||
// 映射数据
|
||||
Map<Long, HostIdentityVO> identities = hostIdentityService.getHostIdentityList()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(HostIdentityVO::getId, Function.identity(), Functions.right()));
|
||||
return authorizedIdList.stream()
|
||||
.map(identities::get)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建授权的主机分组树
|
||||
*
|
||||
* @param userId userId
|
||||
* @param authorizedGroupIdList authorizedGroupIdList
|
||||
* @param type type
|
||||
* @return tree
|
||||
*/
|
||||
@SneakyThrows
|
||||
private AuthorizedHostWrapperVO buildUserAuthorizedHost(Long userId, List<Long> authorizedGroupIdList, String type) {
|
||||
final boolean allData = Lists.isEmpty(authorizedGroupIdList);
|
||||
@Override
|
||||
public AuthorizedHostWrapperVO getUserAuthorizedHost(Long userId, String type) {
|
||||
// 查询授权的数据
|
||||
List<Long> authorizedGroupIdList = dataPermissionApi.getUserAuthorizedRelIdList(DataPermissionTypeEnum.HOST_GROUP, userId);
|
||||
if (Lists.isEmpty(authorizedGroupIdList)) {
|
||||
// 无数据
|
||||
return AuthorizedHostWrapperVO.builder()
|
||||
.groupTree(Lists.empty())
|
||||
.treeNodes(Maps.empty())
|
||||
.hostList(Lists.empty())
|
||||
.latestHosts(Sets.empty())
|
||||
.build();
|
||||
}
|
||||
AuthorizedHostWrapperVO wrapper = new AuthorizedHostWrapperVO();
|
||||
// 查询我的收藏
|
||||
Future<List<Long>> favoriteResult = favoriteApi.getFavoriteRelIdListAsync(FavoriteTypeEnum.HOST, userId);
|
||||
// 查询最近连接的主机
|
||||
Future<List<Long>> latestConnectHostIdList = hostConnectLogService.getLatestConnectHostIdAsync(HostConnectTypeEnum.of(type), userId);
|
||||
// 查询主机拓展信息
|
||||
Future<List<Map<Long, String>>> hostExtraResult = dataExtraApi.getExtraItemsValuesByCacheAsync(userId,
|
||||
Future<Map<Long, String>> labelExtraResult = dataExtraApi.getExtraItemValuesByCacheAsync(userId,
|
||||
DataExtraTypeEnum.HOST,
|
||||
Lists.of(DataExtraItems.ALIAS, DataExtraItems.COLOR));
|
||||
HostExtraItemEnum.LABEL.getItem());
|
||||
// 查询分组
|
||||
List<DataGroupDTO> dataGroup = dataGroupApi.getDataGroupList(DataGroupTypeEnum.HOST);
|
||||
// 查询分组引用
|
||||
Map<Long, Set<Long>> dataGroupRel = dataGroupRelApi.getGroupRelList(DataGroupTypeEnum.HOST);
|
||||
// 查询配置启用的主机
|
||||
List<Long> enabledConfigHostId = this.getEnabledConfigHostId(allData, dataGroupRel, type);
|
||||
// 过滤已经授权的分组
|
||||
if (!allData) {
|
||||
// 构建已授权的分组
|
||||
List<DataGroupDTO> relNodes = new ArrayList<>();
|
||||
TreeUtils.getAllNodes(dataGroup, authorizedGroupIdList, relNodes);
|
||||
dataGroup = new ArrayList<>(new HashSet<>(relNodes));
|
||||
}
|
||||
// 过滤掉无分组权限以及未启用配置的主机
|
||||
this.filterEnabledAuthorizedHost(dataGroup, dataGroupRel, authorizedGroupIdList, type);
|
||||
// 设置主机分组树
|
||||
wrapper.setGroupTree(this.getAuthorizedHostGroupTree(dataGroup));
|
||||
// 设置主机分组下的主机
|
||||
wrapper.setTreeNodes(this.getAuthorizedHostGroupNodes(allData,
|
||||
dataGroup,
|
||||
dataGroupRel,
|
||||
authorizedGroupIdList));
|
||||
// 设置已授权的所有主机
|
||||
wrapper.setHostList(this.getAuthorizedHostList(allData,
|
||||
dataGroup,
|
||||
dataGroupRel,
|
||||
authorizedGroupIdList,
|
||||
enabledConfigHostId));
|
||||
// 设置主机列表
|
||||
wrapper.setHostList(this.getAuthorizedHostList(dataGroupRel));
|
||||
// 设置主机分组节点映射
|
||||
wrapper.setTreeNodes(Maps.map(dataGroupRel, String::valueOf, Function.identity()));
|
||||
// 设置主机拓展信息
|
||||
this.getAuthorizedHostExtra(wrapper.getHostList(),
|
||||
favoriteResult.get(),
|
||||
hostExtraResult.get());
|
||||
labelExtraResult.get());
|
||||
// 设置最近连接的主机
|
||||
wrapper.setLatestHosts(new LinkedHashSet<>(latestConnectHostIdList.get()));
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已启用配置的 hostId
|
||||
*
|
||||
* @param allData allData
|
||||
* @param dataGroupRel dataGroupRel
|
||||
* @param type type
|
||||
* @return enabledHostIdList
|
||||
*/
|
||||
private List<Long> getEnabledConfigHostId(boolean allData,
|
||||
Map<Long, Set<Long>> dataGroupRel,
|
||||
String type) {
|
||||
List<Long> hostIdList = null;
|
||||
if (!allData) {
|
||||
// 非全部数据从分组映射中获取
|
||||
hostIdList = dataGroupRel.values()
|
||||
.stream()
|
||||
.flatMap(Collection::stream)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
if (hostIdList.isEmpty()) {
|
||||
return Lists.empty();
|
||||
}
|
||||
@Override
|
||||
public List<HostKeyVO> getUserAuthorizedHostKey(Long userId) {
|
||||
// 查询授权的数据
|
||||
List<Long> authorizedIdList = dataPermissionApi.getUserAuthorizedRelIdList(DataPermissionTypeEnum.HOST_KEY, userId);
|
||||
if (authorizedIdList.isEmpty()) {
|
||||
return Lists.empty();
|
||||
}
|
||||
// 查询启用配置的主机
|
||||
// 查询数据
|
||||
return hostKeyService.getHostKeyList()
|
||||
.stream()
|
||||
.filter(s -> authorizedIdList.contains(s.getId()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HostIdentityVO> getUserAuthorizedHostIdentity(Long userId) {
|
||||
// 查询授权的数据
|
||||
List<Long> authorizedIdList = dataPermissionApi.getUserAuthorizedRelIdList(DataPermissionTypeEnum.HOST_IDENTITY, userId);
|
||||
if (authorizedIdList.isEmpty()) {
|
||||
return Lists.empty();
|
||||
}
|
||||
// 查询数据
|
||||
return hostIdentityService.getHostIdentityList()
|
||||
.stream()
|
||||
.filter(s -> authorizedIdList.contains(s.getId()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤掉未授权的 dataGroupRel 和 dataGroupRel
|
||||
* 过滤掉未启用配置的 dataGroupRel
|
||||
*
|
||||
* @param dataGroup dataGroup
|
||||
* @param dataGroupRel dataGroupRel
|
||||
* @param authorizedGroupIdList authorizedGroupIdList
|
||||
* @param type type
|
||||
*/
|
||||
private void filterEnabledAuthorizedHost(List<DataGroupDTO> dataGroup,
|
||||
Map<Long, Set<Long>> dataGroupRel,
|
||||
List<Long> authorizedGroupIdList,
|
||||
String type) {
|
||||
// 过滤未授权的分组
|
||||
List<DataGroupDTO> authorizedDataGroup = new ArrayList<>();
|
||||
TreeUtils.getAllNodes(dataGroup, authorizedGroupIdList, authorizedDataGroup);
|
||||
dataGroup.clear();
|
||||
dataGroup.addAll(new HashSet<>(authorizedDataGroup));
|
||||
// 移除未授权的分组引用
|
||||
dataGroupRel.keySet().removeIf(s -> !authorizedGroupIdList.contains(s));
|
||||
// 查询配置已启用的主机
|
||||
List<Long> hostIdList = dataGroupRel.values()
|
||||
.stream()
|
||||
.flatMap(Collection::stream)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
List<Long> enabledConfigHostId = hostConfigService.getEnabledConfigHostId(type, hostIdList);
|
||||
// 从分组引用中移除
|
||||
// 从分组引用中移除未启用的主机
|
||||
dataGroupRel.forEach((k, v) -> v.removeIf(s -> !enabledConfigHostId.contains(s)));
|
||||
return enabledConfigHostId;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -288,59 +236,19 @@ public class AssetAuthorizedDataServiceImpl implements AssetAuthorizedDataServic
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主机分组树 主机节点映射
|
||||
* 查询已授权的主机列表
|
||||
*
|
||||
* @param allData allData
|
||||
* @param dataGroup dataGroup
|
||||
* @param dataGroupRel dataGroupRel
|
||||
* @param authorizedGroupIdList authorizedGroupIdList
|
||||
* @return hostGroupId:hostIdList
|
||||
*/
|
||||
private Map<String, Set<Long>> getAuthorizedHostGroupNodes(boolean allData,
|
||||
List<DataGroupDTO> dataGroup,
|
||||
Map<Long, Set<Long>> dataGroupRel,
|
||||
List<Long> authorizedGroupIdList) {
|
||||
Map<String, Set<Long>> result = new HashMap<>();
|
||||
dataGroup.stream()
|
||||
.map(DataGroupDTO::getId)
|
||||
// 因为可能父菜单没有授权 这里需要判断分组权限
|
||||
.filter(id -> allData || authorizedGroupIdList.contains(id))
|
||||
.forEach(s -> result.put(String.valueOf(s), dataGroupRel.get(s)));
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询已授权的所有主机
|
||||
*
|
||||
* @param allData allData
|
||||
* @param dataGroup dataGroup
|
||||
* @param dataGroupRel dataGroupRel
|
||||
* @param authorizedGroupIdList authorizedGroupIdList
|
||||
* @param enabledConfigHostId enabledConfigHostId
|
||||
* @param dataGroupRel dataGroupRel
|
||||
* @return hosts
|
||||
*/
|
||||
private List<HostVO> getAuthorizedHostList(boolean allData,
|
||||
List<DataGroupDTO> dataGroup,
|
||||
Map<Long, Set<Long>> dataGroupRel,
|
||||
List<Long> authorizedGroupIdList,
|
||||
List<Long> enabledConfigHostId) {
|
||||
private List<HostVO> getAuthorizedHostList(Map<Long, Set<Long>> dataGroupRel) {
|
||||
// 查询主机列表
|
||||
List<HostVO> hosts = hostService.getHostListByCache()
|
||||
Map<Long, HostVO> hostMap = hostService.getHostListByCache()
|
||||
.stream()
|
||||
.filter(s -> enabledConfigHostId.contains(s.getId()))
|
||||
.collect(Collectors.toList());
|
||||
// 全部数据直接返回
|
||||
if (allData) {
|
||||
return hosts;
|
||||
}
|
||||
Map<Long, HostVO> hostMap = hosts.stream()
|
||||
.collect(Collectors.toMap(HostVO::getId, Function.identity(), Functions.right()));
|
||||
// 仅设置已授权的数据
|
||||
return dataGroup.stream()
|
||||
.map(DataGroupDTO::getId)
|
||||
// 因为可能父菜单没有授权 这里需要判断分组权限
|
||||
.filter(authorizedGroupIdList::contains)
|
||||
.map(dataGroupRel::get)
|
||||
// 设置已授权的数据
|
||||
return dataGroupRel.values()
|
||||
.stream()
|
||||
.filter(Lists::isNoneEmpty)
|
||||
.flatMap(Collection::stream)
|
||||
.distinct()
|
||||
@@ -352,13 +260,13 @@ public class AssetAuthorizedDataServiceImpl implements AssetAuthorizedDataServic
|
||||
/**
|
||||
* 设置授权主机的额外参数
|
||||
*
|
||||
* @param hosts hosts
|
||||
* @param favorite favorite
|
||||
* @param extraList extraList
|
||||
* @param hosts hosts
|
||||
* @param favorite favorite
|
||||
* @param labelExtra labelExtra
|
||||
*/
|
||||
private void getAuthorizedHostExtra(List<HostVO> hosts,
|
||||
List<Long> favorite,
|
||||
List<Map<Long, String>> extraList) {
|
||||
Map<Long, String> labelExtra) {
|
||||
if (Lists.isEmpty(hosts)) {
|
||||
return;
|
||||
}
|
||||
@@ -374,25 +282,18 @@ public class AssetAuthorizedDataServiceImpl implements AssetAuthorizedDataServic
|
||||
for (int i = 0; i < hosts.size(); i++) {
|
||||
hosts.get(i).setTags(tags.get(i));
|
||||
}
|
||||
// 设置主机别名
|
||||
Map<Long, String> aliasMap = extraList.get(0);
|
||||
if (!Maps.isEmpty(aliasMap)) {
|
||||
hosts.forEach(s -> {
|
||||
String alias = aliasMap.get(s.getId());
|
||||
if (alias != null) {
|
||||
s.setAlias(Refs.unrefToString(alias));
|
||||
}
|
||||
});
|
||||
}
|
||||
// 设置主机颜色
|
||||
Map<Long, String> colorMap = extraList.get(1);
|
||||
if (!Maps.isEmpty(colorMap)) {
|
||||
hosts.forEach(s -> {
|
||||
HostColorExtraModel color = JSON.parseObject(colorMap.get(s.getId()), HostColorExtraModel.class);
|
||||
if (color != null) {
|
||||
s.setColor(color.getColor());
|
||||
}
|
||||
});
|
||||
// 这种主机标签信息
|
||||
for (HostVO host : hosts) {
|
||||
String extra = labelExtra.get(host.getId());
|
||||
if (extra == null) {
|
||||
continue;
|
||||
}
|
||||
HostLabelExtraModel label = HostExtraItemEnum.LABEL.parse(extra);
|
||||
if (label == null) {
|
||||
continue;
|
||||
}
|
||||
host.setAlias(label.getAlias());
|
||||
host.setColor(label.getColor());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,8 @@ public class AssetDataGrantServiceImpl implements AssetDataGrantService {
|
||||
List<Long> idList = request.getIdList();
|
||||
if (!Lists.isEmpty(idList)) {
|
||||
List<DataGroupDTO> groupList = dataGroupApi.getByIdList(idList);
|
||||
Valid.eq(groupList.size(), idList.size(), ErrorMessage.DATA_MODIFIED);
|
||||
idList.clear();
|
||||
idList.addAll(Lists.map(groupList, DataGroupDTO::getId));
|
||||
}
|
||||
// 数据授权
|
||||
SpringHolder.getBean(AssetDataGrantService.class)
|
||||
@@ -82,7 +83,8 @@ public class AssetDataGrantServiceImpl implements AssetDataGrantService {
|
||||
List<Long> idList = request.getIdList();
|
||||
if (!Lists.isEmpty(idList)) {
|
||||
List<HostKeyDO> keys = hostKeyDAO.selectBatchIds(idList);
|
||||
Valid.eq(keys.size(), idList.size(), ErrorMessage.DATA_MODIFIED);
|
||||
idList.clear();
|
||||
idList.addAll(Lists.map(keys, HostKeyDO::getId));
|
||||
}
|
||||
// 数据授权
|
||||
SpringHolder.getBean(AssetDataGrantService.class)
|
||||
@@ -98,7 +100,8 @@ public class AssetDataGrantServiceImpl implements AssetDataGrantService {
|
||||
List<Long> idList = request.getIdList();
|
||||
if (!Lists.isEmpty(idList)) {
|
||||
List<HostIdentityDO> identities = hostIdentityDAO.selectBatchIds(idList);
|
||||
Valid.eq(identities.size(), idList.size(), ErrorMessage.DATA_MODIFIED);
|
||||
idList.clear();
|
||||
idList.addAll(Lists.map(identities, HostIdentityDO::getId));
|
||||
}
|
||||
// 数据授权
|
||||
SpringHolder.getBean(AssetDataGrantService.class)
|
||||
|
||||
@@ -13,8 +13,10 @@ import com.orion.lang.utils.time.Dates;
|
||||
import com.orion.ops.framework.biz.operator.log.core.utils.OperatorLogs;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.constant.PathConst;
|
||||
import com.orion.ops.framework.common.file.FileClient;
|
||||
import com.orion.ops.framework.common.security.LoginUser;
|
||||
import com.orion.ops.framework.common.utils.PathUtils;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
||||
import com.orion.ops.module.asset.convert.ExecConvert;
|
||||
@@ -26,20 +28,19 @@ import com.orion.ops.module.asset.dao.HostDAO;
|
||||
import com.orion.ops.module.asset.entity.domain.ExecHostLogDO;
|
||||
import com.orion.ops.module.asset.entity.domain.ExecLogDO;
|
||||
import com.orion.ops.module.asset.entity.domain.HostDO;
|
||||
import com.orion.ops.module.asset.entity.dto.ExecCommandExecDTO;
|
||||
import com.orion.ops.module.asset.entity.dto.ExecParameterSchemaDTO;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecCommandExecRequest;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecCommandRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecHostLogVO;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecLogVO;
|
||||
import com.orion.ops.module.asset.enums.ExecHostStatusEnum;
|
||||
import com.orion.ops.module.asset.enums.ExecSourceEnum;
|
||||
import com.orion.ops.module.asset.enums.ExecStatusEnum;
|
||||
import com.orion.ops.module.asset.enums.HostConfigTypeEnum;
|
||||
import com.orion.ops.module.asset.enums.*;
|
||||
import com.orion.ops.module.asset.handler.host.config.model.HostSshConfigModel;
|
||||
import com.orion.ops.module.asset.handler.host.exec.command.ExecTaskExecutors;
|
||||
import com.orion.ops.module.asset.handler.host.exec.command.dto.ExecCommandDTO;
|
||||
import com.orion.ops.module.asset.handler.host.exec.command.dto.ExecCommandHostDTO;
|
||||
import com.orion.ops.module.asset.service.AssetAuthorizedDataService;
|
||||
import com.orion.ops.module.asset.service.ExecCommandService;
|
||||
import com.orion.ops.module.asset.service.HostConfigService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -48,7 +49,6 @@ import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -79,6 +79,9 @@ public class ExecCommandServiceImpl implements ExecCommandService {
|
||||
@Resource
|
||||
private HostDAO hostDAO;
|
||||
|
||||
@Resource
|
||||
private HostConfigService hostConfigService;
|
||||
|
||||
@Resource
|
||||
private AssetAuthorizedDataService assetAuthorizedDataService;
|
||||
|
||||
@@ -86,17 +89,17 @@ public class ExecCommandServiceImpl implements ExecCommandService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ExecLogVO execCommand(ExecCommandRequest request) {
|
||||
log.info("ExecService.startExecCommand start params: {}", JSON.toJSONString(request));
|
||||
LoginUser user = Objects.requireNonNull(SecurityUtils.getLoginUser());
|
||||
Valid.valid(ScriptExecEnum::of, request.getScriptExec());
|
||||
LoginUser user = Valid.notNull(SecurityUtils.getLoginUser());
|
||||
Long userId = user.getId();
|
||||
String command = request.getCommand();
|
||||
List<Long> hostIdList = request.getHostIdList();
|
||||
// 检查主机权限
|
||||
List<Long> authorizedHostIdList = assetAuthorizedDataService.getUserAuthorizedHostId(userId, HostConfigTypeEnum.SSH);
|
||||
List<Long> authorizedHostIdList = assetAuthorizedDataService.getUserAuthorizedHostIdWithEnabledConfig(userId, HostConfigTypeEnum.SSH);
|
||||
hostIdList.removeIf(s -> !authorizedHostIdList.contains(s));
|
||||
log.info("ExecService.startExecCommand host hostList: {}", hostIdList);
|
||||
Valid.notEmpty(hostIdList, ErrorMessage.CHECK_AUTHORIZED_HOST);
|
||||
// 执行命令
|
||||
ExecCommandExecRequest execRequest = ExecConvert.MAPPER.to(request);
|
||||
ExecCommandExecDTO execRequest = ExecConvert.MAPPER.to(request);
|
||||
execRequest.setUserId(userId);
|
||||
execRequest.setUsername(user.getUsername());
|
||||
execRequest.setSource(ExecSourceEnum.BATCH.name());
|
||||
@@ -105,10 +108,13 @@ public class ExecCommandServiceImpl implements ExecCommandService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ExecLogVO execCommandWithSource(ExecCommandExecRequest request) {
|
||||
public ExecLogVO execCommandWithSource(ExecCommandExecDTO request) {
|
||||
String command = request.getCommand();
|
||||
List<Long> hostIdList = request.getHostIdList();
|
||||
// 查询主机信息
|
||||
List<HostDO> hosts = hostDAO.selectBatchIds(hostIdList);
|
||||
// 查询主机配置
|
||||
Map<Long, HostSshConfigModel> hostConfigMap = hostConfigService.getHostConfigMap(hostIdList, HostConfigTypeEnum.SSH);
|
||||
// 插入日志
|
||||
ExecLogDO execLog = ExecLogDO.builder()
|
||||
.userId(request.getUserId())
|
||||
@@ -126,6 +132,7 @@ public class ExecCommandServiceImpl implements ExecCommandService {
|
||||
.command(command)
|
||||
.parameterSchema(request.getParameterSchema())
|
||||
.timeout(request.getTimeout())
|
||||
.scriptExec(request.getScriptExec())
|
||||
.status(ExecStatusEnum.WAITING.name())
|
||||
.build();
|
||||
execLogDAO.insert(execLog);
|
||||
@@ -134,24 +141,13 @@ public class ExecCommandServiceImpl implements ExecCommandService {
|
||||
Map<String, Object> builtinsParams = this.getBaseBuiltinsParams(execId, request);
|
||||
// 设置主机日志
|
||||
List<ExecHostLogDO> execHostLogs = hosts.stream()
|
||||
.map(s -> {
|
||||
String parameter = JSON.toJSONString(this.getHostParams(builtinsParams, s));
|
||||
return ExecHostLogDO.builder()
|
||||
.logId(execId)
|
||||
.hostId(s.getId())
|
||||
.hostName(s.getName())
|
||||
.hostAddress(s.getAddress())
|
||||
.status(ExecHostStatusEnum.WAITING.name())
|
||||
.command(FORMATTER.format(command, parameter))
|
||||
.parameter(parameter)
|
||||
.logPath(this.buildLogPath(execId, s.getId()))
|
||||
.build();
|
||||
}).collect(Collectors.toList());
|
||||
.map(s -> this.convertExecHostLog(s, execLog, hostConfigMap.get(s.getId()), builtinsParams))
|
||||
.collect(Collectors.toList());
|
||||
execHostLogDAO.insertBatch(execHostLogs);
|
||||
// 操作日志
|
||||
OperatorLogs.add(OperatorLogs.LOG_ID, execId);
|
||||
// 开始执行
|
||||
this.startExec(execLog, execHostLogs);
|
||||
this.startExec(execLog, execHostLogs, hostConfigMap);
|
||||
// 返回
|
||||
ExecLogVO result = ExecLogConvert.MAPPER.to(execLog);
|
||||
List<ExecHostLogVO> resultHosts = ExecHostLogConvert.MAPPER.to(execHostLogs);
|
||||
@@ -176,6 +172,7 @@ public class ExecCommandServiceImpl implements ExecCommandService {
|
||||
ExecCommandRequest request = ExecCommandRequest.builder()
|
||||
.description(execLog.getDescription())
|
||||
.timeout(execLog.getTimeout())
|
||||
.scriptExec(execLog.getScriptExec())
|
||||
.command(execLog.getCommand())
|
||||
.parameterSchema(execLog.getParameterSchema())
|
||||
.hostIdList(hostIdList)
|
||||
@@ -186,26 +183,74 @@ public class ExecCommandServiceImpl implements ExecCommandService {
|
||||
/**
|
||||
* 开始执行命令
|
||||
*
|
||||
* @param execLog execLog
|
||||
* @param execHostLogs hostLogs
|
||||
* @param execLog execLog
|
||||
* @param execHostLogs hostLogs
|
||||
* @param hostConfigMap hostConfigMap
|
||||
*/
|
||||
private void startExec(ExecLogDO execLog, List<ExecHostLogDO> execHostLogs) {
|
||||
private void startExec(ExecLogDO execLog,
|
||||
List<ExecHostLogDO> execHostLogs,
|
||||
Map<Long, HostSshConfigModel> hostConfigMap) {
|
||||
// 执行主机
|
||||
List<ExecCommandHostDTO> hosts = execHostLogs.stream()
|
||||
.map(s -> {
|
||||
HostSshConfigModel config = hostConfigMap.get(s.getHostId());
|
||||
return ExecCommandHostDTO.builder()
|
||||
.hostId(s.getHostId())
|
||||
.hostLogId(s.getId())
|
||||
.command(s.getCommand())
|
||||
.logPath(s.getLogPath())
|
||||
.scriptPath(s.getScriptPath())
|
||||
.charset(config.getCharset())
|
||||
.fileNameCharset(config.getFileNameCharset())
|
||||
.fileContentCharset(config.getFileContentCharset())
|
||||
.build();
|
||||
}).collect(Collectors.toList());
|
||||
// 执行信息
|
||||
ExecCommandDTO exec = ExecCommandDTO.builder()
|
||||
.logId(execLog.getId())
|
||||
.timeout(execLog.getTimeout())
|
||||
.hosts(execHostLogs.stream()
|
||||
.map(s -> ExecCommandHostDTO.builder()
|
||||
.hostId(s.getHostId())
|
||||
.hostLogId(s.getId())
|
||||
.command(s.getCommand())
|
||||
.timeout(execLog.getTimeout())
|
||||
.logPath(s.getLogPath())
|
||||
.build())
|
||||
.collect(Collectors.toList()))
|
||||
.scriptExec(ScriptExecEnum.isEnabled(execLog.getScriptExec()))
|
||||
.hosts(hosts)
|
||||
.build();
|
||||
// 开始执行
|
||||
ExecTaskExecutors.start(exec);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为 execHostLog
|
||||
*
|
||||
* @param host host
|
||||
* @param execLog execLog
|
||||
* @param config config
|
||||
* @param builtinsParams builtinsParams
|
||||
* @return execHostLog
|
||||
*/
|
||||
private ExecHostLogDO convertExecHostLog(HostDO host,
|
||||
ExecLogDO execLog,
|
||||
HostSshConfigModel config,
|
||||
Map<String, Object> builtinsParams) {
|
||||
Long execId = execLog.getId();
|
||||
Long hostId = host.getId();
|
||||
// 脚本路径
|
||||
String scriptPath = null;
|
||||
if (ScriptExecEnum.isEnabled(execLog.getScriptExec())) {
|
||||
scriptPath = this.buildScriptPath(config.getUsername(), config.getOsType(), execId, hostId);
|
||||
}
|
||||
// 获取参数
|
||||
String parameter = JSON.toJSONString(this.getHostParams(builtinsParams, host, config, scriptPath));
|
||||
return ExecHostLogDO.builder()
|
||||
.logId(execId)
|
||||
.hostId(hostId)
|
||||
.hostName(host.getName())
|
||||
.hostAddress(host.getAddress())
|
||||
.status(ExecHostStatusEnum.WAITING.name())
|
||||
.command(FORMATTER.format(execLog.getCommand(), parameter))
|
||||
.parameter(parameter)
|
||||
.logPath(this.buildLogPath(execId, hostId))
|
||||
.scriptPath(scriptPath)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取基础内置参数
|
||||
*
|
||||
@@ -213,7 +258,7 @@ public class ExecCommandServiceImpl implements ExecCommandService {
|
||||
* @param request request
|
||||
* @return params
|
||||
*/
|
||||
private Map<String, Object> getBaseBuiltinsParams(Long execId, ExecCommandExecRequest request) {
|
||||
private Map<String, Object> getBaseBuiltinsParams(Long execId, ExecCommandExecDTO request) {
|
||||
String uuid = UUIds.random();
|
||||
Date date = new Date();
|
||||
// 输入参数
|
||||
@@ -225,6 +270,7 @@ public class ExecCommandServiceImpl implements ExecCommandService {
|
||||
params.put("sourceId", request.getSourceId());
|
||||
params.put("seq", request.getExecSeq());
|
||||
params.put("execId", execId);
|
||||
params.put("scriptExec", request.getScriptExec());
|
||||
params.put("uuid", uuid);
|
||||
params.put("uuidShort", uuid.replace("-", Strings.EMPTY));
|
||||
params.put("timestampMillis", date.getTime());
|
||||
@@ -239,9 +285,14 @@ public class ExecCommandServiceImpl implements ExecCommandService {
|
||||
*
|
||||
* @param baseParams baseParams
|
||||
* @param host host
|
||||
* @param config config
|
||||
* @param scriptPath scriptPath
|
||||
* @return params
|
||||
*/
|
||||
private Map<String, Object> getHostParams(Map<String, Object> baseParams, HostDO host) {
|
||||
private Map<String, Object> getHostParams(Map<String, Object> baseParams,
|
||||
HostDO host,
|
||||
HostSshConfigModel config,
|
||||
String scriptPath) {
|
||||
String uuid = UUIds.random();
|
||||
Map<String, Object> params = Maps.newMap(baseParams);
|
||||
params.put("hostId", host.getId());
|
||||
@@ -250,6 +301,11 @@ public class ExecCommandServiceImpl implements ExecCommandService {
|
||||
params.put("hostAddress", host.getAddress());
|
||||
params.put("hostUuid", uuid);
|
||||
params.put("hostUuidShort", uuid.replace("-", Strings.EMPTY));
|
||||
params.put("hostUsername", config.getUsername());
|
||||
params.put("osType", config.getOsType());
|
||||
params.put("port", config.getPort());
|
||||
params.put("charset", config.getCharset());
|
||||
params.put("scriptPath", scriptPath);
|
||||
return params;
|
||||
}
|
||||
|
||||
@@ -279,8 +335,26 @@ public class ExecCommandServiceImpl implements ExecCommandService {
|
||||
* @return logPath
|
||||
*/
|
||||
private String buildLogPath(Long logId, Long hostId) {
|
||||
String logFile = "/exec/" + logId + "/" + logId + "_" + hostId + ".log";
|
||||
String logFile = "/" + PathConst.EXEC + "/" + logId + "/" + logId + "_" + hostId + ".log";
|
||||
return logsFileClient.getReturnPath(logFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* 侯建脚本路径
|
||||
*
|
||||
* @param username username
|
||||
* @param osType osType
|
||||
* @param logId logId
|
||||
* @param hostId hostId
|
||||
* @return scriptPath
|
||||
*/
|
||||
private String buildScriptPath(String username, String osType, Long logId, Long hostId) {
|
||||
HostSshOsTypeEnum os = HostSshOsTypeEnum.of(osType);
|
||||
String name = PathConst.EXEC
|
||||
+ "_" + logId
|
||||
+ "_" + hostId
|
||||
+ os.getScriptSuffix();
|
||||
return PathUtils.buildAppPath(HostSshOsTypeEnum.WINDOWS.equals(os), username, PathConst.SCRIPT, name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,12 +19,14 @@ import com.orion.ops.module.asset.dao.HostDAO;
|
||||
import com.orion.ops.module.asset.entity.domain.ExecJobDO;
|
||||
import com.orion.ops.module.asset.entity.domain.ExecLogDO;
|
||||
import com.orion.ops.module.asset.entity.domain.HostDO;
|
||||
import com.orion.ops.module.asset.entity.dto.ExecCommandExecDTO;
|
||||
import com.orion.ops.module.asset.entity.request.exec.*;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecJobVO;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecLogVO;
|
||||
import com.orion.ops.module.asset.enums.ExecJobStatusEnum;
|
||||
import com.orion.ops.module.asset.enums.ExecSourceEnum;
|
||||
import com.orion.ops.module.asset.enums.HostConfigTypeEnum;
|
||||
import com.orion.ops.module.asset.enums.ScriptExecEnum;
|
||||
import com.orion.ops.module.asset.handler.host.exec.job.ExecCommandJob;
|
||||
import com.orion.ops.module.asset.service.AssetAuthorizedDataService;
|
||||
import com.orion.ops.module.asset.service.ExecCommandService;
|
||||
@@ -79,6 +81,7 @@ public class ExecJobServiceImpl implements ExecJobService {
|
||||
log.info("ExecJobService-createExecJob request: {}", JSON.toJSONString(request));
|
||||
// 验证表达式是否正确
|
||||
Cron.of(request.getExpression());
|
||||
Valid.valid(ScriptExecEnum::of, request.getScriptExec());
|
||||
// 转换
|
||||
ExecJobDO record = ExecJobConvert.MAPPER.to(request);
|
||||
// 查询数据是否冲突
|
||||
@@ -104,6 +107,7 @@ public class ExecJobServiceImpl implements ExecJobService {
|
||||
log.info("ExecJobService-updateExecJobById id: {}, request: {}", id, JSON.toJSONString(request));
|
||||
// 验证表达式是否正确
|
||||
Cron.of(request.getExpression());
|
||||
Valid.valid(ScriptExecEnum::of, request.getScriptExec());
|
||||
// 查询
|
||||
ExecJobDO record = execJobDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
@@ -278,7 +282,7 @@ public class ExecJobServiceImpl implements ExecJobService {
|
||||
OperatorLogs.add(OperatorLogs.NAME, job.getName());
|
||||
OperatorLogs.add(OperatorLogs.SEQ, execSeq);
|
||||
// 执行命令
|
||||
ExecCommandExecRequest exec = ExecCommandExecRequest.builder()
|
||||
ExecCommandExecDTO exec = ExecCommandExecDTO.builder()
|
||||
.userId(request.getUserId())
|
||||
.username(request.getUsername())
|
||||
.source(ExecSourceEnum.JOB.name())
|
||||
@@ -286,6 +290,7 @@ public class ExecJobServiceImpl implements ExecJobService {
|
||||
.execSeq(execSeq)
|
||||
.description(job.getName())
|
||||
.timeout(job.getTimeout())
|
||||
.scriptExec(job.getScriptExec())
|
||||
.command(job.getCommand())
|
||||
.parameterSchema(job.getParameterSchema())
|
||||
.hostIdList(hostIdList)
|
||||
@@ -356,7 +361,7 @@ public class ExecJobServiceImpl implements ExecJobService {
|
||||
*/
|
||||
private void checkHostPermission(List<Long> hostIdList) {
|
||||
// 查询有权限的主机
|
||||
List<Long> authorizedHostIdList = assetAuthorizedDataService.getUserAuthorizedHostId(SecurityUtils.getLoginUserId(), HostConfigTypeEnum.SSH);
|
||||
List<Long> authorizedHostIdList = assetAuthorizedDataService.getUserAuthorizedHostIdWithEnabledConfig(SecurityUtils.getLoginUserId(), HostConfigTypeEnum.SSH);
|
||||
for (Long hostId : hostIdList) {
|
||||
Valid.isTrue(authorizedHostIdList.contains(hostId), Strings.format(ErrorMessage.PLEASE_CHECK_HOST_SSH, hostId));
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import com.orion.lang.utils.io.Files1;
|
||||
import com.orion.ops.framework.biz.operator.log.core.utils.OperatorLogs;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.constant.FieldConst;
|
||||
import com.orion.ops.framework.common.constant.PathConst;
|
||||
import com.orion.ops.framework.common.file.FileClient;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisStrings;
|
||||
@@ -32,10 +32,10 @@ import com.orion.ops.module.asset.entity.request.exec.ExecLogTailRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecHostLogVO;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecLogStatusVO;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecLogVO;
|
||||
import com.orion.ops.module.asset.entity.vo.HostConfigVO;
|
||||
import com.orion.ops.module.asset.enums.ExecHostStatusEnum;
|
||||
import com.orion.ops.module.asset.enums.ExecStatusEnum;
|
||||
import com.orion.ops.module.asset.enums.HostConfigTypeEnum;
|
||||
import com.orion.ops.module.asset.handler.host.config.model.HostSshConfigModel;
|
||||
import com.orion.ops.module.asset.handler.host.exec.command.handler.IExecCommandHandler;
|
||||
import com.orion.ops.module.asset.handler.host.exec.command.handler.IExecTaskHandler;
|
||||
import com.orion.ops.module.asset.handler.host.exec.command.manager.ExecTaskManager;
|
||||
@@ -51,7 +51,6 @@ import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -365,9 +364,7 @@ public class ExecLogServiceImpl implements ExecLogService {
|
||||
List<Long> hostIdList = hostLogs.stream()
|
||||
.map(ExecHostLogDO::getHostId)
|
||||
.collect(Collectors.toList());
|
||||
Map<Long, HostConfigVO> configMap = hostConfigService.getHostConfigList(hostIdList, HostConfigTypeEnum.SSH.getType())
|
||||
.stream()
|
||||
.collect(Collectors.toMap(HostConfigVO::getId, Function.identity()));
|
||||
Map<Long, HostSshConfigModel> configMap = hostConfigService.getHostConfigMap(hostIdList, HostConfigTypeEnum.SSH);
|
||||
// 生成缓存
|
||||
String token = UUIds.random19();
|
||||
String cacheKey = ExecCacheKeyDefine.EXEC_TAIL.format(token);
|
||||
@@ -381,8 +378,7 @@ public class ExecLogServiceImpl implements ExecLogService {
|
||||
.hostId(s.getHostId())
|
||||
.path(s.getLogPath())
|
||||
.charset(Optional.ofNullable(configMap.get(s.getHostId()))
|
||||
.map(HostConfigVO::getConfig)
|
||||
.map(c -> c.get(FieldConst.CHARSET))
|
||||
.map(HostSshConfigModel::getCharset)
|
||||
.map(Objects1::toString)
|
||||
.orElse(Const.UTF_8))
|
||||
.build())
|
||||
@@ -433,7 +429,7 @@ public class ExecLogServiceImpl implements ExecLogService {
|
||||
}
|
||||
// 响应错误信息
|
||||
try {
|
||||
Servlets.transfer(response, Strings.bytes(errorMessage), Const.ERROR_LOG);
|
||||
Servlets.transfer(response, Strings.bytes(errorMessage), PathConst.ERROR_LOG);
|
||||
} catch (Exception ex) {
|
||||
log.error("ExecLogService.downloadLogFile transfer-error id: {}", id, ex);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.orion.ops.module.asset.entity.request.exec.ExecTemplateCreateRequest;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecTemplateQueryRequest;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecTemplateUpdateRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecTemplateVO;
|
||||
import com.orion.ops.module.asset.enums.ScriptExecEnum;
|
||||
import com.orion.ops.module.asset.service.ExecTemplateService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -35,6 +36,7 @@ public class ExecTemplateServiceImpl implements ExecTemplateService {
|
||||
@Override
|
||||
public Long createExecTemplate(ExecTemplateCreateRequest request) {
|
||||
log.info("ExecTemplateService-createExecTemplate request: {}", JSON.toJSONString(request));
|
||||
Valid.valid(ScriptExecEnum::of, request.getScriptExec());
|
||||
// 转换
|
||||
ExecTemplateDO record = ExecTemplateConvert.MAPPER.to(request);
|
||||
// 查询数据是否冲突
|
||||
@@ -49,6 +51,7 @@ public class ExecTemplateServiceImpl implements ExecTemplateService {
|
||||
@Override
|
||||
public Integer updateExecTemplateById(ExecTemplateUpdateRequest request) {
|
||||
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
|
||||
Valid.valid(ScriptExecEnum::of, request.getScriptExec());
|
||||
log.info("ExecTemplateService-updateExecTemplateById id: {}, request: {}", id, JSON.toJSONString(request));
|
||||
// 查询
|
||||
ExecTemplateDO record = execTemplateDAO.selectById(id);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.orion.ops.module.asset.service.impl;
|
||||
|
||||
import com.orion.lang.function.Functions;
|
||||
import com.orion.lang.utils.Exceptions;
|
||||
import com.orion.ops.framework.biz.operator.log.core.utils.OperatorLogs;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
@@ -92,6 +93,18 @@ public class HostConfigServiceImpl implements HostConfigService {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends GenericsDataModel> Map<Long, T> getHostConfigMap(List<Long> hostIdList, HostConfigTypeEnum type) {
|
||||
// 查询
|
||||
List<HostConfigDO> configs = hostConfigDAO.getHostConfigByHostIdList(hostIdList, type.getType());
|
||||
// 返回
|
||||
return configs.stream()
|
||||
.collect(Collectors.toMap(
|
||||
HostConfigDO::getHostId,
|
||||
s -> type.parse(s.getConfig()),
|
||||
Functions.right()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer updateHostConfig(HostConfigUpdateRequest request) {
|
||||
// 查询原配置
|
||||
|
||||
@@ -1,20 +1,16 @@
|
||||
package com.orion.ops.module.asset.service.impl;
|
||||
|
||||
import com.orion.lang.function.Functions;
|
||||
import com.orion.lang.utils.Refs;
|
||||
import com.orion.lang.utils.collect.Maps;
|
||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.handler.data.model.GenericsDataModel;
|
||||
import com.orion.ops.framework.common.handler.data.strategy.MapDataStrategy;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostAliasUpdateRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostExtraQueryRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostExtraUpdateRequest;
|
||||
import com.orion.ops.module.asset.enums.HostExtraItemEnum;
|
||||
import com.orion.ops.module.asset.service.HostExtraService;
|
||||
import com.orion.ops.module.infra.api.DataExtraApi;
|
||||
import com.orion.ops.module.infra.constant.DataExtraItems;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataExtraDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataExtraQueryDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataExtraSetDTO;
|
||||
@@ -39,17 +35,6 @@ public class HostExtraServiceImpl implements HostExtraService {
|
||||
@Resource
|
||||
private DataExtraApi dataExtraApi;
|
||||
|
||||
@Override
|
||||
public Integer updateHostAlias(HostAliasUpdateRequest request) {
|
||||
DataExtraSetDTO update = DataExtraSetDTO.builder()
|
||||
.userId(SecurityUtils.getLoginUserId())
|
||||
.item(DataExtraItems.ALIAS)
|
||||
.relId(request.getId())
|
||||
.value(Refs.json(request.getName()))
|
||||
.build();
|
||||
return dataExtraApi.setExtraItem(update, DataExtraTypeEnum.HOST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getHostExtra(Long hostId, String item) {
|
||||
HostExtraItemEnum extraItem = Valid.valid(HostExtraItemEnum::of, item);
|
||||
@@ -110,21 +95,24 @@ public class HostExtraServiceImpl implements HostExtraService {
|
||||
|
||||
@Override
|
||||
public Integer updateHostExtra(HostExtraUpdateRequest request) {
|
||||
String item = request.getItem();
|
||||
Long hostId = request.getHostId();
|
||||
Long userId = SecurityUtils.getLoginUserId();
|
||||
HostExtraItemEnum extraItem = Valid.valid(HostExtraItemEnum::of, item);
|
||||
MapDataStrategy<GenericsDataModel> strategy = extraItem.getStrategyBean();
|
||||
HostExtraItemEnum item = Valid.valid(HostExtraItemEnum::of, request.getItem());
|
||||
MapDataStrategy<GenericsDataModel> strategy = item.getStrategyBean();
|
||||
// 查询原始配置
|
||||
DataExtraQueryDTO query = DataExtraQueryDTO.builder()
|
||||
.userId(userId)
|
||||
.relId(hostId)
|
||||
.item(item)
|
||||
.item(item.getItem())
|
||||
.build();
|
||||
DataExtraDTO beforeExtraItem = dataExtraApi.getExtraItem(query, DataExtraTypeEnum.HOST);
|
||||
Valid.notNull(beforeExtraItem, ErrorMessage.CONFIG_ABSENT);
|
||||
GenericsDataModel newExtra = extraItem.parse(request.getExtra());
|
||||
GenericsDataModel beforeExtra = extraItem.parse(beforeExtraItem.getValue());
|
||||
if (beforeExtraItem == null) {
|
||||
// 初始化并查询
|
||||
this.checkInitItem(item, userId, hostId);
|
||||
beforeExtraItem = dataExtraApi.getExtraItem(query, DataExtraTypeEnum.HOST);
|
||||
}
|
||||
GenericsDataModel newExtra = item.parse(request.getExtra());
|
||||
GenericsDataModel beforeExtra = item.parse(beforeExtraItem.getValue());
|
||||
// 更新验证
|
||||
strategy.doValidChain(beforeExtra, newExtra);
|
||||
// 更新配置
|
||||
@@ -134,28 +122,42 @@ public class HostExtraServiceImpl implements HostExtraService {
|
||||
/**
|
||||
* 检查配置项并且转为视图 (不存在则初始化默认值)
|
||||
*
|
||||
* @param extraItem extraItem
|
||||
* @param item item
|
||||
* @param extraValue extraValue
|
||||
* @param userId userId
|
||||
* @param hostId hostId
|
||||
* @return viewMap
|
||||
*/
|
||||
private Map<String, Object> checkItemAndToView(HostExtraItemEnum extraItem, String extraValue, Long userId, Long hostId) {
|
||||
String item = extraItem.getItem();
|
||||
MapDataStrategy<GenericsDataModel> strategy = extraItem.getStrategyBean();
|
||||
private Map<String, Object> checkItemAndToView(HostExtraItemEnum item, String extraValue, Long userId, Long hostId) {
|
||||
MapDataStrategy<GenericsDataModel> strategy = item.getStrategyBean();
|
||||
if (extraValue == null) {
|
||||
// 初始化默认数据
|
||||
extraValue = strategy.getDefault().serial();
|
||||
// 插入默认值
|
||||
DataExtraSetDTO set = DataExtraSetDTO.builder()
|
||||
.userId(userId)
|
||||
.relId(hostId)
|
||||
.item(item)
|
||||
.value(extraValue)
|
||||
.build();
|
||||
dataExtraApi.addExtraItem(set, DataExtraTypeEnum.HOST);
|
||||
extraValue = this.checkInitItem(item, userId, hostId);
|
||||
}
|
||||
return strategy.toView(extraValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查配置项 不存在则初始化默认值
|
||||
*
|
||||
* @param item item
|
||||
* @param userId userId
|
||||
* @param hostId hostId
|
||||
* @return defaultValue
|
||||
*/
|
||||
private String checkInitItem(HostExtraItemEnum item, Long userId, Long hostId) {
|
||||
MapDataStrategy<GenericsDataModel> strategy = item.getStrategyBean();
|
||||
// 初始化默认数据
|
||||
String extraValue = strategy.getDefault().serial();
|
||||
// 插入默认值
|
||||
DataExtraSetDTO set = DataExtraSetDTO.builder()
|
||||
.userId(userId)
|
||||
.relId(hostId)
|
||||
.item(item.getItem())
|
||||
.value(extraValue)
|
||||
.build();
|
||||
dataExtraApi.addExtraItem(set, DataExtraTypeEnum.HOST);
|
||||
return extraValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,8 +25,11 @@ import com.orion.ops.module.asset.entity.request.host.HostIdentityCreateRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostIdentityQueryRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostIdentityUpdateRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.HostIdentityVO;
|
||||
import com.orion.ops.module.asset.enums.HostIdentityTypeEnum;
|
||||
import com.orion.ops.module.asset.service.HostIdentityService;
|
||||
import com.orion.ops.module.infra.api.DataExtraApi;
|
||||
import com.orion.ops.module.infra.api.DataPermissionApi;
|
||||
import com.orion.ops.module.infra.enums.DataPermissionTypeEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -60,11 +63,14 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
@Resource
|
||||
private DataExtraApi dataExtraApi;
|
||||
|
||||
@Resource
|
||||
private DataPermissionApi dataPermissionApi;
|
||||
|
||||
@Override
|
||||
public Long createHostIdentity(HostIdentityCreateRequest request) {
|
||||
log.info("HostIdentityService-createHostIdentity request: {}", JSON.toJSONString(request));
|
||||
// 检查秘钥是否存在
|
||||
this.checkKeyIdPresent(request.getKeyId());
|
||||
this.checkCreateParams(request);
|
||||
// 转换
|
||||
HostIdentityDO record = HostIdentityConvert.MAPPER.to(request);
|
||||
// 查询数据是否冲突
|
||||
@@ -85,19 +91,25 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
@Override
|
||||
public Integer updateHostIdentityById(HostIdentityUpdateRequest request) {
|
||||
log.info("HostIdentityService-updateHostIdentityById request: {}", JSON.toJSONString(request));
|
||||
// 查询
|
||||
// 验证参数
|
||||
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
|
||||
HostIdentityTypeEnum type = Valid.valid(HostIdentityTypeEnum::of, request.getType());
|
||||
if (HostIdentityTypeEnum.KEY.equals(type)) {
|
||||
// 秘钥认证
|
||||
this.checkKeyId(request.getKeyId());
|
||||
}
|
||||
// 查询主机身份
|
||||
HostIdentityDO record = hostIdentityDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
// 检查秘钥是否存在
|
||||
this.checkKeyIdPresent(request.getKeyId());
|
||||
// 转换
|
||||
HostIdentityDO updateRecord = HostIdentityConvert.MAPPER.to(request);
|
||||
// 查询数据是否冲突
|
||||
this.checkHostIdentityPresent(updateRecord);
|
||||
// 设置密码
|
||||
String newPassword = PasswordModifier.getEncryptNewPassword(request);
|
||||
updateRecord.setPassword(newPassword);
|
||||
if (HostIdentityTypeEnum.PASSWORD.equals(type)) {
|
||||
// 设置密码
|
||||
String newPassword = PasswordModifier.getEncryptNewPassword(request);
|
||||
updateRecord.setPassword(newPassword);
|
||||
}
|
||||
// 更新
|
||||
LambdaUpdateWrapper<HostIdentityDO> wrapper = Wrappers.<HostIdentityDO>lambdaUpdate()
|
||||
.set(HostIdentityDO::getKeyId, request.getKeyId())
|
||||
@@ -105,10 +117,7 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
int effect = hostIdentityDAO.update(updateRecord, wrapper);
|
||||
log.info("HostIdentityService-updateHostIdentityById effect: {}", effect);
|
||||
// 删除缓存
|
||||
if (!record.getName().equals(updateRecord.getName()) ||
|
||||
!record.getUsername().equals(updateRecord.getUsername())) {
|
||||
RedisMaps.delete(HostCacheKeyDefine.HOST_IDENTITY);
|
||||
}
|
||||
RedisMaps.delete(HostCacheKeyDefine.HOST_IDENTITY);
|
||||
return effect;
|
||||
}
|
||||
|
||||
@@ -155,6 +164,7 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
}
|
||||
// 设置秘钥名称
|
||||
List<Long> keyIdList = dataGrid.stream()
|
||||
.filter(s -> HostIdentityTypeEnum.KEY.name().equals(s.getType()))
|
||||
.map(HostIdentityVO::getKeyId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
@@ -188,6 +198,8 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
hostConfigDAO.setIdentityIdWithNull(id);
|
||||
// 删除主机身份额外配置
|
||||
dataExtraApi.deleteHostIdentityExtra(id);
|
||||
// 删除数据权限
|
||||
dataPermissionApi.deleteByRelId(DataPermissionTypeEnum.HOST_IDENTITY, id);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(HostCacheKeyDefine.HOST_IDENTITY.getKey(), record.getId());
|
||||
log.info("HostIdentityService-deleteHostIdentityById effect: {}", effect);
|
||||
@@ -212,14 +224,28 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查秘钥是否存在
|
||||
* 检查创建参数
|
||||
*
|
||||
* @param request request
|
||||
*/
|
||||
private void checkCreateParams(HostIdentityCreateRequest request) {
|
||||
HostIdentityTypeEnum type = Valid.valid(HostIdentityTypeEnum::of, request.getType());
|
||||
if (HostIdentityTypeEnum.PASSWORD.equals(type)) {
|
||||
// 密码认证
|
||||
Valid.notBlank(request.getPassword(), ErrorMessage.PARAM_MISSING);
|
||||
} else if (HostIdentityTypeEnum.KEY.equals(type)) {
|
||||
// 秘钥认证
|
||||
this.checkKeyId(request.getKeyId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查 keyId 是否存在
|
||||
*
|
||||
* @param keyId keyId
|
||||
*/
|
||||
private void checkKeyIdPresent(Long keyId) {
|
||||
if (keyId == null) {
|
||||
return;
|
||||
}
|
||||
private void checkKeyId(Long keyId) {
|
||||
Valid.notNull(keyId, ErrorMessage.PARAM_MISSING);
|
||||
Valid.notNull(hostKeyDAO.selectById(keyId), ErrorMessage.KEY_ABSENT);
|
||||
}
|
||||
|
||||
@@ -234,6 +260,7 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
return hostIdentityDAO.wrapper()
|
||||
.eq(HostIdentityDO::getId, request.getId())
|
||||
.like(HostIdentityDO::getName, request.getName())
|
||||
.eq(HostIdentityDO::getType, request.getType())
|
||||
.like(HostIdentityDO::getUsername, request.getUsername())
|
||||
.eq(HostIdentityDO::getKeyId, request.getKeyId())
|
||||
.and(Strings.isNotEmpty(searchValue), c -> c
|
||||
|
||||