leofs_manager_client 0.2.6 → 0.2.7
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.
@@ -84,7 +84,7 @@ module LeoFSManager
|
|
84
84
|
|
85
85
|
# Assigned file info Model
|
86
86
|
class AssignedFile
|
87
|
-
attr_reader :node, :vnode_id, :size, :clock, :checksum, :timestamp, :delete
|
87
|
+
attr_reader :node, :vnode_id, :size, :clock, :checksum, :timestamp, :delete, :num_of_chunks
|
88
88
|
|
89
89
|
def initialize(h)
|
90
90
|
@node = h[:node]
|
@@ -94,6 +94,7 @@ module LeoFSManager
|
|
94
94
|
@checksum = h[:checksum]
|
95
95
|
@timestamp = h[:timestamp]
|
96
96
|
@delete = h[:delete]
|
97
|
+
@num_of_chunks = Integer(h[:num_of_chunks])
|
97
98
|
end
|
98
99
|
end
|
99
100
|
|
data/lib/leofs_manager_client.rb
CHANGED
@@ -26,21 +26,7 @@ require "time"
|
|
26
26
|
require_relative "leofs_manager_client/leofs_manager_models"
|
27
27
|
|
28
28
|
module LeoFSManager
|
29
|
-
VERSION = "0.2.
|
30
|
-
|
31
|
-
# Class for close TCP socket on GC.
|
32
|
-
class Remover
|
33
|
-
def initialize(data)
|
34
|
-
@data = data
|
35
|
-
end
|
36
|
-
|
37
|
-
# it will be called on GC.
|
38
|
-
def call(*args)
|
39
|
-
socket = @data[0]
|
40
|
-
socket.close if socket && !socket.closed?
|
41
|
-
warn "Closed socket: #{socket}" if $DEBUG
|
42
|
-
end
|
43
|
-
end
|
29
|
+
VERSION = "0.2.7"
|
44
30
|
|
45
31
|
class Client
|
46
32
|
CMD_VERSION = "version"
|
@@ -69,8 +55,6 @@ module LeoFSManager
|
|
69
55
|
def initialize(*servers)
|
70
56
|
@servers = parse_servers(servers)
|
71
57
|
set_current_server
|
72
|
-
final = Remover.new(@data = [])
|
73
|
-
ObjectSpace.define_finalizer(self, final)
|
74
58
|
@mutex = Mutex.new
|
75
59
|
connect
|
76
60
|
end
|
@@ -184,10 +168,11 @@ module LeoFSManager
|
|
184
168
|
# Remove an endpoint from the system
|
185
169
|
# Return::
|
186
170
|
# _nil_
|
187
|
-
def
|
171
|
+
def s3_delete_endpoint(endpoint)
|
188
172
|
sender(CMD_S3_DEL_ENDPOINT % endpoint)
|
189
173
|
nil
|
190
174
|
end
|
175
|
+
alias :s3_del_endpoint :s3_delete_endpoint
|
191
176
|
|
192
177
|
# Retrieve an endpoint in the system
|
193
178
|
# Return::
|
@@ -213,6 +198,13 @@ module LeoFSManager
|
|
213
198
|
buckets.map {|bucket| Bucket.new(bucket) }
|
214
199
|
end
|
215
200
|
|
201
|
+
# Disconnect to LeoFS Manager explicitly
|
202
|
+
# Return::
|
203
|
+
# _nil_
|
204
|
+
def disconnect!
|
205
|
+
disconnect
|
206
|
+
end
|
207
|
+
|
216
208
|
## ======================================================================
|
217
209
|
## PRIVATE
|
218
210
|
## ======================================================================
|
@@ -234,7 +226,8 @@ module LeoFSManager
|
|
234
226
|
end
|
235
227
|
|
236
228
|
def set_current_server
|
237
|
-
|
229
|
+
@servers.delete(@current_server) if @current_server
|
230
|
+
raise "No servers to connect" if @servers.empty?
|
238
231
|
@current_server = @servers.first
|
239
232
|
end
|
240
233
|
|
@@ -243,20 +236,30 @@ module LeoFSManager
|
|
243
236
|
retry_count = 0
|
244
237
|
begin
|
245
238
|
@socket = TCPSocket.new(@current_server[:host], @current_server[:port])
|
246
|
-
@data[0] = @socket
|
247
239
|
rescue => ex
|
248
240
|
warn "Faild to connect: #{ex.class} (server: #{@current_server})"
|
249
241
|
warn ex.message
|
250
242
|
retry_count += 1
|
251
243
|
if retry_count > 3
|
252
|
-
warn "Connecting another server..."
|
253
|
-
@socket.close if @socket && !@socket.closed?
|
254
|
-
@servers.delete(@current_server)
|
255
244
|
set_current_server
|
245
|
+
warn "Connecting another server: #{@current_server}"
|
256
246
|
retry_count = 0
|
257
247
|
end
|
248
|
+
sleep 1
|
258
249
|
retry
|
259
250
|
end
|
251
|
+
@socket.autoclose = true
|
252
|
+
nil
|
253
|
+
end
|
254
|
+
|
255
|
+
def disconnect
|
256
|
+
@socket.close if @socket && !@socket.closed?
|
257
|
+
end
|
258
|
+
|
259
|
+
def reconnect
|
260
|
+
disconnect
|
261
|
+
sleep 1
|
262
|
+
connect
|
260
263
|
end
|
261
264
|
|
262
265
|
# Send a request to LeoFS Manager
|
@@ -267,8 +270,11 @@ module LeoFSManager
|
|
267
270
|
begin
|
268
271
|
@mutex.synchronize do
|
269
272
|
@socket.puts command
|
270
|
-
response = JSON.parse(@socket.
|
273
|
+
response = JSON.parse(@socket.readline, symbolize_names: true)
|
271
274
|
end
|
275
|
+
rescue EOFError => ex
|
276
|
+
warn "EOFError occured (server: #{@current_server})"
|
277
|
+
reconnect
|
272
278
|
rescue => ex
|
273
279
|
raise "An Error occured: #{ex.class} (server: #{@current_server})\n#{ex.message}"
|
274
280
|
end
|
@@ -70,7 +70,8 @@ module Dummy
|
|
70
70
|
:clock => "",
|
71
71
|
:checksum => "",
|
72
72
|
:timestamp => "",
|
73
|
-
:delete => 0
|
73
|
+
:delete => 0,
|
74
|
+
:num_of_chunks => 0
|
74
75
|
}
|
75
76
|
]
|
76
77
|
}.to_json
|
@@ -102,29 +103,32 @@ module Dummy
|
|
102
103
|
Thread.new do
|
103
104
|
TCPServer.open(Host, Port) do |server|
|
104
105
|
loop do
|
105
|
-
|
106
|
-
|
107
|
-
line.
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
106
|
+
begin
|
107
|
+
socket = server.accept
|
108
|
+
while line = socket.readline.split.first
|
109
|
+
line.rstrip!
|
110
|
+
begin
|
111
|
+
case line
|
112
|
+
when "status"
|
113
|
+
result = Response::Status
|
114
|
+
when "s3-get-buckets"
|
115
|
+
result = Response::S3GetBuckets
|
116
|
+
when "whereis"
|
117
|
+
result = Response::Whereis
|
118
|
+
when "s3-get-endpoints"
|
119
|
+
result = Response::S3GetEndpoints
|
120
|
+
when "s3-get-buckets"
|
121
|
+
result = Response::S3GetBuckets
|
122
|
+
else
|
123
|
+
result = { :result => line }.to_json
|
124
|
+
end
|
125
|
+
rescue => ex
|
126
|
+
result = { :error => ex.message }.to_json
|
127
|
+
ensure
|
128
|
+
socket.puts(result)
|
122
129
|
end
|
123
|
-
rescue => ex
|
124
|
-
result = { :error => ex.message }.to_json
|
125
|
-
ensure
|
126
|
-
socket.puts(result)
|
127
130
|
end
|
131
|
+
rescue EOFError
|
128
132
|
end
|
129
133
|
end
|
130
134
|
end
|
@@ -147,79 +151,94 @@ NoResultAPIs = {
|
|
147
151
|
include LeoFSManager
|
148
152
|
|
149
153
|
describe LeoFSManager do
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
it "raises error when it is passed invalid params" do
|
156
|
-
lambda { Client.new }.should raise_error
|
157
|
-
end
|
158
|
-
|
159
|
-
describe "#status" do
|
160
|
-
it "returns Status" do
|
161
|
-
@manager.status.should be_a Status
|
154
|
+
describe Client do
|
155
|
+
before(:all) do
|
156
|
+
Dummy::Manager.new
|
157
|
+
@manager = Client.new("#{Host}:#{Port}")
|
162
158
|
end
|
163
159
|
|
164
|
-
it "
|
165
|
-
|
160
|
+
it "raises error when it is passed invalid params" do
|
161
|
+
lambda { Client.new }.should raise_error
|
166
162
|
end
|
167
163
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
164
|
+
describe "#status" do
|
165
|
+
it "returns Status" do
|
166
|
+
@manager.status.should be_a Status
|
167
|
+
end
|
168
|
+
|
169
|
+
it "returns SystemInfo" do
|
170
|
+
@manager.status.system_info.should be_a Status::System
|
171
|
+
end
|
172
|
+
|
173
|
+
it "returns Array of Node" do
|
174
|
+
node_list = @manager.status.node_list
|
175
|
+
node_list.should be_a Array
|
176
|
+
node_list.each do |node|
|
177
|
+
node.should be_a Status::Node
|
178
|
+
end
|
173
179
|
end
|
174
180
|
end
|
175
|
-
end
|
176
181
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
182
|
+
describe "#whereis" do
|
183
|
+
it "returns Array of WhereInfo" do
|
184
|
+
result = @manager.whereis("path")
|
185
|
+
result.should be_a Array
|
186
|
+
result.each do |where_info|
|
187
|
+
where_info.should be_a AssignedFile
|
188
|
+
where_info.num_of_chunks.should be_a Integer
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
describe "#du" do
|
194
|
+
it "returns DiskUsage" do
|
195
|
+
@manager.du("node").should be_a StorageStat
|
183
196
|
end
|
184
|
-
end
|
185
|
-
end
|
197
|
+
end
|
186
198
|
|
187
|
-
|
188
|
-
|
189
|
-
|
199
|
+
describe "#s3_gen_key" do
|
200
|
+
it "returns Credential" do
|
201
|
+
@manager.s3_gen_key("user_id").should be_a Credential
|
202
|
+
end
|
190
203
|
end
|
191
|
-
end
|
192
204
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
205
|
+
describe "#s3_get_endpoints" do
|
206
|
+
it "returns Arrany of Endpoint" do
|
207
|
+
result = @manager.s3_get_endpoints
|
208
|
+
result.should be_a Array
|
209
|
+
result.each do |endpoint|
|
210
|
+
endpoint.should be_a Endpoint
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
198
214
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
215
|
+
describe "#s3_get_buckets" do
|
216
|
+
it "returns Array of Bucket" do
|
217
|
+
result = @manager.s3_get_buckets
|
218
|
+
result.should be_a Array
|
219
|
+
result.each do |buckets|
|
220
|
+
buckets.should be_a Bucket
|
221
|
+
end
|
205
222
|
end
|
206
223
|
end
|
207
|
-
end
|
208
224
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
buckets.should be_a Bucket
|
225
|
+
NoResultAPIs.each do |api, num_of_args|
|
226
|
+
describe "##{api}" do
|
227
|
+
it "returns nil" do
|
228
|
+
@manager.send(api, *(["argument"] * num_of_args)).should be_nil
|
229
|
+
end
|
215
230
|
end
|
216
231
|
end
|
217
|
-
end
|
218
232
|
|
219
|
-
|
220
|
-
describe "##{api}" do
|
233
|
+
describe "#disconnect!" do
|
221
234
|
it "returns nil" do
|
222
|
-
@manager.
|
235
|
+
@manager.disconnect!.should be_nil
|
236
|
+
end
|
237
|
+
|
238
|
+
it "accepts no more requests" do
|
239
|
+
lambda {
|
240
|
+
@manager.status
|
241
|
+
}.should raise_error
|
223
242
|
end
|
224
243
|
end
|
225
244
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leofs_manager_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-10-
|
13
|
+
date: 2012-10-22 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: Client for LeoFS Manager
|
16
16
|
email:
|