Module: RhoconnectHelper
- Defined in:
- lib/build/rhoconnect_helper.rb
Constant Summary collapse
- @@enable_redis =
true
- @@enable_resque =
true
- @@enable_push =
true
- @@rhoconnect_bin =
nil
- @@host =
nil
- @@port =
nil
- @@server_pid =
nil
- @@resque_pid =
nil
- @@rhoconnect_push_pid =
nil
- @@redis_pid =
nil
- @@rc_out =
$stdout
- @@resque_out =
$stdout
- @@redis_out =
$stdout
- @@rc_push_out =
$stdout
- @@push_host =
nil
- @@push_port =
nil
- @@server_path =
nil
Class Method Summary collapse
- .api_get(request, params, api_token = nil) ⇒ Object
- .api_post(request, params, api_token = nil) ⇒ Object
- .execute_rhoconnect(workdir, *args) ⇒ Object
- .generate_app(dir, name, run_bundler = true) ⇒ Object
- .host ⇒ Object
- .port ⇒ Object
- .push_host ⇒ Object
- .push_port ⇒ Object
- .reset_server ⇒ Object
- .rhoconnect_bin ⇒ Object
- .set_enable_push(b) ⇒ Object
- .set_enable_rails(b) ⇒ Object
-
.set_enable_redis(b) ⇒ Object
@@enable_rails = true.
- .set_enable_resque(b) ⇒ Object
- .set_rc_out(rc_out) ⇒ Object
- .set_rc_push_out(rc_push_out) ⇒ Object
- .set_redis_out(redis_out) ⇒ Object
- .set_resque_out(resque_out) ⇒ Object
- .set_rhoconnect_bin(path) ⇒ Object
- .start_rails ⇒ Object
- .start_redis ⇒ Object
- .start_resque ⇒ Object
- .start_rhoconnect_push ⇒ Object
- .start_rhoconnect_stack(dir, reset = false) ⇒ Object
- .start_server(dir) ⇒ Object
- .stop_rails ⇒ Object
- .stop_redis ⇒ Object
- .stop_resque ⇒ Object
- .stop_rhoconnect_push ⇒ Object
- .stop_rhoconnect_stack ⇒ Object
- .stop_server ⇒ Object
Class Method Details
.api_get(request, params, api_token = nil) ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/build/rhoconnect_helper.rb', line 138 def self.api_get(request,params,api_token=nil) headers = {} headers[:content_type] = :json headers['X-RhoConnect-API-TOKEN'] = api_token if api_token puts "GET request to Rhoconnect: params: #{params}, headers: #{headers}" RestClient.get("#{@@host}:#{@@port}/rc/v1/#{request}",params.to_json, headers) end |
.api_post(request, params, api_token = nil) ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/build/rhoconnect_helper.rb', line 130 def self.api_post(request,params,api_token=nil) headers = {} headers[:content_type] = :json headers['X-RhoConnect-API-TOKEN'] = api_token if api_token puts "POST request to Rhoconnect: params: #{params}, headers: #{headers}" RestClient.post("#{@@host}:#{@@port}/rc/v1/#{request}",params.to_json, headers) end |
.execute_rhoconnect(workdir, *args) ⇒ Object
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/build/rhoconnect_helper.rb', line 257 def self.execute_rhoconnect(workdir,*args) cmd = "" if RUBY_PLATFORM =~ /(win|w)32$/ cmd = "ruby #{@@rhoconnect_bin}" else cmd = "#{@@rhoconnect_bin}" end args.each do |arg| cmd = "#{cmd} #{arg}" end cmd = "bundle exec #{cmd}" if cmd =~ / start/ puts cmd if workdir Kernel.system(cmd,:chdir => workdir, :out => @@rc_out) else Kernel.system(cmd, :out => @@rc_out) end end |
.generate_app(dir, name, run_bundler = true) ⇒ Object
221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/build/rhoconnect_helper.rb', line 221 def self.generate_app(dir, name, run_bundler = true) puts "Generating rhoconnect app: binary: #{@@rhoconnect_bin}, app name: #{name}, dir: #{dir}" execute_rhoconnect(dir,"app", name) # Patch Gemfile: replace gem version by path to source gem_path = "gem 'rhoconnect', :path => '#{@@rhoconnect_path}'" path_gemfile = File.join(dir, name, "Gemfile") lines = File.read(path_gemfile) lines.gsub!(/(gem 'rhoconnect'.*)/, gem_path) File.open(path_gemfile, 'w') { |f| f.write lines } Kernel.system('bundle install', :chdir => File.join(dir, name)) if run_bundler end |
.host ⇒ Object
43 44 45 |
# File 'lib/build/rhoconnect_helper.rb', line 43 def self.host @@host end |
.port ⇒ Object
48 49 50 |
# File 'lib/build/rhoconnect_helper.rb', line 48 def self.port @@port end |
.push_host ⇒ Object
78 79 80 |
# File 'lib/build/rhoconnect_helper.rb', line 78 def self.push_host @@push_host end |
.push_port ⇒ Object
83 84 85 |
# File 'lib/build/rhoconnect_helper.rb', line 83 def self.push_port @@push_port end |
.reset_server ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/build/rhoconnect_helper.rb', line 146 def self.reset_server begin platform = platform exact_url = "http://#{@@host}:#{@@port}" puts "going to reset server: #{exact_url}" # login to the server api_token = api_post('system/login', { :login => 'rhoadmin', :password => '' }) api_post('system/reset', {:api_token => api_token}) puts "reset OK" rescue Exception => e puts "reset_spec_server failed: #{e}" end end |
.rhoconnect_bin ⇒ Object
38 39 40 |
# File 'lib/build/rhoconnect_helper.rb', line 38 def self.rhoconnect_bin @@rhoconnect_bin end |
.set_enable_push(b) ⇒ Object
23 24 25 |
# File 'lib/build/rhoconnect_helper.rb', line 23 def self.set_enable_push(b) @@enable_push = b end |
.set_enable_rails(b) ⇒ Object
27 28 29 |
# File 'lib/build/rhoconnect_helper.rb', line 27 def self.set_enable_rails(b) # @@enable_rails = b end |
.set_enable_redis(b) ⇒ Object
@@enable_rails = true
15 16 17 |
# File 'lib/build/rhoconnect_helper.rb', line 15 def self.set_enable_redis(b) @@enable_redis = b end |
.set_enable_resque(b) ⇒ Object
19 20 21 |
# File 'lib/build/rhoconnect_helper.rb', line 19 def self.set_enable_resque(b) @@enable_resque = b end |
.set_rc_out(rc_out) ⇒ Object
58 59 60 |
# File 'lib/build/rhoconnect_helper.rb', line 58 def self.set_rc_out(rc_out) @@rc_out = rc_out end |
.set_rc_push_out(rc_push_out) ⇒ Object
73 74 75 |
# File 'lib/build/rhoconnect_helper.rb', line 73 def self.set_rc_push_out(rc_push_out) @@rc_push_out = rc_push_out end |
.set_redis_out(redis_out) ⇒ Object
68 69 70 |
# File 'lib/build/rhoconnect_helper.rb', line 68 def self.set_redis_out(redis_out) @@redis_out = redis_out end |
.set_resque_out(resque_out) ⇒ Object
63 64 65 |
# File 'lib/build/rhoconnect_helper.rb', line 63 def self.set_resque_out(resque_out) @@resque_out = resque_out end |
.set_rhoconnect_bin(path) ⇒ Object
33 34 35 36 |
# File 'lib/build/rhoconnect_helper.rb', line 33 def self.set_rhoconnect_bin(path) @@rhoconnect_path = path @@rhoconnect_bin = File.join(path, 'bin', 'rhoconnect') end |
.start_rails ⇒ Object
249 250 251 |
# File 'lib/build/rhoconnect_helper.rb', line 249 def self.start_rails #TODO end |
.start_redis ⇒ Object
112 113 114 |
# File 'lib/build/rhoconnect_helper.rb', line 112 def self.start_redis @@redis_pid = Kernel.spawn("redis-server", :out => @@redis_out ) end |
.start_resque ⇒ Object
121 122 123 |
# File 'lib/build/rhoconnect_helper.rb', line 121 def self.start_resque @@resque_pid = Kernel.spawn({ "QUEUE" => "*" }, "rake","resque:work",:chdir => @@server_path, :out => @@resque_out ) end |
.start_rhoconnect_push ⇒ Object
235 236 237 238 239 240 |
# File 'lib/build/rhoconnect_helper.rb', line 235 def self.start_rhoconnect_push @@rhoconnect_push_pid = Kernel.spawn("rhoconnect-push start -d 3", :out => @@rc_push_out) @@push_host = Jake.localip @@push_port = 8675 end |
.start_rhoconnect_stack(dir, reset = false) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/build/rhoconnect_helper.rb', line 160 def self.start_rhoconnect_stack(dir,reset = false) if @@enable_redis puts "run redis" start_redis sleep(10) end if @@enable_push puts "run rhoconnect push" start_rhoconnect_push sleep 10 end puts "run rhoconnect" start_server(dir) sleep(10) =begin if @@enable_rails puts "run rails" start_rails sleep 10 end =end if reset puts "reset rhoconnect" reset_server end if @@enable_resque puts "run resque" start_resque sleep(10) end end |
.start_server(dir) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/build/rhoconnect_helper.rb', line 89 def self.start_server(dir) @@server_path = dir if RUBY_PLATFORM =~ /(win|w)32$/ @@server_pid = Kernel.spawn("ruby",@@rhoconnect_bin,"start",:chdir=>@@server_path,:out =>@@rc_out) else @@server_pid = execute_rhoconnect(@@server_path,"startbg") end @@host = Jake.localip @@port = 9292 puts "started rhoconnect server, app path: #{@@server_path}, server_pid: #{@@server_pid}, host: #{@@host}, port: #{@@port}" end |
.stop_rails ⇒ Object
253 254 255 |
# File 'lib/build/rhoconnect_helper.rb', line 253 def self.stop_rails #TODO end |
.stop_redis ⇒ Object
116 117 118 119 |
# File 'lib/build/rhoconnect_helper.rb', line 116 def self.stop_redis Process.kill('INT', @@redis_pid) if @@redis_pid @@redis_pid = nil end |
.stop_resque ⇒ Object
125 126 127 128 |
# File 'lib/build/rhoconnect_helper.rb', line 125 def self.stop_resque Process.kill('INT', @@resque_pid) if @@resque_pid @@resque_pid = nil end |
.stop_rhoconnect_push ⇒ Object
242 243 244 245 246 247 |
# File 'lib/build/rhoconnect_helper.rb', line 242 def self.stop_rhoconnect_push Process.kill('INT', @@rhoconnect_push_pid) if @@rhoconnect_push_pid @@rhoconnect_push_pid = nil @@push_host = nil @@push_port = nil end |
.stop_rhoconnect_stack ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/build/rhoconnect_helper.rb', line 196 def self.stop_rhoconnect_stack if @@enable_resque puts "stop resque" stop_resque end puts "stop rhoconnect" stop_server =begin if @@enable_rails puts "stop rails" stop_rails end =end if @@enable_push puts "stop rhoconnect push" stop_rhoconnect_push end if @@enable_redis puts "stop redis" stop_redis end end |
.stop_server ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/build/rhoconnect_helper.rb', line 104 def self.stop_server execute_rhoconnect(@@server_path,"stop") @@server_pid = nil @@server_path = nil @@host = nil @@port = nil end |