Skip to content

Commit

Permalink
Major rewrite of RabbitMQ service
Browse files Browse the repository at this point in the history
Change-Id: Ice9fbb5a27c0f69e05d7ddb53ef06cf535e81079
  • Loading branch information
Tang Rui committed Feb 23, 2012
1 parent 26c4960 commit e0a1c15
Show file tree
Hide file tree
Showing 16 changed files with 737 additions and 671 deletions.
1 change: 1 addition & 0 deletions rabbit/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ gem "ruby-hmac", :require => "hmac-sha1"
gem "thin"
gem "sinatra"
gem "amqp"
gem "rest-client"

gem 'vcap_common', '>= 1.0.4', :require => ['vcap/common', 'vcap/component']
gem 'vcap_logging', '>=0.1.3', :require => ['vcap/logging']
Expand Down
4 changes: 4 additions & 0 deletions rabbit/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ GEM
little-plugger (>= 1.1.2)
macaddr (1.5.0)
systemu (>= 2.4.0)
mime-types (1.17.2)
multi_json (1.0.4)
nats (0.4.22.beta.4)
daemons (>= 1.1.4)
Expand All @@ -96,6 +97,8 @@ GEM
redisk (>= 0.2.1)
resque (>= 1.3.1)
uuid (>= 2.0.2)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec (2.5.0)
rspec-core (~> 2.5.0)
rspec-expectations (~> 2.5.0)
Expand Down Expand Up @@ -161,6 +164,7 @@ DEPENDENCIES
nats
rake
rcov
rest-client
rspec
ruby-hmac
sinatra
Expand Down
13 changes: 7 additions & 6 deletions rabbit/bin/rabbit_gateway
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env ruby
# -*- mode: ruby -*-
# Copyright (c) 2009-2011 VMware, Inc.
ENV["BUNDLE_GEMFILE"] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup'
require 'vcap_services_base'
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
require "bundler/setup"
require "vcap_services_base"

$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'rabbit_service/rabbit_provisioner'
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
require "rabbit_service/rabbit_provisioner"

class VCAP::Services::Rabbit::Gateway < VCAP::Services::Base::Gateway

Expand All @@ -15,7 +15,8 @@ class VCAP::Services::Rabbit::Gateway < VCAP::Services::Base::Gateway
end

def default_config_file
File.join(File.dirname(__FILE__), '..', 'config', 'rabbit_gateway.yml')
config_base_dir = ENV["CLOUD_FOUNDRY_CONFIG_PATH"] || File.join(File.dirname(__FILE__), "..", "config")
File.join(config_base_dir, "rabbit_gateway.yml")
end

end
Expand Down
18 changes: 10 additions & 8 deletions rabbit/bin/rabbit_node
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# -*- mode: ruby -*-
# Copyright (c) 2009-2011 VMware, Inc.
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
require 'bundler/setup'
require 'vcap_services_base'
require "bundler/setup"
require "vcap_services_base"

$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
require "rabbit_service/rabbit_node"
Expand All @@ -15,15 +15,17 @@ class VCAP::Services::Rabbit::NodeBin < VCAP::Services::Base::NodeBin
end

def default_config_file
File.join(File.dirname(__FILE__), '..', 'config', 'rabbit_node.yml')
File.join(File.dirname(__FILE__), "..", "config", "rabbit_node.yml")
end

def additional_config(options, config)
options[:rabbit_ctl] = parse_property(config, "rabbit_ctl", String)
options[:rabbit_server] = parse_property(config, "rabbit_server", String)
options[:rabbit_port] = parse_property(config, "rabbit_port", Integer)
options[:available_memory] = parse_property(config, "available_memory", Integer)
options[:max_memory] = parse_property(config, "max_memory", Integer)
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[: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
end

Expand Down
18 changes: 13 additions & 5 deletions rabbit/config/rabbit_gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@
service:
name: rabbitmq
version: "2.4"
description: 'RabbitMQ message queue'
plans: ['free']
tags: ['rabbitmq', 'rabitmq-2.4', 'message-queue', 'amqp']
description: "RabbitMQ message queue"
plans: ["free"]
tags: ["rabbitmq", "rabitmq-2.4", "message-queue", "amqp"]
ip_route: localhost
#proxy:
# host: proxy
# port: 8080
# keepalive: true
index: 0
token: "0xdeadbeef"
token: changerabbitmqtoken
logging:
level: debug
mbus: nats://localhost:4222
pid: /var/vcap/sys/run/rabbit_gateway.pid
# allow_over_provision: false
plan_management:
plans:
free:
low_water: 10
high_water: 180
#allow_over_provisioning: false
# z_interval: 30
# check_orphan_interval: 3600
# double_check_orphan_interval: 300
# max_nats_payload: 1048576
20 changes: 14 additions & 6 deletions rabbit/config/rabbit_node.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
---
capacity: 200
plan: free
local_db: sqlite3:/var/vcap/services/rabbit/rabbit_node.db
base_dir: /var/vcap/services/rabbit/
rabbit_ctl: rabbitmqctl
rabbit_server: rabbitmq-server
rabbit_port: 5672
base_dir: /var/vcap/services/rabbit/instances
mbus: nats://localhost:4222
index: 0
logging:
level: debug
ip_route: 127.0.0.1
available_memory: 4096
max_memory: 16
node_id: rabbit_node_1
node_id: rabbit_node_free_1
pid: /var/vcap/sys/run/rabbit_node.pid
migration_nfs: /mnt/appcloud
max_clients: 1000
port_range:
first: 10001
last: 20000
admin_port_range:
first: 20001
last: 30000
rabbitmq_server: /home/tangrui/rabbitmq_server-2.4.1/sbin/rabbitmq-server
rabbitmq_log_dir: /var/vcap/sys/log/rabbit
# z_interval: 30
# max_nats_payload: 1048576
# fqdn_hosts: false
41 changes: 21 additions & 20 deletions rabbit/lib/rabbit_service/rabbit_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@ module Services
module Rabbit
class RabbitError < VCAP::Services::Base::Error::ServiceError
# 31300 - 31399 Rabbit-specific Error
RABBIT_SAVE_INSTANCE_FAILED = [31300, HTTP_INTERNAL, "Could not save instance: %s"]
RABBIT_DESTORY_INSTANCE_FAILED = [31301, HTTP_INTERNAL, "Could not destroy instance: %s"]
RABBIT_FIND_INSTANCE_FAILED = [31302, HTTP_NOT_FOUND, "Could not find instance: %s"]
RABBIT_START_INSTANCE_FAILED = [31303, HTTP_INTERNAL, "Could not start instance: %s"]
RABBIT_STOP_INSTANCE_FAILED = [31304, HTTP_INTERNAL, "Could not stop instance: %s"]
RABBIT_CLEANUP_INSTANCE_FAILED = [31305, HTTP_INTERNAL, "Could not cleanup instance, the reasons: %s"]
RABBIT_INVALID_PLAN = [31306, HTTP_INTERNAL, "Invalid plan: %s"]
RABBIT_START_SERVER_FAILED = [31307, HTTP_INTERNAL, "Could not start rabbitmq server"]
RABBIT_STOP_SERVER_FAILED = [31308, HTTP_INTERNAL, "Could not stop rabbitmq server"]
RABBIT_ADD_VHOST_FAILED = [31309, HTTP_INTERNAL, "Could not add vhost: %s"]
RABBIT_DELETE_VHOST_FAILED = [31310, HTTP_INTERNAL, "Could not delete vhost: %s"]
RABBIT_ADD_USER_FAILED = [31311, HTTP_INTERNAL, "Could not add user: %s"]
RABBIT_DELETE_USER_FAILED = [31312, HTTP_INTERNAL, "Could not delete user: %s"]
RABBIT_GET_PERMISSIONS_FAILED = [31313, HTTP_INTERNAL, "Could not get user %s permission"]
RABBIT_SET_PERMISSIONS_FAILED = [31314, HTTP_INTERNAL, "Could not set user %s permission to %s"]
RABBIT_CLEAR_PERMISSIONS_FAILED = [31315, HTTP_INTERNAL, "Could not clean user %s permissions"]
RABBIT_LIST_USERS_FAILED = [31316, HTTP_INTERNAL, "Could not list users"]
RABBIT_LIST_QUEUES_FAILED = [31317, HTTP_INTERNAL, "Could not list queues on vhost %s"]
RABBIT_LIST_EXCHANGES_FAILED = [31318, HTTP_INTERNAL, "Could not list exchanges on vhost %s"]
RABBIT_LIST_BINDINGS_FAILED = [31319, HTTP_INTERNAL, "Could not list bindings on vhost %s"]
RABBIT_SAVE_INSTANCE_FAILED = [31300, HTTP_INTERNAL, "Could not save instance: %s"]
RABBIT_DESTORY_INSTANCE_FAILED = [31301, HTTP_INTERNAL, "Could not destroy instance: %s"]
RABBIT_FIND_INSTANCE_FAILED = [31302, HTTP_NOT_FOUND, "Could not find instance: %s"]
RABBIT_START_INSTANCE_FAILED = [31303, HTTP_INTERNAL, "Could not start instance: %s"]
RABBIT_STOP_INSTANCE_FAILED = [31304, HTTP_INTERNAL, "Could not stop instance: %s"]
RABBIT_CLEANUP_INSTANCE_FAILED = [31305, HTTP_INTERNAL, "Could not cleanup instance, the reasons: %s"]
RABBIT_INVALID_PLAN = [31306, HTTP_INTERNAL, "Invalid plan: %s"]
RABBIT_START_SERVER_FAILED = [31307, HTTP_INTERNAL, "Could not start rabbitmq server"]
RABBIT_STOP_SERVER_FAILED = [31308, HTTP_INTERNAL, "Could not stop rabbitmq server"]
RABBIT_ADD_VHOST_FAILED = [31309, HTTP_INTERNAL, "Could not add vhost: %s"]
RABBIT_DELETE_VHOST_FAILED = [31310, HTTP_INTERNAL, "Could not delete vhost: %s"]
RABBIT_ADD_USER_FAILED = [31311, HTTP_INTERNAL, "Could not add user: %s"]
RABBIT_DELETE_USER_FAILED = [31312, HTTP_INTERNAL, "Could not delete user: %s"]
RABBIT_GET_PERMISSIONS_FAILED = [31313, HTTP_INTERNAL, "Could not get user %s permission"]
RABBIT_SET_PERMISSIONS_FAILED = [31314, HTTP_INTERNAL, "Could not set user %s permission to %s"]
RABBIT_CLEAR_PERMISSIONS_FAILED = [31315, HTTP_INTERNAL, "Could not clean user %s permissions"]
RABBIT_GET_VHOST_PERMISSIONS_FAILED = [31316, HTTP_INTERNAL, "Could not get vhost %s permissions"]
RABBIT_LIST_USERS_FAILED = [31317, HTTP_INTERNAL, "Could not list users"]
RABBIT_LIST_QUEUES_FAILED = [31318, HTTP_INTERNAL, "Could not list queues on vhost %s"]
RABBIT_LIST_EXCHANGES_FAILED = [31319, HTTP_INTERNAL, "Could not list exchanges on vhost %s"]
RABBIT_LIST_BINDINGS_FAILED = [31320, HTTP_INTERNAL, "Could not list bindings on vhost %s"]
end
end
end
Expand Down
Loading

0 comments on commit e0a1c15

Please sign in to comment.