节点在线、应用在线、配置在线使用令牌查询
大石头 authored at 2021-12-16 19:49:30
15.26 KiB
Stardust
# 远程部署(Nodes/AgentDeploy) > 块:节点代理 > MVC:`Stardust.Web/Areas/Nodes/Controllers/AgentDeployController.cs` > WebApi:`Stardust.WebApi/Areas/Nodes/Controllers/AgentDeployController.cs` > 盘点:2026-11-02 > **WebApi 对齐状态:✅ 已完成(2026-11-04)**——MVC 功能已全部在 WebApi 实现或已一致(缺口补齐/行为对齐/有意不补三类逐项标注);本次处理明细见 §7「2026-11-04 WebApi 补齐记录」;整体验证=dotnet build Release 0 错误 + 6681 冒烟 + McpApiTests 40/40;状态总表=Doc/MVC功能真源/WebApi对齐状态总表.md ## 1. 用户用它做什么 菜单特性:`[DisplayName("远程部署")]`、`[Menu(70, true, Icon = "fa-rocket")]`(`AgentDeployController.cs:16-17`,第二参数 `true` 表示进入 Nodes 区域菜单)。 本页是 **StarAgent 远程部署操作面板**(非 Cube 标准列表):通过 SSH 把 StarAgent 安装到一台或多台目标主机(支持逗号/换行分隔多 IP 或 CIDR 网段)。用户填写 SSH 凭据、操作系统与 .NET 版本、StarServer 地址与安装包下载地址,可先 **测试连接**(仅测目标主机列表中的第一个地址),再 **开始部署**;部署结果以表格展示每台主机的成功/失败、消息,并可弹窗查看详细输出。 ## 2. 入口与跳转 ### 页面 URL | 用途 | URL 模板 | 依据 | |------|----------|------| | 部署操作面板 | GET `/Nodes/AgentDeploy` 或 GET `/Nodes/AgentDeploy/Index` | `AgentDeployController.cs:35-44`;Cube 默认 Index 路由 | | 测试连接 | POST `/Nodes/AgentDeploy/TestConnection` | `Index.cshtml:174-175` | | 开始部署 | POST `/Nodes/AgentDeploy/Deploy?executeOn={server\|web}` | `Index.cshtml:208-209` | ### 谁链进来 | 来源 | 说明 | 文件:行号 | |------|------|-----------| | Nodes 区域菜单 | `[Menu(70, true)]` 菜单名「远程部署」,图标 `fa-rocket` | `AgentDeployController.cs:16-17` | | 应用导航 `_App_Nav.cshtml` | **未**出现 `AgentDeploy` 或「远程部署」链接 | 通读 `Stardust.Web/Views/Shared/_App_Nav.cshtml`,无本页 URL | | 节点导航 `_Node_Nav.cshtml` | **未**链到本页;页签含节点名、在线、历史、命令、性能、框架推荐;StarAgent 产品时另有应用在线、应用发布 | `_Node_Nav.cshtml:18-30`,无 `AgentDeploy` | | 项目导航 `_Project_Nav.cshtml` | **未**链到本页 | 通读 `Stardust.Web/Views/Shared/_Project_Nav.cshtml`,无 `AgentDeploy` | | 其它列表/控制器 | 仓库内 `Stardust.Web` 除本控制器与 `Index.cshtml` 外无其它引用 `AgentDeploy` 的链接 | `Stardust.Web` 内 grep 结果 | ### 本页链出去 | 出口 | 说明 | 文件:行号 | |------|------|-----------| | 无页面级外链 | 面板内 AJAX 调本控制器;部署结果「查看」为 Bootstrap 模态框,不跳转 URL | `Index.cshtml:263-285` | ## 3. 功能清单 | ID | 用户动作 | 入口 | HTTP 与路径 | 参数 | 成功时发生什么 | 失败或禁用条件 | |----|----------|------|-------------|------|----------------|----------------| | F01 | 打开远程部署面板 | Nodes 菜单「远程部署」 | GET `/Nodes/AgentDeploy` | 无 | 渲染 `Index.cshtml`;`ViewBag.ServerUrl` = `http://{Request.Host}`;`ViewBag.DownloadUrl` = `http://x.newlifex.com/star/` | 未在源码确认鉴权失败表现 | | F02 | 查看页标题与说明 | 页面顶部 | — | — | 标题「StarAgent远程部署」、副文案「通过SSH远程部署StarAgent到目标服务器」 | `Index.cshtml:6-12` | | F03 | 填写/修改部署配置 | 「部署配置」表单 | — | 见 §5 各字段 | 前端 `getFormData()` 组装 JSON 对象 | `Index.cshtml:19-97`、`130-141` | | F04 | 选择执行位置 | 单选「StarServer执行(推荐)」/「StarWeb本地执行」 | — | `executeOn`:`server`(默认选中)或 `web` | 测试连接与部署请求携带所选值 | `Index.cshtml:86-96`;`executeOn=web` 时服务端本地分支未实现,见 F07、F08 | | F05 | 重置表单 | 按钮「重置」 | — | — | 浏览器 `type="reset"` 恢复控件默认值(含 SSH 端口 22、执行位置默认、服务器/下载地址为页面初始 value) | `Index.cshtml:108-110` | | F06 | 提交前校验(测试连接/部署共用) | 点击「测试连接」或「开始部署」前 | — | — | 校验非空:`hosts`、`userName`、`password`、`serverUrl`;缺项 `alert` 中文提示并中止 | `Index.cshtml:143-161` | | F07 | **测试连接** | 按钮「测试连接」 | POST `/Nodes/AgentDeploy/TestConnection` | 表单字段:`host`(由 `hosts` 按 `[,;\n\r]` 拆分取**第一个**非空段)、`port`、`userName`、`password`;`executeOn` | `executeOn=server`:MVC 带 Bearer(若有 `StarFactory.Client.Token`)POST 转发至 `{http://Request.Host}/AgentDeploy/TestConnection?host=&port=&userName=&password=`;返回 `Json({ code: 0, data: result })`;前端若 `response.code===0 && response.data.success` 则 `alert('连接测试成功!')` | `executeOn=web`:不转发 SSH,返回 `data.success=false` 及 L.T 未实现文案(`AgentDeployController.cs:128-131`);前端否则 `alert` 失败原因(`response.data.message` 或 `response.message`);异常 `code=500`(`AgentDeployController.cs:135-138`);AJAX `error` 回调 `alert`(`Index.cshtml:190-192`) | | F08 | **开始部署** | 按钮「开始部署」 | POST `/Nodes/AgentDeploy/Deploy?executeOn={server\|web}` | Body:`application/json`,字段 `hosts`、`port`、`userName`、`password`、`osType`、`serverUrl`、`downloadUrl`、`dotnetVersion`(与 `getFormData()` 一致,camelCase) | 先 `confirm('确定要开始部署吗?')`;结果区显示 spinner「正在部署,请稍候...」并展开 `#resultPanel`(`Index.cshtml:199-205`);`executeOn=server`:MVC 转发 JSON 至 StarServer `/AgentDeploy/Deploy`(带 Bearer);成功 `code=0`,`data` 为 `AgentDeployResult[]`,调用 `showDeployResult` 汇总成功/失败数与表格 | `executeOn=web`:`Json({ code: 500, message: L.T(...) })`(`AgentDeployController.cs:78-81`);`code!==0` 或无数组时结果区红色 alert(`Index.cshtml:215-217`);异常 `code=500`(`AgentDeployController.cs:85-90`);AJAX error 解析 `responseJSON.message`(`Index.cshtml:219-225`) | | F09 | 查看部署结果汇总 | 部署 AJAX 成功 | — | — | 顶部 info:「部署完成:成功 N 个,失败 M 个」;表格列:主机、状态(成功/失败图标)、消息、「查看」按钮 | `Index.cshtml:229-257` | | F10 | 查看单台详细输出 | 结果表「查看」 | — | 行索引 `i` | 模态框标题「部署输出 - {host}」;`<pre>` 展示 `result.output`,空则文案「无输出」 | `Index.cshtml:263-285` | | F11 | 标准 Cube 实体 CRUD | — | — | — | **无**:控制器未绑定实体,无 `Search` / GetPage / Insert / Update / Delete | 仅 `Index`、`Deploy`、`TestConnection` | ## 4. 列表 本页为操作面板,**无** Cube 标准列表。 | 小节 | 内容 | |------|------| | 搜索控件 | 无 | | 列 | 无(部署完成后结果区表格见 F09,非列表页列配置) | | 行操作 | 无 | | 工具栏 | 无 Cube 工具栏;表单内按钮见 F05–F08 | | 图表 | 无 | ## 5. 表单与副作用 ### 表单字段(以 `Index.cshtml` 控件为准) | 标签 | 控件 id / name | 类型 | 必填 | 默认值 / 选项 | 说明 | 文件:行号 | |------|----------------|------|------|---------------|------|-----------| | 目标主机 * | `hosts` | `textarea` rows=4 | 前端必填 | 空 | placeholder 说明单 IP、多 IP(逗号或换行)、CIDR;help 示例三行 | `Index.cshtml:22-26` | | 用户名 * | `userName` | `text` | 前端必填 | placeholder `root` | | `Index.cshtml:31-33` | | SSH端口 | `port` | `number` | 否 | `22` | 与 `userName` 同一行布局 | `Index.cshtml:35-38` | | 密码 * | `password` | `password` | 前端必填 | 空 | | `Index.cshtml:42-45` | | 操作系统 | `osType` | `select` | 否 | `Linux`(另选 `Windows`) | | `Index.cshtml:50-55` | | .NET版本 | `dotnetVersion` | `select` | 否 | 选项值 `9`(文案 9.0)、`8`(8.0)、`10`(10.0) | 提交时 `parseInt`,缺省 9 | `Index.cshtml:57-63`、`139` | | 服务器地址 * | `serverUrl` | `text` | 前端必填 | `@ViewBag.ServerUrl`(`http://{Request.Host}`) | help:StarAgent 安装后将连接此服务器 | `Index.cshtml:68-73`;初值 `AgentDeployController.cs:38-40` | | 下载地址 | `downloadUrl` | `text` | 否 | `@ViewBag.DownloadUrl`(`http://x.newlifex.com/star/`) | help:安装包下载地址 | `Index.cshtml:77-82`;初值 `AgentDeployController.cs:41` | | 执行位置 | `executeOn` | `radio` | 否 | `server` 默认 checked;`web` | help 说明 StarServer 适合大规模、StarWeb 适合快速测试 | `Index.cshtml:86-96` | 服务端模型 `AgentDeployModel`(`Stardust/Models/AgentDeployModel.cs`)属性名 PascalCase(`Hosts`、`Port`、`UserName`、`Password`、`OSType`、`ServerUrl`、`DownloadUrl`、`DotnetVersion`),与前端 JSON camelCase 的绑定行为:**未在源码确认**(依赖 ASP.NET Core 全局 JSON 选项)。 ### 按钮 | 文案 | 行为 | 文件:行号 | |------|------|-----------| | 测试连接 | `onclick="testConnection()"`,`btn-info` | `Index.cshtml:102-104` | | 开始部署 | `onclick="startDeploy()"`,`btn-primary` | `Index.cshtml:105-107` | | 重置 | `type="reset"` | `Index.cshtml:108-110` | ### 副作用 - **不写本地业务表**:MVC 层在 `executeOn=server` 时仅 HTTP 代理到 StarServer `AgentDeploy` 接口;实际 SSH 与安装逻辑在 StarServer(本盘点范围外)。 - **Bearer 令牌**:MVC `Deploy` / `TestConnection` 在转发前若 `_starFactory.Client.Token` 非空则设置 `Authorization: Bearer`(`AgentDeployController.cs:63-65`、`112-114`)。 - **追踪**:`Deploy` 使用 `_tracer.NewSpan("AgentDeploy", model)`,异常写 span(`AgentDeployController.cs:53`、`87`)。 - **测试连接主机范围**:仅第一个拆分后的 host,与部署时整段 `hosts` 由 StarServer 解析的行为不一致,用户需知晓(`Index.cshtml:170-171`)。 ## 6. 接口一览 | 接口 | HTTP | 路径 | 权限 | 返回 | |------|------|------|------|------| | `Index` | GET | `/Nodes/AgentDeploy` / `Index` | 未在源码确认 | HTML 视图;设置 `ViewBag.ServerUrl`、`ViewBag.DownloadUrl`(`AgentDeployController.cs:35-44`) | | `TestConnection` | POST | `/Nodes/AgentDeploy/TestConnection` | 未在源码确认 | 成功:`{ code: 0, data: <StarServer 反序列化对象> }`(`AgentDeployController.cs:133`);失败:`{ code: 500, message }`(`AgentDeployController.cs:138`) | | `Deploy` | POST | `/Nodes/AgentDeploy/Deploy?executeOn=server\|web` | 未在源码确认 | 成功:`{ code: 0, data: AgentDeployResult[], message: L.T("Deployment completed.") }`(`AgentDeployController.cs:83`);失败:`{ code: 500, message }`(`AgentDeployController.cs:80-81`、`90`) | 无标准 GetPage / Get / Insert / Update / Delete。 `AgentDeployResult` 字段(用于前端展示):`host`、`success`、`message`、`output`(`Stardust/Models/AgentDeployModel.cs:43-55`;表格绑定 `Index.cshtml:236-250`)。 ## 7. WebApi 差异 | 项 | MVC(`Stardust.Web/.../AgentDeployController.cs`) | WebApi(`Stardust.WebApi/.../AgentDeployController.cs`) | |----|------------------------------------------------------|------------------------------------------------------------| | `Index` | 有,返回部署页与 ViewBag 默认值(`35-44`) | **无** | | `Deploy` | 有;转发 StarServer 时附加 Bearer Token(`63-65`);JSON 信封 `{ code, data, message }`(`83`、`80-81`、`90`) | 有(`32-71`);转发 **无** Bearer;成功 `Json(0, "部署完成", results)`(`62`);`executeOn=web` 返回 `Json(500, "StarWeb本地执行功能暂未实现,请选择StarServer执行")`(`59`) | | `TestConnection` | 有;Bearer(`112-114`);`Json({ code: 0, data })` / `{ code: 500, message }`(`133`、`138`) | 有(`80-116`);转发 **无** Bearer;成功 `Json(0, null, result)`(`109`);失败 `Json(500, ex.Message)`(`114`) | | 依赖注入 | `IHttpClientFactory`、`StarFactory`、`ITracer`(`21-30`) | `IHttpClientFactory`、`ITracer`(`18-25`),**无** `StarFactory` | **WebApi 缺失**:`Index`(无 GET 部署面板、无服务端下发的默认 `ServerUrl` / `DownloadUrl` 接口)。 **行为不同**:StarServer 代理鉴权(MVC 带应用 Token,WebApi 不带);JSON 响应格式;`executeOn=web` 时 Deploy 错误文案(MVC 国际化 L.T vs WebApi 固定中文)。 ### 2026-11-04 WebApi 补齐记录 - **新增** `GET /Nodes/AgentDeploy/Index`(`Stardust.WebApi/.../AgentDeployController.cs:29-37`):返回部署面板首屏默认值 `{ serverUrl: "http://{Request.Host}", downloadUrl: "http://x.newlifex.com/star/" }`,对齐 MVC `Index` 下发的 `ViewBag.ServerUrl` / `ViewBag.DownloadUrl`(MVC `35-44`,DownloadUrl 为常量非配置项)。 - **修改** `Deploy`:注入 `StarFactory`,转发 StarServer 前当 `_starFactory?.Client?.Token` 非空时附加 `Authorization: Bearer`(对齐 MVC `63-68`,安全 V-3);`executeOn=web` 错误文案改为 `L.T("Local execution in StarWeb is not implemented; use StarServer instead.")`(zh-Hans.yml:80 译文「StarWeb本地执行功能暂未实现,请选择StarServer执行」,错误码 500 不变);成功消息改 `L.T("Deployment completed.")`(zh-Hans 译「部署完成」)。 - **修改** `TestConnection`:同上附加 Bearer(对齐 MVC `112-117`);`executeOn=web` 分支原已使用 L.T 键,未动。 - 响应形态沿用 WebApi `Json(code, message, data)`(Cube 标准 JSON,camelCase 序列化);MVC 为匿名对象 `{ code, data, message }`,字段语义一致。 - 无其他缺口:`Deploy` / `TestConnection` 参数、转发目标与逻辑已与 MVC 对齐。 ## 8. 新前端必须保留 - [ ] Nodes 菜单 `[Menu(70, true)]`「远程部署」进入部署面板(GET Index) - [ ] 打开页默认「服务器地址」= 当前站点 `http://{Host}`、「下载地址」= `http://x.newlifex.com/star/` - [ ] 表单字段:目标主机、用户名、SSH 端口(默认 22)、密码、操作系统(Linux/Windows)、.NET 版本(8/9/10)、服务器地址、下载地址、执行位置(server/web,默认 server) - [ ] 前端校验:`hosts`、`userName`、`password`、`serverUrl` 非空(与现有 alert 文案等价) - [ ] **测试连接**:POST TestConnection;仅测 `hosts` 列表第一个地址;成功/失败 alert - [ ] **开始部署**:确认框;POST Deploy JSON body + query `executeOn`;进行中 spinner;结果区展示成功/失败计数与 per-host 表格 - [ ] 结果行「查看」模态展示 `output`(空显示「无输出」) - [ ] `executeOn=server` 时经后端转发 StarServer(MVC 需保留 Bearer 行为;若走 WebApi 需补齐 Token 或等价鉴权) - [ ] `executeOn=web` 时保持「未实现」错误提示(与现网一致) - [ ] 重置按钮恢复表单默认态 - [ ] 无 Cube 列表/CRUD 依赖 ## 9. 证据 - `Stardust.Web/Areas/Nodes/Controllers/AgentDeployController.cs` - `Stardust.Web/Areas/Nodes/Views/AgentDeploy/Index.cshtml` - `Stardust.WebApi/Areas/Nodes/Controllers/AgentDeployController.cs` - `Stardust/Models/AgentDeployModel.cs` - `Stardust.Web/Views/Shared/_App_Nav.cshtml` - `Stardust.Web/Views/Shared/_Node_Nav.cshtml` - `Stardust.Web/Views/Shared/_Project_Nav.cshtml`