Skip to content

Commit

Permalink
Changed kill qc jobs command to use HTGT API as VMs dont have qc inst…
Browse files Browse the repository at this point in the history
…alled.
  • Loading branch information
Alex Hodgkins committed Feb 5, 2013
1 parent c64bcfd commit cb47821
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 50 deletions.
101 changes: 59 additions & 42 deletions lib/LIMS2/WebApp/Controller/User/QC.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ sub view_qc_alignment :Path('/user/view_qc_alignment') :Args(0) {
} }


sub submit_new_qc :Path('/user/submit_new_qc') :Args(0) { sub submit_new_qc :Path('/user/submit_new_qc') :Args(0) {
my ($self, $c) = @_; my ( $self, $c ) = @_;


$c->assert_user_roles( 'edit' ); $c->assert_user_roles( 'edit' );


Expand All @@ -189,14 +189,14 @@ sub submit_new_qc :Path('/user/submit_new_qc') :Args(0) {
$c->stash->{profile} = $c->req->param('profile'); $c->stash->{profile} = $c->req->param('profile');


my $run_id; my $run_id;
if ( $c->req->param('submit_initial_info')){ if ( $c->req->param( 'submit_initial_info' ) ){
try{ try{
# validate input params before doing anything else # validate input params before doing anything else
$c->model('Golgi')->check_params($c->req->params, $requirements); $c->model( 'Golgi' )->check_params( $c->req->params, $requirements );


my $plate_map = create_suggested_plate_map( my $plate_map = create_suggested_plate_map(
$c->stash->{sequencing_project}, $c->stash->{sequencing_project},
$c->model('Golgi')->schema, $c->model( 'Golgi' )->schema,
"Plate", "Plate",
); );
$c->stash->{plate_map} = $plate_map; $c->stash->{plate_map} = $plate_map;
Expand All @@ -218,7 +218,7 @@ sub submit_new_qc :Path('/user/submit_new_qc') :Args(0) {
return; return;
} }


if ( $run_id = $self->_launch_qc($c, $validated_plate_map) ){ if ( $run_id = $self->_launch_qc( $c, $validated_plate_map ) ){
$c->stash->{run_id} = $run_id; $c->stash->{run_id} = $run_id;
$c->stash->{success_msg} = "Your QC job has been submitted with ID $run_id. " $c->stash->{success_msg} = "Your QC job has been submitted with ID $run_id. "
."Go to <a href=\"".$c->uri_for('/user/latest_runs')."\">Latest Runs</a>" ."Go to <a href=\"".$c->uri_for('/user/latest_runs')."\">Latest Runs</a>"
Expand All @@ -229,53 +229,67 @@ sub submit_new_qc :Path('/user/submit_new_qc') :Args(0) {
} }


sub _launch_qc{ sub _launch_qc{
my ($self, $c, $plate_map) = @_; my ($self, $c, $plate_map ) = @_;

my $ua = LWP::UserAgent->new();
my $qc_conf = Config::Tiny->new();
$qc_conf = Config::Tiny->read($ENV{LIMS2_QC_CONFIG});

unless ($qc_conf){
die "No QC submission service has been configured. Cannot submit QC job.";
}


$plate_map ||= {}; $plate_map ||= {};


my $params = { my $params = {
profile => $c->stash->{profile}, profile => $c->stash->{ profile },
template_plate => $c->stash->{template_plate}, template_plate => $c->stash->{ template_plate },
sequencing_projects => $c->stash->{sequencing_project}, sequencing_projects => $c->stash->{ sequencing_project },
plate_map => $plate_map, plate_map => $plate_map,
username => $qc_conf->{_}->{username}, created_by => $c->user->name,
password => $qc_conf->{_}->{password}, species => $c->session->{ selected_species },
created_by => $c->user->name,
species => $c->session->{selected_species},
}; };


my $uri = $qc_conf->{_}->{submit_uri}; my $content = $self->_htgt_api_call( $c, $params, 'submit_uri' );

return $content->{ qc_run_id };
}

#generic function to make a htgt api call, accepting a hashref of user parameters,
#and returning the decoded json content provided by the api page.
sub _htgt_api_call {
my ( $self, $c, $params, $conf_uri_key ) = @_;


my $content; my $content;


try{ #do everythign in a try because if it fails there's no template and you get a useless error
my $req = HTTP::Request->new(POST => $uri); try {
$req->content_type('application/json'); die "No URI specified." unless $conf_uri_key;

my $ua = LWP::UserAgent->new();
my $qc_conf = Config::Tiny->new();
$qc_conf = Config::Tiny->read( $ENV{ LIMS2_QC_CONFIG } );

#add authentication information
$params->{ username } = $qc_conf->{_}->{ username };
$params->{ password } = $qc_conf->{_}->{ password };

my $uri = $qc_conf->{_}->{ $conf_uri_key }; #kill_uri or submit_uri

die "No QC submission service has been configured. Cannot submit QC job."
unless $qc_conf;

#create a http request object sending json
my $req = HTTP::Request->new( POST => $uri );
$req->content_type( 'application/json' );
$req->content( encode_json( $params ) ); $req->content( encode_json( $params ) );


my $response = $ua->request($req); #make the actual request
my $response = $ua->request( $req );


unless ($response->is_success){ die "Request to $uri was not successful. Response: " . $response->status_line
die "Request to $uri was not successful. Response: ".$response->status_line; unless $response->is_success;
}


$content = decode_json( $response->content ); $content = decode_json( $response->content );
} }
catch{ catch {
$c->stash( error_msg => "Sorry, your QC job submission failed with error $_" ); $c->stash( error_msg => "Sorry, your HTGT API submission failed with error: $_" );
return;
}; };


my $run_id = $content->{'qc_run_id'}; return $content;

return $run_id;
} }


sub latest_runs :Path('/user/latest_runs') :Args(0) { sub latest_runs :Path('/user/latest_runs') :Args(0) {
Expand Down Expand Up @@ -313,14 +327,17 @@ sub kill_farm_jobs :Path('/user/kill_farm_jobs') :Args(1) {


$c->assert_user_roles( 'edit' ); $c->assert_user_roles( 'edit' );


my $kill_jobs = HTGT::QC::Util::KillQCFarmJobs->new( my $content = $self->_htgt_api_call( $c, { qc_run_id => $qc_run_id }, 'kill_uri' );
{
qc_run_id => $qc_run_id, if ( $content ) {
config => $self->qc_config, my @jobs_killed = @{ $content->{ job_ids } };
} ); $c->stash( info_msg => "Killing farm jobs (" . join( ' ', @jobs_killed ) . ") from QC run $qc_run_id" );
}
else {
my $error = $c->stash->{ error_msg } . "<br/>Failed to kill farm jobs."; #dont overwrite other error
$c->stash( error_msg => $error );
}


my $jobs_killed = $kill_jobs->kill_unfinished_farm_jobs();
$c->stash( info_msg => 'Killing farm jobs (' . join( ' ', @{$jobs_killed} ) . ') from QC run '.$qc_run_id );
$c->go( 'latest_runs' ); $c->go( 'latest_runs' );


return; return;
Expand Down
76 changes: 68 additions & 8 deletions root/site/user/qc/latest_runs.tt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@


[% INCLUDE 'pagination.tt' pageset = pageset %] [% INCLUDE 'pagination.tt' pageset = pageset %]


<link href="[% c.uri_for( '/static/css/jquery.qtip.min.css' ) %]" rel="stylesheet">

<style type="text/css">
.table-striped tbody tr td.failed { background-color: #FF8080; }
.table-striped tbody tr td.successful { background-color: #80FF80; }
</style>
<script type="text/javascript" src="[% c.uri_for( "/static/js/jquery.qtip.min.js" ) %]"></script>
<script type="text/javascript">
//load tooltips for all last stage links
$(document).ready(function() {
$('.laststage').qtip({
content: {
attr: 'title',
},
position: {
my: 'top left',
at: 'bottom center'
},
hide: {
fixed: true,
delay: 500
},
style: {
classes: 'qtip-blue'
}
});
});
</script>

<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
Expand All @@ -17,18 +46,49 @@
</thead> </thead>
<tbody> <tbody>
[% FOREACH l IN latest -%] [% FOREACH l IN latest -%]
[% IF l.failed %]
[% td_class = "class='failed'" %]
[% ELSIF l.ended %]
[% td_class = "class='successful'" %]
[% ELSE %]
[% td_class = "" %]
[% END %]
<tr> <tr>
<td>[% l.qc_run_id %]</td> <td [% td_class %]>[% l.qc_run_id %]</td>
<td>[% l.created %]</td> <td [% td_class %]>[% l.created %]</td>
<td>[% l.profile %]</td> <td [% td_class %]>[% l.profile %]</td>
<td>[% l.seq_projects %]</td> <td [% td_class %]>[% l.seq_projects %]</td>
<td>[% l.template_plate %]</td> <td [% td_class %]>[% l.template_plate %]</td>
<td><a href="[%c.uri_for( "/user/qc_farm_error_rpt/${l.qc_run_id}___${l.last_stage}" ) %]">[% l.last_stage %]</td> <td [% td_class %]>
<td>[% l.last_stage_time %]</td> [%# the code below stores text in the title attribute of each link,
<td align="center"><a href="[%c.uri_for( "/user/kill_farm_jobs/${l.qc_run_id}" ) %]" class="button link">Kill Farm Jobs</a></td> to create the tooltips on the page. (I'm sorry) %]
<a
href="[%c.uri_for( "/user/qc_farm_error_rpt/${l.qc_run_id}___${l.last_stage}" ) %]"
class="laststage"
title='
[% IF l.previous_stages && l.previous_stages.size %]
[% FOREACH stage IN l.previous_stages -%]
<a href="[%c.uri_for( "/user/qc_farm_error_rpt/${l.qc_run_id}___${stage}" ) %]">[% stage %]</a><br/>
[% END -%]
[% ELSE %]
No previous stages.
[% END %]
'
>[% l.last_stage %]</a><br/>
</td>
<td [% td_class %]>[% l.last_stage_time %]</td>
<td align="center" [% td_class %]>
[% IF l.ended %]
Finished
[% ELSE %]
<a href="[%c.uri_for( "/user/kill_farm_jobs/${l.qc_run_id}" ) %]" class="button link">Kill Farm Jobs</a>
[% END %]
</td>
</tr> </tr>
[% END -%] [% END -%]
</tbody> </tbody>
</table> </table>


</div> </div>


1 change: 1 addition & 0 deletions root/static/css/jquery.qtip.min.css

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

2 changes: 2 additions & 0 deletions root/static/js/jquery.qtip.min.js

Large diffs are not rendered by default.

0 comments on commit cb47821

Please sign in to comment.