Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 11 commits
  • 14 files changed
  • 0 commit comments
  • 1 contributor
View
3 Gemfile
@@ -3,7 +3,10 @@ source :rubygems
gem 'amqp'
gem 'json'
gem 'configatron'
+gem 'active_support', :require => "active_support/core_ext/string/inflections"
group :development do
gem 'rspec'
+ gem 'evented-spec'
+ gem 'mocha'
end
View
10 Gemfile.lock
@@ -1,6 +1,9 @@
GEM
remote: http://rubygems.org/
specs:
+ active_support (3.0.0)
+ activesupport (= 3.0.0)
+ activesupport (3.0.0)
amq-client (0.9.2)
amq-protocol (>= 0.9.0)
eventmachine
@@ -12,8 +15,12 @@ GEM
configatron (2.9.0)
yamler (>= 0.1.0)
diff-lcs (1.1.3)
+ evented-spec (0.9.0)
eventmachine (0.12.10)
json (1.6.6)
+ metaclass (0.0.1)
+ mocha (0.10.5)
+ metaclass (~> 0.0.1)
rspec (2.9.0)
rspec-core (~> 2.9.0)
rspec-expectations (~> 2.9.0)
@@ -28,7 +35,10 @@ PLATFORMS
ruby
DEPENDENCIES
+ active_support
amqp
configatron
+ evented-spec
json
+ mocha
rspec
View
26 Readme.markdown
@@ -0,0 +1,26 @@
+# CloudBalancer
+
+Ever wanted the servers behind your loadbalancer to register themself with
+the it? Ever wished your loadbalancer would react on high load or other
+events on the backend servers?
+
+This project will solve your problems (as soon as its finished, haha...).
+
+## Concept
+ - A new node registers itself at its loadbalancers
+ - Loadbalancer gets in a defined period of time announcements from
+ the nodes about their current status
+ - Loadbalancer weights the nodes according to their status
+ - It will be easy to write your own node-plugin (want to check
+ Seconds_behind_master on a MySQL-Slave?)
+ - In the first version, there will be just generic TCP-relaying, soon
+ after that there will be HTTP-Proxying
+ - Primarily based on AMQP/RabbitMQ
+
+## Planned features
+ - Everything is a plugin
+ - Want to use STOMP instead of AMQP?
+ - Easily write your own checks on a node
+ - Webinterface
+ - HTTP-Proxying (including Varnish-Cache?)
+ - SMTP-Proxying
View
16 bin/cloudbalancer
@@ -0,0 +1,16 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'bundler'
+
+Bundler.require
+
+$: << 'lib'
+
+require './config/config'
+require 'cloud_balancer'
+
+EM.run do
+ runner = CloudBalancer::Runner.new
+ runner.run!
+end
View
5 config/config.rb
@@ -1,8 +1,11 @@
configatron.cluster_password = ""
configatron.server.services = [ ]
+configatron.amqp.host = 'localhost'
+configatron.daemon = :server
+configatron.protocol = :AMQP
if File.exists?("config/config.local.rb")
- require "config/config.local"
+ require "./config/config.local"
end
configatron.server.cluster_password = Configatron::Dynamic.new {configatron.cluster_password}
View
2 lib/cloud_balancer.rb
@@ -2,5 +2,7 @@ module CloudBalancer
autoload :Server, 'cloud_balancer/server'
autoload :Config, 'cloud_balancer/config'
+ autoload :Transport, 'cloud_balancer/transport'
+ autoload :Runner, 'cloud_balancer/runner'
end
View
16 lib/cloud_balancer/runner.rb
@@ -0,0 +1,16 @@
+module CloudBalancer
+ class Runner
+
+ attr_reader :protocol
+ attr_reader :worker
+
+ def initialize
+ @protocol = CloudBalancer::Config.protocol
+ end
+
+ def run!
+ @worker = "CloudBalancer::Transport::#{@protocol.to_s.camelize}".constantize.new
+ end
+
+ end
+end
View
8 lib/cloud_balancer/transport.rb
@@ -0,0 +1,8 @@
+module CloudBalancer
+ module Transport
+
+ autoload :Base, 'cloud_balancer/transport/base'
+ autoload :AMQP, 'cloud_balancer/transport/amqp'
+
+ end
+end
View
23 lib/cloud_balancer/transport/amqp.rb
@@ -0,0 +1,23 @@
+module CloudBalancer
+ module Transport
+ class AMQP
+
+ attr_reader :queue_name, :channel, :consumer
+
+ def initialize
+ connection = ::AMQP.connect(:host => CloudBalancer::Config.amqp.host)
+
+ @channel = ::AMQP::Channel.new(connection)
+
+ @consumer = "CloudBalancer::#{CloudBalancer::Config.daemon.to_s.camelize}".constantize.new
+ end
+
+ def start
+ @queue = @channel.queue("", :exclusive => true)
+ @queue_name = @queue.name
+ @queue.subscribe(&@consumer.method(:handle_message))
+ end
+
+ end
+ end
+end
View
12 spec/cloud_balancer/runner_spec.rb
@@ -0,0 +1,12 @@
+require 'spec_helper'
+
+describe CloudBalancer::Runner do
+
+ it "should instantiate a worker of the defined protocol" do
+ mock_amqp_connect
+ runner = CloudBalancer::Runner.new
+ runner.run!
+ runner.worker.should be_instance_of(CloudBalancer::Transport::AMQP)
+ end
+
+end
View
2 spec/cloud_balancer/server_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe CloudBalancer::Server do
-
+
context "Communication to the nodes" do
it "connects to a message queue server on start" do
View
25 spec/cloud_balancer/transport/amqp_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe CloudBalancer::Transport::AMQP do
+
+ #include EventedSpec::EMSpec
+
+ context "as server" do
+ before do
+ mock_amqp_connect
+ end
+
+ subject do
+ amqp = CloudBalancer::Transport::AMQP.new
+ amqp.start
+ amqp
+ end
+
+ its(:queue_name) { should be_instance_of(String) }
+ its(:queue_name) { should_not be_empty }
+
+ its(:consumer) { should be_instance_of(CloudBalancer::Server) }
+
+ end
+
+end
View
13 spec/helpers.rb
@@ -0,0 +1,13 @@
+module Helpers
+ def mock_amqp_connect
+ queue = mock
+ queue.stubs(:name).returns("generatedstring-123")
+ queue.stubs(:subscribe).returns(true)
+
+ channel = mock
+ channel.stubs(:queue).with("", :exclusive => true).returns(queue)
+
+ ::AMQP.stubs(:connect).returns(true)
+ ::AMQP::Channel.stubs(:new).returns(channel)
+ end
+end
View
11 spec/spec_helper.rb
@@ -10,7 +10,18 @@
require 'cloud_balancer'
require 'ostruct'
+require 'evented-spec'
+
+require './spec/helpers'
+RSpec.configure do |config|
+ config.mock_with :mocha
+ config.include Helpers
+end
# override the configuration
CloudBalancer::Config.cluster_password = "testpass"
CloudBalancer::Config.server.services = [ :www ]
+CloudBalancer::Config.amqp.host = "localhost"
+CloudBalancer::Config.daemon = :server
+CloudBalancer::Config.protocol = :AMQP
+

No commit comments for this range

Something went wrong with that request. Please try again.