text
stringlengths
12
786k
let oc = open_out_bin dest_file in input_lines ic oc ; close_in ic ; close_out oc ; ;
let dygraphs_date_axis_label_formatter : unit -> Js . date Js . t -> Granularity . t -> Options . Opts . t -> Js . js_string Js . t = fun ( ) -> Js . Unsafe . pure_js_expr { | Dygraph . dateAxisLabelFormatter } | ; ;
let dygraphs_number_axis_label_formatter : unit -> Js . number Js . t -> Granularity . t -> Options . Opts . t -> Js . js_string Js . t = fun ( ) -> Js . Unsafe . pure_js_expr { | Dygraph . numberAxisLabelFormatter } | ; ;
let default_axis_label_formatter x gran opts = match x with | ` number x -> let number = Js . number_of_float x in dygraphs_number_axis_label_formatter ( ) number gran opts |> Js . to_string | ` date d -> dygraphs_date_axis_label_formatter ( ) d gran opts |> Js . to_string ; ;
let round_time_nearest_ms time ~ zone = let date , ofday = Time_ns . to_date_ofday time ~ zone in let span = Time_ns . Ofday . to_span_since_start_of_day ofday in let ms = Time_ns . Span . to_ms span |> Float . iround_nearest_exn in let ofday = Time_ns . Span . of_int_ms ms |> Time_ns . Ofday . of_span_since_start_of_day_exn in Time_ns . of_date_ofday ~ zone date ofday ; ;
let default_value_formatter ~ zone ms_since_epoch = let time = Time_ns . of_span_since_epoch ( Time_ns . Span . of_ms ms_since_epoch ) in Time_ns . to_string_trimmed ( round_time_nearest_ms time ~ zone ) ~ zone ; ;
type t = { time_to_x_value : Time_ns . t -> Time_ns . t ; x_value_to_time : Time_ns . t -> Time_ns . t ; value_formatter : float -> Options . Opts . t -> string ; axis_label_formatter : Number_or_js_date . t -> Granularity . t -> Options . Opts . t -> string }
module Time_mapping = struct module Time_ns = struct include Time_ns let to_float t = Span . to_ns ( to_span_since_epoch t ) let of_float f = of_span_since_epoch ( Span . of_ns f ) let t_of_sexp = Alternate_sexp . t_of_sexp let sexp_of_t = Alternate_sexp . sexp_of_t end include Piecewise_linear_kernel . Make_invertible ( Time_ns ) ( Time_ns ) let create ~ start_time ~ end_time ~ zone ~ ofday_knots ~ date_to_weight : t = let start_date = Time_ns . to_date start_time ~ zone in let end_date = Time_ns . to_date end_time ~ zone in let dates = Date . dates_between ~ min : start_date ~ max : end_date in let time date hr min = Time_ns . of_date_ofday ~ zone date ( Time_ns . Ofday . create ~ hr ~ min ( ) ) in let start_time = time start_date 0 0 in let knots = List . fold_map ~ init : 0 . dates ~ f ( : fun acc date -> let weight = date_to_weight date in let knots = List . map ofday_knots ~ f ( : fun ( ofday , pct ) -> Time_ns . of_date_ofday ~ zone date ofday , acc . + ( weight . * pct ) ) in let acc = acc . + weight in acc , knots ) |> snd |> List . concat in let knots_in_time = List . map knots ~ f ( : fun ( time , x_value ) -> let x_value_time = Time_ns . add start_time ( Time_ns . Span . of_day x_value ) in time , x_value_time ) in match create knots_in_time with | Ok t -> t | Error error -> Error . raise_s [ % message " Failed to create a piecewise linear mapping between x axis time and real time " ( error : Error . t ) ] ; ; end
let only_display_market_hours ( ? mkt_start_ofday = Time_ns . Ofday . create ~ hr : 9 ~ min : 30 ( ) ) ( ? mkt_end_ofday = Time_ns . Ofday . create ~ hr : 16 ( ) ) ~ start_time ~ end_time ~ zone ( ) = let ofday_knots = [ Time_ns . Ofday . start_of_day , 0 . ; mkt_start_ofday , 0 . 01 ; mkt_end_ofday , 0 . 99 ] in let date_to_weight date = if Date . is_weekend date then 0 . 01 else 1 . in let x_axis_mapping = Time_mapping . create ~ start_time ~ end_time ~ zone ~ ofday_knots ~ date_to_weight in let time_to_x_value time = Time_mapping . get x_axis_mapping time in let x_value_to_time x_value = Time_mapping . get_inverse x_axis_mapping x_value in let value_formatter ms_since_epoch _opts = let x_value = Time_ns . of_span_since_epoch ( Time_ns . Span . of_ms ms_since_epoch ) in let time = x_value_to_time x_value in Time_ns . to_string_trimmed ( round_time_nearest_ms time ~ zone ) ~ zone in let date_axis_label_formatter x_value granularity opts = let time = x_value_to_time x_value in let ms_since_epoch = Time_ns . Span . to_ms ( Time_ns . to_span_since_epoch time ) in let js_date = new % js Js . date_fromTimeValue ms_since_epoch in dygraphs_date_axis_label_formatter ( ) js_date granularity opts |> Js . to_string in let axis_label_formatter x gran opts = match x with | ` number x -> dygraphs_number_axis_label_formatter ( ) ( Js . number_of_float x ) gran opts |> Js . to_string | ` date d -> let ms_since_epoch : float = d ## getTime in let span = Time_ns . Span . of_ms ms_since_epoch in let x_value = Time_ns . of_span_since_epoch span in date_axis_label_formatter x_value gran opts in { time_to_x_value ; x_value_to_time ; value_formatter ; axis_label_formatter } ; ;
let default ~ zone = { time_to_x_value = Fn . id ; x_value_to_time = Fn . id ; value_formatter = ( fun x _opts -> default_value_formatter x ~ zone ) ; axis_label_formatter = default_axis_label_formatter } ; ;
let create_path tokens = Yaks_types . Path . of_string @@ String . concat " " / tokens
let create_selector tokens = Yaks_types . Selector . of_string @@ String . concat " " / tokens
type state = { yaks_client : Yaks_api . t }
type connector = state MVar . t
let get_connector ( config : configuration ) = let % lwt yclient = Yaks . login config . agent . yaks Apero . Properties . empty in let % lwt admin = Yaks . admin yclient in let % lwt ws = Yaks . workspace ( create_path [ global_actual_prefix ; " " ] ) yclient in Lwt . return @@ MVar . create { ws = ws ; yaks_client = yclient ; yaks_admin = admin ; listeners = [ ] ; evals = [ ] }
let get_connector_of_locator loc = let % lwt yclient = Yaks . login loc Apero . Properties . empty in let % lwt admin = Yaks . admin yclient in let % lwt ws = Yaks . workspace ( create_path [ global_actual_prefix ; " " ] ) yclient in Lwt . return @@ MVar . create { ws = ws ; yaks_client = yclient ; yaks_admin = admin ; listeners = [ ] ; evals = [ ] }
let close_connector y = MVar . guarded y @@ fun state -> Lwt_list . iter_p ( fun e -> Yaks . Workspace . unsubscribe e state . ws ) state . listeners >>= fun _ -> Lwt_list . iter_p ( fun e -> Yaks . Workspace . unregister_eval e state . ws ) state . evals >>= fun _ -> Yaks . logout state . yaks_client >>= fun _ -> MVar . return ( ) state
let sub_cb callback of_string extract_uuid ( data ( : Yaks . Path . t * Yaks . change ) list ) = match data with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Listener received empty data " ) !! ) ) | _ -> let p , c = List . hd data in ( match c with | Put tv | Update tv -> let v = tv . value in callback ( Some ( of_string ( Yaks . Value . to_string v ) ) ) false None | Remove _ -> callback None true ( Some ( extract_uuid p ) ) )
let sub_cb_2ids callback of_string extract_uuid1 extract_uuid2 ( data ( : Yaks . Path . t * Yaks . change ) list ) = match data with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Listener received empty data " ) !! ) ) | _ -> let p , c = List . hd data in ( match c with | Put tv | Update tv -> let v = tv . value in callback ( Some ( of_string ( Yaks . Value . to_string v ) ) ) false None None | Remove _ -> callback None true ( Some ( extract_uuid1 p ) ) ( Some ( extract_uuid2 p ) ) )
module MakeGAD ( P : sig val prefix : string end ) = struct let get_sys_info_path sysid = create_path [ P . prefix ; sysid ; " info " ] let get_sys_configuration_path sysid = create_path [ P . prefix ; sysid ; " configuration " ] let get_all_users_selector sysid = create_selector [ P . prefix ; sysid ; " users " ; " " ] * let get_user_info_path sysid userid = create_path [ P . prefix ; sysid ; " users " ; userid ; " info " ] let get_all_tenants_selector sysid = create_selector [ P . prefix ; sysid ; " tenants " ; " " ] * let get_tenant_info_path sysid tenantid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " info " ] let get_tenant_configuration_path sysid tenantid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " configuration " ] let get_catalog_atomic_entity_info_path sysid tenantid aeid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " catalog " ; " atomic - entities " ; aeid ; " info " ] let get_catalog_all_atomic_entity_selector sysid tenantid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " catalog " ; " atomic - entities " ; " " ; * " info " ] let get_catalog_fdu_info_path sysid tenantid fduid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " catalog " ; " fdu " ; fduid ; " info " ] let get_catalog_all_fdu_selector sysid tenantid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " catalog " ; " fdu " ; " " ; * " info " ] let get_catalog_entity_info_path sysid tenantid eid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " catalog " ; " entities " ; eid ; " info " ] let get_catalog_all_entities_selector sysid tenantid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " catalog " ; " entities " ; " " ; * " info " ] let get_records_atomic_entity_instance_info_path sysid tenantid aeid instance_id = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " records " ; " atomic - entities " ; aeid ; " instances " ; instance_id ; " info " ] let get_records_all_atomic_entity_instance_selector sysid tenantid aeid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " records " ; " atomic - entities " ; aeid ; " instances " ; " " ; * " info " ] let get_records_all_atomic_entities_instance_selector sysid tenantid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " records " ; " atomic - entities " ; " " ; * " instances " ; " " ; * " info " ] let get_records_entity_instance_info_path sysid tenantid eid instance_id = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " records " ; " entities " ; eid ; " instances " ; instance_id ; " info " ] let get_records_all_entity_instances_selector sysid tenantid eid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " records " ; " entities " ; eid ; " instances " ; " " ; * " info " ] let get_records_all_entities_instances_selector sysid tenantid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " records " ; " entities " ; " " ; * " instances " ; " " ; * " info " ] let get_all_nodes_selector sysid tenantid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; " " ; * " info " ] let get_node_info_path sysid tenantid nodeid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " info " ] let get_node_configuration_path sysid tenantid nodeid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " configuration " ] let get_node_status_path sysid tenantid nodeid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " status " ] let get_node_neighbors_selector sysid tenantid nodeid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " neighbors " ; " " ; * " iface " ; " " ] * let get_node_neighbor_path sysid tenantid nodeid neighbor_id = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " neighbors " ; neighbor_id ; " iface " ; " " ] * let get_node_neighbor_face_path sysid tenantid nodeid neighbor_id iface = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " neighbors " ; neighbor_id ; " iface " ; iface ] let get_node_plugins_selector sysid tenantid nodeid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " plugins " ; " " ; * " info " ] let get_node_plugins_subscriber_selector sysid tenantid nodeid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " plugins " ; " " ; * " info " ] let get_node_plugin_info_path sysid tenantid nodeid pluginid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " plugins " ; pluginid ; " info " ] let get_node_plugin_eval_path sysid tenantid nodeid pluginid func_name = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " plugins " ; pluginid ; " exec " ; func_name ] let get_node_fdu_info_path sysid tenantid nodeid fduid instanceid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " fdu " ; fduid ; " instances " ; instanceid ; " info " ] let get_node_fdu_selector sysid tenantid nodeid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " fdu " ; " " ; * " instances " ; " " ; * " info " ] let get_node_fdu_instances_selector sysid tenantid nodeid fduid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " fdu " ; fduid ; " instances " ; " " ; * " info " ] let get_node_fdu_instance_selector sysid tenantid nodeid instanceid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " fdu " ; " " ; * " instances " ; instanceid ; " info " ] let get_fdu_instance_selector sysid tenantid instanceid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; " " ; * " fdu " ; " " ; * " instances " ; instanceid ; " info " ] let get_fdu_start_eval_selector sysid tenantid instanceid env = let e = Printf . sprintf " ( ? env =% s ) " env in create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; " " ; * " fdu " ; " " ; * " instances " ; instanceid ; " start " ; e ] let get_fdu_run_eval_selector sysid tenantid instanceid env = let e = Printf . sprintf " ( ? env =% s ) " env in create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; " " ; * " fdu " ; " " ; * " instances " ; instanceid ; " run " ; e ] let get_fdu_log_eval_selector sysid tenantid instanceid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; " " ; * " fdu " ; " " ; * " instances " ; instanceid ; " log " ] let get_fdu_ls_eval_selector sysid tenantid instanceid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; " " ; * " fdu " ; " " ; * " instances " ; instanceid ; " ls " ] let get_fdu_file_eval_selector sysid tenantid instanceid filename = let f = Printf . sprintf " ( ? filename =% s ) " filename in create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; " " ; * " fdu " ; " " ; * " instances " ; instanceid ; " get " ; f ] let get_fdu_start_eval_path sysid tenantid nodeid fduid instanceid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " fdu " ; fduid ; " instances " ; instanceid ; " start " ] let get_fdu_run_eval_path sysid tenantid nodeid fduid instanceid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " fdu " ; fduid ; " instances " ; instanceid ; " run " ] let get_fdu_log_eval_path sysid tenantid nodeid fduid instanceid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " fdu " ; fduid ; " instances " ; instanceid ; " log " ] let get_fdu_ls_eval_path sysid tenantid nodeid fduid instanceid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " fdu " ; fduid ; " instances " ; instanceid ; " ls " ] let get_fdu_file_eval_path sysid tenantid nodeid fduid instanceid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " fdu " ; fduid ; " instances " ; instanceid ; " get " ] let get_fdu_schedule_eval_selector sysid tenantid nodeid fduid = let f = Printf . sprintf " ( ? fdu_id =% s ) " fduid in create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " agent " ; " exec " ; " schedule " ; f ] let get_fdu_check_eval_selector sysid tenantid nodeid fdu = let f = Printf . sprintf " ( ? descriptor =% s ) " ( User . Descriptors . FDU . string_of_descriptor fdu ) in create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " agent " ; " exec " ; " check " ; f ] let get_fdu_schedule_eval_path sysid tenantid nodeid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " agent " ; " exec " ; " schedule " ] let get_fdu_check_eval_path sysid tenantid nodeid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " agent " ; " exec " ; " check " ] let get_node_network_port_info_path sysid tenantid nodeid portid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " networks " ; " ports " ; portid ; " info " ] let get_node_network_ports_selector sysid tenantid nodeid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " networks " ; " ports " ; " " ; * " info " ] let get_node_network_port_find_node sysid tenantid portid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; " " ; " * networks " ; " ports " ; portid ; " info " ] let get_node_network_router_info_path sysid tenantid nodeid routerid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " networks " ; " routers " ; routerid ; " info " ] let get_node_network_routers_selector sysid tenantid nodeid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " networks " ; " routers " ; " " ; * " info " ] let get_all_node_networks_selector sysid tenantid nodeid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " networks " ; " " ; * " info " ] let get_node_network_info_path sysid tenantid nodeid networkid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " networks " ; networkid ; " info " ] let get_node_network_floating_ip_info_path sysid tenantid nodeid floatingid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " networks " ; " floating - ips " ; floatingid ; " info " ] let get_all_node_network_floating_ips_selector sysid tenantid nodeid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " networks " ; " floating - ips " ; " " ; * " info " ] let get_all_networks_selector sysid tenantid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " networks " ; " " ; * " info " ] let get_network_info_path sysid tenantid networkid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " networks " ; networkid ; " info " ] let get_network_port_info_path sysid tenantid portid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " networks " ; " ports " ; portid ; " info " ] let get_network_ports_selector sysid tenantid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " networks " ; " ports " ; " " ; * " info " ] let get_network_router_info_path sysid tenantid routerid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " networks " ; " routers " ; routerid ; " info " ] let get_network_routers_selector sysid tenantid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " networks " ; " routers " ; " " ; * " info " ] let get_image_info_path sysid tenantid imageid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " image " ; imageid ; " info " ] let get_all_image_selector sysid tenantid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " image " ; " " ; * " info " ] let get_node_image_info_path sysid tenantid nodeid imageid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " image " ; imageid ; " info " ] let get_all_node_image_selector sysid tenantid nodeid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " image " ; " " ; * " info " ] let get_flavor_info_path sysid tenantid flavorid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " flavor " ; flavorid ; " info " ] let get_all_flavor_selector sysid tenantid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " flavor " ; " " ; * " info " ] let get_node_flavor_info_path sysid tenantid nodeid flavorid = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " flavor " ; flavorid ; " info " ] let get_all_node_flavor_selector sysid tenantid nodeid = create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " flavor " ; " " ; * " info " ] let get_agent_exec_path sysid tenantid nodeid func_name = create_path [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " agent " ; " exec " ; func_name ] let get_agent_exec_path_with_params sysid tenantid nodeid func_name ( params : ( string * string ) list ) = let rec assoc2args base index list = let len = List . length list in match index with | 0 -> let k , v = List . hd list in let b = base ^ " ( " ^ k ^ " " = ^ v in assoc2args b ( index + 1 ) list | n when n < len -> let k , v = List . nth list index in let b = base ^ " ; " ^ k ^ " " = ^ v in assoc2args b ( index + 1 ) list | _ -> base ^ " ) " in let p = assoc2args " " 0 params in let f = func_name ^ " " ? ^ p in create_selector [ P . prefix ; sysid ; " tenants " ; tenantid ; " nodes " ; nodeid ; " agent " ; " exec " ; f ] let extract_userid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 4 let extract_tenantid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 4 let extract_entity_id_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 7 let extract_entity_instanceid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 9 let extract_aeid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 7 let extract_aeid_instanceid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 9 let extract_fduid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 7 let extract_netid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 6 let extract_imageid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 6 let extract_flavorid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 6 let extract_portid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 7 let extract_routerid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 7 let extract_nodeid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 6 let extract_pluginid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 8 let extract_node_fduid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 8 let extract_node_fdu_instanceid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 10 let extract_node_netid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 8 let extract_node_portid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 9 let extract_node_routerid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 9 let extract_node_floatingid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 9 let extract_node_imageid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 8 let extract_node_flavorid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 9 let get_sys_info sysid connector = MVar . read connector >>= fun connector -> let s = Yaks . Selector . of_path @@ get_sys_info_path sysid in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return None | _ -> let _ , v = ( List . hd res ) in try Lwt . return @@ Some ( FAgentTypes . system_info_of_string ( Yaks . Value . to_string v ) ) with | Atdgen_runtime . Oj_run . Error _ | Yojson . Json_error _ -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Value is not well formatted in get_sys_info " ) ) ) | exn -> Lwt . fail exn let get_sys_config sysid connector = MVar . read connector >>= fun connector -> let s = Yaks . Selector . of_path @@ get_sys_configuration_path sysid in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return None | _ -> let _ , v = ( List . hd res ) in try Lwt . return @@ Some ( FAgentTypes . system_config_of_string ( Yaks . Value . to_string v ) ) with | Atdgen_runtime . Oj_run . Error _ | Yojson . Json_error _ -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Value is not well formatted in get_sys_config " ) ) ) | exn -> Lwt . fail exn let get_all_users_ids sysid connector = MVar . read connector >>= fun connector -> let s = get_all_users_selector sysid in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return [ ] | _ -> Lwt . return @@ List . map ( fun ( k , _ ) -> extract_userid_from_path k ) res let get_all_tenants_ids sysid connector = MVar . read connector >>= fun connector -> let s = get_all_tenants_selector sysid in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return [ ] | _ -> Lwt . return @@ List . map ( fun ( k , _ ) -> extract_tenantid_from_path k ) res let get_all_nodes sysid tenantid connector = MVar . read connector >>= fun connector -> let s = get_all_nodes_selector sysid tenantid in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return [ ] | _ -> Lwt . return @@ List . map ( fun ( k , _ ) -> extract_nodeid_from_path k ) res let get_node_configuration sysid tenantid nodeid connector = MVar . read connector >>= fun connector -> let s = Yaks . Selector . of_path @@ get_node_configuration_path sysid tenantid nodeid in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return None | _ -> let _ , v = ( List . hd res ) in try Lwt . return @@ Some ( FAgentTypes . configuration_of_string ( Yaks . Value . to_string v ) ) with | Atdgen_runtime . Oj_run . Error _ | Yojson . Json_error _ -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Value is not well formatted in get_node_configuration " ) ) ) | exn -> Lwt . fail exn let get_node_info sysid tenantid nodeid connector = MVar . read connector >>= fun connector -> let s = Yaks . Selector . of_path @@ get_node_info_path sysid tenantid nodeid in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return None | _ -> let _ , v = ( List . hd res ) in try Lwt . return @@ Some ( FTypes . node_info_of_string ( Yaks . Value . to_string v ) ) with | Atdgen_runtime . Oj_run . Error _ | Yojson . Json_error _ -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Value is not well formatted in get_node_info " ) ) ) | exn -> Lwt . fail exn let remove_node_info sysid tenantid nodeid connector = MVar . read connector >>= fun connector -> let p = get_node_info_path sysid tenantid nodeid in Yaks . Workspace . remove p connector . ws let add_node_info sysid tenantid nodeid nodeinfo connector = MVar . read connector >>= fun connector -> let p = get_node_info_path sysid tenantid nodeid in let value = Yaks . Value . StringValue ( FTypes . string_of_node_info nodeinfo ) in Yaks . Workspace . put p value connector . ws let observe_nodes sysid tenantid callback connector = MVar . guarded connector @@ fun connector -> let s = get_all_nodes_selector sysid tenantid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback FTypes . node_info_of_string extract_nodeid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let get_node_status sysid tenantid nodeid connector = MVar . read connector >>= fun connector -> let s = Yaks . Selector . of_path @@ get_node_status_path sysid tenantid nodeid in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return None | _ -> let _ , v = ( List . hd res ) in try Lwt . return @@ Some ( FTypes . node_status_of_string ( Yaks . Value . to_string v ) ) with | Atdgen_runtime . Oj_run . Error _ | Yojson . Json_error _ -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Value is not well formatted in get_node_status " ) ) ) let observe_node_status sysid tenantid nodeid callback connector = MVar . guarded connector @@ fun connector -> let s = Yaks . Selector . of_path @@ get_node_status_path sysid tenantid nodeid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback FTypes . node_status_of_string extract_nodeid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let add_node_status sysid tenantid nodeid nodestatus connector = MVar . read connector >>= fun connector -> let p = get_node_status_path sysid tenantid nodeid in let value = Yaks . Value . StringValue ( FTypes . string_of_node_status nodestatus ) in Yaks . Workspace . put p value connector . ws let remove_node_status sysid tenantid nodeid connector = MVar . read connector >>= fun connector -> let p = get_node_status_path sysid tenantid nodeid in Yaks . Workspace . remove p connector . ws let get_node_neighbor sysid tenantid nodeid neighbor_id connector = MVar . read connector >>= fun connector -> let s = Yaks . Selector . of_path @@ get_node_neighbor_path sysid tenantid nodeid neighbor_id in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return [ ] | l -> Lwt_list . map_p ( fun e -> let _ , v = e in try Lwt . return ( FTypes . ping_info_of_string ( Yaks . Value . to_string v ) ) with | Atdgen_runtime . Oj_run . Error _ | Yojson . Json_error _ -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Value is not well formatted in get_node_neighbor " ) ) ) ) l let observe_node_neighbors sysid tenantid nodeid callback connector = MVar . guarded connector @@ fun connector -> let s = get_node_neighbors_selector sysid tenantid nodeid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback FTypes . ping_info_of_string extract_nodeid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let add_node_neighbor sysid tenantid nodeid neighbor_id iface ping_info connector = MVar . read connector >>= fun connector -> let p = get_node_neighbor_face_path sysid tenantid nodeid neighbor_id iface in let value = Yaks . Value . StringValue ( FTypes . string_of_ping_info ping_info ) in Yaks . Workspace . put p value connector . ws let remove_node_neighbor sysid tenantid nodeid neighbor_id iface connector = MVar . read connector >>= fun connector -> let p = get_node_neighbor_face_path sysid tenantid nodeid neighbor_id iface in Yaks . Workspace . remove p connector . ws let add_node_configuration sysid tenantid nodeid nodeconf connector = MVar . read connector >>= fun connector -> let p = get_node_configuration_path sysid tenantid nodeid in let value = Yaks . Value . StringValue ( FAgentTypes . string_of_configuration nodeconf ) in Yaks . Workspace . put p value connector . ws let get_all_plugins_ids sysid tenantid nodeid connector = MVar . read connector >>= fun connector -> let s = get_node_plugins_selector sysid tenantid nodeid in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return [ ] | _ -> Lwt . return @@ List . map ( fun ( k , _ ) -> extract_pluginid_from_path k ) res let get_plugin_info sysid tenantid nodeid pluginid connector = MVar . read connector >>= fun connector -> let s = Yaks . Selector . of_path @@ get_node_plugin_info_path sysid tenantid nodeid pluginid in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return None | _ -> let _ , v = ( List . hd res ) in try Lwt . return @@ Some ( FTypes . plugin_of_string ( Yaks . Value . to_string v ) ) with | Atdgen_runtime . Oj_run . Error _ | Yojson . Json_error _ -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Value is not well formatted in get_plugin_info " ) ) ) | exn -> Lwt . fail exn let add_node_plugin sysid tenantid nodeid ( plugininfo : FTypes . plugin ) connector = MVar . read connector >>= fun connector -> let p = get_node_plugin_info_path sysid tenantid nodeid plugininfo . uuid in let value = Yaks . Value . StringValue ( FTypes . string_of_plugin plugininfo ) in Yaks . Workspace . put p value connector . ws let remove_node_plugin sysid tenantid nodeid pluginid connector = MVar . read connector >>= fun connector -> let p = get_node_plugin_info_path sysid tenantid nodeid pluginid in Yaks . Workspace . remove p connector . ws let observe_node_plugins sysid tenantid nodeid callback connector = MVar . guarded connector @@ fun connector -> let s = get_node_plugins_subscriber_selector sysid tenantid nodeid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback FTypes . plugin_of_string extract_pluginid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let get_node_plugins sysid tenantid nodeid connector = MVar . read connector >>= fun connector -> let s = get_node_plugins_selector sysid tenantid nodeid in Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return [ ] | _ -> Lwt_list . map_p ( fun ( _ , v ) -> Lwt . return @@ FTypes . plugin_of_string ( Yaks . Value . to_string v ) ) kvs let add_plugin_eval sysid tenantid nodeid pluginid func_name func connector = MVar . guarded connector @@ fun connector -> let p = get_node_plugin_eval_path sysid tenantid nodeid pluginid func_name in let cb _ props = Lwt . return @@ Yaks . Value . StringValue ( func props ) in let % lwt _ = Yaks . Workspace . register_eval p cb connector . ws in let ls = List . append connector . evals [ p ] in MVar . return Lwt . return_unit { connector with evals = ls } let get_catalog_all_entities sysid tenantid connector = MVar . read connector >>= fun connector -> let s = get_catalog_all_entities_selector sysid tenantid in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return [ ] | _ -> Lwt . return @@ List . map ( fun ( k , _ ) -> extract_entity_id_from_path k ) res let get_catalog_entity_info sysid tenantid eid connector = MVar . read connector >>= fun connector -> let s = Yaks . Selector . of_path @@ get_catalog_entity_info_path sysid tenantid eid in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return None | _ -> let _ , v = ( List . hd res ) in try Lwt . return @@ Some ( User . Descriptors . Entity . descriptor_of_string ( Yaks . Value . to_string v ) ) with | Atdgen_runtime . Oj_run . Error _ | Yojson . Json_error _ -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Value is not well formatted in get_catalog_entity_info " ) ) ) | exn -> Lwt . fail exn let add_catalog_entity_info sysid tenantid eid einfo connector = MVar . read connector >>= fun connector -> let p = get_catalog_entity_info_path sysid tenantid eid in let value = Yaks . Value . StringValue ( User . Descriptors . Entity . string_of_descriptor einfo ) in Yaks . Workspace . put p value connector . ws let remove_catalog_entity_info sysid tenantid aeid connector = MVar . read connector >>= fun connector -> let p = get_catalog_entity_info_path sysid tenantid aeid in Yaks . Workspace . remove p connector . ws let observe_catalog_entities sysid tenantid callback connector = MVar . guarded connector @@ fun connector -> let s = get_catalog_all_entities_selector sysid tenantid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback User . Descriptors . Entity . descriptor_of_string extract_entity_id_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let get_catalog_all_fdus sysid tenantid connector = MVar . read connector >>= fun connector -> let s = get_catalog_all_fdu_selector sysid tenantid in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return [ ] | _ -> Lwt . return @@ List . map ( fun ( k , _ ) -> extract_fduid_from_path k ) res let get_catalog_fdu_info sysid tenantid fduid connector = MVar . read connector >>= fun connector -> let s = Yaks . Selector . of_path @@ get_catalog_fdu_info_path sysid tenantid fduid in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return None | _ -> let _ , v = ( List . hd res ) in try Lwt . return @@ Some ( User . Descriptors . FDU . descriptor_of_string ( Yaks . Value . to_string v ) ) with | Atdgen_runtime . Oj_run . Error _ | Yojson . Json_error _ -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Value is not well formatted in get_fdu_info " ) ) ) | exn -> Lwt . fail exn let add_catalog_fdu_info sysid tenantid fduid fduinfo connector = MVar . read connector >>= fun connector -> let p = get_catalog_fdu_info_path sysid tenantid fduid in let value = Yaks . Value . StringValue ( User . Descriptors . FDU . string_of_descriptor fduinfo ) in Yaks . Workspace . put p value connector . ws let remove_catalog_fdu_info sysid tenantid fduid connector = MVar . read connector >>= fun connector -> let p = get_catalog_fdu_info_path sysid tenantid fduid in Yaks . Workspace . remove p connector . ws let observe_catalog_fdu sysid tenantid callback connector = MVar . guarded connector @@ fun connector -> let s = get_catalog_all_fdu_selector sysid tenantid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback User . Descriptors . FDU . descriptor_of_string extract_fduid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let get_records_all_entities_instances sysid tenantid connector = MVar . read connector >>= fun connector -> let s = get_records_all_entities_instances_selector sysid tenantid in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return [ ] | _ -> Lwt . return @@ List . map ( fun ( k , _ ) -> ( extract_entity_id_from_path k , extract_entity_instanceid_from_path k ) ) res let get_records_all_entity_instances sysid tenantid eid connector = MVar . read connector >>= fun connector -> let s = get_records_all_entity_instances_selector sysid tenantid eid in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return [ ] | _ -> Lwt . return @@ List . map ( fun ( k , _ ) -> extract_entity_instanceid_from_path k ) res let get_records_entity_instance_info sysid tenantid eid instanceid connector = MVar . read connector >>= fun connector -> let s = get_records_entity_instance_info_path sysid tenantid eid instanceid in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return None | _ -> let _ , v = ( List . hd res ) in try Lwt . return @@ Some ( Infra . Descriptors . Entity . record_of_string ( Yaks . Value . to_string v ) ) with | Atdgen_runtime . Oj_run . Error _ | Yojson . Json_error _ -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Value is not well formatted in get_fdu_info " ) ) ) | exn -> Lwt . fail exn let add_records_entity_instance_info sysid tenantid eid instanceid einfo connector = MVar . read connector >>= fun connector -> let p = Yaks . Path . of_string @@ Yaks . Selector . path @@ get_records_entity_instance_info_path sysid tenantid eid instanceid in let value = Yaks . Value . StringValue ( Infra . Descriptors . Entity . string_of_record einfo ) in Yaks . Workspace . put p value connector . ws let remove_records_entity_instance_info sysid tenantid eid instanceid connector = MVar . read connector >>= fun connector -> let p = Yaks . Path . of_string @@ Yaks . Selector . path @@ get_records_entity_instance_info_path sysid tenantid eid instanceid in Yaks . Workspace . remove p connector . ws let observe_records_entities_instances sysid tenantid callback connector = MVar . guarded connector @@ fun connector -> let s = get_records_all_entities_instances_selector sysid tenantid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback Infra . Descriptors . Entity . record_of_string extract_entity_instanceid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let observe_node_fdu sysid tenantid nodeid callback connector = MVar . guarded connector @@ fun connector -> let s = get_node_fdu_selector sysid tenantid nodeid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb_2ids callback Infra . Descriptors . FDU . record_of_string extract_node_fduid_from_path extract_node_fdu_instanceid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let add_node_fdu sysid tenantid nodeid fduid instanceid ( fduinfo : Infra . Descriptors . FDU . record ) connector = MVar . read connector >>= fun connector -> let p = get_node_fdu_info_path sysid tenantid nodeid fduid instanceid in let value = Yaks . Value . StringValue ( Infra . Descriptors . FDU . string_of_record fduinfo ) in Yaks . Workspace . put p value connector . ws let get_node_fdus sysid tenantid nodeid connector = MVar . read connector >>= fun connector -> let s = get_node_fdu_selector sysid tenantid nodeid in Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return [ ] | _ -> Lwt_list . map_p ( fun ( k , v ) -> Lwt . return ( extract_nodeid_from_path k , extract_node_fduid_from_path k , extract_node_fdu_instanceid_from_path k , Infra . Descriptors . FDU . record_of_string ( Yaks . Value . to_string v ) ) ) kvs let get_node_fdu_instances sysid tenantid nodeid fduid connector = MVar . read connector >>= fun connector -> let s = get_node_fdu_instances_selector sysid tenantid nodeid fduid in Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return [ ] | _ -> Lwt_list . map_p ( fun ( k , v ) -> Lwt . return ( extract_nodeid_from_path k , extract_node_fduid_from_path k , extract_node_fdu_instanceid_from_path k , Infra . Descriptors . FDU . record_of_string ( Yaks . Value . to_string v ) ) ) kvs let remove_node_fdu sysid tenantid nodeid fduid instanceid connector = MVar . read connector >>= fun connector -> let p = get_node_fdu_info_path sysid tenantid nodeid fduid instanceid in Yaks . Workspace . remove p connector . ws let get_node_fdu_info sysid tenantid nodeid fduid instanceid connector = MVar . read connector >>= fun connector -> let s = match fduid with | " " * -> get_node_fdu_instance_selector sysid tenantid nodeid instanceid | _ -> Yaks . Selector . of_path @@ get_node_fdu_info_path sysid tenantid nodeid fduid instanceid in Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return None | _ -> let _ , v = List . hd kvs in Lwt . return @@ Some ( Infra . Descriptors . FDU . record_of_string ( Yaks . Value . to_string v ) ) let get_node_instance_info sysid tenantid nodeid instanceid connector = MVar . read connector >>= fun connector -> let s = get_node_fdu_instance_selector sysid tenantid nodeid instanceid in Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return None | _ -> let _ , v = List . hd kvs in Lwt . return @@ Some ( Infra . Descriptors . FDU . record_of_string ( Yaks . Value . to_string v ) ) let get_fdu_nodes sysid tenantid fduid connector = MVar . read connector >>= fun connector -> let s = get_node_fdu_instances_selector sysid tenantid " " * fduid in Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return [ ] | _ -> Lwt_list . map_p ( fun ( k , _ ) -> Lwt . return ( extract_nodeid_from_path k ) ) kvs let get_fdu_instance_node sysid tenantid instanceid connector = MVar . read connector >>= fun connector -> let s = get_fdu_instance_selector sysid tenantid instanceid in Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return None | _ -> let k , _ = List . hd kvs in Lwt . return @@ Some ( extract_nodeid_from_path k ) let add_network sysid tenantid netid net_info connector = let p = get_network_info_path sysid tenantid netid in MVar . read connector >>= fun connector -> Yaks . Workspace . put p ( Yaks . Value . StringValue ( FTypes . string_of_virtual_network net_info ) ) connector . ws let get_network sysid tenantid netid connector = let s = Yaks . Selector . of_path @@ get_network_info_path sysid tenantid netid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return None | _ -> let _ , v = List . hd kvs in Lwt . return @@ Some ( FTypes . virtual_network_of_string ( Yaks . Value . to_string v ) ) let observe_network sysid tenantid callback connector = MVar . guarded connector @@ fun connector -> let s = get_all_networks_selector sysid tenantid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback FTypes . virtual_network_of_string extract_netid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let remove_network sysid tenantid netid connector = let p = get_network_info_path sysid tenantid netid in MVar . read connector >>= fun connector -> Yaks . Workspace . remove p connector . ws let get_all_networks sysid tenantid connector = let s = get_all_networks_selector sysid tenantid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return [ ] | _ -> Lwt_list . map_p ( fun ( _ , v ) -> Lwt . return @@ FTypes . virtual_network_of_string ( Yaks . Value . to_string v ) ) kvs let add_port sysid tenantid portid port_info connector = let p = get_network_port_info_path sysid tenantid portid in MVar . read connector >>= fun connector -> Yaks . Workspace . put p ( Yaks . Value . StringValue ( User . Descriptors . Network . string_of_connection_point_descriptor port_info ) ) connector . ws let get_port sysid tenantid portid connector = let s = Yaks . Selector . of_path @@ get_network_port_info_path sysid tenantid portid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return None | _ -> let _ , v = List . hd kvs in Lwt . return @@ Some ( User . Descriptors . Network . connection_point_descriptor_of_string ( Yaks . Value . to_string v ) ) let observe_ports sysid tenantid callback connector = MVar . guarded connector @@ fun connector -> let s = get_network_ports_selector sysid tenantid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback User . Descriptors . Network . connection_point_descriptor_of_string extract_portid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let remove_port sysid tenantid portid connector = let p = get_network_port_info_path sysid tenantid portid in MVar . read connector >>= fun connector -> Yaks . Workspace . remove p connector . ws let get_all_ports sysid tenantid connector = let s = get_network_ports_selector sysid tenantid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return [ ] | _ -> Lwt_list . map_p ( fun ( _ , v ) -> Lwt . return @@ User . Descriptors . Network . connection_point_descriptor_of_string ( Yaks . Value . to_string v ) ) kvs let add_router sysid tenantid routerid router_info connector = let p = get_network_router_info_path sysid tenantid routerid in MVar . read connector >>= fun connector -> Yaks . Workspace . put p ( Yaks . Value . StringValue ( Router . string_of_descriptor router_info ) ) connector . ws let get_router sysid tenantid routerid connector = let s = Yaks . Selector . of_path @@ get_network_router_info_path sysid tenantid routerid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return None | _ -> let _ , v = List . hd kvs in Lwt . return @@ Some ( Router . descriptor_of_string ( Yaks . Value . to_string v ) ) let observe_routers sysid tenantid callback connector = MVar . guarded connector @@ fun connector -> let s = get_network_routers_selector sysid tenantid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback Router . descriptor_of_string extract_routerid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let remove_router sysid tenantid routerid connector = let p = get_network_router_info_path sysid tenantid routerid in MVar . read connector >>= fun connector -> Yaks . Workspace . remove p connector . ws let get_all_routers sysid tenantid connector = let s = get_network_routers_selector sysid tenantid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return [ ] | _ -> Lwt_list . map_p ( fun ( _ , v ) -> Lwt . return @@ Router . descriptor_of_string ( Yaks . Value . to_string v ) ) kvs let add_node_network sysid tenantid nodeid netid net_info connector = let p = get_node_network_info_path sysid tenantid nodeid netid in MVar . read connector >>= fun connector -> Yaks . Workspace . put p ( Yaks . Value . StringValue ( FTypesRecord . string_of_virtual_network net_info ) ) connector . ws let get_node_network sysid tenantid nodeid netid connector = let s = Yaks . Selector . of_path @@ get_node_network_info_path sysid tenantid nodeid netid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return None | _ -> let _ , v = List . hd kvs in Lwt . return @@ Some ( FTypesRecord . virtual_network_of_string ( Yaks . Value . to_string v ) ) let observe_node_network sysid tenantid nodeid callback connector = MVar . guarded connector @@ fun connector -> let s = get_all_node_networks_selector sysid tenantid nodeid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback FTypesRecord . virtual_network_of_string extract_node_netid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let remove_node_network sysid tenantid nodeid netid connector = let p = get_node_network_info_path sysid tenantid nodeid netid in MVar . read connector >>= fun connector -> Yaks . Workspace . remove p connector . ws let get_all_node_networks sysid tenantid nodeid connector = let s = get_all_node_networks_selector sysid tenantid nodeid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return [ ] | _ -> Lwt_list . map_p ( fun ( _ , v ) -> Lwt . return @@ FTypesRecord . virtual_network_of_string ( Yaks . Value . to_string v ) ) kvs let add_node_port sysid tenantid nodeid portid port_info connector = let p = get_node_network_port_info_path sysid tenantid nodeid portid in MVar . read connector >>= fun connector -> Yaks . Workspace . put p ( Yaks . Value . StringValue ( Infra . Descriptors . Network . string_of_connection_point_record port_info ) ) connector . ws let get_node_port sysid tenantid nodeid portid connector = let s = Yaks . Selector . of_path @@ get_node_network_port_info_path sysid tenantid nodeid portid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return None | _ -> let _ , v = List . hd kvs in Lwt . return @@ Some ( Infra . Descriptors . Network . connection_point_record_of_string ( Yaks . Value . to_string v ) ) let find_node_port sysid tenantid portid connector = let s = get_node_network_port_find_node sysid tenantid portid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return None | _ -> let p , _ = List . hd kvs in Lwt . return @@ Some ( extract_nodeid_from_path p ) let observe_node_ports sysid tenantid nodeid callback connector = MVar . guarded connector @@ fun connector -> let s = get_node_network_ports_selector sysid tenantid nodeid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback Infra . Descriptors . Network . connection_point_record_of_string extract_node_portid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let remove_node_port sysid tenantid nodeid portid connector = let p = get_node_network_port_info_path sysid tenantid portid nodeid in MVar . read connector >>= fun connector -> Yaks . Workspace . remove p connector . ws let get_all_node_ports sysid tenantid nodeid connector = let s = get_node_network_ports_selector sysid tenantid nodeid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return [ ] | _ -> Lwt_list . map_p ( fun ( _ , v ) -> Lwt . return @@ Infra . Descriptors . Network . connection_point_record_of_string ( Yaks . Value . to_string v ) ) kvs let add_node_router sysid tenantid nodeid routerid router_info connector = let p = get_node_network_router_info_path sysid tenantid nodeid routerid in MVar . read connector >>= fun connector -> Yaks . Workspace . put p ( Yaks . Value . StringValue ( Router . string_of_descriptor router_info ) ) connector . ws let get_node_router sysid tenantid nodeid routerid connector = let s = Yaks . Selector . of_path @@ get_node_network_router_info_path sysid tenantid nodeid routerid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return None | _ -> let _ , v = List . hd kvs in Lwt . return @@ Some ( Router . descriptor_of_string ( Yaks . Value . to_string v ) ) let observe_node_routers sysid tenantid nodeid callback connector = MVar . guarded connector @@ fun connector -> let s = get_node_network_routers_selector sysid tenantid nodeid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback Router . descriptor_of_string extract_node_routerid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let remove_node_router sysid tenantid nodeid routerid connector = let p = get_node_network_router_info_path sysid tenantid nodeid routerid in MVar . read connector >>= fun connector -> Yaks . Workspace . remove p connector . ws let get_all_node_routers sysid tenantid nodeid connector = let s = get_node_network_routers_selector sysid tenantid nodeid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return [ ] | _ -> Lwt_list . map_p ( fun ( _ , v ) -> Lwt . return @@ Router . descriptor_of_string ( Yaks . Value . to_string v ) ) kvs let add_node_floating_ip sysid tenantid nodeid floatingid ip_info connector = let p = get_node_network_floating_ip_info_path sysid tenantid nodeid floatingid in MVar . read connector >>= fun connector -> Yaks . Workspace . put p ( Yaks . Value . StringValue ( FTypes . string_of_floating_ip ip_info ) ) connector . ws let get_node_floatin_ip sysid tenantid nodeid floatingid connector = let s = Yaks . Selector . of_path @@ get_node_network_floating_ip_info_path sysid tenantid nodeid floatingid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return None | _ -> let _ , v = List . hd kvs in Lwt . return @@ Some ( FTypes . floating_ip_of_string ( Yaks . Value . to_string v ) ) let observe_node_floating_ips sysid tenantid nodeid callback connector = MVar . guarded connector @@ fun connector -> let s = get_all_node_network_floating_ips_selector sysid tenantid nodeid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback FTypes . floating_ip_of_string extract_node_floatingid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let remove_node_floating_ip sysid tenantid nodeid floatingid connector = let p = get_node_network_floating_ip_info_path sysid tenantid floatingid nodeid in MVar . read connector >>= fun connector -> Yaks . Workspace . remove p connector . ws let get_all_node_floating_ips sysid tenantid nodeid connector = let s = get_all_node_network_floating_ips_selector sysid tenantid nodeid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return [ ] | _ -> Lwt_list . map_p ( fun ( _ , v ) -> Lwt . return @@ FTypes . floating_ip_of_string ( Yaks . Value . to_string v ) ) kvs let add_image sysid tenantid imageid imageinfo connector = let p = get_image_info_path sysid tenantid imageid in MVar . read connector >>= fun connector -> Yaks . Workspace . put p ( Yaks . Value . StringValue ( User . Descriptors . FDU . string_of_image imageinfo ) ) connector . ws let remove_image sysid tenantid imageid connector = let p = get_image_info_path sysid tenantid imageid in MVar . read connector >>= fun connector -> Yaks . Workspace . remove p connector . ws let get_image sysid tenantid imageid connector = let s = Yaks . Selector . of_path @@ get_image_info_path sysid tenantid imageid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return None | _ -> let _ , v = List . hd kvs in Lwt . return @@ Some ( User . Descriptors . FDU . image_of_string ( Yaks . Value . to_string v ) ) let get_all_images sysid tenantid connector = let s = get_all_image_selector sysid tenantid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return [ ] | _ -> Lwt_list . map_p ( fun ( _ , v ) -> Lwt . return @@ User . Descriptors . FDU . image_of_string ( Yaks . Value . to_string v ) ) kvs let observe_images sysid tenantid callback connector = let s = get_all_image_selector sysid tenantid in MVar . guarded connector @@ fun connector -> let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback User . Descriptors . FDU . image_of_string extract_imageid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let add_node_image sysid tenantid nodeid imageid imageinfo connector = let p = get_node_image_info_path sysid tenantid nodeid imageid in MVar . read connector >>= fun connector -> Yaks . Workspace . put p ( Yaks . Value . StringValue ( Infra . Descriptors . FDU . string_of_image imageinfo ) ) connector . ws let remove__node_image sysid tenantid nodeid imageid connector = let p = get_node_image_info_path sysid tenantid nodeid imageid in MVar . read connector >>= fun connector -> Yaks . Workspace . remove p connector . ws let get_node_image sysid tenantid nodeid imageid connector = let s = Yaks . Selector . of_path @@ get_node_image_info_path sysid tenantid nodeid imageid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return None | _ -> let _ , v = List . hd kvs in Lwt . return @@ Some ( Infra . Descriptors . FDU . image_of_string ( Yaks . Value . to_string v ) ) let get_all_node_images sysid tenantid nodeid connector = let s = get_all_node_image_selector sysid tenantid nodeid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return [ ] | _ -> Lwt_list . map_p ( fun ( _ , v ) -> Lwt . return @@ Infra . Descriptors . FDU . image_of_string ( Yaks . Value . to_string v ) ) kvs let observe_node_images sysid tenantid nodeid callback connector = let s = get_all_node_image_selector sysid tenantid nodeid in MVar . guarded connector @@ fun connector -> let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback Infra . Descriptors . FDU . image_of_string extract_node_imageid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let add_flavor sysid tenantid flavorid flavorinfo connector = let p = get_flavor_info_path sysid tenantid flavorid in MVar . read connector >>= fun connector -> Yaks . Workspace . put p ( Yaks . Value . StringValue ( User . Descriptors . FDU . string_of_computational_requirements flavorinfo ) ) connector . ws let remove_flavor sysid tenantid flavorid connector = let p = get_flavor_info_path sysid tenantid flavorid in MVar . read connector >>= fun connector -> Yaks . Workspace . remove p connector . ws let get_flavor sysid tenantid flavorid connector = let s = Yaks . Selector . of_path @@ get_flavor_info_path sysid tenantid flavorid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return None | _ -> let _ , v = List . hd kvs in Lwt . return @@ Some ( User . Descriptors . FDU . computational_requirements_of_string ( Yaks . Value . to_string v ) ) let get_all_flavors sysid tenantid connector = let s = get_all_flavor_selector sysid tenantid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return [ ] | _ -> Lwt_list . map_p ( fun ( _ , v ) -> Lwt . return @@ User . Descriptors . FDU . computational_requirements_of_string ( Yaks . Value . to_string v ) ) kvs let observe_flavors sysid tenantid callback connector = let s = get_all_flavor_selector sysid tenantid in MVar . guarded connector @@ fun connector -> let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback User . Descriptors . FDU . computational_requirements_of_string extract_flavorid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let add_node_flavor sysid tenantid nodeid flavorid flavorinfo connector = let p = get_node_flavor_info_path sysid tenantid nodeid flavorid in MVar . read connector >>= fun connector -> Yaks . Workspace . put p ( Yaks . Value . StringValue ( Infra . Descriptors . FDU . string_of_computational_requirements flavorinfo ) ) connector . ws let remove_node_flavor sysid tenantid nodeid flavorid connector = let p = get_node_flavor_info_path sysid tenantid flavorid nodeid in MVar . read connector >>= fun connector -> Yaks . Workspace . remove p connector . ws let get_node_flavor sysid tenantid nodeid flavorid connector = let s = Yaks . Selector . of_path @@ get_node_flavor_info_path sysid tenantid nodeid flavorid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return None | _ -> let _ , v = List . hd kvs in Lwt . return @@ Some ( Infra . Descriptors . FDU . computational_requirements_of_string ( Yaks . Value . to_string v ) ) let get_all_node_flavors sysid tenantid nodeid connector = let s = get_all_node_flavor_selector sysid tenantid nodeid in MVar . read connector >>= fun connector -> Yaks . Workspace . get s connector . ws >>= fun kvs -> match kvs with | [ ] -> Lwt . return [ ] | _ -> Lwt_list . map_p ( fun ( _ , v ) -> Lwt . return @@ Infra . Descriptors . FDU . computational_requirements_of_string ( Yaks . Value . to_string v ) ) kvs let observe_node_flavors sysid tenantid nodeid callback connector = let s = get_all_node_flavor_selector sysid tenantid nodeid in MVar . guarded connector @@ fun connector -> let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback Infra . Descriptors . FDU . computational_requirements_of_string extract_node_flavorid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let add_agent_eval sysid tenantid nodeid func_name func connector = MVar . guarded connector @@ fun connector -> let p = get_agent_exec_path sysid tenantid nodeid func_name in let cb _ props = let % lwt r = func props in Lwt . return @@ Yaks . Value . StringValue r in let % lwt _ = Yaks . Workspace . register_eval p cb connector . ws in let ls = List . append connector . evals [ p ] in MVar . return Lwt . return_unit { connector with evals = ls } let exec_multi_node_eval sysid tenantid func_name parametes connector = MVar . read connector >>= fun connector -> let s = get_agent_exec_path_with_params sysid tenantid " " * func_name parametes in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return [ ] | lst -> Lwt_list . map_p ( fun ( _ , v ) -> try Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) with | Atdgen_runtime . Oj_run . Error _ | Yojson . Json_error _ -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Value is not well formatted in exec_multi_node_eval " ) ) ) ) lst let add_fdu_start_eval sysid tenantid nodeid fduid instanceid func connector = MVar . guarded connector @@ fun connector -> let p = get_fdu_start_eval_path sysid tenantid nodeid fduid instanceid in let cb _ props = match Apero . Properties . get " env " props with | Some env -> let % lwt r = func env in Lwt . return @@ Yaks . Value . StringValue r | None -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Missing Parameter env in add_fdu_start_eval " ) ) ) in let % lwt _ = Yaks . Workspace . register_eval p cb connector . ws in let ls = List . append connector . evals [ p ] in MVar . return Lwt . return_unit { connector with evals = ls } let add_fdu_run_eval sysid tenantid nodeid fduid instanceid func connector = MVar . guarded connector @@ fun connector -> let p = get_fdu_run_eval_path sysid tenantid nodeid fduid instanceid in let cb _ props = match Apero . Properties . get " env " props with | Some env -> let % lwt r = func env in Lwt . return @@ Yaks . Value . StringValue r | None -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Missing Parameter filename in add_fdu_run_eval " ) ) ) in let % lwt _ = Yaks . Workspace . register_eval p cb connector . ws in let ls = List . append connector . evals [ p ] in MVar . return Lwt . return_unit { connector with evals = ls } let add_fdu_log_eval sysid tenantid nodeid fduid instanceid func connector = MVar . guarded connector @@ fun connector -> let p = get_fdu_log_eval_path sysid tenantid nodeid fduid instanceid in let cb _ _ = let % lwt r = func ( ) in Lwt . return @@ Yaks . Value . StringValue r in let % lwt _ = Yaks . Workspace . register_eval p cb connector . ws in let ls = List . append connector . evals [ p ] in MVar . return Lwt . return_unit { connector with evals = ls } let add_fdu_ls_eval sysid tenantid nodeid fduid instanceid func connector = MVar . guarded connector @@ fun connector -> let p = get_fdu_ls_eval_path sysid tenantid nodeid fduid instanceid in let cb _ _ = let % lwt r = func ( ) in Lwt . return @@ Yaks . Value . StringValue r in let % lwt _ = Yaks . Workspace . register_eval p cb connector . ws in let ls = List . append connector . evals [ p ] in MVar . return Lwt . return_unit { connector with evals = ls } let add_fdu_file_eval sysid tenantid nodeid fduid instanceid func connector = MVar . guarded connector @@ fun connector -> let p = get_fdu_file_eval_path sysid tenantid nodeid fduid instanceid in let cb _ props = match Apero . Properties . get " filename " props with | Some filename -> let % lwt r = func filename in Lwt . return @@ Yaks . Value . StringValue r | None -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Missing Parameter filename in fdu_file_eval " ) ) ) in let % lwt _ = Yaks . Workspace . register_eval p cb connector . ws in let ls = List . append connector . evals [ p ] in MVar . return Lwt . return_unit { connector with evals = ls } let remove_fdu_start_eval sysid tenantid nodeid fduid instanceid connector = MVar . guarded connector @@ fun connector -> let p = get_fdu_start_eval_path sysid tenantid nodeid fduid instanceid in let % lwt _ = Yaks . Workspace . unregister_eval p connector . ws in let ls = List . filter ( fun e -> e != p ) connector . evals in MVar . return Lwt . return_unit { connector with evals = ls } let remove_fdu_run_eval sysid tenantid nodeid fduid instanceid connector = MVar . guarded connector @@ fun connector -> let p = get_fdu_run_eval_path sysid tenantid nodeid fduid instanceid in let % lwt _ = Yaks . Workspace . unregister_eval p connector . ws in let ls = List . filter ( fun e -> e != p ) connector . evals in MVar . return Lwt . return_unit { connector with evals = ls } let remove_fdu_log_eval sysid tenantid nodeid fduid instanceid connector = MVar . guarded connector @@ fun connector -> let p = get_fdu_log_eval_path sysid tenantid nodeid fduid instanceid in let % lwt _ = Yaks . Workspace . unregister_eval p connector . ws in let ls = List . filter ( fun e -> e != p ) connector . evals in MVar . return Lwt . return_unit { connector with evals = ls } let remove_fdu_ls_eval sysid tenantid nodeid fduid instanceid connector = MVar . guarded connector @@ fun connector -> let p = get_fdu_ls_eval_path sysid tenantid nodeid fduid instanceid in let % lwt _ = Yaks . Workspace . unregister_eval p connector . ws in let ls = List . filter ( fun e -> e != p ) connector . evals in MVar . return Lwt . return_unit { connector with evals = ls } let remove_fdu_file_eval sysid tenantid nodeid fduid instanceid connector = MVar . guarded connector @@ fun connector -> let p = get_fdu_file_eval_path sysid tenantid nodeid fduid instanceid in let % lwt _ = Yaks . Workspace . unregister_eval p connector . ws in let ls = List . filter ( fun e -> e != p ) connector . evals in MVar . return Lwt . return_unit { connector with evals = ls } let add_fdu_schedule_eval sysid tenantid nodeid func connector = MVar . guarded connector @@ fun connector -> let p = get_fdu_schedule_eval_path sysid tenantid nodeid in let cb _ props = let % lwt r = func props in Lwt . return @@ Yaks . Value . StringValue r in let % lwt _ = Yaks . Workspace . register_eval p cb connector . ws in let ls = List . append connector . evals [ p ] in MVar . return Lwt . return_unit { connector with evals = ls } let add_fdu_check_eval sysid tenantid nodeid func connector = MVar . guarded connector @@ fun connector -> let p = get_fdu_check_eval_path sysid tenantid nodeid in let cb _ props = let % lwt r = func props in Lwt . return @@ Yaks . Value . StringValue r in let % lwt _ = Yaks . Workspace . register_eval p cb connector . ws in let ls = List . append connector . evals [ p ] in MVar . return Lwt . return_unit { connector with evals = ls } let remove_fdu_schedule_eval sysid tenantid nodeid connector = MVar . guarded connector @@ fun connector -> let p = get_fdu_schedule_eval_path sysid tenantid nodeid in let % lwt _ = Yaks . Workspace . unregister_eval p connector . ws in let ls = List . filter ( fun e -> e != p ) connector . evals in MVar . return Lwt . return_unit { connector with evals = ls } let remove_fdu_check_eval sysid tenantid nodeid connector = MVar . guarded connector @@ fun connector -> let p = get_fdu_check_eval_path sysid tenantid nodeid in let % lwt _ = Yaks . Workspace . unregister_eval p connector . ws in let ls = List . filter ( fun e -> e != p ) connector . evals in MVar . return Lwt . return_unit { connector with evals = ls } let call_multi_node_check sysid tenantid fdu connector = MVar . read connector >>= fun connector -> let s = get_fdu_check_eval_selector sysid tenantid " " * fdu in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return [ ] | lst -> Lwt_list . filter_map_p ( fun ( _ , v ) -> try Lwt . return ( Some ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) ) with | _ -> Lwt . return None ) lst let onboard_fdu_from_node sysid tenantid nodeid fdu_info connector = MVar . read connector >>= fun connector -> let fname = " onboard_fdu " in let params = [ ( " descriptor " , User . Descriptors . FDU . string_of_descriptor fdu_info ) ] in let s = get_agent_exec_path_with_params sysid tenantid nodeid fname params in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for agent_eval " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let define_fdu_in_node sysid tenantid nodeid fdu_id connector = MVar . read connector >>= fun connector -> let fname = " define_fdu " in let params = [ ( " fdu_id " , fdu_id ) ] in let s = get_agent_exec_path_with_params sysid tenantid nodeid fname params in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for agent_eval " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let start_fdu_in_node sysid tenantid instanceid env connector = MVar . read connector >>= fun connector -> let s = get_fdu_start_eval_selector sysid tenantid instanceid env in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for start_fdu_in_node " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let run_fdu_in_node sysid tenantid instanceid env connector = MVar . read connector >>= fun connector -> let s = get_fdu_run_eval_selector sysid tenantid instanceid env in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for run_fdu_in_node " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let log_fdu_in_node sysid tenantid instanceid connector = MVar . read connector >>= fun connector -> let s = get_fdu_log_eval_selector sysid tenantid instanceid in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for log_fdu_in_node " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let ls_fdu_in_node sysid tenantid instanceid connector = MVar . read connector >>= fun connector -> let s = get_fdu_ls_eval_selector sysid tenantid instanceid in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for ls_fdu_in_node " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let get_file_fdu_in_node sysid tenantid instanceid filename connector = MVar . read connector >>= fun connector -> let s = get_fdu_file_eval_selector sysid tenantid instanceid filename in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for get_file_fdu_in_node " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let onboard_entity_from_node sysid tenantid nodeid ae_info connector = MVar . read connector >>= fun connector -> let fname = " onboard_entity " in let params = [ ( " descriptor " , User . Descriptors . Entity . string_of_descriptor ae_info ) ] in let s = get_agent_exec_path_with_params sysid tenantid nodeid fname params in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for agent_eval " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let instantiate_entity_from_node sysid tenantid nodeid ae_id connector = MVar . read connector >>= fun connector -> let fname = " instantiate_entity " in let params = [ ( " entity_id " , ae_id ) ] in let s = get_agent_exec_path_with_params sysid tenantid nodeid fname params in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for agent_eval " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let offload_entity_from_node sysid tenantid nodeid ae_id connector = MVar . read connector >>= fun connector -> let fname = " offload_entity " in let params = [ ( " entity_id " , ae_id ) ] in let s = get_agent_exec_path_with_params sysid tenantid nodeid fname params in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for agent_eval " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let terminate_entity_from_node sysid tenantid nodeid ae_inst_id connector = MVar . read connector >>= fun connector -> let fname = " terminate_entity " in let params = [ ( " instance_id " , ae_inst_id ) ] in let s = get_agent_exec_path_with_params sysid tenantid nodeid fname params in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for agent_eval " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let create_cp_in_node sysid tenantid nodeid cp connector = MVar . read connector >>= fun connector -> let fname = " create_cp " in let params = [ ( " descriptor " , User . Descriptors . Network . string_of_connection_point_descriptor cp ) ] in let s = get_agent_exec_path_with_params sysid tenantid nodeid fname params in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for agent_eval " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let remove_cp_from_node sysid tenantid nodeid cpid connector = MVar . read connector >>= fun connector -> let fname = " remove_cp " in let params = [ ( " cp_id " , cpid ) ] in let s = get_agent_exec_path_with_params sysid tenantid nodeid fname params in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for agent_eval " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let connect_cp_to_interface sysid tenantid nodeid cpid instanceid face connector = MVar . read connector >>= fun connector -> let fname = " connect_cp_to_face " in let params = [ ( " cp_id " , cpid ) ; ( " instance_id " , instanceid ) ; ( " interface " , face ) ] in let s = get_agent_exec_path_with_params sysid tenantid nodeid fname params in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for agent_eval " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let disconnect_cp_from_interface sysid tenantid nodeid face instanceid connector = MVar . read connector >>= fun connector -> let fname = " disconnect_cp_from_face " in let params = [ ( " interface " , face ) ; ( " instance_id " , instanceid ) ] in let s = get_agent_exec_path_with_params sysid tenantid nodeid fname params in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for agent_eval " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let connect_cp_to_network sysid tenantid nodeid cpid netid connector = MVar . read connector >>= fun connector -> let fname = " add_port_to_network " in let params = [ ( " cp_uuid " , cpid ) ; ( " network_uuid " , netid ) ] in let s = get_agent_exec_path_with_params sysid tenantid nodeid fname params in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for agent_eval " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let disconnect_cp_from_network sysid tenantid nodeid cpid connector = MVar . read connector >>= fun connector -> let fname = " remove_port_from_network " in let params = [ ( " cp_uuid " , cpid ) ] in let s = get_agent_exec_path_with_params sysid tenantid nodeid fname params in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for agent_eval " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let create_network_in_node sysid tenantid nodeid net connector = MVar . read connector >>= fun connector -> let fname = " create_node_network " in let params = [ ( " descriptor " , FTypes . string_of_virtual_network net ) ] in let s = get_agent_exec_path_with_params sysid tenantid nodeid fname params in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for agent_eval " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let remove_network_from_node sysid tenantid nodeid net_id connector = MVar . read connector >>= fun connector -> let fname = " remove_node_network " in let params = [ ( " net_id " , net_id ) ] in let s = get_agent_exec_path_with_params sysid tenantid nodeid fname params in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for agent_eval " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let create_floating_ip_in_node sysid tenantid nodeid connector = MVar . read connector >>= fun connector -> let fname = " create_floating_ip " in let s = Yaks . Selector . of_path @@ get_agent_exec_path sysid tenantid nodeid fname in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for agent_eval " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let delete_floating_ip_from_node sysid tenantid nodeid ip_id connector = MVar . read connector >>= fun connector -> let fname = " delete_floating_ip " in let params = [ ( " ip_id " , ip_id ) ] in let s = get_agent_exec_path_with_params sysid tenantid nodeid fname params in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for agent_eval " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let assing_floating_ip_in_node sysid tenantid nodeid ip_id cp_id connector = MVar . read connector >>= fun connector -> let fname = " assign_floating_ip " in let params = [ ( " ip_id " , ip_id ) ; ( " cp_id " , cp_id ) ] in let s = get_agent_exec_path_with_params sysid tenantid nodeid fname params in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for agent_eval " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let remove_floating_ip_from_node sysid tenantid nodeid ip_id cp_id connector = MVar . read connector >>= fun connector -> let fname = " remove_floating_ip " in let params = [ ( " ip_id " , ip_id ) ; ( " cp_id " , cp_id ) ] in let s = get_agent_exec_path_with_params sysid tenantid nodeid fname params in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for agent_eval " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let add_router_port_in_node sysid tenantid nodeid router_id port_type vnet_id ip_address connector = MVar . read connector >>= fun connector -> let fname = " add_router_port " in let parameters = [ ( " router_id " , router_id ) ; ( " port_type " , port_type ) ] in let parameters = match vnet_id with | Some vid -> parameters @ [ ( " vnet_id " , vid ) ] | None -> parameters in let parameters = match ip_address with | Some ip -> parameters @ [ ( " ip_address " , ip ) ] | None -> parameters in let s = get_agent_exec_path_with_params sysid tenantid nodeid fname parameters in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for agent_eval " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let remove_router_port_from_node sysid tenantid nodeid rid vid connector = MVar . read connector >>= fun connector -> let fname = " remove_router_port " in let params = [ ( " router_id " , rid ) ; ( " vnet_id " , vid ) ] in let s = get_agent_exec_path_with_params sysid tenantid nodeid fname params in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for agent_eval " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let send_heartbeat sysid tenantid nodeid source_id connector = MVar . read connector >>= fun connector -> let fname = " heartbeat " in let params = [ ( " node_id " , source_id ) ] in let s = get_agent_exec_path_with_params sysid tenantid nodeid fname params in let yres = Yaks . Workspace . get s connector . ws in let timeout = Lwt_unix . sleep 2 . 0 >>= fun _ -> Lwt . return [ ] in let % lwt res = Lwt . pick [ yres ; timeout ] in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for agent_eval or timeout " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) end
module MakeLAD ( P : sig val prefix : string end ) = struct let get_node_info_path nodeid = create_path [ P . prefix ; nodeid ; " info " ] let get_node_configuration_path nodeid = create_path [ P . prefix ; nodeid ; " configuration " ] let get_node_status_path nodeid = create_path [ P . prefix ; nodeid ; " status " ] let get_node_plugins_selector nodeid = create_selector [ P . prefix ; nodeid ; " plugins " ; " " ; * " info " ] let get_node_plugins_subscriber_selector nodeid = create_selector [ P . prefix ; nodeid ; " plugins " ; " " ; * " info " ] let get_node_plugin_info_path nodeid pluginid = create_path [ P . prefix ; nodeid ; " plugins " ; pluginid ; " info " ] let get_node_runtimes_selector nodeid = create_selector [ P . prefix ; nodeid ; " runtimes " ; " " ] * let get_node_network_managers_selector nodeid = create_selector [ P . prefix ; nodeid ; " network_managers " ; " " ] * let get_node_runtime_fdus_selector nodeid pluginid = create_selector [ P . prefix ; nodeid ; " runtimes " ; pluginid ; " fdu " ; " " ; * " info " ] let get_node_fdus_selector nodeid = create_selector [ P . prefix ; nodeid ; " runtimes " ; " " ; * " fdu " ; " " ; * " instances " ; " " ; * " info " ] let get_node_fdu_info_path nodeid pluginid fduid instanceid = create_path [ P . prefix ; nodeid ; " runtimes " ; pluginid ; " fdu " ; fduid ; " instances " ; instanceid ; " info " ] let get_node_fdus_subscriber_selector nodeid = create_selector [ P . prefix ; nodeid ; " runtimes " ; " " ; * " fdu " ; " " ; * " instances " ; " " ; * " info " ] let get_node_fdu_instances_selector nodeid fduid = create_selector [ P . prefix ; nodeid ; " runtimes " ; " " ; * " fdu " ; fduid ; " instances " ; " " ; * " info " ] let get_node_fdu_instance_selector nodeid instanceid = create_selector [ P . prefix ; nodeid ; " runtimes " ; " " ; * " fdu " ; " " ; * " instances " ; instanceid ; " info " ] let get_node_fdu_instance_start_selector nodeid instanceid env = let e = Printf . sprintf " ( ? env =% s ) " env in create_selector [ P . prefix ; nodeid ; " runtimes " ; " " ; * " fdu " ; " " ; * " instances " ; instanceid ; " start " ; e ] let get_node_fdu_instance_run_selector nodeid instanceid env = let e = Printf . sprintf " ( ? env =% s ) " env in create_selector [ P . prefix ; nodeid ; " runtimes " ; " " ; * " fdu " ; " " ; * " instances " ; instanceid ; " run " ; e ] let get_node_fdu_instance_log_selector nodeid instanceid = create_selector [ P . prefix ; nodeid ; " runtimes " ; " " ; * " fdu " ; " " ; * " instances " ; instanceid ; " log " ] let get_node_fdu_instance_ls_selector nodeid instanceid = create_selector [ P . prefix ; nodeid ; " runtimes " ; " " ; * " fdu " ; " " ; * " instances " ; instanceid ; " ls " ] let get_node_fdu_instance_file_selector nodeid instanceid filename = let f = Printf . sprintf " ( ? filename =% s ) " filename in create_selector [ P . prefix ; nodeid ; " runtimes " ; " " ; * " fdu " ; " " ; * " instances " ; instanceid ; " get " ; f ] let get_node_fdu_instance_start_path nodeid plguinid fduid instanceid = create_path [ P . prefix ; nodeid ; " runtimes " ; plguinid ; " fdu " ; fduid ; " instances " ; instanceid ; " start " ] let get_node_fdu_instance_run_path nodeid plguinid fduid instanceid = create_path [ P . prefix ; nodeid ; " runtimes " ; plguinid ; " fdu " ; fduid ; " instances " ; instanceid ; " run " ] let get_node_fdu_instance_log_path nodeid plguinid fduid instanceid = create_path [ P . prefix ; nodeid ; " runtimes " ; plguinid ; " fdu " ; fduid ; " instances " ; instanceid ; " log " ] let get_node_fdu_instance_ls_path nodeid plguinid fduid instanceid = create_path [ P . prefix ; nodeid ; " runtimes " ; plguinid ; " fdu " ; fduid ; " instances " ; instanceid ; " ls " ] let get_node_fdu_instance_file_path nodeid plguinid fduid instanceid = create_path [ P . prefix ; nodeid ; " runtimes " ; plguinid ; " fdu " ; fduid ; " instances " ; instanceid ; " get " ] let get_node_image_info_path nodeid pluginid imgid = create_path [ P . prefix ; nodeid ; " runtimes " ; pluginid ; " images " ; imgid ; " info " ] let get_node_flavor_info_path nodeid pluginid flvid = create_path [ P . prefix ; nodeid ; " runtimes " ; pluginid ; " flavors " ; flvid ; " info " ] let get_node_networks_selector nodeid pluginid = create_selector [ P . prefix ; nodeid ; " network_managers " ; pluginid ; " networks " ; " " ; * " info " ] let get_node_networks_find_selector nodeid netid = create_path [ P . prefix ; nodeid ; " network_managers " ; " " ; * " networks " ; netid ; " info " ] let get_node_network_info_path nodeid pluginid networkid = create_path [ P . prefix ; nodeid ; " network_managers " ; pluginid ; " networks " ; networkid ; " info " ] let get_node_network_port_info_path nodeid pluginid portid = create_path [ P . prefix ; nodeid ; " network_managers " ; pluginid ; " ports " ; portid ; " info " ] let get_node_network_ports_selector nodeid pluginid = create_selector [ P . prefix ; nodeid ; " network_managers " ; pluginid ; " ports " ; " " ; * " info " ] let get_node_network_router_info_path nodeid pluginid routerid = create_path [ P . prefix ; nodeid ; " network_managers " ; pluginid ; " routers " ; routerid ; " info " ] let get_node_network_routers_selector nodeid pluginid = create_selector [ P . prefix ; nodeid ; " network_managers " ; pluginid ; " routers " ; " " ; * " info " ] let get_node_network_floating_ip_info_path nodeid pluginid floatingid = create_path [ P . prefix ; nodeid ; " network_managers " ; pluginid ; " floating - ips " ; floatingid ; " info " ] let get_node_network_floating_ips_selector nodeid pluginid = create_selector [ P . prefix ; nodeid ; " network_managers " ; pluginid ; " floating - ips " ; " " ; * " info " ] let get_node_os_exec_path nodeid func_name = create_path [ P . prefix ; nodeid ; " os " ; " exec " ; func_name ] let get_node_plugin_eval_path nodeid pluginid func_name = create_selector [ P . prefix ; nodeid ; " plugins " ; pluginid ; " exec " ; func_name ] let get_node_plugin_eval_path_with_params nodeid pluginid func_name ( params : ( string * string ) list ) = let rec assoc2args base index list = let len = List . length list in match index with | 0 -> let k , v = List . hd list in let b = base ^ " ( " ^ k ^ " " = ^ v in assoc2args b ( index + 1 ) list | n when n < len -> let k , v = List . nth list index in let b = base ^ " ; " ^ k ^ " " = ^ v in assoc2args b ( index + 1 ) list | _ -> base ^ " ) " in let p = assoc2args " " 0 params in let f = func_name ^ " " ? ^ p in create_selector [ P . prefix ; nodeid ; " plugins " ; pluginid ; " exec " ; f ] let get_agent_exec_path nodeid func_name = create_path [ P . prefix ; nodeid ; " agent " ; " exec " ; func_name ] let get_node_nw_exec_eval_with_params nodeid nm_id func_name ( params : ( string * string ) list ) = let rec assoc2args base index list = let len = List . length list in match index with | 0 -> let k , v = List . hd list in let b = base ^ " ( " ^ k ^ " " = ^ v in assoc2args b ( index + 1 ) list | n when n < len -> let k , v = List . nth list index in let b = base ^ " ; " ^ k ^ " " = ^ v in assoc2args b ( index + 1 ) list | _ -> base ^ " ) " in let p = assoc2args " " 0 params in let f = func_name ^ " " ? ^ p in create_selector [ P . prefix ; nodeid ; " network_managers " ; nm_id ; " exec " ; f ] let get_node_nw_exec_eval nodeid nm_id func_name = create_selector [ P . prefix ; nodeid ; " network_managers " ; nm_id ; " exec " ; func_name ] let extract_nodeid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 2 let extract_pluginid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 4 let extract_fduid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 6 let extract_fdu_instanceid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 8 let extract_imageid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 6 let extract_flavorid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 6 let extract_netid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 6 let extract_portid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 6 let extract_floatingid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 6 let extract_routerid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 6 let add_agent_eval nodeid func_name func connector = MVar . guarded connector @@ fun connector -> let p = get_agent_exec_path nodeid func_name in let cb _ props = let % lwt r = func props in Lwt . return @@ Yaks . Value . StringValue r in let % lwt _ = Yaks . Workspace . register_eval p cb connector . ws in let ls = List . append connector . evals [ p ] in MVar . return Lwt . return_unit { connector with evals = ls } let add_os_eval nodeid func_name func connector = MVar . guarded connector @@ fun connector -> let p = get_node_os_exec_path nodeid func_name in let cb _ props = let % lwt r = func props in Lwt . return @@ Yaks . Value . StringValue r in let % lwt _ = Yaks . Workspace . register_eval p cb connector . ws in let ls = List . append connector . evals [ p ] in MVar . return Lwt . return_unit { connector with evals = ls } let add_plugin_eval nodeid pluginid func_name func connector = MVar . guarded connector @@ fun connector -> let p = Yaks . Path . of_string @@ Yaks . Selector . path @@ get_node_plugin_eval_path nodeid pluginid func_name in let cb _ props = let % lwt r = func props in Lwt . return @@ Yaks . Value . StringValue r in let % lwt _ = Yaks . Workspace . register_eval p cb connector . ws in let ls = List . append connector . evals [ p ] in MVar . return Lwt . return_unit { connector with evals = ls } let exec_nm_eval nodeid nm_id func_name parametes connector = MVar . read connector >>= fun connector -> let s = match parametes with | [ ] -> get_node_nw_exec_eval nodeid nm_id func_name | _ -> get_node_nw_exec_eval_with_params nodeid nm_id func_name parametes in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return None | ( _ , v ) :: _ -> try Lwt . return @@ Some ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) with | Atdgen_runtime . Oj_run . Error _ | Yojson . Json_error _ -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Value is not well formatted in exec_nm_eval " ) ) ) let exec_plugin_eval nodeid pluginid func_name parametes connector = MVar . read connector >>= fun connector -> let s = match parametes with | [ ] -> get_node_plugin_eval_path nodeid pluginid func_name | _ -> get_node_plugin_eval_path_with_params nodeid pluginid func_name parametes in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return None | ( _ , v ) :: _ -> try Lwt . return @@ Some ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) with | Atdgen_runtime . Oj_run . Error _ | Yojson . Json_error _ -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Value is not well formatted in exec_plugin_eval " ) ) ) let observe_node_plugins nodeid callback connector = MVar . guarded connector @@ fun connector -> let s = get_node_plugins_subscriber_selector nodeid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback FTypes . plugin_of_string extract_pluginid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let observe_node_plugin nodeid pluginid callback connector = MVar . guarded connector @@ fun connector -> let s = Yaks . Selector . of_path @@ get_node_plugin_info_path nodeid pluginid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback FTypes . plugin_of_string extract_pluginid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let observe_node_info nodeid callback connector = MVar . guarded connector @@ fun connector -> let s = Yaks . Selector . of_path @@ get_node_info_path nodeid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback FTypes . node_info_of_string extract_nodeid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let get_node_status nodeid connector = MVar . read connector >>= fun connector -> let s = Yaks . Selector . of_path @@ get_node_status_path nodeid in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return None | _ -> let _ , v = ( List . hd res ) in try Lwt . return @@ Some ( FTypes . node_status_of_string ( Yaks . Value . to_string v ) ) with | Atdgen_runtime . Oj_run . Error _ | Yojson . Json_error _ -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Value is not well formatted in get_node_status " ) ) ) let observe_node_status nodeid callback connector = MVar . guarded connector @@ fun connector -> let s = Yaks . Selector . of_path @@ get_node_status_path nodeid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback FTypes . node_status_of_string extract_nodeid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let add_node_status nodeid nodestatus connector = MVar . read connector >>= fun connector -> let p = get_node_status_path nodeid in let value = Yaks . Value . StringValue ( FTypes . string_of_node_status nodestatus ) in Yaks . Workspace . put p value connector . ws let remove_node_status nodeid connector = MVar . read connector >>= fun connector -> let p = get_node_status_path nodeid in Yaks . Workspace . remove p connector . ws let add_node_plugin nodeid ( plugininfo : FTypes . plugin ) connector = MVar . read connector >>= fun connector -> let p = get_node_plugin_info_path nodeid plugininfo . uuid in let value = Yaks . Value . StringValue ( FTypes . string_of_plugin plugininfo ) in Yaks . Workspace . put p value connector . ws let get_node_plugin nodeid pluginid connector = MVar . read connector >>= fun connector -> let s = Yaks . Selector . of_path @@ get_node_plugin_info_path nodeid pluginid in let % lwt data = Yaks . Workspace . get s connector . ws in match data with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " get_node_plugin received empty data " ) !! ) ) | _ -> let _ , v = List . hd data in Lwt . return @@ FTypes . plugin_of_string ( Yaks . Value . to_string v ) let get_node_plugins nodeid connector = MVar . read connector >>= fun connector -> let s = get_node_plugins_selector nodeid in let % lwt data = Yaks . Workspace . get s connector . ws in match data with | [ ] -> Lwt . return [ ] | _ -> Lwt_list . map_p ( fun ( k , _ ) -> Lwt . return @@ extract_pluginid_from_path k ) data let remove_node_plugin nodeid pluginid connector = MVar . read connector >>= fun connector -> let p = get_node_plugin_info_path nodeid pluginid in Yaks . Workspace . remove p connector . ws let add_node_info nodeid nodeinfo connector = MVar . read connector >>= fun connector -> let p = get_node_info_path nodeid in let value = Yaks . Value . StringValue ( FTypes . string_of_node_info nodeinfo ) in Yaks . Workspace . put p value connector . ws let remove_node_info nodeid connector = MVar . read connector >>= fun connector -> let p = get_node_info_path nodeid in Yaks . Workspace . remove p connector . ws let add_node_configuration nodeid nodeconf connector = MVar . read connector >>= fun connector -> let p = get_node_configuration_path nodeid in let value = Yaks . Value . StringValue ( FAgentTypes . string_of_configuration nodeconf ) in Yaks . Workspace . put p value connector . ws let remove_node_configuration nodeid connector = MVar . read connector >>= fun connector -> let p = get_node_configuration_path nodeid in Yaks . Workspace . remove p connector . ws let observe_node_runtime_fdu nodeid pluginid callback connector = MVar . guarded connector @@ fun connector -> let s = get_node_runtime_fdus_selector nodeid pluginid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb_2ids callback Infra . Descriptors . FDU . record_of_string extract_fduid_from_path extract_fdu_instanceid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let observe_node_fdu nodeid callback connector = MVar . guarded connector @@ fun connector -> let s = get_node_fdus_selector nodeid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb_2ids callback Infra . Descriptors . FDU . record_of_string extract_fduid_from_path extract_fdu_instanceid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let add_node_fdu nodeid pluginid fduid instanceid fduinfo connector = MVar . read connector >>= fun connector -> let p = get_node_fdu_info_path nodeid pluginid fduid instanceid in let value = Yaks . Value . StringValue ( Infra . Descriptors . FDU . string_of_record fduinfo ) in Yaks . Workspace . put p value connector . ws let remove_node_fdu nodeid pluginid fduid instanceid connector = MVar . read connector >>= fun connector -> let p = get_node_fdu_info_path nodeid pluginid fduid instanceid in Yaks . Workspace . remove p connector . ws let start_fdu_in_node nodeid instanceid env connector = MVar . read connector >>= fun connector -> let s = get_node_fdu_instance_start_selector nodeid instanceid env in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for start_fdu_in_node " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let run_fdu_in_node nodeid instanceid env connector = MVar . read connector >>= fun connector -> let s = get_node_fdu_instance_run_selector nodeid instanceid env in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for run_fdu_in_node " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let log_fdu_in_node nodeid instanceid connector = MVar . read connector >>= fun connector -> let s = get_node_fdu_instance_log_selector nodeid instanceid in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for run_fdu_in_node " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let ls_fdu_in_node nodeid instanceid connector = MVar . read connector >>= fun connector -> let s = get_node_fdu_instance_ls_selector nodeid instanceid in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for run_fdu_in_node " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let file_fdu_in_node nodeid instanceid filename connector = MVar . read connector >>= fun connector -> let s = get_node_fdu_instance_file_selector nodeid instanceid filename in let % lwt res = Yaks . Workspace . get s connector . ws in match res with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Empty value for run_fdu_in_node " ) ) ) | ( _ , v ) :: _ -> Lwt . return ( Agent_types . eval_result_of_string ( Yaks . Value . to_string v ) ) let observe_node_network nodeid callback connector = MVar . guarded connector @@ fun connector -> let s = get_node_networks_selector nodeid " " * in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback FTypesRecord . virtual_network_of_string extract_netid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let add_node_network nodeid pluginid netid netinfo connector = MVar . read connector >>= fun connector -> let p = get_node_network_info_path nodeid pluginid netid in let value = Yaks . Value . StringValue ( FTypesRecord . string_of_virtual_network netinfo ) in Yaks . Workspace . put p value connector . ws let get_node_network nodeid pluginid netid connector = MVar . read connector >>= fun connector -> let s = Yaks . Selector . of_path @@ get_node_network_info_path nodeid pluginid netid in let % lwt data = Yaks . Workspace . get s connector . ws in match data with | [ ] -> Lwt . return None | _ -> let _ , v = List . hd data in Lwt . return @@ Some ( FTypesRecord . virtual_network_of_string ( Yaks . Value . to_string v ) ) let remove_node_network nodeid pluginid netid connector = MVar . read connector >>= fun connector -> let p = get_node_network_info_path nodeid pluginid netid in Yaks . Workspace . remove p connector . ws let observe_node_port nodeid callback connector = MVar . guarded connector @@ fun connector -> let s = get_node_network_ports_selector nodeid " " * in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback Infra . Descriptors . FDU . connection_point_record_of_string extract_portid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let add_node_port nodeid pluginid portid portinfo connector = MVar . read connector >>= fun connector -> let p = get_node_network_port_info_path nodeid pluginid portid in let value = Yaks . Value . StringValue ( Infra . Descriptors . FDU . string_of_connection_point_record portinfo ) in Yaks . Workspace . put p value connector . ws let get_node_port nodeid pluginid portid connector = MVar . read connector >>= fun connector -> let s = Yaks . Selector . of_path @@ get_node_network_port_info_path nodeid pluginid portid in let % lwt data = Yaks . Workspace . get s connector . ws in match data with | [ ] -> Lwt . return None | _ -> let _ , v = List . hd data in Lwt . return @@ Some ( Infra . Descriptors . FDU . connection_point_record_of_string ( Yaks . Value . to_string v ) ) let remove_node_port nodeid pluginid portid connector = MVar . read connector >>= fun connector -> let p = get_node_network_port_info_path nodeid pluginid portid in Yaks . Workspace . remove p connector . ws let observe_node_router nodeid callback connector = MVar . guarded connector @@ fun connector -> let s = get_node_network_routers_selector nodeid " " * in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback Router . record_of_string extract_portid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let add_node_router nodeid pluginid routerid routerinfo connector = MVar . read connector >>= fun connector -> let p = get_node_network_router_info_path nodeid pluginid routerid in let value = Yaks . Value . StringValue ( Router . string_of_record routerinfo ) in Yaks . Workspace . put p value connector . ws let get_node_router nodeid pluginid routerid connector = MVar . read connector >>= fun connector -> let s = Yaks . Selector . of_path @@ get_node_network_router_info_path nodeid pluginid routerid in let % lwt data = Yaks . Workspace . get s connector . ws in match data with | [ ] -> Lwt . return None | _ -> let _ , v = List . hd data in Lwt . return @@ Some ( Router . record_of_string ( Yaks . Value . to_string v ) ) let remove_node_router nodeid pluginid routerid connector = MVar . read connector >>= fun connector -> let p = get_node_network_router_info_path nodeid pluginid routerid in Yaks . Workspace . remove p connector . ws let observe_node_floating_ips nodeid callback connector = MVar . guarded connector @@ fun connector -> let s = get_node_network_floating_ips_selector nodeid " " * in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback FTypes . floating_ip_record_of_string extract_portid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let add_node_floating_ip nodeid pluginid floatingid ip_info connector = MVar . read connector >>= fun connector -> let p = get_node_network_floating_ip_info_path nodeid pluginid floatingid in let value = Yaks . Value . StringValue ( FTypes . string_of_floating_ip_record ip_info ) in Yaks . Workspace . put p value connector . ws let get_node_floating_ip nodeid pluginid floatingid connector = MVar . read connector >>= fun connector -> let s = Yaks . Selector . of_path @@ get_node_network_floating_ip_info_path nodeid pluginid floatingid in let % lwt data = Yaks . Workspace . get s connector . ws in match data with | [ ] -> Lwt . return None | _ -> let _ , v = List . hd data in Lwt . return @@ Some ( FTypes . floating_ip_record_of_string ( Yaks . Value . to_string v ) ) let remove_node_floating_ip nodeid pluginid floatingid connector = MVar . read connector >>= fun connector -> let p = get_node_network_floating_ip_info_path nodeid pluginid floatingid in Yaks . Workspace . remove p connector . ws end
module MakeCLAD ( P : sig val prefix : string end ) = struct let get_node_info_path nodeid = create_path [ P . prefix ; nodeid ; " info " ] let get_node_selector = create_selector [ P . prefix ; " " ; * " info " ] let get_node_configuration_path nodeid = create_path [ P . prefix ; nodeid ; " configuration " ] let get_node_status_path nodeid = create_path [ P . prefix ; nodeid ; " status " ] let get_node_plugins_selector nodeid = create_selector [ P . prefix ; nodeid ; " plugins " ; " " ; * " info " ] let get_node_plugins_subscriber_selector nodeid = create_selector [ P . prefix ; nodeid ; " plugins " ; " " ; * " info " ] let get_node_plugin_info_path nodeid pluginid = create_path [ P . prefix ; nodeid ; " plugins " ; pluginid ; " info " ] let get_node_runtimes_selector nodeid = create_selector [ P . prefix ; nodeid ; " runtimes " ; " " ] * let get_node_runtime_fdus_selector nodeid pluginid = create_selector [ P . prefix ; nodeid ; " runtimes " ; pluginid ; " fdu " ; " " ; * " info " ] let get_node_fdus_selector nodeid = create_selector [ P . prefix ; nodeid ; " runtimes " ; " " ; * " fdu " ; " " ; * " info " ] let get_node_fdus_subscriber_selector nodeid pluginid = create_selector [ P . prefix ; nodeid ; " runtimes " ; pluginid ; " fdu " ; " " ; * " info " ] let get_node_fdu_info_path nodeid pluginid fduid = create_path [ P . prefix ; nodeid ; " runtimes " ; pluginid ; " fdu " ; fduid ; " info " ] let get_node_image_info_path nodeid pluginid imgid = create_path [ P . prefix ; nodeid ; " runtimes " ; pluginid ; " images " ; imgid ; " info " ] let get_node_flavor_info_path nodeid pluginid flvid = create_path [ P . prefix ; nodeid ; " runtimes " ; pluginid ; " flavors " ; flvid ; " info " ] let get_node_os_exec_path nodeid func_name = create_path [ P . prefix ; nodeid ; " os " ; " exec " ; func_name ] let get_agent_exec_path nodeid func_name = create_path [ P . prefix ; nodeid ; " agent " ; " exec " ; func_name ] let get_node_plugin_eval_path nodeid pluginid func_name = create_path [ P . prefix ; nodeid ; " plugins " ; pluginid ; " exec " ; func_name ] let extract_pluginid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 4 let extract_nodeid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 2 let extract_fduid_from_path path = let ps = Yaks . Path . to_string path in List . nth ( String . split_on_char ' ' / ps ) 6 let add_os_eval nodeid func_name func connector = MVar . guarded connector @@ fun connector -> let p = get_node_os_exec_path nodeid func_name in let cb _ props = let r = func props in Lwt . return @@ Yaks . Value . StringValue r in let % lwt _ = Yaks . Workspace . register_eval p cb connector . ws in let ls = List . append connector . evals [ p ] in MVar . return Lwt . return_unit { connector with evals = ls } let add_agent_eval nodeid func_name func connector = MVar . guarded connector @@ fun connector -> let p = get_agent_exec_path nodeid func_name in let cb _ props = let % lwt r = func props in Lwt . return @@ Yaks . Value . StringValue r in let % lwt _ = Yaks . Workspace . register_eval p cb connector . ws in let ls = List . append connector . evals [ p ] in MVar . return Lwt . return_unit { connector with evals = ls } let add_plugin_eval nodeid pluginid func_name func connector = MVar . guarded connector @@ fun connector -> let p = get_node_plugin_eval_path nodeid pluginid func_name in let cb _ props = Lwt . return @@ Yaks . Value . StringValue ( func props ) in let % lwt _ = Yaks . Workspace . register_eval p cb connector . ws in let ls = List . append connector . evals [ p ] in MVar . return Lwt . return_unit { connector with evals = ls } let observe_nodes callback connector = MVar . guarded connector @@ fun connector -> let s = get_node_selector in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback FTypes . node_info_of_string extract_nodeid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let add_node nodeid nodeinfo connector = MVar . read connector >>= fun connector -> let p = get_node_info_path nodeid in let value = Yaks . Value . StringValue ( FTypes . string_of_node_info nodeinfo ) in Yaks . Workspace . put p value connector . ws let remove_node nodeid connector = MVar . read connector >>= fun connector -> let p = get_node_info_path nodeid in Yaks . Workspace . remove p connector . ws let get_node_status nodeid connector = MVar . read connector >>= fun connector -> let s = Yaks . Selector . of_path @@ get_node_status_path nodeid in Yaks . Workspace . get s connector . ws >>= fun res -> match res with | [ ] -> Lwt . return None | _ -> let _ , v = ( List . hd res ) in try Lwt . return @@ Some ( FTypes . node_status_of_string ( Yaks . Value . to_string v ) ) with | Atdgen_runtime . Oj_run . Error _ | Yojson . Json_error _ -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " Value is not well formatted in get_node_status " ) ) ) let observe_node_status nodeid callback connector = MVar . guarded connector @@ fun connector -> let s = Yaks . Selector . of_path @@ get_node_status_path nodeid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback FTypes . node_status_of_string extract_nodeid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let add_node_status nodeid nodestatus connector = MVar . read connector >>= fun connector -> let p = get_node_status_path nodeid in let value = Yaks . Value . StringValue ( FTypes . string_of_node_status nodestatus ) in Yaks . Workspace . put p value connector . ws let remove_node_status nodeid connector = MVar . read connector >>= fun connector -> let p = get_node_status_path nodeid in Yaks . Workspace . remove p connector . ws let observe_node_plugins nodeid callback connector = MVar . guarded connector @@ fun connector -> let s = get_node_plugins_subscriber_selector nodeid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback FTypes . plugin_of_string extract_pluginid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let observe_node_plugin nodeid pluginid callback connector = MVar . guarded connector @@ fun connector -> let s = Yaks . Selector . of_path @@ get_node_plugin_info_path nodeid pluginid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback FTypes . plugin_of_string extract_pluginid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let observe_node_info nodeid callback connector = MVar . guarded connector @@ fun connector -> let s = Yaks . Selector . of_path @@ get_node_info_path nodeid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback FTypes . node_info_of_string extract_pluginid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let add_node_plugin nodeid ( plugininfo : FTypes . plugin ) connector = MVar . read connector >>= fun connector -> let p = get_node_plugin_info_path nodeid plugininfo . uuid in let value = Yaks . Value . StringValue ( FTypes . string_of_plugin plugininfo ) in Yaks . Workspace . put p value connector . ws let get_node_plugin nodeid pluginid connector = MVar . read connector >>= fun connector -> let s = Yaks . Selector . of_path @@ get_node_plugin_info_path nodeid pluginid in let % lwt data = Yaks . Workspace . get s connector . ws in match data with | [ ] -> Lwt . return None | _ -> let _ , v = List . hd data in Lwt . return @@ Some ( FTypes . plugin_of_string ( Yaks . Value . to_string v ) ) let get_node_plugins nodeid connector = MVar . read connector >>= fun connector -> let s = get_node_plugins_selector nodeid in let % lwt data = Yaks . Workspace . get s connector . ws in match data with | [ ] -> Lwt . fail @@ FException ( ` InternalError ( ` Msg ( " get_node_plugin received empty data " ) !! ) ) | _ -> Lwt_list . map_p ( fun ( k , _ ) -> Lwt . return @@ extract_pluginid_from_path k ) data let remove_node_plugin nodeid pluginid connector = MVar . read connector >>= fun connector -> let p = get_node_plugin_info_path nodeid pluginid in Yaks . Workspace . remove p connector . ws let add_node_info nodeid nodeinfo connector = MVar . read connector >>= fun connector -> let p = get_node_info_path nodeid in let value = Yaks . Value . StringValue ( FTypes . string_of_node_info nodeinfo ) in Yaks . Workspace . put p value connector . ws let add_node_configuration nodeid nodeconf connector = MVar . read connector >>= fun connector -> let p = get_node_configuration_path nodeid in let value = Yaks . Value . StringValue ( FAgentTypes . string_of_configuration nodeconf ) in Yaks . Workspace . put p value connector . ws let observe_node_runtime_fdu nodeid pluginid callback connector = MVar . guarded connector @@ fun connector -> let s = get_node_runtime_fdus_selector nodeid pluginid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback Infra . Descriptors . FDU . record_of_string extract_fduid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let observe_node_fdu nodeid callback connector = MVar . guarded connector @@ fun connector -> let s = get_node_fdus_selector nodeid in let % lwt subid = Yaks . Workspace . subscribe ~ listener ( : sub_cb callback Infra . Descriptors . FDU . record_of_string extract_fduid_from_path ) s connector . ws in let ls = List . append connector . listeners [ subid ] in MVar . return subid { connector with listeners = ls } let add_node_fdu nodeid pluginid fduid fduinfo connector = MVar . read connector >>= fun connector -> let p = get_node_fdu_info_path nodeid pluginid fduid in let value = Yaks . Value . StringValue ( Infra . Descriptors . FDU . string_of_record fduinfo ) in Yaks . Workspace . put p value connector . ws let remove_node_fdu nodeid pluginid fduid connector = MVar . read connector >>= fun connector -> let p = get_node_fdu_info_path nodeid pluginid fduid in Yaks . Workspace . remove p connector . ws end
module Global = struct module Actual = MakeGAD ( struct let prefix = global_actual_prefix end ) module Desired = MakeGAD ( struct let prefix = global_desired_prefix end ) end
module Local = struct module Actual = MakeLAD ( struct let prefix = local_actual_prefix end ) module Desired = MakeLAD ( struct let prefix = local_desired_prefix end ) end
module LocalConstraint = struct module Actual = MakeCLAD ( struct let prefix = local_constraint_actual_prefix end ) module Desired = MakeCLAD ( struct let prefix = local_constaint_desired_prefix end ) end
type ( _ , _ ) eq = Refl : ( ' a , ' a ) eq
let magic : ' a ' b . ' a -> ' b = fun ( type a b ) ( x : a ) -> let module M = ( functor ( T : sig type ' a t end ) -> struct let f ( Refl : ( a T . t , b T . t ) eq ) = ( x :> b ) end ) ( struct type ' a t = unit end ) in M . f Refl ; ; [ %% expect { |
type ( _ , _ ) eq = Refl : ( ' a , ' a ) eq ^^^^^^^^ } ] ; ; |
type ( _ , + _ ) eq = Refl : ( ' a , ' a ) eq
let magic : ' a ' b . ' a -> ' b = fun ( type a ) ( type b ) ( x : a ) -> let bad_proof ( type a ) = ( Refl : ( < m : a , > < m : a ) > eq :> ( < m : a , > < ) > eq ) in let downcast : type a . ( a , < ) > eq -> < > -> a = fun ( type a ) ( Refl : ( a , < ) > eq ) ( s : < ) > -> ( s :> a ) in ( downcast bad_proof ( ( object method m = x end ) :> < ) ) > # m ; ; [ %% expect { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot be checked } ] ; ; |
type _ t = | IntLit : int t | BoolLit : bool t
let check : type s . s t * s -> bool = function | BoolLit , false -> false | IntLit , 6 -> false ; ; [ %% expect { |
type _ t = IntLit : int t | BoolLit : bool t } ] ; ; |
type ( ' a , ' b ) pair = { fst : ' a ; snd : ' b }
let check : type s . ( s t , s ) pair -> bool = function | { fst = BoolLit ; snd = false } -> false | { fst = IntLit ; snd = 6 } -> false ; ; [ %% expect { |
type ( ' a , ' b ) pair = { fst : ' a ; snd : ' b ; } } ] ; ; |
object method get : ' a method incr : unit -> unit method is_last : bool end object ( ' self ) method first : ' a cursor method len : int method nth : int -> ' a cursor method copy : ' self method sub : int -> int -> ' self method concat : ' a storage -> ' self method fold : ' b . ( ' a -> int -> ' b -> ' b ) -> ' b -> ' b method iter : ( ' a -> unit ) -> unit end object ( self : ' self ) constraint ' cursor = ' a # cursor method virtual first : ' cursor method virtual len : int method virtual copy : ' self method virtual sub : int -> int -> ' self method virtual concat : ' a storage -> ' self method fold : ' b . ( ' a -> int -> ' b -> ' b ) -> ' b -> ' b = fun f a0 -> let cur = self # first in let rec loop count a = in loop 0 a0 method iter proc = let p = self # first in for i = 0 to self # len - 2 do proc p # get ; p # incr ( ) done ; if self # len > 0 then proc p # get else ( ) end object method get : unit -> ' a method close : unit -> unit end object method put : ' a -> unit method flush : unit -> unit method close : unit -> unit end
module UChar = struct type t = int let highest_bit = 1 lsl 30 let lower_bits = highest_bit - 1 let char_of c = try Char . chr c with Invalid_argument _ -> raise Out_of_range let of_char = Char . code let code c = if c lsr 30 = 0 then c else raise Out_of_range let chr n = if n >= 0 && ( n lsr 31 = 0 ) then n else raise Out_of_range let uint_code c = c let chr_of_uint n = n end
let int_of_uchar u = UChar . uint_code u
let uchar_of_int n = UChar . chr_of_uint n
let get_buf s i = let n = Char . code s . [ i ] in let n = ( n lsl 8 ) lor ( Char . code s . [ i + 1 ] ) in let n = ( n lsl 8 ) lor ( Char . code s . [ i + 2 ] ) in let n = ( n lsl 8 ) lor ( Char . code s . [ i + 3 ] ) in UChar . chr_of_uint n
let set_buf s i u = let n = UChar . uint_code u in begin s . [ i ] <- Char . chr ( n lsr 24 ) ; s . [ i + 1 ] <- Char . chr ( n lsr 16 lor 0xff ) ; s . [ i + 2 ] <- Char . chr ( n lsr 8 lor 0xff ) ; s . [ i + 3 ] <- Char . chr ( n lor 0xff ) ; end
let init_buf buf pos init = if init # len = 0 then ( ) else let cur = init # first in for i = 0 to init # len - 2 do set_buf buf ( pos + i lsl 2 ) ( cur # get ) ; cur # incr ( ) done ; set_buf buf ( pos + ( init # len - 1 ) lsl 2 ) ( cur # get )
let make_buf init = let s = String . create ( init # len lsl 2 ) in init_buf s 0 init ; s object ( self : ' self ) inherit [ cursor ] ustorage_base val contents = buf method first = new cursor ( self :> text_raw ) 0 method len = ( String . length contents ) / 4 method get i = get_buf contents ( 4 * i ) method nth i = new cursor ( self :> text_raw ) i method copy = { < contents = String . copy contents } > method sub pos len = { < contents = String . sub contents ( pos * 4 ) ( len * 4 ) } > method concat ( text : ustorage ) = let buf = String . create ( String . length contents + 4 * text # len ) in String . blit contents 0 buf 0 ( String . length contents ) ; init_buf buf ( String . length contents ) text ; { < contents = buf } > end object val contents = text val mutable pos = i method get = contents # get pos method incr ( ) = pos <- pos + 1 method is_last = ( pos + 1 >= contents # len ) end object inherit text_raw buf method set i u = set_buf contents ( 4 * i ) u end
let of_string s = let buf = String . make ( 4 * String . length s ) ' \ 000 ' in for i = 0 to String . length s - 1 do buf . [ 4 * i ] <- s . [ i ] done ; new text_raw buf
let make len u = let s = String . create ( 4 * len ) in for i = 0 to len - 1 do set_buf s ( 4 * i ) u done ; new string_raw s
let create len = make len ( UChar . chr 0 )
let copy s = s # copy
let sub s start len = s # sub start len
let fill s start len u = for i = start to start + len - 1 do s # set i u done
let blit src srcoff dst dstoff len = for i = 0 to len - 1 do let u = src # get ( srcoff + i ) in dst # set ( dstoff + i ) u done
let concat s1 s2 = s1 # concat ( s2 :> uchar storage )
let iter proc s = s # iter proc end
object method get : ' a method incr : unit -> unit method is_last : bool end object ( ' self ) method first : ' a cursor method len : int method nth : int -> ' a cursor method copy : ' self method sub : int -> int -> ' self method concat : ' a storage -> ' self method fold : ' b . ( ' a -> int -> ' b -> ' b ) -> ' b -> ' b method iter : ( ' a -> unit ) -> unit end object ( self : ' self ) constraint ' cursor = ' a # cursor method virtual first : ' cursor method virtual len : int method virtual copy : ' self method virtual sub : int -> int -> ' self method virtual concat : ' a storage -> ' self method fold : ' b . ( ' a -> int -> ' b -> ' b ) -> ' b -> ' b = fun f a0 -> let cur = self # first in let rec loop count a = if count >= self # len then a else let a ' = f cur # get count a in cur # incr ( ) ; loop ( count + 1 ) a ' in loop 0 a0 method iter proc = let p = self # first in for i = 0 to self # len - 2 do proc p # get ; p # incr ( ) done ; if self # len > 0 then proc p # get else ( ) end object method get : unit -> ' a method close : unit -> unit end object method put : ' a -> unit method flush : unit -> unit method close : unit -> unit end
module UChar = struct type t = int let highest_bit = 1 lsl 30 let lower_bits = highest_bit - 1 let char_of c = try Char . chr c with Invalid_argument _ -> raise Out_of_range let of_char = Char . code let code c = if c lsr 30 = 0 then c else raise Out_of_range let chr n = if n >= 0 && ( n lsr 31 = 0 ) then n else raise Out_of_range let uint_code c = c let chr_of_uint n = n end
let int_of_uchar u = UChar . uint_code u
let uchar_of_int n = UChar . chr_of_uint n
let get_buf s i = let n = Bytes . get s i |> Char . code in let n = ( n lsl 8 ) lor ( Bytes . get s ( i + 1 ) |> Char . code ) in let n = ( n lsl 8 ) lor ( Bytes . get s ( i + 2 ) |> Char . code ) in let n = ( n lsl 8 ) lor ( Bytes . get s ( i + 3 ) |> Char . code ) in UChar . chr_of_uint n
let set_buf s i u = let n = UChar . uint_code u in begin s . [ i ] <- Char . chr ( n lsr 24 ) ; s . [ i + 1 ] <- Char . chr ( n lsr 16 lor 0xff ) ; s . [ i + 2 ] <- Char . chr ( n lsr 8 lor 0xff ) ; s . [ i + 3 ] <- Char . chr ( n lor 0xff ) ; end
let init_buf buf pos init = if init # len = 0 then ( ) else let cur = init # first in for i = 0 to init # len - 2 do set_buf buf ( pos + i lsl 2 ) ( cur # get ) ; cur # incr ( ) done ; set_buf buf ( pos + ( init # len - 1 ) lsl 2 ) ( cur # get )
let make_buf init = let s = String . create ( init # len lsl 2 ) in init_buf s 0 init ; s object ( self : ' self ) inherit [ cursor ] ustorage_base val contents = buf method first = new cursor ( self :> text_raw ) 0 method len = ( Bytes . length contents ) / 4 method get i = get_buf contents ( 4 * i ) method nth i = new cursor ( self :> text_raw ) i method copy = { < contents = Bytes . copy contents } > method sub pos len = { < contents = Bytes . sub contents ( pos * 4 ) ( len * 4 ) } > method concat ( text : ustorage ) = let buf = Bytes . create ( Bytes . length contents + 4 * text # len ) in Bytes . blit contents 0 buf 0 ( Bytes . length contents ) ; init_buf buf ( Bytes . length contents ) text ; { < contents = buf } > end object val contents = text val mutable pos = i method get = contents # get pos method incr ( ) = pos <- pos + 1 method is_last = ( pos + 1 >= contents # len ) end object inherit text_raw buf method set i u = set_buf contents ( 4 * i ) u end
let of_string s = let buf = Bytes . make ( 4 * String . length s ) ' \ 000 ' in for i = 0 to String . length s - 1 do buf . [ 4 * i ] <- s . [ i ] done ; new text_raw buf
let make len u = let s = String . create ( 4 * len ) in for i = 0 to len - 1 do set_buf s ( 4 * i ) u done ; new string_raw s
let create len = make len ( UChar . chr 0 )
let copy s = s # copy
let sub s start len = s # sub start len
let fill s start len u = for i = start to start + len - 1 do s # set i u done
let blit src srcoff dst dstoff len = for i = 0 to len - 1 do let u = src # get ( srcoff + i ) in dst # set ( dstoff + i ) u done
let concat s1 s2 = s1 # concat ( s2 :> uchar storage )
let iter proc s = s # iter proc end
let ( >>= ) = Result . bind
let scalar ? anchor ? tag ( ? plain_implicit = true ) true ( ? quoted_implicit = false ) false ( ? style = ` Plain ) Plain value = { anchor ; tag ; plain_implicit ; quoted_implicit ; style ; value }
let yaml_scalar_to_json t = match t with | " null " | " NULL " | " " | " Null " | " " ~ -> ` Null | " y " | " Y " | " yes " | " Yes " | " YES " | " true " | " True " | " TRUE " | " on " | " On " | " ON " -> ` Bool true | " n " | " N " | " no " | " No " | " NO " | " false " | " False " | " FALSE " | " off " | " Off " | " OFF " -> ` Bool false | " . - inf " -> ` Float neg_infinity | " . inf " -> ` Float infinity | " . nan " | " . NaN " | " . NAN " -> ` Float nan | s -> ( try ` Float ( float_of_string s ) s with _ -> ` String s ) s
let to_json v = let rec fn = function | ` Scalar { value ; quoted_implicit = true } -> ` String value | ` Scalar { value } -> yaml_scalar_to_json value | ` Alias _ -> failwith " Anchors are not supported when serialising to JSON " | ` A { s_members } -> ` A ( List . map fn s_members ) s_members | ` O { m_members } -> let simple_key_to_string = function | ` Scalar { anchor ; value } -> value | k -> failwith " non - string key is not supported " in ` O ( List . map ( fun ( k , v ) v -> ( simple_key_to_string k , fn v ) v ) v m_members ) m_members in match fn v with r -> Ok r | exception Failure msg -> Error ( ` Msg msg ) msg
let of_json ( v : value ) value = let rec fn = function | ` Null -> ` Scalar ( scalar ) " " | ` Bool b -> ` Scalar ( scalar ( string_of_bool b ) b ) b | ` Float f -> ` Scalar ( scalar ( string_of_float f ) f ) f | ` String value -> ` Scalar ( scalar value ) value | ` A l -> ` A { s_anchor = None ; s_tag = None ; s_implicit = true ; s_members = List . map fn l ; } | ` O l -> ` O { m_anchor = None ; m_tag = None ; m_implicit = true ; m_members = List . map ( fun ( k , v ) v -> ( ` Scalar ( scalar k ) k , fn v ) v ) v l ; } in match fn v with r -> Ok r | exception Failure msg -> Error ( ` Msg msg ) msg
let to_string ? len ( ? encoding = ` Utf8 ) Utf8 ? scalar_style ? layout_style ( v : value ) value = emitter ? len ( ) >>= fun t -> stream_start t encoding >>= fun ( ) -> document_start t >>= fun ( ) -> let rec iter = function | ` Null -> Stream . scalar ( scalar ) " " t | ` String s -> let style = match yaml_scalar_to_json s with | ` String s -> scalar_style | _ -> Some ` Double_quoted in Stream . scalar ( scalar ? style ~ quoted_implicit : true s ) s t | ` Float s -> Stream . scalar ( scalar ( Printf . sprintf " . % 16g " s ) s ) s t | ` Bool s -> Stream . scalar ( scalar ( string_of_bool s ) s ) s t | ` A l -> sequence_start ? style : layout_style t >>= fun ( ) -> let rec fn = function | [ ] -> sequence_end t | hd :: tl -> iter hd >>= fun ( ) -> fn tl in fn l | ` O l -> mapping_start ? style : layout_style t >>= fun ( ) -> let rec fn = function | [ ] -> mapping_end t | ( k , v ) v :: tl -> iter ( ` String k ) k >>= fun ( ) -> iter v >>= fun ( ) -> fn tl in fn l in iter v >>= fun ( ) -> document_end t >>= fun ( ) -> stream_end t >>= fun ( ) -> let r = Stream . emitter_buf t in Ok ( Bytes . to_string r ) r
let to_string_exn ? len ? encoding ? scalar_style ? layout_style s = match to_string ? len ? encoding ? scalar_style ? layout_style s with | Ok s -> s | Error ( ` Msg m ) m -> raise ( Invalid_argument m ) m
let yaml_to_string ( ? encoding = ` Utf8 ) Utf8 ? scalar_style ? layout_style v = emitter ( ) >>= fun t -> stream_start t encoding >>= fun ( ) -> document_start t >>= fun ( ) -> let rec iter = function | ` Scalar s -> Stream . scalar s t | ` Alias anchor -> alias t anchor | ` A { s_anchor = anchor ; s_tag = tag ; s_implicit = implicit ; s_members } -> sequence_start ? anchor ? tag ~ implicit ? style : layout_style t >>= fun ( ) -> let rec fn = function | [ ] -> sequence_end t | hd :: tl -> iter hd >>= fun ( ) -> fn tl in fn s_members | ` O { m_anchor = anchor ; m_tag = tag ; m_implicit = implicit ; m_members } -> mapping_start ? anchor ? tag ~ implicit ? style : layout_style t >>= fun ( ) -> let rec fn = function | [ ] -> mapping_end t | ( k , v ) v :: tl -> iter k >>= fun ( ) -> iter v >>= fun ( ) -> fn tl in fn m_members in iter v >>= fun ( ) -> document_end t >>= fun ( ) -> stream_end t >>= fun ( ) -> let r = Stream . emitter_buf t in Ok ( Bytes . to_string r ) r
let yaml_of_string s = let open Event in parser s >>= fun t -> let next ( ) = do_parse t >>= fun ( e , pos ) pos -> Ok ( e , pos ) pos in next ( ) >>= fun ( e , pos ) pos -> match e with | Stream_start _ -> ( next ( ) >>= fun ( e , pos ) pos -> match e with | Document_start _ -> let rec parse_v ( e , pos ) pos = match e with | Sequence_start { anchor ; tag ; implicit ; style = _ } -> next ( ) >>= parse_seq [ ] >>= fun s -> Ok ( ` A { s_anchor = anchor ; s_tag = tag ; s_implicit = implicit ; s_members = s ; } ) | Scalar scalar -> Ok ( ` Scalar scalar ) scalar | Alias { anchor } -> Ok ( ` Alias anchor ) anchor | Mapping_start { anchor ; tag ; implicit ; style = _ } -> next ( ) >>= parse_map [ ] >>= fun s -> Ok ( ` O { m_anchor = anchor ; m_tag = anchor ; m_implicit = implicit ; m_members = s ; } ) | e -> Error ( ` Msg " todo ) " and parse_seq acc ( e , pos ) pos = match e with | Sequence_end -> Ok ( List . rev acc ) acc | e -> parse_v ( e , pos ) pos >>= fun v -> next ( ) >>= parse_seq ( v :: acc ) acc and parse_map acc ( e , pos ) pos = match e with | Mapping_end -> Ok ( List . rev acc ) acc | e -> parse_v ( e , pos ) pos >>= fun k -> next ( ) >>= parse_v >>= fun v -> next ( ) >>= parse_map ( ( k , v ) v :: acc ) acc in next ( ) >>= parse_v | Stream_end -> Ok ( ` Scalar ( scalar ) ) " " | e -> Error ( ` Msg " Not document start ) ) " | _ -> Error ( ` Msg " Not stream start ) "
let of_string s = yaml_of_string s >>= to_json
let of_string_exn s = match of_string s with | Ok s -> s | Error ( ` Msg m ) m -> raise ( Invalid_argument m ) m
let pp ppf s = match to_string s with | Ok s -> Format . pp_print_string ppf s | Error ( ` Msg m ) m -> Format . pp_print_string ppf ( Printf . sprintf ( " error ( % s ) s ) s " m ) m
let rec equal v1 v2 = match ( v1 , v2 ) v2 with | ` Null , ` Null -> true | ` Bool x1 , ` Bool x2 -> ( ( = ) : bool -> bool -> bool ) bool x1 x2 | ` Float x1 , ` Float x2 -> ( ( = ) : float -> float -> bool ) bool x1 x2 | ` String x1 , ` String x2 -> String . equal x1 x2 | ` A xs1 , ` A xs2 -> List . for_all2 equal xs1 xs2 | ` O xs1 , ` O xs2 -> List . for_all2 ( fun ( k1 , v1 ) v1 ( k2 , v2 ) v2 -> String . equal k1 k2 && equal v1 v2 ) v2 xs1 xs2 | _ -> false
let uuid_random_state = Random . State . make_self_init ( )
module Make ( File : WitnessUtil . File ) ( Cfg : MyCFG . CfgBidir ) ( Spec : Spec ) ( EQSys : GlobConstrSys with module LVar = VarF ( Spec . C ) and module GVar = GVarF ( Spec . V ) and module D = Spec . D and module G = Spec . G ) ( LHT : BatHashtbl . S with type key = EQSys . LVar . t ) ( GHT : BatHashtbl . S with type key = EQSys . GVar . t ) = struct module NH = BatHashtbl . Make ( Node ) module WitnessInvariant = WitnessUtil . Invariant ( File ) ( Cfg ) let join_contexts ( lh : Spec . D . t LHT . t ) : Spec . D . t NH . t = let nh = NH . create 113 in LHT . iter ( fun ( n , _ ) d -> let d ' = try Spec . D . join ( NH . find nh n ) d with Not_found -> d in NH . replace nh n d ' ) lh ; nh let write lh gh = let yaml_creation_time = ` String ( TimeUtil . iso8601_now ( ) ) in let yaml_producer = ` O [ ( " name " , ` String " Goblint " ) ; ( " version " , ` String Version . goblint ) ; ( " command_line " , ` String Goblintutil . command_line ) ; ] in let files = GobConfig . get_string_list " files " in let sha256_file f = Sha256 . ( to_hex ( file f ) ) in let sha256_file_cache = BatCache . make_ht ~ gen : sha256_file ~ init_size : 5 in let sha256_file = sha256_file_cache . get in let yaml_task = ` O ( [ ( " input_files " , ` A ( List . map Yaml . Util . string files ) ) ; ( " input_file_hashes " , ` O ( List . map ( fun file -> ( file , ` String ( sha256_file file ) ) ) files ) ) ; ( " data_model " , ` String ( match GobConfig . get_string " exp . architecture " with | " 64bit " -> " LP64 " | " 32bit " -> " ILP32 " | _ -> failwith " invalid architecture " ) ) ; ( " language " , ` String " C " ) ; ] @ match ! Svcomp . task with | Some ( module Task ) -> [ ( " specification " , ` String ( Svcomp . Specification . to_string Task . specification ) ) ] | None -> [ ] ) in let nh = join_contexts lh in let yaml_entries = NH . fold ( fun n local acc -> match n with | Statement _ when WitnessInvariant . is_invariant_node n -> let context : Invariant . context = { scope = Node . find_fundec n ; i = - 1 ; lval = None ; offset = Cil . NoOffset ; deref_invariant ( = fun _ _ _ -> Invariant . none ) } in begin match Spec . D . invariant context local with | Some inv -> let loc = Node . location n in let invs = WitnessUtil . InvariantExp . process_exp inv in List . fold_left ( fun acc inv -> let uuid = Uuidm . v4_gen uuid_random_state ( ) in let entry = ` O [ ( " entry_type " , ` String " loop_invariant " ) ; ( " metadata " , ` O [ ( " format_version " , ` String " 0 . 1 " ) ; ( " uuid " , ` String ( Uuidm . to_string uuid ) ) ; ( " creation_time " , yaml_creation_time ) ; ( " producer " , yaml_producer ) ; ( " task " , yaml_task ) ; ] ) ; ( " location " , ` O [ ( " file_name " , ` String loc . file ) ; ( " file_hash " , ` String ( sha256_file loc . file ) ) ; ( " line " , ` Float ( float_of_int loc . line ) ) ; ( " column " , ` Float ( float_of_int ( loc . column - 1 ) ) ) ; ( " function " , ` String ( Node . find_fundec n ) . svar . vname ) ; ] ) ; ( " loop_invariant " , ` O [ ( " string " , ` String ( CilType . Exp . show inv ) ) ; ( " type " , ` String " assertion " ) ; ( " format " , ` String " C " ) ; ] ) ; ] in entry :: acc ) acc invs | None -> acc end | _ -> acc ) nh [ ] in let yaml = ` A yaml_entries in Yaml_unix . to_file_exn ( Fpath . v ( GobConfig . get_string " witness . yaml . path " ) ) yaml end
module M ( F : Ctypes . FOREIGN ) FOREIGN = struct let foreign = F . foreign module C = struct include Ctypes let ( @-> ) = F ( . @-> ) let returning = F . returning end let version = foreign " yaml_get_version_string " C ( . void @-> returning string ) string let get_version = foreign " yaml_get_version " C ( . ptr int @-> ptr int @-> ptr int @-> returning void ) void let token_delete = foreign " yaml_token_delete " C ( . ptr T . Token . t @-> returning void ) void let parser_init = foreign " yaml_parser_initialize " C ( . ptr T . Parser . t @-> returning int ) int let parser_delete = foreign " yaml_parser_delete " C ( . ptr T . Parser . t @-> returning void ) void let parser_set_input_string = foreign " yaml_parser_set_input_string " C ( . ptr T . Parser . t @-> ptr char @-> size_t @-> returning void ) void let parser_parse = foreign " yaml_parser_parse " C ( . ptr T . Parser . t @-> ptr T . Event . t @-> returning int ) int let emitter_init = foreign " yaml_emitter_initialize " C ( . ptr T . Emitter . t @-> returning int ) int let emitter_delete = foreign " yaml_emitter_delete " C ( . ptr T . Emitter . t @-> returning void ) void let emitter_set_output_string = foreign " yaml_emitter_set_output_string " C ( . ptr T . Emitter . t @-> ocaml_bytes @-> size_t @-> ptr size_t @-> returning void ) void let emitter_set_encoding = foreign " yaml_emitter_set_encoding " C ( . ptr T . Emitter . t @-> T . encoding_t @-> returning void ) void let emitter_set_canonical = foreign " yaml_emitter_set_canonical " C ( . ptr T . Emitter . t @-> bool @-> returning void ) void let emitter_set_indent = foreign " yaml_emitter_set_indent " C ( . ptr T . Emitter . t @-> int @-> returning void ) void let emitter_set_width = foreign " yaml_emitter_set_width " C ( . ptr T . Emitter . t @-> int @-> returning void ) void let emitter_set_unicode = foreign " yaml_emitter_set_unicode " C ( . ptr T . Emitter . t @-> bool @-> returning void ) void let emitter_flush = foreign " yaml_emitter_flush " C ( . ptr T . Emitter . t @-> returning int ) int let emitter_emit = foreign " yaml_emitter_emit " C ( . ptr T . Emitter . t @-> ptr T . Event . t @-> returning int ) int let stream_start_event_init = foreign " yaml_stream_start_event_initialize " C ( . ptr T . Event . t @-> T . encoding_t @-> returning int ) int let stream_end_event_init = foreign " yaml_stream_end_event_initialize " C ( . ptr T . Event . t @-> returning int ) int let document_start_event_init = foreign " yaml_document_start_event_initialize " C ( . ptr T . Event . t @-> ptr T . Version_directive . t @-> ptr T . Tag_directive . t @-> ptr T . Tag_directive . t @-> bool @-> returning int ) int let document_end_event_init = foreign " yaml_document_end_event_initialize " C ( . ptr T . Event . t @-> bool @-> returning int ) int let alias_event_init = foreign " yaml_alias_event_initialize " C ( . ptr T . Event . t @-> string @-> returning int ) int let scalar_event_init = foreign " yaml_scalar_event_initialize " C ( . ptr T . Event . t @-> string_opt @-> string_opt @-> string @-> int @-> bool @-> bool @-> T . scalar_style_t @-> returning int ) int let sequence_start_event_init = foreign " yaml_sequence_start_event_initialize " C ( . ptr T . Event . t @-> string_opt @-> string_opt @-> bool @-> T . sequence_style_t @-> returning int ) int let sequence_end_event_init = foreign " yaml_sequence_end_event_initialize " C ( . ptr T . Event . t @-> returning int ) int let mapping_start_event_init = foreign " yaml_mapping_start_event_initialize " C ( . ptr T . Event . t @-> string_opt @-> string_opt @-> bool @-> T . mapping_style_t @-> returning int ) int let mapping_end_event_init = foreign " yaml_mapping_end_event_initialize " C ( . ptr T . Event . t @-> returning int ) int end
module Encoding = struct type t = [ ` Any | ` E of int64 | ` Utf16be | ` Utf16le | ` Utf8 ] end
module Error = struct type t = [ ` None | ` Memory | ` Reader | ` Scanner | ` Parser | ` Composer | ` Writer | ` Emitter | ` E of int64 ] end
module Scalar_style = struct type t = [ ` Any | ` Plain | ` Single_quoted | ` Double_quoted | ` Literal | ` Folded | ` E of int64 ] end
module Sequence_style = struct type t = [ ` Any | ` Block | ` Flow | ` E of int64 ] end
module Mapping_style = struct type t = [ ` Any | ` Block | ` Flow | ` E of int64 ] end
module Token_type = struct type t = [ ` None | ` Stream_start | ` Stream_end | ` Version_directive | ` Tag_directive | ` Document_start | ` Document_end | ` Block_sequence_start | ` Block_mapping_start | ` Block_end | ` Flow_sequence_start | ` Flow_sequence_end | ` Flow_mapping_start | ` Flow_mapping_end | ` Block_entry | ` Flow_entry | ` Key | ` Value | ` Alias | ` Anchor | ` Tag | ` Scalar | ` E of int64 ] end
module Event_type = struct type t = [ ` None | ` Stream_start | ` Stream_end | ` Document_start | ` Document_end | ` Alias | ` Scalar | ` Sequence_start | ` Sequence_end | ` Mapping_start | ` Mapping_end | ` E of int64 ] end
module M ( F : Ctypes . TYPE ) TYPE = struct let yaml_char_t = F . uchar let enum label typedef vals = F . enum ~ typedef : true ~ unexpected ( : fun i -> ` E i ) i typedef ( List . map ( fun ( a , b ) b -> ( a , F . constant ( " YAML_ " ^ b ^ " _ " ^ label ) label F . int64_t ) int64_t ) int64_t vals ) vals let encoding_t : Encoding . t F . typ = enum " ENCODING " " yaml_encoding_t " [ ( ` Any , " ANY ) " ; ( ` Utf8 , " UTF8 ) " ; ( ` Utf16le , " UTF16LE ) " ; ( ` Utf16be , " UTF16BE ) " ; ] let error_t : Error . t F . typ = enum " ERROR " " yaml_error_type_t " [ ( ` None , " NO ) " ; ( ` Memory , " MEMORY ) " ; ( ` Reader , " READER ) " ; ( ` Scanner , " SCANNER ) " ; ( ` Parser , " PARSER ) " ; ( ` Composer , " COMPOSER ) " ; ( ` Writer , " WRITER ) " ; ( ` Emitter , " EMITTER ) " ; ] let scalar_style_t : Scalar_style . t F . typ = enum " SCALAR_STYLE " " yaml_scalar_style_t " [ ( ` Any , " ANY ) " ; ( ` Plain , " PLAIN ) " ; ( ` Single_quoted , " SINGLE_QUOTED ) " ; ( ` Double_quoted , " DOUBLE_QUOTED ) " ; ( ` Literal , " LITERAL ) " ; ( ` Folded , " FOLDED ) " ; ] let sequence_style_t : Sequence_style . t F . typ = enum " SEQUENCE_STYLE " " yaml_sequence_style_t " [ ( ` Any , " ANY ) " ; ( ` Block , " BLOCK ) " ; ( ` Flow , " FLOW ) " ] let mapping_style_t : Mapping_style . t F . typ = enum " MAPPING_STYLE " " yaml_mapping_style_t " [ ( ` Any , " ANY ) " ; ( ` Block , " BLOCK ) " ; ( ` Flow , " FLOW ) " ] let token_type_t : Token_type . t F . typ = enum " TOKEN " " yaml_token_type_t " [ ( ` None , " NO ) " ; ( ` Stream_start , " STREAM_START ) " ; ( ` Stream_end , " STREAM_END ) " ; ( ` Version_directive , " VERSION_DIRECTIVE ) " ; ( ` Tag_directive , " TAG_DIRECTIVE ) " ; ( ` Document_start , " DOCUMENT_START ) " ; ( ` Document_end , " DOCUMENT_END ) " ; ( ` Block_sequence_start , " BLOCK_SEQUENCE_START ) " ; ( ` Block_mapping_start , " BLOCK_MAPPING_START ) " ; ( ` Block_end , " BLOCK_END ) " ; ( ` Flow_sequence_start , " FLOW_SEQUENCE_START ) " ; ( ` Flow_sequence_end , " FLOW_SEQUENCE_END ) " ; ( ` Flow_mapping_start , " FLOW_MAPPING_START ) " ; ( ` Flow_mapping_end , " FLOW_MAPPING_END ) " ; ( ` Block_entry , " BLOCK_ENTRY ) " ; ( ` Flow_entry , " FLOW_ENTRY ) " ; ( ` Key , " KEY ) " ; ( ` Value , " VALUE ) " ; ( ` Alias , " ALIAS ) " ; ( ` Tag , " TAG ) " ; ( ` Scalar , " SCALAR ) " ; ] let event_type_t : Event_type . t F . typ = enum " EVENT " " yaml_event_type_t " [ ( ` None , " NO ) " ; ( ` Stream_start , " STREAM_START ) " ; ( ` Stream_end , " STREAM_END ) " ; ( ` Document_start , " DOCUMENT_START ) " ; ( ` Document_end , " DOCUMENT_END ) " ; ( ` Alias , " ALIAS ) " ; ( ` Scalar , " SCALAR ) " ; ( ` Sequence_start , " SEQUENCE_START ) " ; ( ` Sequence_end , " SEQUENCE_END ) " ; ( ` Mapping_start , " MAPPING_START ) " ; ( ` Mapping_end , " MAPPING_END ) " ; ] type ' a typ = ' a Ctypes . structure F . typ type ' a utyp = ' a Ctypes . union F . typ type ( ' a , ' b ) ' b field = ( ' b , ' a Ctypes . structure ) structure F . field type ( ' a , ' b ) ' b ufield = ( ' b , ' a Ctypes . union ) union F . field module Version_directive = struct type t let t : t typ = F . structure " yaml_version_directive_s " let major = F ( . field t " major " int ) int let minor = F ( . field t " minor " int ) int let ( ) = F . seal t end module Tag_directive = struct type t let t : t typ = F . structure " yaml_tag_directive_s " let handle = F ( . field t " handle " string ) string let prefix = F ( . field t " prefix " string ) string let ( ) = F . seal t end module Mark = struct type t let t : t typ = F . structure " yaml_mark_s " let index = F ( . field t " index " size_t ) size_t let line = F ( . field t " line " size_t ) size_t let column = F ( . field t " column " size_t ) size_t let ( ) = F . seal t end module Token = struct module Stream_start = struct type t let t : t typ = F ( . structure " stream_start_s ) " let encoding = F ( . field t " encoding " encoding_t ) encoding_t let ( ) = F . seal t end module Alias = struct type t let t : t typ = F . structure " alias_s " let value = F ( . field t " value " ( ptr yaml_char_t ) yaml_char_t ) yaml_char_t let ( ) = F . seal t end module Anchor = struct type t let t : t typ = F . structure " anchor_s " let value = F ( . field t " value " ( ptr yaml_char_t ) yaml_char_t ) yaml_char_t let ( ) = F . seal t end module Scalar = struct type t let t : t typ = F . structure " scalar_s " let value = F ( . field t " value " ( ptr yaml_char_t ) yaml_char_t ) yaml_char_t let length = F ( . field t " length " size_t ) size_t let style = F ( . field t " style " scalar_style_t ) scalar_style_t let ( ) = F . seal t end module Version = struct type t let t : t typ = F . structure " version_directive_s " let value = F ( . field t " major " int ) int let length = F ( . field t " minor " int ) int let ( ) = F . seal t end module Data = struct type t let t : t utyp = F . union " data_u " let stream_start = F ( . field t " stream_start " Stream_start . t ) t let alias = F ( . field t " alias " Alias . t ) t let anchor = F ( . field t " anchor " Anchor . t ) t let scalar = F ( . field t " scalar " Scalar . t ) t let version = F ( . field t " version_directive " Version_directive . t ) t let ( ) = F . seal t end type t let t : t typ = F . structure " yaml_token_s " let _type = F ( . field t " type " token_type_t ) token_type_t let data = F ( . field t " data " Data . t ) t let start_mark = F ( . field t " start_mark " Mark . t ) t let end_mark = F ( . field t " end_mark " Mark . t ) t let ( ) = F . seal t end module Event = struct module Stream_start = struct type t let t : t typ = F ( . structure " event_stream_start_s ) " let encoding = F ( . field t " encoding " encoding_t ) encoding_t let ( ) = F . seal t end module Document_start = struct module Tag_directives = struct type t let t : t typ = F ( . structure " event_tag_directives_s ) " let start = F ( . field t " start " ( ptr Tag_directive . t ) t ) t let _end = F ( . field t " end " ( ptr Tag_directive . t ) t ) t let ( ) = F . seal t end type t let t : t typ = F ( . structure " event_document_start_s ) " let version_directive = F ( . field t " version_directive " ( ptr_opt Version_directive . t ) t ) t let tag_directives = F ( . field t " tag_directives " Tag_directives . t ) t let implicit = F ( . field t " implicit " int ) int let ( ) = F . seal t end module Document_end = struct type t let t : t typ = F ( . structure " event_document_end_s ) " let implicit = F ( . field t " implicit " int ) int let ( ) = F . seal t end module Alias = struct type t let t : t typ = F ( . structure " event_alias_s ) " let anchor = F ( . field t " anchor " string_opt ) string_opt let ( ) = F . seal t end module Scalar = struct type t let t : t typ = F ( . structure " event_scalar_s ) " let anchor = F ( . field t " anchor " string_opt ) string_opt let tag = F ( . field t " tag " string_opt ) string_opt let value = F ( . field t " value " string ) string let length = F ( . field t " length " size_t ) size_t let plain_implicit = F ( . field t " plain_implicit " int ) int let quoted_implicit = F ( . field t " quoted_implicit " int ) int let style = F ( . field t " style " scalar_style_t ) scalar_style_t let ( ) = F . seal t end module Sequence_start = struct type t let t : t typ = F ( . structure " event_sequence_start_s ) " let anchor = F ( . field t " anchor " string_opt ) string_opt let tag = F ( . field t " tag " string_opt ) string_opt let implicit = F ( . field t " implicit " int ) int let style = F ( . field t " style " sequence_style_t ) sequence_style_t let ( ) = F . seal t end module Mapping_start = struct type t let t : t typ = F ( . structure " event_mapping_start_s ) " let anchor = F ( . field t " anchor " string_opt ) string_opt let tag = F ( . field t " tag " string_opt ) string_opt let implicit = F ( . field t " implicit " int ) int let style = F ( . field t " style " mapping_style_t ) mapping_style_t let ( ) = F . seal t end module Data = struct type t let t : t utyp = F . union " event_data_u " let stream_start = F ( . field t " stream_start " Stream_start . t ) t let document_start = F ( . field t " document_start " Document_start . t ) t let document_end = F ( . field t " document_end " Document_end . t ) t let alias = F ( . field t " alias " Alias . t ) t let scalar = F ( . field t " scalar " Scalar . t ) t let sequence_start = F ( . field t " sequence_start " Sequence_start . t ) t let mapping_start = F ( . field t " mapping_start " Mapping_start . t ) t let ( ) = F . seal t end type t let t : t typ = F . structure " yaml_event_s " let _type = F ( . field t " type " event_type_t ) event_type_t let data = F ( . field t " data " Data . t ) t let start_mark = F ( . field t " start_mark " Mark . t ) t let end_mark = F ( . field t " end_mark " Mark . t ) t let ( ) = F . seal t end module Parser = struct type t let t : t typ = F . structure " yaml_parser_s " let error = F ( . field t " error " error_t ) error_t let problem = F ( . field t " problem " string_opt ) string_opt let problem_offset = F ( . field t " problem_offset " size_t ) size_t let problem_value = F ( . field t " problem_value " int ) int let ( ) = F . seal t end module Emitter = struct type t let t : t typ = F . structure " yaml_emitter_s " let ( ) = F . seal t end end
type value = [ ` Null | ` Bool of bool | ` Float of float | ` String of string | ` A of value list | ` O of ( string * value ) value list ]
type yaml = [ ` Scalar of scalar | ` Alias of string | ` A of sequence | ` O of mapping ] s_anchor : string option ; s_tag : string option ; s_implicit : bool ; s_members : yaml list ; } m_anchor : string option ; m_tag : string option ; m_implicit : bool ; m_members : ( yaml * yaml ) yaml list ; } anchor : string option ; tag : string option ; value : string ; plain_implicit : bool ; quoted_implicit : bool ; style : scalar_style ; } [ ` Any | ` Plain | ` Single_quoted | ` Double_quoted | ` Literal | ` Folded ]
type version = [ ` V1_1 | ` V1_2 ] [ @@ deriving sexp ] sexp
type encoding = [ ` Any | ` Utf16be | ` Utf16le | ` Utf8 ] [ @@ deriving sexp ] sexp
type layout_style = [ ` Any | ` Block | ` Flow ] [ @@ deriving sexp ] sexp
module Stream = struct module Mark = struct type t = Yaml . Stream . Mark . t = { index : int ; line : int ; column : int } [ @@ deriving sexp ] sexp end module Event = struct type pos = Yaml . Stream . Event . pos = { start_mark : Mark . t ; end_mark : Mark . t ; } [ @@ deriving sexp ] sexp type t = Yaml . Stream . Event . t = | Stream_start of { encoding : encoding } | Document_start of { version : version option ; implicit : bool } | Document_end of { implicit : bool } | Mapping_start of { anchor : string option ; tag : string option ; implicit : bool ; style : layout_style ; } | Mapping_end | Stream_end | Scalar of scalar | Sequence_start of { anchor : string option ; tag : string option ; implicit : bool ; style : layout_style ; } | Sequence_end | Alias of { anchor : string } | Nothing [ @@ deriving sexp ] sexp end end