ariatosca-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxmrlv <...@git.apache.org>
Subject [GitHub] incubator-ariatosca pull request #143: ARIA-254 Create multiple nodes per te...
Date Thu, 06 Jul 2017 09:34:46 GMT
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/143#discussion_r125852641
  
    --- Diff: aria/modeling/service_template.py ---
    @@ -690,19 +666,104 @@ def dump(self):
                 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)
                 utils.dump_dict_values(self.artifact_templates, 'Artifact templates')
                 utils.dump_dict_values(self.capability_templates, 'Capability templates')
                 utils.dump_list_values(self.requirement_templates, 'Requirement templates')
     
    +    @property
    +    def next_index(self):
    +        """
    +        Next available node index.
    +
    +        :returns: node index
    +        :rtype: int
    +        """
    +
    +        max_index = 0
    +        if self.nodes:
    +            max_index = max(int(n.name.rsplit('_', 1)[-1]) for n in self.nodes)
    +        return max_index + 1
    +
    +    @property
    +    def next_name(self):
    +        """
    +        Next available node name.
    +
    +        :returns: node name
    +        :rtype: basestring
    +        """
    +
    +        return '{name}_{index}'.format(name=self.name, index=self.next_index)
    +
    +    @property
    +    def scaling(self):
    +        scaling = {}
    +
    +        def extract_property(properties, name):
    +            if name in scaling:
    +                return
    +            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')
    +
    +        def default_property(name, value):
    +            if name not in scaling:
    +                scaling[name] = value
    +
    +        # 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
    +        for policy_template in self.service_template.policy_templates.itervalues():
    --- End diff --
    
    Oh, didn't notice it. I would think that there is not real need to check, just override
the inherited properties. But this is my personal preference 


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message