| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Apache::BalancerManager; |
|
2
|
|
|
|
|
|
|
{ |
|
3
|
|
|
|
|
|
|
$Apache::BalancerManager::VERSION = '0.001002'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Interact with the Apache BalancerManager |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
203029
|
use Moo; |
|
|
1
|
|
|
|
|
13391
|
|
|
|
1
|
|
|
|
|
9
|
|
|
9
|
1
|
|
|
1
|
|
1909
|
use List::Util (); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
19
|
|
|
10
|
1
|
|
|
1
|
|
910
|
use Web::Scraper; |
|
|
1
|
|
|
|
|
163548
|
|
|
|
1
|
|
|
|
|
10
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has url => ( |
|
13
|
|
|
|
|
|
|
is => 'ro', |
|
14
|
|
|
|
|
|
|
required => 1, |
|
15
|
|
|
|
|
|
|
); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has name => ( |
|
18
|
|
|
|
|
|
|
is => 'ro', |
|
19
|
|
|
|
|
|
|
lazy => 1, |
|
20
|
|
|
|
|
|
|
builder => '_build_name', |
|
21
|
|
|
|
|
|
|
); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub _build_name { |
|
24
|
1
|
|
|
1
|
|
11011
|
my $ret = $_[0]->_scraped_content->{name_stuff}; |
|
25
|
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
7
|
$ret =~ s(^LoadBalancer Status for balancer://)(); |
|
27
|
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
11
|
return $ret |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has nonce => ( |
|
32
|
|
|
|
|
|
|
is => 'ro', |
|
33
|
|
|
|
|
|
|
init_arg => undef, |
|
34
|
|
|
|
|
|
|
lazy => 1, |
|
35
|
|
|
|
|
|
|
builder => '_build_nonce', |
|
36
|
|
|
|
|
|
|
); |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _build_nonce { |
|
39
|
1
|
|
|
1
|
|
424
|
my $self = shift; |
|
40
|
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
6
|
my $url = $self->url; |
|
42
|
1
|
|
|
|
|
19
|
my $link = $self->_scraped_content->{data}[0]{link}; |
|
43
|
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
15
|
require URI; |
|
45
|
1
|
|
|
|
|
944
|
require URI::QueryParam; |
|
46
|
1
|
|
|
|
|
710
|
my $uri = URI->new("$url$link"); |
|
47
|
1
|
|
|
|
|
103
|
scalar $uri->query_param('nonce') |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
has _index_content => ( |
|
51
|
|
|
|
|
|
|
is => 'ro', |
|
52
|
|
|
|
|
|
|
init_arg => undef, |
|
53
|
|
|
|
|
|
|
lazy => 1, |
|
54
|
|
|
|
|
|
|
builder => '_build_index_content', |
|
55
|
|
|
|
|
|
|
); |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _build_index_content { |
|
58
|
1
|
|
|
1
|
|
410
|
my $self = shift; |
|
59
|
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
9
|
my $response = $self->_get($self->url); |
|
61
|
1
|
50
|
|
|
|
27055
|
if ($response->is_success) { |
|
62
|
1
|
|
|
|
|
25
|
return $response->decoded_content; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
else { |
|
65
|
0
|
|
|
|
|
0
|
die $response->status_line; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
has _scraper => ( |
|
70
|
|
|
|
|
|
|
is => 'ro', |
|
71
|
|
|
|
|
|
|
init_arg => undef, |
|
72
|
|
|
|
|
|
|
lazy => 1, |
|
73
|
|
|
|
|
|
|
builder => '_build_scraper', |
|
74
|
|
|
|
|
|
|
handles => { |
|
75
|
|
|
|
|
|
|
_scrape => 'scrape', |
|
76
|
|
|
|
|
|
|
}, |
|
77
|
|
|
|
|
|
|
); |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _build_scraper { |
|
80
|
|
|
|
|
|
|
return scraper { |
|
81
|
1
|
|
|
1
|
|
15029
|
process 'h3', name_stuff => 'TEXT'; |
|
82
|
|
|
|
|
|
|
process '//table[2]/tr' => 'data[]' => scraper { |
|
83
|
3
|
|
|
|
|
28393
|
process '//td[1]/a/@href', 'link' => 'TEXT'; |
|
84
|
3
|
|
|
|
|
10138
|
process '//td[1]/a', 'location' => 'TEXT'; |
|
85
|
3
|
|
|
|
|
8317
|
process '//td[2]', 'route' => 'TEXT'; |
|
86
|
3
|
|
|
|
|
8107
|
process '//td[3]', 'route_redirect' => 'TEXT'; |
|
87
|
3
|
|
|
|
|
7714
|
process '//td[4]', 'load_factor' => 'TEXT'; |
|
88
|
3
|
|
|
|
|
7730
|
process '//td[5]', 'lb_set' => 'TEXT'; |
|
89
|
3
|
|
|
|
|
7660
|
process '//td[6]', status => 'TEXT'; |
|
90
|
3
|
|
|
|
|
7938
|
process '//td[7]', times_elected => 'TEXT'; |
|
91
|
3
|
|
|
|
|
7947
|
process '//td[8]', to => 'TEXT'; |
|
92
|
3
|
|
|
|
|
8144
|
process '//td[9]', from => 'TEXT'; |
|
93
|
1
|
|
|
|
|
6749
|
}; |
|
94
|
1
|
|
|
1
|
|
33378
|
}; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
has _scraped_content => ( |
|
98
|
|
|
|
|
|
|
is => 'ro', |
|
99
|
|
|
|
|
|
|
init_arg => undef, |
|
100
|
|
|
|
|
|
|
lazy => 1, |
|
101
|
|
|
|
|
|
|
builder => '_build_scraped_content', |
|
102
|
|
|
|
|
|
|
); |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub _build_scraped_content { |
|
105
|
1
|
|
|
1
|
|
407
|
my $s = $_[0]->_scrape( $_[0]->_index_content ); |
|
106
|
1
|
|
|
|
|
3126
|
$s->{data} = [grep %$_, @{$s->{data}}]; |
|
|
1
|
|
|
|
|
12
|
|
|
107
|
1
|
|
|
|
|
8
|
$s |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
has _user_agent => ( |
|
111
|
|
|
|
|
|
|
is => 'ro', |
|
112
|
|
|
|
|
|
|
lazy => 1, |
|
113
|
|
|
|
|
|
|
init_arg => 'user_agent', |
|
114
|
|
|
|
|
|
|
builder => '_build_user_agent', |
|
115
|
|
|
|
|
|
|
handles => { _get => 'get' }, |
|
116
|
|
|
|
|
|
|
); |
|
117
|
|
|
|
|
|
|
|
|
118
|
0
|
|
|
0
|
|
0
|
sub _build_user_agent { require LWP::UserAgent; LWP::UserAgent->new } |
|
|
0
|
|
|
|
|
0
|
|
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
has _members => ( |
|
121
|
|
|
|
|
|
|
is => 'ro', |
|
122
|
|
|
|
|
|
|
# TODO: support passing memebers as either objects or strings that coerce |
|
123
|
|
|
|
|
|
|
init_arg => undef, |
|
124
|
|
|
|
|
|
|
lazy => 1, |
|
125
|
|
|
|
|
|
|
builder => '_build_members', |
|
126
|
|
|
|
|
|
|
); |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub _build_members { |
|
129
|
1
|
|
|
1
|
|
1091
|
require Apache::BalancerManager::Member; |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
[ |
|
132
|
1
|
|
|
|
|
52
|
map {; |
|
133
|
2
|
|
|
|
|
23
|
$_->{status} = $_->{status} =~ m/Ok/; |
|
134
|
2
|
|
|
|
|
4
|
$_->{manager} = $_[0]; |
|
135
|
2
|
|
|
|
|
23
|
Apache::BalancerManager::Member->new($_), |
|
136
|
1
|
|
|
|
|
3
|
} @{$_[0]->_scraped_content->{data}} |
|
137
|
|
|
|
|
|
|
] |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
2
|
|
|
2
|
1
|
676
|
sub get_member_by_index { $_[0]->_members->[$_[1]]; } |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub get_member_by_location { |
|
143
|
2
|
|
|
2
|
1
|
360
|
my ($self, $location) = @_; |
|
144
|
|
|
|
|
|
|
|
|
145
|
2
|
|
|
3
|
|
7
|
List::Util::first { $_->location eq $location } @{$self->_members}; |
|
|
3
|
|
|
|
|
25
|
|
|
|
2
|
|
|
|
|
43
|
|
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
1
|
|
|
1
|
1
|
469
|
sub member_count { scalar @{$_[0]->_members} } |
|
|
1
|
|
|
|
|
6
|
|
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
1; |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
__END__ |