ariatosca-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From emblempar...@apache.org
Subject [25/28] incubator-ariatosca git commit: wip
Date Tue, 04 Jul 2017 00:47:21 GMT
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/be359a72
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/be359a72
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/be359a72

Branch: refs/heads/ARIA-254-multiple-nodes-per-template
Commit: be359a720206093a13167018a8ea240065659f86
Parents: 8d14329
Author: Tal Liron <tal.liron@gmail.com>
Authored: Tue Jun 13 14:50:17 2017 -0500
Committer: Tal Liron <tal.liron@gmail.com>
Committed: Mon Jul 3 19:46:32 2017 -0500

----------------------------------------------------------------------
 aria/modeling/service_template.py               | 62 +++++++++++++++-----
 aria/parser/presentation/presentation.py        | 12 +++-
 .../profiles/aria-1.0/aria-1.0.yaml             | 23 ++++++--
 .../profiles/tosca-simple-1.0/capabilities.yaml |  1 +
 .../simple_v1_0/modeling/capabilities.py        | 15 +++--
 .../node-cellar/node-cellar.yaml                | 20 ++++---
 6 files changed, 99 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/be359a72/aria/modeling/service_template.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_template.py b/aria/modeling/service_template.py
index a28cd23..4e9842c 100644
--- a/aria/modeling/service_template.py
+++ b/aria/modeling/service_template.py
@@ -359,7 +359,8 @@ class ServiceTemplateBase(TemplateModelMixin):
         utils.instantiate_dict(self, service.meta_data, self.meta_data)
 
         for node_template in self.node_templates.itervalues():
-            for _ in range(node_template.default_instances):
+            print 'scaling', node_template.name, node_template.scaling['default_instances']

+            for _ in range(node_template.scaling['default_instances']):
                 node = node_template.instantiate(container)
                 service.nodes[node.name] = node
 
@@ -666,12 +667,6 @@ class NodeTemplateBase(TemplateModelMixin):
             console.puts(context.style.meta(self.description))
         with context.style.indent:
             console.puts('Type: {0}'.format(context.style.type(self.type.name)))
-            console.puts('Instances: {0:d} ({1:d}{2})'.format(
-                self.default_instances,
-                self.min_instances,
-                ' to {0:d}'.format(self.max_instances)
-                if self.max_instances is not None
-                else ' or more'))
             utils.dump_dict_values(self.properties, 'Properties')
             utils.dump_dict_values(self.attributes, 'Attributes')
             utils.dump_interfaces(self.interface_templates)
@@ -705,18 +700,53 @@ class NodeTemplateBase(TemplateModelMixin):
         return '{name}_{index}'.format(name=self.name, index=self.next_index)
 
     @property
-    def default_instances(self):
-        # TODO: currently finds the first matching policy; but we should emit a validation
error
-        # if more than one policy applies to the same node
+    def scaling(self):
+        scaling = {
+           'min_instances': 0,
+           'max_instances': 1,
+           'default_instances': 1}
+
+        def extract_property(properties, name):
+            prop = properties.get(name)
+            if (prop is not None) and (prop.type_name == 'integer') and (prop.value is not
None):
+                scaling[name] = prop.value
+
+        def extract_properties(properties):
+            extract_property(properties, 'min_instances')
+            extract_property(properties, 'max_instances')
+            extract_property(properties, 'default_instances')
+
+        # TODO: currently finds the first matches capability or policy; but we should emit
a
+        # validation error if more than one applies to the same node
+
+        # From our scaling capabilities
+        for capability_template in self.capability_templates.itervalues():
+            if capability_template.type.role == 'scaling':
+                extract_properties(capability_template.properties)
+
+        # From service scaling policies (will override capabilities)
         for policy_template in self.service_template.policy_templates.itervalues():
             if policy_template.type.role == 'scaling':
                 if policy_template.is_for_node_template(self.name):
-                    default_instances = policy_template.properties.get('default_instances')
-                    if (default_instances is not None) \
-                        and (default_instances.type_name == 'integer'):
-                        return default_instances.value
-                    break
-        return 1
+                    extract_properties(policy_template.properties)
+
+        # Validate
+        if (scaling['min_instances'] < 0) or \
+            (scaling['max_instances'] < 0) or \
+            (scaling['default_instances'] < 0) or \
+            (scaling['max_instances'] < scaling['min_instances']) or \
+            (scaling['default_instances'] < scaling['min_instances']) or \
+            (scaling['default_instances'] > scaling['max_instances']):
+            context = ConsumptionContext.get_thread_local()
+            context.validation.report('invalid scaling parameters for node template "{0}":
'
+                                      'min={1}, max={2}, default={3}'.format(
+                                          self.name,
+                                          scaling['min_instances'],
+                                          scaling['max_instances'],
+                                          scaling['default_instances']),
+                                      level=validation.Issue.BETWEEN_TYPES)
+
+        return scaling
 
     def is_target_node_template_valid(self, target_node_template):
         """

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/be359a72/aria/parser/presentation/presentation.py
----------------------------------------------------------------------
diff --git a/aria/parser/presentation/presentation.py b/aria/parser/presentation/presentation.py
index 7292562..fe55b05 100644
--- a/aria/parser/presentation/presentation.py
+++ b/aria/parser/presentation/presentation.py
@@ -34,6 +34,14 @@ class Value(object):
         self.value = deepcopy_with_locators(value)
         self.description = deepcopy_with_locators(description)
 
+    def _dump(self, context):
+        if self.type is not None:
+            puts(context.style.type(self.type))
+        if self.value is not None:
+            puts(context.style.literal(self.value))
+        if self.description is not None:
+            puts(context.style.meta(self.description))
+
 
 class PresentationBase(HasCachedMethods):
     """
@@ -230,6 +238,8 @@ class AsIsPresentation(PresentationBase):
 
     def _dump(self, context):
         if hasattr(self._raw, '_dump'):
-            self._raw._dump(context)
+            puts(context.style.node(self._name))
+            with context.style.indent:
+                self._raw._dump(context)
         else:
             super(AsIsPresentation, self)._dump(context)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/be359a72/extensions/aria_extension_tosca/profiles/aria-1.0/aria-1.0.yaml
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/profiles/aria-1.0/aria-1.0.yaml b/extensions/aria_extension_tosca/profiles/aria-1.0/aria-1.0.yaml
index 71d6e8e..d7b0c61 100644
--- a/extensions/aria_extension_tosca/profiles/aria-1.0/aria-1.0.yaml
+++ b/extensions/aria_extension_tosca/profiles/aria-1.0/aria-1.0.yaml
@@ -67,18 +67,29 @@ policy_types:
       Scaling.
     derived_from: tosca.policies.Scaling
     properties:
-      default_instances:
+      min_instances:
+        description: >-
+          This property is used to indicate the minimum number of instances that should be
created
+          for the associated TOSCA Node Template by a TOSCA orchestrator.
         type: integer
         default: 1
         constraints:
           - greater_or_equal: 0
-      min_instances:
+      max_instances:
+        description: >-
+          This property is used to indicate the maximum number of instances that should be
created
+          for the associated TOSCA Node Template by a TOSCA orchestrator.
         type: integer
-        default: 0
+        default: 1
         constraints:
           - greater_or_equal: 0
-      max_instances:
+      default_instances:
+        description: >-
+          An optional property that indicates the requested default number of instances that
should
+          be the starting number of instances a TOSCA orchestrator should attempt to allocate.
Note:
+          The value for this property MUST be in the range between the values set for
+          "min_instances" and "max_instances" properties.
         type: integer
-        default: -1
         constraints:
-          - greater_or_equal: -1
+          - greater_or_equal: 0
+        required: false

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/be359a72/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/capabilities.yaml
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/capabilities.yaml b/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/capabilities.yaml
index 30abe10..b705d47 100644
--- a/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/capabilities.yaml
+++ b/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/capabilities.yaml
@@ -132,6 +132,7 @@ capability_types:
       specification: tosca-simple-1.0
       specification_section: 5.4.10
       specification_url: 'http://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html#DEFN_TYPE_CAPABILITIES_SCALABLE'
+      role: scaling
     description: >-
       This is the default TOSCA type that should be used to express a scalability capability
for a node.
     derived_from: tosca.capabilities.Root

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/be359a72/extensions/aria_extension_tosca/simple_v1_0/modeling/capabilities.py
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/capabilities.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/capabilities.py
index d75e723..c86563a 100644
--- a/extensions/aria_extension_tosca/simple_v1_0/modeling/capabilities.py
+++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/capabilities.py
@@ -71,8 +71,8 @@ def get_inherited_capability_definitions(context, presentation, for_presentation
                 type2 = our_capability_definition.type
                 if type1 != type2:
                     context.validation.report(
-                        'capability definition changes type from "%s" to "%s" in "%s"'
-                        % (type1, type2, presentation._fullname),
+                        'capability definition changes type from "{0}" to "{1}" in "{2}"'
+                        .format(type1, type2, presentation._fullname),
                         locator=our_capability_definition._locator, level=Issue.BETWEEN_TYPES)
 
                 # Already cloned?
@@ -133,12 +133,19 @@ def get_template_capabilities(context, presentation):
                 values = get_assigned_and_defined_parameter_values(context,
                                                                    our_capability_assignment,
                                                                    'property')
+
+                print presentation._name
+                print 'our', [(k, v.value) for k, v in our_capability_assignment.properties.iteritems()]
+                print 'ass', [(k, v.value.value) for k, v in capability_assignment.properties.iteritems()]
+                print 'val', [(k, v.value) for k, v in values.iteritems()]
+                
                 if values:
                     capability_assignment._raw['properties'] = values
+                    capability_assignment._reset_method_cache()
             else:
                 context.validation.report(
-                    'capability "%s" not declared at node type "%s" in "%s"'
-                    % (capability_name, presentation.type, presentation._fullname),
+                    'capability "{0}" not declared at node type "{1}" in "{2}"'
+                    .format(capability_name, presentation.type, presentation._fullname),
                     locator=our_capability_assignment._locator, level=Issue.BETWEEN_TYPES)
 
     return capability_assignments

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/be359a72/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml
----------------------------------------------------------------------
diff --git a/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml
b/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml
index e130b13..de57d3c 100644
--- a/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml
+++ b/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml
@@ -201,6 +201,11 @@ topology_template:
         os_users: # map of os.UserInfo
           root:
             password: admin123
+      capabilities:
+        scalable: # will be overriden by policy
+          properties:
+            max_instances: 5
+            default_instances: 3
       interfaces:
         Standard:
           inputs:
@@ -273,13 +278,14 @@ topology_template:
 
   policies:
   
-    scaling:
-      type: openstack.Scaling
-      properties:
-        bandwidth_threshold: 2 GB
-        default_instances: 2
-      targets: # node templates or groups
-        - node_cellar_group
+#    scaling:
+#      type: openstack.Scaling
+#      properties:
+#        bandwidth_threshold: 2 GB
+#        max_instances: 2
+#        default_instances: 2
+#      targets: # node templates or groups
+#        - node_cellar_group
     
     juju:
       description: >-


Mime
View raw message