ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject [03/32] incubator-ariatosca git commit: fixed custom workflows import mechanism
Date Thu, 06 Apr 2017 08:29:29 GMT
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/7c567b0c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/7c567b0c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/7c567b0c

Branch: refs/heads/ARIA-48-aria-cli
Commit: 7c567b0c19053b14633920a057b3aec8cf97fa00
Parents: 61a2b03
Author: Ran Ziv <ran@gigaspaces.com>
Authored: Thu Apr 6 00:23:54 2017 +0300
Committer: Ran Ziv <ran@gigaspaces.com>
Committed: Thu Apr 6 11:29:17 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/7c567b0c/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/7c567b0c/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/7c567b0c/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


Mime
View raw message