webhdfs 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/AUTHORS +1 -0
- data/Gemfile +5 -0
- data/Rakefile +17 -0
- data/VERSION +1 -0
- data/lib/webhdfs.rb +1 -0
- data/lib/webhdfs/fileutils.rb +162 -0
- data/test/test_helper.rb +19 -0
- data/test/webhdfs/fileutils.rb +54 -0
- data/webhdfs.gemspec +23 -0
- metadata +101 -0
data/.gitignore
ADDED
data/AUTHORS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Kazuki Ohta <kazuki.ohta@gmail.com>
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |test|
|
7
|
+
test.libs << 'lib' << 'test'
|
8
|
+
test.test_files = FileList['test/webhdfs/*.rb']
|
9
|
+
test.verbose = true
|
10
|
+
end
|
11
|
+
|
12
|
+
task :coverage do |t|
|
13
|
+
ENV['SIMPLE_COV'] = '1'
|
14
|
+
Rake::Task["test"].invoke
|
15
|
+
end
|
16
|
+
|
17
|
+
task :default => [:build]
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1
|
data/lib/webhdfs.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'webhdfs', 'fileutils.rb')
|
@@ -0,0 +1,162 @@
|
|
1
|
+
module WebHDFS
|
2
|
+
module FileUtils
|
3
|
+
require 'rest_client'
|
4
|
+
|
5
|
+
# This hash table holds command options.
|
6
|
+
OPT_TABLE = {} # internal use only
|
7
|
+
|
8
|
+
@fu_host = 'localhost'
|
9
|
+
@fu_port = 50070
|
10
|
+
def set_host(host, port)
|
11
|
+
@fu_host = host
|
12
|
+
@fu_port = port
|
13
|
+
end
|
14
|
+
|
15
|
+
def mkdir(list, options={})
|
16
|
+
fu_check_options options, OPT_TABLE['mkdir']
|
17
|
+
list = fu_list(list)
|
18
|
+
fu_log "mkdir #{options[:mode] ? ('-m %03o ' % options[:mode]) : ''}#{list.join ' '}" if options[:verbose]
|
19
|
+
if mode = options[:mode]
|
20
|
+
mode = ('0%03o' % mode) if mode.is_a? Integer
|
21
|
+
else
|
22
|
+
mode = '0755'
|
23
|
+
end
|
24
|
+
list.each { |dir|
|
25
|
+
fu_put(dir, 'MKDIRS', {:permission => mode})
|
26
|
+
}
|
27
|
+
end
|
28
|
+
OPT_TABLE['mkdir'] = [:mode, :verbose]
|
29
|
+
module_function :mkdir
|
30
|
+
|
31
|
+
alias mkdir_p mkdir
|
32
|
+
module_function :mkdir_p
|
33
|
+
|
34
|
+
def rm(list, options={})
|
35
|
+
fu_check_options options, OPT_TABLE['rm']
|
36
|
+
list = fu_list(list)
|
37
|
+
fu_log "rm #{list.join ' '}" if options[:verbose]
|
38
|
+
list.each { |dir|
|
39
|
+
fu_delete(dir, 'DELETE', {:recursive => options[:recursive] || false})
|
40
|
+
}
|
41
|
+
end
|
42
|
+
OPT_TABLE['rm'] = [:verbose, :recursive]
|
43
|
+
module_function :rm
|
44
|
+
|
45
|
+
def rmr(list, options={})
|
46
|
+
fu_check_options options, OPT_TABLE['rmr']
|
47
|
+
self.rm(list, options.merge({:recursive => true}))
|
48
|
+
end
|
49
|
+
OPT_TABLE['rmr'] = [:verbose, :recursive]
|
50
|
+
module_function :rmr
|
51
|
+
|
52
|
+
def rename(src, dst, options={})
|
53
|
+
fu_check_options options, OPT_TABLE['rename']
|
54
|
+
fu_log "rename #{src} #{dst}" if options[:verbose]
|
55
|
+
fu_put(src, 'RENAME', {:destination => dst})
|
56
|
+
end
|
57
|
+
OPT_TABLE['rename'] = [:verbose]
|
58
|
+
module_function :rename
|
59
|
+
|
60
|
+
def chmod(mode, list, options={})
|
61
|
+
fu_check_options options, OPT_TABLE['chmod']
|
62
|
+
list = fu_list(list)
|
63
|
+
fu_log sprintf('chmod %o %s', mode, list.join(' ')) if options[:verbose]
|
64
|
+
mode = ('0%03o' % mode) if mode.is_a? Integer
|
65
|
+
list.each { |dir|
|
66
|
+
fu_put(dir, 'SETPERMISSION', {:permission => mode})
|
67
|
+
}
|
68
|
+
end
|
69
|
+
OPT_TABLE['chmod'] = [:verbose]
|
70
|
+
module_function :chmod
|
71
|
+
|
72
|
+
def chown(user, group, list, options={})
|
73
|
+
fu_check_options options, OPT_TABLE['chown']
|
74
|
+
list = fu_list(list)
|
75
|
+
fu_log sprintf('chown %s%s',
|
76
|
+
[user,group].compact.join(':') + ' ',
|
77
|
+
list.join(' ')) if options[:verbose]
|
78
|
+
list.each { |dir|
|
79
|
+
fu_put(dir, 'SETOWNER', {:owner => user, :group => group})
|
80
|
+
}
|
81
|
+
end
|
82
|
+
OPT_TABLE['chown'] = [:verbose]
|
83
|
+
module_function :chown
|
84
|
+
|
85
|
+
def set_repl_factor(list, num, options={})
|
86
|
+
fu_check_options options, OPT_TABLE['set_repl_factor']
|
87
|
+
list = fu_list(list)
|
88
|
+
fu_log sprintf('set_repl_factor %s %d',
|
89
|
+
list.join(' '), num) if options[:verbose]
|
90
|
+
list.each { |dir|
|
91
|
+
fu_put(dir, 'SETREPLICATION', {:replication => num})
|
92
|
+
}
|
93
|
+
end
|
94
|
+
OPT_TABLE['set_repl_factor'] = [:verbose]
|
95
|
+
module_function :set_repl_factor
|
96
|
+
|
97
|
+
def set_atime(list, time, options={})
|
98
|
+
fu_check_options options, OPT_TABLE['set_atime']
|
99
|
+
list = fu_list(list)
|
100
|
+
time = time.to_i
|
101
|
+
fu_log sprintf('set_atime %s %d', list.join(' '), time) if options[:verbose]
|
102
|
+
list.each { |dir|
|
103
|
+
fu_put(dir, 'SETTIMES', {:accesstime => time})
|
104
|
+
}
|
105
|
+
end
|
106
|
+
OPT_TABLE['set_atime'] = [:verbose]
|
107
|
+
module_function :set_atime
|
108
|
+
|
109
|
+
def set_mtime(list, time, options={})
|
110
|
+
fu_check_options options, OPT_TABLE['set_mtime']
|
111
|
+
list = fu_list(list)
|
112
|
+
time = time.to_i
|
113
|
+
fu_log sprintf('set_mtime %s %d', list.join(' '), time) if options[:verbose]
|
114
|
+
list.each { |dir|
|
115
|
+
fu_put(dir, 'SETTIMES', {:modificationtime => time})
|
116
|
+
}
|
117
|
+
end
|
118
|
+
OPT_TABLE['set_mtime'] = [:verbose]
|
119
|
+
module_function :set_mtime
|
120
|
+
|
121
|
+
##
|
122
|
+
def self.private_module_function(name)
|
123
|
+
module_function name
|
124
|
+
private_class_method name
|
125
|
+
end
|
126
|
+
|
127
|
+
def fu_list(arg)
|
128
|
+
[arg].flatten
|
129
|
+
end
|
130
|
+
private_module_function :fu_list
|
131
|
+
|
132
|
+
def fu_put(path, op, params={}, payload='')
|
133
|
+
url = "http://#{@fu_host}:#{@fu_port}/webhdfs/v1/#{path}"
|
134
|
+
RestClient.put url, payload, :params => params.merge({:op => op})
|
135
|
+
end
|
136
|
+
private_module_function :fu_put
|
137
|
+
|
138
|
+
def fu_delete(path, op, params={})
|
139
|
+
url = "http://#{@fu_host}:#{@fu_port}/webhdfs/v1/#{path}"
|
140
|
+
RestClient.delete url, :params => params.merge({:op => op})
|
141
|
+
end
|
142
|
+
private_module_function :fu_delete
|
143
|
+
|
144
|
+
def fu_check_options(options, optdecl)
|
145
|
+
h = options.dup
|
146
|
+
optdecl.each do |opt|
|
147
|
+
h.delete opt
|
148
|
+
end
|
149
|
+
raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless h.empty?
|
150
|
+
end
|
151
|
+
private_module_function :fu_check_options
|
152
|
+
|
153
|
+
@fileutils_output = $stderr
|
154
|
+
@fileutils_label = '[webhdfs]: '
|
155
|
+
def fu_log(msg)
|
156
|
+
@fileutils_output ||= $stderr
|
157
|
+
@fileutils_label ||= ''
|
158
|
+
@fileutils_output.puts @fileutils_label + msg
|
159
|
+
end
|
160
|
+
private_module_function :fu_log
|
161
|
+
end
|
162
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
|
4
|
+
require 'rr'
|
5
|
+
require 'test/unit'
|
6
|
+
class Test::Unit::TestCase
|
7
|
+
include RR::Adapters::TestUnit
|
8
|
+
end
|
9
|
+
|
10
|
+
if ENV['SIMPLE_COV']
|
11
|
+
require 'simplecov'
|
12
|
+
SimpleCov.start do
|
13
|
+
add_filter 'test/'
|
14
|
+
add_filter 'pkg/'
|
15
|
+
add_filter 'vendor/'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'test/unit'
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class FileUtilsTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
require 'webhdfs'
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_rm
|
9
|
+
WebHDFS::FileUtils.mkdir('foo', :mode => 0777, :verbose => true)
|
10
|
+
WebHDFS::FileUtils.rm('foo', :verbose => true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_rmr
|
14
|
+
WebHDFS::FileUtils.mkdir_p('foo/bar/buzz', :mode => 0777, :verbose => true)
|
15
|
+
WebHDFS::FileUtils.rmr('foo', :verbose => true)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_rename
|
19
|
+
#WebHDFS::FileUtils.mkdir_p('foo', :mode => 0777, :verbose => true)
|
20
|
+
#WebHDFS::FileUtils.rename('foo', 'foo2', :verbose => true)
|
21
|
+
#WebHDFS::FileUtils.rmr('foo2', :verbose => true)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_chmod
|
25
|
+
WebHDFS::FileUtils.mkdir('foo', :mode => 0777, :verbose => true)
|
26
|
+
WebHDFS::FileUtils.chmod(0755, 'foo', :verbose => true)
|
27
|
+
WebHDFS::FileUtils.chmod(0777, 'foo', :verbose => true)
|
28
|
+
WebHDFS::FileUtils.rm('foo', :verbose => true)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_chown
|
32
|
+
#WebHDFS::FileUtils.mkdir('foo', :mode => 0777, :verbose => true)
|
33
|
+
#WebHDFS::FileUtils.chown('webuser', 'supergroup', 'foo', :verbose => true)
|
34
|
+
#WebHDFS::FileUtils.rm('foo', :verbose => true)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_set_repl_factor
|
38
|
+
WebHDFS::FileUtils.mkdir('foo', :mode => 0777, :verbose => true)
|
39
|
+
WebHDFS::FileUtils.set_repl_factor('foo', 5)
|
40
|
+
WebHDFS::FileUtils.rm('foo', :verbose => true)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_set_atime
|
44
|
+
#WebHDFS::FileUtils.mkdir('foo', :mode => 0777, :verbose => true)
|
45
|
+
#WebHDFS::FileUtils.set_atime('foo', Time.now)
|
46
|
+
#WebHDFS::FileUtils.rm('foo', :verbose => true)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_set_mtime
|
50
|
+
#WebHDFS::FileUtils.mkdir('foo', :mode => 0777, :verbose => true)
|
51
|
+
#WebHDFS::FileUtils.set_mtime('foo', Time.now)
|
52
|
+
#WebHDFS::FileUtils.rm('foo', :verbose => true)
|
53
|
+
end
|
54
|
+
end
|
data/webhdfs.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "webhdfs"
|
6
|
+
gem.description = "Ruby WebHDFS client"
|
7
|
+
gem.homepage = ""
|
8
|
+
gem.summary = gem.description
|
9
|
+
gem.version = File.read("VERSION").strip
|
10
|
+
gem.authors = ["Kazuki Ohta"]
|
11
|
+
gem.email = "kazuki.ohta@gmail.com"
|
12
|
+
gem.has_rdoc = false
|
13
|
+
#gem.platform = Gem::Platform::RUBY
|
14
|
+
gem.files = `git ls-files`.split("\n")
|
15
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
gem.require_paths = ['lib']
|
18
|
+
|
19
|
+
gem.add_dependency "rest-client", "~> 1.6.7"
|
20
|
+
gem.add_development_dependency "rake", ">= 0.9.2"
|
21
|
+
gem.add_development_dependency "simplecov", ">= 0.5.4"
|
22
|
+
gem.add_development_dependency "rr", ">= 1.0.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webhdfs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kazuki Ohta
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-11 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: &2154610720 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.6.7
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2154610720
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
requirement: &2154610240 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.9.2
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2154610240
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: simplecov
|
38
|
+
requirement: &2154609780 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.5.4
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2154609780
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rr
|
49
|
+
requirement: &2154609320 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2154609320
|
58
|
+
description: Ruby WebHDFS client
|
59
|
+
email: kazuki.ohta@gmail.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- .gitignore
|
65
|
+
- AUTHORS
|
66
|
+
- Gemfile
|
67
|
+
- Rakefile
|
68
|
+
- VERSION
|
69
|
+
- lib/webhdfs.rb
|
70
|
+
- lib/webhdfs/fileutils.rb
|
71
|
+
- test/test_helper.rb
|
72
|
+
- test/webhdfs/fileutils.rb
|
73
|
+
- webhdfs.gemspec
|
74
|
+
homepage: ''
|
75
|
+
licenses: []
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.8.6
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: Ruby WebHDFS client
|
98
|
+
test_files:
|
99
|
+
- test/test_helper.rb
|
100
|
+
- test/webhdfs/fileutils.rb
|
101
|
+
has_rdoc: false
|