From 0b56efc89d28d759925e2986988767a3709e73c1 Mon Sep 17 00:00:00 2001 From: Xuwznln <18435084+Xuwznln@users.noreply.github.com> Date: Thu, 4 Sep 2025 16:46:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0handle=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0material=20edge=E5=85=B3=E7=B3=BB?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- unilabos/app/main.py | 23 ++++++++++++++++++++++- unilabos/app/web/client.py | 12 ++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/unilabos/app/main.py b/unilabos/app/main.py index 3d7761e8..fd03a2fb 100644 --- a/unilabos/app/main.py +++ b/unilabos/app/main.py @@ -258,7 +258,7 @@ def main(): print_unilab_banner(args_dict) # 注册表 - build_registry(args_dict["registry_path"], False, args_dict["upload_registry"]) + lab_registry = build_registry(args_dict["registry_path"], False, args_dict["upload_registry"]) if args_dict["graph"] is None: request_startup_json = http_client.request_startup_json() if not request_startup_json: @@ -279,6 +279,27 @@ def main(): graph_res.physical_setup_graph = graph resource_edge_info = modify_to_backend_format(data["links"]) + materials = lab_registry.obtain_registry_resource_info() + materials.extend(lab_registry.obtain_registry_device_info()) + materials = {k["id"]: k for k in materials} + nodes = {k["id"]: k for k in data["nodes"]} + + for ind, i in enumerate(resource_edge_info[::-1]): + source_node = nodes[i["source"]] + target_node = nodes[i["target"]] + source_handle = i["sourceHandle"] + target_handle = i["targetHandle"] + source_handler_keys = [h["handler_key"] for h in materials[source_node["class"]]["handles"] if h["io_type"] == 'source'] + target_handler_keys = [h["handler_key"] for h in materials[target_node["class"]]["handles"] if h["io_type"] == 'target'] + if not source_handle in source_handler_keys: + print_status(f"节点 {source_node['id']} 的source端点 {source_handle} 不存在,请检查,支持的端点 {source_handler_keys}", "error") + resource_edge_info.pop(-ind - 1) + continue + if not target_handle in target_handler_keys: + print_status(f"节点 {target_node['id']} 的target端点 {target_handle} 不存在,请检查,支持的端点 {target_handler_keys}", "error") + resource_edge_info.pop(-ind - 1) + continue + devices_and_resources = dict_from_graph(graph_res.physical_setup_graph) # args_dict["resources_config"] = initialize_resources(list(deepcopy(devices_and_resources).values())) args_dict["resources_config"] = list(devices_and_resources.values()) diff --git a/unilabos/app/web/client.py b/unilabos/app/web/client.py index 7a50bf4b..c8bab670 100644 --- a/unilabos/app/web/client.py +++ b/unilabos/app/web/client.py @@ -58,10 +58,12 @@ class HTTPClient: headers={"Authorization": f"{'lab' if not self.backend_go else 'Lab'} {self.auth}"}, timeout=100, ) + if self.backend_go and response.status_code == 200: + res = response.json() + if "code" in res and res["code"] != 0: + logger.error(f"添加物料关系失败: {response.text}") if response.status_code != 200 and response.status_code != 201: logger.error(f"添加物料关系失败: {response.status_code}, {response.text}") - elif self.backend_go: - logger.info(f"添加物料关系 {response.text}") return response def resource_add(self, resources: List[Dict[str, Any]], database_process_later: bool) -> requests.Response: @@ -80,10 +82,12 @@ class HTTPClient: headers={"Authorization": f"{'lab' if not self.backend_go else 'Lab'} {self.auth}"}, timeout=100, ) + if self.backend_go and response.status_code == 200: + res = response.json() + if "code" in res and res["code"] != 0: + logger.error(f"添加物料失败: {response.text}") if response.status_code != 200: logger.error(f"添加物料失败: {response.text}") - elif self.backend_go: - logger.info(f"添加物料 {response.text}") return response def resource_get(self, id: str, with_children: bool = False) -> Dict[str, Any]: