Skip to content
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

Fd 869 add status check to api #698

Merged
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
22 changes: 22 additions & 0 deletions wsapi/wsapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@ func HandleHeights(ctx *web.Context) {

type statusResponse struct {
Version string
NodeName string
BootTime int64
CurrentTime int64
CurrentBlockStartTime int64
Expand All @@ -818,17 +819,36 @@ type statusResponse struct {
Syncing bool
SyncingEOMs bool
SyncingDBSigs bool
Running bool
Role string
}

func HandleStatus(ctx *web.Context) {
ServersMutex.Lock()
s := ctx.Server.Env["state"].(interfaces.IState)
ServersMutex.Unlock()

feds := s.GetFedServers(s.GetLLeaderHeight())
audits := s.GetAuditServers(s.GetLLeaderHeight())
role := "follower"
foundRole := false
for _, fed := range feds {
if !foundRole && s.GetIdentityChainID().IsSameAs(fed.GetChainID()) {
role = "leader"
break
}
}
for _, aud := range audits {
if !foundRole && s.GetIdentityChainID().IsSameAs(aud.GetChainID()) {
role = "audit"
}
}

jsonResp := primitives.NewJSON2Response()
jsonResp.ID = 0
jsonResp.Result = statusResponse{
s.GetFactomdVersion(),
s.GetFactomNodeName(),
s.GetBootTime(),
s.GetCurrentTime(),
s.GetCurrentBlockStartTime(),
Expand All @@ -842,6 +862,8 @@ func HandleStatus(ctx *web.Context) {
s.IsSyncing(),
s.IsSyncingEOMs(),
s.IsSyncingDBSigs(),
s.Running(),
role,
}

// REVIEW: should we only conditionally return status 200 if some precondition is met
Expand Down