edge split

This commit is contained in:
flower_linux
2026-05-13 16:45:31 +08:00
parent df5eb5529c
commit 238b814057
31 changed files with 1934 additions and 52 deletions

View File

@@ -76,7 +76,11 @@
| `get_device_tree` | 无 | `0` | `5003` | 返回 `tree` |
| `list_devices` | 无 | `0` | - | 返回 `devices` |
| `get_device` | `deviceId` | `0` | `4044` | 单设备 JSON未找到 `device_not_found` |
| `patch_device_tree_node` | `id`, `patch`(字段同设备树节点) | `0` | `4045`/`5003` | 更新节点并协调;`node_not_found` |
| `patch_device_tree_node` | `id`, `patch`(字段同设备树节点) | `0` | `4045`/`5003` | 更新节点并协调;成功时可选带 `edgeTreeDownlink`(对 `params.edgeId` / `edges/<id>/` 作用域自动 `TREE_FULL` |
| `list_edge_sessions` | 无 | `0` | - | 返回边缘 TCP 会话 `sessions``edgeId`/`helloOk`/`peer` |
| `get_edge_tree_revision` | 无 | `0` | - | 返回 `treeRevision`(与边缘 `CTRL_TREE_PROPOSE` 乐观锁对齐) |
| `push_edge_tree` | `edgeId` | `0` | `4000`/`4047`/`5003`/`5005` | 向已 HELLO 的会话下行 `TREE_FULL`;成功返回 `sent``treeRevision`;无在线会话 `no_active_session`ingress 未启用 `edge_ingress_disabled` |
| edge TCP`TREE_PROPOSE` | JSON`edgeId``baseTreeRevision``entries` | - | `CONFLICT`/`FORBIDDEN_SCOPE` 等 | 与 D-Bus 共用 `DeviceTreeModel::applyEdgePropose``entries` 支持 `op` 省略/`patch`**`op: upsert`**(边缘子树内新增或整节点合并),见 `docs/EDGE_UPLINK_PROTOCOL_v1.md` §6 |
| `get_plugins` | 无 | `0` | - | 合并 protocol/framer/mapper 插件列表 |
| `get_plugins_protocols` | 无 | `0` | - | `protocols` |
| `get_plugins_mappers` | 无 | `0` | - | `mappers` |
@@ -111,10 +115,12 @@
| `5002` | `persist_mappings_failed` | 映射规则内存更新成功但写入 `runtime_mappings.json` 失败 |
| `5003` | `pipeline_unavailable` / `device_tree_unavailable` | Pipeline 或设备树模型未就绪 |
| `5004` | `metadata_*` | 元数据字典读写/解析/保存失败 |
| `5005` | `edge_ingress_disabled` / `edge_ingress_unavailable` | 边缘 TCP ingress 未启用或未初始化 |
| `4005` | `invalid_metadata` | `upsert_metadata` 缺少 `metadataId` |
| `4044` | `device_not_found` | `get_device` 未找到 |
| `4045` | `node_not_found` | `patch_device_tree_node` 未找到节点 |
| `4046` | `metadata_not_found` | `get_metadata` / `delete_metadata` 未找到 |
| `4047` | `no_active_session` | `push_edge_tree` 时该 `edgeId` 无已 HELLO 的 TCP 会话 |
## 7) 维护建议

View File

@@ -6,6 +6,7 @@
#include <QFileInfo>
#include <QJsonArray>
#include <QJsonDocument>
#include <QMutexLocker>
#include <QSaveFile>
#include "core/metadata/MetadataRegistry.h"
@@ -366,6 +367,45 @@ DispatchResult CommandDispatcher::dispatch(const QString& action, const QJsonObj
}
return {0, QStringLiteral("ok"), QJsonObject{{QStringLiteral("tree"), model->toDeviceTreeJson()}}};
}
if (action == QStringLiteral("list_edge_sessions")) {
const QJsonArray arr = softbus::device_bus::DeviceBus::instance().listEdgeIngressSessions();
return {0, QStringLiteral("ok"), QJsonObject{{QStringLiteral("sessions"), arr}}};
}
if (action == QStringLiteral("get_edge_tree_revision")) {
return {0,
QStringLiteral("ok"),
QJsonObject{{QStringLiteral("treeRevision"),
softbus::device_bus::DeviceBus::instance().deviceTreeRevision()}}};
}
if (action == QStringLiteral("push_edge_tree")) {
const QString edgeId = params.value(QStringLiteral("edgeId")).toString();
if (edgeId.isEmpty()) {
return {4000, QStringLiteral("missing_edgeId"), {}};
}
int sent = 0;
QString err;
const bool ok = softbus::device_bus::DeviceBus::instance().pushEdgeTreeFullDownlink(edgeId, &sent, &err);
if (!ok) {
int code = 5003;
if (err == QStringLiteral("no_active_session")) {
code = 4047;
} else if (err == QStringLiteral("missing_edgeId")) {
code = 4000;
} else if (err == QStringLiteral("edge_ingress_disabled") || err == QStringLiteral("edge_ingress_unavailable")) {
code = 5005;
}
return {code, err, QJsonObject{{QStringLiteral("edgeId"), edgeId}}};
}
qint64 rev = 0;
if (auto model = softbus::device_bus::DeviceBus::instance().deviceTreeModel()) {
rev = model->treeRevision();
}
return {0,
QStringLiteral("ok"),
QJsonObject{{QStringLiteral("edgeId"), edgeId},
{QStringLiteral("sent"), sent},
{QStringLiteral("treeRevision"), rev}}};
}
if (action == QStringLiteral("list_devices")) {
const auto devices = softbus::device_bus::DeviceBus::instance().listDevices();
QJsonArray arr;
@@ -389,42 +429,39 @@ DispatchResult CommandDispatcher::dispatch(const QString& action, const QJsonObj
if (!model) {
return {5003, QStringLiteral("device_tree_unavailable"), {}};
}
QMutexLocker locker(&model->writeMutex());
const int idx = model->findIndexById(id);
if (idx < 0) {
return {4045, QStringLiteral("node_not_found"), {}};
}
DeviceTreeNode& node = model->nodesMutable()[idx];
for (auto it = patch.constBegin(); it != patch.constEnd(); ++it) {
const QString k = it.key();
if (k == QStringLiteral("params") && it.value().isObject()) {
QJsonObject p = node.params;
const QJsonObject patchParams = it.value().toObject();
for (auto pit = patchParams.constBegin(); pit != patchParams.constEnd(); ++pit) {
const QString pk = pit.key();
if (pk == QStringLiteral("stableKey") || pk == QStringLiteral("online") || pk == QStringLiteral("lastSeenTs")) {
continue;
}
p.insert(pk, pit.value());
}
node.params = p;
} else if (k == QStringLiteral("name")) {
node.name = it.value().toString();
} else if (k == QStringLiteral("type")) {
node.type = it.value().toString();
} else if (k == QStringLiteral("endpoint")) {
node.endpoint = it.value().toString();
} else if (k == QStringLiteral("driver")) {
node.driver = it.value().toString();
} else if (k == QStringLiteral("capabilitiesRef")) {
node.capabilitiesRef = it.value().toString();
} else if (k == QStringLiteral("enabled")) {
node.enabled = it.value().toBool(node.enabled);
}
if (!model->applyPatchToNodeById(id, patch)) {
return {4045, QStringLiteral("node_not_found"), {}};
}
const DeviceTreeNode& patchedNode = model->nodes().at(idx);
const QVector<QString> edgePushTargets = model->downlinkEdgeIdsForNode(patchedNode);
model->rebuildIndex();
model->bumpTreeRevision();
locker.unlock();
softbus::device_bus::DeviceBus::instance().markDeviceTreeDirty();
(void)softbus::device_bus::DeviceBus::instance().reconcileFromTreeModel();
return {0, QStringLiteral("ok"), QJsonObject{{QStringLiteral("id"), id}}};
QJsonObject data{{QStringLiteral("id"), id}};
if (!edgePushTargets.isEmpty()) {
QJsonArray downlinkArr;
for (const QString& eid : edgePushTargets) {
int sent = 0;
QString err;
const bool ok = softbus::device_bus::DeviceBus::instance().pushEdgeTreeFullDownlink(eid, &sent, &err);
QJsonObject one{{QStringLiteral("edgeId"), eid},
{QStringLiteral("ok"), ok},
{QStringLiteral("sent"), sent}};
if (!ok && !err.isEmpty()) {
one.insert(QStringLiteral("error"), err);
}
downlinkArr.append(one);
}
data.insert(QStringLiteral("edgeTreeDownlink"), downlinkArr);
}
return {0, QStringLiteral("ok"), data};
}
if (action == QStringLiteral("get_plugins")) {
const auto pm = softbus::device_bus::DeviceBus::instance().pluginManager();