Class: Bosh::Agent::HTTPHandler
Constant Summary
Constants inherited
from Handler
Bosh::Agent::Handler::KILL_AGENT_THREAD_TIMEOUT_ON_ERRORS, Bosh::Agent::Handler::KILL_AGENT_THREAD_TIMEOUT_ON_RESTART, Bosh::Agent::Handler::MAX_NATS_RETRIES, Bosh::Agent::Handler::NATS_MAX_PAYLOAD_SIZE, Bosh::Agent::Handler::NATS_RECONNECT_SLEEP
Instance Attribute Summary
Attributes inherited from Handler
#current_long_running_task, #nats, #processors
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Handler
#current_long_running_task?, #decrypt, #encrypt, #find_message_processors, #generate_agent_task_id, #handle_cancel_task, #handle_get_task, #handle_shutdown, #initialize, #kill_main_thread_in, #log_encryption_error, #lookup, #lookup_encryption_handler, #on_connect, #post_prepare_network_change, #process, #process_in_thread, #process_long_running, #setup_heartbeats, #setup_syslog_monitor
Class Method Details
12
13
14
|
# File 'lib/bosh_agent/http_handler.rb', line 12
def self.start
new.start
end
|
Instance Method Details
#handle_message(json) ⇒ Object
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
78
|
# File 'lib/bosh_agent/http_handler.rb', line 51
def handle_message(json)
result = {}
result.extend(MonitorMixin)
cond = result.new_cond
timeout_time = Time.now.to_f + 30
@callback = Proc.new do |response|
result.synchronize do
result.merge!(response)
cond.signal
end
end
super(json)
result.synchronize do
while result.empty?
timeout = timeout_time - Time.now.to_f
unless timeout > 0
raise "Timed out"
end
cond.wait(timeout)
end
end
result
end
|
#publish(reply_to, payload, &blk) ⇒ Object
80
81
82
83
84
|
# File 'lib/bosh_agent/http_handler.rb', line 80
def publish(reply_to, payload, &blk)
response = @callback.call(payload)
blk.call if blk
response
end
|
46
47
48
49
|
# File 'lib/bosh_agent/http_handler.rb', line 46
def shutdown
@logger.info("Exit")
@server.stop
end
|
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/bosh_agent/http_handler.rb', line 16
def start
handler = self
uri = URI.parse(Config.mbus)
@server = Thin::Server.new(uri.host, uri.port) do
use Rack::CommonLogger
if uri.userinfo
use Rack::Auth::Basic do |user, password|
"#{user}:#{password}" == uri.userinfo
end
end
map "/" do
run AgentController.new(handler)
end
end
certificate = Bosh::Ssl::Certificate.new('agent.key',
'agent.cert',
uri.host
).load_or_create
@server.ssl = true
@server.ssl_options = {:ssl_verify => false, :ssl_key_file => certificate.key_path, :ssl_cert_file => certificate.certificate_path }
@server.start!
end
|