Permalink
Browse files

Exposing runtimes in other apps won't work, since they may not have t…

…orquebox-webconsole on their load paths.
  • Loading branch information...
1 parent 66fa78c commit fa042f9f07295140391ae73c1a2f424670f45c47 @tobias tobias committed Apr 19, 2012
Showing with 26 additions and 39 deletions.
  1. +16 −26 lib/torquebox/webconsole.rb
  2. +10 −13 lib/torquebox/webconsole/rack-webconsole-patch.rb
@@ -8,46 +8,36 @@ class Webconsole
extend TorqueBox::Injectors
class << self
- def lookup_runtime(name, app = nil)
+ def lookup_runtime(name)
service_registry = inject('service-registry')
- service_name = nil
+ unit = inject('deployment-unit')
- if app
- _, _, service_name = list_runtimes.detect { |v| v[0] == app && v[1] == name }
- else
- unit = inject('deployment-unit')
- service_name = org.torquebox.core.as.CoreServices.runtimePoolName(unit, name)
- end
-
- return nil unless service_name
+ service_name = org.torquebox.core.as.CoreServices.runtimePoolName(unit, name)
service_controller = service_registry.get_service(service_name)
+
return nil unless service_controller
pool = service_controller.service.value
+ pool.evaluate "require 'torquebox/webconsole'"
- pool.evaluate """
- require 'rack/webconsole'
- require 'torquebox-webconsole'
- """
- [pool] + parse_pool_name(service_name)
- end
+ [pool, name]
+ end
def web_runtime
lookup_runtime('web')
end
def list_runtimes
- service_registry = inject('service-registry')
- service_registry.service_names.to_a.map { |x| parse_pool_name(x) }.reject(&:nil?)
- end
-
- def parse_pool_name(service_name)
- [$1, $3, service_name] if service_name.canonical_name =~
- /"(.*)(-knob\.yml|\.knob)"\.torquebox\.core\.runtime\.pool\.([^.]+)$/
+ prefix = inject('deployment-unit').
+ service_name.
+ append(org.torquebox.core.as.CoreServices::RUNTIME).
+ append("pool").
+ canonical_name
+
+ inject('service-registry').service_names.to_a.map do |x|
+ $1 if x.canonical_name =~ %r{#{prefix}\.([^.]+)$}
+ end.reject(&:nil?)
end
- def runtime_metadata(runtime)
- { :app => runtime[0], :name => runtime[1] }
- end
end
end
end
@@ -4,38 +4,35 @@ module Rack
class Webconsole
class Sandbox
- def switch_runtime(name, app = nil)
- runtime = TorqueBox::Webconsole.lookup_runtime(name, app)
+ def switch_runtime(name)
+ runtime = TorqueBox::Webconsole.lookup_runtime(name)
if runtime.nil?
- msg = "runtime #{name} not found"
- msg << " for app #{app}" if app
- msg
+ "runtime #{name} not found"
else
web_runtime = TorqueBox::Webconsole.web_runtime[0]
web_runtime.evaluate <<-EOS
runtime = TorqueBox::Webconsole.lookup_runtime(%q(#{name}))
$runtime = runtime
EOS
- "switched to #{current_runtime}"
+ "switched to #{name} runtime"
end
end
def list_runtimes
- TorqueBox::Webconsole.list_runtimes.map { |x| TorqueBox::Webconsole.runtime_metadata(x) }
+ TorqueBox::Webconsole.list_runtimes
end
def current_runtime
- TorqueBox::Webconsole.runtime_metadata($runtime[1..-1])
+ web_runtime = TorqueBox::Webconsole.web_runtime[0]
+ web_runtime.evaluate "$runtime[1]"
end
def help
"Welcome to the TorqueBox webconsole. It's rack-webconsole with the following " +
"additions: * list_runtimes - returns list of all of the TorqueBox runtimes " +
- "along with their app names. * switch_runtime(name[, app_name]) - switch " +
- "your execution context to a different runtime. If the app_name isn't " +
- "provided, it will attempt to switch to the given runtime within the current " +
- "application. * current_runtime - returns the name and app name of the " +
- "current runtime."
+ "for the current application. * switch_runtime(name) - switch " +
+ "your execution context to a different runtime. * current_runtime - returns " +
+ "the name of the current runtime."
end
end

0 comments on commit fa042f9

Please sign in to comment.