Github user AviaE commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130820499
  
    --- Diff: aria/orchestrator/topology/topology.py ---
    @@ -0,0 +1,217 @@
    +# 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.Reporter):
    +
    +    _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.RequirementTemplate: None,
    +        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, model_storage=None, *args, **kwargs):
    +        # TODO: model storage is required only for the list of plugins, 
can we get it
    +        # somewhere else?
    +        super(Topology, self).__init__(*args, **kwargs)
    +        self._model_storage = model_storage
    +        self._handlers = dict(self._init_handlers(instance_handler),
    +                              **self._init_handlers(template_handler))
    +
    +    @staticmethod
    +    def _init_handlers(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._Handler):
    +                handlers[getattr(models, attribute_name)] = attribute
    +        return handlers
    +
    +    def instantiate(self, model, **kwargs):
    +        """
    +        all handlers used by instantiate should hold a tuple as value 
(handler, instnace_cls)
    +        :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._handlers.get(model.__class__)
    +            instance_cls = self._init_map.get(model.__class__)
    +            return _handler(self, model).instantiate(instance_cls, 
**kwargs)
    +
    +    def validate(self, model, **kwargs):
    +        if isinstance(model, dict):
    +            return self.validate(model.values())
    --- End diff --
    
    do you need to pass down `**kwargs`?
    Check all relevant places.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to