arango-driver 3.5.0.alpha0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +1073 -0
  4. data/arango_opal.js +15 -0
  5. data/lib/arango-driver.rb +61 -0
  6. data/lib/arango.rb +96 -0
  7. data/lib/arango/aql.rb +188 -0
  8. data/lib/arango/collection.rb +575 -0
  9. data/lib/arango/collection/documents.rb +122 -0
  10. data/lib/arango/collection/edges.rb +149 -0
  11. data/lib/arango/collection/importing.rb +57 -0
  12. data/lib/arango/collection/indexes.rb +53 -0
  13. data/lib/arango/collection/replication.rb +24 -0
  14. data/lib/arango/collection/user.rb +28 -0
  15. data/lib/arango/cursor.rb +67 -0
  16. data/lib/arango/database.rb +188 -0
  17. data/lib/arango/database/analyzer.rb +21 -0
  18. data/lib/arango/database/aql_functions.rb +54 -0
  19. data/lib/arango/database/aql_queries.rb +114 -0
  20. data/lib/arango/database/aql_query_cache.rb +27 -0
  21. data/lib/arango/database/collections.rb +100 -0
  22. data/lib/arango/database/foxx_services.rb +103 -0
  23. data/lib/arango/database/graph_access.rb +27 -0
  24. data/lib/arango/database/http_route.rb +9 -0
  25. data/lib/arango/database/replication.rb +96 -0
  26. data/lib/arango/database/stream_transactions.rb +25 -0
  27. data/lib/arango/database/tasks.rb +67 -0
  28. data/lib/arango/database/transactions.rb +15 -0
  29. data/lib/arango/database/user.rb +26 -0
  30. data/lib/arango/database/view_access.rb +37 -0
  31. data/lib/arango/document.rb +443 -0
  32. data/lib/arango/edge.rb +164 -0
  33. data/lib/arango/error.rb +97 -0
  34. data/lib/arango/error_db.rb +27 -0
  35. data/lib/arango/foxx.rb +255 -0
  36. data/lib/arango/graph.rb +202 -0
  37. data/lib/arango/graph/basics.rb +39 -0
  38. data/lib/arango/graph/edge_access.rb +56 -0
  39. data/lib/arango/graph/vertex_access.rb +33 -0
  40. data/lib/arango/helper/collection_assignment.rb +13 -0
  41. data/lib/arango/helper/database_assignment.rb +14 -0
  42. data/lib/arango/helper/request_method.rb +45 -0
  43. data/lib/arango/helper/return.rb +21 -0
  44. data/lib/arango/helper/satisfaction.rb +28 -0
  45. data/lib/arango/helper/server_assignment.rb +13 -0
  46. data/lib/arango/helper/traversal.rb +12 -0
  47. data/lib/arango/index.rb +103 -0
  48. data/lib/arango/replication.rb +231 -0
  49. data/lib/arango/request.rb +92 -0
  50. data/lib/arango/request_batch.rb +174 -0
  51. data/lib/arango/result.rb +130 -0
  52. data/lib/arango/search_view.rb +23 -0
  53. data/lib/arango/server.rb +68 -0
  54. data/lib/arango/server/administration.rb +296 -0
  55. data/lib/arango/server/agency.rb +23 -0
  56. data/lib/arango/server/async.rb +51 -0
  57. data/lib/arango/server/batch.rb +35 -0
  58. data/lib/arango/server/config.rb +76 -0
  59. data/lib/arango/server/databases.rb +71 -0
  60. data/lib/arango/server/monitoring.rb +17 -0
  61. data/lib/arango/server/opal_support.rb +95 -0
  62. data/lib/arango/server/tasks.rb +69 -0
  63. data/lib/arango/server/user.rb +22 -0
  64. data/lib/arango/task.rb +223 -0
  65. data/lib/arango/transaction.rb +113 -0
  66. data/lib/arango/traversal.rb +212 -0
  67. data/lib/arango/user.rb +174 -0
  68. data/lib/arango/version.rb +3 -0
  69. data/lib/arango/vertex.rb +112 -0
  70. data/lib/arango/view.rb +124 -0
  71. data/lib/arango/view/basics.rb +25 -0
  72. metadata +296 -0
@@ -0,0 +1,174 @@
1
+ module Arango
2
+ class RequestBatch
3
+ include Arango::Helper::Satisfaction
4
+ include Arango::Helper::Return
5
+ include Arango::Helper::DatabaseAssignment
6
+ include Arango::Helper::ServerAssignment
7
+
8
+ # Initialize a new request batch.
9
+ # Request must be a Hash with the keys:
10
+ # - :id, optional
11
+ # - :action, required
12
+ # - :url, required
13
+ # - :body, optional
14
+ # @param server [Arango::Server] The server the requests should be run on. One of server or database must be given.
15
+ # @param database [Arango::Database] The database the requests should be run on. One of server or database must be given.
16
+ # @param requests [Array<Hash>, Hash] Array of requests or a single request as Hash, optional.
17
+ # @return [Arango::RequestBatch]
18
+ def initialize(server: nil, database: nil, requests: [])
19
+ @id = 1
20
+ if database
21
+ assign_database(database)
22
+ elsif server
23
+ assign_server(server)
24
+ else
25
+ raise Arango::Error.new(err: :server_or_database_must_be_given)
26
+ end
27
+ send(:requests=, requests)
28
+ @boundary = "ArangoDriverRequestPart"
29
+ @headers = { 'Content-Type' => "multipart/form-data; boundary=#{@boundary}" }
30
+ end
31
+
32
+ attr_reader :database, :requests, :server
33
+
34
+ # Assign a bunch of requests.
35
+ # @param requests [Array<Hash>, Hash] Array of requests or a single request as Hash, optional.
36
+ # @return [Array<Hash>]
37
+ def requests=(requests)
38
+ requests = [requests] unless requests.is_a?(Array)
39
+ @requests = {}
40
+ requests.each do |request|
41
+ add_request(**request)
42
+ end
43
+ return @requests
44
+ end
45
+
46
+ # Add a single request
47
+ # @param id [String] optional
48
+ # @param action [String]
49
+ # @param url [String]
50
+ # @param body [Hash] optional
51
+ def add_request(get: nil, head: nil, patch: nil, post: nil, put: nil, delete: nil, body: nil, query: nil, headers: nil, block: nil, promise: nil)
52
+ id = @id.to_s
53
+ @id += 1
54
+ @requests[id] = {
55
+ id: id,
56
+ body: body,
57
+ query: query,
58
+ block: block,
59
+ headers: headers,
60
+ promise: promise
61
+ }.delete_if{|_,v| v.nil?}
62
+ @requests[id][:action] = if get then @requests[id][:url] = get; 'GET'
63
+ elsif head then @requests[id][:url] = head; 'HEAD'
64
+ elsif patch then @requests[id][:url] = patch; 'PATCH'
65
+ elsif post then @requests[id][:url] = post; 'POST'
66
+ elsif put then @requests[id][:url] = put; 'PUT'
67
+ elsif delete then @requests[id][:url] = delete; 'DELETE'
68
+ end
69
+ @requests[id]
70
+ end
71
+ alias modify_request add_request
72
+
73
+ def delete_request(id)
74
+ @requests.delete(id)
75
+ @requests
76
+ end
77
+
78
+ # Execute the request batch.
79
+ # @return [Hash<Arango::Result]
80
+ def execute
81
+ body = ""
82
+ @requests.each do |id, request|
83
+ body << "--#{@boundary}\r\n"
84
+ body << "Content-Type: application/x-arango-batchpart\r\n"
85
+ body << "Content-Id: #{id}\r\n\r\n"
86
+ url = "/#{request[:url]}"
87
+ if request.key?(:query)
88
+ url << '?'
89
+ url << URI.encode_www_form(request[:query])
90
+ end
91
+ body << "#{request[:action]} #{url} HTTP/1.1\r\n"
92
+ if request.key?(:headers)
93
+ request[:headers].each do |header, value|
94
+ body << "#{header}: #{value}\r\n"
95
+ end
96
+ end
97
+ body << "\r\n"
98
+ unless request[:body].nil?
99
+ request[:body].delete_if{|_,v| v.nil?}
100
+ body << "#{Oj.dump(request[:body], mode: :json)}\r\n"
101
+ end
102
+ end
103
+ body << "--#{@boundary}--\r\n\r\n" if @requests.length > 0
104
+ result = if @database
105
+ @database.request(post: '_api/batch', body: body, headers: @headers)
106
+ else
107
+ @server.request(post: '_api/batch', body: body, headers: @headers)
108
+ end
109
+ result_hash = _parse_result(result)
110
+ _check_for_errors(result_hash)
111
+ final_result = result_hash
112
+ result_hash.each_key do |id|
113
+ request = @requests[id.to_s]
114
+ if request.key?(:block)
115
+ result = result_hash[id]
116
+ if request.key?(:promise)
117
+ block_result = request[:block].call(result)
118
+ final_result = request[:promise].resolve(block_result)
119
+ else
120
+ final_result = request[:block].call(result)
121
+ end
122
+ end
123
+ end
124
+ final_result
125
+ end
126
+
127
+ private
128
+
129
+ def _check_for_errors(result_hash)
130
+ result_hash.each do |k, result|
131
+ if !result.is_array? && result.error?
132
+ raise Arango::ErrorDB.new(message: result.error_message, code: result.code, data: result.to_h, error_num: result.error_num,
133
+ action: '', url: '', request: { request_part: k })
134
+ end
135
+ end
136
+ result_hash
137
+ end
138
+
139
+ def _parse_result(result)
140
+ parts = result.split("--#{@boundary}")
141
+ result_hash = {}
142
+ parts.each do |part|
143
+ if part == "" || part == "--"
144
+ false
145
+ else
146
+ key = nil
147
+ is_json = false
148
+ body = nil
149
+ code = 0
150
+ lines = part.split("\r\n")
151
+ lines.each do |line|
152
+ if line.start_with?('Content-Id: ')
153
+ key = line[12..-1]
154
+ elsif line.start_with?('HTTP/1.1 ')
155
+ code = line[9..12].to_i
156
+ elsif line.start_with?('Content-Type: application/json')
157
+ is_json = true
158
+ elsif line.start_with?('{') || line.start_with?('[')
159
+ if is_json
160
+ body = Oj.load(line, mode: :json, smybol_keys: true)
161
+ else
162
+ body = line
163
+ end
164
+ end
165
+ end
166
+ res = Arango::Result.new(is_json ? body : { body: body })
167
+ res.response_code = code
168
+ result_hash[key.to_sym] = res
169
+ end
170
+ end
171
+ result_hash
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,130 @@
1
+ module Arango
2
+ class Result
3
+ def initialize(result)
4
+ @result = result ? result : {}
5
+ @is_array = @result.class == Array
6
+ @result.transform_keys!(&:to_sym) unless @is_array
7
+ end
8
+
9
+ attr_accessor :response_code
10
+
11
+ # standard fields
12
+ def code
13
+ return @result[:code] if @result.key?(:code)
14
+ nil
15
+ end
16
+
17
+ def error?
18
+ return @result[:error] if @result.key?(:error)
19
+ false
20
+ end
21
+
22
+ def error_message
23
+ return @result[:errorMessage] if @result.key?(:errorMessage)
24
+ nil
25
+ end
26
+ alias errorMessage error_message
27
+
28
+ def error_num
29
+ return @result[:errorNum] if @result.key?(:errorNum)
30
+ nil
31
+ end
32
+ alias errorNum error_num
33
+
34
+ # access to all other fields
35
+ def [](field_name_or_index)
36
+ return @result[field_name_or_index] if @is_array
37
+ field_name_y = field_name_or_index.to_sym
38
+ return @result[field_name_y] if @result.key?(field_name_y)
39
+ field_name_s = field_name_or_index.to_s
40
+ field_name_lcy = field_name_s.camelize(:lower).to_sym
41
+ return @result[field_name_lcy] if @result.key?(field_name_lcy)
42
+ field_name_ucy = field_name_s.camelize(:upper).to_sym
43
+ return @result[field_name_ucy] if @result.key?(field_name_ucy)
44
+ nil
45
+ end
46
+
47
+ def []=(field_name_or_index, value)
48
+ return @result[field_name_or_index] = value if @is_array
49
+ field_name_y = field_name_or_index.to_sym
50
+ return @result[field_name_y] = value if @result.key?(field_name_y)
51
+ field_name_s = field_name_or_index.to_s
52
+ field_name_lcy = field_name_s.camelize(:lower).to_sym
53
+ return @result[field_name_lcy] = value if @result.key?(field_name_lcy)
54
+ field_name_ucy = field_name_s.camelize(:upper).to_sym
55
+ return @result[field_name_ucy] = value if @result.key?(field_name_ucy)
56
+ nil
57
+ end
58
+
59
+ def method_missing(field_name_or_index, *args, &block)
60
+ return self[field_name_or_index] = args[0] if field_name_or_index.to_s.end_with?('=')
61
+ return self[field_name_or_index] if @is_array
62
+ field_name_or_index = field_name_or_index.to_sym
63
+ return self[field_name_or_index] if key?(field_name_or_index)
64
+ @result.send(field_name_or_index, *args, &block)
65
+ end
66
+
67
+ # convenience
68
+ def delete_if(*args, &block)
69
+ @result.delete_if(*args, &block)
70
+ end
71
+
72
+ def empty?
73
+ @result.empty?
74
+ end
75
+
76
+ def first
77
+ @result.first
78
+ end
79
+
80
+ def is_array?
81
+ @is_array
82
+ end
83
+
84
+ def key?(key)
85
+ return false if @is_array
86
+ field_name_y = key.to_sym
87
+ return true if @result.key?(field_name_y)
88
+ field_name_s = key.to_s
89
+ field_name_lcy = field_name_s.camelize(:lower).to_sym
90
+ return true if @result.key?(field_name_lcy)
91
+ field_name_ucy = field_name_s.camelize(:upper).to_sym
92
+ return true if @result.key?(field_name_ucy)
93
+ false
94
+ end
95
+ alias has_key? key?
96
+
97
+ def map(*args, &block)
98
+ @result.map(*args, &block)
99
+ end
100
+
101
+ def raw_result
102
+ @result
103
+ end
104
+
105
+ def to_underscored_h
106
+ hash = to_h
107
+ hash.transform_keys { |k| k.to_s.underscore }
108
+ end
109
+
110
+ def to_h
111
+ return @result unless @is_array
112
+ @result.to_h
113
+ end
114
+ alias to_hash to_h
115
+
116
+ def to_a
117
+ return @result if @is_array
118
+ @result.to_a
119
+ end
120
+
121
+ def to_ary
122
+ return @result.to_ary if @is_array
123
+ to_a
124
+ end
125
+
126
+ def to_s
127
+ @result.to_s
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,23 @@
1
+ module Arango
2
+ class SearchView
3
+ def initialize
4
+
5
+ end
6
+
7
+ def create
8
+ end
9
+
10
+ def properties
11
+
12
+ end
13
+
14
+ def properties=
15
+
16
+ end
17
+ alias replace_properties properties=
18
+
19
+ def update_properties
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,68 @@
1
+ # === SERVER ===
2
+
3
+ module Arango
4
+ class Server
5
+ include Arango::Helper::Satisfaction
6
+
7
+ include Arango::Server::Administration
8
+ include Arango::Server::Config
9
+ include Arango::Server::Databases
10
+ include Arango::Server::Monitoring
11
+ include Arango::Server::Tasks
12
+ include Arango::Server::OpalSupport
13
+
14
+ # Connect to a ArangoDB server.
15
+ # @param username [String]
16
+ # @param password [String]
17
+ # @param host [String]
18
+ # @param port [String]
19
+ # @param tls [Boolean] Use TLS for the connection, optional, default: false.
20
+ # @return [Arango::Server]
21
+ def initialize(username: "root", password:, host: "localhost", warning: true, port: "8529", return_output: false, timeout: 5, tls: false)
22
+ @tls = tls
23
+ @host = host
24
+ @port = port
25
+ @username = username
26
+ @password = password
27
+ @options = { body: {}, headers: {}, query: {}, userpwd: "#{username}:#{password}" }
28
+ @return_output = return_output
29
+ @warning = warning
30
+ @active_cache = active_cache
31
+ @timeout = timeout
32
+ set_base_uri
33
+ @request = Arango::Request.new(base_uri: @base_uri, options: @options)
34
+ end
35
+
36
+ def endpoint
37
+ "tcp://#{@host}:#{@port}"
38
+ end
39
+
40
+ def request(*args)
41
+ @request.request(*args)
42
+ end
43
+
44
+ # Returns information about the currently running transactions.
45
+ # @return [Arango::Result]
46
+ def transactions
47
+ request(get: '_admin/wal/transactions')
48
+ end
49
+
50
+ # Check if transactions are running on server.
51
+ # @return [Boolean]
52
+ def transactions_running?
53
+ transactions.running_transactions > 0
54
+ end
55
+
56
+ private
57
+
58
+ def download(*args)
59
+ @request.download(*args)
60
+ end
61
+
62
+ def set_base_uri
63
+ @base_uri = "http"
64
+ @base_uri += "s" if @tls
65
+ @base_uri += "://#{@host}:#{@port}"
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,296 @@
1
+ module Arango
2
+ class Server
3
+ module Administration
4
+ # Check availability of the server.
5
+ # @return [Boolean]
6
+ def available?
7
+ 200 == request(get: '_admin/server/availability').code
8
+ end
9
+
10
+ # Returns information about all coordinator endpoints (cluster only).
11
+ # @return [Array<String>]
12
+ def cluster_endpoints
13
+ if in_cluster?
14
+ endpoints = request(get: "_api/cluster/endpoints").endpoints
15
+ endpoints.map { |e| e[:endpoint] }
16
+ end
17
+ end
18
+
19
+ # Returns information about all server endpoints.
20
+ # @return [Array<String>]
21
+ def endpoints
22
+ endpoints = request(get: "_api/endpoint")
23
+ endpoints.map { |e| e[:endpoint] }
24
+ end
25
+
26
+ # Send back what was sent in, headers, post body etc.
27
+ # @param request_hash [Hash] The request body.
28
+ # @return [Hash]
29
+ def echo(request_hash)
30
+ result = request(post: "_admin/echo", body: request_hash)
31
+ Oj.load(result.requestBody, symbol_keys: true)
32
+ end
33
+
34
+ # Return server database engine information
35
+ # @return [Arango::Result]
36
+ def engine
37
+ @engine ||= request(get: '_api/engine')
38
+ end
39
+
40
+ # Return true if the server uses the mmfiles engine.
41
+ # @return [Boolean]
42
+ def mmfiles?
43
+ 'mmfiles' == engine.name
44
+ end
45
+
46
+ # Return true if the server uses the rocksdb engine.
47
+ # @return [Boolean]
48
+ def rocksdb?
49
+ 'rocksdb' == engine.name
50
+ end
51
+
52
+ # Read global logs from the server.
53
+ # Log levels for the upto and level params:
54
+ # - fatal or 0
55
+ # - error or 1
56
+ # - warning or 2
57
+ # - info or 3
58
+ # - debug or 4
59
+ # The parameters upto and level are mutually exclusive.
60
+ # All params are optional.
61
+ # @param upto [Symbol, String, Integer] Returns all log entries up to log level upto. The default value is info.
62
+ # @param level [Symbol, String, Integer]Returns all log entries of log level level.
63
+ # @param start Returns all log entries such that their log entry identifier (lid value) is greater or equal to start.
64
+ # @param size [Integer] Restricts the result to at most size log entries.
65
+ # @param offset [Integer] Starts to return log entries skipping the first offset log entries. offset and size can be used for pagination.
66
+ # @param search [String] Only return the log entries containing the text specified in search.
67
+ # @param sort [Symbol, String] Sort the log entries either ascending (if sort is :asc) or descending (if sort is :desc) according to their lid values.
68
+ # @return [Arango::Result]
69
+ def log(upto: nil, level: nil, start: nil, size: nil, offset: nil, search: nil, sort: nil)
70
+ sort = sort.to_s if sort
71
+ satisfy_category?(sort, [nil, "asc", "desc"])
72
+ query = { start: start, size: size, offset: offset, search: search, sort: sort }
73
+ if upto
74
+ upto = upto.to_s
75
+ satisfy_category?(upto, [nil, "fatal", 0, "error", 1, "warning", 2, "info", 3, "debug", 4])
76
+ query[:upto] = upto
77
+ elsif level
78
+ level = level.to_s
79
+ satisfy_category?(level, [nil, "fatal", 0, "error", 1, "warning", 2, "info", 3, "debug", 4])
80
+ query[:level] = level
81
+ end
82
+ request(get: "_admin/log", query: query)
83
+ end
84
+
85
+ # Returns the current log level settings
86
+ # @return [Arango::Result]
87
+ def log_level
88
+ request(get: "_admin/log/level")
89
+ end
90
+
91
+ # Modifies the current log level settings
92
+ # @param log_level_object [Arango::Result, Hash] Must contain all keys as obtained by log_level. Best is to get the object by calling log_level,
93
+ # modifying it, and passing it here.
94
+ # @return Arango::Result
95
+ def log_level=(log_level_object)
96
+ body = if log_level_object.class == Arango::Result
97
+ log_level_object.to_h
98
+ else
99
+ log_level_object
100
+ end
101
+ request(put: "_admin/log/level", body: body)
102
+ end
103
+
104
+ # Return mode information about a server.
105
+ # @return [Symbol] one of :default or :readonly
106
+ def mode
107
+ request(get: "_admin/server/mode").mode.to_sym
108
+ end
109
+
110
+ # Set server mode.
111
+ # @param mode [String, Symbol] one of :default or :readonly
112
+ # @return [Symbol] one of :default or :readonly
113
+ def mode=(mode)
114
+ satisfy_category?(mode, ["default", "readonly", :default, :readonly])
115
+ body = { mode: mode.to_s }
116
+ request(put: "_admin/server/mode", body: body).mode
117
+ end
118
+
119
+ # Check if server is read only.
120
+ # @return [Boolean]
121
+ def read_only?
122
+ :readonly == mode
123
+ end
124
+
125
+ # Reloads the routing information from the collection routing.
126
+ # @return true
127
+ def reload_routing
128
+ request(get: "_admin/routing/reload")
129
+ true
130
+ end
131
+
132
+ # Returns the role of a server in a cluster.
133
+ # SINGLE: the server is a standalone server without clustering
134
+ # COORDINATOR: the server is a Coordinator in a cluster
135
+ # PRIMARY: the server is a DBServer in a cluster
136
+ # SECONDARY: this role is not used anymore
137
+ # AGENT: the server is an Agency node in a cluster
138
+ # UNDEFINED: in a cluster, UNDEFINED is returned if the server role cannot be
139
+ # determined.
140
+ # @return [String]
141
+ def role
142
+ @role ||= request(get: '_admin/server/role').role
143
+ end
144
+
145
+ # Check if server role is AGENT.
146
+ # @return [Boolean]
147
+ def agent?
148
+ role == 'AGENT'
149
+ end
150
+
151
+ # Check if server role is COORDINATOR.
152
+ # @return [Boolean]
153
+ def coordinator?
154
+ role == 'COORDINATOR'
155
+ end
156
+
157
+ # Check if server role is PRIMARY.
158
+ # @return [Boolean]
159
+ def primary?
160
+ role == 'PRIMARY'
161
+ end
162
+
163
+ # Check if server role is SECONDARY.
164
+ # @return [Boolean]
165
+ def secondary?
166
+ role == 'SECONDARY'
167
+ end
168
+
169
+ # Check if server role is SINGLE.
170
+ # @return [Boolean]
171
+ def single?
172
+ role == 'SINGLE'
173
+ end
174
+
175
+ # Check if server is part of a cluster.
176
+ # @return [Boolean]
177
+ def in_cluster?
178
+ coordinator? || primary? || agent? || secondary?
179
+ end
180
+
181
+ # Returns the id of a server in a cluster.
182
+ # @return [Boolean]
183
+ def server_id
184
+ request(get: "_admin/server/id").serverId if in_cluster?
185
+ end
186
+
187
+ # Returns the statistics information.
188
+ # @return [Arango::Result]
189
+ def statistics
190
+ request(get: "_admin/statistics")
191
+ end
192
+
193
+ # Returns a description of the statistics returned by /_admin/statistics.
194
+ # @return [Arango::Result]
195
+ def statistics_description
196
+ request(get: "_admin/statistics-description")
197
+ end
198
+
199
+ # Returns status information about the server.
200
+ # @return [Arango::Result]
201
+ def status
202
+ request(get: "_admin/status")
203
+ end
204
+
205
+ # Check if the server has the enterprise license.
206
+ # @return [Boolean]
207
+ def enterprise?
208
+ @enterprise ||= (status.license == 'enterprise')
209
+ end
210
+
211
+ # The servers current system time as a Unix timestamp with microsecond precision of the server
212
+ # @return [Float]
213
+ def time
214
+ request(get: "_admin/time").time
215
+ end
216
+
217
+ # Return server version details.
218
+ # The response will contain a details attribute with additional information about included components
219
+ # and their versions. The attribute names and internals of the details object may vary depending on platform and ArangoDB version.
220
+ # @return [Arango::Result]
221
+ def detailed_version
222
+ request(get: "_api/version", query: { details: true })
223
+ end
224
+
225
+ # The server version string. The string has the format “major.minor.sub”. major and minor will be numeric, and sub may contain a number or
226
+ # a textual version.
227
+ # @return [String]
228
+ def version
229
+ request(get: "_api/version").version
230
+ end
231
+
232
+ # Returns the database version that this server requires.
233
+ # @return [String]
234
+ def target_version
235
+ request(get: "_admin/database/target-version").version
236
+ end
237
+
238
+ # Flushes the write-ahead log. By flushing the currently active write-ahead
239
+ # logfile, the data in it can be transferred to collection journals and
240
+ # datafiles. This is useful to ensure that all data for a collection is
241
+ # present in the collection journals and datafiles, for example, when dumping
242
+ # the data of a collection.
243
+ # @param wait_for_sync [Boolean] Whether or not the operation should block until the not-yet synchronized data in the write-ahead log was
244
+ # synchronized to disk.
245
+ # @param wait_for_collector [Boolean] Whether or not the operation should block until the data in the flushed log has been collected by the
246
+ # write-ahead log garbage collector. Note that setting this option to true might block for a long time if
247
+ # there are long-running transactions and the write-ahead log garbage collector cannot
248
+ # finish garbage collection.
249
+ def flush_wal(wait_for_sync: nil, wait_for_collector: nil)
250
+ body = {
251
+ waitForSync: wait_for_sync,
252
+ waitForCollector: wait_for_collector
253
+ }
254
+ !!request(put: "_admin/wal/flush", body: body)
255
+ end
256
+
257
+ # Retrieves the configuration of the write-ahead log. Properties:
258
+ # - allow_oversize_entries: whether or not operations that are bigger than a single logfile can be executed and stored
259
+ # - log_file_size: the size of each write-ahead logfile
260
+ # - historic_logfiles: the maximum number of historic logfiles to keep
261
+ # - reserve_logfiles: the maximum number of reserve logfiles that ArangoDB allocates in the background
262
+ # - throttle_wait: the maximum wait time that operations will wait before they get aborted if case of write-throttling (in milliseconds)
263
+ # - throttle_when_pending: the number of unprocessed garbage-collection operations that, when reached, will activate write-throttling.
264
+ # A value of 0 means that write-throttling will not be triggered.
265
+ # return [Arango::Result]
266
+ def wal_properties
267
+ result = request(get: "_admin/wal/properties")
268
+ raise "WAL properties not available." if result.response_code >= 500
269
+ result
270
+ end
271
+
272
+ # Configures the behavior of the write-ahead log.
273
+ # @param properties_object [Arango::Result] Obtain the object with wal_properties, modify and pass here.
274
+ #
275
+ def wal_properties=(properties_object)
276
+ body = {
277
+ allowOversizeEntries: properties_object.allow_oversize_entries,
278
+ logfileSize: properties_object.logfile_size,
279
+ historicLogfiles: properties_object.historic_logfiles,
280
+ reserveLogfiles: properties_object.reserve_logfiles,
281
+ throttleWait: properties_object.throttle_wait,
282
+ throttleWhenPending: properties_object.throttle_when_pending
283
+ }
284
+ result = request(put: "_admin/wal/properties", body: body)
285
+ raise "WAL properties not available." if result.response_code >= 500
286
+ result
287
+ end
288
+
289
+ # Shutdown the server.
290
+ # @return [Boolean] True if request was successful.
291
+ def shutdown
292
+ 200 == request(delete: "_admin/shutdown").response_code
293
+ end
294
+ end
295
+ end
296
+ end