line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Grid::Request::HTC; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: HTC.pm 8365 2006-04-10 23:08:42Z vfelix $ |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
HTC.pm - Utilities and methods for the Grid::Request modules. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 DESCRIPTION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head2 Overview |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
This method provides several functions and methods that are |
14
|
|
|
|
|
|
|
useful to the Grid modules. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head2 Class and object methods |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=over 4 |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
2
|
|
157232
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
56
|
|
23
|
2
|
|
|
2
|
|
11
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
125
|
|
24
|
2
|
|
|
2
|
|
2400
|
use Config::IniFiles; |
|
2
|
|
|
|
|
87976
|
|
|
2
|
|
|
|
|
76
|
|
25
|
2
|
|
|
2
|
|
1983
|
use File::Which; |
|
2
|
|
|
|
|
2112
|
|
|
2
|
|
|
|
|
127
|
|
26
|
2
|
|
|
2
|
|
15
|
use Log::Log4perl qw(:easy :levels); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
21
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $logger = get_logger(__PACKAGE__); |
29
|
|
|
|
|
|
|
our ($config_section, $drm_param); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $worker_name = "grid_request_worker"; |
32
|
|
|
|
|
|
|
our $WORKER = which($worker_name); |
33
|
|
|
|
|
|
|
if (! defined $WORKER) { |
34
|
|
|
|
|
|
|
croak("No $worker_name found in the PATH.\n\n"); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
2
|
|
1721
|
use vars qw($config $client $server); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
713
|
|
38
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
if ($^W) { |
41
|
|
|
|
|
|
|
$VERSION = $VERSION; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
BEGIN { |
45
|
2
|
|
|
2
|
|
6
|
$config_section = "request"; |
46
|
2
|
|
|
|
|
4
|
$drm_param = "drm"; |
47
|
|
|
|
|
|
|
|
48
|
2
|
|
|
|
|
9
|
my $central_config = "$ENV{HOME}/.grid_request.conf"; |
49
|
|
|
|
|
|
|
|
50
|
2
|
50
|
|
|
|
9
|
$config = defined($ENV{GRID_CONFIG}) ? $ENV{GRID_CONFIG} : $central_config; |
51
|
2
|
50
|
33
|
|
|
47
|
if (-f $config && -r $config) { |
52
|
0
|
|
|
|
|
0
|
my $cfg = Config::IniFiles->new(-file => $config); |
53
|
0
|
0
|
|
|
|
0
|
if (! defined $cfg) { |
54
|
0
|
|
|
|
|
0
|
warn "There was a problem with the configuration file at $config\n"; |
55
|
0
|
|
|
|
|
0
|
warn "Is it a valid INI file with a [" . $config_section . "] section?\n"; |
56
|
0
|
|
|
|
|
0
|
exit 1; |
57
|
|
|
|
|
|
|
} |
58
|
0
|
|
|
|
|
0
|
my $drm = $cfg->val($config_section, $drm_param); |
59
|
0
|
0
|
|
|
|
0
|
if (! defined $drm) { |
60
|
0
|
|
|
|
|
0
|
warn "The config file does not define a '" . $drm_param . "' parameter.\n"; |
61
|
0
|
|
|
|
|
0
|
exit 1; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} else { |
64
|
2
|
|
|
|
|
328
|
warn "The config file $config does not exist or isn't readable.\n"; |
65
|
2
|
|
|
|
|
2491
|
exit 1; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
# Don't initialize if we have already done it... |
68
|
0
|
|
|
|
|
|
Log::Log4perl->easy_init($ERROR); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item $obj->new([%arg]); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
B This is the object contructor. A hash |
75
|
|
|
|
|
|
|
with arguments may be passed. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
B %arg. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
B $self, a blessed hash reference. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub new { |
84
|
|
|
|
|
|
|
my ($class, %arg) = @_; |
85
|
|
|
|
|
|
|
my $self = bless {}, ref($class) || $class; |
86
|
|
|
|
|
|
|
$self->_init(%arg); |
87
|
|
|
|
|
|
|
return $self; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item $obj->_init(); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
B _init in this class is an abstract method |
94
|
|
|
|
|
|
|
and is not implemented. In fact, it will die with an error |
95
|
|
|
|
|
|
|
message if you somehow call this method in this class. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
B None. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
B None. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub _init { |
104
|
|
|
|
|
|
|
$logger->logcroak("_init not implemented in this class.\n"); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub config { $config }; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item $obj->debug([$debug]); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
B The debug method allows the user to set or get |
112
|
|
|
|
|
|
|
the debug level. If an optional argument is sent, it will be used |
113
|
|
|
|
|
|
|
to set the debug level. The default level is "error". When passing a string |
114
|
|
|
|
|
|
|
debug level, case is ignored. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
B Optional integer argument to set debug level. The debug |
117
|
|
|
|
|
|
|
level can be either numeric or a string as follows: |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Name Code |
120
|
|
|
|
|
|
|
---- ---- |
121
|
|
|
|
|
|
|
DEBUG 5 |
122
|
|
|
|
|
|
|
INFO 4 |
123
|
|
|
|
|
|
|
WARN 3 |
124
|
|
|
|
|
|
|
ERROR 2 |
125
|
|
|
|
|
|
|
FATAL 1 |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
B The current debug level in numeric form. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub debug { |
132
|
|
|
|
|
|
|
$logger->debug("In debug."); |
133
|
|
|
|
|
|
|
my ($self, @args) = @_; |
134
|
|
|
|
|
|
|
if (scalar(@args)) { |
135
|
|
|
|
|
|
|
my $debug = uc($args[0]); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
my %levels = ( DEBUG => [5, $DEBUG], |
138
|
|
|
|
|
|
|
INFO => [4, $INFO], |
139
|
|
|
|
|
|
|
WARN => [3, $WARN], |
140
|
|
|
|
|
|
|
ERROR => [2, $ERROR], |
141
|
|
|
|
|
|
|
FATAL => [1, $FATAL] ); |
142
|
|
|
|
|
|
|
my %name_to_level = map { $_ => $levels{$_}->[1] } keys %levels; |
143
|
|
|
|
|
|
|
my %level_to_name = reverse ( |
144
|
|
|
|
|
|
|
map { $_ => $levels{$_}->[0] } keys %levels |
145
|
|
|
|
|
|
|
); |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# Anonymous subroutine. |
148
|
|
|
|
|
|
|
my $set_by_name = sub { |
149
|
|
|
|
|
|
|
my $level_string = shift; |
150
|
|
|
|
|
|
|
$logger->info("Setting new debug level to $level_string."); |
151
|
|
|
|
|
|
|
my $level = $name_to_level{$level_string}; |
152
|
|
|
|
|
|
|
$logger->level($level); |
153
|
|
|
|
|
|
|
# Set the debug level for the object. |
154
|
|
|
|
|
|
|
$self->{debug} = $levels{$level_string}->[0]; |
155
|
|
|
|
|
|
|
}; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
if (exists $levels{$debug}) { |
158
|
|
|
|
|
|
|
# If we have a named debug level. |
159
|
|
|
|
|
|
|
$set_by_name->($debug); |
160
|
|
|
|
|
|
|
} else { |
161
|
|
|
|
|
|
|
# We probably have a numbered debug level. |
162
|
|
|
|
|
|
|
if ( $debug !~ m/\D/ && $debug >= 1 && $debug <= 5) { |
163
|
|
|
|
|
|
|
$set_by_name->( $level_to_name{$debug} ); |
164
|
|
|
|
|
|
|
} else { |
165
|
|
|
|
|
|
|
$logger->error("\"$debug\" is an invalid debug level."); |
166
|
|
|
|
|
|
|
$set_by_name->("ERROR"); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
} else { # No arguments provided. Act like a simple accessor (getter). |
170
|
|
|
|
|
|
|
return $self->{debug}; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
1; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
__END__ |