rhoconnect 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +3 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +32 -27
- data/Rakefile +6 -2
- data/doc/benchmarks.txt +111 -7
- data/examples/simple/config.ru +1 -1
- data/examples/simple/dump.rdb +0 -0
- data/generators/templates/application/config.ru +5 -3
- data/installer/utils/nix_install_test.rb +5 -3
- data/installer/utils/nix_installation.rake +7 -3
- data/lib/rhoconnect/body_content_type_parser.rb +29 -0
- data/lib/rhoconnect/console/server.rb +3 -3
- data/lib/rhoconnect/cors.rb +1 -1
- data/lib/rhoconnect/server.rb +30 -34
- data/lib/rhoconnect/version.rb +1 -1
- data/rhoconnect.gemspec +2 -2
- data/spec/api/admin/stats_spec.rb +9 -4
- data/spec/api/api_helper.rb +1 -0
- data/spec/{rhosync_spec.rb → rhoconnect_spec.rb} +0 -0
- data/spec/server/cors_spec.rb +1 -1
- data/spec/server/server_spec.rb +7 -6
- metadata +14 -14
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rhoconnect (3.0.
|
4
|
+
rhoconnect (3.0.2)
|
5
5
|
bundler (~> 1.0)
|
6
6
|
json (~> 1.5.0)
|
7
7
|
rake (= 0.9.2)
|
8
8
|
redis (>= 2.2.0)
|
9
|
-
resque (~> 1.
|
9
|
+
resque (~> 1.18.0)
|
10
10
|
rest-client (~> 1.6.1)
|
11
11
|
rubyzip (~> 0.9.4)
|
12
|
-
sinatra (
|
12
|
+
sinatra (~> 1.3)
|
13
13
|
templater (~> 1.0.0)
|
14
14
|
uuidtools (>= 2.1.1)
|
15
15
|
|
@@ -17,37 +17,45 @@ GEM
|
|
17
17
|
remote: http://rubygems.org/
|
18
18
|
specs:
|
19
19
|
addressable (2.2.6)
|
20
|
-
|
20
|
+
builder (3.0.0)
|
21
21
|
crack (0.3.1)
|
22
|
-
dbd-jdbc (0.1.4)
|
23
|
-
dbi (0.4.5)
|
24
|
-
deprecated (= 2.0.1)
|
25
|
-
deprecated (2.0.1)
|
26
22
|
diff-lcs (1.1.3)
|
23
|
+
excon (0.7.6)
|
27
24
|
extlib (0.9.15)
|
28
25
|
ffaker (1.8.1)
|
26
|
+
fog (1.0.0)
|
27
|
+
builder
|
28
|
+
excon (~> 0.7.3)
|
29
|
+
formatador (~> 0.2.0)
|
30
|
+
mime-types
|
31
|
+
multi_json (~> 1.0.3)
|
32
|
+
net-scp (~> 1.0.4)
|
33
|
+
net-ssh (~> 2.1.4)
|
34
|
+
nokogiri (~> 1.5.0)
|
35
|
+
ruby-hmac
|
36
|
+
formatador (0.2.1)
|
29
37
|
fpm (0.3.9)
|
30
38
|
json
|
31
39
|
highline (1.6.2)
|
32
|
-
jdbc-sqlite3 (3.7.2)
|
33
|
-
jruby-jars (1.6.4)
|
34
|
-
jruby-openssl (0.7.4)
|
35
|
-
bouncy-castle-java
|
36
|
-
jruby-rack (1.0.10)
|
37
40
|
json (1.5.4)
|
38
|
-
json (1.5.4-java)
|
39
41
|
mime-types (1.16)
|
40
|
-
|
42
|
+
multi_json (1.0.3)
|
43
|
+
net-scp (1.0.4)
|
44
|
+
net-ssh (>= 1.99.1)
|
45
|
+
net-ssh (2.1.4)
|
46
|
+
nokogiri (1.5.0)
|
47
|
+
rack (1.3.4)
|
48
|
+
rack-protection (1.1.4)
|
49
|
+
rack
|
41
50
|
rack-test (0.6.1)
|
42
51
|
rack (>= 1.0)
|
43
52
|
rake (0.9.2)
|
44
53
|
rcov (0.9.10)
|
45
|
-
rcov (0.9.10-java)
|
46
54
|
redis (2.2.2)
|
47
55
|
redis-namespace (1.0.3)
|
48
56
|
redis (< 3.0.0)
|
49
|
-
resque (1.
|
50
|
-
|
57
|
+
resque (1.18.6)
|
58
|
+
multi_json (~> 1.0)
|
51
59
|
redis-namespace (~> 1.0.2)
|
52
60
|
sinatra (>= 0.9.2)
|
53
61
|
vegas (~> 0.1.2)
|
@@ -61,10 +69,12 @@ GEM
|
|
61
69
|
rspec-expectations (2.6.0)
|
62
70
|
diff-lcs (~> 1.1.2)
|
63
71
|
rspec-mocks (2.6.0)
|
72
|
+
ruby-hmac (0.4.0)
|
64
73
|
rubyzip (0.9.4)
|
65
|
-
sinatra (1.
|
66
|
-
rack (~> 1.
|
67
|
-
|
74
|
+
sinatra (1.3.1)
|
75
|
+
rack (>= 1.3.4, ~> 1.3)
|
76
|
+
rack-protection (>= 1.1.2, ~> 1.1)
|
77
|
+
tilt (>= 1.3.3, ~> 1.3)
|
68
78
|
sqlite3 (1.3.4)
|
69
79
|
templater (1.0.0)
|
70
80
|
diff-lcs (>= 1.1.2)
|
@@ -75,23 +85,18 @@ GEM
|
|
75
85
|
uuidtools (2.1.2)
|
76
86
|
vegas (0.1.8)
|
77
87
|
rack (>= 1.0.0)
|
78
|
-
warbler (1.3.2)
|
79
|
-
jruby-jars (>= 1.4.0)
|
80
|
-
jruby-rack (>= 1.0.0)
|
81
|
-
rake (>= 0.8.7)
|
82
|
-
rubyzip (>= 0.9.4)
|
83
88
|
webmock (1.6.4)
|
84
89
|
addressable (> 2.2.5, ~> 2.2)
|
85
90
|
crack (>= 0.1.7)
|
86
91
|
|
87
92
|
PLATFORMS
|
88
|
-
java
|
89
93
|
ruby
|
90
94
|
|
91
95
|
DEPENDENCIES
|
92
96
|
dbd-jdbc (>= 0.1.4)
|
93
97
|
dbi (>= 0.4.5)
|
94
98
|
ffaker (~> 1.8.0)
|
99
|
+
fog (>= 1.0.0)
|
95
100
|
fpm (>= 0.3.8)
|
96
101
|
jdbc-sqlite3 (>= 3.7.2)
|
97
102
|
jruby-openssl (>= 0.7.4)
|
data/Rakefile
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
load 'tasks/redis.rake'
|
3
|
+
load 'installer/utils/nix_installation.rake'
|
3
4
|
|
4
5
|
require 'bundler'
|
5
6
|
Bundler.setup(:default, :development, :test)
|
@@ -34,6 +35,7 @@ begin
|
|
34
35
|
RSpec::Core::RakeTask.new("spec:#{type}") do |t|
|
35
36
|
t.rspec_opts = ["-b", "-c", "-fd"]
|
36
37
|
t.pattern = FileList[TYPES[type]]
|
38
|
+
t.rcov = false
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
@@ -91,8 +93,8 @@ end
|
|
91
93
|
|
92
94
|
# Debian and RPM package building tasks
|
93
95
|
def build_pkg(dist, arch, deps)
|
94
|
-
|
95
|
-
workspace = "#{
|
96
|
+
start_dir = `pwd`.strip
|
97
|
+
workspace = "#{start_dir}/pkg/workspace"
|
96
98
|
version = Rhoconnect::VERSION
|
97
99
|
description = '"Rhoconnect production environment"'
|
98
100
|
post_install = "#{workspace}/unix-like/post-install.sh"
|
@@ -129,6 +131,8 @@ def build_pkg(dist, arch, deps)
|
|
129
131
|
system(fpm_cmd)
|
130
132
|
# Leave no trace...
|
131
133
|
system("rm -rf #{workspace}")
|
134
|
+
|
135
|
+
Dir.chdir(start_dir)
|
132
136
|
end #build_pkg
|
133
137
|
|
134
138
|
desc "Build Debian DEB rhoconnect-#{Rhoconnect::VERSION}_all.deb package into the pkg directory"
|
data/doc/benchmarks.txt
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
RhoConnect Benchmarks
|
2
2
|
===
|
3
3
|
|
4
|
-
Note, these numbers reflect synchronization performance using the rhoconnect bench
|
4
|
+
Note, these numbers reflect synchronization performance using the rhoconnect bench utilities (see the rhoconnect/bench folder for more information).
|
5
5
|
We will be adding more results as we test across different server environments.
|
6
6
|
|
7
|
-
|
7
|
+
## Single-core Amazon EC2 server environment
|
8
|
+
|
9
|
+
### Configuration
|
10
|
+
|
8
11
|
Servers configuration (Amazon EC2 'm1.small' instances) :
|
9
12
|
|
10
13
|
* CPU Units - 1 ECU
|
@@ -15,7 +18,6 @@ Servers configuration (Amazon EC2 'm1.small' instances) :
|
|
15
18
|
|
16
19
|
* Platform - Ubuntu (2.6.38-8-virtual)
|
17
20
|
|
18
|
-
|
19
21
|
Environment (instance #1):
|
20
22
|
|
21
23
|
* Nginx 1.0.0
|
@@ -77,7 +79,7 @@ Environment (instance #2):
|
|
77
79
|
Server instance #1 is running rhoconnect bench applications,
|
78
80
|
the 2nd one executes rhoconnect bench scripts.
|
79
81
|
|
80
|
-
|
82
|
+
### Bench application #1 (benchapp)
|
81
83
|
* Simulates creating multiple objects
|
82
84
|
|
83
85
|
* 100 concurrent users
|
@@ -100,7 +102,7 @@ Throughput(req/s) : 7.13629650622702
|
|
100
102
|
Throughput(req/min) : 428.177790373621
|
101
103
|
</pre>
|
102
104
|
|
103
|
-
|
105
|
+
### Bench application #2 (blobapp)
|
104
106
|
* Simulates creating multiple objects
|
105
107
|
|
106
108
|
* 100 concurrent users
|
@@ -123,7 +125,7 @@ Throughput(req/s) : 7.22833609137099
|
|
123
125
|
Throughput(req/min): 433.700165482259
|
124
126
|
</pre>
|
125
127
|
|
126
|
-
|
128
|
+
### Prepare bench applications for running on server #1
|
127
129
|
|
128
130
|
Go to rhoconnect/bench directory and configure benchapp application:
|
129
131
|
|
@@ -149,7 +151,7 @@ running by visiting its web concole, i.e. :
|
|
149
151
|
http://server_dns_public_name/console/
|
150
152
|
</pre>
|
151
153
|
|
152
|
-
|
154
|
+
### How to execute bench scripts on server #2
|
153
155
|
Before running bench scripts you need configure bench application settings properly.
|
154
156
|
|
155
157
|
Edit rhoconnect/bench/benchapp/settings/settings.yml and set redis and syncserver properties:
|
@@ -164,5 +166,107 @@ Do the same for blobapp settings.yml file.
|
|
164
166
|
|
165
167
|
Then from rhoconnect/becnh directory execute run_cud_script.sh and run_blob_script.sh scripts respectively.
|
166
168
|
|
169
|
+
## Multi-core Amazon EC2 server environments
|
170
|
+
|
171
|
+
### Configuration
|
172
|
+
|
173
|
+
Server configurations:
|
174
|
+
|
175
|
+
* Large (m1.large, 2 cores, 7.5GB memory)
|
176
|
+
|
177
|
+
* Extra Large (m1.xlarge, 4 cores, 15GB memory)
|
178
|
+
|
179
|
+
* High-CPU Extra Large (c1.xlarge, 8 cores, 7GB memory)
|
180
|
+
|
181
|
+
* Platform - Basic 64-bit Amazon Linux AMI 2011.09 (Red Hat based)
|
182
|
+
|
183
|
+
Software environment:
|
184
|
+
|
185
|
+
* Nginx 1.0.6
|
186
|
+
|
187
|
+
* Ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-linux], Ruby Enterprise Edition 2011.03
|
188
|
+
|
189
|
+
* Passenger 3.0.9
|
190
|
+
|
191
|
+
* Redis 2.2.14
|
192
|
+
|
193
|
+
* Rhoconnect 3.0.0
|
194
|
+
|
195
|
+
All above software are installed on servers by executing the following commands:
|
196
|
+
<pre>
|
197
|
+
sudo yum install make patch gcc-c++ zlib-devel curl-devel pcre-devel readline-devel openssl-devel
|
198
|
+
sudo rpm -i rhoconnect-3.0.0.noarch.rpm
|
199
|
+
</pre>
|
200
|
+
|
201
|
+
### Tested bench application (benchapp)
|
202
|
+
|
203
|
+
* Simulates creating multiple objects
|
204
|
+
|
205
|
+
* 100 concurrent users
|
206
|
+
|
207
|
+
* 1 device per user
|
208
|
+
|
209
|
+
* 20 object dataset
|
210
|
+
|
211
|
+
* each object has 7 attributes
|
212
|
+
|
213
|
+
### Prepare bench application for running on servers
|
167
214
|
|
215
|
+
1. Go to rhoconnect/bench directory and configure benchapp application:
|
216
|
+
<pre>
|
217
|
+
sudo cp -R benchapp /opt/nginx/html
|
218
|
+
cd /opt/nginx/html/benchapp
|
219
|
+
sudo /opt/rhoconnect/bin/bundle install --without=test development
|
220
|
+
sudo mkdir public
|
221
|
+
sudo chown -R nginx:nginx /opt/nginx/html/benchapp
|
222
|
+
</pre>
|
223
|
+
|
224
|
+
2. Edit '/opt/nginx/conf/conf.d/rhoconnect.conf' file and point root entry to <b>/opt/nginx/html/benchapp/public</b> directory:
|
225
|
+
<pre>
|
226
|
+
server {
|
227
|
+
listen 80;
|
228
|
+
root /opt/nginx/html/benchapp/public;
|
229
|
+
passenger_enabled on;
|
230
|
+
}
|
231
|
+
</pre>
|
232
|
+
|
233
|
+
3. Start redis and nginx servers:
|
234
|
+
<pre>
|
235
|
+
sudo /etc/init.d/redis start
|
236
|
+
sudo /etc/init.d/nginx start
|
237
|
+
</pre>
|
238
|
+
|
239
|
+
### Benchmark results for large (2 cores) server
|
240
|
+
<pre>
|
241
|
+
Request clientcreate : min: 0.0058, max: 1.0360, avg: 0.1138, err: 0, verification err: 0
|
242
|
+
Request ack-cud : min: 0.0258, max: 0.1998, avg: 0.0642, err: 0, verification err: 0
|
243
|
+
Request clientlogin : min: 0.0056, max: 0.0958, avg: 0.0128, err: 0, verification err: 0
|
244
|
+
Request get-cud : min: 0.0234, max: 0.1777, avg: 0.0476, err: 0, verification err: 0
|
245
|
+
Request create-object : min: 0.0526, max: 0.3074, avg: 0.1242, err: 0, verification err: 0
|
246
|
+
Throughput(req/s) : 8.40951725551376
|
247
|
+
Throughput(req/min): 504.571035330826
|
248
|
+
</pre>
|
249
|
+
|
250
|
+
### Benchmark results for extra large (4 cores) server
|
251
|
+
<pre>
|
252
|
+
Request clientcreate : min: 0.0080, max: 1.0194, avg: 0.0944, err: 0, verification err: 0
|
253
|
+
Request ack-cud : min: 0.0298, max: 0.1381, avg: 0.0573, err: 0, verification err: 0
|
254
|
+
Request clientlogin : min: 0.0091, max: 0.0591, avg: 0.0152, err: 0, verification err: 0
|
255
|
+
Request get-cud : min: 0.0259, max: 0.1679, avg: 0.0443, err: 0, verification err: 0
|
256
|
+
Request create-object : min: 0.0618, max: 0.2778, avg: 0.1112, err: 0, verification err: 0
|
257
|
+
Throughput(req/s) : 8.19117682939103
|
258
|
+
Throughput(req/min): 491.470609763462
|
259
|
+
</pre>
|
260
|
+
|
261
|
+
### Benchmark results for high-cpu extra large (8 cores) server
|
262
|
+
<pre>
|
263
|
+
Request clientcreate : min: 0.0083, max: 1.0162, avg: 0.0741, err: 0, verification err: 0
|
264
|
+
Request ack-cud : min: 0.0277, max: 0.1803, avg: 0.0525, err: 0, verification err: 0
|
265
|
+
Request clientlogin : min: 0.0092, max: 0.0681, avg: 0.0147, err: 0, verification err: 0
|
266
|
+
Request get-cud : min: 0.0259, max: 0.1729, avg: 0.0474, err: 0, verification err: 0
|
267
|
+
Request create-object : min: 0.0599, max: 0.2850, avg: 0.1102, err: 0, verification err: 0
|
268
|
+
Throughput(req/s) : 8.08355941878833
|
269
|
+
Throughput(req/min): 485.0135651273
|
270
|
+
</pre>
|
168
271
|
|
272
|
+
All above results produced by bench script <b>cud_script</b> hosted by large (2 cores) EC2 server.
|
data/examples/simple/config.ru
CHANGED
@@ -25,7 +25,7 @@ Rhoconnect::Server.disable :run
|
|
25
25
|
Rhoconnect::Server.disable :clean_trace
|
26
26
|
Rhoconnect::Server.enable :raise_errors
|
27
27
|
Rhoconnect::Server.set :root, ROOT_PATH
|
28
|
-
Rhoconnect::Server.enable :stats
|
28
|
+
#Rhoconnect::Server.enable :stats
|
29
29
|
Rhoconnect::Server.set :secret, '3ddaa72a36466bae3fc5e54c09324db50cfc30588d8dee1a2700e61195bdbbb5eeb65da2a184d274ce644b20b0e986046c2447730c85555ce18a4eb2fce7ebf5'
|
30
30
|
Rhoconnect::Server.use Rack::Static, :urls => ["/data"], :root => Rhoconnect::Server.root
|
31
31
|
|
data/examples/simple/dump.rdb
CHANGED
Binary file
|
@@ -3,9 +3,12 @@ require 'rubygems'
|
|
3
3
|
require 'bundler'
|
4
4
|
Bundler.require
|
5
5
|
|
6
|
+
ROOT_PATH = File.expand_path(File.dirname(__FILE__))
|
7
|
+
|
6
8
|
if ENV['DEBUG'] == 'yes'
|
7
|
-
|
8
|
-
|
9
|
+
ENV['APP_TYPE'] = 'rhosync'
|
10
|
+
ENV['ROOT_PATH'] = ROOT_PATH
|
11
|
+
require 'debugger'
|
9
12
|
end
|
10
13
|
|
11
14
|
# Try to load vendor-ed rhoconnect, otherwise load the gem
|
@@ -20,7 +23,6 @@ end
|
|
20
23
|
# By default, turn on the resque web console
|
21
24
|
require 'resque/server'
|
22
25
|
|
23
|
-
ROOT_PATH = File.expand_path(File.dirname(__FILE__))
|
24
26
|
|
25
27
|
# Rhoconnect server flags
|
26
28
|
Rhoconnect::Server.disable :run
|
@@ -1,9 +1,10 @@
|
|
1
|
-
|
1
|
+
$:.unshift File.expand_path(File.dirname(__FILE__))
|
2
|
+
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'installer', 'utils'))
|
2
3
|
|
3
|
-
require 'net/http'
|
4
|
-
require 'constants'
|
5
4
|
require 'rubygems'
|
6
5
|
require 'fog'
|
6
|
+
require 'net/http'
|
7
|
+
require 'constants'
|
7
8
|
require 'readline'
|
8
9
|
|
9
10
|
# METHODS
|
@@ -202,6 +203,7 @@ end #compute_time
|
|
202
203
|
|
203
204
|
# SCRIPT
|
204
205
|
|
206
|
+
### This part has been set as a dependency in the :test rake task
|
205
207
|
# Create Packages
|
206
208
|
|
207
209
|
# Creating debian package
|
@@ -1,3 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
namespace :rc_pkg do
|
2
|
+
desc 'Test creation and installation of both DEB and RPM rhoconnect packages.'
|
3
|
+
task :test => ['build:deb', 'build:rpm'] do
|
4
|
+
# Run installation test
|
5
|
+
sudo ruby "installer/utils/nix_install_test.rb"
|
6
|
+
end #:test
|
7
|
+
end #:rc_pkg
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Rhoconnect
|
2
|
+
class BodyContentTypeParser
|
3
|
+
|
4
|
+
# Constants
|
5
|
+
#
|
6
|
+
CONTENT_TYPE = 'CONTENT_TYPE'.freeze
|
7
|
+
POST_BODY = 'rack.input'.freeze
|
8
|
+
FORM_INPUT = 'rack.request.form_input'.freeze
|
9
|
+
FORM_HASH = 'rack.request.form_hash'.freeze
|
10
|
+
|
11
|
+
def initialize(app)
|
12
|
+
@app = app
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
if env['CONTENT_TYPE'] && env['CONTENT_TYPE'].match(/^application\/json/)
|
17
|
+
begin
|
18
|
+
if (body = env[POST_BODY].read).length != 0
|
19
|
+
env.update(FORM_HASH => JSON.parse(body), FORM_INPUT => env[POST_BODY])
|
20
|
+
end
|
21
|
+
rescue JSON::ParserError => jpe
|
22
|
+
log jpe.message + jpe.backtrace.join("\n")
|
23
|
+
return [500, {'Content-Type' => 'text/plain'}, ["Server error while processing client data"]]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
@app.call(env)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -14,9 +14,9 @@ module RhoconnectConsole
|
|
14
14
|
end
|
15
15
|
|
16
16
|
class Server < Sinatra::Base
|
17
|
-
set :views,
|
18
|
-
set :
|
19
|
-
set :static,
|
17
|
+
set :views, RhoconnectConsole::root_path("app","views")
|
18
|
+
set :public_folder, RhoconnectConsole::root_path("app","public")
|
19
|
+
set :static, true
|
20
20
|
use Rack::Session::Cookie
|
21
21
|
HEROKU_NAV = ENV['INSTANCE_ID'] ? RestClient.get('http://nav.heroku.com/v1/providers/header') : nil
|
22
22
|
before do
|
data/lib/rhoconnect/cors.rb
CHANGED
@@ -18,7 +18,7 @@ module Rack
|
|
18
18
|
env['HTTP_ORIGIN'] = 'file://'
|
19
19
|
end
|
20
20
|
if env['HTTP_X_ORIGIN'] and not env['HTTP_ORIGIN']
|
21
|
-
|
21
|
+
log 'ORIGIN header is empty, X-ORIGIN workaround header applied.'
|
22
22
|
env['HTTP_ORIGIN'] = env['HTTP_X_ORIGIN']
|
23
23
|
end
|
24
24
|
cors_headers = nil
|
data/lib/rhoconnect/server.rb
CHANGED
@@ -3,8 +3,10 @@ require 'sinatra/base'
|
|
3
3
|
require 'erb'
|
4
4
|
require 'json'
|
5
5
|
require 'fileutils'
|
6
|
+
#require 'rack/contrib'
|
6
7
|
require 'rhoconnect'
|
7
8
|
require 'rhoconnect/x_domain_session_wrapper'
|
9
|
+
require 'rhoconnect/body_content_type_parser'
|
8
10
|
require 'rhoconnect/cors'
|
9
11
|
|
10
12
|
module Rhoconnect
|
@@ -19,15 +21,13 @@ module Rhoconnect
|
|
19
21
|
|
20
22
|
class Server < Sinatra::Base
|
21
23
|
libdir = File.dirname(File.expand_path(__FILE__))
|
22
|
-
set :views,
|
23
|
-
set :
|
24
|
-
set :static,
|
25
|
-
|
24
|
+
set :views, "#{libdir}/server/views"
|
25
|
+
set :public_folder, "#{libdir}/server/public"
|
26
|
+
set :static, true
|
27
|
+
set :stats, false
|
28
|
+
|
26
29
|
# default secret
|
27
30
|
@@secret = '<changeme>'
|
28
|
-
|
29
|
-
# stats middleware disabled by default
|
30
|
-
@@stats = false
|
31
31
|
|
32
32
|
# Setup route and mimetype for bulk data downloads
|
33
33
|
# TODO: Figure out why "mime :data, 'application/octet-stream'" doesn't work
|
@@ -62,7 +62,7 @@ module Rhoconnect
|
|
62
62
|
def login
|
63
63
|
if params[:login] == 'rhoadmin'
|
64
64
|
user = User.authenticate(params[:login], params[:password])
|
65
|
-
elsif current_app and current_app.can_authenticate?
|
65
|
+
elsif current_app and current_app.can_authenticate? and params[:login]
|
66
66
|
user = current_app.authenticate(params[:login], params[:password], session)
|
67
67
|
end
|
68
68
|
if user
|
@@ -151,7 +151,7 @@ module Rhoconnect
|
|
151
151
|
def mark_deprecated_call_and_reroute(name, namespace, *params)
|
152
152
|
namespace_val = namespace.nil? ? "<namespace>" : "#{namespace}"
|
153
153
|
http_method = request.get? ? "GET" : "POST"
|
154
|
-
warning_message = "Use of the #{http_method} #{request.
|
154
|
+
warning_message = "Use of the #{http_method} #{request.path} is deprecated. Use #{http_method} /api/#{namespace_val}/#{name} instead."
|
155
155
|
response.headers['Warning'] = warning_message
|
156
156
|
Rhoconnect.log warning_message
|
157
157
|
if namespace != nil
|
@@ -177,17 +177,10 @@ module Rhoconnect
|
|
177
177
|
end
|
178
178
|
end
|
179
179
|
|
180
|
+
# TODO: Load middleware statically
|
180
181
|
# hook into new so we can enable middleware
|
181
182
|
def self.new
|
182
|
-
if @@stats == true
|
183
|
-
use Rhoconnect::Stats::Middleware
|
184
|
-
Rhoconnect.stats = true
|
185
|
-
end
|
186
183
|
use XDomainSessionWrapper
|
187
|
-
use Rack::Session::Cookie,
|
188
|
-
:key => 'rhoconnect_session',
|
189
|
-
:expire_after => Rhoconnect.cookie_expire,
|
190
|
-
:secret => @@secret
|
191
184
|
use Rack::Cors do |cfg|
|
192
185
|
cfg.allow do |allow|
|
193
186
|
allow.origins /.*/
|
@@ -197,18 +190,27 @@ module Rhoconnect
|
|
197
190
|
allow.resource '/api/application/*', :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
|
198
191
|
end
|
199
192
|
end
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
193
|
+
use Rhoconnect::BodyContentTypeParser
|
194
|
+
|
195
|
+
if settings.respond_to?(:stats) and settings.send(:stats) == true
|
196
|
+
use Rhoconnect::Stats::Middleware
|
197
|
+
Rhoconnect.stats = true
|
198
|
+
else
|
199
|
+
Rhoconnect::Server.disable :stats
|
200
|
+
Rhoconnect.stats = false
|
201
|
+
end
|
202
|
+
|
203
|
+
Rhoconnect::Server.set :secret, @@secret unless settings.respond_to?(:secret)
|
204
|
+
use Rack::Session::Cookie,
|
205
|
+
:key => 'rhoconnect_session',
|
206
|
+
:expire_after => Rhoconnect.cookie_expire,
|
207
|
+
:secret => Rhoconnect::Server.secret
|
206
208
|
super
|
207
209
|
end
|
208
210
|
|
209
211
|
def initialize
|
210
212
|
# Whine about default session secret
|
211
|
-
check_default_secret!(
|
213
|
+
check_default_secret!(Rhoconnect::Server.secret)
|
212
214
|
super
|
213
215
|
end
|
214
216
|
|
@@ -223,12 +225,7 @@ module Rhoconnect
|
|
223
225
|
cud = JSON.parse(params["cud"])
|
224
226
|
params.delete("cud")
|
225
227
|
params.merge!(cud)
|
226
|
-
end
|
227
|
-
#application/json; charset=UTF-8
|
228
|
-
if request.env['CONTENT_TYPE'] && request.env['CONTENT_TYPE'].match(/^application\/json/)
|
229
|
-
params.merge!(JSON.parse(request.body.read))
|
230
|
-
request.body.rewind
|
231
|
-
end
|
228
|
+
end
|
232
229
|
rescue JSON::ParserError => jpe
|
233
230
|
log jpe.message + jpe.backtrace.join("\n")
|
234
231
|
throw :halt, [500, "Server error while processing client data"]
|
@@ -239,7 +236,6 @@ module Rhoconnect
|
|
239
236
|
if params[:version] and params[:version].to_i < 3
|
240
237
|
throw :halt, [404, "Server supports version 3 or higher of the protocol."]
|
241
238
|
end
|
242
|
-
#log "request params: #{params.inspect}"
|
243
239
|
end
|
244
240
|
|
245
241
|
%w[get post].each do |verb|
|
@@ -272,12 +268,12 @@ module Rhoconnect
|
|
272
268
|
def self.api(name, namespace = nil, verb = :post, &block)
|
273
269
|
old_api_prefix = (namespace == :application) ? :application : :api
|
274
270
|
client_call = (namespace == :application) ? true : false
|
275
|
-
send verb, "/#{old_api_prefix}/#{name}" do
|
276
|
-
mark_deprecated_call_and_reroute(name, namespace, &block)
|
271
|
+
send verb, "/#{old_api_prefix}/#{name}" do
|
272
|
+
mark_deprecated_call_and_reroute(name, namespace, params, &block)
|
277
273
|
end
|
278
274
|
|
279
275
|
send verb, "/api/#{namespace}/#{name}" do
|
280
|
-
execute_api_call
|
276
|
+
execute_api_call(client_call, &block)
|
281
277
|
end
|
282
278
|
end
|
283
279
|
end
|
data/lib/rhoconnect/version.rb
CHANGED
data/rhoconnect.gemspec
CHANGED
@@ -37,13 +37,13 @@ Gem::Specification.new do |s|
|
|
37
37
|
]
|
38
38
|
|
39
39
|
s.add_dependency('bundler', '~> 1.0')
|
40
|
-
s.add_dependency("sinatra", '
|
40
|
+
s.add_dependency("sinatra", '~> 1.3')
|
41
41
|
s.add_dependency('rake', '0.9.2')
|
42
42
|
s.add_dependency('json', '~> 1.5.0')
|
43
43
|
s.add_dependency('rubyzip', '~> 0.9.4')
|
44
44
|
s.add_dependency('uuidtools', '>= 2.1.1')
|
45
45
|
s.add_dependency('redis', '>= 2.2.0')
|
46
|
-
s.add_dependency('resque', '~> 1.
|
46
|
+
s.add_dependency('resque', '~> 1.18.0')
|
47
47
|
s.add_dependency('rest-client', '~> 1.6.1')
|
48
48
|
s.add_dependency('templater', '~> 1.0.0')
|
49
49
|
end
|
@@ -2,12 +2,17 @@ require File.join(File.dirname(__FILE__),'..','api_helper')
|
|
2
2
|
|
3
3
|
describe "RhoconnectApiStats" do
|
4
4
|
it_should_behave_like "ApiHelper" do
|
5
|
+
|
6
|
+
def app
|
7
|
+
@app ||= Rhoconnect::Server.new
|
8
|
+
end
|
9
|
+
|
5
10
|
before(:each) do
|
6
|
-
Rhoconnect.stats
|
11
|
+
Rhoconnect::Server.set :stats, true
|
7
12
|
end
|
8
|
-
|
13
|
+
|
9
14
|
after(:each) do
|
10
|
-
Rhoconnect.stats
|
15
|
+
Rhoconnect::Server.set :stats, false
|
11
16
|
end
|
12
17
|
|
13
18
|
it "should retrieve metric names" do
|
@@ -54,7 +59,7 @@ describe "RhoconnectApiStats" do
|
|
54
59
|
end
|
55
60
|
|
56
61
|
it "should raise error if stats not enabled" do
|
57
|
-
Rhoconnect.stats
|
62
|
+
Rhoconnect::Server.set :stats, false
|
58
63
|
post "/api/admin/stats", {
|
59
64
|
:api_token => @api_token,
|
60
65
|
:metric => 'foo'
|
data/spec/api/api_helper.rb
CHANGED
File without changes
|
data/spec/server/cors_spec.rb
CHANGED
data/spec/server/server_spec.rb
CHANGED
@@ -32,7 +32,7 @@ describe "Server" do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should login if content-type contains extra parameters" do
|
35
|
-
post "/api/admin/login", {"login" => 'rhoadmin', "password" => ''}.to_json, {'CONTENT_TYPE'=>'application/json; charset=UTF-8'}
|
35
|
+
post "/api/admin/login", {"login" => 'rhoadmin', "password" => ''}.to_json, {'CONTENT_TYPE'=>'application/json; charset=UTF-8'}
|
36
36
|
last_response.should be_ok
|
37
37
|
end
|
38
38
|
|
@@ -56,11 +56,13 @@ describe "Server" do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should use Stats::Middleware if stats enabled" do
|
59
|
+
Rhoconnect::Server.server = nil
|
59
60
|
Rhoconnect::Server.enable :stats
|
60
61
|
Rhoconnect::Server.new
|
61
62
|
Rhoconnect.stats.should == true
|
62
63
|
Rhoconnect.stats = nil
|
63
64
|
Rhoconnect::Server.disable :stats
|
65
|
+
Rhoconnect::Server.server = nil
|
64
66
|
end
|
65
67
|
|
66
68
|
it "should update session secret to default" do
|
@@ -253,11 +255,10 @@ describe "Server" do
|
|
253
255
|
last_response.body.should == "Server error while processing client data"
|
254
256
|
end
|
255
257
|
|
256
|
-
it "should
|
257
|
-
|
258
|
-
|
259
|
-
last_response.
|
260
|
-
last_response.body.should == "Internal server error"
|
258
|
+
it "should not login if login is empty" do
|
259
|
+
post "/api/application/clientlogin", ''
|
260
|
+
last_response.status.should == 401
|
261
|
+
last_response.body.should == ""
|
261
262
|
end
|
262
263
|
|
263
264
|
it "should get inserts json" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhoconnect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 3
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 3.0.
|
9
|
+
- 2
|
10
|
+
version: 3.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Rhomobile
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-05 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
type: :runtime
|
@@ -38,14 +38,13 @@ dependencies:
|
|
38
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
|
-
- -
|
41
|
+
- - ~>
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
hash:
|
43
|
+
hash: 9
|
44
44
|
segments:
|
45
45
|
- 1
|
46
|
-
-
|
47
|
-
|
48
|
-
version: 1.2.7
|
46
|
+
- 3
|
47
|
+
version: "1.3"
|
49
48
|
version_requirements: *id002
|
50
49
|
name: sinatra
|
51
50
|
- !ruby/object:Gem::Dependency
|
@@ -136,12 +135,12 @@ dependencies:
|
|
136
135
|
requirements:
|
137
136
|
- - ~>
|
138
137
|
- !ruby/object:Gem::Version
|
139
|
-
hash:
|
138
|
+
hash: 95
|
140
139
|
segments:
|
141
140
|
- 1
|
142
|
-
-
|
141
|
+
- 18
|
143
142
|
- 0
|
144
|
-
version: 1.
|
143
|
+
version: 1.18.0
|
145
144
|
version_requirements: *id008
|
146
145
|
name: resque
|
147
146
|
- !ruby/object:Gem::Dependency
|
@@ -369,6 +368,7 @@ files:
|
|
369
368
|
- lib/rhoconnect/api/user/update_user.rb
|
370
369
|
- lib/rhoconnect/api_token.rb
|
371
370
|
- lib/rhoconnect/app.rb
|
371
|
+
- lib/rhoconnect/body_content_type_parser.rb
|
372
372
|
- lib/rhoconnect/bulk_data/bulk_data.rb
|
373
373
|
- lib/rhoconnect/bulk_data/syncdb.index.schema
|
374
374
|
- lib/rhoconnect/bulk_data/syncdb.schema
|
@@ -538,7 +538,7 @@ files:
|
|
538
538
|
- spec/ping/apple_spec.rb
|
539
539
|
- spec/ping/blackberry_spec.rb
|
540
540
|
- spec/read_state_spec.rb
|
541
|
-
- spec/
|
541
|
+
- spec/rhoconnect_spec.rb
|
542
542
|
- spec/server/cors_spec.rb
|
543
543
|
- spec/server/server_spec.rb
|
544
544
|
- spec/server/x_domain_session_wrapper_spec.rb
|
@@ -663,7 +663,7 @@ test_files:
|
|
663
663
|
- spec/ping/apple_spec.rb
|
664
664
|
- spec/ping/blackberry_spec.rb
|
665
665
|
- spec/read_state_spec.rb
|
666
|
-
- spec/
|
666
|
+
- spec/rhoconnect_spec.rb
|
667
667
|
- spec/server/cors_spec.rb
|
668
668
|
- spec/server/server_spec.rb
|
669
669
|
- spec/server/x_domain_session_wrapper_spec.rb
|