line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#********************************************************************* |
2
|
|
|
|
|
|
|
#*** ResourcePool::Command::Execute |
3
|
|
|
|
|
|
|
#*** Copyright (c) 2002,2003 by Markus Winand |
4
|
|
|
|
|
|
|
#*** $Id: Execute.pm,v 1.10 2013-04-16 10:14:44 mws Exp $ |
5
|
|
|
|
|
|
|
#********************************************************************* |
6
|
|
|
|
|
|
|
package ResourcePool::Command::Execute; |
7
|
|
|
|
|
|
|
|
8
|
8
|
|
|
8
|
|
4579
|
use ResourcePool::Command::Exception; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
237
|
|
9
|
8
|
|
|
8
|
|
102
|
use vars qw($VERSION); |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
287
|
|
10
|
8
|
|
|
8
|
|
9214
|
use Data::Dumper; |
|
8
|
|
|
|
|
104716
|
|
|
8
|
|
|
|
|
7646
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
$VERSION = "1.0107"; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub execute($$@) { |
15
|
23
|
|
|
23
|
1
|
5000
|
my ($self, $command, @addargs) = @_; |
16
|
23
|
|
|
|
|
37
|
my $try = $self->{MaxExecTry}; |
17
|
23
|
|
|
|
|
53
|
my @rc = (); |
18
|
23
|
|
|
|
|
27
|
my $rep; |
19
|
|
|
|
|
|
|
|
20
|
23
|
|
|
|
|
107
|
$command->_resetReports(); |
21
|
23
|
|
100
|
|
|
40
|
do { |
22
|
41
|
|
|
|
|
109
|
$rep = ResourcePool::Command::Execute::Report->new(); |
23
|
41
|
|
|
|
|
51
|
eval { |
24
|
41
|
|
|
|
|
177
|
$command->init(); |
25
|
|
|
|
|
|
|
}; |
26
|
41
|
|
|
|
|
186
|
$rep->setInitException($@); |
27
|
41
|
100
|
|
|
|
76
|
if (! $rep->getInitException()) { |
28
|
36
|
|
|
|
|
107
|
my $plain_rec = $self->get(); |
29
|
36
|
50
|
|
|
|
72
|
if (defined $plain_rec) { |
30
|
36
|
|
|
|
|
47
|
eval { |
31
|
36
|
|
|
|
|
138
|
$command->preExecute($plain_rec); |
32
|
|
|
|
|
|
|
}; |
33
|
36
|
|
|
|
|
168
|
$rep->setPreExecuteException($@); |
34
|
36
|
100
|
|
|
|
68
|
if (! $rep->getPreExecuteException()) { |
35
|
31
|
|
|
|
|
33
|
eval { |
36
|
31
|
|
|
|
|
107
|
@rc = $command->execute($plain_rec, @addargs); |
37
|
|
|
|
|
|
|
}; |
38
|
31
|
|
|
|
|
493
|
$rep->setExecuteException($@); |
39
|
31
|
100
|
|
|
|
65
|
if (! $rep->getExecuteException()) { |
40
|
16
|
|
|
|
|
48
|
$self->executePostExecute($command, $rep, $plain_rec); |
41
|
|
|
|
|
|
|
#$self->executeRevertExecute($command, $rep, $plain_rec); |
42
|
|
|
|
|
|
|
} else { |
43
|
15
|
|
|
|
|
28
|
reportException($rep->getExecuteException(), 'execute'); |
44
|
|
|
|
|
|
|
#$self->executeRevertExecute($command, $rep, $plain_rec); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} else { |
47
|
5
|
|
|
|
|
11
|
reportException($rep->getPreExecuteException(), 'preExecute'); |
48
|
|
|
|
|
|
|
} |
49
|
36
|
100
|
|
|
|
407
|
if ($rep->tobeRepeated()) { |
50
|
20
|
|
|
|
|
56
|
$self->fail($plain_rec); |
51
|
|
|
|
|
|
|
} else { |
52
|
16
|
|
|
|
|
52
|
$self->free($plain_rec); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
36
|
|
|
|
|
120
|
$self->executeCleanup($command, $rep); |
56
|
|
|
|
|
|
|
} else { |
57
|
5
|
|
|
|
|
10
|
reportException($rep->getInitException(), 'init'); |
58
|
|
|
|
|
|
|
} |
59
|
41
|
|
|
|
|
288
|
$command->_addReport($rep); |
60
|
|
|
|
|
|
|
} while ($rep->tobeRepeated() && ($try-- > 0)); |
61
|
23
|
100
|
|
|
|
56
|
if (!$rep->ok()) { |
62
|
12
|
|
100
|
|
|
22
|
die ResourcePool::Command::Exception->new( |
63
|
|
|
|
|
|
|
$rep->getException() |
64
|
|
|
|
|
|
|
, $command |
65
|
|
|
|
|
|
|
, ($self->{MaxExecTry} - $try) || 1 |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
} |
68
|
11
|
50
|
|
|
|
33
|
if (wantarray) { |
69
|
0
|
|
|
|
|
0
|
return @rc; |
70
|
|
|
|
|
|
|
} else { |
71
|
11
|
|
|
|
|
39
|
return $rc[0]; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub executePostExecute($$$$) { |
76
|
16
|
|
|
16
|
0
|
23
|
my ($self, $command, $rep, $plain_rec) = @_; |
77
|
16
|
|
|
|
|
18
|
eval { |
78
|
16
|
|
|
|
|
73
|
$command->postExecute($plain_rec); |
79
|
|
|
|
|
|
|
}; |
80
|
16
|
|
|
|
|
78
|
$rep->setPostExecuteException($@); |
81
|
16
|
100
|
|
|
|
45
|
if ($rep->getPostExecuteException()) { |
82
|
5
|
|
|
|
|
17
|
reportIgnoredException($rep->getPostExecuteException(), 'postExecute'); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
#sub executeRevertExecute($$$$) { |
87
|
|
|
|
|
|
|
# my ($self, $command, $rep, $plain_rec) = @_; |
88
|
|
|
|
|
|
|
# eval { |
89
|
|
|
|
|
|
|
# $command->revertExecute($plain_rec); |
90
|
|
|
|
|
|
|
# }; |
91
|
|
|
|
|
|
|
# $rep->setRevertExecuteException($@); |
92
|
|
|
|
|
|
|
# if ($rep->getRevertExecuteException()) { |
93
|
|
|
|
|
|
|
# reportIgnoredException($rep->getRevertExecuteException(), 'revertExecute'); |
94
|
|
|
|
|
|
|
# } |
95
|
|
|
|
|
|
|
#} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub executeCleanup($$$) { |
98
|
36
|
|
|
36
|
0
|
53
|
my ($self, $command, $rep) = @_; |
99
|
36
|
|
|
|
|
35
|
eval { |
100
|
36
|
|
|
|
|
136
|
$command->cleanup(); |
101
|
|
|
|
|
|
|
}; |
102
|
36
|
|
|
|
|
138
|
$rep->setCleanupException($@); |
103
|
36
|
100
|
|
|
|
59
|
if ($rep->getCleanupException()) { |
104
|
1
|
|
|
|
|
3
|
reportIgnoredException($rep->getCleanupException(), 'cleanup'); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub getExceptionMessage($) { |
110
|
31
|
|
|
31
|
0
|
40
|
my ($ex) = @_; |
111
|
31
|
100
|
|
|
|
61
|
if (ref($ex)) { |
112
|
6
|
50
|
|
|
|
13
|
if (ResourcePool::Command::Execute::Report::isNoFailoverException($ex)) { |
113
|
6
|
|
|
|
|
23
|
return Dumper($ex->rootException()); |
114
|
|
|
|
|
|
|
} else { |
115
|
0
|
|
|
|
|
0
|
return Dumper($ex); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} else { |
118
|
25
|
|
|
|
|
126
|
return $ex; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub reportException($$) { |
123
|
25
|
|
|
25
|
0
|
37
|
my ($ex, $method) = @_; |
124
|
25
|
|
|
|
|
77
|
warn('ResourcePool::Command->' . $method . '() failed: ' |
125
|
|
|
|
|
|
|
. getExceptionMessage($ex) |
126
|
|
|
|
|
|
|
); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub reportIgnoredException($$) { |
130
|
6
|
|
|
6
|
0
|
10
|
my ($ex, $method) = @_; |
131
|
6
|
|
|
|
|
16
|
warn('ResourcePool::Command->' . $method . '() ignored exception: ' |
132
|
|
|
|
|
|
|
. getExceptionMessage($ex) |
133
|
|
|
|
|
|
|
); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
package ResourcePool::Command::Execute::Report; |
137
|
8
|
|
|
8
|
|
84
|
use vars qw($VERSION); |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
5610
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
$VERSION = "1.0100"; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub new($) { |
142
|
51
|
|
|
51
|
|
81
|
my $proto = shift; |
143
|
51
|
|
33
|
|
|
224
|
my $class = ref($proto) || $proto; |
144
|
51
|
|
|
|
|
68
|
my $self = {}; |
145
|
51
|
|
|
|
|
150
|
bless($self, $class); |
146
|
51
|
|
|
|
|
97
|
return $self; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub setInitException($$) { |
150
|
43
|
|
|
43
|
|
60
|
my ($self, $ex) = @_; |
151
|
43
|
|
|
|
|
119
|
$self->{InitException} = $ex; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub setPreExecuteException($$) { |
155
|
38
|
|
|
38
|
|
78
|
my ($self, $ex) = @_; |
156
|
38
|
|
|
|
|
82
|
$self->{PreExecuteException} = $ex; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub setExecuteException($$) { |
160
|
33
|
|
|
33
|
|
57
|
my ($self, $ex) = @_; |
161
|
33
|
|
|
|
|
76
|
$self->{ExecuteException} = $ex; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub setPostExecuteException($$) { |
165
|
18
|
|
|
18
|
|
38
|
my ($self, $ex) = @_; |
166
|
18
|
|
|
|
|
46
|
$self->{PostExecuteException} = $ex; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub setCleanupException($$) { |
170
|
38
|
|
|
38
|
|
66
|
my ($self, $ex) = @_; |
171
|
38
|
|
|
|
|
88
|
$self->{CleanupException} = $ex; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub setRevertExecuteException($$) { |
175
|
0
|
|
|
0
|
|
0
|
my ($self, $ex) = @_; |
176
|
0
|
|
|
|
|
0
|
$self->{RevertExecuteException} = $ex; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub getInitException($) { |
181
|
172
|
|
|
172
|
|
196
|
my ($self) = @_; |
182
|
172
|
|
|
|
|
743
|
return $self->{InitException}; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub getPreExecuteException($) { |
186
|
156
|
|
|
156
|
|
180
|
my ($self) = @_; |
187
|
156
|
|
|
|
|
1122
|
return $self->{PreExecuteException}; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub getExecuteException($) { |
191
|
145
|
|
|
145
|
|
180
|
my ($self) = @_; |
192
|
145
|
|
|
|
|
513
|
return $self->{ExecuteException}; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub getPostExecuteException($) { |
196
|
80
|
|
|
80
|
|
99
|
my ($self) = @_; |
197
|
80
|
|
|
|
|
447
|
return $self->{PostExecuteException}; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub getCleanupException($) { |
201
|
39
|
|
|
39
|
|
58
|
my ($self) = @_; |
202
|
39
|
|
|
|
|
123
|
return $self->{CleanupException}; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub getRevertExecuteException($) { |
206
|
0
|
|
|
0
|
|
0
|
my ($self) = @_; |
207
|
0
|
|
|
|
|
0
|
return $self->{RevertExecuteException}; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub getException($) { |
211
|
87
|
|
|
87
|
|
117
|
my ($self) = @_; |
212
|
87
|
|
100
|
|
|
749
|
return $self->{InitException} |
213
|
|
|
|
|
|
|
|| $self->{PreExecuteException} |
214
|
|
|
|
|
|
|
|| $self->{ExecuteException} |
215
|
|
|
|
|
|
|
|| $self->{PostExecuteException} |
216
|
|
|
|
|
|
|
|| $self->{CleanupException}; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub ok($) { |
220
|
124
|
|
|
124
|
|
151
|
my ($self) = @_; |
221
|
|
|
|
|
|
|
|
222
|
124
|
|
100
|
|
|
214
|
return !$self->getInitException() |
223
|
|
|
|
|
|
|
&& !$self->getPreExecuteException() |
224
|
|
|
|
|
|
|
&& !$self->getExecuteException |
225
|
|
|
|
|
|
|
&& !$self->getPostExecuteException; |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
#sub revertOk($) { |
229
|
|
|
|
|
|
|
# my ($self) = @_; |
230
|
|
|
|
|
|
|
# return $self->getPostExecuteException() |
231
|
|
|
|
|
|
|
# && !$self->getRevertExecuteException(); |
232
|
|
|
|
|
|
|
#} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
sub tobeRepeated($) { |
235
|
89
|
|
|
89
|
|
119
|
my ($self) = @_; |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
# printf("tobeRepeated %d %d\n", (!$self->ok()), isNoFailoverException($self->getExecuteException())); |
238
|
89
|
|
100
|
|
|
148
|
return (!$self->ok()) && !isNoFailoverException($self->getException()); |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
sub isNoFailoverException($) { |
242
|
69
|
|
|
69
|
|
82
|
my ($ex) = @_; |
243
|
69
|
|
|
|
|
72
|
my $rc; |
244
|
69
|
|
|
|
|
74
|
eval { |
245
|
69
|
|
|
|
|
388
|
$rc = $ex->isa('ResourcePool::Command::NoFailoverException'); |
246
|
|
|
|
|
|
|
}; |
247
|
69
|
50
|
|
|
|
146
|
if (! $@) { |
248
|
69
|
|
|
|
|
372
|
return $rc; |
249
|
|
|
|
|
|
|
} |
250
|
0
|
|
|
|
|
|
return 0; # default, do failover |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
1; |