rhoconnect 3.2.1 → 3.3.1.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. data/CHANGELOG.md +24 -5
  2. data/Gemfile +2 -2
  3. data/Gemfile.lock +20 -20
  4. data/bench/benchapp/Gemfile +17 -20
  5. data/bench/benchapp/config.ru +2 -2
  6. data/bench/benchapp/settings/settings.yml +3 -3
  7. data/bench/blobapp/Gemfile +16 -13
  8. data/bench/blobapp/config.ru +2 -2
  9. data/bench/blobapp/settings/settings.yml +5 -3
  10. data/bench/lib/bench.rb +35 -32
  11. data/bench/lib/bench/session.rb +9 -1
  12. data/bench/scripts/blob_cud_script.rb +13 -17
  13. data/bench/scripts/cud_script.rb +11 -12
  14. data/bench/scripts/helpers.rb +5 -7
  15. data/bench/scripts/query_md_script.rb +18 -12
  16. data/bench/scripts/query_only_script.rb +19 -11
  17. data/bench/scripts/query_script.rb +17 -13
  18. data/bench/scripts/test_query_script.rb +46 -17
  19. data/bench/scripts/test_source_script.rb +7 -7
  20. data/commands/commands/dtach_commands/dtach_install.rb +44 -16
  21. data/commands/commands/rhoconnect/spec.rb +13 -9
  22. data/commands/commands/rhoconnect/version.rb +6 -0
  23. data/commands/execute.rb +10 -6
  24. data/doc/deploying.txt +75 -13
  25. data/doc/install.txt +3 -3
  26. data/doc/push-client-setup.txt +1 -1
  27. data/doc/rest-api.txt +4 -23
  28. data/doc/rhoconnect-redis-stack.txt +26 -7
  29. data/doc/settings.txt +9 -3
  30. data/examples/simple/Gemfile +3 -1
  31. data/examples/simple/application.rb +5 -0
  32. data/examples/simple/config.ru +3 -2
  33. data/examples/simple/my_server.rb +14 -0
  34. data/examples/simple/settings/settings.yml +1 -0
  35. data/generators/templates/application/Gemfile +4 -4
  36. data/generators/templates/application/application.rb +4 -0
  37. data/generators/templates/application/settings/settings.yml +4 -1
  38. data/installer/unix-like/create_texts.rb +39 -1
  39. data/installer/unix-like/rho_connect_install_constants.rb +1 -1
  40. data/installer/utils/package_upload/repos.rake +7 -5
  41. data/lib/rhoconnect.rb +3 -2
  42. data/lib/rhoconnect/api/app/ans_login.rb +3 -0
  43. data/lib/rhoconnect/api/app/bulk_data.rb +6 -0
  44. data/lib/rhoconnect/api/{source → app}/fast_delete.rb +1 -1
  45. data/lib/rhoconnect/api/{source → app}/fast_insert.rb +2 -2
  46. data/lib/rhoconnect/api/{source → app}/fast_update.rb +2 -2
  47. data/lib/rhoconnect/api/app/login.rb +5 -0
  48. data/lib/rhoconnect/api/{source → app}/push_deletes.rb +1 -1
  49. data/lib/rhoconnect/api/{source → app}/push_objects.rb +1 -1
  50. data/lib/rhoconnect/api/app/query.rb +4 -0
  51. data/lib/rhoconnect/api/app/queue_updates.rb +94 -0
  52. data/lib/rhoconnect/api/app/search.rb +4 -0
  53. data/lib/rhoconnect/api/client/client_get_db_doc.rb +5 -0
  54. data/lib/rhoconnect/api/client/client_set_db_doc.rb +8 -0
  55. data/lib/rhoconnect/api/client/create.rb +7 -0
  56. data/lib/rhoconnect/api/client/get_client_params.rb +2 -1
  57. data/lib/rhoconnect/api/client/list_client_docs.rb +2 -1
  58. data/lib/rhoconnect/api/client/register.rb +12 -0
  59. data/lib/rhoconnect/api/client/reset.rb +5 -0
  60. data/lib/rhoconnect/api/{source → readstate}/set_refresh_time.rb +2 -1
  61. data/lib/rhoconnect/api/source/get_source_params.rb +3 -2
  62. data/lib/rhoconnect/api/source/list_sources.rb +2 -1
  63. data/lib/rhoconnect/api/source/update_source_params.rb +3 -3
  64. data/lib/rhoconnect/api/store/get_db_doc.rb +4 -0
  65. data/lib/rhoconnect/api/store/set_db_doc.rb +7 -0
  66. data/lib/rhoconnect/api/system/get_adapter.rb +4 -0
  67. data/lib/rhoconnect/api/{admin → system}/get_license_info.rb +2 -1
  68. data/lib/rhoconnect/api/system/login.rb +15 -0
  69. data/lib/rhoconnect/api/{admin → system}/reset.rb +3 -2
  70. data/lib/rhoconnect/api/system/save_adapter.rb +4 -0
  71. data/lib/rhoconnect/api/{admin → system}/stats.rb +2 -1
  72. data/lib/rhoconnect/api/user/create_user.rb +2 -2
  73. data/lib/rhoconnect/api/user/delete_client.rb +6 -0
  74. data/lib/rhoconnect/api/user/delete_user.rb +2 -1
  75. data/lib/rhoconnect/api/user/list_clients.rb +4 -0
  76. data/lib/rhoconnect/api/user/list_source_docs.rb +11 -0
  77. data/lib/rhoconnect/api/user/list_users.rb +1 -1
  78. data/lib/rhoconnect/api/user/ping.rb +7 -0
  79. data/lib/rhoconnect/api/user/show_user.rb +3 -0
  80. data/lib/rhoconnect/api/user/update_user.rb +3 -2
  81. data/lib/rhoconnect/api/user/user_get_db_doc.rb +5 -0
  82. data/lib/rhoconnect/api/user/user_set_db_doc.rb +10 -0
  83. data/lib/rhoconnect/app.rb +12 -2
  84. data/lib/rhoconnect/async.rb +6 -10
  85. data/lib/rhoconnect/bulk_data/bulk_data.rb +4 -4
  86. data/lib/rhoconnect/client.rb +10 -9
  87. data/lib/rhoconnect/client_sync.rb +24 -19
  88. data/lib/rhoconnect/document.rb +18 -4
  89. data/lib/rhoconnect/graph_helper.rb +4 -2
  90. data/lib/rhoconnect/jobs/bulk_data_job.rb +1 -1
  91. data/lib/rhoconnect/jobs/ping_job.rb +39 -29
  92. data/lib/rhoconnect/middleware/admin_user.rb +23 -0
  93. data/lib/rhoconnect/middleware/body_content_type_parser.rb +35 -0
  94. data/lib/rhoconnect/{cors.rb → middleware/cors.rb} +1 -0
  95. data/lib/rhoconnect/middleware/current_app.rb +16 -0
  96. data/lib/rhoconnect/middleware/current_request.rb +16 -0
  97. data/lib/rhoconnect/middleware/current_user.rb +17 -0
  98. data/lib/rhoconnect/middleware/helpers.rb +105 -0
  99. data/lib/rhoconnect/middleware/login_required.rb +22 -0
  100. data/lib/rhoconnect/{stats/middleware.rb → middleware/stats.rb} +5 -3
  101. data/lib/rhoconnect/middleware/x_domain_session_wrapper.rb +58 -0
  102. data/lib/rhoconnect/ping.rb +1 -0
  103. data/lib/rhoconnect/ping/apple.rb +18 -16
  104. data/lib/rhoconnect/ping/blackberry.rb +9 -9
  105. data/lib/rhoconnect/ping/rhoconnect_push.rb +45 -0
  106. data/lib/rhoconnect/server.rb +98 -91
  107. data/lib/rhoconnect/source.rb +5 -1
  108. data/lib/rhoconnect/source_sync.rb +4 -3
  109. data/lib/rhoconnect/stats/record.rb +15 -15
  110. data/lib/rhoconnect/store.rb +253 -75
  111. data/lib/rhoconnect/tasks.rb +3 -3
  112. data/lib/rhoconnect/version.rb +1 -1
  113. data/lib/rhoconnect/web-console/controllers/admins.js +1 -14
  114. data/lib/rhoconnect/web-console/models/adapter.js +18 -8
  115. data/lib/rhoconnect/web-console/models/client.js +15 -9
  116. data/lib/rhoconnect/web-console/models/doc.js +7 -11
  117. data/lib/rhoconnect/web-console/models/session.js +5 -2
  118. data/lib/rhoconnect/web-console/models/source.js +55 -36
  119. data/lib/rhoconnect/web-console/models/user.js +20 -11
  120. data/lib/rhoconnect/web-console/public/backbone.js +8 -2
  121. data/lib/rhoconnect/web-console/templates/index.erb +11 -5
  122. data/lib/rhoconnect/web-console/views/doc.js +6 -8
  123. data/lib/rhoconnect/web-console/views/edit_user.js +6 -3
  124. data/lib/rhoconnect/web-console/views/home.js +98 -25
  125. data/lib/rhoconnect/web-console/views/index.js +1 -1
  126. data/lib/rhoconnect/web-console/views/new_ping.js +6 -3
  127. data/lib/rhoconnect/web-console/views/server_doc.js +12 -4
  128. data/lib/rhoconnect/web-console/views/show_device.js +6 -3
  129. data/rhoconnect.gemspec +1 -2
  130. data/spec/api/{source → app}/fast_delete_spec.rb +4 -4
  131. data/spec/api/{source → app}/fast_insert_spec.rb +4 -4
  132. data/spec/api/{source → app}/fast_update_spec.rb +22 -6
  133. data/spec/api/{source → app}/push_deletes_spec.rb +2 -2
  134. data/spec/api/app/push_objects_spec.rb +45 -0
  135. data/spec/api/client/client_get_db_doc_spec.rb +31 -0
  136. data/spec/api/client/client_set_db_doc_spec.rb +14 -0
  137. data/spec/api/client/get_client_params_spec.rb +3 -2
  138. data/spec/api/client/list_client_docs_spec.rb +2 -2
  139. data/spec/api/{source → readstate}/set_refresh_time_spec.rb +15 -9
  140. data/spec/api/source/get_source_params_spec.rb +3 -2
  141. data/spec/api/source/list_sources_spec.rb +3 -9
  142. data/spec/api/source/update_source_params_spec.rb +4 -4
  143. data/spec/api/store/get_db_doc_spec.rb +32 -0
  144. data/spec/api/store/set_db_doc_spec.rb +43 -0
  145. data/spec/api/system/adapter_spec.rb +33 -0
  146. data/spec/api/{admin → system}/get_license_info_spec.rb +2 -5
  147. data/spec/api/{admin/get_api_token_spec.rb → system/login_spec.rb} +4 -11
  148. data/spec/api/{admin → system}/reset_spec.rb +2 -2
  149. data/spec/api/{admin → system}/stats_spec.rb +19 -13
  150. data/spec/api/user/create_user_spec.rb +15 -8
  151. data/spec/api/{client → user}/delete_client_spec.rb +3 -4
  152. data/spec/api/user/delete_user_spec.rb +33 -4
  153. data/spec/api/user/list_clients_spec.rb +30 -0
  154. data/spec/api/user/list_source_docs_spec.rb +35 -0
  155. data/spec/api/user/list_users_spec.rb +5 -6
  156. data/spec/api/{client → user}/ping_spec.rb +4 -6
  157. data/spec/api/user/show_user_spec.rb +14 -0
  158. data/spec/api/user/update_user_spec.rb +28 -10
  159. data/spec/api/user/user_get_db_doc_spec.rb +16 -0
  160. data/spec/api/user/user_set_db_doc_spec.rb +41 -0
  161. data/spec/apps/rhotestapp/application.rb +4 -0
  162. data/spec/apps/rhotestapp/settings/settings.yml +3 -1
  163. data/spec/bulk_data/bulk_data_spec.rb +13 -0
  164. data/spec/client_sync_spec.rb +41 -59
  165. data/spec/document_spec.rb +23 -0
  166. data/spec/javascripts/doc_view_spec.js +1 -1
  167. data/spec/javascripts/home_view_spec.js +10 -5
  168. data/spec/javascripts/index_view_spec.js +1 -1
  169. data/spec/jobs/ping_job_spec.rb +26 -0
  170. data/spec/perf/store_perf_spec.rb +1 -1
  171. data/spec/ping/android_spec.rb +0 -7
  172. data/spec/ping/apple_spec.rb +7 -0
  173. data/spec/ping/blackberry_spec.rb +10 -0
  174. data/spec/ping/rhoconnect_push_spec.rb +58 -0
  175. data/spec/server/cors_spec.rb +1 -1
  176. data/spec/server/server_spec.rb +152 -104
  177. data/spec/{stats/middleware_spec.rb → server/stats_spec.rb} +4 -5
  178. data/spec/server/x_domain_session_wrapper_spec.rb +3 -3
  179. data/spec/source_spec.rb +2 -2
  180. data/spec/source_sync_spec.rb +2 -0
  181. data/spec/spec_helper.rb +17 -3
  182. data/spec/stats/record_spec.rb +18 -19
  183. data/spec/store_spec.rb +51 -26
  184. data/spec/support/shared_examples.rb +4 -0
  185. data/spec/sync_states_spec.rb +2 -2
  186. metadata +104 -88
  187. data/bench/benchapp/Gemfile.lock +0 -87
  188. data/bench/blobapp/Gemfile.lock +0 -107
  189. data/bench/lib/testdata/5-data.txt +0 -8
  190. data/doc/release.txt +0 -41
  191. data/lib/rhoconnect/api/admin/get_api_token.rb +0 -14
  192. data/lib/rhoconnect/api/admin/login.rb +0 -6
  193. data/lib/rhoconnect/api/application/bulk_data.rb +0 -7
  194. data/lib/rhoconnect/api/application/clientcreate.rb +0 -8
  195. data/lib/rhoconnect/api/application/clientlogin.rb +0 -6
  196. data/lib/rhoconnect/api/application/clientregister.rb +0 -13
  197. data/lib/rhoconnect/api/application/clientreset.rb +0 -6
  198. data/lib/rhoconnect/api/application/query.rb +0 -7
  199. data/lib/rhoconnect/api/application/queue_updates.rb +0 -20
  200. data/lib/rhoconnect/api/application/search.rb +0 -6
  201. data/lib/rhoconnect/api/client/create_client.rb +0 -3
  202. data/lib/rhoconnect/api/client/delete_client.rb +0 -5
  203. data/lib/rhoconnect/api/client/list_clients.rb +0 -3
  204. data/lib/rhoconnect/api/client/ping.rb +0 -7
  205. data/lib/rhoconnect/api/source/get_adapter.rb +0 -3
  206. data/lib/rhoconnect/api/source/get_db_doc.rb +0 -7
  207. data/lib/rhoconnect/api/source/list_source_docs.rb +0 -10
  208. data/lib/rhoconnect/api/source/save_adapter.rb +0 -3
  209. data/lib/rhoconnect/api/source/set_db_doc.rb +0 -10
  210. data/lib/rhoconnect/api/source/upload_file.rb +0 -4
  211. data/lib/rhoconnect/body_content_type_parser.rb +0 -32
  212. data/lib/rhoconnect/x_domain_session_wrapper.rb +0 -53
  213. data/spec/api/admin/api_token_spec.rb +0 -13
  214. data/spec/api/client/create_client_spec.rb +0 -13
  215. data/spec/api/client/list_clients_spec.rb +0 -22
  216. data/spec/api/source/adapter_spec.rb +0 -29
  217. data/spec/api/source/get_db_doc_spec.rb +0 -21
  218. data/spec/api/source/list_source_docs_spec.rb +0 -25
  219. data/spec/api/source/push_objects_spec.rb +0 -27
  220. data/spec/api/source/set_db_doc_spec.rb +0 -32
  221. data/spec/api/source/upload_file_spec.rb +0 -26
@@ -1,3 +1,5 @@
1
+ require 'digest/sha1'
2
+
1
3
  module Rhoconnect
2
4
 
3
5
  class StoreLockException < RuntimeError; end
@@ -18,6 +20,41 @@ module Rhoconnect
18
20
  raise "Error connecting to Redis store." unless @@db and
19
21
  (@@db.is_a?(Redis) or @@db.is_a?(Redis::Client))
20
22
  end
23
+
24
+ def start_transaction
25
+ @@db.multi
26
+ end
27
+
28
+ def execute_transaction
29
+ @@db.exec
30
+ end
31
+
32
+ def doc_type(dockey)
33
+ @@db.type(dockey) if dockey
34
+ end
35
+
36
+ def set_db_doc(dockey, data, append=false)
37
+ if data.is_a?(String)
38
+ put_value(dockey, data)
39
+ else
40
+ put_data(dockey, data, append)
41
+ end
42
+ end
43
+
44
+ def get_db_doc(dockey)
45
+ doctype = Store.doc_type(dockey)
46
+ if doctype == 'string'
47
+ Store.get_value(dockey)
48
+ elsif doctype == 'list'
49
+ Store.get_data(dockey, Array).to_json
50
+ else
51
+ Store.get_data(dockey).to_json
52
+ end
53
+ end
54
+
55
+ def put_object(dockey, key, data={})
56
+ _put_object(dockey, key, data)
57
+ end
21
58
 
22
59
  # Adds set with given data, replaces existing set
23
60
  # if it exists or appends data to the existing set
@@ -26,22 +63,26 @@ module Rhoconnect
26
63
  if dockey and data
27
64
  flash_data(dockey) unless append
28
65
  # Inserts a hash or array
29
- if data.is_a?(Hash)
66
+ if data.is_a?Hash
30
67
  @@db.pipelined do
31
68
  data.each do |key,value|
32
- raise ArgumentError, "Invalid value object: #{value.inspect}. Hash is expected." unless value.is_a?(Hash)
33
- value.each do |attrib,value|
34
- unless _is_reserved?(attrib,value)
35
- @@db.sadd(dockey,setelement(key,attrib,value))
36
- end
37
- end
69
+ raise ArgumentError, "Invalid value object: #{value.inspect}. Hash is expected." unless value.is_a?(Hash)
70
+ _put_object(dockey, key, value)
38
71
  end
39
72
  end
40
73
  else
41
- @@db.pipelined do
42
- data.each do |value|
43
- @@db.sadd(dockey,value)
44
- end
74
+ put_list(dockey,data,append)
75
+ end
76
+ end
77
+ true
78
+ end
79
+
80
+ def put_list(dockey, data=[], append=false)
81
+ if dockey and data
82
+ flash_data(dockey) unless append
83
+ @@db.pipelined do
84
+ data.each do |value|
85
+ @@db.rpush(dockey, value)
45
86
  end
46
87
  end
47
88
  end
@@ -54,24 +95,25 @@ module Rhoconnect
54
95
  return 0 unless dockey and data
55
96
 
56
97
  new_object_count = 0
57
- doc = get_data(dockey)
98
+ objs = get_objects(dockey, data.keys)
58
99
  @@db.pipelined do
59
100
  data.each do |key,value|
60
- is_create = doc[key].nil?
101
+ is_create = objs[key].nil?
61
102
  new_object_count += 1 if is_create
103
+ obj_bucket = _add_bucket_index(dockey, "#{_create_obj_index(key)}")
62
104
  value.each do |attrib,value|
63
105
  next if _is_reserved?(attrib, value)
64
106
 
65
107
  new_element = setelement(key,attrib,value)
66
- element_exists = is_create ? false : doc[key].has_key?(attrib)
108
+ element_exists = is_create ? false : objs[key].has_key?(attrib)
67
109
  if element_exists
68
- existing_element = setelement(key,attrib,doc[key][attrib])
110
+ existing_element = setelement(key,attrib,objs[key][attrib])
69
111
  if existing_element != new_element
70
- @@db.srem(dockey, existing_element)
71
- @@db.sadd(dockey, new_element)
112
+ @@db.srem(obj_bucket, existing_element)
113
+ @@db.sadd(obj_bucket, new_element)
72
114
  end
73
115
  else
74
- @@db.sadd(dockey, new_element)
116
+ @@db.sadd(obj_bucket, new_element)
75
117
  end
76
118
  end
77
119
  end
@@ -84,20 +126,30 @@ module Rhoconnect
84
126
  return 0 unless dockey and data
85
127
 
86
128
  deleted_object_count = 0
87
- doc = get_data(dockey)
129
+ objs = get_objects(dockey, data)
88
130
  @@db.pipelined do
89
131
  data.each do |id|
90
- if doc[id]
91
- doc[id].each do |name,value|
92
- @@db.srem(dockey, setelement(id,name,value))
93
- end
132
+ if _delete_object(dockey, id, objs[id])
94
133
  deleted_object_count += 1
95
134
  end
96
- doc.delete(id)
97
135
  end
98
136
  end
137
+ _cleanup_buckets(dockey, objs.keys)
99
138
  deleted_object_count
100
139
  end
140
+
141
+ # Deletes data from a given doctype,source,user
142
+ def delete_data(dockey,data={})
143
+ if dockey and data
144
+ @@db.pipelined do
145
+ data.each do |key,value|
146
+ _delete_object(dockey, key, value)
147
+ end
148
+ end
149
+ _cleanup_buckets(dockey, data.keys)
150
+ end
151
+ true
152
+ end
101
153
 
102
154
  # Adds a simple key/value pair
103
155
  def put_value(dockey,value)
@@ -122,33 +174,68 @@ module Rhoconnect
122
174
  def decr(dockey)
123
175
  @@db.decr(dockey)
124
176
  end
177
+
178
+ def update_count(dockey, count)
179
+ Store.db.incrby(dockey, count)
180
+ end
181
+
182
+ def get_object(dockey, key)
183
+ _get_object(dockey, key)
184
+ end
185
+
186
+ def get_objects(dockey, keys)
187
+ res = {}
188
+ keys.each do |key|
189
+ res[key] = _get_object(dockey, key)
190
+ end if keys
191
+ res
192
+ end
125
193
 
126
194
  # Retrieves set for given dockey,source,user
127
195
  def get_data(dockey,type=Hash)
128
196
  res = type == Hash ? {} : []
129
197
  if dockey
130
- members = @@db.smembers(dockey)
131
- members.each do |element|
132
- if type == Hash
133
- key,attrib,value = getelement(element)
134
- res[key] = {} unless res[key]
135
- res[key].merge!({attrib => value})
136
- else
137
- res << element
138
- end
139
- end if members
140
- res
198
+ if type == Hash
199
+ buckets = _get_buckets(dockey)
200
+ buckets.each do |bucket|
201
+ members = @@db.smembers(bucket)
202
+ members.each do |element|
203
+ key,attrib,value = getelement(element)
204
+ res[key] = {} unless res[key]
205
+ res[key].merge!({attrib => value})
206
+ end if members
207
+ end if buckets
208
+ else
209
+ res = get_list(dockey)
210
+ end
141
211
  end
212
+ res
213
+ end
214
+
215
+ def get_list(dockey)
216
+ res = []
217
+ if dockey
218
+ res = @@db.lrange(dockey, 0, -1)
219
+ end
220
+ res
142
221
  end
143
222
 
144
223
  # Retrieves diff data hash between two sets
145
224
  def get_diff_data(src_dockey,dst_dockey,p_size=nil)
146
225
  res = {}
147
226
  if src_dockey and dst_dockey
148
- @@db.sdiff(dst_dockey,src_dockey).each do |element|
149
- key,attrib,value = getelement(element)
150
- res[key] = {} unless res[key]
151
- res[key].merge!({attrib => value})
227
+ # obtain combined indices
228
+ indices = @@db.hgetall("#{dst_dockey}:indices")
229
+ indices.merge!(@@db.hgetall("#{dst_dockey}:indices"))
230
+ indices.keys.each do |index|
231
+ dst_bucket_name = "#{dst_dockey}:#{index}"
232
+ src_bucket_name = "#{src_dockey}:#{index}"
233
+ @@db.sdiff(dst_bucket_name,src_bucket_name).each do |element|
234
+ key,attrib,value = getelement(element)
235
+ res[key] = {} unless res[key]
236
+ res[key].merge!({attrib => value})
237
+ end
238
+ break if p_size and (res.size >= p_size)
152
239
  end
153
240
  end
154
241
  if p_size
@@ -159,56 +246,28 @@ module Rhoconnect
159
246
  page_size -= 1
160
247
  break if page_size <= 0
161
248
  end
162
- [diff,res.size]
249
+ diff
163
250
  else
164
- [res,res.size]
251
+ res
165
252
  end
166
253
  end
167
254
 
168
- # Deletes data from a given doctype,source,user
169
- def delete_data(dockey,data={})
170
- if dockey and data
171
- @@db.pipelined do
172
- data.each do |key,value|
173
- value.each do |attrib,val|
174
- @@db.srem(dockey,setelement(key,attrib,val))
175
- end
176
- end
177
- end
178
- end
179
- true
180
- end
181
-
182
255
  # Deletes all keys matching a given mask
183
256
  def flash_data(keymask)
184
- if keymask[/[*\[\]?]/]
257
+ if keymask.to_s[/[*\[\]?]/]
185
258
  # If the keymask contains any pattern matching characters
186
259
  # Use keys command to find all keys matching pattern (this is extremely expensive)
187
260
  # Then delete matches
188
261
  @@db.keys(keymask).each do |key|
189
- @@db.del(key)
262
+ _delete_doc(key)
190
263
  end
191
264
  else
192
265
  # The keymask doesn't contain pattern matching characters
193
266
  # A delete call is all that is needed
194
- @@db.del(keymask)
267
+ _delete_doc(keymask)
195
268
  end
196
269
  end
197
270
 
198
- def exists?(key)
199
- @@db.exists(key)
200
- end
201
-
202
- # Returns array of keys matching a given keymask
203
- def get_keys(keymask)
204
- @@db.keys(keymask)
205
- end
206
-
207
- # Returns true if given item is a member of the given set
208
- def ismember?(setkey,item)
209
- @@db.sismember(setkey,item)
210
- end
211
-
212
271
  # Lock a given key and release when provided block is finished
213
272
  def lock(dockey,timeout=0,raise_on_expire=false)
214
273
  m_lock = get_lock(dockey,timeout,raise_on_expire)
@@ -269,12 +328,33 @@ module Rhoconnect
269
328
 
270
329
  # Create a copy of srckey in dstkey
271
330
  def clone(srckey,dstkey)
272
- @@db.sdiffstore(dstkey,srckey,'')
331
+ buckets = _get_bucket_indices(srckey)
332
+ if buckets.size
333
+ @@db.pipelined do
334
+ buckets.each do |bucket_index|
335
+ _add_bucket_index(dstkey, bucket_index)
336
+ @@db.sdiffstore("#{dstkey}:#{bucket_index}", "#{srckey}:#{bucket_index}", '')
337
+ end
338
+ end
339
+ else
340
+ @@db.sdiffstore(dstkey,srckey,'')
341
+ end
273
342
  end
274
343
 
275
344
  # Rename srckey to dstkey
276
345
  def rename(srckey,dstkey)
277
- @@db.rename(srckey,dstkey) if @@db.exists(srckey)
346
+ buckets = _get_bucket_indices(srckey)
347
+ if buckets.size
348
+ @@db.pipelined do
349
+ @@db.del("#{srckey}:indices")
350
+ buckets.each do |bucket_index|
351
+ _add_bucket_index(dstkey, bucket_index)
352
+ @@db.rename("#{srckey}:#{bucket_index}", "#{dstkey}:#{bucket_index}")
353
+ end
354
+ end
355
+ else
356
+ @@db.rename(srckey,dstkey) if @@db.exists(srckey)
357
+ end
278
358
  end
279
359
 
280
360
  def put_zdata(dockey,assoc_key,data={},append=false)
@@ -327,6 +407,10 @@ module Rhoconnect
327
407
  Store.db.zremrangebyrank(dockey, 0, -1)
328
408
  end
329
409
 
410
+ def exists?(key)
411
+ @@db.exists(key) || @@db.exists("#{key}:indices")
412
+ end
413
+
330
414
  alias_method :set_value, :put_value
331
415
  alias_method :set_data, :put_data
332
416
 
@@ -353,6 +437,100 @@ module Rhoconnect
353
437
  def _is_reserved?(attrib,value) #:nodoc:
354
438
  RESERVED_ATTRIB_NAMES.include? attrib
355
439
  end
440
+
441
+ # operations with docs that are split into buckets
442
+ def _delete_doc(dockey)
443
+ # check if this doc has buckets
444
+ if(@@db.exists("#{dockey}:indices"))
445
+ buckets_list = _get_buckets(dockey)
446
+ # delete all buckets
447
+ @@db.pipelined do
448
+ @@db.del("#{dockey}:indices")
449
+ buckets_list.each do |bucket|
450
+ @@db.del(bucket)
451
+ end
452
+ end
453
+ end
454
+
455
+ # delete main doc
456
+ @@db.del(dockey)
457
+ end
458
+
459
+ # create object's bucket index
460
+ # using SHA1 hashing
461
+ def _create_obj_index(key)
462
+ Digest::SHA1.hexdigest(key)[0..1]
463
+ end
464
+
465
+ def _add_bucket_index(dockey, bucket_index)
466
+ bucket_name = "#{dockey}:#{bucket_index}"
467
+ @@db.hsetnx("#{dockey}:indices", bucket_index, bucket_name)
468
+ bucket_name
469
+ end
470
+
471
+ def _remove_bucket_index(dockey, bucket_index)
472
+ @@db.hdel("#{dockey}:indices", bucket_index)
473
+ end
474
+
475
+ def _get_bucket_indices(dockey)
476
+ @@db.hkeys("#{dockey}:indices")
477
+ end
478
+
479
+ def _get_buckets(dockey)
480
+ @@db.hvals("#{dockey}:indices")
481
+ end
482
+
483
+ def _cleanup_buckets(dockey, keys)
484
+ keys.each do |key|
485
+ obj_index = _create_obj_index(key)
486
+ bucket_name = "#{dockey}:#{obj_index}"
487
+ _remove_bucket_index(dockey, obj_index) unless @@db.exists(bucket_name)
488
+ end if keys
489
+ end
490
+
491
+ def _put_object(dockey, key, obj={})
492
+ return if obj.empty? or not dockey or not key
493
+
494
+ obj_bucket_index = _create_obj_index(key)
495
+ bucket_name = "#{dockey}:#{obj_bucket_index}"
496
+ _add_bucket_index(dockey, obj_bucket_index)
497
+ @@db.pipelined do
498
+ obj.each do |attrib, value|
499
+ unless _is_reserved?(attrib,value)
500
+ @@db.sadd(bucket_name,setelement(key,attrib,value))
501
+ end
502
+ end
503
+ end
504
+ end
505
+
506
+ def _delete_object(dockey, key, obj)
507
+ return false if not key or not dockey or not obj
508
+
509
+ obj_bucket_index = _create_obj_index(key)
510
+ bucket_name = "#{dockey}:#{obj_bucket_index}"
511
+ @@db.pipelined do
512
+ obj.each do |attrib,value|
513
+ @@db.srem(bucket_name, setelement(key,attrib,value))
514
+ end
515
+ end
516
+ true
517
+ end
518
+
519
+ def _get_object(dockey, key)
520
+ return nil unless dockey
521
+ res = nil
522
+ obj_bucket_index = _create_obj_index(key)
523
+ bucket_name = "#{dockey}:#{obj_bucket_index}"
524
+ key_str_size = "#{key}".size
525
+ members = @@db.smembers(bucket_name)
526
+ members.each do |element|
527
+ next unless element[0..key_str_size - 1] == key
528
+ obj_id,attrib,value = getelement(element)
529
+ res ||= {}
530
+ res[attrib] = value
531
+ end if members
532
+ res
533
+ end
356
534
  end
357
535
  end
358
- end
536
+ end
@@ -120,7 +120,8 @@ namespace :rhoconnect do
120
120
  puts "\nNew password can't be empty."
121
121
  elsif new_pass == new_pass_confirm
122
122
  puts ""
123
- RestClient.post("#{$url}/api/user/update_user", {:app_name => $appname, :api_token => $token,
123
+ admin_user = 'rhoadmin'
124
+ RestClient.put("#{$url}/rc/#{Rhoconnect::API_VERSION}/users/#{admin_user}", {:app_name => $appname, :api_token => $token,
124
125
  :attributes => {:new_password => new_pass}})
125
126
  else
126
127
  puts "\nNew password and confirmation must match."
@@ -131,8 +132,7 @@ namespace :rhoconnect do
131
132
  task :reset_refresh => :config do
132
133
  user = ask "user: "
133
134
  source_name = ask "source name: "
134
- RestClient.post("#{$url}/api/source/set_refresh_time", {:api_token => $token,
135
- :user_name => user, :source_name => source_name})
135
+ RestClient.put("#{$url}/rc/#{Rhoconnect::API_VERSION}/readstate/users/#{user}/sources/#{source_name}", {:api_token => $token})
136
136
  end
137
137
 
138
138
  begin