|
|
|
@ -179,33 +179,43 @@ class CommandExecutor: |
|
|
|
""" |
|
|
|
try: |
|
|
|
start_time = time.time() |
|
|
|
device_id = device["device_id"] |
|
|
|
device_source = device["source"] |
|
|
|
command = cmd_task.command |
|
|
|
|
|
|
|
logger.debug(f"开始执行单个命令: 设备={device_id}, 来源={device_source}, 命令={command}") |
|
|
|
|
|
|
|
# 根据设备来源选择执行方式 |
|
|
|
if device.source == "registered": |
|
|
|
if device_source == "registered": |
|
|
|
logger.debug(f"注册设备执行命令: {device_id} -> {command}") |
|
|
|
# 注册设备:通过设备分发器执行 |
|
|
|
result = await self.device_dispatcher.execute_operation( |
|
|
|
device_id=device.device_id, |
|
|
|
protocol_type=device.protocol_type, |
|
|
|
device_id=device_id, |
|
|
|
protocol_type=device["protocol_type"], |
|
|
|
operation="execute_command", |
|
|
|
command=cmd_task.command, |
|
|
|
command=command, |
|
|
|
timeout=cmd_task.timeout |
|
|
|
) |
|
|
|
logger.debug(f"注册设备命令执行完成: {device_id} -> {command}, 结果类型={type(result)}") |
|
|
|
else: |
|
|
|
logger.debug(f"自动发现设备执行命令: {device_id} -> {command}") |
|
|
|
# 自动发现设备:直接调用ADB服务 |
|
|
|
from app.services.auto_discovery_adb_service import auto_discovery_adb_service |
|
|
|
result = await auto_discovery_adb_service.execute_shell_command( |
|
|
|
device.device_id, |
|
|
|
cmd_task.command, |
|
|
|
device_id, |
|
|
|
command, |
|
|
|
timeout=cmd_task.timeout |
|
|
|
) |
|
|
|
logger.debug(f"自动发现设备命令执行完成: {device_id} -> {command}, 结果类型={type(result)}") |
|
|
|
|
|
|
|
execution_time = time.time() - start_time |
|
|
|
|
|
|
|
# 统一使用实体返回格式 |
|
|
|
if isinstance(result, ShellResponse): |
|
|
|
# ShellResponse实体格式 |
|
|
|
logger.debug(f"命令执行成功: {device_id} -> {command}, 输出长度={len(result.output) if result.output else 0}") |
|
|
|
return ShellCommandResult( |
|
|
|
command=cmd_task.command, |
|
|
|
command=command, |
|
|
|
success=result.success, |
|
|
|
output=result.output, |
|
|
|
error=result.error, |
|
|
|
@ -216,9 +226,9 @@ class CommandExecutor: |
|
|
|
) |
|
|
|
else: |
|
|
|
# 其他格式统一转换为失败结果 |
|
|
|
logger.warning(f"命令执行返回格式不符合规范: {type(result)}") |
|
|
|
logger.warning(f"命令执行返回格式不符合规范: {device_id} -> {command}, 返回类型={type(result)}") |
|
|
|
return ShellCommandResult( |
|
|
|
command=cmd_task.command, |
|
|
|
command=command, |
|
|
|
success=False, |
|
|
|
output="", |
|
|
|
error=f"返回格式不符合规范: {type(result)}", |
|
|
|
|