Skip to content

Commit

Permalink
Add new internal API cstack_sync
Browse files Browse the repository at this point in the history
This allows one to force sync the state of xapi db with the cluster
stack, useful for cluster API methods change the state of the cluster.

Signed-off-by: Vincent Liu <[email protected]>
  • Loading branch information
Vincent-lau committed Jun 20, 2024
1 parent 01fd179 commit af714ac
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ocaml/idl/datamodel_cluster.ml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ let pool_resync =
~params:[(Ref _cluster, "self", "The cluster to resync")]
~lifecycle ~allowed_roles:_R_POOL_OP ~errs:[] ()

let cstack_sync =
call ~name:"cstack_sync"
~doc:
"Sync xapi db with the cluster stack synchronously, generate alerts as \
needed. Only happens on the coordinator as this is where the cluster \
watcher perform updates."
~params:[(Ref _cluster, "self", "The cluster to sync")]
~hide_from_docs:true ~pool_internal:true ~lifecycle
~allowed_roles:_R_POOL_OP ~errs:[] ()

let t =
create_obj ~name:_cluster ~descr:"Cluster-wide Cluster metadata"
~doccomments:[] ~gen_constructor_destructor:false ~gen_events:true
Expand Down Expand Up @@ -245,5 +255,6 @@ let t =
; pool_force_destroy
; pool_destroy
; pool_resync
; cstack_sync
]
()
8 changes: 8 additions & 0 deletions ocaml/xapi/message_forwarding.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6399,6 +6399,14 @@ functor
) ;
debug "Cluster.pool_resync for host %s" (Ref.string_of host)
)

let cstack_sync ~__context ~self =
info "Cluster.cstack_sync cluster %s" (Ref.string_of self) ;
let local_fn = Local.Cluster.cstack_sync ~self in
let coor = Helpers.get_master ~__context in
do_op_on ~local_fn ~__context ~host:coor (fun session_id rpc ->
Client.Cluster.cstack_sync ~rpc ~session_id ~self
)
end

module Cluster_host = struct
Expand Down
5 changes: 5 additions & 0 deletions ocaml/xapi/xapi_cluster.ml
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,8 @@ let pool_resync ~__context ~self:_ =
)
(* If host.clustering_enabled then resync_host should successfully
find or create a matching cluster_host which is also enabled *)

let cstack_sync ~__context ~self =
debug "%s: sync db data with cluster stack" __FUNCTION__ ;
Watcher.on_corosync_update ~__context ~cluster:self
["Updates due to cluster api calls"]
10 changes: 10 additions & 0 deletions ocaml/xapi/xapi_cluster.mli
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,13 @@ val pool_resync : __context:Context.t -> self:API.ref_Cluster -> unit
Cluster_host objects (ie., one for each host in the pool if the Cluster
has [pool_auto_join] set. If there is a failure, this function must return
an error that enables the administrator to fix the problem. *)

val cstack_sync : __context:Context.t -> self:API.ref_Cluster -> unit
(** [cstack_sync ~__context ~self] is the implementation of the internal XenAPI method,
which synchronously performs a diagnostics call to xapi-clusterd and updates the
xapi db according to the call. This is used internally by cluster-host-create/destroy
to generate the correct alert as a result of the API call. The other part of the
alerts generated due to network failure (e.g. a host left as its network is down)
is handled by the cluster watcher. This call only happens on the coordinator as that
is where the cluster watcher performs the updates, which shares the code with
this function. *)

0 comments on commit af714ac

Please sign in to comment.