strucutre major ref, relationships still need to move from one-to-many style into many-to-one
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/9c6c378c Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/9c6c378c Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/9c6c378c Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models Commit: 9c6c378cf5479b9b6183067ffb6d4d6e73ad4a04 Parents: 3b52696 Author: mxmrlv <[email protected]> Authored: Tue Jan 24 19:03:10 2017 +0200 Committer: mxmrlv <[email protected]> Committed: Tue Jan 24 19:03:10 2017 +0200 ---------------------------------------------------------------------- aria/modeling/elements.py | 1 + aria/modeling/instance_elements.py | 130 +- aria/modeling/model_elements.py | 118 +- aria/modeling/models.py | 24 +- aria/modeling/orchestrator_elements.py | 46 +- aria/orchestrator/workflows/api/task.py | 37 +- aria/storage/base_model.py | 1486 ++++++++++---------- aria/storage/model.py | 220 +-- aria/storage/structure.py | 91 +- tests/mock/models.py | 33 +- tests/orchestrator/workflows/api/test_task.py | 24 +- tests/storage/__init__.py | 13 +- tests/storage/test_model_storage.py | 5 +- tests/storage/test_new_modelling.py | 8 +- 14 files changed, 1144 insertions(+), 1092 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/9c6c378c/aria/modeling/elements.py ---------------------------------------------------------------------- diff --git a/aria/modeling/elements.py b/aria/modeling/elements.py index af9ee36..1c98da1 100644 --- a/aria/modeling/elements.py +++ b/aria/modeling/elements.py @@ -85,6 +85,7 @@ class Parameter(ModelElement, structure.ModelMixin): This class is used by both service model and service instance elements. """ __tablename__ = 'parameter' + type_name = Column(Text) # Check: value type value = Column(Text) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/9c6c378c/aria/modeling/instance_elements.py ---------------------------------------------------------------------- diff --git a/aria/modeling/instance_elements.py b/aria/modeling/instance_elements.py index 95edeeb..5f28025 100644 --- a/aria/modeling/instance_elements.py +++ b/aria/modeling/instance_elements.py @@ -3,13 +3,14 @@ from sqlalchemy import ( Column, Text, Integer, + Boolean, ) from sqlalchemy import DateTime from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.ext.orderinglist import ordering_list -from . import elements, utils +from . import utils from ..storage import ( structure, type as aria_types, @@ -39,72 +40,66 @@ class ServiceInstance(structure.ModelMixin): @declared_attr def service_template_name(cls): - from . import model_elements - return association_proxy('service_template', model_elements.ServiceTemplate) + return association_proxy('service_template', 'name') # endregion # region foreign keys @declared_attr def substitution_fk(cls): - return cls.foreign_key(Substitution, nullable=True) + return cls.foreign_key('substitution', nullable=True) @declared_attr def service_template_fk(cls): - from . import model_elements - return cls.foreign_key(model_elements.ServiceTemplate) + return cls.foreign_key('service_template') # endregion # region one-to-one relationships @declared_attr def substitution(cls): - return cls.one_to_one_relationship(Substitution) + return cls.one_to_one_relationship('substitution') # endregion # region one-to-many relationships @declared_attr def nodes(cls): - return cls.one_to_many_relationship(Node) + return cls.one_to_many_relationship('node') @declared_attr def groups(cls): - return cls.one_to_many_relationship(Group) + return cls.one_to_many_relationship('group') @declared_attr def policies(cls): - return cls.one_to_many_relationship(Policy) + return cls.one_to_many_relationship('policy') @declared_attr def operations(cls): - return cls.one_to_many_relationship(Operation) + return cls.one_to_many_relationship('operation') # endregion # region many-to-one relationships @declared_attr def service_template(cls): - return cls.many_to_one_relationship('service_template_fk') + return cls.many_to_one_relationship('service_template') # endregion # region many-to-many relationships @declared_attr def inputs(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='inputs') + return cls.many_to_many_relationship('parameter', table_prefix='inputs') @declared_attr def outputs(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='outputs') + return cls.many_to_many_relationship('parameter', table_prefix='outputs') # endregion # association proxies - @declared_attr - def service_template_name(cls): - return association_proxy('service_template', cls.name_column_name()) - def satisfy_requirements(self, context): satisfied = True for node in self.nodes.itervalues(): @@ -177,11 +172,11 @@ class Operation(structure.ModelMixin): # region foreign_keys @declared_attr def service_instance_fk(cls): - return cls.foreign_key(ServiceInstance) + return cls.foreign_key('service_instance') @declared_attr def interface_instance_fk(cls): - return cls.foreign_key(Interface) + return cls.foreign_key('interface') # endregion description = Column(Text) @@ -191,12 +186,13 @@ class Operation(structure.ModelMixin): executor = Column(Text) max_retries = Column(Integer, default=None) retry_interval = Column(Integer, default=None) - + plugin = Column(Text) + operation = Column(Boolean) # region many-to-many relationships @declared_attr def inputs(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='inputs') + return cls.many_to_many_relationship('parameter', table_prefix='inputs') # endregion @@ -253,11 +249,15 @@ class Interface(structure.ModelMixin): # region foreign_keys @declared_attr def group_fk(cls): - return cls.foreign_key(Group) + return cls.foreign_key('group') @declared_attr def node_fk(cls): - return cls.foreign_key(Node) + return cls.foreign_key('node', nullable=True) + + @declared_attr + def relationship_fk(cls): + return cls.foreign_key('relationship', nullable=True) # endregion @@ -267,7 +267,7 @@ class Interface(structure.ModelMixin): # region one-to-many relationships @declared_attr def operations(cls): - return cls.one_to_many_relationship(Operation) + return cls.one_to_many_relationship('operation') # endregion @@ -275,7 +275,7 @@ class Interface(structure.ModelMixin): @declared_attr def inputs(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='inputs') + return cls.many_to_many_relationship('parameter', table_prefix='inputs') # endregion @@ -331,7 +331,7 @@ class Capability(structure.ModelMixin): # region foreign_keys @declared_attr def node_fk(cls): - return cls.foreign_key(Node) + return cls.foreign_key('node') # endregion type_name = Column(Text) @@ -343,7 +343,7 @@ class Capability(structure.ModelMixin): # region many-to-many relationships @declared_attr def properties(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='properties') + return cls.many_to_many_relationship('parameter', table_prefix='properties') # endregion @@ -412,7 +412,7 @@ class Artifact(structure.ModelMixin): @declared_attr def node_fk(cls): - return cls.foreign_key(Node) + return cls.foreign_key('node') # endregion @@ -427,7 +427,7 @@ class Artifact(structure.ModelMixin): @declared_attr def properties(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='properties') + return cls.many_to_many_relationship('parameter', table_prefix='properties') # endregion @@ -487,7 +487,7 @@ class Policy(structure.ModelMixin): # region foreign_keys @declared_attr def service_instance_fk(cls): - return cls.foreign_key(ServiceInstance) + return cls.foreign_key('service_instance') # endregion type_name = Column(Text) @@ -498,7 +498,7 @@ class Policy(structure.ModelMixin): @declared_attr def properties(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='properties') + return cls.many_to_many_relationship('parameter', table_prefix='properties') # endregion @@ -556,7 +556,7 @@ class GroupPolicy(structure.ModelMixin): # region foreign_keys @declared_attr def group_fk(cls): - return cls.foreign_key(Group) + return cls.foreign_key('group') # endregion @@ -567,14 +567,14 @@ class GroupPolicy(structure.ModelMixin): @declared_attr def triggers(cls): - return cls.one_to_many_relationship(GroupPolicyTrigger) + return cls.one_to_many_relationship('group_policy_trigger') # endregion # region many-to-many relationships @declared_attr def properties(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='properties') + return cls.many_to_many_relationship('parameter', table_prefix='properties') # relationships @@ -628,7 +628,7 @@ class GroupPolicyTrigger(structure.ModelMixin): @declared_attr def group_policy_fk(cls): - return cls.foreign_key(GroupPolicy) + return cls.foreign_key('group_policy') # endregion @@ -639,7 +639,7 @@ class GroupPolicyTrigger(structure.ModelMixin): @declared_attr def properties(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='properties') + return cls.many_to_many_relationship('parameter', table_prefix='properties') # endregion @@ -712,11 +712,11 @@ class Substitution(structure.ModelMixin): @declared_attr def capabilities(cls): - return cls.many_to_many_relationship(Mapping, table_prefix='capabilities') + return cls.many_to_many_relationship('mapping', table_prefix='capabilities') @declared_attr def requirements(cls): - return cls.many_to_many_relationship(Mapping, table_prefix='requirements') + return cls.many_to_many_relationship('mapping', table_prefix='requirements') # endregion @@ -776,16 +776,15 @@ class Node(structure.ModelMixin): # region foreign_keys @declared_attr def service_instance_fk(cls): - return cls.foreign_key(ServiceInstance) + return cls.foreign_key('service_instance') @declared_attr def host_fk(cls): - return cls.foreign_key(Node, nullable=True) + return cls.foreign_key('node', nullable=True) @declared_attr def node_template_fk(cls): - from . import model_elements - return cls.foreign_key(model_elements.NodeTemplate) + return cls.foreign_key('node_template') # endregion @@ -816,7 +815,7 @@ class Node(structure.ModelMixin): @declared_attr def node_template(cls): - return cls.many_to_one_relationship('node_template_fk') + return cls.many_to_one_relationship('node_template') @declared_attr def service_template(cls): @@ -826,15 +825,22 @@ class Node(structure.ModelMixin): # region one-to-many relationships @declared_attr def interfaces(cls): - return cls.one_to_many_relationship(Interface) + return cls.one_to_many_relationship('interface') @declared_attr def artifacts(cls): - return cls.one_to_many_relationship(Artifact) + return cls.one_to_many_relationship('artifact') @declared_attr def capabilities(cls): - return cls.one_to_many_relationship(Capability) + return cls.one_to_many_relationship('capability') + + # endregion + + # region many-to-one relationships + @declared_attr + def service_instance(cls): + return cls.many_to_one_relationship('service_instance') # endregion @@ -842,7 +848,7 @@ class Node(structure.ModelMixin): @declared_attr def properties(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='properties') + return cls.many_to_many_relationship('parameter', table_prefix='properties') # endregion @@ -996,9 +1002,10 @@ class Group(structure.ModelMixin): """ __tablename__ = 'group' # region foreign_keys + @declared_attr def service_instance_fk(cls): - return cls.foreign_key(ServiceInstance) + return cls.foreign_key('service_instance') # endregion @@ -1010,19 +1017,18 @@ class Group(structure.ModelMixin): # region one-to-many relationships @declared_attr def interfaces(cls): - return cls.one_to_many_relationship(Interface) + return cls.one_to_many_relationship('interface') @declared_attr def policies(cls): - return cls.one_to_many_relationship(GroupPolicy) + return cls.one_to_many_relationship('group_policy') # endregion # region many-to-many relationships @declared_attr def properties(cls): - return cls.many_to_many_relationship(elements.Parameter, - table_prefix='properties') + return cls.many_to_many_relationship('parameter', table_prefix='properties') # endregion @@ -1100,19 +1106,20 @@ class Relationship(structure.ModelMixin): type_name = Column(Text) template_name = Column(Text) - # region orchestrator required columns + # # region orchestrator required columns source_position = Column(Integer) target_position = Column(Integer) @declared_attr def source_node_fk(cls): - return cls.foreign_key(Node, nullable=True) + return cls.foreign_key('node', nullable=True) @declared_attr def source_node(cls): return cls.many_to_one_relationship( + 'node', 'source_node_fk', - backreference='outbound_relationship_instances', + backreference='outbound_relationships', backref_kwargs=dict( order_by=cls.source_position, collection_class=ordering_list('source_position', count_from=0) @@ -1125,13 +1132,14 @@ class Relationship(structure.ModelMixin): @declared_attr def target_node_fk(cls): - return cls.foreign_key(Node, nullable=True) + return cls.foreign_key('node', nullable=True) @declared_attr def target_node(cls): return cls.many_to_one_relationship( + 'node', 'target_node_fk', - backreference='inbound_relationship_instances', + backreference='inbound_relationships', backref_kwargs=dict( order_by=cls.target_position, collection_class=ordering_list('target_position', count_from=0) @@ -1147,15 +1155,15 @@ class Relationship(structure.ModelMixin): @declared_attr def properties(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='properties') + return cls.many_to_many_relationship('parameter', table_prefix='properties') @declared_attr def source_interfaces(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='source_interfaces') + return cls.many_to_many_relationship('interface', table_prefix='source_interfaces') @declared_attr def target_interfaces(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='target_interfaces') + return cls.many_to_many_relationship('interface', table_prefix='target_interfaces') @property def as_raw(self): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/9c6c378c/aria/modeling/model_elements.py ---------------------------------------------------------------------- diff --git a/aria/modeling/model_elements.py b/aria/modeling/model_elements.py index 91e39d1..f8a4800 100644 --- a/aria/modeling/model_elements.py +++ b/aria/modeling/model_elements.py @@ -20,17 +20,18 @@ from sqlalchemy import ( Text, Integer, DateTime, + Boolean, ) from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.ext.declarative import declared_attr -from . import elements, instance_elements, utils from ..storage import ( structure, - type as aria_type, + type as aria_type, ) from ..utils import collections, formatting, console from ..parser import validation +from . import utils, instance_elements # region Element templates @@ -57,32 +58,36 @@ class ServiceTemplate(structure.ModelMixin): # region foreign keys @declared_attr def substitution_template_fk(cls): - return cls.foreign_key(SubstitutionTemplate, nullable=True) + return cls.foreign_key('substitution_template', nullable=True) # endregion # region one-to-one relationships @declared_attr def substitution_template(cls): - return cls.one_to_one_relationship(SubstitutionTemplate) + return cls.one_to_one_relationship('substitution_template') # endregion - # region one-to-many relationships + # # region one-to-many relationships @declared_attr def node_templates(cls): - return cls.one_to_many_relationship(NodeTemplate) + return cls.one_to_many_relationship('node_template') @declared_attr def group_templates(cls): - return cls.one_to_many_relationship(GroupTemplate) + return cls.one_to_many_relationship('group_template') @declared_attr def policy_templates(cls): - return cls.one_to_many_relationship(PolicyTemplate) + return cls.one_to_many_relationship('policy_template') @declared_attr def operation_templates(cls): - return cls.one_to_many_relationship(OperationTemplate) + """ + Custom workflows + :return: + """ + return cls.one_to_many_relationship('operation_template') # endregion @@ -90,11 +95,11 @@ class ServiceTemplate(structure.ModelMixin): @declared_attr def inputs(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='inputs') + return cls.many_to_many_relationship('parameter', table_prefix='inputs') @declared_attr def outputs(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='outputs') + return cls.many_to_many_relationship('parameter', table_prefix='outputs') # endregion @@ -192,11 +197,11 @@ class InterfaceTemplate(structure.ModelMixin): @declared_attr def node_template_fk(cls): - return cls.foreign_key(NodeTemplate) + return cls.foreign_key('node_template', nullable=True) @declared_attr def group_template_fk(cls): - return cls.foreign_key(GroupTemplate, nullable=True) + return cls.foreign_key('group_template', nullable=True) # endregion @@ -206,17 +211,17 @@ class InterfaceTemplate(structure.ModelMixin): # region one-to-many relationships @declared_attr def operation_templates(cls): - return cls.one_to_many_relationship(OperationTemplate) + return cls.one_to_many_relationship('operation_template') # region many-to-many relationships @declared_attr def inputs(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='inputs') + return cls.many_to_many_relationship('parameter', table_prefix='inputs') @declared_attr def properties(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='properties') + return cls.many_to_many_relationship('parameter', table_prefix='properties') # endregion @property @@ -262,14 +267,16 @@ class InterfaceTemplate(structure.ModelMixin): class OperationTemplate(structure.ModelMixin): __tablename__ = 'operation_template' + # region foreign keys + @declared_attr def service_template_fk(cls): - return cls.foreign_key(ServiceTemplate) + return cls.foreign_key('service_template', nullable=True) @declared_attr def interface_template_fk(cls): - return cls.foreign_key(InterfaceTemplate) + return cls.foreign_key('interface_template', nullable=True) # endregion @@ -280,11 +287,19 @@ class OperationTemplate(structure.ModelMixin): max_retries = Column(Integer) retry_interval = Column(Integer) + # region orchestrator required columns + plugin = Column(Text) + operation = Column(Boolean) + + @declared_attr + def service_template(cls): + return cls.many_to_one_relationship('service_template') + # region many-to-many relationships @declared_attr def inputs(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='inputs') + return cls.many_to_many_relationship('parameter', table_prefix='inputs') # endregion @@ -353,9 +368,10 @@ class ArtifactTemplate(structure.ModelMixin): """ __tablename__ = 'artifact_template' # region foreign keys + @declared_attr def node_template_fk(cls): - return cls.foreign_key(NodeTemplate) + return cls.foreign_key('node_template') # endregion @@ -370,7 +386,7 @@ class ArtifactTemplate(structure.ModelMixin): @declared_attr def properties(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='properties') + return cls.many_to_many_relationship('parameter', table_prefix='properties') # endregion @@ -441,11 +457,11 @@ class PolicyTemplate(structure.ModelMixin): # region foreign keys @declared_attr def service_template_fk(cls): - return cls.foreign_key(ServiceTemplate) + return cls.foreign_key('service_template') @declared_attr def group_template_fk(cls): - return cls.foreign_key(GroupTemplate) + return cls.foreign_key('group_template') # endregion @@ -458,7 +474,7 @@ class PolicyTemplate(structure.ModelMixin): @declared_attr def properties(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='properties') + return cls.many_to_many_relationship('parameter', table_prefix='properties') # endregion @@ -526,7 +542,7 @@ class GroupPolicyTemplate(structure.ModelMixin): # region foreign keys @declared_attr def group_template_fk(cls): - return cls.foreign_key(GroupTemplate) + return cls.foreign_key('group_template') # endregion @@ -536,7 +552,7 @@ class GroupPolicyTemplate(structure.ModelMixin): # region one-to-many relationships @declared_attr def triggers(cls): - return cls.one_to_many_relationship(GroupPolicyTriggerTemplate) + return cls.one_to_many_relationship('group_policy_trigger_template') # end region @@ -544,7 +560,7 @@ class GroupPolicyTemplate(structure.ModelMixin): @declared_attr def properties(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='properties') + return cls.many_to_many_relationship('parameter', table_prefix='properties') # endregion @@ -602,7 +618,7 @@ class GroupPolicyTriggerTemplate(structure.ModelMixin): # region foreign keys @declared_attr def group_policy_template_fk(cls): - return cls.foreign_key(GroupPolicyTemplate) + return cls.foreign_key('group_policy_template') # endregion @@ -613,7 +629,7 @@ class GroupPolicyTriggerTemplate(structure.ModelMixin): @declared_attr def properties(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='properties') + return cls.many_to_many_relationship('parameter', table_prefix='properties') # endregion @@ -711,11 +727,13 @@ class SubstitutionTemplate(structure.ModelMixin): @declared_attr def capability_templates(cls): - return cls.many_to_many_relationship(MappingTemplate, table_prefix='capability_templates') + return cls.many_to_many_relationship('mapping_template', + table_prefix='capability_templates') @declared_attr def requirement_templates(cls): - return cls.many_to_many_relationship(MappingTemplate, table_prefix='requirement_templates') + return cls.many_to_many_relationship('mapping_template', + table_prefix='requirement_templates') # endregion @@ -767,11 +785,11 @@ class NodeTemplate(structure.ModelMixin): # region foreign_keys @declared_attr def service_template_fk(cls): - return cls.foreign_key(ServiceTemplate) + return cls.foreign_key('service_template') @declared_attr def host_fk(cls): - return cls.foreign_key(NodeTemplate, nullable=True) + return cls.foreign_key('node_template', nullable=True) # endregion @@ -793,26 +811,34 @@ class NodeTemplate(structure.ModelMixin): @declared_attr def service_template_name(cls): - return association_proxy('service_template_fk', cls.name_column_name()) + return association_proxy('service_template', cls.name_column_name()) # endregion # region one-to-many relationships @declared_attr def interface_templates(cls): - return cls.one_to_many_relationship(InterfaceTemplate) + return cls.one_to_many_relationship('interface_template') @declared_attr def artifact_templates(cls): - return cls.one_to_many_relationship(ArtifactTemplate) + return cls.one_to_many_relationship('artifact_template') @declared_attr def capability_templates(cls): - return cls.one_to_many_relationship(CapabilityTemplate) + return cls.one_to_many_relationship('capability_template') @declared_attr def requirement_templates(cls): - return cls.one_to_many_relationship(RequirementTemplate) + return cls.one_to_many_relationship('requirement_template') + + # endregion + + # region many-to-many relationships + + @declared_attr + def service_template(cls): + return cls.many_to_one_relationship('service_template') # endregion @@ -820,7 +846,7 @@ class NodeTemplate(structure.ModelMixin): @declared_attr def properties(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='properties') + return cls.many_to_many_relationship('parameter', table_prefix='properties') # endregion @@ -916,7 +942,7 @@ class GroupTemplate(structure.ModelMixin): @declared_attr def service_template_fk(cls): - return cls.foreign_key(ServiceTemplate) + return cls.foreign_key('service_template') # endregion @@ -928,11 +954,11 @@ class GroupTemplate(structure.ModelMixin): # region one-to-many relationships @declared_attr def interface_templates(cls): - return cls.one_to_many_relationship(InterfaceTemplate) + return cls.one_to_many_relationship('interface_template') @declared_attr def policy_templates(cls): - return cls.one_to_many_relationship(PolicyTemplate) + return cls.one_to_many_relationship('policy_template') # endregion @@ -940,7 +966,7 @@ class GroupTemplate(structure.ModelMixin): @declared_attr def properties(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='properties') + return cls.many_to_many_relationship('parameter', table_prefix='properties') # endregion @@ -1026,7 +1052,7 @@ class RequirementTemplate(structure.ModelMixin): # region foreign keys @declared_attr def node_template_fk(cls): - return cls.foreign_key(NodeTemplate, nullable=True) + return cls.foreign_key('node_template', nullable=True) # endregion @@ -1177,7 +1203,7 @@ class CapabilityTemplate(structure.ModelMixin): # region foreign keys @declared_attr def node_template_fk(cls): - return cls.foreign_key(NodeTemplate, nullable=True) + return cls.foreign_key('node_template', nullable=True) # endregion @@ -1192,7 +1218,7 @@ class CapabilityTemplate(structure.ModelMixin): @declared_attr def properties(cls): - return cls.many_to_many_relationship(elements.Parameter, table_prefix='properties') + return cls.many_to_many_relationship('parameter', table_prefix='properties') # endregion http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/9c6c378c/aria/modeling/models.py ---------------------------------------------------------------------- diff --git a/aria/modeling/models.py b/aria/modeling/models.py index ca3e9fa..ef311f6 100644 --- a/aria/modeling/models.py +++ b/aria/modeling/models.py @@ -15,6 +15,7 @@ class Parameter(DB, elements.Parameter): # region template models + class MappingTemplate(DB, model_elements.MappingTemplate): pass @@ -23,23 +24,23 @@ class SubstitutionTemplate(DB, model_elements.SubstitutionTemplate): pass -class ServiceTemplate(DB, model_elements.ServiceTemplate): +class InterfaceTemplate(DB, model_elements.InterfaceTemplate): pass -class NodeTemplate(DB, model_elements.NodeTemplate): +class OperationTemplate(DB, model_elements.OperationTemplate): pass -class GroupTemplate(DB, model_elements.GroupTemplate): +class ServiceTemplate(DB, model_elements.ServiceTemplate): pass -class InterfaceTemplate(DB, model_elements.InterfaceTemplate): +class NodeTemplate(DB, model_elements.NodeTemplate): pass -class OperationTemplate(DB, model_elements.OperationTemplate): +class GroupTemplate(DB, model_elements.GroupTemplate): pass @@ -87,6 +88,10 @@ class Node(DB, instance_elements.Node): pass +class Relationship(DB, instance_elements.Relationship): + pass + + class Artifact(DB, instance_elements.Artifact): pass @@ -107,7 +112,6 @@ class Capability(DB, instance_elements.Capability): pass - class Policy(DB, instance_elements.Policy): pass @@ -120,12 +124,8 @@ class GroupPolicyTrigger(DB, instance_elements.GroupPolicyTrigger): pass -class Relationship(DB, instance_elements.Relationship): - pass - - # endregion - +# # region orchestrator models class Execution(DB, orchestrator_elements.Execution): @@ -143,7 +143,7 @@ class ServiceInstanceUpdateStep(DB, orchestrator_elements.ServiceInstanceUpdateS class ServiceInstanceModification(DB, orchestrator_elements.ServiceInstanceModificationBase): pass - +# class Plugin(DB, orchestrator_elements.PluginBase): pass http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/9c6c378c/aria/modeling/orchestrator_elements.py ---------------------------------------------------------------------- diff --git a/aria/modeling/orchestrator_elements.py b/aria/modeling/orchestrator_elements.py index 6eb3b9f..68bfad4 100644 --- a/aria/modeling/orchestrator_elements.py +++ b/aria/modeling/orchestrator_elements.py @@ -134,11 +134,11 @@ class Execution(ModelMixin): @declared_attr def service_instance_fk(cls): - return cls.foreign_key(instance_elements.ServiceInstance) + return cls.foreign_key('service_instance') @declared_attr def service_instance(cls): - return cls.many_to_one_relationship('service_instance_fk') + return cls.many_to_one_relationship('service_instance') @declared_attr def service_instance_name(cls): @@ -163,7 +163,7 @@ class ServiceInstanceUpdateBase(ModelMixin): # Needed only for pylint. the id will be populated by sqlalcehmy and the proper column. steps = None - __tablename__ = 'deployment_updates' + __tablename__ = 'service_instance_update' _private_fields = ['execution_fk', 'deployment_fk'] @@ -177,11 +177,11 @@ class ServiceInstanceUpdateBase(ModelMixin): @declared_attr def execution_fk(cls): - return cls.foreign_key(Execution, nullable=True) + return cls.foreign_key('execution', nullable=True) @declared_attr def execution(cls): - return cls.many_to_one_relationship('execution_fk') + return cls.many_to_one_relationship('execution') @declared_attr def execution_name(cls): @@ -189,11 +189,11 @@ class ServiceInstanceUpdateBase(ModelMixin): @declared_attr def service_instance_fk(cls): - return cls.foreign_key(instance_elements.ServiceInstance) + return cls.foreign_key('service_instance') @declared_attr def service_instance(cls): - return cls.many_to_one_relationship('service_instance_fk') + return cls.many_to_one_relationship('service_instance') @declared_attr def service_instance_name(cls): @@ -211,7 +211,7 @@ class ServiceInstanceUpdateStepBase(ModelMixin): Deployment update step model representation. """ # Needed only for pylint. the id will be populated by sqlalcehmy and the proper column. - __tablename__ = 'deployment_update_steps' + __tablename__ = 'service_instance_update_step' _private_fields = ['deployment_update_fk'] _action_types = namedtuple('ACTION_TYPES', 'ADD, REMOVE, MODIFY') @@ -239,12 +239,13 @@ class ServiceInstanceUpdateStepBase(ModelMixin): entity_type = Column(Enum(*ENTITY_TYPES, name='entity_type'), nullable=False) @declared_attr - def deployment_update_fk(cls): - return cls.foreign_key(ServiceInstanceUpdateBase) + def service_instance_update_fk(cls): + return cls.foreign_key('service_instance_update') @declared_attr def deployment_update(cls): - return cls.many_to_one_relationship('deployment_update_fk', backreference='steps') + return cls.many_to_one_relationship('service_instance_update', + backreference='steps') @declared_attr def deployment_update_name(cls): @@ -301,11 +302,12 @@ class ServiceInstanceModificationBase(ModelMixin): @declared_attr def service_instance_fk(cls): - return cls.foreign_key(instance_elements.ServiceInstance) + return cls.foreign_key('service_instance') @declared_attr def service_instance(cls): - return cls.many_to_one_relationship('service_instance_fk', backreference='modifications') + return cls.many_to_one_relationship('service_instance', + backreference='modifications') @declared_attr def deployment_name(cls): @@ -316,7 +318,7 @@ class PluginBase(ModelMixin): """ Plugin model representation. """ - __tablename__ = 'plugins' + __tablename__ = 'plugin' archive_name = Column(Text, nullable=False, index=True) distribution = Column(Text) @@ -340,7 +342,7 @@ class TaskBase(ModelMixin): @declared_attr def node_fk(cls): - return cls.foreign_key(instance_elements.Node, nullable=True) + return cls.foreign_key('node', nullable=True) @declared_attr def node_name(cls): @@ -348,11 +350,11 @@ class TaskBase(ModelMixin): @declared_attr def node(cls): - return cls.many_to_one_relationship('node_fk') + return cls.many_to_one_relationship('node') @declared_attr def relationship_fk(cls): - return cls.foreign_key(instance_elements.Relationship, nullable=True) + return cls.foreign_key('relationship', nullable=True) @declared_attr def relationship_name(cls): @@ -360,15 +362,15 @@ class TaskBase(ModelMixin): @declared_attr def relationship(cls): - return cls.many_to_one_relationship('relationship_fk') + return cls.many_to_one_relationship('relationship') @declared_attr def plugin_fk(cls): - return cls.foreign_key(PluginBase, nullable=True) + return cls.foreign_key('plugin', nullable=True) @declared_attr def plugin(cls): - return cls.many_to_one_relationship('plugin_fk') + return cls.many_to_one_relationship('plugin') @declared_attr def plugin_name(cls): @@ -376,11 +378,11 @@ class TaskBase(ModelMixin): @declared_attr def execution_fk(cls): - return cls.foreign_key(Execution, nullable=True) + return cls.foreign_key('execution', nullable=True) @declared_attr def execution(cls): - return cls.many_to_one_relationship('execution_fk') + return cls.many_to_one_relationship('execution') @declared_attr def execution_name(cls): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/9c6c378c/aria/orchestrator/workflows/api/task.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/workflows/api/task.py b/aria/orchestrator/workflows/api/task.py index 70324a6..762af3b 100644 --- a/aria/orchestrator/workflows/api/task.py +++ b/aria/orchestrator/workflows/api/task.py @@ -19,6 +19,7 @@ Provides the tasks to be entered into the task graph from uuid import uuid4 from aria.storage import model +from aria.modeling import models from ... import context from .. import exceptions @@ -75,8 +76,8 @@ class OperationTask(BaseTask): :param actor: the operation host on which this operation is registered. :param inputs: operation inputs. """ - assert isinstance(actor, (model.NodeInstance, - model.RelationshipInstance)) + assert isinstance(actor, (models.Node, + models.Relationship)) super(OperationTask, self).__init__() self.actor = actor self.name = '{name}.{actor.id}'.format(name=name, actor=actor) @@ -98,14 +99,17 @@ class OperationTask(BaseTask): :param instance: the node of which this operation belongs to. :param name: the name of the operation. """ - assert isinstance(instance, model.NodeInstance) - return cls._instance(instance=instance, - name=name, - operation_details=instance.node.operations[name], - inputs=inputs, - plugins=instance.node.plugins or [], - *args, - **kwargs) + assert isinstance(instance, models.Node) + interface_template = \ + instance.node_template.interface_templates.filter_by(name=name.rsplit('.', 1)[0])[0] + return cls._instance( + instance=instance, + name=name, + operation_template=interface_template.operation_templates.filter_by(name=name)[0], + inputs=inputs, + plugins=instance.node_template.plugins or [], + *args, + **kwargs) @classmethod def relationship_instance(cls, instance, name, operation_end, inputs=None, *args, **kwargs): @@ -130,18 +134,17 @@ class OperationTask(BaseTask): plugins = instance.relationship.target_node.plugins return cls._instance(instance=instance, name=name, - operation_details=operation_details, + operation_template=operation_details, inputs=inputs, plugins=plugins or [], *args, **kwargs) @classmethod - def _instance(cls, instance, name, operation_details, inputs, plugins, *args, **kwargs): - operation_mapping = operation_details.get('operation') - operation_inputs = operation_details.get('inputs', {}) - operation_inputs.update(inputs or {}) - plugin_name = operation_details.get('plugin') + def _instance(cls, instance, name, operation_template, inputs, plugins, *args, **kwargs): + operation_mapping = operation_template.operation + operation_template.inputs = inputs + plugin_name = operation_template.plugin matching_plugins = [p for p in plugins if p['name'] == plugin_name] # All matching plugins should have identical package_name/package_version, so it's safe to # take the first found. @@ -149,7 +152,7 @@ class OperationTask(BaseTask): return cls(actor=instance, name=name, operation_mapping=operation_mapping, - inputs=operation_inputs, + inputs=operation_template.inputs, plugin=plugin, *args, **kwargs)
