Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

Commit

Permalink
registries: unify configuration options
Browse files Browse the repository at this point in the history
  • Loading branch information
niamster committed Mar 22, 2015
1 parent a4621b2 commit 3922fde
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -6,7 +6,7 @@ before_install:

before_script:
- sleep 15
- cassandra-cli --batch < <(echo -e "create keyspace dcell with placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' and strategy_options = {replication_factor:1};\nuse dcell;\ncreate column family dcell;")
- cassandra-cli --batch < <(echo -e "create keyspace test with placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' and strategy_options = {replication_factor:1};\nuse test;\ncreate column family dcell;")

services:
- redis-server
Expand Down
2 changes: 1 addition & 1 deletion examples/registry.rb
@@ -1,4 +1,4 @@
require 'dcell/registries/redis_adapter'
def registry
DCell::Registry::RedisAdapter.new server: 'localhost'
DCell::Registry::RedisAdapter.new
end
9 changes: 3 additions & 6 deletions lib/dcell/registries/cassandra_adapter.rb
Expand Up @@ -31,14 +31,11 @@ class CassandraAdapter
include Node
include Global

DEFAULT_KEYSPACE = "dcell"
DEFAULT_CF = "dcell"

def initialize(options)
def initialize(options={})
options = Utils::symbolize_keys options

keyspace = options[:keyspace] || DEFAULT_KEYSPACE
columnfamily = options[:columnfamily] || DEFAULT_CF
keyspace = options[:env] || 'production'
columnfamily = options[:namespace] || 'dcell'

options[:servers] ||= []
options[:servers] << options[:server] if options[:server]
Expand Down
8 changes: 4 additions & 4 deletions lib/dcell/registries/redis_adapter.rb
Expand Up @@ -8,14 +8,14 @@ class RedisAdapter
include Node
include Global

def initialize(options)
def initialize(options={})
options = Utils::symbolize_keys options

@env = options[:env] || 'production'
@namespace = options[:namespace] || "dcell_#{@env}"
env = options[:env] || 'production'
namespace = options[:namespace] || "dcell_#{env}"

redis = Redis.new options
@redis = Redis::Namespace.new @namespace, redis: redis
@redis = Redis::Namespace.new namespace, redis: redis

@node_registry = Registry.new(@redis, 'nodes')
@global_registry = Registry.new(@redis, 'globals')
Expand Down
34 changes: 8 additions & 26 deletions lib/dcell/registries/zk_adapter.rb
Expand Up @@ -6,40 +6,22 @@ class ZkAdapter
include Node
include Global

PREFIX = "/dcell"
DEFAULT_PORT = 2181

# Create a new connection to Zookeeper
#
# servers: a list of Zookeeper servers to connect to. Each server in the
# list has a host/port configuration
def initialize(options)
def initialize(options={})
options = Utils::symbolize_keys options

@env = options[:env] || 'production'
@base_path = "#{PREFIX}/#{@env}"

# Let them specify a single server instead of many
server = options[:server]
if server
servers = [server]
else
servers = options[:servers]
raise "no Zookeeper servers given" unless servers
end
env = options[:env] || 'production'
base_path = options[:namespace] || "/dcell/#{env}"

# Add the default Zookeeper port unless specified
servers.map! do |server|
if server[/:\d+$/]
server
else
"#{server}:#{DEFAULT_PORT}"
end
end
options[:servers] ||= []
options[:servers] << "127.0.0.1:2181" unless options[:servers].any?

@zk = ZK.new(*servers)
@node_registry = Registry.new(@zk, @base_path, :nodes)
@global_registry = Registry.new(@zk, @base_path, :globals)
@zk = ZK.new(*options[:servers])
@node_registry = Registry.new(@zk, base_path, :nodes)
@global_registry = Registry.new(@zk, base_path, :globals)
end

class Registry
Expand Down
6 changes: 3 additions & 3 deletions spec/options/01-options.rb
@@ -1,7 +1,7 @@
TEST_DB = {
redis: {server: 'localhost', env: 'test'},
zk: {server: 'localhost', env: 'test'},
cassandra: {},
redis: {env: 'test'},
zk: {env: 'test'},
cassandra: {env: 'test'},
}
TEST_NODE = {
id: 'test_node',
Expand Down

0 comments on commit 3922fde

Please sign in to comment.