Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B0EC2200C12 for ; Sun, 5 Feb 2017 13:06:32 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id AF826160B67; Sun, 5 Feb 2017 12:06:32 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E0FD2160B59 for ; Sun, 5 Feb 2017 13:06:31 +0100 (CET) Received: (qmail 38889 invoked by uid 500); 5 Feb 2017 12:06:31 -0000 Mailing-List: contact dev-help@ariatosca.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ariatosca.incubator.apache.org Delivered-To: mailing list dev@ariatosca.incubator.apache.org Received: (qmail 38834 invoked by uid 99); 5 Feb 2017 12:06:30 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Feb 2017 12:06:30 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 6579B1806E2 for ; Sun, 5 Feb 2017 12:06:30 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -7.019 X-Spam-Level: X-Spam-Status: No, score=-7.019 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id d8KKjBHGzJF3 for ; Sun, 5 Feb 2017 12:06:29 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 2BE705FC7B for ; Sun, 5 Feb 2017 12:06:28 +0000 (UTC) Received: (qmail 38693 invoked by uid 99); 5 Feb 2017 12:06:27 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Feb 2017 12:06:27 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3E08EE0045; Sun, 5 Feb 2017 12:06:27 +0000 (UTC) From: mxmrlv To: dev@ariatosca.incubator.apache.org Reply-To: dev@ariatosca.incubator.apache.org References: In-Reply-To: Subject: [GitHub] incubator-ariatosca pull request #60: Aria 44 merge parser and storage model... Content-Type: text/plain Message-Id: <20170205120627.3E08EE0045@git1-us-west.apache.org> Date: Sun, 5 Feb 2017 12:06:27 +0000 (UTC) archived-at: Sun, 05 Feb 2017 12:06:32 -0000 Github user mxmrlv commented on a diff in the pull request: https://github.com/apache/incubator-ariatosca/pull/60#discussion_r99487649 --- 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 -- no need to add the interface to the node's interfaces? --- 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. ---