Net::Hadoop::WebHDFS - Client library for Hadoop WebHDFS and HttpFs
use Net::Hadoop::WebHDFS;
my $client = Net::Hadoop::WebHDFS->new( host => 'hostname.local', port => 50070 );
my $statusArrayRef = $client->list('/');
my $contentData = $client->read('/data.txt');
$client->create('/foo/bar/data.bin', $bindata);
This module supports WebHDFS v1 on Hadoop 1.x (and CDH4.0.0 or later), and HttpFs on Hadoop 2.x (and CDH4 or later). WebHDFS/HttpFs has two authentication methods: pseudo authentication and Kerberos, but this module supports pseudo authentication only.
Net::Hadoop::WebHDFS class method and instance methods.
Creates and returns a new client instance with %args. If you are using HttpFs, set httpfs_mode => 1 and port => 14000.
%args might be:
- host :Str = "namenode.local"
- port :Int = 50070
- standby_host :Str = "standby.namenode.local"
- standby_port :Int = 50070
- username :Str = "hadoop"
- doas :Str = "hdfs"
- httpfs_mode :Bool = 0/1
Creates file on HDFS with $body data. If you want to create blank file, pass blank string.
%options might be:
- overwrite :Str = "true" or "false"
- blocksize :Int
- replication :Int
- permission :Str = "0600"
- buffersize :Int
Append $body data to $path file.
%options might be:
- buffersize :Int
Open file of $path and returns its content. Alias: open.
%options might be:
- offset :Int
- length :Int
- buffersize :Int
Make directory $path on HDFS. Alias: mkdirs.
Rename file or directory as $dest.
Delete file $path from HDFS. With optional recursive => 1, files and directories are removed recursively (default false).
Get and returns file status object for $path. Alias: getfilestatus.
Get list of files in directory $path, and returns these status objects arrayref. Alias: liststatus.
Get 'content summary' object and returns it. Alias: getcontentsummary.
Get checksum information object for $path. Alias: getfilechecksum.
Get accessing user's home directory path. Alias: gethomedirectory.
Set permission of $path as octal $mode. Alias: setpermission.
Set owner or group of $path. One of owner/group must be specified. Alias: setowner.
Set replica number for $path. Alias: setreplication.
Set mtime/atime of $path. Alias: settimes.
Create a zero length file.
Test if the user has the rights to do a file system action.
Concatenate paths.
Truncate a path contents.
This is a method wrapping the multiple methods for delegation token handling.
my $token = $client->delegation_token( get => $path );
print "Token: $token\n";
my $milisec = $client->delegation_token( renew => $token );
printf "Token expiration renewed until %s\n", scalar localtime $milisec / 1000;
if ( $client->delegation_token( cancel => $token ) ) {
print "Token cancelled. There will be a new one created.\n";
my $token_new = $client->delegation_token( get => $path );
print "New token: $token_new\n";
printf "New token is %s\n", $token_new eq $token ? 'the same' : 'different';
}
else {
warn "Failed to cancel token $token!";
}
$client->delegation_token( get => $path, [renewer => $username, service => $service, kind => $kind ] ) :Str )
Returns the delegation token id for the specified path.
Returns the new expiration time for the specified delegation token in miliseconds.
Cancels the specified delegation token (which will force a new one to be created.
This is a method wrapping the multiple methods for snapshot handling.
Creates a new snaphot on the specified path and returns the name of the snapshot.
Renames the snaphot.
Deletes the specified snapshot.
This is a method wrapping the multiple methods for extended attributes handling.
my @attr_names = $client->xattr( $path, 'list' );
my %attr = $client->xattr( $path, get => flatten => 1 );
if ( ! exists $attr{'user.bar'} ) {
warn "set user.bar = 42\n";
$client->xattr( $path, create => 'user.bar' => 42 )
|| warn "Failed to create user.bar";
}
else {
warn "alter user.bar = 24\n";
$client->xattr( $path, replace => 'user.bar' => 24 )
|| warn "Failed to replace user.bar";
;
}
if ( exists $attr{'user.foo'} ) {
warn "No more foo\n";
$client->xattr( $path, remove => 'user.foo')
|| warn "Failed to remove user.foo";
;
}
$client->xattr( $path, get => [, names => \@attr_names] [, flatten => 1 ] [, encoding => $enc ] ) :Struct
Returns the extended attribute key/value pairs on a path. The default data set
is an array of hashrefs with the pairs, however if you set <flatten
> to a true
value then a simple hash will be returned.
It is also possible to fetch a subset of the attributes if you specify the
names of them with the <names
> option.
This method will return the names of all the attributes set on <$path
>.
It is possible to create a new extended attribute on a path with this method.
It is possible to replace the value of an existing extended attribute on a path with this method.
Deletes the speficied attribute on <$path
>.
Returns the stat()
hash if successful, and false otherwise. Dies on
interface errors.
Loops recursively over the specified path:
$client->find(
'/user',
sub {
my($cwd, $path) = @_;
my $date = localtime $path->{modificationTime};
my $type = $path->{type} eq q{DIRECTORY} ? "[dir ]" : "[file]";
my $size = sprintf "% 10s",
$path->{blockSize}
? sprintf "%.2f MB", $path->{blockSize} / 1024**2
: 0;
print "$type $size $path->{permission} $path->{owner}:$path->{group} $cwd/$path->{pathSuffix}\n";
},
{ # optional
re_ignore => qr{
\A # Filter some filenames out even before reaching the callback
[_] # logs and meta data, java junk, _SUCCESS files, etc.
}xms,
}
);
TAGOMORI Satoshi <tagomoris {at} gmail.com>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.