Skip to content

Commit fb618b2

Browse files
committed
xapi: Add new message-destroy-all API call
We've seen issues where a client will try to dismiss all their alerts and fail due to the message-destroy call hitting the maximum XAPI request size at ~5000 messages. A new message-destroy-all API avoids this issue while saving the bandwidth required to send a ref for each message. Users of the new API call can choose to dismiss messages that arrived before or after a certain date, or only those with a given priority. Signed-off-by: Christian Pardillo Laursen <christian.pardillolaursen@citrix.com>
1 parent c6eda1a commit fb618b2

File tree

5 files changed

+89
-3
lines changed

5 files changed

+89
-3
lines changed

ocaml/idl/datamodel.ml

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8915,6 +8915,40 @@ module Message = struct
89158915
~params:[(Set (Ref _message), "messages", "Messages to destroy")]
89168916
~allowed_roles:_R_POOL_OP ()
89178917

8918+
let destroy_all =
8919+
call ~name:"destroy_all" ~lifecycle:[]
8920+
~versioned_params:
8921+
[
8922+
{
8923+
param_type= DateTime
8924+
; param_name= "before"
8925+
; param_doc=
8926+
"Cutoff time for destroyed messages - only destroy messages with \
8927+
an earlier timestamp. When no timezone is specified UTC is \
8928+
assumed."
8929+
; param_release= numbered_release "25.39.0-next"
8930+
; param_default= Some (VDateTime (Date.of_ptime Ptime.max))
8931+
}
8932+
; {
8933+
param_type= DateTime
8934+
; param_name= "after"
8935+
; param_doc=
8936+
"Cutoff time for destroyed messages - only destroy messages with \
8937+
a later timestamp. When no timezone is specified UTC is \
8938+
assumed."
8939+
; param_release= numbered_release "25.39.0-next"
8940+
; param_default= Some (VDateTime Date.epoch)
8941+
}
8942+
; {
8943+
param_type= Int
8944+
; param_name= "priority"
8945+
; param_doc= "Priority of messages to be destroyed"
8946+
; param_release= numbered_release "25.39.0-next"
8947+
; param_default= Some (VInt (-1L))
8948+
}
8949+
]
8950+
~allowed_roles:_R_POOL_OP ()
8951+
89188952
let get_all =
89198953
call ~name:"get_all"
89208954
~lifecycle:[(Published, rel_orlando, "")]
@@ -9002,6 +9036,7 @@ module Message = struct
90029036
create
90039037
; destroy
90049038
; destroy_many
9039+
; destroy_all
90059040
; get
90069041
; get_all
90079042
; get_since
@@ -9067,21 +9102,21 @@ module Secret = struct
90679102
param_type= String
90689103
; param_name= "uuid"
90699104
; param_doc= ""
9070-
; param_release= midnight_ride_release
9105+
; param_release= numbered_release "25.39.0"
90719106
; param_default= None
90729107
}
90739108
; {
90749109
param_type= String
90759110
; param_name= "value"
90769111
; param_doc= ""
9077-
; param_release= midnight_ride_release
9112+
; param_release= numbered_release "25.39.0"
90789113
; param_default= None
90799114
}
90809115
; {
90819116
param_type= Map (String, String)
90829117
; param_name= "other_config"
90839118
; param_doc= ""
9084-
; param_release= boston_release
9119+
; param_release= numbered_release "25.39.0"
90859120
; param_default= Some (VMap [])
90869121
}
90879122
]

ocaml/idl/datamodel_lifecycle.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ let prototyped_of_message = function
223223
Some "24.14.0"
224224
| "PCI", "disable_dom0_access" ->
225225
Some "24.14.0"
226+
| "message", "destroy_all" ->
227+
Some "25.39.0-next"
226228
| "message", "destroy_many" ->
227229
Some "22.19.0"
228230
| "VTPM", "set_contents" ->

ocaml/xapi-cli-server/cli_frontend.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ let rec cmdtable_data : (string * cmd_spec) list =
128128
; flags= []
129129
}
130130
)
131+
; ( "message-destroy-all"
132+
, {
133+
reqd= []
134+
; optn= ["before"; "after"; "priority"]
135+
; help= "Destroy all existing messages matching the given conditions."
136+
; implementation= No_fd Cli_operations.message_destroy_all
137+
; flags= []
138+
}
139+
)
131140
; ( "pool-enable-binary-storage"
132141
, {
133142
reqd= []

ocaml/xapi-cli-server/cli_operations.ml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,28 @@ let message_destroy (_ : printer) rpc session_id params =
14201420
in
14211421
Client.Message.destroy_many ~rpc ~session_id ~messages
14221422

1423+
let message_destroy_all (_ : printer) rpc session_id params =
1424+
let fail msg = raise (Cli_util.Cli_failure msg) in
1425+
let before_str = List.assoc_opt "before" params in
1426+
let after_str = List.assoc_opt "after" params in
1427+
let priority_str = List.assoc_opt "priority" params in
1428+
let before =
1429+
try
1430+
Option.map Date.of_iso8601 before_str
1431+
|> Option.value ~default:(Date.of_ptime Ptime.max)
1432+
(* Default value is Ptime.max - everything is before it *)
1433+
with _ -> fail "invalid timestamp format for 'before' (expected RFC3339)"
1434+
in
1435+
let after =
1436+
try Option.map Date.of_iso8601 after_str |> Option.value ~default:Date.epoch
1437+
with _ -> fail "Invalid timestamp format for 'after' (expected RFC3339)"
1438+
in
1439+
let priority =
1440+
try Option.map Int64.of_string priority_str |> Option.value ~default:(-1L)
1441+
with _ -> fail "Invalid priority format (expected integer)"
1442+
in
1443+
Client.Message.destroy_all ~rpc ~session_id ~before ~after ~priority
1444+
14231445
(* Pool operations *)
14241446

14251447
let get_pool_with_default rpc session_id params key =

ocaml/xapi/xapi_message.ml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,24 @@ let get_record ~__context ~self =
730730

731731
let get_all_records ~__context = get_real message_dir (fun _ -> true) 0.0
732732

733+
let destroy_all ~__context ~before ~after ~priority =
734+
let filter_timestamp ts =
735+
Date.is_earlier ts ~than:before && Date.is_later ts ~than:after
736+
in
737+
let priority_filter =
738+
(* Default priority is -1, which stands for any priority *)
739+
if priority = -1L then fun _ -> true else fun p -> p = priority
740+
in
741+
let message_filter msg =
742+
filter_timestamp msg.API.message_timestamp
743+
&& priority_filter msg.API.message_priority
744+
in
745+
let messages =
746+
get_real_inner message_dir message_filter (fun _ -> true)
747+
|> List.map (fun (_, msg, _) -> msg)
748+
in
749+
destroy_many ~__context ~messages
750+
733751
let get_all_records_where ~__context ~expr =
734752
let open Xapi_database in
735753
let expr = Db_filter.expr_of_string expr in

0 commit comments

Comments
 (0)