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
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
module Rhoconnect
|
|
2
|
-
class SourceAdapterException < RuntimeError; end
|
|
3
|
-
|
|
4
|
-
# raise this to cause client to be logged out during a sync
|
|
5
|
-
class SourceAdapterLoginException < SourceAdapterException; end
|
|
6
|
-
|
|
7
|
-
class SourceAdapterLogoffException < SourceAdapterException; end
|
|
8
|
-
|
|
9
|
-
# raise these to trigger rhoconnect sending an error to the client
|
|
10
|
-
class SourceAdapterServerTimeoutException < SourceAdapterException; end
|
|
11
|
-
class SourceAdapterServerErrorException < SourceAdapterException; end
|
|
12
|
-
|
|
13
|
-
class SourceAdapterObjectConflictError < SourceAdapterException; end
|
|
14
|
-
|
|
15
|
-
class SourceAdapter
|
|
16
|
-
attr_accessor :session
|
|
17
|
-
|
|
18
|
-
def initialize(source,credential=nil)
|
|
19
|
-
@source = source
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def self.create(source,credential=nil)
|
|
23
|
-
adapter=nil
|
|
24
|
-
if source
|
|
25
|
-
begin
|
|
26
|
-
if source.name
|
|
27
|
-
source.name = source.name.dup if source.name.frozen?
|
|
28
|
-
source.name.strip!
|
|
29
|
-
end
|
|
30
|
-
# certain adapters are pre-defined and reserved
|
|
31
|
-
# load them and instantiate
|
|
32
|
-
if Rhoconnect.predefined_sources.has_key?(source.name)
|
|
33
|
-
adapter=(Object.const_get(source.name)).new(source)
|
|
34
|
-
elsif Object.const_defined?(source.name) && Object.const_get(source.name).to_s.split("::").first != 'Rhoconnect'
|
|
35
|
-
# fix until source adpaters are phased out, checking for Rhoconnect namespace
|
|
36
|
-
# so that backend models with same name as Rhoconnect models are instantiated correctly
|
|
37
|
-
require under_score(source.name)
|
|
38
|
-
adapter=(Object.const_get(source.name)).new(source)
|
|
39
|
-
else
|
|
40
|
-
adapter=DynamicAdapter.new(source)
|
|
41
|
-
end
|
|
42
|
-
rescue ArgumentError => e
|
|
43
|
-
# Backward compatibility with code generated by gems < 2.2.0
|
|
44
|
-
adapter=(Object.const_get(source.name)).new(source,credential)
|
|
45
|
-
log "WARNING: credential parameter in `initialize` method is deprecated and removed in version >= 2.2.0."
|
|
46
|
-
rescue Exception => e
|
|
47
|
-
log "Failure to create adapter from class #{source.name}: #{e.inspect.to_s}"
|
|
48
|
-
raise e
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
adapter
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def login; end
|
|
55
|
-
|
|
56
|
-
def query(params=nil); end
|
|
57
|
-
|
|
58
|
-
def search(params=nil); end
|
|
59
|
-
|
|
60
|
-
def sync
|
|
61
|
-
if @result and @result.empty?
|
|
62
|
-
@source.lock(:md) do |s|
|
|
63
|
-
s.flash_data(:md)
|
|
64
|
-
s.put_value(:md_size,0)
|
|
65
|
-
end
|
|
66
|
-
else
|
|
67
|
-
if @result
|
|
68
|
-
Store.put_data(@tmp_docname,@result)
|
|
69
|
-
@stash_size += @result.size
|
|
70
|
-
end
|
|
71
|
-
@source.lock(:md) do |s|
|
|
72
|
-
s.flash_data(:md)
|
|
73
|
-
Store.rename(@tmp_docname,s.docname(:md))
|
|
74
|
-
s.put_value(:md_size,@stash_size)
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def do_query(params=nil)
|
|
80
|
-
@tmp_docname = @source.docname(:md) + get_random_uuid
|
|
81
|
-
@stash_size = 0
|
|
82
|
-
params ? self.query(params) : self.query
|
|
83
|
-
if @source.is_pass_through?
|
|
84
|
-
@result
|
|
85
|
-
else
|
|
86
|
-
self.sync
|
|
87
|
-
true
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def stash_result
|
|
92
|
-
return if @result.nil?
|
|
93
|
-
Store.put_data(@tmp_docname,@result,true)
|
|
94
|
-
@stash_size += @result.size
|
|
95
|
-
@result = nil
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def expire_bulk_data(partition = :user)
|
|
99
|
-
Rhoconnect.expire_bulk_data(current_user.login,partition)
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
# do pre-processing before CUD operation
|
|
103
|
-
def validate(operation,operations_hashes,client_ids)
|
|
104
|
-
{}
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def create(create_hash); end
|
|
108
|
-
|
|
109
|
-
def update(update_hash); end
|
|
110
|
-
|
|
111
|
-
def delete(delete_hash); end
|
|
112
|
-
|
|
113
|
-
def ask(params=nil); end
|
|
114
|
-
|
|
115
|
-
def logoff; end
|
|
116
|
-
|
|
117
|
-
def save(docname)
|
|
118
|
-
return if @result.nil?
|
|
119
|
-
if @result.empty?
|
|
120
|
-
Store.flash_data(docname)
|
|
121
|
-
else
|
|
122
|
-
Store.put_data(docname,@result)
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
protected
|
|
127
|
-
def current_user
|
|
128
|
-
@source.user
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
end
|
|
132
|
-
end
|
|
@@ -1,464 +0,0 @@
|
|
|
1
|
-
module Rhoconnect
|
|
2
|
-
class SourceSync
|
|
3
|
-
attr_reader :adapter
|
|
4
|
-
|
|
5
|
-
def initialize(source)
|
|
6
|
-
@source = source
|
|
7
|
-
raise InvalidArgumentError.new('Invalid source') if @source.nil?
|
|
8
|
-
raise InvalidArgumentError.new('Invalid app for source') unless @source.app
|
|
9
|
-
@adapter = SourceAdapter.create(@source)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# CUD Operations
|
|
13
|
-
def create
|
|
14
|
-
_measure_and_process_cud('create')
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def update
|
|
18
|
-
_measure_and_process_cud('update')
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def delete
|
|
22
|
-
_measure_and_process_cud('delete')
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# Pass through CUD to adapter, no data stored
|
|
26
|
-
def pass_through_cud(cud_params,query_params)
|
|
27
|
-
return if _auth_op('login') == false
|
|
28
|
-
res,processed_objects = {},[]
|
|
29
|
-
begin
|
|
30
|
-
['create','update','delete'].each do |op|
|
|
31
|
-
key,objects = op,cud_params[op]
|
|
32
|
-
objects.each do |key,value|
|
|
33
|
-
case op
|
|
34
|
-
when 'create'
|
|
35
|
-
@adapter.send(op.to_sym,value)
|
|
36
|
-
when 'update'
|
|
37
|
-
value['id'] = key
|
|
38
|
-
@adapter.send(op.to_sym,value)
|
|
39
|
-
when 'delete'
|
|
40
|
-
value['id'] = key
|
|
41
|
-
@adapter.send(op.to_sym,value)
|
|
42
|
-
end
|
|
43
|
-
processed_objects << key
|
|
44
|
-
end if objects
|
|
45
|
-
end
|
|
46
|
-
rescue Exception => e
|
|
47
|
-
log "Error in pass through method: #{e.message}"
|
|
48
|
-
res['error'] = {'message' => e.message }
|
|
49
|
-
end
|
|
50
|
-
_auth_op('logoff')
|
|
51
|
-
res['processed'] = processed_objects
|
|
52
|
-
res.to_json
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
# Read Operation; params are query arguments
|
|
56
|
-
def read(client_id=nil,params=nil)
|
|
57
|
-
_read('query',client_id,params)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def search(client_id=nil,params=nil)
|
|
61
|
-
return if _auth_op('login',client_id) == false
|
|
62
|
-
res = _read('search',client_id,params)
|
|
63
|
-
_auth_op('logoff',client_id)
|
|
64
|
-
res
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def process_cud
|
|
68
|
-
if @source.cud_queue or @source.queue
|
|
69
|
-
async(:cud,@source.cud_queue || @source.queue)
|
|
70
|
-
else
|
|
71
|
-
do_cud
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def do_cud
|
|
76
|
-
return if _auth_op('login') == false
|
|
77
|
-
self.create
|
|
78
|
-
self.update
|
|
79
|
-
self.delete
|
|
80
|
-
_auth_op('logoff')
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def process_query(params=nil)
|
|
84
|
-
if @source.query_queue or @source.queue
|
|
85
|
-
async(:query,@source.query_queue || @source.queue,params)
|
|
86
|
-
else
|
|
87
|
-
do_query(params)
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def do_query(params=nil)
|
|
92
|
-
result = nil
|
|
93
|
-
@source.if_need_refresh do
|
|
94
|
-
Rhoconnect::Stats::Record.update("source:query:#{@source.name}") do
|
|
95
|
-
if _auth_op('login')
|
|
96
|
-
result = self.read(nil,params)
|
|
97
|
-
_auth_op('logoff')
|
|
98
|
-
end
|
|
99
|
-
# re-wind refresh time in case of error
|
|
100
|
-
query_failure = Store.exists?(@source.docname(:errors))
|
|
101
|
-
@source.rewind_refresh_time(query_failure)
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
result
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
# Enqueue a job for the source based on job type
|
|
108
|
-
def async(job_type,queue_name,params=nil)
|
|
109
|
-
SourceJob.queue = queue_name
|
|
110
|
-
Resque.enqueue(SourceJob,job_type,@source.id,
|
|
111
|
-
@source.app_id,@source.user_id,params)
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
def fast_insert(new_objs, timeout=10,raise_on_expire=false)
|
|
115
|
-
@source.lock(:md,timeout,raise_on_expire) do |s|
|
|
116
|
-
diff_count = new_objs.size
|
|
117
|
-
@source.put_data(:md, new_objs, true)
|
|
118
|
-
@source.update_count(:md_size,diff_count)
|
|
119
|
-
end
|
|
120
|
-
@source.announce_changes
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
def fast_update(remove_hash, new_hash, timeout=10,raise_on_expire=false)
|
|
124
|
-
return unless ((remove_hash and remove_hash.size > 0) or (new_hash and new_hash.size > 0))
|
|
125
|
-
@source.lock(:md,timeout,raise_on_expire) do |s|
|
|
126
|
-
# get the objects from DB, remove prev attr data, add new attr data
|
|
127
|
-
update_keys = Set.new
|
|
128
|
-
update_keys += Set.new(remove_hash.keys) if remove_hash
|
|
129
|
-
update_keys += Set.new(new_hash.keys) if new_hash
|
|
130
|
-
objs_to_update = @source.get_objects(:md, update_keys.to_a) || {}
|
|
131
|
-
diff_count = -objs_to_update.size
|
|
132
|
-
# remove old values from DB
|
|
133
|
-
@source.delete_data(:md, objs_to_update)
|
|
134
|
-
# update data
|
|
135
|
-
remove_hash.each do |key, obj|
|
|
136
|
-
next unless objs_to_update[key]
|
|
137
|
-
obj.each do |attrib, value|
|
|
138
|
-
objs_to_update[key].delete(attrib)
|
|
139
|
-
objs_to_update.delete(key) if objs_to_update[key].empty?
|
|
140
|
-
end
|
|
141
|
-
end if remove_hash
|
|
142
|
-
new_hash.each do |key, obj|
|
|
143
|
-
objs_to_update[key] ||= {}
|
|
144
|
-
objs_to_update[key].merge!(obj)
|
|
145
|
-
end if new_hash
|
|
146
|
-
# store new data into DB
|
|
147
|
-
@source.put_data(:md, objs_to_update, true)
|
|
148
|
-
diff_count += objs_to_update.size
|
|
149
|
-
@source.update_count(:md_size,diff_count)
|
|
150
|
-
end
|
|
151
|
-
@source.announce_changes
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
def fast_delete(delete_objs, timeout=10,raise_on_expire=false)
|
|
155
|
-
@source.lock(:md,timeout,raise_on_expire) do |s|
|
|
156
|
-
diff_count = -delete_objs.size
|
|
157
|
-
@source.delete_data(:md, delete_objs)
|
|
158
|
-
@source.update_count(:md_size,diff_count)
|
|
159
|
-
end
|
|
160
|
-
@source.announce_changes
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
def push_objects(objects,timeout=10,raise_on_expire=false,rebuild_md=true)
|
|
164
|
-
@source.lock(:md,timeout,raise_on_expire) do |s|
|
|
165
|
-
diff_count = 0
|
|
166
|
-
# in case of rebuild_md
|
|
167
|
-
# we clean-up and rebuild the whole :md doc
|
|
168
|
-
# on every request
|
|
169
|
-
if(rebuild_md)
|
|
170
|
-
doc = @source.get_data(:md)
|
|
171
|
-
orig_doc_size = doc.size
|
|
172
|
-
objects.each do |id,obj|
|
|
173
|
-
doc[id] ||= {}
|
|
174
|
-
doc[id].merge!(obj)
|
|
175
|
-
end
|
|
176
|
-
diff_count = doc.size - orig_doc_size
|
|
177
|
-
@source.put_data(:md,doc)
|
|
178
|
-
else
|
|
179
|
-
# if rebuild_md == false
|
|
180
|
-
# we only operate on specific set values
|
|
181
|
-
# which brings a big optimization
|
|
182
|
-
# in case of small transactions
|
|
183
|
-
diff_count = @source.update_objects(:md, objects)
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
@source.update_count(:md_size,diff_count)
|
|
187
|
-
end
|
|
188
|
-
@source.announce_changes
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
def push_deletes(objects,timeout=10,raise_on_expire=false,rebuild_md=true)
|
|
192
|
-
@source.lock(:md,timeout,raise_on_expire) do |s|
|
|
193
|
-
diff_count = 0
|
|
194
|
-
if(rebuild_md)
|
|
195
|
-
# in case of rebuild_md
|
|
196
|
-
# we clean-up and rebuild the whole :md doc
|
|
197
|
-
# on every request
|
|
198
|
-
doc = @source.get_data(:md)
|
|
199
|
-
orig_doc_size = doc.size
|
|
200
|
-
objects.each do |id|
|
|
201
|
-
doc.delete(id)
|
|
202
|
-
end
|
|
203
|
-
diff_count = doc.size - orig_doc_size
|
|
204
|
-
@source.put_data(:md,doc)
|
|
205
|
-
else
|
|
206
|
-
# if rebuild_md == false
|
|
207
|
-
# we only operate on specific set values
|
|
208
|
-
# which brings a big optimization
|
|
209
|
-
# in case of small transactions
|
|
210
|
-
diff_count = -@source.remove_objects(:md, objects)
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
@source.update_count(:md_size,diff_count)
|
|
214
|
-
end
|
|
215
|
-
@source.announce_changes
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
private
|
|
219
|
-
def _auth_op(operation,client_id=-1)
|
|
220
|
-
edockey = client_id == -1 ? @source.docname(:errors) :
|
|
221
|
-
Client.load(client_id,{:source_name => @source.name}).docname(:search_errors)
|
|
222
|
-
begin
|
|
223
|
-
Store.flash_data(edockey) if operation == 'login'
|
|
224
|
-
@adapter.send operation
|
|
225
|
-
rescue Exception => e
|
|
226
|
-
log "SourceAdapter raised #{operation} exception: #{e}"
|
|
227
|
-
log e.backtrace.join("\n")
|
|
228
|
-
Store.put_data(edockey,{"#{operation}-error"=>{'message'=>e.message}},true)
|
|
229
|
-
return false
|
|
230
|
-
end
|
|
231
|
-
true
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
def _process_create(modified_recs,key,value)
|
|
235
|
-
link = @adapter.create value
|
|
236
|
-
# Store object-id link for the client
|
|
237
|
-
# If we have a link, store object in client document
|
|
238
|
-
# Otherwise, store object for delete on client
|
|
239
|
-
modified_recs.each do |modified_rec|
|
|
240
|
-
if link
|
|
241
|
-
modified_rec[:links] ||= {}
|
|
242
|
-
modified_rec[:links][modified_rec[:key]] = { 'l' => link.to_s }
|
|
243
|
-
modified_rec[:creates] ||= {}
|
|
244
|
-
modified_rec[:creates][link.to_s] = value
|
|
245
|
-
else
|
|
246
|
-
modified_rec[:deletes] ||= {}
|
|
247
|
-
modified_rec[:deletes][modified_rec[:key]] = value
|
|
248
|
-
end
|
|
249
|
-
end
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
def _process_update(modified_recs,key,value)
|
|
253
|
-
# Add id to object hash to forward to backend call
|
|
254
|
-
value['id'] = key
|
|
255
|
-
# Perform operation
|
|
256
|
-
@adapter.update value
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
def _process_delete(modified_recs,key,value)
|
|
260
|
-
value['id'] = key
|
|
261
|
-
@adapter.delete value
|
|
262
|
-
# Perform operation
|
|
263
|
-
modified_recs.each do |modified_rec|
|
|
264
|
-
modified_rec[:dels] ||= {}
|
|
265
|
-
modified_rec[:dels][modified_rec[:key]] = value
|
|
266
|
-
end
|
|
267
|
-
end
|
|
268
|
-
|
|
269
|
-
def _measure_and_process_cud(operation)
|
|
270
|
-
Rhoconnect::Stats::Record.update("source:#{operation}:#{@source.name}") do
|
|
271
|
-
_process_cud(operation)
|
|
272
|
-
end
|
|
273
|
-
end
|
|
274
|
-
|
|
275
|
-
def _process_cud(operation)
|
|
276
|
-
# take everything from the queue and erase it
|
|
277
|
-
# so that no other process will be able to process it again
|
|
278
|
-
operation_hashes = []
|
|
279
|
-
client_ids = []
|
|
280
|
-
@source.lock(operation) do |s|
|
|
281
|
-
operation_hashes,client_ids = s.get_zdata(operation)
|
|
282
|
-
s.flush_zdata(operation)
|
|
283
|
-
end
|
|
284
|
-
invalid_meta = @adapter.validate(operation,operation_hashes,client_ids)
|
|
285
|
-
|
|
286
|
-
errors,links,deletes,creates,dels = {},{},{},{},{}
|
|
287
|
-
operation_hashes.each_with_index do |client_operation_data,index|
|
|
288
|
-
client_id = client_ids[index]
|
|
289
|
-
|
|
290
|
-
current_invalid_meta = invalid_meta[index] || {}
|
|
291
|
-
client_operation_data.each do |key, value|
|
|
292
|
-
begin
|
|
293
|
-
continue_loop = true
|
|
294
|
-
modified_recs = [{:client_id => client_id, :key => key, :value => value }]
|
|
295
|
-
record_invalid_meta = current_invalid_meta[key] || {}
|
|
296
|
-
# Remove object from queue
|
|
297
|
-
client_operation_data.delete(key)
|
|
298
|
-
|
|
299
|
-
# skip the rec - if it is a duplicate of some other record
|
|
300
|
-
next if record_invalid_meta[:duplicate_of]
|
|
301
|
-
|
|
302
|
-
# prepare duplicate docs
|
|
303
|
-
duplicates = record_invalid_meta[:duplicates] || {}
|
|
304
|
-
duplicates.each do |duplicate|
|
|
305
|
-
modified_recs << duplicate
|
|
306
|
-
end
|
|
307
|
-
|
|
308
|
-
# raise conflict error if record is marked with one
|
|
309
|
-
raise SourceAdapterObjectConflictError.new(record_invalid_meta[:error]) if record_invalid_meta[:error]
|
|
310
|
-
|
|
311
|
-
# Call on source adapter to process individual object
|
|
312
|
-
case operation
|
|
313
|
-
when 'create'
|
|
314
|
-
_process_create(modified_recs,key,value)
|
|
315
|
-
when 'update'
|
|
316
|
-
_process_update(modified_recs,key,value)
|
|
317
|
-
when 'delete'
|
|
318
|
-
_process_delete(modified_recs,key,value)
|
|
319
|
-
end
|
|
320
|
-
rescue Exception => e
|
|
321
|
-
log "SourceAdapter raised #{operation} exception: #{e}"
|
|
322
|
-
log e.backtrace.join("\n")
|
|
323
|
-
continue_loop = false
|
|
324
|
-
modified_recs.each do |modified_rec|
|
|
325
|
-
modified_rec[:errors] ||= {}
|
|
326
|
-
modified_rec[:errors][modified_rec[:key]] = modified_rec[:value]
|
|
327
|
-
modified_rec[:errors]["#{modified_rec[:key]}-error"] = {'message'=>e.message}
|
|
328
|
-
end
|
|
329
|
-
end
|
|
330
|
-
|
|
331
|
-
{ :errors => errors,
|
|
332
|
-
:links => links,
|
|
333
|
-
:deletes => deletes,
|
|
334
|
-
:creates => creates,
|
|
335
|
-
:dels => dels }.each do |doc_name, doc|
|
|
336
|
-
modified_recs.each do |modified_rec|
|
|
337
|
-
doc[modified_rec[:client_id]] ||= {}
|
|
338
|
-
next unless modified_rec[doc_name]
|
|
339
|
-
doc[modified_rec[:client_id]].merge!(modified_rec[doc_name])
|
|
340
|
-
end
|
|
341
|
-
end
|
|
342
|
-
break unless continue_loop
|
|
343
|
-
end
|
|
344
|
-
|
|
345
|
-
# Record rest of queue (if something in the middle failed)
|
|
346
|
-
if not client_operation_data.empty?
|
|
347
|
-
@source.put_zdata(operation,client_id,client_operation_data,true)
|
|
348
|
-
end
|
|
349
|
-
end
|
|
350
|
-
|
|
351
|
-
# now, process all the modified docs
|
|
352
|
-
processed_clients = {}
|
|
353
|
-
client_ids.each do |client_id|
|
|
354
|
-
processed_clients[client_id] = Client.load(client_id,{:source_name => @source.name}) unless processed_clients[client_id]
|
|
355
|
-
end
|
|
356
|
-
{ "delete_page" => deletes,
|
|
357
|
-
"#{operation}_links" => links,
|
|
358
|
-
"#{operation}_errors" => errors }.each do |doctype,client_docs|
|
|
359
|
-
client_docs.each do |client_id,data|
|
|
360
|
-
client = processed_clients[client_id]
|
|
361
|
-
client.put_data(doctype,data,true) unless data.empty?
|
|
362
|
-
end
|
|
363
|
-
end
|
|
364
|
-
|
|
365
|
-
if operation == 'create'
|
|
366
|
-
total_creates = {}
|
|
367
|
-
creates.each do |client_id,client_doc|
|
|
368
|
-
next if client_doc.empty?
|
|
369
|
-
client = processed_clients[client_id]
|
|
370
|
-
client.put_data(:cd,client_doc,true)
|
|
371
|
-
client.update_count(:cd_size,client_doc.size)
|
|
372
|
-
total_creates.merge!(client_doc)
|
|
373
|
-
end
|
|
374
|
-
unless total_creates.empty?
|
|
375
|
-
@source.lock(:md) do |s|
|
|
376
|
-
s.put_data(:md,total_creates,true)
|
|
377
|
-
s.update_count(:md_size,total_creates.size)
|
|
378
|
-
end
|
|
379
|
-
end
|
|
380
|
-
end
|
|
381
|
-
|
|
382
|
-
if operation == 'delete'
|
|
383
|
-
# Clean up deleted objects from master document and corresponding client document
|
|
384
|
-
total_dels = {}
|
|
385
|
-
objs = {}
|
|
386
|
-
dels.each do |client_id,client_doc|
|
|
387
|
-
next if client_doc.empty?
|
|
388
|
-
client = processed_clients[client_id]
|
|
389
|
-
client.delete_data(:cd,client_doc)
|
|
390
|
-
client.update_count(:cd_size,-client_doc.size)
|
|
391
|
-
total_dels.merge!(client_doc)
|
|
392
|
-
end
|
|
393
|
-
unless total_dels.empty?
|
|
394
|
-
@source.lock(:md) do |s|
|
|
395
|
-
s.delete_data(:md,total_dels)
|
|
396
|
-
s.update_count(:md_size,-total_dels.size)
|
|
397
|
-
end
|
|
398
|
-
end
|
|
399
|
-
end
|
|
400
|
-
if operation == 'update'
|
|
401
|
-
errors.each do |client_id, error_doc|
|
|
402
|
-
next if error_doc.empty?
|
|
403
|
-
client = processed_clients[client_id]
|
|
404
|
-
cd = client.get_data(:cd)
|
|
405
|
-
error_doc.each do |key, value|
|
|
406
|
-
client.put_data(:update_rollback,{key => cd[key]},true) if cd[key]
|
|
407
|
-
end
|
|
408
|
-
end
|
|
409
|
-
end
|
|
410
|
-
end
|
|
411
|
-
|
|
412
|
-
# Metadata Operation; source adapter returns json
|
|
413
|
-
def _get_data(method)
|
|
414
|
-
if @adapter.respond_to?(method)
|
|
415
|
-
data = @adapter.send(method)
|
|
416
|
-
if data
|
|
417
|
-
@source.put_value(method,data)
|
|
418
|
-
if method == :schema
|
|
419
|
-
parsed = JSON.parse(data)
|
|
420
|
-
schema_version = parsed['version']
|
|
421
|
-
raise "Mandatory version key is not defined in source adapter schema method" if schema_version.nil?
|
|
422
|
-
@source.put_value("#{method}_sha1",Digest::SHA1.hexdigest(schema_version))
|
|
423
|
-
else
|
|
424
|
-
@source.put_value("#{method}_sha1",Digest::SHA1.hexdigest(data))
|
|
425
|
-
end
|
|
426
|
-
end
|
|
427
|
-
end
|
|
428
|
-
end
|
|
429
|
-
|
|
430
|
-
# Read Operation; params are query arguments
|
|
431
|
-
def _read(operation,client_id,params=nil)
|
|
432
|
-
errordoc = nil
|
|
433
|
-
result = nil
|
|
434
|
-
begin
|
|
435
|
-
if operation == 'search'
|
|
436
|
-
client = Client.load(client_id,{:source_name => @source.name})
|
|
437
|
-
errordoc = client.docname(:search_errors)
|
|
438
|
-
compute_token(client.docname(:search_token))
|
|
439
|
-
result = @adapter.search(params)
|
|
440
|
-
@adapter.save(client.docname(:search)) unless @source.is_pass_through?
|
|
441
|
-
else
|
|
442
|
-
errordoc = @source.docname(:errors)
|
|
443
|
-
[:metadata,:schema].each do |method|
|
|
444
|
-
_get_data(method)
|
|
445
|
-
end
|
|
446
|
-
result = @adapter.do_query(params)
|
|
447
|
-
end
|
|
448
|
-
# operation,sync succeeded, remove errors
|
|
449
|
-
Store.lock(errordoc) do
|
|
450
|
-
Store.flash_data(errordoc)
|
|
451
|
-
end
|
|
452
|
-
rescue Exception => e
|
|
453
|
-
# store sync,operation exceptions to be sent to all clients for this source/user
|
|
454
|
-
log "SourceAdapter raised #{operation} exception: #{e}"
|
|
455
|
-
log e.backtrace.join("\n")
|
|
456
|
-
Store.lock(errordoc) do
|
|
457
|
-
Store.put_data(errordoc,{"#{operation}-error"=>{'message'=>e.message}},true)
|
|
458
|
-
end
|
|
459
|
-
end
|
|
460
|
-
# pass through expects result hash
|
|
461
|
-
@source.is_pass_through? ? result : true
|
|
462
|
-
end
|
|
463
|
-
end
|
|
464
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
class Application < Rhoconnect::Base
|
|
2
|
-
class << self
|
|
3
|
-
def authenticate(username,password,session)
|
|
4
|
-
session[:auth] = "delegated"
|
|
5
|
-
raise RuntimeError.new('server error') if password == 'server error'
|
|
6
|
-
raise LoginException.new('login exception') if password == 'wrongpass'
|
|
7
|
-
return "different" if password == "diffuser"
|
|
8
|
-
password == 'wrongpassnomsg' ? false : true
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
# Add hooks for application startup here
|
|
12
|
-
# Don't forget to call super at the end!
|
|
13
|
-
def initializer(path)
|
|
14
|
-
super
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def ans_authenticate(username, password)
|
|
18
|
-
'ansuser:secret' == [username,password].join(':')
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
Application.initializer(File.dirname(__FILE__))
|