added logging for automated logs - would not remove the contextmanager - indeed 
needed


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/e4f08664
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/e4f08664
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/e4f08664

Branch: refs/heads/ARIA-106-Create-sqla-logging-handler
Commit: e4f08664357494818f8af0633ea600f6c0eb9137
Parents: c290a16
Author: mxmrlv <mxm...@gmail.com>
Authored: Tue Feb 21 19:07:42 2017 +0200
Committer: mxmrlv <mxm...@gmail.com>
Committed: Tue Feb 21 19:07:42 2017 +0200

----------------------------------------------------------------------
 aria/logger.py                                  |  4 ++--
 aria/orchestrator/context/workflow.py           |  4 ++++
 aria/orchestrator/workflows/core/engine.py      | 14 +++++++++-----
 aria/orchestrator/workflows/executor/base.py    | 18 ++++++++++--------
 aria/orchestrator/workflows/executor/process.py |  1 +
 aria/storage/modeling/orchestrator_elements.py  |  2 +-
 tests/orchestrator/context/test_operation.py    |  5 +++--
 tests/test_logger.py                            |  2 +-
 8 files changed, 31 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e4f08664/aria/logger.py
----------------------------------------------------------------------
diff --git a/aria/logger.py b/aria/logger.py
index 92f3109..169db53 100644
--- a/aria/logger.py
+++ b/aria/logger.py
@@ -113,9 +113,9 @@ class _DefaultConsoleFormat(logging.Formatter):
     def format(self, record):
         try:
             if hasattr(record, 'prefix'):
-                self._fmt = '%(asctime)s: [%(levelname)s] @%(prefix)s 
->%(message)s'
+                self._fmt = '<%(asctime)s: [%(levelname)s] @%(prefix)s> 
%(message)s'
             else:
-                self._fmt = '%(asctime)s: [%(levelname)s] %(message)s'
+                self._fmt = '<%(asctime)s: [%(levelname)s]> %(message)s'
 
         except AttributeError:
             return record.message

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e4f08664/aria/orchestrator/context/workflow.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/workflow.py 
b/aria/orchestrator/context/workflow.py
index 00ed974..24265a0 100644
--- a/aria/orchestrator/context/workflow.py
+++ b/aria/orchestrator/context/workflow.py
@@ -65,6 +65,10 @@ class WorkflowContext(BaseContext):
         return execution.id
 
     @property
+    def logging_id(self):
+        return '{0}[{1}]'.format(self._workflow_name, self._execution_id)
+
+    @property
     def execution(self):
         """
         The execution model

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e4f08664/aria/orchestrator/workflows/core/engine.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/core/engine.py 
b/aria/orchestrator/workflows/core/engine.py
index 55b4159..05da4ff 100644
--- a/aria/orchestrator/workflows/core/engine.py
+++ b/aria/orchestrator/workflows/core/engine.py
@@ -51,7 +51,7 @@ class Engine(logger.LoggerMixin):
         execute the workflow
         """
         try:
-            events.start_workflow_signal.send(self._workflow_context)
+            self._signal(events.start_workflow_signal)
             while True:
                 cancel = self._is_cancel()
                 if cancel:
@@ -65,11 +65,11 @@ class Engine(logger.LoggerMixin):
                 else:
                     time.sleep(0.1)
             if cancel:
-                
events.on_cancelled_workflow_signal.send(self._workflow_context)
+                self._signal(events.on_cancelled_workflow_signal)
             else:
-                events.on_success_workflow_signal.send(self._workflow_context)
+                self._signal(events.on_success_workflow_signal)
         except BaseException as e:
-            events.on_failure_workflow_signal.send(self._workflow_context, 
exception=e)
+            self._signal(events.on_failure_workflow_signal, exception=e)
             raise
 
     def cancel_execution(self):
@@ -78,7 +78,11 @@ class Engine(logger.LoggerMixin):
         will be modified to 'cancelling' status. If execution is in pending 
mode, execution status
         will be modified to 'cancelled' directly.
         """
-        events.on_cancelling_workflow_signal.send(self._workflow_context)
+        self._signal(events.on_cancelling_workflow_signal)
+
+    def _signal(self, signal, **kwargs):
+        with self._workflow_context.self_logging():
+            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/e4f08664/aria/orchestrator/workflows/executor/base.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/executor/base.py 
b/aria/orchestrator/workflows/executor/base.py
index 4ae046d..6d9b64c 100644
--- a/aria/orchestrator/workflows/executor/base.py
+++ b/aria/orchestrator/workflows/executor/base.py
@@ -39,14 +39,16 @@ class BaseExecutor(logger.LoggerMixin):
         """
         pass
 
-    @staticmethod
-    def _task_started(task):
-        events.start_task_signal.send(task)
+    def _task_started(self, task):
+        self._signal(events.start_task_signal, task)
 
-    @staticmethod
-    def _task_failed(task, exception):
-        events.on_failure_task_signal.send(task, exception=exception)
+    def _task_failed(self, task, exception):
+        self._signal(events.on_failure_task_signal, task, exception=exception)
+
+    def _task_succeeded(self, task):
+        self._signal(events.on_success_task_signal, task)
 
     @staticmethod
-    def _task_succeeded(task):
-        events.on_success_task_signal.send(task)
+    def _signal(signal, task, **kwargs):
+        with task.context.self_logging():
+            signal.send(task, **kwargs)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e4f08664/aria/orchestrator/workflows/executor/process.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/executor/process.py 
b/aria/orchestrator/workflows/executor/process.py
index d999b37..ecc8ca4 100644
--- a/aria/orchestrator/workflows/executor/process.py
+++ b/aria/orchestrator/workflows/executor/process.py
@@ -362,6 +362,7 @@ def _patch_session(ctx, messenger, instrument):
 
 
 def _main():
+
     arguments_json_path = sys.argv[1]
     with open(arguments_json_path) as f:
         arguments = pickle.loads(f.read())

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e4f08664/aria/storage/modeling/orchestrator_elements.py
----------------------------------------------------------------------
diff --git a/aria/storage/modeling/orchestrator_elements.py 
b/aria/storage/modeling/orchestrator_elements.py
index e1671f7..854f00b 100644
--- a/aria/storage/modeling/orchestrator_elements.py
+++ b/aria/storage/modeling/orchestrator_elements.py
@@ -477,5 +477,5 @@ class LogBase(ModelMixin):
     actor = Column(String)
 
     def __repr__(self):
-        return "{self.created_at}: [{self.level}] @{self.prefix} 
->{msg}".format(
+        return "<{self.created_at}: [{self.level}] @{self.actor}> 
{msg}".format(
             self=self, msg=self.msg[:50])

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e4f08664/tests/orchestrator/context/test_operation.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_operation.py 
b/tests/orchestrator/context/test_operation.py
index c2f5fd0..59c25fe 100644
--- a/tests/orchestrator/context/test_operation.py
+++ b/tests/orchestrator/context/test_operation.py
@@ -72,7 +72,8 @@ def thread_executor():
 
 
 @pytest.fixture(params=[(thread.ThreadExecutor()),
-                        (process.ProcessExecutor(python_path=tests.ROOT_DIR))])
+                        (process.ProcessExecutor(python_path=tests.ROOT_DIR))]
+               )
 def executor(request):
     ex = request.param
     try:
@@ -266,7 +267,7 @@ def test_operation_logging(ctx, executor):
 
     logs = ctx.model.log.list()
 
-    assert len(logs) == 2
+    assert len(logs) == 6
 
     op_start_log = [l for l in logs if inputs['op_start'] in l.msg and 
l.level.lower() == 'info']
     assert len(op_start_log) == 1

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e4f08664/tests/test_logger.py
----------------------------------------------------------------------
diff --git a/tests/test_logger.py b/tests/test_logger.py
index 1ad055c..6457884 100644
--- a/tests/test_logger.py
+++ b/tests/test_logger.py
@@ -54,7 +54,7 @@ def test_create_console_log_handler(capsys):
     logger.debug(debug_test_string)
     _, err = capsys.readouterr()
 
-    assert err.count('[DEBUG] 
{test_string}'.format(test_string=debug_test_string))
+    assert '[DEBUG]> {test_string}'.format(test_string=debug_test_string) in 
err
     assert err.count(info_test_string) == 1
 
     # Custom handler

Reply via email to