You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by ra...@apache.org on 2017/04/04 10:22:15 UTC

[21/24] incubator-ariatosca git commit: core.py now works with ids only again; removed unnecessary NotFoundError exception clauses from cli

core.py now works with ids only again; removed unnecessary NotFoundError exception clauses from 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/38d58d4d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/38d58d4d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/38d58d4d

Branch: refs/heads/ARIA-48-aria-cli
Commit: 38d58d4d28cd7be21c152de767ccc567622fb263
Parents: 141dbb0
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Mon Apr 3 15:10:51 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Tue Apr 4 13:20:46 2017 +0300

----------------------------------------------------------------------
 aria/cli/commands/executions.py        | 16 ++++------------
 aria/cli/commands/logs.py              | 16 +++-------------
 aria/cli/commands/node_templates.py    | 16 ++++------------
 aria/cli/commands/nodes.py             | 14 +++-----------
 aria/cli/commands/service_templates.py |  9 ++++++---
 aria/cli/commands/services.py          |  9 ++-------
 aria/cli/commands/workflows.py         | 21 ++++++++-------------
 aria/core.py                           | 16 +++++++---------
 8 files changed, 37 insertions(+), 80 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/38d58d4d/aria/cli/commands/executions.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/executions.py b/aria/cli/commands/executions.py
index fd47eb3..6d8b949 100644
--- a/aria/cli/commands/executions.py
+++ b/aria/cli/commands/executions.py
@@ -16,9 +16,7 @@
 from .. import utils
 from ..table import print_data
 from ..cli import aria
-from ..exceptions import AriaCliError
 from ...modeling.models import Execution
-from ...storage import exceptions as storage_exceptions
 from ...orchestrator.workflow_runner import WorkflowRunner
 from ...utils import formatting
 from ...utils import threading
@@ -46,11 +44,8 @@ def show(execution_id, model_storage, logger):
 
     `EXECUTION_ID` is the execution to get information on.
     """
-    try:
-        logger.info('Showing execution {0}'.format(execution_id))
-        execution = model_storage.execution.get(execution_id)
-    except storage_exceptions.NotFoundError:
-        raise AriaCliError('Execution {0} not found'.format(execution_id))
+    logger.info('Showing execution {0}'.format(execution_id))
+    execution = model_storage.execution.get(execution_id)
 
     print_data(EXECUTION_COLUMNS, execution.to_dict(), 'Execution:', max_width=50)
 
@@ -88,11 +83,8 @@ def list(service_name,
     if service_name:
         logger.info('Listing executions for service {0}...'.format(
             service_name))
-        try:
-            service = model_storage.service.get_by_name(service_name)
-            filters = dict(service=service)
-        except storage_exceptions.NotFoundError:
-            raise AriaCliError('Service {0} does not exist'.format(service_name))
+        service = model_storage.service.get_by_name(service_name)
+        filters = dict(service=service)
     else:
         logger.info('Listing all executions...')
         filters = {}

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/38d58d4d/aria/cli/commands/logs.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/logs.py b/aria/cli/commands/logs.py
index 6890fb4..3662063 100644
--- a/aria/cli/commands/logs.py
+++ b/aria/cli/commands/logs.py
@@ -15,8 +15,6 @@
 
 from .. import utils
 from ..cli import aria
-from ..exceptions import AriaCliError
-from ...storage import exceptions as storage_exceptions
 
 
 @aria.group(name='logs')
@@ -42,12 +40,8 @@ def list(execution_id,
     """
     logger.info('Listing logs for execution id {0}'.format(execution_id))
     # events_logger = get_events_logger(json_output)
-    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))
-
+    logs = model_storage.log.list(filters=dict(execution_fk=execution_id),
+                                  sort=utils.storage_sort_param('created_at', False))
     # TODO: print logs nicely
     if logs:
         for log in logs:
@@ -68,11 +62,7 @@ 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))
-    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))
-
+    logs = model_storage.log.list(filters=dict(execution_fk=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/38d58d4d/aria/cli/commands/node_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/node_templates.py b/aria/cli/commands/node_templates.py
index 0910ded..b97d4a2 100644
--- a/aria/cli/commands/node_templates.py
+++ b/aria/cli/commands/node_templates.py
@@ -16,8 +16,6 @@
 from ..table import print_data
 from .. import utils
 from ..cli import aria
-from ..exceptions import AriaCliError
-from ...storage import exceptions as storage_exceptions
 
 
 NODE_TEMPLATE_COLUMNS = ['id', 'name', 'description', 'service_template_name', 'type_name']
@@ -46,11 +44,8 @@ def show(node_template_id, model_storage, logger):
     # 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))
-    try:
-        #TODO get node template of a specific service template instead?
-        node_template = model_storage.node_template.get(node_template_id)
-    except storage_exceptions.NotFoundError:
-        raise AriaCliError('Node template {0} was not found'.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)
 
@@ -88,11 +83,8 @@ def list(service_template_name, sort_by, descending, model_storage, logger):
     if service_template_name:
         logger.info('Listing node templates for service template {0}...'.format(
             service_template_name))
-        try:
-            service_template = model_storage.service_template.get_by_name(service_template_name)
-            filters = dict(service_template=service_template)
-        except storage_exceptions.NotFoundException:
-            raise AriaCliError('Service template {0} does not exist'.format(service_template_name))
+        service_template = model_storage.service_template.get_by_name(service_template_name)
+        filters = dict(service_template=service_template)
     else:
         logger.info('Listing all node templates...')
         filters = {}

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/38d58d4d/aria/cli/commands/nodes.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/nodes.py b/aria/cli/commands/nodes.py
index 8600ff2..0c9c4e5 100644
--- a/aria/cli/commands/nodes.py
+++ b/aria/cli/commands/nodes.py
@@ -16,8 +16,6 @@
 from .. import utils
 from ..cli import aria
 from ..table import print_data
-from ..exceptions import AriaCliError
-from ...storage import exceptions as storage_exceptions
 
 
 NODE_COLUMNS = ['id', 'name', 'service_name', 'node_template_name', 'state']
@@ -43,10 +41,7 @@ def show(node_id, model_storage, logger):
     `NODE_ID` is the id of the node to get information on.
     """
     logger.info('Showing node {0}'.format(node_id))
-    try:
-        node = model_storage.node.get(node_id)
-    except storage_exceptions.NotFoundError:
-        raise AriaCliError('Node {0} not found'.format(node_id))
+    node = model_storage.node.get(node_id)
 
     print_data(NODE_COLUMNS, node.to_dict(), 'Node:', 50)
 
@@ -80,11 +75,8 @@ def list(service_name,
     """
     if service_name:
         logger.info('Listing nodes for service {0}...'.format(service_name))
-        try:
-            service = model_storage.service.get_by_name(service_name)
-            filters = dict(service=service)
-        except storage_exceptions.NotFoundError:
-            raise AriaCliError('Service {0} does not exist'.format(service_name))
+        service = model_storage.service.get_by_name(service_name)
+        filters = dict(service=service)
     else:
         logger.info('Listing all nodes...')
         filters = {}

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/38d58d4d/aria/cli/commands/service_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/service_templates.py b/aria/cli/commands/service_templates.py
index af6252a..79f8012 100644
--- a/aria/cli/commands/service_templates.py
+++ b/aria/cli/commands/service_templates.py
@@ -26,7 +26,7 @@ from ..table import print_data
 from ..exceptions import AriaCliError
 from ...core import Core
 from ...exceptions import AriaException
-from ...storage.exceptions import StorageError
+from ...storage import exceptions as storage_exceptions
 
 
 DESCRIPTION_LIMIT = 20
@@ -119,7 +119,7 @@ def store(service_template_path, service_template_name, model_storage, resource_
         core.create_service_template(service_template_path,
                                      os.path.dirname(service_template_path),
                                      service_template_name)
-    except StorageError:
+    except storage_exceptions.StorageError:
         logger.info(TWO_MODELS_WITH_THE_SAME_NAME_ERROR_TEMPLATE.format(
             model_class='service template',
             name=service_template_name))
@@ -143,7 +143,10 @@ def delete(service_template_id, model_storage, resource_storage, plugin_manager,
     """
     logger.info('Deleting service template {0}...'.format(service_template_id))
     core = Core(model_storage, resource_storage, plugin_manager)
-    core.delete_service_template(service_template_id)
+    try:
+        core.delete_service_template(service_template_id)
+    except storage_exceptions.NotFoundError:
+        raise AriaCliError()
     logger.info('Service template {0} deleted'.format(service_template_id))
 
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/38d58d4d/aria/cli/commands/services.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/services.py b/aria/cli/commands/services.py
index 00b093c..28fb499 100644
--- a/aria/cli/commands/services.py
+++ b/aria/cli/commands/services.py
@@ -59,11 +59,8 @@ def list(service_template_name,
     if service_template_name:
         logger.info('Listing services for service template {0}...'.format(
             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))
+        service_template = model_storage.service_template.get(service_template_name)
+        filters = dict(service_template=service_template)
     else:
         logger.info('Listing all service...')
         filters = {}
@@ -102,8 +99,6 @@ 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 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',

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/38d58d4d/aria/cli/commands/workflows.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/workflows.py b/aria/cli/commands/workflows.py
index 2180168..efa373e 100644
--- a/aria/cli/commands/workflows.py
+++ b/aria/cli/commands/workflows.py
@@ -14,10 +14,8 @@
 # limitations under the License.
 
 from ..table import print_data
-from .. import utils
 from ..cli import aria
 from ..exceptions import AriaCliError
-from ...storage.exceptions import StorageError
 
 WORKFLOW_COLUMNS = ['name', 'service_template_name', 'service_name']
 
@@ -41,17 +39,14 @@ def show(workflow_name, service_name, model_storage, logger):
 
     `WORKFLOW_NAME` is the name of the workflow to get information on.
     """
-    try:
-        logger.info('Retrieving workflow {0} for service {1}'.format(
-            workflow_name, service_name))
-        service = model_storage.service.get(service_name)
-        workflow = next((wf for wf in service.workflows if
-                         wf.name == workflow_name), None)
-        if not workflow:
-            raise AriaCliError(
-                'Workflow {0} not found for service {1}'.format(workflow_name, service_name))
-    except StorageError:
-        raise AriaCliError('service {0} not found'.format(service_name))
+    logger.info('Retrieving workflow {0} for service {1}'.format(
+        workflow_name, service_name))
+    service = model_storage.service.get(service_name)
+    workflow = next((wf for wf in service.workflows if
+                     wf.name == workflow_name), None)
+    if not workflow:
+        raise AriaCliError(
+            'Workflow {0} not found for service {1}'.format(workflow_name, service_name))
 
     defaults = {
         'service_template_name': service.service_template_name,

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/38d58d4d/aria/core.py
----------------------------------------------------------------------
diff --git a/aria/core.py b/aria/core.py
index 6be6fd1..a589a8e 100644
--- a/aria/core.py
+++ b/aria/core.py
@@ -14,8 +14,6 @@
 # limitations under the License.
 
 from . import exceptions
-from .modeling import models
-from .modeling import utils as modeling_utils
 from .parser.consumption import (
     ConsumptionContext,
     ConsumerChain,
@@ -68,33 +66,33 @@ class Core(object):
         self.model_storage.service_template.delete(service_template)
         self.resource_storage.service_template.delete(entry_id=str(service_template.id))
 
-    def create_service(self, service_template_name, inputs, service_name=None):
-        service_template = self.model_storage.service_template.get_by_name(service_template_name)
+    def create_service(self, service_template_id, inputs, service_name=None):
+        service_template = self.model_storage.service_template.get(service_template_id)
 
         # creating an empty ConsumptionContext, initiating a threadlocal context
         ConsumptionContext()
         with self.model_storage._all_api_kwargs['session'].no_autoflush:
             service = service_template.instantiate(None, inputs)
 
-        service.name = service_name or '{0}_{1}'.format(service_template_name, service.id)
+        service.name = service_name or '{0}_{1}'.format(service_template.name, service.id)
         self.model_storage.service.put(service)
         return service
 
-    def delete_service(self, service_name, force=False):
-        service = self.model_storage.service.get_by_name(service_name)
+    def delete_service(self, service_id, force=False):
+        service = self.model_storage.service.get(service_id)
 
         active_executions = [e for e in service.executions if e.is_active()]
         if active_executions:
             raise exceptions.DependentActiveExecutionsError(
                 "Can't delete service {0} - there is an active execution for this service. "
-                "Active execution id: {1}".format(service_name, active_executions[0].id))
+                "Active execution id: {1}".format(service.name, active_executions[0].id))
 
         if not force:
             available_nodes = [n for n in service.nodes.values() if n.is_available()]
             if available_nodes:
                 raise exceptions.DependentAvailableNodesError(
                     "Can't delete service {0} - there are available nodes for this service. "
-                    "Available node ids: {1}".format(service_name, available_nodes))
+                    "Available node ids: {1}".format(service.name, available_nodes))
 
         self.model_storage.service.delete(service)