Now supports both websocket integrated (ARVADOS_WEBSOCKETS defined) and
authorPeter Amstutz <peter.amstutz@curoverse.com>
Wed, 30 Apr 2014 14:53:35 +0000 (10:53 -0400)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Wed, 30 Apr 2014 14:53:35 +0000 (10:53 -0400)
websocket-only (ARVADOS_WEBSOCKETS=ws-only) server modes.  Added comment to
application.yml.example about setting websocket_address when running in
websocket-only mode.

services/api/app/controllers/arvados/v1/schema_controller.rb
services/api/config/application.default.yml
services/api/config/application.yml.example
services/api/config/initializers/eventbus.rb

index b8f0594138db4c4e491cda476d61340d998b9fbd..c9b18ae71c8f678e072fbe31ce85fddffe81a4a0 100644 (file)
@@ -21,7 +21,6 @@ class Arvados::V1::SchemaController < ApplicationController
         documentationLink: "http://doc.arvados.org/api/index.html",
         protocol: "rest",
         baseUrl: root_url + "/arvados/v1/",
-        websocketUrl: Rails.application.config.websocket_address,
         basePath: "/arvados/v1/",
         rootUrl: root_url,
         servicePath: "arvados/v1/",
@@ -71,6 +70,12 @@ class Arvados::V1::SchemaController < ApplicationController
         resources: {}
       }
 
+      if Rails.application.config.websocket_address
+        discovery[:websocketUrl] = Rails.application.config.websocket_address
+      elsif ENV['ARVADOS_WEBSOCKETS']
+        discovery[:websocketUrl] = (root_url.sub /^http/, 'ws') + "/websockets"
+      end
+
       ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
         begin
           ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
index c05b4afd63f3c2f28c3c78796293150cdf66f54d..37bb1c380f9d48091c76ec167093c7b532709124 100644 (file)
@@ -90,9 +90,6 @@ common:
   # Visitors to the API server will be redirected to the workbench
   workbench_address: https://workbench.local:3001/
 
-  # Websocket endpoint
-  websocket_address: wss://localhost:3002/websocket
-
   # The e-mail address of the user you would like to become marked as an admin
   # user on their first login.
   # In the default configuration, authentication happens through the Arvados SSO
index 9162fc444585d9fa1e59ade9f0df7e144f81cbda..b2b923863dfb1ab5f973b77e26a71908b5499ea3 100644 (file)
@@ -39,3 +39,10 @@ test:
 common:
   #git_repositories_dir: /var/cache/git
   #git_internal_dir: /var/cache/arvados/internal.git
+
+  # You can run the websocket server separately from the regular HTTP service
+  # by setting "ARVADOS_WEBSOCKETS=ws-only" in the environment before running
+  # the websocket server.  When you do this, you need to set the following
+  # configuration variable so that the primary server can give out the correct
+  # address of the dedicated websocket server:
+  #websocket_address: wss://websocket.local/websockets
index 290240394067c7741caf63c1ae5bf7d3017f556a..e04f1fe2f1df184a65b775fa2af6a8ac213de345 100644 (file)
@@ -1,7 +1,18 @@
 require 'eventbus'
 
 Server::Application.configure do
-  if ENV['ARVADOS_WEBSOCKETS'] == '1'
-    config.middleware.insert_after ArvadosApiToken, RackSocket, {:handler => EventBus, :websocket_only => true }
+  # Enables websockets if ARVADOS_WEBSOCKETS is defined with any value.  If
+  # ARVADOS_WEBSOCKETS=ws-only, server will only accept websocket connections
+  # and return an error response for all other requests.
+  if ENV['ARVADOS_WEBSOCKETS']
+    config.middleware.insert_after ArvadosApiToken, RackSocket, {
+      :handler => EventBus,
+      :mount => "/websockets",
+      :websocket_only => (ENV['ARVADOS_WEBSOCKETS'] == "ws-only")
+    }
   end
+
+  # Define websocket_address configuration option, can be overridden in config files.
+  # See application.yml.example for details.
+  config.websocket_address = nil
 end