You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by mx...@apache.org on 2017/04/20 11:14:21 UTC

incubator-ariatosca git commit: review 2 fixes [Forced Update!]

Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-138-Make-logging-more-informative 877e850ec -> f0d093b7a (forced update)


review 2 fixes


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

Branch: refs/heads/ARIA-138-Make-logging-more-informative
Commit: f0d093b7ae95f9863f3cf276cd2b350dd0db8e4d
Parents: d4380fb
Author: max-orlov <ma...@gigaspaces.com>
Authored: Thu Apr 20 13:22:47 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Thu Apr 20 14:14:15 2017 +0300

----------------------------------------------------------------------
 aria/cli/commands/executions.py               | 14 +++++++----
 aria/cli/commands/logs.py                     |  4 +--
 aria/cli/execution_logging.py                 | 29 +++++++++++-----------
 aria/orchestrator/workflows/core/engine.py    |  3 +--
 aria/orchestrator/workflows/events_logging.py |  3 ++-
 5 files changed, 28 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f0d093b7/aria/cli/commands/executions.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/executions.py b/aria/cli/commands/executions.py
index 1ab5aed..99dc206 100644
--- a/aria/cli/commands/executions.py
+++ b/aria/cli/commands/executions.py
@@ -18,9 +18,9 @@ import os
 from .. import helptexts
 from .. import table
 from .. import utils
-from ..core import aria
 from .. import logger as cli_logger
 from .. import execution_logging
+from ..core import aria
 from ...modeling.models import Execution
 from ...orchestrator.workflow_runner import WorkflowRunner
 from ...orchestrator.workflows.executor.dry import DryExecutor
@@ -147,14 +147,15 @@ def start(workflow_name,
     log_iterator = cli_logger.ModelLogIterator(model_storage, workflow_runner.execution_id)
     try:
         while execution_thread.is_alive():
-            execution_logging.drain(log_iterator)
+            execution_logging.log_list(log_iterator)
+            execution_thread.join(1)
 
     except KeyboardInterrupt:
-        _cancel_execution(workflow_runner, execution_thread, logger)
+        _cancel_execution(model_storage, workflow_runner, execution_thread, logger)
 
     # It might be the case where some logs were written and the execution was terminated, thus we
     # need to drain the remaining logs.
-    execution_logging.drain(log_iterator)
+    execution_logging.log_list(log_iterator)
 
     # raise any errors from the execution thread (note these are not workflow execution errors)
     execution_thread.raise_error_if_exists()
@@ -169,12 +170,15 @@ def start(workflow_name,
         model_storage.execution.delete(execution)
 
 
-def _cancel_execution(workflow_runner, execution_thread, logger):
+def _cancel_execution(model_storage, workflow_runner, execution_thread, logger):
     logger.info('Cancelling execution. Press Ctrl+C again to force-cancel')
+    log_iterator = cli_logger.ModelLogIterator(model_storage, workflow_runner.execution_id)
     try:
         workflow_runner.cancel()
         while execution_thread.is_alive():
+            execution_logging.log_list(log_iterator)
             execution_thread.join(1)
     except KeyboardInterrupt:
         logger.info('Force-cancelling execution')
         # TODO handle execution (update status etc.) and exit process
+

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f0d093b7/aria/cli/commands/logs.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/logs.py b/aria/cli/commands/logs.py
index b3b29e9..d29bb9c 100644
--- a/aria/cli/commands/logs.py
+++ b/aria/cli/commands/logs.py
@@ -13,7 +13,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 from ..logger import ModelLogIterator
-from ..cli import aria
+from .. core import aria
 from .. import execution_logging
 
 
@@ -36,7 +36,7 @@ def list(execution_id, model_storage, logger):
     logger.info('Listing logs for execution id {0}'.format(execution_id))
     log_iterator = ModelLogIterator(model_storage, execution_id)
 
-    any_logs = execution_logging.drain(log_iterator)
+    any_logs = execution_logging.log_list(log_iterator)
 
     if not any_logs:
         logger.info('\tNo logs')

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f0d093b7/aria/cli/execution_logging.py
----------------------------------------------------------------------
diff --git a/aria/cli/execution_logging.py b/aria/cli/execution_logging.py
index 4099aff..8baf6d7 100644
--- a/aria/cli/execution_logging.py
+++ b/aria/cli/execution_logging.py
@@ -35,29 +35,28 @@ DEFAULT_FORMATTING = {
 }
 
 
-def _str(item, formatting=None):
-    # Only NO_VERBOSE and LOW_VERBOSE are configurable formats. configuring
-    # the low verbose level should affect any higher level.
-    formats = formatting or DEFAULT_FORMATTING
-    formatting = formats[env.logging.verbosity_level]
+def _str(item, formats=None):
+    # If no formats are passed we revert to the default formats (per level)
+    formats = formats or {}
+    formatting = formats.get(env.logging.verbosity_level,
+                             DEFAULT_FORMATTING[env.logging.verbosity_level])
     msg = StringIO()
 
-    kwargs = dict(item=item)
+    formatting_kwargs = dict(item=item)
 
     if item.task:
-        kwargs['implementation'] = item.task.implementation
-        kwargs['inputs'] = dict(i.unwrap() for i in item.task.inputs.values())
+        formatting_kwargs['implementation'] = item.task.implementation
+        formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.task.inputs.values())
     else:
-        kwargs['implementation'] = item.execution.workflow_name
-        kwargs['inputs'] = dict(i.unwrap() for i in item.execution.inputs.values())
+        formatting_kwargs['implementation'] = item.execution.workflow_name
+        formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.execution.inputs.values())
 
     if 'timestamp' in formatting:
-        kwargs['timestamp'] = item.created_at.strftime(formatting['timestamp'])
+        formatting_kwargs['timestamp'] = item.created_at.strftime(formatting['timestamp'])
     else:
-        kwargs['timestamp'] = item.created_at
+        formatting_kwargs['timestamp'] = item.created_at
 
-    # If no format was supplied just print out the original msg.
-    msg.write(formatting.get('message', '{item.msg}').format(**kwargs))
+    msg.write(formatting['message'].format(**formatting_kwargs))
 
     # Add the exception and the error msg.
     if item.traceback and env.logging.verbosity_level >= logger.MEDIUM_VERBOSE:
@@ -71,7 +70,7 @@ def log(item, *args, **kwargs):
     return getattr(env.logging.logger, item.level.lower())(_str(item), *args, **kwargs)
 
 
-def drain(iterator):
+def log_list(iterator):
     any_logs = False
     for item in iterator:
         log(item)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f0d093b7/aria/orchestrator/workflows/core/engine.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/core/engine.py b/aria/orchestrator/workflows/core/engine.py
index a111247..5e9b496 100644
--- a/aria/orchestrator/workflows/core/engine.py
+++ b/aria/orchestrator/workflows/core/engine.py
@@ -20,7 +20,6 @@ The workflow engine. Executes workflows
 import time
 from datetime import datetime
 
-import logging
 import networkx
 
 from aria import logger
@@ -41,7 +40,7 @@ class Engine(logger.LoggerMixin):
 
     def __init__(self, executor, workflow_context, tasks_graph, **kwargs):
         super(Engine, self).__init__(**kwargs)
-        self.logger.addHandler(logging.NullHandler())
+        self.logger.addHandler(logger.NullHandler())
         self._workflow_context = workflow_context
         self._execution_graph = networkx.DiGraph()
         self._executor = executor

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f0d093b7/aria/orchestrator/workflows/events_logging.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/events_logging.py b/aria/orchestrator/workflows/events_logging.py
index d13c7be..7d15c81 100644
--- a/aria/orchestrator/workflows/events_logging.py
+++ b/aria/orchestrator/workflows/events_logging.py
@@ -22,10 +22,11 @@ Implementation of logger handlers for workflow and operation events.
 """
 
 from .. import events
+from ... import modeling
 
 
 def _get_task_name(task):
-    if hasattr(task.actor, 'source_node'):
+    if isinstance(task.actor, modeling.model_bases.service_instance.RelationshipBase):
         return '{source_node.name}->{target_node.name}'.format(
             source_node=task.actor.source_node, target_node=task.actor.target_node)
     else: