| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package PkgForge::Handler; # -*-perl-*- |
|
2
|
1
|
|
|
1
|
|
1860
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
34
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
44
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# $Id: Handler.pm.in 21263 2012-07-03 14:26:32Z squinney@INF.ED.AC.UK $ |
|
6
|
|
|
|
|
|
|
# $Source:$ |
|
7
|
|
|
|
|
|
|
# $Revision: 21263 $ |
|
8
|
|
|
|
|
|
|
# $HeadURL: https://svn.lcfg.org/svn/source/tags/PkgForge-Server/PkgForge_Server_1_1_10/lib/PkgForge/Handler.pm.in $ |
|
9
|
|
|
|
|
|
|
# $Date: 2012-07-03 15:26:32 +0100 (Tue, 03 Jul 2012) $ |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.1.10'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
5
|
use File::Spec (); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
18
|
|
|
14
|
1
|
|
|
1
|
|
6
|
use Readonly; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
99
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Readonly my $CONFIGDIR => '/etc/pkgforge'; |
|
17
|
|
|
|
|
|
|
Readonly my $BASE_CONF => 'pkgforge.yml'; |
|
18
|
|
|
|
|
|
|
Readonly my $HANDLER_CONF => 'handlers.yml'; |
|
19
|
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
6
|
use Moose; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
12
|
|
|
21
|
1
|
|
|
1
|
|
7204
|
use MooseX::Types::Moose qw(Bool HashRef Str); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
12
|
|
|
22
|
1
|
|
|
1
|
|
6508
|
use PkgForge::Meta::Attribute::Trait::Directory; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
with 'MooseX::LogDispatch', 'PkgForge::ConfigFile', 'MooseX::Getopt'; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has '+configfile' => ( |
|
27
|
|
|
|
|
|
|
default => sub { |
|
28
|
|
|
|
|
|
|
my $class = shift @_; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my @files = ( |
|
31
|
|
|
|
|
|
|
File::Spec->catfile( $CONFIGDIR, $BASE_CONF ), |
|
32
|
|
|
|
|
|
|
File::Spec->catfile( $CONFIGDIR, $HANDLER_CONF ), |
|
33
|
|
|
|
|
|
|
); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $mod = ( split /::/, $class->meta->name )[-1]; |
|
36
|
|
|
|
|
|
|
my $mod_conf = lc($mod) . '.yml'; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
push @files, File::Spec->catfile( $CONFIGDIR, $mod_conf ); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
return \@files; |
|
41
|
|
|
|
|
|
|
}, |
|
42
|
|
|
|
|
|
|
); |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
has '+logger' => ( |
|
45
|
|
|
|
|
|
|
traits => ['NoGetopt'], |
|
46
|
|
|
|
|
|
|
); |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
has '+use_logger_singleton' => ( |
|
49
|
|
|
|
|
|
|
traits => ['NoGetopt'], |
|
50
|
|
|
|
|
|
|
); |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Logging Stuff |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
has 'debug' => ( |
|
55
|
|
|
|
|
|
|
is => 'ro', |
|
56
|
|
|
|
|
|
|
isa => Bool, |
|
57
|
|
|
|
|
|
|
default => 0, |
|
58
|
|
|
|
|
|
|
documentation => 'Log debug messages', |
|
59
|
|
|
|
|
|
|
); |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
has 'logconf' => ( |
|
62
|
|
|
|
|
|
|
is => 'ro', |
|
63
|
|
|
|
|
|
|
isa => 'Maybe[Str]', |
|
64
|
|
|
|
|
|
|
default => '/etc/pkgforge/log-default.cfg', |
|
65
|
|
|
|
|
|
|
predicate => 'has_logconf', |
|
66
|
|
|
|
|
|
|
documentation => 'The logging configuration file', |
|
67
|
|
|
|
|
|
|
); |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
has 'log_dispatch_conf' => ( |
|
70
|
|
|
|
|
|
|
traits => ['NoGetopt'], |
|
71
|
|
|
|
|
|
|
is => 'ro', |
|
72
|
|
|
|
|
|
|
lazy => 1, |
|
73
|
|
|
|
|
|
|
default => sub { |
|
74
|
|
|
|
|
|
|
my ($self) = @_; |
|
75
|
|
|
|
|
|
|
if ( $self->has_logconf && -f $self->logconf ) { |
|
76
|
|
|
|
|
|
|
return $self->logconf; |
|
77
|
|
|
|
|
|
|
} else { |
|
78
|
|
|
|
|
|
|
return { |
|
79
|
|
|
|
|
|
|
class => 'Log::Dispatch::Screen', |
|
80
|
|
|
|
|
|
|
min_level => $self->debug ? 'debug' : 'info', |
|
81
|
|
|
|
|
|
|
stderr => 1, |
|
82
|
|
|
|
|
|
|
format => '[%p] %m%n', |
|
83
|
|
|
|
|
|
|
}; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
}, |
|
86
|
|
|
|
|
|
|
documentation => 'The configuration for Log::Dispatch', |
|
87
|
|
|
|
|
|
|
); |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# Directories |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
has 'logdir' => ( |
|
92
|
|
|
|
|
|
|
is => 'ro', |
|
93
|
|
|
|
|
|
|
isa => Str, |
|
94
|
|
|
|
|
|
|
default => '/var/log/pkgforge', |
|
95
|
|
|
|
|
|
|
required => 1, |
|
96
|
|
|
|
|
|
|
documentation => 'The default directory for log files', |
|
97
|
|
|
|
|
|
|
); |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
has 'incoming' => ( |
|
100
|
|
|
|
|
|
|
traits => ['PkgForge::Directory'], |
|
101
|
|
|
|
|
|
|
is => 'ro', |
|
102
|
|
|
|
|
|
|
isa => Str, |
|
103
|
|
|
|
|
|
|
default => '/var/lib/pkgforge/incoming', |
|
104
|
|
|
|
|
|
|
required => 1, |
|
105
|
|
|
|
|
|
|
documentation => 'The directory for incoming build jobs', |
|
106
|
|
|
|
|
|
|
); |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
has 'accepted' => ( |
|
109
|
|
|
|
|
|
|
traits => ['PkgForge::Directory'], |
|
110
|
|
|
|
|
|
|
is => 'ro', |
|
111
|
|
|
|
|
|
|
isa => Str, |
|
112
|
|
|
|
|
|
|
default => '/var/lib/pkgforge/accepted', |
|
113
|
|
|
|
|
|
|
required => 1, |
|
114
|
|
|
|
|
|
|
documentation => 'The directory for accepted build jobs', |
|
115
|
|
|
|
|
|
|
); |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
has 'tmpdir' => ( |
|
118
|
|
|
|
|
|
|
traits => ['PkgForge::Directory'], |
|
119
|
|
|
|
|
|
|
is => 'ro', |
|
120
|
|
|
|
|
|
|
isa => Str, |
|
121
|
|
|
|
|
|
|
default => '/var/tmp/pkgforge', |
|
122
|
|
|
|
|
|
|
required => 1, |
|
123
|
|
|
|
|
|
|
documentation => 'A directory for temporary files', |
|
124
|
|
|
|
|
|
|
); |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
has 'results' => ( |
|
127
|
|
|
|
|
|
|
traits => ['PkgForge::Directory'], |
|
128
|
|
|
|
|
|
|
is => 'ro', |
|
129
|
|
|
|
|
|
|
isa => Str, |
|
130
|
|
|
|
|
|
|
default => '/var/lib/pkgforge/results', |
|
131
|
|
|
|
|
|
|
required => 1, |
|
132
|
|
|
|
|
|
|
documentation => 'The directory for build job results', |
|
133
|
|
|
|
|
|
|
); |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# Use this error log method as the logger eats $EVAL_ERROR if you are |
|
136
|
|
|
|
|
|
|
# not careful. |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub log_problem { |
|
139
|
|
|
|
|
|
|
my ( $self, $msg, $error ) = @_; |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
$self->logger->error($msg); |
|
142
|
|
|
|
|
|
|
if ($error) { |
|
143
|
|
|
|
|
|
|
$self->logger->error($error); |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
return; |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
no Moose; |
|
150
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
1; |
|
153
|
|
|
|
|
|
|
__END__ |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 NAME |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
PkgForge::Handler - A Moose class to be used by PkgForge handlers. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 VERSION |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
This documentation refers to PkgForge::Handler version 1.1.10 |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
package PkgForge::Handler::Foo; |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
use Moose; |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
extends 'PkgForge::Handler'; |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub execute { } |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This is a Moose class which pulls together all the common aspects of |
|
176
|
|
|
|
|
|
|
Package Forge handlers. A handler is a class which does a specific |
|
177
|
|
|
|
|
|
|
job, for example: accepting incoming jobs or firing off builds of |
|
178
|
|
|
|
|
|
|
accepted jobs. This class requires that the sub-class implements a |
|
179
|
|
|
|
|
|
|
method named C<execute> which actually does the work. |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
The following attributes will be part of any class which inherits from |
|
184
|
|
|
|
|
|
|
this class: |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=over |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item configfile |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
This is inherited from L<MooseX::ConfigFromFile> (via |
|
191
|
|
|
|
|
|
|
L<PkgForge::ConfigFile>), if specified it can be used to initialise |
|
192
|
|
|
|
|
|
|
the class via the C<new_with_config> method. It can be a string or a |
|
193
|
|
|
|
|
|
|
list of strings, each file should be a YAML file, see |
|
194
|
|
|
|
|
|
|
L<PkgForge::ConfigFile> for details. |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=item debug |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
A boolean value to control whether or not debugging messages are |
|
199
|
|
|
|
|
|
|
logged. The default is false. Note that when using a logging |
|
200
|
|
|
|
|
|
|
configuration file it is better to control the minimum log level |
|
201
|
|
|
|
|
|
|
through that file. |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item incoming |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
The directory into which incoming package forge jobs will be |
|
206
|
|
|
|
|
|
|
submitted. The default is C</var/lib/pkgforge/incoming> |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item accepted |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
The directory into which package forge jobs will be transferred if |
|
211
|
|
|
|
|
|
|
they are accepted as valid. The default is C</var/lib/pkgforge/accepted> |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=item results |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
The directory into which the results of finished package forge jobs |
|
216
|
|
|
|
|
|
|
will be stored. The default is C</var/lib/pkgforge/results>. |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=item logdir |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
The directory into which log files will be stored by default. The |
|
221
|
|
|
|
|
|
|
default path is C</var/log/pkgforge>. This attribute does not |
|
222
|
|
|
|
|
|
|
currently have any direct effect on where the log files are stored. It |
|
223
|
|
|
|
|
|
|
is solely provided so that the server initialisation script can ensure |
|
224
|
|
|
|
|
|
|
that the correct directory exists. |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=item logconf |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
The configuration file for the logging system. The default value is |
|
229
|
|
|
|
|
|
|
C</etc/pkgforge/log-default.cfg>. If this is not specified (i.e. set |
|
230
|
|
|
|
|
|
|
to undef) or does not exist then all messages will be logged directly |
|
231
|
|
|
|
|
|
|
to stderr. For servers that is almost certainly not what you want. See |
|
232
|
|
|
|
|
|
|
L<Log::Dispatch::Configurator::AppConfig> for details of the |
|
233
|
|
|
|
|
|
|
configuration file format. |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=item log_dispatch_conf |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
This is the configuration for L<Log::Dispatch>, see that module for |
|
238
|
|
|
|
|
|
|
documentation. Also See L<MooseX::LogDispatch>. You normally control |
|
239
|
|
|
|
|
|
|
this via the configuration file specified in the C<logconf> attribute. |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=item logger |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
This is a reference to the logger object, you can call methods such as |
|
244
|
|
|
|
|
|
|
C<debug> and C<error> on this object to log messages. See |
|
245
|
|
|
|
|
|
|
L<Log::Dispatch> and L<Log::Dispatch::Config> for full details. |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=back |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
A class which inherits from this class will have the following |
|
252
|
|
|
|
|
|
|
methods. This class also requires that the sub-class implements a |
|
253
|
|
|
|
|
|
|
method named C<execute> which actually does the work. |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=over |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=item new() |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
Create a new instance of the class. Optionally set some attributes by |
|
260
|
|
|
|
|
|
|
passing a hash as usual. |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=item new_with_config() |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
Create a new instance of the class with attributes set by either |
|
265
|
|
|
|
|
|
|
entries in the configuration file or the usual hash. See |
|
266
|
|
|
|
|
|
|
L<MooseX::ConfigFromFile> for details. |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=item log_problem( $msg, $error_string ) |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
The logger we are using has a tendency to eat the contents of the |
|
271
|
|
|
|
|
|
|
C<$EVAL_ERROR|$@> variable when it is called. This can make formatting |
|
272
|
|
|
|
|
|
|
error messages quite tricky. If you want your handler to print a |
|
273
|
|
|
|
|
|
|
message on one line and then add any message that might be in |
|
274
|
|
|
|
|
|
|
C<$EVAL_ERROR> on a following line then use this method. Underneath it |
|
275
|
|
|
|
|
|
|
will use the C<error> method of the logger. |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=back |
|
278
|
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
By default Package Forge handlers can be configured via the YAML file |
|
282
|
|
|
|
|
|
|
C</etc/pkgforge/handlers.yml> This can be overridden by any handler |
|
283
|
|
|
|
|
|
|
class so also see the documentation for the specific class. |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
By default, the logging system can be configured via |
|
286
|
|
|
|
|
|
|
C</etc/pkgforge/default.log>. If the file does not exist then the |
|
287
|
|
|
|
|
|
|
handler will log to stderr. |
|
288
|
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
|
290
|
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
This module is powered by L<Moose> and uses L<MooseX::ConfigFromFile>, |
|
292
|
|
|
|
|
|
|
L<MooseX::LogDispatch> and L<MooseX::Types>. |
|
293
|
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
L<PkgForge> |
|
297
|
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
=head1 PLATFORMS |
|
299
|
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
This is the list of platforms on which we have tested this |
|
301
|
|
|
|
|
|
|
software. We expect this software to work on any Unix-like platform |
|
302
|
|
|
|
|
|
|
which is supported by Perl. |
|
303
|
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
ScientificLinux5, Fedora13 |
|
305
|
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
|
307
|
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
Please report any bugs or problems (or praise!) to bugs@lcfg.org, |
|
309
|
|
|
|
|
|
|
feedback and patches are also always very welcome. |
|
310
|
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=head1 AUTHOR |
|
312
|
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
Stephen Quinney <squinney@inf.ed.ac.uk> |
|
314
|
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
316
|
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
Copyright (C) 201O University of Edinburgh. All rights reserved. |
|
318
|
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
320
|
|
|
|
|
|
|
it under the terms of the GPL, version 2 or later. |
|
321
|
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
=cut |