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
@@ -25,6 +25,8 @@ Rhoconnect::Server.set :secret, 'cf8e8a1d3653fcfb2332d8b1af9f6762c3c45e
25
25
  Rhoconnect::Server.set :root, ROOT_PATH
26
26
  Rhoconnect::Server.use Rack::Static, :urls => ["/data"], :root => Rhoconnect::Server.root
27
27
  Rhoconnect::Server.disable :logging
28
+ #Rhoconnect::Server.set :use_async_model, false # true by default
29
+ #Rhoconnect::Server.set :fiberpool_size, 50 # default is 100
28
30
 
29
31
  # Load our rhoconnect application
30
32
  require "#{ROOT_PATH}/application"
@@ -14,6 +14,7 @@ module Bench
14
14
  Bench.concurrency = params[2].to_i unless params[2].nil?
15
15
  Bench.iterations = params[3].to_i unless params[3].nil?
16
16
  Bench.datasize = params[4].to_i unless params[4].nil?
17
+ Bench.simtime = params[5].to_i unless params[5].nil?
17
18
  Bench.admin_login = login
18
19
  Bench.admin_password = password
19
20
  load(script)
@@ -39,6 +40,7 @@ module Bench
39
40
  Bench.concurrency = params[2].to_i unless params[2].nil?
40
41
  Bench.iterations = params[3].to_i unless params[3].nil?
41
42
  Bench.datasize = params[4].to_i unless params[4].nil?
43
+ Bench.simtime = params[5].to_i unless params[5].nil?
42
44
  Bench.admin_login = login
43
45
  Bench.admin_password = password
44
46
  load(script)
@@ -8,7 +8,7 @@ module Bench
8
8
  @clients_group = clientgroup
9
9
  end
10
10
 
11
- def run(server, sync_key, payload, concurrency, niterations, result_filename=nil)
11
+ def run(server, sync_key, payload, concurrency, niterations, result_filename=nil, sim_time = 0)
12
12
  # 1) Extract server name
13
13
  server ||= 'default'
14
14
  if server != 'default'
@@ -33,7 +33,8 @@ module Bench
33
33
  Bench.user_name = "benchuser"
34
34
  Bench.password = "password"
35
35
  Bench.set_server_state("test_db_storage:application:#{Bench.user_name}",expected_data)
36
- Bench.reset_refresh_time('RhoInternalBenchmarkAdapter')
36
+ Bench.reset_refresh_time('RhoInternalBenchmarkAdapter', 0)
37
+ Bench.set_simulate_time('RhoInternalBenchmarkAdapter', sim_time)
37
38
 
38
39
  #6) set the sync key
39
40
  @start_time = Time.now + 10.0
@@ -12,7 +12,7 @@ module Bench
12
12
  def test(concurrency,iterations,&block)
13
13
  total_times = times do
14
14
  0.upto(concurrency - 1) do |thread_id|
15
- sleep rand(2)
15
+ #sleep rand(2)
16
16
  threads << Thread.new(block) do |t|
17
17
  0.upto(iterations - 1) do |iteration|
18
18
  s = Session.new(thread_id, iteration)
data/bench/lib/bench.rb CHANGED
@@ -25,7 +25,7 @@ module Bench
25
25
  include TestData
26
26
  include Utils
27
27
 
28
- attr_accessor :concurrency, :iterations, :admin_login
28
+ attr_accessor :concurrency, :iterations, :admin_login, :simtime
29
29
  attr_accessor :admin_password, :user_name
30
30
  attr_accessor :password, :base_url, :host, :token
31
31
  attr_accessor :total_time, :sessions, :verify_error
@@ -108,6 +108,15 @@ module Bench
108
108
  :content_type => :json)
109
109
  end
110
110
 
111
+ def set_simulate_time(source_name,simulate_time=0)
112
+ token = get_token
113
+ RestClient.post("#{@host}/api/source/update_source_params",
114
+ {:api_token => token, :source_name => source_name,
115
+ :user_name => @user_name,
116
+ :data => {:simulate_time => simulate_time}}.to_json,
117
+ :content_type => :json)
118
+ end
119
+
111
120
  def get_token
112
121
  unless @token
113
122
  @token = RestClient.post("#{@host}/api/admin/login",
data/bench/run_bench.sh CHANGED
@@ -33,7 +33,7 @@ redis-cli flushdb > /dev/null
33
33
 
34
34
  # Run benchmarks for ruby 1.8.7, ree, 1.9.2, and 1.9.3
35
35
  # TODO: 'jruby'
36
- for ruby in '1.9.3' '1.8.7' 'ree'
36
+ for ruby in '1.9.3' '1.9.2' '1.8.7' 'ree'
37
37
  do
38
38
  rvm use $ruby > /dev/null
39
39
  ruby_version=$(rvm current)
@@ -20,7 +20,8 @@ Bench.config do |config|
20
20
  config.reset_app
21
21
  @expected = Bench.get_test_data(@datasize)
22
22
  config.set_server_state("test_db_storage:application:#{config.user_name}",@expected)
23
- config.reset_refresh_time('RhoInternalBenchmarkAdapter')
23
+ config.reset_refresh_time('RhoInternalBenchmarkAdapter', 0)
24
+ config.set_simulate_time('RhoInternalBenchmarkAdapter', Bench.simtime)
24
25
  end
25
26
  end
26
27
 
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'rspec'
3
+ require 'excon'
3
4
  $:.unshift File.join(File.dirname(__FILE__),'..')
4
5
  $:.unshift File.join(File.dirname(__FILE__),'..','lib')
5
6
 
data/bin/rhoconnect CHANGED
@@ -1,34 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'rubygems'
4
- require 'templater'
5
- require File.join(File.dirname(__FILE__), '..','generators','rhoconnect')
6
- $:.unshift File.join(File.dirname(__FILE__),'..','lib')
7
- require File.join(File.dirname(__FILE__), '..','lib','rhoconnect')
8
-
9
- # Stub this method to force 1.8 compatibility (come on templater!)
10
- class Encoding
11
- def find
12
- "utf-8"
13
- end
14
-
15
- def dummy?
16
- false
17
- end
4
+ if File.exists?(File.join(Dir.pwd,'Gemfile'))
5
+ require 'bundler'
6
+ Bundler.require
18
7
  end
19
8
 
20
- class String
21
- def force_encoding(enc)
22
- return self
23
- end
24
- def encoding
25
- if RUBY_VERSION =~ /1\.8/ and Encoding.responds_to?('new')
26
- Encoding.new
27
- else
28
- Encoding.default_external
29
- end
30
- end
31
- end
9
+ $:.unshift File.join(File.dirname(__FILE__),'..')
32
10
 
11
+ require 'templater'
12
+ require 'generators/rhoconnect'
13
+ require 'lib/rhoconnect'
14
+ require 'commands/execute'
33
15
 
34
- Rhoconnect.run_cli(Dir.pwd, 'rhoconnect', Rhoconnect::VERSION, ARGV)
16
+ Execute.start
@@ -73,6 +73,11 @@ def parse_options
73
73
  options[:title] = title
74
74
  end
75
75
 
76
+ options[:simtime] = 0
77
+ opts.on('-S', '--simtime NUMBER', "Force the source adapter to simulate NUMBER seconds communication roundtrip with the backend") do |simtime|
78
+ options[:simtime] = simtime
79
+ end
80
+
76
81
  opts.on( '-A', '--advanced', 'This convinience option combines -m 10 and -x 500') do
77
82
  options[:max_payload] = 500
78
83
  options[:payload] = 500
@@ -80,6 +85,7 @@ def parse_options
80
85
  options[:num_clients] = 10
81
86
  options[:title] ||= "QUERY"
82
87
  options[:save_results] = '.'
88
+ options[:simtime] = 0
83
89
  end
84
90
 
85
91
  options[:distributed] = nil
@@ -91,6 +97,7 @@ def parse_options
91
97
  options[:title] ||= "QUERY"
92
98
  options[:save_results] = '.'
93
99
  options[:distributed] = fname
100
+ options[:simtime] = 0
94
101
  end
95
102
 
96
103
  # This displays the help screen, all programs are
@@ -236,11 +243,13 @@ begin
236
243
  bench_args[7] = options[:num_iterations]
237
244
  # datasize
238
245
  bench_args[8] = payload
246
+ # simulate backend delay
247
+ bench_args[9] = options[:simtime]
239
248
 
240
249
  # now execute Bench
241
250
  if(options[:distributed])
242
251
  sync_key = "#{options[:title]}_#{payload}"
243
- options[:distr_runner].run(Bench.base_url, sync_key, payload, concurrency, options[:num_iterations], result_fname)
252
+ options[:distr_runner].run(Bench.base_url, sync_key, payload, concurrency, options[:num_iterations], result_fname, options[:simtime])
244
253
  else
245
254
  Bench::Cli.start bench_args
246
255
  end
@@ -0,0 +1,6 @@
1
+ Execute.define_task do
2
+ desc 'dtach-about', 'About dtach'
3
+ def dtach_about
4
+ puts "\nSee http://dtach.sourceforge.net/ for information about dtach.\n\n"
5
+ end #dtach_about
6
+ end #do
@@ -0,0 +1,30 @@
1
+ Execute.define_task do
2
+ desc 'dtach-install', 'Install dtach 0.8 from source'
3
+ def dtach_install
4
+ invoke :dtach_about
5
+
6
+ unless windows?
7
+ Dir.chdir('/tmp/')
8
+ unless File.exists?('/tmp/dtach-0.8.tar.gz')
9
+ require 'net/http'
10
+
11
+ url = 'http://downloads.sourceforge.net/project/dtach/dtach/0.8/dtach-0.8.tar.gz'
12
+ open('/tmp/dtach-0.8.tar.gz', 'wb') do |file| file.write(open(url).read) end
13
+ end #do
14
+
15
+ unless File.directory?('/tmp/dtach-0.8')
16
+ system('tar xzf dtach-0.8.tar.gz')
17
+ end #unless
18
+
19
+ ENV['PREFIX'] and bin_dir = "#{ENV['PREFIX']}/bin" or bin_dir = "#{RedisRunner.prefix}bin"
20
+
21
+ mk_bin_dir(bin_dir)
22
+
23
+ Dir.chdir('/tmp/dtach-0.8/')
24
+ system 'cd /tmp/dtach-0.8/ && ./configure && make'
25
+ system "cp /tmp/dtach-0.8/dtach #{bin_dir}"
26
+
27
+ puts "Dtach successfully installed to #{bin_dir}"
28
+ end #unless
29
+ end #dtach_install
30
+ end #do
@@ -0,0 +1,6 @@
1
+ Execute.define_task do
2
+ desc "redis-about", 'About redis'
3
+ def redis_about
4
+ puts "\nSee http://redis.io/ for information about redis.\n\n"
5
+ end #about
6
+ end #do
@@ -0,0 +1,6 @@
1
+ Execute.define_task do
2
+ desc "redis-attach", 'Attach to redis dtach socket'
3
+ def redis_attach
4
+ RedisRunner.attach
5
+ end #redis_attach
6
+ end #do
@@ -0,0 +1,33 @@
1
+ Execute.define_task do
2
+ desc "redis-download", "Download redis package"
3
+ def redis_download
4
+ if windows?
5
+ require 'net/http'
6
+ require 'zip/zip'
7
+ puts "Installing redis to #{redis_home}."
8
+
9
+ Net::HTTP.start("cloud.github.com") do |http|
10
+ resp = http.get("/downloads/dmajkic/redis/#{$redis_ver}-win32-win64.zip")
11
+ open($redis_zip, "wb") do |file|
12
+ file.write(resp.body)
13
+ end #do
14
+ end #do
15
+
16
+ Zip::ZipFile.open($redis_zip) do |zip_file|
17
+ zip_file.each do |f|
18
+ f_path = File.join(redis_home, f.name)
19
+ FileUtils.mkdir_p(File.dirname(f_path))
20
+ zip_file.extract(f, f_path) { true }
21
+ end #do
22
+ end #do
23
+
24
+ FileUtils.mv Dir.glob(File.join(redis_home,'32bit','*')), redis_home
25
+ FileUtils.rm_rf File.join(redis_home, '64bit')
26
+ FileUtils.rm_f $redis_zip
27
+ else
28
+ sh 'rm -rf /tmp/redis/' if File.exists?("#{RedisRunner.redisdir}")
29
+ sh 'git clone git://github.com/antirez/redis.git /tmp/redis -n'
30
+ sh "cd #{RedisRunner.redisdir} && git reset --hard && git checkout #{REDIS_RELEASE}"
31
+ end #if
32
+ end #redis_download
33
+ end #do
@@ -0,0 +1,26 @@
1
+ Execute.define_task do
2
+ desc "redis-install", 'Install the latest verison of Redis from Github (requires git, duh)'
3
+ def redis_install
4
+ invoke :redis_about
5
+ invoke :redis_download
6
+ invoke :redis_make
7
+ unless windows?
8
+ ENV['PREFIX'] and bin_dir = "#{ENV['PREFIX']}/bin" or bin_dir = "#{RedisRunner.prefix}bin"
9
+
10
+ mk_bin_dir(bin_dir)
11
+
12
+ %w(redis-benchmark redis-cli redis-server).each do |bin|
13
+ sh "cp /tmp/redis/src/#{bin} #{bin_dir}"
14
+ end #do
15
+
16
+ puts "Installed redis-benchmark, redis-cli and redis-server to #{bin_dir}"
17
+
18
+ ENV['PREFIX'] and conf_dir = "#{ENV['PREFIX']}/etc" or conf_dir = "#{RedisRunner.prefix}etc"
19
+ unless File.exists?("#{conf_dir}/redis.conf")
20
+ sh "mkdir #{conf_dir}" unless File.exists?("#{conf_dir}")
21
+ sh "cp /tmp/redis/redis.conf #{conf_dir}/redis.conf"
22
+ puts "Installed redis.conf to #{conf_dir} \n You should look at this file!"
23
+ end #unless
24
+ end #unless
25
+ end #redis_install
26
+ end #do
@@ -0,0 +1,9 @@
1
+ Execute.define_task do
2
+ desc "redis-make", "Alias for make clean && make", :hide => true
3
+ def redis_make
4
+ unless windows?
5
+ sh "cd #{RedisRunner.redisdir} && make clean"
6
+ sh "cd #{RedisRunner.redisdir} && make"
7
+ end #unless
8
+ end #redis_make
9
+ end #do
@@ -0,0 +1,7 @@
1
+ Execute.define_task do
2
+ desc "redis-restart", 'Restart redis'
3
+ def redis_restart
4
+ RedisRunner.stop
5
+ RedisRunner.start
6
+ end #redis_restart
7
+ end #do
@@ -0,0 +1,67 @@
1
+ REDIS_RELEASE = "2.4.10"
2
+
3
+ class RedisRunner
4
+
5
+ def self.prefix
6
+ "/usr/local/"
7
+ end
8
+
9
+ def self.redisdir
10
+ "/tmp/redis/"
11
+ end
12
+
13
+ def self.redisconfdir
14
+ server_dir = File.dirname(`which redis-server`)
15
+ conf_file = "#{RedisRunner.prefix}etc/redis.conf"
16
+ unless File.exists? conf_file
17
+ conf_file = "#{server_dir}/redis.conf"
18
+ end
19
+ conf_file
20
+ end
21
+
22
+ def self.dtach_socket
23
+ '/tmp/redis.dtach'
24
+ end
25
+
26
+ # Just check for existance of dtach socket
27
+ def self.running?
28
+ File.exists? dtach_socket
29
+ end
30
+
31
+ def self.start
32
+ if windows?
33
+ puts "Starting redis in a new window..."
34
+ sh "start #{File.join(redis_home,'redis-server')} #{File.join(redis_home,'redis.conf')}" rescue
35
+ "redis-server not installed on your path, please run 'rhoconnect redis-install' first."
36
+ elsif defined?(JRUBY_VERSION)
37
+ puts "Starting redis ..."
38
+ sh "redis-server #{redisconfdir}"
39
+ else
40
+ puts 'Detach with Ctrl+\ Re-attach with rhoconnect redis-attach'
41
+ sleep 1
42
+ command = "dtach -A #{dtach_socket} redis-server #{redisconfdir}"
43
+ sh command
44
+ end
45
+ end
46
+
47
+ # this function is used with Rhostudio where there is no terminal
48
+ def self.startbg
49
+ if windows?
50
+ puts "Starting redis in a new window..."
51
+ sh "start #{File.join(redis_home,'redis-server')} #{File.join(redis_home,'redis.conf')}" rescue
52
+ "redis-server not installed on your path, please run 'rhoconnect redis-install' first."
53
+ else
54
+ puts "Starting redis ..."
55
+ system("redis-server #{redisconfdir} &")
56
+ end
57
+ end
58
+
59
+ def self.attach
60
+ exec "dtach -a #{dtach_socket}"
61
+ end
62
+
63
+ def self.stop
64
+ Redis.new.shutdown rescue nil
65
+ end
66
+
67
+ end #RedisRunner
@@ -0,0 +1,6 @@
1
+ Execute.define_task do
2
+ desc "redis-start", 'Start redis'
3
+ def redis_start
4
+ RedisRunner.start
5
+ end #redis_start
6
+ end #do
@@ -0,0 +1,6 @@
1
+ Execute.define_task do
2
+ desc "redis-startbg", "'Start redis' without dtach - for Rhostudio (internal)", :hide => true
3
+ def redis_startbg
4
+ RedisRunner.startbg
5
+ end #redis_startbg
6
+ end #do
@@ -0,0 +1,6 @@
1
+ Execute.define_task do
2
+ desc "redis-stop", 'Stop redis'
3
+ def redis_stop
4
+ RedisRunner.stop
5
+ end #redis_stop
6
+ end #do
@@ -0,0 +1,7 @@
1
+ Execute.define_task do
2
+ desc "attach", "Attach to rhoconnect console"
3
+ def attach
4
+ invoke :dtach_installed
5
+ sh "dtach -a #{rhoconnect_socket}" unless windows?
6
+ end #attach
7
+ end #do
@@ -0,0 +1,9 @@
1
+ Execute.define_task do
2
+ desc "clean-start", "Clean rhoconnect, get token, and create new user"
3
+ def clean_start
4
+ invoke :get_token
5
+ invoke :reset
6
+ invoke :get_token
7
+ invoke :create_user
8
+ end #clean_start
9
+ end #do
@@ -0,0 +1,15 @@
1
+ Execute.define_task do
2
+ desc "config", "Config", :hide => true
3
+ def config
4
+ $settings = load_settings(File.join('settings','settings.yml'))
5
+ $env = (ENV['RHO_ENV'] || ENV['RACK_ENV'] || :development).to_sym
6
+ uri = URI.parse($settings[$env][:syncserver])
7
+ $url = "#{uri.scheme}://#{uri.host}"
8
+ $url = "#{$url}:#{uri.port}" if uri.port && uri.port != 80
9
+ $host = uri.host
10
+ $port = uri.port
11
+ $appname = $settings[$env][:syncserver].split('/').last
12
+ $token_file = File.join(ENV['HOME'],'.rhoconnect_token')
13
+ $token = File.read($token_file) if File.exist?($token_file)
14
+ end #config
15
+ end #do
@@ -0,0 +1,15 @@
1
+ Execute.define_task do
2
+ desc "console [environment]", "run rhoconnect console"
3
+ def console(environment=nil)
4
+ if RedisRunner.running?
5
+ application_file = ruby19? ? './application' : 'application'
6
+ #load development environment by default
7
+ ENV['RACK_ENV'] = environment || 'development'
8
+ system "irb -rubygems -r #{File.join(File.dirname(__FILE__),'console_helper')} " +
9
+ "-r #{File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'rhoconnect') } " +
10
+ "-r #{application_file}"
11
+ else
12
+ puts "Redis is not running. Please start it by running 'rhoconnect redis-start' command."
13
+ end #if
14
+ end #console
15
+ end #do
@@ -0,0 +1,3 @@
1
+ path = File.join(File.dirname(__FILE__),'..','..', '..', 'lib')
2
+ $:.unshift path
3
+ ROOT_PATH = Dir.pwd
@@ -0,0 +1,18 @@
1
+ Execute.define_task do
2
+ desc "create-user", "Creates and subscribes user for application in rhoconnect"
3
+ def create_user
4
+ invoke :config
5
+ password = ''
6
+ login = ask "new user login: "
7
+ begin
8
+ system "stty -echo"
9
+ password = ask "\nnew user password: "
10
+ system "stty echo"
11
+ rescue NoMethodError, Interrupt
12
+ system "stty echo"
13
+ exit
14
+ end
15
+ puts ''
16
+ RhoconnectApi.create_user($url,$token,login,password)
17
+ end #create_user
18
+ end #do
@@ -0,0 +1,9 @@
1
+ Execute.define_task do
2
+ desc "delete-device", "Deletes a device from rhoconnect"
3
+ def delete_device
4
+ invoke :config
5
+ user_id = ask "device's user_id: "
6
+ device_id = ask "device to delete: "
7
+ RhoconnectApi.delete_client($url,$token,user_id,device_id)
8
+ end #delete_device
9
+ end #do
@@ -0,0 +1,8 @@
1
+ Execute.define_task do
2
+ desc "delete-user", "Deletes a user from rhoconnect"
3
+ def delete_user
4
+ invoke :config
5
+ login = ask "user to delete: "
6
+ RhoconnectApi.delete_user($url,$token,login)
7
+ end #delete_user
8
+ end #do
@@ -0,0 +1,14 @@
1
+ Execute.define_task do
2
+ desc "flushdb", "Flush data store - WARNING: THIS REMOVES ALL DATA IN RHOCONNECT"
3
+ def flushdb
4
+ invoke :config
5
+ puts "*** WARNING: THIS WILL REMOVE ALL DATA FROM YOUR REDIS STORE ***"
6
+ confirm = ask "Are you sure (please answer yes/no)? "
7
+ if confirm == 'yes'
8
+ Redis.new.flushdb
9
+ puts "Database flushed..."
10
+ else
11
+ puts "Aborted..."
12
+ end #if
13
+ end #flushdb
14
+ end #do
@@ -0,0 +1,25 @@
1
+ Execute.define_task do
2
+ desc "get-token", "Fetches current api token from rhoconnect"
3
+ def get_token
4
+ invoke :config
5
+ password = ''
6
+ login = ask "admin login: "
7
+ begin
8
+ system "stty -echo"
9
+ password = ask "\nadmin password: "
10
+ system "stty echo"
11
+ rescue NoMethodError, Interrupt
12
+ system "stty echo"
13
+ exit
14
+ end
15
+ puts ''
16
+ begin
17
+ $token = RhoconnectApi.get_token($url,login,password)
18
+ rescue
19
+ puts "Login failed."
20
+ exit
21
+ end
22
+ File.open($token_file,'w') {|f| f.write $token}
23
+ puts "Token is saved in: #{$token_file}"
24
+ end #get_token
25
+ end #do
@@ -0,0 +1,16 @@
1
+ Execute.define_task do
2
+ desc "reset", "Reset the rhoconnect database (you will need to run rhoconnect:get_token afterwards)"
3
+ def reset
4
+ invoke :config
5
+ confirm = ask " Are you sure? Resetting will remove all data!\n" +
6
+ " It will also return an error code to all\n" +
7
+ " existing devices when they connect! (yes/no):"
8
+
9
+ if confirm == 'yes'
10
+ RhoconnectApi.reset($url,$token)
11
+ puts "Database reset."
12
+ else
13
+ puts "Cancelling."
14
+ end #if
15
+ end #reset
16
+ end #do
@@ -0,0 +1,11 @@
1
+ Execute.define_task do
2
+ desc "reset-refresh", "Reset source refresh time"
3
+ def reset_refresh
4
+ invoke :config
5
+ user = ask "user: "
6
+ source_name = ask "source name: "
7
+ RestClient.post("#{$url}/api/source/set_refresh_time", { :api_token => $token,
8
+ :user_name => user,
9
+ :source_name => source_name })
10
+ end #reset_refresh
11
+ end #do
@@ -0,0 +1,7 @@
1
+ Execute.define_task do
2
+ desc "restart", "Alias for `rhoconnect stop; rhoconnect start`"
3
+ def restart
4
+ invoke :stop
5
+ invoke :start
6
+ end #restart
7
+ end #do
@@ -0,0 +1,11 @@
1
+ Execute.define_task do
2
+ desc "secret", "Generate a cryptographically secure secret session key"
3
+ def secret
4
+ begin
5
+ require 'securerandom'
6
+ puts SecureRandom.hex(64)
7
+ rescue LoadError
8
+ puts "Missing secure random generator. Try running `rhoconnect secret` in a rails application instead."
9
+ end #begin
10
+ end #secret
11
+ end #do
@@ -0,0 +1,26 @@
1
+ Execute.define_task do
2
+ desc "set-admin-password", "Sets the admin password"
3
+ def set_admin_password
4
+ invoke :get_token
5
+ new_pass,new_pass_confirm = '',''
6
+ begin
7
+ system "stty -echo"
8
+ new_pass = ask "\nnew admin password: "
9
+ new_pass_confirm = ask "\nconfirm new admin password: "
10
+ system "stty echo"
11
+ rescue NoMethodError, Interrupt
12
+ system "stty echo"
13
+ exit
14
+ end #begin
15
+ if new_pass == ''
16
+ puts "\nNew password can't be empty."
17
+ elsif new_pass == new_pass_confirm
18
+ puts ""
19
+ RestClient.post("#{$url}/api/user/update_user", { :app_name => $appname,
20
+ :api_token => $token,
21
+ :attributes => { :new_password => new_pass } })
22
+ else
23
+ puts "\nNew password and confirmation must match."
24
+ end #if
25
+ end #set_admin_password
26
+ end #do