rhoconnect 3.4.5 → 4.0.0.beta.10
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 +57 -3
- data/Gemfile +9 -7
- data/Gemfile.lock +37 -37
- data/Rakefile +18 -7
- data/bench/benchapp/Gemfile +1 -1
- data/bench/benchapp/config.ru +0 -3
- data/bench/benchapp/controllers/ruby/application.rb +17 -0
- data/bench/benchapp/controllers/ruby/application_controller.rb +17 -0
- data/bench/benchapp/controllers/ruby/mock_adapter_controller.rb +8 -0
- data/bench/benchapp/controllers/ruby/queue_mock_adapter_controller.rb +8 -0
- data/bench/benchapp/{sources → models/ruby}/mock_adapter.rb +1 -1
- data/bench/benchapp/{sources → models/ruby}/queue_mock_adapter.rb +0 -0
- data/bench/benchapp/spec/{sources → models/ruby}/mock_adapter_spec.rb +1 -1
- data/bench/benchapp/spec/{sources → models/ruby}/queue_mock_adapter_spec.rb +1 -1
- data/bench/benchapp/spec/spec_helper.rb +2 -2
- data/bench/blobapp/Gemfile +1 -1
- data/bench/blobapp/config.ru +0 -3
- data/bench/blobapp/controllers/ruby/application_controller.rb +17 -0
- data/bench/blobapp/controllers/ruby/blob_adapter_controller.rb +8 -0
- data/bench/blobapp/{sources → models/ruby}/blob_adapter.rb +9 -2
- data/bench/blobapp/spec/{sources → models/ruby}/blob_adapter_spec.rb +1 -1
- data/bench/blobapp/spec/spec_helper.rb +1 -1
- data/bench/lib/bench/cli.rb +1 -1
- data/bench/scripts/blob_cud_script.rb +1 -1
- data/bench/scripts/query_md_script.rb +1 -1
- data/bench/scripts/query_only_script.rb +1 -1
- data/bench/scripts/query_script.rb +1 -1
- data/bench/scripts/test_query_script.rb +7 -1
- data/bench/spec/mock_adapter_spec.rb +1 -1
- data/bench/spec/result_spec.rb +3 -3
- data/bin/rhoconnect +5 -3
- data/commands/dtach/dtach_install.rb +2 -2
- data/commands/execute.rb +8 -3
- data/commands/generators/app.rb +3 -3
- data/commands/generators/controller.rb +6 -0
- data/commands/generators/model.rb +6 -0
- data/commands/generators/source.rb +3 -3
- data/commands/generators/update.rb +1 -1
- data/commands/redis/redis_about.rb +2 -2
- data/commands/redis/redis_download.rb +1 -1
- data/commands/redis/redis_install.rb +4 -3
- data/commands/redis/redis_restart.rb +4 -4
- data/commands/redis/redis_start.rb +5 -4
- data/commands/redis/redis_startbg.rb +5 -4
- data/commands/redis/redis_status.rb +13 -0
- data/commands/redis/redis_stop.rb +3 -3
- data/commands/rhoconnect/config.rb +28 -16
- data/commands/rhoconnect/flushdb.rb +1 -2
- data/commands/rhoconnect/get_token.rb +15 -11
- data/commands/rhoconnect/restart.rb +13 -5
- data/commands/rhoconnect/set_admin_password.rb +8 -8
- data/commands/rhoconnect/start.rb +74 -16
- data/commands/rhoconnect/startbg.rb +1 -1
- data/commands/rhoconnect/startdebug.rb +1 -1
- data/commands/rhoconnect/stop.rb +13 -1
- data/commands/rhoconnect/web.rb +5 -5
- data/commands/rhoconnect_console/console.rb +7 -5
- data/commands/{rhoconnect → rhoconnect_spec}/spec.rb +0 -0
- data/commands/rhoconnect_war/war.rb +9 -9
- data/commands/utilities/blank_app.ru +56 -0
- data/commands/utilities/redis_runner.rb +54 -19
- data/doc/authentication.txt +80 -6
- data/doc/blob-sync.txt +104 -97
- data/doc/bulk-sync.txt +1 -1
- data/doc/client-java.txt +3 -3
- data/doc/client-objc.txt +2 -2
- data/doc/client.txt +4 -4
- data/doc/command-line.txt +105 -200
- data/doc/data-partitioning.txt +40 -0
- data/doc/deploying.txt +249 -77
- data/doc/extending-rhoconnect-server.txt +40 -57
- data/doc/heroku-addon.txt +2 -0
- data/doc/install.txt +45 -95
- data/doc/introduction.txt +1 -1
- data/doc/java-plugin.txt +365 -190
- data/doc/metadata.txt +1 -1
- data/doc/migration.txt +108 -142
- data/doc/preparing-production.txt +1 -1
- data/doc/push-backend-setup.txt +2 -0
- data/doc/push-client-setup-android.txt +78 -0
- data/doc/push-client-setup-bb.txt +81 -0
- data/doc/push-client-setup-ios.txt +70 -0
- data/doc/push-client-setup-rps.txt +200 -0
- data/doc/push-client-setup.txt +63 -66
- data/doc/push-server-setup.txt +67 -40
- data/doc/push-testing.txt +29 -0
- data/doc/push.txt +21 -6
- data/doc/rest-api.txt +128 -55
- data/doc/rhoconnect-redis-stack.txt +120 -0
- data/doc/settings.txt +4 -12
- data/doc/source-adapters-intro.txt +28 -0
- data/doc/source-adapters.txt +235 -272
- data/doc/stats-middleware.txt +9 -29
- data/doc/supported-platforms.txt +21 -30
- data/doc/testing.txt +40 -42
- data/doc/tutorial.txt +72 -57
- data/examples/simple/Gemfile +1 -1
- data/examples/simple/application.rb +4 -5
- data/examples/simple/my_server.rb +2 -2
- data/examples/simple/settings/settings.yml +1 -1
- data/generators/rhoconnect.rb +151 -50
- data/generators/templates/application/Gemfile +1 -1
- data/generators/templates/application/Rakefile +3 -3
- data/generators/templates/application/config.ru +1 -4
- data/generators/templates/application/controllers/application_controller.rb +17 -0
- data/generators/templates/application/controllers/js/application_controller.js +14 -0
- data/generators/templates/application/controllers/ruby/application_controller.rb +17 -0
- data/generators/templates/application/package.json +8 -0
- data/generators/templates/application/rcgemfile +2 -5
- data/generators/templates/application/settings/settings.yml +3 -3
- data/generators/templates/application/spec/application_controller_spec.rb +23 -0
- data/generators/templates/application/spec/js_spec.rb +25 -0
- data/generators/templates/application/spec/spec_helper.rb +21 -7
- data/generators/templates/source/controllers/js/controller.js +7 -0
- data/generators/templates/source/controllers/ruby/controller.rb +8 -0
- data/generators/templates/source/controllers/ruby/controller_spec.rb +27 -0
- data/generators/templates/source/models/js/model.js +46 -0
- data/generators/templates/source/{source_adapter.rb → models/ruby/model.rb} +15 -10
- data/generators/templates/source/{source_spec.rb → models/ruby/model_spec.rb} +1 -1
- data/install.sh +5 -5
- data/installer/unix-like/create_texts.rb +2 -2
- data/installer/unix-like/rho_connect_install_constants.rb +2 -2
- data/installer/unix-like/rho_connect_install_utilities.rb +1 -1
- data/installer/utils/constants.rb +4 -4
- data/js-adapters/ballroom.js +216 -0
- data/js-adapters/node.rb +52 -0
- data/js-adapters/node_channel.rb +181 -0
- data/js-adapters/request.js +27 -0
- data/js-adapters/response.js +57 -0
- data/js-adapters/rhoconnect_helpers.js +60 -0
- data/js-adapters/router.js +60 -0
- data/js-adapters/server.js +5 -0
- data/lib/rhoconnect/api/app/ans_login.rb +3 -3
- data/lib/rhoconnect/api/app/bulk_data.rb +10 -10
- data/lib/rhoconnect/api/app/fast_delete.rb +11 -10
- data/lib/rhoconnect/api/app/fast_insert.rb +11 -10
- data/lib/rhoconnect/api/app/fast_update.rb +11 -10
- data/lib/rhoconnect/api/app/login.rb +5 -5
- data/lib/rhoconnect/api/app/push_deletes.rb +12 -11
- data/lib/rhoconnect/api/app/push_objects.rb +12 -11
- data/lib/rhoconnect/api/app/query.rb +8 -7
- data/lib/rhoconnect/api/app/queue_updates.rb +98 -94
- data/lib/rhoconnect/api/app/search.rb +8 -7
- data/lib/rhoconnect/api/client/client_get_db_doc.rb +5 -5
- data/lib/rhoconnect/api/client/client_set_db_doc.rb +8 -8
- data/lib/rhoconnect/api/client/create.rb +7 -7
- data/lib/rhoconnect/api/client/get_client_params.rb +4 -4
- data/lib/rhoconnect/api/client/list_client_docs.rb +17 -17
- data/lib/rhoconnect/api/client/register.rb +12 -12
- data/lib/rhoconnect/api/client/reset.rb +5 -5
- data/lib/rhoconnect/api/readstate/set_refresh_time.rb +9 -9
- data/lib/rhoconnect/api/source/get_source_params.rb +4 -4
- data/lib/rhoconnect/api/source/list_sources.rb +16 -16
- data/lib/rhoconnect/api/source/update_source_params.rb +6 -6
- data/lib/rhoconnect/api/store/get_db_doc.rb +4 -4
- data/lib/rhoconnect/api/store/set_db_doc.rb +7 -7
- data/lib/rhoconnect/api/system/get_adapter.rb +4 -4
- data/lib/rhoconnect/api/system/get_license_info.rb +8 -8
- data/lib/rhoconnect/api/system/login.rb +15 -15
- data/lib/rhoconnect/api/system/reset.rb +11 -11
- data/lib/rhoconnect/api/system/save_adapter.rb +4 -4
- data/lib/rhoconnect/api/system/stats.rb +22 -22
- data/lib/rhoconnect/api/user/create_user.rb +7 -7
- data/lib/rhoconnect/api/user/delete_client.rb +6 -6
- data/lib/rhoconnect/api/user/delete_user.rb +11 -10
- data/lib/rhoconnect/api/user/list_clients.rb +4 -4
- data/lib/rhoconnect/api/user/list_source_docs.rb +10 -10
- data/lib/rhoconnect/api/user/list_users.rb +3 -3
- data/lib/rhoconnect/api/user/ping.rb +3 -3
- data/lib/rhoconnect/api/user/show_user.rb +3 -3
- data/lib/rhoconnect/api/user/update_user.rb +5 -5
- data/lib/rhoconnect/api/user/user_get_db_doc.rb +5 -5
- data/lib/rhoconnect/api/user/user_set_db_doc.rb +10 -10
- data/lib/rhoconnect/api_token.rb +5 -6
- data/lib/rhoconnect/app.rb +6 -46
- data/lib/rhoconnect/application/init.rb +5 -2
- data/lib/rhoconnect/async.rb +76 -39
- data/lib/rhoconnect/bulk_data/bulk_data.rb +6 -4
- data/lib/rhoconnect/client.rb +59 -9
- data/lib/rhoconnect/condition/admin_required.rb +27 -0
- data/lib/rhoconnect/condition/client_required.rb +50 -0
- data/lib/rhoconnect/condition/login_required.rb +22 -0
- data/lib/rhoconnect/condition/source_required.rb +49 -0
- data/lib/rhoconnect/condition/verbs.rb +17 -0
- data/lib/rhoconnect/condition/verify_success.rb +19 -0
- data/lib/rhoconnect/controller/app_base.rb +74 -0
- data/lib/rhoconnect/controller/base.rb +68 -0
- data/lib/rhoconnect/controller/clients_controller.rb +79 -0
- data/lib/rhoconnect/controller/dynamic_adapter_controller.rb +93 -0
- data/lib/rhoconnect/controller/js_base.rb +124 -0
- data/lib/rhoconnect/controller/read_state_controller.rb +22 -0
- data/lib/rhoconnect/controller/source_adapter_base.rb +14 -0
- data/lib/rhoconnect/controller/sources_controller.rb +44 -0
- data/lib/rhoconnect/controller/store_controller.rb +25 -0
- data/lib/rhoconnect/controller/system_controller.rb +67 -0
- data/lib/rhoconnect/controller/users_controller.rb +99 -0
- data/lib/rhoconnect/db_adapter.rb +1 -3
- data/lib/rhoconnect/document.rb +159 -50
- data/lib/rhoconnect/handler/authenticate/execute_methods.rb +77 -0
- data/lib/rhoconnect/handler/authenticate/runner.rb +49 -0
- data/lib/rhoconnect/handler/authenticate.rb +3 -0
- data/lib/rhoconnect/handler/bulk_data.rb +28 -0
- data/lib/rhoconnect/handler/changes/engine.rb +271 -0
- data/lib/rhoconnect/handler/changes/execute_methods.rb +88 -0
- data/lib/rhoconnect/handler/changes/pass_through_runner.rb +11 -0
- data/lib/rhoconnect/handler/changes/runner.rb +53 -0
- data/lib/rhoconnect/handler/changes.rb +31 -0
- data/lib/rhoconnect/handler/helpers/auth_method.rb +29 -0
- data/lib/rhoconnect/handler/helpers/binding.rb +18 -0
- data/lib/rhoconnect/handler/helpers/bulk_data.rb +53 -0
- data/lib/rhoconnect/handler/helpers/source_job.rb +14 -0
- data/lib/rhoconnect/handler/helpers.rb +4 -0
- data/lib/rhoconnect/handler/plugin_callbacks/execute_methods.rb +99 -0
- data/lib/rhoconnect/handler/plugin_callbacks/runner.rb +28 -0
- data/lib/rhoconnect/handler/plugin_callbacks.rb +67 -0
- data/lib/rhoconnect/handler/query/engine.rb +93 -0
- data/lib/rhoconnect/handler/query/execute_methods.rb +21 -0
- data/lib/rhoconnect/handler/query/pass_through_runner.rb +35 -0
- data/lib/rhoconnect/handler/query/runner.rb +270 -0
- data/lib/rhoconnect/handler/query.rb +19 -0
- data/lib/rhoconnect/handler/search/engine.rb +60 -0
- data/lib/rhoconnect/handler/search/execute_methods.rb +32 -0
- data/lib/rhoconnect/handler/search/pass_through_runner.rb +18 -0
- data/lib/rhoconnect/handler/search/runner.rb +104 -0
- data/lib/rhoconnect/handler/search.rb +26 -0
- data/lib/rhoconnect/handler/sync.rb +29 -0
- data/lib/rhoconnect/jobs/source_job.rb +13 -4
- data/lib/rhoconnect/js_adapter.rb +79 -0
- data/lib/rhoconnect/license.rb +10 -2
- data/lib/rhoconnect/middleware/current_user.rb +14 -1
- data/lib/rhoconnect/middleware/helpers.rb +10 -93
- data/lib/rhoconnect/middleware/x_domain_session_wrapper.rb +1 -1
- data/lib/rhoconnect/model/base.rb +229 -0
- data/lib/rhoconnect/model/dynamic_adapter_model.rb +90 -0
- data/lib/rhoconnect/model/js_base.rb +121 -0
- data/lib/rhoconnect/ping/android.rb +1 -1
- data/lib/rhoconnect/predefined_adapters/bench_adapter.rb +7 -4
- data/lib/rhoconnect/read_state.rb +3 -3
- data/lib/rhoconnect/server.rb +159 -190
- data/lib/rhoconnect/source.rb +100 -11
- data/lib/rhoconnect/stats/record.rb +10 -10
- data/lib/rhoconnect/store.rb +905 -591
- data/lib/rhoconnect/{model.rb → store_orm.rb} +53 -115
- data/lib/rhoconnect/tasks.rb +18 -4
- data/lib/rhoconnect/test_methods.rb +30 -17
- data/lib/rhoconnect/user.rb +35 -17
- data/lib/rhoconnect/utilities.rb +1 -1
- data/lib/rhoconnect/version.rb +2 -2
- data/lib/rhoconnect/web-console/server.rb +29 -14
- data/lib/rhoconnect/web-console/views/home.js +10 -10
- data/lib/rhoconnect/web-console/views/new_ping.js +1 -1
- data/lib/rhoconnect.rb +120 -51
- data/rhoconnect.gemspec +4 -3
- data/spec/api/api_helper.rb +1 -6
- data/spec/api/app/fast_delete_spec.rb +4 -4
- data/spec/api/app/fast_insert_spec.rb +4 -4
- data/spec/api/app/fast_update_spec.rb +8 -8
- data/spec/api/app/push_deletes_spec.rb +2 -2
- data/spec/api/app/push_objects_spec.rb +5 -5
- data/spec/api/client/client_get_db_doc_spec.rb +6 -4
- data/spec/api/client/client_set_db_doc_spec.rb +3 -2
- data/spec/api/client/get_client_params_spec.rb +14 -0
- data/spec/api/client/list_client_docs_spec.rb +30 -20
- data/spec/api/client/reset_spec.rb +36 -0
- data/spec/api/source/get_source_params_spec.rb +23 -17
- data/spec/api/system/get_license_info_spec.rb +0 -20
- data/spec/api/system/login_spec.rb +8 -0
- data/spec/api/system/reset_spec.rb +0 -1
- data/spec/api/system/stats_spec.rb +5 -5
- data/spec/api/user/create_user_spec.rb +14 -6
- data/spec/api/user/delete_user_spec.rb +20 -18
- data/spec/api/user/list_users_spec.rb +5 -6
- data/spec/api/user/update_user_spec.rb +5 -4
- data/spec/apps/rhotestapp/config.ru +16 -1
- data/spec/apps/rhotestapp/controllers/js/js_sample_controller.js +23 -0
- data/spec/apps/rhotestapp/controllers/js/sample2_controller.js +32 -0
- data/spec/apps/rhotestapp/controllers/ruby/application_controller.rb +21 -0
- data/spec/apps/rhotestapp/controllers/ruby/sample_adapter_controller.rb +8 -0
- data/spec/apps/rhotestapp/models/js/js_sample.js +55 -0
- data/spec/apps/rhotestapp/models/js/sample2.js +25 -0
- data/spec/apps/rhotestapp/{sources → models/ruby}/base_adapter.rb +0 -0
- data/spec/apps/rhotestapp/{sources → models/ruby}/fixed_schema_adapter.rb +0 -0
- data/spec/apps/rhotestapp/{sources → models/ruby}/other_adapter.rb +0 -0
- data/spec/apps/rhotestapp/{sources → models/ruby}/sample_adapter.rb +0 -0
- data/spec/apps/rhotestapp/{sources → models/ruby}/simple_adapter.rb +2 -2
- data/spec/apps/rhotestapp/{sources → models/ruby}/sub_adapter.rb +0 -0
- data/spec/apps/rhotestapp/settings/settings.yml +0 -1
- data/spec/bulk_data/bulk_data_spec.rb +20 -5
- data/spec/cli/cli_spec.rb +83 -0
- data/spec/client_spec.rb +20 -17
- data/spec/client_sync_spec.rb +244 -406
- data/spec/controllers/js_base_spec.rb +89 -0
- data/spec/doc/doc_spec.rb +18 -18
- data/spec/document_spec.rb +29 -13
- data/spec/dynamic_adapter_spec.rb +6 -6
- data/spec/generator/generator_spec.rb +7 -4
- data/spec/jobs/bulk_data_job_spec.rb +14 -10
- data/spec/jobs/source_job_spec.rb +8 -8
- data/spec/license_spec.rb +5 -2
- data/spec/models/js_model_spec.rb +39 -0
- data/spec/node_spec.rb +42 -0
- data/spec/perf/store_perf_spec.rb +67 -12
- data/spec/ping/android_spec.rb +1 -1
- data/spec/read_state_spec.rb +1 -1
- data/spec/rhoconnect_spec.rb +1 -1
- data/spec/server/cors_spec.rb +14 -18
- data/spec/server/server_spec.rb +265 -88
- data/spec/server/stats_spec.rb +1 -1
- data/spec/source_adapter_spec.rb +54 -27
- data/spec/source_spec.rb +8 -3
- data/spec/source_sync_spec.rb +538 -468
- data/spec/spec_helper.rb +35 -4
- data/spec/stats/record_spec.rb +10 -10
- data/spec/{model_spec.rb → store_orm_spec.rb} +56 -54
- data/spec/store_spec.rb +159 -179
- data/spec/support/shared_examples.rb +36 -27
- data/spec/sync_states_spec.rb +40 -33
- data/spec/test_methods_spec.rb +18 -14
- data/spec/user_spec.rb +17 -30
- metadata +156 -52
- data/bench/benchapp/application.rb +0 -39
- data/bench/blobapp/application.rb +0 -44
- data/commands/rhoconnect/clean_start.rb +0 -9
- data/commands/rhoconnect/create_user.rb +0 -18
- data/commands/rhoconnect/delete_device.rb +0 -9
- data/commands/rhoconnect/delete_user.rb +0 -8
- data/commands/rhoconnect/reset.rb +0 -16
- data/commands/rhoconnect/reset_refresh.rb +0 -11
- data/generators/templates/application/application.rb +0 -43
- data/lib/rhoconnect/client_sync.rb +0 -434
- data/lib/rhoconnect/dynamic_adapter.rb +0 -91
- data/lib/rhoconnect/middleware/admin_user.rb +0 -23
- data/lib/rhoconnect/middleware/current_request.rb +0 -16
- data/lib/rhoconnect/middleware/login_required.rb +0 -22
- data/lib/rhoconnect/source_adapter.rb +0 -132
- data/lib/rhoconnect/source_sync.rb +0 -464
- data/spec/apps/rhotestapp/application.rb +0 -23
data/lib/rhoconnect/license.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'openssl'
|
|
2
|
+
require 'pathname'
|
|
2
3
|
|
|
3
4
|
module Rhoconnect
|
|
4
5
|
class LicenseException < RuntimeError; end
|
|
@@ -6,7 +7,7 @@ module Rhoconnect
|
|
|
6
7
|
|
|
7
8
|
class License
|
|
8
9
|
attr_reader :rhoconnect_version, :licensee, :seats, :issued
|
|
9
|
-
|
|
10
|
+
attr_accessor :license
|
|
10
11
|
|
|
11
12
|
# ships with rhoconnect
|
|
12
13
|
RHO_PUBLICKEY = "99068e3a2708e6fe918252be8880eac539a1d2b2402651d75de5c7a2333a1cb2"
|
|
@@ -19,8 +20,15 @@ module Rhoconnect
|
|
|
19
20
|
elsif ENV['RHOSYNC_LICENSE']
|
|
20
21
|
@license = ENV['RHOSYNC_LICENSE']
|
|
21
22
|
else
|
|
23
|
+
app_config = Rhoconnect.get_config(Rhoconnect.base_directory)
|
|
22
24
|
settings = Rhoconnect.get_config(Rhoconnect.base_directory)[Rhoconnect.environment]
|
|
23
|
-
|
|
25
|
+
licensefile = settings[:licensefile]
|
|
26
|
+
if licensefile
|
|
27
|
+
path_to_license = (Pathname.new(licensefile).absolute?) ? licensefile : File.join(Rhoconnect.base_directory, licensefile)
|
|
28
|
+
else
|
|
29
|
+
path_to_license = File.join(File.dirname(__FILE__), '..', '..', 'generators', 'templates', 'application', 'settings', 'license.key')
|
|
30
|
+
end
|
|
31
|
+
@license = IO.read(path_to_license).strip
|
|
24
32
|
end
|
|
25
33
|
_decrypt
|
|
26
34
|
rescue Exception => e
|
|
@@ -9,9 +9,22 @@ module Rhoconnect
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def call(env)
|
|
12
|
-
env
|
|
12
|
+
#puts "env is *** #{env.inspect}"
|
|
13
|
+
env[Rhoconnect::CURRENT_USER] = extract_current_user(env)
|
|
13
14
|
@app.call(env)
|
|
14
15
|
end
|
|
16
|
+
|
|
17
|
+
def extract_current_user(env)
|
|
18
|
+
user = nil
|
|
19
|
+
if User.is_exist?(env['rack.session'][:login])
|
|
20
|
+
user = User.load(env['rack.session'][:login])
|
|
21
|
+
end
|
|
22
|
+
if user and (user.admin == 1 || env['rack.session'][:app_name] == APP_NAME)
|
|
23
|
+
user
|
|
24
|
+
else
|
|
25
|
+
nil
|
|
26
|
+
end
|
|
27
|
+
end
|
|
15
28
|
end
|
|
16
29
|
end
|
|
17
30
|
end
|
|
@@ -4,6 +4,15 @@ module Rhoconnect
|
|
|
4
4
|
CURRENT_REQUEST = 'CURRENT_REQUEST'.freeze
|
|
5
5
|
CURRENT_APP = 'CURRENT_APP'.freeze
|
|
6
6
|
CURRENT_USER = 'CURRENT_USER'.freeze
|
|
7
|
+
CURRENT_SOURCE = 'CURRENT_SOURCE'.freeze
|
|
8
|
+
CURRENT_CLIENT = 'CURRENT_CLIENT'.freeze
|
|
9
|
+
QUERY_RES = 'QUERY_RES'.freeze
|
|
10
|
+
|
|
11
|
+
UNKNOWN_CLIENT = "Unknown client".freeze
|
|
12
|
+
UNKNOWN_SOURCE = "Unknown source".freeze
|
|
13
|
+
|
|
14
|
+
# TODO : Remove in Rhoconnect 4.0
|
|
15
|
+
SYNC_VERSION = 3
|
|
7
16
|
|
|
8
17
|
# header names, in the form of server's HTTP variables
|
|
9
18
|
# X-RhoConnect-API-TOKEN
|
|
@@ -14,96 +23,4 @@ module Rhoconnect
|
|
|
14
23
|
PAGE_TOKEN_HEADER = 'X-Rhoconnect-PAGE-TOKEN'
|
|
15
24
|
# X-RhoConnect-PAGE-OBJECT-COUNT
|
|
16
25
|
PAGE_OBJECT_COUNT_HEADER = 'X-Rhoconnect-PAGE-OBJECT-COUNT'
|
|
17
|
-
|
|
18
|
-
# old-way admin routes
|
|
19
|
-
OLD_API_URI_REGEXP = /\/api\//
|
|
20
|
-
# new way system routes will be:
|
|
21
|
-
# /rc/<version>/system/<method>
|
|
22
|
-
# /rc/<version>/<resource>/<method>
|
|
23
|
-
SYSTEM_API_URI_REGEXP = /\/rc\/\w+\/\w+/
|
|
24
|
-
# also, /app/v1/<Controller>/push_* are still remain Admin routes
|
|
25
|
-
PUSH_API_URI_REGEXP = /\/app\/\w+\/\w+\/push\w+/
|
|
26
|
-
# also, /app/v1/<Controller>/fast_* are still remain Admin routes
|
|
27
|
-
FAST_CUD_API_URI_REGEXP = /\/app\/\w+\/\w+\/fast\w+/
|
|
28
|
-
|
|
29
|
-
def is_clients_non_admin_route(env)
|
|
30
|
-
# FIXME : not all routes for Clients protocol are admin routes
|
|
31
|
-
full_path = env['SCRIPT_NAME'] + env['PATH_INFO']
|
|
32
|
-
/\/rc\/\w+\/clients/.match(full_path) and not ((env[CURRENT_REQUEST].request_method == 'GET') ||
|
|
33
|
-
(env[CURRENT_REQUEST].request_method == 'POST' and /\/rc\/\w+\/clients\/\w+\/sources/.match(full_path)))
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def is_client_route(env)
|
|
37
|
-
# FIXME - once Controllers concept is implemented
|
|
38
|
-
# remove this - since the inclusion of Admin Middleware
|
|
39
|
-
# will automatically imply what routes are Admin and which are not
|
|
40
|
-
full_path = env['SCRIPT_NAME'] + env['PATH_INFO']
|
|
41
|
-
# login route and index route doesn't need a token
|
|
42
|
-
return true if /\/login/.match(full_path) || full_path == '/'
|
|
43
|
-
# old application routes are not admin
|
|
44
|
-
return true if full_path == '/application'
|
|
45
|
-
return true if full_path == '/api/application'
|
|
46
|
-
return true if /\/application\//.match(full_path)
|
|
47
|
-
# some of the clients routes are not admin
|
|
48
|
-
return true if is_clients_non_admin_route(env)
|
|
49
|
-
# push_objects and push_deletes methods are admin
|
|
50
|
-
return false if PUSH_API_URI_REGEXP.match(full_path)
|
|
51
|
-
# fast_insert/update/delete methods are admin
|
|
52
|
-
return false if FAST_CUD_API_URI_REGEXP.match(full_path)
|
|
53
|
-
# old api methods + every method in /rc/v1/app namespace
|
|
54
|
-
return true if /\/app\//.match(full_path)
|
|
55
|
-
# all other methods in the /rc/v1/ are admin routes
|
|
56
|
-
return false if SYSTEM_API_URI_REGEXP.match(full_path)
|
|
57
|
-
# all old /api methods are admin as well
|
|
58
|
-
return false if OLD_API_URI_REGEXP.match(full_path)
|
|
59
|
-
|
|
60
|
-
# everything else should not be admin
|
|
61
|
-
true
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def is_admin_route(env)
|
|
65
|
-
not is_client_route(env)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def is_login_required(env)
|
|
69
|
-
# FIXME - once Controllers concept is implemented
|
|
70
|
-
# remove this - since the inclusion of LoginRequired Middleware
|
|
71
|
-
# will automatically imply what routes require Login and which are not
|
|
72
|
-
full_path = env['SCRIPT_NAME'] + env['PATH_INFO']
|
|
73
|
-
return false if full_path == '/' or /login/.match(full_path)
|
|
74
|
-
# all methods in app namespace
|
|
75
|
-
return true if /\/app\//.match(full_path)
|
|
76
|
-
# old application routes are not admin
|
|
77
|
-
return true if full_path == '/application'
|
|
78
|
-
return true if full_path == '/api/application'
|
|
79
|
-
return true if /\/application\//.match(full_path)
|
|
80
|
-
# also methods that operate on clients should have an associated user
|
|
81
|
-
return true if is_clients_non_admin_route(env)
|
|
82
|
-
|
|
83
|
-
# for every other route login is not required
|
|
84
|
-
# because it's either an admin route (where api_user must be supplied anyway)
|
|
85
|
-
# or it's a custom route extending RhoConnect server
|
|
86
|
-
false
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def extract_current_user(env)
|
|
90
|
-
user = nil
|
|
91
|
-
if User.is_exist?(env['rack.session'][:login])
|
|
92
|
-
user = User.load(env['rack.session'][:login])
|
|
93
|
-
end
|
|
94
|
-
if user and (user.admin == 1 || env['rack.session'][:app_name] == APP_NAME)
|
|
95
|
-
user
|
|
96
|
-
else
|
|
97
|
-
nil
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def extract_api_user(env)
|
|
102
|
-
r = env[CURRENT_REQUEST]
|
|
103
|
-
# API_TOKEN is either a param or a header
|
|
104
|
-
u = ApiToken.load(env[API_TOKEN_HEADER])
|
|
105
|
-
u = ApiToken.load(r.params['api_token']) unless u
|
|
106
|
-
raise Rhoconnect::ApiException.new(422, "No API token provided") unless u
|
|
107
|
-
u.user
|
|
108
|
-
end
|
|
109
|
-
end
|
|
26
|
+
end
|
|
@@ -21,7 +21,7 @@ module Rhoconnect
|
|
|
21
21
|
if is_sync_protocol(env)
|
|
22
22
|
env['HTTP_COOKIE'] = env['HTTP_COOKIE'] || CGI.unescape(get_session_from_url(env))
|
|
23
23
|
end
|
|
24
|
-
|
|
24
|
+
#puts "and here #{@app.inspect} #{env.inspect}"
|
|
25
25
|
status, headers, body = @app.call(env)
|
|
26
26
|
|
|
27
27
|
if is_sync_protocol(env)
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
module Rhoconnect
|
|
2
|
+
module Model
|
|
3
|
+
class Exception < RuntimeError; end
|
|
4
|
+
# raise this to cause client to be logged out during a sync
|
|
5
|
+
class LoginException < Rhoconnect::Model::Exception; end
|
|
6
|
+
class LogoffException < Rhoconnect::Model::Exception; end
|
|
7
|
+
# raise these to trigger rhoconnect sending an error to the client
|
|
8
|
+
class ServerTimeoutException < Rhoconnect::Model::Exception; end
|
|
9
|
+
class ServerErrorException < Rhoconnect::Model::Exception; end
|
|
10
|
+
class ObjectConflictErrorException < Rhoconnect::Model::Exception; end
|
|
11
|
+
|
|
12
|
+
class Base
|
|
13
|
+
attr_accessor :session, :source
|
|
14
|
+
|
|
15
|
+
def initialize(source)
|
|
16
|
+
@source = source
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# public API Method for loading an instance of the Model
|
|
20
|
+
def self.load(username)
|
|
21
|
+
source = Source.load(self.name,
|
|
22
|
+
{:user_id => username,:app_id => APP_NAME})
|
|
23
|
+
self.create(source)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# public API method to load the Model's data
|
|
27
|
+
def get_data(docname = :md)
|
|
28
|
+
source.get_data(docname)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.create(source)
|
|
32
|
+
model=nil
|
|
33
|
+
if source
|
|
34
|
+
begin
|
|
35
|
+
if source.name
|
|
36
|
+
source.name = source.name.dup if source.name.frozen?
|
|
37
|
+
source.name.strip!
|
|
38
|
+
end
|
|
39
|
+
# certain models are pre-defined and reserved
|
|
40
|
+
# load them and instantiate
|
|
41
|
+
if Rhoconnect.predefined_sources.has_key?(source.name)
|
|
42
|
+
model = (Object.const_get(source.name)).new(source)
|
|
43
|
+
elsif Object.const_defined?(source.name) && Object.const_get(source.name).to_s.split("::").first != 'Rhoconnect'
|
|
44
|
+
# fix until source adpaters are phased out, checking for Rhoconnect namespace
|
|
45
|
+
# so that backend models with same name as Rhoconnect models are instantiated correctly
|
|
46
|
+
kls = Object.const_get(source.name)
|
|
47
|
+
unless kls
|
|
48
|
+
require under_score(source.name)
|
|
49
|
+
model = (Object.const_get(source.name)).new(source)
|
|
50
|
+
else
|
|
51
|
+
model = kls.new(source)
|
|
52
|
+
end
|
|
53
|
+
else
|
|
54
|
+
model=Rhoconnect::Model::DynamicAdapterModel.new(source)
|
|
55
|
+
end
|
|
56
|
+
rescue ArgumentError => e
|
|
57
|
+
# Backward compatibility with code generated by gems < 2.2.0
|
|
58
|
+
log "ERROR: credential parameter in `initialize` method is deprecated and removed in version >= 2.2.0."
|
|
59
|
+
raise e
|
|
60
|
+
rescue Exception => e
|
|
61
|
+
log "Failure to create model from class #{source.name}: #{e.inspect.to_s}"
|
|
62
|
+
raise e
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
model
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def login; end
|
|
69
|
+
|
|
70
|
+
def query(params=nil); end
|
|
71
|
+
|
|
72
|
+
def search(params=nil); end
|
|
73
|
+
|
|
74
|
+
def sync
|
|
75
|
+
if @result and @result.empty?
|
|
76
|
+
@source.lock(:md) do |s|
|
|
77
|
+
s.flush_data(:md)
|
|
78
|
+
s.put_value(:md_size,0)
|
|
79
|
+
end
|
|
80
|
+
else
|
|
81
|
+
if @result
|
|
82
|
+
@source.put_tmp_data(@tmp_docname,@result)
|
|
83
|
+
@stash_size += @result.size
|
|
84
|
+
end
|
|
85
|
+
@source.lock(:md) do |s|
|
|
86
|
+
s.flush_data(:md)
|
|
87
|
+
s.rename_tmp_data(@tmp_docname,:md)
|
|
88
|
+
s.put_value(:md_size,@stash_size)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def before_query
|
|
94
|
+
@tmp_docname = :md.to_s + get_random_uuid
|
|
95
|
+
@stash_size = 0
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def after_query
|
|
99
|
+
res = nil
|
|
100
|
+
if @source.is_pass_through?
|
|
101
|
+
res = @result
|
|
102
|
+
else
|
|
103
|
+
self.sync
|
|
104
|
+
res = true
|
|
105
|
+
end
|
|
106
|
+
res
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def do_query(params=nil)
|
|
110
|
+
before_query
|
|
111
|
+
params ? self.query(params) : self.query
|
|
112
|
+
after_query
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def stash_result
|
|
116
|
+
return if @result.nil?
|
|
117
|
+
@source.put_tmp_data(@tmp_docname,@result,true)
|
|
118
|
+
@stash_size += @result.size
|
|
119
|
+
@result = nil
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def expire_bulk_data(partition = :user)
|
|
123
|
+
Rhoconnect.expire_bulk_data(current_user.login,partition)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# do pre-processing before CUD operation
|
|
127
|
+
def validate(operation,operations_hashes,client_ids)
|
|
128
|
+
{}
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def create(create_hash); end
|
|
132
|
+
|
|
133
|
+
def update(update_hash); end
|
|
134
|
+
|
|
135
|
+
def delete(delete_hash); end
|
|
136
|
+
|
|
137
|
+
def ask(params=nil); end
|
|
138
|
+
|
|
139
|
+
def logoff; end
|
|
140
|
+
|
|
141
|
+
# re-define in subc;ass to provide your own filename
|
|
142
|
+
def store_blob(obj,field_name,blob)
|
|
143
|
+
blob[:tempfile].path if blob[:tempfile]
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# plugin callbacks implementation
|
|
147
|
+
def push_objects(params)
|
|
148
|
+
timeout = params[:timeout] || 10
|
|
149
|
+
raise_on_expire = params[:raise_on_expire] || false
|
|
150
|
+
rebuild_md = params[:rebuild_md].nil? ? true : params[:rebuild_md]
|
|
151
|
+
objects = params[:objects]
|
|
152
|
+
|
|
153
|
+
@source.lock(:md,timeout,raise_on_expire) do |s|
|
|
154
|
+
diff_count = 0
|
|
155
|
+
# in case of rebuild_md
|
|
156
|
+
# we clean-up and rebuild the whole :md doc
|
|
157
|
+
# on every request
|
|
158
|
+
if(rebuild_md)
|
|
159
|
+
doc = @source.get_data(:md)
|
|
160
|
+
orig_doc_size = doc.size
|
|
161
|
+
objects.each do |id,obj|
|
|
162
|
+
doc[id] ||= {}
|
|
163
|
+
doc[id].merge!(obj)
|
|
164
|
+
end if objects
|
|
165
|
+
diff_count = doc.size - orig_doc_size
|
|
166
|
+
@source.put_data(:md,doc)
|
|
167
|
+
else
|
|
168
|
+
# if rebuild_md == false
|
|
169
|
+
# we only operate on specific set values
|
|
170
|
+
# which brings a big optimization
|
|
171
|
+
# in case of small transactions
|
|
172
|
+
diff_count = @source.update_objects(:md, objects)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
@source.update_count(:md_size,diff_count)
|
|
176
|
+
end
|
|
177
|
+
@source.announce_changes
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def push_deletes(params)
|
|
181
|
+
timeout = params[:timeout] || 10
|
|
182
|
+
raise_on_expire = params[:raise_on_expire] || false
|
|
183
|
+
rebuild_md = params[:rebuild_md].nil? ? true : params[:rebuild_md]
|
|
184
|
+
objects = params[:objects]
|
|
185
|
+
|
|
186
|
+
@source.lock(:md,timeout,raise_on_expire) do |s|
|
|
187
|
+
diff_count = 0
|
|
188
|
+
if(rebuild_md)
|
|
189
|
+
# in case of rebuild_md
|
|
190
|
+
# we clean-up and rebuild the whole :md doc
|
|
191
|
+
# on every request
|
|
192
|
+
doc = @source.get_data(:md)
|
|
193
|
+
orig_doc_size = doc.size
|
|
194
|
+
objects.each do |id|
|
|
195
|
+
doc.delete(id)
|
|
196
|
+
end if objects
|
|
197
|
+
diff_count = doc.size - orig_doc_size
|
|
198
|
+
@source.put_data(:md,doc)
|
|
199
|
+
else
|
|
200
|
+
# if rebuild_md == false
|
|
201
|
+
# we only operate on specific set values
|
|
202
|
+
# which brings a big optimization
|
|
203
|
+
# in case of small transactions
|
|
204
|
+
diff_count = -@source.remove_objects(:md, objects)
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
@source.update_count(:md_size,diff_count)
|
|
208
|
+
end
|
|
209
|
+
@source.announce_changes
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
protected
|
|
213
|
+
def current_user
|
|
214
|
+
@source.user
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
# to preserve backward compatibility
|
|
221
|
+
# TODO: Remove in 4.1
|
|
222
|
+
SourceAdapter = Rhoconnect::Model::Base
|
|
223
|
+
SourceAdapterException = Rhoconnect::Model::Exception
|
|
224
|
+
SourceAdapterLoginException = Rhoconnect::Model::LoginException
|
|
225
|
+
SourceAdapterLogoffException = Rhoconnect::Model::LogoffException
|
|
226
|
+
SourceAdapterServerTimeoutException = Rhoconnect::Model::ServerTimeoutException
|
|
227
|
+
SourceAdapterServerErrorException = Rhoconnect::Model::ServerErrorException
|
|
228
|
+
SourceAdapterObjectConflictErrorException = Rhoconnect::Model::ObjectConflictErrorException
|
|
229
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
require 'rest_client'
|
|
3
|
+
require 'uri'
|
|
4
|
+
|
|
5
|
+
module Rhoconnect
|
|
6
|
+
module Model
|
|
7
|
+
class DynamicAdapterModel < Rhoconnect::Model::Base
|
|
8
|
+
attr_accessor :uri, :partition
|
|
9
|
+
|
|
10
|
+
def initialize(source, partition=nil, uri=nil)
|
|
11
|
+
@source = source
|
|
12
|
+
@uri = uri || Rhoconnect.appserver
|
|
13
|
+
@partition = partition || @source.user_id
|
|
14
|
+
|
|
15
|
+
if @uri
|
|
16
|
+
@uri = URI.parse(@uri)
|
|
17
|
+
user = @uri.user
|
|
18
|
+
@uri.user = nil
|
|
19
|
+
@uri = @uri.to_s
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
@token = Rhoconnect.api_token || user
|
|
23
|
+
raise Exception.new("Please provide a :token or set it in uri") unless @token
|
|
24
|
+
super(source)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.authenticate(login,password)
|
|
28
|
+
hsh = {:login => login, :password => password, :api_token => Rhoconnect.api_token}.to_json
|
|
29
|
+
headers = {:content_type => :json, :accept => :json}
|
|
30
|
+
RestClient.post "#{Rhoconnect.appserver}/rhoconnect/authenticate", hsh, headers
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def query(params=nil)
|
|
34
|
+
@result={}
|
|
35
|
+
@result = JSON.parse(send_objects('query',@source.name, @partition, params))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def create(create_hash)
|
|
39
|
+
send_objects('create',@source.name, @partition, create_hash)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def update(update_hash)
|
|
43
|
+
send_objects('update',@source.name, @partition, update_hash)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def delete(delete_hash)
|
|
47
|
+
send_objects('delete',@source.name, @partition, delete_hash)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
#protected
|
|
51
|
+
|
|
52
|
+
def validate_args(action, source_name, partition, obj = {}) # :nodoc:
|
|
53
|
+
raise Exception.new("Please set uri in your settings or through console") unless @uri
|
|
54
|
+
raise ArgumentError.new("Missing object id for #{obj.inspect}") if ['update','delete'].include? action and not obj.has_key?('id')
|
|
55
|
+
raise ArgumentError.new("Missing source_name.") if source_name.empty?
|
|
56
|
+
#raise ArgumentError.new("Missing partition for #{model}.") unless partition or partition.blank?
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def send_objects(action, source_name, partition, obj = {}) # :nodoc:
|
|
60
|
+
validate_args(action, source_name, partition, obj)
|
|
61
|
+
process(:post, "/rhoconnect/#{action}",
|
|
62
|
+
{
|
|
63
|
+
:resource => source_name,
|
|
64
|
+
:partition => partition,
|
|
65
|
+
:attributes => obj
|
|
66
|
+
}
|
|
67
|
+
)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def resource(path) # :nodoc:
|
|
71
|
+
RestClient::Resource.new(@uri)[path]
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def process(method, path, payload = nil) # :nodoc:
|
|
75
|
+
headers = api_headers
|
|
76
|
+
payload = payload.merge!(:api_token => @token).to_json
|
|
77
|
+
args = [method, payload, headers].compact
|
|
78
|
+
response = resource(path).send(*args)
|
|
79
|
+
response
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def api_headers # :nodoc:
|
|
83
|
+
{
|
|
84
|
+
:content_type => :json,
|
|
85
|
+
:accept => :json
|
|
86
|
+
}
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
module Rhoconnect
|
|
2
|
+
module Model
|
|
3
|
+
class JsBase < Rhoconnect::Model::Base
|
|
4
|
+
class << self
|
|
5
|
+
attr_accessor :js_method_list,:actual_name
|
|
6
|
+
end
|
|
7
|
+
attr_accessor :result
|
|
8
|
+
|
|
9
|
+
def method_missing(method_name,*args)
|
|
10
|
+
obj = Object.const_get(self.class.to_s)
|
|
11
|
+
if obj.js_method_list.include? method_name.to_s
|
|
12
|
+
package_and_publish(method_name,args)
|
|
13
|
+
else
|
|
14
|
+
log "METHOD #{method_name} NOT DEFINED IN JS MODEL #{self.class.to_s}"
|
|
15
|
+
return "#{method_name} method not defined for #{self.class.to_s}"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.register_models(models)
|
|
20
|
+
app = App.load(APP_NAME)
|
|
21
|
+
models.each do |key,val|
|
|
22
|
+
a_name = key
|
|
23
|
+
klassified = key.classify
|
|
24
|
+
unless Object.const_defined?(klassified)
|
|
25
|
+
klass = Object.const_set(klassified, Class.new(Rhoconnect::Model::JsBase))
|
|
26
|
+
klass.js_method_list = val
|
|
27
|
+
klass.actual_name = a_name
|
|
28
|
+
end
|
|
29
|
+
source = Source.load(klassified,{:app_id=>APP_NAME,:user_id=>'*'})
|
|
30
|
+
unless source
|
|
31
|
+
sconfig = Rhoconnect.source_config(klassified)
|
|
32
|
+
Source.create(sconfig.merge!(:name => klassified),{:app_id => APP_NAME})
|
|
33
|
+
app.sources << klassified
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def login
|
|
39
|
+
rho_methods('login')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def query(params=nil)
|
|
43
|
+
@result = rho_methods('query',params)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def search(params=nil)
|
|
47
|
+
rho_methods('search',params)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def create(create_hash)
|
|
51
|
+
rho_methods('create',create_hash)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def update(update_hash)
|
|
55
|
+
rho_methods('update',update_hash)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def delete(delete_hash)
|
|
59
|
+
rho_methods('delete',delete_hash)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def logoff
|
|
63
|
+
rho_methods('logoff')
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def store_blob(obj,field_name,blob)
|
|
67
|
+
raise "store_blob not implemented in JavaScript yet."
|
|
68
|
+
# TODO: add method handling here
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
|
|
73
|
+
def rho_methods(name,args=nil)
|
|
74
|
+
obj = Object.const_get(self.class.to_s)
|
|
75
|
+
if obj.js_method_list.include? name
|
|
76
|
+
package_and_publish(name,args)
|
|
77
|
+
else
|
|
78
|
+
sup.send(name,args)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def package_and_publish(method_name,args=nil)
|
|
83
|
+
json = {
|
|
84
|
+
:klss => self.class.actual_name,
|
|
85
|
+
:function => method_name,
|
|
86
|
+
:args => args,
|
|
87
|
+
:route => 'request'
|
|
88
|
+
}
|
|
89
|
+
NodeChannel.publish_channel_and_wait(json,self.class)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
#allows me to call super method by passing string
|
|
96
|
+
class SuperProxy
|
|
97
|
+
def initialize(obj)
|
|
98
|
+
@obj = obj
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def method_missing(meth, *args)
|
|
102
|
+
@obj.class.superclass.superclass.instance_method(meth).bind(@obj).call(*args)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
class Object
|
|
107
|
+
private
|
|
108
|
+
def sup
|
|
109
|
+
SuperProxy.new(self)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
class String
|
|
114
|
+
def classify
|
|
115
|
+
result = self.split("_").inject("") do |res,index|
|
|
116
|
+
res += index.capitalize
|
|
117
|
+
res
|
|
118
|
+
end
|
|
119
|
+
result
|
|
120
|
+
end
|
|
121
|
+
end
|
|
@@ -6,7 +6,7 @@ module Rhoconnect
|
|
|
6
6
|
# register the adapter as pre-defined
|
|
7
7
|
Rhoconnect.register_predefined_source('RhoInternalBenchmarkAdapter')
|
|
8
8
|
|
|
9
|
-
class RhoInternalBenchmarkAdapter < Rhoconnect::
|
|
9
|
+
class RhoInternalBenchmarkAdapter < Rhoconnect::Model::Base
|
|
10
10
|
def initialize(source)
|
|
11
11
|
super(source)
|
|
12
12
|
end
|
|
@@ -22,10 +22,10 @@ module Rhoconnect
|
|
|
22
22
|
#end
|
|
23
23
|
sleep @source.simulate_time
|
|
24
24
|
end
|
|
25
|
-
Rhoconnect::Store.lock(lock_name,1) do
|
|
25
|
+
#Rhoconnect::Store.lock(lock_name,1) do
|
|
26
26
|
@result = Rhoconnect::Store.get_data(db_name)
|
|
27
|
-
end
|
|
28
|
-
|
|
27
|
+
#end
|
|
28
|
+
#@result
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def create(create_hash)
|
|
@@ -54,12 +54,15 @@ module Rhoconnect
|
|
|
54
54
|
Rhoconnect::Store.lock(lock_name,1) do
|
|
55
55
|
Rhoconnect::Store.delete_data(db_name,{id=>delete_hash}) if id
|
|
56
56
|
end
|
|
57
|
+
id
|
|
57
58
|
end
|
|
58
59
|
|
|
59
60
|
def db_name
|
|
60
61
|
res = ''
|
|
61
62
|
if @source.user_id[0..1] == 'nq'
|
|
62
63
|
res = "test_db_storage:#{@source.app_id}:nquser"
|
|
64
|
+
elsif @source.user_id[0..1] == 'mq'
|
|
65
|
+
res = "test_db_storage:#{@source.app_id}:mquser"
|
|
63
66
|
else
|
|
64
67
|
res = "test_db_storage:#{@source.app_id}:benchuser"
|
|
65
68
|
end
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module Rhoconnect
|
|
2
|
-
class ReadState <
|
|
2
|
+
class ReadState < StoreOrm
|
|
3
3
|
field :refresh_time, :integer
|
|
4
4
|
field :prev_refresh_time, :integer
|
|
5
5
|
field :retry_counter, :integer
|
|
@@ -20,11 +20,11 @@ module Rhoconnect
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def self.delete(app_id)
|
|
23
|
-
Store.
|
|
23
|
+
Store.flush_data("#{class_prefix(self)}:#{app_id}:*")
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def self.delete_user(params)
|
|
27
|
-
Store.
|
|
27
|
+
Store.flush_data("#{class_prefix(self)}:#{params[:app_id]}:#{params[:user_id]}:#{params[:source_name]}:*")
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
private
|