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