From 8667ab27f28656cdb5c2140535efc6b1c7899227 Mon Sep 17 00:00:00 2001 From: franklinselva Date: Fri, 22 Sep 2023 15:25:54 +0200 Subject: [PATCH] minor fixes - add logging functionality to PlanMonitor and PlanDispatcher - bugfix processing execution result - bugfix in robot_example.py --- examples/robot_example.py | 2 +- up_esb/execution/executor.py | 4 ++-- up_esb/plexmo/dispatcher.py | 9 ++++++--- up_esb/plexmo/monitor.py | 4 +++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/examples/robot_example.py b/examples/robot_example.py index f9b4963..2ba8213 100644 --- a/examples/robot_example.py +++ b/examples/robot_example.py @@ -234,7 +234,7 @@ def main(): print("*" * 10) graph_executor = bridge.get_executable_graph(plan) - dispatcher.execute_plan(plan, graph_executor) + dispatcher.execute_plan(plan, graph_executor, dry_run=True) print("*" * 10) print(dispatcher.monitor_status) diff --git a/up_esb/execution/executor.py b/up_esb/execution/executor.py index 8610cc3..346d530 100644 --- a/up_esb/execution/executor.py +++ b/up_esb/execution/executor.py @@ -98,8 +98,8 @@ def execute_action(self, task_id): # Check preconditions result = self._check_preconditions(task_id) if isinstance(result, Exception): - precondition_status = ConditionStatus.FAILED, result - action_status = ActionNodeStatus.FAILED, result + precondition_status = ConditionStatus.FAILED + action_status = ActionNodeStatus.FAILED return ActionResult(precondition_status, action_status, postcondition_status, result) elif result: precondition_status = ConditionStatus.SUCCEEDED diff --git a/up_esb/plexmo/dispatcher.py b/up_esb/plexmo/dispatcher.py index 13c1de2..e298d65 100644 --- a/up_esb/plexmo/dispatcher.py +++ b/up_esb/plexmo/dispatcher.py @@ -23,6 +23,7 @@ from up_esb.exceptions import UPESBException, UPESBWarning from up_esb.execution import ActionExecutor, ActionResult +from up_esb.logger import Logger from up_esb.status import ActionNodeStatus, ConditionStatus, DispatcherStatus, MonitorStatus from .monitor import PlanMonitor @@ -35,13 +36,14 @@ def __init__(self): self._graph = None self._status = DispatcherStatus.IDLE self._dispatch_cb = self._default_dispatch_cb - self._replan_cb = self._default_replan_cb + self._replan_cb = None self._options = None self._executor = None self._plan = None self._rules = {} self._monitor = None self._node_data = None + self._logger = Logger(__name__) @property def monitor(self) -> PlanMonitor: @@ -113,9 +115,10 @@ def execute_plan(self, plan: Plan, graph: nx.DiGraph, **options): self._monitor.update_action_status(node_id, ActionNodeStatus.NOT_STARTED) self._status = DispatcherStatus.FAILED - message = f"Predecessors for action {node['node_name']} are not succeeded. Cannot execute the action." + message = f"Predecessors for action {node['node_name']} are not succeeded. Cannot execute the action. Exiting..." if options.get("dry_run", False): - raise UPESBException(message) + self._logger.warning(message) + exit(1) raise UPESBWarning(message) # Execute the action diff --git a/up_esb/plexmo/monitor.py b/up_esb/plexmo/monitor.py index 4eaf68b..1405f52 100644 --- a/up_esb/plexmo/monitor.py +++ b/up_esb/plexmo/monitor.py @@ -22,6 +22,7 @@ from up_esb.exceptions import process_action_result from up_esb.execution import ActionResult +from up_esb.logger import Logger from up_esb.status import ActionNodeStatus, MonitorStatus @@ -32,6 +33,7 @@ def __init__(self, executable_graph: nx.DiGraph): self._graph = executable_graph self._status = MonitorStatus.IDLE self._action_status = ActionNodeStatus.NOT_STARTED + self._logger = Logger(__name__) # Preprocess the graph to remove the executable elements. self._preprocess_graph() @@ -103,4 +105,4 @@ def process_action_result(self, result: ActionResult, dry_run: bool = False) -> else: # Reraise as warning exception = process_action_result(result) - raise Warning(str(exception)) + self._logger.warning(str(exception))