line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Target; |
2
|
|
|
|
|
|
|
|
3
|
34
|
|
|
34
|
|
3425910
|
use strict; |
|
34
|
|
|
|
|
62
|
|
|
34
|
|
|
|
|
901
|
|
4
|
34
|
|
|
34
|
|
172
|
use warnings; |
|
34
|
|
|
|
|
63
|
|
|
34
|
|
|
|
|
1025
|
|
5
|
|
|
|
|
|
|
|
6
|
34
|
|
|
34
|
|
979
|
use English qw(-no_match_vars); |
|
34
|
|
|
|
|
2309
|
|
|
34
|
|
|
|
|
272
|
|
7
|
|
|
|
|
|
|
|
8
|
34
|
|
|
34
|
|
20278
|
use FusionInventory::Agent::Logger; |
|
34
|
|
|
|
|
68
|
|
|
34
|
|
|
|
|
2286
|
|
9
|
34
|
|
|
34
|
|
3327
|
use FusionInventory::Agent::Storage; |
|
34
|
|
|
|
|
68
|
|
|
34
|
|
|
|
|
255
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
8
|
|
|
8
|
1
|
26
|
my ($class, %params) = @_; |
13
|
|
|
|
|
|
|
|
14
|
8
|
100
|
|
|
|
34
|
die 'no basevardir parameter' unless $params{basevardir}; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $self = { |
17
|
|
|
|
|
|
|
logger => $params{logger} || |
18
|
|
|
|
|
|
|
FusionInventory::Agent::Logger->new(), |
19
|
|
|
|
|
|
|
maxDelay => $params{maxDelay} || 3600, |
20
|
|
|
|
|
|
|
initialDelay => $params{delaytime}, |
21
|
7
|
|
66
|
|
|
263
|
}; |
|
|
|
50
|
|
|
|
|
22
|
7
|
|
|
|
|
86
|
bless $self, $class; |
23
|
|
|
|
|
|
|
|
24
|
7
|
|
|
|
|
27
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _init { |
28
|
7
|
|
|
7
|
|
26
|
my ($self, %params) = @_; |
29
|
|
|
|
|
|
|
|
30
|
7
|
|
|
|
|
14
|
my $logger = $self->{logger}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# target identity |
33
|
7
|
|
|
|
|
19
|
$self->{id} = $params{id}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$self->{storage} = FusionInventory::Agent::Storage->new( |
36
|
|
|
|
|
|
|
logger => $self->{logger}, |
37
|
|
|
|
|
|
|
directory => $params{vardir} |
38
|
7
|
|
|
|
|
62
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# handle persistent state |
41
|
7
|
|
|
|
|
38
|
$self->_loadState(); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$self->{nextRunDate} = $self->_computeNextRunDate() |
44
|
7
|
100
|
|
|
|
42
|
if !$self->{nextRunDate}; |
45
|
|
|
|
|
|
|
|
46
|
7
|
|
|
|
|
33
|
$self->_saveState(); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$logger->debug( |
49
|
|
|
|
|
|
|
"[target $self->{id}] Next server contact planned for " . |
50
|
|
|
|
|
|
|
localtime($self->{nextRunDate}) |
51
|
7
|
|
|
|
|
1856
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub getStorage { |
56
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
0
|
return $self->{storage}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub setNextRunDate { |
62
|
0
|
|
|
0
|
1
|
0
|
my ($self, $nextRunDate) = @_; |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
0
|
lock($self->{nextRunDate}) if $self->{shared}; |
65
|
0
|
|
|
|
|
0
|
$self->{nextRunDate} = $nextRunDate; |
66
|
0
|
|
|
|
|
0
|
$self->_saveState(); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub resetNextRunDate { |
70
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
0
|
lock($self->{nextRunDate}) if $self->{shared}; |
73
|
0
|
|
|
|
|
0
|
$self->{nextRunDate} = $self->_computeNextRunDate(); |
74
|
0
|
|
|
|
|
0
|
$self->_saveState(); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub getNextRunDate { |
78
|
2
|
|
|
2
|
1
|
10
|
my ($self) = @_; |
79
|
|
|
|
|
|
|
|
80
|
2
|
|
|
|
|
7
|
return $self->{nextRunDate}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub getFormatedNextRunDate { |
84
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
return $self->{nextRunDate} > 1 ? |
87
|
0
|
0
|
|
|
|
0
|
scalar localtime($self->{nextRunDate}) : "now"; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub getMaxDelay { |
91
|
1
|
|
|
1
|
1
|
4
|
my ($self) = @_; |
92
|
|
|
|
|
|
|
|
93
|
1
|
|
|
|
|
4
|
return $self->{maxDelay}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub setMaxDelay { |
97
|
0
|
|
|
0
|
1
|
0
|
my ($self, $maxDelay) = @_; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
0
|
$self->{maxDelay} = $maxDelay; |
100
|
0
|
|
|
|
|
0
|
$self->_saveState(); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# compute a run date, as current date and a random delay |
104
|
|
|
|
|
|
|
# between maxDelay / 2 and maxDelay |
105
|
|
|
|
|
|
|
sub _computeNextRunDate { |
106
|
4
|
|
|
4
|
|
10
|
my ($self) = @_; |
107
|
|
|
|
|
|
|
|
108
|
4
|
|
|
|
|
7
|
my $ret; |
109
|
4
|
50
|
|
|
|
14
|
if ($self->{initialDelay}) { |
110
|
0
|
|
|
|
|
0
|
$ret = time + ($self->{initialDelay} / 2) + int rand($self->{initialDelay} / 2); |
111
|
0
|
|
|
|
|
0
|
$self->{initialDelay} = undef; |
112
|
|
|
|
|
|
|
} else { |
113
|
|
|
|
|
|
|
$ret = |
114
|
|
|
|
|
|
|
time + |
115
|
|
|
|
|
|
|
$self->{maxDelay} / 2 + |
116
|
4
|
|
|
|
|
34
|
int rand($self->{maxDelay} / 2); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
4
|
|
|
|
|
13
|
return $ret; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub _loadState { |
123
|
7
|
|
|
7
|
|
13
|
my ($self) = @_; |
124
|
|
|
|
|
|
|
|
125
|
7
|
|
|
|
|
32
|
my $data = $self->{storage}->restore(name => 'target'); |
126
|
|
|
|
|
|
|
|
127
|
7
|
100
|
|
|
|
28
|
$self->{maxDelay} = $data->{maxDelay} if $data->{maxDelay}; |
128
|
7
|
100
|
|
|
|
30
|
$self->{nextRunDate} = $data->{nextRunDate} if $data->{nextRunDate}; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub _saveState { |
132
|
7
|
|
|
7
|
|
13
|
my ($self) = @_; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
$self->{storage}->save( |
135
|
|
|
|
|
|
|
name => 'target', |
136
|
|
|
|
|
|
|
data => { |
137
|
|
|
|
|
|
|
maxDelay => $self->{maxDelay}, |
138
|
|
|
|
|
|
|
nextRunDate => $self->{nextRunDate}, |
139
|
|
|
|
|
|
|
} |
140
|
7
|
|
|
|
|
40
|
); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |
144
|
|
|
|
|
|
|
__END__ |