Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-106-Create-sqla-logging-handler e4f086643 -> ad0c52749
no cm is needed (it remained optional in order to add handlers) Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/ad0c5274 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/ad0c5274 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/ad0c5274 Branch: refs/heads/ARIA-106-Create-sqla-logging-handler Commit: ad0c52749327915213ca4f08c7869e39611b8d67 Parents: e4f0866 Author: mxmrlv <[email protected]> Authored: Tue Feb 21 21:09:32 2017 +0200 Committer: mxmrlv <[email protected]> Committed: Tue Feb 21 21:09:32 2017 +0200 ---------------------------------------------------------------------- aria/orchestrator/context/common.py | 17 +++++++++++------ aria/orchestrator/context/operation.py | 1 + aria/orchestrator/context/workflow.py | 1 + aria/orchestrator/decorators.py | 2 +- aria/orchestrator/workflows/core/engine.py | 3 +-- aria/orchestrator/workflows/executor/base.py | 3 +-- tests/orchestrator/context/test_operation.py | 7 ++++--- tests/orchestrator/execution_plugin/test_ssh.py | 6 ------ .../workflows/executor/test_executor.py | 8 -------- 9 files changed, 20 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ad0c5274/aria/orchestrator/context/common.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/context/common.py b/aria/orchestrator/context/common.py index f4d5716..4b1730a 100644 --- a/aria/orchestrator/context/common.py +++ b/aria/orchestrator/context/common.py @@ -26,7 +26,7 @@ from aria import logger as aria_logger from aria.storage import exceptions -class BaseContext(aria_logger.LoggerMixin): +class BaseContext(object): """ Base context object for workflow and operation """ @@ -57,6 +57,14 @@ class BaseContext(aria_logger.LoggerMixin): self._resource = resource_storage self._service_instance_id = service_instance_id self._workdir = workdir + self.logger = None + + def _register_logger(self, logger_name=None, level=None): + self.logger = self.PrefixedLogger(logging.getLogger(logger_name or self.__class__.__name__), + self.logging_id) + self.logger.addHandler(aria_logger.create_console_log_handler()) + self.logger.addHandler(self._get_sqla_handler()) + self.logger.setLevel(level or logging.DEBUG) def _get_sqla_handler(self): api_kwargs = {} @@ -72,14 +80,11 @@ class BaseContext(aria_logger.LoggerMixin): .format(name=self.__class__.__name__, self=self)) @contextmanager - def self_logging(self, handlers=None): - handlers = set(handlers) if handlers else set() + def logging_handlers(self, handlers=None): + handlers = handlers or [] try: - handlers.add(aria_logger.create_console_log_handler()) - handlers.add(self._get_sqla_handler()) for handler in handlers: self.logger.addHandler(handler) - self.logger = self.PrefixedLogger(self.logger, self.logging_id) yield self.logger finally: for handler in handlers: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ad0c5274/aria/orchestrator/context/operation.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/context/operation.py b/aria/orchestrator/context/operation.py index 9dbcc8c..3fb1786 100644 --- a/aria/orchestrator/context/operation.py +++ b/aria/orchestrator/context/operation.py @@ -44,6 +44,7 @@ class BaseOperationContext(BaseContext): self._task_id = task_id self._actor_id = actor_id self._task = None + self._register_logger() def __repr__(self): details = 'implementation={task.implementation}; ' \ http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ad0c5274/aria/orchestrator/context/workflow.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/context/workflow.py b/aria/orchestrator/context/workflow.py index 24265a0..0afaa81 100644 --- a/aria/orchestrator/context/workflow.py +++ b/aria/orchestrator/context/workflow.py @@ -46,6 +46,7 @@ class WorkflowContext(BaseContext): # TODO: execution creation should happen somewhere else # should be moved there, when such logical place exists self._execution_id = self._create_execution() if execution_id is None else execution_id + self._register_logger() def __repr__(self): return ( http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ad0c5274/aria/orchestrator/decorators.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/decorators.py b/aria/orchestrator/decorators.py index f915813..1a8ead0 100644 --- a/aria/orchestrator/decorators.py +++ b/aria/orchestrator/decorators.py @@ -72,7 +72,7 @@ def operation(func=None, toolbelt=False, suffix_template='', logging_handlers=No func_kwargs.setdefault('toolbelt', operation_toolbelt) validate_function_arguments(func, func_kwargs) - with func_kwargs['ctx'].self_logging(handlers=logging_handlers): + with func_kwargs['ctx'].logging_handlers(logging_handlers): return func(**func_kwargs) return _wrapper http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ad0c5274/aria/orchestrator/workflows/core/engine.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/workflows/core/engine.py b/aria/orchestrator/workflows/core/engine.py index 05da4ff..b26a69d 100644 --- a/aria/orchestrator/workflows/core/engine.py +++ b/aria/orchestrator/workflows/core/engine.py @@ -81,8 +81,7 @@ class Engine(logger.LoggerMixin): self._signal(events.on_cancelling_workflow_signal) def _signal(self, signal, **kwargs): - with self._workflow_context.self_logging(): - signal.send(self._workflow_context, **kwargs) + signal.send(self._workflow_context, **kwargs) def _is_cancel(self): return self._workflow_context.execution.status in [model.Execution.CANCELLING, http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ad0c5274/aria/orchestrator/workflows/executor/base.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/workflows/executor/base.py b/aria/orchestrator/workflows/executor/base.py index 6d9b64c..cd8e7ee 100644 --- a/aria/orchestrator/workflows/executor/base.py +++ b/aria/orchestrator/workflows/executor/base.py @@ -50,5 +50,4 @@ class BaseExecutor(logger.LoggerMixin): @staticmethod def _signal(signal, task, **kwargs): - with task.context.self_logging(): - signal.send(task, **kwargs) + signal.send(task, **kwargs) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ad0c5274/tests/orchestrator/context/test_operation.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/context/test_operation.py b/tests/orchestrator/context/test_operation.py index 59c25fe..3001f56 100644 --- a/tests/orchestrator/context/test_operation.py +++ b/tests/orchestrator/context/test_operation.py @@ -71,9 +71,10 @@ def thread_executor(): result.close() [email protected](params=[(thread.ThreadExecutor()), - (process.ProcessExecutor(python_path=tests.ROOT_DIR))] - ) [email protected](params=[ + (thread.ThreadExecutor()), + (process.ProcessExecutor(python_path=tests.ROOT_DIR)) +]) def executor(request): ex = request.param try: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ad0c5274/tests/orchestrator/execution_plugin/test_ssh.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/execution_plugin/test_ssh.py b/tests/orchestrator/execution_plugin/test_ssh.py index cf4c7e1..0981b61 100644 --- a/tests/orchestrator/execution_plugin/test_ssh.py +++ b/tests/orchestrator/execution_plugin/test_ssh.py @@ -413,12 +413,6 @@ class TestFabricEnvHideGroupsAndRunCommands(object): task.runs_on = Stub logger = logging.getLogger() - @staticmethod - @contextlib.contextmanager - def _mock_self_logging(*args, **kwargs): - yield - _Ctx.self_logging = _mock_self_logging - @pytest.fixture(autouse=True) def _setup(self, mocker): self.default_fabric_env = { http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ad0c5274/tests/orchestrator/workflows/executor/test_executor.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/workflows/executor/test_executor.py b/tests/orchestrator/workflows/executor/test_executor.py index 64dfb66..8da801e 100644 --- a/tests/orchestrator/workflows/executor/test_executor.py +++ b/tests/orchestrator/workflows/executor/test_executor.py @@ -95,10 +95,6 @@ class MockContext(object): def deserialize_from_dict(cls, **kwargs): return cls() - @contextmanager - def self_logging(self): - yield self.logger - class MockTask(object): @@ -128,10 +124,6 @@ class MockTask(object): def _update(self): yield self - @contextmanager - def self_logging(self): - yield self.logger - @pytest.fixture(params=[ (thread.ThreadExecutor, {'pool_size': 1}),
