Permalink
Browse files

Changed kill qc jobs command to use HTGT API as VMs dont have qc inst…

…alled.
  • Loading branch information...
1 parent c64bcfd commit cb4782195401e00d2ff73d6129751f4b81355823 @ah19 ah19 committed Feb 5, 2013
@@ -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) {
- my ($self, $c) = @_;
+ my ( $self, $c ) = @_;
$c->assert_user_roles( 'edit' );
@@ -189,14 +189,14 @@ sub submit_new_qc :Path('/user/submit_new_qc') :Args(0) {
$c->stash->{profile} = $c->req->param('profile');
my $run_id;
- if ( $c->req->param('submit_initial_info')){
+ if ( $c->req->param( 'submit_initial_info' ) ){
try{
# 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(
$c->stash->{sequencing_project},
- $c->model('Golgi')->schema,
+ $c->model( 'Golgi' )->schema,
"Plate",
);
$c->stash->{plate_map} = $plate_map;
@@ -218,7 +218,7 @@ sub submit_new_qc :Path('/user/submit_new_qc') :Args(0) {
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->{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>"
@@ -229,53 +229,67 @@ sub submit_new_qc :Path('/user/submit_new_qc') :Args(0) {
}
sub _launch_qc{
- 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.";
- }
+ my ($self, $c, $plate_map ) = @_;
$plate_map ||= {};
my $params = {
- profile => $c->stash->{profile},
- template_plate => $c->stash->{template_plate},
- sequencing_projects => $c->stash->{sequencing_project},
- plate_map => $plate_map,
- username => $qc_conf->{_}->{username},
- password => $qc_conf->{_}->{password},
- created_by => $c->user->name,
- species => $c->session->{selected_species},
+ profile => $c->stash->{ profile },
+ template_plate => $c->stash->{ template_plate },
+ sequencing_projects => $c->stash->{ sequencing_project },
+ plate_map => $plate_map,
+ 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;
- try{
- my $req = HTTP::Request->new(POST => $uri);
- $req->content_type('application/json');
+ #do everythign in a try because if it fails there's no template and you get a useless error
+ try {
+ 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 ) );
- 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 );
}
- catch{
- $c->stash( error_msg => "Sorry, your QC job submission failed with error $_" );
+ catch {
+ $c->stash( error_msg => "Sorry, your HTGT API submission failed with error: $_" );
+ return;
};
- my $run_id = $content->{'qc_run_id'};
-
- return $run_id;
+ return $content;
}
sub latest_runs :Path('/user/latest_runs') :Args(0) {
@@ -313,14 +327,17 @@ sub kill_farm_jobs :Path('/user/kill_farm_jobs') :Args(1) {
$c->assert_user_roles( 'edit' );
- my $kill_jobs = HTGT::QC::Util::KillQCFarmJobs->new(
- {
- qc_run_id => $qc_run_id,
- config => $self->qc_config,
- } );
+ my $content = $self->_htgt_api_call( $c, { qc_run_id => $qc_run_id }, 'kill_uri' );
+
+ if ( $content ) {
+ 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' );
return;
@@ -2,6 +2,35 @@
[% 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">
<thead>
<tr>
@@ -17,18 +46,49 @@
</thead>
<tbody>
[% FOREACH l IN latest -%]
+ [% IF l.failed %]
+ [% td_class = "class='failed'" %]
+ [% ELSIF l.ended %]
+ [% td_class = "class='successful'" %]
+ [% ELSE %]
+ [% td_class = "" %]
+ [% END %]
<tr>
- <td>[% l.qc_run_id %]</td>
- <td>[% l.created %]</td>
- <td>[% l.profile %]</td>
- <td>[% l.seq_projects %]</td>
- <td>[% 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>[% l.last_stage_time %]</td>
- <td align="center"><a href="[%c.uri_for( "/user/kill_farm_jobs/${l.qc_run_id}" ) %]" class="button link">Kill Farm Jobs</a></td>
+ <td [% td_class %]>[% l.qc_run_id %]</td>
+ <td [% td_class %]>[% l.created %]</td>
+ <td [% td_class %]>[% l.profile %]</td>
+ <td [% td_class %]>[% l.seq_projects %]</td>
+ <td [% td_class %]>[% l.template_plate %]</td>
+ <td [% td_class %]>
+ [%# the code below stores text in the title attribute of each link,
+ 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>
[% END -%]
</tbody>
</table>
</div>
+
+

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

0 comments on commit cb47821

Please sign in to comment.