Skip to content

Commit b1c8ba6

Browse files
committed
Add awe debugging support.
1 parent 3d24bc8 commit b1c8ba6

File tree

6 files changed

+175
-1
lines changed

6 files changed

+175
-1
lines changed

Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ compile-typespec: Makefile
7171

7272
bin: $(BIN_PERL) $(BIN_SERVICE_PERL)
7373

74+
#
75+
# Manually run this to update the AweEvents module.
76+
#
77+
log-events:
78+
perl make-log-events-data.pl > lib/Bio/KBase/AppService/AweEvents.pm
79+
7480
deploy: deploy-client deploy-service
7581
deploy-all: deploy-client deploy-service
7682
deploy-client: compile-typespec deploy-docs deploy-libs deploy-scripts

lib/Bio/KBase/AppService/AweEvents.pm

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
package Bio::KBase::AppService::AweEvents;
3+
use strict;
4+
5+
our %events = (
6+
CR => ['CLIENT_REGISTRATION', 'client registered (for the first time)'],
7+
CA => ['CLIENT_AUTO_REREGI', 'client automatically re-registered'],
8+
CU => ['CLIENT_UNREGISTER', 'client unregistered'],
9+
WC => ['WORK_CHECKOUT', 'workunit checkout'],
10+
WF => ['WORK_FAIL', 'workunit fails running'],
11+
SS => ['SERVER_START', 'awe-server start'],
12+
SR => ['SERVER_RECOVER', 'awe-server start with recover option (-recover)'],
13+
JQ => ['JOB_SUBMISSION', 'job submitted'],
14+
TQ => ['TASK_ENQUEUE', 'task parsed and enqueue'],
15+
WD => ['WORK_DONE', 'workunit received successful feedback from client'],
16+
WR => ['WORK_REQUEUE', 'workunit requeue after receive failed feedback from client'],
17+
WP => ['WORK_SUSPEND', 'workunit suspend after failing for conf.Max_Failure times'],
18+
TD => ['TASK_DONE', 'task done (all the workunits in the task have finished)'],
19+
TS => ['TASK_SKIPPED', 'task skipped (skip option > 0)'],
20+
JD => ['JOB_DONE', 'job done (all the tasks in the job have finished)'],
21+
JP => ['JOB_SUSPEND', 'job suspended'],
22+
JL => ['JOB_DELETED', 'job deleted'],
23+
WS => ['WORK_START', 'workunit command start running'],
24+
WE => ['WORK_END', 'workunit command finish running'],
25+
WR => ['WORK_RETURN', 'send back failed workunit to server'],
26+
WI => ['WORK_DISCARD', 'workunit discarded after receiving discard signal from server'],
27+
PS => ['PRE_WORK_START', 'workunit command start running'],
28+
PE => ['PRE_WORK_END', 'workunit command finish running'],
29+
FI => ['FILE_IN', 'start fetching input file from shock'],
30+
FR => ['FILE_READY', 'finish fetching input file from shock'],
31+
FO => ['FILE_OUT', 'start pushing output file to shock'],
32+
FD => ['FILE_DONE', 'finish pushing output file to shock'],
33+
AI => ['ATTR_IN', 'start fetching input attributes from shock'],
34+
AR => ['ATTR_READY', 'finish fetching input attributes from shock'],
35+
WQ => ['WORK_QUEUED', 'workunit queued at proxy'],
36+
);
37+
1;

lib/Bio/KBase/AppService/Shock.pm

+17
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,23 @@ sub get_file
5555
return $self->rest->responseContent();
5656
}
5757

58+
sub get_node
59+
{
60+
my($self, $node) = @_;
61+
62+
if ($node !~ /^http/)
63+
{
64+
$node = $self->server . "/node/$node";
65+
}
66+
my $res = $self->rest->GET($node);
67+
if ($self->rest->responseCode != 200)
68+
{
69+
die "get_node failed: " . $self->rest->responseContent();
70+
}
71+
my $obj = $self->json->decode($self->rest->responseContent());
72+
return $obj->{data};
73+
}
74+
5875
sub put_file
5976
{
6077
my($self, $file) = @_;

lib/javascript/AppService/Client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function AppService(url, auth, auth_cb) {
1818
}
1919

2020
if (typeof(_url) != "string" || _url.length == 0) {
21-
_url = "https://kbase.us/services/app_service";
21+
_url = "http://p3.theseed.org/services/app_service";
2222
}
2323
var _auth = auth ? auth : { 'token' : '', 'user_id' : ''};
2424
var _auth_cb = auth_cb;

make-log-events-data.pl

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use strict;
2+
3+
my $url = 'https://raw.githubusercontent.com/MG-RAST/AWE/master/lib/logger/event/event.go';
4+
5+
open(P, "-|", "curl", $url) or die $!;
6+
7+
8+
print <<'END';
9+
10+
package Bio::KBase::AppService::AweEvents;
11+
use strict;
12+
13+
our %events = (
14+
END
15+
16+
while (<P>)
17+
{
18+
if (m,^\s+(\S+)\s+=\s+"([A-Z][A-Z])".*//(.*),)
19+
{
20+
print "$2 => ['$1', '$3'],\n";
21+
}
22+
}
23+
print ");\n";
24+
print "1;\n";

scripts/appserv-debug-task.pl

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
use Bio::KBase::AppService::Client;
2+
use Bio::KBase::AppService::Shock;
3+
use Bio::KBase::AppService::Awe;
4+
use Bio::KBase::AppService::AweEvents;
5+
use Bio::KBase::AuthToken;
6+
use Getopt::Long::Descriptive;
7+
use strict;
8+
use Data::Dumper;
9+
use JSON::XS;
10+
use File::Slurp;
11+
12+
my($opt, $usage) = describe_options("%c %o task-id",
13+
["url|u=s", "Service URL"],
14+
["help|h", "Show this help message"]);
15+
16+
print($usage->text), exit if $opt->help;
17+
print($usage->text), exit 1 if (@ARGV != 1);
18+
19+
my $token = Bio::KBase::AuthToken->new;
20+
21+
22+
#
23+
# TODO get this from configs
24+
#
25+
my $awe_server = "http://redwood.mcs.anl.gov:7080";
26+
my $awe_root = "/disks/awe";
27+
my $awe_logs = "$awe_root/logs";
28+
29+
my $json = JSON::XS->new->pretty(1);
30+
31+
my $shock = Bio::KBase::AppService::Shock->new(undef, $token->token);
32+
my $awe = Bio::KBase::AppService::Awe->new($awe_server, $token->token);
33+
34+
my $client = Bio::KBase::AppService::Client->new($opt->url);
35+
36+
my $task_id = shift;
37+
38+
my @tasks = ($task_id);
39+
40+
my $res = $client->query_tasks(\@tasks);
41+
42+
my $task_info = $res->{$task_id};
43+
44+
print Dumper($task_info);
45+
46+
my $stderr_node = $shock->get_node($task_info->{stderr_shock_node});
47+
print "Stderr: " . $json->encode($stderr_node);
48+
print '-' x 40 . "\n";
49+
50+
my $stdout_node = $shock->get_node($task_info->{stdout_shock_node});
51+
print "Stdout: " . $json->encode($stdout_node);
52+
print '-' x 40 . "\n";
53+
54+
my $awe_job = $awe->job($task_id);
55+
print "AWE job: " . $json->encode($awe_job);
56+
print '-' x 40 . "\n";
57+
#
58+
# Find the relevant events.
59+
#
60+
61+
for my $log (<$awe_logs/*/event.log>)
62+
{
63+
open(E, "<", $log) or warn "Cannot open $log: $!";
64+
65+
my $printed = 0;
66+
my $qtask_id = quotemeta($task_id);
67+
while (<E>)
68+
{
69+
if (/$qtask_id/)
70+
{
71+
if (!$printed)
72+
{
73+
print "\n$log\n";
74+
$printed = 1;
75+
}
76+
my($date, $level, $code, $rest) = parse_event($_);
77+
my $event_info = $Bio::KBase::AppService::AweEvents::events{$code};
78+
my @details = map { s/=/\t/; $_ } split(/;/, $rest);
79+
print "$event_info->[0]\t$date\n";
80+
print "\t$_\n" foreach @details;
81+
}
82+
}
83+
}
84+
85+
sub parse_event
86+
{
87+
my ($x) = @_;
88+
return $x =~ /^\[([^]]+)\]\s+\[([^]]+)\]\s+([A-Z][A-Z]);(.*)/
89+
}
90+

0 commit comments

Comments
 (0)