Permalink
Browse files

support rabbitmq 2.8 for nonng

Change-Id: I75462dda0e486867b3ab4232200d8c434313c464
  • Loading branch information...
1 parent e9e0965 commit 5a728a5cc61593d820a751a281cf4e4c9fdc39a8 @andyzh andyzh committed Nov 14, 2012
View
@@ -21,12 +21,12 @@ class VCAP::Services::Rabbit::NodeBin < VCAP::Services::Base::NodeBin
def additional_config(options, config)
options[:port_range] = parse_property(config, "port_range", Range)
options[:admin_port_range] = parse_property(config, "admin_port_range", Range)
- options[:rabbitmq_server] = parse_property(config, "rabbitmq_server", String)
options[:rabbitmq_log_dir] = parse_property(config, "rabbitmq_log_dir", String)
options[:rabbitmq_start_timeout] = parse_property(config, "rabbitmq_start_timeout", Integer, :optional => true)
options[:config_template] = File.expand_path("../../resources/rabbitmq.config.erb", __FILE__)
options[:max_clients] = parse_property(config, "max_clients", Integer, :optional => true)
options[:max_memory_factor] = parse_property(config, "max_memory_factor", Float, :optional => true)
+ options[:rabbit] = parse_property(config, "rabbit", Hash)
options
end
@@ -19,8 +19,17 @@ port_range:
admin_port_range:
first: 20001
last: 30000
-rabbitmq_server: rabbitmq-server
rabbitmq_log_dir: /var/vcap/sys/log/rabbit
+supported_versions: ['2.4', '2.8']
+default_version: '2.4'
+rabbit:
+ '2.4':
+ config_template: ../../../resources/rabbitmq24.config.erb
+ rabbitmq_server: /var/vcap/packages/rabbitmq-2.4/sbin/rabbitmq-server
+ '2.8':
+ config_template: ../../../resources/rabbitmq28.config.erb
+ rabbitmq_server: /var/vcap/packages/rabbitmq-2.8/sbin/rabbitmq-server
+ disk_free_limit: 13421772
# rabbitmq_start_timeout: 5
# z_interval: 30
# max_nats_payload: 1048576
@@ -37,6 +37,7 @@ class ProvisionedService
property :pid, Integer
property :memory, Integer, :required => true
property :status, Integer, :default => 0
+ property :version, String
def listening?(interface_ip, instance_port=port)
begin
@@ -74,7 +75,6 @@ def wait_killed(timeout=5, interval=0.2)
def initialize(options)
super(options)
- @config_template = ERB.new(File.read(options[:config_template]))
@free_ports = Set.new
@free_admin_ports = Set.new
@free_ports_mutex = Mutex.new
@@ -86,7 +86,6 @@ def initialize(options)
@binding_options = nil
@base_dir = options[:base_dir]
FileUtils.mkdir_p(@base_dir) if @base_dir
- @rabbitmq_server = @options[:rabbitmq_server]
@rabbitmq_log_dir = @options[:rabbitmq_log_dir]
@max_clients = @options[:max_clients] || 500
# Timeout for rabbitmq client operations, node cannot be blocked on any rabbitmq instances.
@@ -97,7 +96,7 @@ def initialize(options)
@initial_username = "guest"
@initial_password = "guest"
@hostname = get_host
- @supported_versions = ["2.4"]
+ @default_version = @options[:default_version] || "2.4"
end
def pre_send_announcement
@@ -126,10 +125,13 @@ def announcement
end
def provision(plan, credentials = nil, version=nil)
+ version ||= @default_version
raise RabbitError.new(RabbitError::RABBIT_INVALID_PLAN, plan) unless plan.to_s == @plan
+ raise ServiceError.new(ServiceError::UNSUPPORTED_VERSION, version) unless @supported_versions.include?(version)
instance = ProvisionedService.new
instance.plan = 1
instance.plan_option = ""
+ instance.version = version
if credentials
instance.name = credentials["name"]
instance.vhost = credentials["vhost"]
@@ -372,6 +374,9 @@ def memory_for_instance(instance)
def start_instance(instance)
@logger.debug("Starting: #{instance.inspect} on port #{instance.port}")
+ # Set default version to the old instances without version, used for migration
+ instance.version ||= @default_version
+ version_config = @options[:rabbit][instance.version]
pid = Process.fork do
$0 = "Starting RabbitMQ instance: #{instance.name}"
@@ -395,7 +400,9 @@ def start_instance(instance)
# (@max_clients + 2) / 0.9
file_handles_high_watermark = ((@max_clients + 2) / 0.9).to_i
# Writes the RabbitMQ server erlang configuration file
- config = @config_template.result(Kernel.binding)
+ tpl_name = File.expand_path(version_config["config_template"], __FILE__)
+ tpl_file = File.read(tpl_name)
+ config = ERB.new(tpl_file).result(Kernel.binding)
File.open(File.join(config_dir, "rabbitmq.config"), "w") {|f| f.write(config)}
# Enable management plugin
File.open(File.join(config_dir, "enabled_plugins"), "w") do |f|
@@ -425,7 +432,7 @@ def start_instance(instance)
STDOUT.reopen(File.open("#{log_dir}/rabbitmq_stdout.log", "w"))
STDERR.reopen(File.open("#{log_dir}/rabbitmq_stderr.log", "w"))
- exec("#{@rabbitmq_server}")
+ exec("#{version_config["rabbitmq_server"]}")
end
# In parent, detch the child.
Process.detach(pid)
@@ -0,0 +1,4 @@
+[
+ {rabbit, [{vm_memory_high_watermark, <%= vm_memory_high_watermark %>}, {file_handles_high_watermark, <%= file_handles_high_watermark %>}, {disk_free_limit, <%= version_config["disk_free_limit"] %>}]},
+ {rabbitmq_mochiweb, [{listeners, [{mgmt, [{port, <%= admin_port %>}]}]}]}
+].
@@ -61,9 +61,10 @@ def getNodeTestConfig
:max_clients => parse_property(config, "max_clients", Integer, :optional => true),
:port_range => parse_property(config, "port_range", Range),
:admin_port_range => parse_property(config, "admin_port_range", Range),
- :rabbitmq_server => parse_property(config, "rabbitmq_server", String),
+ :supported_versions => parse_property(config, "supported_versions", Array),
+ :default_version => parse_property(config, "default_version", String),
:rabbitmq_log_dir => "/tmp/rabbit_instances/log",
- :config_template => File.expand_path("../../resources/rabbitmq.config.erb", __FILE__)
+ :rabbit => parse_property(config, "rabbit", Hash),
}
options[:local_db] = "sqlite3:" + options[:local_db_file]
options

0 comments on commit 5a728a5

Please sign in to comment.