[Groonga-commit] droonga/fluent-plugin-droonga at c987c7e [master] Make distributor plugins customizable in catalog.json

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Feb 3 13:00:20 JST 2014


Kouhei Sutou	2014-02-03 13:00:20 +0900 (Mon, 03 Feb 2014)

  New Revision: c987c7e540dca7c20dfcefbed4075ccd683c259d
  https://github.com/droonga/fluent-plugin-droonga/commit/c987c7e540dca7c20dfcefbed4075ccd683c259d

  Message:
    Make distributor plugins customizable in catalog.json
    
    You can specify distributor plugins at the top level:
    
        {
          ...,
          "distributor": {
            "plugins": ["search", "crud", "groonga", "watch"]
          }
        }

  Added files:
    lib/droonga/distributor_options.rb
    test/unit/distributor/test_options.rb
  Modified files:
    lib/droonga/catalog/base.rb
    lib/droonga/dispatcher.rb
    lib/droonga/distributor.rb
    sample/cluster/catalog.json
    test/command/config/default/catalog.json
    test/unit/catalog/test_version1.rb

  Modified: lib/droonga/catalog/base.rb (+5 -0)
===================================================================
--- lib/droonga/catalog/base.rb    2014-02-03 12:33:13 +0900 (89b6842)
+++ lib/droonga/catalog/base.rb    2014-02-03 13:00:20 +0900 (e5325a4)
@@ -19,6 +19,7 @@ require "droonga/message_processing_error"
 require "droonga/input_adapter_options"
 require "droonga/output_adapter_options"
 require "droonga/collector_options"
+require "droonga/distributor_options"
 
 module Droonga
   module Catalog
@@ -149,6 +150,10 @@ module Droonga
         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|

  Modified: lib/droonga/dispatcher.rb (+1 -1)
===================================================================
--- lib/droonga/dispatcher.rb    2014-02-03 12:33:13 +0900 (4cf577d)
+++ lib/droonga/dispatcher.rb    2014-02-03 13:00:20 +0900 (9b0f0c4)
@@ -59,7 +59,7 @@ module Droonga
       @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
 

  Modified: lib/droonga/distributor.rb (+1 -2)
===================================================================
--- lib/droonga/distributor.rb    2014-02-03 12:33:13 +0900 (c9a7ebf)
+++ lib/droonga/distributor.rb    2014-02-03 13:00:20 +0900 (213ec6c)
@@ -27,8 +27,7 @@ module Droonga
       @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)

  Added: lib/droonga/distributor_options.rb (+26 -0) 100644
===================================================================
--- /dev/null
+++ lib/droonga/distributor_options.rb    2014-02-03 13:00:20 +0900 (2f61031)
@@ -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

  Modified: sample/cluster/catalog.json (+3 -0)
===================================================================
--- sample/cluster/catalog.json    2014-02-03 12:33:13 +0900 (186e732)
+++ sample/cluster/catalog.json    2014-02-03 13:00:20 +0900 (fb5d014)
@@ -46,5 +46,8 @@
   },
   "collector": {
     "plugins": ["basic", "search"]
+  },
+  "distributor": {
+    "plugins": ["search", "crud", "groonga", "watch"]
   }
 }

  Modified: test/command/config/default/catalog.json (+3 -0)
===================================================================
--- test/command/config/default/catalog.json    2014-02-03 12:33:13 +0900 (c5cade1)
+++ test/command/config/default/catalog.json    2014-02-03 13:00:20 +0900 (7e285da)
@@ -63,5 +63,8 @@
   },
   "collector": {
     "plugins": ["basic", "search"]
+  },
+  "distributor": {
+    "plugins": ["search", "crud", "groonga", "watch"]
   }
 }

  Modified: test/unit/catalog/test_version1.rb (+27 -0)
===================================================================
--- test/unit/catalog/test_version1.rb    2014-02-03 12:33:13 +0900 (d2eadc5)
+++ test/unit/catalog/test_version1.rb    2014-02-03 13:00:20 +0900 (17991ec)
@@ -239,4 +239,31 @@ class CatalogTest < Test::Unit::TestCase
       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

  Added: test/unit/distributor/test_options.rb (+37 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/distributor/test_options.rb    2014-02-03 13:00:20 +0900 (bba58e9)
@@ -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
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index