[Bio] / FortyEight / WebPage / JobDebugger.pm Repository:
ViewVC logotype

Annotation of /FortyEight/WebPage/JobDebugger.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (view) (download) (as text)

1 : paarmann 1.1 package WebPage::JobDebugger;
2 :    
3 :     use warnings;
4 :     use strict;
5 :    
6 :     use Carp qw( confess );
7 : paarmann 1.2 use base qw( WebApp::WebPage );
8 : paarmann 1.1
9 :     use POSIX;
10 :     use File::Basename;
11 :    
12 :     use Job48;
13 :    
14 :     =pod
15 :    
16 :     =head1 NAME
17 :    
18 :     JobDebugger - an instance of WebPage which displays debug information on a job
19 :    
20 :     =head1 DESCRIPTION
21 :    
22 :     TODO
23 :    
24 :     =head1 METHODS
25 :    
26 :     =over 4
27 :    
28 :     =item * B<output> ()
29 :    
30 :     Returns the html output of the page.
31 :    
32 :     =cut
33 :    
34 :     sub output {
35 :     my ($self) = @_;
36 :    
37 :     my $cgi = $self->application->cgi;
38 :     my $content = '';
39 :    
40 :     # check if a user is logged in and admin
41 :     if ($self->application->authorized(2)) {
42 :    
43 :     # delete the job?
44 :     if ($cgi->param('action') and $cgi->param('action') eq 'delete') {
45 :     $self->title('Annotation Server - Delete Job #'.$cgi->param('job'));
46 :     $content = $self->delete_job( $cgi->param('job') );
47 :     }
48 :     else {
49 :     $self->title('Annotation Server - Debug Job #'.$cgi->param('job'));
50 :     $content = $self->debug( $cgi->param('job') );
51 :     }
52 :    
53 :     }
54 :     else {
55 :     $self->application->error('Not authorized to access jobs in debug mode.');
56 :     }
57 :    
58 :     # catch errors
59 :     if ($self->application->error) {
60 :     $content = "<p>An error has occured: ".$self->application->error().
61 :     "<br/>Please return to the <a href='".$self->application->url."?page=Login'>login page</a>.</p>";
62 :     }
63 :    
64 :     return $content;
65 :     }
66 :    
67 :    
68 :     sub debug {
69 :     my ($self, $id) = @_;
70 :    
71 :     my $content = '';
72 :     my $cgi = $self->application->cgi;
73 :    
74 :     # sanity check on job
75 :     my $job = Job48->new( $id );
76 :     unless ($job) {
77 :     $self->application->error("Invalid job id given (id='$id').");
78 :     return $content;
79 :     }
80 :    
81 :     $content = "<h1>Debug Job #$id</h1>";
82 :     $content .= "<p> &raquo <a href='".$self->application->url."?page=Jobs'>Back to the Jobs Overview</a></p>";
83 :     $content .= "<p> &raquo <a href='".$self->application->url."?page=JobDetails&job=".
84 :     $id."'>Back to the Job Details</a></p>";
85 :     $content .= "<p>&nbsp;</p>";
86 :     $content .= "<p> &raquo <a href='".$self->application->url."?page=JobDebugger&action=delete&job=$id'>Delete this job</a></p>";
87 :    
88 :     $content .= "<p id='section_bar'><img src='./Html/48-info.png'/>Job Information</p>";
89 :     $content .= "<table>";
90 :     $content .= "<tr><th>Genome:</th><td>".$job->genome_id." - ".$job->genome_name."</td></tr>";
91 :     $content .= "<tr><th>Meta Genome:</th><td>".$job->metagenome."</td></tr>";
92 :     $content .= "<tr><th>Job:</th><td> #".$id."</td></tr>";
93 :     $content .= "<tr><th>Directory:</th><td>".$job->dir."</td></tr>";
94 :     $content .= "<tr><th>User:</th><td>".$job->user."</td></tr>";
95 :     $content .= "<tr><th>Active:</th><td>".$job->active."</td></tr>";
96 :     $content .= "<tr><th>To be deleted:</th><td>".$job->to_be_deleted."</td></tr>";
97 :     $content .= "</table>";
98 :    
99 :     my $job_dir = $job->dir;
100 :     my $org_dir = $job->orgdir;
101 :     my @stderr_files = <$job_dir/rp.errors/*.stderr>;
102 :     push(@stderr_files, <$org_dir/*.report>);
103 :    
104 :     my @pairs = map { my @a = stat($_); [$_, $a[9]] } @stderr_files;
105 :     @stderr_files = map { $_->[0] } sort { $a->[1] <=> $b->[1] } @pairs;
106 :    
107 :     $content .= "<p id='section_bar'><img src='./Html/48-info.png'/>Error Reports</p>";
108 :     $content .= "<table>";
109 :     for my $sf (@stderr_files) {
110 :     my $b = basename($sf);
111 :     my $url = $self->application->url."?page=JobDebugger&job=$id&file=$b#report";
112 :     my $link = "<a href='$url'>$b</a>";
113 :     $content .= "<tr><td>$link</td></tr>";
114 :     }
115 :     $content .= "</table>";
116 :    
117 :    
118 :     if ($cgi->param('file')) {
119 :     my $file = $cgi->param('file');
120 :     $content .= "<p id='section_bar'><img src='./Html/48-info.png'/><a id='report'>Report</a>: $file</p>";
121 :    
122 :     $content .= "<p> &raquo <a href='".$self->application->url."?page=JobDebugger&job=".
123 :     $id."'>Hide this error report</a></p>";
124 :    
125 :     my $path = $job->orgdir."/$file";
126 :     -f $path or $path = $job->dir."/rp.errors/$file";
127 :    
128 :     if (open(F, "<$path")) {
129 :     $content .= "<pre>\n";
130 :     my @fc = <F>;
131 :     $content .= join('',@fc);
132 :     $content .= "</pre>\n";
133 :     close(F);
134 :     }
135 :     else {
136 :     $content .= "File $file not found in job $id\n";
137 :     }
138 :     }
139 :    
140 :     $content .= "<p id='section_bar'><img src='./Html/48-info.png'/>MetaXML Dump</p>";
141 :     $content .= "<table>";
142 :     for my $key (sort $job->meta->get_metadata_keys()) {
143 :     my $value = $job->meta->get_metadata($key);
144 :     if (ref($value) eq 'ARRAY') {
145 :     $value = join(', ',@$value);
146 :     }
147 :     $value = '' unless (defined $value);
148 :     $content .= "<tr><th>".$key."</th><td>".$value."</td></tr>";
149 :     }
150 :     $content .= "</table>";
151 :    
152 :     $content .= "<p id='section_bar'><img src='./Html/48-info.png'/>MetaXML Log</p>";
153 :     $content .= "<table>";
154 :     for my $ent (@{$job->meta->get_log()}) {
155 :     my ($type, $ltype, $ts, $entry) = @$ent;
156 :     next unless $type eq 'log_entry';
157 :     $ts = strftime('%c', localtime $ts);
158 :     $ltype =~ s,.*/,,;
159 :     $entry = join('&nbsp;&nbsp; || &nbsp;&nbsp;',@$entry) if (ref($entry) eq 'ARRAY');
160 :     $content .= "<tr><th>".$ts."</th><th>".$ltype."</th><td>".$entry."</td></tr>";
161 :     }
162 :     $content .= "</table>";
163 :    
164 :     return $content;
165 :    
166 :     }
167 :    
168 :    
169 :     sub delete_job {
170 :     my ($self, $id) = @_;
171 :    
172 :     # sanity check on job
173 :     my $job = Job48->new( $id );
174 :     unless ($job and $job->active) {
175 :     $self->application->error("Invalid job id given (id='$id').");
176 :     return;
177 :     }
178 :    
179 :     my $content = "<h1>Deleting Job #$id</h1>";
180 :     $content .= '<p>This job is now scheduled for deletion.</p>';
181 :     $content .= "<p> &raquo <a href='".$self->application->url."?page=Jobs'>Back to the Jobs Overview</a></p>";
182 :    
183 :     open(DEL, '>'.$job->dir.'/DELETE')
184 :     or die "Cannot create file in ".$job->dir;
185 :     close(DEL);
186 :     unlink ($job->dir.'/ACTIVE');
187 :    
188 :     $job->meta->add_log_entry('genome', 'Job scheduled for deletion by user '.$self->application->session->user->login.'.');
189 :    
190 :     return $content;
191 :     }
192 :    
193 :    
194 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3