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,91 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rest_client'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Rhoconnect
|
6
|
+
|
7
|
+
class DynamicAdapter < SourceAdapter
|
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
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../generators/rhoconnect'
|
@@ -0,0 +1,203 @@
|
|
1
|
+
require 'zip/zip'
|
2
|
+
require 'zlib'
|
3
|
+
|
4
|
+
module Rhoconnect
|
5
|
+
module BulkDataJob
|
6
|
+
@queue = :bulk_data
|
7
|
+
|
8
|
+
def self.perform(params)
|
9
|
+
bulk_data = nil
|
10
|
+
begin
|
11
|
+
bulk_data = BulkData.load(params["data_name"]) if BulkData.is_exist?(params["data_name"])
|
12
|
+
if bulk_data
|
13
|
+
timer = start_timer('starting bulk data process')
|
14
|
+
bulk_data.process_sources
|
15
|
+
timer = lap_timer('process_sources',timer)
|
16
|
+
ts = Time.now.to_i.to_s
|
17
|
+
create_sqlite_data_file(bulk_data,ts)
|
18
|
+
timer = lap_timer('create_sqlite_data_file',timer)
|
19
|
+
log "bulk_data.dbfile: #{bulk_data.dbfile}"
|
20
|
+
create_hsql_data_file(bulk_data,ts) if Rhoconnect.blackberry_bulk_sync
|
21
|
+
lap_timer('create_hsql_data_file',timer)
|
22
|
+
log "finished bulk data process"
|
23
|
+
bulk_data.state = :completed
|
24
|
+
bulk_data.refresh_time = Time.now.to_i + Rhoconnect.bulk_sync_poll_interval
|
25
|
+
else
|
26
|
+
raise Exception.new("No bulk data found for #{params["data_name"]}")
|
27
|
+
end
|
28
|
+
rescue Exception => e
|
29
|
+
bulk_data.delete if bulk_data
|
30
|
+
log "Bulk data job raised: #{e.message}"
|
31
|
+
log e.backtrace.join("\n")
|
32
|
+
raise e
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.import_data_to_object_values(db,source)
|
37
|
+
data = source.get_data(:md)
|
38
|
+
counter = {}
|
39
|
+
db.transaction do |database|
|
40
|
+
database.prepare("insert into object_values
|
41
|
+
(source_id,attrib,object,value) values (?,?,?,?)") do |stmt|
|
42
|
+
data.each do |object_id,object|
|
43
|
+
object.each do |attrib,value|
|
44
|
+
counter[attrib] = counter[attrib] ? counter[attrib] + 1 : 1
|
45
|
+
stmt.execute(source.source_id.to_i,attrib,object_id,value)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
counter
|
51
|
+
end
|
52
|
+
|
53
|
+
# Loads data into fixed schema table based on source settings
|
54
|
+
def self.import_data_to_fixed_schema(db,source)
|
55
|
+
data = source.get_data(:md)
|
56
|
+
counter = {}
|
57
|
+
columns,qm = [],[]
|
58
|
+
create_table = ["\"object\" varchar(255) PRIMARY KEY"]
|
59
|
+
schema = JSON.parse(source.schema)
|
60
|
+
|
61
|
+
db.transaction do |database|
|
62
|
+
# Create a table with columns specified by 'property' array in settings
|
63
|
+
schema['property'].each do |key,value|
|
64
|
+
create_table << "\"#{key}\" varchar default NULL"
|
65
|
+
columns << key
|
66
|
+
qm << '?'
|
67
|
+
end
|
68
|
+
database.execute("CREATE TABLE #{source.name}(#{create_table.join(",")} );")
|
69
|
+
|
70
|
+
database.prepare("insert into #{source.name} (object,#{columns.join(',')}) values (?,#{qm.join(',')})") do |stmt|
|
71
|
+
data.each do |obj,row|
|
72
|
+
args = [obj]
|
73
|
+
columns.each { |col| args << row[col] }
|
74
|
+
# FIXME: The * is used to expand an array into individual arguments for 'execute' method.
|
75
|
+
# JRuby (1.6.0) won't work without asterisk, but MRI and 1.9.2 are both doing well!
|
76
|
+
stmt.execute(*args) # FIXME: !!!
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Create indexes for specified columns in settings 'index'
|
81
|
+
schema['index'].each do |key,value|
|
82
|
+
val2 = ""
|
83
|
+
value.split(',').each do |col|
|
84
|
+
val2 += ',' if val2.length > 0
|
85
|
+
val2 += "\"#{col}\""
|
86
|
+
end
|
87
|
+
|
88
|
+
database.execute("CREATE INDEX #{key} on #{source.name} (#{val2});")
|
89
|
+
end if schema['index']
|
90
|
+
|
91
|
+
# Create unique indexes for specified columns in settings 'unique_index'
|
92
|
+
schema['unique_index'].each do |key,value|
|
93
|
+
val2 = ""
|
94
|
+
value.split(',').each do |col|
|
95
|
+
val2 += ',' if val2.length > 0
|
96
|
+
val2 += "\"#{col}\""
|
97
|
+
end
|
98
|
+
|
99
|
+
database.execute("CREATE UNIQUE INDEX #{key} on #{source.name} (#{val2});")
|
100
|
+
end if schema['unique_index']
|
101
|
+
end
|
102
|
+
|
103
|
+
return {}
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.refs_to_s(refs)
|
107
|
+
str = ''
|
108
|
+
refs.sort.each do |name,value|
|
109
|
+
str << "#{name},#{value},"
|
110
|
+
end
|
111
|
+
str[0..-2]
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.populate_sources_table(db,sources_refs)
|
115
|
+
db.transaction do |database|
|
116
|
+
database.prepare("insert into sources
|
117
|
+
(source_id,name,sync_priority,partition,sync_type,source_attribs,metadata,schema,blob_attribs,associations)
|
118
|
+
values (?,?,?,?,?,?,?,?,?,?)") do |stmt|
|
119
|
+
sources_refs.each do |source_name,ref|
|
120
|
+
s = ref[:source]
|
121
|
+
stmt.execute(s.source_id,s.name,s.priority,s.partition_type.to_s,
|
122
|
+
s.sync_type.to_s,refs_to_s(ref[:refs]),s.get_value(:metadata),s.schema,s.blob_attribs,s.has_many)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.create_sqlite_data_file(bulk_data,ts)
|
129
|
+
sources_refs = {}
|
130
|
+
schema,index,bulk_data.dbfile = get_file_args(bulk_data.name,ts)
|
131
|
+
FileUtils.mkdir_p(File.dirname(bulk_data.dbfile))
|
132
|
+
|
133
|
+
db = DBAdapter.instance.get_connection(bulk_data.dbfile)
|
134
|
+
db.execute_batch(File.open(schema,'r').read)
|
135
|
+
|
136
|
+
src_counter = 1
|
137
|
+
bulk_data.sources.members.sort.each do |source_name|
|
138
|
+
timer = start_timer("start importing sqlite data for #{source_name}")
|
139
|
+
source = Source.load(source_name,{:app_id => bulk_data.app_id,
|
140
|
+
:user_id => bulk_data.user_id})
|
141
|
+
source.source_id = src_counter
|
142
|
+
src_counter += 1
|
143
|
+
source_attrib_refs = nil
|
144
|
+
if source.schema
|
145
|
+
source_attrib_refs = import_data_to_fixed_schema(db,source)
|
146
|
+
else
|
147
|
+
source_attrib_refs = import_data_to_object_values(db,source)
|
148
|
+
end
|
149
|
+
sources_refs[source_name] =
|
150
|
+
{:source => source, :refs => source_attrib_refs}
|
151
|
+
lap_timer("finished importing sqlite data for #{source_name}",timer)
|
152
|
+
end
|
153
|
+
populate_sources_table(db,sources_refs)
|
154
|
+
|
155
|
+
db.execute_batch(File.open(index,'r').read)
|
156
|
+
db.execute_batch("VACUUM;");
|
157
|
+
db.close
|
158
|
+
|
159
|
+
compress("#{bulk_data.dbfile}.rzip",bulk_data.dbfile)
|
160
|
+
gzip_compress("#{bulk_data.dbfile}.gzip",bulk_data.dbfile)
|
161
|
+
end
|
162
|
+
|
163
|
+
def self.create_hsql_data_file(bulk_data,ts)
|
164
|
+
schema,index,dbfile = get_file_args(bulk_data.name,ts)
|
165
|
+
hsql_file = dbfile + ".hsqldb"
|
166
|
+
cmd = ['java','-cp', File.join(File.expand_path(Rhoconnect.vendor_directory),'hsqldata.jar'),
|
167
|
+
'com.rhomobile.hsqldata.HsqlData', dbfile, hsql_file].join(" ")
|
168
|
+
log "Running hsqldata: #{cmd.to_s}"
|
169
|
+
raise Exception.new("Error running hsqldata") unless
|
170
|
+
system(
|
171
|
+
'java','-cp',
|
172
|
+
File.join(File.expand_path(Rhoconnect.vendor_directory),'hsqldata.jar'),
|
173
|
+
'com.rhomobile.hsqldata.HsqlData',
|
174
|
+
dbfile, hsql_file
|
175
|
+
)
|
176
|
+
gzip_compress("#{hsql_file}.data.gzip","#{hsql_file}.data")
|
177
|
+
end
|
178
|
+
|
179
|
+
def self.get_file_args(bulk_data_name,ts)
|
180
|
+
schema = BulkData.schema_file
|
181
|
+
index = BulkData.index_file
|
182
|
+
dbfile = File.join(Rhoconnect.data_directory,bulk_data_name+'_'+ts+'.data')
|
183
|
+
[schema,index,dbfile]
|
184
|
+
end
|
185
|
+
|
186
|
+
def self.compress(archive,file)
|
187
|
+
Zip::ZipFile.open(archive, 'w') do |zipfile|
|
188
|
+
zipfile.add(URI.escape(File.basename(file)),file)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def self.gzip_compress(archive,file)
|
193
|
+
data = File.new(file, "rb")
|
194
|
+
File.open(archive, 'wb') do |f|
|
195
|
+
gz = Zlib::GzipWriter.new(f)
|
196
|
+
gz.write data.read
|
197
|
+
gz.close
|
198
|
+
end
|
199
|
+
data.close
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rhoconnect/ping'
|
2
|
+
|
3
|
+
module Rhoconnect
|
4
|
+
module PingJob
|
5
|
+
@queue = :ping
|
6
|
+
|
7
|
+
# Perform a ping for all clients registered to a user
|
8
|
+
def self.perform(params)
|
9
|
+
user = User.load(params["user_id"])
|
10
|
+
device_pins = []
|
11
|
+
phone_ids = []
|
12
|
+
user.clients.members.each do |client_id|
|
13
|
+
client = Client.load(client_id,{:source_name => '*'})
|
14
|
+
params.merge!('device_port' => client.device_port, 'device_pin' => client.device_pin, 'phone_id' => client.phone_id)
|
15
|
+
send_push = false
|
16
|
+
if client.device_type and client.device_type.size > 0
|
17
|
+
if client.phone_id and client.phone_id.size > 0
|
18
|
+
unless phone_ids.include? client.phone_id
|
19
|
+
phone_ids << client.phone_id
|
20
|
+
send_push = true
|
21
|
+
end
|
22
|
+
elsif client.device_pin and client.device_pin.size > 0
|
23
|
+
unless device_pins.include? client.device_pin
|
24
|
+
device_pins << client.device_pin
|
25
|
+
send_push = true
|
26
|
+
end
|
27
|
+
else
|
28
|
+
log "Skipping ping for non-registered client_id '#{client_id}'..."
|
29
|
+
next
|
30
|
+
end
|
31
|
+
if send_push
|
32
|
+
klass = Object.const_get(camelize(client.device_type.downcase))
|
33
|
+
if klass
|
34
|
+
params['vibrate'] = params['vibrate'].to_s
|
35
|
+
klass.ping(params)
|
36
|
+
end
|
37
|
+
else
|
38
|
+
log "Dropping ping request for client_id '#{client_id}' because it's already in user's device pin or phone_id list."
|
39
|
+
end
|
40
|
+
else
|
41
|
+
log "Skipping ping for non-registered client_id '#{client_id}'..."
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Rhoconnect
|
2
|
+
class SourceJob
|
3
|
+
class << self
|
4
|
+
attr_accessor :queue
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.perform(job_type,source_id,app_id,user_id,client_id,params)
|
8
|
+
source = Source.load(source_id,{:app_id => app_id,:user_id => user_id})
|
9
|
+
source_sync = SourceSync.new(source)
|
10
|
+
case job_type.to_sym
|
11
|
+
when :query then source_sync.do_query(params)
|
12
|
+
when :cud then source_sync.do_cud(client_id)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
|
3
|
+
module Rhoconnect
|
4
|
+
class LicenseException < RuntimeError; end
|
5
|
+
class LicenseSeatsExceededException < LicenseException; end
|
6
|
+
|
7
|
+
class License
|
8
|
+
attr_reader :rhoconnect_version, :licensee, :seats, :issued
|
9
|
+
#attr_accessor :license
|
10
|
+
|
11
|
+
# ships with rhoconnect
|
12
|
+
RHO_PUBLICKEY = "99068e3a2708e6fe918252be8880eac539a1d2b2402651d75de5c7a2333a1cb2"
|
13
|
+
CLIENT_DOCKEY = 'rho_client_count'
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
begin
|
17
|
+
if ENV['RHOCONNECT_LICENSE']
|
18
|
+
@license = ENV['RHOCONNECT_LICENSE']
|
19
|
+
elsif ENV['RHOSYNC_LICENSE']
|
20
|
+
@license = ENV['RHOSYNC_LICENSE']
|
21
|
+
else
|
22
|
+
settings = Rhoconnect.get_config(Rhoconnect.base_directory)[Rhoconnect.environment]
|
23
|
+
@license = IO.read(File.join(Rhoconnect.base_directory,settings[:licensefile])).strip
|
24
|
+
end
|
25
|
+
_decrypt
|
26
|
+
rescue Exception => e
|
27
|
+
log e.message
|
28
|
+
log e.backtrace.join("\n")
|
29
|
+
raise LicenseException.new("Error verifying license.")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def check_and_use_seat
|
34
|
+
incr = false
|
35
|
+
Store.lock(CLIENT_DOCKEY) do
|
36
|
+
current = Store.get_value(CLIENT_DOCKEY)
|
37
|
+
current = current ? current.to_i : 0
|
38
|
+
if current < self.seats
|
39
|
+
Store.put_value CLIENT_DOCKEY, current + 1
|
40
|
+
incr = true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
unless incr
|
44
|
+
msg = "WARNING: Maximum # of devices exceeded for this license."
|
45
|
+
log msg; raise LicenseSeatsExceededException.new(msg)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def free_seat
|
50
|
+
Store.lock(CLIENT_DOCKEY) do
|
51
|
+
current = Store.get_value(CLIENT_DOCKEY)
|
52
|
+
current = current ? current.to_i : 0
|
53
|
+
if current > 0
|
54
|
+
Store.put_value CLIENT_DOCKEY, current - 1
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def available
|
60
|
+
current = Store.get_value(CLIENT_DOCKEY)
|
61
|
+
current = current ? current.to_i : 0
|
62
|
+
available = self.seats - current
|
63
|
+
available > 0 ? available : 0
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def _decrypt
|
69
|
+
cipher = OpenSSL::Cipher::Cipher.new("aes-256-ecb")
|
70
|
+
cipher.key = _extract_str(RHO_PUBLICKEY)
|
71
|
+
cipher.decrypt
|
72
|
+
|
73
|
+
decrypted = cipher.update(_extract_str(@license))
|
74
|
+
decrypted << cipher.final
|
75
|
+
parts = decrypted.split(',')
|
76
|
+
@rhoconnect_version = parts[0].strip
|
77
|
+
@licensee = parts[1].strip
|
78
|
+
@seats = parts[2].strip.to_i
|
79
|
+
@issued = parts[3].strip
|
80
|
+
end
|
81
|
+
|
82
|
+
def _extract_str(str)
|
83
|
+
str.gsub(/(..)/){|h| h.hex.chr}
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
|
2
|
+
# Collection of methods for locking shared
|
3
|
+
# source documents when source_sync and client_sync
|
4
|
+
# need to access them
|
5
|
+
module LockOps
|
6
|
+
def lock(doc,timeout=0,raise_on_expire=false)
|
7
|
+
Store.lock(docname(doc),timeout,raise_on_expire) do
|
8
|
+
yield self
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|