Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge "[service-ng] Health check for service instances"

  • Loading branch information...
commit d94ebf9b02241753f6a2c6a9c6b3eead8c1619a1 2 parents 6f422cd + 8b0f329
Felix Hu felixhoo authored Gerrit Code Review committed
15 ng/memcached/lib/memcached_service/memcached_node.rb
View
@@ -117,21 +117,22 @@ def migrate_saved_instances_on_startup
def pre_send_announcement
migrate_saved_instances_on_startup
start_provisioned_instances
+ warden_node_init(@options)
+ end
+
+ def service_instances
+ ProvisionedService.all
end
def start_provisioned_instances
- @capacity_lock.synchronize do
- start_instances(ProvisionedService.all)
- end
+ start_all_instances
+ @capacity_lock.synchronize{ @capacity -= ProvisionedService.all.size }
end
def shutdown
super
@logger.info("Shutting down instances..")
- ProvisionedService.all.each do |p_service|
- @logger.debug("Try to terminate memcached container: #{p_service.container}")
- p_service.stop if p_service.running?
- end
+ stop_all_instances
end
def announcement
14 ng/mongodb/lib/mongodb_service/mongodb_node.rb
View
@@ -64,15 +64,19 @@ def migrate_saved_instances_on_startup
def pre_send_announcement
migrate_saved_instances_on_startup
- @capacity_lock.synchronize do
- start_instances(ProvisionedService.all)
- end
+ start_all_instances
+ @capacity_lock.synchronize{ @capacity -= ProvisionedService.all.size }
+ warden_node_init(@options)
+ end
+
+ def service_instances
+ ProvisionedService.all
end
def shutdown
super
@logger.info("Shutting down instances..")
- stop_instances(ProvisionedService.all)
+ stop_all_instances
end
def announcement
@@ -213,7 +217,7 @@ def disable_instance(service_credential, binding_credentials)
@logger.info("disable_instance request: service_credential=#{service_credential}, binding_credentials=#{binding_credentials}")
p_service = ProvisionedService.get(service_credential['name'])
raise ServiceError.new(ServiceError::NOT_FOUND, service_credential['name']) if p_service.nil?
- p_service.stop if p_service.running?
+ p_service.stop
true
rescue => e
@logger.warn(e)
5 ng/mysql/lib/mysql_service/node.rb
View
@@ -47,6 +47,9 @@ class << self
include VCAP::Services::Mysql::WithWarden
include VCAP::Services::Base::Utils
include VCAP::Services::Base::Warden::NodeUtils
+ def service_instances
+ mysqlProvisionedService.all
+ end
end
else
require "mysql_service/without_warden"
@@ -94,7 +97,7 @@ def pre_send_announcement
DataMapper.setup(:default, @local_db)
DataMapper::auto_upgrade!
- pre_send_announcement_internal
+ pre_send_announcement_internal(@options)
EM.add_periodic_timer(STORAGE_QUOTA_INTERVAL) { EM.defer {enforce_storage_quota} }
10 ng/mysql/lib/mysql_service/with_warden.rb
View
@@ -17,17 +17,17 @@ def init_internal(options)
init_ports(options[:port_range])
end
- def pre_send_announcement_internal
+ def pre_send_announcement_internal(options)
@pool_mutex = Mutex.new
@pools = {}
- @capacity_lock.synchronize do
- start_instances(mysqlProvisionedService.all)
- end
+ start_all_instances
+ @capacity_lock.synchronize{ @capacity -= mysqlProvisionedService.all.size }
mysqlProvisionedService.all.each do |instance|
setup_pool(instance)
end
+ warden_node_init(options)
end
def handle_provision_exception(provisioned_service)
@@ -62,7 +62,7 @@ def is_service_started(instance)
def shutdown
super
@logger.info("Shutting down instances..")
- stop_instances(mysqlProvisionedService.all)
+ stop_all_instances
end
def setup_pool(instance)
2  ng/mysql/lib/mysql_service/without_warden.rb
View
@@ -12,7 +12,7 @@ def mysqlProvisionedService
VCAP::Services::Mysql::Node::ProvisionedService
end
- def pre_send_announcement_internal
+ def pre_send_announcement_internal(options)
@pool_mutex = Mutex.new
@pools = {}
4 ng/mysql/spec/spec_helper.rb
View
@@ -14,9 +14,9 @@
# monkey patch of wardenized node
module VCAP::Services::Mysql::WithWarden
alias_method :pre_send_announcement_internal_ori, :pre_send_announcement_internal
- def pre_send_announcement_internal
+ def pre_send_announcement_internal(options)
unless @options[:not_start_instances]
- pre_send_announcement_internal_ori
+ pre_send_announcement_internal_ori(options)
else
@pool_mutex = Mutex.new
@pools = {}
8 ng/postgresql/lib/postgresql_service/model.rb
View
@@ -142,6 +142,14 @@ def stop_options
options
end
+ def status_options
+ options = super
+ options[:status_script] = {
+ :script => "#{service_script} status #{base_dir} #{log_dir} #{bin_dir}"
+ }
+ options
+ end
+
def finish_start?
postgresql_quickcheck(
ip,
5 ng/postgresql/lib/postgresql_service/node.rb
View
@@ -33,7 +33,6 @@ class VCAP::Services::Postgresql::Node
def initialize(options)
super(options)
- @options = options.dup
@postgresql_configs = options[:postgresql]
@max_db_size = (options[:max_db_size] * 1024 * 1024).round
@@ -83,9 +82,7 @@ def self.pgBindUserClass(use_warden)
def pre_send_announcement
self.class.setup_datamapper(:default, @local_db)
pre_send_announcement_prepare
- @capacity_lock.synchronize do
- pre_send_announcement_internal
- end
+ pre_send_announcement_internal(@options)
check_db_consistency
setup_timers
end
12 ng/postgresql/lib/postgresql_service/with_warden.rb
View
@@ -25,6 +25,10 @@ def pgProvisionedService
VCAP::Services::Postgresql::Node::Wardenprovisionedservice
end
+ def service_instances
+ pgProvisionedService.all
+ end
+
def pgBindUser
VCAP::Services::Postgresql::Node::Wardenbinduser
end
@@ -34,12 +38,14 @@ def pre_send_announcement_prepare
@connections = {}
end
- def pre_send_announcement_internal
- start_instances(pgProvisionedService.all)
+ def pre_send_announcement_internal(options)
+ start_all_instances
+ @capacity_lock.synchronize{ @capacity -= pgProvisionedService.all.size }
pgProvisionedService.all.each do |provisionedservice|
global_connection(provisionedservice, true)
migrate_instance provisionedservice
end
+ warden_node_init(options)
end
def migrate_instance provisionedservice
@@ -251,7 +257,7 @@ def setup_timers
def shutdown
super
@logger.info("Shutting down instances..")
- stop_instances(pgProvisionedService.all)
+ stop_all_instances
end
def get_inst_port(instance)
2  ng/postgresql/lib/postgresql_service/without_warden.rb
View
@@ -38,7 +38,7 @@ def pre_send_announcement_prepare
end
end
- def pre_send_announcement_internal
+ def pre_send_announcement_internal(options)
pgProvisionedService.all.each do |provisionedservice|
setup_global_connection provisionedservice
migrate_instance provisionedservice
4 ng/postgresql/spec/spec_helper.rb
View
@@ -14,9 +14,9 @@
# monkey patch of wardenized node
module VCAP::Services::Postgresql::WithWarden
alias_method :pre_send_announcement_internal_ori, :pre_send_announcement_internal
- def pre_send_announcement_internal
+ def pre_send_announcement_internal(options)
unless @use_warden && @options[:not_start_instances]
- pre_send_announcement_internal_ori
+ pre_send_announcement_internal_ori(options)
else
@logger.info("Not to start instances")
pgProvisionedService.all.each do |provisionedservice|
13 ng/rabbit/lib/rabbit_service/rabbit_node.rb
View
@@ -60,19 +60,22 @@ def initialize(options)
options[:initial_password] = @initial_password = "guest"
@hostname = get_host
ProvisionedService.init(options)
- @options = options
end
def pre_send_announcement
- @capacity_lock.synchronize do
- start_instances(ProvisionedService.all)
- end
+ start_all_instances
+ @capacity_lock.synchronize{ @capacity -= ProvisionedService.all.size }
+ warden_node_init(@options)
+ end
+
+ def service_instances
+ ProvisionedService.all
end
def shutdown
super
@logger.info("Shutting down instances..")
- stop_instances(ProvisionedService.all)
+ stop_all_instances
true
end
15 ng/redis/lib/redis_service/redis_node.rb
View
@@ -50,7 +50,6 @@ def initialize(options)
@redis_timeout = options[:redis_timeout] || 2
@service_start_timeout = options[:service_start_timeout] || 3
ProvisionedService.init(options)
- @options = options
@supported_versions = options[:supported_versions]
@default_version = options[:default_version]
end
@@ -67,15 +66,19 @@ def migrate_saved_instances_on_startup
def pre_send_announcement
migrate_saved_instances_on_startup
- @capacity_lock.synchronize do
- start_instances(ProvisionedService.all)
- end
+ start_all_instances
+ @capacity_lock.synchronize{ @capacity -= ProvisionedService.all.size }
+ warden_node_init(@options)
+ end
+
+ def service_instances
+ ProvisionedService.all
end
def shutdown
super
@logger.info("Shutting down instances..")
- stop_instances(ProvisionedService.all)
+ stop_all_instances
true
end
@@ -164,7 +167,7 @@ def restore(instance_id, backup_dir)
dump_file = File.join(backup_dir, "dump.rdb")
if File.exists?(dump_file)
if File.new(dump_file).size > 0
- instance.stop if instance.running?
+ instance.stop
sleep 1
FileUtils.cp(dump_file, File.join(instance.data_dir, "dump.rdb"))
instance.run
2  ng/redis/lib/redis_service/util.rb
View
@@ -80,7 +80,7 @@ def dump_redis_data(instance, dump_path=nil)
def import_redis_data(instance, dump_path)
name = instance.name
dump_file = File.join(dump_path, "dump.rdb")
- instance.stop if instance.running?
+ instance.stop
FileUtils.cp(dump_file, instance.data_dir)
instance.run
true
14 ng/vblob/lib/vblob_service/vblob_node.rb
View
@@ -58,15 +58,19 @@ def initialize(options)
# handle the cases which has already been in the local sqlite database
def pre_send_announcement
- @capacity_lock.synchronize do
- start_instances(ProvisionedService.all)
- end
+ start_all_instances
+ @capacity_lock.synchronize{ @capacity -= ProvisionedService.all.size }
+ warden_node_init(@options)
+ end
+
+ def service_instances
+ ProvisionedService.all
end
def shutdown
super
@logger.info("Shutting down instances..")
- stop_instances(ProvisionedService.all)
+ stop_all_instances
end
def announcement
@@ -224,7 +228,7 @@ def disable_instance(service_credential, binding_credentials)
@logger.info("disable_instance request: service_credential=#{service_credential}, binding_credentials=#{binding_credentials}")
provisioned_service = ProvisionedService.get(service_credential['name'])
raise ServiceError.new(ServiceError::NOT_FOUND, service_credential['name']) if provisioned_service.nil?
- provisioned_service.stop if provisioned_service.running?
+ provisioned_service.stop
true
rescue => e
@logger.warn(e)
Please sign in to comment.
Something went wrong with that request. Please try again.