Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-115-Log-model-should-have-an-Execution-field [created] 
33ff844cd


ARIA-115-Log-model-should-have-an-Execution-field


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

Branch: refs/heads/ARIA-115-Log-model-should-have-an-Execution-field
Commit: 33ff844cdefe2e26744c03b452916f8f834eee2a
Parents: dc18c1d
Author: max-orlov <[email protected]>
Authored: Sun Mar 5 19:18:21 2017 +0200
Committer: max-orlov <[email protected]>
Committed: Sun Mar 5 19:18:21 2017 +0200

----------------------------------------------------------------------
 aria/logger.py                                 | 12 +++++++++---
 aria/orchestrator/context/common.py            |  6 +++++-
 aria/orchestrator/context/workflow.py          |  2 --
 aria/storage/modeling/orchestrator_elements.py |  8 ++++++++
 4 files changed, 22 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/33ff844c/aria/logger.py
----------------------------------------------------------------------
diff --git a/aria/logger.py b/aria/logger.py
index 9fe05ae..6f0b84a 100644
--- a/aria/logger.py
+++ b/aria/logger.py
@@ -98,13 +98,17 @@ def create_console_log_handler(level=logging.DEBUG, 
formatter=None):
     return console
 
 
-def create_sqla_log_handler(session, engine, log_cls, level=logging.DEBUG):
+def create_sqla_log_handler(session, engine, log_cls, execution_id, 
level=logging.DEBUG):
 
     # This is needed since the engine and session are entirely new we need to 
reflect the db
     # schema of the logging model into the engine and session.
     log_cls.__table__.create(bind=engine, checkfirst=True)
 
-    return _SQLAlchemyHandler(session=session, engine=engine, log_cls=log_cls, 
level=level)
+    return _SQLAlchemyHandler(session=session,
+                              engine=engine,
+                              log_cls=log_cls,
+                              execution_id=execution_id,
+                              level=level)
 
 
 class _DefaultConsoleFormat(logging.Formatter):
@@ -148,16 +152,18 @@ def create_file_log_handler(
 
 class _SQLAlchemyHandler(logging.Handler):
 
-    def __init__(self, session, engine, log_cls, **kwargs):
+    def __init__(self, session, engine, log_cls, execution_id, **kwargs):
         logging.Handler.__init__(self, **kwargs)
         self._session = session
         self._engine = engine
         self._cls = log_cls
+        self._execution_id = execution_id
 
     def emit(self, record):
         created_at = 
datetime.strptime(logging.Formatter('%(asctime)s').formatTime(record),
                                        '%Y-%m-%d %H:%M:%S,%f')
         log = self._cls(
+            execution_fk=self._execution_id,
             actor=record.prefix,
             level=record.levelname,
             msg=record.msg,

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/33ff844c/aria/orchestrator/context/common.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/common.py 
b/aria/orchestrator/context/common.py
index b34cd5d..947c474 100644
--- a/aria/orchestrator/context/common.py
+++ b/aria/orchestrator/context/common.py
@@ -51,6 +51,7 @@ class BaseContext(object):
             service_instance_id,
             model_storage,
             resource_storage,
+            execution_id,
             workdir=None,
             **kwargs):
         super(BaseContext, self).__init__(**kwargs)
@@ -60,6 +61,7 @@ class BaseContext(object):
         self._resource = resource_storage
         self._service_instance_id = service_instance_id
         self._workdir = workdir
+        self._execution_id = execution_id
         self.logger = None
 
     def _register_logger(self, logger_name=None, level=None):
@@ -74,7 +76,9 @@ class BaseContext(object):
         if self._model._initiator:
             
api_kwargs.update(self._model._initiator(**self._model._initiator_kwargs))
         api_kwargs.update(**self._model._api_kwargs)
-        return aria_logger.create_sqla_log_handler(log_cls=modeling.model.Log, 
**api_kwargs)
+        return aria_logger.create_sqla_log_handler(log_cls=modeling.model.Log,
+                                                   
execution_id=self._execution_id,
+                                                   **api_kwargs)
 
     def __repr__(self):
         return (

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/33ff844c/aria/orchestrator/context/workflow.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/workflow.py 
b/aria/orchestrator/context/workflow.py
index 0afaa81..6e3aa66 100644
--- a/aria/orchestrator/context/workflow.py
+++ b/aria/orchestrator/context/workflow.py
@@ -32,7 +32,6 @@ class WorkflowContext(BaseContext):
     def __init__(self,
                  workflow_name,
                  parameters=None,
-                 execution_id=None,
                  task_max_attempts=1,
                  task_retry_interval=0,
                  task_ignore_failure=False,
@@ -45,7 +44,6 @@ class WorkflowContext(BaseContext):
         self._task_ignore_failure = task_ignore_failure
         # 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):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/33ff844c/aria/storage/modeling/orchestrator_elements.py
----------------------------------------------------------------------
diff --git a/aria/storage/modeling/orchestrator_elements.py 
b/aria/storage/modeling/orchestrator_elements.py
index 854f00b..22e2e90 100644
--- a/aria/storage/modeling/orchestrator_elements.py
+++ b/aria/storage/modeling/orchestrator_elements.py
@@ -471,6 +471,14 @@ class TaskBase(ModelMixin):
 class LogBase(ModelMixin):
     __tablename__ = 'log'
 
+    @declared_attr
+    def execution_fk(cls):
+        return cls.foreign_key('execution', nullable=True)
+
+    @declared_attr
+    def execution(cls):
+        return cls.many_to_one_relationship('execution')
+
     level = Column(String)
     msg = Column(String)
     created_at = Column(DateTime, index=True)

Reply via email to