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/05 21:23:58 UTC
incubator-ariatosca git commit: fixed custom workflows import
mechanism
Repository: incubator-ariatosca
Updated Branches:
refs/heads/ARIA-48-aria-cli 765da874f -> 5b683123e
fixed custom workflows import mechanism
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/5b683123
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/5b683123
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/5b683123
Branch: refs/heads/ARIA-48-aria-cli
Commit: 5b683123efa2060a023ea21dbc0eda070c8347a6
Parents: 765da87
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Thu Apr 6 00:23:54 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Thu Apr 6 00:23:54 2017 +0300
----------------------------------------------------------------------
aria/exceptions.py | 9 +++++++
aria/orchestrator/exceptions.py | 21 +++++++++++++++++
aria/orchestrator/workflow_runner.py | 39 +++++++++++++++++++------------
3 files changed, 54 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5b683123/aria/exceptions.py
----------------------------------------------------------------------
diff --git a/aria/exceptions.py b/aria/exceptions.py
index 72adda5..bdf9f78 100644
--- a/aria/exceptions.py
+++ b/aria/exceptions.py
@@ -47,14 +47,23 @@ class AriaException(Exception):
class DependentServicesError(AriaError):
+ """
+ Raised when attempting to delete a service template which has existing services
+ """
pass
class DependentActiveExecutionsError(AriaError):
+ """
+ Raised when attempting to delete a service which has active executions
+ """
pass
class DependentAvailableNodesError(AriaError):
+ """
+ Raised when attempting to delete a service which has available nodes
+ """
pass
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5b683123/aria/orchestrator/exceptions.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/exceptions.py b/aria/orchestrator/exceptions.py
index c00b66b..fd3b66d 100644
--- a/aria/orchestrator/exceptions.py
+++ b/aria/orchestrator/exceptions.py
@@ -46,3 +46,24 @@ class TaskAbortException(RuntimeError):
Used internally when ctx.task.abort is called
"""
pass
+
+
+class UndeclaredWorkflowError(AriaError):
+ """
+ Raised when attempting to execute an undeclared workflow
+ """
+ pass
+
+
+class ActiveExecutionsError(AriaError):
+ """
+ Raised when attempting to execute a workflow on a service which already has an active execution
+ """
+ pass
+
+
+class WorkflowImplementationNotFoundError(AriaError):
+ """
+ Raised when attempting to import a workflow's code but the implementation is not found
+ """
+ pass
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5b683123/aria/orchestrator/workflow_runner.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflow_runner.py b/aria/orchestrator/workflow_runner.py
index 65c0d4c..e2ed3cf 100644
--- a/aria/orchestrator/workflow_runner.py
+++ b/aria/orchestrator/workflow_runner.py
@@ -17,14 +17,15 @@
Workflow runner
"""
+import os
import sys
from datetime import datetime
+from . import exceptions
from .context.workflow import WorkflowContext
from .workflows.builtin import BUILTIN_WORKFLOWS, BUILTIN_WORKFLOWS_PATH_PREFIX
from .workflows.core.engine import Engine
from .workflows.executor.process import ProcessExecutor
-from ..exceptions import AriaException
from ..modeling import utils as modeling_utils
from ..modeling import models
from ..utils.imports import import_fullname
@@ -56,6 +57,7 @@ class WorkflowRunner(object):
"""
self._model_storage = model_storage
+ self._resource_storage = resource_storage
self._workflow_name = workflow_name
# the IDs are stored rather than the models themselves, so this module could be used
@@ -127,15 +129,16 @@ 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:
- raise AriaException('No workflow policy {0} declared in service instance {1}'
- .format(self._workflow_name, self.service.name))
+ raise exceptions.UndeclaredWorkflowError(
+ 'No workflow policy {0} declared in service {1}'
+ .format(self._workflow_name, self.service.name))
def _validate_no_active_executions(self):
active_executions = [e for e in self.service.executions if e.is_active()]
if active_executions:
- raise AriaException("Can't start execution; Service {0} has a running "
- "execution with id {1}"
- .format(self.service.name, active_executions[0].id))
+ raise exceptions.ActiveExecutionsError(
+ "Can't start execution; Service {0} has a running execution with id {1}"
+ .format(self.service.name, active_executions[0].id))
def _get_workflow_fn(self):
if self._workflow_name in BUILTIN_WORKFLOWS:
@@ -144,14 +147,20 @@ class WorkflowRunner(object):
workflow = self.service.workflows[self._workflow_name]
+ # TODO: Custom workflow support needs improvement, currently this code uses internal
+ # knowledge of the resource storage; Instead, workflows should probably be loaded
+ # in a similar manner to operation plugins. Also consider passing to import_fullname
+ # as paths instead of appending to sys path.
+ service_template_resources_path = os.path.join(
+ self._resource_storage.service_template.base_path,
+ str(self.service.service_template.id))
+ sys.path.append(service_template_resources_path)
+
try:
- # TODO: perhaps pass to import_fullname as paths instead of appending to sys path?
- # TODO: revisit; workflow.implementation to be used instead?
- sys.path.append(workflow.properties['implementation'].value)
- # sys.path.append(os.path.dirname(str(context.presentation.location)))
- except KeyError:
- # no implementation field - a script has been provided directly
- pass
-
- workflow_fn = import_fullname(workflow.properties['implementation'].value)
+ workflow_fn = import_fullname(workflow.implementation)
+ except ImportError:
+ raise exceptions.WorkflowImplementationNotFoundError(
+ 'Could not find workflow {0} implementation at {1}'.format(
+ self._workflow_name, workflow.implementation))
+
return workflow_fn