| 1 | package MooseFS; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 10 | ▶ | use 5.006; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 10 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 10 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 10 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 10 | ▶ | use IO::Socket::INET; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | MooseFS - The MooseFS Info API! | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | =head1 VERSION | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | Version 0.04 | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 10 | our $VERSION = '0.04'; | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | The large portions of the code in my library have been taken directly from the Web UI that ships with MooseFS. | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | Just use different objects to get different informations of the MooseFS cluster. | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | use MooseFS::Server; | ||||||||||||||||||||
| 30 | my $mfs = MooseFS::Server->new( | ||||||||||||||||||||
| 31 | masterhost => '127.0.0.1' | ||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||
| 33 | say Dumper $mfs->info; | ||||||||||||||||||||
| 34 | say for $mfs->list; | ||||||||||||||||||||
| 35 | say $mfs->masterversion; | ||||||||||||||||||||
| 36 | ... | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | =head1 LIMIT | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | Don't support version below 1.6.13 by now. | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | =cut | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | has masterhost => ( | ||||||||||||||||||||
| 45 | is => 'ro', | ||||||||||||||||||||
| 46 | 0 | ▶ | default => sub { '127.0.0.1' } | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 47 | 10 | ); | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | has masterport => ( | ||||||||||||||||||||
| 50 | is => 'ro', | ||||||||||||||||||||
| 51 | 0 | ▶ | default => sub { 9421 } | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 52 | 10 | ); | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 10 | has masterversion => ( | |||||||||||||||||||
| 55 | is => 'ro', | ||||||||||||||||||||
| 56 | lazy => 1, | ||||||||||||||||||||
| 57 | builder => '_check_version', | ||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 10 | has sock => ( | |||||||||||||||||||
| 61 | is => 'rw', | ||||||||||||||||||||
| 62 | lazy => 1, | ||||||||||||||||||||
| 63 | builder => '_create_sock', | ||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 10 | has info => ( | |||||||||||||||||||
| 67 | is => 'rw', | ||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 0 | ▶ | sub _create_sock { | ||||||||||||||||||
|
Subroutine
_create_sock: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 71 | 0 | my $self = shift; | |||||||||||||||||||
| 72 | 0 | IO::Socket::INET->new( | |||||||||||||||||||
| 73 | PeerAddr => $self->masterhost, | ||||||||||||||||||||
| 74 | PeerPort => $self->masterport, | ||||||||||||||||||||
| 75 | Proto => 'tcp', | ||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||
| 77 | }; | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | ▶ | sub _check_version { | ||||||||||||||||||
|
Subroutine
_check_version: not called CC=6 SCAR=37.4
| |||||||||||||||||||||
| 80 | 0 | my $self = shift; | |||||||||||||||||||
| 81 | 0 | my $s = $self->sock; | |||||||||||||||||||
| 82 | 0 | print $s pack('(LL)>', 510, 0); | |||||||||||||||||||
| 83 | 0 | my $header = $self->myrecv($s, 8); | |||||||||||||||||||
| 84 | 0 | my ($cmd, $length) = unpack('(LL)>', $header); | |||||||||||||||||||
| 85 | 0 | my $data = $self->myrecv($s, $length); | |||||||||||||||||||
| 86 | 0 | ▶ | if ( $cmd == 511 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 87 | 0 | ▶ | if ( $length == 52 ) { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 88 | 0 | return 1400; | |||||||||||||||||||
| 89 | } elsif ( $length == 60 ) { | ||||||||||||||||||||
| 90 | 0 | return 1500; | |||||||||||||||||||
| 91 | ▶ | } elsif ( $length == 68 or $length == 76) { | |||||||||||||||||||
|
Condition0%0/3
$length == 68 or $length == 76
MC/DC0%0/2
$length == 68 or $length == 76
$length == 68
$length == 76
Truth table0%0/3
A or B
A= $length == 68B= $length == 76
| |||||||||||||||||||||
| 92 | 0 | return sprintf "%d%d%02d", unpack("(SCC)>", substr($data, 0, 4)); | |||||||||||||||||||
| 93 | }; | ||||||||||||||||||||
| 94 | }; | ||||||||||||||||||||
| 95 | }; | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 0 | ▶ | sub myrecv { | ||||||||||||||||||
|
Subroutine
myrecv: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 98 | 0 | my ($self, $socket, $len) = @_; | |||||||||||||||||||
| 99 | 0 | my $msg = ''; | |||||||||||||||||||
| 100 | 0 | ▶ | while ( length($msg) < $len ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 101 | 0 | my $chunk; | |||||||||||||||||||
| 102 | 0 | sysread $socket, $chunk, $len-length($msg); | |||||||||||||||||||
| 103 | 0 | ▶ | die "Socket Close." if $chunk eq ''; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 104 | 0 | $msg .= $chunk; | |||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | 0 | return $msg; | |||||||||||||||||||
| 107 | }; | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | =head1 SEE ALSO | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | =over 4 | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | =item L<http://www.moosefs.org> | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | =item L<https://github.com/techhat/python-moosefs> | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | =item L<https://github.com/chenryn/perl-moosefs> | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | =back | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | =head1 AUTHOR | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | chenryn, C<< <rao.chenlin at gmail.com> >> | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | =head1 BUGS | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | Please report any bugs or feature requests to C<bug-moosefs at rt.cpan.org>, or through | ||||||||||||||||||||
| 128 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseFS>. I will be notified, and then you'll | ||||||||||||||||||||
| 129 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | =head1 SUPPORT | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | perldoc MooseFS | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | Copyright 2013 chenryn. | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||
| 149 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||||||||||||
| 150 | copy of the full license at: | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | Any use, modification, and distribution of the Standard or Modified | ||||||||||||||||||||
| 155 | Versions is governed by this Artistic License. By using, modifying or | ||||||||||||||||||||
| 156 | distributing the Package, you accept this license. Do not use, modify, | ||||||||||||||||||||
| 157 | or distribute the Package, if you do not accept this license. | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | If your Modified Version has been derived from a Modified Version made | ||||||||||||||||||||
| 160 | by someone other than you, you are nevertheless required to ensure that | ||||||||||||||||||||
| 161 | your Modified Version complies with the requirements of this license. | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | This license does not grant you the right to use any trademark, service | ||||||||||||||||||||
| 164 | mark, tradename, or logo of the Copyright Holder. | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | This license includes the non-exclusive, worldwide, free-of-charge | ||||||||||||||||||||
| 167 | patent license to make, have made, use, offer to sell, sell, import and | ||||||||||||||||||||
| 168 | otherwise transfer the Package with respect to any patent claims | ||||||||||||||||||||
| 169 | licensable by the Copyright Holder that are necessarily infringed by the | ||||||||||||||||||||
| 170 | Package. If you institute patent litigation (including a cross-claim or | ||||||||||||||||||||
| 171 | counterclaim) against any party alleging that the Package constitutes | ||||||||||||||||||||
| 172 | direct or contributory patent infringement, then this Artistic License | ||||||||||||||||||||
| 173 | to you shall terminate on the date that such litigation is filed. | ||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||||||||||||||||||||
| 176 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||||||||||||||||||||
| 177 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||||||||||||||||||||
| 178 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||||||||||||||||||||
| 179 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||||||||||||||||||||
| 180 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||||||||||||||||||||
| 181 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||||||||||||||||||||
| 182 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | =cut | ||||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | 10 | 1; # End of MooseFS | |||||||||||||||||||