arangorb 1.4.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/ArangoRB.gemspec +20 -18
  3. data/Gemfile +3 -0
  4. data/README.md +1079 -908
  5. data/lib/AQL.rb +155 -0
  6. data/lib/Batch.rb +97 -0
  7. data/lib/Cache.rb +71 -0
  8. data/lib/Collection.rb +852 -0
  9. data/lib/Database.rb +417 -0
  10. data/lib/Document.rb +346 -0
  11. data/lib/Edge.rb +104 -0
  12. data/lib/Error.rb +125 -0
  13. data/lib/Foxx.rb +277 -0
  14. data/lib/Graph.rb +325 -0
  15. data/lib/Index.rb +126 -0
  16. data/lib/Replication.rb +235 -0
  17. data/lib/Request.rb +143 -0
  18. data/lib/Server.rb +466 -0
  19. data/lib/Task.rb +120 -0
  20. data/lib/Transaction.rb +115 -0
  21. data/lib/Traversal.rb +224 -0
  22. data/lib/User.rb +197 -0
  23. data/lib/Vertex.rb +127 -0
  24. data/lib/View.rb +151 -0
  25. data/lib/arangorb.rb +23 -15
  26. data/lib/helpers/Error.rb +28 -0
  27. data/lib/helpers/Return.rb +53 -0
  28. metadata +64 -45
  29. data/lib/ArangoRB_AQL.rb +0 -181
  30. data/lib/ArangoRB_Cache.rb +0 -174
  31. data/lib/ArangoRB_Col.rb +0 -526
  32. data/lib/ArangoRB_DB.rb +0 -363
  33. data/lib/ArangoRB_Doc.rb +0 -319
  34. data/lib/ArangoRB_Edg.rb +0 -184
  35. data/lib/ArangoRB_Gra.rb +0 -201
  36. data/lib/ArangoRB_Index.rb +0 -135
  37. data/lib/ArangoRB_Replication.rb +0 -261
  38. data/lib/ArangoRB_Ser.rb +0 -446
  39. data/lib/ArangoRB_Task.rb +0 -129
  40. data/lib/ArangoRB_Tra.rb +0 -169
  41. data/lib/ArangoRB_Tran.rb +0 -68
  42. data/lib/ArangoRB_User.rb +0 -157
  43. data/lib/ArangoRB_Ver.rb +0 -162
  44. data/spec/arangoRB_helper.rb +0 -4
  45. data/spec/arangoRestart_helper.rb +0 -14
  46. data/spec/arangorb-1.3.0.gem +0 -0
  47. data/spec/lib/0.1.0/arangoAQL_helper.rb +0 -64
  48. data/spec/lib/0.1.0/arangoC_helper.rb +0 -170
  49. data/spec/lib/0.1.0/arangoDB_helper.rb +0 -119
  50. data/spec/lib/0.1.0/arangoDoc_helper.rb +0 -79
  51. data/spec/lib/0.1.0/arangoE_helper.rb +0 -50
  52. data/spec/lib/0.1.0/arangoG_helper.rb +0 -78
  53. data/spec/lib/0.1.0/arangoS_helper.rb +0 -37
  54. data/spec/lib/0.1.0/arangoT_helper.rb +0 -48
  55. data/spec/lib/0.1.0/arangoV_helper.rb +0 -65
  56. data/spec/lib/1.0.0/arangoC_helper.rb +0 -73
  57. data/spec/lib/1.0.0/arangoDB_helper.rb +0 -48
  58. data/spec/lib/1.0.0/arangoI_helper.rb +0 -43
  59. data/spec/lib/1.0.0/arangoS_helper.rb +0 -192
  60. data/spec/lib/1.0.0/arangoTa_helper.rb +0 -49
  61. data/spec/lib/1.0.0/arangoTr_helper.rb +0 -15
  62. data/spec/lib/1.0.0/arangoU_helper.rb +0 -72
  63. data/spec/lib/1.1.0/arangoRB_helper.rb +0 -144
  64. data/spec/lib/1.1.0/arangoRB_walks_helper.rb +0 -19
  65. data/spec/lib/1.2.0/arangoCache_helper.rb +0 -66
  66. data/spec/lib/1.3.0/arangoHash_helper.rb +0 -30
  67. data/spec/lib/arangoRB_0.1.0_helper.rb +0 -9
  68. data/spec/lib/arangoRB_1.0.0_helper.rb +0 -6
  69. data/spec/lib/arangoRB_1.1.0_helper.rb +0 -2
  70. data/spec/lib/arangoRB_1.2.0_helper.rb +0 -2
  71. data/spec/spec_helper.rb +0 -42
@@ -0,0 +1,235 @@
1
+ # === REPLICATION ===
2
+
3
+ module Arango
4
+ class Replication
5
+ def initialize(master:, slave:, includeSystem: true,
6
+ initialSyncMaxWaitTime: nil, incremental: nil,
7
+ restrictCollections: nil, connectTimeout: nil,
8
+ autoResync: nil, idleMinWaitTime: nil, requestTimeout: nil,
9
+ requireFromPresent: nil, idleMaxWaitTime: nil, restrictType: nil,
10
+ maxConnectRetries: nil, adaptivePolling: nil,
11
+ connectionRetryWaitTime: nil, autoResyncRetries: nil, chunkSize: nil,
12
+ verbose: nil)
13
+ assign_master(master)
14
+ assign_slave(slave)
15
+ assign_restrictType(restrictType)
16
+ assign_restrictCollections(restrictCollections)
17
+ @includeSytem = includeSystem
18
+ @initialSyncMaxWaitTime = initialSyncMaxWaitTime,
19
+ @incremental = incremental
20
+ @connectTimeout = connectTimeout
21
+ @autoResync = autoResync
22
+ @idleMinWaitTime = idleMinWaitTime
23
+ @requestTimeout = requestTimeout
24
+ @requireFromPresent = requireFromPresent
25
+ @idleMaxWaitTime = idleMaxWaitTime
26
+ @maxConnectRetries = maxConnectRetries
27
+ @adaptivePolling = adaptivePolling
28
+ @connectionRetryWaitTime = connectionRetryWaitTime
29
+ @autoResyncRetries = autoResyncRetries
30
+ @chunkSize = chunkSize
31
+ @verbose = verbose
32
+ end
33
+
34
+ attr_accessor :endpoint, :username, :password, :includeSystem,
35
+ :initialSyncMaxWaitTime, :incremental, :verbose, :connectTimeout,
36
+ :autoResync, :idleMinWaitTime, :requestTimeout, :requireFromPresent,
37
+ :idleMaxWaitTime, :maxConnectRetries, :adaptivePolling,
38
+ :connectionRetryWaitTime, :autoResyncRetries, :chunkSize
39
+ attr_reader :master, :slave, :restrictType, :restrictCollections
40
+
41
+ def master=(master)
42
+ satisfy_class?(master, [Arango::Database])
43
+ @master = master
44
+ @master_server = @master.server
45
+ end
46
+ alias assign_master master=
47
+
48
+ def slave=(slave)
49
+ satisfy_class?(slave, [Arango::Database])
50
+ @slave = slave
51
+ @slave_server = @slave.server
52
+ end
53
+ alias assign_slave slave=
54
+
55
+ def restrictType=(restrictType)
56
+ satisfy_category?(restrictType, ["include", "exclude", nil])
57
+ @restrictType = value
58
+ end
59
+ alias assign_restrictType restrictType=
60
+
61
+ def restrictCollections=(restrictCollections)
62
+ if restrictCollections.nil?
63
+ @restrictCollections = nil
64
+ else
65
+ satisfy_class?(restrictCollections, [Arango::Collection, String], true)
66
+ @restrictCollections = restrictCollections.map do |v|
67
+ case v
68
+ when String
69
+ v
70
+ when Arango::Collection
71
+ v.name
72
+ end
73
+ end
74
+ end
75
+ end
76
+ alias assign_restrictCollections restrictCollections=
77
+
78
+
79
+ def to_h
80
+ master
81
+ {
82
+ "master": {
83
+ "database": @master.name,
84
+ "username": @master_server.username,
85
+ "endpoint": @master_server.endpoint
86
+ },
87
+ "slave": {
88
+ "database": @slave.name,
89
+ "username": @slave_server.username,
90
+ "endpoint": @slave_server.endpoint
91
+ },
92
+ "options": {
93
+ "includeSytem": @includeSystem,
94
+ "initialSyncMaxWaitTime": @initialSyncMaxWaitTime,
95
+ "restrictType": @restrictType,
96
+ "incremental": @incremental,
97
+ "restrictCollections": @restrictCollections,
98
+ "verbose": @verbose,
99
+ "connectTimeout": @connectTimeout,
100
+ "autoResync": @autoResync,
101
+ "idleMinWaitTime": @idleMinWaitTime,
102
+ "requestTimeout": @requestTimeout,
103
+ "requireFromPresent": @requireFromPresent,
104
+ "idleMaxWaitTime": @idleMaxWaitTime,
105
+ "maxConnectRetries": @maxConnectRetries,
106
+ "adaptivePolling": @adaptivePolling,
107
+ "connectionRetryWaitTime": @connectionRetryWaitTime,
108
+ "autoResyncRetries": @autoResyncRetries,
109
+ "chunkSize": @chunkSize
110
+ }.delete_if{|k,v| v.nil?}
111
+ }
112
+ end
113
+
114
+ # SYNCRONISATION
115
+
116
+ def sync
117
+ body = {
118
+ "username": @master_server.username,
119
+ "password": @master_server.password,
120
+ "endpoint": @master_server.endpoint,
121
+ "database": @master.name,
122
+ "restrictType": @restrictType,
123
+ "incremental": @incremental,
124
+ "includeSystem": @includeSystem,
125
+ "restrictCollections": @restrictCollections,
126
+ "initialSyncMaxWaitTime": @initialSyncMaxWaitTime
127
+ }
128
+ @slave.request("PUT", "_api/replication/sync", body: body)
129
+ end
130
+
131
+ # ENSLAVING
132
+
133
+ def enslave
134
+ body = {
135
+ "username": @master_server.username,
136
+ "password": @master_server.password,
137
+ "includeSystem": @includeSystem,
138
+ "endpoint": @server.endpoint,
139
+ "initialSyncMaxWaitTime": @initialSyncMaxWaitTime,
140
+ "database": @database.name,
141
+ "verbose": verbose,
142
+ "connectTimeout": @connectTimeout,
143
+ "autoResync": @autoResync,
144
+ "idleMinWaitTime": @idleMinWaitTime,
145
+ "requestTimeout": @requestTimeout,
146
+ "requireFromPresent": @requireFromPresent,
147
+ "idleMaxWaitTime": @idleMaxWaitTime,
148
+ "restrictType": @restrictType,
149
+ "maxConnectRetries": @maxConnectRetries,
150
+ "adaptivePolling": @adaptivePolling,
151
+ "connectionRetryWaitTime": @connectionRetryWaitTime,
152
+ "restrictCollections": @restrictCollections,
153
+ "autoResyncRetries": @autoResyncRetries,
154
+ "chunkSize": @chunkSize
155
+ }
156
+ @slave.request("PUT", "_api/replication/make-slave", body: body)
157
+ end
158
+
159
+ # REPLICATION
160
+
161
+ def start(from: nil)
162
+ @slave.request("PUT", "_api/replication/applier-start", query: {from: from})
163
+ end
164
+
165
+ def stop
166
+ @slave.request("PUT", "_api/replication/applier-stop")
167
+ end
168
+
169
+ def state
170
+ @slave.request("GET", "_api/replication/applier-state")
171
+ end
172
+
173
+ def configuration
174
+ @slave.request("GET", "_api/replication/applier-config")
175
+ end
176
+
177
+ def modify
178
+ body = {
179
+ "username": @master_server.username,
180
+ "password": @master_server.password,
181
+ "endpoint": @master_server.endpoint,
182
+ "database": @master.name,
183
+ "verbose": @verbose,
184
+ "autoResync": @autoResync,
185
+ "autoStart": @autoStart,
186
+ "chunkSize": @chunkSize,
187
+ "includeSystem": @includeSystem,
188
+ "connectTimeout": @connectTimeout,
189
+ "idleMinWaitTime": @idleMinWaitTime,
190
+ "requestTimeout": @requestTimeout,
191
+ "restrictType": @restrictType,
192
+ "requireFromPresent": @requireFromPresent,
193
+ "idleMaxWaitTime": @idleMaxWaitTime,
194
+ "maxConnectRetries": @maxConnectRetries,
195
+ "adaptivePolling": @adaptivePolling,
196
+ "initialSyncMaxWaitTime": @initialSyncMaxWaitTime,
197
+ "connectionRetryWaitTime": @connectionRetryWaitTime,
198
+ "restrictCollections": @restrictCollections,
199
+ "autoResyncRetries": @autoResyncRetries
200
+ }
201
+ @slave.request("PUT", "_api/replication/applier-config", body: body)
202
+ end
203
+ alias modifyReplication modifyConfigurationReplication
204
+
205
+ # LOGGER
206
+
207
+ def logger
208
+ @slave.request("GET", "_api/replication/logger-state")
209
+ end
210
+
211
+ def loggerFollow(from: nil, to: nil, chunkSize: nil, includeSystem: nil)
212
+ query = {
213
+ "from": from,
214
+ "to": to,
215
+ "chunkSize": chunkSize,
216
+ "includeSystem": includeSystem
217
+ }
218
+ @slave.request("GET", "_api/replication/logger-follow", query: query)
219
+ end
220
+
221
+ def loggerFirstTick
222
+ @slave.request("GET", "_api/replication/logger-first-tick", key: :firstTick)
223
+ end
224
+
225
+ def loggerRangeTick
226
+ @slave.request("GET", "_api/replication/logger-tick-ranges")
227
+ end
228
+
229
+ # SERVER-ID
230
+
231
+ def serverId
232
+ @slave.request("GET", "_api/replication/server-id", key: :serverId)
233
+ end
234
+ end
235
+ end
data/lib/Request.rb ADDED
@@ -0,0 +1,143 @@
1
+ module Arango
2
+ class Request
3
+ def initialize(return_output:, base_uri:, options:, verbose:, async:)
4
+ @return_output = return_output
5
+ @base_uri = base_uri
6
+ @options = options
7
+ @verbose = verbose
8
+ @async = async
9
+ end
10
+
11
+ attr_accessor :return_output, :base_uri, :options, :verbose, :async
12
+
13
+ def request(action, url, body: {}, headers: {}, query: {},
14
+ key: nil, return_direct_result: @return_output, skip_to_json: false,
15
+ keepNull: false, skip_parsing: false)
16
+ send_url = "#{@base_uri}/"
17
+ send_url += url
18
+
19
+ if body.is_a?(Hash)
20
+ body.delete_if{|k,v| v.nil?} unless keepNull
21
+ end
22
+ query.delete_if{|k,v| v.nil?}
23
+ headers.delete_if{|k,v| v.nil?}
24
+ options = @options.merge({body: body, query: query})
25
+ options[:headers].merge!(headers)
26
+
27
+ if ["GET", "HEAD", "DELETE"].include?(action)
28
+ options.delete(:body)
29
+ end
30
+
31
+ if @verbose
32
+ puts "\n===REQUEST==="
33
+ puts "#{action} #{send_url}\n"
34
+ puts JSON.pretty_generate(options)
35
+ puts "==============="
36
+ end
37
+
38
+ if !skip_to_json && !options[:body].nil?
39
+ options[:body] = Oj.dump(options[:body], mode: :json)
40
+ end
41
+ options.delete_if{|k,v| v.empty?}
42
+
43
+ begin
44
+ response = case action
45
+ when "GET"
46
+ HTTParty.get(send_url, options)
47
+ when "HEAD"
48
+ HTTParty.head(send_url, options)
49
+ when "PATCH"
50
+ HTTParty.patch(send_url, options)
51
+ when "POST"
52
+ HTTParty.post(send_url, options)
53
+ when "PUT"
54
+ HTTParty.put(send_url, options)
55
+ when "DELETE"
56
+ HTTParty.delete(send_url, options)
57
+ end
58
+ rescue Exception => e
59
+ raise Arango::Error.new err: :impossible_to_connect_with_database,
60
+ data: {"error": e.message}
61
+ end
62
+
63
+ if @verbose
64
+ puts "\n===RESPONSE==="
65
+ puts "CODE: #{response.code}"
66
+ end
67
+
68
+ case @async
69
+ when :store
70
+ val = response.headers["x-arango-async-id"]
71
+ if @verbose
72
+ puts val
73
+ puts "==============="
74
+ end
75
+ return val
76
+ when true
77
+ puts "===============" if @verbose
78
+ return true
79
+ end
80
+
81
+ if skip_parsing
82
+ val = response.parsed_response
83
+ if @verbose
84
+ puts val
85
+ puts "==============="
86
+ end
87
+ return val
88
+ end
89
+
90
+ begin
91
+ result = Oj.load(response.parsed_response, mode: :json, symbol_keys: true)
92
+ rescue Exception => e
93
+ raise Arango::Error.new err: :impossible_to_parse_arangodb_response,
94
+ data: {"response": response.parsed_response, "action": action, "url": send_url,
95
+ "request": JSON.pretty_generate(options)}
96
+ end
97
+
98
+ if @verbose
99
+ case result
100
+ when Hash, Array
101
+ puts JSON.pretty_generate(result)
102
+ else
103
+ puts "#{result}\n"
104
+ end
105
+ puts "==============="
106
+ end
107
+
108
+ case result
109
+ when Hash
110
+ if result[:error]
111
+ raise Arango::ErrorDB.new message: result[:errorMessage],
112
+ code: result[:code], data: result, errorNum: result[:errorNum],
113
+ action: action, url: send_url, request: options
114
+ elsif return_direct_result
115
+ return result
116
+ end
117
+ when Array, NilClass
118
+ return result
119
+ else
120
+ raise Arango::Error.new message: "ArangoRB didn't return a valid result",
121
+ data: {"response": response, "action": action, "url": send_url, "request": JSON.pretty_generate(options)}
122
+ end
123
+ return key.nil? ? result.delete_if{|k,v| k == :error || k == :code} : result[key]
124
+ end
125
+
126
+ def download(url:, path:, body: {}, headers: {}, query: {})
127
+ send_url = "#{@base_uri}/"
128
+ send_url += url
129
+ body.delete_if{|k,v| v.nil?}
130
+ query.delete_if{|k,v| v.nil?}
131
+ headers.delete_if{|k,v| v.nil?}
132
+ body = Oj.dump(body, mode: :json)
133
+ options = @options.merge({body: body, query: query, headers: headers, stream_body: true})
134
+ puts "\n#{action} #{send_url}\n" if @verbose
135
+ File.open(path, "w") do |file|
136
+ file.binmode
137
+ HTTParty.post(send_url, options) do |fragment|
138
+ file.write(fragment)
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
data/lib/Server.rb ADDED
@@ -0,0 +1,466 @@
1
+ # === SERVER ===
2
+
3
+ module Arango
4
+ class Server
5
+ include Arango::Helper_Error
6
+
7
+ def initialize(username: "root", password:, server: "localhost",
8
+ warning: true, port: "8529", verbose: false, return_output: false, async: false, active_cache: false, pool: false, size: 5, timeout: 5)
9
+ @base_uri = "http://#{server}:#{port}"
10
+ @server = server
11
+ @port = port
12
+ @username = username
13
+ @password = password
14
+ @options = {body: {}, headers: {}, query: {},
15
+ basic_auth: {username: @username, password: @password }, format: :plain}
16
+ @verbose = verbose
17
+ @return_output = return_output
18
+ @warning = warning
19
+ @active_cache = active_cache
20
+ @cache = @active_cache ? Arango::Cache.new : nil
21
+ @pool = pool
22
+ @size = size
23
+ @timeout = timeout
24
+ @request = Arango::Request.new(return_output: @return_output,
25
+ base_uri: @base_uri, options: @options, verbose: @verbose, async: @async)
26
+ assign_async(async)
27
+ if @pool
28
+ @internal_request = ConnectionPool.new(size: @size, timeout: @timeout){ @request }
29
+ end
30
+ end
31
+
32
+ # === DEFINE ===
33
+
34
+ attr_reader :async, :port, :server, :base_uri, :username, :cache,
35
+ :verbose, :return_output, :active_cache, :pool
36
+ attr_accessor :warning, :size, :timeout
37
+
38
+ def active_cache=(active)
39
+ satisfy_category?(active, [true, false])
40
+ @active_cache = active
41
+ if @active_cache
42
+ @cache ||= Arango::Cache.new
43
+ elsif !@cache.nil?
44
+ @cache.clear
45
+ end
46
+ end
47
+
48
+ def pool=(pool)
49
+ satisfy_category?(pool, [true, false])
50
+ return if @pool == pool
51
+ @pool = pool
52
+ if @pool
53
+ @internal_request = ConnectionPool.new(size: @size, timeout: @timeout){ @request }
54
+ else
55
+ @internal_request&.shutdown { |conn| conn.quit }
56
+ @internal_request = nil
57
+ end
58
+ end
59
+ alias changePoolStatus pool=
60
+
61
+ def restartPool
62
+ changePoolStatus(false)
63
+ changePoolStatus(true)
64
+ end
65
+
66
+ def verbose=(verbose)
67
+ satisfy_category?(verbose, [true, false])
68
+ @verbose = verbose
69
+ @request.verbose = verbose
70
+ end
71
+
72
+ def return_output=(return_output)
73
+ satisfy_category?(return_output, [true, false])
74
+ @return_output = return_output
75
+ @request.return_output = return_output
76
+ end
77
+
78
+ def username=(username)
79
+ @username = username
80
+ @options[:basic_auth][:username] = @username
81
+ @request.options = options
82
+ end
83
+
84
+ def password=(password)
85
+ @password = password
86
+ @options[:basic_auth][:password] = @password
87
+ @request.options = options
88
+ end
89
+
90
+ def port=(port)
91
+ @port = port
92
+ @base_uri = "http://#{@server}:#{@port}"
93
+ @request.base_uri = @base_uri
94
+ end
95
+
96
+ def server=(server)
97
+ @server = server
98
+ @base_uri = "http://#{@server}:#{@port}"
99
+ @request.base_uri = @base_uri
100
+ end
101
+
102
+ def async=(async)
103
+ satisfy_category?(async, ["true", "false", false, true, "store", :store])
104
+ case async
105
+ when true, "true"
106
+ @options[:headers]["x-arango-async"] = "true"
107
+ @async = true
108
+ when :store, "store"
109
+ @options[:headers]["x-arango-async"] ="store"
110
+ @async = :store
111
+ when false, "false"
112
+ @options[:headers].delete("x-arango-async")
113
+ @async = false
114
+ end
115
+ @request.async = @async
116
+ @request.options = @options
117
+ end
118
+ alias assign_async async=
119
+
120
+ # === TO HASH ===
121
+
122
+ def to_h
123
+ hash = {
124
+ "base_uri": @base_uri,
125
+ "server": @server,
126
+ "port": @port,
127
+ "username": @username,
128
+ "async": @async,
129
+ "verbose": @verbose,
130
+ "return_output": @return_output,
131
+ "warning": @warning
132
+ }.delete_if{|k,v| v.nil?}
133
+ end
134
+
135
+ # === REQUESTS ===
136
+
137
+ def request(*args)
138
+ if @pool
139
+ @internal_request.with{|request| request.request(*args)}
140
+ else
141
+ @request.request(*args)
142
+ end
143
+ end
144
+
145
+ def download(*args)
146
+ if @pool
147
+ @internal_request.with{|request| request.download(*args)}
148
+ else
149
+ @request.download(*args)
150
+ end
151
+ end
152
+
153
+ # == DATABASE ==
154
+
155
+ def [](database)
156
+ Arango::Database.new(name: database, server: self)
157
+ end
158
+
159
+ def database(name:)
160
+ Arango::Database.new(name: name, server: self)
161
+ end
162
+
163
+ def databases(user: false)
164
+ if user
165
+ result = request("GET", "_api/database/user", key: :result)
166
+ else
167
+ result = request("GET", "_api/database", key: :result)
168
+ end
169
+ return result if return_directly?(result)
170
+ result.map{|db| Arango::Database.new(name: db, server: self)}
171
+ end
172
+
173
+ # == CLUSTER ==
174
+
175
+ def checkPort(port: @port)
176
+ request("GET", "_admin/clusterCheckPort", query: {port: port.to_s})
177
+ end
178
+
179
+ # === MONITORING ===
180
+
181
+ def log(upto: nil, level: nil, start: nil, size: nil, offset: nil, search: nil, sort: nil)
182
+ satisfy_category?(upto, [nil, "fatal", 0, "error", 1, "warning", 2, "info", 3, "debug", 4])
183
+ satisfy_category?(sort, [nil, "asc", "desc"])
184
+ query = {
185
+ upto: upto, level: level, start: start, size: size,
186
+ offset: offset, search: search, sort: sort
187
+ }
188
+ request("GET", "_admin/log", query: query)
189
+ end
190
+
191
+ def loglevel
192
+ request("GET", "_admin/log/level")
193
+ end
194
+
195
+ def updateLoglevel(body:)
196
+ request("PUT", "_admin/log/level", body: body)
197
+ end
198
+
199
+ def reload
200
+ request("GET", "_admin/routing/reload")
201
+ return true
202
+ end
203
+
204
+ def available?
205
+ request("POST", "_admin/routing/availability", body: {})
206
+ end
207
+
208
+ def statistics
209
+ request("GET", "_admin/statistics")
210
+ end
211
+
212
+ def statisticsDescription
213
+ request("GET", "_admin/statistics-description")
214
+ end
215
+
216
+ def status
217
+ request("GET", "_admin/status")
218
+ end
219
+
220
+ def role
221
+ request("GET", "_admin/server/role", key: :role)
222
+ end
223
+
224
+ def serverData
225
+ request("GET", "_admin/server/id")
226
+ end
227
+
228
+ def mode
229
+ request("GET", "_admin/server/mode")
230
+ end
231
+
232
+ def updateMode(mode:)
233
+ satisfy_category?(mode, ["default", "readonly"])
234
+ body = {mode: mode}
235
+ request("PUT", "_admin/server/mode", body: mode)
236
+ end
237
+
238
+ def clusterHealth
239
+ request("GET", "_admin/health")
240
+ end
241
+
242
+ def clusterStatistics dbserver:
243
+ query = {DBserver: dbserver}
244
+ request("GET", "_admin/clusterStatistics", query: query)
245
+ end
246
+
247
+ def serverId
248
+ request("GET", "_api/replication/server-id", key: :serverId)
249
+ end
250
+
251
+ # === ENDPOINT ===
252
+
253
+ def endpoint
254
+ "tcp://#{@server}:#{@port}"
255
+ end
256
+
257
+ def endpoints
258
+ request("GET", "_api/cluster/endpoints")
259
+ end
260
+
261
+ def allEndpoints(warning: @warning)
262
+ warning_deprecated(warning, "allEndpoints")
263
+ request("GET", "_api/endpoint")
264
+ end
265
+
266
+ # === USER ===
267
+
268
+ def user(password: "", name:, extra: {}, active: nil)
269
+ Arango::User.new(server: self, password: password, name: name, extra: extra,
270
+ active: active)
271
+ end
272
+
273
+ def users
274
+ result = request("GET", "_api/user", key: :result)
275
+ return result if return_directly?(result)
276
+ result.map do |user|
277
+ Arango::User.new(name: user[:user], active: user[:active],
278
+ extra: user[:extra], server: self)
279
+ end
280
+ end
281
+
282
+ # == TASKS ==
283
+
284
+ def tasks
285
+ result = request("GET", "_api/tasks")
286
+ return result if return_directly?(result)
287
+ result.map do |task|
288
+ database = Arango::Database.new(name: task[:database], server: self)
289
+ Arango::Task.new(body: task, database: database)
290
+ end
291
+ end
292
+
293
+ # === ASYNC ===
294
+
295
+ def fetchAsync(id:)
296
+ request("PUT", "_api/job/#{id}")
297
+ end
298
+
299
+ def cancelAsync(id:)
300
+ request("PUT", "_api/job/#{id}/cancel", key: :result)
301
+ end
302
+
303
+ def destroyAsync(id:, stamp: nil)
304
+ query = {"stamp": stamp}
305
+ request("DELETE", "_api/job/#{id}", query: query, key: :result)
306
+ end
307
+
308
+ def destroyAsyncByType(type:, stamp: nil)
309
+ satisfy_category?(type, ["all", "expired"])
310
+ query = {"stamp": stamp}
311
+ request("DELETE", "_api/job/#{type}", query: query)
312
+ end
313
+
314
+ def destroyAllAsync
315
+ destroyAsyncByType(type: "all")
316
+ end
317
+
318
+ def destroyExpiredAsync
319
+ destroyAsyncByType(type: "expired")
320
+ end
321
+
322
+ def retrieveAsync(id:)
323
+ request("GET", "_api/job/#{id}")
324
+ end
325
+
326
+ def retrieveAsyncByType(type:, count: nil)
327
+ satisfy_category?(type, ["done", "pending"])
328
+ request("GET", "_api/job/#{type}", query: {count: count})
329
+ end
330
+
331
+ def retrieveDoneAsync(count: nil)
332
+ retrieveAsyncByType(type: "done", count: count)
333
+ end
334
+
335
+ def retrievePendingAsync(count: nil)
336
+ retrieveAsyncByType(type: "pending", count: count)
337
+ end
338
+
339
+ # === BATCH ===
340
+
341
+ def batch(boundary: "XboundaryX", queries: [])
342
+ Arango::Batch.new(server: self, boundary: boundary, queries: queries)
343
+ end
344
+
345
+ def createDumpBatch(ttl:, dbserver: nil)
346
+ query = { DBserver: dbserver }
347
+ body = { ttl: ttl }
348
+ result = request("POST", "_api/replication/batch",
349
+ body: body, query: query)
350
+ return result if return_directly?(result)
351
+ return result[:id]
352
+ end
353
+
354
+ def destroyDumpBatch(id:, dbserver: nil)
355
+ query = {DBserver: dbserver}
356
+ result = request("DELETE", "_api/replication/batch/#{id}", query: query)
357
+ return_delete(result)
358
+ end
359
+
360
+ def prolongDumpBatch(id:, ttl:, dbserver: nil)
361
+ query = { DBserver: dbserver }
362
+ body = { ttl: ttl }
363
+ result = request("PUT", "_api/replication/batch/#{id}",
364
+ body: body, query: query)
365
+ return result if return_directly?(result)
366
+ return true
367
+ end
368
+
369
+ # === AGENCY ===
370
+
371
+ def agencyConfig
372
+ request("GET", "_api/agency/config")
373
+ end
374
+
375
+ def agencyWrite(body:, agency_mode: nil)
376
+ satisfy_category?(agency_mode, ["waitForCommmitted", "waitForSequenced", "noWait", nil])
377
+ headers = {"X-ArangoDB-Agency-Mode": agency_mode}
378
+ request("POST", "_api/agency/write", headers: headers,
379
+ body: body)
380
+ end
381
+
382
+ def agencyRead(body:, agency_mode: nil)
383
+ satisfy_category?(agency_mode, ["waitForCommmitted", "waitForSequenced", "noWait", nil])
384
+ headers = {"X-ArangoDB-Agency-Mode": agency_mode}
385
+ request("POST", "_api/agency/read", headers: headers,
386
+ body: body)
387
+ end
388
+
389
+ # === MISCELLANEOUS FUNCTIONS ===
390
+
391
+ def version(details: nil)
392
+ query = {"details": details}
393
+ request("GET", "_api/version", query: query)
394
+ end
395
+
396
+ def engine
397
+ request("GET", "_api/engine")
398
+ end
399
+
400
+ def flushWAL(waitForSync: nil, waitForCollector: nil)
401
+ body = {
402
+ "waitForSync": waitForSync,
403
+ "waitForCollector": waitForCollector
404
+ }
405
+ result = request("PUT", "_admin/wal/flush", body: body)
406
+ return return_directly?(result) ? result: true
407
+ end
408
+
409
+ def propertyWAL
410
+ request("GET", "_admin/wal/properties")
411
+ end
412
+
413
+ def changePropertyWAL(allowOversizeEntries: nil, logfileSize: nil,
414
+ historicLogfiles: nil, reserveLogfiles: nil, throttleWait: nil,
415
+ throttleWhenPending: nil)
416
+ body = {
417
+ "allowOversizeEntries": allowOversizeEntries,
418
+ "logfileSize": allowOversizeEntries,
419
+ "historicLogfiles": historicLogfiles,
420
+ "reserveLogfiles": reserveLogfiles,
421
+ "throttleWait": throttleWait,
422
+ "throttleWhenPending": throttleWhenPending
423
+ }
424
+ request("PUT", "_admin/wal/properties", body: body)
425
+ end
426
+
427
+ def transactions
428
+ request("GET", "_admin/wal/transactions")
429
+ end
430
+
431
+ def time
432
+ request("GET", "_admin/time", key: :time)
433
+ end
434
+
435
+ def echo
436
+ request("POST", "_admin/echo", body: {})
437
+ end
438
+
439
+ def databaseVersion
440
+ request("GET", "_admin/database/target-version", key: :version)
441
+ end
442
+
443
+ def shutdown
444
+ result = request("DELETE", "_admin/shutdown")
445
+ return return_directly?(result) ? result: true
446
+ end
447
+
448
+ def test(body:)
449
+ request("POST", "_admin/test", body: body)
450
+ end
451
+
452
+ def execute(body:)
453
+ request("POST", "_admin/execute", body: body)
454
+ end
455
+
456
+ def return_directly?(result)
457
+ return @async != false || @return_direct_result
458
+ return result if result == true
459
+ end
460
+
461
+ def return_delete(result)
462
+ return result if @async != false
463
+ return return_directly?(result) ? result : true
464
+ end
465
+ end
466
+ end