Class: Fluent::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.



38
39
40
41
# File 'lib/fluent/plugin/in_gcloud_pubsub.rb', line 38

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

Instance Method Details

#do_GET(req, res) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fluent/plugin/in_gcloud_pubsub.rb', line 43

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



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fluent/plugin/in_gcloud_pubsub.rb', line 66

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

#render_json(code, obj) ⇒ Object



62
63
64
# File 'lib/fluent/plugin/in_gcloud_pubsub.rb', line 62

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