Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/MGRAST/lib/WebPage/Analysis.pm
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ sub phylogenetic_data {
while (my ($mgid, $jobid) = each %{$self->{mgdb}->_job_map}) {
my $jobj = $mgrast->Job->init( {job_id => $jobid} );
my $alpha = $jobj->stats('alpha_diversity_shannon')->{'alpha_diversity_shannon'};
my $curve = $self->{mgdb}->get_rarefaction_coords($jobid);
my $curve = $self->{mgdb}->get_rarefaction_coords($jobj->metagenome_id);
if ($alpha) { $mgid_alpha->{$mgid} = $alpha; }
if (@$curve) { $mgid_curve->{$mgid} = $curve; }
}
Expand Down
2 changes: 1 addition & 1 deletion src/MGRAST/lib/resources/download.pm
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ sub instance {
foreach my $set (@$setlist) {
if (($set->{file_id} eq $file) || ($set->{file_name} eq $file)) {
if ($link) {
my $data = $self->get_shock_preauth($set->{node_id}, $self->mgrast_token);
my $data = $self->get_shock_preauth($set->{node_id}, $self->mgrast_token, $set->{file_name});
$self->return_data($data);
} else {
$self->return_shock_file($set->{node_id}, $set->{file_size}, $set->{file_name}, $self->mgrast_token);
Expand Down
4 changes: 2 additions & 2 deletions src/MGRAST/lib/resources/job.pm
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ sub info {
'required' => {},
'body' => { "metagenome_id" => ["string", "unique MG-RAST metagenome identifier"],
"user_id" => ["string", "unique user identifier to share with"],
"user_email" => ["string", "user email to share with"].
"user_email" => ["string", "user email to share with"],
"edit" => ["boolean", "if true edit rights shared, else (default) view rights only"] } }
},
{ 'name' => "public",
Expand Down Expand Up @@ -453,4 +453,4 @@ sub get_post_data {
return $pdata;
}

1;
1;
65 changes: 56 additions & 9 deletions src/MGRAST/lib/resources/pipeline.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ sub new {
# Add name / attributes
$self->{name} = "pipeline";
$self->{version} = '3.0';
$self->{attributes} = { data => [ 'list', ['object', 'workflow document'] ],
error => [ 'list', ['string', 'error that occured'] ],
status => [ 'int', 'http status code' ] };
$self->{attributes} = {
data => [ 'list', ['object', 'workflow document'] ],
error => [ 'list', ['string', 'error that occured'] ],
status => [ 'int', 'http status code' ]
};
return $self;
}

Expand All @@ -42,7 +44,8 @@ sub info {
'attributes' => "self",
'parameters' => { 'options' => {},
'required' => {},
'body' => {} } },
'body' => {} }
},
{ 'name' => "instance",
'request' => $self->cgi->url."/".$self->name."/{ID}",
'description' => "Returns a single job document.",
Expand All @@ -53,7 +56,8 @@ sub info {
'attributes' => $self->attributes,
'parameters' => { 'options' => {},
'required' => { "id" => ["string","unique object identifier"] },
'body' => {} } },
'body' => {} }
},
{ 'name' => "query",
'request' => $self->cgi->url."/".$self->name,
'description' => "Returns a set of data matching the query criteria.",
Expand All @@ -64,7 +68,21 @@ sub info {
'attributes' => $self->attributes,
'parameters' => { 'options' => {},
'required' => {},
'body' => {} } }
'body' => {} }
},
{ 'name' => "change",
'request' => $self->cgi->url."/".$self->name."/{ID}",
'description' => "Change the status of a job in the pipeline: these are admin functions",
'example' => [ 'curl -X GET -H "auth: admin_auth_key" "'.$self->cgi->url."/".$self->name.'/{job ID}?action=resume"',
"resume a suspended job in pipeline" ],
'method' => "GET",
'type' => "synchronous" ,
'attributes' => $self->attributes,
'parameters' => { 'options' => { "action" => [ "string", "action to be performed" ],
"level" => [ "int", "priority level to set if 'action=priority'"] },
'required' => { "id" => ["string","unique object identifier"] },
'body' => {} }
}
]
};
$self->return_data($content);
Expand Down Expand Up @@ -103,8 +121,34 @@ sub instance {
unless ($self->user->has_right(undef, 'view', 'metagenome', $job->{metagenome_id}) || $self->user->has_star_right('view', 'metagenome')) {
$self->return_data( {"ERROR" => "insufficient permissions to view this data"}, 401 );
}

# get awe jobs
my $data = $self->get_awe_query({'info.name' => [$job->{job_id}]}, $self->mgrast_token);

# get options
my $action = $self->cgi->param('action') || undef;
my $level = $self->cgi->param('level') || 1;

# admin action
if ($action && $self->user->is_admin('MGRAST')) {
# get non-deleted job document
my $awe_id = "";
foreach my $doc (@{$data->{data}}) {
unless ($doc->{state} eq 'deleted') {
$awe_id = $doc->{id};
last;
}
}
unless ($awe_id) {
$self->return_data( {"ERROR" => "No AWE job available for given id: ".$rest->[0]}, 404 );
}
if ($action eq 'priority') {
$data = $self->awe_job_action($awe_id, "priority=$level", $self->mgrast_token)
} else {
$data = $self->awe_job_action($awe_id, $action, $self->mgrast_token)
}
}

# return it
$self->return_data($data);
}

Expand All @@ -126,9 +170,12 @@ sub query {
if (scalar(keys %params) == 0) {
$self->return_data( {"ERROR" => "Missing query paramaters"}, 401 );
}
# other users data if admin
if ($self->user->is_admin('MGRAST') && exists($params{'info.user'})) {
# check for admin
if ($self->user->is_admin('MGRAST')) {
# check for user selection otherwise skip the info.user and get all
if (exists($params{'info.user'})) {
$params{'info.user'} = [ $self->user_id($params{'info.user'}) ];
}
}
# this users data
else {
Expand Down
23 changes: 21 additions & 2 deletions src/MGRAST/lib/resources/resource.pm
Original file line number Diff line number Diff line change
Expand Up @@ -760,12 +760,12 @@ sub get_shock_node {

# get the shock preauth url for a file
sub get_shock_preauth {
my ($self, $id, $auth) = @_;
my ($self, $id, $auth, $fn) = @_;

my $response = undef;
eval {
my @args = $auth ? ('Authorization', "OAuth $auth") : ();
my $get = $self->agent->get($Conf::shock_url.'/node/'.$id.'?download_url', @args);
my $get = $self->agent->get($Conf::shock_url.'/node/'.$id.'?download_url'.($fn ? "&filename=".$fn : ""), @args);
$response = $self->json->decode( $get->content );
};
if ($@ || (! ref($response))) {
Expand Down Expand Up @@ -856,6 +856,25 @@ sub post_awe_job {
}
}

# PUT command to perfrom action on a job
sub awe_job_action {
my ($self, $id, $action, $auth) = @_;

my $response = undef;
eval {
my @args = $auth ? ('Authorization', "OAuth $auth") : ();
my $req = POST($Conf::awe_url.'/job/'.$id.'?'.$action, @args);
$req->method('PUT');
my $put = $self->agent->request($req);
$response = $self->json->decode( $put->content );
};
if ($@ || (! ref($response))) {
$self->return_data( {"ERROR" => "Unable to PUT to AWE: ".$@}, 500 );
} else {
return $response;
}
}

# get list of jobs for query
sub get_awe_query {
my ($self, $params, $auth) = @_;
Expand Down