rhoconnect 3.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +208 -0
- data/CREDITS +38 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +97 -0
- data/LICENSE +75 -0
- data/README.md +10 -0
- data/Rakefile +82 -0
- data/bench/bench +7 -0
- data/bench/bench_runner.rb +112 -0
- data/bench/benchapp/Gemfile +21 -0
- data/bench/benchapp/Gemfile.lock +76 -0
- data/bench/benchapp/Rakefile +22 -0
- data/bench/benchapp/application.rb +39 -0
- data/bench/benchapp/config.ru +36 -0
- data/bench/benchapp/settings/license.key +1 -0
- data/bench/benchapp/settings/settings.yml +20 -0
- data/bench/benchapp/sources/mock_adapter.rb +55 -0
- data/bench/benchapp/sources/queue_mock_adapter.rb +2 -0
- data/bench/benchapp/spec/sources/mock_adapter_spec.rb +25 -0
- data/bench/benchapp/spec/sources/queue_mock_adapter_spec.rb +25 -0
- data/bench/benchapp/spec/spec_helper.rb +42 -0
- data/bench/blobapp/Gemfile +31 -0
- data/bench/blobapp/Gemfile.lock +103 -0
- data/bench/blobapp/Rakefile +25 -0
- data/bench/blobapp/application.rb +44 -0
- data/bench/blobapp/config.ru +36 -0
- data/bench/blobapp/settings/license.key +1 -0
- data/bench/blobapp/settings/settings.yml +16 -0
- data/bench/blobapp/sources/blob_adapter.rb +71 -0
- data/bench/blobapp/spec/sources/blob_adapter_spec.rb +25 -0
- data/bench/blobapp/spec/spec_helper.rb +42 -0
- data/bench/lib/bench/cli.rb +16 -0
- data/bench/lib/bench/logging.rb +13 -0
- data/bench/lib/bench/mock_client.rb +41 -0
- data/bench/lib/bench/result.rb +50 -0
- data/bench/lib/bench/runner.rb +107 -0
- data/bench/lib/bench/session.rb +67 -0
- data/bench/lib/bench/statistics.rb +56 -0
- data/bench/lib/bench/test_data.rb +98 -0
- data/bench/lib/bench/timer.rb +10 -0
- data/bench/lib/bench/utils.rb +49 -0
- data/bench/lib/bench.rb +129 -0
- data/bench/lib/testdata/100-data.txt +148 -0
- data/bench/lib/testdata/5-data.txt +9 -0
- data/bench/lib/testdata/images/icon.ico +0 -0
- data/bench/lib/testdata/images/icon.png +0 -0
- data/bench/lib/testdata/images/loading-Landscape.png +0 -0
- data/bench/lib/testdata/images/loading-LandscapeLeft.png +0 -0
- data/bench/lib/testdata/images/loading-LandscapeRight.png +0 -0
- data/bench/lib/testdata/images/loading-Portrait.png +0 -0
- data/bench/lib/testdata/images/loading-PortraitUpsideDown.png +0 -0
- data/bench/lib/testdata/images/loading.png +0 -0
- data/bench/lib/testdata/images/loading@2x.png +0 -0
- data/bench/run_bench.sh +42 -0
- data/bench/run_blob_script.sh +3 -0
- data/bench/run_cud_script.sh +3 -0
- data/bench/run_query_md_script.sh +3 -0
- data/bench/run_query_only_script.sh +3 -0
- data/bench/run_query_script.sh +3 -0
- data/bench/scripts/blob_cud_script.rb +98 -0
- data/bench/scripts/cud_script.rb +92 -0
- data/bench/scripts/helpers.rb +101 -0
- data/bench/scripts/query_md_script.rb +45 -0
- data/bench/scripts/query_only_script.rb +51 -0
- data/bench/scripts/query_script.rb +45 -0
- data/bench/spec/bench_spec_helper.rb +33 -0
- data/bench/spec/logging_spec.rb +15 -0
- data/bench/spec/mock_adapter_spec.rb +61 -0
- data/bench/spec/mock_client_spec.rb +65 -0
- data/bench/spec/result_spec.rb +61 -0
- data/bench/spec/utils_spec.rb +36 -0
- data/bin/rhoconnect +34 -0
- data/bin/rhoconnect-setup +84 -0
- data/doc/async-jobs.txt +69 -0
- data/doc/authentication.txt +76 -0
- data/doc/benchmarks.txt +168 -0
- data/doc/blob-sync.txt +130 -0
- data/doc/bulk-sync.txt +102 -0
- data/doc/client.txt +432 -0
- data/doc/command-line.txt +210 -0
- data/doc/contributing.txt +60 -0
- data/doc/deploying.txt +82 -0
- data/doc/install.txt +28 -0
- data/doc/introduction.txt +20 -0
- data/doc/licensing.txt +18 -0
- data/doc/metadata.txt +458 -0
- data/doc/migration.txt +182 -0
- data/doc/public/css/print.css +29 -0
- data/doc/public/css/screen.css +257 -0
- data/doc/public/css/style.css +20 -0
- data/doc/push.txt +135 -0
- data/doc/release.txt +41 -0
- data/doc/rest-api.txt +367 -0
- data/doc/source-adapters.txt +325 -0
- data/doc/stats-middleware.txt +69 -0
- data/doc/testing.txt +222 -0
- data/doc/tutorial.txt +315 -0
- data/doc/web-console.txt +35 -0
- data/examples/simple/Rakefile +14 -0
- data/examples/simple/application.rb +27 -0
- data/examples/simple/config.ru +49 -0
- data/examples/simple/settings/license.key +1 -0
- data/examples/simple/settings/settings.yml +23 -0
- data/examples/simple/sources/sample_adapter.rb +5 -0
- data/examples/simple/sources/simple_adapter.rb +5 -0
- data/generators/rhoconnect.rb +119 -0
- data/generators/templates/application/Gemfile +21 -0
- data/generators/templates/application/Rakefile +22 -0
- data/generators/templates/application/application.rb +39 -0
- data/generators/templates/application/config.ru +36 -0
- data/generators/templates/application/settings/license.key +1 -0
- data/generators/templates/application/settings/settings.yml +14 -0
- data/generators/templates/application/spec/spec_helper.rb +42 -0
- data/generators/templates/source/source_adapter.rb +47 -0
- data/generators/templates/source/source_spec.rb +25 -0
- data/install.sh +408 -0
- data/installer/unix-like/rho_connect_install_checkers.rb +140 -0
- data/installer/unix-like/rho_connect_install_constants.rb +51 -0
- data/installer/unix-like/rho_connect_install_debian.rb +63 -0
- data/installer/unix-like/rho_connect_install_dnd.rb +58 -0
- data/installer/unix-like/rho_connect_install_get_params.rb +30 -0
- data/installer/unix-like/rho_connect_install_installers.rb +142 -0
- data/installer/unix-like/rho_connect_install_utilities.rb +85 -0
- data/installer/unix-like/rho_connect_install_yum.rb +63 -0
- data/installer/unix-like/rhoinstaller.rb +89 -0
- data/installer/utils/create_texts.rb +366 -0
- data/installer/utils/install_test.rb +140 -0
- data/installer/windows/EnvVarUpdate.nsh +328 -0
- data/installer/windows/ServiceLib.nsh +369 -0
- data/installer/windows/configUi.ini +44 -0
- data/installer/windows/icon.ico +0 -0
- data/installer/windows/rhosync.nsi +418 -0
- data/installer/windows/uninstall.bat +7 -0
- data/lib/rhoconnect/api/admin/get_api_token.rb +14 -0
- data/lib/rhoconnect/api/admin/get_license_info.rb +8 -0
- data/lib/rhoconnect/api/admin/login.rb +6 -0
- data/lib/rhoconnect/api/admin/reset.rb +10 -0
- data/lib/rhoconnect/api/admin/stats.rb +21 -0
- data/lib/rhoconnect/api/application/bulk_data.rb +7 -0
- data/lib/rhoconnect/api/application/clientcreate.rb +8 -0
- data/lib/rhoconnect/api/application/clientlogin.rb +6 -0
- data/lib/rhoconnect/api/application/clientregister.rb +6 -0
- data/lib/rhoconnect/api/application/clientreset.rb +6 -0
- data/lib/rhoconnect/api/application/query.rb +7 -0
- data/lib/rhoconnect/api/application/queue_updates.rb +6 -0
- data/lib/rhoconnect/api/application/search.rb +6 -0
- data/lib/rhoconnect/api/client/create_client.rb +3 -0
- data/lib/rhoconnect/api/client/delete_client.rb +5 -0
- data/lib/rhoconnect/api/client/get_client_params.rb +3 -0
- data/lib/rhoconnect/api/client/list_client_docs.rb +12 -0
- data/lib/rhoconnect/api/client/list_clients.rb +3 -0
- data/lib/rhoconnect/api/client/ping.rb +7 -0
- data/lib/rhoconnect/api/source/get_adapter.rb +3 -0
- data/lib/rhoconnect/api/source/get_db_doc.rb +7 -0
- data/lib/rhoconnect/api/source/get_source_params.rb +3 -0
- data/lib/rhoconnect/api/source/list_source_docs.rb +10 -0
- data/lib/rhoconnect/api/source/list_sources.rb +15 -0
- data/lib/rhoconnect/api/source/push_deletes.rb +8 -0
- data/lib/rhoconnect/api/source/push_objects.rb +8 -0
- data/lib/rhoconnect/api/source/save_adapter.rb +3 -0
- data/lib/rhoconnect/api/source/set_db_doc.rb +8 -0
- data/lib/rhoconnect/api/source/set_refresh_time.rb +8 -0
- data/lib/rhoconnect/api/source/upload_file.rb +4 -0
- data/lib/rhoconnect/api/user/create_user.rb +7 -0
- data/lib/rhoconnect/api/user/delete_user.rb +9 -0
- data/lib/rhoconnect/api/user/list_users.rb +3 -0
- data/lib/rhoconnect/api/user/update_user.rb +4 -0
- data/lib/rhoconnect/api_token.rb +19 -0
- data/lib/rhoconnect/app.rb +76 -0
- data/lib/rhoconnect/bulk_data/bulk_data.rb +88 -0
- data/lib/rhoconnect/bulk_data/syncdb.index.schema +4 -0
- data/lib/rhoconnect/bulk_data/syncdb.schema +41 -0
- data/lib/rhoconnect/bulk_data.rb +2 -0
- data/lib/rhoconnect/client.rb +96 -0
- data/lib/rhoconnect/client_sync.rb +412 -0
- data/lib/rhoconnect/console/app/helpers/auth_helper.rb +22 -0
- data/lib/rhoconnect/console/app/helpers/extensions.rb +19 -0
- data/lib/rhoconnect/console/app/helpers/helpers.rb +57 -0
- data/lib/rhoconnect/console/app/public/ThickBox.css +649 -0
- data/lib/rhoconnect/console/app/public/home.css +438 -0
- data/lib/rhoconnect/console/app/public/images/foot_logo_rhoconnect.png +0 -0
- data/lib/rhoconnect/console/app/public/images/header_halo.jpg +0 -0
- data/lib/rhoconnect/console/app/public/images/land_separator.gif +0 -0
- data/lib/rhoconnect/console/app/public/images/landing_header.jpg +0 -0
- data/lib/rhoconnect/console/app/public/images/logo_rhoconnect.png +0 -0
- data/lib/rhoconnect/console/app/public/images/rhomobile_rhohub_logo.png +0 -0
- data/lib/rhoconnect/console/app/public/images/tabs_separator.png +0 -0
- data/lib/rhoconnect/console/app/public/jqplot/excanvas.min.js +35 -0
- data/lib/rhoconnect/console/app/public/jqplot/jqplot.barRenderer.min.js +34 -0
- data/lib/rhoconnect/console/app/public/jqplot/jqplot.canvasAxisLabelRenderer.js +187 -0
- data/lib/rhoconnect/console/app/public/jqplot/jqplot.canvasAxisTickRenderer.js +226 -0
- data/lib/rhoconnect/console/app/public/jqplot/jqplot.canvasTextRenderer.js +408 -0
- data/lib/rhoconnect/console/app/public/jqplot/jqplot.categoryAxisRenderer.min.js +34 -0
- data/lib/rhoconnect/console/app/public/jqplot/jqplot.cursor.js +952 -0
- data/lib/rhoconnect/console/app/public/jqplot/jqplot.dateAxisRenderer.js +313 -0
- data/lib/rhoconnect/console/app/public/jqplot/jqplot.dateAxisRenderer.min.js +34 -0
- data/lib/rhoconnect/console/app/public/jqplot/jqplot.pointLabels.min.js +34 -0
- data/lib/rhoconnect/console/app/public/jqplot/jquery-1.4.2.min.js +154 -0
- data/lib/rhoconnect/console/app/public/jqplot/jquery.jqplot.min.css +1 -0
- data/lib/rhoconnect/console/app/public/jqplot/jquery.jqplot.min.js +34 -0
- data/lib/rhoconnect/console/app/public/main.css +7 -0
- data/lib/rhoconnect/console/app/public/reset.css +76 -0
- data/lib/rhoconnect/console/app/public/style.css +2201 -0
- data/lib/rhoconnect/console/app/public/text.txt +0 -0
- data/lib/rhoconnect/console/app/routes/adapter.rb +28 -0
- data/lib/rhoconnect/console/app/routes/auth.rb +29 -0
- data/lib/rhoconnect/console/app/routes/client.rb +31 -0
- data/lib/rhoconnect/console/app/routes/docs.rb +145 -0
- data/lib/rhoconnect/console/app/routes/heroku.rb +19 -0
- data/lib/rhoconnect/console/app/routes/home.rb +63 -0
- data/lib/rhoconnect/console/app/routes/timing.rb +242 -0
- data/lib/rhoconnect/console/app/routes/user.rb +117 -0
- data/lib/rhoconnect/console/app/views/adapter.erb +16 -0
- data/lib/rhoconnect/console/app/views/client.erb +30 -0
- data/lib/rhoconnect/console/app/views/content.erb +14 -0
- data/lib/rhoconnect/console/app/views/doc.erb +8 -0
- data/lib/rhoconnect/console/app/views/docdata.erb +28 -0
- data/lib/rhoconnect/console/app/views/docs.erb +30 -0
- data/lib/rhoconnect/console/app/views/edituser.erb +13 -0
- data/lib/rhoconnect/console/app/views/headermenu.erb +40 -0
- data/lib/rhoconnect/console/app/views/home.erb +24 -0
- data/lib/rhoconnect/console/app/views/index.erb +58 -0
- data/lib/rhoconnect/console/app/views/jqplot.erb +52 -0
- data/lib/rhoconnect/console/app/views/layout.erb +165 -0
- data/lib/rhoconnect/console/app/views/login.erb +26 -0
- data/lib/rhoconnect/console/app/views/newuser.erb +17 -0
- data/lib/rhoconnect/console/app/views/ping.erb +28 -0
- data/lib/rhoconnect/console/app/views/result.erb +11 -0
- data/lib/rhoconnect/console/app/views/rightboxlinks.erb +15 -0
- data/lib/rhoconnect/console/app/views/select_doc.erb +17 -0
- data/lib/rhoconnect/console/app/views/upload_doc.erb +23 -0
- data/lib/rhoconnect/console/app/views/user.erb +29 -0
- data/lib/rhoconnect/console/app/views/users.erb +12 -0
- data/lib/rhoconnect/console/rhoconnect_api.rb +245 -0
- data/lib/rhoconnect/console/server.rb +32 -0
- data/lib/rhoconnect/console.rb +3 -0
- data/lib/rhoconnect/cors.rb +229 -0
- data/lib/rhoconnect/credential.rb +9 -0
- data/lib/rhoconnect/db_adapter.rb +46 -0
- data/lib/rhoconnect/document.rb +49 -0
- data/lib/rhoconnect/dynamic_adapter.rb +91 -0
- data/lib/rhoconnect/generator.rb +1 -0
- data/lib/rhoconnect/jobs/bulk_data_job.rb +203 -0
- data/lib/rhoconnect/jobs/ping_job.rb +46 -0
- data/lib/rhoconnect/jobs/source_job.rb +16 -0
- data/lib/rhoconnect/license.rb +86 -0
- data/lib/rhoconnect/lock_ops.rb +11 -0
- data/lib/rhoconnect/model.rb +414 -0
- data/lib/rhoconnect/ping/android.rb +56 -0
- data/lib/rhoconnect/ping/apple.rb +52 -0
- data/lib/rhoconnect/ping/blackberry.rb +56 -0
- data/lib/rhoconnect/ping.rb +3 -0
- data/lib/rhoconnect/read_state.rb +31 -0
- data/lib/rhoconnect/rho_indifferent_access.rb +88 -0
- data/lib/rhoconnect/server/views/index.erb +13 -0
- data/lib/rhoconnect/server.rb +286 -0
- data/lib/rhoconnect/source.rb +289 -0
- data/lib/rhoconnect/source_adapter.rb +123 -0
- data/lib/rhoconnect/source_sync.rb +302 -0
- data/lib/rhoconnect/stats/middleware.rb +20 -0
- data/lib/rhoconnect/stats/record.rb +108 -0
- data/lib/rhoconnect/store.rb +232 -0
- data/lib/rhoconnect/tasks.rb +350 -0
- data/lib/rhoconnect/test_methods.rb +220 -0
- data/lib/rhoconnect/user.rb +95 -0
- data/lib/rhoconnect/version.rb +3 -0
- data/lib/rhoconnect/x_domain_session_wrapper.rb +53 -0
- data/lib/rhoconnect.rb +285 -0
- data/rhoconnect.gemspec +67 -0
- data/spec/api/admin/api_token_spec.rb +14 -0
- data/spec/api/admin/get_api_token_spec.rb +36 -0
- data/spec/api/admin/get_license_info_spec.rb +38 -0
- data/spec/api/admin/reset_spec.rb +22 -0
- data/spec/api/admin/stats_spec.rb +66 -0
- data/spec/api/api_helper.rb +21 -0
- data/spec/api/application/rhoconnect_api_spec.rb +548 -0
- data/spec/api/client/create_client_spec.rb +13 -0
- data/spec/api/client/delete_client_spec.rb +13 -0
- data/spec/api/client/get_client_params_spec.rb +18 -0
- data/spec/api/client/list_client_docs_spec.rb +32 -0
- data/spec/api/client/list_clients_spec.rb +22 -0
- data/spec/api/client/ping_spec.rb +23 -0
- data/spec/api/rhosync_api_spec.rb.orig +606 -0
- data/spec/api/source/adapter_spec.rb +29 -0
- data/spec/api/source/get_db_doc_spec.rb +21 -0
- data/spec/api/source/get_source_params_spec.rb +32 -0
- data/spec/api/source/list_source_docs_spec.rb +25 -0
- data/spec/api/source/list_sources_spec.rb +26 -0
- data/spec/api/source/push_deletes_spec.rb +18 -0
- data/spec/api/source/push_objects_spec.rb +27 -0
- data/spec/api/source/set_db_doc_spec.rb +19 -0
- data/spec/api/source/set_refresh_time_spec.rb +43 -0
- data/spec/api/source/upload_file_spec.rb +26 -0
- data/spec/api/user/create_user_spec.rb +16 -0
- data/spec/api/user/delete_user_spec.rb +36 -0
- data/spec/api/user/list_users_spec.rb +30 -0
- data/spec/api/user/update_user_spec.rb +31 -0
- data/spec/api_token_spec.rb +14 -0
- data/spec/app_spec.rb +18 -0
- data/spec/apps/emptyapp/application.rb +27 -0
- data/spec/apps/emptyapp/settings/license.key +1 -0
- data/spec/apps/emptyapp/settings/settings.yml +14 -0
- data/spec/apps/rhotestapp/Rakefile +1 -0
- data/spec/apps/rhotestapp/application.rb +19 -0
- data/spec/apps/rhotestapp/config.ru +1 -0
- data/spec/apps/rhotestapp/settings/apple_fake_cert.pem +1 -0
- data/spec/apps/rhotestapp/settings/license.key +1 -0
- data/spec/apps/rhotestapp/settings/settings.yml +36 -0
- data/spec/apps/rhotestapp/sources/base_adapter.rb +9 -0
- data/spec/apps/rhotestapp/sources/fixed_schema_adapter.rb +28 -0
- data/spec/apps/rhotestapp/sources/sample_adapter.rb +71 -0
- data/spec/apps/rhotestapp/sources/simple_adapter.rb +41 -0
- data/spec/apps/rhotestapp/sources/sub_adapter.rb +7 -0
- data/spec/apps/rhotestapp/vendor/mygem-0.1.0/lib/mygem/mygem.rb +8 -0
- data/spec/apps/rhotestapp/vendor/mygem-0.1.0/lib/mygem.rb +1 -0
- data/spec/bulk_data/bulk_data_spec.rb +97 -0
- data/spec/client_spec.rb +124 -0
- data/spec/client_sync_spec.rb +774 -0
- data/spec/doc/base.html +72 -0
- data/spec/doc/doc_spec.rb +376 -0
- data/spec/doc/footer.html +4 -0
- data/spec/doc/header.html +30 -0
- data/spec/document_spec.rb +31 -0
- data/spec/dynamic_adapter_spec.rb +43 -0
- data/spec/factories/factories.rb +17 -0
- data/spec/generator/generator_spec.rb +58 -0
- data/spec/generator/generator_spec_helper.rb +9 -0
- data/spec/jobs/bulk_data_job_spec.rb +125 -0
- data/spec/jobs/ping_job_spec.rb +102 -0
- data/spec/jobs/source_job_spec.rb +29 -0
- data/spec/license_spec.rb +66 -0
- data/spec/model_spec.rb +273 -0
- data/spec/perf/bulk_data_perf_spec.rb +32 -0
- data/spec/perf/perf_spec_helper.rb +50 -0
- data/spec/perf/store_perf_spec.rb +27 -0
- data/spec/ping/android_spec.rb +91 -0
- data/spec/ping/apple_spec.rb +70 -0
- data/spec/ping/blackberry_spec.rb +62 -0
- data/spec/read_state_spec.rb +35 -0
- data/spec/rhosync_spec.rb +75 -0
- data/spec/server/cors_spec.rb +287 -0
- data/spec/server/server_spec.rb +470 -0
- data/spec/server/x_domain_session_wrapper_spec.rb +150 -0
- data/spec/source_adapter_spec.rb +125 -0
- data/spec/source_spec.rb +114 -0
- data/spec/source_sync_spec.rb +328 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +231 -0
- data/spec/stats/middleware_spec.rb +53 -0
- data/spec/stats/record_spec.rb +92 -0
- data/spec/store_spec.rb +251 -0
- data/spec/support/shared_examples.rb +168 -0
- data/spec/sync_states_spec.rb +72 -0
- data/spec/test_methods_spec.rb +134 -0
- data/spec/testdata/1000-data.txt +1414 -0
- data/spec/testdata/compressed/compress-data.txt +1 -0
- data/spec/testdata/upload1.txt +1 -0
- data/spec/testdata/upload2.txt +1 -0
- data/spec/user_spec.rb +139 -0
- data/tasks/redis.rake +206 -0
- metadata +706 -0
@@ -0,0 +1,412 @@
|
|
1
|
+
module Rhoconnect
|
2
|
+
class ClientSync
|
3
|
+
attr_accessor :source,:client,:p_size,:source_sync
|
4
|
+
|
5
|
+
VERSION = 3
|
6
|
+
UNKNOWN_CLIENT = "Unknown client"
|
7
|
+
UNKNOWN_SOURCE = "Unknown source"
|
8
|
+
|
9
|
+
|
10
|
+
def initialize(source,client,p_size=nil)
|
11
|
+
raise ArgumentError.new(UNKNOWN_CLIENT) unless client
|
12
|
+
raise ArgumentError.new(UNKNOWN_SOURCE) unless source
|
13
|
+
@source,@client,@p_size = source,client,p_size ? p_size.to_i : 500
|
14
|
+
@source_sync = SourceSync.new(@source)
|
15
|
+
end
|
16
|
+
|
17
|
+
def receive_cud(cud_params={},query_params=nil)
|
18
|
+
if @source.is_pass_through?
|
19
|
+
@source_sync.pass_through_cud(cud_params,query_params)
|
20
|
+
else
|
21
|
+
_process_blobs(cud_params)
|
22
|
+
processed = 0
|
23
|
+
['create','update','delete'].each do |op|
|
24
|
+
key,value = op,cud_params[op]
|
25
|
+
processed += _receive_cud(key,value) if value
|
26
|
+
end
|
27
|
+
@source_sync.process_cud(@client.id) if processed > 0
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def send_cud(token=nil,query_params=nil)
|
32
|
+
res = []
|
33
|
+
if not _ack_token(token) and not @source.is_pass_through?
|
34
|
+
res = resend_page(token)
|
35
|
+
else
|
36
|
+
query_result = @source_sync.process_query(query_params)
|
37
|
+
if @source.is_pass_through?
|
38
|
+
res = send_pass_through_data(query_result)
|
39
|
+
else
|
40
|
+
res = send_new_page
|
41
|
+
end
|
42
|
+
end
|
43
|
+
_format_result(res[0],res[1],res[2],res[3])
|
44
|
+
end
|
45
|
+
|
46
|
+
def search(params)
|
47
|
+
if params
|
48
|
+
return _resend_search_result if params[:token] and params[:resend]
|
49
|
+
if params[:token] and !_ack_search(params[:token])
|
50
|
+
formatted_result = _format_search_result
|
51
|
+
@client.flash_data('search*')
|
52
|
+
return formatted_result
|
53
|
+
end
|
54
|
+
end
|
55
|
+
_do_search(params)
|
56
|
+
end
|
57
|
+
|
58
|
+
def build_page
|
59
|
+
res = {}
|
60
|
+
yield res
|
61
|
+
res.reject! {|key,value| value.nil? or value.empty?}
|
62
|
+
res.merge!(_send_errors)
|
63
|
+
res
|
64
|
+
end
|
65
|
+
|
66
|
+
def send_new_page
|
67
|
+
token,progress_count,total_count,res = '',0,0,{}
|
68
|
+
if schema_changed?
|
69
|
+
_expire_bulk_data
|
70
|
+
token = compute_token(@client.docname(:page_token))
|
71
|
+
res = {'schema-changed' => 'true'}
|
72
|
+
else
|
73
|
+
compute_errors_page
|
74
|
+
res = build_page do |r|
|
75
|
+
progress_count,total_count,r['insert'] = compute_page
|
76
|
+
r['delete'] = compute_deleted_page
|
77
|
+
r['links'] = compute_links_page
|
78
|
+
r['metadata'] = compute_metadata
|
79
|
+
end
|
80
|
+
if res['insert'] or res['delete'] or res['links']
|
81
|
+
token = compute_token(@client.docname(:page_token))
|
82
|
+
else
|
83
|
+
_delete_errors_page
|
84
|
+
end
|
85
|
+
@client.put_data(:cd,res['insert'],true)
|
86
|
+
@client.delete_data(:cd,res['delete'])
|
87
|
+
end
|
88
|
+
[token,progress_count,total_count,res]
|
89
|
+
end
|
90
|
+
|
91
|
+
def send_pass_through_data(data)
|
92
|
+
data ||= {}
|
93
|
+
data.each_key do |object_id|
|
94
|
+
data[object_id].each { |attrib,value| data[object_id][attrib] = '' if value.nil? }
|
95
|
+
end
|
96
|
+
token = ''
|
97
|
+
compute_errors_page
|
98
|
+
res = build_page do |r|
|
99
|
+
r['insert'] = data
|
100
|
+
r['metadata'] = compute_metadata
|
101
|
+
end
|
102
|
+
if res['insert']
|
103
|
+
token = compute_token(@client.docname(:page_token))
|
104
|
+
else
|
105
|
+
_delete_errors_page
|
106
|
+
end
|
107
|
+
[token,0,data.size,res]
|
108
|
+
end
|
109
|
+
|
110
|
+
# Resend token for a client, also sends exceptions
|
111
|
+
def resend_page(token=nil)
|
112
|
+
token,progress_count,total_count,res = '',0,0,{}
|
113
|
+
schema_page = @client.get_value(:schema_page)
|
114
|
+
if schema_page
|
115
|
+
res = {'schema-changed' => 'true'}
|
116
|
+
else
|
117
|
+
res = build_page do |r|
|
118
|
+
r['insert'] = @client.get_data(:page)
|
119
|
+
r['delete'] = @client.get_data(:delete_page)
|
120
|
+
r['links'] = @client.get_data(:create_links_page)
|
121
|
+
r['metadata'] = @client.get_value(:metadata_page)
|
122
|
+
progress_count = @client.get_value(:cd_size).to_i
|
123
|
+
total_count = @client.get_value(:total_count_page).to_i
|
124
|
+
end
|
125
|
+
end
|
126
|
+
token = @client.get_value(:page_token)
|
127
|
+
[token,progress_count,total_count,res]
|
128
|
+
end
|
129
|
+
|
130
|
+
# Checks if schema changed
|
131
|
+
def schema_changed?
|
132
|
+
if @source_sync.adapter.respond_to?(:schema)
|
133
|
+
schema_sha1 = @source.get_value(:schema_sha1)
|
134
|
+
if @client.get_value(:schema_sha1).nil?
|
135
|
+
@client.put_value(:schema_sha1,schema_sha1)
|
136
|
+
return false
|
137
|
+
elsif @client.get_value(:schema_sha1) == schema_sha1
|
138
|
+
return false
|
139
|
+
end
|
140
|
+
@client.put_value(:schema_sha1,schema_sha1)
|
141
|
+
@client.put_value(:schema_page,schema_sha1)
|
142
|
+
return true
|
143
|
+
else
|
144
|
+
return false
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# Computes the metadata sha1 and returns metadata if client's sha1 doesn't
|
149
|
+
# match source's sha1
|
150
|
+
def compute_metadata
|
151
|
+
metadata_sha1,metadata = @source.lock(:metadata) do |s|
|
152
|
+
[s.get_value(:metadata_sha1),s.get_value(:metadata)]
|
153
|
+
end
|
154
|
+
return if @client.get_value(:metadata_sha1) == metadata_sha1
|
155
|
+
@client.put_value(:metadata_sha1,metadata_sha1)
|
156
|
+
@client.put_value(:metadata_page,metadata)
|
157
|
+
metadata
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
# Computes diffs between master doc and client doc, trims it to page size,
|
162
|
+
# stores page, and returns page as hash
|
163
|
+
def compute_page
|
164
|
+
res,diffsize,total_count = @source.lock(:md) do |s|
|
165
|
+
res,diffsize = Store.get_diff_data(@client.docname(:cd),s.docname(:md),@p_size)
|
166
|
+
total_count = s.get_value(:md_size).to_i
|
167
|
+
[res,diffsize,total_count]
|
168
|
+
end
|
169
|
+
@client.put_data(:page,res)
|
170
|
+
progress_count = total_count - diffsize
|
171
|
+
@client.put_value(:cd_size,progress_count)
|
172
|
+
@client.put_value(:total_count_page,total_count)
|
173
|
+
[progress_count,total_count,res]
|
174
|
+
end
|
175
|
+
|
176
|
+
# Computes search result, updates md for source and cd for client with the result
|
177
|
+
def compute_search
|
178
|
+
client_res,diffsize = Store.get_diff_data(@client.docname(:cd),@client.docname(:search),@p_size)
|
179
|
+
@client.put_data(:cd,client_res,true)
|
180
|
+
@client.update_count(:cd_size,client_res.size)
|
181
|
+
@client.put_data(:search_page,client_res)
|
182
|
+
|
183
|
+
@source.lock(:md) do |s|
|
184
|
+
source_diff,source_diffsize = Store.get_diff_data(s.docname(:md),@client.docname(:cd))
|
185
|
+
s.put_data(:md,source_diff,true)
|
186
|
+
s.update_count(:md_size,source_diff.size)
|
187
|
+
end
|
188
|
+
|
189
|
+
[client_res,client_res.size]
|
190
|
+
end
|
191
|
+
|
192
|
+
# Computes deleted objects (down to individual attributes)
|
193
|
+
# in the client document, trims it to page size, stores page, and returns page as hash
|
194
|
+
def compute_deleted_page
|
195
|
+
res = {}
|
196
|
+
delete_page_doc = @client.docname(:delete_page)
|
197
|
+
page_size = @p_size
|
198
|
+
diff = @source.lock(:md) { |s| Store.get_diff_data(s.docname(:md),@client.docname(:cd))[0] }
|
199
|
+
diff.each do |key,value|
|
200
|
+
res[key] = value
|
201
|
+
value.each do |attrib,val|
|
202
|
+
Store.db.sadd(delete_page_doc,setelement(key,attrib,val))
|
203
|
+
end
|
204
|
+
page_size -= 1
|
205
|
+
break if page_size <= 0
|
206
|
+
end
|
207
|
+
res
|
208
|
+
end
|
209
|
+
|
210
|
+
# Computes errors for client and stores a copy as errors page
|
211
|
+
def compute_errors_page
|
212
|
+
['create','update','delete'].each do |operation|
|
213
|
+
@client.lock("#{operation}_errors") do |c|
|
214
|
+
c.rename("#{operation}_errors","#{operation}_errors_page")
|
215
|
+
end
|
216
|
+
end
|
217
|
+
@client.lock("update_rollback") do |c|
|
218
|
+
c.rename("update_rollback","update_rollback_page")
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
# Computes create links for a client and stores a copy as links page
|
223
|
+
def compute_links_page
|
224
|
+
@client.lock(:create_links) do |c|
|
225
|
+
c.rename(:create_links,:create_links_page)
|
226
|
+
c.get_data(:create_links_page)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
class << self
|
231
|
+
# Resets the store for a given app,client
|
232
|
+
def reset(client, params=nil)
|
233
|
+
return unless client
|
234
|
+
if params == nil or params[:sources] == nil
|
235
|
+
client.flash_data('*')
|
236
|
+
else
|
237
|
+
params[:sources].each do |source|
|
238
|
+
client.flash_source_data('*', source['name'])
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
def search_all(client,params=nil)
|
244
|
+
raise ArgumentError.new(UNKNOWN_CLIENT) unless client
|
245
|
+
return [] unless params[:sources]
|
246
|
+
res = []
|
247
|
+
params[:sources].each do |source|
|
248
|
+
s = Source.load(source['name'],{:app_id => client.app_id,
|
249
|
+
:user_id => client.user_id})
|
250
|
+
client.source_name = source['name']
|
251
|
+
cs = ClientSync.new(s,client,params[:p_size])
|
252
|
+
params[:token] = source['token'] if source['token']
|
253
|
+
search_res = cs.search(params)
|
254
|
+
res << search_res if search_res
|
255
|
+
end
|
256
|
+
res
|
257
|
+
end
|
258
|
+
|
259
|
+
def bulk_data(partition,client)
|
260
|
+
raise ArgumentError.new(UNKNOWN_CLIENT) unless client
|
261
|
+
name = BulkData.get_name(partition,client.user_id)
|
262
|
+
data = BulkData.load(name)
|
263
|
+
|
264
|
+
sources = client.app.partition_sources(partition,client.user_id)
|
265
|
+
return {:result => :nop} if sources.length <= 0
|
266
|
+
|
267
|
+
do_bd_sync = data.nil?
|
268
|
+
do_bd_sync = (data.completed? and
|
269
|
+
(data.refresh_time <= Time.now.to_i or !data.dbfiles_exist?)) unless do_bd_sync
|
270
|
+
|
271
|
+
if do_bd_sync
|
272
|
+
data.delete if data
|
273
|
+
data = BulkData.create(:name => name,
|
274
|
+
:app_id => client.app_id,
|
275
|
+
:user_id => client.user_id,
|
276
|
+
:sources => sources,
|
277
|
+
:refresh_time => Time.now.to_i + Rhoconnect.bulk_sync_poll_interval)
|
278
|
+
BulkData.enqueue("data_name" => name)
|
279
|
+
end
|
280
|
+
|
281
|
+
if data and data.completed? and data.dbfiles_exist?
|
282
|
+
client.update_clientdoc(sources)
|
283
|
+
{:result => :url, :url => data.url}
|
284
|
+
elsif data
|
285
|
+
{:result => :wait}
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
private
|
291
|
+
|
292
|
+
# expires the bulk data for the client
|
293
|
+
def _expire_bulk_data
|
294
|
+
[:user,:app].each do |partition|
|
295
|
+
Rhoconnect.expire_bulk_data(@client.user_id,partition)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
def _resend_search_result
|
300
|
+
res = @client.get_data(:search_page)
|
301
|
+
_format_search_result(res,res.size)
|
302
|
+
end
|
303
|
+
|
304
|
+
def _ack_search(search_token)
|
305
|
+
if @client.get_value(:search_token) != search_token
|
306
|
+
@client.flash_data('search*')
|
307
|
+
@client.put_data(:search_errors,
|
308
|
+
{'search-error'=>{'message'=>'Search error - invalid token'}}
|
309
|
+
)
|
310
|
+
return false
|
311
|
+
end
|
312
|
+
true
|
313
|
+
end
|
314
|
+
|
315
|
+
def _do_search(params={})
|
316
|
+
# call source adapter search unless client is sending token for ack
|
317
|
+
search_params = params[:search] if params
|
318
|
+
res = @source_sync.search(@client.id,search_params) if params.nil? or !params[:token]
|
319
|
+
res,diffsize = @source.is_pass_through? ? [res,res.size] : compute_search
|
320
|
+
formatted_res = _format_search_result(res,diffsize)
|
321
|
+
@client.flash_data('search*') if diffsize == 0
|
322
|
+
formatted_res
|
323
|
+
end
|
324
|
+
|
325
|
+
def _format_search_result(res={},diffsize=nil)
|
326
|
+
error = @client.get_data(:search_errors)
|
327
|
+
if not error.empty?
|
328
|
+
[ {'version'=>VERSION},
|
329
|
+
{'source'=>@source.name},
|
330
|
+
{'search-error'=>error} ]
|
331
|
+
else
|
332
|
+
search_token = @client.get_value(:search_token)
|
333
|
+
search_token ||= ''
|
334
|
+
return [] if res.empty?
|
335
|
+
[ {'version'=>VERSION},
|
336
|
+
{'token' => search_token},
|
337
|
+
{'source'=>@source.name},
|
338
|
+
{'count'=>res.size},
|
339
|
+
{'insert'=>res} ]
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
def _receive_cud(operation,params)
|
344
|
+
return 0 if not ['create','update','delete'].include?(operation)
|
345
|
+
@client.lock(operation) { |c| c.put_data(operation,params,true) }
|
346
|
+
return 1
|
347
|
+
end
|
348
|
+
|
349
|
+
def _process_blobs(params)
|
350
|
+
unless params[:blob_fields].nil?
|
351
|
+
[:create,:update].each do |utype|
|
352
|
+
objects = params[utype] || {}
|
353
|
+
objects.each do |id,obj|
|
354
|
+
params[:blob_fields].each do |field|
|
355
|
+
blob = params["#{field}-#{id}"]
|
356
|
+
obj[field] = @client.app.store_blob(obj,field,blob)
|
357
|
+
end
|
358
|
+
end
|
359
|
+
end
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
def _ack_token(token)
|
364
|
+
stored_token = @client.get_value(:page_token)
|
365
|
+
if stored_token
|
366
|
+
if token and stored_token == token
|
367
|
+
@client.put_value(:page_token,nil)
|
368
|
+
@client.flash_data(:schema_page)
|
369
|
+
@client.flash_data(:metadata_page)
|
370
|
+
@client.flash_data(:create_links_page)
|
371
|
+
@client.flash_data(:page)
|
372
|
+
@client.flash_data(:delete_page)
|
373
|
+
_delete_errors_page
|
374
|
+
return true
|
375
|
+
end
|
376
|
+
else
|
377
|
+
return true
|
378
|
+
end
|
379
|
+
false
|
380
|
+
end
|
381
|
+
|
382
|
+
def _delete_errors_page
|
383
|
+
['create','update','delete'].each do |operation|
|
384
|
+
@client.flash_data("#{operation}_errors_page")
|
385
|
+
end
|
386
|
+
@client.flash_data("update_rollback_page")
|
387
|
+
end
|
388
|
+
|
389
|
+
def _send_errors
|
390
|
+
res = {}
|
391
|
+
['create','update','delete'].each do |operation|
|
392
|
+
res["#{operation}-error"] = @client.get_data("#{operation}_errors_page")
|
393
|
+
end
|
394
|
+
res["source-error"] = @source.lock(:errors) { |s| s.get_data(:errors) }
|
395
|
+
res["update-rollback"] = @client.get_data(:update_rollback_page)
|
396
|
+
res.reject! {|key,value| value.nil? or value.empty?}
|
397
|
+
res
|
398
|
+
end
|
399
|
+
|
400
|
+
def _format_result(token,progress_count,total_count,res)
|
401
|
+
count = 0
|
402
|
+
count += res['insert'].length if res['insert']
|
403
|
+
count += res['delete'].length if res['delete']
|
404
|
+
[ {'version'=>VERSION},
|
405
|
+
{'token'=>(token ? token : '')},
|
406
|
+
{'count'=>count},
|
407
|
+
{'progress_count'=>progress_count},
|
408
|
+
{'total_count'=>total_count},
|
409
|
+
res ]
|
410
|
+
end
|
411
|
+
end
|
412
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class RhoconnectConsole::Server
|
2
|
+
helpers do
|
3
|
+
|
4
|
+
def login_required
|
5
|
+
session[:token].nil?
|
6
|
+
end
|
7
|
+
|
8
|
+
def report_error(message)
|
9
|
+
session[:errors] = [] if session[:errors].nil?
|
10
|
+
session[:errors] << message
|
11
|
+
end
|
12
|
+
|
13
|
+
def verify_presence_of(param,message)
|
14
|
+
report_error(message) if params[param].nil? or params[param].length == 0
|
15
|
+
end
|
16
|
+
|
17
|
+
def verify_format_of(param,message)
|
18
|
+
report_error(message) if params[param].nil? or params[param] !~ /^(http|https):\/\//
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Hash
|
2
|
+
public
|
3
|
+
def symbolize_keys
|
4
|
+
hash = {}
|
5
|
+
self.each do |key, value|
|
6
|
+
hash[(key.to_sym rescue key) || key] = value
|
7
|
+
end
|
8
|
+
hash
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class String
|
13
|
+
public
|
14
|
+
def ends_with?(str)
|
15
|
+
str = str.to_str
|
16
|
+
tail = self[-str.length, str.length]
|
17
|
+
tail == str
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class RhoconnectConsole::Server
|
2
|
+
helpers do
|
3
|
+
def url_path(*path_parts)
|
4
|
+
[ path_prefix, path_parts ].join("/").squeeze('/')
|
5
|
+
end
|
6
|
+
alias_method :u, :url_path
|
7
|
+
|
8
|
+
def resque_path
|
9
|
+
# Replace 'console' at the end of path by 'resque'
|
10
|
+
url_path("").sub!(/console\/?\Z/, "resque/")
|
11
|
+
end
|
12
|
+
|
13
|
+
def path_prefix
|
14
|
+
request.env['SCRIPT_NAME']
|
15
|
+
end
|
16
|
+
|
17
|
+
def is_errors?
|
18
|
+
session[:errors] and session[:errors].size > 0
|
19
|
+
end
|
20
|
+
|
21
|
+
def show_errors
|
22
|
+
return '' unless session[:errors]
|
23
|
+
res = []
|
24
|
+
session[:errors].each do |error|
|
25
|
+
res << "<p style=\"color:#800\">#{error}</p>"
|
26
|
+
end
|
27
|
+
session[:errors] = nil
|
28
|
+
res.join
|
29
|
+
end
|
30
|
+
|
31
|
+
def handle_api_error(error_message)
|
32
|
+
begin
|
33
|
+
yield
|
34
|
+
rescue RestClient::Exception => re
|
35
|
+
session[:errors] ||= []
|
36
|
+
if re.response.body.nil? or re.response.body.length == 0
|
37
|
+
session[:errors] << "#{error_message}: [#{re.http_code}] #{re.message}"
|
38
|
+
else
|
39
|
+
session[:errors] << "#{error_message}: #{re.response.body}"
|
40
|
+
end
|
41
|
+
rescue Exception => e
|
42
|
+
session[:errors] ||= []
|
43
|
+
session[:errors] << "#{error_message}: #{e.message}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def doc_params
|
48
|
+
doc_params = "source_id=#{CGI.escape(params[:source_id])}&user_id=#{CGI.escape(params[:user_id])}"
|
49
|
+
doc_params += "&device_id=#{CGI.escape(params[:device_id])}" if params[:device_id]
|
50
|
+
doc_params
|
51
|
+
end
|
52
|
+
|
53
|
+
def doc_is_string
|
54
|
+
params[:dbkey].ends_with?('token') or params[:dbkey].ends_with?('size')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|