Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix gem management issues for uaa and client

wait for uaa to start before registering with nats

Change-Id: I473eb566a168ae08e2f2cced97c5134dec786cd9
  • Loading branch information...
commit 0da16d9746ca6b68749ae031acb6779f035b08c3 1 parent d96a2f4
@daleolds daleolds authored
View
2  Gemfile
@@ -2,3 +2,5 @@ source 'http://rubygems.org'
gem 'vcap_common'
gem 'vcap_logging', :require => ['vcap/logging']
+gem 'rest-client'
+
View
38 Gemfile.lock
@@ -0,0 +1,38 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ daemons (1.1.8)
+ eventmachine (0.12.11.cloudfoundry.3)
+ json_pure (1.6.6)
+ mime-types (1.18)
+ nats (0.4.22)
+ daemons (>= 1.1.4)
+ eventmachine (>= 0.12.10)
+ json_pure (>= 1.6.1)
+ thin (>= 1.3.1)
+ posix-spawn (0.3.6)
+ rack (1.4.1)
+ rake (0.9.2.2)
+ rest-client (1.6.7)
+ mime-types (>= 1.16)
+ thin (1.3.1)
+ daemons (>= 1.0.9)
+ eventmachine (>= 0.12.6)
+ rack (>= 1.0.0)
+ vcap_common (1.0.10)
+ eventmachine (~> 0.12.11.cloudfoundry.3)
+ nats (~> 0.4.22.beta.8)
+ posix-spawn (~> 0.3.6)
+ thin (~> 1.3.1)
+ yajl-ruby (~> 0.8.3)
+ vcap_logging (0.1.4)
+ rake
+ yajl-ruby (0.8.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ rest-client
+ vcap_common
+ vcap_logging
View
24 bin/uaa
@@ -11,10 +11,15 @@
# subcomponent's license, as noted in the LICENSE file.
#
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", __FILE__)
+require "bundler"
+Bundler.setup
+
require 'yaml'
require 'nats/client'
require 'vcap/common'
require 'vcap/logging'
+require 'rest_client'
VCAP::Logging.setup_from_config()
logger = VCAP::Logging.logger('uaa')
@@ -23,7 +28,7 @@ root=File.absolute_path(File.join(File.dirname(__FILE__), ".."))
if File.exist?(root) then
logger.info("Using root=#{root}")
else
- abort("#{root} is not a directory. Do you need to init submodules?")
+ abort("#{root} is not a directory. Do you need to init submodules?")
end
cfg_path = ENV['CLOUD_FOUNDRY_CONFIG_PATH'] ? ENV['CLOUD_FOUNDRY_CONFIG_PATH'] : File.join(root, "config")
@@ -66,7 +71,7 @@ logger.info("Preparing to launch NATS from #{pid}")
router_msg = { :host => config["uaa"]["host"]||"localhost", :port => config["uaa"]["port"]||8080, :uris => config["uaa"]["uris"]||["uaa.vcap.me"], :tags => {:component => "UAA"} }
router_json = Yajl::Encoder.encode(router_msg)
-discover_msg = { :type => 'UAA',
+discover_msg = { :type => 'UAA',
:host => "%s:%s" % [config["uaa"]["host"]||"localhost", config["uaa"]["port"]||8080],
:index => 0,
:credentials => [config["varz"]["username"], config["varz"]["password"]]
@@ -77,10 +82,23 @@ mbus = config["mbus"] || "nats://localhost:4222/"
Thread.new do
+ max_wait = 30
+ uaa_is_up = false
+ start_time = Time.now
+ logger.info("Waiting for uaa to start within #{max_wait} seconds")
+ begin
+ response = RestClient.get "#{discover_msg[:host]}/login", accept: "application/json",
+ open_timeout: 2, timeout: 2
+ uaa_is_up = response.code == 200 && response.body =~ /prompts/
+ rescue Exception => e
+ logger.info "waiting for uaa to start: #{e}"
+ sleep 2
+ end while !uaa_is_up && Time.now - start_time < max_wait
+
# NATS will block and we want to wait for the tomcat process so this
# has to go in a new thread
- logger.info("Launching NATS from uaa")
+ logger.info("UAA started, registering with NATS")
NATS.start(:uri => mbus) do
NATS.subscribe('vcap.component.discover') do |msg, reply|
View
2  gem/Rakefile
@@ -11,7 +11,7 @@
#
require "rspec/core/rake_task"
-require "bundler/gem_tasks"
+#require "bundler/gem_tasks" # only available in bundler >= 1.0.15
require "rdoc/task"
task :default => [:cover]
View
4 gem/lib/uaa/user_account.rb
@@ -64,6 +64,10 @@ def get(user_id)
json_get("/User/#{URI.encode(user_id)}", @authorization)
end
+ def get_by_name(name)
+ json_get("/User/#{URI.encode(user_id_from_name(name))}", @authorization)
+ end
+
def list
json_get("/Users?attributes=userName", @authorization)
end
View
6 gem/spec/integration_spec.rb
@@ -81,13 +81,13 @@
it "deletes the user by name" do
@user_acct.delete_by_name(@username)
- # TODO: query that the user is gone
+ expect { @user_acct.get_by_name(@username) }
+ .to raise_exception(Cloudfoundry::Uaa::UserAccount::NotFound)
end
- it "deletes the user by name" do
+ it "complains about an attempt to delete a non-existent user" do
expect { @user_acct.delete_by_name("non-existent-user") }
.to raise_exception(Cloudfoundry::Uaa::UserAccount::NotFound)
- # TODO: query that the user is gone
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.