Skip to content

Commit

Permalink
Allow toolbox reloading via app, UI, and API.
Browse files Browse the repository at this point in the history
Introduce an app ToolCache to help ensure this operation remains speedy.
  • Loading branch information
jmchilton committed Jan 3, 2016
1 parent b68991c commit 864cc32
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 6 deletions.
15 changes: 11 additions & 4 deletions lib/galaxy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,19 +744,26 @@ class ConfiguresGalaxyMixin:
def _configure_genome_builds( self, data_table_name="__dbkeys__", load_old_style=True ):
self.genome_builds = GenomeBuilds( self, data_table_name=data_table_name, load_old_style=load_old_style )

def _configure_toolbox( self ):
def reload_toolbox(self):
# Initialize the tools, making sure the list of tool configs includes the reserved migrated_tools_conf.xml file.

tool_configs = self.config.tool_configs
if self.config.migrated_tools_config not in tool_configs:
tool_configs.append( self.config.migrated_tools_config )

from galaxy.managers.citations import CitationsManager
self.citations_manager = CitationsManager( self )

from galaxy import tools
self.toolbox = tools.ToolBox( tool_configs, self.config.tool_path, self )
self.reindex_tool_search()

def _configure_toolbox( self ):
from galaxy.managers.citations import CitationsManager
self.citations_manager = CitationsManager( self )

from galaxy.tools.toolbox.cache import ToolCache
self.tool_cache = ToolCache()

self.reload_toolbox()

from galaxy.tools.deps import containers
galaxy_root_dir = os.path.abspath(self.config.root)
file_path = os.path.abspath(getattr(self.config, "file_path"))
Expand Down
7 changes: 6 additions & 1 deletion lib/galaxy/tools/toolbox/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,12 @@ def quick_load( tool_file, async=True ):
def load_tool( self, config_file, guid=None, repository_id=None, **kwds ):
"""Load a single tool from the file named by `config_file` and return an instance of `Tool`."""
# Parse XML configuration file and get the root element
tool = self.create_tool( config_file=config_file, repository_id=repository_id, guid=guid, **kwds )
tool_cache = getattr( self.app, 'tool_cache', None )
tool = tool_cache and tool_cache.get_tool( config_file )
if tool is None:
tool = self.create_tool( config_file=config_file, repository_id=repository_id, guid=guid, **kwds )
if tool_cache:
self.app.tool_cache.cache_tool(config_file, tool)
tool_id = tool.id
if not tool_id.startswith("__"):
# do not monitor special tools written to tmp directory - no reason
Expand Down
17 changes: 17 additions & 0 deletions lib/galaxy/tools/toolbox/cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


class ToolCache(object):
""" Cache tool defintions to allow quickly reloading the whole
toolbox.
"""

def __init__(self):
self._tools_by_path = {}

def get_tool(self, config_filename):
""" Get the tool from the cache if the tool is up to date.
"""
return self._tools_by_path.get(config_filename, None)

def cache_tool(self, config_filename, tool):
self._tools_by_path[config_filename] = tool
9 changes: 9 additions & 0 deletions lib/galaxy/webapps/galaxy/api/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ def tool_lineages(self, trans):
rval.append(entry)
return rval

@expose_api
@require_admin
def reload_toolbox(self, trans):
"""
PUT /api/configuration/toolbox
Reload the Galaxy toolbox (but not individual tools).
"""
self.app.reload_toolbox()


def _tool_conf_to_dict(conf):
return dict(
Expand Down
6 changes: 6 additions & 0 deletions lib/galaxy/webapps/galaxy/buildapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ def populate_api_routes( webapp, app ):
controller="configuration",
action="tool_lineages"
)
webapp.mapper.connect(
'/api/configuration/toolbox',
controller="configuration",
action="reload_toolbox",
conditions=dict( method=["PUT"] )
)
webapp.mapper.resource( 'configuration', 'configuration', path_prefix='/api' )
webapp.mapper.connect( "configuration_version",
"/api/version", controller="configuration",
Expand Down
3 changes: 2 additions & 1 deletion lib/tool_shed/galaxy_install/tool_migration_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from galaxy import util
from galaxy.tools.toolbox import ToolSection
from galaxy.tools.toolbox.parser import ensure_tool_conf_item
from galaxy.util.odict import odict

from tool_shed.galaxy_install import install_manager
Expand Down Expand Up @@ -272,7 +273,7 @@ def get_containing_tool_sections( self, tool_config ):
proprietary_tool_config = section_elem.get( 'file' )
if tool_config == proprietary_tool_config:
# The tool is loaded inside of the section_elem.
tool_sections.append( ToolSection( proprietary_tool_panel_elem ) )
tool_sections.append( ToolSection( ensure_tool_conf_item( proprietary_tool_panel_elem ) ) )
if not is_displayed:
is_displayed = True
return is_displayed, tool_sections
Expand Down
26 changes: 26 additions & 0 deletions templates/admin/reload_tool.mako
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ $().ready(function() {
%endif
focus_el.focus();
});
$().ready(function() {
$("#reload_toolbox").click(function(){
$.ajax({
url: "${h.url_for(controller="/api/configuration", action="toolbox")}",
type: 'PUT',
success: function(result) {
alert("Toolbox reloaded.");
}
});
});
});
</script>

%if message:
Expand Down Expand Up @@ -54,3 +65,18 @@ $().ready(function() {
</form>
</div>
</div>
<p>
<div class="toolForm">
<div class="toolFormTitle">Reload Toolbox</div>
<div class="toolFormBody">
<form name="reload_toolbox_form" id="reload_toolbox_form" action="" method="" >
<div class="form-row">
Clicking <a href="#" id="reload_toolbox">here</a> will reload
the Galaxy toolbox. This will cause newly discovered tools
to be added, tools now missing from tool confs to be removed,
and items in the panel reordered. Individual tools, even ones
with modified tool descriptions willl not be reloaded.
</div>
</form>
</div>
</div>

0 comments on commit 864cc32

Please sign in to comment.