ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxm...@apache.org
Subject incubator-ariatosca git commit: moved more things around
Date Mon, 30 Jan 2017 09:31:35 GMT
Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-44-Merge-parser-and-storage-models 7b4c35130 -> 4fb361305


moved more things around


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/4fb36130
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/4fb36130
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/4fb36130

Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models
Commit: 4fb3613050018d742957839193fea6b3a8d66b00
Parents: 7b4c351
Author: mxmrlv <mxmrlv@gmail.com>
Authored: Mon Jan 30 11:31:25 2017 +0200
Committer: mxmrlv <mxmrlv@gmail.com>
Committed: Mon Jan 30 11:31:25 2017 +0200

----------------------------------------------------------------------
 aria/parser/modeling/__init__.py                |   5 +-
 aria/parser/modeling/storage.py                 | 135 -------------------
 aria/parser/modeling/utils.py                   |   6 +-
 aria/storage/exceptions.py                      |   6 -
 aria/storage/modeling/elements.py               |   8 +-
 aria/storage/modeling/utils.py                  |  27 +---
 aria/storage_initializer.py                     | 135 +++++++++++++++++++
 .../simple_v1_0/modeling/data_types.py          |   4 +-
 8 files changed, 148 insertions(+), 178 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/4fb36130/aria/parser/modeling/__init__.py
----------------------------------------------------------------------
diff --git a/aria/parser/modeling/__init__.py b/aria/parser/modeling/__init__.py
index b8e1286..d507a26 100644
--- a/aria/parser/modeling/__init__.py
+++ b/aria/parser/modeling/__init__.py
@@ -23,7 +23,7 @@ from .model_elements import (ServiceModel, NodeTemplate, RequirementTemplate,
Ca
                              GroupPolicyTemplate, GroupPolicyTriggerTemplate, MappingTemplate,
                              SubstitutionTemplate, InterfaceTemplate, OperationTemplate)
 from .types import TypeHierarchy, Type, RelationshipType, PolicyType, PolicyTriggerType
-from .storage import initialize_storage
+from .exceptions import CannotEvaluateFunctionException
 
 __all__ = (
     'IdType',
@@ -65,4 +65,5 @@ __all__ = (
     'RelationshipType',
     'PolicyType',
     'PolicyTriggerType',
-    'initialize_storage')
+    'CannotEvaluateFunctionException'
+)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/4fb36130/aria/parser/modeling/storage.py
----------------------------------------------------------------------
diff --git a/aria/parser/modeling/storage.py b/aria/parser/modeling/storage.py
deleted file mode 100644
index 172fd98..0000000
--- a/aria/parser/modeling/storage.py
+++ /dev/null
@@ -1,135 +0,0 @@
-# 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.
-
-from datetime import datetime
-from threading import RLock
-
-from ...storage import model
-from ...orchestrator import operation
-from ...utils.console import puts, Colored
-from ...utils.formatting import safe_repr
-
-
-def initialize_storage(context, model_storage, deployment_id):
-    blueprint = create_blueprint(context)
-    model_storage.blueprint.put(blueprint)
-
-    deployment = create_deployment(context, blueprint, deployment_id)
-    model_storage.deployment.put(deployment)
-
-    # Create nodes and node instances
-    for node_template in context.modeling.model.node_templates.values():
-        model_storage.node_template.put(node_template)
-
-        for a_node in context.modeling.instance.find_nodes(node_template.name):
-            node = create_node_instance(deployment, node_template, a_node)
-            model_storage.node.put(node)
-
-    # Create relationships
-    for node_template in context.modeling.model.node_templates.values():
-        for index, requirement_template in enumerate(node_template.requirement_templates):
-            # We are currently limited only to requirements for specific node templates!
-            if requirement_template.target_node_template_name:
-                model_storage.requirement_template.put(requirement_template)
-
-                for node in context.modeling.instance.find_nodes(node_template.name):
-                    for relationship_model in node.relationships:
-                        if relationship_model.source_requirement_index == index:
-                            source_instance = \
-                                model_storage.node_instance.get_by_name(node.id)
-                            target_instance = \
-                                model_storage.node_instance.get_by_name(
-                                    relationship_model.target_node_id)
-                            relationship = \
-                                create_relationship_instance(source_instance, target_instance)
-                            model_storage.relationship.put(relationship)
-
-
-def create_blueprint(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(
-        plan={},
-        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_deployment(context, service_template, service_instance_id):
-    now = datetime.utcnow()
-    return model.ServiceInstance(
-        name='{0}_{1}'.format(service_template.name, service_instance_id),
-        service_template=service_template,
-        description=context.modeling.instance.description or '',
-        created_at=now,
-        updated_at=now,
-        workflows={},
-        permalink='',
-        policy_triggers={},
-        scaling_groups={}
-    )
-
-
-def create_node_instance(service_instance, node, node_model):
-    return model.Node(
-        service_instance=service_instance,
-        name=node_model.id,
-        runtime_properties={},
-        version=None,
-        node_template=node,
-        state='',
-        scaling_groups=[]
-    )
-
-
-def create_relationship_instance(source_instance, target_instance):
-    return model.Relationship(
-        source_node=source_instance,
-        target_node=target_instance
-    )
-
-
-_TERMINAL_LOCK = RLock()
-
-
-@operation
-def _dry_node(ctx, _plugin, _implementation, **kwargs):
-    with _TERMINAL_LOCK:
-        print '> node instance: %s' % Colored.red(ctx.node_instance.name)
-        _dump_implementation(_plugin, _implementation)
-
-
-@operation
-def _dry_relationship(ctx, _plugin, _implementation, **kwargs):
-    with _TERMINAL_LOCK:
-        puts('> relationship instance: %s -> %s' % (
-            Colored.red(ctx.relationship_instance.source_node_instance.name),
-            Colored.red(ctx.relationship_instance.target_node_instance.name)))
-        _dump_implementation(_plugin, _implementation)
-
-
-def _dump_implementation(plugin, implementation):
-    if plugin:
-        print '  plugin: %s' % Colored.magenta(plugin)
-    if implementation:
-        print '  implementation: %s' % Colored.yellow(safe_repr(implementation))

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/4fb36130/aria/parser/modeling/utils.py
----------------------------------------------------------------------
diff --git a/aria/parser/modeling/utils.py b/aria/parser/modeling/utils.py
index 1638604..21db433 100644
--- a/aria/parser/modeling/utils.py
+++ b/aria/parser/modeling/utils.py
@@ -21,7 +21,7 @@ from ...utils.collections import OrderedDict
 from ...utils.console import puts
 from ..exceptions import InvalidValueError
 from ..presentation import Value
-from ...storage.exceptions import CannotEvaluateFunctionException
+from .exceptions import CannotEvaluateFunctionException
 
 # UUID = ShortUUID() # default alphabet is base57, which is alphanumeric without visually
ambiguous
 # characters; ID length is 22
@@ -57,7 +57,7 @@ def coerce_value(context, container, value, report_issues=False):
         return [coerce_value(context, container, v, report_issues) for v in value]
     elif isinstance(value, dict):
         return OrderedDict((k, coerce_value(context, container, v, report_issues))
-                           for k, v in value.iteritems())
+                           for k, v in value.items())
     elif hasattr(value, '_evaluate'):
         try:
             value = value._evaluate(context, container)
@@ -73,7 +73,7 @@ def coerce_value(context, container, value, report_issues=False):
 def validate_dict_values(context, the_dict):
     if not the_dict:
         return
-    validate_list_values(context, the_dict.itervalues())
+    validate_list_values(context, the_dict.values())
 
 
 def validate_list_values(context, the_list):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/4fb36130/aria/storage/exceptions.py
----------------------------------------------------------------------
diff --git a/aria/storage/exceptions.py b/aria/storage/exceptions.py
index 6b69859..f982f63 100644
--- a/aria/storage/exceptions.py
+++ b/aria/storage/exceptions.py
@@ -23,9 +23,3 @@ class StorageError(exceptions.AriaError):
     General storage exception
     """
     pass
-
-
-class CannotEvaluateFunctionException(exceptions.AriaException):
-    """
-    ARIA modeling exception: cannot evaluate the function at this time.
-    """

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/4fb36130/aria/storage/modeling/elements.py
----------------------------------------------------------------------
diff --git a/aria/storage/modeling/elements.py b/aria/storage/modeling/elements.py
index b58e757..8c432f5 100644
--- a/aria/storage/modeling/elements.py
+++ b/aria/storage/modeling/elements.py
@@ -18,9 +18,9 @@ from sqlalchemy import (
     Text
 )
 
+from ...parser.modeling import utils
 from ...utils.collections import OrderedDict
 from ...utils.console import puts
-from .utils import coerce_value
 
 from . import structure
 from . import type
@@ -47,11 +47,11 @@ class ParameterBase(structure.ModelElementBase, structure.ModelMixin):
         return OrderedDict((
             ('name', self.name),
             ('type_name', self.type),
-            ('value', self._coerce_value()),
+            ('value', self._cast_value()),
             ('description', self.description)))
 
     # TODO: change name
-    def _coerce_value(self):
+    def _cast_value(self):
         if self.type is None:
             return
 
@@ -71,7 +71,7 @@ class ParameterBase(structure.ModelElementBase, structure.ModelMixin):
 
     def coerce_values(self, context, container, report_issues):
         if self.value is not None:
-            self.value = coerce_value(context, container, self.value, report_issues)
+            self.value = utils.coerce_value(context, container, self.value, report_issues)
 
 
 class MetadataBase(structure.ModelElementBase, structure.ModelMixin):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/4fb36130/aria/storage/modeling/utils.py
----------------------------------------------------------------------
diff --git a/aria/storage/modeling/utils.py b/aria/storage/modeling/utils.py
index 3d645f7..22f6680 100644
--- a/aria/storage/modeling/utils.py
+++ b/aria/storage/modeling/utils.py
@@ -17,12 +17,8 @@ from random import randrange
 
 from shortuuid import ShortUUID
 
-from aria.utils.collections import OrderedDict
-from aria.utils.console import puts
-from aria.parser.exceptions import InvalidValueError
-from aria.parser.presentation import Value
+from ...utils.console import puts
 
-from ..exceptions import CannotEvaluateFunctionException
 
 # UUID = ShortUUID() # default alphabet is base57, which is alphanumeric without visually
ambiguous
 # characters; ID length is 22
@@ -50,27 +46,6 @@ def generate_hex_string():
     return '%05x' % randrange(16 ** 5)
 
 
-def coerce_value(context, container, value, report_issues=False):
-    if isinstance(value, Value):
-        value = value.value
-
-    if isinstance(value, list):
-        return [coerce_value(context, container, v, report_issues) for v in value]
-    elif isinstance(value, dict):
-        return OrderedDict((k, coerce_value(context, container, v, report_issues))
-                           for k, v in value.iteritems())
-    elif hasattr(value, '_evaluate'):
-        try:
-            value = value._evaluate(context, container)
-            value = coerce_value(context, container, value, report_issues)
-        except CannotEvaluateFunctionException:
-            pass
-        except InvalidValueError as e:
-            if report_issues:
-                context.validation.report(e.issue)
-    return value
-
-
 def validate_dict_values(context, the_dict):
     if not the_dict:
         return

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/4fb36130/aria/storage_initializer.py
----------------------------------------------------------------------
diff --git a/aria/storage_initializer.py b/aria/storage_initializer.py
new file mode 100644
index 0000000..0386baa
--- /dev/null
+++ b/aria/storage_initializer.py
@@ -0,0 +1,135 @@
+# 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.
+
+from datetime import datetime
+from threading import RLock
+
+from .storage import model
+from .orchestrator import operation
+from .utils.formatting import safe_repr
+from .utils.console import puts, Colored
+
+
+def initialize_storage(context, model_storage, deployment_id):
+    blueprint = _create_blueprint(context)
+    model_storage.blueprint.put(blueprint)
+
+    deployment = _create_deployment(context, blueprint, deployment_id)
+    model_storage.deployment.put(deployment)
+
+    # Create nodes and node instances
+    for node_template in context.modeling.model.node_templates.values():
+        model_storage.node_template.put(node_template)
+
+        for a_node in context.modeling.instance.find_nodes(node_template.name):
+            node = _create_node_instance(deployment, node_template, a_node)
+            model_storage.node.put(node)
+
+    # Create relationships
+    for node_template in context.modeling.model.node_templates.values():
+        for index, requirement_template in enumerate(node_template.requirement_templates):
+            # We are currently limited only to requirements for specific node templates!
+            if requirement_template.target_node_template_name:
+                model_storage.requirement_template.put(requirement_template)
+
+                for node in context.modeling.instance.find_nodes(node_template.name):
+                    for relationship_model in node.relationships:
+                        if relationship_model.source_requirement_index == index:
+                            source_instance = \
+                                model_storage.node_instance.get_by_name(node.id)
+                            target_instance = \
+                                model_storage.node_instance.get_by_name(
+                                    relationship_model.target_node_id)
+                            relationship = \
+                                _create_relationship_instance(source_instance, target_instance)
+                            model_storage.relationship.put(relationship)
+
+
+def _create_blueprint(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(
+        plan={},
+        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_deployment(context, service_template, service_instance_id):
+    now = datetime.utcnow()
+    return model.ServiceInstance(
+        name='{0}_{1}'.format(service_template.name, service_instance_id),
+        service_template=service_template,
+        description=context.modeling.instance.description or '',
+        created_at=now,
+        updated_at=now,
+        workflows={},
+        permalink='',
+        policy_triggers={},
+        scaling_groups={}
+    )
+
+
+def _create_node_instance(service_instance, node, node_model):
+    return model.Node(
+        service_instance=service_instance,
+        name=node_model.id,
+        runtime_properties={},
+        version=None,
+        node_template=node,
+        state='',
+        scaling_groups=[]
+    )
+
+
+def _create_relationship_instance(source_instance, target_instance):
+    return model.Relationship(
+        source_node=source_instance,
+        target_node=target_instance
+    )
+
+
+_TERMINAL_LOCK = RLock()
+
+
+@operation
+def _dry_node(ctx, _plugin, _implementation, **kwargs):
+    with _TERMINAL_LOCK:
+        print '> node instance: %s' % Colored.red(ctx.node_instance.name)
+        _dump_implementation(_plugin, _implementation)
+
+
+@operation
+def _dry_relationship(ctx, _plugin, _implementation, **kwargs):
+    with _TERMINAL_LOCK:
+        puts('> relationship instance: %s -> %s' % (
+            Colored.red(ctx.relationship_instance.source_node_instance.name),
+            Colored.red(ctx.relationship_instance.target_node_instance.name)))
+        _dump_implementation(_plugin, _implementation)
+
+
+def _dump_implementation(plugin, implementation):
+    if plugin:
+        print '  plugin: %s' % Colored.magenta(plugin)
+    if implementation:
+        print '  implementation: %s' % Colored.yellow(safe_repr(implementation))

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/4fb36130/extensions/aria_extension_tosca/simple_v1_0/modeling/data_types.py
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/data_types.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/data_types.py
index 99dcfea..ea692e3 100644
--- a/extensions/aria_extension_tosca/simple_v1_0/modeling/data_types.py
+++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/data_types.py
@@ -397,8 +397,8 @@ def coerce_value(context, presentation, the_type, entry_schema, constraints,
val
 
     if hasattr(the_type, '_coerce_value'):
         # Delegate to '_coerce_value' (likely a DataType instance)
-        return the_type._coerce_value(context, presentation, entry_schema, constraints, value,
-                                      aspect)
+        return the_type._cast_value(context, presentation, entry_schema, constraints, value,
+                                    aspect)
 
     # Coerce to primitive type
     return coerce_to_primitive(context, presentation, the_type, constraints, value, aspect)


Mime
View raw message