Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-48-aria-cli 79f5d78eb -> c1f8eb6a9
various review 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/c1f8eb6a Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/c1f8eb6a Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/c1f8eb6a Branch: refs/heads/ARIA-48-aria-cli Commit: c1f8eb6a924f93656dee6d82ded2dc83ed6b4cc9 Parents: 79f5d78 Author: Ran Ziv <r...@gigaspaces.com> Authored: Tue Apr 18 18:44:34 2017 +0300 Committer: Ran Ziv <r...@gigaspaces.com> Committed: Tue Apr 18 18:44:34 2017 +0300 ---------------------------------------------------------------------- aria/cli/commands/node_templates.py | 3 --- aria/cli/commands/plugins.py | 4 ++-- aria/cli/commands/service_templates.py | 21 +++++---------------- aria/cli/commands/services.py | 29 ++++++++++++++--------------- aria/cli/core/aria.py | 4 ++-- aria/cli/inputs.py | 2 +- aria/cli/utils.py | 18 ++++++++++++------ aria/core.py | 19 ++++--------------- aria/modeling/exceptions.py | 19 +++++++++++++------ aria/modeling/service_template.py | 3 ++- aria/orchestrator/workflow_runner.py | 14 +++++++------- tox.ini | 2 +- 12 files changed, 63 insertions(+), 75 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c1f8eb6a/aria/cli/commands/node_templates.py ---------------------------------------------------------------------- diff --git a/aria/cli/commands/node_templates.py b/aria/cli/commands/node_templates.py index b63b630..c79e125 100644 --- a/aria/cli/commands/node_templates.py +++ b/aria/cli/commands/node_templates.py @@ -41,10 +41,7 @@ def show(node_template_id, model_storage, logger): `NODE_TEMPLATE_ID` is the node id to get information on. """ - # logger.info('Showing node template {0} for service template {1}'.format( - # node_template_id, service_template_name)) logger.info('Showing node template {0}'.format(node_template_id)) - #TODO get node template of a specific service template instead? node_template = model_storage.node_template.get(node_template_id) print_data(NODE_TEMPLATE_COLUMNS, node_template.to_dict(), 'Node template:', max_width=50) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c1f8eb6a/aria/cli/commands/plugins.py ---------------------------------------------------------------------- diff --git a/aria/cli/commands/plugins.py b/aria/cli/commands/plugins.py index 680284f..41a272e 100644 --- a/aria/cli/commands/plugins.py +++ b/aria/cli/commands/plugins.py @@ -15,10 +15,10 @@ import zipfile +from .. import utils from ..core import aria from ..exceptions import AriaCliError from ..table import print_data -from ..utils import storage_sort_param PLUGIN_COLUMNS = ['id', 'package_name', 'package_version', 'supported_platform', @@ -129,5 +129,5 @@ def list(sort_by, descending, model_storage, logger): """ logger.info('Listing all plugins...') plugins_list = [p.to_dict() for p in model_storage.plugin.list( - sort=storage_sort_param(sort_by, descending))] + sort=utils.storage_sort_param(sort_by, descending))] print_data(PLUGIN_COLUMNS, plugins_list, 'Plugins:') http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c1f8eb6a/aria/cli/commands/service_templates.py ---------------------------------------------------------------------- diff --git a/aria/cli/commands/service_templates.py b/aria/cli/commands/service_templates.py index 93dc188..2ef37c0 100644 --- a/aria/cli/commands/service_templates.py +++ b/aria/cli/commands/service_templates.py @@ -16,15 +16,12 @@ import os -from .. import utils from .. import csar from .. import service_template_utils +from .. import utils from ..core import aria from ..table import print_data -from ..exceptions import AriaCliError -from ..utils import handle_storage_exception from ...core import Core -from ...exceptions import AriaException from ...storage import exceptions as storage_exceptions @@ -124,7 +121,8 @@ def store(service_template_path, service_template_name, service_template_filenam os.path.dirname(service_template_path), service_template_name) except storage_exceptions.StorageError as e: - handle_storage_exception(e, 'service template', service_template_name) + utils.check_overriding_storage_exceptions(e, 'service template', service_template_name) + raise logger.info('Service template {0} stored'.format(service_template_name)) @@ -143,10 +141,7 @@ def delete(service_template_name, model_storage, resource_storage, plugin_manage logger.info('Deleting service template {0}...'.format(service_template_name)) service_template = model_storage.service_template.get_by_name(service_template_name) core = Core(model_storage, resource_storage, plugin_manager) - try: - core.delete_service_template(service_template.id) - except storage_exceptions.NotFoundError: - raise AriaCliError() + core.delete_service_template(service_template.id) logger.info('Service template {0} deleted'.format(service_template_name)) @@ -183,13 +178,7 @@ def validate(service_template, service_template_filename, logger.info('Validating service template: {0}'.format(service_template)) service_template_path = service_template_utils.get(service_template, service_template_filename) core = Core(model_storage, resource_storage, plugin_manager) - - try: - core.validate_service_template(service_template_path) - except AriaException as e: - # TODO: gather errors from parser and dump them via CLI? - raise AriaCliError(str(e)) - + core.validate_service_template(service_template_path) logger.info('Service template validated successfully') http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c1f8eb6a/aria/cli/commands/services.py ---------------------------------------------------------------------- diff --git a/aria/cli/commands/services.py b/aria/cli/commands/services.py index 4728509..afa5e42 100644 --- a/aria/cli/commands/services.py +++ b/aria/cli/commands/services.py @@ -19,12 +19,11 @@ from StringIO import StringIO from . import service_templates from .. import helptexts +from .. import utils from ..core import aria -from ..exceptions import AriaCliError from ..table import print_data -from ..utils import storage_sort_param, handle_storage_exception from ...core import Core -from ...exceptions import AriaException +from ...modeling import exceptions as modeling_exceptions from ...storage import exceptions as storage_exceptions @@ -66,7 +65,7 @@ def list(service_template_name, filters = {} services_list = [d.to_dict() for d in model_storage.service.list( - sort=storage_sort_param(sort_by=sort_by, descending=descending), + sort=utils.storage_sort_param(sort_by=sort_by, descending=descending), filters=filters)] print_data(SERVICE_COLUMNS, services_list, 'Services:') @@ -95,18 +94,18 @@ def create(service_template_name, """ logger.info('Creating new service from service template {0}...'.format( service_template_name)) + core = Core(model_storage, resource_storage, plugin_manager) + service_template = model_storage.service_template.get_by_name(service_template_name) try: - core = Core(model_storage, resource_storage, plugin_manager) - service_template = model_storage.service_template.get_by_name(service_template_name) service = core.create_service(service_template.id, inputs, service_name) except storage_exceptions.StorageError as e: - handle_storage_exception(e, 'service', service_name) - except AriaException as e: - logger.info(str(e)) + utils.check_overriding_storage_exceptions(e, 'service', service_name) + raise + except modeling_exceptions.InputsException: service_templates.print_service_template_inputs(model_storage, service_template_name, logger) - raise AriaCliError(str(e)) + raise logger.info("Service created. The service's name is {0}".format(service.name)) @@ -171,11 +170,11 @@ def inputs(service_name, model_storage, logger): logger.info('Showing inputs for service {0}...'.format(service_name)) service = model_storage.service.get_by_name(service_name) if service.inputs: - inputs_ = StringIO() - for input_name, input in service.inputs.iteritems(): - inputs_.write(' - "{0}":{1}'.format(input_name, os.linesep)) - inputs_.write(' Value: {0}{1}'.format(input.value, os.linesep)) - logger.info(inputs_.getvalue()) + inputs_string = StringIO() + for input_name, input_ in service.inputs.iteritems(): + inputs_string.write(' - "{0}":{1}'.format(input_name, os.linesep)) + inputs_string.write(' Value: {0}{1}'.format(input_.value, os.linesep)) + logger.info(inputs_string.getvalue()) else: logger.info('\tNo inputs') logger.info('') http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c1f8eb6a/aria/cli/core/aria.py ---------------------------------------------------------------------- diff --git a/aria/cli/core/aria.py b/aria/cli/core/aria.py index cd1036e..fb5a81b 100644 --- a/aria/cli/core/aria.py +++ b/aria/cli/core/aria.py @@ -354,7 +354,7 @@ class Options(object): help=help) @staticmethod - def task_max_attempts(default=1): + def task_max_attempts(default=30): return click.option( '--task-max-attempts', type=int, @@ -370,7 +370,7 @@ class Options(object): help=helptexts.SORT_BY) @staticmethod - def task_retry_interval(default=1): + def task_retry_interval(default=30): return click.option( '--task-retry-interval', type=int, http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c1f8eb6a/aria/cli/inputs.py ---------------------------------------------------------------------- diff --git a/aria/cli/inputs.py b/aria/cli/inputs.py index 78db846..0ff48dc 100644 --- a/aria/cli/inputs.py +++ b/aria/cli/inputs.py @@ -18,7 +18,7 @@ import glob import yaml from .env import logger -from.exceptions import AriaCliError +from .exceptions import AriaCliError def inputs_to_dict(resources): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c1f8eb6a/aria/cli/utils.py ---------------------------------------------------------------------- diff --git a/aria/cli/utils.py b/aria/cli/utils.py index fad1b07..3cc68c9 100644 --- a/aria/cli/utils.py +++ b/aria/cli/utils.py @@ -152,10 +152,16 @@ def generate_progress_handler(file_path, action='', max_bar_length=80): return print_progress -def handle_storage_exception(e, model_class, name): +def check_overriding_storage_exceptions(e, model_class, name): + """ + This method checks whether the storage exception is a known type where we'd like to override + the exception message; If so, it raises a new error. Otherwise it simply returns. + """ + assert isinstance(e, BaseException) if 'UNIQUE constraint failed' in e.message: - msg = 'Could not store {model_class} `{name}`{linesep}' \ - 'There already a exists a {model_class} with the same name' \ - .format(model_class=model_class, name=name, linesep=os.linesep) - raise AriaCliError(msg) - raise AriaCliError() + new_message = \ + 'Could not store {model_class} `{name}`{linesep}' \ + 'There already a exists a {model_class} with the same name' \ + .format(model_class=model_class, name=name, linesep=os.linesep) + trace = sys.exc_info()[2] + raise type(e), type(e)(new_message), trace # pylint: disable=raising-non-exception http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c1f8eb6a/aria/core.py ---------------------------------------------------------------------- diff --git a/aria/core.py b/aria/core.py index f5e2025..af1984a 100644 --- a/aria/core.py +++ b/aria/core.py @@ -16,7 +16,6 @@ from . import exceptions from .parser import consumption from .parser.loading.location import UriLocation -from .storage import exceptions as storage_exceptions class Core(object): @@ -69,14 +68,12 @@ class Core(object): # creating an empty ConsumptionContext, initiating a threadlocal context context = consumption.ConsumptionContext() + storage_session = self.model_storage._all_api_kwargs['session'] # setting no autoflush for the duration of instantiation - this helps avoid dependency # constraints as they're being set up - with self.model_storage._all_api_kwargs['session'].no_autoflush: + with storage_session.no_autoflush: service = service_template.instantiate(None, self.model_storage, inputs=inputs) - self.model_storage._all_api_kwargs['session'].flush() - - with self.model_storage._all_api_kwargs['session'].no_autoflush: consumption.ConsumerChain( context, ( @@ -88,17 +85,9 @@ class Core(object): if context.validation.dump_issues(): raise exceptions.InstantiationError('Failed to instantiate service template') - # If the user didn't enter a name for this service, we'll want to auto generate it. - # But how will we ensure a unique but simple name? We'll append the services' unique id - # to the service_templates name. Since this service is not in the storage yet, we'll put it - # there, and pull out its id. - self.model_storage.service.put(service) + storage_session.flush() # flushing so service.id would auto-populate service.name = service_name or '{0}_{1}'.format(service_template.name, service.id) - try: - self.model_storage.service.update(service) - except storage_exceptions.StorageError: - self.model_storage.service.delete(service) - raise + self.model_storage.service.put(service) return service def delete_service(self, service_id, force=False): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c1f8eb6a/aria/modeling/exceptions.py ---------------------------------------------------------------------- diff --git a/aria/modeling/exceptions.py b/aria/modeling/exceptions.py index 8225f37..19fd942 100644 --- a/aria/modeling/exceptions.py +++ b/aria/modeling/exceptions.py @@ -22,6 +22,13 @@ class ModelingException(AriaException): """ +class InputsException(ModelingException): + """ + ARIA inputs exception. + """ + pass + + class ValueFormatException(ModelingException): """ ARIA modeling exception: the value is in the wrong format. @@ -34,19 +41,19 @@ class CannotEvaluateFunctionException(ModelingException): """ -class MissingRequiredInputsException(ModelingException): +class MissingRequiredInputsException(InputsException): """ - ARIA modeling exception: Required inputs have been omitted + ARIA modeling exception: Required inputs have been omitted. """ -class InputsOfWrongTypeException(ModelingException): +class InputsOfWrongTypeException(InputsException): """ - ARIA modeling exception: Inputs of the wrong types have been provided + ARIA modeling exception: Inputs of the wrong types have been provided. """ -class UndeclaredInputsException(ModelingException): +class UndeclaredInputsException(InputsException): """ - ARIA modeling exception: Undeclared inputs have been provided + ARIA modeling exception: Undeclared inputs have been provided. """ http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c1f8eb6a/aria/modeling/service_template.py ---------------------------------------------------------------------- diff --git a/aria/modeling/service_template.py b/aria/modeling/service_template.py index 9a07b53..f1c2bcb 100644 --- a/aria/modeling/service_template.py +++ b/aria/modeling/service_template.py @@ -1237,7 +1237,8 @@ class RequirementTemplateBase(TemplateModelMixin): # Find first node that matches the type elif self.target_node_type is not None: - for target_node_template in context.modeling.template.node_templates.itervalues(): + for target_node_template in \ + self.node_template.service_template.node_templates.values(): if self.target_node_type.get_descendant(target_node_template.type.name) is None: continue http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c1f8eb6a/aria/orchestrator/workflow_runner.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/workflow_runner.py b/aria/orchestrator/workflow_runner.py index 7b043c5..0051e8e 100644 --- a/aria/orchestrator/workflow_runner.py +++ b/aria/orchestrator/workflow_runner.py @@ -23,7 +23,7 @@ from datetime import datetime from . import exceptions from .context.workflow import WorkflowContext -from .workflows.builtin import BUILTIN_WORKFLOWS, BUILTIN_WORKFLOWS_PATH_PREFIX +from .workflows import builtin from .workflows.core.engine import Engine from .workflows.executor.process import ProcessExecutor from ..modeling import models @@ -31,8 +31,8 @@ from ..modeling import utils as modeling_utils from ..utils.imports import import_fullname -DEFAULT_TASK_MAX_ATTEMPTS = 1 -DEFAULT_TASK_RETRY_INTERVAL = 1 +DEFAULT_TASK_MAX_ATTEMPTS = 30 +DEFAULT_TASK_RETRY_INTERVAL = 30 class WorkflowRunner(object): @@ -110,7 +110,7 @@ class WorkflowRunner(object): workflow_name=self._workflow_name, inputs={}) - if self._workflow_name in BUILTIN_WORKFLOWS: + if self._workflow_name in builtin.BUILTIN_WORKFLOWS: workflow_inputs = dict() # built-in workflows don't have any inputs else: workflow_inputs = self.service.workflows[self._workflow_name].inputs @@ -123,7 +123,7 @@ class WorkflowRunner(object): def _validate_workflow_exists_for_service(self): if self._workflow_name not in self.service.workflows and \ - self._workflow_name not in BUILTIN_WORKFLOWS: + self._workflow_name not in builtin.BUILTIN_WORKFLOWS: raise exceptions.UndeclaredWorkflowError( 'No workflow policy {0} declared in service {1}' .format(self._workflow_name, self.service.name)) @@ -137,8 +137,8 @@ class WorkflowRunner(object): .format(self.service.name, active_executions[0].id)) def _get_workflow_fn(self): - if self._workflow_name in BUILTIN_WORKFLOWS: - return import_fullname('{0}.{1}'.format(BUILTIN_WORKFLOWS_PATH_PREFIX, + if self._workflow_name in builtin.BUILTIN_WORKFLOWS: + return import_fullname('{0}.{1}'.format(builtin.BUILTIN_WORKFLOWS_PATH_PREFIX, self._workflow_name)) workflow = self.service.workflows[self._workflow_name] http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c1f8eb6a/tox.ini ---------------------------------------------------------------------- diff --git a/tox.ini b/tox.ini index fa4bd5c..6ad048f 100644 --- a/tox.ini +++ b/tox.ini @@ -41,7 +41,7 @@ commands=pytest tests --cov-report term-missing --cov aria commands=pytest tests --cov-report term-missing --cov aria [testenv:pylint_code] -commands=pylint --rcfile=aria/.pylintrc --disable=fixme,missing-docstring --ignore=commands.py aria +commands=pylint --rcfile=aria/.pylintrc --disable=fixme,missing-docstring aria [testenv:pylint_tests] commands=pylint --rcfile=tests/.pylintrc --disable=fixme,missing-docstring tests