line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Helios::JobType; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
14
|
use 5.008; |
|
1
|
|
|
|
|
2
|
|
4
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
6
|
1
|
|
|
1
|
|
4
|
use TheSchwartz::FuncMap; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
19
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
3
|
use Helios::Config; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
16
|
|
9
|
1
|
|
|
1
|
|
317
|
use Helios::ObjectDriver; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
10
|
1
|
|
|
1
|
|
4
|
use Helios::Error; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
14
|
|
11
|
1
|
|
|
1
|
|
3
|
use Helios::Error::JobTypeError; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '2.80'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Helios::JobType - class to represent Helios jobtypes |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# use the lookup() class method to retrieve jobtypes |
22
|
|
|
|
|
|
|
# from the Helios collective database |
23
|
|
|
|
|
|
|
my $jobtype = Helios::JobType->lookup(name => 'Helios::TestService'); |
24
|
|
|
|
|
|
|
--OR-- |
25
|
|
|
|
|
|
|
my $jobtype = Helios::JobType->lookup(jobtypeid => 1); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
print "Name: ", $jobtype->getName, " Jobtypeid: ", $jobtype->getJobtypeid,"\n"; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# use new() and create() to create new jobtypes |
30
|
|
|
|
|
|
|
my $newtype = Helios::JobType->new( name => 'NewJobType' ); |
31
|
|
|
|
|
|
|
$newtype->create(); |
32
|
|
|
|
|
|
|
print "Created jobtype ",$newtype->getJobtypeid,"\n"; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 DESCRIPTION |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Objects of the Helios::JobType class represent jobtypes in the Helios job |
38
|
|
|
|
|
|
|
processing system. Every job has a jobtype, which is roughly analogous to the |
39
|
|
|
|
|
|
|
queue a job is in. Usually, a jobtype's name is the same as the Helios service |
40
|
|
|
|
|
|
|
that will be running the job, in effect creating a single queue for each Helios |
41
|
|
|
|
|
|
|
service. In certain advanced configurations, Helios services can be |
42
|
|
|
|
|
|
|
configured to service jobs of several jobtypes. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 ACCESSOR METHODS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
set/getName name of the jobtype in the Helios database |
47
|
|
|
|
|
|
|
set/getJobtypeid jobtypeid in the Helios database |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
set/getConfig config hash to use |
50
|
|
|
|
|
|
|
set/getDriver Data::ObjectDriver to Helios database |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
0
|
0
|
|
sub debug { defined($_[1]) ? $_[0]->{debug} = $_[1] : return $_[0]->{debug} } |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub setName { |
57
|
0
|
|
|
0
|
0
|
|
$_[0]->{name} = $_[1]; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
sub getName { |
60
|
0
|
|
|
0
|
0
|
|
return $_[0]->{name}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub setJobtypeid { |
64
|
0
|
|
|
0
|
0
|
|
$_[0]->{jobtypeid} = $_[1]; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
sub getJobtypeid { |
67
|
0
|
|
|
0
|
0
|
|
return $_[0]->{jobtypeid}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub setConfig { |
71
|
0
|
|
|
0
|
0
|
|
$_[0]->{config} = $_[1]; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
sub getConfig { |
74
|
0
|
|
|
0
|
0
|
|
return $_[0]->{config}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub setDriver { |
78
|
0
|
|
|
0
|
0
|
|
$_[0]->{driver} = $_[1]; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
sub getDriver { |
81
|
0
|
|
|
0
|
0
|
|
initDriver(@_); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
sub initDriver { |
84
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
85
|
0
|
|
|
|
|
|
my $d = Helios::ObjectDriver->getDriver(@_); |
86
|
0
|
|
|
|
|
|
$self->setDriver($d); |
87
|
0
|
|
|
|
|
|
return $d; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 OBJECT INITIALIZATION |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 new([name => $jobtypename][, config => $config_hashref][, driver => $driver_obj][, obj => $elemental_obj]) |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Creates a new Helios::JobType object. If parameters are passed, calls init() |
95
|
|
|
|
|
|
|
with those parameters to initialize the object's values. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub new { |
100
|
0
|
|
|
0
|
1
|
|
my $cl = shift; |
101
|
0
|
|
|
|
|
|
my $self = { |
102
|
|
|
|
|
|
|
jobtypeid => undef, |
103
|
|
|
|
|
|
|
name => undef, |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
_obj => undef, |
106
|
|
|
|
|
|
|
debug => undef, |
107
|
|
|
|
|
|
|
driver => undef, |
108
|
|
|
|
|
|
|
config => undef, |
109
|
|
|
|
|
|
|
}; |
110
|
0
|
|
|
|
|
|
bless $self, $cl; |
111
|
0
|
0
|
|
|
|
|
$self->init(@_) if @_; |
112
|
0
|
|
|
|
|
|
return $self; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 init() |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
If any parameters are passed to new(), init() will be called to further |
119
|
|
|
|
|
|
|
initialize the object. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub init { |
124
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
125
|
0
|
|
|
|
|
|
my %params = @_; |
126
|
|
|
|
|
|
|
# populate any params we were given |
127
|
0
|
|
|
|
|
|
$self->{debug} = $params{debug}; |
128
|
0
|
|
|
|
|
|
$self->{name} = $params{name}; |
129
|
0
|
|
|
|
|
|
$self->{jobtypeid} = $params{jobtypeid}; |
130
|
0
|
|
|
|
|
|
$self->{driver} = $params{driver}; |
131
|
0
|
|
|
|
|
|
$self->{config} = $params{config}; |
132
|
|
|
|
|
|
|
# if we were given an elemental object, inflate our object from it |
133
|
|
|
|
|
|
|
# otherwise, our init() is done |
134
|
0
|
0
|
|
|
|
|
if ($params{obj}) { |
135
|
0
|
|
|
|
|
|
return $self->_inflate($params{obj}); |
136
|
|
|
|
|
|
|
} else { |
137
|
0
|
|
|
|
|
|
return $self; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 _inflate() |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
If an elemental object is passed to new() or init() using the 'obj' parameter, |
145
|
|
|
|
|
|
|
_inflate() will be called to expand the elemental object into the full Helios |
146
|
|
|
|
|
|
|
object. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Helios::JobType objects can be inflated from TheSchwartz::FuncMap objects. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub _inflate { |
153
|
0
|
|
|
0
|
|
|
my $self = shift; |
154
|
0
|
|
|
|
|
|
my $obj = shift; |
155
|
|
|
|
|
|
|
# we were given an object to inflate from |
156
|
0
|
|
|
|
|
|
$self->{_obj} = $obj; |
157
|
0
|
|
|
|
|
|
$self->{name} = $obj->funcname(); |
158
|
0
|
|
|
|
|
|
$self->{jobtypeid} = $obj->funcid(); |
159
|
0
|
|
|
|
|
|
return $self; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 CLASS METHODS |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 lookup([name => $name]|[jobtypeid => $jobtypeid]) |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Given either a jobtype name or jobtypeid, the lookup method will attempt to |
168
|
|
|
|
|
|
|
find a jobtype matching that criteria in the collective database and returns a |
169
|
|
|
|
|
|
|
Helios::JobType object representing that jobtype to the calling routine. If a |
170
|
|
|
|
|
|
|
matching jobtype is not found, undef is returned. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
THROWS: Helios::Error::JobTypeError if a problem occurs querying the Helios |
173
|
|
|
|
|
|
|
database. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub lookup { |
178
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
179
|
0
|
|
|
|
|
|
my %params = @_; |
180
|
0
|
|
|
|
|
|
my $jobtypeid = $params{jobtypeid}; |
181
|
0
|
|
|
|
|
|
my $name = $params{name}; |
182
|
0
|
|
|
|
|
|
my $config = $params{config}; |
183
|
0
|
|
0
|
|
|
|
my $debug = $params{debug} || 0; |
184
|
0
|
|
|
|
|
|
my $drvr; |
185
|
|
|
|
|
|
|
my $obj; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
# throw an error if we don't have either name or jobtypeid |
188
|
0
|
0
|
0
|
|
|
|
unless ($params{jobtypeid} || $params{name}) { |
189
|
0
|
|
|
|
|
|
Helios::Error::JobTypeError->throw('lookup(): Either a jobtypeid or name is required.'); |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
eval { |
193
|
0
|
|
|
|
|
|
$drvr = Helios::ObjectDriver->getDriver(config => $config); |
194
|
0
|
0
|
|
|
|
|
if ($jobtypeid) { |
195
|
|
|
|
|
|
|
# use $jobtypeid! |
196
|
0
|
|
|
|
|
|
$obj = $drvr->lookup('TheSchwartz::FuncMap' => $jobtypeid); |
197
|
|
|
|
|
|
|
} else { |
198
|
|
|
|
|
|
|
# use name |
199
|
0
|
|
|
|
|
|
my $itr = $drvr->search('TheSchwartz::FuncMap' => {funcname => $name}); |
200
|
0
|
|
|
|
|
|
$obj = $itr->next(); |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
0
|
|
|
|
|
|
1; |
204
|
0
|
0
|
|
|
|
|
} or do { |
205
|
0
|
|
|
|
|
|
my $E = $@; |
206
|
0
|
|
|
|
|
|
Helios::Error::JobTypeError->throw('lookup(): '."$E"); |
207
|
|
|
|
|
|
|
}; |
208
|
|
|
|
|
|
|
|
209
|
0
|
0
|
|
|
|
|
if (defined($obj)) { |
210
|
|
|
|
|
|
|
# we found it! |
211
|
0
|
|
|
|
|
|
return Helios::JobType->new( |
212
|
|
|
|
|
|
|
obj => $obj, |
213
|
|
|
|
|
|
|
driver => $drvr, |
214
|
|
|
|
|
|
|
config => Helios::ObjectDriver->getConfig(), |
215
|
|
|
|
|
|
|
debug => $debug, |
216
|
|
|
|
|
|
|
); |
217
|
|
|
|
|
|
|
} else { |
218
|
|
|
|
|
|
|
# we didn't find it |
219
|
0
|
|
|
|
|
|
return undef; |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 OBJECT METHODS |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head2 create([name => $name]) |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
Given a jobtype name, create() creates a jobtype with that name in the Helios |
229
|
|
|
|
|
|
|
collective database and returns the new jobtype's jobtypeid. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
If the jobtype's name is not specified, the value returned by getName() will be |
232
|
|
|
|
|
|
|
used. |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
THROWS: Helios::Error::JobTypeError if the JobType creation fails. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=cut |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
sub create { |
239
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
240
|
0
|
|
|
|
|
|
my %params = @_; |
241
|
0
|
|
0
|
|
|
|
my $name = $params{name} || $self->getName(); |
242
|
0
|
|
0
|
|
|
|
my $config = $params{config} || $self->getConfig(); |
243
|
0
|
|
|
|
|
|
my $id; |
244
|
|
|
|
|
|
|
my $obj; |
245
|
|
|
|
|
|
|
|
246
|
0
|
0
|
|
|
|
|
unless ($name) { |
247
|
0
|
|
|
|
|
|
Helios::Error::JobTypeError->throw('create(): A jobtype name is required to create a jobtype.'); |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
eval { |
251
|
0
|
|
|
|
|
|
my $drvr = $self->getDriver(config => $config); |
252
|
0
|
|
|
|
|
|
$obj = TheSchwartz::FuncMap->new( funcname => $name); |
253
|
0
|
|
|
|
|
|
$drvr->insert($obj); |
254
|
0
|
|
|
|
|
|
1; |
255
|
0
|
0
|
|
|
|
|
} or do { |
256
|
0
|
|
|
|
|
|
my $E = $@; |
257
|
0
|
|
|
|
|
|
Helios::Error::JobTypeError->throw("create(): $E"); |
258
|
|
|
|
|
|
|
}; |
259
|
|
|
|
|
|
|
# use the new TheSchwartz::FuncMap object to (re)inflate $self |
260
|
0
|
|
|
|
|
|
$self->_inflate($obj); |
261
|
|
|
|
|
|
|
# the calling routine expects to receive the jobtypeid |
262
|
0
|
|
|
|
|
|
return $self->getJobtypeid; |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=head2 remove() |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
The remove() method deletes a jobtype from the Helios collective database. |
269
|
|
|
|
|
|
|
It returns 1 if successful and throws a Helios::Error::JobTypeError if the |
270
|
|
|
|
|
|
|
removal operation fails. |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
USE WITH CAUTION. All Helios jobs, both enqueued and completed, have an |
273
|
|
|
|
|
|
|
associated jobtype, and removing a jobtype that still has associated jobs in |
274
|
|
|
|
|
|
|
the system will have unintended consequences! |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
THROWS: Helios::Error::JobTypeError if the removal operation fails. |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=cut |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
sub remove { |
281
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
282
|
0
|
|
|
|
|
|
my $jobtypeid = $self->getJobtypeid; |
283
|
0
|
|
|
|
|
|
my $drvr; |
284
|
|
|
|
|
|
|
my $r; |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
# we actually need the FuncMap object here, because we're going to use |
287
|
|
|
|
|
|
|
# D::OD to do the delete operation. |
288
|
0
|
0
|
0
|
|
|
|
unless ($self->{_obj} && $jobtypeid) { |
289
|
0
|
|
|
|
|
|
Helios::Error::JobTypeError->throw('remove(): Helios::JobType object was not properly initialized; cannot remove.'); |
290
|
|
|
|
|
|
|
} |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
eval { |
293
|
0
|
|
|
|
|
|
$drvr = $self->getDriver(); |
294
|
0
|
|
|
|
|
|
$drvr->remove($self->{_obj}); |
295
|
|
|
|
|
|
|
|
296
|
0
|
|
|
|
|
|
1; |
297
|
0
|
0
|
|
|
|
|
} or do { |
298
|
0
|
|
|
|
|
|
my $E = $@; |
299
|
0
|
|
|
|
|
|
Helios::Error::JobTypeError->throw("remove(): $E"); |
300
|
|
|
|
|
|
|
}; |
301
|
|
|
|
|
|
|
# signal the calling routine remove was successful |
302
|
0
|
|
|
|
|
|
return 1; |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
1; |
307
|
|
|
|
|
|
|
__END__ |