Skip to content

Commit 3b15dad

Browse files
committed
Finish out initial implementation.
1 parent a3a14f7 commit 3b15dad

File tree

5 files changed

+96
-4
lines changed

5 files changed

+96
-4
lines changed

AppService.spec

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ module AppService
3434
task_parameters parameters;
3535
} Task;
3636

37-
typedef mapping<string stage, string status> task_status;
37+
// typedef mapping<string stage, string status> task_status;
38+
typedef string task_status;
3839

3940
funcdef enumerate_apps()
4041
returns (list<App>);

awe

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ my $rest = REST::Client->new();
1818
$rest->addHeader("Authorization", "OAuth " . $token->token);
1919
my $url = "http://redwood:7080";
2020

21-
my $cur = $col->find({ "info.user" => "olson" });
21+
my $cur = $col->find({ '$and' => [ { "info.user" => "olson" }, { state => { '$ne' => "deleted" }} ] });
2222

2323
while (my $j = $cur->next)
2424
{
@@ -30,7 +30,7 @@ while (my $j = $cur->next)
3030
my $state = $j->{state};
3131

3232
next unless $user eq 'olson';
33-
print join("\t", $id, $user, $proj, $state, $start), "\n";
33+
print join("\t", $id, $user, $proj, $state, $start, $info->{priority}), "\n";
3434

3535
# $rest->DELETE("$url/job/$id");
3636

lib/Bio/KBase/AppService/AppServiceImpl.pm

+41-1
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ sub start_app
265265
user => $ctx->user_id,
266266
clientgroups => '',
267267
userattr => $userattr,
268+
priority => 2,
268269
);
269270

270271
my $shock = Bio::KBase::AppService::Shock->new($self->{shock_server}, $ctx->token);
@@ -375,6 +376,17 @@ sub query_task_status
375376
my $ctx = $Bio::KBase::AppService::Service::CallContext;
376377
my($status);
377378
#BEGIN query_task_status
379+
380+
my $awe = Bio::KBase::AppService::Awe->new($self->{awe_server}, $ctx->token);
381+
382+
$status = {};
383+
384+
for my $task_id (@$tasks)
385+
{
386+
my ($res, $error) = $awe->job_state($task_id);
387+
$status->{$task_id} = $res;
388+
}
389+
378390
#END query_task_status
379391
my @_bad_returns;
380392
(ref($status) eq 'HASH') or push(@_bad_returns, "Invalid type for return variable \"status\" (value was \"$status\")");
@@ -449,7 +461,35 @@ sub enumerate_tasks
449461
my($return);
450462
#BEGIN enumerate_tasks
451463

452-
464+
my $awe = Bio::KBase::AppService::Awe->new($self->{awe_server}, $ctx->token);
465+
466+
$return = [];
467+
468+
#
469+
# TODO: paging of requests
470+
#
471+
472+
my $q = "/job?query&info.user=" . $ctx->user_id . "&info.pipeline=AppService";
473+
print STDERR "Query tasks: $q\n";
474+
my ($res, $error) = $awe->GET($q);
475+
if ($res)
476+
{
477+
for my $t (@{$res->{data}})
478+
{
479+
my $u = $t->{info}->{userattr};
480+
my $r = {
481+
id => $t->{id},
482+
app => $u->{app_id},
483+
workspace => $u->{workspace},
484+
parameters => decode_json($u->{parameters}),
485+
};
486+
push(@$return, $r);
487+
}
488+
}
489+
else
490+
{
491+
die "Query failed: $error\n";
492+
}
453493

454494
#END enumerate_tasks
455495
my @_bad_returns;

lib/Bio/KBase/AppService/Awe.pm

+24
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,30 @@ sub submit
5959
}
6060
}
6161

62+
sub GET
63+
{
64+
my($self, $query) = @_;
65+
my $url = $self->server . "/$query";
66+
my $res = $self->ua->get($url, $self->auth_header());
67+
68+
if ($res->is_success)
69+
{
70+
my $awe_res = $self->json->decode($res->content);
71+
if ($awe_res->{status} eq 200)
72+
{
73+
return $awe_res;
74+
}
75+
else
76+
{
77+
return undef, $awe_res->{error};
78+
}
79+
}
80+
else
81+
{
82+
return undef, $res->content;
83+
}
84+
}
85+
6286
sub job_state
6387
{
6488
my($self, $job_id) = @_;

scripts/appserv-enumerate-tasks.pl

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use Bio::KBase::AppService::Client;
2+
use Getopt::Long::Descriptive;
3+
use strict;
4+
use Data::Dumper;
5+
6+
my($opt, $usage) = describe_options("%c %o",
7+
["url|u=s", "Service URL"],
8+
["help|h", "Show this help message"]);
9+
10+
print($usage->text), exit if $opt->help;
11+
print($usage->text), exit 1 if (@ARGV != 0);
12+
13+
my $client = Bio::KBase::AppService::Client->new($opt->url);
14+
15+
my $tasks = $client->enumerate_tasks();
16+
17+
my $mlab = 0;
18+
my $mid = 0;
19+
20+
my $status = $client->query_task_status([ map { $_->{id} } @$tasks ]);
21+
22+
for my $task (@$tasks)
23+
{
24+
25+
print join("\t", $task->{id}, $task->{app}, $task->{workspace}, $status->{$task->{id}}), "\n";
26+
}
27+

0 commit comments

Comments
 (0)