Github user mxmrlv commented on a diff in the pull request:
https://github.com/apache/incubator-ariatosca/pull/20#discussion_r87984742
--- Diff: aria/context/operation.py ---
@@ -17,52 +17,113 @@
Workflow and operation contexts
"""
-from uuid import uuid4
-from aria.logger import LoggerMixin
+from .common import BaseContext
-class OperationContext(LoggerMixin):
+
+class BaseOperationContext(BaseContext):
"""
Context object used during operation creation and execution
"""
- def __init__(
- self,
- name,
- operation_details,
- workflow_context,
- node_instance,
- 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 {}
+ def __init__(self, name, workflow_context, task, **kwargs):
+ super(BaseOperationContext, self).__init__(
+ name=name,
+ model_storage=workflow_context.model,
+ resource_storage=workflow_context.resource,
+ deployment_id=workflow_context._deployment_id,
+ workflow_id=workflow_context._workflow_id,
+ execution_id=workflow_context._execution_id,
+ parameters=workflow_context.parameters,
+ **kwargs)
+ self._workflow_context = workflow_context
+ self._task_model = task
+ self._actor = self.task.actor
def __repr__(self):
details = ', '.join(
'{0}={1}'.format(key, value)
- for key, value in self.operation_details.items())
+ for key, value in self.task.operation_details.items())
return '{name}({0})'.format(details, name=self.name)
- def __getattr__(self, attr):
- try:
- return getattr(self.workflow_context, attr)
- except AttributeError:
- return super(OperationContext, self).__getattribute__(attr)
+ @property
+ def task(self):
+ """
+ The task in the model storage
+ :return: Task model
+ """
+ return self._task_model
+
+
+class NodeOperationContext(BaseOperationContext):
+ """
+ Context for node based operations.
+ """
+ @property
+ def node(self):
+ """
+ the node of the current operation
+ :return:
+ """
+ return self._actor.node
+
+ @property
+ def node_instance(self):
+ """
+ The node instance of the current operation
+ :return:
+ """
+ return self._actor
+
+class RelationshipOperationContext(BaseOperationContext):
+ """
+ Context for relationship based operations.
+ """
@property
- def operation(self):
+ def node(self):
--- End diff --
source_node
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---