ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From emblempar...@apache.org
Subject incubator-ariatosca git commit: Fix parser and workflow to work with new models [Forced Update!]
Date Fri, 03 Feb 2017 02:57:48 GMT
Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-44-Merge-parser-and-storage-models 283d70256 -> 2e0faa688 (forced update)


Fix parser and workflow to work with new models


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

Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models
Commit: 2e0faa68826ce4eec7991e0f8ddc3f63486d0d02
Parents: fdf3a08
Author: Tal Liron <tal.liron@gmail.com>
Authored: Thu Feb 2 20:34:18 2017 -0600
Committer: Tal Liron <tal.liron@gmail.com>
Committed: Thu Feb 2 20:57:41 2017 -0600

----------------------------------------------------------------------
 aria/cli/args_parser.py                         |   4 +-
 aria/cli/commands.py                            |  13 +-
 aria/orchestrator/workflows/builtin/heal.py     |   6 +-
 aria/orchestrator/workflows/builtin/install.py  |  18 +-
 aria/orchestrator/workflows/builtin/start.py    |   6 +-
 aria/orchestrator/workflows/builtin/stop.py     |   6 +-
 .../orchestrator/workflows/builtin/uninstall.py |  18 +-
 aria/orchestrator/workflows/builtin/utils.py    |  51 ++---
 .../orchestrator/workflows/builtin/workflows.py | 175 +++++++++++-------
 aria/parser/modeling/__init__.py                |   3 +-
 aria/parser/modeling/storage.py                 | 184 +++++++++++++++++++
 aria/storage/modeling/instance_elements.py      |   2 +-
 .../profiles/tosca-simple-1.0/groups.yaml       |   2 +-
 .../simple_v1_0/modeling/data_types.py          |   4 +-
 14 files changed, 360 insertions(+), 132 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2e0faa68/aria/cli/args_parser.py
----------------------------------------------------------------------
diff --git a/aria/cli/args_parser.py b/aria/cli/args_parser.py
index e661620..50fec39 100644
--- a/aria/cli/args_parser.py
+++ b/aria/cli/args_parser.py
@@ -138,9 +138,9 @@ def add_workflow_parser(workflow):
         default='install',
         help='The workflow name')
     workflow.add_argument(
-        '-d', '--deployment-id',
+        '-i', '--service-instance-id',
         required=False,
-        help='A unique ID for the deployment')
+        help='A unique ID for the service instance')
 
 
 @sub_parser_decorator(

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2e0faa68/aria/cli/commands.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands.py b/aria/cli/commands.py
index 45c866a..91d748f 100644
--- a/aria/cli/commands.py
+++ b/aria/cli/commands.py
@@ -42,7 +42,7 @@ from ..parser.consumption import (
     Instance
 )
 from ..parser.loading import LiteralLocation, UriLocation
-from ..parser.modeling import initialize_storage
+from ..parser.modeling.storage import initialize_storage
 from ..utils.application import StorageManager
 from ..utils.caching import cachedmethod
 from ..utils.console import (puts, Colored, indent)
@@ -211,10 +211,10 @@ class WorkflowCommand(BaseCommand):
     def __call__(self, args_namespace, unknown_args):
         super(WorkflowCommand, self).__call__(args_namespace, unknown_args)
 
-        deployment_id = args_namespace.deployment_id or 1 
+        service_instance_id = args_namespace.service_instance_id or 1 
         context = self._parse(args_namespace.uri)
         workflow_fn, inputs = self._get_workflow(context, args_namespace.workflow)
-        self._run(context, args_namespace.workflow, workflow_fn, inputs, deployment_id)
+        self._run(context, args_namespace.workflow, workflow_fn, inputs, service_instance_id)
     
     def _parse(self, uri):
         # Parse
@@ -259,13 +259,14 @@ class WorkflowCommand(BaseCommand):
         
         return workflow_fn, inputs
     
-    def _run(self, context, workflow_name, workflow_fn, inputs, deployment_id):
+    def _run(self, context, workflow_name, workflow_fn, inputs, service_instance_id):
         # Storage
         def _initialize_storage(model_storage):
-            initialize_storage(context, model_storage, deployment_id)
+            initialize_storage(context, model_storage, service_instance_id)
 
         # Create runner
-        runner = Runner(workflow_name, workflow_fn, inputs, _initialize_storage, deployment_id)
+        runner = Runner(workflow_name, workflow_fn, inputs, _initialize_storage,
+                        service_instance_id)
         
         # Run
         runner.run()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2e0faa68/aria/orchestrator/workflows/builtin/heal.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/builtin/heal.py b/aria/orchestrator/workflows/builtin/heal.py
index 87ac492..72f04a1 100644
--- a/aria/orchestrator/workflows/builtin/heal.py
+++ b/aria/orchestrator/workflows/builtin/heal.py
@@ -21,7 +21,7 @@ Builtin heal workflow
 
 from aria import workflow
 
-from .workflows import (install_node_instance, uninstall_node_instance)
+from .workflows import (install_node, uninstall_node)
 from ..api import task
 
 
@@ -78,7 +78,7 @@ def heal_uninstall(ctx, graph, failing_node_instances, targeted_node_instances):
 
     # create install sub workflow for every node instance
     for node_instance in failing_node_instances:
-        node_instance_sub_workflow = task.WorkflowTask(uninstall_node_instance,
+        node_instance_sub_workflow = task.WorkflowTask(uninstall_node,
                                                        node_instance=node_instance)
         node_instance_sub_workflows[node_instance.id] = node_instance_sub_workflow
         graph.add_tasks(node_instance_sub_workflow)
@@ -131,7 +131,7 @@ def heal_install(ctx, graph, failing_node_instances, targeted_node_instances):
 
     # create install sub workflow for every node instance
     for node_instance in failing_node_instances:
-        node_instance_sub_workflow = task.WorkflowTask(install_node_instance,
+        node_instance_sub_workflow = task.WorkflowTask(install_node,
                                                        node_instance=node_instance)
         node_instance_sub_workflows[node_instance.id] = node_instance_sub_workflow
         graph.add_tasks(node_instance_sub_workflow)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2e0faa68/aria/orchestrator/workflows/builtin/install.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/builtin/install.py b/aria/orchestrator/workflows/builtin/install.py
index 81d1da2..20afb64 100644
--- a/aria/orchestrator/workflows/builtin/install.py
+++ b/aria/orchestrator/workflows/builtin/install.py
@@ -17,18 +17,18 @@
 Builtin install workflow
 """
 
-from .workflows import install_node_instance
-from .utils import create_node_instance_task_dependencies
+from .workflows import install_node
+from .utils import create_node_task_dependencies
 from ..api.task import WorkflowTask
 from ... import workflow
 
 
 @workflow
 def install(ctx, graph):
-    tasks_and_node_instances = []
-    for node_instance in ctx.model.node_instance.iter():
-        tasks_and_node_instances.append((
-            WorkflowTask(install_node_instance, node_instance=node_instance),
-            node_instance))
-    graph.add_tasks([task for task, _ in tasks_and_node_instances])
-    create_node_instance_task_dependencies(graph, tasks_and_node_instances)
+    tasks_and_nodes = []
+    for node in ctx.model.node.iter():
+        tasks_and_nodes.append((
+            WorkflowTask(install_node, node=node),
+            node))
+    graph.add_tasks([task for task, _ in tasks_and_nodes])
+    create_node_task_dependencies(graph, tasks_and_nodes)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2e0faa68/aria/orchestrator/workflows/builtin/start.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/builtin/start.py b/aria/orchestrator/workflows/builtin/start.py
index a044d73..ad67554 100644
--- a/aria/orchestrator/workflows/builtin/start.py
+++ b/aria/orchestrator/workflows/builtin/start.py
@@ -17,12 +17,12 @@
 Builtin start workflow
 """
 
-from .workflows import start_node_instance
+from .workflows import start_node
 from ..api.task import WorkflowTask
 from ... import workflow
 
 
 @workflow
 def start(ctx, graph):
-    for node_instance in ctx.model.node_instance.iter():
-        graph.add_tasks(WorkflowTask(start_node_instance, node_instance=node_instance))
+    for node in ctx.model.node.iter():
+        graph.add_tasks(WorkflowTask(start_node, node=node))

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2e0faa68/aria/orchestrator/workflows/builtin/stop.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/builtin/stop.py b/aria/orchestrator/workflows/builtin/stop.py
index 584c0d3..23ac366 100644
--- a/aria/orchestrator/workflows/builtin/stop.py
+++ b/aria/orchestrator/workflows/builtin/stop.py
@@ -17,12 +17,12 @@
 Builtin stop workflow
 """
 
-from .workflows import stop_node_instance
+from .workflows import stop_node
 from ..api.task import WorkflowTask
 from ... import workflow
 
 
 @workflow
 def stop(ctx, graph):
-    for node_instance in ctx.model.node_instance.iter():
-        graph.add_tasks(WorkflowTask(stop_node_instance, node_instance=node_instance))
+    for node in ctx.model.node.iter():
+        graph.add_tasks(WorkflowTask(stop_node, node=node))

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2e0faa68/aria/orchestrator/workflows/builtin/uninstall.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/builtin/uninstall.py b/aria/orchestrator/workflows/builtin/uninstall.py
index bfcc9ec..7948f3e 100644
--- a/aria/orchestrator/workflows/builtin/uninstall.py
+++ b/aria/orchestrator/workflows/builtin/uninstall.py
@@ -17,18 +17,18 @@
 Builtin uninstall workflow
 """
 
-from .workflows import uninstall_node_instance
-from .utils import create_node_instance_task_dependencies
+from .workflows import uninstall_node
+from .utils import create_node_task_dependencies
 from ..api.task import WorkflowTask
 from ... import workflow
 
 
 @workflow
 def uninstall(ctx, graph):
-    tasks_and_node_instances = []
-    for node_instance in ctx.model.node_instance.iter():
-        tasks_and_node_instances.append((
-            WorkflowTask(uninstall_node_instance, node_instance=node_instance),
-            node_instance))
-    graph.add_tasks([task for task, _ in tasks_and_node_instances])
-    create_node_instance_task_dependencies(graph, tasks_and_node_instances, reverse=True)
+    tasks_and_nodes = []
+    for node in ctx.model.node.iter():
+        tasks_and_nodes.append((
+            WorkflowTask(uninstall_node, node=node),
+            node))
+    graph.add_tasks([task for task, _ in tasks_and_nodes])
+    create_node_task_dependencies(graph, tasks_and_nodes, reverse=True)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2e0faa68/aria/orchestrator/workflows/builtin/utils.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/builtin/utils.py b/aria/orchestrator/workflows/builtin/utils.py
index 8b7a8bc..855f911 100644
--- a/aria/orchestrator/workflows/builtin/utils.py
+++ b/aria/orchestrator/workflows/builtin/utils.py
@@ -16,50 +16,49 @@
 from ..api.task import OperationTask
 
 
-def create_node_instance_task(operation_name, node_instance):
+def create_node_task(operation_name, node):
     """
-    Returns a new operation task if the operation exists in the node instance, otherwise
returns
-    None.
+    Returns a new operation task if the operation exists in the node, otherwise returns None.
     """
 
-    if operation_name in node_instance.node.operations:
-        return OperationTask.node_instance(instance=node_instance,
+    if _has_operation(node.interfaces, operation_name):
+        return OperationTask.node_instance(instance=node,
                                            name=operation_name)
     return None
 
 
-def create_relationship_instance_tasks(operation_name, operations_attr, node_instance):
+def create_relationship_tasks(operation_name, edge, node):
     """
-    Returns a list of operation tasks for each outbound relationship of the node instance
if
-    the operation exists there.
+    Returns a list of operation tasks for each outbound relationship of the node if the operation
+    exists there.
     """
 
+    edge = 'source' # TODO: support target?
+
     sequence = []
-    for relationship_instance in node_instance.outbound_relationship_instances:
-        if operation_name in getattr(relationship_instance.relationship, operations_attr):
+    for relationship in node.outbound_relationships:
+        if _has_operation(getattr(relationship, edge + '_interfaces'), operation_name):
             sequence.append(
-                OperationTask.relationship_instance(instance=relationship_instance,
-                                                    name=operation_name,
-                                                    operation_end=operations_attr))
+                OperationTask.relationship_instance(instance=relationship,
+                                                    name=operation_name + '_' + edge))
     return sequence
 
 
-def create_node_instance_task_dependencies(graph, tasks_and_node_instances, reverse=False):
+def create_node_task_dependencies(graph, tasks_and_nodes, reverse=False):
     """
-    Creates dependencies between tasks if there is an outbound relationship between their
node
-    instances.
+    Creates dependencies between tasks if there is a relationship (outbound) between their
nodes.
     """
 
-    def get_task(node_instance_id):
-        for task, node_instance in tasks_and_node_instances:
-            if node_instance.id == node_instance_id:
+    def get_task(node_id):
+        for task, node in tasks_and_nodes:
+            if node.id == node_id:
                 return task
         return None
 
-    for task, node_instance in tasks_and_node_instances:
+    for task, node in tasks_and_nodes:
         dependencies = []
-        for relationship_instance in node_instance.outbound_relationship_instances:
-            dependency = get_task(relationship_instance.target_node_instance.id)
+        for relationship in node.outbound_relationships:
+            dependency = get_task(relationship.target_node.id)
             if dependency:
                 dependencies.append(dependency)
         if dependencies:
@@ -68,3 +67,11 @@ def create_node_instance_task_dependencies(graph, tasks_and_node_instances,
reve
                     graph.add_dependency(dependency, task)
             else:
                 graph.add_dependency(task, dependencies)
+
+
+def _has_operation(interfaces, operation_name):
+    for interface in interfaces:
+        for operation in interface.operations:
+            if operation.name == operation_name:
+                return True
+    return False

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2e0faa68/aria/orchestrator/workflows/builtin/workflows.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/builtin/workflows.py b/aria/orchestrator/workflows/builtin/workflows.py
index c2fbded..180b4e9 100644
--- a/aria/orchestrator/workflows/builtin/workflows.py
+++ b/aria/orchestrator/workflows/builtin/workflows.py
@@ -17,122 +17,157 @@
 A set of builtin workflows.
 """
 
-from .utils import (create_node_instance_task, create_relationship_instance_tasks)
+from .utils import (create_node_task, create_relationship_tasks)
 from ... import workflow
 
 
+NORMATIVE_STANDARD_INTERFACE = 'Standard' # 'tosca.interfaces.node.lifecycle.Standard'
+NORMATIVE_CONFIGURE_INTERFACE = 'Configure' # 'tosca.interfaces.relationship.Configure'
+
+NORMATIVE_CREATE = NORMATIVE_STANDARD_INTERFACE + '.create'
+NORMATIVE_START = NORMATIVE_STANDARD_INTERFACE + '.start'
+NORMATIVE_STOP = NORMATIVE_STANDARD_INTERFACE + '.stop'
+NORMATIVE_DELETE = NORMATIVE_STANDARD_INTERFACE + '.delete'
+
+NORMATIVE_CONFIGURE = NORMATIVE_STANDARD_INTERFACE + '.configure'
+NORMATIVE_PRE_CONFIGURE_SOURCE = NORMATIVE_CONFIGURE_INTERFACE + '.pre_configure_source'
+NORMATIVE_PRE_CONFIGURE_TARGET = NORMATIVE_CONFIGURE_INTERFACE + '.pre_configure_target'
+NORMATIVE_POST_CONFIGURE_SOURCE = NORMATIVE_CONFIGURE_INTERFACE + '.post_configure_source'
+NORMATIVE_POST_CONFIGURE_TARGET = NORMATIVE_CONFIGURE_INTERFACE + '.post_configure_target'
+
+NORMATIVE_ADD_SOURCE = NORMATIVE_CONFIGURE_INTERFACE + '.add_source'
+NORMATIVE_ADD_TARGET = NORMATIVE_CONFIGURE_INTERFACE + '.add_target'
+NORMATIVE_REMOVE_TARGET = NORMATIVE_CONFIGURE_INTERFACE + '.remove_target'
+NORMATIVE_TARGET_CHANGED = NORMATIVE_CONFIGURE_INTERFACE + '.target_changed'
+
+
 __all__ = (
-    'install_node_instance',
-    'uninstall_node_instance',
-    'start_node_instance',
-    'stop_node_instance',
+    'NORMATIVE_STANDARD_INTERFACE',
+    'NORMATIVE_CONFIGURE_INTERFACE',
+    'NORMATIVE_CREATE',
+    'NORMATIVE_START',
+    'NORMATIVE_STOP',
+    'NORMATIVE_DELETE',
+    'NORMATIVE_CONFIGURE',
+    'NORMATIVE_PRE_CONFIGURE_SOURCE',
+    'NORMATIVE_PRE_CONFIGURE_TARGET',
+    'NORMATIVE_POST_CONFIGURE_SOURCE',
+    'NORMATIVE_POST_CONFIGURE_TARGET',
+    'NORMATIVE_ADD_SOURCE',
+    'NORMATIVE_ADD_TARGET',
+    'NORMATIVE_REMOVE_TARGET',
+    'NORMATIVE_TARGET_CHANGED',
+    'install_node',
+    'uninstall_node',
+    'start_node',
+    'stop_node',
 )
 
 
-@workflow(suffix_template='{node_instance.id}')
-def install_node_instance(graph, node_instance, **kwargs):
+@workflow(suffix_template='{node.id}')
+def install_node(graph, node, **kwargs):
     sequence = []
 
     # Create
     sequence.append(
-        create_node_instance_task(
-            'tosca.interfaces.node.lifecycle.Standard.create',
-            node_instance))
+        create_node_task(
+            NORMATIVE_CREATE,
+            node))
 
     # Configure
     sequence += \
-        create_relationship_instance_tasks(
-            'tosca.interfaces.relationship.Configure.pre_configure_source',
-            'source_operations',
-            node_instance)
+        create_relationship_tasks(
+            NORMATIVE_PRE_CONFIGURE_SOURCE,
+            'source',
+            node)
     sequence += \
-        create_relationship_instance_tasks(
-            'tosca.interfaces.relationship.Configure.pre_configure_target',
-            'target_operations',
-            node_instance)
+        create_relationship_tasks(
+            NORMATIVE_PRE_CONFIGURE_TARGET,
+            'target',
+            node)
     sequence.append(
-        create_node_instance_task(
-            'tosca.interfaces.node.lifecycle.Standard.configure',
-            node_instance))
+        create_node_task(
+            NORMATIVE_CONFIGURE,
+            node))
     sequence += \
-        create_relationship_instance_tasks(
-            'tosca.interfaces.relationship.Configure.post_configure_source',
-            'source_operations',
-            node_instance)
+        create_relationship_tasks(
+            NORMATIVE_POST_CONFIGURE_SOURCE,
+            'source',
+            node)
     sequence += \
-        create_relationship_instance_tasks(
-            'tosca.interfaces.relationship.Configure.post_configure_target',
-            'target_operations',
-            node_instance)
+        create_relationship_tasks(
+            NORMATIVE_POST_CONFIGURE_TARGET,
+            'target',
+            node)
 
     # Start
-    sequence += _create_start_tasks(node_instance)
+    sequence += _create_start_tasks(node)
 
     graph.sequence(*sequence)
 
 
-@workflow(suffix_template='{node_instance.id}')
-def uninstall_node_instance(graph, node_instance, **kwargs):
+@workflow(suffix_template='{node.id}')
+def uninstall_node(graph, node, **kwargs):
     # Stop
-    sequence = _create_stop_tasks(node_instance)
+    sequence = _create_stop_tasks(node)
 
     # Delete
     sequence.append(
-        create_node_instance_task(
-            'tosca.interfaces.node.lifecycle.Standard.delete',
-            node_instance))
+        create_node_task(
+            NORMATIVE_DELETE,
+            node))
 
     graph.sequence(*sequence)
 
 
-@workflow(suffix_template='{node_instance.id}')
-def start_node_instance(graph, node_instance, **kwargs):
-    graph.sequence(*_create_start_tasks(node_instance))
+@workflow(suffix_template='{node.id}')
+def start_node(graph, node, **kwargs):
+    graph.sequence(*_create_start_tasks(node))
 
 
-@workflow(suffix_template='{node_instance.id}')
-def stop_node_instance(graph, node_instance, **kwargs):
-    graph.sequence(*_create_stop_tasks(node_instance))
+@workflow(suffix_template='{node.id}')
+def stop_node(graph, node, **kwargs):
+    graph.sequence(*_create_stop_tasks(node))
 
 
-def _create_start_tasks(node_instance):
+def _create_start_tasks(node):
     sequence = []
     sequence.append(
-        create_node_instance_task(
-            'tosca.interfaces.node.lifecycle.Standard.start',
-            node_instance))
+        create_node_task(
+            NORMATIVE_START,
+            node))
     sequence += \
-        create_relationship_instance_tasks(
-            'tosca.interfaces.relationship.Configure.add_source',
-            'source_operations',
-            node_instance)
+        create_relationship_tasks(
+            NORMATIVE_ADD_SOURCE,
+            'source',
+            node)
     sequence += \
-        create_relationship_instance_tasks(
-            'tosca.interfaces.relationship.Configure.add_target',
-            'target_operations',
-            node_instance)
+        create_relationship_tasks(
+            NORMATIVE_ADD_TARGET,
+            'target',
+            node)
     sequence += \
-        create_relationship_instance_tasks(
-            'tosca.interfaces.relationship.Configure.target_changed',
-            'target_operations',
-            node_instance)
+        create_relationship_tasks(
+            NORMATIVE_TARGET_CHANGED,
+            'target',
+            node)
     return sequence
 
 
-def _create_stop_tasks(node_instance):
+def _create_stop_tasks(node):
     sequence = []
     sequence += \
-        create_relationship_instance_tasks(
-            'tosca.interfaces.relationship.Configure.remove_target',
-            'target_operations',
-            node_instance)
+        create_relationship_tasks(
+            NORMATIVE_REMOVE_TARGET,
+            'target',
+            node)
     sequence += \
-        create_relationship_instance_tasks(
-            'tosca.interfaces.relationship.Configure.target_changed',
-            'target_operations',
-            node_instance)
+        create_relationship_tasks(
+            NORMATIVE_TARGET_CHANGED,
+            'target',
+            node)
     sequence.append(
-        create_node_instance_task(
-            'tosca.interfaces.node.lifecycle.Standard.stop',
-            node_instance))
+        create_node_task(
+            NORMATIVE_STOP,
+            node))
     return sequence

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2e0faa68/aria/parser/modeling/__init__.py
----------------------------------------------------------------------
diff --git a/aria/parser/modeling/__init__.py b/aria/parser/modeling/__init__.py
index d507a26..cad25ca 100644
--- a/aria/parser/modeling/__init__.py
+++ b/aria/parser/modeling/__init__.py
@@ -25,6 +25,7 @@ from .model_elements import (ServiceModel, NodeTemplate, RequirementTemplate,
Ca
 from .types import TypeHierarchy, Type, RelationshipType, PolicyType, PolicyTriggerType
 from .exceptions import CannotEvaluateFunctionException
 
+
 __all__ = (
     'IdType',
     'ModelingContext',
@@ -65,5 +66,5 @@ __all__ = (
     'RelationshipType',
     'PolicyType',
     'PolicyTriggerType',
-    'CannotEvaluateFunctionException'
+    'CannotEvaluateFunctionException',
 )

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2e0faa68/aria/parser/modeling/storage.py
----------------------------------------------------------------------
diff --git a/aria/parser/modeling/storage.py b/aria/parser/modeling/storage.py
new file mode 100644
index 0000000..4bb85af
--- /dev/null
+++ b/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
+            pass
+        model_storage.interface.put(s_interface)
+        for operation_name, op in interface.operations.iteritems():
+            operation_name = '{0}.{1}'.format(interface_name, operation_name)
+            s_operation = model.Operation(name=operation_name,
+                                          implementation='{0}.{1}'.format(__name__, fn_name),
+                                          interface=s_interface)
+            plugin, implementation = _parse_implementation(context, op.implementation)
+            s_operation.inputs.append(model.Parameter(name='_plugin', # pylint: ignore=no-member
+                                                      value=plugin,
+                                                      type='str'))
+            s_operation.inputs.append(model.Parameter(name='_implementation', # pylint: ignore=no-member
+                                                      value=implementation,
+                                                      type='str'))
+            model_storage.operation.put(s_operation)
+
+
+def _parse_implementation(context, implementation):
+    if not implementation:
+        return '', ''
+
+    index = implementation.find('>')
+    if index == -1:
+        return 'execution', implementation
+    plugin = implementation[:index].strip()
+
+    # TODO: validation should happen in parser
+    if (plugin != 'execution') and (_get_plugin(context, plugin) is None):
+        raise ValueError('unknown plugin: "%s"' % plugin)
+
+    implementation = implementation[index+1:].strip()
+    return plugin, implementation
+
+
+def _get_plugin(context, plugin_name):
+    def is_plugin(type_name):
+        return context.modeling.policy_types.get_role(type_name) == 'plugin'
+
+    for policy in context.modeling.instance.policies.itervalues():
+        if (policy.name == plugin_name) and is_plugin(policy.type_name):
+            return policy
+
+    return None
+
+
+_TERMINAL_LOCK = RLock()
+
+
+@operation
+def _dry_node(ctx, _plugin, _implementation, **kwargs):
+    with _TERMINAL_LOCK:
+        print '> node instance: %s' % Colored.red(ctx.node.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.source_node.name),
+            Colored.red(ctx.relationship.target_node.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/2e0faa68/aria/storage/modeling/instance_elements.py
----------------------------------------------------------------------
diff --git a/aria/storage/modeling/instance_elements.py b/aria/storage/modeling/instance_elements.py
index e3dedc8..4d73a79 100644
--- a/aria/storage/modeling/instance_elements.py
+++ b/aria/storage/modeling/instance_elements.py
@@ -193,7 +193,7 @@ class OperationBase(structure.ModelMixin):
         return cls.many_to_one_relationship('service_instance')
 
     @declared_attr
-    def interfaces(cls):
+    def interface(cls):
         return cls.many_to_one_relationship('interface')
     # region many-to-many relationships
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2e0faa68/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/groups.yaml
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/groups.yaml b/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/groups.yaml
index 08da2f3..a252a7c 100644
--- a/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/groups.yaml
+++ b/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/groups.yaml
@@ -24,5 +24,5 @@ group_types:
     description: >-
       This is the default (root) TOSCA Group Type definition that all other TOSCA base Group
Types derive from.
     interfaces:
-      standard:
+      Standard:
         type: tosca.interfaces.node.lifecycle.Standard

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2e0faa68/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 ea692e3..99dcfea 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._cast_value(context, presentation, entry_schema, constraints, value,
-                                    aspect)
+        return the_type._coerce_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