You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ariatosca.apache.org by mx...@apache.org on 2017/08/09 12:07:01 UTC
[5/8] incubator-ariatosca git commit: self fixes
self 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/6c5c4a67
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/6c5c4a67
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/6c5c4a67
Branch: refs/heads/ARIA-174-Refactor-instantiation-phase
Commit: 6c5c4a67f495d58d6270b73d79c12f38916eea01
Parents: 56841a4
Author: max-orlov <ma...@gigaspaces.com>
Authored: Tue Aug 1 11:37:25 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Wed Aug 9 14:54:09 2017 +0300
----------------------------------------------------------------------
aria/cli/commands/service_templates.py | 8 +-
aria/cli/commands/services.py | 6 +-
aria/core.py | 29 +++--
aria/modeling/functions.py | 10 +-
.../execution_plugin/instantiation.py | 121 ++++++++-----------
aria/orchestrator/topology/instance_handler.py | 2 +-
aria/parser/consumption/consumer.py | 3 +-
aria/utils/__init__.py | 47 +++++++
8 files changed, 126 insertions(+), 100 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/6c5c4a67/aria/cli/commands/service_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/service_templates.py b/aria/cli/commands/service_templates.py
index 608d178..89662a9 100644
--- a/aria/cli/commands/service_templates.py
+++ b/aria/cli/commands/service_templates.py
@@ -28,7 +28,7 @@ from ...core import Core
from ...storage import exceptions as storage_exceptions
from ...parser import consumption
from ...utils import (formatting, collections, console)
-from ... orchestrator.topology import Topology
+from ... orchestrator import topology
DESCRIPTION_FIELD_LENGTH_LIMIT = 20
SERVICE_TEMPLATE_COLUMNS = \
@@ -57,7 +57,7 @@ def service_templates():
def show(service_template_name, model_storage, mode_full, mode_types, format_json, format_yaml,
logger):
"""
- Show information for a stored service template
+ Show information for a stored service templates
SERVICE_TEMPLATE_NAME is the unique name of the stored service template.
"""
@@ -73,9 +73,9 @@ def show(service_template_name, model_storage, mode_full, mode_types, format_jso
elif format_yaml:
console.puts(formatting.yaml_dumps(collections.prune(service_template.as_raw)))
else:
- console.puts(Topology().dump(service_template))
+ console.puts(topology.Topology().dump(service_template))
elif mode_types:
- console.puts(Topology().dump_types(service_template=service_template))
+ console.puts(topology.Topology().dump_types(service_template=service_template))
else:
logger.info('Showing service template {0}...'.format(service_template_name))
service_template_dict = service_template.to_dict()
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/6c5c4a67/aria/cli/commands/services.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/services.py b/aria/cli/commands/services.py
index 4890bb7..6752899 100644
--- a/aria/cli/commands/services.py
+++ b/aria/cli/commands/services.py
@@ -20,7 +20,6 @@ CLI ``services`` sub-commands.
import os
from StringIO import StringIO
-from aria.orchestrator.topology import Topology
from . import service_templates
from .. import helptexts
from .. import table
@@ -31,6 +30,7 @@ from ...modeling import exceptions as modeling_exceptions
from ...storage import exceptions as storage_exceptions
from ...parser import consumption
from ...utils import (formatting, collections, console)
+from ...orchestrator import topology
DESCRIPTION_FIELD_LENGTH_LIMIT = 20
@@ -74,9 +74,9 @@ def show(service_name, model_storage, mode_full, mode_graph, format_json, format
elif format_yaml:
console.puts(formatting.yaml_dumps(collections.prune(service.as_raw)))
else:
- console.puts(Topology().dump(service))
+ console.puts(topology.Topology().dump(service))
elif mode_graph:
- console.puts(Topology().dump_graph(service))
+ console.puts(topology.Topology().dump_graph(service))
else:
logger.info('Showing service {0}...'.format(service_name))
service_dict = service.to_dict()
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/6c5c4a67/aria/core.py
----------------------------------------------------------------------
diff --git a/aria/core.py b/aria/core.py
index e726be7..a81ae13 100644
--- a/aria/core.py
+++ b/aria/core.py
@@ -20,7 +20,7 @@ ARIA core module.
from . import exceptions
from .parser import consumption
from .parser.loading.location import UriLocation
-from .orchestrator.topology import Topology
+from .orchestrator import topology
class Core(object):
@@ -74,20 +74,19 @@ class Core(object):
# setting no autoflush for the duration of instantiation - this helps avoid dependency
# constraints as they're being set up
with storage_session.no_autoflush:
- topology = Topology(self.model_storage)
- service = topology.instantiate(service_template, inputs=inputs)
- topology.coerce(service)
-
- topology.validate(service)
- topology.satisfy_requirements(service)
- topology.coerce(service)
-
- topology.validate_capabilities(service)
- topology.find_hosts(service)
- topology.configure_operations(service)
- topology.coerce(service)
-
- if topology.dump_issues():
+ topology_ = topology.Topology(self.model_storage)
+ service = topology_.instantiate(service_template, inputs=inputs)
+ topology_.coerce(service)
+
+ topology_.validate(service)
+ topology_.satisfy_requirements(service)
+ topology_.coerce(service)
+
+ topology_.validate_capabilities(service)
+ topology_.find_hosts(service)
+ topology_.configure_operations(service)
+ topology_.coerce(service)
+ if topology_.dump_issues():
raise exceptions.InstantiationError('Failed to instantiate service template `{0}`'
.format(service_template.name))
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/6c5c4a67/aria/modeling/functions.py
----------------------------------------------------------------------
diff --git a/aria/modeling/functions.py b/aria/modeling/functions.py
index 7330268..31c3839 100644
--- a/aria/modeling/functions.py
+++ b/aria/modeling/functions.py
@@ -16,8 +16,8 @@
"""
Mechanism for evaluating intrinsic functions.
"""
-
from ..parser.exceptions import InvalidValueError
+from ..parser.consumption import ConsumptionContext
from ..utils.collections import OrderedDict
from . import exceptions
@@ -102,12 +102,10 @@ def evaluate(value, container_holder, report_issues=False): # pylint: disable=to
final = False
except exceptions.CannotEvaluateFunctionException:
pass
- except InvalidValueError:
+ except InvalidValueError as e:
if report_issues:
- # TODO: do not use the context for "reporting"
- pass
- # context = ConsumptionContext.get_thread_local()
- # context.validation.report(e.issue)
+ context = ConsumptionContext.get_thread_local()
+ context.validation.report(e.issue)
elif isinstance(value, list):
evaluated_list = []
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/6c5c4a67/aria/orchestrator/execution_plugin/instantiation.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/execution_plugin/instantiation.py b/aria/orchestrator/execution_plugin/instantiation.py
index 49605b9..8b52015 100644
--- a/aria/orchestrator/execution_plugin/instantiation.py
+++ b/aria/orchestrator/execution_plugin/instantiation.py
@@ -18,12 +18,11 @@ Instantiation of :class:`~aria.modeling.models.Operation` models.
"""
# TODO: this module will eventually be moved to a new "aria.instantiation" package
-
-from ...utils.collections import OrderedDict
from ...modeling.functions import Function
+from ... import utils
-def configure_operation(operation):
+def configure_operation(operation, reporter):
host = None
interface = operation.interface
if interface.node is not None:
@@ -34,11 +33,11 @@ def configure_operation(operation):
else: # either False or None (None meaning that edge was not specified)
host = interface.relationship.source_node.host
- _configure_common(operation)
+ _configure_common(operation, reporter)
if host is None:
_configure_local(operation)
else:
- _configure_remote(operation)
+ _configure_remote(operation, reporter)
# Any remaining un-handled configuration parameters will become extra arguments, available as
# kwargs in either "run_script_locally" or "run_script_with_ssh"
@@ -47,7 +46,7 @@ def configure_operation(operation):
operation.arguments[key] = value.instantiate(None)
-def _configure_common(operation):
+def _configure_common(operation, reporter):
"""
Local and remote operations.
"""
@@ -55,7 +54,7 @@ def _configure_common(operation):
from ...modeling.models import Argument
operation.arguments['script_path'] = Argument.wrap('script_path', operation.implementation,
'Relative path to the executable file.')
- operation.arguments['process'] = Argument.wrap('process', _get_process(operation),
+ operation.arguments['process'] = Argument.wrap('process', _get_process(operation, reporter),
'Sub-process configuration.')
@@ -69,7 +68,7 @@ def _configure_local(operation):
operations.run_script_locally.__name__)
-def _configure_remote(operation):
+def _configure_remote(operation, reporter):
"""
Remote SSH operation via Fabric.
"""
@@ -77,7 +76,7 @@ def _configure_remote(operation):
from ...modeling.models import Argument
from . import operations
- ssh = _get_ssh(operation)
+ ssh = _get_ssh(operation, reporter)
# Defaults
# TODO: find a way to configure these generally in the service template
@@ -106,24 +105,17 @@ def _configure_remote(operation):
# Make sure we have a user
if fabric_env.get('user') is None:
- # TODO: fix
- pass
- # context = ConsumptionContext.get_thread_local()
- # context.validation.report('must configure "ssh.user" for "{0}"'
- # .format(operation.implementation),
- # level=validation.Issue.BETWEEN_TYPES)
+ reporter.report('must configure "ssh.user" for "{0}"'.format(operation.implementation),
+ level=reporter.Issue.BETWEEN_TYPES)
# Make sure we have an authentication value
if (fabric_env.get('password') is None) and \
(fabric_env.get('key') is None) and \
(fabric_env.get('key_filename') is None):
- # TODO: fix
- pass
- # context = ConsumptionContext.get_thread_local()
- # context.validation.report(
- # 'must configure "ssh.password", "ssh.key", or "ssh.key_filename" for "{0}"'.format(
- # operation.implementation),
- # level=validation.Issue.BETWEEN_TYPES)
+ reporter.report(
+ 'must configure "ssh.password", "ssh.key", or "ssh.key_filename" for "{0}"'
+ .format(operation.implementation),
+ level=reporter.Issue.BETWEEN_TYPES)
operation.arguments['fabric_env'] = Argument.wrap('fabric_env', fabric_env,
'Fabric configuration.')
@@ -132,105 +124,94 @@ def _configure_remote(operation):
operations.run_script_with_ssh.__name__)
-def _get_process(operation):
+def _get_process(operation, reporter):
value = (operation.configurations.get('process')._value
if 'process' in operation.configurations
else None)
if value is None:
return {}
- _validate_type(value, dict, 'process')
- value = OrderedDict(value)
+ _validate_type(value, dict, 'process', reporter)
+ value = utils.collections.OrderedDict(value)
for k, v in value.iteritems():
if k == 'eval_python':
- value[k] = _coerce_bool(v, 'process.eval_python')
+ value[k] = _coerce_bool(v, 'process.eval_python', reporter)
elif k == 'cwd':
- _validate_type(v, basestring, 'process.cwd')
+ _validate_type(v, basestring, 'process.cwd', reporter)
elif k == 'command_prefix':
- _validate_type(v, basestring, 'process.command_prefix')
+ _validate_type(v, basestring, 'process.command_prefix', reporter)
elif k == 'args':
- value[k] = _dict_to_list_of_strings(v, 'process.args')
+ value[k] = _dict_to_list_of_strings(v, 'process.args', reporter)
elif k == 'env':
- _validate_type(v, dict, 'process.env')
+ _validate_type(v, dict, 'process.env', reporter)
else:
- # TODO: fix
- pass
- # context = ConsumptionContext.get_thread_local()
- # context.validation.report('unsupported configuration parameter: "process.{0}"'
- # .format(k),
- # level=validation.Issue.BETWEEN_TYPES)
+ reporter.report('unsupported configuration parameter: "process.{0}"'.format(k),
+ level=reporter.Issue.BETWEEN_TYPES)
return value
-def _get_ssh(operation):
+def _get_ssh(operation, reporter):
value = (operation.configurations.get('ssh')._value
if 'ssh' in operation.configurations
else None)
if value is None:
return {}
- _validate_type(value, dict, 'ssh')
- value = OrderedDict(value)
+ _validate_type(value, dict, 'ssh', reporter)
+ value = utils.collections.OrderedDict(value)
for k, v in value.iteritems():
if k == 'use_sudo':
- value[k] = _coerce_bool(v, 'ssh.use_sudo')
+ value[k] = _coerce_bool(v, 'ssh.use_sudo', reporter)
elif k == 'hide_output':
- value[k] = _dict_to_list_of_strings(v, 'ssh.hide_output')
+ value[k] = _dict_to_list_of_strings(v, 'ssh.hide_output', reporter)
elif k == 'warn_only':
- value[k] = _coerce_bool(v, 'ssh.warn_only')
+ value[k] = _coerce_bool(v, 'ssh.warn_only', reporter)
elif k == 'user':
- _validate_type(v, basestring, 'ssh.user')
+ _validate_type(v, basestring, 'ssh.user', reporter)
elif k == 'password':
- _validate_type(v, basestring, 'ssh.password')
+ _validate_type(v, basestring, 'ssh.password', reporter)
elif k == 'key':
- _validate_type(v, basestring, 'ssh.key')
+ _validate_type(v, basestring, 'ssh.key', reporter)
elif k == 'key_filename':
- _validate_type(v, basestring, 'ssh.key_filename')
+ _validate_type(v, basestring, 'ssh.key_filename', reporter)
elif k == 'address':
- _validate_type(v, basestring, 'ssh.address')
+ _validate_type(v, basestring, 'ssh.address', reporter)
else:
- # TODO: fix
- pass
- # context = ConsumptionContext.get_thread_local()
- # context.validation.report('unsupported configuration parameter: "ssh.{0}"'.format(k),
- # level=validation.Issue.BETWEEN_TYPES)
+ reporter.report('unsupported configuration parameter: "ssh.{0}"'.format(k),
+ level=reporter.Issue.BETWEEN_TYPES)
return value
-def _validate_type(value, the_type, name):
+def _validate_type(value, the_type, name, reporter):
if isinstance(value, Function):
return
if not isinstance(value, the_type):
- # TODO: fix
- pass
- # context = ConsumptionContext.get_thread_local()
- # context.validation.report('"{0}" configuration is not a {1}: {2}'
- # .format(name, full_type_name(the_type), safe_repr(value)),
- # level=validation.Issue.BETWEEN_TYPES)
+ reporter.report(
+ '"{0}" configuration is not a {1}: {2}'.format(
+ name, utils.type.full_type_name(the_type), utils.formatting.safe_repr(value)),
+ level=reporter.Issue.BETWEEN_TYPES)
-def _coerce_bool(value, name):
+def _coerce_bool(value, name, reporter):
if value is None:
return None
if isinstance(value, bool):
return value
- _validate_type(value, basestring, name)
+ _validate_type(value, basestring, name, reporter)
if value == 'true':
return True
elif value == 'false':
return False
else:
- # TODO: fix
- pass
- # context = ConsumptionContext.get_thread_local()
- # context.validation.report('"{0}" configuration is not "true" or "false": {1}'
- # .format(name, safe_repr(value)),
- # level=validation.Issue.BETWEEN_TYPES)
+ reporter.report(
+ '"{0}" configuration is not "true" or "false": {1}'.format(
+ name, utils.formatting.safe_repr(value)),
+ level=reporter.Issue.BETWEEN_TYPES)
-def _dict_to_list_of_strings(the_dict, name):
- _validate_type(the_dict, dict, name)
+def _dict_to_list_of_strings(the_dict, name, reporter):
+ _validate_type(the_dict, dict, name, reporter)
value = []
for k in sorted(the_dict):
v = the_dict[k]
- _validate_type(v, basestring, '{0}.{1}'.format(name, k))
+ _validate_type(v, basestring, '{0}.{1}'.format(name, k), reporter)
value.append(v)
return value
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/6c5c4a67/aria/orchestrator/topology/instance_handler.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/topology/instance_handler.py b/aria/orchestrator/topology/instance_handler.py
index dbebf48..ea58d88 100644
--- a/aria/orchestrator/topology/instance_handler.py
+++ b/aria/orchestrator/topology/instance_handler.py
@@ -384,7 +384,7 @@ class Operation(common._OperatorHolderHandlerMixin):
self._model.function is None):
# ("interface" is None for workflow operations, which do not currently use "plugin")
# The default (None) plugin is the execution plugin
- execution_plugin.instantiation.configure_operation(self._model)
+ execution_plugin.instantiation.configure_operation(self._model, self._topology)
else:
# In the future plugins may be able to add their own "configure_operation" hook that
# can validate the configuration and otherwise create specially derived arguments. For
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/6c5c4a67/aria/parser/consumption/consumer.py
----------------------------------------------------------------------
diff --git a/aria/parser/consumption/consumer.py b/aria/parser/consumption/consumer.py
index fb60d66..878a161 100644
--- a/aria/parser/consumption/consumer.py
+++ b/aria/parser/consumption/consumer.py
@@ -14,7 +14,6 @@
# limitations under the License.
-from ...orchestrator import topology
from ...exceptions import AriaException
from ...utils.exceptions import print_exception
from ..validation import Issue
@@ -28,6 +27,8 @@ class Consumer(object):
"""
def __init__(self, context):
+ from ...orchestrator import topology
+
self.topology = topology.Topology()
self.context = context
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/6c5c4a67/aria/utils/__init__.py
----------------------------------------------------------------------
diff --git a/aria/utils/__init__.py b/aria/utils/__init__.py
index 2a957a9..43dd882 100644
--- a/aria/utils/__init__.py
+++ b/aria/utils/__init__.py
@@ -16,3 +16,50 @@
"""
General-purpose utilities package.
"""
+
+from . import (
+ archive,
+ argparse,
+ caching,
+ collections,
+ console,
+ exceptions,
+ file,
+ formatting,
+ http,
+ imports,
+ openclose,
+ plugin,
+ process,
+ specification,
+ threading,
+ type,
+ uris,
+ uuid,
+ validation,
+ versions
+)
+
+
+__all__ = (
+ 'archive',
+ 'argparse',
+ 'caching',
+ 'collections',
+ 'console',
+ 'exceptions',
+ 'file',
+ 'formatting',
+ 'http',
+ 'imports',
+ 'openclose',
+ 'plugin',
+ 'process',
+ 'specification',
+ 'threading',
+ 'type',
+ 'uris',
+ 'uuid',
+ 'validation',
+ 'versions'
+)