ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tliron <...@git.apache.org>
Subject [GitHub] incubator-ariatosca pull request #60: Aria 44 merge parser and storage model...
Date Sun, 05 Feb 2017 17:40:11 GMT
Github user tliron commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/60#discussion_r99494748
  
    --- Diff: aria/parser/modeling/storage.py ---
    @@ -0,0 +1,184 @@
    +# 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.
    +
    +"""
    +This solution is temporary, as we plan to combine aria.parser.modeling and aria.storage.modeling
    +into one package (aria.modeling?).
    +"""
    +
    +from datetime import datetime
    +from threading import RLock
    +
    +from ...storage.modeling import model
    +from ...orchestrator.decorators import operation
    +from ...utils.console import puts, Colored
    +from ...utils.formatting import safe_repr
    +
    +
    +def initialize_storage(context, model_storage, service_instance_id):
    +    s_service_template = create_service_template(context)
    +    model_storage.service_template.put(s_service_template)
    +
    +    s_service_instance = create_service_instance(context, s_service_template, service_instance_id)
    +    model_storage.service_instance.put(s_service_instance)
    +
    +    # Create nodes templates and nodes
    +    for node_template in context.modeling.model.node_templates.itervalues():
    +        s_node_template = create_node_template(s_service_template, node_template)
    +        model_storage.node_template.put(s_node_template)
    +
    +        for node in context.modeling.instance.find_nodes(node_template.name):
    +            s_node = create_node(s_service_instance, s_node_template, node)
    +            model_storage.node.put(s_node)
    +            create_interfaces(context, model_storage, node.interfaces, s_node, 'node',
'_dry_node')
    +
    +    # Create relationships between nodes
    +    for source_node in context.modeling.instance.nodes.itervalues():
    +        for relationship in source_node.relationships:
    +            s_source_node = model_storage.node.get_by_name(source_node.id)
    +            s_target_node = model_storage.node.get_by_name(relationship.target_node_id)
    +            s_relationship = create_relationship(s_source_node, s_target_node)
    +            model_storage.relationship.put(s_relationship)
    +            create_interfaces(context, model_storage, relationship.source_interfaces,
    +                              s_relationship, 'relationship', '_dry_relationship')
    +
    +
    +def create_service_template(context):
    +    now = datetime.utcnow()
    +    main_file_name = unicode(context.presentation.location)
    +    try:
    +        name = context.modeling.model.metadata.values.get('template_name')
    +    except AttributeError:
    +        name = None
    +    return model.ServiceTemplate(
    +        name=name or main_file_name,
    +        description=context.modeling.model.description or '',
    +        created_at=now,
    +        updated_at=now,
    +        main_file_name=main_file_name)
    +
    +
    +def create_service_instance(context, service_template, service_instance_id):
    +    now = datetime.utcnow()
    +    return model.ServiceInstance(
    +        name='%s_%s' % (service_template.name, service_instance_id),
    +        service_template=service_template,
    +        description=context.modeling.instance.description or '',
    +        created_at=now,
    +        updated_at=now)
    +
    +
    +def create_node_template(service_template, node_template):
    +    return model.NodeTemplate(
    +        name=node_template.name,
    +        type_name=node_template.type_name,
    +        default_instances=node_template.default_instances,
    +        min_instances=node_template.min_instances,
    +        max_instances=node_template.max_instances or 100,
    +        service_template=service_template)
    +
    +
    +def create_node(service_instance, node_template, node):
    +    return model.Node(
    +        name=node.id,
    +        state='',
    +        node_template=node_template,
    +        service_instance=service_instance)
    +
    +
    +def create_relationship(source_node, target_node):
    +    return model.Relationship(
    +        source_node=source_node,
    +        target_node=target_node)
    +
    +
    +def create_interfaces(context, model_storage, interfaces, obj, attr_name, fn_name):
    +    for interface_name, interface in interfaces.iteritems():
    +        s_interface = model.Interface(name=interface_name,
    +                                      type_name=interface.type_name)
    +        setattr(s_interface, attr_name, obj)
    +        try:
    +            obj.source_interfaces.append(s_interface)
    +        except AttributeError:
    +            # is a node
    --- End diff --
    
    If it's a node it just doesn't have this extra constraint. Line #111 would be enough.


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