line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Flower::Rest; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
14278
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
7
|
1
|
|
|
1
|
|
7
|
use feature qw(say switch); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
83
|
|
8
|
1
|
|
|
1
|
|
5
|
use Data::Printer; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
9
|
1
|
|
|
1
|
|
52
|
use Mojo::Base 'Mojolicious::Controller'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
10
|
1
|
|
|
1
|
|
127
|
use JSON::XS; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
79
|
|
11
|
1
|
|
|
1
|
|
910
|
use Number::Format qw/format_bytes/; |
|
1
|
|
|
|
|
5253
|
|
|
1
|
|
|
|
|
96
|
|
12
|
1
|
|
|
1
|
|
807
|
use Data::FreqConvert; |
|
1
|
|
|
|
|
19540
|
|
|
1
|
|
|
|
|
1126
|
|
13
|
|
|
|
|
|
|
my $json = JSON::XS->new->allow_nonref; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#my $json = JSON::XS->new->allow_nonref(); |
16
|
|
|
|
|
|
|
# respond to a ping |
17
|
|
|
|
|
|
|
sub ping { |
18
|
1
|
|
|
1
|
0
|
322
|
my $self = shift; |
19
|
1
|
|
|
|
|
14
|
my $config = $self->config; |
20
|
1
|
|
|
|
|
70
|
my $nodes = $self->req->json; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Add all the nodes that have been advertised to us by the pinger. |
23
|
1
|
|
|
|
|
2934
|
foreach (@$nodes) { |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# add nodes that have a UUID |
26
|
|
|
|
|
|
|
$config->{nodes}->add_if_necessary($_) |
27
|
0
|
0
|
|
|
|
0
|
if ( $_->{uuid} ); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$self->render( |
31
|
1
|
|
|
|
|
9
|
json => { result => 'ok', 'uuid' => $config->{nodes}->self->uuid } ); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# list my files |
35
|
|
|
|
|
|
|
sub files { |
36
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
37
|
0
|
|
|
|
|
|
my $config = $self->config; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $files_hashref = $config->{nodes}->self->files->as_hashref; |
40
|
0
|
|
|
|
|
|
$self->render( json => { result => 'ok', files => $files_hashref } ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# list my files |
46
|
|
|
|
|
|
|
sub query { |
47
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
48
|
0
|
|
|
|
|
|
my $config = $self->config; |
49
|
0
|
|
0
|
|
|
|
my $type = $self->param('type') || "class"; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$self->ua->get('http://localhost:9200/_search?size=10000000&pretty=1' => sub { |
53
|
0
|
|
|
0
|
|
|
my ($ua, $tx) = @_; |
54
|
0
|
|
|
|
|
|
my $hits = $tx->res->json->{hits}{hits}; |
55
|
0
|
|
|
|
|
|
my $h = {}; |
56
|
0
|
|
|
|
|
|
my @freq = (); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
for my $hit (@$hits) { |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
#$hit->{_source}{name}=~ s/\W//g; |
62
|
0
|
0
|
|
|
|
|
push @freq,$hit->{_source}{$type} unless !$hit->{_source}{$type}; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $data = Data::FreqConvert->new; |
67
|
0
|
|
|
|
|
|
$h = $data->freq(\@freq); |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$self->render("interface/root",set => $h); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
}); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# all files we know about |
76
|
|
|
|
|
|
|
sub files_all { |
77
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
78
|
0
|
|
|
|
|
|
my $config = $self->config; |
79
|
0
|
|
|
|
|
|
my $stats = {}; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my @all_files = (); |
82
|
0
|
|
|
|
|
|
foreach my $node ( $config->{nodes}->list ) { |
83
|
0
|
|
|
|
|
|
$stats->{total_nodes}++; |
84
|
0
|
|
|
|
|
|
push @all_files, @{ $node->files->as_hashref }; |
|
0
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
$stats->{total_files} = scalar @all_files; |
88
|
0
|
|
|
|
|
|
$stats->{total_bytes} += $_->{size} foreach @all_files; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
$stats->{$_} = format_bytes( $stats->{$_} ) |
91
|
0
|
|
|
|
|
|
foreach (qw/total_files total_bytes/); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# sort for presentation |
94
|
|
|
|
|
|
|
# newest at the top |
95
|
0
|
|
|
|
|
|
@all_files = sort { $b->{mtime} <=> $a->{mtime} } @all_files; |
|
0
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
$self->render( |
98
|
|
|
|
|
|
|
json => { |
99
|
|
|
|
|
|
|
result => 'ok', |
100
|
|
|
|
|
|
|
files => \@all_files, |
101
|
|
|
|
|
|
|
stats => $stats |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
sub file_get_by_uuid { |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
109
|
0
|
|
|
|
|
|
my $config = $self->config; |
110
|
0
|
|
|
|
|
|
my $stats = {}; |
111
|
0
|
|
|
|
|
|
my @user_files = (); |
112
|
0
|
|
|
|
|
|
my @all_files = (); |
113
|
0
|
|
|
|
|
|
foreach my $node ( $config->{nodes}->list ) { |
114
|
0
|
|
|
|
|
|
$stats->{total_nodes}++; |
115
|
0
|
|
|
|
|
|
push @all_files, @{ $node->files->as_hashref }; |
|
0
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
$stats->{total_files} = 0; |
122
|
|
|
|
|
|
|
#scalar @all_files; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
foreach(@all_files){ |
125
|
|
|
|
|
|
|
|
126
|
0
|
0
|
|
|
|
|
next unless $config->{nodes}->self->uuid =~ $_->{uuid}; |
127
|
0
|
|
|
|
|
|
$stats->{total_files}++; |
128
|
0
|
|
|
|
|
|
$stats->{total_bytes} += $_->{size}; |
129
|
0
|
|
|
|
|
|
push @user_files ,$_ ; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
$stats->{$_} = format_bytes( $stats->{$_} ) |
132
|
0
|
|
|
|
|
|
foreach (qw/total_files total_bytes/); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# sort for presentation |
135
|
|
|
|
|
|
|
# newest at the top |
136
|
0
|
|
|
|
|
|
@all_files = sort { $b->{mtime} <=> $a->{mtime} } @user_files; |
|
0
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
p $config; |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
$self->render( |
142
|
|
|
|
|
|
|
json => { |
143
|
|
|
|
|
|
|
result => 'ok', |
144
|
|
|
|
|
|
|
files => \@all_files, |
145
|
|
|
|
|
|
|
stats => $stats |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
); |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
1; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
__DATA__ |