Class: Fluent::Plugin::GcloudPubSubInput::RPCServlet

Inherits:
WEBrick::HTTPServlet::AbstractServlet
  • Object
show all
Defined in:
lib/fluent/plugin/in_gcloud_pubsub.rb

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Constructor Details

#initialize(server, plugin) ⇒ RPCServlet

Returns a new instance of RPCServlet.



59
60
61
62
# File 'lib/fluent/plugin/in_gcloud_pubsub.rb', line 59

def initialize(server, plugin)
  super
  @plugin = plugin
end

Instance Method Details

#do_GET(req, res) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/fluent/plugin/in_gcloud_pubsub.rb', line 64

def do_GET(req, res)
  begin
    code, header, body = process(req, res)
  rescue
    code, header, body = render_json(500, {
        'ok' => false,
        'message' => 'Internal Server Error',
        'error' => "#{$!}",
        'backtrace'=> $!.backtrace
    })
  end

  res.status = code
  header.each_pair {|k,v|
    res[k] = v
  }
  res.body = body
end

#process(req, res) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/fluent/plugin/in_gcloud_pubsub.rb', line 87

def process(req, res)
  ret = {'ok' => true}
  case req.path_info
  when '/stop'
    @plugin.stop_pull
  when '/start'
    @plugin.start_pull
  when '/status'
    ret['status'] = @plugin.status_of_pull
  else
    raise Error.new "Invalid path_info: #{req.path_info}"
  end
  render_json(200, ret)
end

#render_json(code, obj) ⇒ Object



83
84
85
# File 'lib/fluent/plugin/in_gcloud_pubsub.rb', line 83

def render_json(code, obj)
  [code, {'Content-Type' => 'application/json'}, obj.to_json]
end