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.4"

Class Method Summary collapse

Class Method Details

._conv(stat) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
# File 'lib/hdfs_jruby.rb', line 180

def _conv(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'
  return file_info
end

._path(path) ⇒ Object



173
174
175
176
177
178
# File 'lib/hdfs_jruby.rb', line 173

def _path(path)
  if path.nil?
    raise "path is nil"
  end
  Path.new(path)
end

.connectAsUser(user) ⇒ Object



39
40
41
42
43
# File 'lib/hdfs_jruby.rb', line 39

def connectAsUser(user)
  uri =  Hdfs::FileSystem.getDefaultUri(@conf)
  @fs.close if ! @fs.nil?
  @fs = Hdfs::FileSystem.get(uri, @conf, user)
end

.delete(path, r = false) ⇒ Object



106
107
108
# File 'lib/hdfs_jruby.rb', line 106

def delete(path, r=false)
  @fs.delete(_path(path), r)
end

.directory?(path) ⇒ Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/hdfs_jruby.rb', line 114

def directory?(path)
  @fs.isDirectory(_path(path))
end

.exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/hdfs_jruby.rb', line 98

def exists?(path)
  @fs.exists(_path(path))
end

.file?(path) ⇒ Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/hdfs_jruby.rb', line 110

def file?(path)
  @fs.isFile(_path(path))
end

.get(remote, local) ⇒ Object



130
131
132
# File 'lib/hdfs_jruby.rb', line 130

def get(remote, local)
  @fs.copyToLocalFile(Path.new(remote), Path.new(local))
end

.get_home_directoryObject



134
135
136
# File 'lib/hdfs_jruby.rb', line 134

def get_home_directory()
  @fs.getHomeDirectory()
end

.get_working_directoryObject



138
139
140
# File 'lib/hdfs_jruby.rb', line 138

def get_working_directory()
  @fs.getWorkingDirectory()
end

.list(path, opts = {}) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/hdfs_jruby.rb', line 74

def list(path, opts={})
  use_glob = opts[:glob] ? true : false
  p = _path(path)

  list = nil
  if use_glob
    list = @fs.globStatus(p)
  else
    list = @fs.listStatus(p)
  end
    
  if ! block_given?
    ret_list = []
    list.each do | stat |
      ret_list << _conv(stat)
    end
    return ret_list
  else
    list.each do | stat |
      yield _conv(stat)
    end
  end
end

.ls(path) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/hdfs_jruby.rb', line 45

def ls(path)
  p = _path(path)
  list = @fs.globStatus(p)
  return [] if list.nil?

  ret_list = []
  list.each do |stat|
    if stat.isDir
      sub_list = @fs.listStatus(stat.getPath)
      next if sub_list.nil?
      
      sub_list.each do | s |
        if block_given?
          yield _conv(s)
        else
          ret_list << _conv(s)
        end
      end
    else
      if block_given?
        yield _conv(stat)
      else
        ret_list << _conv(stat)
      end
    end
  end
  ret_list if ! block_given?
end

.mkdir(path) ⇒ Object



122
123
124
# File 'lib/hdfs_jruby.rb', line 122

def mkdir(path)
  @fs.mkdirs(_path(path))
end

.move(src, dst) ⇒ Object



102
103
104
# File 'lib/hdfs_jruby.rb', line 102

def move(src, dst)
  @fs.rename(Path.new(src), Path.new(dst))
end

.put(local, remote) ⇒ Object



126
127
128
# File 'lib/hdfs_jruby.rb', line 126

def put(local, remote)
  @fs.copyFromLocalFile(Path.new(local), Path.new(remote))
end

.set_owner(path, owner, group) ⇒ Object



150
151
152
# File 'lib/hdfs_jruby.rb', line 150

def set_owner(path, owner, group)
  @fs.setOwner(_path(path), owner, group)
end

.set_permission(path, perm) ⇒ Object



146
147
148
# File 'lib/hdfs_jruby.rb', line 146

def set_permission(path, perm)
  @fs.setPermission(_path(path), org.apache.hadoop.fs.permission.FsPermission.new(perm))
end

.set_working_directory(path) ⇒ Object



142
143
144
# File 'lib/hdfs_jruby.rb', line 142

def set_working_directory(path)
  @fs.setWorkingDirectory(_path())
end

.size(path) ⇒ Object



118
119
120
# File 'lib/hdfs_jruby.rb', line 118

def size(path)
  @fs.getFileStatus(_path(path)).getLen()
end