Beispiel #1
0
    def load(self, configuration):
        """
        Loads the forker

        :param configuration: API compatibility argument (raises ValueError
                              if present)
        :raise KeyError: A mandatory property is missing
        :raise ValueError: Invalid parameter/file encountered
        :raise BundleException: Error installing a bundle
        :raise Exception: Error instantiating a component
        """
        if configuration is not None:
            raise ValueError("Do NOT try to give a configuration to the "
                             "Forker loader")

        # To simplify...
        context = self._context

        # Get/Update the Home and Base directories
        home, base = self._find_cohorte_directories()

        # Get the node UID and name
        node_uid, node_name = self._update_node()

        # Generate the forker UID if needed
        uid = self._update_uid()
       
        # Update the file finder, as framework properties may have been
        # modified
        self._finder.update_roots()

        # Set up isolate/forker specific framework properties
        self._framework.add_property(cohorte.PROP_KIND, LOADER_KIND)
        self._framework.add_property(cohorte.PROP_NAME, cohorte.FORKER_NAME)

        # Setup Herald property
        self._framework.add_property(herald.FWPROP_PEER_UID, uid)
        self._framework.add_property(herald.FWPROP_PEER_NAME,
                                     cohorte.FORKER_NAME)
        self._framework.add_property(herald.FWPROP_NODE_UID, node_uid)
        self._framework.add_property(herald.FWPROP_NODE_NAME, node_name)
        self._framework.add_property(herald.FWPROP_PEER_GROUPS,
                                     ('all', 'forkers', 'monitors',
                                      node_uid, node_name))

        # Load the boot components
        boot_config = self._config.load_boot(LOADER_KIND)

        # Get the node Data directory
        node_data_dir = boot_config.properties['cohorte.node.data.dir']
        _logger.info('''Loading a forker with the following properties:
* Home.....: %s
* Base.....: %s
* Node UID.: %s
* Node Name: %s
* Node Data: %s
* UID......: %s''', home, base, node_uid, node_name, node_data_dir, uid)        

        # Let the utility method do its job
        utils.boot_load(context, boot_config)
    def load(self, configuration):
        """
        Loads the Pelix isolate

        :param configuration: Isolate configuration dictionary (required)
        :raise KeyError: A mandatory property is missing
        :raise ValueError: Invalid parameter/file encountered
        :raise BundleException: Error installing a bundle
        :raise Exception: Error instantiating a component
        """
        if not configuration:
            raise KeyError("A configuration is required to load a "
                           "Pelix isolate")

        # Parse the configuration (boot-like part)
        base_config = self._config.load_boot_dict(configuration)

        # Use the boot utility method to load the isolate
        utils.boot_load(self._context, base_config)
    def load(self, configuration):
        """
        Loads the Pelix isolate

        :param configuration: Isolate configuration dictionary (required)
        :raise KeyError: A mandatory property is missing
        :raise ValueError: Invalid parameter/file encountered
        :raise BundleException: Error installing a bundle
        :raise Exception: Error instantiating a component
        """
        if not configuration:
            raise KeyError("A configuration is required to load a "
                           "Pelix isolate")

        # Parse the configuration (boot-like part)
        base_config = self._config.load_boot_dict(configuration)

        # Use the boot utility method to load the isolate
        utils.boot_load(self._context, base_config)
Beispiel #4
0
    def _load_top_composer(self):
        """
        Installs and starts the top composer bundles
        """
        # Get installed bundles
        # installed = set(bundle.get_symbolic_name()
        #                 for bundle in self._context.get_bundles())

        # Read the top composer configuration file
        top_config = self._config.read("composer/python-top.js")

        # ######### added by: Bassem D. (issue #6)
        # Extract bundle names
        # bundles = [bundle['name'] for bundle in top_config['bundles']]

        # Start new bundles
        # for name in bundles:
        #    if name not in installed:
        #        self._context.install_bundle(name).start()

        # instantiates manually components declared on configuration files
        utils.boot_load(self._context, self._config.load_boot_dict(top_config))
Beispiel #5
0
    def _load_top_composer(self):
        """
        Installs and starts the top composer bundles
        """
        # Get installed bundles
        # installed = set(bundle.get_symbolic_name()
        #                 for bundle in self._context.get_bundles())

        # Read the top composer configuration file
        top_config = self._config.read("composer/python-top.js")

        # ######### added by: Bassem D. (issue #6)
        # Extract bundle names
        # bundles = [bundle['name'] for bundle in top_config['bundles']]

        # Start new bundles
        # for name in bundles:
        #    if name not in installed:
        #        self._context.install_bundle(name).start()

        # instantiates manually components declared on configuration files
        utils.boot_load(self._context, self._config.load_boot_dict(top_config))
Beispiel #6
0
    def load(self, configuration):
        """
        Loads the forker

        :param configuration: API compatibility argument (raises ValueError
                              if present)
        :raise KeyError: A mandatory property is missing
        :raise ValueError: Invalid parameter/file encountered
        :raise BundleException: Error installing a bundle
        :raise Exception: Error instantiating a component
        """
        if configuration is not None:
            raise ValueError("Do NOT try to give a configuration to the "
                             "Forker loader")

        # To simplify...
        context = self._context

        # Get/Update the Home and Base directories
        home, base = self._find_cohorte_directories()

        # Get the node UID and name
        node_uid, node_name = self._update_node()

        # Generate the forker UID if needed
        uid = self._update_uid()

        # Update the file finder, as framework properties may have been
        # modified
        self._finder.update_roots()

        # Set up isolate/forker specific framework properties
        self._framework.add_property(cohorte.PROP_KIND, LOADER_KIND)
        self._framework.add_property(cohorte.PROP_NAME, cohorte.FORKER_NAME)

        # Setup Herald property
        self._framework.add_property(herald.FWPROP_PEER_UID, uid)
        self._framework.add_property(herald.FWPROP_PEER_NAME,
                                     cohorte.FORKER_NAME)
        self._framework.add_property(herald.FWPROP_NODE_UID, node_uid)
        self._framework.add_property(herald.FWPROP_NODE_NAME, node_name)
        self._framework.add_property(
            herald.FWPROP_PEER_GROUPS,
            ('all', 'forkers', 'monitors', node_uid, node_name))

        # Load the boot components
        boot_config = self._config.load_boot(LOADER_KIND)

        # Get the node Data directory
        node_data_dir = boot_config.properties['cohorte.node.data.dir']
        _logger.info(
            '''Loading a forker with the following properties:
* Home.....: %s
* Base.....: %s
* Node UID.: %s
* Node Name: %s
* Node Data: %s
* UID......: %s''', home, base, node_uid, node_name, node_data_dir, uid)

        # Let the utility method do its job
        utils.boot_load(context, boot_config)
Beispiel #7
0
    def load(self, configuration):
        """
        Grabs the configuration from the broker and uses the corresponding
        loader (instantiates it if needed).

        The *cohorte.configuration.broker* framework property must be set
        correctly before calling this method, or a KeyError exception will be
        raised.

        :raise KeyError: A mandatory property is missing
        :raise ValueError: Invalid parameter/file encountered
        :raise BundleException: Error installing a bundle
        :raise Exception: Unknown error raised while loading the isolate
        """
        # To simplify...
        context = self._context
        framework = self._framework

        # Get the broker URL
        broker_url = context.get_property(cohorte.PROP_CONFIG_BROKER)
        if not broker_url:
            raise KeyError("No configuration broker URL given")

        # Load it
        broker_access = self._parse_url(broker_url)
        raw_data = self._grab_broker_configuration(broker_access)

        # Parse it
        json_data = json.loads(raw_data)

        # Get the kind of this isolate
        kind = json_data['kind']

        # Store Cohorte isolate and Herald peer properties (same values)
        framework.add_property(cohorte.PROP_UID, json_data['uid'])
        framework.add_property(herald.FWPROP_PEER_UID, json_data['uid'])

        isolate_name = json_data['name']
        framework.add_property(cohorte.PROP_NAME, isolate_name)
        framework.add_property(herald.FWPROP_PEER_NAME, isolate_name)

        node_uid = json_data['node_uid']
        framework.add_property(cohorte.PROP_NODE_UID, node_uid)
        framework.add_property(herald.FWPROP_NODE_UID, node_uid)

        node_name = json_data['node_name']
        framework.add_property(cohorte.PROP_NODE_NAME, node_name)
        framework.add_property(herald.FWPROP_NODE_NAME, node_name)

        node_data_dir = json_data['node_data_dir']
        framework.add_property(cohorte.PROP_NODE_DATA_DIR, node_data_dir)        

        framework.add_property(cohorte.PROP_KIND, kind)
        framework.add_property(herald.FWPROP_PEER_GROUPS,
                               ('all', isolate_name, node_uid, node_name))

        # Get the boot configuration
        if 'boot' in json_data:
            # Use the one in the given configuration
            boot_config = self._config.load_boot_dict(json_data['boot'])
            _logger.debug("Using boot configuration from the broker")
        else:
            # By default, load the boot file for this kind
            boot_config = self._config.load_boot(kind)
            _logger.debug("Using boot configuration from the local files")

        # Let the utility method do its job
        utils.boot_load(context, boot_config)

        # Use a specific loader to continue
        kind_filter = "({0}={1})".format(cohorte.SVCPROP_ISOLATE_LOADER_KIND,
                                         kind)
        svc_ref = context.get_service_reference(cohorte.SERVICE_ISOLATE_LOADER,
                                                kind_filter)
        if svc_ref is None:
            raise ValueError("No isolate loader found for kind '{0}'"
                             .format(kind))

        try:
            # Call the loader
            loader = context.get_service(svc_ref)
            loader.load(json_data)

            # Keep the reference to the loader
            self._loader_ref = svc_ref
        finally:
            # Clean the service usage
            context.unget_service(svc_ref)
Beispiel #8
0
    def load(self, configuration):
        """
        Grabs the configuration from the broker and uses the corresponding
        loader (instantiates it if needed).

        The *cohorte.configuration.broker* framework property must be set
        correctly before calling this method, or a KeyError exception will be
        raised.

        :raise KeyError: A mandatory property is missing
        :raise ValueError: Invalid parameter/file encountered
        :raise BundleException: Error installing a bundle
        :raise Exception: Unknown error raised while loading the isolate
        """
        # To simplify...
        context = self._context
        framework = self._framework

        # Get the broker URL
        broker_url = context.get_property(cohorte.PROP_CONFIG_BROKER)
        if not broker_url:
            raise KeyError("No configuration broker URL given")

        # Load it
        broker_access = self._parse_url(broker_url)
        raw_data = self._grab_broker_configuration(broker_access)

        # Parse it
        json_data = json.loads(raw_data)

        # Get the kind of this isolate
        kind = json_data['kind']

        # Store Cohorte isolate and Herald peer properties (same values)
        framework.add_property(cohorte.PROP_UID, json_data['uid'])
        framework.add_property(herald.FWPROP_PEER_UID, json_data['uid'])

        isolate_name = json_data['name']
        framework.add_property(cohorte.PROP_NAME, isolate_name)
        framework.add_property(herald.FWPROP_PEER_NAME, isolate_name)

        node_uid = json_data['node_uid']
        framework.add_property(cohorte.PROP_NODE_UID, node_uid)
        framework.add_property(herald.FWPROP_NODE_UID, node_uid)

        node_name = json_data['node_name']
        framework.add_property(cohorte.PROP_NODE_NAME, node_name)
        framework.add_property(herald.FWPROP_NODE_NAME, node_name)

        node_data_dir = json_data['node_data_dir']
        framework.add_property(cohorte.PROP_NODE_DATA_DIR, node_data_dir)        

        framework.add_property(cohorte.PROP_KIND, kind)
        framework.add_property(herald.FWPROP_PEER_GROUPS,
                               ('all', isolate_name, node_uid, node_name))

        # Get the boot configuration
        if 'boot' in json_data:
            # Use the one in the given configuration
            boot_config = self._config.load_boot_dict(json_data['boot'])
            _logger.debug("Using boot configuration from the broker")
        else:
            # By default, load the boot file for this kind
            boot_config = self._config.load_boot(kind)
            _logger.debug("Using boot configuration from the local files")

        # Let the utility method do its job
        utils.boot_load(context, boot_config)

        # Use a specific loader to continue
        kind_filter = "({0}={1})".format(cohorte.SVCPROP_ISOLATE_LOADER_KIND,
                                         kind)
        svc_ref = context.get_service_reference(cohorte.SERVICE_ISOLATE_LOADER,
                                                kind_filter)
        if svc_ref is None:
            raise ValueError("No isolate loader found for kind '{0}'"
                             .format(kind))

        try:
            # Call the loader
            loader = context.get_service(svc_ref)
            loader.load(json_data)

            # Keep the reference to the loader
            self._loader_ref = svc_ref
        finally:
            # Clean the service usage
            context.unget_service(svc_ref)