Skip to content

Commit

Permalink
Make distributor plugins customizable in catalog.json
Browse files Browse the repository at this point in the history
You can specify distributor plugins at the top level:

    {
      ...,
      "distributor": {
        "plugins": ["search", "crud", "groonga", "watch"]
      }
    }
  • Loading branch information
kou committed Feb 3, 2014
1 parent 0d15ee3 commit c987c7e
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/droonga/catalog/base.rb
Expand Up @@ -19,6 +19,7 @@
require "droonga/input_adapter_options"
require "droonga/output_adapter_options"
require "droonga/collector_options"
require "droonga/distributor_options"

module Droonga
module Catalog
Expand Down Expand Up @@ -149,6 +150,10 @@ def collector_options
CollectorOptions.new(@data["collector"])
end

def distributor_options
DistributorOptions.new(@data["distributor"])
end

private
def compute_total_weight(dataset)
dataset["ring"].reduce(0) do |result, zone|
Expand Down
2 changes: 1 addition & 1 deletion lib/droonga/dispatcher.rb
Expand Up @@ -59,7 +59,7 @@ def initialize(options)
@farm = Farm.new(name, @loop, :dispatcher => self)
@forwarder = Forwarder.new(@loop)
@replier = Replier.new(@forwarder)
@distributor = Distributor.new(self, @options)
@distributor = Distributor.new(self, Droonga.catalog.distributor_options)
@collector = Collector.new(Droonga.catalog.collector_options)
end

Expand Down
3 changes: 1 addition & 2 deletions lib/droonga/distributor.rb
Expand Up @@ -27,8 +27,7 @@ def initialize(dispatcher, options={})
@dispatcher = dispatcher
@plugins = []
@options = options
# TODO: don't put the default distributions
load_plugins(options[:distributors] || ["search", "crud", "groonga", "watch"])
load_plugins(@options.plugins)
end

def distribute(components)
Expand Down
26 changes: 26 additions & 0 deletions lib/droonga/distributor_options.rb
@@ -0,0 +1,26 @@
# Copyright (C) 2014 Droonga Project
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1 as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

module Droonga
class DistributorOptions
def initialize(data)
@data = data || {}
end

def plugins
@data["plugins"] || []
end
end
end
3 changes: 3 additions & 0 deletions sample/cluster/catalog.json
Expand Up @@ -46,5 +46,8 @@
},
"collector": {
"plugins": ["basic", "search"]
},
"distributor": {
"plugins": ["search", "crud", "groonga", "watch"]
}
}
3 changes: 3 additions & 0 deletions test/command/config/default/catalog.json
Expand Up @@ -63,5 +63,8 @@
},
"collector": {
"plugins": ["basic", "search"]
},
"distributor": {
"plugins": ["search", "crud", "groonga", "watch"]
}
}
27 changes: 27 additions & 0 deletions test/unit/catalog/test_version1.rb
Expand Up @@ -239,4 +239,31 @@ def test_collector
end
end
end

class DistributorOptionsTest < self
def options(data)
catalog = create_catalog(minimum_data.merge(data), "base-path")
catalog.distributor_options
end

class PluginsTest < self
def plugins(data)
options(data).plugins
end

def test_nothing
assert_equal([], plugins({}))
end

def test_distributor
data = {
"distributor" => {
"plugins" => ["search", "crud", "groonga", "watch"],
}
}
assert_equal(["search", "crud", "groonga", "watch"],
plugins(data))
end
end
end
end
37 changes: 37 additions & 0 deletions test/unit/distributor/test_options.rb
@@ -0,0 +1,37 @@
# Copyright (C) 2014 Droonga Project
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1 as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

require "droonga/distributor_options"

class DistributorOptionsTest < Test::Unit::TestCase
def options(data)
Droonga::DistributorOptions.new(data)
end

class PluginsTest < self
def plugins(data)
options(data).plugins
end

def test_nothing
assert_equal([], plugins({}))
end

def test_have_values
assert_equal(["search", "crud", "groonga", "watch"],
plugins("plugins" => ["search", "crud", "groonga", "watch"]))
end
end
end

0 comments on commit c987c7e

Please sign in to comment.