-
Notifications
You must be signed in to change notification settings - Fork 296
CA-420987: xapi_message: Add message-destroy-all API #6806
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8915,6 +8915,40 @@ module Message = struct | |
| ~params:[(Set (Ref _message), "messages", "Messages to destroy")] | ||
| ~allowed_roles:_R_POOL_OP () | ||
|
|
||
| let destroy_all = | ||
| call ~name:"destroy_all" ~lifecycle:[] | ||
| ~versioned_params: | ||
| [ | ||
| { | ||
| param_type= DateTime | ||
| ; param_name= "before" | ||
| ; param_doc= | ||
| "Cutoff time for destroyed messages - only destroy messages with \ | ||
| an earlier timestamp. When no timezone is specified UTC is \ | ||
| assumed." | ||
| ; param_release= numbered_release "25.39.0-next" | ||
| ; param_default= Some (VDateTime (Date.of_ptime Ptime.max)) | ||
| } | ||
| ; { | ||
| param_type= DateTime | ||
| ; param_name= "after" | ||
| ; param_doc= | ||
| "Cutoff time for destroyed messages - only destroy messages with \ | ||
| a later timestamp. When no timezone is specified UTC is \ | ||
| assumed." | ||
| ; param_release= numbered_release "25.39.0-next" | ||
| ; param_default= Some (VDateTime Date.epoch) | ||
| } | ||
| ; { | ||
| param_type= Int | ||
| ; param_name= "priority" | ||
| ; param_doc= "Priority of messages to be destroyed" | ||
| ; param_release= numbered_release "25.39.0-next" | ||
| ; param_default= Some (VInt (-1L)) | ||
| } | ||
| ] | ||
| ~allowed_roles:_R_POOL_OP () | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think with the params, the API is not convenient to use. are OK. failed.
|
||
|
|
||
| let get_all = | ||
| call ~name:"get_all" | ||
| ~lifecycle:[(Published, rel_orlando, "")] | ||
|
|
@@ -9002,6 +9036,7 @@ module Message = struct | |
| create | ||
| ; destroy | ||
| ; destroy_many | ||
| ; destroy_all | ||
| ; get | ||
| ; get_all | ||
| ; get_since | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -550,20 +550,18 @@ let make_param_funs getallrecs getbyuuid record class_name def_filters | |
| ) | ||
| all | ||
| in | ||
| (* Filter on everything on the cmd line except params=... *) | ||
| let filter_params = | ||
| List.filter | ||
| (fun (p, _) -> not (List.mem p ("params" :: stdparams))) | ||
| params | ||
| in | ||
| (* Filter out all params beginning with "database:" *) | ||
| let filter_params = | ||
| List.filter | ||
| (fun (p, _) -> not (Astring.String.is_prefix ~affix:"database:" p)) | ||
| filter_params | ||
| (* Add in the default filters *) | ||
| def_filters | ||
| @ List.filter | ||
| (fun (p, _) -> | ||
| (* Filter on everything on the cmd line except params=... *) | ||
| (not (List.mem p ("params" :: stdparams))) | ||
| (* Filter out all params beginning with "database:" *) | ||
| && not (Astring.String.is_prefix ~affix:"database:" p) | ||
| ) | ||
| params | ||
| in | ||
| (* Add in the default filters *) | ||
| let filter_params = def_filters @ filter_params in | ||
| (* Filter all the records *) | ||
| let records = | ||
| List.fold_left filter_records_on_fields all_recs filter_params | ||
|
|
@@ -573,22 +571,20 @@ let make_param_funs getallrecs getbyuuid record class_name def_filters | |
| select_fields params | ||
| (if print_all then all_recs else records) | ||
| def_list_params | ||
| in | ||
| let print_params = | ||
| List.map | ||
| (fun fields -> List.filter (fun field -> not field.hidden) fields) | ||
| print_params | ||
| in | ||
| let print_params = | ||
| List.map | ||
| (fun fields -> | ||
| List.map | ||
| (fun field -> | ||
| if field.expensive then makeexpensivefield field else field | ||
| (* Hide hidden fields, redact expensive fields *) | ||
| |> List.map | ||
| (List.filter_map (fun field -> | ||
| if field.hidden then | ||
| None | ||
| else | ||
| Some | ||
| ( if field.expensive then | ||
| makeexpensivefield field | ||
| else | ||
| field | ||
| ) | ||
| ) | ||
| fields | ||
| ) | ||
| print_params | ||
| ) | ||
| in | ||
| printer | ||
| (Cli_printer.PTable (List.map (List.map print_field) print_params)) | ||
|
|
@@ -1428,6 +1424,28 @@ let message_destroy (_ : printer) rpc session_id params = | |
| in | ||
| Client.Message.destroy_many ~rpc ~session_id ~messages | ||
|
|
||
| let message_destroy_all (_ : printer) rpc session_id params = | ||
| let fail msg = raise (Cli_util.Cli_failure msg) in | ||
| let before_str = List.assoc_opt "before" params in | ||
| let after_str = List.assoc_opt "after" params in | ||
| let priority_str = List.assoc_opt "priority" params in | ||
| let before = | ||
| try | ||
| Option.map Date.of_iso8601 before_str | ||
| |> Option.value ~default:(Date.of_ptime Ptime.max) | ||
| (* Default value is Ptime.max - everything is before it *) | ||
| with _ -> fail "invalid timestamp format for 'before' (expected RFC3339)" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could include an example for the expected format - that would be more helpful than just the RFC. |
||
| in | ||
| let after = | ||
| try Option.map Date.of_iso8601 after_str |> Option.value ~default:Date.epoch | ||
| with _ -> fail "Invalid timestamp format for 'after' (expected RFC3339)" | ||
| in | ||
| let priority = | ||
| try Option.map Int64.of_string priority_str |> Option.value ~default:(-1L) | ||
| with _ -> fail "Invalid priority format (expected integer)" | ||
| in | ||
| Client.Message.destroy_all ~rpc ~session_id ~before ~after ~priority | ||
|
|
||
| (* Pool operations *) | ||
|
|
||
| let get_pool_with_default rpc session_id params key = | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a place where the values of different priorities are explained? It would be useful here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would a different API be more convenient?
with the semantics that all messages before/after the timestamp are removed. I would imagine that this is the common use case.