[ARVADOS] created: 052cfead6e6e87d605cbe7beece4752ee78aa62f

git at public.curoverse.com git at public.curoverse.com
Fri Apr 18 14:00:53 EDT 2014


        at  052cfead6e6e87d605cbe7beece4752ee78aa62f (commit)


commit 052cfead6e6e87d605cbe7beece4752ee78aa62f
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Fri Apr 18 14:00:44 2014 -0400

    Added missing events controller file.
    Added input form to send raw events to websocket server for development.

diff --git a/apps/workbench/app/views/websocket/index.html.erb b/apps/workbench/app/views/websocket/index.html.erb
index 64b00e0..21ec7ac 100644
--- a/apps/workbench/app/views/websocket/index.html.erb
+++ b/apps/workbench/app/views/websocket/index.html.erb
@@ -3,13 +3,30 @@
 <% end %>
 <h1>Event bus debugging page</h1>
 
+<form>
+<input type="text" style="width:100%" id="websocket-message-type">
+<textarea style="width:100%; height: 10em" id="websocket-message-content"></textarea>
+<button type="button" id="send-to-websocket">Send</button>
+</form>
+
+<br>
+
 <p id="PutStuffHere"></p>
 
 <script>
-function putStuffThere(content) {
+$(function() {
+putStuffThere = function (content) {
   $("#PutStuffHere").append(content["message"] + "<br>");
-}
+};
 
 var dispatcher = new WebSocketRails('localhost:3032/arvados/v1/events');
 dispatcher.bind('hello', putStuffThere);
+
+sendStuff = function () {
+  dispatcher.trigger($("#websocket-message-type").val(), JSON.parse($("#websocket-message-content").val()));
+};
+
+$("#send-to-websocket").click(sendStuff);
+});
+
 </script>
diff --git a/services/api/app/controllers/arvados/v1/events_controller.rb b/services/api/app/controllers/arvados/v1/events_controller.rb
new file mode 100644
index 0000000..473348b
--- /dev/null
+++ b/services/api/app/controllers/arvados/v1/events_controller.rb
@@ -0,0 +1,16 @@
+class Arvados::V1::EventsController < WebsocketRails::BaseController
+  def initialize_session
+    # "The initialize_session method will be called the first time a controller
+    # is subscribed to an event in the event router. Values added to the
+    # controller data store from inside the initialize_session method will be
+    # available throughout the course of the server lifetime."
+  end
+
+  def client_connected
+    send_message :hello, {:message => "hello world!"}
+  end
+
+  def hello
+    send_message :hello, {:message => "Nice to meetcha #{message['name']}"}
+  end
+end
diff --git a/services/api/config/events.rb b/services/api/config/events.rb
index b30dd1e..e1605c1 100644
--- a/services/api/config/events.rb
+++ b/services/api/config/events.rb
@@ -12,5 +12,6 @@ WebsocketRails::EventMap.describe do
   #   end
   # The above will handle an event triggered on the client like `product.new`.
 
-  subscribe :client_connected, :to => Arvados::V1::EventsController, :with_method => :client_connected
+  subscribe :client_connected, "arvados/v1/events#client_connected"
+  subscribe :hello, "arvados/v1/events#hello"
 end

commit 443b35cdf69ed41a16f50ec5f1fc0d8db4527bf6
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Fri Apr 18 11:25:29 2014 -0400

    Added the correct route to API server to connect to websockets.
    Added websocket-rails gem to workbench in order to use the javascript client.
    Added websockets controller/view to workbench for debugging.

diff --git a/apps/workbench/Gemfile b/apps/workbench/Gemfile
index ee43a89..1a40691 100644
--- a/apps/workbench/Gemfile
+++ b/apps/workbench/Gemfile
@@ -61,3 +61,4 @@ gem 'piwik_analytics'
 gem 'httpclient'
 gem 'themes_for_rails'
 gem "deep_merge", :require => 'deep_merge/rails_compat'
+gem 'websocket-rails'
diff --git a/apps/workbench/Gemfile.lock b/apps/workbench/Gemfile.lock
index e1e2b81..49651af 100644
--- a/apps/workbench/Gemfile.lock
+++ b/apps/workbench/Gemfile.lock
@@ -60,13 +60,21 @@ GEM
     coffee-script-source (1.6.3)
     commonjs (0.2.7)
     daemon_controller (1.1.7)
+    daemons (1.1.9)
     deep_merge (1.0.1)
+    em-synchrony (1.0.3)
+      eventmachine (>= 1.0.0.beta.1)
     erubis (2.7.0)
+    eventmachine (1.0.3)
     execjs (2.0.2)
+    faye-websocket (0.7.2)
+      eventmachine (>= 0.12.0)
+      websocket-driver (>= 0.3.1)
     ffi (1.9.3)
     headless (1.0.1)
     highline (1.6.20)
     hike (1.2.3)
+    hiredis (0.5.2)
     httpclient (2.3.4.1)
     i18n (0.6.5)
     journey (1.0.4)
@@ -135,6 +143,9 @@ GEM
     rake (10.1.0)
     rdoc (3.12.2)
       json (~> 1.4)
+    redis (3.0.7)
+    redis-objects (0.9.1)
+      redis (>= 3.0.2)
     ref (1.0.5)
     rubyzip (1.1.0)
     rvm-capistrano (1.5.1)
@@ -160,6 +171,10 @@ GEM
     therubyracer (0.12.0)
       libv8 (~> 3.16.14.0)
       ref
+    thin (1.6.2)
+      daemons (>= 1.0.9)
+      eventmachine (>= 1.0.0)
+      rack (>= 1.0.0)
     thor (0.18.1)
     tilt (1.4.1)
     treetop (1.4.15)
@@ -171,6 +186,15 @@ GEM
       json (>= 1.8.0)
     websocket (1.0.7)
     websocket-driver (0.3.2)
+    websocket-rails (0.7.0)
+      em-synchrony
+      faye-websocket
+      hiredis
+      rack
+      rails
+      redis
+      redis-objects
+      thin
     xpath (2.0.0)
       nokogiri (~> 1.3)
 
@@ -204,3 +228,4 @@ DEPENDENCIES
   themes_for_rails
   therubyracer
   uglifier (>= 1.0.3)
+  websocket-rails
diff --git a/apps/workbench/app/assets/javascripts/application.js b/apps/workbench/app/assets/javascripts/application.js
index 6afc8c3..51d0079 100644
--- a/apps/workbench/app/assets/javascripts/application.js
+++ b/apps/workbench/app/assets/javascripts/application.js
@@ -21,6 +21,7 @@
 //= require bootstrap/modal
 //= require bootstrap3-editable/bootstrap-editable
 //= require_tree .
+//= require websocket_rails/main
 
 jQuery(function($){
     $.ajaxSetup({
diff --git a/apps/workbench/app/controllers/websocket_controller.rb b/apps/workbench/app/controllers/websocket_controller.rb
new file mode 100644
index 0000000..a49c15f
--- /dev/null
+++ b/apps/workbench/app/controllers/websocket_controller.rb
@@ -0,0 +1,10 @@
+class WebsocketController < ApplicationController
+  skip_before_filter :find_objects_for_index
+
+  def index
+  end
+
+  def model_class
+    "Websocket"
+  end
+end
diff --git a/apps/workbench/app/views/websocket/index.html.erb b/apps/workbench/app/views/websocket/index.html.erb
new file mode 100644
index 0000000..64b00e0
--- /dev/null
+++ b/apps/workbench/app/views/websocket/index.html.erb
@@ -0,0 +1,15 @@
+<% content_for :page_title do %>
+  Event bus debugging page
+<% end %>
+<h1>Event bus debugging page</h1>
+
+<p id="PutStuffHere"></p>
+
+<script>
+function putStuffThere(content) {
+  $("#PutStuffHere").append(content["message"] + "<br>");
+}
+
+var dispatcher = new WebSocketRails('localhost:3032/arvados/v1/events');
+dispatcher.bind('hello', putStuffThere);
+</script>
diff --git a/apps/workbench/config/routes.rb b/apps/workbench/config/routes.rb
index 8c89238..9d7a3c9 100644
--- a/apps/workbench/config/routes.rb
+++ b/apps/workbench/config/routes.rb
@@ -43,6 +43,7 @@ ArvadosWorkbench::Application.routes.draw do
   get '/collections/:uuid/*file' => 'collections#show_file', :format => false
 
   post 'actions' => 'actions#post'
+  get 'websockets' => 'websocket#index'
 
   root :to => 'users#welcome'
 
diff --git a/services/api/config/events.rb b/services/api/config/events.rb
index b40d976..b30dd1e 100644
--- a/services/api/config/events.rb
+++ b/services/api/config/events.rb
@@ -11,4 +11,6 @@ WebsocketRails::EventMap.describe do
   #     subscribe :new, :to => ProductController, :with_method => :new_product
   #   end
   # The above will handle an event triggered on the client like `product.new`.
+
+  subscribe :client_connected, :to => Arvados::V1::EventsController, :with_method => :client_connected
 end
diff --git a/services/api/config/initializers/websocket_rails.rb b/services/api/config/initializers/websocket_rails.rb
index 55bb501..6755c88 100644
--- a/services/api/config/initializers/websocket_rails.rb
+++ b/services/api/config/initializers/websocket_rails.rb
@@ -10,7 +10,7 @@ WebsocketRails.setup do |config|
 
   # Set to true if you wish to log the internal websocket_rails events
   # such as the keepalive `websocket_rails.ping` event.
-  # config.log_internal_events = false
+  config.log_internal_events = true
 
   # Change to true to enable standalone server mode
   # Start the standalone server with rake websocket_rails:start_server
@@ -21,10 +21,10 @@ WebsocketRails.setup do |config|
   # Change to true to enable channel synchronization between
   # multiple server instances.
   # * Requires Redis.
-  config.synchronize = false
+  config.synchronize = true
 
   # Prevent Thin from daemonizing (default is true)
-  # config.daemonize = false
+  config.daemonize = false
 
   # Uncomment and edit to point to a different redis instance.
   # Will not be used unless standalone or synchronization mode
@@ -59,6 +59,6 @@ WebsocketRails.setup do |config|
   # Supporting HTTP streaming on Internet Explorer versions 8 & 9
   # requires CORS to be enabled for GET "/websocket" request.
   # List here the origin domains allowed to perform the request.
-  # config.allowed_origins = ['http://localhost:3000']
+  config.allowed_origins = ['http://localhost:3000']
 
 end
diff --git a/services/api/config/routes.rb b/services/api/config/routes.rb
index 211701a..87d6120 100644
--- a/services/api/config/routes.rb
+++ b/services/api/config/routes.rb
@@ -124,6 +124,8 @@ Server::Application.routes.draw do
     end
   end
 
+  match '/arvados/v1/events', :to => WebsocketRails::ConnectionManager.new
+
   # omniauth
   match '/auth/:provider/callback', :to => 'user_sessions#create'
   match '/auth/failure', :to => 'user_sessions#failure'

commit bcef5dd7b288f5eecfe1fa5286bf6baa077d40c3
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Thu Apr 17 14:51:23 2014 -0400

    Initial setup of websocket-rails

diff --git a/services/api/Gemfile b/services/api/Gemfile
index e50802e..38e6373 100644
--- a/services/api/Gemfile
+++ b/services/api/Gemfile
@@ -64,5 +64,6 @@ gem 'google-api-client', '~> 0.6.3'
 gem 'trollop'
 
 gem 'themes_for_rails'
+gem 'websocket-rails'
 
 gem 'arvados-cli', '>= 0.1.20140328152103'
diff --git a/services/api/Gemfile.lock b/services/api/Gemfile.lock
index 7a516d5..62a705b 100644
--- a/services/api/Gemfile.lock
+++ b/services/api/Gemfile.lock
@@ -69,11 +69,18 @@ GEM
     coffee-script-source (1.7.0)
     curb (0.8.5)
     daemon_controller (1.2.0)
+    daemons (1.1.9)
+    em-synchrony (1.0.3)
+      eventmachine (>= 1.0.0.beta.1)
     erubis (2.7.0)
+    eventmachine (1.0.3)
     execjs (2.0.2)
     extlib (0.9.16)
     faraday (0.8.9)
       multipart-post (~> 1.2.0)
+    faye-websocket (0.7.2)
+      eventmachine (>= 0.12.0)
+      websocket-driver (>= 0.3.1)
     google-api-client (0.6.4)
       addressable (>= 2.3.2)
       autoparse (>= 0.3.3)
@@ -87,6 +94,7 @@ GEM
     hashie (1.2.0)
     highline (1.6.21)
     hike (1.2.3)
+    hiredis (0.5.2)
     httpauth (0.2.1)
     i18n (0.6.9)
     journey (1.0.4)
@@ -157,6 +165,8 @@ GEM
     rdoc (3.12.2)
       json (~> 1.4)
     redis (3.0.7)
+    redis-objects (0.9.1)
+      redis (>= 3.0.2)
     ref (1.0.5)
     rvm-capistrano (1.5.1)
       capistrano (~> 2.15.4)
@@ -182,6 +192,10 @@ GEM
     therubyracer (0.12.1)
       libv8 (~> 3.16.14.0)
       ref
+    thin (1.6.2)
+      daemons (>= 1.0.9)
+      eventmachine (>= 1.0.0)
+      rack (>= 1.0.0)
     thor (0.19.1)
     tilt (1.4.1)
     treetop (1.4.15)
@@ -193,6 +207,16 @@ GEM
       execjs (>= 0.3.0)
       json (>= 1.8.0)
     uuidtools (2.1.4)
+    websocket-driver (0.3.2)
+    websocket-rails (0.7.0)
+      em-synchrony
+      faye-websocket
+      hiredis
+      rack
+      rails
+      redis
+      redis-objects
+      thin
 
 PLATFORMS
   ruby
@@ -220,3 +244,4 @@ DEPENDENCIES
   therubyracer
   trollop
   uglifier (>= 1.0.3)
+  websocket-rails
diff --git a/services/api/app/assets/javascripts/application.js b/services/api/app/assets/javascripts/application.js
index 37c7bfc..e6cc085 100644
--- a/services/api/app/assets/javascripts/application.js
+++ b/services/api/app/assets/javascripts/application.js
@@ -7,3 +7,5 @@
 //= require jquery
 //= require jquery_ujs
 //= require_tree .
+//= require websocket_rails/main
+
diff --git a/services/api/app/models/job.rb b/services/api/app/models/job.rb
index 0b2247b..6768d48 100644
--- a/services/api/app/models/job.rb
+++ b/services/api/app/models/job.rb
@@ -185,13 +185,13 @@ class Job < ArvadosModel
   end
 
   def log_buffer
-    begin
-      @@redis ||= Redis.new(:timeout => 0)
-      if @@redis.exists uuid
-        @@redis.getrange(uuid, 0 - 2**10, -1)
-      end
-    rescue Redis::CannotConnectError
+    #begin
+      #@@redis ||= Redis.new(:timeout => 0)
+      #if @@redis.exists uuid
+      #  @@redis.getrange(uuid, 0 - 2**10, -1)
+      #end
+    #rescue Redis::CannotConnectError
       return '(not available)'
-    end
+    #end
   end
 end
diff --git a/services/api/config/application.rb b/services/api/config/application.rb
index 24648a9..ace2169 100644
--- a/services/api/config/application.rb
+++ b/services/api/config/application.rb
@@ -32,5 +32,7 @@ module Server
 
     # Configure sensitive parameters which will be filtered from the log file.
     config.filter_parameters += [:password]
+    config.middleware.delete Rack::Lock
+    config.threadsafe!
   end
 end
diff --git a/services/api/config/environment.rb b/services/api/config/environment.rb
index 4ccec85..ad0479d 100644
--- a/services/api/config/environment.rb
+++ b/services/api/config/environment.rb
@@ -4,6 +4,7 @@ require 'josh_id'
 
 # Initialize the rails application
 Server::Application.initialize!
+
 begin
   Rails.cache.clear
 rescue Errno::ENOENT => e
diff --git a/services/api/config/events.rb b/services/api/config/events.rb
new file mode 100644
index 0000000..b40d976
--- /dev/null
+++ b/services/api/config/events.rb
@@ -0,0 +1,14 @@
+WebsocketRails::EventMap.describe do
+  # You can use this file to map incoming events to controller actions.
+  # One event can be mapped to any number of controller actions. The
+  # actions will be executed in the order they were subscribed.
+  #
+  # Uncomment and edit the next line to handle the client connected event:
+  #   subscribe :client_connected, :to => Controller, :with_method => :method_name
+  #
+  # Here is an example of mapping namespaced events:
+  #   namespace :product do
+  #     subscribe :new, :to => ProductController, :with_method => :new_product
+  #   end
+  # The above will handle an event triggered on the client like `product.new`.
+end
diff --git a/services/api/config/initializers/websocket_rails.rb b/services/api/config/initializers/websocket_rails.rb
new file mode 100644
index 0000000..55bb501
--- /dev/null
+++ b/services/api/config/initializers/websocket_rails.rb
@@ -0,0 +1,64 @@
+WebsocketRails.setup do |config|
+
+  # Uncomment to override the default log level. The log level can be
+  # any of the standard Logger log levels. By default it will mirror the
+  # current Rails environment log level.
+  # config.log_level = :debug
+
+  # Uncomment to change the default log file path.
+  # config.log_path = "#{Rails.root}/log/websocket_rails.log"
+
+  # Set to true if you wish to log the internal websocket_rails events
+  # such as the keepalive `websocket_rails.ping` event.
+  # config.log_internal_events = false
+
+  # Change to true to enable standalone server mode
+  # Start the standalone server with rake websocket_rails:start_server
+  # * Requires Redis
+  config.standalone = true
+  config.standalone_port = 3032
+
+  # Change to true to enable channel synchronization between
+  # multiple server instances.
+  # * Requires Redis.
+  config.synchronize = false
+
+  # Prevent Thin from daemonizing (default is true)
+  # config.daemonize = false
+
+  # Uncomment and edit to point to a different redis instance.
+  # Will not be used unless standalone or synchronization mode
+  # is enabled.
+  # config.redis_options = {:host => 'localhost', :port => '6379'}
+
+  # By default, all subscribers in to a channel will be removed
+  # when that channel is made private. If you don't wish active
+  # subscribers to be removed from a previously public channel
+  # when making it private, set the following to true.
+  # config.keep_subscribers_when_private = false
+
+  # Set to true if you wish to broadcast channel subscriber_join and
+  # subscriber_part events. All subscribers of a channel will be
+  # notified when other clients join and part the channel. If you are
+  # using the UserManager, the current_user object will be sent along
+  # with the event.
+  # config.broadcast_subscriber_events = true
+
+  # Used as the key for the WebsocketRails.users Hash. This method
+  # will be called on the `current_user` object in your controller
+  # if one exists. If `current_user` does not exist or does not
+  # respond to the identifier, the key will default to `connection.id`
+  # config.user_identifier = :id
+
+  # Uncomment and change this option to override the class associated
+  # with your `current_user` object. This class will be used when
+  # synchronization is enabled and you trigger events from background
+  # jobs using the WebsocketRails.users UserManager.
+  # config.user_class = User
+
+  # Supporting HTTP streaming on Internet Explorer versions 8 & 9
+  # requires CORS to be enabled for GET "/websocket" request.
+  # List here the origin domains allowed to perform the request.
+  # config.allowed_origins = ['http://localhost:3000']
+
+end

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list