-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
223 additions
and
36 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,63 @@ | ||
package http | ||
|
||
import ( | ||
"context" | ||
"sort" | ||
"time" | ||
|
||
v1 "github.com/vinceanalytics/vince/gen/go/vince/v1" | ||
) | ||
|
||
// NewNodesFromServers creates a slice of Nodes from a slice of Servers. | ||
func NewNodesFromServers(servers *v1.Server_List) *v1.Node_List { | ||
nodes := &v1.Node_List{ | ||
Items: make([]*v1.Node, len(servers.Items)), | ||
} | ||
for i, s := range servers.Items { | ||
nodes.Items[i] = &v1.Node{ | ||
Id: s.Id, | ||
Addr: s.Addr, | ||
Voter: s.Suffrage == v1.Server_Voter, | ||
} | ||
} | ||
ls := nodes.Items | ||
sort.Slice(ls, func(i, j int) bool { | ||
return ls[i].Id < ls[j].Id | ||
}) | ||
return nodes | ||
} | ||
|
||
// Test tests the node's reachability and leadership status. If an error | ||
// occurs, the Error field will be populated. | ||
func TestNode(ctx context.Context, n *v1.Node, ga GetAddresser, leaderAddr string, timeout time.Duration) { | ||
start := time.Now() | ||
n.Time = time.Since(start).Seconds() | ||
n.TimeS = time.Since(start).String() | ||
n.Reachable = false | ||
n.Leader = false | ||
doCtx, cancel := context.WithTimeout(ctx, timeout) | ||
defer cancel() | ||
|
||
apiAddr, err := ga.GetNodeAPIAddr(doCtx, n.Addr) | ||
if err != nil { | ||
n.Error = err.Error() | ||
return | ||
} | ||
n.ApiAddr = apiAddr | ||
n.Reachable = true | ||
n.Leader = n.Addr == leaderAddr | ||
} | ||
|
||
func Voters(n *v1.Node_List) (o *v1.Node_List) { | ||
o = &v1.Node_List{} | ||
for _, e := range n.Items { | ||
if e.Voter { | ||
o.Items = append(o.Items, e) | ||
} | ||
} | ||
ls := o.Items | ||
sort.Slice(ls, func(i, j int) bool { | ||
return ls[i].Id < ls[j].Id | ||
}) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,6 @@ message Credential { | |
READY = 6; | ||
BACKUP = 7; | ||
LOAD = 8; | ||
REMOVE = 9; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters