Module: Hdfs
- Includes:
- Java
- Defined in:
- lib/hdfs_jruby.rb,
lib/hdfs_jruby/file.rb,
lib/hdfs_jruby/version.rb
Defined Under Namespace
Classes: Configuration, File, FileSystem, FsPermission, Path
Constant Summary
collapse
- JAR_PATTERN_0_20 =
"hadoop-core-*.jar"
- HADOOP_HOME =
ENV["HADOOP_HOME"]
- VERSION =
"0.0.2"
Class Method Summary
collapse
Class Method Details
._path(path) ⇒ Object
137
138
139
140
141
142
|
# File 'lib/hdfs_jruby.rb', line 137
def _path(path)
if path.nil?
raise "path is nil"
end
Path.new(path)
end
|
.delete(path, r = false) ⇒ Object
72
73
74
|
# File 'lib/hdfs_jruby.rb', line 72
def delete(path, r=false)
@fs.delete(_path(path), r)
end
|
.directory?(path) ⇒ Boolean
80
81
82
|
# File 'lib/hdfs_jruby.rb', line 80
def directory?(path)
@fs.isDirectory(_path(path))
end
|
.exists?(path) ⇒ Boolean
64
65
66
|
# File 'lib/hdfs_jruby.rb', line 64
def exists?(path)
@fs.exists(_path(path))
end
|
.file?(path) ⇒ Boolean
76
77
78
|
# File 'lib/hdfs_jruby.rb', line 76
def file?(path)
@fs.isFile(_path(path))
end
|
.get(remote, local) ⇒ Object
96
97
98
|
# File 'lib/hdfs_jruby.rb', line 96
def get(remote, local)
@fs.copyToLocalFile(Path.new(remote), Path.new(local))
end
|
.get_home_directory ⇒ Object
100
101
102
|
# File 'lib/hdfs_jruby.rb', line 100
def get_home_directory()
@fs.getHomeDirectory()
end
|
.get_working_directory ⇒ Object
104
105
106
|
# File 'lib/hdfs_jruby.rb', line 104
def get_working_directory()
@fs.getWorkingDirectory()
end
|
.list(path, use_glob = true) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/hdfs_jruby.rb', line 39
def list(path, use_glob=true)
p = _path(path)
if ! block_given?
raise "error"
else
list = nil
if use_glob
list = @fs.globStatus(p)
else
list = @fs.listStatus(p)
end
list.each do | stat |
file_info = {}
file_info['path'] = stat.getPath.to_s
file_info['length'] = stat.getLen.to_i
file_info['modificationTime'] = stat.getModificationTime.to_i
file_info['owner'] = stat.getOwner.to_s
file_info['group'] = stat.getGroup.to_s
file_info['permission'] = stat.getPermission.toShort.to_i
file_info['type'] = !stat.isDir ? 'FILE': 'DIRECTORY'
yield file_info
end
end
end
|
.mkdir(path) ⇒ Object
88
89
90
|
# File 'lib/hdfs_jruby.rb', line 88
def mkdir(path)
@fs.mkdirs(_path(path))
end
|
.move(src, dst) ⇒ Object
68
69
70
|
# File 'lib/hdfs_jruby.rb', line 68
def move(src, dst)
@fs.rename(Path.new(src), Path.new(dst))
end
|
.put(local, remote) ⇒ Object
92
93
94
|
# File 'lib/hdfs_jruby.rb', line 92
def put(local, remote)
@fs.copyFromLocalFile(Path.new(local), Path.new(remote))
end
|
.set_owner(path, owner, group) ⇒ Object
116
117
118
|
# File 'lib/hdfs_jruby.rb', line 116
def set_owner(path, owner, group)
@fs.setOwner(_path(path), owner, group)
end
|
.set_permission(path, perm) ⇒ Object
112
113
114
|
# File 'lib/hdfs_jruby.rb', line 112
def set_permission(path, perm)
@fs.setPermission(_path(path), org.apache.hadoop.fs.permission.FsPermission.new(perm))
end
|
.set_working_directory(path) ⇒ Object
108
109
110
|
# File 'lib/hdfs_jruby.rb', line 108
def set_working_directory(path)
@fs.setWorkingDirectory(_path())
end
|
.size(path) ⇒ Object
84
85
86
|
# File 'lib/hdfs_jruby.rb', line 84
def size(path)
@fs.getFileStatus(_path(path)).getLen()
end
|