text
stringlengths 0
601k
|
---|
let events = Xwatcher_util . makeEventObj ( ) |
let watchers : watcher array = [ ] || |
let source_dirname = Js . Option . getExn [ % external __dirname ] __dirname |
let bsb = Node . Path . join [ | source_dirname ; bsb_exe ] | |
let rec onChange = fun eventType fileName -> Js . log { j | Event $ eventType $ fileName | j } j ; events ## push ( eventType , fileName ) fileName ; build bsb events lock ( fun [ @ bs ] bs ( ) -> idle ( ) ) let watchFiles = getWatchFiles sourceDirs in watchers |> Js . Vector . filterInPlace ( fun [ @ bs ] bs { dir ; watcher } watcher -> if dir = bsconfig || Js . Vector . memByRef dir watchFiles then true else begin Js . log { j | $ dir is no longer watched | j } j ; Node . Fs . Watch . close watcher ; false end ) ; watchFiles |> Js . Array . forEach ( fun dir -> if not ( Js . Array . some ( fun { dir = watcher_dir } watcher_dir -> watcher_dir = dir ) dir watchers ) watchers then begin Js . log { j | watching dir $ dir now | j } j ; Js . Vector . pushBack ( makeWatcher dir ( fun [ @ bs ] bs x y -> onChange x y ) ) watchers end ) |
let ( ) = Node . Process . putEnvVar " BS_VSCODE " " 1 " ; Js . Vector . pushBack ( makeWatcher bsconfig ( fun [ @ bs ] bs x y -> onChange x y ) y ) y watchers ; build bsb events lock ( fun [ @ bs ] bs ( ) -> idle ( ) ) |
let source_dirname = Js . Option . getExn [ % external __dirname ] __dirname |
let cwd = Node . Process . cwd ( ) |
let root = if Node . Fs . existsSync ( Node . Path . join [ | cwd ; bsconfig ] ) | then cwd else Xwatcher_util . findFile ~ prev : cwd ~ cwd ( : Node . Path . dirname cwd ) cwd bsconfig |
let jscomp = Js . log { j | Root : $ root | j } j ; Node . Path . join [ | root ; " jscomp " ] | |
let lock = Xwatcher_util . makeLock ( ) |
let events = Xwatcher_util . makeEventObj ( ) |
let exec ( ) = buildWithShell command events lock ( fun [ @ bs ] bs ( ) -> ( ) ) |
let watch dir = makeWatcher dir ( fun [ @ bs ] bs _event fileName -> if Js . String . endsWith " . ml " fileName || Js . String . endsWith " . mli " fileName || Js . String . endsWith " . cppo " fileName || Js . String . endsWith " . js " fileName || fileName = " Makefile " || fileName = " Makefile . shared " then exec ( ) ) |
let ( ) = Node . Process . putEnvVar " BS_VSCODE " " 1 " ; match Js . Array . sliceFrom 2 Node . Process . argv with | [ " |- build ] " | -> Xwatcher_util . spawnInheritIgnore command | _ -> begin Js . Vector . iter ( fun [ @ bs ] bs x -> ignore @@ watch ( Node . Path . join [ | jscomp ; x ] ) | ) [ | " core " ; " syntax " ; " ext " ; " depends " ; " others " ; " ounit " ; " ounit_tests " ; " test " ; " runtime " ; " xwatcher " ; " bsb " ; " common " ; " super_errors " ; " . " ] ; | exec ( ) end |
let getWatchFiles file = if Fs . existsSync file then Js . String . split " \ n " ( Fs . readFileAsUtf8Sync file ) |> Js . Array . filter ( fun x -> String . length ( Js . String . trim x ) x <> 0 ) 0 else [ ] || method empty : unit -> unit method needRebuild : unit -> bool method push : string * string -> unit method currentEvents : unit -> ( string * string ) string array |
type eventObj = _eventObj Js . t |
let rec findFile ~ prev ~ cwd f = if String . length prev = String . length cwd then Js . Exn . raiseError { j | $ f not found | j } j else if Fs . existsSync ( Node . Path . join [ | cwd ; f ] ) | then cwd else findFile cwd ( Node . Path . dirname cwd ) f |
let makeEventObj ( ) : eventObj = object ( self ) self val events : ( string * string ) string array = [ ] || method empty ( ) = Js . Vector . empty self ## events method push a = Js . Vector . pushBack a self ## events method needRebuild ( ) = Array . length self ## events <> 0 method currentEvents ( ) = self ## events end [ @ bs ] bs |
type t ( _ [ @ bs . as { json | [ ] | json } json ] json ) json -> ( _ [ @ bs . as { json | { " stdio " : " inherit " } | json } json ] json ) json -> t = " spawn " [ @@ bs . module " child_process ] " ( _ [ @ bs . as { json | [ ] | json } json ] json ) json -> ( _ [ @ bs . as { json | { " stdio " : " inherit " , " shell " : true } | json } json ] json ) json -> t = " spawn " [ @@ bs . module " child_process ] " ( _ [ @ bs . as { json | [ ] | json } json ] json ) json -> ( _ [ @ bs . as { json | { " stdio " : " inherit " , " shell " : true } | json } json ] json ) json -> unit = " spawn " [ @@ bs . module " child_process ] " method acquire : unit -> bool method release : unit -> unit |
type lock = _lock Js . t |
let makeLock ( ) : lock = object ( objectself ) objectself val mutable isBuilding = false method acquire ( ) = if self ## isBuilding then false else begin self ## isBuilding #= true ; true end method release ( ) = self ## isBuilding #= false end [ @ bs ] bs |
let rec build cmd ( event : eventObj ) eventObj ( lock : lock ) idle = if lock ## acquire ( ) then begin Js . log " >>>> Start compiling " ; let events = event ## currentEvents ( ) in Js . log { j | Rebuilding since $ events | j } j ; event ## empty ( ) ; spawnInheritNoShell cmd |> onExit ( fun ( ) -> Js . log " >>>> Finish compiling " ; lock ## release ( ) ; if event ## needRebuild ( ) then build cmd event lock idle else idle ( ) [ @ bs ] bs ) end |
let rec buildWithShell cmd ( event : eventObj ) eventObj ( lock : lock ) idle = if lock ## acquire ( ) then begin Js . log " >>>> Start compiling " ; let events = event ## currentEvents ( ) in Js . log { j | Rebuilding since $ events | j } j ; event ## empty ( ) ; spawnInherit cmd |> onExit ( fun ( ) -> Js . log " >>>> Finish compiling " ; lock ## release ( ) ; if event ## needRebuild ( ) then build cmd event lock idle else idle ( ) [ @ bs ] bs ) end |
type watcher = { dir : string ; watcher : Fs . Watch . t } string -> ( string -> string -> unit [ @ bs ] bs ) bs -> Node . Fs . Watch . t = " watch " [ @@ bs . module " fs ] " |
let makeWatcher file onChange = { watcher = watchOnChange file onChange ; dir = file } |
let make_printable i_char = match i_char with n when ( ( ( Char . code n ) < 32 ) or ( ( Char . code n ) > 126 ) ) -> ' . ' | _ -> i_char ; ; |
let make_hex chr = Printf . sprintf " . % 2x " ( Char . code chr ) ; ; |
let conditional_add_st bffr ch = match bffr with n when ( ( Buffer . length bffr ) = 0 ) -> Buffer . add_string bffr ch | n when ( ( Buffer . length bffr ) = 4 ) -> Buffer . add_string bffr ( " " ^ ch ) | n when ( ( ( Buffer . length bffr ) mod 5 ) = 4 ) -> Buffer . add_string bffr ( " " ^ ch ) | _ -> Buffer . add_string bffr ch ; ; |
let string_map str fnc = let rec strmap st acc = match st with " " -> List . rev acc | _ -> strmap ( String . sub st 1 ( ( String . length st ) - 1 ) ) ( ( fnc st . [ 0 ] ) :: acc ) in strmap str [ ] ; ; |
let rec output_lines fle f_buf s_buf curpos = let str_buf = String . create 16 in |
let res = input fle str_buf 0 16 in ( if ( res < 16 ) then ( List . iter ( conditional_add_st f_buf ) List . iter ( Buffer . add_char s_buf ) else ( List . iter ( conditional_add_st f_buf ) ( string_map str_buf make_hex ) ; List . iter ( Buffer . add_char s_buf ) ( string_map str_buf make_printable ) ) ) ; Printf . printf " % 0 . 7x : %- 40s % s \ n " curpos ( Buffer . contents f_buf ) ( Buffer . contents s_buf ) ; if ( res < 16 ) then exit ( 0 ) else Buffer . clear f_buf ; Buffer . clear s_buf ; output_lines fle f_buf s_buf ( curpos + res ) ; ; |
let output_file fname = let fo = open_in_bin fname in |
let res = output_lines fo ( Buffer . create 16 ) ( Buffer . create 16 ) 0 in close_in fo ; res ; ; |
let rec build_char_list sb acc = let nval = try Some ( Scanf . bscanf sb " % 2x " ( fun x -> Char . chr x ) ) with End_of_file -> None in match nval with Some n -> build_char_list sb ( n :: acc ) | None -> List . rev acc ; ; |
let rec input_lines source_chan dest_chan = let write_line sc dc = try let istr = String . sub ( input_line sc ) 9 39 in let buf = Buffer . create 32 in with End_of_file -> false in let do_more = write_line source_chan dest_chan in match do_more with | false -> ( ) ; ; |
let input_file source_file dest_file = let ic = open_in source_file in |
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 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.