@@ -19,6 +19,16 @@ module D = Debug.Make (struct let name = "observer_interface" end)
1919
2020open D
2121
22+ let service_name = " observer"
23+
24+ let queue_name = Xcp_service. common_prefix ^ service_name
25+
26+ let default_sockets_dir = " /var/lib/xcp"
27+
28+ let default_path = Filename. concat default_sockets_dir service_name
29+
30+ let uri () = " file:" ^ default_path
31+
2232module Errors = struct
2333 type error =
2434 | Internal_error of string
@@ -148,3 +158,107 @@ module ObserverAPI (R : RPC) = struct
148158 declare " Observer.set_compress_tracing_files" []
149159 (dbg_p @-> bool_p @-> returning unit_p err)
150160end
161+
162+ module type Server_impl = sig
163+ type context = unit
164+
165+ val create :
166+ context
167+ -> dbg :debug_info
168+ -> uuid :string
169+ -> name_label :string
170+ -> attributes :(string * string ) list
171+ -> endpoints :string list
172+ -> enabled :bool
173+ -> unit
174+
175+ val destroy : context -> dbg :debug_info -> uuid :string -> unit
176+
177+ val set_enabled :
178+ context -> dbg :debug_info -> uuid :string -> enabled :bool -> unit
179+
180+ val set_attributes :
181+ context
182+ -> dbg :debug_info
183+ -> uuid :string
184+ -> attributes :(string * string ) list
185+ -> unit
186+
187+ val set_endpoints :
188+ context -> dbg :debug_info -> uuid :string -> endpoints :string list -> unit
189+
190+ val init : context -> dbg :debug_info -> unit
191+
192+ val set_trace_log_dir : context -> dbg :debug_info -> dir :string -> unit
193+
194+ val set_export_interval : context -> dbg :debug_info -> interval :float -> unit
195+
196+ val set_max_spans : context -> dbg :debug_info -> spans :int -> unit
197+
198+ val set_max_traces : context -> dbg :debug_info -> traces :int -> unit
199+
200+ val set_max_file_size : context -> dbg :debug_info -> file_size :int -> unit
201+
202+ val set_host_id : context -> dbg :debug_info -> host_id :string -> unit
203+
204+ val set_compress_tracing_files :
205+ context -> dbg :debug_info -> enabled :bool -> unit
206+ end
207+
208+ module Server (Impl : Server_impl ) () = struct
209+ module S = ObserverAPI (Idl.Exn. GenServer () )
210+
211+ let _ =
212+ S. create (fun dbg uuid name_label attributes endpoints enabled ->
213+ Impl. create () ~dbg ~uuid ~name_label ~attributes ~endpoints ~enabled
214+ ) ;
215+ S. destroy (fun dbg uuid -> Impl. destroy () ~dbg ~uuid ) ;
216+ S. set_enabled (fun dbg uuid enabled ->
217+ Impl. set_enabled () ~dbg ~uuid ~enabled
218+ ) ;
219+ S. set_attributes (fun dbg uuid attributes ->
220+ Impl. set_attributes () ~dbg ~uuid ~attributes
221+ ) ;
222+ S. set_endpoints (fun dbg uuid endpoints ->
223+ Impl. set_endpoints () ~dbg ~uuid ~endpoints
224+ ) ;
225+ S. init (fun dbg -> Impl. init () ~dbg ) ;
226+ S. set_trace_log_dir (fun dbg dir -> Impl. set_trace_log_dir () ~dbg ~dir ) ;
227+ S. set_export_interval (fun dbg interval ->
228+ Impl. set_export_interval () ~dbg ~interval
229+ ) ;
230+ S. set_max_spans (fun dbg spans -> Impl. set_max_spans () ~dbg ~spans ) ;
231+ S. set_max_traces (fun dbg traces -> Impl. set_max_traces () ~dbg ~traces ) ;
232+ S. set_max_file_size (fun dbg file_size ->
233+ Impl. set_max_file_size () ~dbg ~file_size
234+ ) ;
235+ S. set_host_id (fun dbg host_id -> Impl. set_host_id () ~dbg ~host_id ) ;
236+ S. set_compress_tracing_files (fun dbg enabled ->
237+ Impl. set_compress_tracing_files () ~dbg ~enabled
238+ )
239+
240+ (* Bind all *)
241+ let process call = Idl.Exn. server S. implementation call
242+ end
243+
244+ let rec retry_econnrefused f =
245+ try f () with
246+ | Unix. Unix_error (Unix. ECONNREFUSED, "connect" , _ ) ->
247+ (* debug "Caught ECONNREFUSED; retrying in 5s"; *)
248+ Thread. delay 5. ; retry_econnrefused f
249+ | e ->
250+ (* error "Caught %s: does the observer service need restarting?"
251+ (Printexc.to_string e); *)
252+ raise e
253+
254+ module Client = ObserverAPI (Idl.Exn. GenClient (struct
255+ open Xcp_client
256+
257+ let rpc call =
258+ retry_econnrefused (fun () ->
259+ if ! use_switch then
260+ json_switch_rpc queue_name call
261+ else
262+ xml_http_rpc ~srcstr: (get_user_agent () ) ~dststr: queue_name uri call
263+ )
264+ end ))
0 commit comments