Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-139-attributes c42bb4032 -> 309cedb16


Fixes to relationships and test cases

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

Branch: refs/heads/ARIA-139-attributes
Commit: 309cedb1647eb290374ccb9c33ac020a038b83da
Parents: c42bb40
Author: Tal Liron <[email protected]>
Authored: Mon May 1 17:00:54 2017 -0500
Committer: Tal Liron <[email protected]>
Committed: Mon May 1 17:00:54 2017 -0500

----------------------------------------------------------------------
 aria/modeling/functions.py                      | 11 ++++++-
 aria/modeling/relationship.py                   | 19 +++++++++----
 aria/modeling/service_template.py               | 18 ++++++------
 .../block-storage-1/block-storage-1.yaml        |  2 +-
 .../block-storage-2/block-storage-2.yaml        |  2 +-
 .../block-storage-3/block-storage-3.yaml        |  2 +-
 .../block-storage-4/block-storage-4.yaml        |  2 +-
 .../block-storage-5/block-storage-5.yaml        |  6 ++--
 .../block-storage-6/block-storage-6.yaml        |  4 +--
 .../use-cases/multi-tier-1/multi-tier-1.yaml    | 14 ++++-----
 .../simple_v1_0/modeling/__init__.py            | 30 +++++++++-----------
 11 files changed, 61 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/309cedb1/aria/modeling/functions.py
----------------------------------------------------------------------
diff --git a/aria/modeling/functions.py b/aria/modeling/functions.py
index e736144..7c773ed 100644
--- a/aria/modeling/functions.py
+++ b/aria/modeling/functions.py
@@ -58,7 +58,16 @@ class Evaluation(object):
 
 
 class NodeTemplateConstraint(object):
-    def apply(self, target_node_template, source_node_template):
+    """
+    Used to constrain requirements for node templates.
+
+    Must be serializable.
+    """
+
+    def matches(self, source_node_template, target_node_template):
+        """
+        Returns true is the target matches the constraint for the source.
+        """
         raise NotImplementedError
 
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/309cedb1/aria/modeling/relationship.py
----------------------------------------------------------------------
diff --git a/aria/modeling/relationship.py b/aria/modeling/relationship.py
index e6830b8..c2ef6b6 100644
--- a/aria/modeling/relationship.py
+++ b/aria/modeling/relationship.py
@@ -147,13 +147,18 @@ def one_to_one(model_class,
                        false to disable
     :type back_populates: basestring|bool
     """
-    if back_populates is None:
-        back_populates = model_class.__tablename__
+    backref_kwargs = None
+    if back_populates is not NO_BACK_POP:
+        if back_populates is None:
+            back_populates = model_class.__tablename__
+        backref_kwargs = {'name': back_populates, 'uselist': False}
+        back_populates = None
 
     return _relationship(model_class,
                          other_table,
                          fk=fk,
                          back_populates=back_populates,
+                         backref_kwargs=backref_kwargs,
                          other_fk=other_fk)
 
 
@@ -188,6 +193,7 @@ def one_to_many(model_class,
     """
     if back_populates is None:
         back_populates = model_class.__tablename__
+
     return _relationship(
         model_class,
         child_table,
@@ -328,10 +334,11 @@ def _relationship(model_class,
 
     if backref_kwargs:
         assert back_populates is None
-        return relationship(lambda: _get_class_for_table(model_class, 
other_table_name),
-                            backref=backref(**backref_kwargs),
-                            **relationship_kwargs
-                           )
+        return relationship(
+            lambda: _get_class_for_table(model_class, other_table_name),
+            backref=backref(**backref_kwargs),
+            **relationship_kwargs
+        )
     else:
         if back_populates is not NO_BACK_POP:
             relationship_kwargs['back_populates'] = back_populates

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/309cedb1/aria/modeling/service_template.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_template.py 
b/aria/modeling/service_template.py
index 5e1c7a5..1cbd539 100644
--- a/aria/modeling/service_template.py
+++ b/aria/modeling/service_template.py
@@ -530,10 +530,10 @@ class NodeTemplateBase(TemplateModelMixin):
     max_instances = Column(Integer, default=None)
     target_node_template_constraints = Column(PickleType)
 
-    def is_target_node_valid(self, target_node_template):
+    def is_target_node_template_valid(self, target_node_template):
         if self.target_node_template_constraints:
-            for node_type_constraint in self.target_node_template_constraints:
-                if not node_type_constraint.apply(target_node_template, self):
+            for node_template_constraint in 
self.target_node_template_constraints:
+                if not node_template_constraint.matches(self, 
target_node_template):
                     return False
         return True
 
@@ -1194,9 +1194,7 @@ class RequirementTemplateBase(TemplateModelMixin):
 
     @declared_attr
     def relationship_template(cls):
-        return relationship.one_to_one(cls,
-                                       'relationship_template',
-                                       back_populates=relationship.NO_BACK_POP)
+        return relationship.one_to_one(cls, 'relationship_template')
 
     # endregion
 
@@ -1233,7 +1231,7 @@ class RequirementTemplateBase(TemplateModelMixin):
 
         # We might already have a specific node template, so we'll just verify 
it
         if self.target_node_template is not None:
-            if not 
source_node_template.is_target_node_valid(self.target_node_template):
+            if not 
source_node_template.is_target_node_template_valid(self.target_node_template):
                 context.validation.report('requirement "{0}" of node template 
"{1}" is for node '
                                           'template "{2}" but it does not 
match constraints'.format(
                                               self.name,
@@ -1258,7 +1256,7 @@ class RequirementTemplateBase(TemplateModelMixin):
                 if 
self.target_node_type.get_descendant(target_node_template.type.name) is None:
                     continue
 
-                if not 
source_node_template.is_target_node_valid(target_node_template):
+                if not 
source_node_template.is_target_node_template_valid(target_node_template):
                     continue
 
                 target_node_capability = 
self.find_target_capability(source_node_template,
@@ -1554,8 +1552,8 @@ class CapabilityTemplateBase(TemplateModelMixin):
 
         # Apply requirement constraints
         if requirement.target_node_template_constraints:
-            for node_type_constraint in 
requirement.target_node_template_constraints:
-                if not node_type_constraint.apply(target_node_template, 
source_node_template):
+            for node_template_constraint in 
requirement.target_node_template_constraints:
+                if not node_template_constraint.matches(source_node_template, 
target_node_template):
                     return False
 
         return True

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/309cedb1/examples/tosca-simple-1.0/use-cases/block-storage-1/block-storage-1.yaml
----------------------------------------------------------------------
diff --git 
a/examples/tosca-simple-1.0/use-cases/block-storage-1/block-storage-1.yaml 
b/examples/tosca-simple-1.0/use-cases/block-storage-1/block-storage-1.yaml
index ff6dc92..b912fb2 100644
--- a/examples/tosca-simple-1.0/use-cases/block-storage-1/block-storage-1.yaml
+++ b/examples/tosca-simple-1.0/use-cases/block-storage-1/block-storage-1.yaml
@@ -65,4 +65,4 @@ topology_template:
       value: { get_attribute: [ my_server, private_address ] }
     volume_id:
       description: The volume id of the block storage instance.
-      value: { get_attribute: [ my_storage, volume_id ] }
+      value: { get_property: [ my_storage, volume_id ] } # ARIA NOTE: wrong in 
spec

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/309cedb1/examples/tosca-simple-1.0/use-cases/block-storage-2/block-storage-2.yaml
----------------------------------------------------------------------
diff --git 
a/examples/tosca-simple-1.0/use-cases/block-storage-2/block-storage-2.yaml 
b/examples/tosca-simple-1.0/use-cases/block-storage-2/block-storage-2.yaml
index 09c30a7..ac475cf 100644
--- a/examples/tosca-simple-1.0/use-cases/block-storage-2/block-storage-2.yaml
+++ b/examples/tosca-simple-1.0/use-cases/block-storage-2/block-storage-2.yaml
@@ -72,4 +72,4 @@ topology_template:
 
     volume_id:
       description: The volume id of the block storage instance.
-      value: { get_attribute: [ my_storage, volume_id ] }
+      value: { get_property: [ my_storage, volume_id ] } # ARIA NOTE: wrong in 
spec

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/309cedb1/examples/tosca-simple-1.0/use-cases/block-storage-3/block-storage-3.yaml
----------------------------------------------------------------------
diff --git 
a/examples/tosca-simple-1.0/use-cases/block-storage-3/block-storage-3.yaml 
b/examples/tosca-simple-1.0/use-cases/block-storage-3/block-storage-3.yaml
index 3018fe9..c3f183e 100644
--- a/examples/tosca-simple-1.0/use-cases/block-storage-3/block-storage-3.yaml
+++ b/examples/tosca-simple-1.0/use-cases/block-storage-3/block-storage-3.yaml
@@ -65,4 +65,4 @@ topology_template:
       value: { get_attribute: [ my_server, private_address ] }
     volume_id:
       description: The volume id of the block storage instance.
-      value: { get_attribute: [ my_storage, volume_id ] }
+      value: { get_property: [ my_storage, volume_id ] } # ARIA NOTE: wrong in 
spec

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/309cedb1/examples/tosca-simple-1.0/use-cases/block-storage-4/block-storage-4.yaml
----------------------------------------------------------------------
diff --git 
a/examples/tosca-simple-1.0/use-cases/block-storage-4/block-storage-4.yaml 
b/examples/tosca-simple-1.0/use-cases/block-storage-4/block-storage-4.yaml
index 0693ddd..e2bdb9f 100644
--- a/examples/tosca-simple-1.0/use-cases/block-storage-4/block-storage-4.yaml
+++ b/examples/tosca-simple-1.0/use-cases/block-storage-4/block-storage-4.yaml
@@ -93,4 +93,4 @@ topology_template:
       value: { get_attribute: [ my_web_app_tier_2, private_address ] }
     volume_id:
       description: The volume id of the block storage instance.
-      value: { get_attribute: [ my_storage, volume_id ] }
+      value: { get_property: [ my_storage, volume_id ] } # ARIA NOTE: wrong in 
spec

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/309cedb1/examples/tosca-simple-1.0/use-cases/block-storage-5/block-storage-5.yaml
----------------------------------------------------------------------
diff --git 
a/examples/tosca-simple-1.0/use-cases/block-storage-5/block-storage-5.yaml 
b/examples/tosca-simple-1.0/use-cases/block-storage-5/block-storage-5.yaml
index 5f5cf71..a0c2229 100644
--- a/examples/tosca-simple-1.0/use-cases/block-storage-5/block-storage-5.yaml
+++ b/examples/tosca-simple-1.0/use-cases/block-storage-5/block-storage-5.yaml
@@ -100,10 +100,10 @@ topology_template:
   outputs:
     private_ip_1:
       description: The private IP address of the application's first tier.
-      value: { get_attribute: [my_web_app_tier_1, private_address] }
+      value: { get_attribute: [ my_web_app_tier_1, private_address ] }
     private_ip_2:
       description: The private IP address of the application's second tier.
-      value: { get_attribute: [my_web_app_tier_2, private_address] }
+      value: { get_attribute: [ my_web_app_tier_2, private_address ] }
     volume_id:
       description: The volume id of the block storage instance.
-      value: { get_attribute: [my_storage, volume_id] }
+      value: { get_property: [ my_storage, volume_id ] } # ARIA NOTE: wrong in 
spec

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/309cedb1/examples/tosca-simple-1.0/use-cases/block-storage-6/block-storage-6.yaml
----------------------------------------------------------------------
diff --git 
a/examples/tosca-simple-1.0/use-cases/block-storage-6/block-storage-6.yaml 
b/examples/tosca-simple-1.0/use-cases/block-storage-6/block-storage-6.yaml
index 808245b..534884a 100644
--- a/examples/tosca-simple-1.0/use-cases/block-storage-6/block-storage-6.yaml
+++ b/examples/tosca-simple-1.0/use-cases/block-storage-6/block-storage-6.yaml
@@ -96,7 +96,7 @@ topology_template:
       value: { get_attribute: [ my_server2, private_address ] }
     volume_id_1:
       description: The volume id of the first block storage instance.
-      value: { get_attribute: [my_storage, volume_id] }
+      value: { get_property: [ my_storage, volume_id ] } # ARIA NOTE: wrong in 
spec
     volume_id_2:
       description: The volume id of the second block storage instance.
-      value: { get_attribute: [ my_storage2, volume_id ] }
+      value: { get_property: [ my_storage2, volume_id ] } # ARIA NOTE: wrong 
in spec

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/309cedb1/examples/tosca-simple-1.0/use-cases/multi-tier-1/multi-tier-1.yaml
----------------------------------------------------------------------
diff --git a/examples/tosca-simple-1.0/use-cases/multi-tier-1/multi-tier-1.yaml 
b/examples/tosca-simple-1.0/use-cases/multi-tier-1/multi-tier-1.yaml
index 3485e49..50401ec 100644
--- a/examples/tosca-simple-1.0/use-cases/multi-tier-1/multi-tier-1.yaml
+++ b/examples/tosca-simple-1.0/use-cases/multi-tier-1/multi-tier-1.yaml
@@ -59,7 +59,7 @@ topology_template:
              implementation: scripts/nodejs/configure.sh
              inputs:
                github_url: { get_property: [ SELF, github_url ] }
-               mongodb_ip: { get_attribute: [mongo_server, private_address] }
+               mongodb_ip: { get_attribute: [ mongo_server, private_address ] }
            start: scripts/nodejs/start.sh
 
     nodejs:
@@ -90,7 +90,7 @@ topology_template:
           configure:
             implementation: scripts/mongodb/config.sh
             inputs:
-              mongodb_ip: { get_attribute: [mongo_server, ip_address] }
+              mongodb_ip: { get_attribute: [ mongo_server, private_address ] } 
# ARIA NOTE: wrong in spec
           start: scripts/mongodb/start.sh
 
     elasticsearch:
@@ -115,7 +115,7 @@ topology_template:
                   pre_configure_source:
                     implementation: python/logstash/configure_elasticsearch.py
                     inputs:
-                      elasticsearch_ip: { get_attribute: 
[elasticsearch_server, ip_address] }
+                      elasticsearch_ip: { get_attribute: [ 
elasticsearch_server, private_address ] } # ARIA NOTE: wrong in spec
       interfaces:
         Standard: # ARIA NOTE: wrong in spec
           create: scripts/lostash/create.sh
@@ -133,8 +133,8 @@ topology_template:
           configure:
             implementation: scripts/kibana/config.sh
             inputs:
-              elasticsearch_ip: { get_attribute: [ elasticsearch_server, 
ip_address ] }
-              kibana_ip: { get_attribute: [ kibana_server, ip_address ] }
+              elasticsearch_ip: { get_attribute: [ elasticsearch_server, 
private_address ] } # ARIA NOTE: wrong in spec
+              kibana_ip: { get_attribute: [ kibana_server, private_address ] } 
# ARIA NOTE: wrong in spec
           start: scripts/kibana/start.sh
 
     app_collectd:
@@ -155,7 +155,7 @@ topology_template:
           configure:
             implementation: python/collectd/config.py
             inputs:
-              logstash_ip: { get_attribute: [ logstash_server, ip_address ] }
+              logstash_ip: { get_attribute: [ logstash_server, private_address 
] } # ARIA NOTE: wrong in spec
           start: scripts/collectd/start.sh
 
     app_rsyslog:
@@ -176,7 +176,7 @@ topology_template:
           configure:
             implementation: scripts/rsyslog/config.sh
             inputs:
-              logstash_ip: { get_attribute: [ logstash_server, ip_address ] }
+              logstash_ip: { get_attribute: [ logstash_server, private_address 
] } # ARIA NOTE: wrong in spec
           start: scripts/rsyslog/start.sh
 
     app_server:

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/309cedb1/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py 
b/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py
index 9c830d9..add0766 100644
--- a/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py
+++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py
@@ -185,7 +185,7 @@ def create_node_template_model(context, service_template, 
node_template):
 
     if node_template.node_filter:
         model.target_node_template_constraints = []
-        create_node_filter_constraint_filters(context, 
node_template.node_filter,
+        create_node_filter_constraints(context, node_template.node_filter,
                                               
model.target_node_template_constraints)
 
     return model
@@ -277,7 +277,7 @@ def create_requirement_template_model(context, 
service_template, requirement):
 
     if requirement.node_filter:
         model.target_node_template_constraints = []
-        create_node_filter_constraint_filters(context, requirement.node_filter,
+        create_node_filter_constraints(context, requirement.node_filter,
                                               
model.target_node_template_constraints)
 
     relationship = requirement.relationship
@@ -561,14 +561,13 @@ def create_interface_template_models(context, 
service_template, interfaces, sour
                 interfaces[interface_name] = interface
 
 
-def create_node_filter_constraint_filters(context, node_filter, 
target_node_template_constraints):
+def create_node_filter_constraints(context, node_filter, 
target_node_template_constraints):
     properties = node_filter.properties
     if properties is not None:
         for property_name, constraint_clause in properties:
-            func = create_constraint_clause_filter(context, node_filter, 
constraint_clause,
-                                                   property_name, None)
-            if func is not None:
-                target_node_template_constraints.append(func)
+            constraint = create_constraint(context, node_filter, 
constraint_clause, property_name,
+                                           None)
+            target_node_template_constraints.append(constraint)
 
     capabilities = node_filter.capabilities
     if capabilities is not None:
@@ -576,21 +575,20 @@ def create_node_filter_constraint_filters(context, 
node_filter, target_node_temp
             properties = capability.properties
             if properties is not None:
                 for property_name, constraint_clause in properties:
-                    func = create_constraint_clause_filter(context, 
node_filter, constraint_clause,
-                                                           property_name, 
capability_name)
-                    if func is not None:
-                        target_node_template_constraints.append(func)
+                    constraint = create_constraint(context, node_filter, 
constraint_clause,
+                                                   property_name, 
capability_name)
+                    target_node_template_constraints.append(constraint)
 
 
-def create_constraint_clause_filter(context, node_filter, constraint_clause, 
property_name, # pylint: disable=too-many-return-statements
-                                    capability_name):
+def create_constraint(context, node_filter, constraint_clause, property_name, 
capability_name): # pylint: disable=too-many-return-statements
     constraint_key = constraint_clause._raw.keys()[0]
 
     the_type = constraint_clause._get_type(context)
 
     def coerce_constraint(constraint):
         if the_type is not None:
-            return coerce_value(context, node_filter, the_type, None, None, 
constraint, constraint_key) 
+            return coerce_value(context, node_filter, the_type, None, None, 
constraint,
+                                constraint_key) 
         else:
             return constraint
 
@@ -617,10 +615,10 @@ def create_constraint_clause_filter(context, node_filter, 
constraint_clause, pro
                            coerce_constraint(constraint_clause.less_or_equal))
     elif constraint_key == 'in_range':
         return InRange(property_name, capability_name,
-                       coerce_constraints(constraint_clause.in_range), 
plural=True)
+                       coerce_constraints(constraint_clause.in_range))
     elif constraint_key == 'valid_values':
         return ValidValues(property_name, capability_name,
-                           coerce_constraints(constraint_clause.valid_values), 
plural=True)
+                           coerce_constraints(constraint_clause.valid_values))
     elif constraint_key == 'length':
         return Length(property_name, capability_name,
                       coerce_constraint(constraint_clause.length))

Reply via email to