Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-48-aria-cli 81e5847ac -> 718c78cd7
created custom error classes for core.py exceptions, fixed error messages Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/718c78cd Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/718c78cd Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/718c78cd Branch: refs/heads/ARIA-48-aria-cli Commit: 718c78cd729f4ecfb02407e262ff9bfc8eb2413b Parents: 81e5847 Author: Ran Ziv <[email protected]> Authored: Thu Mar 30 17:15:20 2017 +0300 Committer: Ran Ziv <[email protected]> Committed: Thu Mar 30 17:15:20 2017 +0300 ---------------------------------------------------------------------- aria/core.py | 32 ++++++++++++++++---------------- aria/exceptions.py | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/718c78cd/aria/core.py ---------------------------------------------------------------------- diff --git a/aria/core.py b/aria/core.py index 50487b6..55ef2f0 100644 --- a/aria/core.py +++ b/aria/core.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +from . import exceptions from .modeling import models from .modeling import utils as modeling_utils -from .exceptions import AriaException from .parser.consumption import ( ConsumptionContext, ConsumerChain, @@ -62,8 +62,8 @@ class Core(object): def delete_service_template(self, service_template_id): service_template = self.model_storage.service_template.get(service_template_id) if service_template.services.all(): - raise AriaException("Can't delete service template {0} - Service template has " - "existing services") + raise exceptions.DependentServicesError( + "Can't delete service template {0} - Service template has existing services") self.model_storage.service_template.delete(service_template) self.resource_storage.service_template.delete(entry_id=str(service_template.id)) @@ -90,20 +90,20 @@ class Core(object): def delete_service(self, service_name, force=False): service = self.model_storage.service.get_by_name(service_name) - running_executions = [e for e in service.executions - if e.status not in models.Execution.ACTIVE_STATES] - if running_executions: - raise AriaException("Can't delete service {0} - there is a running execution " - "for this service. Running execution id: {1}" - .format(service_name, running_executions[0].id)) + active_executions = [e for e in service.executions + if e.status not in models.Execution.ACTIVE_STATES] + 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)) if not force: - running_nodes = [n for n in service.nodes.values() - if n.state not in ('deleted', 'errored')] - if running_nodes: - raise AriaException("Can't delete service {0} - there are running nodes " - "for this service. Running node ids: {1}" - .format(service_name, running_nodes)) + available_nodes = [n for n in service.nodes.values() + if n.state not in ('deleted', 'errored')] + 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)) self.model_storage.service.delete(service) @@ -113,5 +113,5 @@ class Core(object): context.presentation.location = UriLocation(service_template_path) ConsumerChain(context, (Read, Validate, ServiceTemplate)).consume() if context.validation.dump_issues(): - raise AriaException('Failed to parse service template') + raise exceptions.ParsingError('Failed to parse service template') return context http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/718c78cd/aria/exceptions.py ---------------------------------------------------------------------- diff --git a/aria/exceptions.py b/aria/exceptions.py index a180ce1..72adda5 100644 --- a/aria/exceptions.py +++ b/aria/exceptions.py @@ -44,3 +44,19 @@ class AriaException(Exception): # Make sure it's our traceback cause_traceback = traceback self.cause_traceback = cause_traceback + + +class DependentServicesError(AriaError): + pass + + +class DependentActiveExecutionsError(AriaError): + pass + + +class DependentAvailableNodesError(AriaError): + pass + + +class ParsingError(AriaError): + pass
