You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ariatosca.apache.org by em...@apache.org on 2017/08/09 13:34:04 UTC

[1/5] incubator-ariatosca git commit: ARIA-174 Refactor instantiation phase [Forced Update!]

Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-321-clearwater 531b6006d -> 40be30864 (forced update)


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/orchestrator/topology/topology.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/topology/topology.py b/aria/orchestrator/topology/topology.py
new file mode 100644
index 0000000..8ee33d1
--- /dev/null
+++ b/aria/orchestrator/topology/topology.py
@@ -0,0 +1,223 @@
+# 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 ...parser.validation import issue
+from ...modeling import models
+from ...utils import console
+from . import (
+    template_handler,
+    instance_handler,
+    common
+)
+
+
+class Topology(issue.ReporterMixin):
+
+    _init_map = {
+        models.ServiceTemplate: models.Service,
+        models.ArtifactTemplate: models.Artifact,
+        models.CapabilityTemplate: models.Capability,
+        models.GroupTemplate: models.Group,
+        models.InterfaceTemplate: models.Interface,
+        models.NodeTemplate: models.Node,
+        models.PolicyTemplate: models.Policy,
+        models.SubstitutionTemplate: models.Substitution,
+        models.RelationshipTemplate: models.Relationship,
+        models.OperationTemplate: models.Operation,
+        models.SubstitutionTemplateMapping: models.SubstitutionMapping,
+
+        # Common
+        models.Metadata: models.Metadata,
+        models.Attribute: models.Attribute,
+        models.Property: models.Property,
+        models.Input: models.Input,
+        models.Output: models.Output,
+        models.Configuration: models.Configuration,
+        models.Argument: models.Argument,
+        models.Type: models.Type
+    }
+
+    def __init__(self, *args, **kwargs):
+        super(Topology, self).__init__(*args, **kwargs)
+        self._model_cls_to_handler = dict(self._init_handlers(instance_handler),
+                                          **self._init_handlers(template_handler))
+
+    @staticmethod
+    def _init_handlers(module_):
+        """
+        Register handlers from a handler module to the models
+
+        :param module_: The module to look for handlers
+        :return: a dict where the key is the models class, and the value is the handler class
+        associated with it from the provided module
+        """
+        handlers = {}
+        for attribute_name in dir(module_):
+            if attribute_name.startswith('_'):
+                continue
+            attribute = getattr(module_, attribute_name)
+            if isinstance(attribute, type) and issubclass(attribute, common.HandlerBase):
+                handlers[getattr(models, attribute_name)] = attribute
+        return handlers
+
+    def instantiate(self, model, **kwargs):
+        """
+        instantiate the provided model
+
+        :param model:
+        :param kwargs:
+        :return:
+        """
+        if isinstance(model, dict):
+            return dict((name, self.instantiate(value, **kwargs))
+                        for name, value in model.iteritems())
+        elif isinstance(model, list):
+            return list(self.instantiate(value, **kwargs) for value in model)
+        elif model is not None:
+            _handler = self._model_cls_to_handler[model.__class__]
+            model_instance_cls = self._init_map[model.__class__]
+            return _handler(self, model).instantiate(model_instance_cls, **kwargs)
+
+    def validate(self, model, **kwargs):
+        if isinstance(model, dict):
+            return self.validate(model.values(), **kwargs)
+        elif isinstance(model, list):
+            return all(self.validate(value, **kwargs) for value in model)
+        elif model is not None:
+            _handler = self._model_cls_to_handler[model.__class__]
+            return _handler(self, model).validate(**kwargs)
+
+    def dump(self, model, out_stream=None, title=None, **kwargs):
+        out_stream = out_stream or console.TopologyStylizer()
+
+        # if model is empty, no need to print out the section name
+        if model and title:
+            out_stream.write('{0}:'.format(title))
+
+        if isinstance(model, dict):
+            if str(out_stream):
+                with out_stream.indent():
+                    return self.dump(model.values(), out_stream=out_stream, **kwargs)
+            else:
+                return self.dump(model.values(), out_stream=out_stream, **kwargs)
+
+        elif isinstance(model, list):
+            for value in model:
+                self.dump(value, out_stream=out_stream, **kwargs)
+
+        elif model is not None:
+            _handler = self._model_cls_to_handler[model.__class__]
+            _handler(self, model).dump(out_stream=out_stream, **kwargs)
+
+        return out_stream
+
+    def dump_graph(self, service):
+        out_stream = console.TopologyStylizer()
+        for node in service.nodes.itervalues():
+            if not node.inbound_relationships:
+                self._dump_graph_node(out_stream, node)
+        return out_stream
+
+    def _dump_graph_node(self, out_stream, node, capability=None):
+        out_stream.write(out_stream.node_style(node.name))
+        if capability is not None:
+            out_stream.write('{0} ({1})'.format(out_stream.property_style(capability.name),
+                                                out_stream.type_style(capability.type.name)))
+        if node.outbound_relationships:
+            with out_stream.indent():
+                for relationship_model in node.outbound_relationships:
+                    styled_relationship_name = out_stream.property_style(relationship_model.name)
+                    if relationship_model.type is not None:
+                        out_stream.write('-> {0} ({1})'.format(
+                            styled_relationship_name,
+                            out_stream.type_style(relationship_model.type.name)))
+                    else:
+                        out_stream.write('-> {0}'.format(styled_relationship_name))
+                    with out_stream.indent(3):
+                        self._dump_graph_node(out_stream,
+                                              relationship_model.target_node,
+                                              relationship_model.target_capability)
+
+    def coerce(self, model, **kwargs):
+        if isinstance(model, dict):
+            return self.coerce(model.values(), **kwargs)
+        elif isinstance(model, list):
+            return all(self.coerce(value, **kwargs) for value in model)
+        elif model is not None:
+            _handler = self._model_cls_to_handler[model.__class__]
+            return _handler(self, model).coerce(**kwargs)
+
+    def dump_types(self, service_template, out_stream=None):
+        out_stream = out_stream or console.TopologyStylizer()
+        self.dump(service_template.node_types, out_stream, 'Node types')
+        self.dump(service_template.group_types, out_stream, 'Group types')
+        self.dump(service_template.capability_types, out_stream, 'Capability types')
+        self.dump(service_template.relationship_types, out_stream, 'Relationship types')
+        self.dump(service_template.policy_types, out_stream, 'Policy types')
+        self.dump(service_template.artifact_types, out_stream, 'Artifact types')
+        self.dump(service_template.interface_types, out_stream, 'Interface types')
+
+        return out_stream
+
+    def satisfy_requirements(self, model, **kwargs):
+        if isinstance(model, dict):
+            return self.satisfy_requirements(model.values(), **kwargs)
+        elif isinstance(model, list):
+            return all(self.satisfy_requirements(value, **kwargs) for value in model)
+        elif model is not None:
+            _handler = self._model_cls_to_handler[model.__class__]
+            return _handler(self, model).satisfy_requirements(**kwargs)
+
+    def validate_capabilities(self, model, **kwargs):
+        if isinstance(model, dict):
+            return self.validate_capabilities(model.values(), **kwargs)
+        elif isinstance(model, list):
+            return all(self.validate_capabilities(value, **kwargs) for value in model)
+        elif model is not None:
+            _handler = self._model_cls_to_handler[model.__class__]
+            return _handler(self, model).validate_capabilities(**kwargs)
+
+    def _find_host(self, node):
+        if node.type.role == 'host':
+            return node
+
+        def target_has_role(rel, role):
+            return (rel.target_capability is not None and
+                    rel.target_capability.type.role == role)
+
+        for outbound_relationship in node.outbound_relationships:
+            if target_has_role(outbound_relationship, 'host'):
+                host = self._find_host(outbound_relationship.target_node)
+                if host is not None:
+                    return host
+        for inbound_relationship in node.inbound_relationships:
+            if target_has_role(inbound_relationship, 'feature'):
+                host = self._find_host(inbound_relationship.source_node)
+                if host is not None:
+                    return host
+        return None
+
+    def assign_hosts(self, service):
+        for node in service.nodes.values():
+            node.host = self._find_host(node)
+
+    def configure_operations(self, model, **kwargs):
+        if isinstance(model, dict):
+            return self.configure_operations(model.values(), **kwargs)
+        elif isinstance(model, list):
+            return all(self.configure_operations(value, **kwargs) for value in model)
+        elif model is not None:
+            _handler = self._model_cls_to_handler[model.__class__]
+            return _handler(self, model).configure_operations(**kwargs)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/orchestrator/topology/utils.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/topology/utils.py b/aria/orchestrator/topology/utils.py
new file mode 100644
index 0000000..ec74391
--- /dev/null
+++ b/aria/orchestrator/topology/utils.py
@@ -0,0 +1,48 @@
+# 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 copy import deepcopy
+
+
+def deepcopy_with_locators(value):
+    """
+    Like :func:`deepcopy`, but also copies over locators.
+    """
+
+    res = deepcopy(value)
+    copy_locators(res, value)
+    return res
+
+
+def copy_locators(target, source):
+    """
+    Copies over ``_locator`` for all elements, recursively.
+
+    Assumes that target and source have exactly the same list/dict structure.
+    """
+
+    locator = getattr(source, '_locator', None)
+    if locator is not None:
+        try:
+            setattr(target, '_locator', locator)
+        except AttributeError:
+            pass
+
+    if isinstance(target, list) and isinstance(source, list):
+        for i, _ in enumerate(target):
+            copy_locators(target[i], source[i])
+    elif isinstance(target, dict) and isinstance(source, dict):
+        for k, v in target.items():
+            copy_locators(v, source[k])

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/orchestrator/workflow_runner.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflow_runner.py b/aria/orchestrator/workflow_runner.py
index 0eac61c..4dbf29b 100644
--- a/aria/orchestrator/workflow_runner.py
+++ b/aria/orchestrator/workflow_runner.py
@@ -141,9 +141,8 @@ class WorkflowRunner(object):
                                                      supplied_inputs=inputs or {})
         modeling_utils.validate_required_inputs_are_supplied(declared_inputs=workflow_inputs,
                                                              supplied_inputs=inputs or {})
-        execution.inputs = modeling_utils.merge_parameter_values(inputs,
-                                                                 workflow_inputs,
-                                                                 model_cls=models.Input)
+        execution.inputs = modeling_utils.merge_parameter_values(
+            inputs, workflow_inputs, model_cls=models.Input)
         # TODO: these two following calls should execute atomically
         self._validate_no_active_executions(execution)
         self._model_storage.execution.put(execution)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/orchestrator/workflows/api/task.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/api/task.py b/aria/orchestrator/workflows/api/task.py
index ec96d27..6ce4a00 100644
--- a/aria/orchestrator/workflows/api/task.py
+++ b/aria/orchestrator/workflows/api/task.py
@@ -137,14 +137,13 @@ class OperationTask(BaseTask):
         operation = self.actor.interfaces[self.interface_name].operations[self.operation_name]
         self.plugin = operation.plugin
         self.function = operation.function
-        self.arguments = modeling_utils.merge_parameter_values(arguments,
-                                                               operation.arguments,
-                                                               model_cls=models.Argument)
+        self.arguments = modeling_utils.merge_parameter_values(arguments, operation.arguments)
 
         actor = self.actor
         if hasattr(actor, '_wrapped'):
             # Unwrap instrumented model
             actor = actor._wrapped
+
         if isinstance(actor, models.Node):
             self._context_cls = context.operation.NodeOperationContext
         elif isinstance(actor, models.Relationship):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/parser/consumption/__init__.py
----------------------------------------------------------------------
diff --git a/aria/parser/consumption/__init__.py b/aria/parser/consumption/__init__.py
index bd4b29c..f9caf5f 100644
--- a/aria/parser/consumption/__init__.py
+++ b/aria/parser/consumption/__init__.py
@@ -20,7 +20,6 @@ Consumption package.
    :nosignatures:
 
    aria.parser.consumption.ConsumptionContext
-   aria.parser.consumption.Style
 
 Consumers
 ---------
@@ -47,7 +46,6 @@ Consumers
 
 from .exceptions import ConsumerException
 from .context import ConsumptionContext
-from .style import Style
 from .consumer import (
     Consumer,
     ConsumerChain
@@ -70,7 +68,6 @@ from .inputs import Inputs
 __all__ = (
     'ConsumerException',
     'ConsumptionContext',
-    'Style',
     'Consumer',
     'ConsumerChain',
     'Read',

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/parser/consumption/consumer.py
----------------------------------------------------------------------
diff --git a/aria/parser/consumption/consumer.py b/aria/parser/consumption/consumer.py
index 4f4c614..878a161 100644
--- a/aria/parser/consumption/consumer.py
+++ b/aria/parser/consumption/consumer.py
@@ -27,6 +27,9 @@ class Consumer(object):
     """
 
     def __init__(self, context):
+        from ...orchestrator import topology
+
+        self.topology = topology.Topology()
         self.context = context
 
     def consume(self):
@@ -73,6 +76,10 @@ class ConsumerChain(Consumer):
                     handle_exception(consumer, e)
                 else:
                     raise e
+
+            if consumer.topology.has_issues:
+                self.context.validation.extend_issues(consumer.topology.issues)
+
             if self.context.validation.has_issues:
                 break
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/parser/consumption/context.py
----------------------------------------------------------------------
diff --git a/aria/parser/consumption/context.py b/aria/parser/consumption/context.py
index 6fa61f4..9164984 100644
--- a/aria/parser/consumption/context.py
+++ b/aria/parser/consumption/context.py
@@ -16,12 +16,12 @@
 import sys
 import threading
 
+from ...utils import console
 from ..validation import ValidationContext
 from ..loading import LoadingContext
 from ..reading import ReadingContext
 from ..presentation import PresentationContext
 from ..modeling import ModelingContext
-from .style import Style
 
 
 _thread_locals = threading.local()
@@ -58,12 +58,12 @@ class ConsumptionContext(object):
     def __init__(self, set_thread_local=True):
         self.args = []
         self.out = sys.stdout
-        self.style = Style()
         self.validation = ValidationContext()
         self.loading = LoadingContext()
         self.reading = ReadingContext()
         self.presentation = PresentationContext()
         self.modeling = ModelingContext()
+        self.style = console.TopologyStylizer()
 
         if set_thread_local:
             self.set_thread_local()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/parser/consumption/modeling.py
----------------------------------------------------------------------
diff --git a/aria/parser/consumption/modeling.py b/aria/parser/consumption/modeling.py
index 44027b9..221b308 100644
--- a/aria/parser/consumption/modeling.py
+++ b/aria/parser/consumption/modeling.py
@@ -13,8 +13,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from ...utils.formatting import json_dumps, yaml_dumps
 from .consumer import Consumer, ConsumerChain
+from ...utils.formatting import json_dumps, yaml_dumps
 
 
 class DeriveServiceTemplate(Consumer):
@@ -42,7 +42,7 @@ class CoerceServiceTemplateValues(Consumer):
     """
 
     def consume(self):
-        self.context.modeling.template.coerce_values(True)
+        self.topology.coerce(self.context.modeling.template, report_issues=True)
 
 
 class ValidateServiceTemplate(Consumer):
@@ -51,7 +51,7 @@ class ValidateServiceTemplate(Consumer):
     """
 
     def consume(self):
-        self.context.modeling.template.validate()
+        self.topology.validate(self.context.modeling.template)
 
 
 class ServiceTemplate(ConsumerChain):
@@ -74,7 +74,7 @@ class ServiceTemplate(ConsumerChain):
             raw = self.context.modeling.template_as_raw
             self.context.write(json_dumps(raw, indent=indent))
         else:
-            self.context.modeling.template.dump()
+            self.context.write(self.topology.dump(self.context.modeling.template))
 
 
 class Types(Consumer):
@@ -92,7 +92,7 @@ class Types(Consumer):
             raw = self.context.modeling.types_as_raw
             self.context.write(json_dumps(raw, indent=indent))
         else:
-            self.context.modeling.template.dump_types()
+            self.topology.dump_types(self.context, self.context.modeling.template)
 
 
 class InstantiateServiceInstance(Consumer):
@@ -105,9 +105,10 @@ class InstantiateServiceInstance(Consumer):
             self.context.validation.report('InstantiateServiceInstance consumer: missing service '
                                            'template')
             return
-
-        self.context.modeling.template.instantiate(None, None,
-                                                   inputs=dict(self.context.modeling.inputs))
+        self.context.modeling.instance = self.topology.instantiate(
+            self.context.modeling.template,
+            inputs=dict(self.context.modeling.inputs)
+        )
 
 
 class CoerceServiceInstanceValues(Consumer):
@@ -116,7 +117,7 @@ class CoerceServiceInstanceValues(Consumer):
     """
 
     def consume(self):
-        self.context.modeling.instance.coerce_values(True)
+        self.topology.coerce(self.context.modeling.instance, report_issues=True)
 
 
 class ValidateServiceInstance(Consumer):
@@ -125,7 +126,7 @@ class ValidateServiceInstance(Consumer):
     """
 
     def consume(self):
-        self.context.modeling.instance.validate()
+        self.topology.validate(self.context.modeling.instance)
 
 
 class SatisfyRequirements(Consumer):
@@ -134,7 +135,7 @@ class SatisfyRequirements(Consumer):
     """
 
     def consume(self):
-        self.context.modeling.instance.satisfy_requirements()
+        self.topology.satisfy_requirements(self.context.modeling.instance)
 
 
 class ValidateCapabilities(Consumer):
@@ -143,7 +144,7 @@ class ValidateCapabilities(Consumer):
     """
 
     def consume(self):
-        self.context.modeling.instance.validate_capabilities()
+        self.topology.validate_capabilities(self.context.modeling.instance)
 
 
 class FindHosts(Consumer):
@@ -152,7 +153,7 @@ class FindHosts(Consumer):
     """
 
     def consume(self):
-        self.context.modeling.instance.find_hosts()
+        self.topology.assign_hosts(self.context.modeling.instance)
 
 
 class ConfigureOperations(Consumer):
@@ -161,7 +162,7 @@ class ConfigureOperations(Consumer):
     """
 
     def consume(self):
-        self.context.modeling.instance.configure_operations()
+        self.topology.configure_operations(self.context.modeling.instance)
 
 
 class ServiceInstance(ConsumerChain):
@@ -193,4 +194,5 @@ class ServiceInstance(ConsumerChain):
             raw = self.context.modeling.instance_as_raw
             self.context.write(json_dumps(raw, indent=indent))
         else:
-            self.context.modeling.instance.dump()
+            str_rep = self.topology.dump(self.context.modeling.instance)
+            self.context.write(str_rep)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/parser/consumption/style.py
----------------------------------------------------------------------
diff --git a/aria/parser/consumption/style.py b/aria/parser/consumption/style.py
deleted file mode 100644
index 1b52cd3..0000000
--- a/aria/parser/consumption/style.py
+++ /dev/null
@@ -1,54 +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 ...utils.console import Colored, indent
-from ...utils.formatting import safe_repr
-
-
-class Style(object):
-    def __init__(self, indentation=2):
-        self.indentation = indentation
-
-    @property
-    def indent(self):
-        return indent(self.indentation)
-
-    @staticmethod
-    def section(value):
-        return Colored.cyan(value, bold=True)
-
-    @staticmethod
-    def type(value):
-        return Colored.blue(value, bold=True)
-
-    @staticmethod
-    def node(value):
-        return Colored.red(value, bold=True)
-
-    @staticmethod
-    def property(value):
-        return Colored.magenta(value, bold=True)
-
-    @staticmethod
-    def literal(value):
-        return Colored.magenta(safe_repr(value))
-
-    @staticmethod
-    def meta(value):
-        return Colored.green(value)
-
-    @staticmethod
-    def required(value):
-        return Colored.white(value)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/parser/modeling/context.py
----------------------------------------------------------------------
diff --git a/aria/parser/modeling/context.py b/aria/parser/modeling/context.py
index 3d75617..d8a1f7a 100644
--- a/aria/parser/modeling/context.py
+++ b/aria/parser/modeling/context.py
@@ -19,6 +19,10 @@ from ...utils.collections import StrictDict, prune
 from ...utils.uuid import generate_uuid
 
 
+# See: http://www.faqs.org/rfcs/rfc1035.html
+ID_MAX_LENGTH = 63
+
+
 class IdType(object):
     LOCAL_SERIAL = 0
     """
@@ -61,7 +65,7 @@ class ModelingContext(object):
         #self.id_type = IdType.LOCAL_SERIAL
         #self.id_type = IdType.LOCAL_RANDOM
         self.id_type = IdType.UNIVERSAL_RANDOM
-        self.id_max_length = 63 # See: http://www.faqs.org/rfcs/rfc1035.html
+        self.id_max_length = ID_MAX_LENGTH
         self.inputs = StrictDict(key_class=basestring)
 
         self._serial_id_counter = itertools.count(1)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/parser/presentation/fields.py
----------------------------------------------------------------------
diff --git a/aria/parser/presentation/fields.py b/aria/parser/presentation/fields.py
index 959bad1..5c08d4a 100644
--- a/aria/parser/presentation/fields.py
+++ b/aria/parser/presentation/fields.py
@@ -571,7 +571,7 @@ class Field(object):
     def _dump_primitive(self, context, value):
         if hasattr(value, 'as_raw'):
             value = as_raw(value)
-        puts('%s: %s' % (self.name, context.style.literal(value)))
+        puts('%s: %s' % (self.name, context.style.literal_style(value)))
 
     # primitive list
 
@@ -606,11 +606,11 @@ class Field(object):
 
     def _dump_primitive_list(self, context, value):
         puts('%s:' % self.name)
-        with context.style.indent:
+        with context.style.indent():
             for primitive in value:
                 if hasattr(primitive, 'as_raw'):
                     primitive = as_raw(primitive)
-                puts(context.style.literal(primitive))
+                puts(context.style.literal_style(primitive))
 
     # primitive dict
 
@@ -635,11 +635,11 @@ class Field(object):
 
     def _dump_primitive_dict(self, context, value):
         puts('%s:' % self.name)
-        with context.style.indent:
+        with context.style.indent():
             for v in value.itervalues():
                 if hasattr(v, 'as_raw'):
                     v = as_raw(v)
-                puts(context.style.literal(v))
+                puts(context.style.literal_style(v))
 
     # object
 
@@ -654,7 +654,7 @@ class Field(object):
 
     def _dump_object(self, context, value):
         puts('%s:' % self.name)
-        with context.style.indent:
+        with context.style.indent():
             if hasattr(value, '_dump'):
                 value._dump(context)
 
@@ -669,7 +669,7 @@ class Field(object):
 
     def _dump_object_list(self, context, value):
         puts('%s:' % self.name)
-        with context.style.indent:
+        with context.style.indent():
             for v in value:
                 if hasattr(v, '_dump'):
                     v._dump(context)
@@ -685,7 +685,7 @@ class Field(object):
 
     def _dump_object_dict(self, context, value):
         puts('%s:' % self.name)
-        with context.style.indent:
+        with context.style.indent():
             for v in value.itervalues():
                 if hasattr(v, '_dump'):
                     v._dump(context)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/parser/presentation/presentation.py
----------------------------------------------------------------------
diff --git a/aria/parser/presentation/presentation.py b/aria/parser/presentation/presentation.py
index fb71a1e..3f9f86d 100644
--- a/aria/parser/presentation/presentation.py
+++ b/aria/parser/presentation/presentation.py
@@ -37,13 +37,13 @@ class Value(object):
 
     def _dump(self, context):
         if self.type is not None:
-            puts(context.style.type(self.type))
+            puts(context.style.type_style(self.type))
         if self.value is not None:
-            puts(context.style.literal(self.value))
+            puts(context.style.literal_style(self.value))
         if self.description is not None:
-            puts(context.style.meta(self.description))
+            puts(context.style.meta_style(self.description))
         if self.required is not None:
-            puts(context.style.required(self.required))
+            puts(context.style.required_style(self.required))
 
 
 class PresentationBase(HasCachedMethods):
@@ -142,7 +142,7 @@ class PresentationBase(HasCachedMethods):
 
         if self._name:
             puts(context.style.node(self._name))
-            with context.style.indent:
+            with context.style.indent():
                 self._dump_content(context)
         else:
             self._dump_content(context)
@@ -162,7 +162,7 @@ class PresentationBase(HasCachedMethods):
             for field_name in self._iter_field_names():  # pylint: disable=no-member
                 self._dump_field(context, field_name)
         else:
-            puts(context.style.literal(self._raw))
+            puts(context.style.literal_style(self._raw))
 
     def _dump_field(self, context, field_name):
         """
@@ -242,7 +242,7 @@ class AsIsPresentation(PresentationBase):
     def _dump(self, context):
         if hasattr(self._raw, '_dump'):
             puts(context.style.node(self._name))
-            with context.style.indent:
+            with context.style.indent():
                 self._raw._dump(context)
         else:
             super(AsIsPresentation, self)._dump(context)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/parser/reading/__init__.py
----------------------------------------------------------------------
diff --git a/aria/parser/reading/__init__.py b/aria/parser/reading/__init__.py
index 065ca56..c110585 100644
--- a/aria/parser/reading/__init__.py
+++ b/aria/parser/reading/__init__.py
@@ -24,8 +24,6 @@ Reading package.
    JinjaReader
    JsonReader
    Locator
-   deepcopy_with_locators
-   copy_locators
    RawReader
    Reader
    ReaderSource
@@ -36,7 +34,7 @@ Reading package.
 from .raw import RawReader
 from .reader import Reader
 from .yaml import YamlReader
-from .locator import (Locator, deepcopy_with_locators, copy_locators)
+from .locator import Locator
 from .json import JsonReader
 from .jinja import JinjaReader
 from .context import ReadingContext
@@ -57,8 +55,6 @@ __all__ = (
     'ReadingContext',
     'RawReader',
     'Locator',
-    'deepcopy_with_locators',
-    'copy_locators',
     'YamlReader',
     'JsonReader',
     'JinjaReader')

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/parser/reading/locator.py
----------------------------------------------------------------------
diff --git a/aria/parser/reading/locator.py b/aria/parser/reading/locator.py
index 965164d..57b4d50 100644
--- a/aria/parser/reading/locator.py
+++ b/aria/parser/reading/locator.py
@@ -10,9 +10,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from copy import deepcopy
-
-
 from ...utils.console import puts, Colored, indent
 
 
@@ -120,35 +117,3 @@ class Locator(object):
     def __str__(self):
         # Should be in same format as Issue.locator_as_str
         return '"%s":%d:%d' % (self.location, self.line, self.column)
-
-
-def deepcopy_with_locators(value):
-    """
-    Like :func:`deepcopy`, but also copies over locators.
-    """
-
-    res = deepcopy(value)
-    copy_locators(res, value)
-    return res
-
-
-def copy_locators(target, source):
-    """
-    Copies over ``_locator`` for all elements, recursively.
-
-    Assumes that target and source have exactly the same list/dict structure.
-    """
-
-    locator = getattr(source, '_locator', None)
-    if locator is not None:
-        try:
-            setattr(target, '_locator', locator)
-        except AttributeError:
-            pass
-
-    if isinstance(target, list) and isinstance(source, list):
-        for i, _ in enumerate(target):
-            copy_locators(target[i], source[i])
-    elif isinstance(target, dict) and isinstance(source, dict):
-        for k, v in target.items():
-            copy_locators(v, source[k])

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/parser/validation/context.py
----------------------------------------------------------------------
diff --git a/aria/parser/validation/context.py b/aria/parser/validation/context.py
index ef641bd..da9eef6 100644
--- a/aria/parser/validation/context.py
+++ b/aria/parser/validation/context.py
@@ -13,15 +13,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from .issue import Issue
-from ...utils.threading import LockedList
-from ...utils.collections import FrozenList
-from ...utils.exceptions import print_exception
-from ...utils.console import puts, Colored, indent
-from ...utils.formatting import as_raw
+from . import issue
 
 
-class ValidationContext(object):
+class ValidationContext(issue.ReporterMixin):
     """
     Validation context.
 
@@ -35,53 +30,7 @@ class ValidationContext(object):
     :vartype max_level: int
     """
 
-    def __init__(self):
+    def __init__(self, *args, **kwargs):
+        super(ValidationContext, self).__init__(*args, **kwargs)
         self.allow_unknown_fields = False
         self.allow_primitive_coersion = False
-        self.max_level = Issue.ALL
-
-        self._issues = LockedList()
-
-    def report(self, message=None, exception=None, location=None, line=None,
-               column=None, locator=None, snippet=None, level=Issue.PLATFORM, issue=None):
-        if issue is None:
-            issue = Issue(message, exception, location, line, column, locator, snippet, level)
-
-        # Avoid duplicate issues
-        with self._issues:
-            for i in self._issues:
-                if str(i) == str(issue):
-                    return
-
-            self._issues.append(issue)
-
-    @property
-    def has_issues(self):
-        return len(self._issues) > 0
-
-    @property
-    def issues(self):
-        issues = [i for i in self._issues if i.level <= self.max_level]
-        issues.sort(key=lambda i: (i.level, i.location, i.line, i.column, i.message))
-        return FrozenList(issues)
-
-    @property
-    def issues_as_raw(self):
-        return [as_raw(i) for i in self.issues]
-
-    def dump_issues(self):
-        issues = self.issues
-        if issues:
-            puts(Colored.blue('Validation issues:', bold=True))
-            with indent(2):
-                for issue in issues:
-                    puts(Colored.blue(issue.heading_as_str))
-                    details = issue.details_as_str
-                    if details:
-                        with indent(3):
-                            puts(details)
-                    if issue.exception is not None:
-                        with indent(3):
-                            print_exception(issue.exception)
-            return True
-        return False

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/parser/validation/issue.py
----------------------------------------------------------------------
diff --git a/aria/parser/validation/issue.py b/aria/parser/validation/issue.py
index db8065d..42fc580 100644
--- a/aria/parser/validation/issue.py
+++ b/aria/parser/validation/issue.py
@@ -15,8 +15,14 @@
 
 from __future__ import absolute_import  # so we can import standard 'collections'
 
-from ...utils.collections import OrderedDict
-from ...utils.type import full_type_name
+from ...utils import (
+    collections,
+    type,
+    threading,
+    exceptions,
+    console,
+    formatting
+)
 
 
 class Issue(object):
@@ -82,14 +88,14 @@ class Issue(object):
 
     @property
     def as_raw(self):
-        return OrderedDict((
+        return collections.OrderedDict((
             ('level', self.level),
             ('message', self.message),
             ('location', self.location),
             ('line', self.line),
             ('column', self.column),
             ('snippet', self.snippet),
-            ('exception', full_type_name(self.exception) if self.exception else None)))
+            ('exception', type.full_type_name(self.exception) if self.exception else None)))
 
     @property
     def locator_as_str(self):
@@ -124,3 +130,61 @@ class Issue(object):
         if details:
             heading_str += ', ' + details
         return heading_str
+
+
+class ReporterMixin(object):
+
+    Issue = Issue
+
+    def __init__(self, *args, **kwargs):
+        super(ReporterMixin, self).__init__(*args, **kwargs)
+        self._issues = threading.LockedList()
+        self.max_level = self.Issue.ALL
+
+    def report(self, message=None, exception=None, location=None, line=None,
+               column=None, locator=None, snippet=None, level=Issue.PLATFORM, issue=None):
+        if issue is None:
+            issue = self.Issue(message, exception, location, line, column, locator, snippet, level)
+
+        # Avoid duplicate issues
+        with self._issues:
+            for i in self._issues:
+                if str(i) == str(issue):
+                    return
+
+            self._issues.append(issue)
+
+    @property
+    def has_issues(self):
+        return len(self._issues) > 0
+
+    @property
+    def issues(self):
+        issues = [i for i in self._issues if i.level <= self.max_level]
+        issues.sort(key=lambda i: (i.level, i.location, i.line, i.column, i.message))
+        return collections.FrozenList(issues)
+
+    @property
+    def issues_as_raw(self):
+        return [formatting.as_raw(i) for i in self.issues]
+
+    def extend_issues(self, *issues):
+        with self._issues:
+            self._issues.extend(*issues)
+
+    def dump_issues(self):
+        issues = self.issues
+        if issues:
+            console.puts(console.Colored.blue('Validation issues:', bold=True))
+            with console.indent(2):
+                for issue in issues:
+                    console.puts(console.Colored.blue(issue.heading_as_str))
+                    details = issue.details_as_str
+                    if details:
+                        with console.indent(3):
+                            console.puts(details)
+                    if issue.exception is not None:
+                        with console.indent(3):
+                            exceptions.print_exception(issue.exception)
+            return True
+        return False

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/utils/__init__.py
----------------------------------------------------------------------
diff --git a/aria/utils/__init__.py b/aria/utils/__init__.py
index 2a957a9..43dd882 100644
--- a/aria/utils/__init__.py
+++ b/aria/utils/__init__.py
@@ -16,3 +16,50 @@
 """
 General-purpose utilities package.
 """
+
+from . import (
+    archive,
+    argparse,
+    caching,
+    collections,
+    console,
+    exceptions,
+    file,
+    formatting,
+    http,
+    imports,
+    openclose,
+    plugin,
+    process,
+    specification,
+    threading,
+    type,
+    uris,
+    uuid,
+    validation,
+    versions
+)
+
+
+__all__ = (
+    'archive',
+    'argparse',
+    'caching',
+    'collections',
+    'console',
+    'exceptions',
+    'file',
+    'formatting',
+    'http',
+    'imports',
+    'openclose',
+    'plugin',
+    'process',
+    'specification',
+    'threading',
+    'type',
+    'uris',
+    'uuid',
+    'validation',
+    'versions'
+)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/utils/console.py
----------------------------------------------------------------------
diff --git a/aria/utils/console.py b/aria/utils/console.py
index 2f6f622..81e8cf8 100644
--- a/aria/utils/console.py
+++ b/aria/utils/console.py
@@ -19,19 +19,64 @@ Abstraction API above terminal color libraries.
 
 import os
 import sys
+from StringIO import StringIO
 
 from contextlib import contextmanager
 
-from .formatting import safe_str
 from ..cli import color
+from . import formatting
 
 
 _indent_string = ''
 
 
+class TopologyStylizer(object):
+    def __init__(self, indentation=0):
+        self._str = StringIO()
+        self._indentation = indentation
+
+    def write(self, string):
+        self._str.write(' ' * self._indentation)
+        self._str.write(string)
+        self._str.write(os.linesep)
+
+    @contextmanager
+    def indent(self, indentation=2):
+        self._indentation += indentation
+        yield
+        self._indentation -= indentation
+
+    @staticmethod
+    def type_style(value):
+        return Colored.blue(value, bold=True)
+
+    @staticmethod
+    def node_style(value):
+        return Colored.red(value, bold=True)
+
+    @staticmethod
+    def property_style(value):
+        return Colored.magenta(value, bold=True)
+
+    @staticmethod
+    def literal_style(value):
+        return Colored.magenta(formatting.safe_repr(value))
+
+    @staticmethod
+    def required_style(value):
+        return Colored.white(value)
+
+    @staticmethod
+    def meta_style(value):
+        return Colored.green(value)
+
+    def __str__(self):
+        return self._str.getvalue()
+
+
 def puts(string='', newline=True, stream=sys.stdout):
     stream.write(_indent_string)
-    stream.write(safe_str(string))
+    stream.write(formatting.safe_str(string))
     if newline:
         stream.write(os.linesep)
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/extensions/aria_extension_tosca/simple_v1_0/misc.py
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/simple_v1_0/misc.py b/extensions/aria_extension_tosca/simple_v1_0/misc.py
index 23beb3c..a65ff41 100644
--- a/extensions/aria_extension_tosca/simple_v1_0/misc.py
+++ b/extensions/aria_extension_tosca/simple_v1_0/misc.py
@@ -52,7 +52,7 @@ class Description(AsIsPresentation):
 
     def _dump(self, context):
         value = as_raw(self.value)
-        puts(context.style.meta(value))
+        puts(context.style.meta_style(value))
 
 
 @allow_unknown_fields

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py
index 2620150..1f90d29 100644
--- a/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py
+++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py
@@ -497,8 +497,11 @@ def create_plugin_specification_model(context, policy):
 
 
 def create_workflow_operation_template_model(context, service_template, policy):
-    model = OperationTemplate(name=policy._name,
-                              service_template=service_template)
+    model = OperationTemplate(name=policy._name)
+    # since we use backpopulates, these fields are populated upon commit, we get a weird(temporary)
+    # behavior where in previous code service_template.workflow_templates is a dict which has None
+    # as key for the value of model.
+    service_template.workflow_templates[model.name] = model
 
     if policy.description:
         model.description = policy.description.value
@@ -606,7 +609,7 @@ def create_parameter_model_from_value(template_parameter, template_parameter_nam
 def create_parameter_models_from_assignments(properties, source_properties, model_cls):
     if source_properties:
         for property_name, prop in source_properties.iteritems():
-            properties[property_name] = model_cls(name=property_name, # pylint: disable=unexpected-keyword-arg
+            properties[property_name] = model_cls(name=property_name,                               # pylint: disable=unexpected-keyword-arg
                                                   type_name=prop.value.type,
                                                   value=prop.value.value,
                                                   description=prop.value.description)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/tests/parser/service_templates.py
----------------------------------------------------------------------
diff --git a/tests/parser/service_templates.py b/tests/parser/service_templates.py
index 55cd4ad..9e8fcae 100644
--- a/tests/parser/service_templates.py
+++ b/tests/parser/service_templates.py
@@ -47,6 +47,7 @@ def consume_use_case(use_case_name, consumer_class_name='instance', cache=True):
     assert not context.validation.has_issues
     return context, dumper
 
+
 def consume_types_use_case(use_case_name, consumer_class_name='instance', cache=True):
     cachedmethod.ENABLED = cache
     uri = get_service_template_uri('tosca-simple-1.0', 'types', use_case_name,
@@ -61,12 +62,23 @@ def consume_types_use_case(use_case_name, consumer_class_name='instance', cache=
     assert not context.validation.has_issues
     return context, dumper
 
+
 def consume_node_cellar(consumer_class_name='instance', cache=True):
+    consume_test_case(
+        get_service_template_uri('tosca-simple-1.0', 'node-cellar', 'node-cellar.yaml'),
+        consumer_class_name=consumer_class_name,
+        inputs_uri=get_service_template_uri('tosca-simple-1.0', 'node-cellar', 'inputs.yaml'),
+        cache=cache
+
+    )
+
+
+def consume_test_case(uri, inputs_uri=None, consumer_class_name='instance', cache=True):
     cachedmethod.ENABLED = cache
-    uri = get_service_template_uri('tosca-simple-1.0', 'node-cellar', 'node-cellar.yaml')
+    uri = get_service_template_uri(uri)
     context = create_context(uri)
-    context.args.append('--inputs=' + get_service_template_uri('tosca-simple-1.0', 'node-cellar',
-                                                               'inputs.yaml'))
+    if inputs_uri:
+        context.args.append('--inputs=' + get_service_template_uri(inputs_uri))
     consumer, dumper = create_consumer(context, consumer_class_name)
     consumer.consume()
     context.validation.dump_issues()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/tests/parser/test_reqs_caps.py
----------------------------------------------------------------------
diff --git a/tests/parser/test_reqs_caps.py b/tests/parser/test_reqs_caps.py
new file mode 100644
index 0000000..e92aec4
--- /dev/null
+++ b/tests/parser/test_reqs_caps.py
@@ -0,0 +1,29 @@
+# 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 .service_templates import consume_test_case
+from ..helpers import get_service_template_uri
+
+
+def test_satisfy_capability_type():
+    consume_reqs_caps_template1('instance')
+
+
+def consume_reqs_caps_template1(consumer_class_name, cache=True):
+    consume_test_case(
+        get_service_template_uri('tosca-simple-1.0', 'reqs_caps', 'reqs_caps1.yaml'),
+        consumer_class_name=consumer_class_name,
+        cache=cache
+    )

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/tests/resources/service-templates/tosca-simple-1.0/reqs_caps/reqs_caps1.yaml
----------------------------------------------------------------------
diff --git a/tests/resources/service-templates/tosca-simple-1.0/reqs_caps/reqs_caps1.yaml b/tests/resources/service-templates/tosca-simple-1.0/reqs_caps/reqs_caps1.yaml
new file mode 100644
index 0000000..466a78e
--- /dev/null
+++ b/tests/resources/service-templates/tosca-simple-1.0/reqs_caps/reqs_caps1.yaml
@@ -0,0 +1,40 @@
+# 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.
+
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+capability_types:
+  Socket:
+    derived_from: tosca.capabilities.Root
+
+node_types:
+  Socket:
+    derived_from: tosca.nodes.Root
+    capabilities:
+      socket: Socket
+
+  Plug:
+    derived_from: tosca.nodes.Root
+    requirements:
+      - plug:
+          capability: Socket
+
+topology_template:
+  node_templates:
+    socket:
+      type: Socket
+
+    plug:
+      type: Plug
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/tests/storage/__init__.py
----------------------------------------------------------------------
diff --git a/tests/storage/__init__.py b/tests/storage/__init__.py
index 8ca1480..8a4d613 100644
--- a/tests/storage/__init__.py
+++ b/tests/storage/__init__.py
@@ -23,8 +23,6 @@ from sqlalchemy import (
     MetaData
 )
 
-from aria.modeling import models
-
 
 class TestFileSystem(object):
 


[3/5] incubator-ariatosca git commit: ARIA-174 Refactor instantiation phase

Posted by em...@apache.org.
ARIA-174 Refactor instantiation phase

The main issue this PR addressed was the consolidation
of instantiation mechanism into a single package - `topology`.

The code itself got additional refactoring:
1. `dump` no longer prints onto the console but rather returns a string representation to be printed.
2. The service related consumers use the new `topology` package.

These additional issues were fixed as part of this PR:
* Req-Cap mechanism is now trying to satisfy requirements for a specific capability type.
* Issue with resuming workflows - accessing a non existing attribute.


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

Branch: refs/heads/ARIA-321-clearwater
Commit: df2b916e624719e5f77e29c1e893c55f88e15862
Parents: a43bc6b
Author: max-orlov <ma...@gigaspaces.com>
Authored: Thu Jul 13 16:49:15 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Wed Aug 9 15:52:08 2017 +0300

----------------------------------------------------------------------
 aria/cli/commands/executions.py                 |   2 +-
 aria/cli/commands/service_templates.py          |   7 +-
 aria/cli/commands/services.py                   |   6 +-
 aria/core.py                                    |  36 +-
 aria/modeling/functions.py                      |   3 +-
 aria/modeling/mixins.py                         |  42 +-
 aria/modeling/service_common.py                 |  27 -
 aria/modeling/service_instance.py               | 535 +-------------
 aria/modeling/service_template.py               | 740 +------------------
 aria/modeling/utils.py                          |  85 +--
 .../execution_plugin/instantiation.py           | 113 ++-
 aria/orchestrator/topology/__init__.py          |  16 +
 aria/orchestrator/topology/common.py            |  69 ++
 aria/orchestrator/topology/instance_handler.py  | 671 +++++++++++++++++
 aria/orchestrator/topology/template_handler.py  | 606 +++++++++++++++
 aria/orchestrator/topology/topology.py          | 223 ++++++
 aria/orchestrator/topology/utils.py             |  48 ++
 aria/orchestrator/workflow_runner.py            |   5 +-
 aria/orchestrator/workflows/api/task.py         |   5 +-
 aria/parser/consumption/__init__.py             |   3 -
 aria/parser/consumption/consumer.py             |   7 +
 aria/parser/consumption/context.py              |   4 +-
 aria/parser/consumption/modeling.py             |  32 +-
 aria/parser/consumption/style.py                |  54 --
 aria/parser/modeling/context.py                 |   6 +-
 aria/parser/presentation/fields.py              |  16 +-
 aria/parser/presentation/presentation.py        |  14 +-
 aria/parser/reading/__init__.py                 |   6 +-
 aria/parser/reading/locator.py                  |  35 -
 aria/parser/validation/context.py               |  59 +-
 aria/parser/validation/issue.py                 |  72 +-
 aria/utils/__init__.py                          |  47 ++
 aria/utils/console.py                           |  49 +-
 .../aria_extension_tosca/simple_v1_0/misc.py    |   2 +-
 .../simple_v1_0/modeling/__init__.py            |   9 +-
 tests/parser/service_templates.py               |  18 +-
 tests/parser/test_reqs_caps.py                  |  29 +
 .../tosca-simple-1.0/reqs_caps/reqs_caps1.yaml  |  40 +
 tests/storage/__init__.py                       |   2 -
 39 files changed, 2069 insertions(+), 1674 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/cli/commands/executions.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/executions.py b/aria/cli/commands/executions.py
index 4783442..f130d95 100644
--- a/aria/cli/commands/executions.py
+++ b/aria/cli/commands/executions.py
@@ -181,7 +181,7 @@ def resume(execution_id,
     executor = DryExecutor() if dry else None  # use WorkflowRunner's default executor
 
     execution = model_storage.execution.get(execution_id)
-    if execution.status != execution.status.CANCELLED:
+    if execution.status != execution.CANCELLED:
         logger.info("Can't resume execution {execution.id} - "
                     "execution is in status {execution.status}. "
                     "Can only resume executions in status {valid_status}"

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/cli/commands/service_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/service_templates.py b/aria/cli/commands/service_templates.py
index f567aa8..5a7039c 100644
--- a/aria/cli/commands/service_templates.py
+++ b/aria/cli/commands/service_templates.py
@@ -28,7 +28,7 @@ from ...core import Core
 from ...storage import exceptions as storage_exceptions
 from ...parser import consumption
 from ...utils import (formatting, collections, console)
-
+from ... orchestrator import topology
 
 DESCRIPTION_FIELD_LENGTH_LIMIT = 20
 SERVICE_TEMPLATE_COLUMNS = \
@@ -73,10 +73,9 @@ def show(service_template_name, model_storage, mode_full, mode_types, format_jso
         elif format_yaml:
             console.puts(formatting.yaml_dumps(collections.prune(service_template.as_raw)))
         else:
-            service_template.dump()
+            console.puts(topology.Topology().dump(service_template))
     elif mode_types:
-        consumption.ConsumptionContext()
-        service_template.dump_types()
+        console.puts(topology.Topology().dump_types(service_template=service_template))
     else:
         logger.info('Showing service template {0}...'.format(service_template_name))
         service_template_dict = service_template.to_dict()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/cli/commands/services.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/services.py b/aria/cli/commands/services.py
index a99f5b3..6752899 100644
--- a/aria/cli/commands/services.py
+++ b/aria/cli/commands/services.py
@@ -30,6 +30,7 @@ from ...modeling import exceptions as modeling_exceptions
 from ...storage import exceptions as storage_exceptions
 from ...parser import consumption
 from ...utils import (formatting, collections, console)
+from ...orchestrator import topology
 
 
 DESCRIPTION_FIELD_LENGTH_LIMIT = 20
@@ -73,10 +74,9 @@ def show(service_name, model_storage, mode_full, mode_graph, format_json, format
         elif format_yaml:
             console.puts(formatting.yaml_dumps(collections.prune(service.as_raw)))
         else:
-            service.dump()
+            console.puts(topology.Topology().dump(service))
     elif mode_graph:
-        consumption.ConsumptionContext()
-        service.dump_graph()
+        console.puts(topology.Topology().dump_graph(service))
     else:
         logger.info('Showing service {0}...'.format(service_name))
         service_dict = service.to_dict()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/core.py
----------------------------------------------------------------------
diff --git a/aria/core.py b/aria/core.py
index e214b1a..e3b3b36 100644
--- a/aria/core.py
+++ b/aria/core.py
@@ -20,6 +20,7 @@ ARIA core module.
 from . import exceptions
 from .parser import consumption
 from .parser.loading.location import UriLocation
+from .orchestrator import topology
 
 
 class Core(object):
@@ -67,31 +68,26 @@ class Core(object):
         self.resource_storage.service_template.delete(entry_id=str(service_template.id))
 
     def create_service(self, service_template_id, inputs, service_name=None):
-
         service_template = self.model_storage.service_template.get(service_template_id)
 
-        # creating an empty ConsumptionContext, initiating a threadlocal context
-        context = consumption.ConsumptionContext()
-
         storage_session = self.model_storage._all_api_kwargs['session']
         # setting no autoflush for the duration of instantiation - this helps avoid dependency
         # constraints as they're being set up
         with storage_session.no_autoflush:
-            service = service_template.instantiate(None, self.model_storage, inputs=inputs)
-
-            consumption.ConsumerChain(
-                context,
-                (
-                    consumption.CoerceServiceInstanceValues,
-                    consumption.ValidateServiceInstance,
-                    consumption.SatisfyRequirements,
-                    consumption.CoerceServiceInstanceValues,
-                    consumption.ValidateCapabilities,
-                    consumption.FindHosts,
-                    consumption.ConfigureOperations,
-                    consumption.CoerceServiceInstanceValues
-                )).consume()
-            if context.validation.dump_issues():
+            topology_ = topology.Topology()
+            service = topology_.instantiate(
+                service_template, inputs=inputs, plugins=self.model_storage.plugin.list())
+            topology_.coerce(service, report_issues=True)
+
+            topology_.validate(service)
+            topology_.satisfy_requirements(service)
+            topology_.coerce(service, report_issues=True)
+
+            topology_.validate_capabilities(service)
+            topology_.assign_hosts(service)
+            topology_.configure_operations(service)
+            topology_.coerce(service, report_issues=True)
+            if topology_.dump_issues():
                 raise exceptions.InstantiationError('Failed to instantiate service template `{0}`'
                                                     .format(service_template.name))
 
@@ -122,6 +118,8 @@ class Core(object):
     def _parse_service_template(service_template_path):
         context = consumption.ConsumptionContext()
         context.presentation.location = UriLocation(service_template_path)
+        # Most of the parser uses the topology package in order to manipulate the models.
+        # However, here we use the Consumer mechanism, but this should change in the future.
         consumption.ConsumerChain(
             context,
             (

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/modeling/functions.py
----------------------------------------------------------------------
diff --git a/aria/modeling/functions.py b/aria/modeling/functions.py
index 6544adf..31c3839 100644
--- a/aria/modeling/functions.py
+++ b/aria/modeling/functions.py
@@ -16,9 +16,8 @@
 """
 Mechanism for evaluating intrinsic functions.
 """
-
-from ..parser.consumption import ConsumptionContext
 from ..parser.exceptions import InvalidValueError
+from ..parser.consumption import ConsumptionContext
 from ..utils.collections import OrderedDict
 from . import exceptions
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/modeling/mixins.py
----------------------------------------------------------------------
diff --git a/aria/modeling/mixins.py b/aria/modeling/mixins.py
index 4acbe6e..d58c25a 100644
--- a/aria/modeling/mixins.py
+++ b/aria/modeling/mixins.py
@@ -25,8 +25,7 @@ from sqlalchemy import (
     PickleType
 )
 
-from ..parser.consumption import ConsumptionContext
-from ..utils import console, collections, caching, formatting
+from ..utils import collections, caching
 from ..utils.type import canonical_type_name, full_type_name
 from . import utils, functions
 
@@ -132,26 +131,17 @@ class InstanceModelMixin(ModelMixin):
     def as_raw(self):
         raise NotImplementedError
 
-    def validate(self):
-        pass
-
     def coerce_values(self, report_issues):
         pass
 
-    def dump(self):
-        pass
-
 
-class TemplateModelMixin(InstanceModelMixin):
+class TemplateModelMixin(InstanceModelMixin):                                                       # pylint: disable=abstract-method
     """
     Mix-in for service template models.
 
     All model models can be instantiated into service instance models.
     """
 
-    def instantiate(self, container):
-        raise NotImplementedError
-
 
 class ParameterMixin(TemplateModelMixin, caching.HasCachedMethods):                                 #pylint: disable=abstract-method
     """
@@ -306,34 +296,6 @@ class ParameterMixin(TemplateModelMixin, caching.HasCachedMethods):
             ('value', self.value),
             ('description', self.description)))
 
-    def instantiate(self, container):
-        return self.__class__(name=self.name,  # pylint: disable=unexpected-keyword-arg
-                              type_name=self.type_name,
-                              _value=self._value,
-                              description=self.description)
-
-    def coerce_values(self, report_issues):
-        value = self._value
-        if value is not None:
-            evaluation = functions.evaluate(value, self, report_issues)
-            if (evaluation is not None) and evaluation.final:
-                # A final evaluation can safely replace the existing value
-                self._value = evaluation.value
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        if self.type_name is not None:
-            console.puts('{0}: {1} ({2})'.format(
-                context.style.property(self.name),
-                context.style.literal(formatting.as_raw(self.value)),
-                context.style.type(self.type_name)))
-        else:
-            console.puts('{0}: {1}'.format(
-                context.style.property(self.name),
-                context.style.literal(formatting.as_raw(self.value))))
-        if self.description:
-            console.puts(context.style.meta(self.description))
-
     @property
     def unwrapped(self):
         return self.name, self.value

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/modeling/service_common.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_common.py b/aria/modeling/service_common.py
index 4ce9dae..478e530 100644
--- a/aria/modeling/service_common.py
+++ b/aria/modeling/service_common.py
@@ -26,11 +26,9 @@ from sqlalchemy import (
 )
 from sqlalchemy.ext.declarative import declared_attr
 
-from ..parser.consumption import ConsumptionContext
 from ..utils import (
     collections,
     formatting,
-    console,
 )
 from .mixins import InstanceModelMixin, TemplateModelMixin, ParameterMixin
 from . import relationship
@@ -563,17 +561,6 @@ class TypeBase(InstanceModelMixin):
         self._append_raw_children(types)
         return types
 
-    def coerce_values(self, report_issues):
-        pass
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        if self.name:
-            console.puts(context.style.type(self.name))
-        with context.style.indent:
-            for child in self.children:
-                child.dump()
-
     def _append_raw_children(self, types):
         for child in self.children:
             raw_child = formatting.as_raw(child)
@@ -612,17 +599,3 @@ class MetadataBase(TemplateModelMixin):
         return collections.OrderedDict((
             ('name', self.name),
             ('value', self.value)))
-
-    def coerce_values(self, report_issues):
-        pass
-
-    def instantiate(self, container):
-        from . import models
-        return models.Metadata(name=self.name,
-                               value=self.value)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        console.puts('{0}: {1}'.format(
-            context.style.property(self.name),
-            context.style.literal(self.value)))

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/modeling/service_instance.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py
index ae6a0a0..daeb0a4 100644
--- a/aria/modeling/service_instance.py
+++ b/aria/modeling/service_instance.py
@@ -30,19 +30,15 @@ from sqlalchemy import DateTime
 from sqlalchemy.ext.declarative import declared_attr
 from sqlalchemy.ext.orderinglist import ordering_list
 
+from . import (
+    relationship,
+    types as modeling_types
+)
 from .mixins import InstanceModelMixin
-from ..orchestrator import execution_plugin
-from ..parser import validation
-from ..parser.consumption import ConsumptionContext
+
 from ..utils import (
     collections,
     formatting,
-    console
-)
-from . import (
-    relationship,
-    utils,
-    types as modeling_types
 )
 
 
@@ -232,50 +228,6 @@ class ServiceBase(InstanceModelMixin):
     :type: :class:`~datetime.datetime`
     """)
 
-    def satisfy_requirements(self):
-        satisfied = True
-        for node in self.nodes.itervalues():
-            if not node.satisfy_requirements():
-                satisfied = False
-        return satisfied
-
-    def validate_capabilities(self):
-        satisfied = True
-        for node in self.nodes.itervalues():
-            if not node.validate_capabilities():
-                satisfied = False
-        return satisfied
-
-    def find_hosts(self):
-        for node in self.nodes.itervalues():
-            node.find_host()
-
-    def configure_operations(self):
-        for node in self.nodes.itervalues():
-            node.configure_operations()
-        for group in self.groups.itervalues():
-            group.configure_operations()
-        for operation in self.workflows.itervalues():
-            operation.configure()
-
-    def is_node_a_target(self, target_node):
-        for node in self.nodes.itervalues():
-            if self._is_node_a_target(node, target_node):
-                return True
-        return False
-
-    def _is_node_a_target(self, source_node, target_node):
-        if source_node.outbound_relationships:
-            for relationship_model in source_node.outbound_relationships:
-                if relationship_model.target_node.name == target_node.name:
-                    return True
-                else:
-                    node = relationship_model.target_node
-                    if node is not None:
-                        if self._is_node_a_target(node, target_node):
-                            return True
-        return False
-
     @property
     def as_raw(self):
         return collections.OrderedDict((
@@ -289,70 +241,6 @@ class ServiceBase(InstanceModelMixin):
             ('outputs', formatting.as_raw_dict(self.outputs)),
             ('workflows', formatting.as_raw_list(self.workflows))))
 
-    def validate(self):
-        utils.validate_dict_values(self.meta_data)
-        utils.validate_dict_values(self.nodes)
-        utils.validate_dict_values(self.groups)
-        utils.validate_dict_values(self.policies)
-        if self.substitution is not None:
-            self.substitution.validate()
-        utils.validate_dict_values(self.inputs)
-        utils.validate_dict_values(self.outputs)
-        utils.validate_dict_values(self.workflows)
-
-    def coerce_values(self, report_issues):
-        utils.coerce_dict_values(self.meta_data, report_issues)
-        utils.coerce_dict_values(self.nodes, report_issues)
-        utils.coerce_dict_values(self.groups, report_issues)
-        utils.coerce_dict_values(self.policies, report_issues)
-        if self.substitution is not None:
-            self.substitution.coerce_values(report_issues)
-        utils.coerce_dict_values(self.inputs, report_issues)
-        utils.coerce_dict_values(self.outputs, report_issues)
-        utils.coerce_dict_values(self.workflows, report_issues)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        if self.description is not None:
-            console.puts(context.style.meta(self.description))
-        utils.dump_dict_values(self.meta_data, 'Metadata')
-        for node in self.nodes.itervalues():
-            node.dump()
-        for group in self.groups.itervalues():
-            group.dump()
-        for policy in self.policies.itervalues():
-            policy.dump()
-        if self.substitution is not None:
-            self.substitution.dump()
-        utils.dump_dict_values(self.inputs, 'Inputs')
-        utils.dump_dict_values(self.outputs, 'Outputs')
-        utils.dump_dict_values(self.workflows, 'Workflows')
-
-    def dump_graph(self):
-        for node in self.nodes.itervalues():
-            if not self.is_node_a_target(node):
-                self._dump_graph_node(node)
-
-    def _dump_graph_node(self, node, capability=None):
-        context = ConsumptionContext.get_thread_local()
-        console.puts(context.style.node(node.name))
-        if capability is not None:
-            console.puts('{0} ({1})'.format(context.style.property(capability.name),
-                                            context.style.type(capability.type.name)))
-        if node.outbound_relationships:
-            with context.style.indent:
-                for relationship_model in node.outbound_relationships:
-                    relationship_name = context.style.property(relationship_model.name)
-                    if relationship_model.type is not None:
-                        console.puts('-> {0} ({1})'.format(relationship_name,
-                                                           context.style.type(
-                                                               relationship_model.type.name)))
-                    else:
-                        console.puts('-> {0}'.format(relationship_name))
-                    with console.indent(3):
-                        self._dump_graph_node(relationship_model.target_node,
-                                              relationship_model.target_capability)
-
 
 class NodeBase(InstanceModelMixin):
     """
@@ -616,118 +504,6 @@ class NodeBase(InstanceModelMixin):
             return attribute.value if attribute else None
         return None
 
-    def satisfy_requirements(self):
-        node_template = self.node_template
-        satisfied = True
-        for requirement_template in node_template.requirement_templates:
-            # Find target template
-            target_node_template, target_node_capability = \
-                requirement_template.find_target(node_template)
-            if target_node_template is not None:
-                satisfied = self._satisfy_capability(target_node_capability,
-                                                     target_node_template,
-                                                     requirement_template)
-            else:
-                context = ConsumptionContext.get_thread_local()
-                context.validation.report('requirement "{0}" of node "{1}" has no target node '
-                                          'template'.format(requirement_template.name, self.name),
-                                          level=validation.Issue.BETWEEN_INSTANCES)
-                satisfied = False
-        return satisfied
-
-    def _satisfy_capability(self, target_node_capability, target_node_template,
-                            requirement_template):
-        from . import models
-        context = ConsumptionContext.get_thread_local()
-        # Find target nodes
-        target_nodes = target_node_template.nodes
-        if target_nodes:
-            target_node = None
-            target_capability = None
-
-            if target_node_capability is not None:
-                # Relate to the first target node that has capacity
-                for node in target_nodes:
-                    a_target_capability = node.capabilities.get(target_node_capability.name)
-                    if a_target_capability.relate():
-                        target_node = node
-                        target_capability = a_target_capability
-                        break
-            else:
-                # Use first target node
-                target_node = target_nodes[0]
-
-            if target_node is not None:
-                if requirement_template.relationship_template is not None:
-                    relationship_model = \
-                        requirement_template.relationship_template.instantiate(self)
-                else:
-                    relationship_model = models.Relationship()
-                relationship_model.name = requirement_template.name
-                relationship_model.requirement_template = requirement_template
-                relationship_model.target_node = target_node
-                relationship_model.target_capability = target_capability
-                self.outbound_relationships.append(relationship_model)
-                return True
-            else:
-                context.validation.report('requirement "{0}" of node "{1}" targets node '
-                                          'template "{2}" but its instantiated nodes do not '
-                                          'have enough capacity'.format(
-                                              requirement_template.name,
-                                              self.name,
-                                              target_node_template.name),
-                                          level=validation.Issue.BETWEEN_INSTANCES)
-                return False
-        else:
-            context.validation.report('requirement "{0}" of node "{1}" targets node template '
-                                      '"{2}" but it has no instantiated nodes'.format(
-                                          requirement_template.name,
-                                          self.name,
-                                          target_node_template.name),
-                                      level=validation.Issue.BETWEEN_INSTANCES)
-            return False
-
-    def validate_capabilities(self):
-        context = ConsumptionContext.get_thread_local()
-        satisfied = False
-        for capability in self.capabilities.itervalues():
-            if not capability.has_enough_relationships:
-                context.validation.report('capability "{0}" of node "{1}" requires at least {2:d} '
-                                          'relationships but has {3:d}'.format(
-                                              capability.name,
-                                              self.name,
-                                              capability.min_occurrences,
-                                              capability.occurrences),
-                                          level=validation.Issue.BETWEEN_INSTANCES)
-                satisfied = False
-        return satisfied
-
-    def find_host(self):
-        def _find_host(node):
-            if node.type.role == 'host':
-                return node
-            for the_relationship in node.outbound_relationships:
-                if (the_relationship.target_capability is not None) and \
-                    the_relationship.target_capability.type.role == 'host':
-                    host = _find_host(the_relationship.target_node)
-                    if host is not None:
-                        return host
-            for the_relationship in node.inbound_relationships:
-                if (the_relationship.target_capability is not None) and \
-                    the_relationship.target_capability.type.role == 'feature':
-                    host = _find_host(the_relationship.source_node)
-                    if host is not None:
-                        return host
-            return None
-
-        self.host = _find_host(self)
-
-    def configure_operations(self):
-        for interface in self.interfaces.itervalues():
-            interface.configure_operations()
-        for the_relationship in self.outbound_relationships:
-            the_relationship.configure_operations()
-
     @property
     def as_raw(self):
         return collections.OrderedDict((
@@ -740,46 +516,6 @@ class NodeBase(InstanceModelMixin):
             ('capabilities', formatting.as_raw_list(self.capabilities)),
             ('relationships', formatting.as_raw_list(self.outbound_relationships))))
 
-    def validate(self):
-        context = ConsumptionContext.get_thread_local()
-        if len(self.name) > context.modeling.id_max_length:
-            context.validation.report('"{0}" has an ID longer than the limit of {1:d} characters: '
-                                      '{2:d}'.format(
-                                          self.name,
-                                          context.modeling.id_max_length,
-                                          len(self.name)),
-                                      level=validation.Issue.BETWEEN_INSTANCES)
-
-        # TODO: validate that node template is of type?
-
-        utils.validate_dict_values(self.properties)
-        utils.validate_dict_values(self.attributes)
-        utils.validate_dict_values(self.interfaces)
-        utils.validate_dict_values(self.artifacts)
-        utils.validate_dict_values(self.capabilities)
-        utils.validate_list_values(self.outbound_relationships)
-
-    def coerce_values(self, report_issues):
-        utils.coerce_dict_values(self.properties, report_issues)
-        utils.coerce_dict_values(self.attributes, report_issues)
-        utils.coerce_dict_values(self.interfaces, report_issues)
-        utils.coerce_dict_values(self.artifacts, report_issues)
-        utils.coerce_dict_values(self.capabilities, report_issues)
-        utils.coerce_list_values(self.outbound_relationships, report_issues)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        console.puts('Node: {0}'.format(context.style.node(self.name)))
-        with context.style.indent:
-            console.puts('Type: {0}'.format(context.style.type(self.type.name)))
-            console.puts('Template: {0}'.format(context.style.node(self.node_template.name)))
-            utils.dump_dict_values(self.properties, 'Properties')
-            utils.dump_dict_values(self.attributes, 'Attributes')
-            utils.dump_interfaces(self.interfaces)
-            utils.dump_dict_values(self.artifacts, 'Artifacts')
-            utils.dump_dict_values(self.capabilities, 'Capabilities')
-            utils.dump_list_values(self.outbound_relationships, 'Relationships')
-
 
 class GroupBase(InstanceModelMixin):
     """
@@ -885,10 +621,6 @@ class GroupBase(InstanceModelMixin):
     :type: :obj:`basestring`
     """)
 
-    def configure_operations(self):
-        for interface in self.interfaces.itervalues():
-            interface.configure_operations()
-
     @property
     def as_raw(self):
         return collections.OrderedDict((
@@ -896,27 +628,6 @@ class GroupBase(InstanceModelMixin):
             ('properties', formatting.as_raw_dict(self.properties)),
             ('interfaces', formatting.as_raw_list(self.interfaces))))
 
-    def validate(self):
-        utils.validate_dict_values(self.properties)
-        utils.validate_dict_values(self.interfaces)
-
-    def coerce_values(self, report_issues):
-        utils.coerce_dict_values(self.properties, report_issues)
-        utils.coerce_dict_values(self.interfaces, report_issues)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        console.puts('Group: {0}'.format(context.style.node(self.name)))
-        with context.style.indent:
-            console.puts('Type: {0}'.format(context.style.type(self.type.name)))
-            utils.dump_dict_values(self.properties, 'Properties')
-            utils.dump_interfaces(self.interfaces)
-            if self.nodes:
-                console.puts('Member nodes:')
-                with context.style.indent:
-                    for node in self.nodes:
-                        console.puts(context.style.node(node.name))
-
 
 class PolicyBase(InstanceModelMixin):
     """
@@ -1030,29 +741,6 @@ class PolicyBase(InstanceModelMixin):
             ('type_name', self.type.name),
             ('properties', formatting.as_raw_dict(self.properties))))
 
-    def validate(self):
-        utils.validate_dict_values(self.properties)
-
-    def coerce_values(self, report_issues):
-        utils.coerce_dict_values(self.properties, report_issues)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        console.puts('Policy: {0}'.format(context.style.node(self.name)))
-        with context.style.indent:
-            console.puts('Type: {0}'.format(context.style.type(self.type.name)))
-            utils.dump_dict_values(self.properties, 'Properties')
-            if self.nodes:
-                console.puts('Target nodes:')
-                with context.style.indent:
-                    for node in self.nodes:
-                        console.puts(context.style.node(node.name))
-            if self.groups:
-                console.puts('Target groups:')
-                with context.style.indent:
-                    for group in self.groups:
-                        console.puts(context.style.node(group.name))
-
 
 class SubstitutionBase(InstanceModelMixin):
     """
@@ -1130,19 +818,6 @@ class SubstitutionBase(InstanceModelMixin):
             ('node_type_name', self.node_type.name),
             ('mappings', formatting.as_raw_dict(self.mappings))))
 
-    def validate(self):
-        utils.validate_dict_values(self.mappings)
-
-    def coerce_values(self, report_issues):
-        utils.coerce_dict_values(self.mappings, report_issues)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        console.puts('Substitution:')
-        with context.style.indent:
-            console.puts('Node type: {0}'.format(context.style.type(self.node_type.name)))
-            utils.dump_dict_values(self.mappings, 'Mappings')
-
 
 class SubstitutionMappingBase(InstanceModelMixin):
     """
@@ -1238,31 +913,6 @@ class SubstitutionMappingBase(InstanceModelMixin):
         return collections.OrderedDict((
             ('name', self.name),))
 
-    def coerce_values(self, report_issues):
-        pass
-
-    def validate(self):
-        context = ConsumptionContext.get_thread_local()
-        if (self.capability is None) and (self.requirement_template is None):
-            context.validation.report('mapping "{0}" refers to neither capability nor a requirement'
-                                      ' in node: {1}'.format(
-                                          self.name,
-                                          formatting.safe_repr(self.node.name)),
-                                      level=validation.Issue.BETWEEN_TYPES)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        if self.capability is not None:
-            console.puts('{0} -> {1}.{2}'.format(
-                context.style.node(self.name),
-                context.style.node(self.capability.node.name),
-                context.style.node(self.capability.name)))
-        else:
-            console.puts('{0} -> {1}.{2}'.format(
-                context.style.node(self.name),
-                context.style.node(self.node.name),
-                context.style.node(self.requirement_template.name)))
-
 
 class RelationshipBase(InstanceModelMixin):
     """
@@ -1436,10 +1086,6 @@ class RelationshipBase(InstanceModelMixin):
     :type: :obj:`int`
     """)
 
-    def configure_operations(self):
-        for interface in self.interfaces.itervalues():
-            interface.configure_operations()
-
     @property
     def as_raw(self):
         return collections.OrderedDict((
@@ -1452,33 +1098,6 @@ class RelationshipBase(InstanceModelMixin):
             ('properties', formatting.as_raw_dict(self.properties)),
             ('interfaces', formatting.as_raw_list(self.interfaces))))
 
-    def validate(self):
-        utils.validate_dict_values(self.properties)
-        utils.validate_dict_values(self.interfaces)
-
-    def coerce_values(self, report_issues):
-        utils.coerce_dict_values(self.properties, report_issues)
-        utils.coerce_dict_values(self.interfaces, report_issues)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        if self.name:
-            console.puts('{0} ->'.format(context.style.node(self.name)))
-        else:
-            console.puts('->')
-        with context.style.indent:
-            console.puts('Node: {0}'.format(context.style.node(self.target_node.name)))
-            if self.target_capability:
-                console.puts('Capability: {0}'.format(context.style.node(
-                    self.target_capability.name)))
-            if self.type is not None:
-                console.puts('Relationship type: {0}'.format(context.style.type(self.type.name)))
-            if (self.relationship_template is not None) and self.relationship_template.name:
-                console.puts('Relationship template: {0}'.format(
-                    context.style.node(self.relationship_template.name)))
-            utils.dump_dict_values(self.properties, 'Properties')
-            utils.dump_interfaces(self.interfaces, 'Interfaces')
-
 
 class CapabilityBase(InstanceModelMixin):
     """
@@ -1595,25 +1214,6 @@ class CapabilityBase(InstanceModelMixin):
             ('type_name', self.type.name),
             ('properties', formatting.as_raw_dict(self.properties))))
 
-    def validate(self):
-        utils.validate_dict_values(self.properties)
-
-    def coerce_values(self, report_issues):
-        utils.coerce_dict_values(self.properties, report_issues)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        console.puts(context.style.node(self.name))
-        with context.style.indent:
-            console.puts('Type: {0}'.format(context.style.type(self.type.name)))
-            console.puts('Occurrences: {0:d} ({1:d}{2})'.format(
-                self.occurrences,
-                self.min_occurrences or 0,
-                ' to {0:d}'.format(self.max_occurrences)
-                if self.max_occurrences is not None
-                else ' or more'))
-            utils.dump_dict_values(self.properties, 'Properties')
-
 
 class InterfaceBase(InstanceModelMixin):
     """
@@ -1738,10 +1338,6 @@ class InterfaceBase(InstanceModelMixin):
     :type: :obj:`basestring`
     """)
 
-    def configure_operations(self):
-        for operation in self.operations.itervalues():
-            operation.configure()
-
     @property
     def as_raw(self):
         return collections.OrderedDict((
@@ -1751,24 +1347,6 @@ class InterfaceBase(InstanceModelMixin):
             ('inputs', formatting.as_raw_dict(self.inputs)),
             ('operations', formatting.as_raw_list(self.operations))))
 
-    def validate(self):
-        utils.validate_dict_values(self.inputs)
-        utils.validate_dict_values(self.operations)
-
-    def coerce_values(self, report_issues):
-        utils.coerce_dict_values(self.inputs, report_issues)
-        utils.coerce_dict_values(self.operations, report_issues)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        console.puts(context.style.node(self.name))
-        if self.description:
-            console.puts(context.style.meta(self.description))
-        with context.style.indent:
-            console.puts('Interface type: {0}'.format(context.style.type(self.type.name)))
-            utils.dump_dict_values(self.inputs, 'Inputs')
-            utils.dump_dict_values(self.operations, 'Operations')
-
 
 class OperationBase(InstanceModelMixin):
     """
@@ -1944,45 +1522,6 @@ class OperationBase(InstanceModelMixin):
     :type: :obj:`float`
     """)
 
-    def configure(self):
-        if (self.implementation is None) and (self.function is None):
-            return
-
-        if (self.interface is not None) and (self.plugin is None) and (self.function is None):
-            # ("interface" is None for workflow operations, which do not currently use "plugin")
-            # The default (None) plugin is the execution plugin
-            execution_plugin.instantiation.configure_operation(self)
-        else:
-            # In the future plugins may be able to add their own "configure_operation" hook that
-            # can validate the configuration and otherwise create specially derived arguments. For
-            # now, we just send all configuration parameters as arguments without validation.
-            utils.instantiate_dict(self, self.arguments,
-                                   utils.dict_as_arguments(self.configurations))
-
-        if self.interface is not None:
-            # Send all interface inputs as extra arguments
-            # ("interface" is None for workflow operations)
-            # Note that they will override existing arguments of the same names
-            utils.instantiate_dict(self, self.arguments,
-                                   utils.dict_as_arguments(self.interface.inputs))
-
-        # Send all inputs as extra arguments
-        # Note that they will override existing arguments of the same names
-        utils.instantiate_dict(self, self.arguments, utils.dict_as_arguments(self.inputs))
-
-        # Check for reserved arguments
-        from ..orchestrator.decorators import OPERATION_DECORATOR_RESERVED_ARGUMENTS
-        used_reserved_names = \
-            OPERATION_DECORATOR_RESERVED_ARGUMENTS.intersection(self.arguments.keys())
-        if used_reserved_names:
-            context = ConsumptionContext.get_thread_local()
-            context.validation.report('using reserved arguments in operation "{0}": {1}'
-                                      .format(
-                                          self.name,
-                                          formatting.string_list_as_string(used_reserved_names)),
-                                      level=validation.Issue.EXTERNAL)
-
-
     @property
     def as_raw(self):
         return collections.OrderedDict((
@@ -1992,46 +1531,6 @@ class OperationBase(InstanceModelMixin):
             ('dependencies', self.dependencies),
             ('inputs', formatting.as_raw_dict(self.inputs))))
 
-    def validate(self):
-        # TODO must be associated with either interface or service
-        utils.validate_dict_values(self.inputs)
-        utils.validate_dict_values(self.configurations)
-        utils.validate_dict_values(self.arguments)
-
-    def coerce_values(self, report_issues):
-        utils.coerce_dict_values(self.inputs, report_issues)
-        utils.coerce_dict_values(self.configurations, report_issues)
-        utils.coerce_dict_values(self.arguments, report_issues)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        console.puts(context.style.node(self.name))
-        if self.description:
-            console.puts(context.style.meta(self.description))
-        with context.style.indent:
-            if self.implementation is not None:
-                console.puts('Implementation: {0}'.format(
-                    context.style.literal(self.implementation)))
-            if self.dependencies:
-                console.puts(
-                    'Dependencies: {0}'.format(
-                        ', '.join((str(context.style.literal(v)) for v in self.dependencies))))
-            utils.dump_dict_values(self.inputs, 'Inputs')
-            if self.executor is not None:
-                console.puts('Executor: {0}'.format(context.style.literal(self.executor)))
-            if self.max_attempts is not None:
-                console.puts('Max attempts: {0}'.format(context.style.literal(self.max_attempts)))
-            if self.retry_interval is not None:
-                console.puts('Retry interval: {0}'.format(
-                    context.style.literal(self.retry_interval)))
-            if self.plugin is not None:
-                console.puts('Plugin: {0}'.format(
-                    context.style.literal(self.plugin.name)))
-            utils.dump_dict_values(self.configurations, 'Configuration')
-            if self.function is not None:
-                console.puts('Function: {0}'.format(context.style.literal(self.function)))
-            utils.dump_dict_values(self.arguments, 'Arguments')
-
 
 class ArtifactBase(InstanceModelMixin):
     """
@@ -2150,27 +1649,3 @@ class ArtifactBase(InstanceModelMixin):
             ('repository_url', self.repository_url),
             ('repository_credential', formatting.as_agnostic(self.repository_credential)),
             ('properties', formatting.as_raw_dict(self.properties))))
-
-    def validate(self):
-        utils.validate_dict_values(self.properties)
-
-    def coerce_values(self, report_issues):
-        utils.coerce_dict_values(self.properties, report_issues)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        console.puts(context.style.node(self.name))
-        if self.description:
-            console.puts(context.style.meta(self.description))
-        with context.style.indent:
-            console.puts('Artifact type: {0}'.format(context.style.type(self.type.name)))
-            console.puts('Source path: {0}'.format(context.style.literal(self.source_path)))
-            if self.target_path is not None:
-                console.puts('Target path: {0}'.format(context.style.literal(self.target_path)))
-            if self.repository_url is not None:
-                console.puts('Repository URL: {0}'.format(
-                    context.style.literal(self.repository_url)))
-            if self.repository_credential:
-                console.puts('Repository credential: {0}'.format(
-                    context.style.literal(self.repository_credential)))
-            utils.dump_dict_values(self.properties, 'Properties')

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/modeling/service_template.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_template.py b/aria/modeling/service_template.py
index 2246340..d988d21 100644
--- a/aria/modeling/service_template.py
+++ b/aria/modeling/service_template.py
@@ -21,8 +21,6 @@ ARIA modeling service template module
 
 from __future__ import absolute_import  # so we can import standard 'types'
 
-from datetime import datetime
-
 from sqlalchemy import (
     Column,
     Text,
@@ -33,15 +31,10 @@ from sqlalchemy import (
 )
 from sqlalchemy.ext.declarative import declared_attr
 
-from ..parser import validation
-from ..parser.consumption import ConsumptionContext
-from ..parser.reading import deepcopy_with_locators
-from ..utils import (collections, formatting, console)
-from ..utils.versions import VersionString
+from ..utils import (collections, formatting)
 from .mixins import TemplateModelMixin
 from . import (
     relationship,
-    utils,
     types as modeling_types
 )
 
@@ -331,130 +324,6 @@ class ServiceTemplateBase(TemplateModelMixin):
             ('interface_types', formatting.as_raw(self.interface_types)),
             ('artifact_types', formatting.as_raw(self.artifact_types))))
 
-    def instantiate(self, container, model_storage, inputs=None):  # pylint: disable=arguments-differ
-        from . import models
-        now = datetime.now()
-        service = models.Service(created_at=now,
-                                 updated_at=now,
-                                 description=deepcopy_with_locators(self.description),
-                                 service_template=self)
-
-        # TODO: we want to remove this use of the context
-        context = ConsumptionContext.get_thread_local()
-        context.modeling.instance = service
-
-        utils.validate_no_undeclared_inputs(declared_inputs=self.inputs,
-                                            supplied_inputs=inputs or {})
-        utils.validate_required_inputs_are_supplied(declared_inputs=self.inputs,
-                                                    supplied_inputs=inputs or {})
-
-        service.inputs = utils.merge_parameter_values(inputs, self.inputs, model_cls=models.Input)
-        # TODO: now that we have inputs, we should scan properties and inputs and evaluate functions
-
-        for plugin_specification in self.plugin_specifications.itervalues():
-            if plugin_specification.enabled:
-                if plugin_specification.resolve(model_storage):
-                    plugin = plugin_specification.plugin
-                    service.plugins[plugin.name] = plugin
-                else:
-                    context = ConsumptionContext.get_thread_local()
-                    context.validation.report('specified plugin not found: {0}'.format(
-                        plugin_specification.name), level=validation.Issue.EXTERNAL)
-
-        utils.instantiate_dict(self, service.meta_data, self.meta_data)
-
-        for node_template in self.node_templates.itervalues():
-            for _ in range(node_template.scaling['default_instances']):
-                node = node_template.instantiate(container)
-                service.nodes[node.name] = node
-
-        utils.instantiate_dict(self, service.groups, self.group_templates)
-        utils.instantiate_dict(self, service.policies, self.policy_templates)
-        utils.instantiate_dict(self, service.workflows, self.workflow_templates)
-
-        if self.substitution_template is not None:
-            service.substitution = self.substitution_template.instantiate(container)
-
-        utils.instantiate_dict(self, service.outputs, self.outputs)
-
-        return service
-
-    def validate(self):
-        utils.validate_dict_values(self.meta_data)
-        utils.validate_dict_values(self.node_templates)
-        utils.validate_dict_values(self.group_templates)
-        utils.validate_dict_values(self.policy_templates)
-        if self.substitution_template is not None:
-            self.substitution_template.validate()
-        utils.validate_dict_values(self.inputs)
-        utils.validate_dict_values(self.outputs)
-        utils.validate_dict_values(self.workflow_templates)
-        if self.node_types is not None:
-            self.node_types.validate()
-        if self.group_types is not None:
-            self.group_types.validate()
-        if self.policy_types is not None:
-            self.policy_types.validate()
-        if self.relationship_types is not None:
-            self.relationship_types.validate()
-        if self.capability_types is not None:
-            self.capability_types.validate()
-        if self.interface_types is not None:
-            self.interface_types.validate()
-        if self.artifact_types is not None:
-            self.artifact_types.validate()
-
-    def coerce_values(self, report_issues):
-        utils.coerce_dict_values(self.meta_data, report_issues)
-        utils.coerce_dict_values(self.node_templates, report_issues)
-        utils.coerce_dict_values(self.group_templates, report_issues)
-        utils.coerce_dict_values(self.policy_templates, report_issues)
-        if self.substitution_template is not None:
-            self.substitution_template.coerce_values(report_issues)
-        utils.coerce_dict_values(self.inputs, report_issues)
-        utils.coerce_dict_values(self.outputs, report_issues)
-        utils.coerce_dict_values(self.workflow_templates, report_issues)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        if self.description is not None:
-            console.puts(context.style.meta(self.description))
-        utils.dump_dict_values(self.meta_data, 'Metadata')
-        for node_template in self.node_templates.itervalues():
-            node_template.dump()
-        for group_template in self.group_templates.itervalues():
-            group_template.dump()
-        for policy_template in self.policy_templates.itervalues():
-            policy_template.dump()
-        if self.substitution_template is not None:
-            self.substitution_template.dump()
-        utils.dump_dict_values(self.inputs, 'Inputs')
-        utils.dump_dict_values(self.outputs, 'Outputs')
-        utils.dump_dict_values(self.workflow_templates, 'Workflow templates')
-
-    def dump_types(self):
-        if self.node_types.children:
-            console.puts('Node types:')
-            self.node_types.dump()
-        if self.group_types.children:
-            console.puts('Group types:')
-            self.group_types.dump()
-        if self.capability_types.children:
-            console.puts('Capability types:')
-            self.capability_types.dump()
-        if self.relationship_types.children:
-            console.puts('Relationship types:')
-            self.relationship_types.dump()
-        if self.policy_types.children:
-            console.puts('Policy types:')
-            self.policy_types.dump()
-        if self.artifact_types.children:
-            console.puts('Artifact types:')
-            self.artifact_types.dump()
-        if self.interface_types.children:
-            console.puts('Interface types:')
-            self.interface_types.dump()
-
 
 class NodeTemplateBase(TemplateModelMixin):
     """
@@ -625,114 +494,6 @@ class NodeTemplateBase(TemplateModelMixin):
             ('capability_templates', formatting.as_raw_list(self.capability_templates)),
             ('requirement_templates', formatting.as_raw_list(self.requirement_templates))))
 
-    def instantiate(self, container):
-        from . import models
-        node = models.Node(name=self._next_name,
-                           type=self.type,
-                           description=deepcopy_with_locators(self.description),
-                           state=models.Node.INITIAL,
-                           node_template=self)
-        utils.instantiate_dict(node, node.properties, self.properties)
-        utils.instantiate_dict(node, node.attributes, self.attributes)
-        utils.instantiate_dict(node, node.interfaces, self.interface_templates)
-        utils.instantiate_dict(node, node.artifacts, self.artifact_templates)
-        utils.instantiate_dict(node, node.capabilities, self.capability_templates)
-
-        # Default attributes
-        if ('tosca_name' in node.attributes) \
-            and (node.attributes['tosca_name'].type_name == 'string'):
-            node.attributes['tosca_name'].value = self.name
-        if 'tosca_id' in node.attributes \
-            and (node.attributes['tosca_id'].type_name == 'string'):
-            node.attributes['tosca_id'].value = node.name
-
-        return node
-
-    def validate(self):
-        utils.validate_dict_values(self.properties)
-        utils.validate_dict_values(self.attributes)
-        utils.validate_dict_values(self.interface_templates)
-        utils.validate_dict_values(self.artifact_templates)
-        utils.validate_dict_values(self.capability_templates)
-        utils.validate_list_values(self.requirement_templates)
-
-    def coerce_values(self, report_issues):
-        utils.coerce_dict_values(self.properties, report_issues)
-        utils.coerce_dict_values(self.attributes, report_issues)
-        utils.coerce_dict_values(self.interface_templates, report_issues)
-        utils.coerce_dict_values(self.artifact_templates, report_issues)
-        utils.coerce_dict_values(self.capability_templates, report_issues)
-        utils.coerce_list_values(self.requirement_templates, report_issues)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        console.puts('Node template: {0}'.format(context.style.node(self.name)))
-        if self.description:
-            console.puts(context.style.meta(self.description))
-        with context.style.indent:
-            console.puts('Type: {0}'.format(context.style.type(self.type.name)))
-            utils.dump_dict_values(self.properties, 'Properties')
-            utils.dump_dict_values(self.attributes, 'Attributes')
-            utils.dump_interfaces(self.interface_templates)
-            utils.dump_dict_values(self.artifact_templates, 'Artifact templates')
-            utils.dump_dict_values(self.capability_templates, 'Capability templates')
-            utils.dump_list_values(self.requirement_templates, 'Requirement templates')
-
-    @property
-    def scaling(self):
-        scaling = {}
-
-        def extract_property(properties, name):
-            if name in scaling:
-                return
-            prop = properties.get(name)
-            if (prop is not None) and (prop.type_name == 'integer') and (prop.value is not None):
-                scaling[name] = prop.value
-
-        def extract_properties(properties):
-            extract_property(properties, 'min_instances')
-            extract_property(properties, 'max_instances')
-            extract_property(properties, 'default_instances')
-
-        def default_property(name, value):
-            if name not in scaling:
-                scaling[name] = value
-
-        # From our scaling capabilities
-        for capability_template in self.capability_templates.itervalues():
-            if capability_template.type.role == 'scaling':
-                extract_properties(capability_template.properties)
-
-        # From service scaling policies
-        for policy_template in self.service_template.policy_templates.itervalues():
-            if policy_template.type.role == 'scaling':
-                if policy_template.is_for_node_template(self.name):
-                    extract_properties(policy_template.properties)
-
-        # Defaults
-        default_property('min_instances', 0)
-        default_property('max_instances', 1)
-        default_property('default_instances', 1)
-
-        # Validate
-        # pylint: disable=too-many-boolean-expressions
-        if ((scaling['min_instances'] < 0) or
-                (scaling['max_instances'] < 0) or
-                (scaling['default_instances'] < 0) or
-                (scaling['max_instances'] < scaling['min_instances']) or
-                (scaling['default_instances'] < scaling['min_instances']) or
-                (scaling['default_instances'] > scaling['max_instances'])):
-            context = ConsumptionContext.get_thread_local()
-            context.validation.report('invalid scaling parameters for node template "{0}": '
-                                      'min={1}, max={2}, default={3}'.format(
-                                          self.name,
-                                          scaling['min_instances'],
-                                          scaling['max_instances'],
-                                          scaling['default_instances']),
-                                      level=validation.Issue.BETWEEN_TYPES)
-
-        return scaling
-
     def is_target_node_template_valid(self, target_node_template):
         """
         Checks if ``target_node_template`` matches all our ``target_node_template_constraints``.
@@ -769,6 +530,40 @@ class NodeTemplateBase(TemplateModelMixin):
 
         return '{name}_{index}'.format(name=self.name, index=self._next_index)
 
+    @property
+    def scaling(self):
+        scaling = {}
+
+        def extract_property(properties, name):
+            if name in scaling:
+                return
+            prop = properties.get(name)
+            if (prop is not None) and (prop.type_name == 'integer') and (prop.value is not None):
+                scaling[name] = prop.value
+
+        def extract_properties(properties):
+            extract_property(properties, 'min_instances')
+            extract_property(properties, 'max_instances')
+            extract_property(properties, 'default_instances')
+
+        # From our scaling capabilities
+        for capability_template in self.capability_templates.itervalues():
+            if capability_template.type.role == 'scaling':
+                extract_properties(capability_template.properties)
+
+        # From service scaling policies
+        for policy_template in self.service_template.policy_templates.itervalues():
+            if policy_template.type.role == 'scaling':
+                if policy_template.is_for_node_template(self.name):
+                    extract_properties(policy_template.properties)
+
+        # Defaults
+        scaling.setdefault('min_instances', 0)
+        scaling.setdefault('max_instances', 1)
+        scaling.setdefault('default_instances', 1)
+
+        return scaling
+
 
 class GroupTemplateBase(TemplateModelMixin):
     """
@@ -876,40 +671,6 @@ class GroupTemplateBase(TemplateModelMixin):
             ('properties', formatting.as_raw_dict(self.properties)),
             ('interface_templates', formatting.as_raw_list(self.interface_templates))))
 
-    def instantiate(self, container):
-        from . import models
-        group = models.Group(name=self.name,
-                             type=self.type,
-                             description=deepcopy_with_locators(self.description),
-                             group_template=self)
-        utils.instantiate_dict(self, group.properties, self.properties)
-        utils.instantiate_dict(self, group.interfaces, self.interface_templates)
-        if self.node_templates:
-            for node_template in self.node_templates:
-                group.nodes += node_template.nodes
-        return group
-
-    def validate(self):
-        utils.validate_dict_values(self.properties)
-        utils.validate_dict_values(self.interface_templates)
-
-    def coerce_values(self, report_issues):
-        utils.coerce_dict_values(self.properties, report_issues)
-        utils.coerce_dict_values(self.interface_templates, report_issues)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        console.puts('Group template: {0}'.format(context.style.node(self.name)))
-        if self.description:
-            console.puts(context.style.meta(self.description))
-        with context.style.indent:
-            console.puts('Type: {0}'.format(context.style.type(self.type.name)))
-            utils.dump_dict_values(self.properties, 'Properties')
-            utils.dump_interfaces(self.interface_templates)
-            if self.node_templates:
-                console.puts('Member node templates: {0}'.format(', '.join(
-                    (str(context.style.node(v.name)) for v in self.node_templates))))
-
     def contains_node_template(self, name):
         for node_template in self.node_templates:
             if node_template.name == name:
@@ -1022,42 +783,6 @@ class PolicyTemplateBase(TemplateModelMixin):
             ('type_name', self.type.name),
             ('properties', formatting.as_raw_dict(self.properties))))
 
-    def instantiate(self, container):
-        from . import models
-        policy = models.Policy(name=self.name,
-                               type=self.type,
-                               description=deepcopy_with_locators(self.description),
-                               policy_template=self)
-        utils.instantiate_dict(self, policy.properties, self.properties)
-        if self.node_templates:
-            for node_template in self.node_templates:
-                policy.nodes += node_template.nodes
-        if self.group_templates:
-            for group_template in self.group_templates:
-                policy.groups += group_template.groups
-        return policy
-
-    def validate(self):
-        utils.validate_dict_values(self.properties)
-
-    def coerce_values(self, report_issues):
-        utils.coerce_dict_values(self.properties, report_issues)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        console.puts('Policy template: {0}'.format(context.style.node(self.name)))
-        if self.description:
-            console.puts(context.style.meta(self.description))
-        with context.style.indent:
-            console.puts('Type: {0}'.format(context.style.type(self.type.name)))
-            utils.dump_dict_values(self.properties, 'Properties')
-            if self.node_templates:
-                console.puts('Target node templates: {0}'.format(', '.join(
-                    (str(context.style.node(v.name)) for v in self.node_templates))))
-            if self.group_templates:
-                console.puts('Target group templates: {0}'.format(', '.join(
-                    (str(context.style.node(v.name)) for v in self.group_templates))))
-
     def is_for_node_template(self, name):
         for node_template in self.node_templates:
             if node_template.name == name:
@@ -1134,26 +859,6 @@ class SubstitutionTemplateBase(TemplateModelMixin):
             ('node_type_name', self.node_type.name),
             ('mappings', formatting.as_raw_dict(self.mappings))))
 
-    def instantiate(self, container):
-        from . import models
-        substitution = models.Substitution(node_type=self.node_type,
-                                           substitution_template=self)
-        utils.instantiate_dict(container, substitution.mappings, self.mappings)
-        return substitution
-
-    def validate(self):
-        utils.validate_dict_values(self.mappings)
-
-    def coerce_values(self, report_issues):
-        utils.coerce_dict_values(self.mappings, report_issues)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        console.puts('Substitution template:')
-        with context.style.indent:
-            console.puts('Node type: {0}'.format(context.style.type(self.node_type.name)))
-            utils.dump_dict_values(self.mappings, 'Mappings')
-
 
 class SubstitutionTemplateMappingBase(TemplateModelMixin):
     """
@@ -1233,59 +938,6 @@ class SubstitutionTemplateMappingBase(TemplateModelMixin):
         return collections.OrderedDict((
             ('name', self.name),))
 
-    def coerce_values(self, report_issues):
-        pass
-
-    def instantiate(self, container):
-        from . import models
-        context = ConsumptionContext.get_thread_local()
-        if self.capability_template is not None:
-            node_template = self.capability_template.node_template
-        else:
-            node_template = self.requirement_template.node_template
-        nodes = node_template.nodes
-        if len(nodes) == 0:
-            context.validation.report(
-                'mapping "{0}" refers to node template "{1}" but there are no '
-                'node instances'.format(self.mapped_name, self.node_template.name),
-                level=validation.Issue.BETWEEN_INSTANCES)
-            return None
-        # The TOSCA spec does not provide a way to choose the node,
-        # so we will just pick the first one
-        node = nodes[0]
-        capability = None
-        if self.capability_template:
-            for a_capability in node.capabilities.itervalues():
-                if a_capability.capability_template.name == self.capability_template.name:
-                    capability = a_capability
-        return models.SubstitutionMapping(name=self.name,
-                                          capability=capability,
-                                          requirement_template=self.requirement_template,
-                                          node=node)
-
-
-    def validate(self):
-        context = ConsumptionContext.get_thread_local()
-        if (self.capability_template is None) and (self.requirement_template is None):
-            context.validation.report('mapping "{0}" refers to neither capability nor a requirement'
-                                      ' in node template: {1}'.format(
-                                          self.name,
-                                          formatting.safe_repr(self.node_template.name)),
-                                      level=validation.Issue.BETWEEN_TYPES)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        if self.capability_template is not None:
-            node_template = self.capability_template.node_template
-        else:
-            node_template = self.requirement_template.node_template
-        console.puts('{0} -> {1}.{2}'.format(
-            context.style.node(self.name),
-            context.style.node(node_template.name),
-            context.style.node(self.capability_template.name
-                               if self.capability_template
-                               else self.requirement_template.name)))
-
 
 class RequirementTemplateBase(TemplateModelMixin):
     """
@@ -1424,56 +1076,6 @@ class RequirementTemplateBase(TemplateModelMixin):
     :type: [:class:`NodeTemplateConstraint`]
     """)
 
-    def find_target(self, source_node_template):
-        context = ConsumptionContext.get_thread_local()
-
-        # We might already have a specific node template, so we'll just verify it
-        if self.target_node_template is not None:
-            if not source_node_template.is_target_node_template_valid(self.target_node_template):
-                context.validation.report('requirement "{0}" of node template "{1}" is for node '
-                                          'template "{2}" but it does not match constraints'.format(
-                                              self.name,
-                                              self.target_node_template.name,
-                                              source_node_template.name),
-                                          level=validation.Issue.BETWEEN_TYPES)
-            if (self.target_capability_type is not None) \
-                or (self.target_capability_name is not None):
-                target_node_capability = self.find_target_capability(source_node_template,
-                                                                     self.target_node_template)
-                if target_node_capability is None:
-                    return None, None
-            else:
-                target_node_capability = None
-
-            return self.target_node_template, target_node_capability
-
-        # Find first node that matches the type
-        elif self.target_node_type is not None:
-            for target_node_template in \
-                    self.node_template.service_template.node_templates.itervalues():
-                if self.target_node_type.get_descendant(target_node_template.type.name) is None:
-                    continue
-
-                if not source_node_template.is_target_node_template_valid(target_node_template):
-                    continue
-
-                target_node_capability = self.find_target_capability(source_node_template,
-                                                                     target_node_template)
-                if target_node_capability is None:
-                    continue
-
-                return target_node_template, target_node_capability
-
-        return None, None
-
-    def find_target_capability(self, source_node_template, target_node_template):
-        for capability_template in target_node_template.capability_templates.itervalues():
-            if capability_template.satisfies_requirement(source_node_template,
-                                                         self,
-                                                         target_node_template):
-                return capability_template
-        return None
-
     @property
     def as_raw(self):
         return collections.OrderedDict((
@@ -1487,43 +1089,6 @@ class RequirementTemplateBase(TemplateModelMixin):
             ('target_capability_name', self.target_capability_name),
             ('relationship_template', formatting.as_raw(self.relationship_template))))
 
-    def validate(self):
-        if self.relationship_template:
-            self.relationship_template.validate()
-
-    def coerce_values(self, report_issues):
-        if self.relationship_template is not None:
-            self.relationship_template.coerce_values(report_issues)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        if self.name:
-            console.puts(context.style.node(self.name))
-        else:
-            console.puts('Requirement:')
-        with context.style.indent:
-            if self.target_node_type is not None:
-                console.puts('Target node type: {0}'.format(
-                    context.style.type(self.target_node_type.name)))
-            elif self.target_node_template is not None:
-                console.puts('Target node template: {0}'.format(
-                    context.style.node(self.target_node_template.name)))
-            if self.target_capability_type is not None:
-                console.puts('Target capability type: {0}'.format(
-                    context.style.type(self.target_capability_type.name)))
-            elif self.target_capability_name is not None:
-                console.puts('Target capability name: {0}'.format(
-                    context.style.node(self.target_capability_name)))
-            if self.target_node_template_constraints:
-                console.puts('Target node template constraints:')
-                with context.style.indent:
-                    for constraint in self.target_node_template_constraints:
-                        console.puts(context.style.literal(constraint))
-            if self.relationship_template:
-                console.puts('Relationship:')
-                with context.style.indent:
-                    self.relationship_template.dump()
-
 
 class RelationshipTemplateBase(TemplateModelMixin):
     """
@@ -1606,37 +1171,6 @@ class RelationshipTemplateBase(TemplateModelMixin):
             ('properties', formatting.as_raw_dict(self.properties)),
             ('interface_templates', formatting.as_raw_list(self.interface_templates))))
 
-    def instantiate(self, container):
-        from . import models
-        relationship_model = models.Relationship(name=self.name,
-                                                 type=self.type,
-                                                 relationship_template=self)
-        utils.instantiate_dict(container, relationship_model.properties, self.properties)
-        utils.instantiate_dict(container, relationship_model.interfaces, self.interface_templates)
-        return relationship_model
-
-    def validate(self):
-        # TODO: either type or name must be set
-        utils.validate_dict_values(self.properties)
-        utils.validate_dict_values(self.interface_templates)
-
-    def coerce_values(self, report_issues):
-        utils.coerce_dict_values(self.properties, report_issues)
-        utils.coerce_dict_values(self.interface_templates, report_issues)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        if self.type is not None:
-            console.puts('Relationship type: {0}'.format(context.style.type(self.type.name)))
-        else:
-            console.puts('Relationship template: {0}'.format(
-                context.style.node(self.name)))
-        if self.description:
-            console.puts(context.style.meta(self.description))
-        with context.style.indent:
-            utils.dump_dict_values(self.properties, 'Properties')
-            utils.dump_interfaces(self.interface_templates, 'Interface templates')
-
 
 class CapabilityTemplateBase(TemplateModelMixin):
     """
@@ -1739,29 +1273,6 @@ class CapabilityTemplateBase(TemplateModelMixin):
     :type: :obj:`int`
     """)
 
-    def satisfies_requirement(self,
-                              source_node_template,
-                              requirement,
-                              target_node_template):
-        # Do we match the required capability type?
-        if requirement.target_capability_type and \
-            requirement.target_capability_type.get_descendant(self.type.name) is None:
-            return False
-
-        # Are we in valid_source_node_types?
-        if self.valid_source_node_types:
-            for valid_source_node_type in self.valid_source_node_types:
-                if valid_source_node_type.get_descendant(source_node_template.type.name) is None:
-                    return False
-
-        # Apply requirement constraints
-        if requirement.target_node_template_constraints:
-            for node_template_constraint in requirement.target_node_template_constraints:
-                if not node_template_constraint.matches(source_node_template, target_node_template):
-                    return False
-
-        return True
-
     @property
     def as_raw(self):
         return collections.OrderedDict((
@@ -1773,42 +1284,6 @@ class CapabilityTemplateBase(TemplateModelMixin):
             ('valid_source_node_types', [v.name for v in self.valid_source_node_types]),
             ('properties', formatting.as_raw_dict(self.properties))))
 
-    def instantiate(self, container):
-        from . import models
-        capability = models.Capability(name=self.name,
-                                       type=self.type,
-                                       min_occurrences=self.min_occurrences,
-                                       max_occurrences=self.max_occurrences,
-                                       occurrences=0,
-                                       capability_template=self)
-        utils.instantiate_dict(container, capability.properties, self.properties)
-        return capability
-
-    def validate(self):
-        utils.validate_dict_values(self.properties)
-
-    def coerce_values(self, report_issues):
-        utils.coerce_dict_values(self.properties, report_issues)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        console.puts(context.style.node(self.name))
-        if self.description:
-            console.puts(context.style.meta(self.description))
-        with context.style.indent:
-            console.puts('Type: {0}'.format(context.style.type(self.type.name)))
-            console.puts(
-                'Occurrences: {0:d}{1}'.format(
-                    self.min_occurrences or 0,
-                    ' to {0:d}'.format(self.max_occurrences)
-                    if self.max_occurrences is not None
-                    else ' or more'))
-            if self.valid_source_node_types:
-                console.puts('Valid source node types: {0}'.format(
-                    ', '.join((str(context.style.type(v.name))
-                               for v in self.valid_source_node_types))))
-            utils.dump_dict_values(self.properties, 'Properties')
-
 
 class InterfaceTemplateBase(TemplateModelMixin):
     """
@@ -1938,34 +1413,6 @@ class InterfaceTemplateBase(TemplateModelMixin):
             # TODO fix self.properties reference
             ('operation_templates', formatting.as_raw_list(self.operation_templates))))
 
-    def instantiate(self, container):
-        from . import models
-        interface = models.Interface(name=self.name,
-                                     type=self.type,
-                                     description=deepcopy_with_locators(self.description),
-                                     interface_template=self)
-        utils.instantiate_dict(container, interface.inputs, self.inputs)
-        utils.instantiate_dict(container, interface.operations, self.operation_templates)
-        return interface
-
-    def validate(self):
-        utils.validate_dict_values(self.inputs)
-        utils.validate_dict_values(self.operation_templates)
-
-    def coerce_values(self, report_issues):
-        utils.coerce_dict_values(self.inputs, report_issues)
-        utils.coerce_dict_values(self.operation_templates, report_issues)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        console.puts(context.style.node(self.name))
-        if self.description:
-            console.puts(context.style.meta(self.description))
-        with context.style.indent:
-            console.puts('Interface type: {0}'.format(context.style.type(self.type.name)))
-            utils.dump_dict_values(self.inputs, 'Inputs')
-            utils.dump_dict_values(self.operation_templates, 'Operation templates')
-
 
 class OperationTemplateBase(TemplateModelMixin):
     """
@@ -2124,65 +1571,6 @@ class OperationTemplateBase(TemplateModelMixin):
             ('dependencies', self.dependencies),
             ('inputs', formatting.as_raw_dict(self.inputs))))
 
-    def instantiate(self, container):
-        from . import models
-
-        plugin = self.plugin_specification.plugin \
-            if (self.plugin_specification is not None) and self.plugin_specification.enabled \
-            else None
-
-        operation = models.Operation(name=self.name,
-                                     description=deepcopy_with_locators(self.description),
-                                     relationship_edge=self.relationship_edge,
-                                     implementation=self.implementation,
-                                     dependencies=self.dependencies,
-                                     executor=self.executor,
-                                     plugin=plugin,
-                                     function=self.function,
-                                     max_attempts=self.max_attempts,
-                                     retry_interval=self.retry_interval,
-                                     operation_template=self)
-
-        utils.instantiate_dict(container, operation.inputs, self.inputs)
-        utils.instantiate_dict(container, operation.configurations, self.configurations)
-
-        return operation
-
-    def validate(self):
-        utils.validate_dict_values(self.inputs)
-        utils.validate_dict_values(self.configurations)
-
-    def coerce_values(self, report_issues):
-        utils.coerce_dict_values(self.inputs, report_issues)
-        utils.coerce_dict_values(self.configurations, report_issues)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        console.puts(context.style.node(self.name))
-        if self.description:
-            console.puts(context.style.meta(self.description))
-        with context.style.indent:
-            if self.implementation is not None:
-                console.puts('Implementation: {0}'.format(
-                    context.style.literal(self.implementation)))
-            if self.dependencies:
-                console.puts('Dependencies: {0}'.format(
-                    ', '.join((str(context.style.literal(v)) for v in self.dependencies))))
-            utils.dump_dict_values(self.inputs, 'Inputs')
-            if self.executor is not None:
-                console.puts('Executor: {0}'.format(context.style.literal(self.executor)))
-            if self.max_attempts is not None:
-                console.puts('Max attempts: {0}'.format(context.style.literal(self.max_attempts)))
-            if self.retry_interval is not None:
-                console.puts('Retry interval: {0}'.format(
-                    context.style.literal(self.retry_interval)))
-            if self.plugin_specification is not None:
-                console.puts('Plugin specification: {0}'.format(
-                    context.style.literal(self.plugin_specification.name)))
-            utils.dump_dict_values(self.configurations, 'Configuration')
-            if self.function is not None:
-                console.puts('Function: {0}'.format(context.style.literal(self.function)))
-
 
 class ArtifactTemplateBase(TemplateModelMixin):
     """
@@ -2295,43 +1683,6 @@ class ArtifactTemplateBase(TemplateModelMixin):
             ('repository_credential', formatting.as_agnostic(self.repository_credential)),
             ('properties', formatting.as_raw_dict(self.properties))))
 
-    def instantiate(self, container):
-        from . import models
-        artifact = models.Artifact(name=self.name,
-                                   type=self.type,
-                                   description=deepcopy_with_locators(self.description),
-                                   source_path=self.source_path,
-                                   target_path=self.target_path,
-                                   repository_url=self.repository_url,
-                                   repository_credential=self.repository_credential,
-                                   artifact_template=self)
-        utils.instantiate_dict(container, artifact.properties, self.properties)
-        return artifact
-
-    def validate(self):
-        utils.validate_dict_values(self.properties)
-
-    def coerce_values(self, report_issues):
-        utils.coerce_dict_values(self.properties, report_issues)
-
-    def dump(self):
-        context = ConsumptionContext.get_thread_local()
-        console.puts(context.style.node(self.name))
-        if self.description:
-            console.puts(context.style.meta(self.description))
-        with context.style.indent:
-            console.puts('Artifact type: {0}'.format(context.style.type(self.type.name)))
-            console.puts('Source path: {0}'.format(context.style.literal(self.source_path)))
-            if self.target_path is not None:
-                console.puts('Target path: {0}'.format(context.style.literal(self.target_path)))
-            if self.repository_url is not None:
-                console.puts('Repository URL: {0}'.format(
-                    context.style.literal(self.repository_url)))
-            if self.repository_credential:
-                console.puts('Repository credential: {0}'.format(
-                    context.style.literal(self.repository_credential)))
-            utils.dump_dict_values(self.properties, 'Properties')
-
 
 class PluginSpecificationBase(TemplateModelMixin):
     """
@@ -2399,24 +1750,3 @@ class PluginSpecificationBase(TemplateModelMixin):
             ('name', self.name),
             ('version', self.version),
             ('enabled', self.enabled)))
-
-    def coerce_values(self, report_issues):
-        pass
-
-    def resolve(self, model_storage):
-        # TODO: we are planning a separate "instantiation" module where this will be called or
-        # moved to.
-        plugins = model_storage.plugin.list()
-        matching_plugins = []
-        if plugins:
-            for plugin in plugins:
-                if (plugin.name == self.name) and \
-                    ((self.version is None) or \
-                     (VersionString(plugin.package_version) >= self.version)):
-                    matching_plugins.append(plugin)
-        self.plugin = None
-        if matching_plugins:
-            # Return highest version of plugin
-            key = lambda plugin: VersionString(plugin.package_version).key
-            self.plugin = sorted(matching_plugins, key=key)[-1]
-        return self.plugin is not None


[2/5] incubator-ariatosca git commit: ARIA-174 Refactor instantiation phase

Posted by em...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/modeling/utils.py
----------------------------------------------------------------------
diff --git a/aria/modeling/utils.py b/aria/modeling/utils.py
index 274eb88..305020b 100644
--- a/aria/modeling/utils.py
+++ b/aria/modeling/utils.py
@@ -22,8 +22,6 @@ from json import JSONEncoder
 from StringIO import StringIO
 
 from . import exceptions
-from ..parser.consumption import ConsumptionContext
-from ..utils.console import puts
 from ..utils.type import validate_value_type
 from ..utils.collections import OrderedDict
 from ..utils.formatting import string_list_as_string
@@ -84,7 +82,7 @@ def validate_required_inputs_are_supplied(declared_inputs, supplied_inputs):
             .format(string_list_as_string(missing_required_inputs)))
 
 
-def merge_parameter_values(provided_values, declared_parameters, model_cls):
+def merge_parameter_values(provided_values, declared_parameters, model_cls=None):
     """
     Merges parameter values according to those declared by a type.
 
@@ -109,6 +107,7 @@ def merge_parameter_values(provided_values, declared_parameters, model_cls):
     provided_values = provided_values or {}
     provided_values_of_wrong_type = OrderedDict()
     model_parameters = OrderedDict()
+    model_cls = model_cls or _get_class_from_sql_relationship(declared_parameters)
 
     for declared_parameter_name, declared_parameter in declared_parameters.iteritems():
         if declared_parameter_name in provided_values:
@@ -125,14 +124,14 @@ def merge_parameter_values(provided_values, declared_parameters, model_cls):
                 # TODO This error shouldn't be raised (or caught), but right now we lack support
                 # for custom data_types, which will raise this error. Skipping their validation.
                 pass
-            model_parameters[declared_parameter_name] = model_cls( # pylint: disable=unexpected-keyword-arg
+            model_parameters[declared_parameter_name] = model_cls(                                  # pylint: disable=unexpected-keyword-arg
                 name=declared_parameter_name,
                 type_name=type_name,
                 description=declared_parameter.description,
                 value=value)
         else:
             # Copy default value from declaration
-            model_parameters[declared_parameter_name] = declared_parameter.instantiate(None)
+            model_parameters[declared_parameter_name] = model_cls(**declared_parameter.as_raw)
 
     if provided_values_of_wrong_type:
         error_message = StringIO()
@@ -144,76 +143,6 @@ def merge_parameter_values(provided_values, declared_parameters, model_cls):
     return model_parameters
 
 
-def coerce_dict_values(the_dict, report_issues=False):
-    if not the_dict:
-        return
-    coerce_list_values(the_dict.itervalues(), report_issues)
-
-
-def coerce_list_values(the_list, report_issues=False):
-    if not the_list:
-        return
-    for value in the_list:
-        value.coerce_values(report_issues)
-
-
-def validate_dict_values(the_dict):
-    if not the_dict:
-        return
-    validate_list_values(the_dict.itervalues())
-
-
-def validate_list_values(the_list):
-    if not the_list:
-        return
-    for value in the_list:
-        value.validate()
-
-
-def instantiate_dict(container, the_dict, from_dict):
-    if not from_dict:
-        return
-    for name, value in from_dict.iteritems():
-        value = value.instantiate(container)
-        if value is not None:
-            the_dict[name] = value
-
-
-def instantiate_list(container, the_list, from_list):
-    if not from_list:
-        return
-    for value in from_list:
-        value = value.instantiate(container)
-        if value is not None:
-            the_list.append(value)
-
-
-def dump_list_values(the_list, name):
-    if not the_list:
-        return
-    puts('%s:' % name)
-    context = ConsumptionContext.get_thread_local()
-    with context.style.indent:
-        for value in the_list:
-            value.dump()
-
-
-def dump_dict_values(the_dict, name):
-    if not the_dict:
-        return
-    dump_list_values(the_dict.itervalues(), name)
-
-
-def dump_interfaces(interfaces, name='Interfaces'):
-    if not interfaces:
-        return
-    puts('%s:' % name)
-    context = ConsumptionContext.get_thread_local()
-    with context.style.indent:
-        for interface in interfaces.itervalues():
-            interface.dump()
-
-
 def parameters_as_values(the_dict):
     return dict((k, v.value) for k, v in the_dict.iteritems())
 
@@ -244,3 +173,9 @@ def fix_doc(cls):
     cls.__doc__ = cls.__bases__[-1].__doc__
 
     return cls
+
+
+def _get_class_from_sql_relationship(field):
+    class_ = field._sa_adapter.owner_state.class_
+    prop_name = field._sa_adapter.attr.key
+    return getattr(class_, prop_name).property.mapper.class_

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/orchestrator/execution_plugin/instantiation.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/execution_plugin/instantiation.py b/aria/orchestrator/execution_plugin/instantiation.py
index f55aa50..8b52015 100644
--- a/aria/orchestrator/execution_plugin/instantiation.py
+++ b/aria/orchestrator/execution_plugin/instantiation.py
@@ -18,16 +18,11 @@ Instantiation of :class:`~aria.modeling.models.Operation` models.
 """
 
 # TODO: this module will eventually be moved to a new "aria.instantiation" package
-
-from ...utils.type import full_type_name
-from ...utils.formatting import safe_repr
-from ...utils.collections import OrderedDict
-from ...parser import validation
-from ...parser.consumption import ConsumptionContext
 from ...modeling.functions import Function
+from ... import utils
 
 
-def configure_operation(operation):
+def configure_operation(operation, reporter):
     host = None
     interface = operation.interface
     if interface.node is not None:
@@ -38,11 +33,11 @@ def configure_operation(operation):
         else: # either False or None (None meaning that edge was not specified)
             host = interface.relationship.source_node.host
 
-    _configure_common(operation)
+    _configure_common(operation, reporter)
     if host is None:
         _configure_local(operation)
     else:
-        _configure_remote(operation)
+        _configure_remote(operation, reporter)
 
     # Any remaining un-handled configuration parameters will become extra arguments, available as
     # kwargs in either "run_script_locally" or "run_script_with_ssh"
@@ -51,7 +46,7 @@ def configure_operation(operation):
             operation.arguments[key] = value.instantiate(None)
 
 
-def _configure_common(operation):
+def _configure_common(operation, reporter):
     """
     Local and remote operations.
     """
@@ -59,7 +54,7 @@ def _configure_common(operation):
     from ...modeling.models import Argument
     operation.arguments['script_path'] = Argument.wrap('script_path', operation.implementation,
                                                        'Relative path to the executable file.')
-    operation.arguments['process'] = Argument.wrap('process', _get_process(operation),
+    operation.arguments['process'] = Argument.wrap('process', _get_process(operation, reporter),
                                                    'Sub-process configuration.')
 
 
@@ -73,7 +68,7 @@ def _configure_local(operation):
                                           operations.run_script_locally.__name__)
 
 
-def _configure_remote(operation):
+def _configure_remote(operation, reporter):
     """
     Remote SSH operation via Fabric.
     """
@@ -81,7 +76,7 @@ def _configure_remote(operation):
     from ...modeling.models import Argument
     from . import operations
 
-    ssh = _get_ssh(operation)
+    ssh = _get_ssh(operation, reporter)
 
     # Defaults
     # TODO: find a way to configure these generally in the service template
@@ -110,20 +105,17 @@ def _configure_remote(operation):
 
     # Make sure we have a user
     if fabric_env.get('user') is None:
-        context = ConsumptionContext.get_thread_local()
-        context.validation.report('must configure "ssh.user" for "{0}"'
-                                  .format(operation.implementation),
-                                  level=validation.Issue.BETWEEN_TYPES)
+        reporter.report('must configure "ssh.user" for "{0}"'.format(operation.implementation),
+                        level=reporter.Issue.BETWEEN_TYPES)
 
     # Make sure we have an authentication value
     if (fabric_env.get('password') is None) and \
         (fabric_env.get('key') is None) and \
         (fabric_env.get('key_filename') is None):
-        context = ConsumptionContext.get_thread_local()
-        context.validation.report('must configure "ssh.password", "ssh.key", or "ssh.key_filename" '
-                                  'for "{0}"'
-                                  .format(operation.implementation),
-                                  level=validation.Issue.BETWEEN_TYPES)
+        reporter.report(
+            'must configure "ssh.password", "ssh.key", or "ssh.key_filename" for "{0}"'
+            .format(operation.implementation),
+            level=reporter.Issue.BETWEEN_TYPES)
 
     operation.arguments['fabric_env'] = Argument.wrap('fabric_env', fabric_env,
                                                       'Fabric configuration.')
@@ -132,97 +124,94 @@ def _configure_remote(operation):
                                           operations.run_script_with_ssh.__name__)
 
 
-def _get_process(operation):
+def _get_process(operation, reporter):
     value = (operation.configurations.get('process')._value
              if 'process' in operation.configurations
              else None)
     if value is None:
         return {}
-    _validate_type(value, dict, 'process')
-    value = OrderedDict(value)
+    _validate_type(value, dict, 'process', reporter)
+    value = utils.collections.OrderedDict(value)
     for k, v in value.iteritems():
         if k == 'eval_python':
-            value[k] = _coerce_bool(v, 'process.eval_python')
+            value[k] = _coerce_bool(v, 'process.eval_python', reporter)
         elif k == 'cwd':
-            _validate_type(v, basestring, 'process.cwd')
+            _validate_type(v, basestring, 'process.cwd', reporter)
         elif k == 'command_prefix':
-            _validate_type(v, basestring, 'process.command_prefix')
+            _validate_type(v, basestring, 'process.command_prefix', reporter)
         elif k == 'args':
-            value[k] = _dict_to_list_of_strings(v, 'process.args')
+            value[k] = _dict_to_list_of_strings(v, 'process.args', reporter)
         elif k == 'env':
-            _validate_type(v, dict, 'process.env')
+            _validate_type(v, dict, 'process.env', reporter)
         else:
-            context = ConsumptionContext.get_thread_local()
-            context.validation.report('unsupported configuration parameter: "process.{0}"'
-                                      .format(k),
-                                      level=validation.Issue.BETWEEN_TYPES)
+            reporter.report('unsupported configuration parameter: "process.{0}"'.format(k),
+                            level=reporter.Issue.BETWEEN_TYPES)
     return value
 
 
-def _get_ssh(operation):
+def _get_ssh(operation, reporter):
     value = (operation.configurations.get('ssh')._value
              if 'ssh' in operation.configurations
              else None)
     if value is None:
         return {}
-    _validate_type(value, dict, 'ssh')
-    value = OrderedDict(value)
+    _validate_type(value, dict, 'ssh', reporter)
+    value = utils.collections.OrderedDict(value)
     for k, v in value.iteritems():
         if k == 'use_sudo':
-            value[k] = _coerce_bool(v, 'ssh.use_sudo')
+            value[k] = _coerce_bool(v, 'ssh.use_sudo', reporter)
         elif k == 'hide_output':
-            value[k] = _dict_to_list_of_strings(v, 'ssh.hide_output')
+            value[k] = _dict_to_list_of_strings(v, 'ssh.hide_output', reporter)
         elif k == 'warn_only':
-            value[k] = _coerce_bool(v, 'ssh.warn_only')
+            value[k] = _coerce_bool(v, 'ssh.warn_only', reporter)
         elif k == 'user':
-            _validate_type(v, basestring, 'ssh.user')
+            _validate_type(v, basestring, 'ssh.user', reporter)
         elif k == 'password':
-            _validate_type(v, basestring, 'ssh.password')
+            _validate_type(v, basestring, 'ssh.password', reporter)
         elif k == 'key':
-            _validate_type(v, basestring, 'ssh.key')
+            _validate_type(v, basestring, 'ssh.key', reporter)
         elif k == 'key_filename':
-            _validate_type(v, basestring, 'ssh.key_filename')
+            _validate_type(v, basestring, 'ssh.key_filename', reporter)
         elif k == 'address':
-            _validate_type(v, basestring, 'ssh.address')
+            _validate_type(v, basestring, 'ssh.address', reporter)
         else:
-            context = ConsumptionContext.get_thread_local()
-            context.validation.report('unsupported configuration parameter: "ssh.{0}"'.format(k),
-                                      level=validation.Issue.BETWEEN_TYPES)
+            reporter.report('unsupported configuration parameter: "ssh.{0}"'.format(k),
+                            level=reporter.Issue.BETWEEN_TYPES)
     return value
 
 
-def _validate_type(value, the_type, name):
+def _validate_type(value, the_type, name, reporter):
     if isinstance(value, Function):
         return
     if not isinstance(value, the_type):
-        context = ConsumptionContext.get_thread_local()
-        context.validation.report('"{0}" configuration is not a {1}: {2}'
-                                  .format(name, full_type_name(the_type), safe_repr(value)),
-                                  level=validation.Issue.BETWEEN_TYPES)
+        reporter.report(
+            '"{0}" configuration is not a {1}: {2}'.format(
+                name, utils.type.full_type_name(the_type), utils.formatting.safe_repr(value)),
+            level=reporter.Issue.BETWEEN_TYPES)
 
 
-def _coerce_bool(value, name):
+def _coerce_bool(value, name, reporter):
     if value is None:
         return None
     if isinstance(value, bool):
         return value
-    _validate_type(value, basestring, name)
+    _validate_type(value, basestring, name, reporter)
     if value == 'true':
         return True
     elif value == 'false':
         return False
     else:
-        context = ConsumptionContext.get_thread_local()
-        context.validation.report('"{0}" configuration is not "true" or "false": {1}'
-                                  .format(name, safe_repr(value)),
-                                  level=validation.Issue.BETWEEN_TYPES)
+        reporter.report(
+            '"{0}" configuration is not "true" or "false": {1}'.format(
+                name, utils.formatting.safe_repr(value)),
+            level=reporter.Issue.BETWEEN_TYPES)
 
 
-def _dict_to_list_of_strings(the_dict, name):
-    _validate_type(the_dict, dict, name)
+def _dict_to_list_of_strings(the_dict, name, reporter):
+    _validate_type(the_dict, dict, name, reporter)
     value = []
     for k in sorted(the_dict):
         v = the_dict[k]
-        _validate_type(v, basestring, '{0}.{1}'.format(name, k))
+        _validate_type(v, basestring, '{0}.{1}'.format(name, k), reporter)
         value.append(v)
     return value

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/orchestrator/topology/__init__.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/topology/__init__.py b/aria/orchestrator/topology/__init__.py
new file mode 100644
index 0000000..099a950
--- /dev/null
+++ b/aria/orchestrator/topology/__init__.py
@@ -0,0 +1,16 @@
+# 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 .topology import Topology

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/orchestrator/topology/common.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/topology/common.py b/aria/orchestrator/topology/common.py
new file mode 100644
index 0000000..5124557
--- /dev/null
+++ b/aria/orchestrator/topology/common.py
@@ -0,0 +1,69 @@
+# 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.
+
+
+class HandlerBase(object):
+    def __init__(self, topology, model):
+        self._topology = topology
+        self._model = model
+
+    def coerce(self, **kwargs):
+        raise NotImplementedError
+
+    def _coerce(self, *models, **kwargs):
+        for template in models:
+            self._topology.coerce(template, **kwargs)
+
+    def validate(self, **kwargs):
+        raise NotImplementedError
+
+    def _validate(self, *models, **kwargs):
+        for template in models:
+            self._topology.validate(template, **kwargs)
+
+    def dump(self, out_stream):
+        raise NotImplementedError
+
+
+class TemplateHandlerBase(HandlerBase):
+    """
+    Base handler for template based models
+    """
+
+    def instantiate(self, instance_cls, **kwargs):
+        raise NotImplementedError
+
+
+class InstanceHandlerBase(HandlerBase):
+    """
+    Base handler for instance based models
+
+    """
+    def validate(self, **kwargs):
+        raise NotImplementedError
+
+    def coerce(self, **kwargs):
+        raise NotImplementedError
+
+    def dump(self, out_stream):
+        raise NotImplementedError
+
+
+class ActorHandlerBase(HandlerBase):
+    """
+    Base handler for any model which has (or contains a field which references) an operation
+    """
+    def configure_operations(self):
+        raise NotImplementedError

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/orchestrator/topology/instance_handler.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/topology/instance_handler.py b/aria/orchestrator/topology/instance_handler.py
new file mode 100644
index 0000000..51f26c6
--- /dev/null
+++ b/aria/orchestrator/topology/instance_handler.py
@@ -0,0 +1,671 @@
+# 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 ... parser.modeling import context
+from ... modeling import models, functions
+from ... utils import formatting
+from .. import execution_plugin
+from .. import decorators
+from . import common
+
+
+class Artifact(common.InstanceHandlerBase):
+
+    def coerce(self, **kwargs):
+        self._topology.coerce(self._model.properties, **kwargs)
+
+    def validate(self, **kwargs):
+        self._topology.validate(self._model.properties, **kwargs)
+
+    def dump(self, out_stream):
+        with out_stream.indent():
+            out_stream.write(out_stream.node_style(self._model.name))
+            out_stream.write(out_stream.meta_style(self._model.description))
+            with out_stream.indent():
+                out_stream.write('Artifact type: {0}'.format(out_stream.type_style(
+                    self._model.type.name)))
+                out_stream.write('Source path: {0}'.format(
+                    out_stream.literal_style(self._model.source_path)))
+                if self._model.target_path is not None:
+                    out_stream.write('Target path: {0}'.format(
+                        out_stream.literal_style(self._model.target_path)))
+                if self._model.repository_url is not None:
+                    out_stream.write('Repository URL: {0}'.format(
+                        out_stream.literal_style(self._model.repository_url)))
+                if self._model.repository_credential:
+                    out_stream.write('Repository credential: {0}'.format(
+                        out_stream.literal_style(self._model.repository_credential)))
+                self._topology.dump(self._model.properties, out_stream, title='Properties')
+
+
+class Capability(common.InstanceHandlerBase):
+    def coerce(self, **kwargs):
+        self._topology.coerce(self._model.properties, **kwargs)
+
+    def validate(self, **kwargs):
+        self._topology.validate(self._model.properties, **kwargs)
+
+    def dump(self, out_stream):
+        out_stream.write(out_stream.node_style(self._model.name))
+        with out_stream.indent():
+            out_stream.write('Type: {0}'.format(out_stream.type_style(self._model.type.name)))
+            out_stream.write('Occurrences: {0:d} ({1:d}{2})'.format(
+                self._model.occurrences,
+                self._model.min_occurrences or 0,
+                ' to {0:d}'.format(self._model.max_occurrences)
+                if self._model.max_occurrences is not None
+                else ' or more'))
+            self._topology.dump(self._model.properties, out_stream, title='Properties')
+
+
+class Group(common.ActorHandlerBase):
+
+    def coerce(self, **kwargs):
+        self._coerce(self._model.properties, self._model.interfaces, **kwargs)
+
+    def validate(self, **kwargs):
+        self._validate(self._model.properties,
+                       self._model.interfaces,
+                       **kwargs)
+
+    def dump(self, out_stream):
+        out_stream.write('Group: {0}'.format(out_stream.node_style(self._model.name)))
+        with out_stream.indent():
+            out_stream.write('Type: {0}'.format(out_stream.type_style(self._model.type.name)))
+            self._topology.dump(self._model.properties, out_stream, title='Properties')
+            self._topology.dump(self._model.interfaces, out_stream, title='Interfaces')
+            if self._model.nodes:
+                out_stream.write('Member nodes:')
+                with out_stream.indent():
+                    for node in self._model.nodes:
+                        out_stream.write(out_stream.node_style(node.name))
+
+    def configure_operations(self):
+        for interface in self._model.interfaces.values():
+            self._topology.configure_operations(interface)
+
+
+class Interface(common.ActorHandlerBase):
+    def coerce(self, **kwargs):
+        self._coerce(self._model.inputs, self._model.operations, **kwargs)
+
+    def validate(self, **kwargs):
+        self._validate(self._model.inputs,
+                       self._model.operations,
+                       **kwargs)
+
+    def dump(self, out_stream):
+        out_stream.write(out_stream.node_style(self._model.name))
+        if self._model.description:
+            out_stream.write(out_stream.meta_style(self._model.description))
+        with out_stream.indent():
+            out_stream.write('Interface type: {0}'.format(
+                out_stream.type_style(self._model.type.name)))
+            self._topology.dump(self._model.inputs, out_stream, title='Inputs')
+            self._topology.dump(self._model.operations, out_stream, title='Operations')
+
+    def configure_operations(self):
+        for operation in self._model.operations.values():
+            self._topology.configure_operations(operation)
+
+
+class Node(common.ActorHandlerBase):
+    def coerce(self, **kwargs):
+        self._coerce(self._model.properties,
+                     self._model.attributes,
+                     self._model.interfaces,
+                     self._model.artifacts,
+                     self._model.capabilities,
+                     self._model.outbound_relationships,
+                     **kwargs)
+
+    def validate(self, **kwargs):
+        if len(self._model.name) > context.ID_MAX_LENGTH:
+            self._topology.report(
+                '"{0}" has an ID longer than the limit of {1:d} characters: {2:d}'.format(
+                    self._model.name, context.ID_MAX_LENGTH, len(self._model.name)),
+                level=self._topology.Issue.BETWEEN_INSTANCES)
+
+        self._validate(self._model.properties,
+                       self._model.attributes,
+                       self._model.interfaces,
+                       self._model.artifacts,
+                       self._model.capabilities,
+                       self._model.outbound_relationships)
+
+    def dump(self, out_stream):
+        out_stream.write('Node: {0}'.format(out_stream.node_style(self._model.name)))
+        with out_stream.indent():
+            out_stream.write('Type: {0}'.format(out_stream.type_style(self._model.type.name)))
+            out_stream.write('Template: {0}'.format(
+                out_stream.node_style(self._model.node_template.name)))
+            self._topology.dump(self._model.properties, out_stream, title='Properties')
+            self._topology.dump(self._model.attributes, out_stream, title='Attributes')
+            self._topology.dump(self._model.interfaces, out_stream, title='Interfaces')
+            self._topology.dump(self._model.artifacts, out_stream, title='Artifacts')
+            self._topology.dump(self._model.capabilities, out_stream, title='Capabilities')
+            self._topology.dump(self._model.outbound_relationships, out_stream,
+                                title='Relationships')
+
+    def configure_operations(self):
+        for interface in self._model.interfaces.values():
+            self._topology.configure_operations(interface)
+        for relationship in self._model.outbound_relationships:
+            self._topology.configure_operations(relationship)
+
+    def validate_capabilities(self):
+        satisfied = False
+        for capability in self._model.capabilities.itervalues():
+            if not capability.has_enough_relationships:
+                self._topology.report(
+                    'capability "{0}" of node "{1}" requires at least {2:d} '
+                    'relationships but has {3:d}'.format(capability.name,
+                                                         self._model.name,
+                                                         capability.min_occurrences,
+                                                         capability.occurrences),
+                    level=self._topology.Issue.BETWEEN_INSTANCES)
+                satisfied = False
+        return satisfied
+
+    def satisfy_requirements(self):
+        satisfied = True
+        for requirement_template in self._model.node_template.requirement_templates:
+
+            # Since we try and satisfy requirements, which are node template bound, and use that
+            # information in the creation of the relationship, Some requirements may have been
+            # satisfied by a previous run on that node template.
+            # The entire mechanism of satisfying requirements needs to be refactored.
+            if any(rel.requirement_template == requirement_template
+                   for rel in self._model.outbound_relationships):
+                continue
+
+            # Find target template
+            target_node_template, target_node_capability = self._find_target(requirement_template)
+            if target_node_template is not None:
+                satisfied = self._satisfy_capability(
+                    target_node_capability, target_node_template, requirement_template)
+            else:
+                self._topology.report('requirement "{0}" of node "{1}" has no target node template'.
+                                      format(requirement_template.name, self._model.name),
+                                      level=self._topology.Issue.BETWEEN_INSTANCES)
+                satisfied = False
+        return satisfied
+
+    def _satisfy_capability(self, target_node_capability, target_node_template,
+                            requirement_template):
+        # Find target nodes
+        target_nodes = target_node_template.nodes
+        if target_nodes:
+            target_node = None
+            target_capability = None
+
+            if target_node_capability is not None:
+                # Relate to the first target node that has capacity
+                for node in target_nodes:
+                    a_target_capability = node.capabilities.get(target_node_capability.name)
+                    if a_target_capability.relate():
+                        target_node = node
+                        target_capability = a_target_capability
+                        break
+            else:
+                # Use first target node
+                target_node = target_nodes[0]
+
+            if target_node is not None:
+                if requirement_template.relationship_template is not None:
+                    relationship_model = self._topology.instantiate(
+                        requirement_template.relationship_template)
+                else:
+                    relationship_model = models.Relationship()
+                relationship_model.name = requirement_template.name
+                relationship_model.requirement_template = requirement_template
+                relationship_model.target_node = target_node
+                relationship_model.target_capability = target_capability
+                self._model.outbound_relationships.append(relationship_model)
+                return True
+            else:
+                self._topology.report(
+                    'requirement "{0}" of node "{1}" targets node '
+                    'template "{2}" but its instantiated nodes do not '
+                    'have enough capacity'.format(
+                        requirement_template.name, self._model.name, target_node_template.name),
+                    level=self._topology.Issue.BETWEEN_INSTANCES)
+                return False
+        else:
+            self._topology.report(
+                'requirement "{0}" of node "{1}" targets node template '
+                '"{2}" but it has no instantiated nodes'.format(
+                    requirement_template.name, self._model.name, target_node_template.name),
+                level=self._topology.Issue.BETWEEN_INSTANCES)
+            return False
+
+    def _find_target(self, requirement_template):
+        # We might already have a specific node template from the requirement template, so
+        # we'll just verify it
+        if requirement_template.target_node_template is not None:
+            if not self._model.node_template.is_target_node_template_valid(
+                    requirement_template.target_node_template):
+                self._topology.report(
+                    'requirement "{0}" of node template "{1}" is for node '
+                    'template "{2}" but it does not match constraints'.format(
+                        requirement_template.name,
+                        requirement_template.target_node_template.name,
+                        self._model.node_template.name),
+                    level=self._topology.Issue.BETWEEN_TYPES)
+            if (requirement_template.target_capability_type is not None or
+                    requirement_template.target_capability_name is not None):
+                target_node_capability = self._get_capability(requirement_template)
+                if target_node_capability is None:
+                    return None, None
+            else:
+                target_node_capability = None
+
+            return requirement_template.target_node_template, target_node_capability
+
+        # Find first node that matches the type
+        elif requirement_template.target_node_type is not None:
+            for target_node_template in \
+                    self._model.node_template.service_template.node_templates.itervalues():
+                if requirement_template.target_node_type.get_descendant(
+                        target_node_template.type.name) is None:
+                    continue
+
+                if not self._model.node_template.is_target_node_template_valid(
+                        target_node_template):
+                    continue
+
+                target_node_capability = self._get_capability(requirement_template,
+                                                              target_node_template)
+
+                if target_node_capability is None:
+                    continue
+
+                return target_node_template, target_node_capability
+
+        # Find the first node which has a capability of the required type
+        elif requirement_template.target_capability_type is not None:
+            for target_node_template in \
+                    self._model.node_template.service_template.node_templates.itervalues():
+                target_node_capability = \
+                    self._get_capability(requirement_template, target_node_template)
+                if target_node_capability:
+                    return target_node_template, target_node_capability
+
+        return None, None
+
+    def _get_capability(self, requirement_template, target_node_template=None):
+        target_node_template = target_node_template or requirement_template.target_node_template
+
+        for capability_template in target_node_template.capability_templates.values():
+            if self._satisfies_requirement(
+                    capability_template, requirement_template, target_node_template):
+                return capability_template
+
+        return None
+
+    def _satisfies_requirement(
+            self, capability_template, requirement_template, target_node_template):
+        # Do we match the required capability type?
+        if (requirement_template.target_capability_type and
+                requirement_template.target_capability_type.get_descendant(
+                    capability_template.type.name) is None):
+            return False
+
+        # Are we in valid_source_node_types?
+        if capability_template.valid_source_node_types:
+            for valid_source_node_type in capability_template.valid_source_node_types:
+                if valid_source_node_type.get_descendant(
+                        self._model.node_template.type.name) is None:
+                    return False
+
+        # Apply requirement constraints
+        if requirement_template.target_node_template_constraints:
+            for node_template_constraint in requirement_template.target_node_template_constraints:
+                if not node_template_constraint.matches(
+                        self._model.node_template, target_node_template):
+                    return False
+
+        return True
+
+
+class Operation(common.ActorHandlerBase):
+    def coerce(self, **kwargs):
+        self._coerce(self._model.inputs,
+                     self._model.configurations,
+                     self._model.arguments,
+                     **kwargs)
+
+    def validate(self, **kwargs):
+        self._validate(self._model.inputs,
+                       self._model.configurations,
+                       self._model.arguments,
+                       **kwargs)
+
+    def dump(self, out_stream):
+        out_stream.write(out_stream.node_style(self._model.name))
+        if self._model.description:
+            out_stream.write(out_stream.meta_style(self._model.description))
+        with out_stream.indent():
+            if self._model.implementation is not None:
+                out_stream.write('Implementation: {0}'.format(
+                    out_stream.literal_style(self._model.implementation)))
+            if self._model.dependencies:
+                out_stream.write(
+                    'Dependencies: {0}'.format(', '.join((str(out_stream.literal_style(v))
+                                                          for v in self._model.dependencies))))
+            self._topology.dump(self._model.inputs, out_stream, title='Inputs')
+            if self._model.executor is not None:
+                out_stream.write('Executor: {0}'.format(out_stream.literal_style(
+                    self._model.executor)))
+            if self._model.max_attempts is not None:
+                out_stream.write('Max attempts: {0}'.format(out_stream.literal_style(
+                    self._model.max_attempts)))
+            if self._model.retry_interval is not None:
+                out_stream.write('Retry interval: {0}'.format(
+                    out_stream.literal_style(self._model.retry_interval)))
+            if self._model.plugin is not None:
+                out_stream.write('Plugin: {0}'.format(
+                    out_stream.literal_style(self._model.plugin.name)))
+            self._topology.dump(self._model.configurations, out_stream, title='Configuration')
+            if self._model.function is not None:
+                out_stream.write('Function: {0}'.format(out_stream.literal_style(
+                    self._model.function)))
+            self._topology.dump(self._model.arguments, out_stream, title='Arguments')
+
+    def configure_operations(self):
+        if self._model.implementation is None and self._model.function is None:
+            return
+
+        if (self._model.interface is not None and
+                self._model.plugin is None and
+                self._model.function is None):
+            # ("interface" is None for workflow operations, which do not currently use "plugin")
+            # The default (None) plugin is the execution plugin
+            execution_plugin.instantiation.configure_operation(self._model, self._topology)
+        else:
+            # In the future plugins may be able to add their own "configure_operation" hook that
+            # can validate the configuration and otherwise create specially derived arguments. For
+            # now, we just send all configuration parameters as arguments without validation.
+            for key, conf in self._model.configurations.items():
+                self._model.arguments[key] = self._topology.instantiate(conf.as_argument())
+
+        if self._model.interface is not None:
+            # Send all interface inputs as extra arguments
+            # ("interface" is None for workflow operations)
+            # Note that they will override existing arguments of the same names
+            for key, input in self._model.interface.inputs.items():
+                self._model.arguments[key] = self._topology.instantiate(input.as_argument())
+
+        # Send all inputs as extra arguments
+        # Note that they will override existing arguments of the same names
+        for key, input in self._model.inputs.items():
+            self._model.arguments[key] = self._topology.instantiate(input.as_argument())
+
+        # Check for reserved arguments
+        used_reserved_names = set(decorators.OPERATION_DECORATOR_RESERVED_ARGUMENTS).intersection(
+            self._model.arguments.keys())
+        if used_reserved_names:
+            self._topology.report(
+                'using reserved arguments in operation "{0}": {1}'.format(
+                    self._model.name, formatting.string_list_as_string(used_reserved_names)),
+                level=self._topology.Issue.EXTERNAL)
+
+
+class Policy(common.InstanceHandlerBase):
+    def coerce(self, **kwargs):
+        self._topology.coerce(self._model.properties, **kwargs)
+
+    def validate(self, **kwargs):
+        self._topology.validate(self._model.properties, **kwargs)
+
+    def dump(self, out_stream):
+        out_stream.write('Policy: {0}'.format(out_stream.node_style(self._model.name)))
+        with out_stream.indent():
+            out_stream.write('Type: {0}'.format(out_stream.type_style(self._model.type.name)))
+            self._topology.dump(self._model.properties, out_stream, title='Properties')
+            if self._model.nodes:
+                out_stream.write('Target nodes:')
+                with out_stream.indent():
+                    for node in self._model.nodes:
+                        out_stream.write(out_stream.node_style(node.name))
+            if self._model.groups:
+                out_stream.write('Target groups:')
+                with out_stream.indent():
+                    for group in self._model.groups:
+                        out_stream.write(out_stream.node_style(group.name))
+
+
+class Relationship(common.ActorHandlerBase):
+    def coerce(self, **kwargs):
+        self._coerce(self._model.properties,
+                     self._model.interfaces,
+                     **kwargs)
+
+    def validate(self, **kwargs):
+        self._validate(self._model.properties,
+                       self._model.interfaces,
+                       **kwargs)
+
+    def dump(self, out_stream):
+        if self._model.name:
+            out_stream.write('{0} ->'.format(out_stream.node_style(self._model.name)))
+        else:
+            out_stream.write('->')
+        with out_stream.indent():
+            out_stream.write('Node: {0}'.format(out_stream.node_style(
+                self._model.target_node.name)))
+            if self._model.target_capability:
+                out_stream.write('Capability: {0}'.format(out_stream.node_style(
+                    self._model.target_capability.name)))
+            if self._model.type is not None:
+                out_stream.write('Relationship type: {0}'.format(
+                    out_stream.type_style(self._model.type.name)))
+            if (self._model.relationship_template is not None and
+                    self._model.relationship_template.name):
+                out_stream.write('Relationship template: {0}'.format(
+                    out_stream.node_style(self._model.relationship_template.name)))
+            self._topology.dump(self._model.properties, out_stream, title='Properties')
+            self._topology.dump(self._model.interfaces, out_stream, title='Interfaces')
+
+    def configure_operations(self):
+        for interface in self._model.interfaces.values():
+            self._topology.configure_operations(interface)
+
+
+class Service(common.ActorHandlerBase):
+    def coerce(self, **kwargs):
+        self._coerce(self._model.meta_data,
+                     self._model.nodes,
+                     self._model.groups,
+                     self._model.policies,
+                     self._model.substitution,
+                     self._model.inputs,
+                     self._model.outputs,
+                     self._model.workflows,
+                     **kwargs)
+
+    def validate(self, **kwargs):
+        self._validate(self._model.meta_data,
+                       self._model.nodes,
+                       self._model.groups,
+                       self._model.policies,
+                       self._model.substitution,
+                       self._model.inputs,
+                       self._model.outputs,
+                       self._model.workflows,
+                       **kwargs)
+
+    def dump(self, out_stream):
+        if self._model.description is not None:
+            out_stream.write(out_stream.meta_style(self._model.description))
+        self._topology.dump(self._model.meta_data, out_stream, title='Metadata')
+        self._topology.dump(self._model.nodes, out_stream)
+        self._topology.dump(self._model.groups, out_stream)
+        self._topology.dump(self._model.policies, out_stream)
+        self._topology.dump(self._model.substitution, out_stream)
+        self._topology.dump(self._model.inputs, out_stream, title='Inputs')
+        self._topology.dump(self._model.outputs, out_stream, title='Outputs')
+        self._topology.dump(self._model.workflows, out_stream, title='Workflows')
+
+    def configure_operations(self):
+        for node in self._model.nodes.itervalues():
+            self._topology.configure_operations(node)
+        for group in self._model.groups.itervalues():
+            self._topology.configure_operations(group)
+        for operation in self._model.workflows.itervalues():
+            self._topology.configure_operations(operation)
+
+    def validate_capabilities(self):
+        satisfied = True
+        for node in self._model.nodes.values():
+            if not self._topology.validate_capabilities(node):
+                satisfied = False
+        return satisfied
+
+    def satisfy_requirements(self):
+        return all(self._topology.satisfy_requirements(node)
+                   for node in self._model.nodes.values())
+
+
+class Substitution(common.InstanceHandlerBase):
+    def coerce(self, **kwargs):
+        self._topology.coerce(self._model.mappings, **kwargs)
+
+    def validate(self, **kwargs):
+        self._topology.validate(self._model.mappings, **kwargs)
+
+    def dump(self, out_stream):
+        out_stream.write('Substitution:')
+        with out_stream.indent():
+            out_stream.write('Node type: {0}'.format(out_stream.type_style(
+                self._model.node_type.name)))
+            self._topology.dump(self._model.mappings, out_stream, title='Mappings')
+
+
+class SubstitutionMapping(common.InstanceHandlerBase):
+
+    def coerce(self, **kwargs):
+        pass
+
+    def validate(self, **_):
+        if (self._model.capability is None) and (self._model.requirement_template is None):
+            self._topology.report(
+                'mapping "{0}" refers to neither capability nor a requirement'
+                ' in node: {1}'.format(
+                    self._model.name, formatting.safe_repr(self._model.node_style.name)),
+                level=self._topology.Issue.BETWEEN_TYPES)
+
+    def dump(self, out_stream):
+        if self._model.capability is not None:
+            out_stream.write('{0} -> {1}.{2}'.format(
+                out_stream.node_style(self._model.name),
+                out_stream.node_style(self._model.capability.node.name),
+                out_stream.node_style(self._model.capability.name)))
+        else:
+            out_stream.write('{0} -> {1}.{2}'.format(
+                out_stream.node_style(self._model.name),
+                out_stream.node_style(self._model.node.name),
+                out_stream.node_style(self._model.requirement_template.name)))
+
+
+class Metadata(common.InstanceHandlerBase):
+
+    def dump(self, out_stream):
+        out_stream.write('{0}: {1}'.format(
+            out_stream.property_style(self._model.name),
+            out_stream.literal_style(self._model.value)))
+
+    def coerce(self, **_):
+        pass
+
+    def instantiate(self, instance_cls):
+        return instance_cls(name=self._model.name, value=self._model.value)
+
+    def validate(self):
+        pass
+
+
+class _Parameter(common.InstanceHandlerBase):
+
+    def dump(self, out_stream):
+        if self._model.type_name is not None:
+            out_stream.write('{0}: {1} ({2})'.format(
+                out_stream.property_style(self._model.name),
+                out_stream.literal_style(formatting.as_raw(self._model.value)),
+                out_stream.type_style(self._model.type_name)))
+        else:
+            out_stream.write('{0}: {1}'.format(
+                out_stream.property_style(self._model.name),
+                out_stream.literal_style(formatting.as_raw(self._model.value))))
+        if self._model.description:
+            out_stream.write(out_stream.meta_style(self._model.description))
+
+    def instantiate(self, instance_cls, **kwargs):
+        return instance_cls(
+            name=self._model.name,                                                                  # pylint: disable=unexpected-keyword-arg
+            type_name=self._model.type_name,
+            _value=self._model._value,
+            description=self._model.description
+        )
+
+    def validate(self):
+        pass
+
+    def coerce(self, report_issues):                                                                # pylint: disable=arguments-differ
+        value = self._model._value
+        if value is not None:
+            evaluation = functions.evaluate(value, self._model, report_issues)
+            if (evaluation is not None) and evaluation.final:
+                # A final evaluation can safely replace the existing value
+                self._model._value = evaluation.value
+
+
+class Attribute(_Parameter):
+    pass
+
+
+class Input(_Parameter):
+    pass
+
+
+class Output(_Parameter):
+    pass
+
+
+class Argument(_Parameter):
+    pass
+
+
+class Property(_Parameter):
+    pass
+
+
+class Configuration(_Parameter):
+    pass
+
+
+class Type(common.InstanceHandlerBase):
+    def coerce(self, **_):
+        pass
+
+    def dump(self, out_stream):
+        if self._model.name:
+            out_stream.write(out_stream.type_style(self._model.name))
+        with out_stream.indent():
+            for child in self._model.children:
+                self._topology.dump(child, out_stream)
+
+    def validate(self, **kwargs):
+        pass

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/df2b916e/aria/orchestrator/topology/template_handler.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/topology/template_handler.py b/aria/orchestrator/topology/template_handler.py
new file mode 100644
index 0000000..bf0ef9f
--- /dev/null
+++ b/aria/orchestrator/topology/template_handler.py
@@ -0,0 +1,606 @@
+# 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 ...utils import (
+    formatting,
+    versions
+)
+from ...modeling import utils as modeling_utils
+from . import utils, common
+
+
+class ServiceTemplate(common.TemplateHandlerBase):
+    def dump(self, out_stream):
+        if self._model.description is not None:
+            out_stream.write(out_stream.meta_style(self._model.description))
+        self._topology.dump(self._model.meta_data, out_stream, title='Metadata')
+        self._topology.dump(self._model.node_templates, out_stream)
+        self._topology.dump(self._model.group_templates, out_stream)
+        self._topology.dump(self._model.policy_templates, out_stream)
+        self._topology.dump(self._model.substitution_template, out_stream)
+        self._topology.dump(self._model.inputs, out_stream, title='Inputs')
+        self._topology.dump(self._model.outputs, out_stream, title='Outputs')
+        self._topology.dump(self._model.workflow_templates, out_stream, title='Workflow templates')
+
+    def coerce(self, **kwargs):
+        self._coerce(self._model.meta_data,
+                     self._model.node_templates,
+                     self._model.group_templates,
+                     self._model.policy_templates,
+                     self._model.substitution_template,
+                     self._model.inputs,
+                     self._model.outputs,
+                     self._model.workflow_templates,
+                     **kwargs)
+
+    def instantiate(self, instance_cls, inputs=None, plugins=None):                                 # pylint: disable=arguments-differ
+        now = datetime.now()
+
+        modeling_utils.validate_no_undeclared_inputs(
+            declared_inputs=self._model.inputs, supplied_inputs=inputs or {})
+        modeling_utils.validate_required_inputs_are_supplied(
+            declared_inputs=self._model.inputs, supplied_inputs=inputs or {})
+
+        service = instance_cls(
+            created_at=now,
+            updated_at=now,
+            description=utils.deepcopy_with_locators(self._model.description),
+            service_template=self._model,
+            inputs=modeling_utils.merge_parameter_values(inputs, self._model.inputs)
+        )
+
+        for plugin_specification in self._model.plugin_specifications.itervalues():
+            if plugin_specification.enabled and plugins:
+                if self._resolve_plugin_specification(plugin_specification, plugins):
+                    plugin = plugin_specification.plugin
+                    service.plugins[plugin.name] = plugin
+                else:
+                    self._topology.report('specified plugin not found: {0}'.format(
+                        plugin_specification.name), level=self._topology.Issue.EXTERNAL)
+        service.meta_data = self._topology.instantiate(self._model.meta_data)
+
+        for node_template in self._model.node_templates.itervalues():
+            for _ in range(self._scaling(node_template)['default_instances']):
+                node = self._topology.instantiate(node_template)
+                service.nodes[node.name] = node
+
+        service.groups = self._topology.instantiate(self._model.group_templates)
+        service.policies = self._topology.instantiate(self._model.policy_templates)
+        service.workflows = self._topology.instantiate(self._model.workflow_templates)
+        service.substitution = self._topology.instantiate(self._model.substitution_template)
+        service.outputs = self._topology.instantiate(self._model.outputs)
+
+        return service
+
+    @staticmethod
+    def _resolve_plugin_specification(plugin_specification, plugins):
+        matching_plugins = []
+        if plugins:
+            for plugin in plugins:
+                if (plugin.name == plugin_specification.name and
+                        (plugin_specification.version is None or
+                         versions.VersionString(plugin.package_version) >=
+                         plugin_specification.version)
+                   ):
+                    matching_plugins.append(plugin)
+        plugin_specification.plugin = None
+        if matching_plugins:
+            # Return highest version of plugin
+            plugin_specification.plugin = \
+                max(matching_plugins,
+                    key=lambda plugin: versions.VersionString(plugin.package_version).key)
+        return plugin_specification.plugin is not None
+
+    def _scaling(self, node_template):
+        scaling = node_template.scaling
+
+        if any([scaling['min_instances'] < 0,
+                scaling['max_instances'] < scaling['min_instances'],
+                scaling['max_instances'] < 0,
+
+                scaling['default_instances'] < 0,
+                scaling['default_instances'] < scaling['min_instances'],
+                scaling['default_instances'] > scaling['max_instances']
+               ]):
+            self._topology.report(
+                'invalid scaling parameters for node template "{0}": min={min_instances}, max='
+                '{max_instances}, default={default_instances}'.format(self._model.name, **scaling),
+                level=self._topology.Issue.BETWEEN_TYPES)
+
+        return scaling
+
+    def validate(self, **kwargs):
+        self._validate(
+            self._model.meta_data,
+            self._model.node_templates,
+            self._model.group_templates,
+            self._model.policy_templates,
+            self._model.substitution_template,
+            self._model.inputs,
+            self._model.outputs,
+            self._model.workflow_templates,
+            self._model.node_types,
+            self._model.group_types,
+            self._model.policy_types,
+            self._model.relationship_types,
+            self._model.capability_types,
+            self._model.interface_types,
+            self._model.artifact_types,
+            **kwargs
+        )
+
+
+class ArtifactTemplate(common.TemplateHandlerBase):
+    def dump(self, out_stream):
+        out_stream.write(out_stream.node_style(self._model.name))
+        if self._model.description:
+            out_stream.write(out_stream.meta_style(self._model.description))
+        with out_stream.indent():
+            out_stream.write('Artifact type: {0}'.format(out_stream.type_style(
+                self._model.type.name)))
+            out_stream.write('Source path: {0}'.format(out_stream.literal_style(
+                self._model.source_path)))
+            if self._model.target_path is not None:
+                out_stream.write('Target path: {0}'.format(out_stream.literal_style(
+                    self._model.target_path)))
+            if self._model.repository_url is not None:
+                out_stream.write('Repository URL: {0}'.format(
+                    out_stream.literal_style(self._model.repository_url)))
+            if self._model.repository_credential:
+                out_stream.write('Repository credential: {0}'.format(
+                    out_stream.literal_style(self._model.repository_credential)))
+            self._topology.dump(self._model.properties, out_stream, title='Properties')
+
+    def coerce(self, **kwargs):
+        self._topology.coerce(self._model.properties, **kwargs)
+
+    def instantiate(self, instance_cls, **_):
+        return instance_cls(
+            name=self._model.name,
+            type=self._model.type,
+            description=utils.deepcopy_with_locators(self._model.description),
+            source_path=self._model.source_path,
+            target_path=self._model.target_path,
+            repository_url=self._model.repository_url,
+            repository_credential=self._model.repository_credential,
+            artifact_template=self._model)
+
+    def validate(self, **kwargs):
+        self._topology.validate(self._model.properties, **kwargs)
+
+
+class CapabilityTemplate(common.TemplateHandlerBase):
+    def dump(self, out_stream):
+        out_stream.write(out_stream.node_style(self._model.name))
+        if self._model.description:
+            out_stream.write(out_stream.meta_style(self._model.description))
+        with out_stream.indent():
+            out_stream.write('Type: {0}'.format(out_stream.type_style(self._model.type.name)))
+            out_stream.write(
+                'Occurrences: {0:d}{1}'.format(
+                    self._model.min_occurrences or 0,
+                    ' to {0:d}'.format(self._model.max_occurrences)
+                    if self._model.max_occurrences is not None
+                    else ' or more'))
+            if self._model.valid_source_node_types:
+                out_stream.write('Valid source node types: {0}'.format(
+                    ', '.join((str(out_stream.type_style(v.name))
+                               for v in self._model.valid_source_node_types))))
+            self._topology.dump(self._model.properties, out_stream, title='Properties')
+
+    def coerce(self, **kwargs):
+        self._topology.coerce(self._model.properties, **kwargs)
+
+    def instantiate(self, instance_cls, **_):
+        return instance_cls(name=self._model.name,
+                            type=self._model.type,
+                            min_occurrences=self._model.min_occurrences,
+                            max_occurrences=self._model.max_occurrences,
+                            occurrences=0,
+                            capability_template=self._model)
+
+    def validate(self, **kwargs):
+        self._topology.validate(self._model.properties, **kwargs)
+
+
+class RequirementTemplate(common.TemplateHandlerBase):
+    def dump(self, out_stream):
+        if self._model.name:
+            out_stream.write(out_stream.node_style(self._model.name))
+        else:
+            out_stream.write('Requirement:')
+        with out_stream.indent():
+            if self._model.target_node_type is not None:
+                out_stream.write('Target node type: {0}'.format(
+                    out_stream.type_style(self._model.target_node_type.name)))
+            elif self._model.target_node_template is not None:
+                out_stream.write('Target node template: {0}'.format(
+                    out_stream.node_style(self._model.target_node_template.name)))
+            if self._model.target_capability_type is not None:
+                out_stream.write('Target capability type: {0}'.format(
+                    out_stream.type_style(self._model.target_capability_type.name)))
+            elif self._model.target_capability_name is not None:
+                out_stream.write('Target capability name: {0}'.format(
+                    out_stream.node_style(self._model.target_capability_name)))
+            if self._model.target_node_template_constraints:
+                out_stream.write('Target node template constraints:')
+                with out_stream.indent():
+                    for constraint in self._model.target_node_template_constraints:
+                        out_stream.write(out_stream.literal_style(constraint))
+            if self._model.relationship_template:
+                out_stream.write('Relationship:')
+                with out_stream.indent():
+                    self._topology.dump(self._model.relationship_template, out_stream)
+
+    def coerce(self, **kwargs):
+        self._topology.coerce(self._model.relationship_template, **kwargs)
+
+    def instantiate(self, instance_cls, **_):
+        pass
+
+    def validate(self, **kwargs):
+        self._topology.validate(self._model.relationship_template, **kwargs)
+
+
+class GroupTemplate(common.TemplateHandlerBase):
+    def dump(self, out_stream):
+        out_stream.write('Group template: {0}'.format(out_stream.node_style(self._model.name)))
+        if self._model.description:
+            out_stream.write(out_stream.meta_style(self._model.description))
+        with out_stream.indent():
+            out_stream.write('Type: {0}'.format(out_stream.type_style(self._model.type.name)))
+            self._topology.dump(self._model.properties, out_stream, title='Properties')
+            self._topology.dump(self._model.interface_templates, out_stream,
+                                title='Interface Templates')
+            if self._model.node_templates:
+                out_stream.write('Member node templates: {0}'.format(', '.join(
+                    (str(out_stream.node_style(v.name)) for v in self._model.node_templates))))
+
+    def coerce(self, **kwargs):
+        self._coerce(self._model.properties,
+                     self._model.interface_templates,
+                     **kwargs)
+
+    def instantiate(self, instance_cls, **_):
+        group = instance_cls(
+            name=self._model.name,
+            type=self._model.type,
+            description=utils.deepcopy_with_locators(self._model.description),
+            group_template=self._model)
+        group.properties = self._topology.instantiate(self._model.properties)
+        group.interfaces = self._topology.instantiate(self._model.interface_templates)
+        if self._model.node_templates:
+            for node_template in self._model.node_templates:
+                group.nodes += node_template.nodes
+        return group
+
+    def validate(self, **kwargs):
+        self._validate(self._model.properties,
+                       self._model.interface_templates,
+                       **kwargs)
+
+
+class InterfaceTemplate(common.TemplateHandlerBase):
+    def dump(self, out_stream):
+        out_stream.write(out_stream.node_style(self._model.name))
+        if self._model.description:
+            out_stream.write(out_stream.meta_style(self._model.description))
+        with out_stream.indent():
+            out_stream.write('Interface type: {0}'.format(out_stream.type_style(
+                self._model.type.name)))
+            self._topology.dump(self._model.inputs, out_stream, title='Inputs')
+            self._topology.dump(self._model.operation_templates, out_stream,
+                                title='Operation templates')
+
+    def coerce(self, **kwargs):
+        self._coerce(self._model.inputs,
+                     self._model.operation_templates,
+                     **kwargs)
+
+    def instantiate(self, instance_cls, **_):
+        interface = instance_cls(
+            name=self._model.name,
+            type=self._model.type,
+            description=utils.deepcopy_with_locators(self._model.description),
+            interface_template=self._model)
+        interface.inputs = self._topology.instantiate(self._model.inputs)
+        interface.operations = self._topology.instantiate(self._model.operation_templates)
+        return interface
+
+    def validate(self, **kwargs):
+        self._validate(self._model.inputs,
+                       self._model.operation_templates,
+                       **kwargs)
+
+
+class NodeTemplate(common.TemplateHandlerBase):
+    def dump(self, out_stream):
+        out_stream.write('Node template: {0}'.format(out_stream.node_style(self._model.name)))
+        with out_stream.indent():
+            if self._model.description:
+                out_stream.write(out_stream.meta_style(self._model.description))
+            out_stream.write('Type: {0}'.format(out_stream.type_style(self._model.type.name)))
+            self._topology.dump(self._model.properties, out_stream, title='Properties')
+            self._topology.dump(self._model.attributes, out_stream, title='Attributes')
+            self._topology.dump(
+                self._model.interface_templates, out_stream, title='Interface Templates')
+            self._topology.dump(
+                self._model.artifact_templates, out_stream, title='Artifact Templates')
+            self._topology.dump(
+                self._model.capability_templates, out_stream, title='Capability Templates')
+            self._topology.dump(
+                self._model.requirement_templates, out_stream, title='Requirement Templates')
+
+    def coerce(self, **kwargs):
+        self._coerce(self._model.properties,
+                     self._model.attributes,
+                     self._model.interface_templates,
+                     self._model.artifact_templates,
+                     self._model.capability_templates,
+                     self._model.requirement_templates,
+                     **kwargs)
+
+    def instantiate(self, instance_cls, **_):
+        node = instance_cls(
+            name=self._model._next_name,
+            type=self._model.type,
+            description=utils.deepcopy_with_locators(self._model.description),
+            node_template=self._model
+        )
+
+        node.properties = self._topology.instantiate(self._model.properties)
+        node.attributes = self._topology.instantiate(self._model.attributes)
+        node.interfaces = self._topology.instantiate(self._model.interface_templates)
+        node.artifacts = self._topology.instantiate(self._model.artifact_templates)
+        node.capabilities = self._topology.instantiate(self._model.capability_templates)
+
+        # Default attributes
+        if 'tosca_name' in node.attributes and node.attributes['tosca_name'].type_name == 'string':
+            node.attributes['tosca_name'].value = self._model.name
+        if 'tosca_id' in node.attributes and node.attributes['tosca_id'].type_name == 'string':
+            node.attributes['tosca_id'].value = node.name
+
+        return node
+
+    def validate(self, **kwargs):
+        self._validate(self._model.properties,
+                       self._model.attributes,
+                       self._model.interface_templates,
+                       self._model.artifact_templates,
+                       self._model.capability_templates,
+                       self._model.requirement_templates,
+                       **kwargs)
+
+
+class PolicyTemplate(common.TemplateHandlerBase):
+    def dump(self, out_stream):
+        out_stream.write('Policy template: {0}'.format(out_stream.node_style(self._model.name)))
+        if self._model.description:
+            out_stream.write(out_stream.meta_style(self._model.description))
+        with out_stream.indent():
+            out_stream.write('Type: {0}'.format(out_stream.type_style(self._model.type.name)))
+            self._topology.dump(self._model.properties, out_stream, title='Properties')
+            if self._model.node_templates:
+                out_stream.write('Target node templates: {0}'.format(', '.join(
+                    (str(out_stream.node_style(v.name)) for v in self._model.node_templates))))
+            if self._model.group_templates:
+                out_stream.write('Target group templates: {0}'.format(', '.join(
+                    (str(out_stream.node_style(v.name)) for v in self._model.group_templates))))
+
+    def coerce(self, **kwargs):
+        self._topology.coerce(self._model.properties, **kwargs)
+
+    def instantiate(self, instance_cls, **_):
+        policy = instance_cls(
+            name=self._model.name,
+            type=self._model.type,
+            description=utils.deepcopy_with_locators(self._model.description),
+            policy_template=self._model)
+
+        policy.properties = self._topology.instantiate(self._model.properties)
+        if self._model.node_templates:
+            for node_template in self._model.node_templates:
+                policy.nodes += node_template.nodes
+        if self._model.group_templates:
+            for group_template in self._model.group_templates:
+                policy.groups += group_template.groups
+        return policy
+
+    def validate(self, **kwargs):
+        self._topology.validate(self._model.properties, **kwargs)
+
+
+class SubstitutionTemplate(common.TemplateHandlerBase):
+
+    def dump(self, out_stream):
+        out_stream.write('Substitution template:')
+        with out_stream.indent():
+            out_stream.write('Node type: {0}'.format(out_stream.type_style(
+                self._model.node_type.name)))
+            self._topology.dump(self._model.mappings, out_stream, title='Mappings')
+
+    def coerce(self, **kwargs):
+        self._topology.coerce(self._model.mappings, **kwargs)
+
+    def instantiate(self, instance_cls, **_):
+        return instance_cls(node_type=self._model.node_type, substitution_template=self._model)
+
+    def validate(self, **kwargs):
+        self._topology.validate(self._model.mappings, **kwargs)
+
+
+class SubstitutionTemplateMapping(common.TemplateHandlerBase):
+
+    def dump(self, out_stream):
+        if self._topology.capability_template is not None:
+            node_template = self._model.capability_template.node_template
+        else:
+            node_template = self._model.requirement_template.node_template
+        out_stream.write('{0} -> {1}.{2}'.format(
+            out_stream.node_style(self._model.name),
+            out_stream.node_style(node_template.name),
+            out_stream.node_style(self._model.capability_template.name
+                                  if self._model.capability_template
+                                  else self._model.requirement_template.name)))
+
+    def coerce(self, **_):
+        pass
+
+    def instantiate(self, instance_cls, **_):
+        substitution_mapping = instance_cls(
+            name=self._model.name,
+            requirement_template=self._model.requirement_template)
+
+        if self._model.capability_template is not None:
+            node_template = self._model.capability_template.node_template
+        else:
+            node_template = self._model.requirement_template.node_template
+        nodes = node_template.nodes
+        if len(nodes) == 0:
+            self._topology.report(
+                'mapping "{0}" refers to node template "{1}" but there are no node instances'.
+                format(self._model.mapped_name, self._model.node_template.name),
+                level=self._topology.Issue.BETWEEN_INSTANCES)
+            return None
+        # The TOSCA spec does not provide a way to choose the node,
+        # so we will just pick the first one
+        substitution_mapping.node_style = nodes[0]
+        if self._model.capability_template:
+            for a_capability in substitution_mapping.node_style.capabilities.itervalues():
+                if a_capability.capability_template.name == \
+                        self._model.capability_template.name:
+                    substitution_mapping.capability = a_capability
+
+        return substitution_mapping
+
+    def validate(self, **_):
+        if self._model.capability_template is None and self._model.requirement_template is None:
+            self._topology.report(
+                'mapping "{0}" refers to neither capability nor a requirement '
+                'in node template: {1}'.format(
+                    self._model.name, formatting.safe_repr(self._model.node_template.name)),
+                level=self._topology.Issue.BETWEEN_TYPES)
+
+
+class RelationshipTemplate(common.TemplateHandlerBase):
+    def dump(self, out_stream):
+        if self._model.type is not None:
+            out_stream.write('Relationship type: {0}'.format(out_stream.type_style(
+                self._model.type.name)))
+        else:
+            out_stream.write('Relationship template: {0}'.format(
+                out_stream.node_style(self._model.name)))
+        if self._model.description:
+            out_stream.write(out_stream.meta_style(self._model.description))
+        with out_stream.indent():
+            self._topology.dump(self._model.properties, out_stream, title='Properties')
+            self._topology.dump(self._model.interface_templates, out_stream,
+                                title='Interface Templates')
+
+    def coerce(self, **kwargs):
+        self._coerce(self._model.properties, self._model.interface_templates, **kwargs)
+
+    def instantiate(self, instance_cls, **_):
+        relationship = instance_cls(
+            name=self._model.name,
+            type=self._model.type,
+            relationship_template=self._model)
+
+        relationship.properties = self._topology.instantiate(self._model.properties)
+        relationship.interfaces = self._topology.instantiate(self._model.interface_templates)
+        return relationship
+
+    def validate(self, **kwargs):
+        self._validate(self._model.properties, self._model.interface_templates, **kwargs)
+
+
+class OperationTemplate(common.TemplateHandlerBase):
+
+    def dump(self, out_stream):
+        out_stream.write(out_stream.node_style(self._model.name))
+        if self._model.description:
+            out_stream.write(out_stream.meta_style(self._model.description))
+        with out_stream.indent():
+            if self._model.implementation is not None:
+                out_stream.write('Implementation: {0}'.format(
+                    out_stream.literal_style(self._model.implementation)))
+            if self._model.dependencies:
+                out_stream.write('Dependencies: {0}'.format(', '.join(
+                    (str(out_stream.literal_style(v)) for v in self._model.dependencies))))
+            self._topology.dump(self._model.inputs, out_stream, title='Inputs')
+            if self._model.executor is not None:
+                out_stream.write('Executor: {0}'.format(
+                    out_stream.literal_style(self._model.executor)))
+            if self._model.max_attempts is not None:
+                out_stream.write('Max attempts: {0}'.format(out_stream.literal_style(
+                    self._model.max_attempts)))
+            if self._model.retry_interval is not None:
+                out_stream.write('Retry interval: {0}'.format(
+                    out_stream.literal_style(self._model.retry_interval)))
+            if self._model.plugin_specification is not None:
+                out_stream.write('Plugin specification: {0}'.format(
+                    out_stream.literal_style(self._model.plugin_specification.name)))
+            self._topology.dump(self._model.configurations, out_stream, title='Configuration')
+            if self._model.function is not None:
+                out_stream.write('Function: {0}'.format(out_stream.literal_style(
+                    self._model.function)))
+
+    def coerce(self, **kwargs):
+        self._coerce(self._model.inputs,
+                     self._model.configurations,
+                     **kwargs)
+
+    def instantiate(self, instance_cls, **_):
+        operation = instance_cls(
+            name=self._model.name,
+            description=utils.deepcopy_with_locators(self._model.description),
+            relationship_edge=self._model.relationship_edge,
+            implementation=self._model.implementation,
+            dependencies=self._model.dependencies,
+            executor=self._model.executor,
+            function=self._model.function,
+            max_attempts=self._model.max_attempts,
+            retry_interval=self._model.retry_interval,
+            operation_template=self._model)
+
+        if (self._model.plugin_specification is not None and
+                self._model.plugin_specification.enabled):
+            operation.plugin = self._model.plugin_specification.plugin
+
+        operation.inputs = self._topology.instantiate(self._model.inputs)
+        operation.configurations = self._topology.instantiate(self._model.configurations)
+
+        return operation
+
+    def validate(self, **kwargs):
+        self._validate(self._model.inputs,
+                       self._model.configurations,
+                       **kwargs)
+
+
+class PluginSpecification(common.HandlerBase):
+    def validate(self, **kwargs):
+        pass
+
+    def coerce(self, **kwargs):
+        pass
+
+    def instantiate(self, **_):
+        pass
+
+    def dump(self, out_stream):
+        pass


[4/5] incubator-ariatosca git commit: ARIA-321 Provide Clearwater IMS example

Posted by em...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/data.yaml
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/data.yaml b/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/data.yaml
index 771a969..61d4186 100644
--- a/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/data.yaml
+++ b/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/data.yaml
@@ -18,7 +18,7 @@ data_types:
   #
   # Primitive
   #
-  
+
   timestamp:
     _extensions:
       coerce_value: aria_extension_tosca.simple_v1_0.data_types.coerce_timestamp
@@ -60,7 +60,7 @@ data_types:
       specification: tosca-simple-1.0
       specification_section: 3.2.5
       specification_url: 'http://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html#TYPE_TOSCA_MAP'
-  
+
   #
   # Scalar
   #
@@ -142,7 +142,7 @@ data_types:
           The optional user (name or ID) used for non-token based credentials.
         type: string
         required: false
-  
+
   tosca.datatypes.network.NetworkInfo:
     _extensions:
       shorthand_name: NetworkInfo
@@ -171,7 +171,7 @@ data_types:
         entry_schema:
           type: string
         required: false
-  
+
   tosca.datatypes.network.PortInfo:
     _extensions:
       shorthand_name: PortInfo
@@ -210,7 +210,7 @@ data_types:
         entry_schema:
           type: string
         required: false
-  
+
   tosca.datatypes.network.PortDef:
     _extensions:
       shorthand_name: PortDef

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/interfaces.yaml
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/interfaces.yaml b/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/interfaces.yaml
index 473bd98..29cc8dd 100644
--- a/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/interfaces.yaml
+++ b/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/interfaces.yaml
@@ -24,7 +24,7 @@ interface_types:
       specification_url: 'http://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html#_Ref384391055'
     description: >-
       This is the default (root) TOSCA Interface Type definition that all other TOSCA Interface Types derive from.
-  
+
   tosca.interfaces.node.lifecycle.Standard:
     _extensions:
       shorthand_name: Standard

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/nodes.yaml
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/nodes.yaml b/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/nodes.yaml
index 1d2fe90..05963b7 100644
--- a/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/nodes.yaml
+++ b/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/nodes.yaml
@@ -45,14 +45,14 @@ node_types:
         type: tosca.interfaces.node.lifecycle.Standard
     capabilities:
       feature:
-        type: tosca.capabilities.Node  
+        type: tosca.capabilities.Node
     requirements:
       - dependency:
           capability: tosca.capabilities.Node
           node: tosca.nodes.Root
           relationship: tosca.relationships.DependsOn
           occurrences: [ 0, UNBOUNDED ]
-  
+
   tosca.nodes.Compute:
     _extensions:
       shorthand_name: Compute
@@ -133,11 +133,11 @@ node_types:
           capability: tosca.capabilities.Endpoint
           relationship: tosca.relationships.RoutesTo
           occurrences: [ 0, UNBOUNDED ]
-  
+
   #
   # Software
   #
-  
+
   tosca.nodes.SoftwareComponent:
     _extensions:
       shorthand_name: SoftwareComponent
@@ -211,7 +211,7 @@ node_types:
           capability: tosca.capabilities.Container
           node: tosca.nodes.WebServer
           relationship: tosca.relationships.HostedOn
-  
+
   tosca.nodes.DBMS:
     _extensions:
       shorthand_name: DBMS # ARIA NOTE: omitted in the spec
@@ -276,7 +276,7 @@ node_types:
           capability: tosca.capabilities.Container
           node: tosca.nodes.DBMS
           relationship: tosca.relationships.HostedOn
-  
+
   #
   # Container
   #
@@ -351,7 +351,7 @@ node_types:
     capabilities:
       storage_endpoint:
         type: tosca.capabilities.Endpoint
-  
+
   tosca.nodes.BlockStorage:
     _extensions:
       shorthand_name: BlockStorage
@@ -463,7 +463,7 @@ node_types:
     capabilities:
       link:
         type: tosca.capabilities.network.Linkable
-  
+
   tosca.nodes.network.Port:
     _extensions:
       shorthand_name: Port
@@ -472,7 +472,7 @@ node_types:
       specification_section: 7.5.2
     description: >-
       The TOSCA Port node represents a logical entity that associates between Compute and Network normative types.
-      
+
       The Port node type effectively represents a single virtual NIC on the Compute node instance.
     derived_from: tosca.nodes.Root
     properties:

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/policies.yaml
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/policies.yaml b/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/policies.yaml
index c65e38b..7b35bb9 100644
--- a/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/policies.yaml
+++ b/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/policies.yaml
@@ -24,7 +24,7 @@ policy_types:
       specification_url: 'http://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html#DEFN_TYPE_POLICIES_ROOT'
     description: >-
       This is the default (root) TOSCA Policy Type definition that all other TOSCA base Policy Types derive from.
-  
+
   tosca.policies.Placement:
     _extensions:
       shorthand_name: Placement # ARIA NOTE: omitted in the spec
@@ -35,7 +35,7 @@ policy_types:
     description: >-
       This is the default (root) TOSCA Policy Type definition that is used to govern placement of TOSCA nodes or groups of nodes.
     derived_from: tosca.policies.Root
-  
+
   tosca.policies.Scaling:
     _extensions:
       shorthand_name: Scaling # ARIA NOTE: omitted in the spec
@@ -46,7 +46,7 @@ policy_types:
     description: >-
       This is the default (root) TOSCA Policy Type definition that is used to govern scaling of TOSCA nodes or groups of nodes.
     derived_from: tosca.policies.Root
-  
+
   tosca.policies.Update:
     _extensions:
       shorthand_name: Update # ARIA NOTE: omitted in the spec
@@ -57,7 +57,7 @@ policy_types:
     description: >-
       This is the default (root) TOSCA Policy Type definition that is used to govern update of TOSCA nodes or groups of nodes.
     derived_from: tosca.policies.Root
-  
+
   tosca.policies.Performance:
     _extensions:
       shorthand_name: Performance # ARIA NOTE: omitted in the spec

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/relationships.yaml
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/relationships.yaml b/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/relationships.yaml
index b9d3176..9f2c32c 100644
--- a/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/relationships.yaml
+++ b/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/relationships.yaml
@@ -43,7 +43,7 @@ relationship_types:
     interfaces:
       Configure:
         type: tosca.interfaces.relationship.Configure
-  
+
   tosca.relationships.DependsOn:
     _extensions:
       shorthand_name: DependsOn
@@ -55,7 +55,7 @@ relationship_types:
       This type represents a general dependency relationship between two nodes.
     derived_from: tosca.relationships.Root
     valid_target_types: [ tosca.capabilities.Node ]
-  
+
   tosca.relationships.HostedOn:
     _extensions:
       shorthand_name: HostedOn
@@ -67,7 +67,7 @@ relationship_types:
       This type represents a hosting relationship between two nodes.
     derived_from: tosca.relationships.Root
     valid_target_types: [ tosca.capabilities.Container ]
-  
+
   tosca.relationships.ConnectsTo:
     _extensions:
       shorthand_name: ConnectsTo
@@ -83,7 +83,7 @@ relationship_types:
       credential:
         type: tosca.datatypes.Credential
         required: false
-  
+
   tosca.relationships.AttachesTo:
     _extensions:
       shorthand_name: AttachesTo
@@ -116,7 +116,7 @@ relationship_types:
           The logical name of the device as exposed to the instance.
           Note: A runtime property that gets set when the model gets instantiated by the orchestrator.
         type: string
-  
+
   tosca.relationships.RoutesTo:
     _extensions:
       shorthand_name: RoutesTo
@@ -128,11 +128,11 @@ relationship_types:
       This type represents an intentional network routing between two Endpoints in different networks.
     derived_from: tosca.relationships.ConnectsTo
     valid_target_types: [ tosca.capabilities.Endpoint ]
-  
+
   #
   # Network
   #
-  
+
   tosca.relationships.network.LinksTo:
     _extensions:
       shorthand_name: LinksTo
@@ -144,7 +144,7 @@ relationship_types:
       This relationship type represents an association relationship between Port and Network node types.
     derived_from: tosca.relationships.DependsOn
     valid_target_types: [ tosca.capabilities.network.Linkable ]
-  
+
   tosca.relationships.network.BindsTo:
     _extensions:
       shorthand_name: BindsTo # ARIA NOTE: the spec says "network.BindsTo" which seems wrong

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/extensions/aria_extension_tosca/profiles/tosca-simple-nfv-1.0/nodes.yaml
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/profiles/tosca-simple-nfv-1.0/nodes.yaml b/extensions/aria_extension_tosca/profiles/tosca-simple-nfv-1.0/nodes.yaml
index 73f0ecd..8d1f0a2 100644
--- a/extensions/aria_extension_tosca/profiles/tosca-simple-nfv-1.0/nodes.yaml
+++ b/extensions/aria_extension_tosca/profiles/tosca-simple-nfv-1.0/nodes.yaml
@@ -98,11 +98,11 @@ node_types:
         # ARIA NOTE: commented out in 5.9.2.5
         description: >-
           Monitoring parameter, which can be tracked for a VNFC based on this VDU. Examples include:
-          memory-consumption, CPU-utilisation, bandwidth-consumption, VNFC downtime, etc.        
+          memory-consumption, CPU-utilisation, bandwidth-consumption, VNFC downtime, etc.
         type: tosca.capabilities.nfv.Metric
     #requirements:
       # ARIA NOTE: virtual_storage is TBD
-      
+
       # ARIA NOTE: csd04 attempts to deprecate the inherited local_storage requirement, but this
       # is not possible in TOSCA
     artifacts:

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/extensions/aria_extension_tosca/simple_v1_0/data_types.py
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/simple_v1_0/data_types.py b/extensions/aria_extension_tosca/simple_v1_0/data_types.py
index 513b517..216f1e4 100644
--- a/extensions/aria_extension_tosca/simple_v1_0/data_types.py
+++ b/extensions/aria_extension_tosca/simple_v1_0/data_types.py
@@ -163,7 +163,7 @@ class Version(object):
     #TYPE_TOSCA_VERSION>`__
     """
 
-    REGULAR = \
+    REGEX = \
         r'^(?P<major>\d+)\.(?P<minor>\d+)(\.(?P<fix>\d+)' + \
         r'((\.(?P<qualifier>\d+))(\-(?P<build>\d+))?)?)?$'
 
@@ -176,7 +176,7 @@ class Version(object):
 
     def __init__(self, entry_schema, constraints, value, aspect): # pylint: disable=unused-argument
         str_value = str(value)
-        match = re.match(Version.REGULAR, str_value)
+        match = re.match(Version.REGEX, str_value)
         if match is None:
             raise ValueError(
                 'version must be formatted as <major_version>.<minor_version>'
@@ -376,11 +376,14 @@ class Scalar(object):
 
     def __init__(self, entry_schema, constraints, value, aspect): # pylint: disable=unused-argument
         str_value = str(value)
-        match = re.match(self.REGULAR, str_value) # pylint: disable=no-member
+        match = re.match(self.REGEX, str_value) # pylint: disable=no-member
         if match is None:
             raise ValueError('scalar must be formatted as <scalar> <unit>: %s' % safe_repr(value))
 
         self.factor = float(match.group('scalar'))
+        if self.factor < 0:
+            raise ValueError('scalar is negative: %s' % safe_repr(self.factor))
+
         self.unit = match.group('unit')
 
         unit_lower = self.unit.lower()
@@ -435,7 +438,7 @@ class ScalarSize(Scalar):
     """
 
     # See: http://www.regular-expressions.info/floatingpoint.html
-    REGULAR = \
+    REGEX = \
         r'^(?P<scalar>[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)\s*(?P<unit>B|kB|KiB|MB|MiB|GB|GiB|TB|TiB)$'
 
     UNITS = {
@@ -464,7 +467,7 @@ class ScalarTime(Scalar):
     """
 
     # See: http://www.regular-expressions.info/floatingpoint.html
-    REGULAR = r'^(?P<scalar>[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)\s*(?P<unit>ns|us|ms|s|m|h|d)$'
+    REGEX = r'^(?P<scalar>[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)\s*(?P<unit>ns|us|ms|s|m|h|d)$'
 
     UNITS = {
         'ns':     0.000000001,
@@ -490,7 +493,7 @@ class ScalarFrequency(Scalar):
     """
 
     # See: http://www.regular-expressions.info/floatingpoint.html
-    REGULAR = r'^(?P<scalar>[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)\s*(?P<unit>Hz|kHz|MHz|GHz)$'
+    REGEX = r'^(?P<scalar>[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)\s*(?P<unit>Hz|kHz|MHz|GHz)$'
 
     UNITS = {
         'Hz':           1.0,

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/extensions/aria_extension_tosca/simple_v1_0/modeling/capabilities.py
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/capabilities.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/capabilities.py
index 5427c7e..1b95bec 100644
--- a/extensions/aria_extension_tosca/simple_v1_0/modeling/capabilities.py
+++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/capabilities.py
@@ -68,12 +68,14 @@ def get_inherited_capability_definitions(context, presentation, for_presentation
                 capability_definition = capability_definitions[capability_name]
 
                 # Check if we changed the type
-                type1 = capability_definition.type
-                type2 = our_capability_definition.type
-                if type1 != type2:
+                type1 = capability_definition._get_type(context)
+                type2 = our_capability_definition._get_type(context)
+
+                if not type1._is_descendant(context, type2):
                     context.validation.report(
-                        'capability definition changes type from "{0}" to "{1}" in "{2}"'
-                        .format(type1, type2, presentation._fullname),
+                        'capability definition type "{0}" is not a descendant of overridden '
+                        'capability definition type "{1}"' \
+                        .format(type1._name, type2._name),
                         locator=our_capability_definition._locator, level=Issue.BETWEEN_TYPES)
 
                 merge_capability_definition(context, presentation, capability_definition,
@@ -168,6 +170,8 @@ def merge_capability_definition(context, presentation, capability_definition,
                                 from_capability_definition):
     raw_properties = OrderedDict()
 
+    capability_definition._raw['type'] = from_capability_definition.type
+
     # Merge properties from type
     from_property_defintions = from_capability_definition.properties
     merge_raw_parameter_definitions(context, presentation, raw_properties, from_property_defintions,

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/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 9dee0f2..13ce9a3 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
@@ -159,10 +159,6 @@ def get_data_type(context, presentation, field_name, allow_none=False):
         else:
             return str
 
-    # Make sure not derived from self
-    if type_name == presentation._name:
-        return None
-
     # Avoid circular definitions
     container_data_type = get_container_data_type(presentation)
     if (container_data_type is not None) and (container_data_type._name == type_name):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/extensions/aria_extension_tosca/simple_v1_0/modeling/functions.py
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/functions.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/functions.py
index 590c6a0..ecbfde9 100644
--- a/extensions/aria_extension_tosca/simple_v1_0/modeling/functions.py
+++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/functions.py
@@ -200,20 +200,24 @@ class GetProperty(Function):
         for modelable_entity in modelable_entities:
             properties = None
 
+            # First argument refers to a requirement template?
             if hasattr(modelable_entity, 'requirement_templates') \
                 and modelable_entity.requirement_templates \
                 and (req_or_cap_name in [v.name for v in modelable_entity.requirement_templates]):
-                for requirement_template in modelable_entity.requirement_templates:
-                    if requirement_template.name == req_or_cap_name:
-                        # First argument refers to a requirement
-                        # TODO: should follow to matched capability in other node...
+                for requirement in modelable_entity.requirement_templates:
+                    if requirement.name == req_or_cap_name:
+                        # TODO
                         raise CannotEvaluateFunctionException()
-                        # break
+            # First argument refers to a capability?
+            elif hasattr(modelable_entity, 'capabilities') \
+                and modelable_entity.capabilities \
+                and (req_or_cap_name in modelable_entity.capabilities):
+                properties = modelable_entity.capabilities[req_or_cap_name].properties
                 nested_property_name_or_index = self.nested_property_name_or_index[1:]
+            # First argument refers to a capability template?
             elif hasattr(modelable_entity, 'capability_templates') \
                 and modelable_entity.capability_templates \
                 and (req_or_cap_name in modelable_entity.capability_templates):
-                # First argument refers to a capability
                 properties = modelable_entity.capability_templates[req_or_cap_name].properties
                 nested_property_name_or_index = self.nested_property_name_or_index[1:]
             else:
@@ -640,7 +644,7 @@ def get_target(container_holder, name, locator):
 
 def get_modelable_entity_parameter(modelable_entity, parameters, nested_parameter_name_or_index):
     if not parameters:
-        return False, True, None
+        return Evaluation(None, True)
 
     found = True
     final = True

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/extensions/aria_extension_tosca/simple_v1_0/modeling/interfaces.py
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/interfaces.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/interfaces.py
index fffd5c1..23a03b7 100644
--- a/extensions/aria_extension_tosca/simple_v1_0/modeling/interfaces.py
+++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/interfaces.py
@@ -400,13 +400,15 @@ def merge_raw_operation_definitions(context, raw_operations, our_operations, int
 def merge_interface_definition(context, interface, our_source, presentation, type_name):
     if hasattr(our_source, 'type'):
         # Check if we changed the interface type
-        input_type1 = interface.type
-        input_type2 = our_source.type
-        if (input_type1 is not None) and (input_type2 is not None) and (input_type1 != input_type2):
+        type1 = interface._get_type(context)
+        type2 = our_source._get_type(context)
+
+        if (type2 is not None) and not type1._is_descendant(context, type2):
             context.validation.report(
-                'interface definition "%s" changes type from "%s" to "%s" in "%s"'
-                % (interface._name, input_type1, input_type2, presentation._fullname),
-                locator=input_type2._locator, level=Issue.BETWEEN_TYPES)
+                'interface definition type "{0}" is not a descendant of overridden '
+                'interface definition type "{1}"' \
+                .format(type1._name, type2._name),
+                locator=our_source._locator, level=Issue.BETWEEN_TYPES)
 
     # Add/merge inputs
     our_interface_inputs = our_source._get_inputs(context) \

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/extensions/aria_extension_tosca/simple_v1_0/modeling/parameters.py
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/parameters.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/parameters.py
index f271b4d..5c14ad2 100644
--- a/extensions/aria_extension_tosca/simple_v1_0/modeling/parameters.py
+++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/parameters.py
@@ -18,7 +18,8 @@ from aria.utils.formatting import pluralize
 from aria.parser.presentation import Value
 from aria.parser.validation import Issue
 
-from .data_types import coerce_value
+from .data_types import (coerce_value, get_primitive_data_type)
+from ..presentation.types import get_type_by_name
 
 
 #
@@ -149,16 +150,22 @@ def validate_required_values(context, presentation, values, definitions):
 
 def merge_raw_parameter_definition(context, presentation, raw_property_definition,
                                    our_property_definition, field_name, property_name):
-    # Check if we changed the type
-    # TODO: allow a sub-type?
-    type1 = raw_property_definition.get('type')
-    type2 = our_property_definition.type
+    # Check if we changed the parameter type
+    type1_name = raw_property_definition.get('type')
+    type1 = get_type_by_name(context, type1_name, 'data_types')
+    if type1 is None:
+        type1 = get_primitive_data_type(type1_name)
+    our_property_definition._reset_method_cache()
+    type2 = our_property_definition._get_type(context)
+
     if type1 != type2:
-        context.validation.report(
-            'override changes type from "%s" to "%s" for property "%s" in "%s"'
-            % (type1, type2, property_name, presentation._fullname),
-            locator=presentation._get_child_locator(field_name, property_name),
-            level=Issue.BETWEEN_TYPES)
+        if not hasattr(type1, '_is_descendant') or not type1._is_descendant(context, type2):
+            context.validation.report(
+                'property definition type "{0}" is not a descendant of overridden '
+                'property definition type "{1}"' \
+                .format(type1_name, type2._name),
+                locator=presentation._get_child_locator(field_name, property_name),
+                level=Issue.BETWEEN_TYPES)
 
     merge(raw_property_definition, our_property_definition._raw)
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/extensions/aria_extension_tosca/simple_v1_0/presentation/types.py
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/simple_v1_0/presentation/types.py b/extensions/aria_extension_tosca/simple_v1_0/presentation/types.py
index 920ebed..5f9750e 100644
--- a/extensions/aria_extension_tosca/simple_v1_0/presentation/types.py
+++ b/extensions/aria_extension_tosca/simple_v1_0/presentation/types.py
@@ -18,7 +18,8 @@ def convert_name_to_full_type_name(context, name, types_dict): # pylint: disable
     """
     Converts a type name to its full type name, or else returns it unchanged.
 
-    Works by checking for ``shorthand_name`` in the types' ``_extensions`` field. See also
+    Works by checking for ``shorthand_name`` and ``type_qualified_name`` in the types'
+    ``_extensions`` field. See also
     :class:`aria_extension_tosca.v1_0.presentation.extensible.ExtensiblePresentation`.
 
     Can be used as the conversion function argument in ``type_validator`` and
@@ -36,9 +37,10 @@ def convert_name_to_full_type_name(context, name, types_dict): # pylint: disable
 
 def get_type_by_name(context, name, *types_dict_names):
     """
-    Gets a type either by its full name or its shorthand name or typequalified name.
+    Gets a type either by its full name or its shorthand name or type-qualified name.
 
-    Works by checking for ``shorthand_name`` in the types' ``_extensions`` field. See also
+    Works by checking for ``shorthand_name`` and ``type_qualified_name`` in the types'
+    ``_extensions`` field. See also
     :class:`~aria_extension_tosca.v1_0.presentation.extensible.ExtensiblePresentation`.
 
     The arguments from the third onwards are used to locate a nested field under

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/extensions/aria_extension_tosca/simple_v1_0/types.py
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/simple_v1_0/types.py b/extensions/aria_extension_tosca/simple_v1_0/types.py
index 787aac2..b662a20 100644
--- a/extensions/aria_extension_tosca/simple_v1_0/types.py
+++ b/extensions/aria_extension_tosca/simple_v1_0/types.py
@@ -193,6 +193,17 @@ class DataType(ExtensiblePresentation):
         return get_data_type(context, self, 'derived_from', allow_none=True)
 
     @cachedmethod
+    def _is_descendant(self, context, the_type):
+        if the_type is None:
+            return False
+        if not hasattr(the_type, '_name'):
+            # Must be a primitive type
+            return self._get_primitive_ancestor(context) == the_type
+        if the_type._name == self._name:
+            return True
+        return self._is_descendant(context, the_type._get_parent(context))
+
+    @cachedmethod
     def _get_primitive_ancestor(self, context):
         parent = self._get_parent(context)
         if parent is not None:
@@ -387,6 +398,14 @@ class InterfaceType(ExtensiblePresentation):
                                        'interface_types')
 
     @cachedmethod
+    def _is_descendant(self, context, the_type):
+        if the_type is None:
+            return False
+        elif the_type._name == self._name:
+            return True
+        return self._is_descendant(context, the_type._get_parent(context))
+
+    @cachedmethod
     def _get_inputs(self, context):
         return FrozenDict(get_inherited_parameter_definitions(context, self, 'inputs'))
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/tests/end2end/test_hello_world.py
----------------------------------------------------------------------
diff --git a/tests/end2end/test_hello_world.py b/tests/end2end/test_hello_world.py
index 5e4d7fd..094ffc3 100644
--- a/tests/end2end/test_hello_world.py
+++ b/tests/end2end/test_hello_world.py
@@ -20,7 +20,7 @@ from .. import helpers
 
 
 def test_hello_world(testenv):
-    hello_world_template_uri = helpers.get_example_uri('hello-world', 'helloworld.yaml')
+    hello_world_template_uri = helpers.get_example_uri('hello-world', 'hello-world.yaml')
     service_name = testenv.install_service(hello_world_template_uri)
 
     try:

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml
----------------------------------------------------------------------
diff --git a/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml b/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml
index 5a46532..260f0bf 100644
--- a/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml
+++ b/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml
@@ -89,7 +89,7 @@ topology_template:
       value: *DEFAULT_OPENSTACK_CREDENTIAL
 
   node_templates:
-  
+
     # Application
 
     node_cellar:
@@ -135,7 +135,7 @@ topology_template:
           properties:
             protocol: udp
             url_path: /nodecellar
-    
+
     node_cellar_database:
       description: >-
         Node Cellar MongoDB database.
@@ -151,7 +151,7 @@ topology_template:
           repository: node_cellar
 
     # Server software
-    
+
     nodejs:
       description: >-
         Node.js instance.
@@ -202,7 +202,7 @@ topology_template:
     loadbalancer:
       type: nginx.LoadBalancer
       properties:
-        algorithm: round-robin   
+        algorithm: round-robin
 
     # Hosts
 
@@ -273,7 +273,7 @@ topology_template:
           create: create_data_volume.sh
 
   groups:
-  
+
     node_cellar_group:
       type: openstack.Secured
       members:
@@ -286,7 +286,7 @@ topology_template:
             openstack_credential: { get_input: openstack_credential }
 
   policies:
-  
+
     app_scaling:
       type: aria.Scaling
       properties:
@@ -295,7 +295,7 @@ topology_template:
       targets:
         - node_cellar
         - nodejs
-  
+
     host_scaling:
       type: openstack.Scaling
       properties:
@@ -304,7 +304,7 @@ topology_template:
         default_instances: 2
       targets: # node templates or groups
         - node_cellar_group
-    
+
     juju:
       description: >-
         Juju plugin executes charms.
@@ -345,7 +345,7 @@ policy_types:
     description: >-
       Workflow to put all nodes in/out of maintenance mode. For web servers, this will show a "this
       site is under maintenance and we'll be back soon" web page. Database nodes will then close all
-      client connections cleanly and shut down services. 
+      client connections cleanly and shut down services.
     derived_from: aria.Workflow
     properties:
       implementation:

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/tests/resources/service-templates/tosca-simple-1.0/node-cellar/types/mongodb.yaml
----------------------------------------------------------------------
diff --git a/tests/resources/service-templates/tosca-simple-1.0/node-cellar/types/mongodb.yaml b/tests/resources/service-templates/tosca-simple-1.0/node-cellar/types/mongodb.yaml
index 34d0a9d..7031252 100644
--- a/tests/resources/service-templates/tosca-simple-1.0/node-cellar/types/mongodb.yaml
+++ b/tests/resources/service-templates/tosca-simple-1.0/node-cellar/types/mongodb.yaml
@@ -44,7 +44,7 @@ node_types:
   mongodb.Database:
     description: >-
       MongoDB database.
-      
+
       Supports importing database data if a mongodb.DatabaseDump is provided.
     derived_from: tosca.nodes.Database
     interfaces:

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/tests/resources/service-templates/tosca-simple-1.0/node-cellar/types/nodejs.yaml
----------------------------------------------------------------------
diff --git a/tests/resources/service-templates/tosca-simple-1.0/node-cellar/types/nodejs.yaml b/tests/resources/service-templates/tosca-simple-1.0/node-cellar/types/nodejs.yaml
index 19cc7b9..2b4d451 100644
--- a/tests/resources/service-templates/tosca-simple-1.0/node-cellar/types/nodejs.yaml
+++ b/tests/resources/service-templates/tosca-simple-1.0/node-cellar/types/nodejs.yaml
@@ -30,7 +30,7 @@ node_types:
         file: https://nodejs.org/dist/v4.4.7/node-v4.4.7-linux-x64.tar.xz
         deploy_path: /opt/nodejs
     capabilities:
-      data_endpoint: # @override 
+      data_endpoint: # @override
         type: tosca.capabilities.Endpoint
         properties:
           port:

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/tests/resources/service-templates/tosca-simple-1.0/node-cellar/types/openstack.yaml
----------------------------------------------------------------------
diff --git a/tests/resources/service-templates/tosca-simple-1.0/node-cellar/types/openstack.yaml b/tests/resources/service-templates/tosca-simple-1.0/node-cellar/types/openstack.yaml
index 99ee902..6941c1a 100644
--- a/tests/resources/service-templates/tosca-simple-1.0/node-cellar/types/openstack.yaml
+++ b/tests/resources/service-templates/tosca-simple-1.0/node-cellar/types/openstack.yaml
@@ -31,7 +31,7 @@ node_types:
 
       You may assign an image_id or attach an openstack.Image artifact (the artifact
       will take precedence).
-    
+
       You may assign either flavor_id or flavor_name (flavor_id will take precedence).
       If neither are assigned, flavor_name has a default value.
     derived_from: tosca.nodes.Compute
@@ -87,7 +87,7 @@ node_types:
   openstack.Volume:
     description: >-
       OpenStack volume.
-      
+
       See: http://developer.openstack.org/api-ref-blockstorage-v2.html
     derived_from: tosca.nodes.BlockStorage
     properties:

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/tests/resources/service-templates/tosca-simple-1.0/types/shorthand-1/shorthand-1.yaml
----------------------------------------------------------------------
diff --git a/tests/resources/service-templates/tosca-simple-1.0/types/shorthand-1/shorthand-1.yaml b/tests/resources/service-templates/tosca-simple-1.0/types/shorthand-1/shorthand-1.yaml
index b295f95..bb5a84e 100644
--- a/tests/resources/service-templates/tosca-simple-1.0/types/shorthand-1/shorthand-1.yaml
+++ b/tests/resources/service-templates/tosca-simple-1.0/types/shorthand-1/shorthand-1.yaml
@@ -6,17 +6,17 @@ description: >-
 topology_template:
 
   node_templates:
-  
+
     my_server:
       type: Compute
       requirements:
         - local_storage:
-            node: my_block_storage           
+            node: my_block_storage
             relationship:
               type: AttachesTo
               properties:
                 location: /path1/path2
-  
+
     my_block_storage:
       type: BlockStorage
       properties:

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/tests/resources/service-templates/tosca-simple-1.0/types/typequalified-1/typequalified-1.yaml
----------------------------------------------------------------------
diff --git a/tests/resources/service-templates/tosca-simple-1.0/types/typequalified-1/typequalified-1.yaml b/tests/resources/service-templates/tosca-simple-1.0/types/typequalified-1/typequalified-1.yaml
index 5f11fd4..b54604f 100644
--- a/tests/resources/service-templates/tosca-simple-1.0/types/typequalified-1/typequalified-1.yaml
+++ b/tests/resources/service-templates/tosca-simple-1.0/types/typequalified-1/typequalified-1.yaml
@@ -6,17 +6,17 @@ description: >-
 topology_template:
 
   node_templates:
-  
+
     my_server:
       type: tosca:Compute
       requirements:
         - local_storage:
-            node: my_block_storage           
+            node: my_block_storage
             relationship:
               type: AttachesTo
               properties:
                 location: /path1/path2
-  
+
     my_block_storage:
       type: tosca:BlockStorage
       properties:


[5/5] incubator-ariatosca git commit: ARIA-321 Provide Clearwater IMS example

Posted by em...@apache.org.
ARIA-321 Provide Clearwater IMS example

* Allows capabilities, interfaces, and properties to override parent
definition types only if the new type is a descendant of the overridden
type
* Fix bugs in model instrumentation (to allow ctx access to capability
properties and complex values)
* Fix to get_property intrinsic function
* Don't let scalar values be negative
* Doc fixes related to ARIA-277


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

Branch: refs/heads/ARIA-321-clearwater
Commit: 40be3086436b895c527345dc243a4ee30cde40d5
Parents: df2b916
Author: Tal Liron <ta...@gmail.com>
Authored: Thu Jul 27 17:58:17 2017 -0500
Committer: Tal Liron <ta...@gmail.com>
Committed: Wed Aug 9 08:15:48 2017 -0500

----------------------------------------------------------------------
 README.rst                                      |   2 +-
 aria/modeling/functions.py                      |   4 +-
 aria/modeling/service_common.py                 |   2 +-
 aria/modeling/service_instance.py               |  89 ++-
 .../clearwater/clearwater-single-static.yaml    | 111 +++
 examples/clearwater/scripts/bono/create.sh      |   4 +
 examples/clearwater/scripts/bono/delete.sh      |   0
 examples/clearwater/scripts/dime/create.sh      |   5 +
 examples/clearwater/scripts/dime/delete.sh      |   0
 examples/clearwater/scripts/ellis/configure.sh  |  14 +
 examples/clearwater/scripts/ellis/create.sh     |   4 +
 examples/clearwater/scripts/ellis/delete.sh     |   0
 examples/clearwater/scripts/homer/create.sh     |  12 +
 examples/clearwater/scripts/homer/delete.sh     |   0
 examples/clearwater/scripts/homestead/create.sh |  10 +
 examples/clearwater/scripts/homestead/delete.sh |   0
 examples/clearwater/scripts/host/configure.sh   | 157 +++++
 examples/clearwater/scripts/memento/create.sh   |   4 +
 examples/clearwater/scripts/memento/delete.sh   |   0
 examples/clearwater/scripts/ralf/create.sh      |   0
 examples/clearwater/scripts/ralf/delete.sh      |   0
 examples/clearwater/scripts/sprout/create.sh    |   4 +
 examples/clearwater/scripts/sprout/delete.sh    |   0
 examples/clearwater/scripts/vellum/create.sh    |   8 +
 examples/clearwater/scripts/vellum/delete.sh    |   0
 examples/clearwater/types/cassandra.yaml        |  16 +
 examples/clearwater/types/clearwater.yaml       | 683 +++++++++++++++++++
 examples/clearwater/types/ims.yaml              | 431 ++++++++++++
 examples/clearwater/types/smtp.yaml             |  21 +
 examples/hello-world/hello-world.yaml           |  38 ++
 examples/hello-world/helloworld.yaml            |  38 --
 .../block-storage-1/block-storage-1.yaml        |   6 +-
 .../block-storage-2/block-storage-2.yaml        |   6 +-
 .../block-storage-3/block-storage-3.yaml        |   4 +-
 .../block-storage-4/block-storage-4.yaml        |   2 +-
 .../use-cases/non-normative-types.yaml          |   6 +-
 .../webserver-dbms-1/webserver-dbms-1.yaml      |  10 +-
 .../profiles/tosca-simple-1.0/artifacts.yaml    |  18 +-
 .../profiles/tosca-simple-1.0/capabilities.yaml |   8 +-
 .../profiles/tosca-simple-1.0/data.yaml         |  10 +-
 .../profiles/tosca-simple-1.0/interfaces.yaml   |   2 +-
 .../profiles/tosca-simple-1.0/nodes.yaml        |  18 +-
 .../profiles/tosca-simple-1.0/policies.yaml     |   8 +-
 .../tosca-simple-1.0/relationships.yaml         |  16 +-
 .../profiles/tosca-simple-nfv-1.0/nodes.yaml    |   4 +-
 .../simple_v1_0/data_types.py                   |  15 +-
 .../simple_v1_0/modeling/capabilities.py        |  14 +-
 .../simple_v1_0/modeling/data_types.py          |   4 -
 .../simple_v1_0/modeling/functions.py           |  18 +-
 .../simple_v1_0/modeling/interfaces.py          |  14 +-
 .../simple_v1_0/modeling/parameters.py          |  27 +-
 .../simple_v1_0/presentation/types.py           |   8 +-
 .../aria_extension_tosca/simple_v1_0/types.py   |  19 +
 tests/end2end/test_hello_world.py               |   2 +-
 .../node-cellar/node-cellar.yaml                |  18 +-
 .../node-cellar/types/mongodb.yaml              |   2 +-
 .../node-cellar/types/nodejs.yaml               |   2 +-
 .../node-cellar/types/openstack.yaml            |   4 +-
 .../types/shorthand-1/shorthand-1.yaml          |   6 +-
 .../types/typequalified-1/typequalified-1.yaml  |   6 +-
 60 files changed, 1766 insertions(+), 168 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/README.rst
----------------------------------------------------------------------
diff --git a/README.rst b/README.rst
index b9a8213..1284808 100644
--- a/README.rst
+++ b/README.rst
@@ -91,7 +91,7 @@ This section will describe how to run a simple "Hello World" example.
 First, provide ARIA with the ARIA "hello world" service-template and name it (e.g.
 ``my-service-template``)::
 
-    aria service-templates store examples/hello-world/helloworld.yaml my-service-template
+    aria service-templates store examples/hello-world/hello-world.yaml my-service-template
 
 Now create a service based on this service-template and name it (e.g. ``my-service``)::
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/aria/modeling/functions.py
----------------------------------------------------------------------
diff --git a/aria/modeling/functions.py b/aria/modeling/functions.py
index 31c3839..554bbfb 100644
--- a/aria/modeling/functions.py
+++ b/aria/modeling/functions.py
@@ -19,6 +19,7 @@ Mechanism for evaluating intrinsic functions.
 from ..parser.exceptions import InvalidValueError
 from ..parser.consumption import ConsumptionContext
 from ..utils.collections import OrderedDict
+from ..utils.type import full_type_name
 from . import exceptions
 
 
@@ -88,7 +89,8 @@ def evaluate(value, container_holder, report_issues=False): # pylint: disable=to
             if (evaluation is None) \
                 or (not hasattr(evaluation, 'value')) \
                 or (not hasattr(evaluation, 'final')):
-                raise InvalidValueError('bad __evaluate__ implementation')
+                raise InvalidValueError('bad __evaluate__ implementation: {0}'
+                                        .format(full_type_name(value)))
 
             evaluated = True
             value = evaluation.value

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/aria/modeling/service_common.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_common.py b/aria/modeling/service_common.py
index 478e530..d1f6b00 100644
--- a/aria/modeling/service_common.py
+++ b/aria/modeling/service_common.py
@@ -28,7 +28,7 @@ from sqlalchemy.ext.declarative import declared_attr
 
 from ..utils import (
     collections,
-    formatting,
+    formatting
 )
 from .mixins import InstanceModelMixin, TemplateModelMixin, ParameterMixin
 from . import relationship

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/aria/modeling/service_instance.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py
index daeb0a4..0205488 100644
--- a/aria/modeling/service_instance.py
+++ b/aria/modeling/service_instance.py
@@ -38,7 +38,7 @@ from .mixins import InstanceModelMixin
 
 from ..utils import (
     collections,
-    formatting,
+    formatting
 )
 
 
@@ -228,6 +228,80 @@ class ServiceBase(InstanceModelMixin):
     :type: :class:`~datetime.datetime`
     """)
 
+    def get_node_by_type(self, type_name):
+        """
+        Finds the first node of a type (or descendent type).
+        """
+        service_template = self.service_template
+
+        if service_template is not None:
+            node_types = service_template.node_types
+            if node_types is not None:
+                for node in self.nodes.itervalues():
+                    if node_types.is_descendant(type_name, node.type.name):
+                        return node
+
+        return None
+
+    def get_policy_by_type(self, type_name):
+        """
+        Finds the first policy of a type (or descendent type).
+        """
+        service_template = self.service_template
+
+        if service_template is not None:
+            policy_types = service_template.policy_types
+            if policy_types is not None:
+                for policy in self.policies.itervalues():
+                    if policy_types.is_descendant(type_name, policy.type.name):
+                        return policy
+
+        return None
+
+    def satisfy_requirements(self):
+        satisfied = True
+        for node in self.nodes.itervalues():
+            if not node.satisfy_requirements():
+                satisfied = False
+        return satisfied
+
+    def validate_capabilities(self):
+        satisfied = True
+        for node in self.nodes.itervalues():
+            if not node.validate_capabilities():
+                satisfied = False
+        return satisfied
+
+    def find_hosts(self):
+        for node in self.nodes.itervalues():
+            node.find_host()
+
+    def configure_operations(self):
+        for node in self.nodes.itervalues():
+            node.configure_operations()
+        for group in self.groups.itervalues():
+            group.configure_operations()
+        for operation in self.workflows.itervalues():
+            operation.configure()
+
+    def is_node_a_target(self, target_node):
+        for node in self.nodes.itervalues():
+            if self._is_node_a_target(node, target_node):
+                return True
+        return False
+
+    def _is_node_a_target(self, source_node, target_node):
+        if source_node.outbound_relationships:
+            for relationship_model in source_node.outbound_relationships:
+                if relationship_model.target_node.name == target_node.name:
+                    return True
+                else:
+                    node = relationship_model.target_node
+                    if node is not None:
+                        if self._is_node_a_target(node, target_node):
+                            return True
+        return False
+
     @property
     def as_raw(self):
         return collections.OrderedDict((
@@ -479,14 +553,15 @@ class NodeBase(InstanceModelMixin):
 
     @classmethod
     def determine_state(cls, op_name, is_transitional):
-        """ :returns the state the node should be in as a result of running the
-            operation on this node.
+        """
+        :returns the state the node should be in as a result of running the operation on this node.
 
-            e.g. if we are running tosca.interfaces.node.lifecycle.Standard.create, then
-            the resulting state should either 'creating' (if the task just started) or 'created'
-            (if the task ended).
+        E.g. if we are running tosca.interfaces.node.lifecycle.Standard.create, then
+        the resulting state should either 'creating' (if the task just started) or 'created'
+        (if the task ended).
 
-            If the operation is not a standard tosca lifecycle operation, then we return None"""
+        If the operation is not a standard TOSCA lifecycle operation, then we return None.
+        """
 
         state_type = 'transitional' if is_transitional else 'finished'
         try:

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/clearwater-single-static.yaml
----------------------------------------------------------------------
diff --git a/examples/clearwater/clearwater-single-static.yaml b/examples/clearwater/clearwater-single-static.yaml
new file mode 100644
index 0000000..79ea020
--- /dev/null
+++ b/examples/clearwater/clearwater-single-static.yaml
@@ -0,0 +1,111 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: >-
+  Project Clearwater is an open-source IMS core, developed by Metaswitch Networks and released under
+  the GNU GPLv3.
+
+metadata:
+  template_name: clearwater-single-static
+  template_author: ARIA
+  template_version: '1.0'
+  aria_version: '0.1.2'
+
+imports:
+  - types/clearwater.yaml
+  - aria-1.0
+
+topology_template:
+
+  inputs:
+    hosts.ssh.user:
+      type: string
+      default: ubuntu
+    hosts.ssh.password:
+      type: string
+      default: ubuntu
+    static_host.public_address:
+      type: string
+      default: 192.168.1.170
+    static_host.private_address:
+      type: string
+      default: { get_input: static_host.public_address }
+
+  node_templates:
+    bono:
+      type: clearwater.Bono
+      requirements:
+        - sip_downstream: clearwater.Sprout
+        - sip_secure_downstream: clearwater.Sprout
+
+    i-cscf:
+      type: clearwater.I-CSCF
+
+    s-cscf:
+      type: clearwater.S-CSCF
+
+    sprout:
+      type: clearwater.Sprout
+#      requirements:
+#        - sip_upstream: clearwater.Bono
+
+    dime:
+      type: clearwater.Dime
+
+    homestead:
+      type: clearwater.Homestead
+
+    ralf:
+      type: clearwater.Ralf
+
+    vellum:
+      type: clearwater.Vellum
+
+    homer:
+      type: clearwater.Homer
+
+    ellis:
+      type: clearwater.Ellis
+      properties:
+        provision_numbers_count: 1000
+
+    static_host:
+      type: clearwater.Host
+      attributes:
+        public_address: { get_input: static_host.public_address }
+        private_address: { get_input: static_host.private_address }
+      capabilities:
+        host:
+          properties:
+            ssh.user: { get_input: hosts.ssh.user }
+            ssh.password: { get_input: hosts.ssh.password }
+            max_log_directory_size: 50 MiB
+            reduce_cassandra_mem_usage: true
+
+    smtp:
+      type: smtp.SMTP
+      properties:
+          # TODO: not validating required :(
+        address: 127.0.0.1
+      capabilities:
+        smtp:
+          properties:
+            # TODO: not validating required :(
+            username: username
+            password: password
+
+  policies:
+    configuration:
+      type: clearwater.Configuration
+      properties:
+        zone: example.com
+        secret: secret
+
+  substitution_mappings:
+    node_type: ims.nodes.IMS
+    capabilities:
+       p-cscf: [ bono, p-cscf ]
+       i-cscf: [ i-cscf, i-cscf ]
+       s-cscf: [ s-cscf, s-cscf ]
+       hss: [ homestead, hss ]
+       ctf: [ ralf, ctf ]
+       xdms: [ homer, xdms ]

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/scripts/bono/create.sh
----------------------------------------------------------------------
diff --git a/examples/clearwater/scripts/bono/create.sh b/examples/clearwater/scripts/bono/create.sh
new file mode 100644
index 0000000..7eb94b1
--- /dev/null
+++ b/examples/clearwater/scripts/bono/create.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+set -e
+
+yes | aptdcon --hide-terminal --install bono restund

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/scripts/bono/delete.sh
----------------------------------------------------------------------
diff --git a/examples/clearwater/scripts/bono/delete.sh b/examples/clearwater/scripts/bono/delete.sh
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/scripts/dime/create.sh
----------------------------------------------------------------------
diff --git a/examples/clearwater/scripts/dime/create.sh b/examples/clearwater/scripts/dime/create.sh
new file mode 100644
index 0000000..04b2d2d
--- /dev/null
+++ b/examples/clearwater/scripts/dime/create.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+set -e
+
+# Installs Homestead and Ralf
+yes | aptdcon --hide-terminal --install dime clearwater-prov-tools

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/scripts/dime/delete.sh
----------------------------------------------------------------------
diff --git a/examples/clearwater/scripts/dime/delete.sh b/examples/clearwater/scripts/dime/delete.sh
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/scripts/ellis/configure.sh
----------------------------------------------------------------------
diff --git a/examples/clearwater/scripts/ellis/configure.sh b/examples/clearwater/scripts/ellis/configure.sh
new file mode 100644
index 0000000..7ed387d
--- /dev/null
+++ b/examples/clearwater/scripts/ellis/configure.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+set -e
+
+PROVISION_NUMBERS_START=$(ctx node properties provision_numbers_start)
+PROVISION_NUMBERS_COUNT=$(ctx node properties provision_numbers_count)
+
+if [ "$PROVISION_NUMBERS_COUNT" != 0 ]; then
+	cd /usr/share/clearwater/ellis
+	. env/bin/activate
+	python src/metaswitch/ellis/tools/create_numbers.py \
+		--start "$PROVISION_NUMBERS_START" \
+		--count "$PROVISION_NUMBERS_COUNT"
+	deactivate
+fi

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/scripts/ellis/create.sh
----------------------------------------------------------------------
diff --git a/examples/clearwater/scripts/ellis/create.sh b/examples/clearwater/scripts/ellis/create.sh
new file mode 100644
index 0000000..93d3fb4
--- /dev/null
+++ b/examples/clearwater/scripts/ellis/create.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+set -e
+
+yes | aptdcon --hide-terminal --install ellis

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/scripts/ellis/delete.sh
----------------------------------------------------------------------
diff --git a/examples/clearwater/scripts/ellis/delete.sh b/examples/clearwater/scripts/ellis/delete.sh
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/scripts/homer/create.sh
----------------------------------------------------------------------
diff --git a/examples/clearwater/scripts/homer/create.sh b/examples/clearwater/scripts/homer/create.sh
new file mode 100644
index 0000000..74510ab
--- /dev/null
+++ b/examples/clearwater/scripts/homer/create.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+set -e
+
+yes | aptdcon --hide-terminal --install homer
+
+# ARIA fix to avoid warnings by Twisted for missing service_identity library
+# (Crest is used by both Homer and Homestead-prov)
+cd /usr/share/clearwater/crest
+. env/bin/activate
+pip install service_identity
+deactivate
+service homer restart

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/scripts/homer/delete.sh
----------------------------------------------------------------------
diff --git a/examples/clearwater/scripts/homer/delete.sh b/examples/clearwater/scripts/homer/delete.sh
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/scripts/homestead/create.sh
----------------------------------------------------------------------
diff --git a/examples/clearwater/scripts/homestead/create.sh b/examples/clearwater/scripts/homestead/create.sh
new file mode 100644
index 0000000..b130bd2
--- /dev/null
+++ b/examples/clearwater/scripts/homestead/create.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+set -e
+
+# ARIA fix to avoid warnings by Twisted for missing service_identity library
+# (Crest is used by both Homer and Homestead-prov)
+cd /usr/share/clearwater/crest
+. env/bin/activate
+pip install service_identity
+deactivate
+service homer restart

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/scripts/homestead/delete.sh
----------------------------------------------------------------------
diff --git a/examples/clearwater/scripts/homestead/delete.sh b/examples/clearwater/scripts/homestead/delete.sh
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/scripts/host/configure.sh
----------------------------------------------------------------------
diff --git a/examples/clearwater/scripts/host/configure.sh b/examples/clearwater/scripts/host/configure.sh
new file mode 100644
index 0000000..0bc5e99
--- /dev/null
+++ b/examples/clearwater/scripts/host/configure.sh
@@ -0,0 +1,157 @@
+#!/bin/bash
+set -e
+
+ZONE=$(ctx service get_policy_by_type clearwater.Configuration properties zone)
+GEOGRAPHICALLY_REDUNDANT=$(ctx service get_policy_by_type clearwater.Configuration properties geographically_redundant)
+SITE_NAME=$(ctx service get_policy_by_type clearwater.Configuration properties site_name)
+SECRET=$(ctx service get_policy_by_type clearwater.Configuration properties secret)
+
+SMTP_HOSTNAME=$(ctx service get_node_by_type smtp.SMTP properties address)
+SMTP_USERNAME=$(ctx service get_node_by_type smtp.SMTP capabilities smtp properties username)
+SMTP_PASSWORD=$(ctx service get_node_by_type smtp.SMTP capabilities smtp properties password)
+
+MAX_LOG_DIRECTORY_SIZE=$(ctx node capabilities host properties max_log_directory_size value)
+REDUCE_CASSANDRA_MEM_USAGE=$(ctx node capabilities host properties reduce_cassandra_mem_usage)
+
+PRIVATE_IP=$(ctx node attributes private_address)
+PUBLIC_IP=$(ctx node attributes public_address)
+PUBLIC_HOSTNAME=$(hostname)
+# TODO: comma-separated list of all private IP addresses in group
+ETCD_CLUSTER=$PRIVATE_IP
+
+REPO_FILE=/etc/apt/sources.list.d/clearwater.list
+REPO_LINE='deb http://repo.cw-ngv.com/stable binary/'
+KEY_URL=http://repo.cw-ngv.com/repo_key
+
+
+#
+# Repository
+#
+
+if [ ! -f "$REPO_FILE" ]; then
+	echo "$REPO_LINE" > "$REPO_FILE"
+	curl --location "$KEY_URL" | apt-key add -
+	apt update
+fi
+
+if ! type aptdcon > /dev/null; then
+	# This will allow us to do concurrent installs
+	apt install aptdaemon --yes
+fi
+
+yes | aptdcon --hide-terminal --install clearwater-management
+
+
+#
+# DNS
+#
+
+S_CSCF_HOST="$PRIVATE_IP scscf.$HOSTNAME # ARIA"
+grep --quiet --fixed-strings "$S_CSCF_HOST" /etc/hosts || echo "$S_CSCF_HOST" >> /etc/hosts
+
+
+#
+# Local configuration
+#
+
+mkdir --parents /etc/clearwater
+CONFIG_FILE=/etc/clearwater/local_config
+echo "# Created by ARIA on $(date -u)" > "$CONFIG_FILE"
+
+echo >> "$CONFIG_FILE"
+echo "# Local IP configuration" >> "$CONFIG_FILE"
+echo "local_ip=$PRIVATE_IP" >> "$CONFIG_FILE"
+echo "public_ip=$PUBLIC_IP" >> "$CONFIG_FILE"
+echo "public_hostname=$PUBLIC_HOSTNAME" >> "$CONFIG_FILE"
+echo "etcd_cluster=$ETCD_CLUSTER" >> "$CONFIG_FILE"
+
+if [ "$MAX_LOG_DIRECTORY_SIZE" != 0 ]; then
+	echo >> "$CONFIG_FILE"
+	echo "max_log_directory_size=$MAX_LOG_DIRECTORY_SIZE" >> "$CONFIG_FILE"
+fi
+
+if [ "$GEOGRAPHICALLY_REDUNDANT" = True ]; then
+	echo >> "$CONFIG_FILE"
+	echo "# Geographically redundant" >> "$CONFIG_FILE"
+	echo "local_site_name=$SITE_NAME" >> "$CONFIG_FILE"
+
+	# On the first Vellum node in the second site, you should set remote_cassandra_seeds to the
+	# IP address of a Vellum node in the first site.
+	#echo "remote_cassandra_seeds=" >> "$CONFIG_FILE"
+fi
+
+
+#
+# Shared configuration
+#
+
+if [ "$GEOGRAPHICALLY_REDUNDANT" = True ]; then
+	SPROUT_HOSTNAME=sprout.$SITE_NAME.$ZONE
+	SPROUT_REGISTRATION_STORE=vellum.$SITE_NAME.$ZONE
+	HS_HOSTNAME=hs.$SITE_NAME.$ZONE:8888
+	HS_PROVISIONING_HOSTNAME=hs.$SITE_NAME.$ZONE:8889
+	RALF_HOSTNAME=ralf.$SITE_NAME.$ZONE:10888
+	RALF_SESSION_STORE=vellum.$ZONE
+	XDMS_HOSTNAME=homer.$SITE_NAME.$ZONE:7888
+	CHRONOS_HOSTNAME=vellum.$SITE_NAME.$ZONE
+	CASSANDRA_HOSTNAME=vellum.$SITE_NAME.$ZONE
+else
+	VELLUM_IP=$PRIVATE_IP
+	HOMESTEAD_IP=$PRIVATE_IP
+	HOMER_IP=$PRIVATE_IP
+
+	SPROUT_HOSTNAME=$PUBLIC_HOSTNAME
+	SPROUT_REGISTRATION_STORE=$VELLUM_IP
+	HS_HOSTNAME=$HOMESTEAD_IP:8888
+	HS_PROVISIONING_HOSTNAME=$HOMESTEAD_IP:8889
+	RALF_HOSTNAME=
+	RALF_SESSION_STORE=
+	XDMS_HOSTNAME=$HOMER_IP:7888
+	CHRONOS_HOSTNAME=
+	CASSANDRA_HOSTNAME=
+fi
+
+mkdir --parents /etc/clearwater
+CONFIG_FILE=/etc/clearwater/shared_config
+echo "# Created by ARIA on $(date -u)" > "$CONFIG_FILE"
+
+echo >> "$CONFIG_FILE"
+echo "# Deployment definitions" >> "$CONFIG_FILE"
+echo "home_domain=$ZONE" >> "$CONFIG_FILE"
+echo "sprout_hostname=$SPROUT_HOSTNAME" >> "$CONFIG_FILE"
+echo "sprout_registration_store=$SPROUT_REGISTRATION_STORE" >> "$CONFIG_FILE"
+echo "hs_hostname=$HS_HOSTNAME" >> "$CONFIG_FILE"
+echo "hs_provisioning_hostname=$HS_PROVISIONING_HOSTNAME" >> "$CONFIG_FILE"
+echo "ralf_hostname=$RALF_HOSTNAME" >> "$CONFIG_FILE"
+echo "ralf_session_store=$RALF_SESSION_STORE" >> "$CONFIG_FILE"
+echo "xdms_hostname=$XDMS_HOSTNAME" >> "$CONFIG_FILE"
+echo "chronos_hostname=$CHRONOS_HOSTNAME" >> "$CONFIG_FILE"
+echo "cassandra_hostname=$CASSANDRA_HOSTNAME" >> "$CONFIG_FILE"
+
+echo >> "$CONFIG_FILE"
+echo "# Email server configuration" >> "$CONFIG_FILE"
+echo "smtp_smarthost=$SMTP_HOSTNAME" >> "$CONFIG_FILE"
+echo "smtp_username=$SMTP_USERNAME" >> "$CONFIG_FILE"
+echo "smtp_password=$SMTP_PASSWORD" >> "$CONFIG_FILE"
+echo "email_recovery_sender=clearwater@$ZONE" >> "$CONFIG_FILE"
+
+echo >> "$CONFIG_FILE"
+echo "# I-CSCF/S-CSCF configuration (used by Bono to proxy to Sprout)" >> "$CONFIG_FILE"
+echo "upstream_hostname=scscf.$HOSTNAME" >> "$CONFIG_FILE"
+
+echo >> "$CONFIG_FILE"
+echo "# Keys" >> "$CONFIG_FILE"
+echo "signup_key=$SECRET" >> "$CONFIG_FILE"
+echo "turn_workaround=$SECRET" >> "$CONFIG_FILE"
+echo "ellis_api_key=$SECRET" >> "$CONFIG_FILE"
+echo "ellis_cookie_key=$SECRET" >> "$CONFIG_FILE"
+
+if [ "$REDUCE_CASSANDRA_MEM_USAGE" = True ]; then
+	echo >> "$CONFIG_FILE"
+	echo "# $REDUCE_CASSANDRA_MEM_USAGE" >> "$CONFIG_FILE"
+	echo "reduce_cassandra_mem_usage=Y" >> "$CONFIG_FILE"
+fi
+
+# Copy to other hosts in etcd group
+#yes | aptdcon --hide-terminal --install clearwater-config-manager
+#cw-upload_shared_config

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/scripts/memento/create.sh
----------------------------------------------------------------------
diff --git a/examples/clearwater/scripts/memento/create.sh b/examples/clearwater/scripts/memento/create.sh
new file mode 100644
index 0000000..6894015
--- /dev/null
+++ b/examples/clearwater/scripts/memento/create.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+set -e
+
+yes | aptdcon --hide-terminal --install memento-as memento-nginx

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/scripts/memento/delete.sh
----------------------------------------------------------------------
diff --git a/examples/clearwater/scripts/memento/delete.sh b/examples/clearwater/scripts/memento/delete.sh
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/scripts/ralf/create.sh
----------------------------------------------------------------------
diff --git a/examples/clearwater/scripts/ralf/create.sh b/examples/clearwater/scripts/ralf/create.sh
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/scripts/ralf/delete.sh
----------------------------------------------------------------------
diff --git a/examples/clearwater/scripts/ralf/delete.sh b/examples/clearwater/scripts/ralf/delete.sh
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/scripts/sprout/create.sh
----------------------------------------------------------------------
diff --git a/examples/clearwater/scripts/sprout/create.sh b/examples/clearwater/scripts/sprout/create.sh
new file mode 100644
index 0000000..c8161e7
--- /dev/null
+++ b/examples/clearwater/scripts/sprout/create.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+set -e
+
+yes | aptdcon --hide-terminal --install sprout

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/scripts/sprout/delete.sh
----------------------------------------------------------------------
diff --git a/examples/clearwater/scripts/sprout/delete.sh b/examples/clearwater/scripts/sprout/delete.sh
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/scripts/vellum/create.sh
----------------------------------------------------------------------
diff --git a/examples/clearwater/scripts/vellum/create.sh b/examples/clearwater/scripts/vellum/create.sh
new file mode 100644
index 0000000..98b9d42
--- /dev/null
+++ b/examples/clearwater/scripts/vellum/create.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+set -e
+
+yes | aptdcon --hide-terminal --install vellum
+
+# Memento
+# TODO: see if there is a Memento node
+#yes | aptdcon --hide-terminal --install memento-cassandra

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/scripts/vellum/delete.sh
----------------------------------------------------------------------
diff --git a/examples/clearwater/scripts/vellum/delete.sh b/examples/clearwater/scripts/vellum/delete.sh
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/types/cassandra.yaml
----------------------------------------------------------------------
diff --git a/examples/clearwater/types/cassandra.yaml b/examples/clearwater/types/cassandra.yaml
new file mode 100644
index 0000000..10ad34f
--- /dev/null
+++ b/examples/clearwater/types/cassandra.yaml
@@ -0,0 +1,16 @@
+
+capability_types:
+
+  cassandra.Endpoint:
+    derived_from: tosca.capabilities.Endpoint.Database
+    properties:
+      port: # override
+        type: tosca.datatypes.network.PortDef
+        default: 7000
+
+  cassandra.Endpoint.Thrift:
+    derived_from: tosca.capabilities.Endpoint.Database
+    properties:
+      port: # override
+        type: tosca.datatypes.network.PortDef
+        default: 9160

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/types/clearwater.yaml
----------------------------------------------------------------------
diff --git a/examples/clearwater/types/clearwater.yaml b/examples/clearwater/types/clearwater.yaml
new file mode 100644
index 0000000..7aab82c
--- /dev/null
+++ b/examples/clearwater/types/clearwater.yaml
@@ -0,0 +1,683 @@
+
+imports:
+  - ims.yaml
+  - smtp.yaml
+  - cassandra.yaml
+
+dsl_definitions:
+
+  clearwater_operation_dependencies: &CLEARWATER_OPERATION_DEPENDENCIES
+    - "ssh.user > { get_property: [ HOST, host, ssh.user ] }"
+    - "ssh.password > { get_property: [ HOST, host, ssh.password ] }"
+    - "ssh.address > { get_attribute: [ HOST, public_address ] }"
+    - "ssh.use_sudo > true"
+
+policy_types:
+
+  clearwater.Configuration:
+    derived_from: tosca.policies.Root
+    properties:
+      zone:
+        description: >-
+          The domain name for SIP addresses, for example if its "example.com" then a SIP address
+          could be "6505550243@example.com".
+        type: string
+      geographically_redundant:
+        description: >-
+          Enable a geographically redundant deployment.
+        
+          See: http://clearwater.readthedocs.io/en/stable/Geographic_redundancy.html
+        type: boolean
+        default: false
+      site_name:
+        description: >-
+          Used by geographically redundant deployments.
+        type: string
+      secret:
+        description: >-
+          Used for registration via Ellis.
+        type: string
+
+capability_types:
+
+  clearwater.Container:
+    description: >-
+      Clearwater container capability.
+    derived_from: tosca.capabilities.Container
+    properties:
+      ssh.user:
+        type: string
+      ssh.password:
+        type: string
+      max_log_directory_size:
+        type: scalar-unit.size
+        default: 0 B # 0 means no max size
+      reduce_cassandra_mem_usage:
+        type: boolean
+        default: false
+
+  # http://clearwater.readthedocs.io/en/stable/Clearwater_IP_Port_Usage.html
+
+  # SIP endpoints
+
+  clearwater.Endpoint.SIP.Upstream:
+    derived_from: tosca.capabilities.Endpoint
+    properties:
+      protocol: # override
+        type: string
+        default: sip
+      port: # override
+        type: tosca.datatypes.network.PortDef
+        default: 5052
+
+  clearwater.Endpoint.SIP.Upstream.Secure:
+    derived_from: tosca.capabilities.Endpoint
+    properties:
+      protocol: # override
+        type: string
+        default: sip
+      port: # override
+        type: tosca.datatypes.network.PortDef
+        default: 5054
+      secure: # override
+        type: boolean
+        default: true
+
+  clearwater.Endpoint.SIP.Proxy:
+    derived_from: tosca.capabilities.Endpoint
+    properties:
+      protocol: # override
+        type: string
+        default: sip
+      port: # override
+        type: tosca.datatypes.network.PortDef
+        default: 5058
+
+  clearwater.Endpoint.SIP.Public:
+    derived_from: tosca.capabilities.Endpoint.Public
+    properties:
+      protocol: # override
+        type: string
+        default: sip
+      port: # override
+        type: tosca.datatypes.network.PortDef
+        default: 5060
+
+  clearwater.Endpoint.SIP.Public.Secure:
+    derived_from: tosca.capabilities.Endpoint.Public
+    properties:
+      protocol: # override
+        type: string
+        default: sip
+      port: # override
+        type: tosca.datatypes.network.PortDef
+        default: 5062
+      secure: # override
+        type: boolean
+        default: true
+
+  # STUN endpoints
+
+  clearwater.Endpoint.STUN:
+    derived_from: tosca.capabilities.Endpoint
+    properties:
+      protocol: # override
+        type: string
+        default: stun
+      port: # override
+        type: tosca.datatypes.network.PortDef
+        default: 3478
+
+  # Diameter endpoints
+
+  clearwater.Endpoint.Diameter.HSS:
+    description: >-
+      In shared_config: hs_listen_port
+    derived_from: tosca.capabilities.Endpoint
+    properties:
+      protocol: # override
+        type: string
+        default: diameter
+      port: # override
+        type: tosca.datatypes.network.PortDef
+        default: 3868
+
+  clearwater.Endpoint.Diameter.CTF:
+    description: >-
+      In shared_config: ralf_listen_port
+    derived_from: tosca.capabilities.Endpoint
+    properties:
+      protocol: # override
+        type: string
+        default: diameter
+      port: # override
+        type: tosca.datatypes.network.PortDef
+        default: 3869
+
+  # Management endpoints
+
+  clearwater.Endpoint.Management.Homer:
+    derived_from: ims.interfaces.HTTP
+    properties:
+      port: # override
+        type: tosca.datatypes.network.PortDef
+        default: 7888
+
+  clearwater.Endpoint.Management.Homestead:
+    derived_from: ims.interfaces.HTTP
+    properties:
+      port: # override
+        type: tosca.datatypes.network.PortDef
+        default: 8888
+
+  clearwater.Endpoint.Management.Homestead.Provisioning:
+    description: >-
+      In shared_config: homestead_provisioning_port
+    derived_from: ims.interfaces.HTTP
+    properties:
+      port: # override
+        type: tosca.datatypes.network.PortDef
+        default: 8889
+
+  clearwater.Endpoint.Management.Sprout:
+    derived_from: ims.interfaces.HTTP
+    properties:
+      port: # override
+        type: tosca.datatypes.network.PortDef
+        default: 9886
+
+  clearwater.Endpoint.Management.Ralf:
+    derived_from: ims.interfaces.HTTP
+    properties:
+      port: # override
+        type: tosca.datatypes.network.PortDef
+        default: 9888 # note: some documentation shows 10888
+
+  # Web endpoints
+
+  clearwater.Endpoint.Public.Web:
+    derived_from: tosca.capabilities.Endpoint.Public
+    properties:
+      protocol: # override
+        type: string
+        default: http
+      port: # override
+        type: tosca.datatypes.network.PortDef
+        default: 80
+      url_path: # override
+        type: string
+        default: /
+
+  clearwater.Endpoint.Public.Web.Secure:
+    derived_from: tosca.capabilities.Endpoint.Public
+    properties:
+      protocol: # override
+        type: string
+        default: https
+      port: # override
+        type: tosca.datatypes.network.PortDef
+        default: 443
+      secure: # override
+        type: boolean
+        default: true
+      url_path: # override
+        type: string
+        default: /        
+
+  # Other endpoints
+
+  clearwater.Endpoint.Chronos:
+    derived_from: tosca.capabilities.Endpoint
+    properties:
+      port: # override
+        type: tosca.datatypes.network.PortDef
+        default: 7253
+
+  clearwater.Endpoint.Memcached:
+    derived_from: tosca.capabilities.Endpoint
+    properties:
+      port: # override
+        type: tosca.datatypes.network.PortDef
+        default: 11211
+
+  clearwater.Endpoint.Astaire:
+    derived_from: tosca.capabilities.Endpoint
+    properties:
+      port: # override
+        type: tosca.datatypes.network.PortDef
+        default: 11311
+
+data_types:
+
+  clearwater.Number:
+    derived_from: string
+    constraints:
+      - pattern: '^\d{10}$'
+
+node_types:
+
+  # http://clearwater.readthedocs.io/en/stable/Clearwater_Architecture.html
+
+  clearwater.SoftwareComponent:
+    description: >-
+      Clearwater software components must be installed in a Clearwater-capable compute node.
+    derived_from: tosca.nodes.SoftwareComponent
+    requirements:
+      - host: # override
+          capability: clearwater.Container
+          node: tosca.nodes.Compute # TODO: we shouldn't need this, see comment in ARIA-174
+          relationship: tosca.relationships.HostedOn
+
+  clearwater.Bono:
+    description: >-
+      Clearwater edge proxy.
+
+      The Bono nodes form a horizontally scalable SIP edge proxy providing both a SIP IMS Gm
+      compliant interface and a WebRTC interface to clients. Client connections are load balanced
+      across the nodes. The Bono node provides the anchor point for the client's connection to the
+      Clearwater system, including support for various NAT traversal mechanisms. A client is
+      therefore anchored to a particular Bono node for the duration of its registration, but can
+      move to another Bono node if the connection or client fails.
+
+      Clients can connect to Bono using SIP/UDP or SIP/TCP. Bono supports any WebRTC client that
+      performs call setup signaling using SIP over WebSocket.
+
+      Alternatively, Clearwater can be deployed with a third party P-CSCF or Session Border
+      Controller implementing P-CSCF. In this case Bono nodes are not required.
+    derived_from: clearwater.SoftwareComponent
+    capabilities:
+      p-cscf: ims.functions.P-CSCF
+      gm: ims.interfaces.Gm
+      sip_endpoint: clearwater.Endpoint.SIP.Public
+      sip_secure_endpoint: clearwater.Endpoint.SIP.Public.Secure
+      sip_proxy: clearwater.Endpoint.SIP.Proxy # open to Sprout
+      stun_endoint: clearwater.Endpoint.STUN
+    requirements:
+      - sip_downstream:
+          capability: clearwater.Endpoint.SIP.Upstream
+          node: tosca.nodes.Root # TODO: we shouldn't need this, see comment in ARIA-174
+          occurrences: [ 0, UNBOUNDED ]       
+      - sip_secure_downstream:
+          capability: clearwater.Endpoint.SIP.Upstream.Secure
+          node: tosca.nodes.Root # TODO: we shouldn't need this, see comment in ARIA-174
+          occurrences: [ 0, UNBOUNDED ]       
+      - ralf: # for billable events
+          capability: clearwater.Endpoint.Management.Ralf
+          node: tosca.nodes.Root # TODO: we shouldn't need this, see comment in ARIA-174
+    interfaces:
+      Standard:
+        type: tosca.interfaces.node.lifecycle.Standard
+        create:
+          implementation:
+            primary: scripts/bono/create.sh
+            dependencies: *CLEARWATER_OPERATION_DEPENDENCIES
+        delete:
+          implementation:
+            primary: scripts/bono/delete.sh
+            dependencies: *CLEARWATER_OPERATION_DEPENDENCIES
+
+  clearwater.Sprout:
+    description: >-
+      Clearwater SIP router.
+
+      The Sprout nodes act as a horizontally scalable, combined SIP registrar and authoritative
+      routing proxy, and handle client authentication and the ISC interface to application servers.
+      The Sprout nodes also contain the in-built MMTEL application server. SIP transactions are load
+      balanced across the Sprout cluster, so there is no long-lived association between a client and
+      a particular Sprout node. Sprout does not store any long-lived data itself and instead uses
+      web service interfaces to Homestead and Homer to retrieve HSS configuration such as
+      authentication data/user profiles and MMTEL service settings APIs to Vellum for storing
+      subscriber registration data and for running timers.
+
+      Sprout is where the bulk of the I-CSCF and S-CSCF function resides, with the remainder
+      provided by Dime (and backed by the long-lived data stores on Vellum).            
+    derived_from: clearwater.SoftwareComponent
+    capabilities:
+      sip_endpoint: clearwater.Endpoint.SIP.Upstream # open to Bono
+      sip_secure_endpoint: clearwater.Endpoint.SIP.Upstream.Secure # open to Bono
+      management_endpoint: clearwater.Endpoint.Management.Sprout
+      memento:
+        type: tosca.capabilities.Container
+        valid_source_types: [ clearwater.Memento ]
+    requirements:
+#      - sip_upstream: # cyclical!
+#          capability: clearwater.Endpoint.SIP.Proxy      
+#          node: tosca.nodes.Root # TODO: we shouldn't need this, see comment in ARIA-174
+#          occurrences: [ 0, UNBOUNDED ]       
+      - homer: # for subscriber profiles
+          capability: clearwater.Endpoint.Management.Homer
+          node: tosca.nodes.Root # TODO: we shouldn't need this, see comment in ARIA-174
+      - ralf: # for billable events
+          capability: clearwater.Endpoint.Management.Ralf
+          node: tosca.nodes.Root # TODO: we shouldn't need this, see comment in ARIA-174
+      - chronos:
+          capability: clearwater.Endpoint.Chronos
+          node: clearwater.Vellum
+      - astaire:
+          capability: clearwater.Endpoint.Astaire
+          node: clearwater.Vellum
+    interfaces:
+      Standard:
+        type: tosca.interfaces.node.lifecycle.Standard
+        create:
+          implementation:
+            primary: scripts/sprout/create.sh
+            dependencies: *CLEARWATER_OPERATION_DEPENDENCIES
+        delete:
+          implementation:
+            primary: scripts/sprout/delete.sh
+            dependencies: *CLEARWATER_OPERATION_DEPENDENCIES
+
+  clearwater.Memento:
+    derived_from: tosca.nodes.Root
+    capabilities:
+      sip-as: ims.functions.SIP-AS
+      web_secure_endpoint: clearwater.Endpoint.Public.Web.Secure
+    requirements:
+      - host:
+          capability: tosca.capabilities.Container
+          node: clearwater.Sprout
+      - cassandra_thrift:
+          capability: cassandra.Endpoint.Thrift
+          node: clearwater.Vellum
+    interfaces:
+      Standard:
+        type: tosca.interfaces.node.lifecycle.Standard
+        create:
+          implementation:
+            primary: scripts/memento/create.sh
+            dependencies: *CLEARWATER_OPERATION_DEPENDENCIES
+        delete:
+          implementation:
+            primary: scripts/memento/delete.sh
+            dependencies: *CLEARWATER_OPERATION_DEPENDENCIES
+
+  clearwater.Dime:
+    description: >-
+      Clearwater Diameter gateway.
+
+      Dime nodes run Clearwater's Homestead and Ralf components.
+    derived_from: clearwater.SoftwareComponent
+    capabilities:
+      host:
+         type: tosca.capabilities.Container
+         valid_source_types: [ clearwater.DimeSoftwareComponent ]
+    interfaces:
+      Standard:
+        type: tosca.interfaces.node.lifecycle.Standard
+        create:
+          implementation:
+            primary: scripts/dime/create.sh
+            dependencies: *CLEARWATER_OPERATION_DEPENDENCIES
+        delete:
+          implementation:
+            primary: scripts/dime/delete.sh
+            dependencies: *CLEARWATER_OPERATION_DEPENDENCIES
+
+  clearwater.DimeSoftwareComponent:
+    description: >-
+      Base type for Dime software components.
+    derived_from: clearwater.SoftwareComponent
+    requirements:
+      - host: # override
+          capability: tosca.capabilities.Container
+          node: clearwater.Dime
+
+  clearwater.Homestead:
+    description: >-
+      Clearwater HSS cache.
+
+      Homestead provides a web services interface to Sprout for retrieving authentication
+      credentials and user profile information. It can either master the data (in which case it
+      exposes a web services provisioning interface) or can pull the data from an IMS compliant HSS
+      over the Cx interface. The Homestead nodes themselves are stateless - the mastered / cached
+      subscriber data is all stored on Vellum (via Cassandra's Thrift interface).
+
+      In the IMS architecture, the HSS mirror function is considered to be part of the I-CSCF and
+      S-CSCF components, so in Clearwater I-CSCF and S-CSCF function is implemented with a
+      combination of Sprout and Dime clusters.
+    derived_from: clearwater.DimeSoftwareComponent
+    capabilities:
+      hss: ims.functions.HSS
+      cx: ims.interfaces.Cx
+      diameter_endpoint: clearwater.Endpoint.Diameter.HSS
+      management_endpoint: clearwater.Endpoint.Management.Homestead # open to Ellis
+      provisioning_management_endpoint: clearwater.Endpoint.Management.Homestead.Provisioning # open to Ellis
+    requirements:
+      - cassandra_thrift:
+          capability: cassandra.Endpoint.Thrift
+          node: clearwater.Vellum
+    interfaces:
+      Standard:
+        type: tosca.interfaces.node.lifecycle.Standard
+        create:
+          implementation:
+            primary: scripts/homestead/create.sh
+            dependencies: *CLEARWATER_OPERATION_DEPENDENCIES
+        delete:
+          implementation:
+            primary: scripts/homestead/delete.sh
+            dependencies: *CLEARWATER_OPERATION_DEPENDENCIES
+
+  clearwater.Ralf:
+    description: >-
+      Clearwater CTF.
+
+      Ralf provides an HTTP API that both Bono and Sprout can use to report billable events that
+      should be passed to the CDF (Charging Data Function) over the Rf billing interface. Ralf is
+      stateless, using Vellum to maintain the long lived session state and run the timers necessary
+      to enable it to conform to the Rf protocol.
+    derived_from: clearwater.DimeSoftwareComponent
+    capabilities:
+      ctf: ims.functions.CTF
+      rf: ims.interfaces.Rf
+      diameter_endpoint: clearwater.Endpoint.Diameter.CTF
+      management_endpoint: clearwater.Endpoint.Management.Ralf # open to Sprout, Bono, Vellum
+    requirements:
+      - chronos:
+          capability: clearwater.Endpoint.Chronos
+          node: clearwater.Vellum
+      - astaire:
+          capability: clearwater.Endpoint.Astaire
+          node: clearwater.Vellum
+    interfaces:
+      Standard:
+        type: tosca.interfaces.node.lifecycle.Standard
+        create:
+          implementation:
+            primary: scripts/ralf/create.sh
+            dependencies: *CLEARWATER_OPERATION_DEPENDENCIES
+        delete:
+          implementation:
+            primary: scripts/ralf/delete.sh
+            dependencies: *CLEARWATER_OPERATION_DEPENDENCIES
+
+  clearwater.Vellum:
+    description: >-
+      Clearwater state store.
+
+      Vellum is used to maintain all long-lived state in the deployment. It does this by running a
+      number of cloud optimized, distributed storage clusters.
+
+      - Cassandra. Cassandra is used by Homestead to store authentication credentials and profile
+      information, and is used by Homer to store MMTEL service settings. Vellum exposes Cassandra's
+      Thrift API.
+
+      - etcd. etcd is used by Vellum itself to share clustering information between Vellum nodes and
+      by other nodes in the deployment for shared configuration.
+
+      - Chronos. Chronos is a distributed, redundant, reliable timer service developed by
+      Clearwater. It is used by Sprout and Ralf nodes to enable timers to be run (e.g. for SIP
+      Registration expiry) without pinning operations to a specific node (one node can set the timer
+      and another act on it when it pops). Chronos is accessed via an HTTP API.
+
+      - Memcached / Astaire. Vellum also runs a Memcached cluster fronted by Astaire. Astaire is a
+      service developed by Clearwater that enabled more rapid scale up and scale down of memcached
+      clusters. This cluster is used by Sprout and Ralf for storing registration and session state.
+    derived_from: clearwater.SoftwareComponent
+    capabilities:
+      cassandra_endpoint: cassandra.Endpoint # open to other Vellum
+      cassandra_thrift_endpoint: cassandra.Endpoint.Thrift # open to Homer, Dime (Homestead), Sprout (Memento)
+      chronos_endpoint: clearwater.Endpoint.Chronos # open to other Vellum, Sprout, Dime (Ralf)
+      memcached_endpoint: clearwater.Endpoint.Memcached # open to other Vellum
+      astaire_endpoint: clearwater.Endpoint.Astaire # open to Sprout, Dime (Ralf)
+#    requirements: # cyclical!
+#      - ralf:
+#          capability: clearwater.Endpoint.Management.Ralf
+#          node: tosca.nodes.Root # TODO: we shouldn't need this, see comment in ARIA-174
+    interfaces:
+      Standard:
+        type: tosca.interfaces.node.lifecycle.Standard
+        create:
+          implementation:
+            primary: scripts/vellum/create.sh
+            dependencies: *CLEARWATER_OPERATION_DEPENDENCIES
+        delete:
+          implementation:
+            primary: scripts/vellum/delete.sh
+            dependencies: *CLEARWATER_OPERATION_DEPENDENCIES
+
+  clearwater.Homer:
+    description: >-
+      Clearwater XDMS.
+
+      Homer is a standard XDMS used to store MMTEL service settings documents for each user of the
+      system. Documents are created, read, updated and deleted using a standard XCAP interface. As
+      with Homestead, the Homer nodes use Vellum as the data store for all long lived data.
+    derived_from: clearwater.SoftwareComponent
+    capabilities:
+      xdms: ims.functions.XDMS
+      management_endpoint: clearwater.Endpoint.Management.Homer # open to Sprout, Ellis
+    requirements:
+      - cassandra_thrift:
+          capability: cassandra.Endpoint.Thrift
+          node: clearwater.Vellum
+    interfaces:
+      Standard:
+        type: tosca.interfaces.node.lifecycle.Standard
+        create:
+          implementation:
+            primary: scripts/homer/create.sh
+            dependencies: *CLEARWATER_OPERATION_DEPENDENCIES
+        delete:
+          implementation:
+            primary: scripts/homer/delete.sh
+            dependencies: *CLEARWATER_OPERATION_DEPENDENCIES
+
+  clearwater.Ellis:
+    description: >-
+      Ellis is a sample provisioning portal providing self sign-up, password management, line
+      management and control of MMTEL service settings. It is not intended to be a part of
+      production Clearwater deployments (it is not easy to horizontally scale because of the MySQL
+      underpinnings for one thing) but to make the system easy to use out of the box.
+    derived_from: clearwater.SoftwareComponent
+    properties:
+      provision_numbers_start:
+        type: clearwater.Number
+        default: '6505550000'
+      provision_numbers_count:
+        type: integer
+        default: 0 # 0 means do not provision numbers
+        constraints:
+          - greater_or_equal: 0
+    capabilities:
+      web_endpoint: clearwater.Endpoint.Public.Web
+      web_secure_endpoint: clearwater.Endpoint.Public.Web.Secure
+    requirements:
+      - homer: # for subscriber profiles
+          capability: clearwater.Endpoint.Management.Homer
+          node: tosca.nodes.Root # TODO: we shouldn't need this, see comment in ARIA-174
+      - homestead: # for subscriber authentication
+          capability: clearwater.Endpoint.Management.Homestead
+          node: tosca.nodes.Root # TODO: we shouldn't need this, see comment in ARIA-174
+      - homestead_provisioning:
+          capability: clearwater.Endpoint.Management.Homestead.Provisioning
+          node: tosca.nodes.Root # TODO: we shouldn't need this, see comment in ARIA-174
+      - ralf: # TODO: really?
+          capability: clearwater.Endpoint.Management.Ralf
+          node: tosca.nodes.Root # TODO: we shouldn't need this, see comment in ARIA-174
+    interfaces:
+      Standard:
+        type: tosca.interfaces.node.lifecycle.Standard
+        create:
+          implementation:
+            primary: scripts/ellis/create.sh
+            dependencies: *CLEARWATER_OPERATION_DEPENDENCIES
+        configure:
+          implementation:
+            primary: scripts/ellis/configure.sh
+            dependencies: *CLEARWATER_OPERATION_DEPENDENCIES
+        delete:
+          implementation:
+            primary: scripts/ellis/delete.sh
+            dependencies: *CLEARWATER_OPERATION_DEPENDENCIES
+
+  clearwater.I-CSCF:
+    description: >-
+      Clearwater I-CSCF.
+
+      Logical node encompassing Sprout and Homestead. Required only if you need to expose the I-CSCF
+      function.
+    derived_from: tosca.nodes.Root
+    capabilities:
+      i-cscf: ims.functions.I-CSCF
+    requirements:
+      - sprout:
+          capability: tosca.capabilities.Node
+          node: clearwater.Sprout
+      - homestead:
+          capability: tosca.capabilities.Node
+          node: clearwater.Homestead
+
+  clearwater.S-CSCF:
+    description: >-
+      Clearwater S-CSCF.
+
+      Logical node encompassing Sprout and Homestead. Required only if you need to expose the S-CSCF
+      function.
+    derived_from: tosca.nodes.Root
+    capabilities:
+      s-cscf: ims.functions.S-CSCF
+    requirements:
+      - sprout:
+          capability: tosca.capabilities.Node
+          node: clearwater.Sprout
+      - homestead:
+          capability: tosca.capabilities.Node
+          node: clearwater.Homestead
+
+  clearwater.Host:
+    description: >-
+      Default Clearwater host.
+
+      Note that any node can function as a Clearwater host as long as it has a clearwater.Container
+      capability.
+    derived_from: tosca.nodes.Compute
+    interfaces:
+      Standard:
+        type: tosca.interfaces.node.lifecycle.Standard
+        configure:
+          implementation:
+            primary: scripts/host/configure.sh
+            dependencies: *CLEARWATER_OPERATION_DEPENDENCIES
+    capabilities:
+      host: # override
+        type: clearwater.Container
+        valid_source_types: [ tosca.nodes.SoftwareComponent ]
+      os: # override
+        type: tosca.capabilities.OperatingSystem
+        properties:
+          architecture:
+            type: string
+            default: x86_64
+          type:
+            type: string
+            default: linux
+          distribution:
+            type: string
+            default: ubuntu
+          version:
+            type: version
+            default: 14.04
+      smtp:
+        type: smtp.SMTP

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/types/ims.yaml
----------------------------------------------------------------------
diff --git a/examples/clearwater/types/ims.yaml b/examples/clearwater/types/ims.yaml
new file mode 100644
index 0000000..6a64e6e
--- /dev/null
+++ b/examples/clearwater/types/ims.yaml
@@ -0,0 +1,431 @@
+capability_types:
+
+  # https://en.wikipedia.org/wiki/IP_Multimedia_Subsystem#Core_network
+
+  ims.functions.Root:
+    derived_from: tosca.capabilities.Root
+
+  ims.functions.CTF: # not mentioned in Wikipedia
+    description: >-
+      Charging Trigger Function.
+    derived_from: ims.functions.Root
+
+  ims.functions.XDMS: # not mentioned in Wikipedia
+    description: >-
+      XML Document Management Server
+    derived_from: ims.functions.Root
+
+  ims.functions.HSS:
+    description: >-
+      The home subscriber server (HSS), or user profile server function (UPSF), is a master user
+      database that supports the IMS network entities that actually handle calls. It contains the
+      subscription-related information (subscriber profiles), performs authentication and
+      authorization of the user, and can provide information about the subscriber's location and IP
+      information. It is similar to the GSM home location register (HLR) and Authentication centre
+      (AuC).
+
+      A subscriber location function (SLF) is needed to map user addresses when multiple HSSs are
+      used.
+    derived_from: ims.functions.Root
+
+  ims.functions.CSCF:
+    description: >-
+      Several roles of SIP servers or proxies, collectively called Call Session Control Function
+      (CSCF), are used to process SIP signalling packets in the IMS.
+    derived_from: ims.functions.Root
+
+  ims.functions.P-CSCF:
+    description: >-
+      A Proxy-CSCF (P-CSCF) is a SIP proxy that is the first point of contact for the IMS terminal.
+      It can be located either in the visited network (in full IMS networks) or in the home network
+      (when the visited network is not IMS compliant yet). Some networks may use a Session Border
+      Controller (SBC) for this function. The P-CSCF is at its core a specialized SBC for the
+      User–network interface which not only protects the network, but also the IMS terminal. The use
+      of an additional SBC between the IMS terminal and the P-CSCF is unnecessary and infeasible due
+      to the signaling being encrypted on this leg. The terminal discovers its P-CSCF with either
+      DHCP, or it may be configured (e.g. during initial provisioning or via a 3GPP IMS Management
+      Object (MO)) or in the ISIM or assigned in the PDP Context (in General Packet Radio Service
+      (GPRS)).
+    derived_from: ims.functions.CSCF
+
+  ims.functions.I-CSCF:
+    description: >-
+      An Interrogating-CSCF (I-CSCF) is another SIP function located at the edge of an
+      administrative domain. Its IP address is published in the Domain Name System (DNS) of the
+      domain (using NAPTR and SRV type of DNS records), so that remote servers can find it, and use
+      it as a forwarding point (e.g., registering) for SIP packets to this domain.
+    derived_from: ims.functions.CSCF
+
+  ims.functions.S-CSCF:
+    description: >-
+      A Serving-CSCF (S-CSCF) is the central node of the signalling plane. It is a SIP server, but
+      performs session control too. It is always located in the home network. It uses Diameter Cx
+      and Dx interfaces to the HSS to download user profiles and upload user-to-S-CSCF associations
+      (the user profile is only cached locally for processing reasons only and is not changed). All
+      necessary subscriber profile information is loaded from the HSS.
+    derived_from: ims.functions.CSCF
+
+  ims.functions.AS:
+    description: >-
+      SIP Application servers (AS) host and execute services, and interface with the S-CSCF using
+      SIP. An example of an application server that is being developed in 3GPP is the Voice call
+      continuity Function (VCC Server). Depending on the actual service, the AS can operate in SIP
+      proxy mode, SIP UA (user agent) mode or SIP B2BUA mode. An AS can be located in the home
+      network or in an external third-party network. If located in the home network, it can query
+      the HSS with the Diameter Sh or Si interfaces (for a SIP-AS).
+    derived_from: ims.functions.Root
+
+  ims.functions.SIP-AS:
+    description: >-
+      Host and execute IMS specific services.
+    derived_from: ims.functions.AS
+
+  ims.functions.IM-SSF:
+    description: >-
+      IP Multimedia Service Switching Function. Interfaces SIP to CAP to communicate with CAMEL
+      Application Servers.
+    derived_from: ims.functions.AS
+
+  ims.functions.OSA-SCS:
+    description: >-
+      OSA service capability server. Interfaces SIP to the OSA framework.
+    derived_from: ims.functions.AS
+
+  ims.functions.AS-ILCM:
+    description: >-
+      The AS-ILCM (Application Server - Incoming Leg Control Model) stores transaction state, and
+      may optionally store session state depending on the specific service being executed. The
+      AS-ILCM interfaces to the S-CSCF (ILCM) for an incoming leg. Application Logic provides the
+      service(s) and interacts between the AS-ILCM and AS-OLCM.
+    derived_from: ims.functions.AS
+
+  ims.functions.AS-OLCM:
+    description: >-
+      The AS-OLCM (Application Server - Outgoing Leg Control Model) stores transaction state, and
+      may optionally store session state depending on the specific service being executed. The
+      AS-OLCM interfaces to the S-CSCF (OLCM) for an outgoing leg. Application Logic provides the
+      service(s) and interacts between the AS-ILCM and AS-OLCM.
+    derived_from: ims.functions.AS
+
+  ims.functions.MRF:
+    description: >-
+      The Media Resource Function (MRF) provides media related functions such as media manipulation
+      (e.g. voice stream mixing) and playing of tones and announcements.
+
+      Each MRF is further divided into a media resource function controller (MRFC) and a media
+      resource function processor (MRFP).
+    derived_from: ims.functions.Root
+
+  ims.functions.MRFC:
+    description: >-
+      The MRFC is a signalling plane node that interprets information coming from an AS and S-CSCF
+      to control the MRFP.
+    derived_from: ims.functions.Root
+
+  ims.functions.MRFP:
+    description: >-
+      The MRFP is a media plane node used to mix, source or process media streams. It can also
+      manage access right to shared resources.
+    derived_from: ims.functions.Root
+
+  ims.functions.MRB:
+    description: >-
+      The Media Resource Broker (MRB) is a functional entity that is responsible for both collection
+      of appropriate published MRF information and supplying of appropriate MRF information to
+      consuming entities such as the AS. MRB can be used in two modes:
+      * Query mode: AS queries the MRB for media and sets up the call using the response of MRB
+      * In-Line Mode: AS sends a SIP INVITE to the MRB. The MRB sets up the call
+    derived_from: ims.functions.Root
+
+  ims.functions.BGCF:
+    description: >-
+      A Breakout Gateway Control Function (BGCF) is a SIP proxy which processes requests for routing
+      from an S-CSCF when the S-CSCF has determined that the session cannot be routed using DNS or
+      ENUM/DNS. It includes routing functionality based on telephone numbers.
+    derived_from: ims.functions.Root
+
+  ims.functions.PTSNGateway:
+    description: >-
+      A PSTN/CS gateway interfaces with PSTN circuit switched (CS) networks. For signalling, CS
+      networks use ISDN User Part (ISUP) (or BICC) over Message Transfer Part (MTP), while IMS uses
+      SIP over IP. For media, CS networks use Pulse-code modulation (PCM), while IMS uses Real-time
+      Transport Protocol (RTP).
+    derived_from: ims.functions.Root
+
+  ims.functions.SGW:
+    description: >-
+      A signalling gateway (SGW) interfaces with the signalling plane of the CS. It transforms lower
+      layer protocols as Stream Control Transmission Protocol (SCTP, an IP protocol) into Message
+      Transfer Part (MTP, an Signalling System 7 (SS7) protocol), to pass ISDN User Part (ISUP) from
+      the MGCF to the CS network.
+    derived_from: ims.functions.PTSNGateway
+
+  ims.functions.MGCF:
+    description: >-
+      A media gateway controller function (MGCF) is a SIP endpoint that does call control protocol
+      conversion between SIP and ISUP/BICC and interfaces with the SGW over SCTP. It also controls
+      the resources in a Media Gateway (MGW) across an H.248 interface.
+    derived_from: ims.functions.PTSNGateway
+
+  ims.functions.MGW:
+    description: >-
+      A media gateway (MGW) interfaces with the media plane of the CS network, by converting between
+      RTP and PCM. It can also transcode when the codecs don't match (e.g., IMS might use AMR, PSTN
+      might use G.711).
+    derived_from: ims.functions.PTSNGateway
+
+  # https://en.wikipedia.org/wiki/IP_Multimedia_Subsystem#Interfaces_description
+
+  ims.interfaces.Diameter:
+    derived_from: tosca.capabilities.Endpoint
+
+  ims.interfaces.TCP:
+    derived_from: tosca.capabilities.Endpoint
+
+  ims.interfaces.SIP:
+    derived_from: tosca.capabilities.Endpoint
+    properties:
+      protocol: # override
+        type: string
+        default: sip
+
+  ims.interfaces.RTP:
+    derived_from: tosca.capabilities.Endpoint
+    properties:
+      protocol: # override
+        type: string
+        default: rtp
+
+  ims.interfaces.H248:
+    derived_from: tosca.capabilities.Endpoint
+    properties:
+      protocol: # override
+        type: string
+        default: h248
+
+  ims.interfaces.HTTP:
+    derived_from: tosca.capabilities.Endpoint
+    properties:
+      protocol: # override
+        type: string
+        default: http
+
+  ims.interfaces.MAP:
+    derived_from: tosca.capabilities.Endpoint
+    properties:
+      protocol: # override
+        type: string
+        default: map
+
+  ims.interfaces.Cr:
+    description: >-
+      Used by MRFC to fetch documents (e.g. scripts, announcement files, and other resources) from
+      an AS. Also used for media control related commands.
+    derived_from: ims.interfaces.TCP
+
+  ims.interfaces.Cx:
+    description: >-
+      Used to send subscriber data to the S-CSCF; including filter criteria and their priority. Also
+      used to furnish CDF and/or OCF addresses.
+    derived_from: ims.interfaces.Diameter
+
+  ims.interfaces.Dh:
+    description: >-
+      Used by AS to find the HSS holding the user profile information in a multi-HSS environment.
+      DH_SLF_QUERY indicates an IMPU and DX_SLF_RESP return the HSS name.
+    derived_from: ims.interfaces.Diameter
+
+  ims.interfaces.Dx:
+    description: >-
+      Used by I-CSCF or S-CSCF to find a correct HSS in a multi-HSS environment. DX_SLF_QUERY
+      indicates an IMPU and DX_SLF_RESP return the HSS name.
+    derived_from: ims.interfaces.Diameter
+
+  ims.interfaces.Gm:
+    description: >-
+      Used to exchange messages between SIP user equipment (UE) or Voip gateway and P-CSCF.
+    derived_from: ims.interfaces.SIP
+
+  ims.interfaces.Go:
+    description: >-
+      Allows operators to control QoS in a user plane and exchange charging correlation
+      information between IMS and GPRS network.
+    derived_from: ims.interfaces.Diameter
+
+  ims.interfaces.Gq:
+    description: >-
+      Used to exchange policy decisions-related information between P-CSCF and PDF.
+    derived_from: ims.interfaces.Diameter
+
+  ims.interfaces.Gx:
+    description: >-
+      Used to exchange policy decisions-related information between PCEF and PCRF.
+    derived_from: ims.interfaces.Diameter
+
+  ims.interfaces.Gy:
+    description: >-
+      Used for online flow-based bearer charging. Functionally equivalent to Ro interface.
+    derived_from: ims.interfaces.Diameter
+
+  ims.interfaces.ISC:
+    description: >-
+      Reference point between S-CSCF and AS. Main functions are to:
+      * Notify the AS of the registered IMPU, registration state and UE capabilities
+      * Supply the AS with information to allow it to execute multiple services
+      * Convey charging function addresses
+    derived_from: ims.interfaces.SIP
+
+  ims.interfaces.Ici:
+    description: >-
+      Used to exchange messages between an IBCF and another IBCF belonging to a different IMS
+      network.
+    derived_from: ims.interfaces.SIP
+
+  ims.interfaces.Izi:
+    description: >-
+      Used to forward media streams from a TrGW to another TrGW belonging to a different IMS
+      network.
+    derived_from: ims.interfaces.RTP
+
+  ims.interfaces.Ma:
+    description: >-
+      Main functions are to:
+      * Forward SIP requests which are destined to a public service identity hosted by the AS
+      * Originate a session on behalf of a user or public service identity, if the AS has no
+        knowledge of a S-CSCF assigned to that user or public service identity
+      * Convey charging function addresses
+    derived_from: ims.interfaces.SIP
+
+  ims.interfaces.Mg:
+    description: >-
+      ISUP signalling to SIP signalling and forwards SIP signalling to I-CSCF.
+    derived_from: ims.interfaces.SIP
+
+  ims.interfaces.Mi:
+    description: >-
+      Used to exchange messages between S-CSCF and BGCF.
+    derived_from: ims.interfaces.SIP
+
+  ims.interfaces.Mj:
+    description: >-
+      Used for the interworking with the PSTN/CS domain, when the BGCF has determined that a
+      breakout should occur in the same IMS network to send SIP message from BGCF to MGCF.
+    derived_from: ims.interfaces.SIP
+
+  ims.interfaces.Mk:
+    description: >-
+      Used for the interworking with the PSTN/CS domain, when the BGCF has determined that a
+      breakout should occur in another IMS network to send SIP message from BGCF to the BGCF in the
+      other network.
+    derived_from: ims.interfaces.SIP
+
+  ims.interfaces.Mm:
+    description: >-
+      Used for exchanging messages between IMS and external IP networks.
+    derived_from: ims.interfaces.SIP
+
+  ims.interfaces.Mn:
+    description: >-
+      Allows control of user-plane resources.
+    derived_from: ims.interfaces.H248
+
+  ims.interfaces.Mp:
+    description: >-
+      Allows an MRFC to control media stream resources provided by an MRFP.
+    derived_from: ims.interfaces.H248
+
+  ims.interfaces.Mr:
+    description: >-
+      Used to exchange information between S-CSCF and MRFC.
+    derived_from: ims.interfaces.SIP
+
+  ims.interfaces.Mr2:
+    description: >-
+      Used to exchange session controls between AS and MRFC.
+    derived_from: ims.interfaces.SIP
+
+  ims.interfaces.Mw:
+    description: >-
+      Used to exchange messages between CSCFs. AGCF appears as a P-CSCF to the other CSCFs.
+    derived_from: ims.interfaces.SIP
+
+  ims.interfaces.Mx:
+    description: >-
+      Used for the interworking with another IMS network, when the BGCF has determined that a
+      breakout should occur in the other IMS network to send SIP message from BGCF to the IBCF in
+      the other network.
+    derived_from: ims.interfaces.SIP
+
+  ims.interfaces.P1:
+    description: >-
+      Used for call control services by AGCF to control H.248 A-MGW and residential gateways.
+    derived_from: ims.interfaces.H248
+
+  ims.interfaces.P2:
+    description: >-
+      Reference point between AGCF and CSCF.
+    derived_from: ims.interfaces.SIP
+
+  ims.interfaces.Rc:
+    description: >-
+      Used by the AS to request that media resources be assigned to a call when using MRB in-line
+      mode or in query mode.
+    derived_from: ims.interfaces.SIP
+
+  ims.interfaces.Rf:
+    description: >-
+      Used to exchange offline charging information with CDF.
+    derived_from: ims.interfaces.Diameter
+
+  ims.interfaces.Ro:
+    description: >-
+        Used to exchange online charging information with OCF.
+    derived_from: ims.interfaces.Diameter
+
+  ims.interfaces.Rx:
+    description: >-
+      Used to exchange policy and charging related information between P-CSCF and PCRF. Replacement
+      for the Gq reference point.
+    derived_from: ims.interfaces.Diameter
+
+  ims.interfaces.Sh:
+    description: >-
+      Used to exchange User Profile information (e.g., user-related data, group lists,
+      user-service-related information or user location information or charging function addresses
+      (used when the AS has not received the third-party REGISTER for a user)) between an AS (SIP
+      AS or OSA SCS) and HSS. Also allow AS to activate/deactivate filter criteria stored in the HSS
+      on a per-subscriber basis.
+    derived_from: ims.interfaces.Diameter
+
+  ims.interfaces.Si:
+    description: >-
+      Transports CAMEL subscription information, including triggers for use by CAMEL-based
+      application services information.
+    derived_from: ims.interfaces.MAP
+
+  ims.interfaces.Sr:
+    description: >-
+      Used by MRFC to fetch documents (scripts and other resources) from an AS.
+    derived_from: ims.interfaces.HTTP
+
+  ims.interfaces.Ut:
+    description: >-
+      Facilitates the management of subscriber information related to services and settings.
+    derived_from: ims.interfaces.HTTP
+
+  ims.interfaces.Z:
+    description: >-
+      Conversion of POTS services to SIP messages.
+    derived_from: tosca.capabilities.Root
+
+node_types:
+
+  ims.nodes.IMS:
+    derived_from: tosca.nodes.Root
+    capabilities:
+      p-cscf: ims.functions.P-CSCF
+      i-cscf: ims.functions.I-CSCF
+      s-cscf: ims.functions.S-CSCF
+      hss: ims.functions.HSS
+      ctf: ims.functions.CTF
+      xdms: ims.functions.XDMS

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/clearwater/types/smtp.yaml
----------------------------------------------------------------------
diff --git a/examples/clearwater/types/smtp.yaml b/examples/clearwater/types/smtp.yaml
new file mode 100644
index 0000000..b79d9d2
--- /dev/null
+++ b/examples/clearwater/types/smtp.yaml
@@ -0,0 +1,21 @@
+
+capability_types:
+
+  smtp.SMTP:
+    derived_from: tosca.capabilities.Root
+    properties:
+      username:
+        type: string
+      password:
+        type: string
+
+node_types:
+
+  smtp.SMTP:
+    derived_from: tosca.nodes.SoftwareComponent
+    properties:
+      address:
+        type: string
+    capabilities:
+      smtp:
+        type: smtp.SMTP

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/hello-world/hello-world.yaml
----------------------------------------------------------------------
diff --git a/examples/hello-world/hello-world.yaml b/examples/hello-world/hello-world.yaml
new file mode 100644
index 0000000..86e2ad0
--- /dev/null
+++ b/examples/hello-world/hello-world.yaml
@@ -0,0 +1,38 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+node_types:
+
+  WebServer:
+    derived_from: tosca:Root
+    capabilities:
+      host:
+        type: tosca:Container
+
+  WebApp:
+    derived_from: tosca:WebApplication
+    properties:
+      port:
+        type: integer
+
+topology_template:
+
+  node_templates:
+    web_server:
+      type: WebServer
+
+    web_app:
+      type: WebApp
+      properties:
+        port: 9090
+      requirements:
+        - host: web_server
+      interfaces:
+        Standard:
+          configure: scripts/configure.sh
+          start: scripts/start.sh
+          stop: scripts/stop.sh
+
+  outputs:
+    port:
+      type: integer
+      value: { get_property: [ web_app, port ] }

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/hello-world/helloworld.yaml
----------------------------------------------------------------------
diff --git a/examples/hello-world/helloworld.yaml b/examples/hello-world/helloworld.yaml
deleted file mode 100644
index 2fdc4d4..0000000
--- a/examples/hello-world/helloworld.yaml
+++ /dev/null
@@ -1,38 +0,0 @@
-tosca_definitions_version: tosca_simple_yaml_1_0
-
-node_types:
-
-  WebServer:
-    derived_from: tosca:Root
-    capabilities:
-      host:
-        type: tosca.capabilities.Container
-
-  WebApp:
-    derived_from: tosca.nodes.WebApplication
-    properties:
-      port:
-        type: integer
-
-topology_template:
-
-  node_templates:
-    web_server:
-      type: WebServer
-
-    web_app:
-      type: WebApp
-      properties:
-        port: 9090
-      requirements:
-        - host: web_server
-      interfaces:
-        Standard:
-          configure: scripts/configure.sh
-          start: scripts/start.sh
-          stop: scripts/stop.sh
-
-  outputs:
-    port:
-      type: integer
-      value: { get_property: [ web_app, port ] }

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/tosca-simple-1.0/use-cases/block-storage-1/block-storage-1.yaml
----------------------------------------------------------------------
diff --git a/examples/tosca-simple-1.0/use-cases/block-storage-1/block-storage-1.yaml b/examples/tosca-simple-1.0/use-cases/block-storage-1/block-storage-1.yaml
index b912fb2..8b3bab3 100644
--- a/examples/tosca-simple-1.0/use-cases/block-storage-1/block-storage-1.yaml
+++ b/examples/tosca-simple-1.0/use-cases/block-storage-1/block-storage-1.yaml
@@ -24,7 +24,7 @@ topology_template:
     storage_snapshot_id:
       type: string
       description: >-
-        Optional identifier for an existing snapshot to use when creating storage.    
+        Optional identifier for an existing snapshot to use when creating storage.
     storage_location:
       type: string
       description: Block storage mount point (filesystem path).
@@ -42,8 +42,8 @@ topology_template:
         os:
           properties:
             architecture: x86_64
-            type: linux 
-            distribution: fedora 
+            type: linux
+            distribution: fedora
             version: 18.0
       requirements:
         - local_storage:

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/tosca-simple-1.0/use-cases/block-storage-2/block-storage-2.yaml
----------------------------------------------------------------------
diff --git a/examples/tosca-simple-1.0/use-cases/block-storage-2/block-storage-2.yaml b/examples/tosca-simple-1.0/use-cases/block-storage-2/block-storage-2.yaml
index ac475cf..9a2c0b0 100644
--- a/examples/tosca-simple-1.0/use-cases/block-storage-2/block-storage-2.yaml
+++ b/examples/tosca-simple-1.0/use-cases/block-storage-2/block-storage-2.yaml
@@ -29,7 +29,7 @@ topology_template:
     storage_snapshot_id:
       type: string
       description: >-
-        Optional identifier for an existing snapshot to use when creating storage.    
+        Optional identifier for an existing snapshot to use when creating storage.
     storage_location:
       type: string
       description: Block storage mount point (filesystem path).
@@ -47,8 +47,8 @@ topology_template:
         os:
           properties:
             architecture: x86_64
-            type: Linux 
-            distribution: Fedora 
+            type: Linux
+            distribution: Fedora
             version: 18.0
       requirements:
         - local_storage:

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/tosca-simple-1.0/use-cases/block-storage-3/block-storage-3.yaml
----------------------------------------------------------------------
diff --git a/examples/tosca-simple-1.0/use-cases/block-storage-3/block-storage-3.yaml b/examples/tosca-simple-1.0/use-cases/block-storage-3/block-storage-3.yaml
index c3f183e..0b09b34 100644
--- a/examples/tosca-simple-1.0/use-cases/block-storage-3/block-storage-3.yaml
+++ b/examples/tosca-simple-1.0/use-cases/block-storage-3/block-storage-3.yaml
@@ -38,8 +38,8 @@ topology_template:
         os:
           properties:
             architecture: x86_64
-            type: Linux 
-            distribution: Fedora 
+            type: Linux
+            distribution: Fedora
             version: 18.0
       requirements:
         - local_storage:

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/tosca-simple-1.0/use-cases/block-storage-4/block-storage-4.yaml
----------------------------------------------------------------------
diff --git a/examples/tosca-simple-1.0/use-cases/block-storage-4/block-storage-4.yaml b/examples/tosca-simple-1.0/use-cases/block-storage-4/block-storage-4.yaml
index e2bdb9f..d3c2614 100644
--- a/examples/tosca-simple-1.0/use-cases/block-storage-4/block-storage-4.yaml
+++ b/examples/tosca-simple-1.0/use-cases/block-storage-4/block-storage-4.yaml
@@ -33,7 +33,7 @@ topology_template:
     storage_snapshot_id:
       type: string
       description: >-
-        Optional identifier for an existing snapshot to use when creating storage.    
+        Optional identifier for an existing snapshot to use when creating storage.
 
   node_templates:
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/tosca-simple-1.0/use-cases/non-normative-types.yaml
----------------------------------------------------------------------
diff --git a/examples/tosca-simple-1.0/use-cases/non-normative-types.yaml b/examples/tosca-simple-1.0/use-cases/non-normative-types.yaml
index 24f22a3..da89dcb 100644
--- a/examples/tosca-simple-1.0/use-cases/non-normative-types.yaml
+++ b/examples/tosca-simple-1.0/use-cases/non-normative-types.yaml
@@ -50,7 +50,7 @@ capability_types:
         required: false
       publish_ports:
         description: >-
-          List of ports mappings from source (Docker container) to target (host) ports to publish. 
+          List of ports mappings from source (Docker container) to target (host) ports to publish.
         type: list
         entry_schema: PortSpec
         required: false
@@ -118,7 +118,7 @@ node_types:
       # Further constrain the 'host' capability to only allow MySQL databases
       host:
         type: tosca.capabilities.Container # ARIA NOTE: missing in spec
-        valid_source_types: [ tosca.nodes.Database.MySQL ] 
+        valid_source_types: [ tosca.nodes.Database.MySQL ]
 
   tosca.nodes.WebServer.Apache:
     _extensions:
@@ -143,7 +143,7 @@ node_types:
         required: false # ARIA NOTE: missing in spec
     requirements:
       - database_endpoint:
-          capability: tosca.capabilities.Endpoint.Database  
+          capability: tosca.capabilities.Endpoint.Database
           node: tosca.nodes.Database
           relationship: tosca.relationships.ConnectsTo
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/examples/tosca-simple-1.0/use-cases/webserver-dbms-1/webserver-dbms-1.yaml
----------------------------------------------------------------------
diff --git a/examples/tosca-simple-1.0/use-cases/webserver-dbms-1/webserver-dbms-1.yaml b/examples/tosca-simple-1.0/use-cases/webserver-dbms-1/webserver-dbms-1.yaml
index faf109d..daa24df 100644
--- a/examples/tosca-simple-1.0/use-cases/webserver-dbms-1/webserver-dbms-1.yaml
+++ b/examples/tosca-simple-1.0/use-cases/webserver-dbms-1/webserver-dbms-1.yaml
@@ -51,11 +51,11 @@ topology_template:
         Standard:
           create: wordpress_install.sh
           configure:
-            implementation: wordpress_configure.sh           
+            implementation: wordpress_configure.sh
             inputs:
               wp_db_name: { get_property: [ mysql_database, name ] }
               wp_db_user: { get_property: [ mysql_database, user ] }
-              wp_db_password: { get_property: [ mysql_database, password ] }  
+              wp_db_password: { get_property: [ mysql_database, password ] }
               # In my own template, find requirement/capability, find port property
               wp_db_port: { get_property: [ SELF, database_endpoint, port ] }
 
@@ -85,7 +85,7 @@ topology_template:
         - host: server
       interfaces:
         Standard:
-          # ARIA NOTE: not declared in spec              
+          # ARIA NOTE: not declared in spec
           #inputs:
           #  db_root_password: { get_property: [ mysql_dbms, root_password ] }
           create: mysql_dbms_install.sh
@@ -112,8 +112,8 @@ topology_template:
         os:
           properties:
             architecture: x86_64
-            type: linux 
-            distribution: fedora 
+            type: linux
+            distribution: fedora
             version: 17.0
 
   outputs:

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/artifacts.yaml
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/artifacts.yaml b/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/artifacts.yaml
index cfb0df5..945622f 100644
--- a/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/artifacts.yaml
+++ b/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/artifacts.yaml
@@ -24,7 +24,7 @@ artifact_types:
       specification_url: 'http://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html#DEFN_TYPE_ARTIFACTS_ROOT'
     description: >-
       This is the default (root) TOSCA Artifact Type definition that all other TOSCA base Artifact Types derive from.
-  
+
   tosca.artifacts.File:
     _extensions:
       shorthand_name: File
@@ -34,11 +34,11 @@ artifact_types:
     description: >-
       This artifact type is used when an artifact definition needs to have its associated file simply treated as a file and no special handling/handlers are invoked (i.e., it is not treated as either an implementation or deployment artifact type).
     derived_from: tosca.artifacts.Root
-  
+
   #
   # Deployments
   #
-  
+
   tosca.artifacts.Deployment:
     _extensions:
       shorthand_name: Deployment # ARIA NOTE: omitted in the spec
@@ -51,7 +51,7 @@ artifact_types:
       represents a binary packaging of an application or service that is used to install/create or deploy it as part of a node's
       lifecycle.
     derived_from: tosca.artifacts.Root
-    
+
   tosca.artifacts.Deployment.Image:
     _extensions:
       shorthand_name: Deployment.Image
@@ -64,7 +64,7 @@ artifact_types:
       (whether real or virtual) whose contents are typically already installed and pre-configured (i.e., "stateful") and prepared
       to be run on a known target container.
     derived_from: tosca.artifacts.Deployment
-  
+
   tosca.artifacts.Deployment.Image.VM:
     _extensions:
       shorthand_name: Deployment.VM # ARIA NOTE: omitted in the spec
@@ -78,11 +78,11 @@ artifact_types:
       with any configurations and can be run on another machine using a hypervisor which virtualizes typical server (i.e.,
       hardware) resources.
     derived_from: tosca.artifacts.Deployment
-  
+
   #
   # Implementations
   #
-  
+
   tosca.artifacts.Implementation:
     _extensions:
       shorthand_name: Implementation # ARIA NOTE: omitted in the spec
@@ -94,7 +94,7 @@ artifact_types:
       This artifact type represents the parent type for all implementation artifacts in TOSCA. These artifacts are used to
       implement operations of TOSCA interfaces either directly (e.g., scripts) or indirectly (e.g., config. files).
     derived_from: tosca.artifacts.Root
-  
+
   tosca.artifacts.Implementation.Bash:
     _extensions:
       shorthand_name: Implementation.Bash # ARIA NOTE: mistake in spec? shouldn't we have "Implementation." as prefix?
@@ -106,7 +106,7 @@ artifact_types:
     derived_from: tosca.artifacts.Implementation
     mime_type: application/x-sh
     file_ext: [ sh ]
-  
+
   tosca.artifacts.Implementation.Python:
     _extensions:
       shorthand_name: Implementation.Python # ARIA NOTE: mistake in spec? shouldn't we have "Implementation." as prefix?

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/40be3086/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/capabilities.yaml
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/capabilities.yaml b/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/capabilities.yaml
index b705d47..66a4046 100644
--- a/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/capabilities.yaml
+++ b/extensions/aria_extension_tosca/profiles/tosca-simple-1.0/capabilities.yaml
@@ -51,7 +51,7 @@ capability_types:
     derived_from: tosca.capabilities.Root
     properties:
       num_cpus:
-        description: >-    
+        description: >-
           Number of (actual or virtual) CPUs associated with the Compute node.
         type: integer
         constraints:
@@ -239,7 +239,7 @@ capability_types:
       specification_url: 'http://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html#DEFN_TYPE_CAPABILITIES_ENDPOINT_PUBLIC'
     description: >-
       This capability represents a public endpoint which is accessible to the general internet (and its public IP address ranges).
-  
+
       This public endpoint capability also can be used to create a floating (IP) address that the underlying network assigns from a
       pool allocated from the application's underlying public network. This floating address is managed by the underlying network
       such that can be routed an application's private address and remains reliable to internet clients.
@@ -292,14 +292,14 @@ capability_types:
     description: >-
       This is the default TOSCA type that should be used or extended to define a specialized database endpoint capability.
     derived_from: tosca.capabilities.Endpoint
-  
+
   #
   # Network
   #
 
   tosca.capabilities.network.Bindable:
     _extensions:
-      shorthand_name: Bindable # ARIA NOTE: mistake in spec? has "network." as a prefix 
+      shorthand_name: Bindable # ARIA NOTE: mistake in spec? has "network." as a prefix
       type_qualified_name: tosca:Bindable
       specification: tosca-simple-1.0
       specification_section: 5.4.11