Class: Fluent::BigObjectOutput_AVRO::TableElement
- Inherits:
-
Object
- Object
- Fluent::BigObjectOutput_AVRO::TableElement
- Includes:
- Configurable
- Defined in:
- lib/fluent/plugin/out_bigobject_avro.rb
Instance Attribute Summary collapse
-
#mpattern ⇒ Object
readonly
Returns the value of attribute mpattern.
Instance Method Summary collapse
- #configure(conf) ⇒ Object
-
#initialize(log, bo_hostname, bo_port) ⇒ TableElement
constructor
A new instance of TableElement.
-
#send_binary(chunk) ⇒ Object
Send data to Bigobject using binary AVRO.
- #to_s ⇒ Object
Constructor Details
#initialize(log, bo_hostname, bo_port) ⇒ TableElement
Returns a new instance of TableElement.
28 29 30 31 32 33 34 |
# File 'lib/fluent/plugin/out_bigobject_avro.rb', line 28 def initialize(log, bo_hostname, bo_port) super() @log = log @bo_hostname = bo_hostname @bo_port = bo_port @bo_url="http://#{@bo_hostname}:#{@bo_port}/cmd" end |
Instance Attribute Details
#mpattern ⇒ Object (readonly)
Returns the value of attribute mpattern.
26 27 28 |
# File 'lib/fluent/plugin/out_bigobject_avro.rb', line 26 def mpattern @mpattern end |
Instance Method Details
#configure(conf) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fluent/plugin/out_bigobject_avro.rb', line 36 def configure(conf) super @avro_schema = Avro::Schema.parse(File.open(@schema_file, "rb").read) @avro_writer = Avro::IO::DatumWriter.new(@avro_schema) @mpattern = Fluent::MatchPattern.create(pattern) @mapping = (@column_mapping==nil)? nil:parse_column_mapping(@column_mapping) @log.info("column mapping for #{pattern} - #{@mapping}") @format_proc = Proc.new { |record| if (@mapping==nil) record else new_record = {} @mapping.each { |k, c| new_record[c] = record[k] } new_record end } end |
#send_binary(chunk) ⇒ Object
Send data to Bigobject using binary AVRO
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/fluent/plugin/out_bigobject_avro.rb', line 59 def send_binary(chunk) buffer = StringIO.new() dw = Avro::DataFile::Writer.new(buffer, @avro_writer, @avro_schema) i=0 chunk.msgpack_each { |tag, time, data| data = @format_proc.call(data) dw<<data i+=1 } dw.flush begin socket = TCPSocket.open(@bo_hostname, @bo_port) begin #timeout=60 opt = [1, 60].pack('I!I!') # { int l_onoff; int l_linger; } socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, opt) opt = [60, 0].pack('L!L!') # struct timeval socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, opt) socket.write(buffer.string) ensure socket.close end rescue Exception => e @log.error(e.) raise "Failed to send_binary: #{e.message}" end @log.debug("sending #{i} rows to bigobject via avro") end |
#to_s ⇒ Object
92 93 94 |
# File 'lib/fluent/plugin/out_bigobject_avro.rb', line 92 def to_s "pattern:#{pattern}, column_mapping:#{column_mapping}" end |