line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Backup::Omni::Utils; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
1015
|
use Try::Tiny; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
69
|
|
6
|
1
|
|
|
1
|
|
7
|
use Backup::Omni::Exception; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
7
|
1
|
|
|
1
|
|
87
|
use Params::Validate ':all'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
200
|
|
8
|
1
|
|
|
1
|
|
1622
|
use DateTime::Format::Strptime; |
|
1
|
|
|
|
|
257371
|
|
|
1
|
|
|
|
|
95
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Backup::Omni::Class |
11
|
1
|
|
|
|
|
25
|
version => $VERSION, |
12
|
|
|
|
|
|
|
base => 'Badger::Utils', |
13
|
|
|
|
|
|
|
constants => 'HASH ARRAY OMNISTAT OMNIABORT', |
14
|
|
|
|
|
|
|
constant => { |
15
|
|
|
|
|
|
|
ABORT => '%s -session %s', |
16
|
|
|
|
|
|
|
CONVERT => '%s -session %s -status_only', |
17
|
|
|
|
|
|
|
BADDATE => 'unable to perform date parsing, reason: %s', |
18
|
|
|
|
|
|
|
BADPARM => 'invalid parameters passed from %s at line %s', |
19
|
|
|
|
|
|
|
BADTEMP => 'bad temporary session id', |
20
|
|
|
|
|
|
|
NORESUL => 'unable to find any results for %s', |
21
|
|
|
|
|
|
|
NOABORT => 'unable to abort %s', |
22
|
|
|
|
|
|
|
}, |
23
|
|
|
|
|
|
|
exports => { |
24
|
|
|
|
|
|
|
any => 'db2dt dt2db omni2dt trim ltrim rtrim convert_id abort_id', |
25
|
|
|
|
|
|
|
all => 'db2dt dt2db omni2dt trim ltrim rtrim convert_id abort_id', |
26
|
|
|
|
|
|
|
} |
27
|
1
|
|
|
1
|
|
12
|
; |
|
1
|
|
|
|
|
2
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Params::Validate::validation_options( |
30
|
|
|
|
|
|
|
on_fail => sub { |
31
|
|
|
|
|
|
|
my $params = shift; |
32
|
|
|
|
|
|
|
my $class = __PACKAGE__; |
33
|
|
|
|
|
|
|
Backup::Omni::Base::validation_exception($params, $class); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
38
|
|
|
|
|
|
|
# Public Methods |
39
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Perl trim function to remove whitespace from the start and end of the string |
42
|
|
|
|
|
|
|
sub trim { |
43
|
0
|
|
|
0
|
1
|
|
my $string = shift; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$string =~ s/^\s+//; |
46
|
0
|
|
|
|
|
|
$string =~ s/\s+$//; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
return $string; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Left trim function to remove leading whitespace |
53
|
|
|
|
|
|
|
sub ltrim { |
54
|
0
|
|
|
0
|
1
|
|
my $string = shift; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$string =~ s/^\s+//; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
return $string; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Right trim function to remove trailing whitespace |
63
|
|
|
|
|
|
|
sub rtrim { |
64
|
0
|
|
|
0
|
1
|
|
my $string = shift; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$string =~ s/\s+$//; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return $string; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub db2dt { |
73
|
0
|
|
|
0
|
1
|
|
my ($p) = shift; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $dt; |
76
|
|
|
|
|
|
|
my $parser; |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
if ($p =~ m/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/) { |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
$parser = DateTime::Format::Strptime->new( |
81
|
|
|
|
|
|
|
pattern => '%Y-%m-%d %H:%M:%S', |
82
|
|
|
|
|
|
|
time_zone => 'local', |
83
|
|
|
|
|
|
|
on_error => sub { |
84
|
0
|
|
|
0
|
|
|
my ($obj, $err) = @_; |
85
|
0
|
|
|
|
|
|
my $ex = Backup::Omni::Exception->new( |
86
|
|
|
|
|
|
|
type => 'backup.omni.utils.db2dt', |
87
|
|
|
|
|
|
|
info => sprintf(BADDATE, $err) |
88
|
|
|
|
|
|
|
); |
89
|
0
|
|
|
|
|
|
$ex->throw; |
90
|
|
|
|
|
|
|
} |
91
|
0
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
$dt = $parser->parse_datetime($p); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
} else { |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my ($package, $file, $line) = caller; |
98
|
0
|
|
|
|
|
|
my $ex = Backup::Omni::Exception->new( |
99
|
|
|
|
|
|
|
type => 'backup.omni.utils.db2dt', |
100
|
|
|
|
|
|
|
info => sprintf(BADPARM, $package, $line) |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
$ex->throw; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
return $dt; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub dt2db { |
112
|
0
|
|
|
0
|
1
|
|
my ($p) = shift; |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
my $ft; |
115
|
|
|
|
|
|
|
my $parser; |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
my $ref = ref($p); |
118
|
|
|
|
|
|
|
|
119
|
0
|
0
|
0
|
|
|
|
if ($ref && $p->isa('DateTime')) { |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
$parser = DateTime::Format::Strptime->new( |
122
|
|
|
|
|
|
|
pattern => '%Y-%m-%d %H:%M:%S', |
123
|
|
|
|
|
|
|
time_zone => 'local', |
124
|
|
|
|
|
|
|
on_error => sub { |
125
|
0
|
|
|
0
|
|
|
my ($obj, $err) = @_; |
126
|
0
|
|
|
|
|
|
my $ex = Backup::Omni::Exception->new( |
127
|
|
|
|
|
|
|
type => 'backup.omni.utils.dt2db', |
128
|
|
|
|
|
|
|
info => sprintf(BADDATE, $err) |
129
|
|
|
|
|
|
|
); |
130
|
0
|
|
|
|
|
|
$ex->throw; |
131
|
|
|
|
|
|
|
} |
132
|
0
|
|
|
|
|
|
); |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
$ft = $parser->format_datetime($p); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
} else { |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
my ($package, $file, $line) = caller; |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
my $ex = Backup::Omni::Exception->new( |
141
|
|
|
|
|
|
|
type => 'backup.omni.utils.dt2db', |
142
|
|
|
|
|
|
|
info => sprintf(BADPARM, $package, $line) |
143
|
|
|
|
|
|
|
); |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
$ex->throw; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
return $ft; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub omni2dt { |
154
|
0
|
|
|
0
|
1
|
|
my ($p) = shift; |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
my $dt; |
157
|
|
|
|
|
|
|
my $parser; |
158
|
|
|
|
|
|
|
|
159
|
0
|
0
|
|
|
|
|
if ($p =~ m/\w{3} \d{2} \w{3} \d{4} \d{2}:\d{2}:\d{2} \w{2} \w{3}/) { |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
$parser = DateTime::Format::Strptime->new( |
162
|
|
|
|
|
|
|
pattern => '%a %d %b %Y %r', |
163
|
|
|
|
|
|
|
time_zone => 'local', |
164
|
|
|
|
|
|
|
on_error => sub { |
165
|
0
|
|
|
0
|
|
|
my ($obj, $err) = @_; |
166
|
0
|
|
|
|
|
|
my $ex = Backup::Omni::Exception->new( |
167
|
|
|
|
|
|
|
type => 'backup.omni.utils.omni2dt', |
168
|
|
|
|
|
|
|
info => sprintf(BADDATE, $err) |
169
|
|
|
|
|
|
|
); |
170
|
0
|
|
|
|
|
|
$ex->throw; |
171
|
|
|
|
|
|
|
} |
172
|
0
|
|
|
|
|
|
); |
173
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
$dt = $parser->parse_datetime($p); |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
} else { |
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
my ($package, $file, $line) = caller; |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
my $ex = Backup::Omni::Exception->new( |
181
|
|
|
|
|
|
|
type => 'backup.omni.utils.omni2dt', |
182
|
|
|
|
|
|
|
info => sprintf(BADPARM, $package, $line) |
183
|
|
|
|
|
|
|
); |
184
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
$ex->throw; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
0
|
|
|
|
|
|
return $dt; |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub convert_id { |
194
|
0
|
|
|
0
|
1
|
|
my $session = shift; |
195
|
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
my $id; |
197
|
|
|
|
|
|
|
|
198
|
0
|
0
|
|
|
|
|
if ($session =~ m/^R-/) { |
199
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
|
my $command = sprintf(CONVERT, OMNISTAT, $session); |
201
|
0
|
|
|
|
|
|
my @result = `$command`; |
202
|
0
|
|
|
|
|
|
my $rc = $?; |
203
|
|
|
|
|
|
|
|
204
|
0
|
0
|
|
|
|
|
unless (grep(/SessionID/, @result)) { |
205
|
|
|
|
|
|
|
|
206
|
0
|
|
|
|
|
|
my $ex = Backp::Omni::Exception->new( |
207
|
|
|
|
|
|
|
type => 'backup.omni.utils.convert_id', |
208
|
|
|
|
|
|
|
info => sprintf(NORESUL, $session) |
209
|
|
|
|
|
|
|
); |
210
|
|
|
|
|
|
|
|
211
|
0
|
|
|
|
|
|
$ex->throw; |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
($id) = split(' ', $result[2]); |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
} else { |
218
|
|
|
|
|
|
|
|
219
|
0
|
|
|
|
|
|
my $ex = Backup::Omni::Exception->new( |
220
|
|
|
|
|
|
|
type => 'backup.omni.utils.convert_id', |
221
|
|
|
|
|
|
|
info => BADTEMP |
222
|
|
|
|
|
|
|
); |
223
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
$ex->throw; |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
0
|
|
|
|
|
|
return $id; |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
sub abort_id { |
233
|
0
|
|
|
0
|
1
|
|
my $session = shift; |
234
|
|
|
|
|
|
|
|
235
|
0
|
|
|
|
|
|
my $command = sprintf(ABORT, OMNIABORT, $session); |
236
|
0
|
|
|
|
|
|
my @result = `$command`; |
237
|
0
|
|
|
|
|
|
my $rc = $?; |
238
|
|
|
|
|
|
|
|
239
|
0
|
0
|
|
|
|
|
unless (grep(/$session/, @result)) { |
240
|
|
|
|
|
|
|
|
241
|
0
|
|
|
|
|
|
my $ex = Backp::Omni::Exception->new( |
242
|
|
|
|
|
|
|
type => 'backup.omni.utils.abort_id', |
243
|
|
|
|
|
|
|
info => sprintf(NOABORT, $session) |
244
|
|
|
|
|
|
|
); |
245
|
|
|
|
|
|
|
|
246
|
0
|
|
|
|
|
|
$ex->throw; |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
1; |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
__END__ |