Skip to content
Snippets Groups Projects
Commit 1ce924df authored by Jono Wenger's avatar Jono Wenger
Browse files

Move IsReady to xxDK

parent 7a69cc6b
No related branches found
No related tags found
2 merge requests!510Release,!432Control node reg
......@@ -115,33 +115,6 @@ type IsReadyInfo struct {
HowClose float64
}
// IsReady returns true if at least percentReady of node registrations has
// completed. If not all have completed, then it returns false and howClose will
// be a percent (0-1) of node registrations completed.
//
// Parameters:
// - percentReady - The percentage of nodes required to be registered with to
// be ready. This is a number between 0 and 1.
//
// Returns:
// - JSON of [IsReadyInfo].
func (c *Cmix) IsReady(percentReady float64) ([]byte, error) {
// Check if the network is currently healthy
if !c.api.GetCmix().IsHealthy() {
return json.Marshal(&IsReadyInfo{false, 0})
}
numReg, numNodes, err := c.api.GetNodeRegistrationStatus()
if err != nil {
jww.FATAL.Panicf("Failed to get node registration status: %+v", err)
}
isReady := (float64(numReg) / float64(numNodes)) >= percentReady
howClose := float64(numReg) / (float64(numNodes) * percentReady)
return json.Marshal(&IsReadyInfo{isReady, howClose})
}
// NetworkFollowerStatus gets the state of the network follower. It returns a
// status with the following values:
// Stopped - 0
......@@ -180,6 +153,21 @@ func (c *Cmix) GetNodeRegistrationStatus() ([]byte, error) {
return json.Marshal(nodeRegReport)
}
// IsReady returns true if at least percentReady of node registrations has
// completed. If not all have completed, then it returns false and howClose will
// be a percent (0-1) of node registrations completed.
//
// Parameters:
// - percentReady - The percentage of nodes required to be registered with to
// be ready. This is a number between 0 and 1.
//
// Returns:
// - JSON of [IsReadyInfo].
func (c *Cmix) IsReady(percentReady float64) ([]byte, error) {
isReady, howClose := c.api.IsReady(percentReady)
return json.Marshal(&IsReadyInfo{isReady, howClose})
}
// PauseNodeRegistrations stops all node registrations and returns a function to
// resume them.
//
......
......@@ -484,6 +484,28 @@ func (c *Cmix) GetNodeRegistrationStatus() (int, int, error) {
return numRegistered, len(nodes) - numStale, nil
}
// IsReady returns true if at least percentReady of node registrations has
// completed. If not all have completed, then it returns false and howClose will
// be a percent (0-1) of node registrations completed.
func (c *Cmix) IsReady(percentReady float64) (isReady bool, howClose float64) {
// Check if the network is currently healthy
if !c.network.IsHealthy() {
return false, 0
}
numReg, numNodes, err := c.GetNodeRegistrationStatus()
if err != nil {
jww.FATAL.Panicf("Failed to get node registration status: %+v", err)
}
isReady = (float64(numReg) / float64(numNodes)) >= percentReady
howClose = float64(numReg) / (float64(numNodes) * percentReady)
return isReady, howClose
}
// PauseNodeRegistrations stops all node registrations and returns a function to
// resume them.
func (c *Cmix) PauseNodeRegistrations(timeout time.Duration) error {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment