示例#1
0
    def map_user_input_to_available_plugins(self):
        parsed_plugin_list = [self.parsed_disruptor_config,
                              self.parsed_monitor_config,
                              self.parsed_runner_config]

        for parsed_config_data in parsed_plugin_list:
            for plugin in parsed_config_data:
                plugin_data = parsed_config_data.get(plugin, None)
                if plugin_data:
                    for plugin_data_item in plugin_data:
                        for plugin_item, item_data in \
                                plugin_data[plugin_data_item].items():
                            plugin_key = plugin + "::" + plugin_data_item
                            self.node_plugin_map[plugin_item] = \
                                plugin_data_item
                            if self.plugin_input_data.get(plugin_key, None):
                                self.plugin_input_data.get(plugin_key).\
                                    append({plugin_item: item_data})
                            else:
                                self.plugin_input_data[plugin_key] = \
                                    [{plugin_item: item_data}]
                else:
                    LOG.warning("No input data given for plugin %s", plugin)

        common.dump_on_console(self.node_plugin_map, "Node Plugin Map")
示例#2
0
    def __init__(self, parser):
        """
        Get the resource form haparser as input parameter and creates
        all the objects that are needed to run the executor.
        """
        # Resoruce from haparser
        self.executor_threads = []
        self.executor_data = parser.parsed_executor_config
        self.plugin_to_class_map = parser.plugin_to_class_map
        self.node_plugin_map = parser.node_plugin_map
        self.module_plugin_map = parser.module_plugin_map
        self.sync_objects = {}
        self.finish_execution_objects = {}
        self.open_pipes = []

        if self.executor_data:
            ha_infra.dump_on_console(self.executor_data, "Executor Data")

        ha_infra.dump_on_console(self.plugin_to_class_map,
                                 "Plugins to Class map")
示例#3
0
    def __init__(self, parser):
        """
        Get the resource form haparser as input parameter and creates
        all the objects that are needed to run the executor.
        """
        # Resoruce from haparser
        self.executor_threads = []
        self.executor_data = parser.parsed_executor_config
        self.plugin_to_class_map = parser.plugin_to_class_map
        self.node_plugin_map = parser.node_plugin_map
        self.module_plugin_map = parser.module_plugin_map
        self.sync_objects = {}
        self.finish_execution_objects = {}
        self.open_pipes = []

        if self.executor_data:
            ha_infra.dump_on_console(self.executor_data, "Executor Data")

        ha_infra.dump_on_console(self.plugin_to_class_map,
                                 "Plugins to Class map")
示例#4
0
    def __init__(self, cfg_file=None): 
        """
        :param cfg_file: input configuration file for the HA framework
        """
        self.user_input_file = cfg_file
        self.parsed_disruptor_config = {}
        self.parsed_runner_config = {}
        self.parsed_executor_config = {}
        self.parsed_monitor_config = {}
        self.plugin_input_data = {}
        self.resource_dirs = []
        self.plugin_to_class_map = {}
        self.node_plugin_map = {}
        self.module_plugin_map = {}

        # base
        self.openstack_config = {}

        infra_source_path = os.environ.get('HAPATH', None)
        if infra_source_path is None:
            LOG.critical("Run the install.sh ** source install.sh **")
            common.ha_exit(0)

        self.parsed_executor_config = self.parse_and_load_input_file(
            self.user_input_file)

        self.parsed_disruptor_config = \
            self.parse_and_load_input_file(infra_source_path +
                                           "/configs/disruptors.yaml")
        self.parsed_monitor_config = \
            self.parse_and_load_input_file(infra_source_path +
                                           "/configs/monitors.yaml")
        self.parsed_runner_config = \
            self.parse_and_load_input_file(infra_source_path +
                                           "/configs/runners.yaml")

        # dump the parsed info from the user on the console
        common.dump_on_console(self.parsed_executor_config, "Executor Config")
        common.dump_on_console(self.parsed_disruptor_config, "Disruptor Config")
        common.dump_on_console(self.parsed_monitor_config, "Monitor Config")
        common.dump_on_console(self.parsed_runner_config, "Runner Config")

        self.load_plugins_and_create_map()
示例#5
0
    def map_plugins_to_class_and_create_instances(self):

        if self.resource_dirs is None:
            LOG.critical('Unable to map type and resources, can not proceed')
            common.ha_exit(0) 

        # Load all the plugin modules defined under the Framework dir
        plugin_dirs = []
        for path in self.resource_dirs:
            for dirpath, dirname, filenames in os.walk(path):
                dirpath_split = dirpath.split('/')
                if dirpath_split[len(dirpath_split)-1] in FRAMEWORK_MODULES:
                    LOG.info("Loading all the plugins under %s ", dirpath)
                    plugin_dirs.append(dirpath + "/plugins")

        for plugin_dir in plugin_dirs:
            for filename in os.listdir(plugin_dir):
                if filename.endswith('.py') and "__init__" not in filename:
                    try:
                        module = filename[:-3]
                        plugin_dir_name = plugin_dir.split("/")[-2]
                        self.module_plugin_map[module.lower()] = \
                            plugin_dir_name.lower()

                        module_name = plugin_dir_name+".plugins."+filename[:-3]
                        LOG.info("Loading the plugin %s", module_name)
                        loaded_mod = __import__(module_name,
                                                fromlist=[module_name])

                        # Load class from imported module
                        # class_name = self.get_class_name(module_name)
                        class_names = inspect.getmembers(loaded_mod,
                                                         inspect.isclass)
                        for clas_name in class_names:
                            if clas_name[0].lower().startswith('base'):
                                base_class_name = clas_name[0]
                                LOG.info("Loading the Class %s",
                                         base_class_name)
                                try:
                                    loaded_base_class = \
                                        getattr(loaded_mod, base_class_name)
                                    break
                                except AttributeError as err:
                                    LOG.critical("Cannot load base class %s "
                                                 "from mod %s",
                                                 base_class_name, loaded_mod)

                        for clas_name in class_names:
                            if not clas_name[0].lower().startswith('base'):
                                class_name = clas_name[0]
                                LOG.info("Loading the Class %s", class_name)
                                try:
                                    loaded_class = getattr(loaded_mod,
                                                           class_name)
                                    if issubclass(loaded_class,
                                                  loaded_base_class):
                                        break
                                except AttributeError as err:
                                    LOG.critical("Cannot load class %s "
                                                 "from mod %s",
                                                 class_name, loaded_mod)

                        # Create an instance of the class
                        file_mod_name = filename[:-3]
                        input_arg_key = plugin_dir_name + "::" + file_mod_name
                        input_arguments = self.plugin_input_data.get(
                            input_arg_key, None)
                        instance = loaded_class(input_arguments)
                        if instance:
                            self.plugin_to_class_map[filename[:-3]] = instance
                    except OSError as err:
                        if DEBUG:
                            LOG.debug("Loading Module %s failed, error = %s",
                                      module, err)
                            common.ha_exit(0)

        # in the end if type_resource is empty, nothing to run exit
        if not self.plugin_to_class_map:
            LOG.critical('Cannot map plugins and load the class')
            common.ha_exit(0) 
        else: 
            LOG.info('All plugins and classes loaded successfully')

        common.dump_on_console(self.plugin_to_class_map, "Plugin to Class Map")
        return self.plugin_to_class_map