Skip to content

Commit

Permalink
Flip API endpoint to the jobs API instead of hacking it into the exis…
Browse files Browse the repository at this point in the history
…ting tools api.
  • Loading branch information
dannon committed Sep 16, 2015
1 parent 1a5ef15 commit c51bfaa
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 38 deletions.
7 changes: 3 additions & 4 deletions client/galaxy/scripts/mvc/tools/tools-form-base.js
Expand Up @@ -65,12 +65,11 @@ define(['utils/utils', 'utils/deferred', 'mvc/ui/ui-misc', 'mvc/form/form-view',
this.options.id = options.id;
this.options.version = options.version;

// construct url
var build_url = Galaxy.root + 'api/tools/' + options.id + '/build?';
//var build_url = Galaxy.root + 'api/tools/random_lines1/build?';
if (options.job_id) {
build_url += 'job_id=' + options.job_id;
build_url = Galaxy.root + 'api/jobs/' + options.job_id + '/build_for_rerun';
} else {
// construct url
var build_url = Galaxy.root + 'api/tools/' + options.id + '/build?';
if (options.dataset_id) {
build_url += 'dataset_id=' + options.dataset_id;
} else {
Expand Down
12 changes: 12 additions & 0 deletions lib/galaxy/webapps/galaxy/api/jobs.py
Expand Up @@ -17,6 +17,7 @@
from galaxy import model
from galaxy import util
from galaxy.web import _future_expose_api as expose_api
from galaxy.web import _future_expose_api_anonymous as expose_api_anonymous
from galaxy.web.base.controller import BaseAPIController
from galaxy.web.base.controller import UsesLibraryMixinItems

Expand Down Expand Up @@ -185,6 +186,17 @@ def outputs( self, trans, id, **kwd ):
job = self.__get_job( trans, id )
return self.__dictify_associations( trans, job.output_datasets, job.output_library_datasets )

@expose_api_anonymous
def build_for_rerun( self, trans, id, **kwd ):
job = self.__get_job(trans, id)
if not job:
raise exceptions.ObjectNotFound("Could not access job with id '%s'" % id)
id = job.tool_id
tool_version = job.tool_version
inputs = job.get_param_values( trans.app )
tool = self.app.toolbox.get_tool( id, tool_version )
return tool.to_json(trans, inputs)

def __dictify_associations( self, trans, *association_lists ):
rval = []
for association_list in association_lists:
Expand Down
33 changes: 1 addition & 32 deletions lib/galaxy/webapps/galaxy/api/tools.py
Expand Up @@ -2,7 +2,6 @@

from galaxy.exceptions import ObjectNotFound
from galaxy.exceptions import InternalServerError
from galaxy.exceptions import MalformedId
from galaxy import web, util
from galaxy import managers
from galaxy.web import _future_expose_api_anonymous_and_sessionless as expose_api_anonymous_and_sessionless
Expand Down Expand Up @@ -94,17 +93,7 @@ def build( self, trans, id, **kwd ):
"""
if 'payload' in kwd:
kwd = kwd.get('payload')
if id == 'undefined' and 'job_id' in kwd:
# We don't know the tool, but we do have a job id. This is a rerun.
job = self.__get_job(trans, kwd['job_id'])
if not job:
raise ObjectNotFound("Could not access job with id '%s'" % kwd['job_id'])
id = job.tool_id
tool_version = job.tool_version
inputs = job.get_param_values( trans.app )
kwd['inputs'] = inputs
else:
tool_version = kwd.get( 'tool_version', None )
tool_version = kwd.get( 'tool_version', None )
tool = self._get_tool( id, tool_version=tool_version, user=trans.user )
return tool.to_json(trans, kwd.get('inputs', kwd))

Expand Down Expand Up @@ -598,23 +587,3 @@ def set_value( param_dict, group_name, group_index, param_name, param_value ):
dataset_dict[ 'id' ] = trans.security.encode_id( dataset_dict[ 'id' ] )
dataset_dict[ 'track_config' ] = self.get_new_track_config( trans, output_dataset )
return dataset_dict

def __get_job( self, trans, id ):
try:
decoded_job_id = self.decode_id( id )
except Exception:
raise MalformedId()
query = trans.sa_session.query( trans.app.model.Job )
if trans.user_is_admin():
query = query.filter(
trans.app.model.Job.id == decoded_job_id
)
else:
query = query.filter(
trans.app.model.Job.user == trans.user,
trans.app.model.Job.id == decoded_job_id
)
job = query.first()
if job is None:
raise ObjectNotFound()
return job
1 change: 1 addition & 0 deletions lib/galaxy/webapps/galaxy/buildapp.py
Expand Up @@ -517,6 +517,7 @@ def populate_api_routes( webapp, app ):
webapp.mapper.connect( 'job_search', '/api/jobs/search', controller='jobs', action='search', conditions=dict( method=['POST'] ) )
webapp.mapper.connect( 'job_inputs', '/api/jobs/{id}/inputs', controller='jobs', action='inputs', conditions=dict( method=['GET'] ) )
webapp.mapper.connect( 'job_outputs', '/api/jobs/{id}/outputs', controller='jobs', action='outputs', conditions=dict( method=['GET'] ) )
webapp.mapper.connect( 'build_for_rerun', '/api/jobs/{id}/build_for_rerun', controller='jobs', action='build_for_rerun', conditions=dict( method=['GET'] ) )

# Job files controllers. Only for consumption by remote job runners.
webapp.mapper.resource( 'file',
Expand Down
2 changes: 1 addition & 1 deletion static/maps/mvc/tools/tools-form-base.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c51bfaa

Please sign in to comment.