32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/fluent/plugin_helper/storage.rb', line 32
def storage_create(usage: '', type: nil, conf: nil, default_type: nil)
if conf && conf.respond_to?(:arg) && !conf.arg.empty?
usage = conf.arg
end
if !usage.empty? && usage !~ /^[a-zA-Z][-_.a-zA-Z0-9]*$/
raise Fluent::ConfigError, "Argument in <storage ARG> uses invalid characters: '#{usage}'"
end
s = @_storages[usage]
if s && s.running
return s.storage
elsif s
else type = if type
type
elsif conf && conf.respond_to?(:[])
raise Fluent::ConfigError, "@type is required in <storage>" unless conf['@type']
conf['@type']
elsif default_type
default_type
else
raise ArgumentError, "BUG: both type and conf are not specified"
end
storage = Plugin.new_storage(type, parent: self)
config = case conf
when Fluent::Config::Element
conf
when Hash
conf = Hash[conf.map{|k,v| [k.to_s, v]}]
Fluent::Config::Element.new('storage', usage, conf, [])
when nil
Fluent::Config::Element.new('storage', usage, {'@type' => type}, [])
else
raise ArgumentError, "BUG: conf must be a Element, Hash (or unspecified), but '#{conf.class}'"
end
storage.configure(config)
if @_storages_started
storage.start
end
s = @_storages[usage] = StorageState.new(wrap_instance(storage), false)
end
s.storage
end
|