webhdfs 0.4.1 → 0.5.0

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/AUTHORS CHANGED
@@ -1 +1,2 @@
1
1
  Kazuki Ohta <kazuki.ohta@gmail.com>
2
+ TAGOMORI Satoshi <tagomoris@gmail.com>
data/COPYING ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (C) 2012 Fluentd Project
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # webhdfs - A client library implementation for Hadoop WebHDFS, and HttpFs, for Ruby
2
+
3
+ The webhdfs gem is to access Hadoop WebHDFS (EXPERIMENTAL: and HttpFs). WebHDFS::Client is a client class, and WebHDFS::FileUtils is utility like 'fileutils'.
4
+
5
+ ## Installation
6
+
7
+ gem install webhdfs
8
+
9
+ ## Usage
10
+
11
+ ### WebHDFS::Client
12
+
13
+ For client object interface:
14
+
15
+ require 'webhdfs'
16
+ client = WebHDFS::Client.new(hostname, port)
17
+ # or with pseudo username authentication
18
+ client = WebHDFS::Client.new(hostname, port, username)
19
+
20
+ To create/append/read files:
21
+
22
+ client.create('/path/to/file', data)
23
+ client.create('/path/to/file', data, :overwrite => false, :blocksize => 268435456, :replication => 5, :permission => 0666)
24
+
25
+ client.append('/path/to/existing/file', data)
26
+
27
+ client.read('/path/to/target') #=> data
28
+ client.read('/path/to/target' :offset => 2048, :length => 1024) #=> data
29
+
30
+ To mkdir/rename/delete directories or files:
31
+
32
+ client.mkdir('/hdfs/dirname')
33
+ client.mkdir('/hdfs/dirname', :permission => 0777)
34
+
35
+ client.rename(original_path, dst_path)
36
+
37
+ client.delete(path)
38
+ client.delete(dir_path, :recursive => true)
39
+
40
+ To get status or list of files and directories:
41
+
42
+ client.stat(file_path) #=> key-value pairs for file status
43
+ client.list(dir_path) #=> list of key-value pairs for files in dir_path
44
+
45
+ And, 'content_summary', 'checksum', 'homedir', 'chmod', 'chown', 'replication' and 'touch' methods available.
46
+
47
+ ### WebHDFS::FileUtils
48
+
49
+ require 'webhdfs/fileutils'
50
+ WebHDFS::FileUtils.set_server(host, port)
51
+ # or
52
+ WebHDFS::FileUtils.set_server(host, port, username, doas)
53
+
54
+ WebHDFS::FileUtils.copy_from_local(localpath, hdfspath)
55
+ WebHDFS::FileUtils.copy_to_local(hdfspath, localpath)
56
+
57
+ WebHDFS::FileUtils.append(path, data)
58
+
59
+ ### For HttpFs
60
+
61
+ For HttpFs instead of WebHDFS:
62
+
63
+ client = WebHDFS::Client('hostname', 14000)
64
+ client.httpfs_mode = true
65
+
66
+ client.read(path) #=> data
67
+
68
+ # or with webhdfs/filetuils
69
+ WebHDFS::FileUtils.set_server('hostname', 14000)
70
+ WebHDFS::FileUtils.set_httpfs_mode
71
+ WebHDFS::FileUtils.copy_to_local(remote_path, local_path)
72
+
73
+ ## AUTHORS
74
+
75
+ * Kazuki Ohta <kazuki.ohta@gmail.com>
76
+ * TAGOMORI Satoshi <tagomoris@gmail.com>
77
+
78
+ ## LICENSE
79
+
80
+ * Copyright: Copyright (c) 2012- Fluentd Project
81
+ * License: Apache License, Version 2.0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.5.0
data/lib/webhdfs.rb CHANGED
@@ -1,2 +1 @@
1
- # require File.join(File.dirname(__FILE__), 'webhdfs', 'fileutils.rb')
2
1
  require File.join(File.dirname(__FILE__), 'webhdfs', 'client.rb')
@@ -12,31 +12,40 @@ module WebHDFS
12
12
 
13
13
  attr_accessor :host, :port, :username, :doas
14
14
  attr_accessor :open_timeout, :read_timeout
15
+ attr_accessor :httpfs_mode
15
16
 
16
17
  def initialize(host='localhost', port=50070, username=nil, doas=nil)
17
18
  @host = host
18
19
  @port = port
19
20
  @username = username
20
21
  @doas = doas
22
+
23
+ @httpfs_mode = false
21
24
  end
22
25
 
23
26
  # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=CREATE
24
27
  # [&overwrite=<true|false>][&blocksize=<LONG>][&replication=<SHORT>]
25
28
  # [&permission=<OCTAL>][&buffersize=<INT>]"
26
29
  def create(path, body, options={})
30
+ if @httpfs_mode
31
+ options = options.merge({'data' => 'true'})
32
+ end
27
33
  check_options(options, OPT_TABLE['CREATE'])
28
34
  res = operate_requests('PUT', path, 'CREATE', options, body)
29
35
  res.code == '201'
30
36
  end
31
- OPT_TABLE['CREATE'] = ['overwrite', 'blocksize', 'replication', 'permission', 'buffersize']
37
+ OPT_TABLE['CREATE'] = ['overwrite', 'blocksize', 'replication', 'permission', 'buffersize', 'data']
32
38
 
33
39
  # curl -i -X POST "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=APPEND[&buffersize=<INT>]"
34
40
  def append(path, body, options={})
41
+ if @httpfs_mode
42
+ options = options.merge({'data' => 'true'})
43
+ end
35
44
  check_options(options, OPT_TABLE['APPEND'])
36
45
  res = operate_requests('POST', path, 'APPEND', options, body)
37
46
  res.code == '200'
38
47
  end
39
- OPT_TABLE['APPEND'] = ['buffersize']
48
+ OPT_TABLE['APPEND'] = ['buffersize', 'data']
40
49
 
41
50
  # curl -i -L "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=OPEN
42
51
  # [&offset=<LONG>][&length=<LONG>][&buffersize=<INT>]"
@@ -129,7 +138,8 @@ module WebHDFS
129
138
  # [&owner=<USER>][&group=<GROUP>]"
130
139
  def chown(path, options={})
131
140
  check_options(options, OPT_TABLE['SETOWNER'])
132
- unless options.has_key?('owner') or options.has_key?('group')
141
+ unless options.has_key?('owner') or options.has_key?('group') or
142
+ options.has_key?(:owner) or options.has_key?(:group)
133
143
  raise ArgumentError, "'chown' needs at least one of owner or group"
134
144
  end
135
145
  res = operate_requests('PUT', path, 'SETOWNER', options)
@@ -153,7 +163,8 @@ module WebHDFS
153
163
  # accesstime: radix-10 logn integer
154
164
  def touch(path, options={})
155
165
  check_options(options, OPT_TABLE['SETTIMES'])
156
- unless options.has_key?('modificationtime') or options.has_key?('accesstime')
166
+ unless options.has_key?('modificationtime') or options.has_key?('accesstime') or
167
+ options.has_key?(:modificationtime) or options.has_key?(:accesstime)
157
168
  raise ArgumentError, "'chown' needs at least one of modificationtime or accesstime"
158
169
  end
159
170
  res = operate_requests('PUT', path, 'SETTIMES', options)
@@ -173,8 +184,8 @@ module WebHDFS
173
184
  # end
174
185
 
175
186
  def check_options(options, optdecl=[])
176
- ex = options.keys - (optdecl || [])
177
- raise ArgumentError, "no such option: #{ex.keys.join(' ')}" unless ex.empty?
187
+ ex = options.keys.map(&:to_s) - (optdecl || [])
188
+ raise ArgumentError, "no such option: #{ex.join(' ')}" unless ex.empty?
178
189
  end
179
190
 
180
191
  def check_success_json(res, attr=nil)
@@ -205,7 +216,7 @@ module WebHDFS
205
216
 
206
217
  REDIRECTED_OPERATIONS = ['APPEND', 'CREATE', 'OPEN', 'GETFILECHECKSUM']
207
218
  def operate_requests(method, path, op, params={}, payload=nil)
208
- if REDIRECTED_OPERATIONS.include?(op)
219
+ if not @httpfs_mode and REDIRECTED_OPERATIONS.include?(op)
209
220
  res = request(@host, @port, method, path, op, params, nil)
210
221
  unless res.is_a?(Net::HTTPRedirection) and res['location']
211
222
  msg = "NameNode returns non-redirection (or without location header), code:#{res.code}, body:#{res.body}."
@@ -219,7 +230,11 @@ module WebHDFS
219
230
  end
220
231
  request(uri.host, uri.port, method, rpath, nil, {}, payload)
221
232
  else
222
- request(@host, @port, method, path, op, params, nil)
233
+ if @httpfs_mode and not payload.nil?
234
+ request(@host, @port, method, path, op, params, payload, {'Content-Type' => 'application/octet-stream'})
235
+ else
236
+ request(@host, @port, method, path, op, params, payload)
237
+ end
223
238
  end
224
239
  end
225
240
 
@@ -229,7 +244,7 @@ module WebHDFS
229
244
  # IOException 403 Forbidden
230
245
  # FileNotFoundException 404 Not Found
231
246
  # RumtimeException 500 Internal Server Error
232
- def request(host, port, method, path, op=nil, params={}, payload=nil)
247
+ def request(host, port, method, path, op=nil, params={}, payload=nil, header=nil)
233
248
  conn = Net::HTTP.start(host, port)
234
249
  conn.open_timeout = @open_timeout if @open_timeout
235
250
  conn.read_timeout = @read_timeout if @read_timeout
@@ -240,7 +255,7 @@ module WebHDFS
240
255
  path
241
256
  end
242
257
 
243
- res = conn.send_request(method, request_path, payload)
258
+ res = conn.send_request(method, request_path, payload, header)
244
259
 
245
260
  case res
246
261
  when Net::HTTPSuccess
@@ -1,11 +1,12 @@
1
- module WebHDFS
2
- class FileNotFoundError < StandardError; end
1
+ module WebHDFS; end
2
+ class WebHDFS::Error < StandardError; end
3
3
 
4
- class IOError < StandardError; end
5
- class SecurityError < StandardError; end
4
+ class WebHDFS::FileNotFoundError < WebHDFS::Error; end
6
5
 
7
- class ClientError < StandardError; end
8
- class ServerError < StandardError; end
6
+ class WebHDFS::IOError < WebHDFS::Error; end
7
+ class WebHDFS::SecurityError < WebHDFS::Error; end
9
8
 
10
- class RequestFailedError < StandardError; end
11
- end
9
+ class WebHDFS::ClientError < WebHDFS::Error; end
10
+ class WebHDFS::ServerError < WebHDFS::Error; end
11
+
12
+ class WebHDFS::RequestFailedError < WebHDFS::Error; end
@@ -1,29 +1,46 @@
1
+ require_relative 'client'
2
+
1
3
  module WebHDFS
2
4
  module FileUtils
3
- require 'rest_client'
4
-
5
- # This hash table holds command options.
6
- OPT_TABLE = {} # internal use only
7
-
8
5
  # Those values hold NameNode location
9
6
  @fu_host = 'localhost'
10
7
  @fu_port = 50070
8
+ @fu_user = nil
9
+ @fu_doas = nil
10
+ @fu_httpfs_mode = false
11
11
 
12
12
  # Public: Set hostname and port number of WebHDFS
13
13
  #
14
14
  # host - hostname
15
15
  # port - port
16
+ # user - username
17
+ # doas - proxy user name
16
18
  #
17
19
  # Examples
18
20
  #
19
21
  # FileUtils.set_server 'localhost', 50070
20
22
  #
21
- def set_server(host, port)
23
+ def set_server(host, port, user=nil, doas=nil)
22
24
  @fu_host = host
23
25
  @fu_port = port
26
+ @fu_user = user
27
+ @fu_doas = doas
24
28
  end
25
29
  module_function :set_server
26
30
 
31
+ # Public: Set httpfs mode enable/disable
32
+ #
33
+ # mode - boolean (default true)
34
+ #
35
+ # Examples
36
+ #
37
+ # FileUtils.set_httpfs_mode
38
+ #
39
+ def set_httpfs_mode(mode=true)
40
+ @fu_httpfs_mode = mode
41
+ end
42
+ module_function :set_httpfs_mode
43
+
27
44
  # Public: Copy local file into HDFS
28
45
  #
29
46
  # file - local file path
@@ -35,28 +52,18 @@ module WebHDFS
35
52
  # FileUtils.copy_from_local 'local_file', 'remote_file'
36
53
  #
37
54
  def copy_from_local(file, path, options={})
38
- fu_check_options options, OPT_TABLE['copy_from_local']
39
- fu_log "copy_from_local local=#{file} hdfs=#{path}" if options[:verbose]
40
- if mode = options[:mode]
41
- mode = ('0%03o' % mode) if mode.is_a? Integer
55
+ opts = options.dup
56
+ fu_log "copy_from_local local=#{file} hdfs=#{path}" if opts.delete(:verbose)
57
+ if mode = opts.delete(:mode)
58
+ mode = ('%03o' % mode) if mode.is_a? Integer
42
59
  else
43
- mode = '0644'
44
- end
45
- options[:permission] = mode
46
- options[:overwrite] ||= true
47
- begin
48
- fu_put(path, 'CREATE', options)
49
- rescue RestClient::TemporaryRedirect => e
50
- # must be redirected
51
- raise e unless [301, 302, 307].include? e.response.code
52
- # must have location
53
- location = e.response.headers[:location]
54
- raise e if location.nil? or location.empty?
55
- # put contents
56
- RestClient.put location, File.new(file, 'rb')
60
+ mode = '644'
57
61
  end
62
+ opts[:permission] = mode
63
+ opts[:overwrite] ||= true
64
+
65
+ client.create(path, File.new(file, 'rb').read(File.size(file)), opts)
58
66
  end
59
- OPT_TABLE['copy_from_local'] = [:overwrite, :blocksize, :replication, :mode, :buffersize, :verbose]
60
67
  module_function :copy_from_local
61
68
 
62
69
  # Public: Copy remote HDFS file into local
@@ -70,14 +77,12 @@ module WebHDFS
70
77
  # FileUtils.copy_to_local 'remote_file', 'local_file'
71
78
  #
72
79
  def copy_to_local(path, file, options={})
73
- fu_check_options options, OPT_TABLE['copy_to_local']
74
- fu_log "copy_to_local hdfs=#{path} local=#{file}" if options[:verbose]
80
+ opts = options.dup
81
+ fu_log "copy_to_local hdfs=#{path} local=#{file}" if opts.delete(:verbose)
75
82
  File.open(file, "wb") do |f|
76
- ret = fu_get(path, 'OPEN', options)
77
- f.write ret
83
+ f.write client.read(path, opts)
78
84
  end
79
85
  end
80
- OPT_TABLE['copy_to_local'] = [:offset, :length, :buffersize, :verbose]
81
86
  module_function :copy_to_local
82
87
 
83
88
  # Public: Append to HDFS file
@@ -91,21 +96,10 @@ module WebHDFS
91
96
  # FileUtils.append 'remote_path', 'contents'
92
97
  #
93
98
  def append(path, body, options={})
94
- fu_check_options options, OPT_TABLE['append']
95
- fu_log "append #{body.bytesize} bytes to #{path}" if options[:verbose]
96
- begin
97
- fu_post(path, 'APPEND', options)
98
- rescue RestClient::TemporaryRedirect => e
99
- # must be redirected
100
- raise e unless [301, 302, 307].include? e.response.code
101
- # must have location
102
- location = e.response.headers[:location]
103
- raise e if location.nil? or location.empty?
104
- # put contents
105
- RestClient.post location, body
106
- end
99
+ opts = options.dup
100
+ fu_log "append #{body.bytesize} bytes to #{path}" if opts.delete(:verbose)
101
+ client.append(path, body, opts)
107
102
  end
108
- OPT_TABLE['append'] = [:buffersize, :verbose]
109
103
  module_function :append
110
104
 
111
105
  # Public: Create one or more directories.
@@ -120,19 +114,19 @@ module WebHDFS
120
114
  # FileUtils.mkdir 'tmp', :mode => 0700
121
115
  #
122
116
  def mkdir(list, options={})
123
- fu_check_options options, OPT_TABLE['mkdir']
124
- list = fu_list(list)
125
- fu_log "mkdir #{options[:mode] ? ('-m %03o ' % options[:mode]) : ''}#{list.join ' '}" if options[:verbose]
126
- if mode = options[:mode]
117
+ opts = options.dup
118
+ list = [list].flatten
119
+ fu_log "mkdir #{options[:mode] ? ('-m %03o ' % options[:mode]) : ''}#{list.join ' '}" if opts.delete(:verbose)
120
+ if mode = opts[:mode]
127
121
  mode = ('0%03o' % mode) if mode.is_a? Integer
128
122
  else
129
123
  mode = '0755'
130
124
  end
125
+ c = client
131
126
  list.each { |dir|
132
- fu_put(dir, 'MKDIRS', {:permission => mode})
127
+ c.mkdir(dir, {:permission => mode})
133
128
  }
134
129
  end
135
- OPT_TABLE['mkdir'] = [:mode, :verbose]
136
130
  module_function :mkdir
137
131
 
138
132
  # Public: Create one or more directories recursively.
@@ -161,14 +155,14 @@ module WebHDFS
161
155
  # FileUtils.rm 'dir', :recursive => true
162
156
  #
163
157
  def rm(list, options={})
164
- fu_check_options options, OPT_TABLE['rm']
165
- list = fu_list(list)
166
- fu_log "rm #{list.join ' '}" if options[:verbose]
158
+ opts = options.dup
159
+ list = [list].flatten
160
+ fu_log "rm #{list.join ' '}" if opts.delete(:verbose)
161
+ c = client
167
162
  list.each { |dir|
168
- fu_delete(dir, 'DELETE', {:recursive => options[:recursive] || false})
163
+ c.delete(dir, {:recursive => opts[:recursive] || false})
169
164
  }
170
165
  end
171
- OPT_TABLE['rm'] = [:verbose, :recursive]
172
166
  module_function :rm
173
167
 
174
168
  # Public: Remove one or more directories/files recursively.
@@ -183,10 +177,8 @@ module WebHDFS
183
177
  # FileUtils.rmr 'dir'
184
178
  #
185
179
  def rmr(list, options={})
186
- fu_check_options options, OPT_TABLE['rmr']
187
180
  self.rm(list, options.merge({:recursive => true}))
188
181
  end
189
- OPT_TABLE['rmr'] = [:verbose]
190
182
  module_function :rmr
191
183
 
192
184
  # Public: Rename a file or directory.
@@ -200,11 +192,10 @@ module WebHDFS
200
192
  # FileUtils.rename 'from', 'to'
201
193
  #
202
194
  def rename(src, dst, options={})
203
- fu_check_options options, OPT_TABLE['rename']
204
- fu_log "rename #{src} #{dst}" if options[:verbose]
205
- fu_put(src, 'RENAME', {:destination => dst})
195
+ opts = options.dup
196
+ fu_log "rename #{src} #{dst}" if opts.delete(:verbose)
197
+ client.rename(src, dst, opts)
206
198
  end
207
- OPT_TABLE['rename'] = [:verbose]
208
199
  module_function :rename
209
200
 
210
201
  # Public: Change permission of one or more directories/files.
@@ -219,15 +210,15 @@ module WebHDFS
219
210
  # FileUtils.chmod 0644, 'file'
220
211
  #
221
212
  def chmod(mode, list, options={})
222
- fu_check_options options, OPT_TABLE['chmod']
223
- list = fu_list(list)
224
- fu_log sprintf('chmod %o %s', mode, list.join(' ')) if options[:verbose]
225
- mode = ('0%03o' % mode) if mode.is_a? Integer
226
- list.each { |dir|
227
- fu_put(dir, 'SETPERMISSION', {:permission => mode})
213
+ opts = options.dup
214
+ list = [list].flatten
215
+ fu_log sprintf('chmod %o %s', mode, list.join(' ')) if opts.delete(:verbose)
216
+ mode = ('%03o' % mode) if mode.is_a? Integer
217
+ c = client
218
+ list.each { |entry|
219
+ c.chmod(entry, mode, opts)
228
220
  }
229
221
  end
230
- OPT_TABLE['chmod'] = [:verbose]
231
222
  module_function :chmod
232
223
 
233
224
  # Public: Change an ownership of one or more directories/files.
@@ -243,16 +234,16 @@ module WebHDFS
243
234
  # FileUtils.chmod 0644, 'file'
244
235
  #
245
236
  def chown(user, group, list, options={})
246
- fu_check_options options, OPT_TABLE['chown']
247
- list = fu_list(list)
237
+ opts = options.dup
238
+ list = [list].flatten
248
239
  fu_log sprintf('chown %s%s',
249
240
  [user,group].compact.join(':') + ' ',
250
- list.join(' ')) if options[:verbose]
251
- list.each { |dir|
252
- fu_put(dir, 'SETOWNER', {:owner => user, :group => group})
241
+ list.join(' ')) if opts.delete(:verbose)
242
+ c = client
243
+ list.each { |entry|
244
+ c.chown(entry, {:owner => user, :group => group})
253
245
  }
254
246
  end
255
- OPT_TABLE['chown'] = [:verbose]
256
247
  module_function :chown
257
248
 
258
249
  # Public: Set a replication factor of files
@@ -266,15 +257,15 @@ module WebHDFS
266
257
  # FileUtils.set_repl_factor 'file', 3
267
258
  #
268
259
  def set_repl_factor(list, num, options={})
269
- fu_check_options options, OPT_TABLE['set_repl_factor']
270
- list = fu_list(list)
260
+ opts = options.dup
261
+ list = [list].flatten
271
262
  fu_log sprintf('set_repl_factor %s %d',
272
- list.join(' '), num) if options[:verbose]
273
- list.each { |dir|
274
- fu_put(dir, 'SETREPLICATION', {:replication => num})
263
+ list.join(' '), num) if opts.delete(:verbose)
264
+ c = client
265
+ list.each { |entry|
266
+ c.replication(entry, num, opts)
275
267
  }
276
268
  end
277
- OPT_TABLE['set_repl_factor'] = [:verbose]
278
269
  module_function :set_repl_factor
279
270
 
280
271
  # Public: Set an access time of files
@@ -288,15 +279,15 @@ module WebHDFS
288
279
  # FileUtils.set_atime 'file', Time.now
289
280
  #
290
281
  def set_atime(list, time, options={})
291
- fu_check_options options, OPT_TABLE['set_atime']
292
- list = fu_list(list)
282
+ opts = options.dup
283
+ list = [list].flatten
293
284
  time = time.to_i
294
- fu_log sprintf('set_atime %s %d', list.join(' '), time) if options[:verbose]
295
- list.each { |dir|
296
- fu_put(dir, 'SETTIMES', {:accesstime => time})
285
+ fu_log sprintf('set_atime %s %d', list.join(' '), time) if opts.delete(:verbose)
286
+ c = client
287
+ list.each { |entry|
288
+ c.touch(entry, {:accesstime => time})
297
289
  }
298
290
  end
299
- OPT_TABLE['set_atime'] = [:verbose]
300
291
  module_function :set_atime
301
292
 
302
293
  # Public: Set a modification time of files
@@ -310,15 +301,15 @@ module WebHDFS
310
301
  # FileUtils.set_mtime 'file', Time.now
311
302
  #
312
303
  def set_mtime(list, time, options={})
313
- fu_check_options options, OPT_TABLE['set_mtime']
314
- list = fu_list(list)
304
+ opts = options.dup
305
+ list = [list].flatten
315
306
  time = time.to_i
316
- fu_log sprintf('set_mtime %s %d', list.join(' '), time) if options[:verbose]
317
- list.each { |dir|
318
- fu_put(dir, 'SETTIMES', {:modificationtime => time})
307
+ fu_log sprintf('set_mtime %s %d', list.join(' '), time) if opts.delete(:verbose)
308
+ c = client
309
+ list.each { |entry|
310
+ c.touch(entry, {:modificationtime => time})
319
311
  }
320
312
  end
321
- OPT_TABLE['set_mtime'] = [:verbose]
322
313
  module_function :set_mtime
323
314
 
324
315
  # Internal: make functin private
@@ -327,50 +318,6 @@ module WebHDFS
327
318
  private_class_method name
328
319
  end
329
320
 
330
- # Internal: make list
331
- def fu_list(arg)
332
- [arg].flatten
333
- end
334
- private_module_function :fu_list
335
-
336
- # Internal: HTTP GET
337
- def fu_get(path, op, params={}, payload='')
338
- url = "http://#{@fu_host}:#{@fu_port}/webhdfs/v1/#{path}"
339
- RestClient.get url, :params => params.merge({:op => op})
340
- end
341
- private_module_function :fu_get
342
-
343
- # Internal: HTTP PUT
344
- def fu_put(path, op, params={}, payload='')
345
- url = "http://#{@fu_host}:#{@fu_port}/webhdfs/v1/#{path}"
346
- RestClient.put url, payload, :params => params.merge({:op => op})
347
- end
348
- private_module_function :fu_put
349
-
350
- # Internal: HTTP POST
351
- def fu_post(path, op, params={}, payload='')
352
- url = "http://#{@fu_host}:#{@fu_port}/webhdfs/v1/#{path}"
353
- RestClient.post url, payload, :params => params.merge({:op => op})
354
- end
355
- private_module_function :fu_post
356
-
357
- # Internal: HTTP DELETE
358
- def fu_delete(path, op, params={})
359
- url = "http://#{@fu_host}:#{@fu_port}/webhdfs/v1/#{path}"
360
- RestClient.delete url, :params => params.merge({:op => op})
361
- end
362
- private_module_function :fu_delete
363
-
364
- # Internal: Check options Hash
365
- def fu_check_options(options, optdecl)
366
- h = options.dup
367
- optdecl.each do |opt|
368
- h.delete opt
369
- end
370
- raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless h.empty?
371
- end
372
- private_module_function :fu_check_options
373
-
374
321
  @fileutils_output = $stderr
375
322
  @fileutils_label = '[webhdfs]: '
376
323
  # Internal: Logging
@@ -380,5 +327,15 @@ module WebHDFS
380
327
  @fileutils_output.puts @fileutils_label + msg
381
328
  end
382
329
  private_module_function :fu_log
330
+
331
+ # Internal
332
+ def client
333
+ client = WebHDFS::Client.new(@fu_host, @fu_port, @fu_user, @fu_doas)
334
+ if @fu_httpfs_mode
335
+ client.httpfs_mode = true
336
+ end
337
+ client
338
+ end
339
+ private_module_function :client
383
340
  end
384
341
  end
data/webhdfs.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path('../lib', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.name = "webhdfs"
6
- gem.description = "Ruby WebHDFS client"
6
+ gem.description = "Ruby WebHDFS/HttpFs client"
7
7
  gem.homepage = ""
8
8
  gem.summary = gem.description
9
9
  gem.version = File.read("VERSION").strip
@@ -16,7 +16,6 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  gem.require_paths = ['lib']
18
18
 
19
- gem.add_dependency "rest-client", "~> 1.6.7"
20
19
  gem.add_development_dependency "rake", ">= 0.9.2"
21
20
  gem.add_development_dependency "rdoc", ">= 3.12"
22
21
  gem.add_development_dependency "simplecov", ">= 0.5.4"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webhdfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-20 00:00:00.000000000 Z
12
+ date: 2012-06-13 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rest-client
16
- requirement: !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: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: 1.6.7
30
14
  - !ruby/object:Gem::Dependency
31
15
  name: rake
32
16
  requirement: !ruby/object:Gem::Requirement
@@ -91,7 +75,7 @@ dependencies:
91
75
  - - ! '>='
92
76
  - !ruby/object:Gem::Version
93
77
  version: 1.0.0
94
- description: Ruby WebHDFS client
78
+ description: Ruby WebHDFS/HttpFs client
95
79
  email: kazuki.ohta@gmail.com
96
80
  executables: []
97
81
  extensions: []
@@ -99,7 +83,9 @@ extra_rdoc_files: []
99
83
  files:
100
84
  - .gitignore
101
85
  - AUTHORS
86
+ - COPYING
102
87
  - Gemfile
88
+ - README.md
103
89
  - Rakefile
104
90
  - VERSION
105
91
  - lib/webhdfs.rb
@@ -133,7 +119,7 @@ rubyforge_project:
133
119
  rubygems_version: 1.8.21
134
120
  signing_key:
135
121
  specification_version: 3
136
- summary: Ruby WebHDFS client
122
+ summary: Ruby WebHDFS/HttpFs client
137
123
  test_files:
138
124
  - test/test_helper.rb
139
125
  - test/webhdfs/fileutils.rb