[
https://issues.apache.org/jira/browse/ARIA-105?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15931673#comment-15931673
]
ASF GitHub Bot commented on ARIA-105:
-------------------------------------
Github user mxmrlv commented on a diff in the pull request:
https://github.com/apache/incubator-ariatosca/pull/72#discussion_r106804866
--- Diff: aria/orchestrator/workflows/api/task.py ---
@@ -92,144 +93,133 @@ def __init__(self,
if ignore_failure is None else
ignore_failure)
self.runs_on = runs_on
- @classmethod
- def _merge_inputs(cls, operation_inputs, additional_inputs=None):
- final_inputs = dict((p.name, p.as_raw['value']) for p in
operation_inputs)
- final_inputs.update(additional_inputs or {})
- return final_inputs
+ # Wrap inputs
+ if inputs:
+ for k, v in inputs.iteritems():
+ if not isinstance(v, models.Parameter):
+ inputs[k] = models.Parameter.wrap(k, v)
+
+ # TODO: These extra inputs should likely be stored as a separate
entry in the task model,
+ # because they are different from the operation inputs. The two
kinds of inputs should also
+ # not be merged.
+
+ if interface_name or operation_name:
+ operation = OperationTask._get_operation(actor.interfaces,
interface_name,
+ operation_name)
+ if operation is None:
+ raise exceptions.TaskException(
+ 'Could not find operation "{0}" on interface "{1}" for
{2} "{3}"'
+ .format(operation_name, interface_name, actor_type,
actor.name))
+
+ self.plugin = None
+ if operation.plugin_specification:
+ self.plugin =
OperationTask._find_plugin(operation.plugin_specification)
+ if self.plugin is None:
+ raise exceptions.TaskException(
+ 'Could not find plugin of operation "{0}" on
interface "{1}" for {2} "{3}"'
+ .format(operation_name, interface_name,
actor_type, actor.name))
+
+ self.implementation = operation.implementation
+ self.inputs = OperationTask._merge_inputs(operation.inputs,
inputs)
+
+ self.name = OperationTask.NAME_FORMAT.format(type=actor_type,
+ name=actor.name,
+
interface=interface_name,
+
operation=operation_name)
+ else:
+ self.name = name
+ self.implementation = implementation
+ self.inputs = inputs or {}
+ self.plugin = None
@classmethod
- def node(cls, instance, name, inputs=None, *args, **kwargs):
+ def for_node(cls,
+ node,
+ interface_name,
+ operation_name,
+ max_attempts=None,
+ retry_interval=None,
+ ignore_failure=None,
+ inputs=None):
"""
- Represents a node based operation
+ Creates an operation on a node.
- :param instance: the node of which this operation belongs to.
- :param name: the name of the operation.
+ :param node: the node of which this operation belongs to.
+ :param interface_name: the name of the interface.
+ :param operation_name: the name of the operation.
+ :param inputs: any additional inputs to the operation
"""
- assert isinstance(instance, model.Node)
- interface_name = _get_interface_name(name)
- interfaces = instance.interfaces.filter_by(name=interface_name)
- if interfaces.count() > 1:
- raise exceptions.TaskException(
- "More than one interface with the same name `{0}`
found".format(name)
- )
- elif interfaces.count() == 0:
- raise exceptions.TaskException(
- "No Interface with the name `{interface_name}`
found".format(
- interface_name=interface_name)
- )
-
- operation_templates = interfaces[0].operations.filter_by(name=name)
- if operation_templates.count() > 1:
- raise exceptions.TaskException(
- "More than one operation with the same name `{0}` were
found".format(name)
- )
-
- elif operation_templates.count() == 0:
- raise exceptions.TaskException(
- "No interface with the name `{operation_name}`
found".format(
- operation_name=name)
- )
-
- return cls._instance(
- instance=instance,
- name=name,
- operation_template=operation_templates[0],
- plugins=instance.plugins or [],
- runs_on=model.Task.RUNS_ON_NODE_INSTANCE,
- inputs=cls._merge_inputs(operation_templates[0].inputs,
inputs),
- *args,
- **kwargs)
+
+ assert isinstance(node, models.Node)
+ return cls(
+ actor=node,
+ actor_type='node',
+ interface_name=interface_name,
+ operation_name=operation_name,
+ max_attempts=max_attempts,
+ retry_interval=retry_interval,
+ ignore_failure=ignore_failure,
+ inputs=inputs,
+ runs_on=models.Task.RUNS_ON_NODE)
@classmethod
- def relationship(cls, instance, name, edge, runs_on=None, inputs=None,
*args,
- **kwargs):
+ def for_relationship(cls,
+ relationship,
+ interface_name,
+ operation_name,
+ max_attempts=None,
+ retry_interval=None,
+ ignore_failure=None,
+ inputs=None,
+ runs_on=models.Task.RUNS_ON_SOURCE):
"""
- Represents a relationship based operation
+ Creates an operation on a relationship edge.
- :param instance: the relationship of which this operation belongs
to.
- :param name: the name of the operation.
- :param edge: the edge of the interface ("source" or "target").
- :param runs_on: where to run the operation ("source" or "target");
if None defaults to the
- interface edge.
- :param inputs any additional inputs to the operation
+ :param relationship: the relationship of which this operation
belongs to.
+ :param interface_name: the name of the interface.
+ :param operation_name: the name of the operation.
+ :param inputs: any additional inputs to the operation
+ :param runs_on: where to run the operation ("source" or "target");
defaults to "source"
"""
- assert isinstance(instance, model.Relationship)
- interface_name = _get_interface_name(name)
- interfaces = instance.interfaces.filter_by(name=interface_name,
edge=edge)
- count = interfaces.count()
- if count > 1:
- raise exceptions.TaskException(
- "More than one interface with the same name
`{interface_name}` found at `{edge}`"
- + " edge".format(
- interface_name=interface_name, edge=edge)
- )
- elif count == 0:
- raise exceptions.TaskException(
- "No interface with the name `{interface_name}` found at
`{edge}` edge".format(
- interface_name=interface_name, edge=edge)
- )
-
- operations = interfaces.all()[0].operations.filter_by(name=name)
- count = operations.count()
- if count > 1:
- raise exceptions.TaskException(
- "More than one operation with the same name `{0}`
found".format(name)
- )
- elif count == 0:
- raise exceptions.TaskException(
- "No operation with the name `{operation_name}`
found".format(
- operation_name=name)
- )
-
- if not runs_on:
- if edge == cls.SOURCE_OPERATION:
- runs_on = model.Task.RUNS_ON_SOURCE
- else:
- runs_on = model.Task.RUNS_ON_TARGET
-
- if runs_on == model.Task.RUNS_ON_SOURCE:
- plugins = instance.source_node.plugins
- else:
- plugins = instance.target_node.plugins
-
- return cls._instance(instance=instance,
- name=name,
- operation_template=operations[0],
- plugins=plugins or [],
- runs_on=runs_on,
-
inputs=cls._merge_inputs(operations[0].inputs, inputs),
- *args,
- **kwargs)
- @classmethod
- def _instance(cls,
- instance,
- name,
- operation_template,
- inputs,
- plugins,
- runs_on,
- *args,
- **kwargs):
- matching_plugins = [p for p in plugins if p['name'] ==
operation_template.plugin]
- # All matching plugins should have identical
package_name/package_version, so it's safe to
- # take the first found.
- plugin = matching_plugins[0] if matching_plugins else {}
- return cls(actor=instance,
- name=name,
- implementation=operation_template.implementation,
- inputs=inputs,
- plugin=plugin,
- runs_on=runs_on,
- *args,
- **kwargs)
+ assert isinstance(relationship, models.Relationship)
+ assert runs_on in models.Task.RUNS_ON
+ return cls(
+ actor=relationship,
+ actor_type='relationship',
+ interface_name=interface_name,
+ operation_name=operation_name,
+ max_attempts=max_attempts,
+ retry_interval=retry_interval,
+ ignore_failure=ignore_failure,
+ inputs=inputs,
+ runs_on=runs_on)
+
+ @staticmethod
+ def _get_operation(interfaces, interface_name, operation_name):
+ interface = interfaces.get(interface_name)
+ if interface is not None:
+ return interface.operations.get(operation_name)
+ return None
+
+ @staticmethod
+ def _find_plugin(plugin_specification):
--- End diff --
still not sure about extracting the context and using it in the model...
> Integrate new models into parser
> --------------------------------
>
> Key: ARIA-105
> URL: https://issues.apache.org/jira/browse/ARIA-105
> Project: AriaTosca
> Issue Type: Task
> Reporter: Ran Ziv
> Assignee: Tal Liron
>
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)