rhoconnect 3.1.2 → 3.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (248) hide show
  1. data/CHANGELOG.md +14 -2
  2. data/CREDITS +151 -10
  3. data/Gemfile +16 -5
  4. data/Gemfile.lock +58 -23
  5. data/Rakefile +70 -50
  6. data/bench/bench_runner.rb +2 -2
  7. data/bench/benchapp/Gemfile +6 -0
  8. data/bench/benchapp/Gemfile.lock +5 -0
  9. data/bench/benchapp/config.ru +2 -0
  10. data/bench/lib/bench/cli.rb +2 -0
  11. data/bench/lib/bench/distr_runner.rb +3 -2
  12. data/bench/lib/bench/runner.rb +1 -1
  13. data/bench/lib/bench.rb +10 -1
  14. data/bench/run_bench.sh +1 -1
  15. data/bench/scripts/test_query_script.rb +2 -1
  16. data/bench/spec/bench_spec_helper.rb +1 -0
  17. data/bin/rhoconnect +9 -27
  18. data/bin/rhoconnect-benchmark +10 -1
  19. data/commands/commands/dtach_commands/dtach_about.rb +6 -0
  20. data/commands/commands/dtach_commands/dtach_install.rb +30 -0
  21. data/commands/commands/redis_commands/redis_about.rb +6 -0
  22. data/commands/commands/redis_commands/redis_attach.rb +6 -0
  23. data/commands/commands/redis_commands/redis_download.rb +33 -0
  24. data/commands/commands/redis_commands/redis_install.rb +26 -0
  25. data/commands/commands/redis_commands/redis_make.rb +9 -0
  26. data/commands/commands/redis_commands/redis_restart.rb +7 -0
  27. data/commands/commands/redis_commands/redis_runner.rb +67 -0
  28. data/commands/commands/redis_commands/redis_start.rb +6 -0
  29. data/commands/commands/redis_commands/redis_startbg.rb +6 -0
  30. data/commands/commands/redis_commands/redis_stop.rb +6 -0
  31. data/commands/commands/rhoconnect/attach.rb +7 -0
  32. data/commands/commands/rhoconnect/clean_start.rb +9 -0
  33. data/commands/commands/rhoconnect/config.rb +15 -0
  34. data/commands/commands/rhoconnect/console.rb +15 -0
  35. data/commands/commands/rhoconnect/console_helper.rb +3 -0
  36. data/commands/commands/rhoconnect/create_user.rb +18 -0
  37. data/commands/commands/rhoconnect/delete_device.rb +9 -0
  38. data/commands/commands/rhoconnect/delete_user.rb +8 -0
  39. data/commands/commands/rhoconnect/flushdb.rb +14 -0
  40. data/commands/commands/rhoconnect/get_token.rb +25 -0
  41. data/commands/commands/rhoconnect/reset.rb +16 -0
  42. data/commands/commands/rhoconnect/reset_refresh.rb +11 -0
  43. data/commands/commands/rhoconnect/restart.rb +7 -0
  44. data/commands/commands/rhoconnect/secret.rb +11 -0
  45. data/commands/commands/rhoconnect/set_admin_password.rb +26 -0
  46. data/commands/commands/rhoconnect/spec.rb +15 -0
  47. data/commands/commands/rhoconnect/start.rb +18 -0
  48. data/commands/commands/rhoconnect/startbg.rb +34 -0
  49. data/commands/commands/rhoconnect/startdebug.rb +35 -0
  50. data/commands/commands/rhoconnect/stop.rb +11 -0
  51. data/commands/commands/rhoconnect/war.rb +32 -0
  52. data/commands/commands/rhoconnect/web.rb +7 -0
  53. data/commands/execute.rb +35 -0
  54. data/commands/generators/app.rb +6 -0
  55. data/commands/generators/source.rb +6 -0
  56. data/commands/utilities/dtach_installed.rb +10 -0
  57. data/doc/benchmarks-running.txt +5 -0
  58. data/doc/command-line.txt +216 -27
  59. data/doc/heroku-addon.txt +1 -1
  60. data/doc/preparing-production.txt +20 -1
  61. data/doc/public/cli.txt +191 -0
  62. data/doc/push-backend-setup.txt +148 -0
  63. data/doc/push-client-setup.txt +61 -0
  64. data/doc/push-server-setup.txt +91 -0
  65. data/doc/push.txt +8 -137
  66. data/doc/rest-api.txt +96 -0
  67. data/doc/settings.txt +1 -1
  68. data/doc/supported-platforms.txt +2 -1
  69. data/doc/tutorial.txt +6 -4
  70. data/examples/simple/Gemfile +39 -0
  71. data/examples/simple/Rakefile +7 -12
  72. data/examples/simple/config.ru +16 -31
  73. data/examples/simple/settings/settings.yml +5 -4
  74. data/examples/simple/sources/product.rb +51 -0
  75. data/generators/templates/application/Gemfile +7 -0
  76. data/generators/templates/application/Rakefile +5 -18
  77. data/generators/templates/application/config.ru +11 -19
  78. data/install.sh +24 -49
  79. data/installer/unix-like/create_texts.rb +71 -123
  80. data/installer/unix-like/post_install.sh +3 -0
  81. data/installer/unix-like/post_uninstall.sh +2 -0
  82. data/installer/unix-like/pre_install.sh +5 -3
  83. data/installer/unix-like/pre_uninstall.sh +14 -6
  84. data/installer/unix-like/rho_connect_install_checkers.rb +1 -1
  85. data/installer/unix-like/rho_connect_install_constants.rb +6 -10
  86. data/installer/unix-like/rho_connect_install_debian.rb +2 -2
  87. data/installer/unix-like/rho_connect_install_dnd.rb +2 -5
  88. data/installer/unix-like/rho_connect_install_installers.rb +15 -23
  89. data/installer/unix-like/rho_connect_install_yum.rb +2 -2
  90. data/installer/utils/constants.rb +4 -4
  91. data/installer/utils/create_sha1.rb +1 -1
  92. data/installer/utils/nix_install_test.rb +32 -31
  93. data/installer/utils/nix_installation.rake +1 -1
  94. data/installer/utils/package_upload/repos.rake +34 -30
  95. data/installer/utils/package_upload/s3_upload.rb +3 -3
  96. data/lib/rhoconnect/api/source/fast_delete.rb +10 -0
  97. data/lib/rhoconnect/api/source/fast_insert.rb +10 -0
  98. data/lib/rhoconnect/api/source/fast_update.rb +10 -0
  99. data/lib/rhoconnect/api/source/get_source_params.rb +1 -1
  100. data/lib/rhoconnect/api/source/list_sources.rb +2 -2
  101. data/lib/rhoconnect/api/source/save_adapter.rb +1 -1
  102. data/lib/rhoconnect/api/source/update_source_params.rb +6 -0
  103. data/lib/rhoconnect/async.rb +82 -0
  104. data/lib/rhoconnect/bulk_data/bulk_data.rb +5 -1
  105. data/lib/rhoconnect/client_sync.rb +18 -3
  106. data/lib/rhoconnect/console/rhoconnect_api.rb +2 -2
  107. data/lib/rhoconnect/console/server.rb +5 -32
  108. data/lib/rhoconnect/console.rb +2 -2
  109. data/lib/rhoconnect/graph_helper.rb +225 -0
  110. data/lib/rhoconnect/jobs/bulk_data_job.rb +24 -2
  111. data/lib/rhoconnect/server.rb +31 -11
  112. data/lib/rhoconnect/source.rb +10 -5
  113. data/lib/rhoconnect/source_sync.rb +32 -2
  114. data/lib/rhoconnect/tasks.rb +19 -108
  115. data/lib/rhoconnect/test_methods.rb +20 -0
  116. data/lib/rhoconnect/utilities.rb +118 -0
  117. data/lib/rhoconnect/version.rb +1 -1
  118. data/lib/rhoconnect/web-console/controllers/admins.js +245 -0
  119. data/lib/rhoconnect/web-console/models/adapter.js +53 -0
  120. data/lib/rhoconnect/web-console/models/client.js +105 -0
  121. data/lib/rhoconnect/web-console/models/doc.js +113 -0
  122. data/lib/rhoconnect/web-console/models/session.js +40 -0
  123. data/lib/rhoconnect/web-console/models/source.js +115 -0
  124. data/lib/rhoconnect/web-console/models/stats.js +84 -0
  125. data/lib/rhoconnect/web-console/models/user.js +111 -0
  126. data/lib/rhoconnect/web-console/public/backbone.js +1432 -0
  127. data/lib/rhoconnect/web-console/public/bootstrap.css +3990 -0
  128. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/excanvas.min.js +0 -0
  129. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jqplot.barRenderer.min.js +0 -0
  130. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jqplot.canvasAxisLabelRenderer.js +0 -0
  131. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jqplot.canvasAxisTickRenderer.js +0 -0
  132. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jqplot.canvasTextRenderer.js +0 -0
  133. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jqplot.categoryAxisRenderer.min.js +0 -0
  134. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jqplot.cursor.js +0 -0
  135. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jqplot.dateAxisRenderer.js +0 -0
  136. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jqplot.dateAxisRenderer.min.js +0 -0
  137. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jqplot.pointLabels.min.js +0 -0
  138. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jquery-1.4.2.min.js +0 -0
  139. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jquery.jqplot.min.css +0 -0
  140. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jquery.jqplot.min.js +0 -0
  141. data/lib/rhoconnect/web-console/public/jquery-1.7.1.min.js +154 -0
  142. data/lib/rhoconnect/web-console/public/rhoconnect-web.js +15 -0
  143. data/lib/rhoconnect/web-console/public/underscore.js +999 -0
  144. data/lib/rhoconnect/web-console/server.rb +55 -0
  145. data/lib/rhoconnect/web-console/templates/index.erb +90 -0
  146. data/lib/rhoconnect/web-console/templates/jqplot.erb +60 -0
  147. data/lib/rhoconnect/web-console/views/api_token.js +16 -0
  148. data/lib/rhoconnect/web-console/views/doc.js +63 -0
  149. data/lib/rhoconnect/web-console/views/edit_user.js +43 -0
  150. data/lib/rhoconnect/web-console/views/home.js +56 -0
  151. data/lib/rhoconnect/web-console/views/index.js +63 -0
  152. data/lib/rhoconnect/web-console/views/new_ping.js +58 -0
  153. data/lib/rhoconnect/web-console/views/new_user.js +29 -0
  154. data/lib/rhoconnect/web-console/views/server_doc.js +103 -0
  155. data/lib/rhoconnect/web-console/views/set_adapter.js +38 -0
  156. data/lib/rhoconnect/web-console/views/settings.js +53 -0
  157. data/lib/rhoconnect/web-console/views/show_device.js +56 -0
  158. data/lib/rhoconnect/web-console/views/show_user.js +38 -0
  159. data/lib/rhoconnect/web-console/views/source_docs.js +30 -0
  160. data/lib/rhoconnect/web-console/views/stats.js +69 -0
  161. data/lib/rhoconnect/web-console/views/users.js +20 -0
  162. data/lib/rhoconnect.rb +2 -1
  163. data/rhoconnect.gemspec +3 -1
  164. data/spec/api/application/rhoconnect_api_spec.rb +3 -5
  165. data/spec/api/source/fast_delete_spec.rb +27 -0
  166. data/spec/api/source/fast_insert_spec.rb +28 -0
  167. data/spec/api/source/fast_update_spec.rb +51 -0
  168. data/spec/api/source/get_source_params_spec.rb +1 -0
  169. data/spec/api/source/update_source_params_spec.rb +24 -0
  170. data/spec/async_spec.rb +19 -0
  171. data/spec/client_sync_spec.rb +19 -2
  172. data/spec/javascripts/PlayerSpec.js +58 -0
  173. data/spec/javascripts/admins_routes_spec.js +117 -0
  174. data/spec/javascripts/admins_spec.js +27 -0
  175. data/spec/javascripts/doc_view_spec.js +37 -0
  176. data/spec/javascripts/edit_user_view_spec.js +44 -0
  177. data/spec/javascripts/helpers/SpecHelper.js +9 -0
  178. data/spec/javascripts/helpers/jasmine-jquery.js +305 -0
  179. data/spec/javascripts/helpers/jasmine-sinon.js +43 -0
  180. data/spec/javascripts/helpers/sinon-1.3.2.js +3551 -0
  181. data/spec/javascripts/home_view_spec.js +39 -0
  182. data/spec/javascripts/index_view_spec.js +42 -0
  183. data/spec/javascripts/new_ping_view_spec.js +48 -0
  184. data/spec/javascripts/new_user_view_spec.js +42 -0
  185. data/spec/javascripts/server_doc_view_spec.js +39 -0
  186. data/spec/javascripts/set_adapter_view_spec.js +32 -0
  187. data/spec/javascripts/show_device_view_spec.js +41 -0
  188. data/spec/javascripts/show_user_view_spec.js +46 -0
  189. data/spec/javascripts/source_docs_view_spec.js +36 -0
  190. data/spec/javascripts/support/jasmine.yml +79 -0
  191. data/spec/javascripts/support/jasmine_config.rb +23 -0
  192. data/spec/javascripts/support/jasmine_runner.rb +32 -0
  193. data/spec/javascripts/users_view_spec.js +35 -0
  194. data/spec/jobs/bulk_data_job_spec.rb +10 -2
  195. data/spec/perf/bulk_data_perf_spec.rb +1 -0
  196. data/spec/server/server_spec.rb +3 -1
  197. data/spec/source_sync_spec.rb +14 -1
  198. data/spec/spec_helper.rb +51 -0
  199. data/spec/store_spec.rb +6 -0
  200. data/spec/test_methods_spec.rb +11 -0
  201. data/tasks/redis.rake +3 -1
  202. metadata +172 -64
  203. data/doc/contributing.txt +0 -60
  204. data/lib/rhoconnect/console/app/helpers/auth_helper.rb +0 -22
  205. data/lib/rhoconnect/console/app/helpers/extensions.rb +0 -19
  206. data/lib/rhoconnect/console/app/helpers/helpers.rb +0 -57
  207. data/lib/rhoconnect/console/app/public/ThickBox.css +0 -649
  208. data/lib/rhoconnect/console/app/public/home.css +0 -431
  209. data/lib/rhoconnect/console/app/public/images/foot_logo_rhoconnect.png +0 -0
  210. data/lib/rhoconnect/console/app/public/images/header_halo.jpg +0 -0
  211. data/lib/rhoconnect/console/app/public/images/land_separator.gif +0 -0
  212. data/lib/rhoconnect/console/app/public/images/landing_header.jpg +0 -0
  213. data/lib/rhoconnect/console/app/public/images/logo_rhoconnect.png +0 -0
  214. data/lib/rhoconnect/console/app/public/images/tabs_separator.png +0 -0
  215. data/lib/rhoconnect/console/app/public/main.css +0 -7
  216. data/lib/rhoconnect/console/app/public/reset.css +0 -76
  217. data/lib/rhoconnect/console/app/public/style.css +0 -2201
  218. data/lib/rhoconnect/console/app/public/text.txt +0 -0
  219. data/lib/rhoconnect/console/app/routes/adapter.rb +0 -28
  220. data/lib/rhoconnect/console/app/routes/auth.rb +0 -29
  221. data/lib/rhoconnect/console/app/routes/client.rb +0 -31
  222. data/lib/rhoconnect/console/app/routes/docs.rb +0 -145
  223. data/lib/rhoconnect/console/app/routes/heroku.rb +0 -19
  224. data/lib/rhoconnect/console/app/routes/home.rb +0 -63
  225. data/lib/rhoconnect/console/app/routes/timing.rb +0 -242
  226. data/lib/rhoconnect/console/app/routes/user.rb +0 -122
  227. data/lib/rhoconnect/console/app/views/adapter.erb +0 -16
  228. data/lib/rhoconnect/console/app/views/client.erb +0 -30
  229. data/lib/rhoconnect/console/app/views/content.erb +0 -14
  230. data/lib/rhoconnect/console/app/views/doc.erb +0 -8
  231. data/lib/rhoconnect/console/app/views/docdata.erb +0 -28
  232. data/lib/rhoconnect/console/app/views/docs.erb +0 -30
  233. data/lib/rhoconnect/console/app/views/edituser.erb +0 -13
  234. data/lib/rhoconnect/console/app/views/headermenu.erb +0 -40
  235. data/lib/rhoconnect/console/app/views/home.erb +0 -24
  236. data/lib/rhoconnect/console/app/views/index.erb +0 -58
  237. data/lib/rhoconnect/console/app/views/jqplot.erb +0 -52
  238. data/lib/rhoconnect/console/app/views/layout.erb +0 -153
  239. data/lib/rhoconnect/console/app/views/login.erb +0 -26
  240. data/lib/rhoconnect/console/app/views/newuser.erb +0 -17
  241. data/lib/rhoconnect/console/app/views/ping.erb +0 -40
  242. data/lib/rhoconnect/console/app/views/result.erb +0 -11
  243. data/lib/rhoconnect/console/app/views/rightboxlinks.erb +0 -15
  244. data/lib/rhoconnect/console/app/views/select_doc.erb +0 -17
  245. data/lib/rhoconnect/console/app/views/upload_doc.erb +0 -23
  246. data/lib/rhoconnect/console/app/views/user.erb +0 -29
  247. data/lib/rhoconnect/console/app/views/users.erb +0 -19
  248. data/lib/rhoconnect/server/views/index.erb +0 -13
@@ -0,0 +1,225 @@
1
+ module GraphHelper
2
+
3
+ def source_timing(params)
4
+ #name,data,options
5
+ puts "display is #{params}"
6
+ @displayname = params['display_name']
7
+ names = []
8
+ begin
9
+ names = get_sources('all') #RhoconnectApi::list_sources(session[:server],session[:token],:all)
10
+ rescue Exception => e
11
+ puts "errror #{e.message}"
12
+ end
13
+ @sources = []
14
+
15
+ names.each do |name|
16
+ s = {}
17
+ data = []
18
+ series = []
19
+ options = { :legend => { :show => true }, :title => name }
20
+ s['name'] = name
21
+
22
+ keys = get_user_count("source:*:#{name}") #RhoconnectApi::stats(session[:server],session[:token], :names => "source:*:#{name}")
23
+
24
+ xmin = 9999999999999999
25
+ xmax = -1
26
+ ymin = 9999999999999999
27
+ ymax = -1
28
+ keys.each do |key|
29
+ method = key.gsub(/source:/,"").gsub(/:.*/,"")
30
+ series << {:showLabel => true, :label => method }
31
+
32
+ range = get_user_count(nil,key,0,-1) #RhoconnectApi::stats(session[:server],session[:token], {:metric => key, :start => 0, :finish => -1})
33
+ thisdata = []
34
+ range.each do |value|
35
+ count = value.split(',')[0]
36
+ value.gsub!(/.*,/,"")
37
+ thisdata << value.split(":").reverse
38
+ thisdata[-1][0] = thisdata[-1][0].to_i * 1000
39
+ thisdata[-1][1] = thisdata[-1][1].to_f
40
+ thisdata[-1][1] /= count.to_f
41
+
42
+ ymin = thisdata[-1][1].to_f if thisdata[-1][1] && thisdata[-1][1].to_f < ymin
43
+ ymax = thisdata[-1][1].to_f if thisdata[-1][1] && thisdata[-1][1].to_f > ymax
44
+
45
+ end
46
+ data << thisdata
47
+ xmin = thisdata[0][0].to_i if thisdata[0] && thisdata[0][0].to_i < xmin
48
+ xmax = thisdata[-1][0].to_i if thisdata[-1] && thisdata[-1][0].to_i > xmax
49
+ end
50
+
51
+ options[:axes] = {
52
+ :yaxis => { :tickOptions => { :formatString =>'%.3f'}, :autoscale => true, :min => 0, :max => ymax + (ymax * 0.05), :label => 'Seconds', :labelRenderer => '$.jqplot.CanvasAxisLabelRenderer' },
53
+ :xaxis => { :autoscale => true, :renderer=>'$.jqplot.DateAxisRenderer',
54
+ :tickOptions => {:formatString => '%m/%d/%y'}}
55
+ }
56
+
57
+ s['data'] = data
58
+ options[:series] = series
59
+ options[:cursor] = {:zoom => true, :showTooltip => true}
60
+
61
+ s['options'] = options
62
+
63
+ @sources << s
64
+ end
65
+ @graph_t = 'source'
66
+ @data = [[[1,2],[3,4],[5,6]]].to_json
67
+ erb :jqplot, :layout => false
68
+ end
69
+
70
+
71
+ def http_timing(params)
72
+ @uri = 'timing/httptiming'
73
+
74
+ #name,data,options
75
+ @displayname = params['display_name']
76
+ names = ["GET","POST"]
77
+ begin
78
+ names = get_sources('all') #RhoconnectApi::list_sources(session[:server],session[:token],:all)
79
+ rescue Exception => e
80
+ puts "errror #{e.message}"
81
+ end
82
+ names << "ALL"
83
+ @sources = []
84
+
85
+ names.each do |name|
86
+ s = {}
87
+ data = []
88
+ series = []
89
+ options = { :legend => { :show => true }, :title => name }
90
+ s['name'] = name
91
+
92
+ name = "*" if name == "ALL"
93
+ keys = get_user_count("http:*:#{name}") #RhoconnectApi::stats(session[:server],session[:token], :names => "http:*:#{name}")
94
+
95
+ xmin = 9999999999999999
96
+ xmax = -1
97
+ ymin = 9999999999999999
98
+ ymax = -1
99
+ keys.each do |key|
100
+ method = key.gsub(/http:.*?:/,"")
101
+ method.gsub!(/:.*/,"") unless name == "*"
102
+ series << {:showLabel => true, :label => method }
103
+
104
+ range = get_user_count(nil,key,0,-1) #RhoconnectApi::stats(session[:server],session[:token], {:metric => key, :start => 0, :finish => -1})
105
+ thisdata = []
106
+ range.each do |value|
107
+ count = value.split(',')[0]
108
+ value.gsub!(/.*,/,"")
109
+ thisdata << value.split(":").reverse
110
+ thisdata[-1][0] = thisdata[-1][0].to_i * 1000
111
+ thisdata[-1][1] = thisdata[-1][1].to_f
112
+ thisdata[-1][1] /= count.to_f
113
+
114
+ ymin = thisdata[-1][1].to_f if thisdata[-1][1] && thisdata[-1][1].to_f < ymin
115
+ ymax = thisdata[-1][1].to_f if thisdata[-1][1] && thisdata[-1][1].to_f > ymax
116
+
117
+ end
118
+ data << thisdata
119
+ xmin = thisdata[0][0].to_i if thisdata[0] && thisdata[0][0].to_i < xmin
120
+ xmax = thisdata[-1][0].to_i if thisdata[-1] && thisdata[-1][0].to_i > xmax
121
+ end
122
+
123
+ options[:axes] = {
124
+ :yaxis => { :tickOptions => { :formatString =>'%.3f'}, :autoscale => true, :min => 0, :max => ymax + (ymax * 0.05), :label => 'Seconds', :labelRenderer => '$.jqplot.CanvasAxisLabelRenderer' },
125
+ :xaxis => { :autoscale => true, :renderer=>'$.jqplot.DateAxisRenderer',
126
+ :tickOptions => {:formatString => '%m/%d/%y'}}
127
+ }
128
+
129
+ s['data'] = data
130
+ options[:series] = series
131
+ options[:cursor] = {:zoom => true, :showTooltip => true}
132
+
133
+ s['options'] = options
134
+
135
+ @sources << s
136
+ end
137
+ @graph_t = 'http'
138
+ @data = [[[1,2],[3,4],[5,6]]].to_json
139
+ erb :jqplot, :layout => false
140
+ end
141
+
142
+ def count_graph(uri,title,name,metric)
143
+ start = 0
144
+ finish = -1
145
+ now = Time.now.to_i
146
+ format = "%m/%d/%y"
147
+
148
+ thisdata = []
149
+ series = []
150
+ series <<
151
+ options = { :legend => { :show => false }, :title => title }
152
+ @sources = []
153
+
154
+ s = {}
155
+ usercount = []
156
+
157
+ usercount = get_user_count(nil,metric,start,finish)
158
+
159
+ usercount.each do |count|
160
+ user,timestamp = count.split(':')
161
+ user = user.to_i
162
+ timestamp = timestamp.to_i * 1000
163
+ thisdata << [timestamp,user]
164
+ end
165
+
166
+ options[:axes] = {
167
+ :xaxis => { :autoscale => true, :renderer=>'$.jqplot.DateAxisRenderer',
168
+ :tickOptions => {:formatString => format}},
169
+ :yaxis => {:label => name, :labelRenderer => '$.jqplot.CanvasAxisLabelRenderer'}
170
+ }
171
+
172
+ options[:cursor] = {:zoom => true, :showTooltip => true}
173
+ s['name'] = name
174
+ s['data'] = [thisdata]
175
+ s['options'] = options
176
+ @sources << s
177
+ erb :jqplot, :layout => false
178
+ end
179
+
180
+ def get_user_count(name=nil,metric_p=nil,start=nil,finish=nil)
181
+ begin
182
+ if Rhoconnect.stats == true
183
+ names = name
184
+ if names
185
+ Rhoconnect::Stats::Record.keys(names)
186
+ else
187
+ metric = metric_p
188
+ rtype = Rhoconnect::Stats::Record.rtype(metric)
189
+ if rtype == 'zset'
190
+ # returns [] if no results
191
+ Rhoconnect::Stats::Record.range(metric,start,finish)
192
+ elsif rtype == 'string'
193
+ Rhoconnect::Stats::Record.get_value(metric) || ''
194
+ else
195
+ raise ApiException.new(404, "Unknown metric")
196
+ end
197
+ end
198
+ else
199
+ raise ApiException.new(500, "Stats not enabled")
200
+ end
201
+ rescue Exception => e
202
+ puts "error #{e.message} -- #{metric}"
203
+ usercount = ["0:#{Time.now.to_i}"]
204
+ end
205
+ end
206
+
207
+ def get_sources(partition_type)
208
+ sources = App.load(APP_NAME).sources
209
+ puts "sources is -- #{sources}"
210
+ if partition_type.nil? or partition_type == 'all'
211
+ sources
212
+ else
213
+ res = []
214
+ sources.each do |name|
215
+ s = Source.load(name,{:app_id => APP_NAME,:user_id => '*'})
216
+ if s.partition_type and s.partition_type == partition_type.to_sym
217
+ res << name
218
+ end
219
+ end
220
+ res
221
+ end
222
+
223
+ end
224
+
225
+ end
@@ -20,19 +20,39 @@ module Rhoconnect
20
20
  create_hsql_data_file(bulk_data,ts) if Rhoconnect.blackberry_bulk_sync
21
21
  lap_timer('create_hsql_data_file',timer)
22
22
  log "finished bulk data process"
23
+ #bulk_data.state = :completed
24
+ #bulk_data.refresh_time = Time.now.to_i + Rhoconnect.bulk_sync_poll_interval
25
+ else
26
+ raise Exception.new("No bulk data found for #{params["data_name"]}")
27
+ end
28
+ rescue Exception => e
29
+ bulk_data.delete if bulk_data
30
+ log "Bulk data job raised: #{e.message}"
31
+ log e.backtrace.join("\n")
32
+ raise e
33
+ end
34
+ end
35
+
36
+ def self.after_perform_x(*args)
37
+ log "BulkDataJob.after_perform_x hook called ..."
38
+ params = args[0] # 1st parameter is bulk data
39
+ begin
40
+ bulk_data = BulkData.load(params["data_name"]) if BulkData.is_exist?(params["data_name"])
41
+ if bulk_data
23
42
  bulk_data.state = :completed
24
43
  bulk_data.refresh_time = Time.now.to_i + Rhoconnect.bulk_sync_poll_interval
44
+ log "BulkDataJob.after_perform_x hook set data state to complete."
25
45
  else
26
46
  raise Exception.new("No bulk data found for #{params["data_name"]}")
27
47
  end
28
48
  rescue Exception => e
29
49
  bulk_data.delete if bulk_data
30
- log "Bulk data job raised: #{e.message}"
50
+ log "Bulk data after_perform_x raised: #{e.message}"
31
51
  log e.backtrace.join("\n")
32
52
  raise e
33
53
  end
34
54
  end
35
-
55
+
36
56
  def self.import_data_to_object_values(db,source)
37
57
  data = source.get_data(:md)
38
58
  counter = {}
@@ -129,6 +149,8 @@ module Rhoconnect
129
149
  sources_refs = {}
130
150
  schema,index,bulk_data.dbfile = get_file_args(bulk_data.name,ts)
131
151
  FileUtils.mkdir_p(File.dirname(bulk_data.dbfile))
152
+ # TODO: remove old bulk files!
153
+ # FileUtils.rm Dir.glob(File.join(Rhoconnect.data_directory, "#{bulk_data.name}*"))
132
154
 
133
155
  db = DBAdapter.instance.get_connection(bulk_data.dbfile)
134
156
  db.execute_batch(File.open(schema,'r').read)
@@ -3,7 +3,6 @@ require 'sinatra/base'
3
3
  require 'erb'
4
4
  require 'json'
5
5
  require 'fileutils'
6
- #require 'rack/contrib'
7
6
  require 'rhoconnect'
8
7
  require 'rhoconnect/x_domain_session_wrapper'
9
8
  require 'rhoconnect/body_content_type_parser'
@@ -20,9 +19,6 @@ module Rhoconnect
20
19
  end
21
20
 
22
21
  class Server < Sinatra::Base
23
- libdir = File.dirname(File.expand_path(__FILE__))
24
- set :views, "#{libdir}/server/views"
25
- set :public_folder, "#{libdir}/server/public"
26
22
  set :static, true
27
23
  set :stats, false
28
24
  # default secret
@@ -200,7 +196,30 @@ module Rhoconnect
200
196
  end
201
197
  end
202
198
 
199
+ private
200
+ def self._use_async_framework
201
+ return false if settings.respond_to?(:use_async_model) and settings.use_async_model == false
202
+ return false if @dispatch_framework_initialized
203
+
204
+ @dispatch_framework_initialized ||=true
205
+ if RUBY_VERSION =~ /1.9/ and not defined?(JRUBY_VERSION)
206
+ require 'rhoconnect/async'
207
+ register Rhoconnect::Synchrony
208
+ helpers Rhoconnect::AsyncHelpers
209
+ else
210
+ settings.use_async_model = false
211
+ end
212
+ end
213
+
203
214
  def self.new
215
+ # by default, enable this feature
216
+ if not settings.respond_to?(:use_async_model) or settings.use_async_model != false
217
+ set :use_async_model, true
218
+ end
219
+ # this must be called first - because
220
+ # it redefines some of the middleware
221
+ Rhoconnect::Server._use_async_framework
222
+
204
223
  if settings.respond_to?(:stats) and settings.send(:stats) == true
205
224
  Rhoconnect.stats = true
206
225
  else
@@ -208,6 +227,7 @@ module Rhoconnect
208
227
  Rhoconnect.stats = false
209
228
  end
210
229
  settings.use_middleware
230
+
211
231
  super
212
232
  end
213
233
 
@@ -222,12 +242,16 @@ module Rhoconnect
222
242
  before do
223
243
  cache_control :no_cache
224
244
  headers({'pragma'=>'no-cache'})
225
-
245
+
226
246
  if params[:version] and params[:version].to_i < 3
227
247
  throw :halt, [404, "Server supports version 3 or higher of the protocol."]
228
248
  end
229
249
  end
230
-
250
+
251
+ get '/' do
252
+ redirect "/console/"
253
+ end
254
+
231
255
  %w[get post].each do |verb|
232
256
  send(verb, "/*application*") do
233
257
  unless request_action == 'clientlogin'
@@ -236,11 +260,7 @@ module Rhoconnect
236
260
  pass
237
261
  end
238
262
  end
239
-
240
- get '/' do
241
- erb :index
242
- end
243
-
263
+
244
264
  # old routes
245
265
  post '/login' do
246
266
  mark_deprecated_call_and_reroute(:login, :admin, self, params)
@@ -68,6 +68,13 @@ module Rhoconnect
68
68
  end
69
69
  end
70
70
 
71
+ def update_fields(fields)
72
+ fields.each do |name,value|
73
+ arg = "#{name}=".to_sym
74
+ self.send(arg, value)
75
+ end
76
+ end
77
+
71
78
  def to_array
72
79
  res = []
73
80
  @@string_fields.each do |field|
@@ -90,14 +97,11 @@ module Rhoconnect
90
97
 
91
98
  # source fields
92
99
  define_fields([:id, :rho__id, :name, :url, :login, :password, :callback_url, :partition_type, :sync_type,
93
- :queue, :query_queue, :cud_queue, :belongs_to, :has_many, :pass_through], [:source_id, :priority, :retry_limit])
100
+ :queue, :query_queue, :cud_queue, :belongs_to, :has_many, :pass_through], [:source_id, :priority, :retry_limit, :simulate_time])
94
101
 
95
102
  def initialize(fields)
96
103
  self.name = fields['name'] || fields[:name]
97
- fields.each do |name,value|
98
- arg = "#{name}=".to_sym
99
- self.send(arg, value) if self.respond_to?(arg)
100
- end
104
+ update_fields(fields)
101
105
  end
102
106
 
103
107
  def self.set_defaults(fields)
@@ -113,6 +117,7 @@ module Rhoconnect
113
117
  fields[:belongs_to] = fields[:belongs_to].to_json if fields[:belongs_to]
114
118
  fields[:schema] = fields[:schema].to_json if fields[:schema]
115
119
  fields[:retry_limit] = fields[:retry_limit] ? fields[:retry_limit] : 0
120
+ fields[:simulate_time] = fields[:simulate_time] ? fields[:simulate_time] : 0
116
121
  end
117
122
 
118
123
  def self.create(fields,params)
@@ -111,6 +111,29 @@ module Rhoconnect
111
111
  @source.app_id,@source.user_id,params)
112
112
  end
113
113
 
114
+ def fast_insert(new_objs, timeout=10,raise_on_expire=false)
115
+ @source.lock(:md,timeout,raise_on_expire) do |s|
116
+ diff_count = new_objs.size
117
+ @source.put_data(:md, new_objs, true)
118
+ @source.update_count(:md_size,diff_count)
119
+ end
120
+ end
121
+
122
+ def fast_update(orig_hash, new_hash, timeout=10,raise_on_expire=false)
123
+ @source.lock(:md,timeout,raise_on_expire) do |s|
124
+ @source.delete_data(:md, orig_hash)
125
+ @source.put_data(:md, new_hash, true)
126
+ end
127
+ end
128
+
129
+ def fast_delete(delete_objs, timeout=10,raise_on_expire=false)
130
+ @source.lock(:md,timeout,raise_on_expire) do |s|
131
+ diff_count = -delete_objs.size
132
+ @source.delete_data(:md, delete_objs)
133
+ @source.update_count(:md_size,diff_count)
134
+ end
135
+ end
136
+
114
137
  def push_objects(objects,timeout=10,raise_on_expire=false,rebuild_md=true)
115
138
  @source.lock(:md,timeout,raise_on_expire) do |s|
116
139
  diff_count = 0
@@ -360,10 +383,17 @@ module Rhoconnect
360
383
  # Metadata Operation; source adapter returns json
361
384
  def _get_data(method)
362
385
  if @adapter.respond_to?(method)
363
- data = @adapter.send(method)
386
+ data = @adapter.send(method)
364
387
  if data
365
388
  @source.put_value(method,data)
366
- @source.put_value("#{method}_sha1",Digest::SHA1.hexdigest(data))
389
+ if method == :schema
390
+ parsed = JSON.parse(data)
391
+ schema_version = parsed['version']
392
+ raise "Mandatory version key is not defined in source adapter schema method" if schema_version.nil?
393
+ @source.put_value("#{method}_sha1",Digest::SHA1.hexdigest(schema_version))
394
+ else
395
+ @source.put_value("#{method}_sha1",Digest::SHA1.hexdigest(data))
396
+ end
367
397
  end
368
398
  end
369
399
  end
@@ -1,111 +1,19 @@
1
- require 'json'
2
1
  require 'zip/zip'
3
2
  require 'uri'
4
- require File.join(File.dirname(__FILE__),'console','rhoconnect_api')
3
+ $:.unshift File.dirname(__FILE__)
4
+ require 'console/rhoconnect_api'
5
+ require 'utilities'
5
6
 
7
+ DEPRECATION_MSG = "\n" +
8
+ "*** Warning: As of version 4.0 of rhoconnect, the rake command will be deprecated. ***\n" +
9
+ "*** Use the corresponding rhoconnect commands instead. ***\n" +
10
+ "*** Type 'rhoconnect help' for more information on these commands. ***\n" +
11
+ "\n"
6
12
 
7
- module Rhoconnect
8
- module TaskHelper
9
- def post(path,params)
10
- req = Net::HTTP.new($host,$port)
11
- resp = req.post(path, params.to_json, 'Content-Type' => 'application/json')
12
- print_resp(resp, resp.is_a?(Net::HTTPSuccess) ? true : false)
13
- end
14
-
15
- def print_resp(resp,success=true)
16
- if success
17
- puts "=> OK"
18
- else
19
- puts "=> FAILED"
20
- end
21
- puts "=> " + resp.body if resp and resp.body and resp.body.length > 0
22
- end
23
-
24
- def archive(path)
25
- File.join(path,File.basename(path))+'.zip'
26
- end
27
-
28
- def ask(msg)
29
- print msg
30
- STDIN.gets.chomp
31
- end
32
-
33
- def load_settings(file)
34
- begin
35
- $settings = YAML.load_file(file)
36
- rescue Exception => e
37
- puts "Error opening settings file #{file}: #{e}."
38
- puts e.backtrace.join("\n")
39
- raise e
40
- end
41
- end
42
-
43
- def rhoconnect_socket
44
- '/tmp/rhoconnect.dtach'
45
- end
46
-
47
- def rhoconnect_pid
48
- if windows?
49
- Dir.mkdir 'C:/TMP' unless File.directory? 'C:/TMP'
50
- 'C:/TMP/rhoconnect.pid'
51
- else
52
- '/tmp/rhoconnect.pid'
53
- end
54
- end
55
-
56
- def windows?
57
- RUBY_PLATFORM =~ /(win|w)32$/
58
- end
59
-
60
- def ruby19?
61
- RUBY_VERSION =~ /1.9/
62
- end
63
-
64
- def jruby?
65
- defined?(JRUBY_VERSION)
66
- end
67
-
68
- def thin?
69
- begin
70
- require 'thin'
71
- 'rackup -s thin'
72
- rescue LoadError
73
- nil
74
- end
75
- end
76
-
77
- def mongrel?
78
- begin
79
- require 'mongrel'
80
- 'rackup -s mongrel'
81
- rescue LoadError
82
- nil
83
- end
84
- end
85
-
86
- def report_missing_server
87
- msg =<<-EOF
88
- Could not find 'thin' or 'mongrel' on your system. Please install one:
89
- gem install thin
90
- or
91
- gem install mongrel
92
- EOF
93
- puts msg
94
- exit 1
95
- end
96
-
97
- # def jetty_rackup?
98
- # 'jruby -S jetty-rackup'
99
- # end
100
-
101
- def trinidad?
102
- 'jruby -S trinidad -p 9292 -r config.ru'
103
- end
104
- end
105
- end
13
+ puts DEPRECATION_MSG if $0.include? 'rake'
106
14
 
107
15
  namespace :rhoconnect do
108
- include Rhoconnect::TaskHelper
16
+ include Utilities
109
17
  include RhoconnectApi
110
18
 
111
19
  task :config do
@@ -256,7 +164,7 @@ namespace :rhoconnect do
256
164
  else
257
165
  puts 'Detach with Ctrl+\ Re-attach with rake rhoconnect:attach'
258
166
  sleep 2
259
- sh "dtach -A #{rhoconnect_socket} #{cmd} config.ru -P #{rhoconnect_pid}"
167
+ system "dtach -A #{rhoconnect_socket} #{cmd} config.ru -P #{rhoconnect_pid}"
260
168
  end
261
169
  end
262
170
 
@@ -305,10 +213,13 @@ namespace :rhoconnect do
305
213
 
306
214
  desc "run rhoconnect console"
307
215
  task :console, :environment do |t, args|
308
- if RedisRunner.running?
216
+ if RedisRunner.running?
217
+ application_file = ruby19? ? './application' : 'application'
309
218
  #load development environment by default
310
219
  ENV['RACK_ENV'] = args[:environment] || 'development'
311
- sh "irb -rubygems -r #{File.join(File.dirname(__FILE__),'console')} -r #{File.dirname(__FILE__)} -r application"
220
+ system "irb -rubygems -r #{File.join(File.dirname(__FILE__),'console')} " +
221
+ "-r #{File.dirname(__FILE__)} " +
222
+ "-r #{application_file}"
312
223
  else
313
224
  puts "Redis is not running. Please start it by running 'rake redis:start' command."
314
225
  end
@@ -319,13 +230,13 @@ namespace :rhoconnect do
319
230
  if windows?
320
231
  File.delete "#{rhoconnect_pid}" if system("FOR /F %A in (#{rhoconnect_pid}) do taskkill /F /PID %A")
321
232
  else
322
- sh "cat #{rhoconnect_pid} | xargs kill -3"
233
+ system "cat #{rhoconnect_pid} | xargs kill -3"
323
234
  end
324
235
  end
325
236
 
326
237
  desc "Attach to rhoconnect console"
327
238
  task :attach => :dtach_installed do
328
- sh "dtach -a #{rhoconnect_socket}" unless windows?
239
+ system "dtach -a #{rhoconnect_socket}" unless windows?
329
240
  end
330
241
 
331
242
  desc "Launch the web console in a browser - uses :syncserver: in settings.yml"
@@ -380,7 +291,7 @@ namespace :rhoconnect do
380
291
  end
381
292
  # build the executable WAR using the config/warble.rb file
382
293
  ENV['BUNDLE_WITHOUT'] = ['development','test'].join(':')
383
- sh 'warble executable war'
294
+ system 'warble executable war'
384
295
  else
385
296
  puts "Cannot build WAR files outside of JRuby environment!"
386
297
  end
@@ -45,6 +45,26 @@ module Rhoconnect
45
45
  return @s.is_pass_through? ? res : md
46
46
  end
47
47
 
48
+ # Executes the adapter's search method based on search_params
49
+ # and returns a hash of hashes.
50
+ # For example, if master document was
51
+ # {
52
+ # "1"=>{"name"=>"Acme", "industry"=>"Electronics"},
53
+ # "2"=>{"name"=>"Best", "industry"=>"Software"}
54
+ # }
55
+ #
56
+ # Then call test_search("name"=>"Acme") would return
57
+ # {
58
+ # "1"=>{"name"=>"Acme", "industry"=>"Electronics"},
59
+ # }
60
+ def test_search(search_params)
61
+ pass_through = @s.pass_through
62
+ @s.pass_through = 'true'
63
+ res = @ss.search(@c.id, search_params)
64
+ @s.pass_through = pass_through
65
+ res
66
+ end
67
+
48
68
  # Executes the adapter's query method and returns
49
69
  # the metadata stored in redis
50
70
  # For example, if your source adapter metadata method was: