ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxm...@apache.org
Subject [19/32] incubator-ariatosca git commit: fixed storage exceptions in CLI
Date Thu, 06 Apr 2017 08:54:28 GMT
fixed storage exceptions in CLI


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

Branch: refs/heads/logger_task
Commit: a9d1ae3bf6b47edcee9230847f9964c09b99971d
Parents: 735e01b
Author: Ran Ziv <ran@gigaspaces.com>
Authored: Mon Apr 3 14:58:17 2017 +0300
Committer: Ran Ziv <ran@gigaspaces.com>
Committed: Thu Apr 6 11:29:17 2017 +0300

----------------------------------------------------------------------
 aria/cli/commands/executions.py     | 14 +++++---------
 aria/cli/commands/logs.py           | 16 +++++++++++++---
 aria/cli/commands/node_templates.py |  6 +++---
 aria/cli/commands/nodes.py          |  6 +++---
 aria/cli/commands/services.py       | 23 ++++++++++++++---------
 aria/storage/exceptions.py          |  4 ++++
 aria/storage/sql_mapi.py            |  8 ++++----
 7 files changed, 46 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a9d1ae3b/aria/cli/commands/executions.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/executions.py b/aria/cli/commands/executions.py
index d767fa1..fd47eb3 100644
--- a/aria/cli/commands/executions.py
+++ b/aria/cli/commands/executions.py
@@ -13,15 +13,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import json
-import time
-
 from .. import utils
 from ..table import print_data
-from ..cli import aria, helptexts
+from ..cli import aria
 from ..exceptions import AriaCliError
 from ...modeling.models import Execution
-from ...storage.exceptions import StorageError
+from ...storage import exceptions as storage_exceptions
 from ...orchestrator.workflow_runner import WorkflowRunner
 from ...utils import formatting
 from ...utils import threading
@@ -52,7 +49,7 @@ def show(execution_id, model_storage, logger):
     try:
         logger.info('Showing execution {0}'.format(execution_id))
         execution = model_storage.execution.get(execution_id)
-    except StorageError:
+    except storage_exceptions.NotFoundError:
         raise AriaCliError('Execution {0} not found'.format(execution_id))
 
     print_data(EXECUTION_COLUMNS, execution.to_dict(), 'Execution:', max_width=50)
@@ -94,9 +91,8 @@ def list(service_name,
         try:
             service = model_storage.service.get_by_name(service_name)
             filters = dict(service=service)
-        except StorageError:
-            raise AriaCliError('Service {0} does not exist'.format(
-                service_name))
+        except storage_exceptions.NotFoundError:
+            raise AriaCliError('Service {0} does not exist'.format(service_name))
     else:
         logger.info('Listing all executions...')
         filters = {}

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a9d1ae3b/aria/cli/commands/logs.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/logs.py b/aria/cli/commands/logs.py
index 3662063..6890fb4 100644
--- a/aria/cli/commands/logs.py
+++ b/aria/cli/commands/logs.py
@@ -15,6 +15,8 @@
 
 from .. import utils
 from ..cli import aria
+from ..exceptions import AriaCliError
+from ...storage import exceptions as storage_exceptions
 
 
 @aria.group(name='logs')
@@ -40,8 +42,12 @@ def list(execution_id,
     """
     logger.info('Listing logs for execution id {0}'.format(execution_id))
     # events_logger = get_events_logger(json_output)
-    logs = model_storage.log.list(filters=dict(execution_fk=execution_id),
-                                  sort=utils.storage_sort_param('created_at', False))
+    try:
+        logs = model_storage.log.list(filters=dict(execution_fk=execution_id),
+                                      sort=utils.storage_sort_param('created_at', False))
+    except storage_exceptions.NotFoundError:
+        raise AriaCliError('Execution {0} does not exist'.format(execution_id))
+
     # TODO: print logs nicely
     if logs:
         for log in logs:
@@ -62,7 +68,11 @@ def delete(execution_id, model_storage, logger):
     `EXECUTION_ID` is the execution logs to delete.
     """
     logger.info('Deleting logs for execution id {0}'.format(execution_id))
-    logs = model_storage.log.list(filters=dict(execution_fk=execution_id))
+    try:
+        logs = model_storage.log.list(filters=dict(execution_fk=execution_id))
+    except storage_exceptions.NotFoundError:
+        raise AriaCliError('Execution {0} does not exist'.format(execution_id))
+
     for log in logs:
         model_storage.log.delete(log)
     logger.info('Deleted logs for execution id {0}'.format(execution_id))

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a9d1ae3b/aria/cli/commands/node_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/node_templates.py b/aria/cli/commands/node_templates.py
index 7365f0c..0910ded 100644
--- a/aria/cli/commands/node_templates.py
+++ b/aria/cli/commands/node_templates.py
@@ -17,7 +17,7 @@ from ..table import print_data
 from .. import utils
 from ..cli import aria
 from ..exceptions import AriaCliError
-from ...storage.exceptions import StorageError
+from ...storage import exceptions as storage_exceptions
 
 
 NODE_TEMPLATE_COLUMNS = ['id', 'name', 'description', 'service_template_name', 'type_name']
@@ -49,7 +49,7 @@ def show(node_template_id, model_storage, logger):
     try:
         #TODO get node template of a specific service template instead?
         node_template = model_storage.node_template.get(node_template_id)
-    except StorageError:
+    except storage_exceptions.NotFoundError:
         raise AriaCliError('Node template {0} was not found'.format(node_template_id))
 
     print_data(NODE_TEMPLATE_COLUMNS, node_template.to_dict(), 'Node template:', max_width=50)
@@ -91,7 +91,7 @@ def list(service_template_name, sort_by, descending, model_storage, logger):
         try:
             service_template = model_storage.service_template.get_by_name(service_template_name)
             filters = dict(service_template=service_template)
-        except StorageError:
+        except storage_exceptions.NotFoundException:
             raise AriaCliError('Service template {0} does not exist'.format(service_template_name))
     else:
         logger.info('Listing all node templates...')

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a9d1ae3b/aria/cli/commands/nodes.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/nodes.py b/aria/cli/commands/nodes.py
index f38c917..8600ff2 100644
--- a/aria/cli/commands/nodes.py
+++ b/aria/cli/commands/nodes.py
@@ -17,7 +17,7 @@ from .. import utils
 from ..cli import aria
 from ..table import print_data
 from ..exceptions import AriaCliError
-from ...storage.exceptions import StorageError
+from ...storage import exceptions as storage_exceptions
 
 
 NODE_COLUMNS = ['id', 'name', 'service_name', 'node_template_name', 'state']
@@ -45,7 +45,7 @@ def show(node_id, model_storage, logger):
     logger.info('Showing node {0}'.format(node_id))
     try:
         node = model_storage.node.get(node_id)
-    except StorageError:
+    except storage_exceptions.NotFoundError:
         raise AriaCliError('Node {0} not found'.format(node_id))
 
     print_data(NODE_COLUMNS, node.to_dict(), 'Node:', 50)
@@ -83,7 +83,7 @@ def list(service_name,
         try:
             service = model_storage.service.get_by_name(service_name)
             filters = dict(service=service)
-        except StorageError:
+        except storage_exceptions.NotFoundError:
             raise AriaCliError('Service {0} does not exist'.format(service_name))
     else:
         logger.info('Listing all nodes...')

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a9d1ae3b/aria/cli/commands/services.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/services.py b/aria/cli/commands/services.py
index ae04d7e..00b093c 100644
--- a/aria/cli/commands/services.py
+++ b/aria/cli/commands/services.py
@@ -25,7 +25,7 @@ from ..table import print_data
 from ..utils import storage_sort_param
 from ...core import Core
 from ...exceptions import AriaException
-from ...storage.exceptions import StorageError
+from ...storage import exceptions as storage_exceptions
 
 
 SERVICE_COLUMNS = ['id', 'name', 'service_template_name', 'created_at', 'updated_at']
@@ -40,27 +40,30 @@ def services():
 
 
 @services.command(name='list', short_help='List services')
-@aria.options.service_template_id()
+@aria.options.service_template_name()
 @aria.options.sort_by()
 @aria.options.descending
 @aria.options.verbose()
 @aria.pass_model_storage
 @aria.pass_logger
-def list(service_template_id,
+def list(service_template_name,
          sort_by,
          descending,
          model_storage,
          logger):
     """List services
 
-    If `--service-template-id` is provided, list services for that service template.
+    If `--service-template-name` is provided, list services for that service template.
     Otherwise, list services for all service templates.
     """
-    if service_template_id:
+    if service_template_name:
         logger.info('Listing services for service template {0}...'.format(
-            service_template_id))
-        service_template = model_storage.service_template.get(service_template_id)
-        filters = dict(service_template=service_template)
+            service_template_name))
+        try:
+            service_template = model_storage.service_template.get(service_template_name)
+            filters = dict(service_template=service_template)
+        except storage_exceptions.NotFoundError:
+            raise AriaCliError('Service template {0} does not exist'.format(service_template_name))
     else:
         logger.info('Listing all service...')
         filters = {}
@@ -99,7 +102,9 @@ def create(service_template_name,
     try:
         core = Core(model_storage, resource_storage, plugin_manager)
         service = core.create_service(service_template_name, inputs, service_name)
-    except StorageError:
+    except storage_exceptions.NotFoundError:
+        raise AriaCliError('Service template {0} does not exist'.format(service_template_name))
+    except storage_exceptions.StorageError:
         logger.info(TWO_MODELS_WITH_THE_SAME_NAME_ERROR_TEMPLATE.format(
             model_class='service',
             name=service_name))

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a9d1ae3b/aria/storage/exceptions.py
----------------------------------------------------------------------
diff --git a/aria/storage/exceptions.py b/aria/storage/exceptions.py
index f982f63..3f0ecec 100644
--- a/aria/storage/exceptions.py
+++ b/aria/storage/exceptions.py
@@ -23,3 +23,7 @@ class StorageError(exceptions.AriaError):
     General storage exception
     """
     pass
+
+
+class NotFoundError(StorageError):
+    pass

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a9d1ae3b/aria/storage/sql_mapi.py
----------------------------------------------------------------------
diff --git a/aria/storage/sql_mapi.py b/aria/storage/sql_mapi.py
index 8d34bb4..144c925 100644
--- a/aria/storage/sql_mapi.py
+++ b/aria/storage/sql_mapi.py
@@ -59,7 +59,7 @@ class SQLAlchemyModelAPI(api.ModelAPI):
         result = query.first()
 
         if not result:
-            raise exceptions.StorageError(
+            raise exceptions.NotFoundError(
                 'Requested `{0}` with ID `{1}` was not found'
                 .format(self.model_cls.__name__, entry_id)
             )
@@ -69,13 +69,13 @@ class SQLAlchemyModelAPI(api.ModelAPI):
         assert hasattr(self.model_cls, 'name')
         result = self.list(include=include, filters={'name': entry_name})
         if not result:
-            raise exceptions.StorageError(
-                'Requested {0} with NAME `{1}` was not found'
+            raise exceptions.NotFoundError(
+                'Requested {0} with name `{1}` was not found'
                 .format(self.model_cls.__name__, entry_name)
             )
         elif len(result) > 1:
             raise exceptions.StorageError(
-                'Requested {0} with NAME `{1}` returned more than 1 value'
+                'Requested {0} with name `{1}` returned more than 1 value'
                 .format(self.model_cls.__name__, entry_name)
             )
         else:


Mime
View raw message