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/24 10:55:22 UTC
[1/9] incubator-ariatosca git commit: ARIA-150 Fixed simple
hello-world example [Forced Update!]
Repository: incubator-ariatosca
Updated Branches:
refs/heads/ARIA-146-Support-colorful-execution-logging 12209c6b3 -> 1c074676b (forced update)
ARIA-150 Fixed simple hello-world example
The simple hello-world example had a missing host node,
which caused an error at service creation phase.
The example now uses custom types which do not require
the extra host node.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/7a4a1dda
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/7a4a1dda
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/7a4a1dda
Branch: refs/heads/ARIA-146-Support-colorful-execution-logging
Commit: 7a4a1ddabadef814affb56778c7614256ca8fe00
Parents: 29bc84b
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Sun Apr 23 15:39:57 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Sun Apr 23 15:39:57 2017 +0300
----------------------------------------------------------------------
examples/hello-world/helloworld.yaml | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7a4a1dda/examples/hello-world/helloworld.yaml
----------------------------------------------------------------------
diff --git a/examples/hello-world/helloworld.yaml b/examples/hello-world/helloworld.yaml
index b6efaca..77cef30 100644
--- a/examples/hello-world/helloworld.yaml
+++ b/examples/hello-world/helloworld.yaml
@@ -1,18 +1,23 @@
-tosca_definitions_version: tosca_simple_profile_for_nfv_1_0
+tosca_definitions_version: tosca_simple_yaml_1_0
node_types:
+ web_server:
+ derived_from: tosca.nodes.Root
+ capabilities:
+ host:
+ type: tosca.capabilities.Container
+
web_app:
derived_from: tosca.nodes.WebApplication
properties:
port:
type: integer
- default: 8080
topology_template:
node_templates:
web_server:
- type: tosca.nodes.WebServer
+ type: web_server
web_app:
type: web_app
[4/9] incubator-ariatosca git commit: wip
Posted by mx...@apache.org.
wip
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/1e0f030e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/1e0f030e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/1e0f030e
Branch: refs/heads/ARIA-146-Support-colorful-execution-logging
Commit: 1e0f030e2ba2c20c47b4711e707ecabe21b3b7e5
Parents: 7a4a1dd
Author: max-orlov <ma...@gigaspaces.com>
Authored: Thu Apr 20 18:51:46 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Mon Apr 24 11:47:11 2017 +0300
----------------------------------------------------------------------
aria/cli/color.py | 50 ++++++++++++++++++++++++++++++++++++++
aria/cli/execution_logging.py | 19 +++++++++++----
aria/core.py | 4 +--
3 files changed, 66 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1e0f030e/aria/cli/color.py
----------------------------------------------------------------------
diff --git a/aria/cli/color.py b/aria/cli/color.py
new file mode 100644
index 0000000..54ee4bf
--- /dev/null
+++ b/aria/cli/color.py
@@ -0,0 +1,50 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+from StringIO import StringIO
+
+import colorama
+
+colorama.init()
+
+
+class StyledString(str):
+
+ fore = colorama.Fore
+ back = colorama.Back
+ style = colorama.Style
+
+ def __init__(self, str_, *args):
+ super(StyledString, self).__init__()
+ # TODO: raise proper exception
+ if not all(self._is_valid(arg) for arg in args):
+ raise Exception("bla bla bla")
+ self._str = str_
+ self._args = args
+ self._stylized_str = None
+
+ def __str__(self):
+ if self._stylized_str is None:
+ styling_str = StringIO()
+ for arg in self._args:
+ styling_str.write(arg)
+ styling_str.write(self._str)
+ styling_str.write(self.style.RESET_ALL)
+ self.stylized_str = styling_str.getvalue()
+
+ return self.stylized_str
+
+ def _is_valid(self, value):
+ return any(value in vars(instance).values()
+ for instance in (self.fore, self.back, self.style))
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1e0f030e/aria/cli/execution_logging.py
----------------------------------------------------------------------
diff --git a/aria/cli/execution_logging.py b/aria/cli/execution_logging.py
index 8baf6d7..17e396d 100644
--- a/aria/cli/execution_logging.py
+++ b/aria/cli/execution_logging.py
@@ -15,21 +15,22 @@
from StringIO import StringIO
+from .color import StyledString
from . import logger
from .env import env
DEFAULT_FORMATTING = {
logger.NO_VERBOSE: {'message': '{item.msg}'},
logger.LOW_VERBOSE: {
- 'message': '{timestamp} | {item.level[0]} | {item.msg}',
- 'timestamp': '%H:%M:%S'
+ 'message': '{timestamp} | {level} | {item.msg}',
+ 'timestamp': '%H:%M:%S',
},
logger.MEDIUM_VERBOSE: {
- 'message': '{timestamp} | {item.level[0]} | {implementation} | {item.msg} ',
+ 'message': '{timestamp} | {level} | {implementation} | {item.msg} ',
'timestamp': '%H:%M:%S'
},
logger.HIGH_VERBOSE: {
- 'message': '{timestamp} | {item.level[0]} | {implementation}({inputs}) | {item.msg} ',
+ 'message': '{timestamp} | {level} | {implementation}({inputs}) | {item.msg} ',
'timestamp': '%H:%M:%S'
},
}
@@ -41,9 +42,17 @@ def _str(item, formats=None):
formatting = formats.get(env.logging.verbosity_level,
DEFAULT_FORMATTING[env.logging.verbosity_level])
msg = StringIO()
-
formatting_kwargs = dict(item=item)
+ # region level styling
+
+ levels_format = {
+ 'debug': (StyledString.back.LIGHTRED_EX,)
+ }
+ formatting_kwargs['level'] = StyledString(item.level[0], *levels_format.get(item.level.lower(), []))
+
+ # endregion level styling
+
if item.task:
formatting_kwargs['implementation'] = item.task.implementation
formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.task.inputs.values())
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1e0f030e/aria/core.py
----------------------------------------------------------------------
diff --git a/aria/core.py b/aria/core.py
index af1984a..4e19506 100644
--- a/aria/core.py
+++ b/aria/core.py
@@ -77,8 +77,8 @@ class Core(object):
consumption.ConsumerChain(
context,
(
- consumption.SatisfyRequirements,
- consumption.ValidateCapabilities,
+ # consumption.SatisfyRequirements,
+ # consumption.ValidateCapabilities,
consumption.FindHosts,
consumption.ConfigureOperations
)).consume()
[3/9] incubator-ariatosca git commit: wip2
Posted by mx...@apache.org.
wip2
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/61765891
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/61765891
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/61765891
Branch: refs/heads/ARIA-146-Support-colorful-execution-logging
Commit: 6176589198ec2be61c3d5085cd563958d1ac229a
Parents: 1e0f030
Author: max-orlov <ma...@gigaspaces.com>
Authored: Thu Apr 20 20:18:11 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Mon Apr 24 11:47:11 2017 +0300
----------------------------------------------------------------------
aria/cli/color.py | 20 ++++++---
aria/cli/execution_logging.py | 92 +++++++++++++++++++++++++++++---------
2 files changed, 86 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/61765891/aria/cli/color.py
----------------------------------------------------------------------
diff --git a/aria/cli/color.py b/aria/cli/color.py
index 54ee4bf..7b20d30 100644
--- a/aria/cli/color.py
+++ b/aria/cli/color.py
@@ -19,32 +19,42 @@ import colorama
colorama.init()
-class StyledString(str):
+class StyledString(object):
fore = colorama.Fore
back = colorama.Back
style = colorama.Style
- def __init__(self, str_, *args):
+ def __init__(self, str_to_stylize, *args, **kwargs):
+ """
+
+ :param str_to_stylize:
+ :param args:
+ :param kwargs:
+ to_close: specifies if end the format on the current line. default to True
+ """
super(StyledString, self).__init__()
# TODO: raise proper exception
if not all(self._is_valid(arg) for arg in args):
raise Exception("bla bla bla")
- self._str = str_
+ self._str = str_to_stylize
self._args = args
self._stylized_str = None
def __str__(self):
if self._stylized_str is None:
styling_str = StringIO()
- for arg in self._args:
- styling_str.write(arg)
+ self._apply_style(styling_str)
styling_str.write(self._str)
styling_str.write(self.style.RESET_ALL)
self.stylized_str = styling_str.getvalue()
return self.stylized_str
+ def _apply_style(self, styling_str):
+ for arg in self._args:
+ styling_str.write(arg)
+
def _is_valid(self, value):
return any(value in vars(instance).values()
for instance in (self.fore, self.back, self.style))
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/61765891/aria/cli/execution_logging.py
----------------------------------------------------------------------
diff --git a/aria/cli/execution_logging.py b/aria/cli/execution_logging.py
index 17e396d..0743abd 100644
--- a/aria/cli/execution_logging.py
+++ b/aria/cli/execution_logging.py
@@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-
+import os
from StringIO import StringIO
from .color import StyledString
@@ -20,22 +20,67 @@ from . import logger
from .env import env
DEFAULT_FORMATTING = {
- logger.NO_VERBOSE: {'message': '{item.msg}'},
+ logger.NO_VERBOSE: {'message': '{message}'},
logger.LOW_VERBOSE: {
- 'message': '{timestamp} | {level} | {item.msg}',
+ 'message': '{timestamp} | {level} | {message}',
+ 'level': '{level[0]}',
'timestamp': '%H:%M:%S',
},
logger.MEDIUM_VERBOSE: {
- 'message': '{timestamp} | {level} | {implementation} | {item.msg} ',
+ 'message': '{timestamp} | {level} | {implementation} | {message} ',
+ 'level': '{level[0]}',
'timestamp': '%H:%M:%S'
},
logger.HIGH_VERBOSE: {
- 'message': '{timestamp} | {level} | {implementation}({inputs}) | {item.msg} ',
+ 'message': '{timestamp} | {level} | {implementation}({inputs}) | {message} ',
+ 'level': '{level[0]}',
'timestamp': '%H:%M:%S'
},
}
+def _style_level(level):
+ levels_format = {
+ 'info': (StyledString.fore.LIGHTBLUE_EX, ),
+ 'debug': (StyledString.fore.LIGHTRED_EX, StyledString.style.DIM),
+ 'error': (StyledString.fore.RED, )
+ }
+ return StyledString(level[0], *levels_format.get(level.lower(), []))
+
+
+def _style_timestamp(timestamp, level):
+ timestamp_format = {
+ 'info': (StyledString.fore.LIGHTBLUE_EX, StyledString.style.DIM),
+ 'debug': (StyledString.fore.LIGHTBLUE_EX, StyledString.style.DIM),
+ 'error': (StyledString.fore.RED,)
+ }
+ return StyledString(timestamp, *timestamp_format.get(level.lower(), []))
+
+
+def _style_msg(msg, level):
+ msg_foramts = {
+ 'info': (StyledString.fore.LIGHTBLUE_EX, ),
+ 'debug': (StyledString.fore.LIGHTBLUE_EX, StyledString.style.DIM),
+ 'error': (StyledString.fore.RED, ),
+ }
+ return StyledString(msg, *msg_foramts.get(level.lower(), []))
+
+
+def _style_traceback(traceback):
+ return StyledString(traceback, StyledString.fore.RED, StyledString.style.DIM)
+
+
+def _style_implementation(implementation, level):
+ implementation_formats = {
+ 'info': (StyledString.style.DIM, StyledString.fore.LIGHTBLACK_EX),
+ 'debug': (StyledString.style.DIM, StyledString.fore.LIGHTBLACK_EX),
+ 'error': (StyledString.fore.RED, ),
+ }
+ return StyledString(implementation, *implementation_formats.get(level.lower(), []))
+
+_style_inputs = _style_implementation
+
+
def _str(item, formats=None):
# If no formats are passed we revert to the default formats (per level)
formats = formats or {}
@@ -44,33 +89,36 @@ def _str(item, formats=None):
msg = StringIO()
formatting_kwargs = dict(item=item)
- # region level styling
-
- levels_format = {
- 'debug': (StyledString.back.LIGHTRED_EX,)
- }
- formatting_kwargs['level'] = StyledString(item.level[0], *levels_format.get(item.level.lower(), []))
-
- # endregion level styling
+ # level
+ formatting_kwargs['level'] = _style_level(item.level)
+ # implementation
if item.task:
- formatting_kwargs['implementation'] = item.task.implementation
- formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.task.inputs.values())
+ implementation = item.task.implementation
+ inputs = dict(i.unwrap() for i in item.task.inputs.values())
else:
- formatting_kwargs['implementation'] = item.execution.workflow_name
- formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.execution.inputs.values())
+ implementation = item.execution.workflow_name
+ inputs = dict(i.unwrap() for i in item.execution.inputs.values())
+
+ formatting_kwargs['implementation'] = _style_implementation(implementation, item.level)
+ formatting_kwargs['inputs'] = _style_inputs(inputs, item.level)
+ # timestamp
if 'timestamp' in formatting:
- formatting_kwargs['timestamp'] = item.created_at.strftime(formatting['timestamp'])
+ timestamp = item.created_at.strftime(formatting['timestamp'])
else:
- formatting_kwargs['timestamp'] = item.created_at
+ timestamp = item.created_at
+ formatting_kwargs['timestamp'] = _style_timestamp(timestamp, item.level)
- msg.write(formatting['message'].format(**formatting_kwargs))
+ # message
+ formatting_kwargs['message'] = _style_msg(item.msg, item.level)
+
+ msg.write(formatting['message'].format(**formatting_kwargs) + os.linesep)
# Add the exception and the error msg.
if item.traceback and env.logging.verbosity_level >= logger.MEDIUM_VERBOSE:
for line in item.traceback.splitlines(True):
- msg.write('\t' + '|' + line)
+ msg.write(_style_traceback('\t' + '|' + line))
return msg.getvalue()
@@ -85,3 +133,5 @@ def log_list(iterator):
log(item)
any_logs = True
return any_logs
+
+
[6/9] incubator-ariatosca git commit: modified executions logging
Posted by mx...@apache.org.
modified executions logging
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/0d5ff7f4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/0d5ff7f4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/0d5ff7f4
Branch: refs/heads/ARIA-146-Support-colorful-execution-logging
Commit: 0d5ff7f46282094c1f01edba230d5b0a8d1235d0
Parents: f91adbc
Author: max-orlov <ma...@gigaspaces.com>
Authored: Sat Apr 22 11:09:15 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Mon Apr 24 11:47:11 2017 +0300
----------------------------------------------------------------------
aria/cli/commands/executions.py | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0d5ff7f4/aria/cli/commands/executions.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/executions.py b/aria/cli/commands/executions.py
index 3eb53ab..a156c3f 100644
--- a/aria/cli/commands/executions.py
+++ b/aria/cli/commands/executions.py
@@ -20,6 +20,7 @@ from .. import table
from .. import utils
from .. import logger as cli_logger
from .. import execution_logging
+from .. import color
from ..core import aria
from ...modeling.models import Execution
from ...orchestrator.workflow_runner import WorkflowRunner
@@ -165,9 +166,13 @@ def start(workflow_name,
execution_thread.raise_error_if_exists()
execution = workflow_runner.execution
- logger.info('Execution has ended with "{0}" status'.format(execution.status))
+ status_msg = 'Execution has ended with "{0}" status'.format(execution.status)
+ status_msg = color.StyledString(status_msg, color.StyledString.FORE.RED)
+ logger.info(status_msg)
if execution.status == Execution.FAILED and execution.error:
- logger.info('Execution error:{0}{1}'.format(os.linesep, execution.error))
+ error_msg = color.StyledString('Execution error:{0}{1}'.format(os.linesep, execution.error),
+ color.StyledString.FORE.RED)
+ logger.info(error_msg)
if dry:
# remove traces of the dry execution (including tasks, logs, inputs..)
[7/9] incubator-ariatosca git commit: added markingup
Posted by mx...@apache.org.
added markingup
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/87c141e3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/87c141e3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/87c141e3
Branch: refs/heads/ARIA-146-Support-colorful-execution-logging
Commit: 87c141e3d0d7e9b21affda496ea306b6527431fc
Parents: ceb88db
Author: max-orlov <ma...@gigaspaces.com>
Authored: Fri Apr 21 19:48:07 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Mon Apr 24 11:47:11 2017 +0300
----------------------------------------------------------------------
aria/cli/commands/logs.py | 5 +-
aria/cli/core/aria.py | 9 +++
aria/cli/execution_logging.py | 129 +++++++++++++++++++++----------------
3 files changed, 85 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/87c141e3/aria/cli/commands/logs.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/logs.py b/aria/cli/commands/logs.py
index 79aff07..f52cfc1 100644
--- a/aria/cli/commands/logs.py
+++ b/aria/cli/commands/logs.py
@@ -28,15 +28,18 @@ def logs():
short_help='List execution logs')
@aria.argument('execution-id')
@aria.options.verbose()
+@aria.options.mark_pattern()
@aria.pass_model_storage
@aria.pass_logger
-def list(execution_id, model_storage, logger):
+def list(execution_id, mark_pattern, model_storage, logger):
"""Display logs for an execution
"""
logger.info('Listing logs for execution id {0}'.format(execution_id))
log_iterator = ModelLogIterator(model_storage, execution_id)
+ execution_logging.stylized_log.set(mark_pattern=mark_pattern)
any_logs = execution_logging.log_list(log_iterator)
+ execution_logging.stylized_log.reset(to_defaults=True)
if not any_logs:
logger.info('\tNo logs')
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/87c141e3/aria/cli/core/aria.py
----------------------------------------------------------------------
diff --git a/aria/cli/core/aria.py b/aria/cli/core/aria.py
index ed7c490..6436c3e 100644
--- a/aria/cli/core/aria.py
+++ b/aria/cli/core/aria.py
@@ -425,5 +425,14 @@ class Options(object):
required=required,
help=helptexts.SERVICE_ID)
+ @staticmethod
+ def mark_pattern(default=None):
+ return click.option(
+ '-m',
+ '--mark-pattern',
+ help='pattern this',
+ type=str,
+ default=default
+ )
options = Options()
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/87c141e3/aria/cli/execution_logging.py
----------------------------------------------------------------------
diff --git a/aria/cli/execution_logging.py b/aria/cli/execution_logging.py
index f8eec22..17ea774 100644
--- a/aria/cli/execution_logging.py
+++ b/aria/cli/execution_logging.py
@@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
+import re
from StringIO import StringIO
from functools import partial
@@ -27,7 +28,7 @@ MESSAGE = 'message'
IMPLEMENTATION = 'implementation'
INPUTS = 'inputs'
TRACEBACK = 'traceback'
-
+MARKER = 'marker'
DEFAULT_FORMATTING = {
logger.NO_VERBOSE: {'message': '{message}'},
@@ -48,7 +49,7 @@ DEFAULT_FORMATTING = {
},
}
-DEFAULT_STYLES = {
+DEFAULT_STYLING = {
LEVEL: {
'info': (StyledString.FORE.LIGHTMAGENTA_EX,),
'debug': (StyledString.FORE.LIGHTMAGENTA_EX, StyledString.STYLE.DIM),
@@ -76,90 +77,104 @@ DEFAULT_STYLES = {
},
TRACEBACK: {
'error': (StyledString.FORE.RED, )
- }
+ },
+
+ MARKER: StyledString.BACK.LIGHTYELLOW_EX
}
class _StylizedLogs(object):
- def __init__(self, styles=None):
- self._styles = styles or DEFAULT_STYLES
+ def __init__(self, formats=None, styles=None):
+ self._formats = formats or DEFAULT_FORMATTING
+ self._styles = styles or DEFAULT_STYLING
+ self._mark_pattern = None
- def set_styles(self, styles):
- self._styles = styles
+ def set(self, styles=None, formats=None, mark_pattern=None):
+ self._styles = styles or DEFAULT_STYLING
+ self._formats = formats or DEFAULT_FORMATTING
+ self._mark_pattern = mark_pattern
- def unset_styles(self, to_defaults=False):
- self._styles = DEFAULT_STYLES if to_defaults else {}
+ def reset(self, to_defaults=False):
+ self._styles = DEFAULT_STYLING if to_defaults else {}
+ self._formats = DEFAULT_FORMATTING if to_defaults else {}
+ self._mark_pattern = None
def __getattr__(self, item):
- return partial(self._style, style_type=item)
+ return partial(self._stilize, style_type=item[1:])
- def level(self, level):
- return self._style(level[0], level, LEVEL)
+ def _level(self, level):
+ return self._stilize(level[0], level, LEVEL)
- def _style(self, msg, level, style_type):
+ def _stilize(self, msg, level, style_type):
return StyledString(msg, *self._styles[style_type].get(level.lower(), []))
- def back(self, str_):
- if 'web_app' not in str_:
+ def _mark(self, str_):
+ # TODO; this needs more work. since colors cause the patten not to match (since its not a continuous string)
+ if self._mark_pattern is None:
return str_
- modified_str = StyledString.BACK.LIGHTYELLOW_EX +\
- str_.replace(StyledString.STYLE.RESET_ALL,
- StyledString.STYLE.RESET_ALL + StyledString.BACK.LIGHTYELLOW_EX) + StyledString.STYLE.RESET_ALL
+ else:
+ regex_pattern = re.compile(self._mark_pattern)
+ if not re.match(regex_pattern, str_):
+ return str_
+ marker = self._styles[MARKER]
+ modified_str = (
+ marker +
+ str_.replace(StyledString.STYLE.RESET_ALL, StyledString.STYLE.RESET_ALL + marker) +
+ StyledString.STYLE.RESET_ALL
+ )
return modified_str
-stylized_log = _StylizedLogs()
+ def __call__(self, item):
+ # If no formats are passed we revert to the default formats (per level)
+ formatting = self._formats.get(env.logging.verbosity_level,
+ DEFAULT_FORMATTING[env.logging.verbosity_level])
+ msg = StringIO()
+ formatting_kwargs = dict(item=item)
+ # level
+ formatting_kwargs['level'] = self._level(item.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()
- formatting_kwargs = dict(item=item)
+ # implementation
+ if item.task:
+ # operation task
+ implementation = item.task.implementation
+ inputs = dict(i.unwrap() for i in item.task.inputs.values())
+ else:
+ # execution task
+ implementation = item.execution.workflow_name
+ inputs = dict(i.unwrap() for i in item.execution.inputs.values())
- # level
- formatting_kwargs['level'] = stylized_log.level(item.level)
+ formatting_kwargs['implementation'] = self._implementation(implementation, item.level)
+ formatting_kwargs['inputs'] = self._inputs(inputs, item.level)
- # implementation
- if item.task:
- # operation task
- implementation = item.task.implementation
- inputs = dict(i.unwrap() for i in item.task.inputs.values())
- else:
- # execution task
- implementation = item.execution.workflow_name
- inputs = dict(i.unwrap() for i in item.execution.inputs.values())
+ # timestamp
+ if 'timestamp' in formatting:
+ timestamp = item.created_at.strftime(formatting['timestamp'])
+ else:
+ timestamp = item.created_at
+ formatting_kwargs['timestamp'] = self._timestamp(timestamp, item.level)
- formatting_kwargs['implementation'] = stylized_log.implementation(implementation, item.level)
- formatting_kwargs['inputs'] = stylized_log.inputs(inputs, item.level)
+ # message
+ formatting_kwargs['message'] = self._message(item.msg, item.level)
- # timestamp
- if 'timestamp' in formatting:
- timestamp = item.created_at.strftime(formatting['timestamp'])
- else:
- timestamp = item.created_at
- formatting_kwargs['timestamp'] = stylized_log.timestamp(timestamp, item.level)
+ # The message would be marked out if containing the provided pattern
+ msg.write(self._mark(formatting['message'].format(**formatting_kwargs)))
- # message
- formatting_kwargs['message'] = stylized_log.message(item.msg, item.level)
+ # Add the exception and the error msg.
+ if item.traceback and env.logging.verbosity_level >= logger.MEDIUM_VERBOSE:
+ msg.write(os.linesep)
+ for line in item.traceback.splitlines(True):
+ msg.write(self._traceback('\t' + '|' + line, item.level))
- message = formatting['message'].format(**formatting_kwargs)
- message = stylized_log.back(message)
- msg.write(message)
+ return msg.getvalue()
- # Add the exception and the error msg.
- if item.traceback and env.logging.verbosity_level >= logger.MEDIUM_VERBOSE:
- msg.write(os.linesep)
- for line in item.traceback.splitlines(True):
- msg.write(stylized_log.traceback('\t' + '|' + line, item.level))
- return msg.getvalue()
+stylized_log = _StylizedLogs()
def log(item, *args, **kwargs):
- return getattr(env.logging.logger, item.level.lower())(_str(item), *args, **kwargs)
+ return getattr(env.logging.logger, item.level.lower())(stylized_log(item), *args, **kwargs)
def log_list(iterator):
[8/9] incubator-ariatosca git commit: added markingup
Posted by mx...@apache.org.
added markingup
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/ceb88db8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/ceb88db8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/ceb88db8
Branch: refs/heads/ARIA-146-Support-colorful-execution-logging
Commit: ceb88db8315031df487af0bab599d29624ab01f9
Parents: 86cb111
Author: max-orlov <ma...@gigaspaces.com>
Authored: Fri Apr 21 19:04:09 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Mon Apr 24 11:47:11 2017 +0300
----------------------------------------------------------------------
aria/cli/color.py | 13 ++++++++++---
aria/cli/execution_logging.py | 11 ++++++++++-
2 files changed, 20 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ceb88db8/aria/cli/color.py
----------------------------------------------------------------------
diff --git a/aria/cli/color.py b/aria/cli/color.py
index ed71238..a5ed9b7 100644
--- a/aria/cli/color.py
+++ b/aria/cli/color.py
@@ -39,12 +39,19 @@ class StyledString(object):
def __str__(self):
return self._stylized_str
+ def _style_str(self, styling_str=None):
+ str_ = styling_str or StringIO
+ for arg in self._args:
+ str_.write(arg)
+ if styling_str is not None:
+ return str_
+ else:
+ return str_.getvalue()
+
def _apply_style(self):
assert all(self._is_valid(arg) for arg in self._args)
-
styling_str = StringIO()
- for arg in self._args:
- styling_str.write(arg)
+ self._style_str(styling_str)
styling_str.write(self._original_str)
styling_str.write(self.STYLE.RESET_ALL)
self._stylized_str = styling_str.getvalue()
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ceb88db8/aria/cli/execution_logging.py
----------------------------------------------------------------------
diff --git a/aria/cli/execution_logging.py b/aria/cli/execution_logging.py
index 6019b94..f8eec22 100644
--- a/aria/cli/execution_logging.py
+++ b/aria/cli/execution_logging.py
@@ -100,6 +100,13 @@ class _StylizedLogs(object):
def _style(self, msg, level, style_type):
return StyledString(msg, *self._styles[style_type].get(level.lower(), []))
+ def back(self, str_):
+ if 'web_app' not in str_:
+ return str_
+ modified_str = StyledString.BACK.LIGHTYELLOW_EX +\
+ str_.replace(StyledString.STYLE.RESET_ALL,
+ StyledString.STYLE.RESET_ALL + StyledString.BACK.LIGHTYELLOW_EX) + StyledString.STYLE.RESET_ALL
+ return modified_str
stylized_log = _StylizedLogs()
@@ -138,7 +145,9 @@ def _str(item, formats=None):
# message
formatting_kwargs['message'] = stylized_log.message(item.msg, item.level)
- msg.write(formatting['message'].format(**formatting_kwargs))
+ message = formatting['message'].format(**formatting_kwargs)
+ message = stylized_log.back(message)
+ msg.write(message)
# Add the exception and the error msg.
if item.traceback and env.logging.verbosity_level >= logger.MEDIUM_VERBOSE:
[9/9] incubator-ariatosca git commit: a new way to configure colors
Posted by mx...@apache.org.
a new way to configure colors
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/1c074676
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/1c074676
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/1c074676
Branch: refs/heads/ARIA-146-Support-colorful-execution-logging
Commit: 1c074676bed7cc31fb11e83a9d6ccf5e8e461283
Parents: 0d5ff7f
Author: max-orlov <ma...@gigaspaces.com>
Authored: Mon Apr 24 13:54:36 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Mon Apr 24 13:54:36 2017 +0300
----------------------------------------------------------------------
aria/cli/color.py | 43 +++++++-
aria/cli/commands/executions.py | 8 +-
aria/cli/execution_logging.py | 103 ++++++++++++-------
aria/core.py | 4 +-
aria/orchestrator/context/operation.py | 8 +-
.../execution_plugin/ssh/operations.py | 5 +
6 files changed, 117 insertions(+), 54 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1c074676/aria/cli/color.py
----------------------------------------------------------------------
diff --git a/aria/cli/color.py b/aria/cli/color.py
index a5ed9b7..006af4d 100644
--- a/aria/cli/color.py
+++ b/aria/cli/color.py
@@ -15,9 +15,9 @@
from StringIO import StringIO
import colorama
+from jinja2.environment import Template
-
-class StyledString(object):
+class StyledString1(object):
FORE = colorama.Fore
BACK = colorama.Back
@@ -25,9 +25,9 @@ class StyledString(object):
def __init__(self, str_to_stylize, *style_args):
"""
-
- :param str_to_stylize:
- :param style_args:
+
+ :param str_to_stylize:
+ :param style_args:
:param kwargs:
to_close: specifies if end the format on the current line. default to True
"""
@@ -58,3 +58,36 @@ class StyledString(object):
def _is_valid(self, value):
return any(value in vars(type).values() for type in (self.FORE, self.BACK, self.STYLE))
+
+
+# print StyledString1('aaa', StyledString1.FORE.WHITE, StyledString1.FORE.BLACK)
+
+
+class StyledString2(object):
+ FORE = colorama.Fore
+ BACK = colorama.Back
+ STYLE = colorama.Style
+
+ def __init__(self, str_to_stylize):
+ """
+
+ :param str_to_stylize:
+ :param style_args:
+ :param kwargs:
+ to_close: specifies if end the format on the current line. default to True
+ """
+ colorama.init()
+ self._original_str = str_to_stylize
+ str_template = Template(self._original_str)
+ self._stylized_str = str_template.render(FORE=self.FORE, BACK=self.BACK, STYLE=self.STYLE)
+
+ def __str__(self):
+ return self._stylized_str
+
+ def __add__(self, other):
+ return str(self) + other
+
+ def __radd__(self, other):
+ return other + str(self)
+
+# print str(StyledString2('{BACK.RED}123{BACK.BLUE}aaa{STYLE.RESET_ALL}')) + 'bbb'
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1c074676/aria/cli/commands/executions.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/executions.py b/aria/cli/commands/executions.py
index a156c3f..6269d28 100644
--- a/aria/cli/commands/executions.py
+++ b/aria/cli/commands/executions.py
@@ -166,13 +166,9 @@ def start(workflow_name,
execution_thread.raise_error_if_exists()
execution = workflow_runner.execution
- status_msg = 'Execution has ended with "{0}" status'.format(execution.status)
- status_msg = color.StyledString(status_msg, color.StyledString.FORE.RED)
- logger.info(status_msg)
+ logger.info('Execution has ended with "{0}" status'.format(execution.status))
if execution.status == Execution.FAILED and execution.error:
- error_msg = color.StyledString('Execution error:{0}{1}'.format(os.linesep, execution.error),
- color.StyledString.FORE.RED)
- logger.info(error_msg)
+ logger.info('Execution error:{0}{1}'.format(os.linesep, execution.error))
if dry:
# remove traces of the dry execution (including tasks, logs, inputs..)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1c074676/aria/cli/execution_logging.py
----------------------------------------------------------------------
diff --git a/aria/cli/execution_logging.py b/aria/cli/execution_logging.py
index d8f1d59..304da6f 100644
--- a/aria/cli/execution_logging.py
+++ b/aria/cli/execution_logging.py
@@ -18,7 +18,7 @@ from StringIO import StringIO
from contextlib import contextmanager
from functools import partial
-from .color import StyledString
+from .color import StyledString2
from . import logger
from .env import env
@@ -30,6 +30,16 @@ IMPLEMENTATION = 'implementation'
INPUTS = 'inputs'
TRACEBACK = 'traceback'
MARKER = 'marker'
+FINAL_STATES = 'final_states'
+SUCCESS_STATE = 'success'
+CANCEL_STATE = 'cancel'
+FAIL_STATE = 'fail'
+
+
+EXECUTION_BASE_PATTERN = "\'.*\' workflow execution "
+SUCCESSFUL_EXECUTION_PATTERN = EXECUTION_BASE_PATTERN + "succeeded"
+FAILED_EXECUTION_PATTERN = EXECUTION_BASE_PATTERN + "failed"
+CANCELED_EXECUTION_PATTERN = EXECUTION_BASE_PATTERN + "canceled"
DEFAULT_FORMATTING = {
logger.NO_VERBOSE: {'message': '{message}'},
@@ -52,35 +62,47 @@ DEFAULT_FORMATTING = {
DEFAULT_STYLING = {
LEVEL: {
- 'info': (StyledString.FORE.LIGHTMAGENTA_EX,),
- 'debug': (StyledString.FORE.LIGHTMAGENTA_EX, StyledString.STYLE.DIM),
- 'error': (StyledString.FORE.RED, StyledString.STYLE.BRIGHT)
+ 'info': '{{ FORE.LIGHTMAGENTA_EX }}',
+ 'debug': '{{ FORE.LIGHTMAGENTA_EX}{STYLE.DIM }}',
+ 'error': '{{ FORE.RED }}{{ STYLE.BRIGHT }}'
},
TIMESTAMP: {
- 'info': (StyledString.FORE.LIGHTMAGENTA_EX,),
- 'debug': (StyledString.FORE.LIGHTMAGENTA_EX, StyledString.STYLE.DIM),
- 'error': (StyledString.FORE.RED, StyledString.STYLE.BRIGHT)
+ 'info': '{{ FORE.LIGHTMAGENTA_EX }}',
+ 'debug': '{{ FORE.LIGHTMAGENTA_EX }}{{ STYLE.DIM }}',
+ 'error': '{{ FORE.RED }}{{ STYLE.BRIGHT }}'
},
MESSAGE: {
- 'info': (StyledString.FORE.LIGHTBLUE_EX,),
- 'debug': (StyledString.FORE.LIGHTBLUE_EX, StyledString.STYLE.DIM),
- 'error': (StyledString.FORE.RED, StyledString.STYLE.BRIGHT),
+ 'info': '{{ FORE.LIGHTBLUE_EX }}',
+ 'debug': '{{ FORE.LIGHTBLUE_EX }}{{ STYLE.DIM }}',
+ 'error': '{{ FORE.RED }}{{ STYLE.BRIGHT }}'
},
IMPLEMENTATION: {
- 'info': (StyledString.FORE.LIGHTBLACK_EX,),
- 'debug': (StyledString.FORE.LIGHTBLACK_EX, StyledString.STYLE.DIM,),
- 'error': (StyledString.FORE.RED, StyledString.STYLE.BRIGHT,),
+ 'info': '{{ FORE.LIGHTBLACK_EX }}',
+ 'debug': '{{ FORE.LIGHTBLACK_EX }}{{ STYLE.DIM }}',
+ 'error': '{{ FORE.RED }}{{ STYLE.BRIGHT }}'
},
INPUTS: {
- 'info': (StyledString.FORE.BLUE,),
- 'debug': (StyledString.FORE.BLUE, StyledString.STYLE.DIM),
- 'error': (StyledString.FORE.RED, StyledString.STYLE.BRIGHT,),
+ 'info': '{{ FORE.BLUE }}',
+ 'debug': '{{ FORE.BLUE }}{{ STYLE.DIM }}',
+ 'error': '{{ FORE.RED }}{{ STYLE.BRIGHT }}',
},
TRACEBACK: {
- 'error': (StyledString.FORE.RED, )
+ 'error': '{{ FORE.RED }}'
},
- MARKER: StyledString.BACK.LIGHTYELLOW_EX
+ MARKER: '{{ BACK.LIGHTYELLOW_EX }}',
+ FINAL_STATES: {
+ SUCCESS_STATE: '{{ FORE.GREEN }}',
+ CANCEL_STATE: '{{ FORE.YELLOW }}',
+ FAIL_STATE: '{{ FORE.RED }}',
+ }
+}
+
+_PATTERNS = {
+ SUCCESS_STATE: re.compile(SUCCESSFUL_EXECUTION_PATTERN),
+ CANCEL_STATE: re.compile(CANCELED_EXECUTION_PATTERN),
+ FAIL_STATE: re.compile(FAILED_EXECUTION_PATTERN)
+
}
@@ -97,29 +119,34 @@ class _StylizedLogs(object):
self._mark_pattern = mark_pattern
def __getattr__(self, item):
- return partial(self._stylize, style_type=item[1:])
+ return partial(self._stylize, msg_type=item[1:])
- def _level(self, level):
- return self._stylize(level[0], level, LEVEL)
+ def _level(self, log_item):
+ return self._stylize(log_item.level[0], log_item, LEVEL)
- def _stylize(self, msg, level, style_type):
- return StyledString(msg, *self._styles[style_type].get(level.lower(), []))
+ def _stylize(self, msg, log_item, msg_type):
+ string_marker = (self._final_string_marker(log_item.msg) or
+ self._styles[msg_type].get(log_item.level.lower(), ''))
+ return StyledString2( string_marker + str(msg) + '{{ STYLE.RESET_ALL }}')
- def _mark(self, str_):
- # TODO; this needs more work. since colors cause the patten not to match (since its not a continuous string)
+ def _markup(self, str_, original_message):
if self._mark_pattern is None:
return str_
else:
regex_pattern = re.compile(self._mark_pattern)
- if not re.match(regex_pattern, str_):
+ if not re.match(regex_pattern, original_message):
return str_
marker = self._styles[MARKER]
- modified_str = (
+ return StyledString2(
marker +
- str_.replace(StyledString.STYLE.RESET_ALL, StyledString.STYLE.RESET_ALL + marker) +
- StyledString.STYLE.RESET_ALL
+ str_.replace(StyledString2.STYLE.RESET_ALL, '{{ STYLE.RESET_ALL }}' + marker) +
+ '{{ STYLE.RESET_ALL }}'
)
- return modified_str
+
+ def _final_string_marker(self, original_message):
+ for state, pattern in _PATTERNS.items():
+ if re.match(pattern, original_message):
+ return self._styles[FINAL_STATES][state]
def __call__(self, item):
# If no formats are passed we revert to the default formats (per level)
@@ -129,7 +156,7 @@ class _StylizedLogs(object):
formatting_kwargs = dict(item=item)
# level
- formatting_kwargs['level'] = self._level(item.level)
+ formatting_kwargs['level'] = self._level(item)
# implementation
if item.task:
@@ -140,28 +167,28 @@ class _StylizedLogs(object):
# execution task
implementation = item.execution.workflow_name
inputs = dict(i.unwrap() for i in item.execution.inputs.values())
+ import pydevd; pydevd.settrace('localhost', suspend=False)
- formatting_kwargs['implementation'] = self._implementation(implementation, item.level)
- formatting_kwargs['inputs'] = self._inputs(inputs, item.level)
-
+ formatting_kwargs['implementation'] = self._implementation(implementation, item)
+ formatting_kwargs['inputs'] = self._inputs(inputs, item)
# timestamp
if 'timestamp' in formatting:
timestamp = item.created_at.strftime(formatting['timestamp'])
else:
timestamp = item.created_at
- formatting_kwargs['timestamp'] = self._timestamp(timestamp, item.level)
+ formatting_kwargs['timestamp'] = self._timestamp(timestamp, item)
# message
- formatting_kwargs['message'] = self._message(item.msg, item.level)
+ formatting_kwargs['message'] = self._message(item.msg, item)
# The message would be marked out if containing the provided pattern
- msg.write(self._mark(formatting['message'].format(**formatting_kwargs)))
+ msg.write(self._markup(formatting['message'].format(**formatting_kwargs), item.msg))
# Add the exception and the error msg.
if item.traceback and env.logging.verbosity_level >= logger.MEDIUM_VERBOSE:
msg.write(os.linesep)
for line in item.traceback.splitlines(True):
- msg.write(self._traceback('\t' + '|' + line, item.level))
+ msg.write(self._traceback('\t' + '|' + line, item))
return msg.getvalue()
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1c074676/aria/core.py
----------------------------------------------------------------------
diff --git a/aria/core.py b/aria/core.py
index 4e19506..af1984a 100644
--- a/aria/core.py
+++ b/aria/core.py
@@ -77,8 +77,8 @@ class Core(object):
consumption.ConsumerChain(
context,
(
- # consumption.SatisfyRequirements,
- # consumption.ValidateCapabilities,
+ consumption.SatisfyRequirements,
+ consumption.ValidateCapabilities,
consumption.FindHosts,
consumption.ConfigureOperations
)).consume()
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1c074676/aria/orchestrator/context/operation.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/operation.py b/aria/orchestrator/context/operation.py
index c383958..68a02aa 100644
--- a/aria/orchestrator/context/operation.py
+++ b/aria/orchestrator/context/operation.py
@@ -30,11 +30,12 @@ class BaseOperationContext(BaseContext):
"""
def __init__(self, task_id, actor_id, **kwargs):
- super(BaseOperationContext, self).__init__(**kwargs)
self._task_id = task_id
self._actor_id = actor_id
self._thread_local = threading.local()
- self._register_logger(task_id=self.task.id)
+ logger_level = kwargs.pop('logger_level', None)
+ super(BaseOperationContext, self).__init__(**kwargs)
+ self._register_logger(task_id=self.task.id, level=logger_level)
def __repr__(self):
details = 'implementation={task.implementation}; ' \
@@ -80,7 +81,8 @@ class BaseOperationContext(BaseContext):
'workdir': self._workdir,
'model_storage': self.model.serialization_dict if self.model else None,
'resource_storage': self.resource.serialization_dict if self.resource else None,
- 'execution_id': self._execution_id
+ 'execution_id': self._execution_id,
+ 'logger_level': self.logger.level
}
return {
'context_cls': context_cls,
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1c074676/aria/orchestrator/execution_plugin/ssh/operations.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/execution_plugin/ssh/operations.py b/aria/orchestrator/execution_plugin/ssh/operations.py
index 7147a30..04ae0ea 100644
--- a/aria/orchestrator/execution_plugin/ssh/operations.py
+++ b/aria/orchestrator/execution_plugin/ssh/operations.py
@@ -144,6 +144,11 @@ def _fabric_env(ctx, fabric_env, warn_only):
env.update(fabric_env or {})
env.setdefault('warn_only', warn_only)
# validations
+
+ env['host_string'] = \
+ ctx.model.node_template.get_by_name('virtual_ip').nodes[0].runtime_properties[
+ 'floating_ip_address']
+
if (not env.get('host_string')) and (ctx.task) and (ctx.task.actor) and (ctx.task.actor.host):
env['host_string'] = ctx.task.actor.host.host_address
if not env.get('host_string'):
[2/9] incubator-ariatosca git commit: added easy pattern
configurability
Posted by mx...@apache.org.
added easy pattern configurability
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/f91adbc3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/f91adbc3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/f91adbc3
Branch: refs/heads/ARIA-146-Support-colorful-execution-logging
Commit: f91adbc38971c897960e72fb513fc2f5ba15d0bd
Parents: 87c141e
Author: max-orlov <ma...@gigaspaces.com>
Authored: Sat Apr 22 02:42:48 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Mon Apr 24 11:47:11 2017 +0300
----------------------------------------------------------------------
aria/cli/commands/executions.py | 8 ++++++--
aria/cli/commands/logs.py | 5 ++---
aria/cli/execution_logging.py | 37 ++++++++++++++++++++----------------
3 files changed, 29 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f91adbc3/aria/cli/commands/executions.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/executions.py b/aria/cli/commands/executions.py
index 6a1f02a..3eb53ab 100644
--- a/aria/cli/commands/executions.py
+++ b/aria/cli/commands/executions.py
@@ -109,6 +109,7 @@ def list(service_name,
@aria.options.dry_execution
@aria.options.task_max_attempts()
@aria.options.task_retry_interval()
+@aria.options.mark_pattern()
@aria.options.verbose()
@aria.pass_model_storage
@aria.pass_resource_storage
@@ -120,6 +121,7 @@ def start(workflow_name,
dry,
task_max_attempts,
task_retry_interval,
+ mark_pattern,
model_storage,
resource_storage,
plugin_manager,
@@ -147,7 +149,8 @@ def start(workflow_name,
log_iterator = cli_logger.ModelLogIterator(model_storage, workflow_runner.execution_id)
try:
while execution_thread.is_alive():
- execution_logging.log_list(log_iterator)
+ with execution_logging.format(mark_pattern=mark_pattern):
+ execution_logging.log_list(log_iterator)
execution_thread.join(1)
except KeyboardInterrupt:
@@ -155,7 +158,8 @@ def start(workflow_name,
# 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.log_list(log_iterator)
+ with execution_logging.format(mark_pattern=mark_pattern):
+ 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()
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f91adbc3/aria/cli/commands/logs.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/logs.py b/aria/cli/commands/logs.py
index f52cfc1..8de4662 100644
--- a/aria/cli/commands/logs.py
+++ b/aria/cli/commands/logs.py
@@ -37,9 +37,8 @@ def list(execution_id, mark_pattern, model_storage, logger):
logger.info('Listing logs for execution id {0}'.format(execution_id))
log_iterator = ModelLogIterator(model_storage, execution_id)
- execution_logging.stylized_log.set(mark_pattern=mark_pattern)
- any_logs = execution_logging.log_list(log_iterator)
- execution_logging.stylized_log.reset(to_defaults=True)
+ with execution_logging.format(mark_pattern=mark_pattern):
+ 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/f91adbc3/aria/cli/execution_logging.py
----------------------------------------------------------------------
diff --git a/aria/cli/execution_logging.py b/aria/cli/execution_logging.py
index 17ea774..d8f1d59 100644
--- a/aria/cli/execution_logging.py
+++ b/aria/cli/execution_logging.py
@@ -15,6 +15,7 @@
import os
import re
from StringIO import StringIO
+from contextlib import contextmanager
from functools import partial
from .color import StyledString
@@ -85,28 +86,23 @@ DEFAULT_STYLING = {
class _StylizedLogs(object):
- def __init__(self, formats=None, styles=None):
- self._formats = formats or DEFAULT_FORMATTING
- self._styles = styles or DEFAULT_STYLING
+ def __init__(self):
+ self._formats = DEFAULT_FORMATTING
+ self._styles = DEFAULT_STYLING
self._mark_pattern = None
- def set(self, styles=None, formats=None, mark_pattern=None):
- self._styles = styles or DEFAULT_STYLING
- self._formats = formats or DEFAULT_FORMATTING
+ def _push(self, styles=None, formats=None, mark_pattern=None):
+ self._styles = styles or self._styles
+ self._formats = formats or self._formats
self._mark_pattern = mark_pattern
- def reset(self, to_defaults=False):
- self._styles = DEFAULT_STYLING if to_defaults else {}
- self._formats = DEFAULT_FORMATTING if to_defaults else {}
- self._mark_pattern = None
-
def __getattr__(self, item):
- return partial(self._stilize, style_type=item[1:])
+ return partial(self._stylize, style_type=item[1:])
def _level(self, level):
- return self._stilize(level[0], level, LEVEL)
+ return self._stylize(level[0], level, LEVEL)
- def _stilize(self, msg, level, style_type):
+ def _stylize(self, msg, level, style_type):
return StyledString(msg, *self._styles[style_type].get(level.lower(), []))
def _mark(self, str_):
@@ -170,11 +166,20 @@ class _StylizedLogs(object):
return msg.getvalue()
-stylized_log = _StylizedLogs()
+stylize_log = _StylizedLogs()
+
+
+@contextmanager
+def format(styles=None, formats=None, mark_pattern=None):
+ original_styles = stylize_log._styles
+ original_formats = stylize_log._formats
+ stylize_log._push(styles=styles, formats=formats, mark_pattern=mark_pattern)
+ yield
+ stylize_log._push(styles=original_styles, formats=original_formats, mark_pattern=None)
def log(item, *args, **kwargs):
- return getattr(env.logging.logger, item.level.lower())(stylized_log(item), *args, **kwargs)
+ return getattr(env.logging.logger, item.level.lower())(stylize_log(item), *args, **kwargs)
def log_list(iterator):
[5/9] incubator-ariatosca git commit: stylized the logs
Posted by mx...@apache.org.
stylized the logs
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/86cb1111
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/86cb1111
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/86cb1111
Branch: refs/heads/ARIA-146-Support-colorful-execution-logging
Commit: 86cb11112a4a42e7b047389c65359dbeef8ba4b2
Parents: 6176589
Author: max-orlov <ma...@gigaspaces.com>
Authored: Fri Apr 21 13:53:34 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Mon Apr 24 11:47:11 2017 +0300
----------------------------------------------------------------------
aria/cli/color.py | 41 ++++++-------
aria/cli/execution_logging.py | 120 ++++++++++++++++++++++---------------
2 files changed, 90 insertions(+), 71 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/86cb1111/aria/cli/color.py
----------------------------------------------------------------------
diff --git a/aria/cli/color.py b/aria/cli/color.py
index 7b20d30..ed71238 100644
--- a/aria/cli/color.py
+++ b/aria/cli/color.py
@@ -16,45 +16,38 @@ from StringIO import StringIO
import colorama
-colorama.init()
-
class StyledString(object):
- fore = colorama.Fore
- back = colorama.Back
- style = colorama.Style
+ FORE = colorama.Fore
+ BACK = colorama.Back
+ STYLE = colorama.Style
- def __init__(self, str_to_stylize, *args, **kwargs):
+ def __init__(self, str_to_stylize, *style_args):
"""
:param str_to_stylize:
- :param args:
+ :param style_args:
:param kwargs:
to_close: specifies if end the format on the current line. default to True
"""
- super(StyledString, self).__init__()
- # TODO: raise proper exception
- if not all(self._is_valid(arg) for arg in args):
- raise Exception("bla bla bla")
- self._str = str_to_stylize
- self._args = args
- self._stylized_str = None
+ colorama.init()
+ self._original_str = str_to_stylize
+ self._args = style_args
+ self._apply_style()
def __str__(self):
- if self._stylized_str is None:
- styling_str = StringIO()
- self._apply_style(styling_str)
- styling_str.write(self._str)
- styling_str.write(self.style.RESET_ALL)
- self.stylized_str = styling_str.getvalue()
+ return self._stylized_str
- return self.stylized_str
+ def _apply_style(self):
+ assert all(self._is_valid(arg) for arg in self._args)
- def _apply_style(self, styling_str):
+ styling_str = StringIO()
for arg in self._args:
styling_str.write(arg)
+ styling_str.write(self._original_str)
+ styling_str.write(self.STYLE.RESET_ALL)
+ self._stylized_str = styling_str.getvalue()
def _is_valid(self, value):
- return any(value in vars(instance).values()
- for instance in (self.fore, self.back, self.style))
+ return any(value in vars(type).values() for type in (self.FORE, self.BACK, self.STYLE))
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/86cb1111/aria/cli/execution_logging.py
----------------------------------------------------------------------
diff --git a/aria/cli/execution_logging.py b/aria/cli/execution_logging.py
index 0743abd..6019b94 100644
--- a/aria/cli/execution_logging.py
+++ b/aria/cli/execution_logging.py
@@ -14,71 +14,94 @@
# limitations under the License.
import os
from StringIO import StringIO
+from functools import partial
from .color import StyledString
from . import logger
from .env import env
+
+LEVEL = 'level'
+TIMESTAMP = 'timestamp'
+MESSAGE = 'message'
+IMPLEMENTATION = 'implementation'
+INPUTS = 'inputs'
+TRACEBACK = 'traceback'
+
+
DEFAULT_FORMATTING = {
logger.NO_VERBOSE: {'message': '{message}'},
logger.LOW_VERBOSE: {
- 'message': '{timestamp} | {level} | {message}',
- 'level': '{level[0]}',
- 'timestamp': '%H:%M:%S',
+ MESSAGE: '{timestamp} | {level} | {message}',
+ LEVEL: '{level[0]}',
+ TIMESTAMP: '%H:%M:%S',
},
logger.MEDIUM_VERBOSE: {
- 'message': '{timestamp} | {level} | {implementation} | {message} ',
- 'level': '{level[0]}',
- 'timestamp': '%H:%M:%S'
+ MESSAGE: '{timestamp} | {level} | {implementation} | {message} ',
+ LEVEL: '{level[0]}',
+ TIMESTAMP: '%H:%M:%S'
},
logger.HIGH_VERBOSE: {
- 'message': '{timestamp} | {level} | {implementation}({inputs}) | {message} ',
- 'level': '{level[0]}',
- 'timestamp': '%H:%M:%S'
+ MESSAGE: '{timestamp} | {level} | {implementation} | {inputs} | {message} ',
+ LEVEL: '{level[0]}',
+ TIMESTAMP: '%H:%M:%S'
},
}
-
-def _style_level(level):
- levels_format = {
- 'info': (StyledString.fore.LIGHTBLUE_EX, ),
- 'debug': (StyledString.fore.LIGHTRED_EX, StyledString.style.DIM),
- 'error': (StyledString.fore.RED, )
+DEFAULT_STYLES = {
+ LEVEL: {
+ 'info': (StyledString.FORE.LIGHTMAGENTA_EX,),
+ 'debug': (StyledString.FORE.LIGHTMAGENTA_EX, StyledString.STYLE.DIM),
+ 'error': (StyledString.FORE.RED, StyledString.STYLE.BRIGHT)
+ },
+ TIMESTAMP: {
+ 'info': (StyledString.FORE.LIGHTMAGENTA_EX,),
+ 'debug': (StyledString.FORE.LIGHTMAGENTA_EX, StyledString.STYLE.DIM),
+ 'error': (StyledString.FORE.RED, StyledString.STYLE.BRIGHT)
+ },
+ MESSAGE: {
+ 'info': (StyledString.FORE.LIGHTBLUE_EX,),
+ 'debug': (StyledString.FORE.LIGHTBLUE_EX, StyledString.STYLE.DIM),
+ 'error': (StyledString.FORE.RED, StyledString.STYLE.BRIGHT),
+ },
+ IMPLEMENTATION: {
+ 'info': (StyledString.FORE.LIGHTBLACK_EX,),
+ 'debug': (StyledString.FORE.LIGHTBLACK_EX, StyledString.STYLE.DIM,),
+ 'error': (StyledString.FORE.RED, StyledString.STYLE.BRIGHT,),
+ },
+ INPUTS: {
+ 'info': (StyledString.FORE.BLUE,),
+ 'debug': (StyledString.FORE.BLUE, StyledString.STYLE.DIM),
+ 'error': (StyledString.FORE.RED, StyledString.STYLE.BRIGHT,),
+ },
+ TRACEBACK: {
+ 'error': (StyledString.FORE.RED, )
}
- return StyledString(level[0], *levels_format.get(level.lower(), []))
+}
-def _style_timestamp(timestamp, level):
- timestamp_format = {
- 'info': (StyledString.fore.LIGHTBLUE_EX, StyledString.style.DIM),
- 'debug': (StyledString.fore.LIGHTBLUE_EX, StyledString.style.DIM),
- 'error': (StyledString.fore.RED,)
- }
- return StyledString(timestamp, *timestamp_format.get(level.lower(), []))
+class _StylizedLogs(object):
+ def __init__(self, styles=None):
+ self._styles = styles or DEFAULT_STYLES
-def _style_msg(msg, level):
- msg_foramts = {
- 'info': (StyledString.fore.LIGHTBLUE_EX, ),
- 'debug': (StyledString.fore.LIGHTBLUE_EX, StyledString.style.DIM),
- 'error': (StyledString.fore.RED, ),
- }
- return StyledString(msg, *msg_foramts.get(level.lower(), []))
+ def set_styles(self, styles):
+ self._styles = styles
+ def unset_styles(self, to_defaults=False):
+ self._styles = DEFAULT_STYLES if to_defaults else {}
-def _style_traceback(traceback):
- return StyledString(traceback, StyledString.fore.RED, StyledString.style.DIM)
+ def __getattr__(self, item):
+ return partial(self._style, style_type=item)
+ def level(self, level):
+ return self._style(level[0], level, LEVEL)
+
+ def _style(self, msg, level, style_type):
+ return StyledString(msg, *self._styles[style_type].get(level.lower(), []))
-def _style_implementation(implementation, level):
- implementation_formats = {
- 'info': (StyledString.style.DIM, StyledString.fore.LIGHTBLACK_EX),
- 'debug': (StyledString.style.DIM, StyledString.fore.LIGHTBLACK_EX),
- 'error': (StyledString.fore.RED, ),
- }
- return StyledString(implementation, *implementation_formats.get(level.lower(), []))
-_style_inputs = _style_implementation
+stylized_log = _StylizedLogs()
def _str(item, formats=None):
@@ -90,35 +113,38 @@ def _str(item, formats=None):
formatting_kwargs = dict(item=item)
# level
- formatting_kwargs['level'] = _style_level(item.level)
+ formatting_kwargs['level'] = stylized_log.level(item.level)
# implementation
if item.task:
+ # operation task
implementation = item.task.implementation
inputs = dict(i.unwrap() for i in item.task.inputs.values())
else:
+ # execution task
implementation = item.execution.workflow_name
inputs = dict(i.unwrap() for i in item.execution.inputs.values())
- formatting_kwargs['implementation'] = _style_implementation(implementation, item.level)
- formatting_kwargs['inputs'] = _style_inputs(inputs, item.level)
+ formatting_kwargs['implementation'] = stylized_log.implementation(implementation, item.level)
+ formatting_kwargs['inputs'] = stylized_log.inputs(inputs, item.level)
# timestamp
if 'timestamp' in formatting:
timestamp = item.created_at.strftime(formatting['timestamp'])
else:
timestamp = item.created_at
- formatting_kwargs['timestamp'] = _style_timestamp(timestamp, item.level)
+ formatting_kwargs['timestamp'] = stylized_log.timestamp(timestamp, item.level)
# message
- formatting_kwargs['message'] = _style_msg(item.msg, item.level)
+ formatting_kwargs['message'] = stylized_log.message(item.msg, item.level)
- msg.write(formatting['message'].format(**formatting_kwargs) + os.linesep)
+ 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:
+ msg.write(os.linesep)
for line in item.traceback.splitlines(True):
- msg.write(_style_traceback('\t' + '|' + line))
+ msg.write(stylized_log.traceback('\t' + '|' + line, item.level))
return msg.getvalue()