Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-138-Make-logging-more-informative d4380fb8f -> 877e850ec
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/877e850e Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/877e850e Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/877e850e Branch: refs/heads/ARIA-138-Make-logging-more-informative Commit: 877e850ecc3a136c48cb334c6196236daf74bdeb Parents: d4380fb Author: max-orlov <[email protected]> Authored: Thu Apr 20 13:22:47 2017 +0300 Committer: max-orlov <[email protected]> Committed: Thu Apr 20 13:22:47 2017 +0300 ---------------------------------------------------------------------- aria/cli/commands/executions.py | 14 +++++++---- aria/cli/commands/logs.py | 4 +-- aria/cli/execution_logging.py | 29 +++++++++++----------- aria/orchestrator/workflows/events_logging.py | 3 ++- 4 files changed, 27 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/877e850e/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/877e850e/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/877e850e/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/877e850e/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:
