ariatosca-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxm...@apache.org
Subject incubator-ariatosca git commit: fixed dumps issues
Date Thu, 27 Jul 2017 15:07:16 GMT
Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-174-Refactor-instantiation-phase ec7b9c970 -> b3724c942


fixed dumps issues


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

Branch: refs/heads/ARIA-174-Refactor-instantiation-phase
Commit: b3724c942d35f2d6e25e6af4fd7dfc6ed54de34e
Parents: ec7b9c9
Author: max-orlov <maxim@gigaspaces.com>
Authored: Thu Jul 27 18:07:11 2017 +0300
Committer: max-orlov <maxim@gigaspaces.com>
Committed: Thu Jul 27 18:07:11 2017 +0300

----------------------------------------------------------------------
 aria/cli/commands/service_templates.py         |   4 +-
 aria/cli/commands/services.py                  |   4 +-
 aria/orchestrator/topology/common.py           |   4 +-
 aria/orchestrator/topology/instance_handler.py | 269 ++++++++++----------
 aria/orchestrator/topology/template_handler.py | 252 +++++++++---------
 aria/orchestrator/topology/topology.py         | 164 ++++++------
 6 files changed, 359 insertions(+), 338 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b3724c94/aria/cli/commands/service_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/service_templates.py b/aria/cli/commands/service_templates.py
index 482170b..608d178 100644
--- a/aria/cli/commands/service_templates.py
+++ b/aria/cli/commands/service_templates.py
@@ -73,9 +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:
-            logger.info(Topology().dump(service_template))
+            console.puts(Topology().dump(service_template))
     elif mode_types:
-        logger.info(Topology().dump_types(service_template=service_template))
+        console.puts(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/b3724c94/aria/cli/commands/services.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/services.py b/aria/cli/commands/services.py
index 3b07866..4890bb7 100644
--- a/aria/cli/commands/services.py
+++ b/aria/cli/commands/services.py
@@ -74,9 +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:
-            logger.info(Topology().dump(service))
+            console.puts(Topology().dump(service))
     elif mode_graph:
-        logger.info(Topology().dump_graph(service))
+        console.puts(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/b3724c94/aria/orchestrator/topology/common.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/topology/common.py b/aria/orchestrator/topology/common.py
index e788b4a..45e9ab0 100644
--- a/aria/orchestrator/topology/common.py
+++ b/aria/orchestrator/topology/common.py
@@ -33,13 +33,13 @@ class _Handler(object):
         for template in templates:
             self._topology.validate(template)
 
-    def dump(self, console):
+    def dump(self, out_stream):
         pass
 
 
 class _TemplateHandlerMixin(_Handler):
 
-    def instantiate(self, instance_cls, **kwargs):
+    def instantiate(self, instance_cls):
         raise NotImplementedError
 
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b3724c94/aria/orchestrator/topology/instance_handler.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/topology/instance_handler.py b/aria/orchestrator/topology/instance_handler.py
index dc204fe..2c32466 100644
--- a/aria/orchestrator/topology/instance_handler.py
+++ b/aria/orchestrator/topology/instance_handler.py
@@ -29,24 +29,25 @@ class Artifact(common._InstanceHandlerMixin):
     def validate(self, **kwargs):
         self._topology.validate(self._model.properties)
 
-    def dump(self, console):
-        console.write(console.node(self._model.name))
-        if self._model.description:
-            console.write(console.meta(self._model.description))
-        with console.indent:
-            console.write('Artifact type: {0}'.format(console.type(self._model.type.name)))
-            console.write('Source path: {0}'.format(
-                console.literal(self._model.source_path)))
-            if self._model.target_path is not None:
-                console.write('Target path: {0}'.format(
-                    console.literal(self._model.target_path)))
-            if self._model.repository_url is not None:
-                console.write('Repository URL: {0}'.format(
-                    console.literal(self._model.repository_url)))
-            if self._model.repository_credential:
-                console.write('Repository credential: {0}'.format(
-                    console.literal(self._model.repository_credential)))
-            self._topology.dump(self._model.properties, console, 'Properties')
+    def dump(self, out_stream):
+        with out_stream.indent():
+            out_stream.write(out_stream.node(self._model.name))
+            out_stream.write(out_stream.meta(self._model.description))
+            with out_stream.indent():
+                out_stream.write('Artifact type: {0}'.format(out_stream.type(
+                    self._model.type.name)))
+                out_stream.write('Source path: {0}'.format(
+                    out_stream.literal(self._model.source_path)))
+                if self._model.target_path is not None:
+                    out_stream.write('Target path: {0}'.format(
+                        out_stream.literal(self._model.target_path)))
+                if self._model.repository_url is not None:
+                    out_stream.write('Repository URL: {0}'.format(
+                        out_stream.literal(self._model.repository_url)))
+                if self._model.repository_credential:
+                    out_stream.write('Repository credential: {0}'.format(
+                        out_stream.literal(self._model.repository_credential)))
+                self._topology.dump(self._model.properties, out_stream, 'Properties')
 
 
 class Capability(common._InstanceHandlerMixin):
@@ -56,17 +57,17 @@ class Capability(common._InstanceHandlerMixin):
     def validate(self, **kwargs):
         self._topology.validate(self._model.properties)
 
-    def dump(self, console):
-        console.write(console.node(self._model.name))
-        with console.indent:
-            console.write('Type: {0}'.format(console.type(self._model.type.name)))
-            console.write('Occurrences: {0:d} ({1:d}{2})'.format(
+    def dump(self, out_stream):
+        out_stream.write(out_stream.node(self._model.name))
+        with out_stream.indent():
+            out_stream.write('Type: {0}'.format(out_stream.type(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, console, 'Properties')
+            self._topology.dump(self._model.properties, out_stream, 'Properties')
 
 
 class Group(common._OperatorHolderHandlerMixin):
@@ -78,17 +79,17 @@ class Group(common._OperatorHolderHandlerMixin):
         self._validate(self._model.properties,
                        self._model.interfaces)
 
-    def dump(self, console):
-        console.write('Group: {0}'.format(console.node(self._model.name)))
-        with console.indent:
-            console.write('Type: {0}'.format(console.type(self._model.type.name)))
-            self._topology.dump(self._model.properties, console, 'Properties')
-            self._topology.dump(self._model.interfaces, console, 'Interfaces')
+    def dump(self, out_stream):
+        out_stream.write('Group: {0}'.format(out_stream.node(self._model.name)))
+        with out_stream.indent():
+            out_stream.write('Type: {0}'.format(out_stream.type(self._model.type.name)))
+            self._topology.dump(self._model.properties, out_stream, 'Properties')
+            self._topology.dump(self._model.interfaces, out_stream, 'Interfaces')
             if self._model.nodes:
-                console.write('Member nodes:')
-                with console.indent:
+                out_stream.write('Member nodes:')
+                with out_stream.indent():
                     for node in self._model.nodes:
-                        console.write(console.node(node.name))
+                        out_stream.write(out_stream.node(node.name))
 
     def configure_operations(self):
         for interface in self._model.interfaces.values():
@@ -103,14 +104,14 @@ class Interface(common._OperatorHolderHandlerMixin):
         self._validate(self._model.inputs,
                        self._model.operations)
 
-    def dump(self, console):
-        console.write(console.node(self._model.name))
+    def dump(self, out_stream):
+        out_stream.write(out_stream.node(self._model.name))
         if self._model.description:
-            console.write(console.meta(self._model.description))
-        with console.indent:
-            console.write('Interface type: {0}'.format(console.type(self._model.type.name)))
-            self._topology.dump(self._model.inputs, console, 'Inputs')
-            self._topology.dump(self._model.operations, console, 'Operations')
+            out_stream.write(out_stream.meta(self._model.description))
+        with out_stream.indent():
+            out_stream.write('Interface type: {0}'.format(out_stream.type(self._model.type.name)))
+            self._topology.dump(self._model.inputs, out_stream, 'Inputs')
+            self._topology.dump(self._model.operations, out_stream, 'Operations')
 
     def configure_operations(self):
         for operation in self._model.operations.values():
@@ -141,17 +142,18 @@ class Node(common._OperatorHolderHandlerMixin):
                        self._model.capabilities,
                        self._model.outbound_relationships)
 
-    def dump(self, console):
-        console.write('Node: {0}'.format(console.node(self._model.name)))
-        with console.indent:
-            console.write('Type: {0}'.format(console.type(self._model.type.name)))
-            console.write('Template: {0}'.format(console.node(self._model.node_template.name)))
-            self._topology.dump(self._model.properties, console, 'Properties')
-            self._topology.dump(self._model.attributes, console, 'Attributes')
-            self._topology.dump(self._model.interfaces, console, 'Interfaces')
-            self._topology.dump(self._model.artifacts, console, 'Artifacts')
-            self._topology.dump(self._model.capabilities, console, 'Capabilities')
-            self._topology.dump(self._model.outbound_relationships, console, 'Relationships')
+    def dump(self, out_stream):
+        out_stream.write('Node: {0}'.format(out_stream.node(self._model.name)))
+        with out_stream.indent():
+            out_stream.write('Type: {0}'.format(out_stream.type(self._model.type.name)))
+            out_stream.write('Template: {0}'.format(
+                out_stream.node(self._model.node_template.name)))
+            self._topology.dump(self._model.properties, out_stream, 'Properties')
+            self._topology.dump(self._model.attributes, out_stream, 'Attributes')
+            self._topology.dump(self._model.interfaces, out_stream, 'Interfaces')
+            self._topology.dump(self._model.artifacts, out_stream, 'Artifacts')
+            self._topology.dump(self._model.capabilities, out_stream, 'Capabilities')
+            self._topology.dump(self._model.outbound_relationships, out_stream, 'Relationships')
 
     def configure_operations(self):
         for interface in self._model.interfaces.values():
@@ -336,33 +338,34 @@ class Operation(common._OperatorHolderHandlerMixin):
                        self._model.configurations,
                        self._model.arguments)
 
-    def dump(self, console):
-        console.write(console.node(self._model.name))
+    def dump(self, out_stream):
+        out_stream.write(out_stream.node(self._model.name))
         if self._model.description:
-            console.write(console.meta(self._model.description))
-        with console.indent:
+            out_stream.write(out_stream.meta(self._model.description))
+        with out_stream.indent():
             if self._model.implementation is not None:
-                console.write('Implementation: {0}'.format(
-                    console.literal(self._model.implementation)))
+                out_stream.write('Implementation: {0}'.format(
+                    out_stream.literal(self._model.implementation)))
             if self._model.dependencies:
-                console.write(
+                out_stream.write(
                     'Dependencies: {0}'.format(
-                        ', '.join((str(console.literal(v)) for v in self._model.dependencies))))
-            self._topology.dump(self._model.inputs, console, 'Inputs')
+                        ', '.join((str(out_stream.literal(v)) for v in self._model.dependencies))))
+            self._topology.dump(self._model.inputs, out_stream, 'Inputs')
             if self._model.executor is not None:
-                console.write('Executor: {0}'.format(console.literal(self._model.executor)))
+                out_stream.write('Executor: {0}'.format(out_stream.literal(self._model.executor)))
             if self._model.max_attempts is not None:
-                console.write('Max attempts: {0}'.format(console.literal(self._model.max_attempts)))
+                out_stream.write('Max attempts: {0}'.format(out_stream.literal(
+                    self._model.max_attempts)))
             if self._model.retry_interval is not None:
-                console.write('Retry interval: {0}'.format(
-                    console.literal(self._model.retry_interval)))
+                out_stream.write('Retry interval: {0}'.format(
+                    out_stream.literal(self._model.retry_interval)))
             if self._model.plugin is not None:
-                console.write('Plugin: {0}'.format(
-                    console.literal(self._model.plugin.name)))
-            self._topology.dump(self._model.configurations, console, 'Configuration')
+                out_stream.write('Plugin: {0}'.format(
+                    out_stream.literal(self._model.plugin.name)))
+            self._topology.dump(self._model.configurations, out_stream, 'Configuration')
             if self._model.function is not None:
-                console.write('Function: {0}'.format(console.literal(self._model.function)))
-            self._topology.dump(self._model.arguments, console, 'Arguments')
+                out_stream.write('Function: {0}'.format(out_stream.literal(self._model.function)))
+            self._topology.dump(self._model.arguments, out_stream, 'Arguments')
 
     def configure_operations(self):
         if self._model.implementation is None and self._model.function is None:
@@ -410,21 +413,21 @@ class Policy(common._InstanceHandlerMixin):
     def validate(self, **kwargs):
         self._topology.validate(self._model.properties)
 
-    def dump(self, console):
-        console.write('Policy: {0}'.format(console.node(self._model.name)))
-        with console.indent:
-            console.write('Type: {0}'.format(console.type(self._model.type.name)))
-            self._topology.dump(self._model.properties, console, 'Properties')
+    def dump(self, out_stream):
+        out_stream.write('Policy: {0}'.format(out_stream.node(self._model.name)))
+        with out_stream.indent():
+            out_stream.write('Type: {0}'.format(out_stream.type(self._model.type.name)))
+            self._topology.dump(self._model.properties, out_stream, 'Properties')
             if self._model.nodes:
-                console.write('Target nodes:')
-                with console.indent:
+                out_stream.write('Target nodes:')
+                with out_stream.indent():
                     for node in self._model.nodes:
-                        console.write(console.node(node.name))
+                        out_stream.write(out_stream.node(node.name))
             if self._model.groups:
-                console.write('Target groups:')
-                with console.indent:
+                out_stream.write('Target groups:')
+                with out_stream.indent():
                     for group in self._model.groups:
-                        console.write(console.node(group.name))
+                        out_stream.write(out_stream.node(group.name))
 
 
 class Relationship(common._OperatorHolderHandlerMixin):
@@ -437,25 +440,25 @@ class Relationship(common._OperatorHolderHandlerMixin):
         self._validate(self._model.properties,
                        self._model.interfaces)
 
-    def dump(self, console):
+    def dump(self, out_stream):
         if self._model.name:
-            console.write('{0} ->'.format(console.node(self._model.name)))
+            out_stream.write('{0} ->'.format(out_stream.node(self._model.name)))
         else:
-            console.write('->')
-        with console.indent:
-            console.write('Node: {0}'.format(console.node(self._model.target_node.name)))
+            out_stream.write('->')
+        with out_stream.indent():
+            out_stream.write('Node: {0}'.format(out_stream.node(self._model.target_node.name)))
             if self._model.target_capability:
-                console.write('Capability: {0}'.format(console.node(
+                out_stream.write('Capability: {0}'.format(out_stream.node(
                     self._model.target_capability.name)))
             if self._model.type is not None:
-                console.write('Relationship type: {0}'.format(
-                    console.type(self._model.type.name)))
+                out_stream.write('Relationship type: {0}'.format(
+                    out_stream.type(self._model.type.name)))
             if (self._model.relationship_template is not None and
                     self._model.relationship_template.name):
-                console.write('Relationship template: {0}'.format(
-                    console.node(self._model.relationship_template.name)))
-            self._topology.dump(self._model.properties, console, 'Properties')
-            self._topology.dump(self._model.interfaces, console, 'Interfaces')
+                out_stream.write('Relationship template: {0}'.format(
+                    out_stream.node(self._model.relationship_template.name)))
+            self._topology.dump(self._model.properties, out_stream, 'Properties')
+            self._topology.dump(self._model.interfaces, out_stream, 'Interfaces')
 
     def configure_operations(self):
         for interface in self._model.interfaces.values():
@@ -484,17 +487,17 @@ class Service(common._OperatorHolderHandlerMixin):
                        self._model.outputs,
                        self._model.workflows)
 
-    def dump(self, console):
+    def dump(self, out_stream):
         if self._model.description is not None:
-            console.write(console.meta(self._model.description))
-        self._topology.dump(self._model.meta_data, console, 'Metadata')
-        self._topology.dump(self._model.nodes, console)
-        self._topology.dump(self._model.groups, console)
-        self._topology.dump(self._model.policies, console)
-        self._topology.dump(self._model.substitution, console)
-        self._topology.dump(self._model.inputs, console, 'Inputs')
-        self._topology.dump(self._model.outputs, console, 'Outputs')
-        self._topology.dump(self._model.workflows, console, 'Workflows')
+            out_stream.write(out_stream.meta(self._model.description))
+        self._topology.dump(self._model.meta_data, out_stream, '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, 'Inputs')
+        self._topology.dump(self._model.outputs, out_stream, 'Outputs')
+        self._topology.dump(self._model.workflows, out_stream, 'Workflows')
 
     def configure_operations(self):
         for node in self._model.nodes.itervalues():
@@ -523,11 +526,11 @@ class Substitution(common._InstanceHandlerMixin):
     def validate(self, **kwargs):
         self._topology.validate(self._model.mappings)
 
-    def dump(self, console):
-        console.write('Substitution:')
-        with console.indent:
-            console.write('Node type: {0}'.format(console.type(self._model.node_type.name)))
-            self._topology.dump(self._model.mappings, console, 'Mappings')
+    def dump(self, out_stream):
+        out_stream.write('Substitution:')
+        with out_stream.indent():
+            out_stream.write('Node type: {0}'.format(out_stream.type(self._model.node_type.name)))
+            self._topology.dump(self._model.mappings, out_stream, 'Mappings')
 
 
 class SubstitutionMapping(common._InstanceHandlerMixin):
@@ -540,25 +543,25 @@ class SubstitutionMapping(common._InstanceHandlerMixin):
                     self._model.name, formatting.safe_repr(self._model.node.name)),
                 level=self._topology.Issue.BETWEEN_TYPES)
 
-    def dump(self, console):
+    def dump(self, out_stream):
         if self._model.capability is not None:
-            console.write('{0} -> {1}.{2}'.format(
-                console.node(self._model.name),
-                console.node(self._model.capability.node.name),
-                console.node(self._model.capability.name)))
+            out_stream.write('{0} -> {1}.{2}'.format(
+                out_stream.node(self._model.name),
+                out_stream.node(self._model.capability.node.name),
+                out_stream.node(self._model.capability.name)))
         else:
-            console.write('{0} -> {1}.{2}'.format(
-                console.node(self._model.name),
-                console.node(self._model.node.name),
-                console.node(self._model.requirement_template.name)))
+            out_stream.write('{0} -> {1}.{2}'.format(
+                out_stream.node(self._model.name),
+                out_stream.node(self._model.node.name),
+                out_stream.node(self._model.requirement_template.name)))
 
 
 class Metadata(common._InstanceHandlerMixin):
 
-    def dump(self, console):
-        console.write('{0}: {1}'.format(
-            console.property(self._topology.name),
-            console.literal(self._topology.value)))
+    def dump(self, out_stream):
+        out_stream.write('{0}: {1}'.format(
+            out_stream.property(self._topology.name),
+            out_stream.literal(self._topology.value)))
 
     def coerce(self):
         pass
@@ -572,18 +575,18 @@ class Metadata(common._InstanceHandlerMixin):
 
 class _Parameter(common._InstanceHandlerMixin):
 
-    def dump(self, console):
+    def dump(self, out_stream):
         if self._model.type_name is not None:
-            console.write('{0}: {1} ({2})'.format(
-                console.property(self._model.name),
-                console.literal(formatting.as_raw(self._model.value)),
-                console.type(self._model.type_name)))
+            out_stream.write('{0}: {1} ({2})'.format(
+                out_stream.property(self._model.name),
+                out_stream.literal(formatting.as_raw(self._model.value)),
+                out_stream.type(self._model.type_name)))
         else:
-            console.write('{0}: {1}'.format(
-                console.property(self._model.name),
-                console.literal(formatting.as_raw(self._model.value))))
+            out_stream.write('{0}: {1}'.format(
+                out_stream.property(self._model.name),
+                out_stream.literal(formatting.as_raw(self._model.value))))
         if self._model.description:
-            console.write(console.meta(self._model.description))
+            out_stream.write(out_stream.meta(self._model.description))
 
     def instantiate(self, instance_cls, **kwargs):
         return instance_cls(
@@ -625,9 +628,9 @@ class Type(common._InstanceHandlerMixin):
     def coerce(self):
         pass
 
-    def dump(self, console):
+    def dump(self, out_stream):
         if self._model.name:
-            console.write(console.type(self._model.name))
-        with console.indent:
+            out_stream.write(out_stream.type(self._model.name))
+        with out_stream.indent():
             for child in self._model.children:
-                self._topology.dump(child, console)
+                self._topology.dump(child, out_stream)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b3724c94/aria/orchestrator/topology/template_handler.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/topology/template_handler.py b/aria/orchestrator/topology/template_handler.py
index 51be788..fc8750f 100644
--- a/aria/orchestrator/topology/template_handler.py
+++ b/aria/orchestrator/topology/template_handler.py
@@ -21,17 +21,17 @@ from . import utils, common
 
 
 class ServiceTemplate(common._TemplateHandlerMixin):
-    def dump(self, console):
+    def dump(self, out_stream):
         if self._model.description is not None:
-            console.write(console.meta(self._model.description))
-        self._topology.dump(self._model.meta_data, console, 'Metadata')
-        self._topology.dump(self._model.node_templates, console)
-        self._topology.dump(self._model.group_templates, console)
-        self._topology.dump(self._model.policy_templates, console)
-        self._topology.dump(self._model.substitution_template, console)
-        self._topology.dump(self._model.inputs, console, 'Inputs')
-        self._topology.dump(self._model.outputs, console, 'Outputs')
-        self._topology.dump(self._model.workflow_templates, console, 'Workflow templates')
+            out_stream.write(out_stream.meta(self._model.description))
+        self._topology.dump(self._model.meta_data, out_stream, '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, 'Inputs')
+        self._topology.dump(self._model.outputs, out_stream, 'Outputs')
+        self._topology.dump(self._model.workflow_templates, out_stream, 'Workflow templates')
 
     def coerce(self, **kwargs):
         self._coerce(self._model.meta_data,
@@ -143,22 +143,23 @@ class ServiceTemplate(common._TemplateHandlerMixin):
 
 
 class ArtifactTemplate(common._TemplateHandlerMixin):
-    def dump(self, console):
-        console.write(console.node(self._model.name))
+    def dump(self, out_stream):
+        out_stream.write(out_stream.node(self._model.name))
         if self._model.description:
-            console.write(console.meta(self._model.description))
-        with console.indent:
-            console.write('Artifact type: {0}'.format(console.type(self._model.type.name)))
-            console.write('Source path: {0}'.format(console.literal(self._model.source_path)))
+            out_stream.write(out_stream.meta(self._model.description))
+        with out_stream.indent():
+            out_stream.write('Artifact type: {0}'.format(out_stream.type(self._model.type.name)))
+            out_stream.write('Source path: {0}'.format(out_stream.literal(self._model.source_path)))
             if self._model.target_path is not None:
-                console.write('Target path: {0}'.format(console.literal(self._model.target_path)))
+                out_stream.write('Target path: {0}'.format(out_stream.literal(
+                    self._model.target_path)))
             if self._model.repository_url is not None:
-                console.write('Repository URL: {0}'.format(
-                    console.literal(self._model.repository_url)))
+                out_stream.write('Repository URL: {0}'.format(
+                    out_stream.literal(self._model.repository_url)))
             if self._model.repository_credential:
-                console.write('Repository credential: {0}'.format(
-                    console.literal(self._model.repository_credential)))
-            self._topology.dump(self._model.properties, console, 'Properties')
+                out_stream.write('Repository credential: {0}'.format(
+                    out_stream.literal(self._model.repository_credential)))
+            self._topology.dump(self._model.properties, out_stream, 'Properties')
 
     def coerce(self, **kwargs):
         self._topology.coerce(self._model.properties, **kwargs)
@@ -179,23 +180,23 @@ class ArtifactTemplate(common._TemplateHandlerMixin):
 
 
 class CapabilityTemplate(common._TemplateHandlerMixin):
-    def dump(self, console):
-        console.write(console.node(self._model.name))
+    def dump(self, out_stream):
+        out_stream.write(out_stream.node(self._model.name))
         if self._model.description:
-            console.write(console.meta(self._model.description))
-        with console.indent:
-            console.write('Type: {0}'.format(console.type(self._model.type.name)))
-            console.write(
+            out_stream.write(out_stream.meta(self._model.description))
+        with out_stream.indent():
+            out_stream.write('Type: {0}'.format(out_stream.type(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:
-                console.write('Valid source node types: {0}'.format(
-                    ', '.join((str(console.type(v.name))
+                out_stream.write('Valid source node types: {0}'.format(
+                    ', '.join((str(out_stream.type(v.name))
                                for v in self._model.valid_source_node_types))))
-            self._topology.dump(self._model.properties, console, 'Properties')
+            self._topology.dump(self._model.properties, out_stream, 'Properties')
 
     def coerce(self):
         self._topology.coerce(self._model.properties)
@@ -213,33 +214,33 @@ class CapabilityTemplate(common._TemplateHandlerMixin):
 
 
 class RequirementTemplate(common._TemplateHandlerMixin):
-    def dump(self, console):
+    def dump(self, out_stream):
         if self._model.name:
-            console.write(console.node(self._model.name))
+            out_stream.write(out_stream.node(self._model.name))
         else:
-            console.write('Requirement:')
-        with console.indent:
+            out_stream.write('Requirement:')
+        with out_stream.indent():
             if self._model.target_node_type is not None:
-                console.write('Target node type: {0}'.format(
-                    console.type(self._model.target_node_type.name)))
+                out_stream.write('Target node type: {0}'.format(
+                    out_stream.type(self._model.target_node_type.name)))
             elif self._model.target_node_template is not None:
-                console.write('Target node template: {0}'.format(
-                    console.node(self._model.target_node_template.name)))
+                out_stream.write('Target node template: {0}'.format(
+                    out_stream.node(self._model.target_node_template.name)))
             if self._model.target_capability_type is not None:
-                console.write('Target capability type: {0}'.format(
-                    console.type(self._model.target_capability_type.name)))
+                out_stream.write('Target capability type: {0}'.format(
+                    out_stream.type(self._model.target_capability_type.name)))
             elif self._model.target_capability_name is not None:
-                console.write('Target capability name: {0}'.format(
-                    console.node(self._model.target_capability_name)))
+                out_stream.write('Target capability name: {0}'.format(
+                    out_stream.node(self._model.target_capability_name)))
             if self._model.target_node_template_constraints:
-                console.write('Target node template constraints:')
-                with console.indent:
+                out_stream.write('Target node template constraints:')
+                with out_stream.indent():
                     for constraint in self._model.target_node_template_constraints:
-                        console.write(console.literal(constraint))
+                        out_stream.write(out_stream.literal(constraint))
             if self._model.relationship_template:
-                console.write('Relationship:')
-                with console.indent:
-                    self._topology.dump(self._model.relationship_template, console)
+                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)
@@ -257,17 +258,17 @@ class RequirementTemplate(common._TemplateHandlerMixin):
 
 
 class GroupTemplate(common._TemplateHandlerMixin):
-    def dump(self, console):
-        console.write('Group template: {0}'.format(console.node(self._model.name)))
+    def dump(self, out_stream):
+        out_stream.write('Group template: {0}'.format(out_stream.node(self._model.name)))
         if self._model.description:
-            console.write(console.meta(self._model.description))
-        with console.indent:
-            console.write('Type: {0}'.format(console.type(self._model.type.name)))
-            self._topology.dump(self._model.properties, console, 'Properties')
-            self._topology.dump(self._model.interface_templates, console, 'Interface Templates')
+            out_stream.write(out_stream.meta(self._model.description))
+        with out_stream.indent():
+            out_stream.write('Type: {0}'.format(out_stream.type(self._model.type.name)))
+            self._topology.dump(self._model.properties, out_stream, 'Properties')
+            self._topology.dump(self._model.interface_templates, out_stream, 'Interface Templates')
             if self._model.node_templates:
-                console.write('Member node templates: {0}'.format(', '.join(
-                    (str(console.node(v.name)) for v in self._model.node_templates))))
+                out_stream.write('Member node templates: {0}'.format(', '.join(
+                    (str(out_stream.node(v.name)) for v in self._model.node_templates))))
 
     def coerce(self, **kwargs):
         self._coerce(self._model.properties,
@@ -293,14 +294,14 @@ class GroupTemplate(common._TemplateHandlerMixin):
 
 
 class InterfaceTemplate(common._TemplateHandlerMixin):
-    def dump(self, console):
-        console.write(console.node(self._model.name))
+    def dump(self, out_stream):
+        out_stream.write(out_stream.node(self._model.name))
         if self._model.description:
-            console.write(console.meta(self._model.description))
-        with console.indent:
-            console.write('Interface type: {0}'.format(console.type(self._model.type.name)))
-            self._topology.dump(self._model.inputs, console, 'Inputs')
-            self._topology.dump(self._model.operation_templates, console, 'Operation templates')
+            out_stream.write(out_stream.meta(self._model.description))
+        with out_stream.indent():
+            out_stream.write('Interface type: {0}'.format(out_stream.type(self._model.type.name)))
+            self._topology.dump(self._model.inputs, out_stream, 'Inputs')
+            self._topology.dump(self._model.operation_templates, out_stream, 'Operation templates')
 
     def coerce(self, **kwargs):
         self._coerce(self._model.inputs,
@@ -323,17 +324,22 @@ class InterfaceTemplate(common._TemplateHandlerMixin):
 
 
 class NodeTemplate(common._TemplateHandlerMixin):
-    def dump(self, console):
-        console.write('Node template: {0}'.format(console.node(self._model.name)))
-        if self._model.description:
-            console.write(console.meta(self._model.description))
-        console.write('Type: {0}'.format(console.type(self._model.type.name)))
-        self._topology.dump(self._model.properties, console, 'Properties')
-        self._topology.dump(self._model.attributes, console, 'Attributes')
-        self._topology.dump(self._model.interface_templates, console, 'Interface Templates')
-        self._topology.dump(self._model.artifact_templates, console, 'Artifact Templates')
-        self._topology.dump(self._model.capability_templates, console, 'Capability Templates')
-        self._topology.dump(self._model.requirement_templates, console, 'Requirement Templates')
+    def dump(self, out_stream):
+        out_stream.write('Node template: {0}'.format(out_stream.node(self._model.name)))
+        with out_stream.indent():
+            if self._model.description:
+                out_stream.write(out_stream.meta(self._model.description))
+            out_stream.write('Type: {0}'.format(out_stream.type(self._model.type.name)))
+            self._topology.dump(self._model.properties, out_stream, 'Properties')
+            self._topology.dump(self._model.attributes, out_stream, 'Attributes')
+            self._topology.dump(
+                self._model.interface_templates, out_stream, 'Interface Templates')
+            self._topology.dump(
+                self._model.artifact_templates, out_stream, 'Artifact Templates')
+            self._topology.dump(
+                self._model.capability_templates, out_stream, 'Capability Templates')
+            self._topology.dump(
+                self._model.requirement_templates, out_stream, 'Requirement Templates')
 
     def coerce(self, **kwargs):
         self._coerce(self._model.properties,
@@ -376,19 +382,19 @@ class NodeTemplate(common._TemplateHandlerMixin):
 
 
 class PolicyTemplate(common._TemplateHandlerMixin):
-    def dump(self, console):
-        console.write('Policy template: {0}'.format(console.node(self._model.name)))
+    def dump(self, out_stream):
+        out_stream.write('Policy template: {0}'.format(out_stream.node(self._model.name)))
         if self._model.description:
-            console.write(console.meta(self._model.description))
-        with console.indent:
-            console.write('Type: {0}'.format(console.type(self._model.type.name)))
-            self._topology.dump(self._model.properties, console, 'Properties')
+            out_stream.write(out_stream.meta(self._model.description))
+        with out_stream.indent():
+            out_stream.write('Type: {0}'.format(out_stream.type(self._model.type.name)))
+            self._topology.dump(self._model.properties, out_stream, 'Properties')
             if self._model.node_templates:
-                console.write('Target node templates: {0}'.format(', '.join(
-                    (str(console.node(v.name)) for v in self._model.node_templates))))
+                out_stream.write('Target node templates: {0}'.format(', '.join(
+                    (str(out_stream.node(v.name)) for v in self._model.node_templates))))
             if self._model.group_templates:
-                console.write('Target group templates: {0}'.format(', '.join(
-                    (str(console.node(v.name)) for v in self._model.group_templates))))
+                out_stream.write('Target group templates: {0}'.format(', '.join(
+                    (str(out_stream.node(v.name)) for v in self._model.group_templates))))
 
     def coerce(self, **kwargs):
         self._topology.coerce(self._model.properties, **kwargs)
@@ -415,11 +421,11 @@ class PolicyTemplate(common._TemplateHandlerMixin):
 
 class SubstitutionTemplate(common._TemplateHandlerMixin):
 
-    def dump(self, console):
-        console.write('Substitution template:')
-        with console.indent:
-            console.write('Node type: {0}'.format(console.type(self._model.node_type.name)))
-            self._topology.dump(self._model.mappings, console, 'Mappings')
+    def dump(self, out_stream):
+        out_stream.write('Substitution template:')
+        with out_stream.indent():
+            out_stream.write('Node type: {0}'.format(out_stream.type(self._model.node_type.name)))
+            self._topology.dump(self._model.mappings, out_stream, 'Mappings')
 
     def coerce(self, **kwargs):
         self._topology.coerce(self._model.mappings, **kwargs)
@@ -434,15 +440,15 @@ class SubstitutionTemplate(common._TemplateHandlerMixin):
 
 class SubstitutionTemplateMapping(common._TemplateHandlerMixin):
 
-    def dump(self, console):
+    def dump(self, out_stream):
         if self._topology.capability_template is not None:
             node_template = self._topology.capability_template.node_template
         else:
             node_template = self._topology.requirement_template.node_template
-        console.write('{0} -> {1}.{2}'.format(
-            console.node(self._topology.name),
-            console.node(node_template.name),
-            console.node(self._topology.capability_template.name
+        out_stream.write('{0} -> {1}.{2}'.format(
+            out_stream.node(self._topology.name),
+            out_stream.node(node_template.name),
+            out_stream.node(self._topology.capability_template.name
                          if self._topology.capability_template
                          else self._topology.requirement_template.name)))
 
@@ -486,17 +492,18 @@ class SubstitutionTemplateMapping(common._TemplateHandlerMixin):
 
 
 class RelationshipTemplate(common._TemplateHandlerMixin):
-    def dump(self, console):
+    def dump(self, out_stream):
         if self._model.type is not None:
-            console.write('Relationship type: {0}'.format(console.type(self._model.type.name)))
+            out_stream.write('Relationship type: {0}'.format(out_stream.type(
+                self._model.type.name)))
         else:
-            console.write('Relationship template: {0}'.format(
-                console.node(self._model.name)))
+            out_stream.write('Relationship template: {0}'.format(
+                out_stream.node(self._model.name)))
         if self._model.description:
-            console.write(console.meta(self._model.description))
-        with console.indent:
-            self._topology.dump(self._model.properties, console, 'Properties')
-            self._topology.dump(self._model.interface_templates, console, 'Interface Templates')
+            out_stream.write(out_stream.meta(self._model.description))
+        with out_stream.indent():
+            self._topology.dump(self._model.properties, out_stream, 'Properties')
+            self._topology.dump(self._model.interface_templates, out_stream, 'Interface Templates')
 
     def coerce(self, **kwargs):
         self._coerce(self._model.properties, self._model.interface_templates, **kwargs)
@@ -517,31 +524,32 @@ class RelationshipTemplate(common._TemplateHandlerMixin):
 
 class OperationTemplate(common._TemplateHandlerMixin):
 
-    def dump(self, console):
-        console.write(console.node(self._model.name))
+    def dump(self, out_stream):
+        out_stream.write(out_stream.node(self._model.name))
         if self._model.description:
-            console.write(console.meta(self._model.description))
-        with console.indent:
+            out_stream.write(out_stream.meta(self._model.description))
+        with out_stream.indent():
             if self._model.implementation is not None:
-                console.write('Implementation: {0}'.format(
-                    console.literal(self._model.implementation)))
+                out_stream.write('Implementation: {0}'.format(
+                    out_stream.literal(self._model.implementation)))
             if self._model.dependencies:
-                console.write('Dependencies: {0}'.format(
-                    ', '.join((str(console.literal(v)) for v in self._model.dependencies))))
-            self._topology.dump(self._model.inputs, console, 'Inputs')
+                out_stream.write('Dependencies: {0}'.format(
+                    ', '.join((str(out_stream.literal(v)) for v in self._model.dependencies))))
+            self._topology.dump(self._model.inputs, out_stream, 'Inputs')
             if self._model.executor is not None:
-                console.write('Executor: {0}'.format(console.literal(self._model.executor)))
+                out_stream.write('Executor: {0}'.format(out_stream.literal(self._model.executor)))
             if self._model.max_attempts is not None:
-                console.write('Max attempts: {0}'.format(console.literal(self._model.max_attempts)))
+                out_stream.write('Max attempts: {0}'.format(out_stream.literal(
+                    self._model.max_attempts)))
             if self._model.retry_interval is not None:
-                console.write('Retry interval: {0}'.format(
-                    console.literal(self._model.retry_interval)))
+                out_stream.write('Retry interval: {0}'.format(
+                    out_stream.literal(self._model.retry_interval)))
             if self._model.plugin_specification is not None:
-                console.write('Plugin specification: {0}'.format(
-                    console.literal(self._model.plugin_specification.name)))
-            self._topology.dump(self._model.configurations, console, 'Configuration')
+                out_stream.write('Plugin specification: {0}'.format(
+                    out_stream.literal(self._model.plugin_specification.name)))
+            self._topology.dump(self._model.configurations, out_stream, 'Configuration')
             if self._model.function is not None:
-                console.write('Function: {0}'.format(console.literal(self._model.function)))
+                out_stream.write('Function: {0}'.format(out_stream.literal(self._model.function)))
 
     def coerce(self, **kwargs):
         self._coerce(self._model.inputs,
@@ -579,5 +587,5 @@ class PluginSpecification(common._TemplateHandlerMixin):
     def instantiate(self, **kwargs):
         pass
 
-    def dump(self, console):
+    def dump(self, out_stream):
         pass

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b3724c94/aria/orchestrator/topology/topology.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/topology/topology.py b/aria/orchestrator/topology/topology.py
index c66749d..e086d08 100644
--- a/aria/orchestrator/topology/topology.py
+++ b/aria/orchestrator/topology/topology.py
@@ -13,11 +13,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 from StringIO import StringIO
+from contextlib import contextmanager
 
 from ...parser.validation import issue
 from ...modeling import models
 from ...utils import (
-    console as console_utils,
+    console,
     formatting
 )
 from . import (
@@ -27,6 +28,50 @@ from . import (
 )
 
 
+class _Stylizer(object):
+    def __init__(self, indentation=2):
+        self._str = StringIO()
+        self._indentation = indentation
+
+    def write(self, str_):
+        console.puts(str_, stream=self._str)
+
+    @contextmanager
+    def indent(self, indent=None):
+        with console.indent(indent or self._indentation):
+            yield
+
+    @staticmethod
+    def section(value):
+        return console.Colored.cyan(value, bold=True)
+
+    @staticmethod
+    def type(value):
+        return console.Colored.blue(value, bold=True)
+
+    @staticmethod
+    def node(value):
+        return console.Colored.red(value, bold=True)
+
+    @staticmethod
+    def property(value):
+        return console.Colored.magenta(value, bold=True)
+
+    @staticmethod
+    def literal(value):
+        return console.Colored.magenta(formatting.safe_repr(value))
+
+    @staticmethod
+    def meta(value):
+        return console.Colored.green(value)
+
+    def __repr__(self):
+        return self._str.getvalue()
+
+    def __str__(self):
+        return repr(self)
+
+
 class Topology(issue.Reporter):
 
     _init_map = {
@@ -54,49 +99,6 @@ class Topology(issue.Reporter):
         models.Type: models.Type
     }
 
-    class Stylizer(object):
-
-        def __init__(self, indentation=2):
-            self._str = StringIO()
-            self.indentation = indentation
-
-        def write(self, str_):
-            console_utils.puts(str_, stream=self._str)
-
-        @property
-        def indent(self):
-            return console_utils.indent(self.indentation)
-
-        @staticmethod
-        def section(value):
-            return console_utils.Colored.cyan(value, bold=True)
-
-        @staticmethod
-        def type(value):
-            return console_utils.Colored.blue(value, bold=True)
-
-        @staticmethod
-        def node(value):
-            return console_utils.Colored.red(value, bold=True)
-
-        @staticmethod
-        def property(value):
-            return console_utils.Colored.magenta(value, bold=True)
-
-        @staticmethod
-        def literal(value):
-            return console_utils.Colored.magenta(formatting.safe_repr(value))
-
-        @staticmethod
-        def meta(value):
-            return console_utils.Colored.green(value)
-
-        def __repr__(self):
-            return self._str.getvalue()
-
-        def __str__(self):
-            return repr(self)
-
     def __init__(self, model_storage=None, *args, **kwargs):
         # TODO: model storage is required only for the list of plugins, can we get it
         # somewhere else?
@@ -142,46 +144,54 @@ class Topology(issue.Reporter):
             _handler = self._handlers.get(model.__class__)
             return _handler(self, model).validate(**kwargs)
 
-    def dump(self, model, console=None, section_name=None, **kwargs):
-        console = console or self.Stylizer()
+    def dump(self, model, out_stream=None, section_name=None, **kwargs):
+        out_stream = out_stream or _Stylizer()
 
         # if model is empty, no need to print out the section name
         if model and section_name:
-            console.write('{0}:'.format(section_name))
+            out_stream.write('{0}:'.format(section_name))
 
         if isinstance(model, dict):
-            return self.dump(model.values(), console=console, **kwargs)
+            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):
-            with console.indent:
-                for value in model:
-                    self.dump(value, console=console, **kwargs)
+            for value in model:
+                self.dump(value, out_stream=out_stream, **kwargs)
+        
         elif model is not None:
             _handler = self._handlers.get(model.__class__)
-            _handler(self, model).dump(console=console, **kwargs)
-        return str(console)
+            _handler(self, model).dump(out_stream=out_stream, **kwargs)
+
+        return out_stream
 
     def dump_graph(self, service, **kwargs):
-        console = self.Stylizer()
+        out_stream = _Stylizer()
         for node in service.nodes.itervalues():
             if not node.inbound_relationships:
-                self._dump_graph_node(console, node)
+                self._dump_graph_node(out_stream, node)
+        return out_stream
 
-    def _dump_graph_node(self, console, node, capability=None):
-        console.write(console.style.node(node.name))
+    def _dump_graph_node(self, out_stream, node, capability=None):
+        out_stream.write(out_stream.node(node.name))
         if capability is not None:
-            console.write('{0} ({1})'.format(console.style.property(capability.name),
-                                             console.style.type(capability.type.name)))
+            out_stream.write('{0} ({1})'.format(out_stream.property(capability.name),
+                                                out_stream.type(capability.type.name)))
         if node.outbound_relationships:
-            with console.style.indent:
+            with out_stream.indent():
                 for relationship_model in node.outbound_relationships:
-                    relationship_name = console.style.property(relationship_model.name)
+                    relationship_name = out_stream.property(relationship_model.name)
                     if relationship_model.type is not None:
-                        console.write('-> {0} ({1})'.format(
-                            relationship_name, console.style.type(relationship_model.type.name)))
+                        out_stream.write('-> {0} ({1})'.format(
+                            relationship_name, out_stream.type(relationship_model.type.name)))
                     else:
-                        console.write('-> {0}'.format(relationship_name))
-                    with console.indent(3):
-                        self._dump_graph_node(relationship_model.target_node,
+                        out_stream.write('-> {0}'.format(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):
@@ -193,17 +203,17 @@ class Topology(issue.Reporter):
             _handler = self._handlers.get(model.__class__)
             return _handler(self, model).coerce(**kwargs)
 
-    def dump_types(self, service_template, console=None):
-        console = console or self.Stylizer()
-        console.write(self.dump(service_template.node_types, console))
-        console.write(self.dump(service_template.group_types, console))
-        console.write(self.dump(service_template.capability_types, console))
-        console.write(self.dump(service_template.relationship_types, console))
-        console.write(self.dump(service_template.policy_types, console))
-        console.write(self.dump(service_template.artifact_types, console))
-        console.write(self.dump(service_template.interface_types, console))
-
-        return str(console)
+    def dump_types(self, service_template, out_stream=None):
+        out_stream = out_stream or _Stylizer()
+        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 str(out_stream)
 
     def satisfy_requirements(self, model, **kwargs):
         if isinstance(model, dict):


Mime
View raw message