@@ -427,20 +427,22 @@ module TraceHelper = struct
427427 Tracing_propagator.Propagator.Http. inject_into trace_context
428428end
429429
430+ let choose_rpc () =
431+ let open Xmlrpc_client in
432+ if ! Xapi_globs. use_xmlrpc then
433+ (XMLRPC_protocol. rpc, " /" )
434+ else
435+ (JSONRPC_protocol. rpc, " /jsonrpc" )
436+
430437(* Note that both this and `make_timeboxed_rpc` are almost always
431438 * partially applied, returning a function of type 'Rpc.request -> Rpc.response'.
432439 * The body is therefore not evaluated until the RPC call is actually being
433440 * made. *)
434- let make_rpc ~__context rpc : Rpc.response =
435- let subtask_of = Ref. string_of ( Context. get_task_id __context) in
441+ let make_rpc' ~ subtask_of ? task_id ~__context rpc : Rpc.response =
442+ let subtask_of = Ref. string_of subtask_of in
436443 let open Xmlrpc_client in
437444 let tracing = Context. set_client_span __context in
438- let dorpc, path =
439- if ! Xapi_globs. use_xmlrpc then
440- (XMLRPC_protocol. rpc, " /" )
441- else
442- (JSONRPC_protocol. rpc, " /jsonrpc" )
443- in
445+ let dorpc, path = choose_rpc () in
444446 let http = xmlrpc ~subtask_of ~version: " 1.1" path in
445447 let http = TraceHelper. inject_span_into_req tracing http in
446448 let transport =
@@ -449,25 +451,27 @@ let make_rpc ~__context rpc : Rpc.response =
449451 else
450452 SSL
451453 ( SSL. make ~use_stunnel_cache: true ~verify_cert: (Stunnel_client. pool () )
454+ ?task_id:(Option. map Ref. string_of task_id)
452455 ()
453456 , Pool_role. get_master_address ()
454457 , ! Constants. https_port
455458 )
456459 in
457460 dorpc ~srcstr: " xapi" ~dststr: " xapi" ~transport ~http rpc
458461
462+ (* erase optional labeled arguments for partial applications to work *)
463+ let make_rpc ~__context rpc =
464+ make_rpc' ~subtask_of: (Context. get_task_id __context) ~__context rpc
465+
459466let make_timeboxed_rpc ~__context timeout rpc : Rpc.response =
460- let subtask_of = Ref. string_of ( Context. get_task_id __context) in
467+ let subtask_of = Context. get_task_id __context in
461468 Server_helpers. exec_with_new_task " timeboxed_rpc"
462469 ~subtask_of: (Context. get_task_id __context) (fun __context ->
463470 (* Note we need a new task here because the 'resources' (including stunnel pid) are
464471 * associated with the task. To avoid conflating the stunnel with any real resources
465472 * the task has acquired we make a new one specifically for the stunnel pid *)
466- let open Xmlrpc_client in
467- let tracing = Context. set_client_span __context in
468- let http = xmlrpc ~subtask_of ~version: " 1.1" " /" in
469- let http = TraceHelper. inject_span_into_req tracing http in
470473 let task_id = Context. get_task_id __context in
474+
471475 let cancel () =
472476 let resources =
473477 Locking_helpers.Thread_state. get_acquired_resources_by_task task_id
@@ -477,20 +481,9 @@ let make_timeboxed_rpc ~__context timeout rpc : Rpc.response =
477481 let module Scheduler = Xapi_stdext_threads_scheduler. Scheduler in
478482 Scheduler. add_to_queue (Ref. string_of task_id) Scheduler. OneShot timeout
479483 cancel ;
480- let transport =
481- if Pool_role. is_master () then
482- Unix Xapi_globs. unix_domain_socket
483- else
484- SSL
485- ( SSL. make ~verify_cert: (Stunnel_client. pool () )
486- ~use_stunnel_cache: true ~task_id: (Ref. string_of task_id) ()
487- , Pool_role. get_master_address ()
488- , ! Constants. https_port
489- )
490- in
491- let result =
492- XMLRPC_protocol. rpc ~srcstr: " xapi" ~dststr: " xapi" ~transport ~http rpc
493- in
484+
485+ let result = make_rpc' ~subtask_of ~task_id ~__context rpc in
486+
494487 Scheduler. remove_from_queue (Ref. string_of task_id) ;
495488 result
496489 )
@@ -525,6 +518,10 @@ let make_remote_rpc_of_url ~verify_cert ~srcstr ~dststr (url, pool_secret) call
525518 http
526519 in
527520 let transport = transport_of_url ~verify_cert url in
521+ (* we should determine the protocol based on Content-type, not the URL,
522+ but since we currently only use the URL to determine the protocol:
523+ keep this as XMLRPC for now, because we don't have JSONRPC duplicates for
524+ all handlers *)
528525 XMLRPC_protocol. rpc ~transport ~srcstr ~dststr ~http call
529526
530527(* This one uses rpc-light *)
@@ -535,9 +532,10 @@ let make_remote_rpc ?(verify_cert = Stunnel_client.pool ()) ~__context
535532 SSL (SSL. make ~verify_cert () , remote_address, ! Constants. https_port)
536533 in
537534 let tracing = Context. tracing_of __context in
538- let http = xmlrpc ~version: " 1.0" " /" in
535+ let dorpc, path = choose_rpc () in
536+ let http = xmlrpc ~version: " 1.0" path in
539537 let http = TraceHelper. inject_span_into_req tracing http in
540- XMLRPC_protocol. rpc ~srcstr: " xapi" ~dststr: " remote_xapi" ~transport ~http xml
538+ dorpc ~srcstr: " xapi" ~dststr: " remote_xapi" ~transport ~http xml
541539
542540(* Helper type for an object which may or may not be in the local database. *)
543541type 'a api_object =
@@ -611,10 +609,9 @@ let call_emergency_mode_functions hostname f =
611609 , ! Constants. https_port
612610 )
613611 in
614- let http = xmlrpc ~version: " 1.0" " /" in
615- let rpc =
616- XMLRPC_protocol. rpc ~srcstr: " xapi" ~dststr: " xapi" ~transport ~http
617- in
612+ let dorpc, path = choose_rpc () in
613+ let http = xmlrpc ~version: " 1.0" path in
614+ let rpc = dorpc ~srcstr: " xapi" ~dststr: " xapi" ~transport ~http in
618615 let session_id =
619616 Client.Client.Session. slave_local_login ~rpc
620617 ~psecret: (Xapi_globs. pool_secret () )
0 commit comments