added failsafe
This commit is contained in:
parent
7f405ea6e5
commit
6d4e4c31f3
1 changed files with 15 additions and 1 deletions
16
node.go
16
node.go
|
|
@ -8,7 +8,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrServerNotFound = errors.New("server not found")
|
var (
|
||||||
|
ErrServerNotFound = errors.New("server not found")
|
||||||
|
ErrNodesOffline = errors.New("one or more nodes are offline")
|
||||||
|
ErrNodesNotSearched = errors.New("one or more nodes could not be searched")
|
||||||
|
)
|
||||||
|
|
||||||
type NodeStatus string
|
type NodeStatus string
|
||||||
|
|
||||||
|
|
@ -59,12 +63,16 @@ func (c *NodeClient) FindServer(ctx context.Context, name, id string) (s *Server
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
nodeOffline := false
|
||||||
|
nodeNotSearched := false
|
||||||
for _, node := range nl {
|
for _, node := range nl {
|
||||||
if node.Status != NodeStatusOnline {
|
if node.Status != NodeStatusOnline {
|
||||||
|
nodeOffline = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
sl, err := c.ListServers(ctx, node)
|
sl, err := c.ListServers(ctx, node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
nodeNotSearched = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, s := range sl {
|
for _, s := range sl {
|
||||||
|
|
@ -76,6 +84,12 @@ func (c *NodeClient) FindServer(ctx context.Context, name, id string) (s *Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if nodeOffline {
|
||||||
|
return nil, ErrNodesOffline
|
||||||
|
}
|
||||||
|
if nodeNotSearched {
|
||||||
|
return nil, ErrNodesNotSearched
|
||||||
|
}
|
||||||
return nil, ErrServerNotFound
|
return nil, ErrServerNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue