fluent-plugin-droonga 0.9.0 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/Gemfile +8 -1
- data/fluent-plugin-droonga.gemspec +2 -2
- data/lib/droonga/adapter.rb +39 -0
- data/lib/droonga/adapter_runner.rb +99 -0
- data/lib/droonga/catalog/base.rb +11 -11
- data/lib/droonga/catalog/dataset.rb +54 -0
- data/lib/droonga/catalog/version1.rb +1 -1
- data/lib/droonga/collector.rb +5 -7
- data/lib/droonga/collector_plugin.rb +7 -7
- data/lib/droonga/command.rb +36 -0
- data/lib/droonga/{plugin/input_adapter/crud.rb → command_repository.rb} +14 -8
- data/lib/droonga/dispatcher.rb +86 -54
- data/lib/droonga/distributed_command_planner.rb +183 -0
- data/lib/droonga/distributor.rb +43 -17
- data/lib/droonga/handler.rb +13 -72
- data/lib/droonga/handler_message.rb +5 -5
- data/lib/droonga/handler_messenger.rb +4 -1
- data/lib/droonga/handler_plugin.rb +2 -2
- data/lib/droonga/handler_runner.rb +104 -0
- data/lib/droonga/input_message.rb +4 -4
- data/lib/droonga/legacy_pluggable.rb +66 -0
- data/lib/droonga/{input_adapter.rb → legacy_plugin.rb} +27 -22
- data/lib/droonga/{plugin_repository.rb → legacy_plugin_repository.rb} +2 -4
- data/lib/droonga/message_matcher.rb +101 -0
- data/lib/droonga/{input_adapter_plugin.rb → planner.rb} +14 -10
- data/lib/droonga/planner_plugin.rb +54 -0
- data/lib/droonga/pluggable.rb +9 -45
- data/lib/droonga/plugin.rb +9 -33
- data/lib/droonga/plugin/collector/basic.rb +2 -0
- data/lib/droonga/plugin/collector/search.rb +31 -37
- data/lib/droonga/plugin/{handler/groonga/table_remove.rb → metadata/adapter_message.rb} +23 -18
- data/lib/droonga/plugin/{handler/search.rb → metadata/handler_action.rb} +19 -15
- data/lib/droonga/plugin/metadata/input_message.rb +39 -0
- data/lib/droonga/plugin/planner/crud.rb +49 -0
- data/lib/droonga/plugin/{distributor → planner}/distributed_search_planner.rb +62 -70
- data/lib/droonga/plugin/{distributor → planner}/groonga.rb +11 -32
- data/lib/droonga/plugin/{distributor → planner}/search.rb +5 -5
- data/lib/droonga/plugin/{distributor → planner}/watch.rb +15 -6
- data/lib/droonga/plugin_loader.rb +10 -0
- data/lib/droonga/plugin_registerable.rb +34 -10
- data/lib/droonga/plugin_registry.rb +58 -0
- data/lib/droonga/plugins/crud.rb +124 -0
- data/lib/droonga/plugins/error.rb +50 -0
- data/lib/droonga/{output_adapter_plugin.rb → plugins/groonga.rb} +9 -13
- data/lib/droonga/plugins/groonga/column_create.rb +123 -0
- data/lib/droonga/plugins/groonga/generic_command.rb +65 -0
- data/lib/droonga/{plugin/output_adapter/groonga.rb → plugins/groonga/generic_response.rb} +16 -15
- data/lib/droonga/plugins/groonga/select.rb +124 -0
- data/lib/droonga/plugins/groonga/table_create.rb +106 -0
- data/lib/droonga/plugins/groonga/table_remove.rb +57 -0
- data/lib/droonga/plugins/search.rb +40 -0
- data/lib/droonga/plugins/watch.rb +156 -0
- data/lib/droonga/processor.rb +8 -10
- data/lib/droonga/searcher.rb +14 -4
- data/lib/droonga/searcher/mecab_filter.rb +67 -0
- data/lib/droonga/session.rb +5 -5
- data/lib/droonga/test.rb +1 -1
- data/lib/droonga/test/stub_handler_message.rb +1 -1
- data/lib/droonga/test/{stub_distributor.rb → stub_planner.rb} +1 -1
- data/lib/droonga/worker.rb +7 -8
- data/lib/fluent/plugin/out_droonga.rb +0 -1
- data/sample/cluster/catalog.json +2 -4
- data/sample/mecab_filter/data.grn +7 -0
- data/sample/mecab_filter/ddl.grn +7 -0
- data/sample/mecab_filter/search_with_mecab_filter.json +21 -0
- data/sample/mecab_filter/search_without_mecab_filter.json +21 -0
- data/test/command/config/default/catalog.json +2 -5
- data/test/command/suite/search/error/no-query.expected +13 -0
- data/test/command/suite/search/error/no-query.test +7 -0
- data/test/command/suite/search/error/unknown-source.expected +26 -0
- data/test/command/suite/watch/subscribe.expected +3 -3
- data/test/command/suite/watch/unsubscribe.expected +3 -3
- data/test/unit/catalog/test_dataset.rb +385 -0
- data/test/unit/catalog/test_version1.rb +111 -45
- data/test/unit/fixtures/catalog/version1.json +0 -3
- data/test/unit/helper.rb +2 -1
- data/test/unit/helper/distributed_search_planner_helper.rb +83 -0
- data/test/unit/plugin/collector/test_basic.rb +233 -376
- data/test/unit/plugin/collector/test_search.rb +8 -17
- data/test/unit/plugin/planner/search_planner/test_basic.rb +120 -0
- data/test/unit/plugin/planner/search_planner/test_group_by.rb +573 -0
- data/test/unit/plugin/planner/search_planner/test_output.rb +388 -0
- data/test/unit/plugin/planner/search_planner/test_sort_by.rb +938 -0
- data/test/unit/plugin/{distributor → planner}/test_search.rb +20 -75
- data/test/unit/{plugin/handler → plugins/crud}/test_add.rb +11 -11
- data/test/unit/plugins/groonga/select/test_adapter_input.rb +213 -0
- data/test/unit/{plugin/output_adapter/groonga/test_select.rb → plugins/groonga/select/test_adapter_output.rb} +12 -13
- data/test/unit/{plugin/handler → plugins}/groonga/test_column_create.rb +20 -5
- data/test/unit/{plugin/handler → plugins}/groonga/test_table_create.rb +5 -0
- data/test/unit/{plugin/handler → plugins}/groonga/test_table_remove.rb +8 -1
- data/test/unit/{plugin/handler → plugins}/test_groonga.rb +5 -5
- data/test/unit/{plugin/handler → plugins}/test_search.rb +21 -5
- data/test/unit/{plugin/handler → plugins}/test_watch.rb +29 -10
- data/{lib/droonga/command_mapper.rb → test/unit/test_command_repository.rb} +16 -22
- data/test/unit/{test_plugin.rb → test_legacy_plugin.rb} +3 -3
- data/test/unit/{test_plugin_repository.rb → test_legacy_plugin_repository.rb} +3 -3
- data/test/unit/test_message_matcher.rb +137 -0
- metadata +86 -66
- data/bin/grn2jsons +0 -82
- data/lib/droonga/distribution_planner.rb +0 -76
- data/lib/droonga/distributor_plugin.rb +0 -95
- data/lib/droonga/output_adapter.rb +0 -53
- data/lib/droonga/plugin/collector/groonga.rb +0 -83
- data/lib/droonga/plugin/distributor/crud.rb +0 -84
- data/lib/droonga/plugin/handler/add.rb +0 -109
- data/lib/droonga/plugin/handler/forward.rb +0 -75
- data/lib/droonga/plugin/handler/groonga.rb +0 -99
- data/lib/droonga/plugin/handler/groonga/column_create.rb +0 -106
- data/lib/droonga/plugin/handler/groonga/table_create.rb +0 -91
- data/lib/droonga/plugin/handler/watch.rb +0 -108
- data/lib/droonga/plugin/input_adapter/groonga.rb +0 -49
- data/lib/droonga/plugin/input_adapter/groonga/select.rb +0 -63
- data/lib/droonga/plugin/output_adapter/crud.rb +0 -51
- data/lib/droonga/plugin/output_adapter/groonga/select.rb +0 -54
- data/lib/groonga_command_converter.rb +0 -143
- data/sample/fluentd.conf +0 -8
- data/test/unit/plugin/distributor/test_search_planner.rb +0 -1102
- data/test/unit/plugin/input_adapter/groonga/test_select.rb +0 -248
- data/test/unit/test_command_mapper.rb +0 -44
- data/test/unit/test_groonga_command_converter.rb +0 -242
@@ -1,53 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
#
|
3
|
-
# Copyright (C) 2013 Droonga Project
|
4
|
-
#
|
5
|
-
# This library is free software; you can redistribute it and/or
|
6
|
-
# modify it under the terms of the GNU Lesser General Public
|
7
|
-
# License version 2.1 as published by the Free Software Foundation.
|
8
|
-
#
|
9
|
-
# This library is distributed in the hope that it will be useful,
|
10
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
-
# Lesser General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU Lesser General Public
|
15
|
-
# License along with this library; if not, write to the Free Software
|
16
|
-
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
-
|
18
|
-
require "droonga/pluggable"
|
19
|
-
require "droonga/output_adapter_plugin"
|
20
|
-
require "droonga/output_message"
|
21
|
-
|
22
|
-
module Droonga
|
23
|
-
class OutputAdapter
|
24
|
-
include Pluggable
|
25
|
-
|
26
|
-
def initialize(dispatcher, options={})
|
27
|
-
@dispatcher = dispatcher
|
28
|
-
load_plugins(options[:plugins] || [])
|
29
|
-
end
|
30
|
-
|
31
|
-
def adapt(message)
|
32
|
-
adapted_message = message
|
33
|
-
message["via"].reverse_each do |command|
|
34
|
-
@plugins.each do |plugin|
|
35
|
-
next unless plugin.processable?(command)
|
36
|
-
output_message = OutputMessage.new(adapted_message)
|
37
|
-
process(command, output_message)
|
38
|
-
adapted_message = output_message.adapted_message
|
39
|
-
end
|
40
|
-
end
|
41
|
-
adapted_message
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
def instantiate_plugin(name)
|
46
|
-
OutputAdapterPlugin.repository.instantiate(name, @dispatcher)
|
47
|
-
end
|
48
|
-
|
49
|
-
def log_tag
|
50
|
-
"output-adapter"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
#
|
3
|
-
# Copyright (C) 2014 Droonga Project
|
4
|
-
#
|
5
|
-
# This library is free software; you can redistribute it and/or
|
6
|
-
# modify it under the terms of the GNU Lesser General Public
|
7
|
-
# License version 2.1 as published by the Free Software Foundation.
|
8
|
-
#
|
9
|
-
# This library is distributed in the hope that it will be useful,
|
10
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
-
# Lesser General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU Lesser General Public
|
15
|
-
# License along with this library; if not, write to the Free Software
|
16
|
-
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
-
|
18
|
-
require "droonga/plugin/collector/basic"
|
19
|
-
|
20
|
-
module Droonga
|
21
|
-
class GroongaCollector < BasicCollector
|
22
|
-
repository.register("groonga", self)
|
23
|
-
|
24
|
-
command :collector_groonga_gather
|
25
|
-
def collector_groonga_gather(result)
|
26
|
-
collector_gather(result)
|
27
|
-
end
|
28
|
-
|
29
|
-
command :collector_groonga_reduce
|
30
|
-
def collector_groonga_reduce(request)
|
31
|
-
collector_reduce(request)
|
32
|
-
end
|
33
|
-
|
34
|
-
def reduce(deal, left_value, right_value)
|
35
|
-
reduced_value = nil
|
36
|
-
|
37
|
-
case deal["type"]
|
38
|
-
when "groonga_result"
|
39
|
-
#XXX how to merge multiple erros?
|
40
|
-
#XXX how to mix regular results and erros?
|
41
|
-
# reduced_value = merge_groonga_result(left_value, right_value)
|
42
|
-
reduced_value = left_value || right_value
|
43
|
-
else
|
44
|
-
reduced_value = super
|
45
|
-
end
|
46
|
-
|
47
|
-
reduced_value
|
48
|
-
end
|
49
|
-
|
50
|
-
def merge_groonga_result(left_value, right_value)
|
51
|
-
result = []
|
52
|
-
|
53
|
-
result << merge_groonga_header(left_value.shift, right_value.shift)
|
54
|
-
|
55
|
-
left_value.each_with_index do |left, index|
|
56
|
-
right = right_value[index]
|
57
|
-
result << reduce({ "type" => "and" }, left, right)
|
58
|
-
end
|
59
|
-
|
60
|
-
result
|
61
|
-
end
|
62
|
-
|
63
|
-
def merge_groonga_header(left_header, right_header)
|
64
|
-
status = [left_header.shift, right_header.shift].min
|
65
|
-
|
66
|
-
start_time = reduce({ "type" => "average" },
|
67
|
-
left_header.shift,
|
68
|
-
right_header.shift)
|
69
|
-
|
70
|
-
elapsed_time = reduce({ "type" => "average" },
|
71
|
-
left_header.shift,
|
72
|
-
right_header.shift)
|
73
|
-
|
74
|
-
#XXX we should merge error informations more smarter...
|
75
|
-
error_information = reduce({ "type" => "sum",
|
76
|
-
"limit" => UNLIMITED },
|
77
|
-
left_header,
|
78
|
-
right_header)
|
79
|
-
|
80
|
-
[status, start_time, elapsed_time] + error_information
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
#
|
3
|
-
# Copyright (C) 2013 Droonga Project
|
4
|
-
#
|
5
|
-
# This library is free software; you can redistribute it and/or
|
6
|
-
# modify it under the terms of the GNU Lesser General Public
|
7
|
-
# License version 2.1 as published by the Free Software Foundation.
|
8
|
-
#
|
9
|
-
# This library is distributed in the hope that it will be useful,
|
10
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
-
# Lesser General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU Lesser General Public
|
15
|
-
# License along with this library; if not, write to the Free Software
|
16
|
-
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
-
|
18
|
-
require "droonga/distributor_plugin"
|
19
|
-
|
20
|
-
module Droonga
|
21
|
-
class CRUDDistributor < Droonga::DistributorPlugin
|
22
|
-
repository.register("crud", self)
|
23
|
-
|
24
|
-
command :add
|
25
|
-
def add(message)
|
26
|
-
key = message["body"]["key"] || rand.to_s
|
27
|
-
scatter_all(message, key)
|
28
|
-
end
|
29
|
-
|
30
|
-
command :update
|
31
|
-
def update(message)
|
32
|
-
key = message["body"]["key"] || rand.to_s
|
33
|
-
scatter_all(message, key)
|
34
|
-
end
|
35
|
-
|
36
|
-
# TODO: What is this?
|
37
|
-
command :reset
|
38
|
-
def reset(message)
|
39
|
-
key = message["body"]["key"] || rand.to_s
|
40
|
-
scatter_all(message, key)
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
def scatterer(message, key)
|
45
|
-
scatterer = super
|
46
|
-
scatterer["outputs"] << "success"
|
47
|
-
scatterer["outputs"] << "errors"
|
48
|
-
scatterer
|
49
|
-
end
|
50
|
-
|
51
|
-
def reducer(message)
|
52
|
-
reducer = super
|
53
|
-
reducer["body"]["success"] = {
|
54
|
-
"success_reduced" => {
|
55
|
-
"type" => "and",
|
56
|
-
},
|
57
|
-
}
|
58
|
-
reducer["inputs"] << "success"
|
59
|
-
reducer["outputs"] << "success_reduced"
|
60
|
-
reducer["body"]["errors"] = {
|
61
|
-
"errors_reduced" => {
|
62
|
-
"type" => "sum",
|
63
|
-
"limit" => -1,
|
64
|
-
},
|
65
|
-
}
|
66
|
-
reducer["inputs"] << "errors"
|
67
|
-
reducer["outputs"] << "errors_reduced"
|
68
|
-
reducer
|
69
|
-
end
|
70
|
-
|
71
|
-
def gatherer(message)
|
72
|
-
gatherer = super
|
73
|
-
gatherer["body"]["success_reduced"] = {
|
74
|
-
"output" => "success",
|
75
|
-
}
|
76
|
-
gatherer["inputs"] << "success_reduced"
|
77
|
-
gatherer["body"]["errors_reduced"] = {
|
78
|
-
"output" => "errors",
|
79
|
-
}
|
80
|
-
gatherer["inputs"] << "errors_reduced"
|
81
|
-
gatherer
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
@@ -1,109 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
#
|
3
|
-
# Copyright (C) 2013 Droonga Project
|
4
|
-
#
|
5
|
-
# This library is free software; you can redistribute it and/or
|
6
|
-
# modify it under the terms of the GNU Lesser General Public
|
7
|
-
# License version 2.1 as published by the Free Software Foundation.
|
8
|
-
#
|
9
|
-
# This library is distributed in the hope that it will be useful,
|
10
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
-
# Lesser General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU Lesser General Public
|
15
|
-
# License along with this library; if not, write to the Free Software
|
16
|
-
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
-
|
18
|
-
require "groonga"
|
19
|
-
|
20
|
-
require "droonga/handler_plugin"
|
21
|
-
require "droonga/message_processing_error"
|
22
|
-
|
23
|
-
module Droonga
|
24
|
-
class AddHandler < Droonga::HandlerPlugin
|
25
|
-
repository.register("add", self)
|
26
|
-
|
27
|
-
class MissingTableParameter < BadRequest
|
28
|
-
def initialize
|
29
|
-
super("\"table\" must be specified.")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class MissingPrimaryKeyParameter < BadRequest
|
34
|
-
def initialize(table_name)
|
35
|
-
super("\"key\" must be specified. " +
|
36
|
-
"The table #{table_name.inspect} requires a primary key for a new record.")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class UnknownTable < NotFound
|
41
|
-
def initialize(table_name)
|
42
|
-
super("The table #{table_name.inspect} does not exist in the dataset.")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
class InvalidValue < BadRequest
|
47
|
-
def initialize(column, value, request)
|
48
|
-
super("The column #{column.inspect} cannot store the value #{value.inspect}.",
|
49
|
-
request)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
class UnknownColumn < NotFound
|
54
|
-
def initialize(column, table, request)
|
55
|
-
super("The column #{column.inspect} does not exist in the table #{table.inspect}.",
|
56
|
-
request)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
command :add
|
61
|
-
def add(message, messenger)
|
62
|
-
succeeded = process_add(message.request)
|
63
|
-
outputs = {
|
64
|
-
"success" => succeeded,
|
65
|
-
}
|
66
|
-
messenger.emit(outputs)
|
67
|
-
end
|
68
|
-
|
69
|
-
private
|
70
|
-
def process_add(request)
|
71
|
-
raise MissingTableParameter.new unless request.include?("table")
|
72
|
-
|
73
|
-
table = @context[request["table"]]
|
74
|
-
raise UnknownTable.new(request["table"]) unless table
|
75
|
-
|
76
|
-
if table.support_key?
|
77
|
-
unless request.include?("key")
|
78
|
-
raise MissingPrimaryKeyParameter.new(request["table"])
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
add_record(table, request)
|
83
|
-
true
|
84
|
-
end
|
85
|
-
|
86
|
-
def add_record(table, request)
|
87
|
-
record = nil
|
88
|
-
if table.support_key?
|
89
|
-
record = table.add(request["key"])
|
90
|
-
else
|
91
|
-
record = table.add
|
92
|
-
end
|
93
|
-
(request["values"] || []).each do |column, value|
|
94
|
-
begin
|
95
|
-
record[column] = value
|
96
|
-
rescue Groonga::InvalidArgument => error
|
97
|
-
record.delete if record.added?
|
98
|
-
raise InvalidValue.new(column, value, request)
|
99
|
-
rescue ArgumentError => error
|
100
|
-
record.delete if record.added?
|
101
|
-
raise InvalidValue.new(column, value, request)
|
102
|
-
rescue Groonga::NoSuchColumn => error
|
103
|
-
record.delete if record.added?
|
104
|
-
raise UnknownColumn.new(column, request["table"], request)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
#
|
3
|
-
# Copyright (C) 2013 Droonga Project
|
4
|
-
#
|
5
|
-
# This library is free software; you can redistribute it and/or
|
6
|
-
# modify it under the terms of the GNU Lesser General Public
|
7
|
-
# License version 2.1 as published by the Free Software Foundation.
|
8
|
-
#
|
9
|
-
# This library is distributed in the hope that it will be useful,
|
10
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
-
# Lesser General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU Lesser General Public
|
15
|
-
# License along with this library; if not, write to the Free Software
|
16
|
-
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
-
|
18
|
-
=begin
|
19
|
-
|
20
|
-
TODO: What is this?
|
21
|
-
|
22
|
-
require "droonga/legacy_plugin"
|
23
|
-
require "droonga/logger"
|
24
|
-
|
25
|
-
module Droonga
|
26
|
-
class MergeHandler < Droonga::LegacyPlugin
|
27
|
-
Droonga::LegacyPlugin.repository.register("forward", self)
|
28
|
-
|
29
|
-
CONFIG_FILE_PATH = 'config.json'
|
30
|
-
|
31
|
-
def handlable?(command)
|
32
|
-
true
|
33
|
-
end
|
34
|
-
|
35
|
-
def handle(command, request, *arguments)
|
36
|
-
destination = get_destination
|
37
|
-
post(request,
|
38
|
-
"to" => destination, "type" => command, "arguments" => arguments)
|
39
|
-
rescue => exception
|
40
|
-
Logger.error("error while handling #{command}",
|
41
|
-
request: request,
|
42
|
-
arguments: arguments,
|
43
|
-
exception: exception)
|
44
|
-
end
|
45
|
-
|
46
|
-
def get_destination
|
47
|
-
loop do
|
48
|
-
refresh_config
|
49
|
-
if @config && @config["forward"]
|
50
|
-
path = @context.database.path
|
51
|
-
destination = @config["forward"][path]
|
52
|
-
return destination unless destination.nil? || destination.empty?
|
53
|
-
end
|
54
|
-
sleep 5
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def refresh_config
|
59
|
-
unless File.exists?(CONFIG_FILE_PATH)
|
60
|
-
@config = nil
|
61
|
-
return
|
62
|
-
end
|
63
|
-
mtime = File.mtime(CONFIG_FILE_PATH)
|
64
|
-
return if @config_mtime == mtime
|
65
|
-
open(CONFIG_FILE_PATH) do |file|
|
66
|
-
@config = JSON.parse(file.read)
|
67
|
-
end
|
68
|
-
@config_mtime = mtime
|
69
|
-
rescue => exception
|
70
|
-
Logger.error("error while refreshing config", exception: exception)
|
71
|
-
@config = nil
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
=end
|
@@ -1,99 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
#
|
3
|
-
# Copyright (C) 2013 Droonga Project
|
4
|
-
#
|
5
|
-
# This library is free software; you can redistribute it and/or
|
6
|
-
# modify it under the terms of the GNU Lesser General Public
|
7
|
-
# License version 2.1 as published by the Free Software Foundation.
|
8
|
-
#
|
9
|
-
# This library is distributed in the hope that it will be useful,
|
10
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
-
# Lesser General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU Lesser General Public
|
15
|
-
# License along with this library; if not, write to the Free Software
|
16
|
-
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
-
|
18
|
-
require "groonga"
|
19
|
-
|
20
|
-
require "droonga/handler_plugin"
|
21
|
-
|
22
|
-
module Droonga
|
23
|
-
class GroongaHandler < Droonga::HandlerPlugin
|
24
|
-
repository.register("groonga", self)
|
25
|
-
|
26
|
-
command :table_create
|
27
|
-
def table_create(message, messenger)
|
28
|
-
command = TableCreate.new(@context)
|
29
|
-
outputs = format_outputs(command.execute(message.request))
|
30
|
-
messenger.emit(outputs)
|
31
|
-
end
|
32
|
-
|
33
|
-
command :table_remove
|
34
|
-
def table_remove(message, messenger)
|
35
|
-
command = TableRemove.new(@context)
|
36
|
-
outputs = format_outputs(command.execute(message.request))
|
37
|
-
messenger.emit(outputs)
|
38
|
-
end
|
39
|
-
|
40
|
-
command :column_create
|
41
|
-
def column_create(message, messenger)
|
42
|
-
command = ColumnCreate.new(@context)
|
43
|
-
outputs = format_outputs(command.execute(message.request))
|
44
|
-
messenger.emit(outputs)
|
45
|
-
end
|
46
|
-
|
47
|
-
def prefer_synchronous?(command)
|
48
|
-
return true
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
def format_outputs(result)
|
53
|
-
{
|
54
|
-
"result" => result,
|
55
|
-
}
|
56
|
-
end
|
57
|
-
|
58
|
-
module Status
|
59
|
-
SUCCESS = 0
|
60
|
-
INVALID_ARGUMENT = -22
|
61
|
-
end
|
62
|
-
|
63
|
-
class Command
|
64
|
-
class CommandError < StandardError
|
65
|
-
attr_reader :status, :message, :result
|
66
|
-
|
67
|
-
def initialize(params={})
|
68
|
-
@status = params[:status]
|
69
|
-
@message = params[:message]
|
70
|
-
@result = params[:result]
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def initialize(context)
|
75
|
-
@context = context
|
76
|
-
end
|
77
|
-
|
78
|
-
def execute(request)
|
79
|
-
@start_time = Time.now.to_f
|
80
|
-
result = process_request(request)
|
81
|
-
[header(Status::SUCCESS), result]
|
82
|
-
rescue CommandError => error
|
83
|
-
[header(error.status, error.message), error.result]
|
84
|
-
end
|
85
|
-
|
86
|
-
private
|
87
|
-
def header(return_code, error_message="")
|
88
|
-
elapsed_time = Time.now.to_f - @start_time
|
89
|
-
header = [return_code, @start_time, elapsed_time]
|
90
|
-
header.push(error_message) unless error_message.empty?
|
91
|
-
header
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
require "droonga/plugin/handler/groonga/table_create"
|
98
|
-
require "droonga/plugin/handler/groonga/table_remove"
|
99
|
-
require "droonga/plugin/handler/groonga/column_create"
|