Esempio n. 1
0
    def load_component(self, component_name, params=None, parent=None):
        """
    Load given component (DomainAdapter/DomainManager) from config.
    Initiate the given component class, pass the additional attributes,
    register the event listeners and return with the newly created object.

    :param component_name: component's config name
    :type component_name: str
    :param params: component parameters
    :type params: dict
    :param parent: define the parent of the actual component's configuration
    :type parent: dict
    :return: initiated component
    :rtype: :any:`AbstractESCAPEAdapter` or :any:`AbstractDomainManager`
    """
        try:
            # Get component class
            component_class = CONFIG.get_component(component=component_name,
                                                   parent=parent)
            # If it's found
            if component_class is not None:
                # Get optional parameters of this component
                if not params:
                    params = CONFIG.get_component_params(
                        component=component_name, parent=parent)
                # Initialize component
                component = component_class(**params)
                # Set up listeners for e.g. DomainChangedEvents
                component.addListeners(self._ca)
                # Set up listeners for DeployNFFGEvent
                component.addListeners(self._ca._layer_API)
                # Return the newly created object
                return component
            else:
                log.error(
                    "Configuration of '%s' is missing. Skip initialization!" %
                    component_name)
                raise ConfigurationError("Missing component configuration!")
        except AttributeError:
            log.error("%s is not found. Skip component initialization!" %
                      component_name)
            raise
        except ImportError:
            log.error(
                "Could not import module: %s. Skip component initialization!" %
                component_name)
            raise
Esempio n. 2
0
    def load_default_mgrs(self):
        """
    Initiate and start default DomainManagers defined in CONFIG.

    :return: None
    """
        log.info("Initialize additional DomainManagers from config...")
        # very dummy initialization
        mgrs = CONFIG.get_managers()
        if not mgrs:
            log.info("No DomainManager has been configured!")
            return
        for mgr_name in mgrs:
            # Get manager parameters from config
            mgr_cfg = CONFIG.get_component_params(component=mgr_name)
            if 'domain_name' in mgr_cfg:
                if mgr_cfg['domain_name'] in self.domains:
                    log.warning(
                        "Domain name collision! Domain Manager: %s has already "
                        "initiated with the domain name: %s" %
                        (self.get_component_by_domain(
                            domain_name=mgr_cfg['domain_name']),
                         mgr_cfg['domain_name']))
            else:
                # If no domain name was given, use the manager config name by default
                mgr_cfg['domain_name'] = mgr_name
            # Get manager class
            mgr_class = CONFIG.get_component(component=mgr_name)
            if mgr_class.IS_LOCAL_MANAGER:
                loaded_local_mgr = [
                    name for name, mgr in self.__repository.iteritems()
                    if mgr.IS_LOCAL_MANAGER
                ]
                if loaded_local_mgr:
                    log.warning(
                        "A local DomainManager has already been initiated with "
                        "the name: %s! Skip initiating DomainManager: %s" %
                        (loaded_local_mgr, mgr_name))
                    return
            log.debug("Load DomainManager based on config: %s" % mgr_name)
            # Start domain manager
            self.start_mgr(name=mgr_name, mgr_params=mgr_cfg)