ariatosca-dev 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 #72: ARIA-105 integrate modeling
Date Wed, 08 Mar 2017 15:00:05 GMT
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/72#discussion_r104934167
  
    --- Diff: aria/modeling/service_template.py ---
    @@ -0,0 +1,1693 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +# pylint: disable=too-many-lines, no-self-argument, no-member, abstract-method
    +
    +from __future__ import absolute_import  # so we can import standard 'types'
    +
    +from types import FunctionType
    +from datetime import datetime
    +
    +from sqlalchemy import (
    +    Column,
    +    Text,
    +    Integer,
    +    DateTime
    +)
    +from sqlalchemy.ext.declarative import declared_attr
    +
    +from ..parser import validation
    +from ..utils import collections, formatting, console
    +from .bases import TemplateModelMixin
    +from . import (
    +    utils,
    +    types as modeling_types
    +)
    +
    +
    +class ServiceTemplateBase(TemplateModelMixin):
    +    """
    +    A service template is a source for creating :class:`Service` instances.
    +
    +    It is usually created by various DSL parsers, such as ARIA's TOSCA extension. However,
it can
    +    also be created programmatically.
    +
    +    :ivar name: Name (unique for this ARIA installation)
    +    :vartype name: basestring
    +    :ivar description: Human-readable description
    +    :vartype description: basestring
    +    :ivar main_file_name: Filename of CSAR or YAML file from which this service template
was parsed
    +    :vartype main_file_name: basestring
    +    :ivar meta_data: Custom annotations
    +    :vartype meta_data: {basestring: :class:`Metadata`}
    +    :ivar node_templates: Templates for creating nodes
    +    :vartype node_templates: [:class:`NodeTemplate`]
    +    :ivar group_templates: Templates for creating groups
    +    :vartype group_templates: [:class:`GroupTemplate`]
    +    :ivar policy_templates: Templates for creating policies
    +    :vartype policy_templates: [:class:`PolicyTemplate`]
    +    :ivar substitution_template: The entire service can appear as a node
    +    :vartype substitution_template: :class:`SubstitutionTemplate`
    +    :ivar inputs: Externally provided parameters
    +    :vartype inputs: {basestring: :class:`Parameter`}
    +    :ivar outputs: These parameters are filled in after service installation
    +    :vartype outputs: {basestring: :class:`Parameter`}
    +    :ivar operation_templates: Custom operations that can be performed on the service
    +    :vartype operation_templates: {basestring: :class:`OperationTemplate`}
    +    :ivar plugins: Plugins required by services
    +    :vartype plugins: {basestring: :class:`Plugin`}
    +    :ivar node_types: Base for the node type hierarchy
    +    :vartype node_types: :class:`Type`
    +    :ivar group_types: Base for the group type hierarchy
    +    :vartype group_types: :class:`Type`
    +    :ivar policy_types: Base for the policy type hierarchy
    +    :vartype policy_types: :class:`Type`
    +    :ivar relationship_types: Base for the relationship type hierarchy
    +    :vartype relationship_types: :class:`Type`
    +    :ivar capability_types: Base for the capability type hierarchy
    +    :vartype capability_types: :class:`Type`
    +    :ivar interface_types: Base for the interface type hierarchy
    +    :vartype interface_types: :class:`Type`
    +    :ivar artifact_types: Base for the artifact type hierarchy
    +    :vartype artifact_types: :class:`Type`
    +    :ivar plugins: Plugins required to be installed
    +    :vartype plugins: {basestring: :class:`Plugin`}
    +    :ivar created_at: Creation timestamp
    +    :vartype created_at: :class:`datetime.datetime`
    +    :ivar updated_at: Update timestamp
    +    :vartype updated_at: :class:`datetime.datetime`
    +
    +    :ivar services: Instantiated services
    +    :vartype services: [:class:`Service`]
    +    """
    +
    +    __tablename__ = 'service_template'
    +
    +    description = Column(Text)
    +    main_file_name = Column(Text)
    +
    +    @declared_attr
    +    def meta_data(cls):
    +        # Warning! We cannot use the attr name "metadata" because it's used by SqlAlchemy!
    +        return cls.many_to_many_relationship('metadata', dict_key='name')
    +
    +    @declared_attr
    +    def node_templates(cls):
    +        return cls.one_to_many_relationship('node_template')
    +
    +    @declared_attr
    +    def group_templates(cls):
    +        return cls.one_to_many_relationship('group_template')
    +
    +    @declared_attr
    +    def policy_templates(cls):
    +        return cls.one_to_many_relationship('policy_template')
    +
    +    @declared_attr
    +    def substitution_template(cls):
    +        return cls.one_to_one_relationship('substitution_template')
    +
    +    @declared_attr
    +    def inputs(cls):
    +        return cls.many_to_many_relationship('parameter', table_prefix='inputs',
    +                                             dict_key='name')
    +
    +    @declared_attr
    +    def outputs(cls):
    +        return cls.many_to_many_relationship('parameter', table_prefix='outputs',
    +                                             dict_key='name')
    +
    +    @declared_attr
    +    def operation_templates(cls):
    +        return cls.one_to_many_relationship('operation_template', dict_key='name')
    +
    +    @declared_attr
    +    def plugins(cls):
    +        return cls.one_to_many_relationship('plugin')
    +
    +    @declared_attr
    +    def node_types(cls):
    +        return cls.one_to_one_relationship('type', key='node_type_fk', backreference='')
    +
    +    @declared_attr
    +    def group_types(cls):
    +        return cls.one_to_one_relationship('type', key='group_type_fk', backreference='')
    +
    +    @declared_attr
    +    def policy_types(cls):
    +        return cls.one_to_one_relationship('type', key='policy_type_fk', backreference='')
    +
    +    @declared_attr
    +    def relationship_types(cls):
    +        return cls.one_to_one_relationship('type', key='relationship_type_fk', backreference='')
    +
    +    @declared_attr
    +    def capability_types(cls):
    +        return cls.one_to_one_relationship('type', key='capability_type_fk', backreference='')
    +
    +    @declared_attr
    +    def interface_types(cls):
    +        return cls.one_to_one_relationship('type', key='interface_type_fk', backreference='')
    +
    +    @declared_attr
    +    def artifact_types(cls):
    +        return cls.one_to_one_relationship('type', key='artifact_type_fk', backreference='')
    +
    +    # region orchestration
    +
    +    created_at = Column(DateTime, nullable=False, index=True)
    +    updated_at = Column(DateTime)
    +
    +    # endregion
    +
    +    # region foreign keys
    +
    +    __private_fields__ = ['substitution_template_fk',
    +                          'node_type_fk',
    +                          'group_type_fk',
    +                          'policy_type_fk',
    +                          'relationship_type_fk',
    +                          'capability_type_fk',
    +                          'interface_type_fk',
    +                          'artifact_type_fk']
    +
    +    # ServiceTemplate one-to-one to SubstitutionTemplate
    +    @declared_attr
    +    def substitution_template_fk(cls):
    +        return cls.foreign_key('substitution_template', nullable=True)
    +
    +    # ServiceTemplate one-to-one to Type
    +    @declared_attr
    +    def node_type_fk(cls):
    +        return cls.foreign_key('type', nullable=True)
    +
    +    # ServiceTemplate one-to-one to Type
    +    @declared_attr
    +    def group_type_fk(cls):
    +        return cls.foreign_key('type', nullable=True)
    +
    +    # ServiceTemplate one-to-one to Type
    +    @declared_attr
    +    def policy_type_fk(cls):
    +        return cls.foreign_key('type', nullable=True)
    +
    +    # ServiceTemplate one-to-one to Type
    +    @declared_attr
    +    def relationship_type_fk(cls):
    +        return cls.foreign_key('type', nullable=True)
    +
    +    # ServiceTemplate one-to-one to Type
    +    @declared_attr
    +    def capability_type_fk(cls):
    +        return cls.foreign_key('type', nullable=True)
    +
    +    # ServiceTemplate one-to-one to Type
    +    @declared_attr
    +    def interface_type_fk(cls):
    +        return cls.foreign_key('type', nullable=True)
    +
    +    # ServiceTemplate one-to-one to Type
    +    @declared_attr
    +    def artifact_type_fk(cls):
    +        return cls.foreign_key('type', nullable=True)
    +
    +    # endregion
    +
    +    def get_node_template(self, node_template_name):
    +        if self.node_templates:
    +            for node_template in self.node_templates:
    +                if node_template.name == node_template_name:
    +                    return node_template
    +        return None
    +
    +    def get_group_template(self, group_template_name):
    +        if self.group_templates:
    +            for group_template in self.group_templates:
    +                if group_template.name == group_template_name:
    +                    return group_template
    +        return None
    +
    +    @property
    +    def as_raw(self):
    +        return collections.OrderedDict((
    +            ('description', self.description),
    +            ('metadata', formatting.as_raw_dict(self.meta_data)),
    +            ('node_templates', formatting.as_raw_list(self.node_templates)),
    +            ('group_templates', formatting.as_raw_list(self.group_templates)),
    +            ('policy_templates', formatting.as_raw_list(self.policy_templates)),
    +            ('substitution_template', formatting.as_raw(self.substitution_template)),
    +            ('inputs', formatting.as_raw_dict(self.inputs)),
    +            ('outputs', formatting.as_raw_dict(self.outputs)),
    +            ('operation_templates', formatting.as_raw_list(self.operation_templates))))
    +
    +    @property
    +    def types_as_raw(self):
    --- End diff --
    
    is this really needed?


---
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