| Class | Dsadmin::BackendInterface |
| In: |
lib/dsadmin/backend_interface.rb
|
| Parent: | Object |
Class for interfacing to a particular backend (admind) instance. Usually you will create one BackendInterface instance per admind instance you want to connect to, and use that from all threads.
# File lib/dsadmin/backend_interface.rb, line 90
90: def initialize(host, port, callerid = nil, token = nil)
91: @host = host
92: @port = port.to_i
93: @callerid = callerid
94: @auth_token = token
95: end
Call the backend with the given request, and return the response
# File lib/dsadmin/backend_interface.rb, line 36
36: def call(request)
37: assertKindOf(Request, request)
38:
39: sock = nil
40:
41: begin
42: begin
43: sock = new_connection
44: rescue
45: log.warning("Could not establish connection to #{@host}:#{@port}")
46: return Response::TEMP_UNAVAILABLE
47: end
48:
49: sock.write(request.to_yaml)
50: sock.close_write
51: res = Response.from_yaml(sock.read.to_s)
52: rescue ArgumentError => e
53: log.bug(e)
54: return Response::BAD_BACKEND_ANSWER
55: ensure
56: sock.close() unless(sock.nil? || sock.closed?)
57: end
58:
59: return res
60: end
Call the backend with the given request (using the security token for admind-to-admind communication), and return the response
# File lib/dsadmin/backend_interface.rb, line 65
65: def call_internal(controller, action, data = Hash.new)
66: requireNotNil(@auth_token)
67: requireNotNil(@callerid)
68: req = Request.new_internal(controller, action, @callerid, @auth_token, data)
69: call(req)
70: end
Call the backend with the given request, and return the response
# File lib/dsadmin/backend_interface.rb, line 73
73: def call_with_user(controller, action, username, password, data = Hash.new)
74: req = Request.new_client(controller, action, username, password, data)
75: call(req)
76: end