ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxm...@apache.org
Subject [1/2] incubator-ariatosca git commit: ARIATOSCA-9-API-for-operation-context(wip)
Date Tue, 08 Nov 2016 08:57:19 GMT
Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-9-API-for-operation-context [created] d671f47f0


ARIATOSCA-9-API-for-operation-context(wip)


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

Branch: refs/heads/ARIA-9-API-for-operation-context
Commit: caa561018299f86bbe625e697b09bf10f6c2f74e
Parents: f380043
Author: mxmrlv <mxmrlv@gmail.com>
Authored: Thu Oct 27 20:39:09 2016 +0300
Committer: mxmrlv <mxmrlv@gmail.com>
Committed: Thu Oct 27 20:39:09 2016 +0300

----------------------------------------------------------------------
 aria/contexts.py                    | 101 +++++++++++++++++++++++--------
 aria/workflows/builtin/workflows.py |  42 ++++++-------
 2 files changed, 93 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/caa56101/aria/contexts.py
----------------------------------------------------------------------
diff --git a/aria/contexts.py b/aria/contexts.py
index ae7fc66..7d1421e 100644
--- a/aria/contexts.py
+++ b/aria/contexts.py
@@ -40,13 +40,41 @@ class WorkflowContext(LoggerMixin):
             **kwargs):
         super(WorkflowContext, self).__init__(**kwargs)
         self.name = name
-        self.id = str(uuid4())
-        self.model = model_storage
-        self.resource = resource_storage
-        self.deployment_id = deployment_id
-        self.workflow_id = workflow_id
-        self.execution_id = str(uuid4())
-        self.parameters = parameters or {}
+        self._id = str(uuid4())
+        self._model = model_storage
+        self._resource = resource_storage
+        self._deployment_id = deployment_id
+        self._workflow_id = workflow_id
+        self._execution_id = str(uuid4())
+        self._parameters = parameters or {}
+
+    @property
+    def id(self):
+        return self._id
+
+    @property
+    def model(self):
+        return self.model
+
+    @property
+    def resource(self):
+        return self._resource
+
+    @property
+    def deployment_id(self):
+        return self._deployment_id
+
+    @property
+    def workflow_id(self):
+        return self._workflow_id
+
+    @property
+    def execution_id(self):
+        return self._execution_id
+
+    @property
+    def parameters(self):
+        return self._parameters
 
     def __repr__(self):
         return (
@@ -59,7 +87,7 @@ class WorkflowContext(LoggerMixin):
             self,
             name,
             operation_details,
-            node_instance,
+            model,
             inputs=None):
         """
         Called during workflow creation, return an operation context. This object should
be added to
@@ -69,7 +97,7 @@ class WorkflowContext(LoggerMixin):
             name=name,
             operation_details=operation_details,
             workflow_context=self,
-            node_instance=node_instance,
+            model=model,
             inputs=inputs or {})
 
     @property
@@ -174,27 +202,31 @@ class OperationContext(LoggerMixin):
             name,
             operation_details,
             workflow_context,
-            node_instance,
+            operation_host,
             inputs=None):
         super(OperationContext, self).__init__()
         self.name = name
-        self.id = str(uuid4())
-        self.operation_details = operation_details
-        self.workflow_context = workflow_context
-        self.node_instance = node_instance
-        self.inputs = inputs or {}
+        self._id = str(uuid4())
+        self._operation_details = operation_details
+        self._workflow_context = workflow_context
+        self._operation_host = operation_host
+        self._inputs = inputs or {}
 
-    def __repr__(self):
-        details = ', '.join(
-            '{0}={1}'.format(key, value)
-            for key, value in self.operation_details.items())
-        return '{name}({0})'.format(details, name=self.name)
+    @property
+    def operation_details(self):
+        return self._operation_details
 
-    def __getattr__(self, attr):
-        try:
-            return getattr(self.workflow_context, attr)
-        except AttributeError:
-            return super(OperationContext, self).__getattribute__(attr)
+    @property
+    def workflow_context(self):
+        return self._workflow_context
+
+    @property
+    def inputs(self):
+        return self._inputs
+
+    @property
+    def operation_host(self):
+        return self._operation_host
 
     @property
     def operation(self):
@@ -209,3 +241,22 @@ class OperationContext(LoggerMixin):
         Store the operation in the model storage
         """
         self.storage.operation.store(value)
+
+    def __repr__(self):
+        details = ', '.join(
+            '{0}={1}'.format(key, value)
+            for key, value in self.operation_details.items())
+        return '{name}({0})'.format(details, name=self.name)
+
+    def __getattr__(self, attr):
+        # The retrieval order is as follows:
+        # 1. from the operation host (node_instance/relationship_instance)
+        # 2. from the workflow context
+        # 3. from the operation_context
+        try:
+            return getattr(self.operation_host, attr)
+        except AttributeError:
+            try:
+                return getattr(self.workflow_context, attr)
+            except AttributeError:
+                return super(OperationContext, self).__getattribute__(attr)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/caa56101/aria/workflows/builtin/workflows.py
----------------------------------------------------------------------
diff --git a/aria/workflows/builtin/workflows.py b/aria/workflows/builtin/workflows.py
index b6fbb94..1a3a6ab 100644
--- a/aria/workflows/builtin/workflows.py
+++ b/aria/workflows/builtin/workflows.py
@@ -42,20 +42,18 @@ def install_node_instance(context, graph, node_instance):
     """
     create_node_instance = context.operation(
         name='aria.interfaces.lifecycle.create.{0}'.format(node_instance.id),
-        operation_details=node_instance.node.operations[
-            'aria.interfaces.lifecycle.create'],
-        node_instance=node_instance
+        operation_details=node_instance.node.operations['aria.interfaces.lifecycle.create'],
+        operation_host=node_instance
     )
     configure_node_instance = context.operation(
         name='aria.interfaces.lifecycle.configure.{0}'.format(node_instance.id),
         operation_details=node_instance.node.operations['aria.interfaces.lifecycle.configure'],
-        node_instance=node_instance
+        operation_host=node_instance
         )
     start_node_instance = context.operation(
         name='aria.interfaces.lifecycle.start.{0}'.format(node_instance.id),
-        operation_details=node_instance.node.operations[
-            'aria.interfaces.lifecycle.start'],
-        node_instance=node_instance
+        operation_details=node_instance.node.operations['aria.interfaces.lifecycle.start'],
+        operation_host=node_instance
     )
     graph.chain(tasks=[
         create_node_instance,
@@ -125,15 +123,13 @@ def uninstall_node_instance(graph, context, node_instance):
         """
     stop_node_instance = context.operation(
         name='aria.interfaces.lifecycle.stop.{0}'.format(node_instance.id),
-        operation_details=node_instance.node.operations[
-            'aria.interfaces.lifecycle.stop'],
-        node_instance=node_instance
+        operation_details=node_instance.node.operations['aria.interfaces.lifecycle.stop'],
+        operation_host=node_instance,
     )
     delete_node_instance = context.operation(
         name='aria.interfaces.lifecycle.delete.{0}'.format(node_instance.id),
-        operation_details=node_instance.node.operations[
-            'aria.interfaces.lifecycle.delete'],
-        node_instance=node_instance
+        operation_details=node_instance.node.operations['aria.interfaces.lifecycle.delete'],
+        operation_host=node_instance
     )
 
     graph.chain(tasks=[
@@ -188,11 +184,10 @@ def execute_operation_on_instance(
         operation_name=operation)
 
     graph.add_task(
-        context.operation(
-            name=task_name,
-            operation_details=node_instance.node.operations[operation],
-            node_instance=node_instance,
-            parameters=operation_kwargs)
+        context.operation(name=task_name,
+                          operation_details=node_instance.node.operations[operation],
+                          parameters=operation_kwargs,
+                          operation_host=node_instance)
     )
 
 
@@ -245,15 +240,12 @@ def relationship_tasks(node_instance, relationship_instance, context,
operation_
     )
     source_operation = context.operation(
         name=operation_name_template.format('source'),
-        node_instance=node_instance,
-        operation_details=relationship_instance.relationship.source_operations[
-            operation_name])
+        operation_details=relationship_instance.relationship.source_operations[operation_name],
+        operation_host=relationship_instance)
     target_operation = context.operation(
         name=operation_name_template.format('target'),
-        node_instance=context.storage.node_instance.get(
-            relationship_instance.target_id),
-        operation_details=relationship_instance.relationship.target_operations[
-            operation_name])
+        operation_details=relationship_instance.relationship.target_operations[operation_name],
+        operation_host=relationship_instance)
     sub_graph = context.task_graph(name=sub_workflow_name)
     sub_graph.add_task(source_operation)
     sub_graph.add_task(target_operation)


Mime
View raw message