Beispiel #1
0
 def get_conf_watchers(self):
     conf_watchers = []
     conf_watchers.extend([(get_tool_conf_watcher(lambda: reload_data_managers(self.app)), filename) for filename in util.listify(self.filename) if filename])
     if self.app.config.shed_data_manager_config_file:
         conf_watchers.append((get_tool_conf_watcher(lambda: reload_data_managers(self.app)), self.app.config.shed_data_manager_config_file))
     [watcher.watch_file(filename) for watcher, filename in conf_watchers]
     return [watcher for watcher, filename in conf_watchers]
Beispiel #2
0
 def get_conf_watchers(self):
     """
     Sets up monitoring of data manager related config files.
     These are the data_manager_conf.xml and shed_data_manager_conf.xml files
     as well as any loc file in the tool-data directory.
     """
     conf_watchers = []
     conf_watchers.extend([
         (get_tool_conf_watcher(lambda: reload_data_managers(self.app)),
          filename) for filename in util.listify(self.filename) if filename
     ])
     if self.app.config.shed_data_manager_config_file:
         conf_watchers.append(
             (get_tool_conf_watcher(lambda: reload_data_managers(self.app)),
              self.app.config.shed_data_manager_config_file))
     [watcher.watch_file(filename) for watcher, filename in conf_watchers]
     tool_data_watcher = get_tool_data_dir_watcher(
         self.app.tool_data_tables, self.app.config)
     tool_data_watcher.watch_directory(self.app.config.tool_data_path)
     if self.app.config.shed_tool_data_path:
         tool_data_watcher.watch_directory(
             self.app.config.shed_tool_data_path)
     conf_watchers.append(
         (tool_data_watcher, self.app.tool_data_tables.tool_data_path))
     return [watcher for watcher, filename in conf_watchers]
 def __init__(self, app, start_thread=True):
     self.app = app
     # ToolConfWatcher objects will watch the tool_cache if the tool_cache is passed into get_tool_conf_watcher.
     # Watching the tool_cache means removing outdated items from the tool_cache.
     # Only the reload_toolbox callback will re-populate the cache, so we pass the tool_cache only to the ToolConfWatcher that
     # watches regular tools.
     # If there are multiple ToolConfWatcher objects for the same handler or web process a race condition occurs between the two cache_cleanup functions.
     # If the reload_data_managers callback wins, the cache will miss the tools that had been removed from the cache
     # and will be blind to further changes in these tools.
     self.tool_config_watcher = get_tool_conf_watcher(
         reload_callback=lambda: reload_toolbox(self.app),
         tool_cache=self.app.tool_cache)
     self.data_manager_config_watcher = get_tool_conf_watcher(
         reload_callback=lambda: reload_data_managers(self.app))
     self.tool_data_watcher = get_tool_data_dir_watcher(
         self.app.tool_data_tables, config=self.app.config)
     self.tool_watcher = get_tool_watcher(self, app.config)
     if getattr(self.app, 'is_job_handler', False):
         self.job_rule_watcher = get_watcher(app.config,
                                             'watch_job_rules',
                                             monitor_what_str='job rules')
     else:
         self.job_rule_watcher = get_watcher(app.config, '__invalid__')
     if start_thread:
         self.start()
Beispiel #4
0
 def get_conf_watchers(self):
     conf_watchers = []
     conf_watchers.extend([
         (get_tool_conf_watcher(lambda: reload_data_managers(self.app)),
          filename) for filename in util.listify(self.filename) if filename
     ])
     if self.app.config.shed_data_manager_config_file:
         conf_watchers.append(
             (get_tool_conf_watcher(lambda: reload_data_managers(self.app)),
              self.app.config.shed_data_manager_config_file))
     [watcher.watch_file(filename) for watcher, filename in conf_watchers]
     return [watcher for watcher, filename in conf_watchers]
Beispiel #5
0
    def __init__(self, app):
        self.app = app
        self.active = False

        # ToolConfWatcher objects will watch the tool_cache if the tool_cache is passed into get_tool_conf_watcher.
        # Watching the tool_cache means removing outdated items from the tool_cache.
        # Only the reload_toolbox callback will re-populate the cache, so we pass the tool_cache only to the ToolConfWatcher that
        # watches regular tools.
        # If there are multiple ToolConfWatcher objects for the same handler or web process a race condition occurs between the two cache_cleanup functions.
        # If the reload_data_managers callback wins, the cache will miss the tools that had been removed from the cache
        # and will be blind to further changes in these tools.

        def reload_toolbox():
            save_integrated_tool_panel = False
            try:
                # Run and wait for toolbox reload on the process that watches the config files.
                # The toolbpox reload will update the integrated_tool_panel_file
                self.app.queue_worker.send_local_control_task(
                    'reload_toolbox', get_response=True),
            except Exception:
                save_integrated_tool_panel = True
                log.exception("Exception occured while reloading toolbox")
            self.app.queue_worker.send_control_task(
                'reload_toolbox',
                noop_self=True,
                kwargs={
                    'save_integrated_tool_panel': save_integrated_tool_panel
                }),

        self.tool_config_watcher = get_tool_conf_watcher(
            reload_callback=reload_toolbox,
            tool_cache=self.app.tool_cache,
        )
        self.data_manager_config_watcher = get_tool_conf_watcher(
            reload_callback=lambda: self.app.queue_worker.send_control_task(
                'reload_data_managers'), )
        self.tool_data_watcher = get_watcher(self.app.config,
                                             'watch_tool_data_dir',
                                             monitor_what_str='data tables')
        self.tool_watcher = get_tool_watcher(self, app.config)
        if getattr(self.app, 'is_job_handler', False):
            self.job_rule_watcher = get_watcher(app.config,
                                                'watch_job_rules',
                                                monitor_what_str='job rules')
        else:
            self.job_rule_watcher = get_watcher(app.config, '__invalid__')
        self.core_config_watcher = get_watcher(
            app.config,
            'watch_core_config',
            monitor_what_str='core config file')
        self.tour_watcher = get_watcher(app.config,
                                        'watch_tours',
                                        monitor_what_str='tours')
 def __init__(self, app):
     self.app = app
     # ToolConfWatcher objects will watch the tool_cache if the tool_cache is passed into get_tool_conf_watcher.
     # Watching the tool_cache means removing outdated items from the tool_cache.
     # Only the reload_toolbox callback will re-populate the cache, so we pass the tool_cache only to the ToolConfWatcher that
     # watches regular tools.
     # If there are multiple ToolConfWatcher objects for the same handler or web process a race condition occurs between the two cache_cleanup functions.
     # If the reload_data_managers callback wins, the cache will miss the tools that had been removed from the cache
     # and will be blind to further changes in these tools.
     self.tool_config_watcher = get_tool_conf_watcher(reload_callback=lambda: reload_toolbox(self.app), tool_cache=self.app.tool_cache)
     self.data_manager_config_watcher = get_tool_conf_watcher(reload_callback=lambda: reload_data_managers(self.app))
     self.tool_data_watcher = get_tool_data_dir_watcher(self.app.tool_data_tables, config=self.app.config)
     self.tool_watcher = get_tool_watcher(self, app.config)
     self.start()
Beispiel #7
0
 def __init__( self, test_case ):
     app = test_case.app
     # Handle app/config stuff needed by toolbox but not by tools.
     app.job_config.get_tool_resource_parameters = lambda tool_id: None
     app.config.update_integrated_tool_panel = True
     config_files = test_case.config_files
     tool_root_dir = test_case.test_directory
     super( SimplifiedToolBox, self ).__init__(
         config_files,
         tool_root_dir,
         app,
     )
     self._tool_conf_watcher = get_tool_conf_watcher(dummy_callback)
Beispiel #8
0
def test_tool_conf_watcher():
    if not watcher.can_watch:
        from nose.plugins.skip import SkipTest
        raise SkipTest()

    callback = CallbackRecorder()
    conf_watcher = watcher.get_tool_conf_watcher(callback.call)

    with __test_directory() as t:
        tool_conf_path = path.join(t, "test_conf.xml")
        conf_watcher.watch_file(tool_conf_path)

        open(tool_conf_path, "w").write("b")
        wait_for_reload(lambda: callback.called)
        conf_watcher.shutdown()
        assert not conf_watcher.thread.is_alive()
Beispiel #9
0
def test_tool_conf_watcher():
    callback = CallbackRecorder()
    conf_watcher = watcher.get_tool_conf_watcher(callback.call)
    conf_watcher.start()

    with __test_directory() as t:
        tool_conf_path = path.join(t, "test_conf.xml")
        with open(tool_conf_path, "w") as f:
            f.write("a")
        conf_watcher.watch_file(tool_conf_path)
        time.sleep(2)
        with open(tool_conf_path, "w") as f:
            f.write("b")
        wait_for_reload(lambda: callback.called)
        conf_watcher.shutdown()
        assert conf_watcher.thread is None