Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Revert "Merge branch 'services-r8' into services-r9"

This should have gone to services-r9 branch, not master -- sorry!

This reverts commit 4b2b7e1
  • Loading branch information...
commit 409cd99e3a85566995fc0bbc541f70e01115b69d 1 parent 4b2b7e1
@kushmerick kushmerick authored Gerrit Code Review committed
Showing with 2,747 additions and 3,133 deletions.
  1. +1 −1  atmos/Gemfile.lock
  2. BIN  atmos/vendor/cache/vcap_services_base-0.1.5.gem
  3. BIN  atmos/vendor/cache/vcap_services_base-0.1.6.gem
  4. +2 −2 base/Gemfile.lock
  5. +1 −1  base/lib/base/asynchronous_service_gateway.rb
  6. +2 −6 base/lib/base/backup.rb
  7. +18 −18 base/lib/base/base.rb
  8. +2 −3 base/lib/base/gateway.rb
  9. +58 −49 base/lib/base/node.rb
  10. +1 −3 base/lib/base/node_bin.rb
  11. +38 −60 base/lib/base/provisioner.rb
  12. +0 −1  base/lib/base/service_error.rb
  13. +1 −1  base/lib/base/version.rb
  14. +23 −1 base/spec/async_gw_spec.rb
  15. +2 −23 base/spec/backup_spec.rb
  16. +673 −1 base/spec/base_spec.rb
  17. +0 −410 base/spec/helper/async_gw_spec_helper.rb
  18. +0 −22 base/spec/helper/backup_spec_helper.rb
  19. +0 −60 base/spec/helper/base_spec_helper.rb
  20. +0 −317 base/spec/helper/node_spec_helper.rb
  21. +0 −388 base/spec/helper/provision_spec_helper.rb
  22. +0 −219 base/spec/helper/spec_helper.rb
  23. +0 −343 base/spec/node_spec.rb
  24. +0 −426 base/spec/provision_spec.rb
  25. +1,385 −0 base/spec/spec_helper.rb
  26. +1 −1  filesystem/Gemfile.lock
  27. BIN  filesystem/vendor/cache/vcap_services_base-0.1.5.gem
  28. BIN  filesystem/vendor/cache/vcap_services_base-0.1.6.gem
  29. +1 −1  mongodb/Gemfile.lock
  30. +6 −11 mongodb/bin/mongodb_backup
  31. +1 −1  mongodb/bin/mongodb_node
  32. +1 −6 mongodb/config/mongodb_gateway.yml
  33. +2 −3 mongodb/config/mongodb_node.yml
  34. +2 −2 mongodb/config/mongodb_worker.yml
  35. +47 −35 mongodb/lib/mongodb_service/mongodb_node.rb
  36. +4 −0 mongodb/lib/mongodb_service/mongodb_provisioner.rb
  37. +1 −1  mongodb/resources/mongodb.conf.erb
  38. +15 −2 mongodb/spec/mongodb_provision_spec.rb
  39. +1 −2  mongodb/spec/spec_helper.rb
  40. BIN  mongodb/vendor/cache/vcap_services_base-0.1.5.gem
  41. BIN  mongodb/vendor/cache/vcap_services_base-0.1.6.gem
  42. +1 −1  mysql/Gemfile.lock
  43. +8 −3 mysql/bin/mysql_backup
  44. +1 −0  mysql/bin/mysql_node
  45. +1 −1  mysql/config/mysql_backup.yml
  46. +1 −7 mysql/config/mysql_gateway.yml
  47. +2 −3 mysql/config/mysql_node.yml
  48. +1 −1  mysql/config/mysql_worker.yml
  49. +49 −24 mysql/lib/mysql_service/node.rb
  50. +4 −0 mysql/lib/mysql_service/provisioner.rb
  51. +130 −122 mysql/spec/mysql_node_spec.rb
  52. +7 −7 mysql/spec/mysql_provisioner_spec.rb
  53. +1 −3 mysql/spec/spec_helper.rb
  54. BIN  mysql/vendor/cache/vcap_services_base-0.1.5.gem
  55. BIN  mysql/vendor/cache/vcap_services_base-0.1.6.gem
  56. +1 −1  neo4j/Gemfile.lock
  57. BIN  neo4j/vendor/cache/vcap_services_base-0.1.5.gem
  58. BIN  neo4j/vendor/cache/vcap_services_base-0.1.6.gem
  59. +1 −1  postgresql/Gemfile.lock
  60. +5 −3 postgresql/bin/postgresql_backup
  61. +1 −0  postgresql/bin/postgresql_node
  62. +1 −1  postgresql/config/postgresql_backup.yml
  63. +0 −7 postgresql/config/postgresql_gateway.yml
  64. +2 −3 postgresql/config/postgresql_node.yml
  65. +53 −125 postgresql/lib/postgresql_service/node.rb
  66. +4 −0 postgresql/lib/postgresql_service/provisioner.rb
  67. +0 −9 postgresql/lib/postgresql_service/storage_quota.rb
  68. +46 −231 postgresql/spec/postgresql_node_spec.rb
  69. +7 −7 postgresql/spec/postgresql_provisioner_spec.rb
  70. +1 −3 postgresql/spec/spec_helper.rb
  71. BIN  postgresql/vendor/cache/vcap_services_base-0.1.5.gem
  72. BIN  postgresql/vendor/cache/vcap_services_base-0.1.6.gem
  73. +1 −1  redis/Gemfile.lock
  74. +8 −12 redis/bin/redis_backup
  75. +1 −0  redis/bin/redis_node
  76. +1 −6 redis/config/redis_gateway.yml
  77. +2 −3 redis/config/redis_node.yml
  78. +1 −1  redis/config/redis_worker.yml
  79. +42 −30 redis/lib/redis_service/redis_node.rb
  80. +4 −0 redis/lib/redis_service/redis_provisioner.rb
  81. +59 −25 redis/spec/node_spec.rb
  82. +3 −11 redis/spec/provisioner_spec.rb
  83. +7 −60 redis/spec/spec_helper.rb
  84. BIN  redis/vendor/cache/vcap_services_base-0.1.5.gem
  85. BIN  redis/vendor/cache/vcap_services_base-0.1.6.gem
  86. +1 −1  service_broker/Gemfile.lock
  87. BIN  service_broker/vendor/cache/vcap_services_base-0.1.5.gem
  88. BIN  service_broker/vendor/cache/vcap_services_base-0.1.6.gem
View
2  atmos/Gemfile.lock
@@ -124,7 +124,7 @@ GEM
thin (~> 1.3.1)
yajl-ruby (~> 0.8.3)
vcap_logging (0.1.3)
- vcap_services_base (0.1.6)
+ vcap_services_base (0.1.5)
curb (~> 0.7.16)
datamapper (~> 1.1.0)
do_sqlite3 (~> 0.10.3)
View
BIN  atmos/vendor/cache/vcap_services_base-0.1.5.gem
Binary file not shown
View
BIN  atmos/vendor/cache/vcap_services_base-0.1.6.gem
Binary file not shown
View
4 base/Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- vcap_services_base (0.1.6)
+ vcap_services_base (0.1.5)
curb (~> 0.7.16)
datamapper (~> 1.1.0)
do_sqlite3 (~> 0.10.3)
@@ -130,7 +130,7 @@ GEM
uuid (2.3.4)
macaddr (~> 1.0)
uuidtools (2.1.2)
- vcap_common (1.0.6)
+ vcap_common (1.0.4)
eventmachine (~> 0.12.11.cloudfoundry.3)
logging (>= 1.5.0)
nats (~> 0.4.22.beta.4)
View
2  base/lib/base/asynchronous_service_gateway.rb
@@ -544,7 +544,7 @@ def send_heartbeat
req = create_http_request(
:head => @cc_req_hdrs,
- :body => @svc_json
+ :body => @svc_json,
)
http = EM::HttpRequest.new(@offering_uri).post(req)
View
8 base/lib/base/backup.rb
@@ -187,12 +187,8 @@ def run
return false
end
else
- begin
- # child process
- exec(@cmd)
- rescue => e
- exit!
- end
+ # child process
+ exec(@cmd)
end
end
View
36 base/lib/base/base.rb
@@ -41,26 +41,26 @@ def initialize(options)
@logger.error("Exiting due to NATS error: #{e}")
exit
end
- @node_nats = NATS.connect(:uri => options[:mbus]) do
- status_port = status_user = status_password = nil
- if not options[:status].nil?
- status_port = options[:status][:port]
- status_user = options[:status][:user]
- status_password = options[:status][:password]
- end
-
- VCAP::Component.register(
- :nats => @node_nats,
- :type => service_description,
- :host => @local_ip,
- :index => options[:index] || 0,
- :config => options,
- :port => status_port,
- :user => status_user,
- :password => status_password
- )
+ @node_nats = NATS.connect(:uri => options[:mbus]) {
on_connect_node
+ }
+ status_port = status_user = status_password = nil
+ if not options[:status].nil?
+ status_port = options[:status][:port]
+ status_user = options[:status][:user]
+ status_password = options[:status][:password]
end
+
+ VCAP::Component.register(
+ :nats => @node_nats,
+ :type => service_description,
+ :host => @local_ip,
+ :index => options[:index] || 0,
+ :config => options,
+ :port => status_port,
+ :user => status_user,
+ :password => status_password
+ )
else
@logger.info("NATS is disabled")
end
View
5 base/lib/base/gateway.rb
@@ -93,8 +93,7 @@ def start
:allow_over_provisioning => @config[:allow_over_provisioning],
:max_nats_payload => @config[:max_nats_payload],
:additional_options => additional_options,
- :status => @config[:status],
- :plan_management => @config[:plan_management]
+ :status => @config[:status]
)
sg = async_gateway_class.new(
:proxy => @config[:proxy],
@@ -106,7 +105,7 @@ def start
:cloud_controller_uri => cloud_controller_uri,
:check_orphan_interval => @config[:check_orphan_interval],
:double_check_orphan_interval => @config[:double_check_orphan_interval],
- :api_extensions => @config[:api_extensions]
+ :api_extensions => @config[:api_extensions],
)
Thin::Server.start(@config[:host], @config[:port], sg)
end
View
107 base/lib/base/node.rb
@@ -13,10 +13,6 @@ class VCAP::Services::Base::Node < VCAP::Services::Base::Base
def initialize(options)
super(options)
@node_id = options[:node_id]
- @plan = options[:plan]
- @capacity = options[:capacity]
- @max_capacity = @capacity
- @capacity_lock = Mutex.new
@migration_nfs = options[:migration_nfs]
z_interval = options[:z_interval] || 30
@@ -36,19 +32,45 @@ def flavor
def on_connect_node
@logger.debug("#{service_description}: Connected to node mbus")
-
- %w[provision unprovision bind unbind restore disable_instance
- enable_instance import_instance cleanup_nfs purge_orphan
- ].each do |op|
- eval %[@node_nats.subscribe("#{service_name}.#{op}.#{@node_id}") { |msg, reply| EM.defer{ on_#{op}(msg, reply) } }]
- end
- %w[discover check_orphan].each do |op|
- eval %[@node_nats.subscribe("#{service_name}.#{op}") { |msg, reply| EM.defer{ on_#{op}(msg, reply) } }]
- end
-
+ @node_nats.subscribe("#{service_name}.provision.#{@node_id}") { |msg, reply|
+ EM.defer { on_provision(msg, reply) }
+ }
+ @node_nats.subscribe("#{service_name}.unprovision.#{@node_id}") { |msg, reply|
+ EM.defer { on_unprovision(msg, reply) }
+ }
+ @node_nats.subscribe("#{service_name}.bind.#{@node_id}") { |msg, reply|
+ EM.defer { on_bind(msg, reply) }
+ }
+ @node_nats.subscribe("#{service_name}.unbind.#{@node_id}") { |msg, reply|
+ EM.defer { on_unbind(msg, reply) }
+ }
+ @node_nats.subscribe("#{service_name}.restore.#{@node_id}") { |msg, reply|
+ EM.defer { on_restore(msg, reply) }
+ }
+ @node_nats.subscribe("#{service_name}.discover") { |_, reply|
+ on_discover(reply)
+ }
+ # rebalance channels
+ @node_nats.subscribe("#{service_name}.disable_instance.#{@node_id}") { |msg, reply|
+ on_disable_instance(msg, reply)
+ }
+ @node_nats.subscribe("#{service_name}.enable_instance.#{@node_id}") { |msg, reply|
+ on_enable_instance(msg, reply)
+ }
+ @node_nats.subscribe("#{service_name}.import_instance.#{@node_id}") { |msg, reply|
+ on_import_instance(msg, reply)
+ }
+ @node_nats.subscribe("#{service_name}.cleanup_nfs.#{@node_id}") { |msg, reply|
+ on_cleanup_nfs(msg, reply)
+ }
+ #Orphan
+ @node_nats.subscribe("#{service_name}.check_orphan") { |msg| EM.defer { on_check_orphan(msg) } }
+ @node_nats.subscribe("#{service_name}.purge_orphan.#{@node_id}") { |msg| EM.defer { on_purge_orphan(msg) } }
pre_send_announcement
send_node_announcement
- EM.add_periodic_timer(30) { send_node_announcement }
+ EM.add_periodic_timer(30) {
+ send_node_announcement
+ }
end
def on_provision(msg, reply)
@@ -60,11 +82,10 @@ def on_provision(msg, reply)
credential = provision(plan, credentials)
credential['node_id'] = @node_id
response.credentials = credential
- @capacity_lock.synchronize{ @capacity -= capacity_unit }
@logger.debug("#{service_description}: Successfully provisioned service for request #{msg}: #{response.inspect}")
publish(reply, encode_success(response))
rescue => e
- @logger.warn("Exception at on_provision #{e}")
+ @logger.warn(e)
publish(reply, encode_failure(response, e))
end
@@ -77,12 +98,11 @@ def on_unprovision(msg, reply)
result = unprovision(name, bindings)
if result
publish(reply, encode_success(response))
- @capacity_lock.synchronize{ @capacity += capacity_unit }
else
publish(reply, encode_failure(response))
end
rescue => e
- @logger.warn("Exception at on_unprovision #{e}")
+ @logger.warn(e)
publish(reply, encode_failure(response, e))
end
@@ -96,7 +116,7 @@ def on_bind(msg, reply)
response.credentials = bind(name, bind_opts, credentials)
publish(reply, encode_success(response))
rescue => e
- @logger.warn("Exception at on_bind #{e}")
+ @logger.warn(e)
publish(reply, encode_failure(response, e))
end
@@ -111,7 +131,7 @@ def on_unbind(msg, reply)
publish(reply, encode_failure(response))
end
rescue => e
- @logger.warn("Exception at on_unbind #{e}")
+ @logger.warn(e)
publish(reply, encode_failure(response, e))
end
@@ -128,7 +148,7 @@ def on_restore(msg, reply)
publish(reply, encode_failure(response))
end
rescue => e
- @logger.warn("Exception at on_restore #{e}")
+ @logger.warn(e)
publish(reply, encode_failure(response, e))
end
@@ -144,7 +164,7 @@ def on_disable_instance(msg, reply)
result = dump_instance(prov_cred, binding_creds, file_path) if result
publish(reply, Yajl::Encoder.encode(result))
rescue => e
- @logger.warn("Exception at on_disable_instance #{e}")
+ @logger.warn(e)
end
# enable instance and send updated credentials back
@@ -159,7 +179,7 @@ def on_enable_instance(msg, reply)
result = [prov_cred, binding_creds_hash]
publish(reply, Yajl::Encoder.encode(result))
rescue => e
- @logger.warn("Exception at on_enable_instance #{e}")
+ @logger.warn(e)
end
# Cleanup nfs folder which contains migration data
@@ -171,11 +191,11 @@ def on_cleanup_nfs(msg, reply)
FileUtils.rm_rf(get_migration_folder(instance))
publish(reply, Yajl::Encoder.encode(true))
rescue => e
- @logger.warn("Exception at on_cleanup_nfs #{e}")
+ @logger.warn(e)
end
# Send all handles to gateway to check orphan
- def on_check_orphan(msg, reply)
+ def on_check_orphan(msg)
@logger.debug("#{service_description}: Request to check orphan")
live_ins_list = all_instances_list
live_bind_list = all_bindings_list
@@ -189,15 +209,15 @@ def on_check_orphan(msg, reply)
publish("#{service_name}.node_handles", request.encode)
end
rescue => e
- @logger.warn("Exception at on_check_orphan #{e}")
+ @logger.warn(e)
end
- def on_purge_orphan(msg, reply)
+ def on_purge_orphan(msg)
@logger.debug("#{service_description}: Request to purge orphan" )
request = PurgeOrphanRequest.decode(msg)
purge_orphan(request.orphan_ins_list,request.orphan_binding_list)
rescue => e
- @logger.warn("Exception at on_purge_orphan #{e}")
+ @logger.warn(e)
end
def purge_orphan(oi_list,ob_list)
@@ -251,32 +271,27 @@ def on_import_instance(msg, reply)
result = import_instance(prov_cred, binding_creds_hash, file_path, plan)
publish(reply, Yajl::Encoder.encode(result))
rescue => e
- @logger.warn("Exception at on_import_instance #{e}")
+ @logger.warn(e)
end
- def on_discover(msg, reply)
- send_node_announcement(msg, reply)
+ def on_discover(reply)
+ send_node_announcement(reply)
end
def pre_send_announcement
end
- def send_node_announcement(msg=nil, reply=nil)
+ def send_node_announcement(reply = nil)
unless node_ready?
@logger.debug("#{service_description}: Not ready to send announcement")
return
end
@logger.debug("#{service_description}: Sending announcement for #{reply || "everyone"}")
- req = nil
- req = Yajl::Parser.parse(msg) if msg
- if !req || req["plan"] == @plan
- a = announcement
- a[:id] = @node_id
- a[:plan] = @plan
- publish(reply || "#{service_name}.announce", Yajl::Encoder.encode(a))
- end
- rescue => e
- @logger.warn("Exception at send_node_announcement #{e}")
+ a = announcement
+ a[:id] = @node_id
+ publish(reply || "#{service_name}.announce", Yajl::Encoder.encode(a))
+ rescue
+ @logger.warn(e)
end
def node_ready?()
@@ -301,12 +316,6 @@ def healthz_details()
}
end
- def capacity_unit
- # subclasses could overwrite this method to re-define
- # the capacity unit decreased/increased by provision/unprovision
- 1
- end
-
# Helper
def encode_success(response)
response.success = true
View
4 base/lib/base/node_bin.rb
@@ -50,8 +50,6 @@ def start
options = {
:index => parse_property(config, "index", Integer, :optional => true),
- :plan => parse_property(config, "plan", String, :optional => true, :default => "free"),
- :capacity => parse_property(config, "capacity", Integer, :optional => true, :default => 200),
:base_dir => parse_property(config, "base_dir", String),
:ip_route => parse_property(config, "ip_route", String, :optional => true),
:node_id => parse_property(config, "node_id", String),
@@ -101,7 +99,7 @@ def parse_property(hash, key, type, options = {})
obj = hash[key]
if obj.nil?
raise "Missing required option: #{key}" unless options[:optional]
- options[:default]
+ nil
elsif type == Range
raise "Invalid Range object: #{obj}" unless obj.kind_of?(Hash)
first, last = obj["first"], obj["last"]
View
98 base/lib/base/provisioner.rb
@@ -24,10 +24,10 @@ def initialize(options)
super(options)
@version = options[:version]
@node_timeout = options[:node_timeout]
+ @allow_over_provisioning = options[:allow_over_provisioning]
@nodes = {}
@prov_svcs = {}
@handles_for_check_orphan = {}
- @plan_mgmt = options[:plan_management] && options[:plan_management][:plans] || {}
reset_orphan_stat
z_interval = options[:z_interval] || 30
@@ -42,6 +42,7 @@ def initialize(options)
end
EM.add_periodic_timer(60) { process_nodes }
+
end
def create_redis(opt)
@@ -85,7 +86,7 @@ def find_all_bindings(name)
end
def process_nodes
- @nodes.delete_if {|_, node| Time.now.to_i - node["time"] > 300}
+ @nodes.delete_if {|_, timestamp| Time.now.to_i - timestamp > 300}
end
def pre_send_announcement
@@ -93,22 +94,24 @@ def pre_send_announcement
def on_connect_node
@logger.debug("[#{service_description}] Connected to node mbus..")
- %w[announce node_handles handles update_service_handle].each do |op|
- eval %[@node_nats.subscribe("#{service_name}.#{op}") { |msg, reply| on_#{op}(msg, reply) }]
- end
-
+ @node_nats.subscribe("#{service_name}.announce") { |msg|
+ on_node_announce(msg)
+ }
+ @node_nats.subscribe("#{service_name}.node_handles") { |msg| on_node_handles(msg) }
+ @node_nats.subscribe("#{service_name}.handles") {|msg, reply| on_query_handles(msg, reply) }
+ @node_nats.subscribe("#{service_name}.update_service_handle") {|msg, reply| on_update_service_handle(msg, reply) }
pre_send_announcement()
@node_nats.publish("#{service_name}.discover")
end
- def on_announce(msg, reply=nil)
+ def on_node_announce(msg)
@logger.debug("[#{service_description}] Received node announcement: #{msg}")
announce_message = Yajl::Parser.parse(msg)
- @nodes[announce_message["id"]] = announce_message.merge({"time" => Time.now.to_i}) if announce_message["id"]
+ @nodes[announce_message["id"]] = Time.now.to_i if announce_message["id"]
end
# query all handles for a given instance
- def on_handles(instance, reply)
+ def on_query_handles(instance, reply)
@logger.debug("[#{service_description}] Receive query handles request for instance: #{instance}")
if instance.empty?
res = Yajl::Encoder.encode(@prov_svcs)
@@ -119,7 +122,7 @@ def on_handles(instance, reply)
@node_nats.publish(reply, res)
end
- def on_node_handles(msg, reply)
+ def on_node_handles(msg)
@logger.debug("[#{service_description}] Received node handles")
response = NodeHandlesReport.decode(msg)
nid = response.node_id
@@ -139,7 +142,7 @@ def on_node_handles(msg, reply)
ob_count = @staging_orphan_bindings.values.reduce(0) { |m, v| m += v.count }
@logger.debug("Staging Orphans: Instances: #{oi_count}; Bindings: #{ob_count}")
rescue => e
- @logger.warn("Exception at on_node_handles #{e}")
+ @logger.warn(e)
end
def check_orphan(handles, &blk)
@@ -149,7 +152,7 @@ def check_orphan(handles, &blk)
@node_nats.publish("#{service_name}.check_orphan","Send Me Handles")
blk.call(success)
rescue => e
- @logger.warn("Exception at check_orphan #{e}")
+ @logger.warn(e)
if e.instance_of? ServiceError
blk.call(failure(e))
else
@@ -179,7 +182,7 @@ def double_check_orphan(handles)
ob_count = @final_orphan_bindings.values.reduce(0) { |m, v| m += v.count }
@logger.debug("Final Orphans: Instances: #{oi_count}; Bindings: #{ob_count}")
rescue => e
- @logger.warn("Exception at double_check_orphan #{e}")
+ @logger.warn(e)
end
def purge_orphan(orphan_ins_hash,orphan_bind_hash, &blk)
@@ -206,7 +209,7 @@ def purge_orphan(orphan_ins_hash,orphan_bind_hash, &blk)
end
blk.call(success)
rescue => e
- @logger.warn("Exception at purge_orphan #{e}")
+ @logger.warn(e)
if e.instance_of? ServiceError
blk.call(failure(e))
else
@@ -257,7 +260,7 @@ def unprovision_service(instance_id, &blk)
if e.instance_of? ServiceError
blk.call(failure(e))
else
- @logger.warn("Exception at unprovision_service #{e}")
+ @logger.warn(e)
blk.call(internal_fail)
end
end
@@ -266,38 +269,28 @@ def unprovision_service(instance_id, &blk)
def provision_service(request, prov_handle=nil, &blk)
@logger.debug("[#{service_description}] Attempting to provision instance (request=#{request.extract})")
subscription = nil
- plan = request.plan || "free"
- plan_nodes = @nodes.select{ |_, node| node["plan"] == plan }
- @logger.debug("Going to query nodes #{plan_nodes}")
- if plan_nodes.count > 0
- barrier = VCAP::Services::Base::Barrier.new(:timeout => BARRIER_TIMEOUT, :callbacks => plan_nodes.length) do |responses|
- @logger.debug("[#{service_description}] Found the following nodes: #{responses.inspect}")
- @node_nats.unsubscribe(subscription)
- provision_node(request, responses, prov_handle, blk) unless responses.empty?
+ barrier = VCAP::Services::Base::Barrier.new(:timeout => BARRIER_TIMEOUT, :callbacks => @nodes.length) do |responses|
+ @logger.debug("[#{service_description}] Found the following nodes: #{responses.inspect}")
+ @node_nats.unsubscribe(subscription)
+ unless responses.empty?
+ provision_node(request, responses, prov_handle, blk)
end
- req = Yajl::Encoder.encode({"plan" => plan})
- subscription = @node_nats.request("#{service_name}.discover", req) {|msg| barrier.call(msg)}
- else
- @logger.error("Unknown plan(#{plan})")
- blk.call(failure(ServiceError.new(ServiceError::UNKNOWN_PLAN, plan)))
end
+ subscription = @node_nats.request("#{service_name}.discover") {|msg| barrier.call(msg)}
rescue => e
- @logger.warn("Exception at provision_service #{e}")
+ @logger.warn(e)
blk.call(internal_fail)
end
def provision_node(request, node_msgs, prov_handle, blk)
@logger.debug("[#{service_description}] Provisioning node (request=#{request.extract}, nnodes=#{node_msgs.length})")
- plan = request.plan
nodes = node_msgs.map { |msg| Yajl::Parser.parse(msg.first) }
- allow_over_provisioning = @plan_mgmt[plan.to_sym] && @plan_mgmt[plan.to_sym][:allow_over_provisioning] || false
- @logger.debug("Pick best node from: #{nodes}")
best_node = nodes.max_by { |node| node_score(node) }
- if best_node && ( allow_over_provisioning || node_score(best_node) > 0 )
+ if best_node && ( @allow_over_provisioning || node_score(best_node) > 0 )
best_node = best_node["id"]
@logger.debug("[#{service_description}] Provisioning on #{best_node}")
prov_req = ProvisionRequest.new
- prov_req.plan = plan
+ prov_req.plan = request.plan
# use old credentials to provision a service if provided.
prov_req.credentials = prov_handle["credentials"] if prov_handle
subscription = nil
@@ -391,7 +384,7 @@ def bind_instance(instance_id, binding_options, bind_handle=nil, &blk)
if e.instance_of? ServiceError
blk.call(failure(e))
else
- @logger.warn("Exception at bind_instance #{e}")
+ @logger.warn(e)
blk.call(internal_fail)
end
end
@@ -436,7 +429,7 @@ def unbind_instance(instance_id, handle_id, binding_options, &blk)
if e.instance_of? ServiceError
blk.call(failure(e))
else
- @logger.warn("Exception at unbind_instance #{e}")
+ @logger.warn(e)
blk.call(internal_fail)
end
end
@@ -478,7 +471,7 @@ def restore_instance(instance_id, backup_path, &blk)
if e.instance_of? ServiceError
blk.call(failure(e))
else
- @logger.warn("Exception at restore_instance #{e}")
+ @logger.warn(e)
blk.call(internal_fail)
end
end
@@ -563,7 +556,7 @@ def recover(instance_id, backup_path, handles, &blk)
end
end
rescue => e
- @logger.warn("Exception at recover #{e}")
+ @logger.warn(e)
blk.call(internal_fail)
end
@@ -728,28 +721,15 @@ def varz_details()
end
end
- plan_mgmt = []
- @plan_mgmt.each do |plan, v|
- plan_nodes = @nodes.select { |_, node| node["plan"] == plan }
- score = plan_nodes.inject { |sum, node| sum + node_score(node) }
- plan_mgmt << {
- :plan => plan,
- :score => score,
- :low_water => v[:low_water],
- :high_water => v[:high_water]
- }
- end
-
varz = {
:nodes => @nodes,
:prov_svcs => svcs,
:orphan_instances => orphan_instances,
- :orphan_bindings => orphan_bindings,
- :plans => plan_mgmt
+ :orphan_bindings => orphan_bindings
}
return varz
rescue => e
- @logger.warn("Exception at varz_details #{e}")
+ @logger.warn(e)
end
def healthz_details()
@@ -786,7 +766,7 @@ def wrap_error(service_msg)
# handle request exception
def handle_error(e, &blk)
- @logger.warn("Exception at handle_error #{e}")
+ @logger.warn(e)
if e.instance_of? ServiceError
blk.call(failure(e))
else
@@ -803,16 +783,14 @@ def find_node(instance_id)
node_id
end
+ # Service Provisioner subclasses must implement the following
+ # methods
+
# node_score(node) -> number. this base class provisions on the
# "best" node (lowest load, most free capacity, etc). this method
# should return a number; higher scores represent "better" nodes;
# negative/zero scores mean that a node should be ignored
- def node_score(node)
- node['available_capacity'] if node
- end
-
- # Service Provisioner subclasses must implement the following
- # methods
+ abstract :node_score
# service_name() --> string
# (inhereted from VCAP::Services::Base::Base)
View
1  base/lib/base/service_error.rb
@@ -28,7 +28,6 @@ class ServiceError < StandardError
INVALID_CONTENT = [30000, HTTP_BAD_REQUEST, 'Invalid Content-Type']
MALFORMATTED_REQ = [30001, HTTP_BAD_REQUEST, 'Malformatted request']
UNKNOWN_LABEL = [30002, HTTP_BAD_REQUEST, 'Unknown label']
- UNKNOWN_PLAN = [30003, HTTP_BAD_REQUEST, 'Unknown plan %s']
# 30100 - 30199 401 Unauthorized
NOT_AUTHORIZED = [30100, HTTP_NOT_AUTHORIZED, 'Not authorized']
View
2  base/lib/base/version.rb
@@ -1,7 +1,7 @@
module VCAP
module Services
module Base
- VERSION = "0.1.6"
+ VERSION = "0.1.5"
end
end
end
View
24 base/spec/async_gw_spec.rb
@@ -1,7 +1,29 @@
+
# Copyright (c) 2009-2011 VMware, Inc.
-require 'helper/spec_helper'
+require 'spec_helper'
+
require 'eventmachine'
+module Do
+
+ # the tests below do various things then wait for something to
+ # happen -- so there's a potential for a race condition. to
+ # minimize the risk of the race condition, increase this value (0.1
+ # seems to work about 90% of the time); but to make the tests run
+ # faster, decrease it
+ STEP_DELAY = 0.5
+
+ def self.at(index, &blk)
+ EM.add_timer(index*STEP_DELAY) { blk.call if blk }
+ end
+
+ # Respect the real seconds while doing concurrent testing
+ def self.sec(index, &blk)
+ EM.add_timer(index) { blk.call if blk }
+ end
+
+end
+
describe AsyncGatewayTests do
it "should invoke check_orphan in check_orphan_interval time" do
View
25 base/spec/backup_spec.rb
@@ -1,5 +1,6 @@
# Copyright (c) 2009-2011 VMware, Inc.
-require 'helper/spec_helper'
+require 'spec_helper'
+
require 'eventmachine'
describe BackupTest do
@@ -17,26 +18,4 @@
end
end
end
-
- it "should return true if execution suceeds" do
- errback_called = false
- on_err = Proc.new do |cmd, code, msg|
- errback_called = true
- end
- res = CMDHandle.execute("echo", 1, on_err)
- res.should be_true
- errback_called.should be_false
- end
-
- it "should handle errors if the executable is not found or execution fails" do
- ["cmdnotfound", "ls filenotfound"].each do |cmd|
- errback_called = false
- on_err = Proc.new do |cmd, code, msg|
- errback_called = true
- end
- res = CMDHandle.execute(cmd, 1, on_err)
- res.should be_false
- errback_called.should be_true
- end
- end
end
View
674 base/spec/base_spec.rb
@@ -1,7 +1,28 @@
# Copyright (c) 2009-2011 VMware, Inc.
-require 'helper/spec_helper'
+require 'spec_helper'
+
require 'eventmachine'
+module Do
+
+ # the tests below do various things then wait for something to
+ # happen -- so there's a potential for a race condition. to
+ # minimize the risk of the race condition, increase this value (0.1
+ # seems to work about 90% of the time); but to make the tests run
+ # faster, decrease it
+ STEP_DELAY = 0.5
+
+ def self.at(index, &blk)
+ EM.add_timer(index*STEP_DELAY) { blk.call if blk }
+ end
+
+ # Respect the real seconds while doing concurrent testing
+ def self.sec(index, &blk)
+ EM.add_timer(index) { blk.call if blk }
+ end
+
+end
+
describe BaseTests do
it "should connect to node message bus" do
@@ -15,3 +36,654 @@
end
+describe NodeTests do
+
+ it "should announce on startup" do
+ node = nil
+ provisioner = nil
+ EM.run do
+ # start provisioner then node
+ Do.at(0) { provisioner = NodeTests.create_provisioner }
+ Do.at(1) { node = NodeTests.create_node }
+ Do.at(2) { EM.stop }
+ end
+ provisioner.got_announcement.should be_true
+ end
+
+ it "should call varz/healthz" do
+ node = nil
+ provisioner = nil
+ EM.run do
+ # start provisioner then node
+ Do.at(0) { provisioner = NodeTests.create_provisioner }
+ Do.at(1) { node = NodeTests.create_node }
+ Do.at(12) { EM.stop }
+ end
+ node.varz_invoked.should be_true
+ node.healthz_invoked.should be_true
+ end
+
+ it "should announce on request" do
+ node = nil
+ provisioner = nil
+ EM.run do
+ # start node then provisioner
+ Do.at(0) { node = NodeTests.create_node }
+ Do.at(1) { provisioner = NodeTests.create_provisioner }
+ Do.at(2) { EM.stop }
+ end
+ node.announcement_invoked.should be_true
+ provisioner.got_announcement.should be_true
+ end
+
+ it "should not announce if not ready" do
+ node = nil
+ provisioner = nil
+ EM.run do
+ # start provisioner then node
+ Do.at(0) { node = NodeTests.create_node; node.set_ready(false) }
+ Do.at(1) { provisioner = NodeTests.create_provisioner }
+ Do.at(2) { EM.stop }
+ end
+ provisioner.got_announcement.should be_false
+ end
+
+ it "should support concurrent provision" do
+ node = nil
+ provisioner = nil
+ EM.run do
+ # start node then provisioner
+ Do.sec(0) { node = NodeTests.create_node }
+ Do.sec(1) { provisioner = NodeTests.create_provisioner }
+ # Start 5 concurrent provision requests, each of which takes 5 seconds to finish
+ # Non-concurrent provision handler won't finish in 10 seconds
+ Do.sec(2) { 5.times { provisioner.send_provision_request } }
+ Do.sec(20) { EM.stop }
+ end
+ node.provision_invoked.should be_true
+ node.provision_times.should == 5
+ provisioner.got_provision_response.should be_true
+ end
+
+ it "should handle error in node provision" do
+ node = nil
+ provisioner = nil
+ EM.run do
+ # start node then provisioner
+ Do.sec(0) { node = NodeTests.create_error_node }
+ Do.sec(1) { provisioner = NodeTests.create_error_provisioner}
+ Do.sec(2) { provisioner.send_provision_request }
+ Do.sec(20) { EM.stop }
+ end
+ node.provision_invoked.should be_true
+ provisioner.response.should =~ /Service unavailable/
+ end
+
+ it "should support unprovision" do
+ node = nil
+ provisioner = nil
+ EM.run do
+ # start node then provisioner
+ Do.at(0) { node = NodeTests.create_node }
+ Do.at(1) { provisioner = NodeTests.create_provisioner }
+ Do.at(2) { provisioner.send_unprovision_request }
+ Do.at(20) { EM.stop }
+ end
+ node.unprovision_invoked.should be_true
+ end
+
+ it "should handle error in unprovision" do
+ node = nil
+ provisioner = nil
+ EM.run do
+ # start node then provisioner
+ Do.at(0) { node = NodeTests.create_error_node }
+ Do.at(1) { provisioner = NodeTests.create_error_provisioner }
+ Do.at(2) { provisioner.send_unprovision_request }
+ Do.at(20) { EM.stop }
+ end
+ node.unprovision_invoked.should be_true
+ provisioner.response.should =~ /Service unavailable/
+ end
+
+ it "should support bind" do
+ node = nil
+ provisioner = nil
+ EM.run do
+ # start node then provisioner
+ Do.at(0) { node = NodeTests.create_node }
+ Do.at(1) { provisioner = NodeTests.create_provisioner }
+ Do.at(2) { provisioner.send_bind_request }
+ Do.at(20) { EM.stop }
+ end
+ node.bind_invoked.should be_true
+ end
+
+ it "should handle error in bind" do
+ node = nil
+ provisioner = nil
+ EM.run do
+ # start node then provisioner
+ Do.at(0) { node = NodeTests.create_error_node }
+ Do.at(1) { provisioner = NodeTests.create_error_provisioner }
+ Do.at(2) { provisioner.send_bind_request }
+ Do.at(20) { EM.stop }
+ end
+ node.bind_invoked.should be_true
+ provisioner.response.should =~ /Service unavailable/
+ end
+
+ it "should support unbind" do
+ node = nil
+ provisioner = nil
+ EM.run do
+ # start node then provisioner
+ Do.at(0) { node = NodeTests.create_node }
+ Do.at(1) { provisioner = NodeTests.create_provisioner }
+ Do.at(2) { provisioner.send_unbind_request }
+ Do.at(20) { EM.stop }
+ end
+ node.unbind_invoked.should be_true
+ end
+
+ it "should handle error in unbind" do
+ node = nil
+ provisioner = nil
+ EM.run do
+ # start node then provisioner
+ Do.at(0) { node = NodeTests.create_error_node }
+ Do.at(1) { provisioner = NodeTests.create_error_provisioner }
+ Do.at(2) { provisioner.send_unbind_request }
+ Do.at(20) { EM.stop }
+ end
+ node.unbind_invoked.should be_true
+ provisioner.response.should =~ /Service unavailable/
+ end
+
+ it "should support restore" do
+ node = nil
+ provisioner = nil
+ EM.run do
+ # start node then provisioner
+ Do.at(0) { node = NodeTests.create_node }
+ Do.at(1) { provisioner = NodeTests.create_provisioner }
+ Do.at(2) { provisioner.send_restore_request }
+ Do.at(20) { EM.stop }
+ end
+ node.restore_invoked.should be_true
+ end
+
+ it "should handle error in restore" do
+ node = nil
+ provisioner = nil
+ EM.run do
+ # start node then provisioner
+ Do.at(0) { node = NodeTests.create_error_node }
+ Do.at(1) { provisioner = NodeTests.create_error_provisioner }
+ Do.at(2) { provisioner.send_restore_request }
+ Do.at(20) { EM.stop }
+ end
+ node.restore_invoked.should be_true
+ provisioner.response.should =~ /Service unavailable/
+ end
+
+ it "should support check_orphan when no handles" do
+ node = nil
+ provisioner = nil
+ EM.run do
+ # start node then provisioner
+ Do.at(0) { node = NodeTests.create_node}
+ Do.at(1) { provisioner = NodeTests.create_provisioner }
+ Do.at(2) { provisioner.send_check_orphan_request }
+ Do.at(5) { EM.stop }
+ end
+ provisioner.ins_hash[TEST_NODE_ID].count.should == 0
+ provisioner.bind_hash[TEST_NODE_ID].count.should == 0
+ end
+
+ it "should support check_orphan when node has massive instances" do
+ node = nil
+ provisioner = nil
+ EM.run do
+ # start node then provisioner
+ Do.at(0) { node = NodeTests.create_node(1024 * 128, 1024)}
+ Do.at(1) { provisioner = NodeTests.create_provisioner }
+ Do.at(2) { provisioner.send_check_orphan_request }
+ Do.at(30) { EM.stop }
+ end
+ provisioner.ins_hash[TEST_NODE_ID].count.should == 1024 * 128
+ provisioner.bind_hash[TEST_NODE_ID].count.should == 1024
+ end
+
+ it "should support check_orphan when node has massive bindings" do
+ node = nil
+ provisioner = nil
+ EM.run do
+ # start node then provisioner
+ Do.at(0) { node = NodeTests.create_node(1024, 1024 * 64)}
+ Do.at(1) { provisioner = NodeTests.create_provisioner }
+ Do.at(2) { provisioner.send_check_orphan_request }
+ Do.at(30) { EM.stop }
+ end
+ provisioner.ins_hash[TEST_NODE_ID].count.should == 1024
+ provisioner.bind_hash[TEST_NODE_ID].count.should == 1024 * 64
+ end
+
+ it "should support check_orphan when node has massive handles" do
+ node = nil
+ provisioner = nil
+ EM.run do
+ # start node then provisioner
+ Do.at(0) { node = NodeTests.create_node(1024 * 128, 1024 * 16)}
+ Do.at(1) { provisioner = NodeTests.create_provisioner }
+ Do.at(2) { provisioner.send_check_orphan_request }
+ Do.at(45) { EM.stop }
+ end
+ provisioner.ins_hash[TEST_NODE_ID].count.should == 1024 * 128
+ provisioner.bind_hash[TEST_NODE_ID].count.should == 1024 * 16
+ end
+
+ it "should support purge_orphan" do
+ node = nil
+ provisioner = nil
+ EM.run do
+ # start node then provisioner
+ Do.at(0) { node = NodeTests.create_node }
+ Do.at(1) { provisioner = NodeTests.create_provisioner }
+ Do.at(2) { provisioner.send_purge_orphan_request }
+ Do.at(5) { EM.stop }
+ end
+ node.unprovision_count.should == 2
+ node.unbind_count.should == 2
+ end
+end
+
+describe ProvisionerTests do
+
+ it "should autodiscover 1 node when started first" do
+ provisioner = nil
+ node = nil
+ # start provisioner, then node
+ EM.run do
+ Do.at(0) { provisioner = ProvisionerTests.create_provisioner }
+ Do.at(1) { node = ProvisionerTests.create_node(1) }
+ Do.at(2) { EM.stop }
+ end
+ provisioner.node_count.should == 1
+ end
+
+ it "should autodiscover 1 node when started second" do
+ provisioner = nil
+ node = nil
+ EM.run do
+ # start node, then provisioner
+ Do.at(0) { node = ProvisionerTests.create_node(1) }
+ Do.at(1) { provisioner = ProvisionerTests.create_provisioner }
+ Do.at(2) { EM.stop }
+ end
+ provisioner.node_count.should == 1
+ end
+
+ it "should autodiscover 3 nodes when started first" do
+ provisioner = nil
+ node1 = nil
+ node2 = nil
+ node3 = nil
+ # start provisioner, then nodes
+ EM.run do
+ Do.at(0) { provisioner = ProvisionerTests.create_provisioner }
+ Do.at(1) { node1 = ProvisionerTests.create_node(1) }
+ Do.at(2) { node2 = ProvisionerTests.create_node(2) }
+ Do.at(3) { node3 = ProvisionerTests.create_node(3) }
+ Do.at(4) { EM.stop }
+ end
+ provisioner.node_count.should == 3
+ end
+
+ it "should autodiscover 3 nodes when started second" do
+ provisioner = nil
+ node1 = nil
+ node2 = nil
+ node3 = nil
+ EM.run do
+ # start nodes, then provisioner
+ Do.at(0) { node1 = ProvisionerTests.create_node(1) }
+ Do.at(1) { node2 = ProvisionerTests.create_node(2) }
+ Do.at(2) { node3 = ProvisionerTests.create_node(3) }
+ Do.at(3) { provisioner = ProvisionerTests.create_provisioner }
+ Do.at(4) { EM.stop }
+ end
+ provisioner.node_count.should == 3
+ end
+
+ it "should support provision" do
+ provisioner = nil
+ gateway = nil
+ node = nil
+ EM.run do
+ Do.at(0) { provisioner = ProvisionerTests.create_provisioner }
+ Do.at(1) { gateway = ProvisionerTests.create_gateway(provisioner) }
+ Do.at(2) { node = ProvisionerTests.create_node(1) }
+ Do.at(3) { gateway.send_provision_request }
+ Do.at(4) { EM.stop }
+ end
+ gateway.got_provision_response.should be_true
+ end
+
+ it "should handle error in provision" do
+ provisioner = nil
+ gateway = nil
+ node = nil
+ EM.run do
+ Do.at(0) { provisioner = ProvisionerTests.create_provisioner }
+ Do.at(1) { gateway = ProvisionerTests.create_error_gateway(provisioner) }
+ Do.at(2) { node = ProvisionerTests.create_error_node(1) }
+ Do.at(3) { gateway.send_provision_request }
+ Do.at(4) { EM.stop }
+ end
+ node.got_provision_request.should be_true
+ gateway.provision_response.should be_false
+ gateway.error_msg['status'].should == 500
+ gateway.error_msg['msg']['code'].should == 30500
+ end
+
+ it "should pick the best node when provisioning" do
+ provisioner = nil
+ gateway = nil
+ node1 = nil
+ node2 = nil
+ EM.run do
+ Do.at(0) { provisioner = ProvisionerTests.create_provisioner }
+ Do.at(1) { gateway = ProvisionerTests.create_gateway(provisioner) }
+ Do.at(2) { node1 = ProvisionerTests.create_node(1, 1) }
+ Do.at(3) { node2 = ProvisionerTests.create_node(2, 2) }
+ Do.at(4) { gateway.send_provision_request }
+ Do.at(5) { EM.stop }
+ end
+ node1.got_provision_request.should be_false
+ node2.got_provision_request.should be_true
+ end
+
+ it "should support unprovision" do
+ provisioner = nil
+ gateway = nil
+ node = nil
+ EM.run do
+ Do.at(0) { provisioner = ProvisionerTests.create_provisioner }
+ Do.at(1) { gateway = ProvisionerTests.create_gateway(provisioner) }
+ Do.at(2) { node = ProvisionerTests.create_node(1) }
+ Do.at(3) { gateway.send_provision_request }
+ Do.at(4) { gateway.send_unprovision_request }
+ Do.at(5) { EM.stop }
+ end
+ node.got_unprovision_request.should be_true
+ end
+
+ it "should handle error in unprovision" do
+ provisioner = nil
+ gateway = nil
+ node = nil
+ EM.run do
+ Do.at(0) { provisioner = ProvisionerTests.create_provisioner }
+ Do.at(1) { gateway = ProvisionerTests.create_error_gateway(provisioner) }
+ Do.at(2) { node = ProvisionerTests.create_error_node(1) }
+ Do.at(3) { ProvisionerTests.setup_fake_instance(gateway, provisioner, node) }
+ Do.at(4) { gateway.send_unprovision_request }
+ Do.at(5) { EM.stop }
+ end
+ node.got_unprovision_request.should be_true
+ gateway.unprovision_response.should be_false
+ gateway.error_msg.should_not == nil
+ gateway.error_msg['status'].should == 500
+ gateway.error_msg['msg']['code'].should == 30500
+ end
+
+ it "should support bind" do
+ provisioner = nil
+ gateway = nil
+ node = nil
+ EM.run do
+ Do.at(0) { provisioner = ProvisionerTests.create_provisioner }
+ Do.at(1) { gateway = ProvisionerTests.create_gateway(provisioner) }
+ Do.at(2) { node = ProvisionerTests.create_node(1) }
+ Do.at(3) { gateway.send_provision_request }
+ Do.at(4) { gateway.send_bind_request }
+ Do.at(5) { EM.stop }
+ end
+ gateway.got_provision_response.should be_true
+ gateway.got_bind_response.should be_true
+ end
+
+ it "should handle error in bind" do
+ provisioner = nil
+ gateway = nil
+ node = nil
+ EM.run do
+ Do.at(0) { provisioner = ProvisionerTests.create_provisioner }
+ Do.at(1) { gateway = ProvisionerTests.create_error_gateway(provisioner) }
+ Do.at(2) { node = ProvisionerTests.create_error_node(1) }
+ Do.at(3) { ProvisionerTests.setup_fake_instance(gateway, provisioner, node) }
+ Do.at(4) { gateway.send_bind_request }
+ Do.at(5) { EM.stop }
+ end
+ node.got_bind_request.should be_true
+ gateway.bind_response.should be_false
+ gateway.error_msg['status'].should == 500
+ gateway.error_msg['msg']['code'].should == 30500
+ end
+
+ it "should handle error in unbind" do
+ provisioner = nil
+ gateway = nil
+ node = nil
+ EM.run do
+ Do.at(0) { provisioner = ProvisionerTests.create_provisioner }
+ Do.at(1) { gateway = ProvisionerTests.create_error_gateway(provisioner) }
+ Do.at(2) { node = ProvisionerTests.create_error_node(1) }
+ Do.at(3) {
+ ProvisionerTests.setup_fake_instance(gateway, provisioner, node)
+ bind_id = "fake_bind_id"
+ gateway.bind_id = bind_id
+ provisioner.prov_svcs[bind_id] = {:credentials => {'node_id' =>node.node_id }}
+ }
+ Do.at(5) { gateway.send_unbind_request }
+ Do.at(6) { EM.stop }
+ end
+ node.got_unbind_request.should be_true
+ gateway.unbind_response.should be_false
+ gateway.error_msg['status'].should == 500
+ gateway.error_msg['msg']['code'].should == 30500
+ end
+
+ it "should support restore" do
+ provisioner = nil
+ gateway = nil
+ node = nil
+ EM.run do
+ Do.at(0) { provisioner = ProvisionerTests.create_provisioner }
+ Do.at(1) { gateway = ProvisionerTests.create_gateway(provisioner) }
+ Do.at(2) { node = ProvisionerTests.create_node(1) }
+ Do.at(3) { gateway.send_provision_request }
+ Do.at(4) { gateway.send_restore_request }
+ Do.at(5) { EM.stop }
+ end
+ gateway.got_restore_response.should be_true
+ end
+
+ it "should handle error in restore" do
+ provisioner = nil
+ gateway = nil
+ node = nil
+ EM.run do
+ Do.at(0) { provisioner = ProvisionerTests.create_provisioner }
+ Do.at(1) { gateway = ProvisionerTests.create_error_gateway(provisioner) }
+ Do.at(2) { node = ProvisionerTests.create_error_node(1) }
+ Do.at(3) { ProvisionerTests.setup_fake_instance(gateway, provisioner, node) }
+ Do.at(4) { gateway.send_restore_request }
+ Do.at(5) { EM.stop }
+ end
+ node.got_restore_request.should be_true
+ gateway.error_msg['status'].should == 500
+ gateway.error_msg['msg']['code'].should == 30500
+ end
+
+ it "should support recover" do
+ provisioner = nil
+ gateway = nil
+ node = nil
+ EM.run do
+ Do.at(0) { provisioner = ProvisionerTests.create_provisioner }
+ Do.at(1) { gateway = ProvisionerTests.create_gateway(provisioner) }
+ Do.at(2) { node = ProvisionerTests.create_node(1) }
+ Do.at(3) { gateway.send_provision_request }
+ Do.at(4) { gateway.send_recover_request }
+ Do.at(10) { EM.stop }
+ end
+ gateway.got_recover_response.should be_true
+ end
+
+ it "should support varz" do
+ provisioner = nil
+ gateway = nil
+ node = nil
+ prov_svcs_before = nil
+ prov_svcs_after = nil
+ varz_invoked_before = nil
+ varz_invoked_after = nil
+ EM.run do
+ Do.at(0) { provisioner = ProvisionerTests.create_provisioner }
+ Do.at(1) { gateway = ProvisionerTests.create_gateway(provisioner) }
+ Do.at(2) { node = ProvisionerTests.create_node(1) }
+ Do.at(3) { gateway.send_provision_request }
+ Do.at(4) { gateway.send_bind_request }
+ Do.at(5) {
+ prov_svcs_before = Marshal.dump(provisioner.prov_svcs)
+ varz_invoked_before = provisioner.varz_invoked
+ }
+ # varz is invoked 5 seconds after provisioner is created
+ Do.at(11) {
+ prov_svcs_after = Marshal.dump(provisioner.prov_svcs)
+ varz_invoked_after = provisioner.varz_invoked
+ }
+ Do.at(12) { EM.stop }
+ end
+ varz_invoked_before.should be_false
+ varz_invoked_after.should be_true
+ prov_svcs_before.should == prov_svcs_after
+ end
+
+ it "should support healthz" do
+ provisioner = nil
+ gateway = nil
+ node = nil
+ prov_svcs_before = nil
+ prov_svcs_after = nil
+ healthz_invoked_before = nil
+ healthz_invoked_after = nil
+ EM.run do
+ Do.at(0) { provisioner = ProvisionerTests.create_provisioner }
+ Do.at(1) { gateway = ProvisionerTests.create_gateway(provisioner) }
+ Do.at(2) { node = ProvisionerTests.create_node(1) }
+ Do.at(3) { gateway.send_provision_request }
+ Do.at(4) { gateway.send_bind_request }
+ Do.at(5) {
+ prov_svcs_before = Marshal.dump(provisioner.prov_svcs)
+ healthz_invoked_before = provisioner.healthz_invoked
+ }
+ # healthz is invoked 5 seconds after provisioner is created
+ Do.at(11) {
+ prov_svcs_after = Marshal.dump(provisioner.prov_svcs)
+ healthz_invoked_after = provisioner.healthz_invoked
+ }
+ Do.at(12) { EM.stop }
+ end
+ healthz_invoked_before.should be_false
+ healthz_invoked_after.should be_true
+ prov_svcs_before.should == prov_svcs_after
+ end
+
+ it "should allow over provisioning when it is configured so" do
+ provisioner = nil
+ gateway = nil
+ node = nil
+ EM.run do
+ Do.at(0) { provisioner = ProvisionerTests.create_provisioner({:allow_over_provisioning => true}) }
+ Do.at(1) { gateway = ProvisionerTests.create_gateway(provisioner) }
+ Do.at(2) { node = ProvisionerTests.create_node(1, -1) }
+ Do.at(3) { gateway.send_provision_request }
+ Do.at(4) { EM.stop }
+ end
+ node.got_provision_request.should be_true
+ end
+
+ it "should not allow over provisioning when it is not configured so" do
+ provisioner = nil
+ gateway = nil
+ node = nil
+ EM.run do
+ Do.at(0) { provisioner = ProvisionerTests.create_provisioner({:allow_over_provisioning => false}) }
+ Do.at(1) { gateway = ProvisionerTests.create_gateway(provisioner) }
+ Do.at(2) { node = ProvisionerTests.create_node(1, -1) }
+ Do.at(3) { gateway.send_provision_request }
+ Do.at(4) { EM.stop }
+ end
+ node.got_provision_request.should be_false
+ end
+
+ it "should support check orphan" do
+ provisioner = nil
+ gateway = nil
+ node = nil
+ EM.run do
+ Do.at(0) { provisioner = ProvisionerTests.create_provisioner }
+ Do.at(1) { gateway = ProvisionerTests.create_gateway(provisioner) }
+ Do.at(2) { node = ProvisionerTests.create_node(2) }
+ Do.at(3) { node = ProvisionerTests.create_node(3) }
+ Do.at(4) { gateway.send_check_orphan_request }
+ Do.at(8) { gateway.send_double_check_orphan_request }
+ Do.at(10) { EM.stop }
+ end
+ provisioner.staging_orphan_instances["node-2"].count.should == 2
+ provisioner.staging_orphan_instances["node-3"].count.should == 2
+ provisioner.final_orphan_instances["node-2"].count.should == 1
+ provisioner.final_orphan_instances["node-3"].count.should == 2
+ provisioner.staging_orphan_bindings["node-2"].count.should == 1
+ provisioner.staging_orphan_bindings["node-3"].count.should == 2
+ provisioner.final_orphan_bindings["node-2"].count.should == 1
+ provisioner.final_orphan_bindings["node-3"].count.should == 2
+ end
+
+ it "should handle error in check orphan" do
+ provisioner = nil
+ gateway = nil
+ node = nil
+ EM.run do
+ Do.at(0) { provisioner = ProvisionerTests.create_provisioner }
+ Do.at(1) { gateway = ProvisionerTests.create_error_gateway(provisioner) }
+ Do.at(2) { node = ProvisionerTests.create_error_node(1) }
+ Do.at(3) { gateway.send_check_orphan_request }
+ Do.at(4) { EM.stop }
+ end
+ node.got_check_orphan_request.should be_true
+ provisioner.staging_orphan_instances["node-1"].should be_nil
+ provisioner.final_orphan_instances["node-1"].should be_nil
+ end
+
+ it "should support purging massive orphans" do
+ provisioner = nil
+ gateway = nil
+ node = nil
+ node2 = nil
+ EM.run do
+ Do.at(0) { provisioner = ProvisionerTests.create_provisioner }
+ Do.at(1) { gateway = ProvisionerTests.create_gateway(provisioner, 1024 * 128, 1024 * 16) }
+ Do.at(2) { node = ProvisionerTests.create_node(1) }
+ Do.at(4) { gateway.send_purge_orphan_request }
+ Do.at(60) { EM.stop }
+ end
+ node.got_purge_orphan_request.should be_true
+ gateway.got_purge_orphan_response.should be_true
+ node.purge_ins_list.count.should == 1024 * 128
+ node.purge_bind_list.count.should == 1024 * 16
+ end
+end
View
410 base/spec/helper/async_gw_spec_helper.rb
@@ -1,410 +0,0 @@
-require 'base/asynchronous_service_gateway'
-
-class AsyncGatewayTests
- CC_PORT = 34512
- GW_PORT = 34513
- NODE_TIMEOUT = 5
-
- def self.create_nice_gateway
- MockGateway.new(true)
- end
-
- def self.create_nasty_gateway
- MockGateway.new(false)
- end
-
- def self.create_check_orphan_gateway(nice, check_interval, double_check_interval)
- MockGateway.new(nice, nil, check_interval, double_check_interval)
- end
-
- def self.create_timeout_gateway(nice, timeout)
- MockGateway.new(nice, timeout)
- end
-
- def self.create_cloudcontroller
- MockCloudController.new
- end
-
- class MockGateway
- attr_accessor :provision_http_code
- attr_accessor :unprovision_http_code
- attr_accessor :bind_http_code
- attr_accessor :unbind_http_code
- attr_accessor :restore_http_code
- attr_accessor :recover_http_code
- attr_reader :purge_orphan_http_code
- attr_reader :check_orphan_http_code
-
- def initialize(nice, timeout=nil, check_interval=-1, double_check_interval=3)
- @token = '0xdeadbeef'
- @cc_head = {
- 'Content-Type' => 'application/json',
- 'X-VCAP-Service-Token' => @token,
- }
- @label = "service-1.0"
- if timeout
- # Nice timeout provisioner will finish the job in timeout,
- # while un-nice timeout provisioner won't.
- @sp = nice ?
- TimeoutProvisioner.new(timeout - 1) :
- TimeoutProvisioner.new(timeout + 1)
- else
- @sp = nice ? NiceProvisioner.new : NastyProvisioner.new
- end
- sg = VCAP::Services::AsynchronousServiceGateway.new(
- :service => {
- :label => @label,
- :name => 'service',
- :version => '1.0',
- :description => 'sample desc',
- :plans => ['free'],
- :tags => ['nosql']
- },
- :token => @token,
- :provisioner => @sp,
- :node_timeout => timeout || NODE_TIMEOUT,
- :cloud_controller_uri => "http://localhost:#{CC_PORT}",
- :check_orphan_interval => check_interval,
- :double_check_orphan_interval => double_check_interval
- )
- @server = Thin::Server.new('localhost', GW_PORT, sg)
- @provision_http_code = 0
- @unprovision_http_code = 0
- @bind_http_code = 0
- @unbind_http_code = 0
- @restore_http_code = 0
- @recover_http_code = 0
- @purge_orphan_http_code = 0
- @check_orphan_http_code = 0
- @last_service_id = nil
- @last_bind_id = nil
- end
-
- def start
- Thread.new { @server.start }
- end
-
- def stop
- @server.stop
- end
-
- def gen_req(body = nil)
- req = { :head => @cc_head }
- req[:body] = body if body
- req
- end
-
- def check_orphan_invoked
- @sp.check_orphan_invoked
- end
-
- def double_check_orphan_invoked
- @sp.double_check_orphan_invoked
- end
-
- def send_provision_request
- msg = VCAP::Services::Api::GatewayProvisionRequest.new(
- :label => @label,
- :name => 'service',
- :email => "foobar@abc.com",
- :plan => "free"
- ).encode
- http = EM::HttpRequest.new("http://localhost:#{GW_PORT}/gateway/v1/configurations").post(gen_req(msg))
- http.callback {
- @provision_http_code = http.response_header.status
- if @provision_http_code == 200
- res = VCAP::Services::Api::GatewayProvisionResponse.decode(http.response)
- @last_service_id = res.service_id
- end
- }
- http.errback {
- @provision_http_code = -1
- }
- end
-
- def send_unprovision_request(service_id = nil)
- service_id ||= @last_service_id
- http = EM::HttpRequest.new("http://localhost:#{GW_PORT}/gateway/v1/configurations/#{service_id}").delete(gen_req)
- http.callback {
- @unprovision_http_code = http.response_header.status
- }
- http.errback {
- @unprovision_http_code = -1
- }
- end
-
- def send_bind_request(service_id = nil)
- service_id ||= @last_service_id
- msg = VCAP::Services::Api::GatewayBindRequest.new(
- :service_id => service_id,
- :label => @label,
- :email => "foobar@abc.com",
- :binding_options => {}
- ).encode
- http = EM::HttpRequest.new("http://localhost:#{GW_PORT}/gateway/v1/configurations/#{service_id}/handles").post(gen_req(msg))
- http.callback {
- @bind_http_code = http.response_header.status
- if @bind_http_code == 200
- res = VCAP::Services::Api::GatewayBindResponse.decode(http.response)
- @last_bind_id = res.service_id
- end
- }
- http.errback {
- @bind_http_code = -1
- }
- end
-
- def send_unbind_request(service_id = nil, bind_id = nil)
- service_id ||= @last_service_id
- bind_id ||= @last_bind_id
- msg = Yajl::Encoder.encode({
- :service_id => service_id,
- :handle_id => bind_id,
- :binding_options => {}
- })
- http = EM::HttpRequest.new("http://localhost:#{GW_PORT}/gateway/v1/configurations/#{service_id}/handles/#{bind_id}").delete(gen_req(msg))
- http.callback {
- @unbind_http_code = http.response_header.status
- }
- http.errback {
- @unbind_http_code = -1
- }
- end
-
- def send_restore_request(service_id = nil)
- service_id ||= @last_service_id
- msg = Yajl::Encoder.encode({
- :instance_id => service_id,
- :backup_path => '/'
- })
- http = EM::HttpRequest.new("http://localhost:#{GW_PORT}/service/internal/v1/restore").post(gen_req(msg))
- http.callback {
- @restore_http_code = http.response_header.status
- }
- http.errback {
- @restore_http_code = -1
- }
- end
-
- def send_recover_request(service_id = nil)
- service_id ||= @last_service_id
- msg = Yajl::Encoder.encode({
- :instance_id => service_id,
- :backup_path => '/'
- })
- http = EM::HttpRequest.new("http://localhost:#{GW_PORT}/service/internal/v1/recover").post(gen_req(msg))
- http.callback {
- @recover_http_code = http.response_header.status
- }
- http.errback {
- @recover_http_code = -1
- }
- end
-
- def send_purge_orphan_request
- msg = Yajl::Encoder.encode({
- :orphan_instances => TEST_PURGE_INS_HASH,
- :orphan_bindings => TEST_PURGE_BIND_HASH
- })
- http = EM::HttpRequest.new("http://localhost:#{GW_PORT}/service/internal/v1/purge_orphan").delete(gen_req(msg))
- http.callback {
- @purge_orphan_http_code = http.response_header.status
- }
- http.errback {
- @purge_orphan_http_code = -1
- }
- end
- def send_check_orphan_request
- msg = Yajl::Encoder.encode({
- })
- http = EM::HttpRequest.new("http://localhost:#{GW_PORT}/service/internal/v1/check_orphan").post(gen_req(msg))
- http.callback {
- @check_orphan_http_code = http.response_header.status
- }
- http.errback {
- @check_orphan_http_code = -1
- }
- end
- end
-
- class MockCloudController
- def initialize
- @server = Thin::Server.new('localhost', CC_PORT, Handler.new)
- end
-
- def start
- Thread.new { @server.start }
- end
-
- def stop
- @server.stop if @server
- end
-
- class Handler < Sinatra::Base
- post "/services/v1/offerings" do
- "{}"
- end
-
- get "/services/v1/offerings/:label/handles" do
- Yajl::Encoder.encode({
- :handles => [{
- 'service_id' => MockProvisioner::SERV_ID,
- 'configuration' => {},
- 'credentials' => {}
- }]
- })
- end
-
- get "/services/v1/offerings/:label/handles/:id" do
- "{}"
- end
- end
- end
-
- class MockProvisioner
- SERV_ID = "service_id"
- BIND_ID = "bind_id"
-
- include VCAP::Services::Base::Error
-
- attr_accessor :got_provision_request
- attr_accessor :got_unprovision_request
- attr_accessor :got_bind_request
- attr_accessor :got_unbind_request
- attr_accessor :got_restore_request
- attr_accessor :got_recover_request
- attr_reader :purge_orphan_invoked
- attr_reader :check_orphan_invoked
- attr_reader :double_check_orphan_invoked
-
- def initialize
- @got_provision_request = false
- @got_unprovision_request = false
- @got_bind_request = false
- @got_unbind_request = false
- @got_restore_request = false
- @got_recover_request = false
- @purge_orphan_invoked = false
- @check_orphan_invoked = false
- @double_check_orphan_invoked = false
- end
-
- def register_update_handle_callback
- # Do nothing
- end
-
- def update_handles(handles)
- # Do nothing
- end
-
- end
-
- class NiceProvisioner < MockProvisioner
- def provision_service(request, prov_handle=nil, &blk)
- @got_provision_request = true
- blk.call(success({:data => {}, :service_id => SERV_ID, :credentials => {}}))
- end
-
- def unprovision_service(instance_id, &blk)
- @got_unprovision_request = true
- blk.call(success(true))
- end
-
- def bind_instance(instance_id, binding_options, bind_handle=nil, &blk)
- @got_bind_request = true
- blk.call(success({:configuration => {}, :service_id => BIND_ID, :credentials => {}}))
- end
-
- def unbind_instance(instance_id, handle_id, binding_options, &blk)
- @got_unbind_request = true
- blk.call(success(true))
- end
-
- def restore_instance(instance_id, backup_path, &blk)
- @got_restore_request = true
- blk.call(success(true))
- end
-
- def recover(instance_id, backup_path, handles, &blk)
- @got_recover_reqeust = true
- blk.call(success(true))
- end
-
- def purge_orphan(orphan_ins_hash, orphan_binding_hash, &blk)
- @purge_orphan_invoked = true
- blk.call(success(true))
- end
-
- def check_orphan(handles, &blk)
- @check_orphan_invoked = true
- blk.call(success(true))
- end
-
- def double_check_orphan(handles)
- @double_check_orphan_invoked = true
- end
- end
-
- class NastyProvisioner < MockProvisioner
- def provision_service(request, prov_handle=nil, &blk)
- @got_provision_request = true
- blk.call(internal_fail)
- end
-
- def unprovision_service(instance_id, &blk)
- @got_unprovision_request = true
- blk.call(internal_fail)
- end
-
- def bind_instance(instance_id, binding_options, bind_handle=nil, &blk)
- @got_bind_request = true
- blk.call(internal_fail)
- end
-
- def unbind_instance(instance_id, handle_id, binding_options, &blk)
- @got_unbind_request = true
- blk.call(internal_fail)
- end
-
- def restore_instance(instance_id, backup_path, &blk)
- @got_restore_request = true
- blk.call(internal_fail)
- end
-
- def recover(instance_id, backup_path, handles, &blk)
- @got_recover_reqeust = true
- blk.call(internal_fail)
- end
-
- def purge_orphan(orphan_ins_hash,orphan_binding_hash,&blk)
- @purge_orphan_invoked = true
- blk.call(internal_fail)
- end
- def check_orphan(handles,&blk)
- @check_orphan_invoked = true
- blk.call(internal_fail)
- end
- end
-
- # Timeout Provisioner is a simple version of provisioner.
- # It only support provisioning.
- class TimeoutProvisioner < MockProvisioner
- def initialize(timeout)
- @timeout = timeout
- end
-
- def provision_service(request, prov_handle=nil, &blk)
- @got_provision_request = true
- EM.add_timer(@timeout) do
- blk.call(
- success({
- :data => {},
- :service_id => SERV_ID,
- :credentials => {}
- }
- )
- )
- end
- end
- end
-end
View
22 base/spec/helper/backup_spec_helper.rb
@@ -1,22 +0,0 @@
-require "base/backup"
-
-class BackupTest
- class ZombieBackup < VCAP::Services::Base::Backup
- define_method(:default_config_file) {}
- define_method(:backup_db) {}
- attr_reader :exit_invoked
-
- def initialize
- super
- @exit_invoked = false
- end
-
- def start
- sleep 3000
- end
-
- def exit
- @exit_invoked = true
- end
- end
-end
View
60 base/spec/helper/base_spec_helper.rb
@@ -1,60 +0,0 @@
-require 'base/base'
-
-class BaseTests
-
- module Options
-
- LOGGER = Logger.new(STDOUT)
- NATS_URI = "nats://localhost:4222"
- IP_ROUTE = "127.0.0.1"
- NODE_TIMEOUT = 5
- PLAN = "free"
- CAPACITY = 200
-
- def self.default(more=nil)
- options = {
- :logger => LOGGER,
- :plan => PLAN,
- :capacity => CAPACITY,
- :ip_route => IP_ROUTE,
- :mbus => NATS_URI,
- :node_timeout => NODE_TIMEOUT
- }
- more.each { |k,v| options[k] = v } if more
- options
- end
- end
-
- def self.create_base
- BaseTester.new(Options.default)
- end
-
- class BaseTester < VCAP::Services::Base::Base
- attr_accessor :node_mbus_connected
- attr_accessor :varz_invoked
- attr_accessor :healthz_invoked
- def initialize(options)
- @node_mbus_connected = false
- @varz_invoked = false
- @healthz_invoked = false
- super(options)
- end
- def flavor
- "flavor"
- end
- def service_name
- "service_name"
- end
- def on_connect_node
- @node_mbus_connected = true
- end
- def varz_details
- @varz_invoked = true
- {}
- end
- def healthz_details
- @healthz_invoked = true
- {}
- end
- end
-end
View
317 base/spec/helper/node_spec_helper.rb
@@ -1,317 +0,0 @@
-require 'base/node'
-
-class NodeTests
-
- def self.create_node(options={})
- NodeTester.new(BaseTests::Options.default({:node_id => NodeTester::ID}).merge(options))
- end
-
- def self.create_error_node
- NodeErrorTester.new(BaseTests::Options.default({:node_id => NodeTester::ID}))
- end
-
- def self.create_error_provisioner
- MockErrorProvisioner.new
- end
-
- def self.create_provisioner
- MockProvisioner.new
- end
-
- class NodeTester < VCAP::Services::Base::Node
- attr_accessor :announcement_invoked
- attr_accessor :provision_invoked
- attr_accessor :unprovision_invoked
- attr_accessor :bind_invoked
- attr_accessor :unbind_invoked
- attr_accessor :restore_invoked
- attr_accessor :provision_times
- attr_reader :unprovision_count
- attr_reader :unbind_count
- attr_reader :capacity
- attr_accessor :varz_invoked
- attr_accessor :healthz_invoked
- SERVICE_NAME = "Test"
- ID = "node-1"
- def initialize(options)
- super(options)
- @ready = true
- @announcement_invoked = false
- @provision_invoked = false
- @unprovision_invoked = false
- @bind_invoked = false
- @unbind_invoked = false
- @restore_invoked = false
- @provision_times = 0
- @mutex = Mutex.new
- @unprovision_count = 0
- @unbind_count = 0
- @varz_invoked = false
- @healthz_invoked = false
- @ins_count = options[:ins_count] || 0
- @bind_count = options[:bind_count] || 0
- @plan = options[:plan] || "free"
- end
- def service_name
- SERVICE_NAME
- end
- def set_ready(r)
- @ready = r
- end
- def node_ready?
- @ready
- end
- def announcement
- @announcement_invoked = true
- Hash.new
- end
- def provision(plan, credential)
- sleep 5 # Provision takes 5 seconds to finish
- @mutex.synchronize { @provision_times += 1 }
- @provision_invoked = true
- Hash.new
- end
- def unprovision(name, bindings)
- @unprovision_invoked = true
- @mutex.synchronize{ @unprovision_count += 1 }
- end
- def bind(name, bind_opts, credential)
- @bind_invoked = true
- end
- def unbind(credentials)
- @unbind_invoked = true
- @mutex.synchronize{ @unbind_count += 1 }
- end
- def restore(isntance_id, backup_path)
- @restore_invoked = true
- end
- def varz_details
- @varz_invoked = true
- {}
- end
- def healthz_details
- @healthz_invoked = true
- {}
- end
-
- def all_instances_list
- generate_ins_list(@ins_count)
- end
-
- def all_bindings_list
- generate_bind_list(@bind_count)
- end
-
- end
-
- class MockProvisioner
- include VCAP::Services::Internal
- attr_accessor :got_announcement
- attr_accessor :got_announcement_by_plan
- attr_accessor :got_provision_response
- attr_accessor :ins_hash
- attr_accessor :bind_hash
- def initialize
- @got_announcement = false
- @got_announcement_by_plan = false
- @got_provision_response = false
- @got_unprovision_response = false
- @got_bind_response = false
- @got_unbind_response = false
- @got_restore_response = false
- @ins_hash = Hash.new { |h,k| h[k] = [] }
- @bind_hash = Hash.new { |h,k| h[k] = [] }
- @nats = NATS.connect(:uri => BaseTests::Options::NATS_URI) {
- @nats.subscribe("#{NodeTester::SERVICE_NAME}.announce") {
- @got_announcement = true
- }
- @nats.subscribe("#{NodeTester::SERVICE_NAME}.node_handles") do |msg|
- response = NodeHandlesReport.decode(msg)
- @ins_hash[response.node_id].concat(response.instances_list)
- @bind_hash[response.node_id].concat(response.bindings_list)
- end
- @nats.publish("#{NodeTester::SERVICE_NAME}.discover")
- }
- end
- def send_discover_by_plan(plan)
- req = Yajl::Encoder.encode({"plan" => plan})
- @nats.request("#{NodeTester::SERVICE_NAME}.discover", req) {|_| @got_announcement_by_plan = true }
- end
- def send_provision_request
- req = ProvisionRequest.new
- req.plan = "free"
- @nats.request("#{NodeTester::SERVICE_NAME}.provision.#{NodeTester::ID}", req.encode) {
- @got_provision_response = true
- }
- end
- def send_unprovision_request
- req = UnprovisionRequest.new
- req.name = "fake"
- req.bindings = []
- @nats.request("#{NodeTester::SERVICE_NAME}.unprovision.#{NodeTester::ID}", req.encode ) {
- @got_unprovision_response = true
- }
- end
- def send_bind_request
- req = BindRequest.new
- req.name = "fake"
- req.bind_opts = {}
- @nats.request("#{NodeTester::SERVICE_NAME}.bind.#{NodeTester::ID}", req.encode) {
- @got_bind_response = true
- }
- end
- def send_unbind_request