rhoconnect 4.0.0.beta.10 → 4.0.0.beta.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/CHANGELOG.md +11 -0
  2. data/Gemfile.lock +6 -6
  3. data/Rakefile +1 -1
  4. data/commands/generators/controller.rb +1 -1
  5. data/commands/generators/model.rb +1 -1
  6. data/doc/deploying.txt +41 -38
  7. data/doc/source-adapters-js.txt +263 -0
  8. data/generators/templates/application/controllers/js/application_controller.js +6 -4
  9. data/generators/templates/source/controllers/js/controller.js +4 -4
  10. data/generators/templates/source/models/js/model.js +3 -1
  11. data/install.sh +76 -6
  12. data/installer/utils/constants.rb +4 -4
  13. data/js-adapters/ballroom.js +6 -7
  14. data/js-adapters/node_channel.rb +14 -8
  15. data/js-adapters/request.js +7 -8
  16. data/js-adapters/response.js +10 -2
  17. data/js-adapters/rhoconnect_helpers.js +34 -33
  18. data/js-adapters/router.js +15 -12
  19. data/lib/rhoconnect/controller/js_base.rb +2 -7
  20. data/lib/rhoconnect/document.rb +1 -1
  21. data/lib/rhoconnect/model/base.rb +25 -10
  22. data/lib/rhoconnect/model/js_base.rb +4 -3
  23. data/lib/rhoconnect/source.rb +15 -1
  24. data/lib/rhoconnect/version.rb +1 -1
  25. data/spec/apps/rhotestapp/models/js/js_sample.js +61 -14
  26. data/spec/apps/rhotestapp/models/ruby/sample_adapter.rb +5 -0
  27. data/spec/controllers/js_base_spec.rb +16 -11
  28. data/spec/models/js_model_spec.rb +68 -7
  29. data/spec/server/server_spec.rb +28 -0
  30. data/spec/source_adapter_spec.rb +0 -11
  31. data/spec/source_spec.rb +39 -0
  32. data/spec/spec_helper.rb +11 -0
  33. metadata +4 -44
  34. data/lib/rhoconnect/api/app/ans_login.rb +0 -3
  35. data/lib/rhoconnect/api/app/bulk_data.rb +0 -10
  36. data/lib/rhoconnect/api/app/fast_delete.rb +0 -11
  37. data/lib/rhoconnect/api/app/fast_insert.rb +0 -11
  38. data/lib/rhoconnect/api/app/fast_update.rb +0 -11
  39. data/lib/rhoconnect/api/app/login.rb +0 -5
  40. data/lib/rhoconnect/api/app/push_deletes.rb +0 -12
  41. data/lib/rhoconnect/api/app/push_objects.rb +0 -12
  42. data/lib/rhoconnect/api/app/query.rb +0 -8
  43. data/lib/rhoconnect/api/app/queue_updates.rb +0 -98
  44. data/lib/rhoconnect/api/app/search.rb +0 -8
  45. data/lib/rhoconnect/api/client/client_get_db_doc.rb +0 -5
  46. data/lib/rhoconnect/api/client/client_set_db_doc.rb +0 -8
  47. data/lib/rhoconnect/api/client/create.rb +0 -7
  48. data/lib/rhoconnect/api/client/get_client_params.rb +0 -4
  49. data/lib/rhoconnect/api/client/list_client_docs.rb +0 -17
  50. data/lib/rhoconnect/api/client/register.rb +0 -12
  51. data/lib/rhoconnect/api/client/reset.rb +0 -5
  52. data/lib/rhoconnect/api/readstate/set_refresh_time.rb +0 -9
  53. data/lib/rhoconnect/api/source/get_source_params.rb +0 -4
  54. data/lib/rhoconnect/api/source/list_sources.rb +0 -16
  55. data/lib/rhoconnect/api/source/update_source_params.rb +0 -6
  56. data/lib/rhoconnect/api/store/get_db_doc.rb +0 -4
  57. data/lib/rhoconnect/api/store/set_db_doc.rb +0 -7
  58. data/lib/rhoconnect/api/system/get_adapter.rb +0 -4
  59. data/lib/rhoconnect/api/system/get_license_info.rb +0 -9
  60. data/lib/rhoconnect/api/system/login.rb +0 -15
  61. data/lib/rhoconnect/api/system/reset.rb +0 -11
  62. data/lib/rhoconnect/api/system/save_adapter.rb +0 -4
  63. data/lib/rhoconnect/api/system/stats.rb +0 -22
  64. data/lib/rhoconnect/api/user/create_user.rb +0 -7
  65. data/lib/rhoconnect/api/user/delete_client.rb +0 -6
  66. data/lib/rhoconnect/api/user/delete_user.rb +0 -11
  67. data/lib/rhoconnect/api/user/list_clients.rb +0 -4
  68. data/lib/rhoconnect/api/user/list_source_docs.rb +0 -11
  69. data/lib/rhoconnect/api/user/list_users.rb +0 -3
  70. data/lib/rhoconnect/api/user/ping.rb +0 -3
  71. data/lib/rhoconnect/api/user/show_user.rb +0 -3
  72. data/lib/rhoconnect/api/user/update_user.rb +0 -5
  73. data/lib/rhoconnect/api/user/user_get_db_doc.rb +0 -5
  74. data/lib/rhoconnect/api/user/user_set_db_doc.rb +0 -10
data/install.sh CHANGED
@@ -46,7 +46,7 @@ checkDeps ()
46
46
  }
47
47
 
48
48
  # determinePkgMgr
49
- # Determines if the system is currently using rpm or
49
+ # Determines if the system is currently using rpm or
50
50
  # debian based pckage management
51
51
  determinePkgMgr ()
52
52
  {
@@ -195,7 +195,7 @@ installRuby ()
195
195
  echo "tar -xzf ${prefix}/${rubyTar} -C ${prefix}" >> $log
196
196
  tar -xzf ${prefix}/${rubyTar} -C ${prefix} > /dev/null 2>&1
197
197
  fi
198
-
198
+
199
199
  echo "Installing ruby. This may take some time..." | tee -a $log
200
200
  echo "pushd ${prefix}/${rubyDir}" | tee -a $log
201
201
  pushd ${prefix}/${rubyDir}
@@ -204,14 +204,14 @@ installRuby ()
204
204
  echo "make && make install" | tee -a $log
205
205
  make >> $log 2>&1
206
206
  make install >> $log 2>&1
207
-
207
+
208
208
  if (( $? )) ; then
209
209
  echo "Some dependencies not installed..." | tee -a $log
210
210
  echo "Please install them and then re-run the installation script." | tee -a $log
211
211
  echo "For troubleshooting see file $log ..." | tee -a $log
212
212
  exit 1
213
213
  fi
214
-
214
+
215
215
  popd
216
216
  echo -e "$rubyDir is successfully installed.\n" | tee -a $log
217
217
  }
@@ -257,10 +257,15 @@ webServer=""
257
257
  rubyVersion=""
258
258
  rubyBinDir=""
259
259
 
260
- # Define ruby vession to be installed ...
260
+ # Define ruby and nodejs versions to be installed ...
261
261
  RUBY_PATCH="p392"
262
262
  RUBY_VERSION="ruby-1.9.3-${RUBY_PATCH}"
263
263
 
264
+ NODE_VERSION=v0.10.4
265
+ NODE_URL=http://nodejs.org/dist/${NODE_VERSION}/node-${NODE_VERSION}.tar.gz
266
+ ARCH=$([[ `uname -m` == x86_64 ]] && echo "x64" || echo "x86")
267
+ NODE_BIN_URL=http://nodejs.org/dist/${NODE_VERSION}/node-${NODE_VERSION}-linux-${ARCH}.tar.gz
268
+
264
269
  # parse command-line options
265
270
  parseOpts "$*"
266
271
 
@@ -293,10 +298,75 @@ fi
293
298
  # Install redis, sqllite3, nginx, rhoconnect
294
299
  opts=" -d $dist -l $log"
295
300
  ${prefix}/bin/ruby ${INSTALL_DIR}/unix-like/rhoinstaller.rb ${opts}
296
- if (( $? )) ; then
301
+ if (( $? )) ; then
297
302
  echo "Installation failed. For troubleshooting see file $log ..." | tee -a $log
298
303
  exit 1
299
304
  fi
300
305
 
306
+
307
+ ##################################################################################
308
+ # Install nodejs
309
+ echo
310
+ echo "Downloading ${NODE_URL} file ..." | tee -a $log
311
+ wget ${NODE_URL} -O node-${NODE_VERSION}.tar.gz -o /dev/null
312
+ tar -xzf node-${NODE_VERSION}.tar.gz > /dev/null 2>&1
313
+
314
+ echo "Building nodejs $NODE_VERSION ..." | tee -a $log
315
+ cd node-${NODE_VERSION}/
316
+ # Cent OS/RHEL 5 requires python 2.6
317
+ export PYTHON=`which python26 2> /dev/null`
318
+ $PYTHON ./configure --prefix=$prefix >> $log 2>&1
319
+ make >> $log 2>&1
320
+ make install >> $log 2>&1
321
+ if [[ $? != 0 ]]; then
322
+ echo "Installation of nodejs $NODE_VERSION is failed. For troubleshooting see file $log ..." | tee -a $log
323
+ exit
324
+ fi
325
+ cd ../
326
+ rm node-${NODE_VERSION}.tar.gz
327
+ rm -rf node-${NODE_VERSION}/
328
+
329
+ echo "nodejs $NODE_VERSION is successfully installed" | tee -a $log
330
+ echo
331
+
332
+ # TODO:
333
+ # if [ -e /etc/redhat-release ] ; then
334
+ # grep '5\.[0-9]\{1,2\}' /etc/redhat-release > /dev/null
335
+ # CentOS5=$?
336
+ # else
337
+ # CentOS5=1
338
+ # fi
339
+ # if [ $CentOS5 -eq 0 ] ; then
340
+ # echo "CentOS 5.x is found ..."
341
+ # echo "Downloading ${NODE_URL} source file ..." | tee -a $log
342
+ # wget ${NODE_URL} -O node-${NODE_VERSION}.tar.gz -o /dev/null
343
+ # tar -xzf node-${NODE_VERSION}.tar.gz > /dev/null 2>&1
344
+ # echo "Building nodejs $NODE_VERSION ..." | tee -a $log
345
+ # cd node-${NODE_VERSION}/
346
+ # # Cent OS/RHEL 5 requires python 2.6
347
+ # export PYTHON=`which python26 2> /dev/null`
348
+ # $PYTHON ./configure --prefix=$prefix >> $log 2>&1
349
+ # make >> $log 2>&1
350
+ # make install >> $log 2>&1
351
+ # if [[ $? != 0 ]]; then
352
+ # echo "Installation of nodejs $NODE_VERSION is failed. For troubleshooting see file $log ..." | tee -a $log
353
+ # exit
354
+ # fi
355
+ # cd ../
356
+ # rm node-${NODE_VERSION}.tar.gz
357
+ # rm -rf node-${NODE_VERSION}/
358
+ # else
359
+ # echo "Downloading ${NODE_BIN_URL} linux binary file ..." | tee -a $log
360
+ # wget ${NODE_BIN_URL} -O node-${NODE_VERSION}-linux-${ARCH}.tar.gz -o /dev/null
361
+ # path=`pwd`
362
+ # pushd ${prefix}
363
+ # tar xzf ${path}/node-${NODE_VERSION}-linux-${ARCH}.tar.gz --strip=1 > /dev/null 2>&1
364
+ # popd
365
+ # fi
366
+ # echo "nodejs $NODE_VERSION is successfully installed" | tee -a $log
367
+ #
368
+
369
+ ##################################################################################
370
+
301
371
  # Create configuration scripts for redis, nginx, thin.
302
372
  ${prefix}/bin/ruby ${INSTALL_DIR}/unix-like/create_texts.rb ${opts}
@@ -12,19 +12,19 @@ module Constants
12
12
  SSH_KEY = "#{HOME_DIR}/.ssh/#{PEM_FILE}"
13
13
  ACCESS_KEY_FILE = "#{HOME_DIR}/.ec2"
14
14
  UBUNTU_STACK = { :image_id => 'ami-02d7f547', # jenkins-ubuntu-12.04-test-image
15
- :tags => {'Name' => 'Ubuntu-12.04'},
15
+ :tags => {'Name' => 'Ubuntu-12.04'},
16
16
  :flavor_id => 'c1.xlarge',
17
17
  :key_name => 'jenkinskey',
18
18
  :groups => 'load-test',
19
19
  :user => 'ubuntu'}
20
- CENTOS5_STACK = { :image_id => 'ami-6aaf8d2f', # jenkins-centos-5.9-test-image
21
- :tags => {'Name' => 'CentOS-5.9'},
20
+ CENTOS5_STACK = { :image_id => 'ami-bed9f5fb', # jenkins-centos-5.9-test-image
21
+ :tags => {'Name' => 'CentOS-5.9'},
22
22
  :flavor_id => 'c1.xlarge',
23
23
  :key_name => 'jenkinskey',
24
24
  :groups => 'load-test',
25
25
  :user => 'root'}
26
26
  CENTOS6_STACK = { :image_id => 'ami-02ae8c47', # jenkins-centos-6.3-test-image
27
- :tags => {'Name' => 'CentOS-6.3'},
27
+ :tags => {'Name' => 'CentOS-6.3'},
28
28
  :flavor_id => 'c1.xlarge',
29
29
  :key_name => 'jenkinskey',
30
30
  :groups => 'load-test',
@@ -6,7 +6,8 @@ var redis = require('redis'),
6
6
  routes = require('./router'),
7
7
  client_sub = redis.createClient(),
8
8
  client_pub = redis.createClient(),
9
- pub_channel = process.argv[2] + "RedisPUB";
9
+ pub_channel = process.argv[2] + "RedisPUB",
10
+ rcHelpers = require('./rhoconnect_helpers');
10
11
 
11
12
  //define global hash functions to store callbacks, routes
12
13
  rhoconnectCallbacks = {};
@@ -176,11 +177,6 @@ var defaults = function(hsh){
176
177
 
177
178
  var format_options = function(opts){
178
179
  return JSON.stringify(opts);
179
- // var f_opts = "";
180
- // for(var propt in opts){
181
- // f_opts += propt + ":" + opts[propt];
182
- // }
183
- // return f_opts;
184
180
  };
185
181
 
186
182
  function guid() {
@@ -213,4 +209,7 @@ exports.put = put;
213
209
  exports.del = del;
214
210
  exports.post = post;
215
211
  exports.defaults = defaults;
216
- exports.exitNodejs = exitNodejs;
212
+ exports.exitNodejs = exitNodejs;
213
+ exports.stashResult = rcHelpers.stashResult;
214
+ exports.source = rcHelpers.source;
215
+ module.exports.Store = rcHelpers.Store;
@@ -96,7 +96,8 @@ module Rhoconnect
96
96
  rescue Exception=>e
97
97
  RESULT_HASH[key][:status] = 'broken'
98
98
  RESULT_HASH[key][:result] = "exception #{e.message}\n#{e.backtrace}"
99
- puts "Timeout on wait, setting JavaScript result state to broken: #{e.inspect}"
99
+ log "Timeout on wait, setting JavaScript result state to broken: #{e.inspect}"
100
+ log e.backtrace.join("\n")
100
101
  end
101
102
 
102
103
  #request waiting either timed out or returned response
@@ -151,24 +152,29 @@ module Rhoconnect
151
152
  end
152
153
 
153
154
  def process_message(curr_model,data)
154
- #puts "proccessing msg #{data}"
155
- if curr_model.respond_to?(data['function'])
155
+ # puts "proccessing msg #{data.inspect}"
156
+ klass = curr_model
157
+ klass = Object.const_get(data['kls']) if data['kls']
158
+ if klass.respond_to?(data['function'].to_sym)
156
159
  if data['args'] and data['args'].size > 0
157
160
  if(data['function'] == 'stash_result')
158
- curr_model.send('result=',data['args'])
159
- curr_model.send(data['function'])
161
+ klass.send('result=',data['args'])
162
+ klass.send(data['function'])
160
163
  process_res = nil
161
164
  else
162
- res = curr_model.send(data['function'],data['args'])
165
+ res = klass.send(data['function'],*data['args'])
163
166
  end
164
167
  else
165
- res = curr_model.send(data['function'])
168
+ res = klass.send(data['function'])
166
169
  end
167
170
  else
168
171
  raise Exception.new("Method #{data['function']} not found in model #{curr_model.class.name.to_s}.")
169
172
  end
170
173
 
171
- process_res = res.is_a?(String) ? res : res.to_hash if res
174
+ process_res = res
175
+ unless res.is_a?(String) or res.is_a?(TrueClass) or res.is_a?(FalseClass) or res.nil?
176
+ process_res = res.to_hash
177
+ end
172
178
 
173
179
  {:result=>process_res,:callback=>data['callback'],:request_id=>data['request_id'],:route=>'response'}
174
180
  end
@@ -1,20 +1,20 @@
1
- var Request = function(){
1
+ var Request = function(){
2
2
  this.__defineGetter__("params",function(){
3
- return params;
3
+ return params;
4
4
  });
5
-
5
+
6
6
  this.__defineSetter__("params",function(arg){
7
7
  params = arg;
8
8
  });
9
-
9
+
10
10
  this.__defineGetter__("header",function(){
11
11
  return header;
12
12
  });
13
-
13
+
14
14
  this.__defineSetter__("header",function(arg){
15
15
  header = arg;
16
16
  });
17
-
17
+
18
18
  this.__defineGetter__("model",function(){
19
19
  return model;
20
20
  });
@@ -22,6 +22,5 @@ var Request = function(){
22
22
  this.__defineSetter__("model",function(arg){
23
23
  model = arg;
24
24
  });
25
-
26
- }
25
+ };
27
26
  module.exports = Request;
@@ -34,20 +34,28 @@ var Response = function(){
34
34
  exception = arg;
35
35
  });
36
36
 
37
+ this.__defineGetter__("currentUser",function(){
38
+ return currentUser;
39
+ });
40
+
41
+ this.__defineSetter__("currentUser",function(arg){
42
+ currentUser = arg;
43
+ });
44
+
37
45
  this.send = function(data){
38
46
  var ballroom = require("./ballroom");
39
47
  var user_json = {};
40
48
 
41
49
  //if callback we are sending request to ruby
42
- if(data['callback']){
50
+ if(data && data['callback']){
43
51
  this.params = null;
44
52
  this.header['route'] = 'request';
45
53
  user_json = data;
46
54
  }
47
55
  else{
48
56
  user_json["result"] = data;
57
+ this.header['route'] = 'response';
49
58
  }
50
-
51
59
  Object.extend(user_json,this.params);
52
60
  Object.extend(user_json,this.header);
53
61
  Object.extend(user_json,this.exception);
@@ -1,19 +1,13 @@
1
1
 
2
- var current_user = function(resp,callback){
3
- var json = {};
4
- json['function'] = 'current_user';
5
- json['args'] = '';
6
- json['callback'] = callback;
7
- resp.send(json);
8
- }
9
2
 
10
- var stash_result = function(resp,callback){
3
+ var stashResult = function(resp){
11
4
  var json = {};
5
+ var callback = function(){};
12
6
  json['function'] = 'stash_result';
13
7
  json['args'] = resp.params;
14
8
  json['callback'] = callback;
15
9
  resp.send(json);
16
- }
10
+ };
17
11
 
18
12
  var source = function(resp,callback){
19
13
  var json = {};
@@ -21,40 +15,47 @@ var source = function(resp,callback){
21
15
  json['args'] = '';
22
16
  json['callback'] = callback;
23
17
  resp.send(json);
24
- }
18
+ };
19
+
20
+ var getData = function(resp,callback){
21
+ var json = {};
22
+ json['function'] = 'get_data';
23
+ json['args'] = '';
24
+ json['callback'] = callback;
25
+ resp.send(json);
26
+ };
25
27
 
26
28
  var Store = function(){
27
- var kls = 'Store';
28
-
29
- this.put_value = function(resp,callback){
30
- var json = this.format_json('put_value',resp.params);
29
+
30
+ this.putValue = function(resp,callback){
31
+ var json = this.formatJson('put_value',resp.params,callback);
31
32
  resp.send(json);
32
- }
33
- this.get_value = function(resp,callback){
34
- var json = this.format_json('get_value',resp.params);
33
+ };
34
+ this.getValue = function(resp,callback){
35
+ var json = this.formatJson('get_value',resp.params,callback);
35
36
  resp.send(json);
36
- }
37
- this.put_data = function(resp,callback){
38
- var json = this.format_json('put_data',resp.params);
37
+ };
38
+ this.putData = function(resp,callback){
39
+ var json = this.formatJson('put_data',resp.params,callback);
39
40
  resp.send(json);
40
- }
41
- this.get_data = function(resp,callback){
42
- var json = this.format_json('get_data',resp.params);
41
+ };
42
+ this.getData = function(resp,callback){
43
+ var json = this.formatJson('get_data',resp.params,callback);
43
44
  resp.send(json);
44
- }
45
-
46
- function format_json(method,args){
45
+ };
46
+
47
+ this.formatJson = function(method,args,callback){
47
48
  var json = {};
48
- json['kls'] = this.kls;
49
+ json['kls'] = 'Store';
49
50
  json['function'] = method;
50
51
  json['args'] = args;
52
+ json['callback'] = callback;
51
53
  json['route'] = 'request';
52
54
  return json;
53
- }
54
- }
55
-
55
+ };
56
+ };
56
57
 
57
- exports.current_user = current_user;
58
- exports.stash_result = stash_result;
58
+ exports.stashResult = stashResult;
59
+ exports.getData = getData;
59
60
  exports.source = source;
60
- module.exports.Store = Store;
61
+ module.exports.Store = new Store();
@@ -6,47 +6,50 @@ var router = function(json){
6
6
  case 'request':
7
7
  try {
8
8
  var request = new Request();
9
- var response = new Response();
9
+ var resp1 = new Response();
10
10
 
11
11
  request.params = json['args'];
12
12
  request.header = {'request_id':json['request_id'],'route':json['route']};
13
13
  request.model = json['model'];
14
- response.header = {'request_id':json['request_id'],'route':'response'};
14
+ resp1.currentUser = json['user'];
15
+ resp1.header = {'request_id':json['request_id'],'route':'response'};
15
16
 
16
17
  //if calling model function directly load file first
17
18
  if(json['klss'] !== undefined){
19
+ var model_dir = '';
18
20
  if(process.argv[3] == 'test' ){
19
- var model_dir = process.cwd() + "/spec/apps/rhotestapp/models/js/";
21
+ model_dir = process.cwd() + "/spec/apps/rhotestapp/models/js/";
20
22
  }
21
23
  else{
22
- var model_dir = process.cwd() + "/models/js/";
24
+ model_dir = process.cwd() + "/models/js/";
23
25
  }
24
26
  //console.error("path is: ******* " + model_dir + json['klss'] + '.js');
25
27
  var mod = require(model_dir + json['klss'] + '.js');
26
- mod[ json['function']](response);
28
+ mod[json['function']](resp1);
27
29
  }
28
30
  else{
29
31
  //console.error("reg routes are: " + registeredRoutes[json['url']]);
30
- registeredRoutes[json['url']](request,response);
32
+ registeredRoutes[json['url']](request,resp1);
31
33
  }
32
34
  break;
33
35
  }
34
36
  catch(e){
35
37
  console.error("Node.js error caught: "+ e);
36
38
  console.error("Backtrace: " + e.stack);
37
- response.exception = {"error": e};
38
- response.send(null);
39
+ resp1.exception = {"error": e};
40
+ resp1.send(null);
39
41
  }
40
42
  break;
41
43
  case 'response':
42
44
  //console.error("result callback is: " + json['callback'])
43
45
  var cback = json['callback'];
44
46
  json['callback'] = undefined;
45
- var response = new Response();
46
- response.header = {'request_id':json['request_id'],'route':'response'};
47
- response.result = json['result'];
47
+ var resp2 = new Response();
48
+ resp2.header = {'request_id':json['request_id'],'route':'response'};
49
+ resp2.result = json['result'];
48
50
 
49
- rhoconnectCallbacks[cback](response);
51
+
52
+ rhoconnectCallbacks[cback](resp2);
50
53
  delete rhoconnectCallbacks[cback];
51
54
  break;
52
55
  case 'deregister':
@@ -62,13 +62,7 @@ module Rhoconnect
62
62
  end
63
63
 
64
64
  def self.hshify(str)
65
- result = JSON.parse(str, :symbolize_names => true)
66
- # result = str.split(",").inject({}) do |res,element|
67
- # items = element.split(":")
68
- # res[items[0].to_sym] = items[1]
69
- # res
70
- # end
71
- result
65
+ JSON.parse(str, :symbolize_names => true)
72
66
  end
73
67
 
74
68
  def self.js_block(key,finish_block=nil)
@@ -79,6 +73,7 @@ module Rhoconnect
79
73
  :model => under_score(params[:source_name]),
80
74
  :route => 'request'
81
75
  }
76
+ json[:user] = @model.current_user.login if @model
82
77
  return_value = NodeChannel.publish_channel_and_wait(json,@model)
83
78
  if finish_block
84
79
  self.send(finish_block, return_value)
@@ -138,7 +138,7 @@ module Document
138
138
  # app-partitioned sources go to 0
139
139
  # everything else if sharded
140
140
  if(source.partition == :user)
141
- index_char = Digest::SHA1.hexdigest("#{user_id}:#{source.name}")[0]
141
+ index_char = Digest::SHA1.hexdigest("#{source.partition_name}:#{source.name}")[0]
142
142
  # designate Store 0 only for system data
143
143
  num_user_stores = Store.num_stores - 1
144
144
  if num_user_stores > 0
@@ -28,8 +28,12 @@ module Rhoconnect
28
28
  source.get_data(docname)
29
29
  end
30
30
 
31
- def self.create(source)
32
- model=nil
31
+ def self.partition_name(user_id)
32
+ user_id
33
+ end
34
+
35
+ def self.load_source_model(source)
36
+ model_klass=nil
33
37
  if source
34
38
  begin
35
39
  if source.name
@@ -39,20 +43,32 @@ module Rhoconnect
39
43
  # certain models are pre-defined and reserved
40
44
  # load them and instantiate
41
45
  if Rhoconnect.predefined_sources.has_key?(source.name)
42
- model = (Object.const_get(source.name)).new(source)
46
+ model_klass = Object.const_get(source.name)
43
47
  elsif Object.const_defined?(source.name) && Object.const_get(source.name).to_s.split("::").first != 'Rhoconnect'
44
48
  # fix until source adpaters are phased out, checking for Rhoconnect namespace
45
49
  # so that backend models with same name as Rhoconnect models are instantiated correctly
46
- kls = Object.const_get(source.name)
47
- unless kls
50
+ model_klass = Object.const_get(source.name)
51
+ unless model_klass
48
52
  require under_score(source.name)
49
- model = (Object.const_get(source.name)).new(source)
50
- else
51
- model = kls.new(source)
53
+ model_klass = Object.const_get(source.name)
52
54
  end
53
55
  else
54
- model=Rhoconnect::Model::DynamicAdapterModel.new(source)
56
+ model_klass=Rhoconnect::Model::DynamicAdapterModel
55
57
  end
58
+ rescue Exception => e
59
+ log "Failure to find class for model #{source.name}: #{e.inspect.to_s}"
60
+ raise e
61
+ end
62
+ end
63
+ model_klass
64
+ end
65
+
66
+ def self.create(source)
67
+ model=nil
68
+ model_klass = load_source_model(source)
69
+ if model_klass
70
+ begin
71
+ model = model_klass.new(source)
56
72
  rescue ArgumentError => e
57
73
  # Backward compatibility with code generated by gems < 2.2.0
58
74
  log "ERROR: credential parameter in `initialize` method is deprecated and removed in version >= 2.2.0."
@@ -209,7 +225,6 @@ module Rhoconnect
209
225
  @source.announce_changes
210
226
  end
211
227
 
212
- protected
213
228
  def current_user
214
229
  @source.user
215
230
  end
@@ -64,8 +64,8 @@ module Rhoconnect
64
64
  end
65
65
 
66
66
  def store_blob(obj,field_name,blob)
67
- raise "store_blob not implemented in JavaScript yet."
68
- # TODO: add method handling here
67
+ blob[:path] = blob[:tempfile].path
68
+ rho_methods('storeBlob',blob)
69
69
  end
70
70
 
71
71
  private
@@ -84,9 +84,10 @@ module Rhoconnect
84
84
  :klss => self.class.actual_name,
85
85
  :function => method_name,
86
86
  :args => args,
87
+ :user => current_user.login,
87
88
  :route => 'request'
88
89
  }
89
- NodeChannel.publish_channel_and_wait(json,self.class)
90
+ NodeChannel.publish_channel_and_wait(json,self)
90
91
  end
91
92
  end
92
93
  end
@@ -359,7 +359,21 @@ module Rhoconnect
359
359
  end
360
360
 
361
361
  def user_by_partition
362
- self.partition.to_sym == :user ? self.user_id : '__shared__'
362
+ self.partition.to_sym == :user ? partition_name : '__shared__'
363
+ end
364
+
365
+ def partition_name
366
+ # edge case - used in deleting documents
367
+ return self.user_id if self.user_id == '*'
368
+ # default is user_id
369
+ pname = self.user_id
370
+ begin
371
+ model_klass = Rhoconnect::Model::Base.load_source_model(self)
372
+ pname = model_klass ? model_klass.partition_name(self.user_id) : self.user_id
373
+ # eat the exception here
374
+ rescue Exception => e
375
+ end
376
+ pname
363
377
  end
364
378
 
365
379
  def check_refresh_time
@@ -1,3 +1,3 @@
1
1
  module Rhoconnect
2
- VERSION = '4.0.0.beta.10'
2
+ VERSION = '4.0.0.beta.12'
3
3
  end