line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Hadoop::HuahinManager; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
28654
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
5
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
101
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1081
|
use URI::Escape qw//; |
|
1
|
|
|
|
|
1507
|
|
|
1
|
|
|
|
|
33
|
|
8
|
1
|
|
|
1
|
|
1151
|
use JSON::XS qw//; |
|
1
|
|
|
|
|
10193
|
|
|
1
|
|
|
|
|
27
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
827
|
use Furl; |
|
1
|
|
|
|
|
35743
|
|
|
1
|
|
|
|
|
841
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = "0.03"; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
1
|
|
|
1
|
1
|
2649
|
my ($this, %opts) = @_; |
16
|
1
|
50
|
|
|
|
6
|
croak "Huahin Manager server name missing" unless $opts{server}; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
50
|
|
|
23
|
my $self = +{ |
|
|
|
33
|
|
|
|
|
|
|
|
50
|
|
|
|
|
19
|
|
|
|
|
|
|
server => $opts{server}, |
20
|
|
|
|
|
|
|
port => $opts{port} || 9010, |
21
|
|
|
|
|
|
|
useragent => $opts{useragent} || "Furl Net::Hadoop::HuahinManager $VERSION", |
22
|
|
|
|
|
|
|
timeout => $opts{timeout} || 10, |
23
|
|
|
|
|
|
|
}; |
24
|
1
|
|
|
|
|
15
|
$self->{furl} = Furl::HTTP->new(agent => $self->{useragent}, timeout => $self->{timeout}); |
25
|
1
|
|
|
|
|
49
|
return bless $self, $this; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub list { |
29
|
0
|
|
|
0
|
1
|
|
my ($self, $op) = @_; |
30
|
0
|
|
0
|
|
|
|
$op ||= 'all'; |
31
|
0
|
|
|
|
|
|
my $path = '/job/list'; # for all |
32
|
0
|
0
|
|
|
|
|
if ($op eq 'failed') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
$path = '/job/list/failed'; |
34
|
|
|
|
|
|
|
} elsif ($op eq 'killed') { |
35
|
0
|
|
|
|
|
|
$path = '/job/list/killed'; |
36
|
|
|
|
|
|
|
} elsif ($op eq 'prep') { |
37
|
0
|
|
|
|
|
|
$path = '/job/list/prep'; |
38
|
|
|
|
|
|
|
} elsif ($op eq 'running') { |
39
|
0
|
|
|
|
|
|
$path = '/job/list/running'; |
40
|
|
|
|
|
|
|
} elsif ($op eq 'succeeded') { |
41
|
0
|
|
|
|
|
|
$path = '/job/list/succeeded'; |
42
|
|
|
|
|
|
|
} |
43
|
0
|
|
|
|
|
|
return $self->request('GET', $path); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub status { |
47
|
0
|
|
|
0
|
1
|
|
my ($self, $jobid) = @_; |
48
|
0
|
|
|
|
|
|
return $self->request('GET', '/job/status/' . URI::Escape::uri_escape($jobid)); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub detail { |
52
|
0
|
|
|
0
|
1
|
|
my ($self, $jobid) = @_; |
53
|
0
|
|
|
|
|
|
return $self->request('GET', '/job/detail/' . URI::Escape::uri_escape($jobid)); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub kill { |
57
|
0
|
|
|
0
|
1
|
|
my ($self, $jobid) = @_; |
58
|
0
|
|
|
|
|
|
return $self->request('DELETE', '/job/kill/id/' . URI::Escape::uri_escape($jobid)); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub kill_by_name { |
62
|
0
|
|
|
0
|
1
|
|
my ($self, $jobname) = @_; |
63
|
0
|
|
|
|
|
|
return $self->request('DELETE', '/job/kill/name/' . URI::Escape::uri_escape($jobname)); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub request { |
67
|
0
|
|
|
0
|
0
|
|
my ($self, $method, $path) = @_; |
68
|
0
|
|
|
|
|
|
my @request_params = ( |
69
|
|
|
|
|
|
|
method => $method, |
70
|
|
|
|
|
|
|
host => $self->{server}, |
71
|
|
|
|
|
|
|
port => $self->{port}, |
72
|
|
|
|
|
|
|
path_query => $path, |
73
|
|
|
|
|
|
|
); |
74
|
0
|
|
|
|
|
|
my ($ver, $code, $msg, $headers, $body) = $self->{furl}->request(@request_params); |
75
|
0
|
|
|
|
|
|
my $content_type = undef; |
76
|
0
|
|
|
|
|
|
for (my $i = 0; $i < scalar(@$headers); $i += 2) { |
77
|
0
|
0
|
|
|
|
|
if ($headers->[$i] =~ m!\Acontent-type\Z!i) { |
78
|
0
|
|
|
|
|
|
$content_type = $headers->[$i+1]; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
|
if ($code == 200) { |
83
|
0
|
0
|
0
|
|
|
|
if ($content_type =~ m!^application/json! and length($body) > 0) { |
84
|
0
|
|
|
|
|
|
return JSON::XS::decode_json($body); |
85
|
|
|
|
|
|
|
} |
86
|
0
|
|
|
|
|
|
return 1; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
# error |
89
|
0
|
|
|
|
|
|
carp "Huahin Manager returns error: $code"; |
90
|
0
|
|
|
|
|
|
return undef; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |