Skip to content

xapi-stdext-date: replace all usages to use clock instead #6358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@
base64
(bos :with-test)
cdrom
(clock (= :version))
cmdliner
cohttp
conf-pam
Expand Down Expand Up @@ -398,7 +399,6 @@
(xapi-idl (= :version))
(xapi-inventory (= :version))
(xapi-log (= :version))
(xapi-stdext-date (= :version))
(xapi-stdext-pervasives (= :version))
(xapi-stdext-std (= :version))
(xapi-stdext-threads (= :version))
Expand Down Expand Up @@ -604,6 +604,7 @@ This package provides an Lwt compatible interface to the library.")
(alcotest :with-test)
astring
(base64 (>= "3.1.0"))
(clock (= :version))
fmt
ipaddr
mtime
Expand All @@ -619,7 +620,6 @@ This package provides an Lwt compatible interface to the library.")
xapi-backtrace
(xapi-idl (= :version))
(xapi-log (= :version))
(xapi-stdext-date (= :version))
(xapi-stdext-pervasives (= :version))
(xapi-stdext-threads (= :version))
(xapi-tracing (= :version))
Expand Down
2 changes: 1 addition & 1 deletion http-lib.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ depends: [
"alcotest" {with-test}
"astring"
"base64" {>= "3.1.0"}
"clock" {= version}
"fmt"
"ipaddr"
"mtime"
Expand All @@ -28,7 +29,6 @@ depends: [
"xapi-backtrace"
"xapi-idl" {= version}
"xapi-log" {= version}
"xapi-stdext-date" {= version}
"xapi-stdext-pervasives" {= version}
"xapi-stdext-threads" {= version}
"xapi-tracing" {= version}
Expand Down
2 changes: 1 addition & 1 deletion ocaml/alerts/certificate/certificate_check.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module XenAPI = Client.Client
module Date = Xapi_stdext_date.Date
module Date = Clock.Date

type cert =
| CA of API.ref_Certificate * API.datetime
Expand Down
9 changes: 5 additions & 4 deletions ocaml/alerts/certificate/certificate_check.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

val alert : (Rpc.call -> Rpc.response) -> [< `session] Ref.t -> unit

(* Below exposed only for ease of testing *)
(* Below exposed only for ease of testing, drop any documentation *)
(**/**)

type cert =
| CA of API.ref_Certificate * API.datetime
Expand All @@ -25,11 +26,11 @@ val certificate_description : cert -> string

val alert_conditions : cert -> (int * (string * int64)) list

val get_expiry : cert -> Xapi_stdext_date.Date.t
val get_expiry : cert -> Clock.Date.t

val maybe_generate_alert :
Xapi_stdext_date.Date.t
Clock.Date.t
-> string
-> (int * (string * int64)) list
-> Xapi_stdext_date.Date.t
-> Clock.Date.t
-> (string * (string * int64)) option
5 changes: 3 additions & 2 deletions ocaml/alerts/certificate/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
(modes best)
(libraries
astring
ptime
xapi-expiry-alerts
xapi-client
xapi-consts
xapi-types
xapi-stdext-date
clock
)
)

Expand All @@ -18,7 +19,7 @@
(modules certificate_check_main)
(libraries
certificate_check

http_lib
xapi-client
xapi-types
Expand Down
2 changes: 1 addition & 1 deletion ocaml/alerts/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
(name expiry_alert)
(public_name xapi-expiry-alerts)
(libraries
clock
xapi-client
xapi-types
xapi-stdext-date
)
)
6 changes: 3 additions & 3 deletions ocaml/alerts/expiry_alert.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*)

module XenAPI = Client.Client
module Date = Xapi_stdext_date.Date
module Date = Clock.Date

type message_name = string

Expand All @@ -37,7 +37,7 @@ type raw_alert = {
; obj_uuid: string
; obj_description: string
; alert_conditions: (remaining_days * message_id) list
; expiry: Xapi_stdext_date.Date.t (* when the obj will expire *)
; expiry: Date.t (* when the obj will expire *)
}

let seconds_per_day = 3600. *. 24.
Expand Down Expand Up @@ -87,7 +87,7 @@ let filter_messages msg_name_list msg_obj_uuid alert all_msgs =
)

let alert ~rpc ~session_id raw_alerts =
let now = Date.now () in
let now = Clock.Date.now () in
let all_msgs = all_messages rpc session_id in
List.iter
(fun {cls; obj_uuid; obj_description; alert_conditions; expiry} ->
Expand Down
8 changes: 4 additions & 4 deletions ocaml/alerts/expiry_alert.mli
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type raw_alert = {
* sent, and when it has expired, message "host_server_certificate_expired"
* should be sent.
*)
; expiry: Xapi_stdext_date.Date.t
; expiry: Clock.Date.t
(* the last second when the obj is valid, it will expire in the next second *)
}

Expand All @@ -69,17 +69,17 @@ val alert :

(* Below exposed only for ease of testing *)

val message_body : string -> Xapi_stdext_date.Date.t -> string
val message_body : string -> Clock.Date.t -> string

val expired_message : string -> string

val expiring_message : string -> string

val maybe_generate_alert :
Xapi_stdext_date.Date.t
Clock.Date.t
-> string
-> (remaining_days * message_id) list
-> Xapi_stdext_date.Date.t
-> Clock.Date.t
-> (string * message_id) option
(** An inner function exposed only for ease of testing, it returns None if there is no
need for an expiry alert as it is not expiring or expired yet, otherwise an "alert"
Expand Down
1 change: 0 additions & 1 deletion ocaml/forkexecd/lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
xapi-log
xapi-stdext-pervasives
xapi-stdext-unix
xapi-stdext-date
xapi-tracing
)
(preprocess (per_module ((pps ppx_deriving_rpc) Fe))))
2 changes: 1 addition & 1 deletion ocaml/forkexecd/lib/fe_systemctl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ let exists ~service = Sys.file_exists (path service)
(** creation time of [path] as a string *)
let ctime path =
let ctime = Unix.((stat path).st_ctime) in
Xapi_stdext_date.Date.(of_unix_time ctime |> to_rfc3339)
Clock.Date.(of_unix_time ctime |> to_rfc3339)

let start_transient ?env ?properties ?(exec_ty = Type.Simple) ~service cmd args
=
Expand Down
2 changes: 1 addition & 1 deletion ocaml/idl/datamodel_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

*)
module Date = struct
module Date = Xapi_stdext_date.Date
module Date = Clock.Date
include Date

let t_of_rpc rpc = Date.of_iso8601 (Rpc.string_of_rpc rpc)
Expand Down
6 changes: 3 additions & 3 deletions ocaml/idl/datamodel_types.mli
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Date : sig
include module type of Xapi_stdext_date.Date
include module type of Clock.Date

val t_of_rpc : Rpc.t -> Xapi_stdext_date.Date.t
val t_of_rpc : Rpc.t -> Clock.Date.t

val rpc_of_t : Xapi_stdext_date.Date.t -> Rpc.t
val rpc_of_t : Clock.Date.t -> Rpc.t
end

val oss_since_303 : string option
Expand Down
2 changes: 1 addition & 1 deletion ocaml/idl/dune
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
xapi-backtrace
xapi-consts
xapi-schema
xapi-stdext-date
clock
xapi-stdext-std
)
(wrapped false)
Expand Down
2 changes: 1 addition & 1 deletion ocaml/idl/ocaml_backend/gen_api.ml
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ let gen_client_types _config highapi =
; ["module Ref = Ref"]
; [
"module Date = struct"
; " open Xapi_stdext_date"
; " module Date = Clock.Date"
; " include Date"
; " let rpc_of_t x = DateTime (Date.to_rfc3339 x)"
; " let t_of_rpc = function String x | DateTime x -> Date.of_iso8601 \
Expand Down
2 changes: 1 addition & 1 deletion ocaml/libs/http-lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
xapi-consts.xapi_version
xapi-idl.updates
xapi-log
xapi-stdext-date
clock
xapi-stdext-pervasives
xapi-stdext-threads
xapi-stdext-unix
Expand Down
5 changes: 2 additions & 3 deletions ocaml/libs/http-lib/xMLRPC.ml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module To = struct
let boolean b = value (box "boolean" [pcdata (if b then "1" else "0")])

let datetime s =
value (box "dateTime.iso8601" [pcdata (Xapi_stdext_date.Date.to_rfc3339 s)])
value (box "dateTime.iso8601" [pcdata (Clock.Date.to_rfc3339 s)])

let double x =
let txt =
Expand Down Expand Up @@ -197,8 +197,7 @@ module From = struct
let boolean = value (singleton ["boolean"] (( <> ) (Xml.PCData "0")))

let datetime x =
Xapi_stdext_date.Date.of_iso8601
(value (singleton ["dateTime.iso8601"] (pcdata id)) x)
Clock.Date.of_iso8601 (value (singleton ["dateTime.iso8601"] (pcdata id)) x)

let double = value (singleton ["double"] (pcdata float_of_string))

Expand Down
4 changes: 2 additions & 2 deletions ocaml/libs/http-lib/xMLRPC.mli
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module To : sig
val boolean : bool -> xmlrpc
(** Marshal a boolean. *)

val datetime : Xapi_stdext_date.Date.t -> xmlrpc
val datetime : Clock.Date.t -> xmlrpc
(** Marshal a date-time. *)

val double : float -> xmlrpc
Expand Down Expand Up @@ -98,7 +98,7 @@ module From : sig
val boolean : xmlrpc -> bool
(** Parse a boolean. *)

val datetime : xmlrpc -> Xapi_stdext_date.Date.t
val datetime : xmlrpc -> Clock.Date.t
(** Parse a date-time. *)

val double : xmlrpc -> float
Expand Down
2 changes: 1 addition & 1 deletion ocaml/libs/xapi-stdext/lib/xapi-stdext-date/date.mli
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*)

(** date-time with support for keeping timezone for ISO 8601 conversion *)
type t
type t = Clock.Date.t

(** Conversions *)

Expand Down
4 changes: 2 additions & 2 deletions ocaml/license/daily_license_check.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module XenAPI = Client.Client
module Date = Xapi_stdext_date.Date
module Date = Clock.Date

type result = Good | Expiring of string list | Expired of string list

Expand All @@ -18,7 +18,7 @@ let days_to_expiry ~expiry now =
let get_expiry_date pool_license =
List.assoc_opt "expiry" pool_license
|> Fun.flip Option.bind (fun e -> if e = "never" then None else Some e)
|> Option.map Xapi_stdext_date.Date.of_iso8601
|> Option.map Clock.Date.of_iso8601

let get_hosts all_license_params threshold =
List.filter_map
Expand Down
2 changes: 1 addition & 1 deletion ocaml/license/daily_license_check_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let _ =
in
Xapi_stdext_pervasives.Pervasiveext.finally
(fun () ->
let now = Xapi_stdext_date.Date.now () in
let now = Clock.Date.now () in
let pool, pool_license_state, all_license_params =
Daily_license_check.get_info_from_db rpc session_id
in
Expand Down
4 changes: 2 additions & 2 deletions ocaml/license/dune
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
xapi-consts
xapi-client
xapi-types
xapi-stdext-date
clock
)
)

Expand All @@ -21,7 +21,7 @@
http_lib
xapi-client
xapi-types
xapi-stdext-date
clock
xapi-stdext-pervasives
)
)
Expand Down
2 changes: 1 addition & 1 deletion ocaml/quicktest/dune
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
xapi_internal
xapi-log
xapi-types
xapi-stdext-date
clock
xapi-stdext-pervasives
xapi-stdext-std
xapi-stdext-threads
Expand Down
7 changes: 3 additions & 4 deletions ocaml/quicktest/qt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ module Time = struct

let now () = Unix.gettimeofday ()

let of_field = Xapi_stdext_date.Date.to_unix_time
let of_field = Clock.Date.to_unix_time

let pp t = Xapi_stdext_date.Date.(of_unix_time t |> to_rfc3339)
let pp t = Clock.Date.(of_unix_time t |> to_rfc3339)

let check t ~after ~before =
Alcotest.(check bool)
Expand Down Expand Up @@ -268,8 +268,7 @@ module VDI = struct
)
; ( `Same
, "snapshot_time"
, fun vdi ->
vdi.API.vDI_snapshot_time |> Xapi_stdext_date.Date.to_rfc3339
, fun vdi -> vdi.API.vDI_snapshot_time |> Clock.Date.to_rfc3339
)
; (`Same, "virtual_size", fun vdi -> vdi.API.vDI_location)
]
Expand Down
2 changes: 1 addition & 1 deletion ocaml/quicktest/qt.mli
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module Time : sig

val now : unit -> t

val of_field : Xapi_stdext_date.Date.t -> t
val of_field : Clock.Date.t -> t

val pp : t -> string

Expand Down
2 changes: 1 addition & 1 deletion ocaml/quicktest/quicktest_date.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Client = Client.Client
module Date = Xapi_stdext_date.Date
module Date = Clock.Date

let test_host_get_server_localtime rpc session_id () =
let host = Client.Host.get_by_uuid ~rpc ~session_id ~uuid:Qt.localhost_uuid in
Expand Down
2 changes: 1 addition & 1 deletion ocaml/quicktest/quicktest_event.ml
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ let event_message_test rpc session_id () =
) ;
let messages =
Client.Client.Message.get ~rpc ~session_id ~cls ~obj_uuid
~since:Xapi_stdext_date.Date.epoch
~since:Clock.Date.epoch
in
let has_msg m = List.exists (fun (r, _) -> r = m) messages in
Alcotest.(check bool)
Expand Down
4 changes: 2 additions & 2 deletions ocaml/quicktest/quicktest_vdi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ let vdi_bad_introduce rpc session_id sr_info () =
~location:(Ref.string_of (Ref.make ()))
~xenstore_data:[] ~sm_config:[] ~managed:true ~virtual_size:0L
~physical_utilisation:0L ~metadata_of_pool:Ref.null
~is_a_snapshot:false ~snapshot_time:Xapi_stdext_date.Date.epoch
~is_a_snapshot:false ~snapshot_time:Clock.Date.epoch
~snapshot_of:Ref.null
in
Alcotest.fail
Expand All @@ -161,7 +161,7 @@ let vdi_bad_introduce rpc session_id sr_info () =
~other_config:[] ~location:vdir.API.vDI_location ~xenstore_data:[]
~sm_config:[] ~managed:true ~virtual_size:0L
~physical_utilisation:0L ~metadata_of_pool:Ref.null
~is_a_snapshot:false ~snapshot_time:Xapi_stdext_date.Date.epoch
~is_a_snapshot:false ~snapshot_time:Clock.Date.epoch
~snapshot_of:Ref.null
in
Alcotest.fail
Expand Down
Loading
Loading