优化docker sdk版本
This commit is contained in:
parent
cdea54e77a
commit
9d5f1d2dd3
@ -8,19 +8,20 @@ from utils.odm_monitor import ODMProcessMonitor
|
|||||||
class CommandRunner:
|
class CommandRunner:
|
||||||
"""执行网格处理命令的类"""
|
"""执行网格处理命令的类"""
|
||||||
|
|
||||||
def __init__(self, output_dir: str, max_retries: int = 3, mode: str = "快拼模式"):
|
def __init__(self, output_dir: str, mode: str = "快拼模式"):
|
||||||
self.output_dir = output_dir
|
self.output_dir = output_dir
|
||||||
self.max_retries = max_retries
|
|
||||||
self.logger = logging.getLogger('UAV_Preprocess.CommandRunner')
|
self.logger = logging.getLogger('UAV_Preprocess.CommandRunner')
|
||||||
self.monitor = ODMProcessMonitor(max_retries=max_retries, mode=mode)
|
self.monitor = ODMProcessMonitor(mode=mode)
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
|
|
||||||
def _run_command(self, grid_idx: int):
|
def run_grid_commands(self, grid_points: Dict[int, pd.DataFrame]):
|
||||||
"""执行单个网格的处理"""
|
"""处理所有网格"""
|
||||||
try:
|
self.logger.info("开始执行网格处理")
|
||||||
grid_dir = os.path.join(self.output_dir, f'grid_{grid_idx + 1}')
|
for grid_idx in grid_points.keys():
|
||||||
grid_dir = os.path.abspath(grid_dir) # 确保使用绝对路径
|
grid_dir = os.path.abspath(os.path.join(
|
||||||
|
self.output_dir, f'grid_{grid_idx + 1}'
|
||||||
|
))
|
||||||
|
|
||||||
success, error_msg = self.monitor.run_odm_with_monitor(
|
success, error_msg = self.monitor.run_odm_with_monitor(
|
||||||
grid_dir=grid_dir,
|
grid_dir=grid_dir,
|
||||||
grid_idx=grid_idx,
|
grid_idx=grid_idx,
|
||||||
@ -28,19 +29,4 @@ class CommandRunner:
|
|||||||
)
|
)
|
||||||
|
|
||||||
if not success:
|
if not success:
|
||||||
raise Exception(error_msg)
|
raise Exception(f"网格 {grid_idx + 1} 处理失败: {error_msg}")
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
self.logger.error(f"网格 {grid_idx + 1} 处理失败: {str(e)}")
|
|
||||||
raise
|
|
||||||
|
|
||||||
def run_grid_commands(self, grid_points: Dict[int, pd.DataFrame]):
|
|
||||||
"""处理所有网格"""
|
|
||||||
self.logger.info("开始执行网格处理")
|
|
||||||
|
|
||||||
for grid_idx in grid_points.keys():
|
|
||||||
try:
|
|
||||||
self._run_command(grid_idx)
|
|
||||||
except Exception as e:
|
|
||||||
self.logger.error(f"网格 {grid_idx + 1} 处理失败,停止后续执行: {str(e)}")
|
|
||||||
raise
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import os
|
import os
|
||||||
import time
|
|
||||||
import logging
|
import logging
|
||||||
import docker
|
import docker
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
@ -23,66 +22,54 @@ class ODMProcessMonitor:
|
|||||||
|
|
||||||
def run_odm_with_monitor(self, grid_dir: str, grid_idx: int, fast_mode: bool = True) -> Tuple[bool, str]:
|
def run_odm_with_monitor(self, grid_dir: str, grid_idx: int, fast_mode: bool = True) -> Tuple[bool, str]:
|
||||||
"""运行ODM容器"""
|
"""运行ODM容器"""
|
||||||
attempt = 0
|
try:
|
||||||
while attempt < self.max_retries:
|
self.logger.info(f"开始处理网格 {grid_idx + 1}")
|
||||||
try:
|
|
||||||
self.logger.info(f"网格 {grid_idx + 1} 第 {attempt + 1} 次尝试")
|
|
||||||
|
|
||||||
# 准备容器配置
|
# 准备容器配置
|
||||||
volumes = {
|
volumes = {
|
||||||
grid_dir: {'bind': '/datasets', 'mode': 'rw'}
|
grid_dir: {'bind': '/datasets', 'mode': 'rw'}
|
||||||
}
|
}
|
||||||
|
|
||||||
# 准备命令参数
|
# 准备命令参数
|
||||||
command = [
|
command = [
|
||||||
"--project-path", "/datasets", "project",
|
"--project-path", "/datasets", "project",
|
||||||
"--max-concurrency", "10",
|
"--max-concurrency", "10",
|
||||||
"--force-gps",
|
"--force-gps",
|
||||||
"--rerun-all"
|
"--rerun-all"
|
||||||
]
|
]
|
||||||
|
|
||||||
if fast_mode:
|
if fast_mode:
|
||||||
command.extend([
|
command.extend([
|
||||||
"--feature-quality", "lowest",
|
"--feature-quality", "lowest",
|
||||||
"--orthophoto-resolution", "8",
|
"--orthophoto-resolution", "8",
|
||||||
"--fast-orthophoto",
|
"--fast-orthophoto",
|
||||||
"--skip-3dmodel"
|
"--skip-3dmodel"
|
||||||
])
|
])
|
||||||
|
|
||||||
# 运行容器
|
# 运行容器并等待完成
|
||||||
container = self.client.containers.run(
|
container = self.client.containers.run(
|
||||||
"opendronemap/odm",
|
"opendronemap/odm",
|
||||||
command=command,
|
command=command,
|
||||||
volumes=volumes,
|
volumes=volumes,
|
||||||
detach=True,
|
detach=True,
|
||||||
remove=True
|
remove=True,
|
||||||
)
|
environment={"PYTHONUNBUFFERED": "1"},
|
||||||
|
mem_limit="0", # 不限制内存
|
||||||
|
cpu_count=0, # 使用所有CPU
|
||||||
|
network_mode="host" # 使用主机网络模式
|
||||||
|
)
|
||||||
|
|
||||||
# 等待容器完成
|
# 等待容器完成并获取状态码
|
||||||
result = container.wait()
|
result = container.wait()
|
||||||
|
|
||||||
# 只在失败时获取日志
|
# 检查是否成功完成
|
||||||
if result['StatusCode'] != 0:
|
if result['StatusCode'] == 0 and self._check_success(grid_dir):
|
||||||
logs = container.logs().decode('utf-8')
|
self.logger.info(f"网格 {grid_idx + 1} 处理成功")
|
||||||
self.logger.error("容器执行失败,最后10行日志:")
|
return True, ""
|
||||||
self.logger.error(''.join(logs.split('\n')[-10:]))
|
|
||||||
|
|
||||||
# 检查是否成功完成
|
return False, f"网格 {grid_idx + 1} 处理失败"
|
||||||
if result['StatusCode'] == 0 and self._check_success(grid_dir):
|
|
||||||
self.logger.info(f"网格 {grid_idx + 1} ODM处理成功")
|
|
||||||
return True, ""
|
|
||||||
|
|
||||||
self.logger.warning(f"网格 {grid_idx + 1} 第 {attempt + 1} 次尝试失败")
|
except Exception as e:
|
||||||
|
error_msg = f"执行异常: {str(e)}"
|
||||||
except Exception as e:
|
self.logger.error(error_msg)
|
||||||
error_msg = f"执行异常: {str(e)}"
|
return False, error_msg
|
||||||
self.logger.error(error_msg)
|
|
||||||
return False, error_msg
|
|
||||||
|
|
||||||
attempt += 1
|
|
||||||
if attempt < self.max_retries:
|
|
||||||
time.sleep(30)
|
|
||||||
|
|
||||||
error_msg = f"网格 {grid_idx + 1} 在 {self.max_retries} 次尝试后仍然失败"
|
|
||||||
self.logger.error(error_msg)
|
|
||||||
return False, error_msg
|
|
||||||
|
Loading…
Reference in New Issue
Block a user