Permalink
Browse files

fix advertising message of service broker

1. Use ServiceOfferingRequest message object instead of raw json
2. Fix unit test in dev_setup
3. support https scheme for external_uri

Change-Id: Id987018f59fd08f28584371f9026f575eeea321a
  • Loading branch information...
1 parent 9c33fc5 commit 2c186f9a14bc9601954cbfe800141dac05f2cd1a @andl andl committed Aug 28, 2012
View
@@ -22,7 +22,6 @@ group :test do
gem "rake"
gem "rspec"
gem "rack-test"
- gem "rcov"
gem "simplecov"
gem "simplecov-rcov"
gem "ci_reporter"
@@ -152,7 +152,6 @@ GEM
rack-test (0.5.7)
rack (>= 1.0)
rake (0.9.2.2)
- rcov (0.9.9)
redis (3.0.1)
redis-namespace (1.2.1)
redis (~> 3.0.0)
@@ -216,7 +215,6 @@ DEPENDENCIES
nats
rack-test
rake
- rcov
rspec
simplecov
simplecov-rcov
View
@@ -33,9 +33,14 @@ end
namespace "test" do
def run_spec
- sh "nats-server &"
- Dir.chdir("spec"){ yield }
- sh "pkill -f nats-server"
+ Dir.chdir("spec")
+ if `ps ax | grep nats-server | grep -v grep`.empty?
+ sh "nats-server &"
+ yield
+ sh "pkill -f nats-server"
+ else
+ yield
+ end
end
task "spec" do |t|
@@ -46,7 +46,7 @@ def setup(opts)
@token = opts[:token]
@hb_interval = opts[:heartbeat_interval] || 60
@cld_ctrl_uri = http_uri(opts[:cloud_controller_uri])
- @external_uri = opts[:external_uri]
+ @external_uri = parse_uri(opts[:external_uri])
@offering_uri = "#{@cld_ctrl_uri}/services/v1/offerings/"
@service_list_uri = "#{@cld_ctrl_uri}/proxied_services/#{API_VERSION}/offerings"
@router_start_channel = nil
@@ -56,7 +56,7 @@ def setup(opts)
@router_register_json = {
:host => @host,
:port => @port,
- :uris => [ @external_uri ],
+ :uris => [ @external_uri.host ],
:tags => {:components => "ServiceBroker"},
}.to_json
@@ -119,6 +119,14 @@ def setup(opts)
abort_request(error_msg)
end
+ def parse_uri(uri_str)
+ uri = URI.parse(uri_str)
+ uri = URI.parse('http://' + uri_str) unless uri.scheme
+
+ raise "Invalid external uri: #{uri_str}" unless uri.scheme.start_with? 'http'
+ uri
+ end
+
def start_nats(uri)
f = Fiber.current
@nats = NATS.connect(:uri => uri) do
@@ -166,13 +174,16 @@ def fetch_brokered_services
def advertise_saved_services(active=true)
BrokeredService.all.each do |bsvc|
- req = {}
- req[:label] = bsvc.label
- req[:active] = active
- req[:acls] = bsvc.acls
- req[:url] = "http://#{@external_uri}"
- req[:plans] = ["default"]
- req[:tags] = ["default"]
+ req = VCAP::Services::Api::ServiceOfferingRequest.new({
+ :label => bsvc.label,
+ :active => active,
+ :acls => bsvc.acls,
+ :url => @external_uri.to_s,
+ :plans => ["default"],
+ :tags => [],
+ :supported_versions => [bsvc.version],
+ :version_aliases => {:current => bsvc.version},
+ }).extract
advertise_brokered_service_to_cc(req)
end
end
@@ -296,16 +307,18 @@ def advertise_brokered_service(request)
opt = VCAP.symbolize_keys(opt)
svc = {}
name, version = VCAP::Services::Api::Util.parse_label(label)
- svc[:label] = "#{name}_#{opt[:name]}-#{version}"
- svc[:active] = true
- svc[:description] = "#{des} (option '#{opt[:name]}')"
- # Add required fields
- svc[:acls] = opt[:acls]
- svc[:url] = "http://#{@external_uri}"
- svc[:plans] = ["default"]
- svc[:tags] = ["default"]
- svc[:supported_versions] = [ version ]
- svc[:version_aliases] = { "current" => version }
+
+ svc = VCAP::Services::Api::ServiceOfferingRequest.new({
+ :label => "#{name}_#{opt[:name]}-#{version}",
+ :active => true,
+ :description => "#{des} (option '#{opt[:name]}')",
+ :acls => opt[:acls],
+ :url => @external_uri.to_s,
+ :plans => ["default"],
+ :tags => [],
+ :supported_versions => [version],
+ :version_aliases => {:current => version},
+ }).extract
# update or create local database entry
bsvc = BrokeredService.get(svc[:label])
@@ -15,7 +15,13 @@
require 'vcap/common'
def load_config()
- config_file = File.join(File.dirname(__FILE__), '..', 'config', 'service_broker.yml')
+ config_file = nil
+ if ENV["CLOUD_FOUNDRY_CONFIG_PATH"]
+ config_file = File.join(ENV["CLOUD_FOUNDRY_CONFIG_PATH"],
+ "service_broker.yml")
+ else
+ config_file = File.join(File.dirname(__FILE__), '..', 'config', 'service_broker.yml')
+ end
config = YAML.load_file(config_file)
config = VCAP.symbolize_keys(config)
config[:host] = "localhost"
Binary file not shown.

0 comments on commit 2c186f9

Please sign in to comment.