Skip to content
6 changes: 3 additions & 3 deletions src/MGRAST/cgi/api.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if (lc($request_method) eq 'options') {
-type => 'text/plain',
-charset => 'UTF-8',
-Access_Control_Allow_Methods => 'POST, GET, OPTIONS',
-Access_Control_Allow_Headers => 'AUTH'
-Access_Control_Allow_Headers => 'AUTH, AUTHORIZATION'
);
print "";
exit 0;
Expand Down Expand Up @@ -150,12 +150,12 @@ else {

# check for authentication
my $user;
if ($cgi->http('HTTP_AUTH') || $cgi->param('auth')) {
if ($cgi->http('HTTP_AUTH') || $cgi->param('auth') || $cgi->http('HTTP_AUTHORIZATION') || $cgi->param('authorization')) {
eval {
require Auth;
Auth->import();
my $message;
($user, $message) = Auth::authenticate($cgi->http('HTTP_AUTH') || $cgi->param('auth'));
($user, $message) = Auth::authenticate($cgi->http('HTTP_AUTH') || $cgi->param('auth') || $cgi->http('HTTP_AUTHORIZATION') || $cgi->param('authorization'));
unless($user) {
unless ($message eq "valid kbase user") {
print $cgi->header( -type => 'application/json',
Expand Down
85 changes: 62 additions & 23 deletions src/MGRAST/lib/JobDB/Job.pm
Original file line number Diff line number Diff line change
Expand Up @@ -916,13 +916,10 @@ sub jobs_mixs_metadata_fast {
sub fetch_browsepage_in_progress {
my ($self, $user, $count_only) = @_;

# get jobs
my $jobs = $self->_master->Job->get_objects({ owner => $user});
my $id2job = {};
foreach my $job (@$jobs) {
$id2job->{$job->{job_id}} = $job;
unless (ref($user) && $user->isa("WebServerBackend::User")) {
return [];
}

# get mgrast token
my $mgrast_token = undef;
if ($Conf::mgrast_oauth_name && $Conf::mgrast_oauth_pswd) {
Expand All @@ -938,7 +935,8 @@ sub fetch_browsepage_in_progress {
$json->max_size(0);
$json->allow_nonref;

my $stage_titles = { 'upload' => 'Upload',
my $stage_titles = {
'upload' => 'Upload',
'preprocess_qc' => 'Sequence Filtering',
'dereplication' => 'Dereplication',
'screen' => 'Sequence Screening',
Expand All @@ -956,30 +954,71 @@ sub fetch_browsepage_in_progress {
my $get = $agent->get($Conf::awe_url.'/job?query&limit=0&info.user=mgu'.$user->{_id}, @args);
$stats = $json->decode( $get->content );
};
# awe is down, get minimal info from DB
if ($@ || (! $stats) || (exists($stats->{error}) && $stats->{error})) {
print STDERR "AWE job info retrieval failed for user ".$user->{_id}.": $@".($stats && $stats->{error} ? $stats->{error} : "")."\n";
return $count_only ? 0 : [];

# get job info
my $dbh = $self->_master()->db_handle();
my $sql = "select _id, job_id, name, metagenome_id from Job where owner=".$user->{_id}." and metagenome_id is not null and (viewable=0 or viewable is null)";
my $sth = $dbh->prepare($sql);
$sth->execute;
my $jobdata = $sth->fetchall_arrayref();
$sth->finish;

# get jobs to skip
$sql = "select job from JobAttributes where tag='deleted' or tag='no_sims_found'";
$sth = $dbh->prepare($sql);
$sth->execute;
my %skip = map { $_->[0], 1 } @{ $sth->fetchall_arrayref() };
$sth->finish;

# get display jobs: _id, job_id, name, metagenome_id
my %id2job = map { $_->[1], $_ } grep { ! exists $skip{$_->[0]} } @$jobdata;

if ($count_only) {
return scalar(keys %id2job);
} else {
my $data_table = [];
foreach my $job_id (keys %id2job) {
push(@$data_table, {
job_id => $job_id,
metagenome_id => $id2job{$job_id}[3],
metagenome_name => $id2job{$job_id}[2],
states => [],
status => 'stage unknown: running' });
}
return $data_table;
}
# build progress from AWE
} else {
my $stati = $stats->{data};
my $running = [];
foreach my $job (@{$stats->{data}}) {
unless (($job->{state} eq 'completed') || ($job->{state} eq 'deleted')) {
push @$running, $job;
}
}
if ($count_only) {
return scalar(@$stati);
return scalar(@$running);
} else {
my $data_table = [];
foreach my $job (@$stati) {
my $row = { job_id => $job->{info}->{name},
metagenome_id => $id2job->{$job->{info}->{name}}->{metagenome_id},
metagenome_name => $id2job->{$job->{info}->{name}}->{name},
foreach my $job (@$running) {
my $row = {
job_id => $job->{info}{userattr}{job_id},
metagenome_id => $job->{info}{userattr}{id},
metagenome_name => $job->{info}{userattr}{name},
states => [],
status => undef };
my $i=1;
foreach my $stage (@{$job->{tasks}}) {
if (! $row->{status} && ($stage->{remainwork} > 0 || $i == scalar(@{$job->{tasks}}))) {
$row->{status} = ($stage_titles->{$stage->{cmd}->{description}} ? $stage_titles->{$stage->{cmd}->{description}} : $stage->{cmd}->{description}).": ".$stage->{state};
}
push(@{$row->{states}}, { stage => $stage_titles->{$stage->{cmd}->{description}} ? $stage_titles->{$stage->{cmd}->{description}} : $stage->{cmd}->{description}, status => $stage->{state} });
$i++;
}
push(@$data_table, $row);
my $i = 1;
$row->{metagenome_id} =~ s/^mgm//;
foreach my $stage (@{$job->{tasks}}) {
if (! $row->{status} && ($stage->{remainwork} > 0 || $i == scalar(@{$job->{tasks}}))) {
$row->{status} = ($stage_titles->{$stage->{cmd}->{description}} ? $stage_titles->{$stage->{cmd}->{description}} : $stage->{cmd}->{description}).": ".$stage->{state};
}
push(@{$row->{states}}, { stage => $stage_titles->{$stage->{cmd}->{description}} ? $stage_titles->{$stage->{cmd}->{description}} : $stage->{cmd}->{description}, status => $stage->{state} });
$i++;
}
push(@$data_table, $row);
}
return $data_table;
}
Expand Down
4 changes: 4 additions & 0 deletions src/MGRAST/lib/resources/user.pm
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,10 @@ sub query {

# check what operator
my $val = uri_unescape($self->cgi->param($key));
if ($key eq "id") {
$key = "_id";
$val =~ s/mgu//;
}

my $str = $key;

Expand Down
2 changes: 1 addition & 1 deletion src/WebApplication/WebComponent/Register.pm
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ sub country_codes {
'AG' => 'Antigua and Barbuda',
'GT' => 'Guatemala',
'MC' => 'Monaco',
'GE' => 'Abkhazia',
'GE' => 'Georgia',
'CY' => 'Northern Cyprus',
'LV' => 'Latvia',
'MH' => 'Marshall Islands',
Expand Down