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

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Feb 3 12:41:14 JST 2014


Kouhei Sutou	2014-02-03 12:41:14 +0900 (Mon, 03 Feb 2014)

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

  Message:
    Make collector plugins customizable in catalog.json
    
    You can specify collector plugins at the top level:
    
        {
          ...,
          "collector": {
            "plugins": ["basic", "search"]
          }
        }

  Copied files:
    lib/droonga/collector_options.rb
      (from lib/droonga/collector.rb)
    test/unit/collector/test_options.rb
      (from lib/droonga/collector.rb)
  Modified files:
    lib/droonga/catalog/base.rb
    lib/droonga/collector.rb
    lib/droonga/dispatcher.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:24:41 +0900 (188da9f)
+++ lib/droonga/catalog/base.rb    2014-02-03 12:41:14 +0900 (89b6842)
@@ -18,6 +18,7 @@ require "zlib"
 require "droonga/message_processing_error"
 require "droonga/input_adapter_options"
 require "droonga/output_adapter_options"
+require "droonga/collector_options"
 
 module Droonga
   module Catalog
@@ -144,6 +145,10 @@ module Droonga
         OutputAdapterOptions.new(@data["output_adapter"])
       end
 
+      def collector_options
+        CollectorOptions.new(@data["collector"])
+      end
+
       private
       def compute_total_weight(dataset)
         dataset["ring"].reduce(0) do |result, zone|

  Modified: lib/droonga/collector.rb (+3 -2)
===================================================================
--- lib/droonga/collector.rb    2014-02-03 12:24:41 +0900 (2c3b682)
+++ lib/droonga/collector.rb    2014-02-03 12:41:14 +0900 (8450aca)
@@ -22,8 +22,9 @@ module Droonga
   class Collector
     include Pluggable
 
-    def initialize
-      load_plugins(["basic", "search"]) # TODO: make customizable
+    def initialize(options)
+      @options = options
+      load_plugins(@options.plugins)
     end
 
     private

  Copied: lib/droonga/collector_options.rb (+6 -18) 64%
===================================================================
--- lib/droonga/collector.rb    2014-02-03 12:24:41 +0900 (2c3b682)
+++ lib/droonga/collector_options.rb    2014-02-03 12:41:14 +0900 (d6de95b)
@@ -1,6 +1,4 @@
-# -*- coding: utf-8 -*-
-#
-# Copyright (C) 2013 Droonga Project
+# 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
@@ -15,24 +13,14 @@
 # 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/pluggable"
-require "droonga/collector_plugin"
-
 module Droonga
-  class Collector
-    include Pluggable
-
-    def initialize
-      load_plugins(["basic", "search"]) # TODO: make customizable
-    end
-
-    private
-    def instantiate_plugin(name)
-      CollectorPlugin.repository.instantiate(name)
+  class CollectorOptions
+    def initialize(data)
+      @data = data || {}
     end
 
-    def log_tag
-      "collector"
+    def plugins
+      @data["plugins"] || []
     end
   end
 end

  Modified: lib/droonga/dispatcher.rb (+1 -1)
===================================================================
--- lib/droonga/dispatcher.rb    2014-02-03 12:24:41 +0900 (27878b4)
+++ lib/droonga/dispatcher.rb    2014-02-03 12:41:14 +0900 (4cf577d)
@@ -60,7 +60,7 @@ module Droonga
       @forwarder = Forwarder.new(@loop)
       @replier = Replier.new(@forwarder)
       @distributor = Distributor.new(self, @options)
-      @collector = Collector.new
+      @collector = Collector.new(Droonga.catalog.collector_options)
     end
 
     def start

  Modified: sample/cluster/catalog.json (+3 -0)
===================================================================
--- sample/cluster/catalog.json    2014-02-03 12:24:41 +0900 (f447386)
+++ sample/cluster/catalog.json    2014-02-03 12:41:14 +0900 (186e732)
@@ -43,5 +43,8 @@
   },
   "output_adapter": {
     "plugins": ["crud", "groonga"]
+  },
+  "collector": {
+    "plugins": ["basic", "search"]
   }
 }

  Modified: test/command/config/default/catalog.json (+3 -0)
===================================================================
--- test/command/config/default/catalog.json    2014-02-03 12:24:41 +0900 (88eb533)
+++ test/command/config/default/catalog.json    2014-02-03 12:41:14 +0900 (c5cade1)
@@ -60,5 +60,8 @@
   },
   "output_adapter": {
     "plugins": ["crud", "groonga"]
+  },
+  "collector": {
+    "plugins": ["basic", "search"]
   }
 }

  Modified: test/unit/catalog/test_version1.rb (+26 -0)
===================================================================
--- test/unit/catalog/test_version1.rb    2014-02-03 12:24:41 +0900 (6191e00)
+++ test/unit/catalog/test_version1.rb    2014-02-03 12:41:14 +0900 (d2eadc5)
@@ -213,4 +213,30 @@ class CatalogTest < Test::Unit::TestCase
       end
     end
   end
+
+  class CollectorOptionsTest < self
+    def options(data)
+      catalog = create_catalog(minimum_data.merge(data), "base-path")
+      catalog.collector_options
+    end
+
+    class PluginsTest < self
+      def plugins(data)
+        options(data).plugins
+      end
+
+      def test_nothing
+        assert_equal([], plugins({}))
+      end
+
+      def test_collector
+        data = {
+          "collector" => {
+            "plugins" => ["basic", "search"],
+          }
+        }
+        assert_equal(["basic", "search"], plugins(data))
+      end
+    end
+  end
 end

  Copied: test/unit/collector/test_options.rb (+14 -15) 60%
===================================================================
--- lib/droonga/collector.rb    2014-02-03 12:24:41 +0900 (2c3b682)
+++ test/unit/collector/test_options.rb    2014-02-03 12:41:14 +0900 (6dbb935)
@@ -1,6 +1,4 @@
-# -*- coding: utf-8 -*-
-#
-# Copyright (C) 2013 Droonga Project
+# 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
@@ -15,24 +13,25 @@
 # 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/pluggable"
-require "droonga/collector_plugin"
+require "droonga/collector_options"
 
-module Droonga
-  class Collector
-    include Pluggable
+class CollectorOptionsTest < Test::Unit::TestCase
+  def options(data)
+    Droonga::CollectorOptions.new(data)
+  end
 
-    def initialize
-      load_plugins(["basic", "search"]) # TODO: make customizable
+  class PluginsTest < self
+    def plugins(data)
+      options(data).plugins
     end
 
-    private
-    def instantiate_plugin(name)
-      CollectorPlugin.repository.instantiate(name)
+    def test_nothing
+      assert_equal([], plugins({}))
     end
 
-    def log_tag
-      "collector"
+    def test_have_values
+      assert_equal(["basic", "search"],
+                   plugins("plugins" => ["basic", "search"]))
     end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



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