mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-02 19:57:42 +08:00
[FIX] fix false status condition can not update bug
This commit is contained in:
parent
d811cc0594
commit
160dddeb1f
@ -19,6 +19,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@ -152,7 +153,6 @@ func handleResult(serviceTable *termtables.Table, v *client.HostNode) {
|
||||
}
|
||||
} else {
|
||||
if v.Type == client.OutOfDisk || v.Type == client.MemoryPressure || v.Type == client.DiskPressure || v.Type == client.InstallNotReady {
|
||||
|
||||
formatReady = "\033[0;31;31m true \033[0m"
|
||||
} else {
|
||||
formatReady = "\033[0;32;32m true \033[0m"
|
||||
@ -192,6 +192,11 @@ func NewCmdNode() cli.Command {
|
||||
{
|
||||
Name: "get",
|
||||
Usage: "get hostID/internal ip",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "output,o",
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
Common(c)
|
||||
id := c.Args().First()
|
||||
@ -201,6 +206,11 @@ func NewCmdNode() cli.Command {
|
||||
}
|
||||
v, err := clients.RegionClient.Nodes().Get(id)
|
||||
handleErr(err)
|
||||
if c.String("output") == "json" {
|
||||
jsIndent, _ := json.MarshalIndent(v, "", "\t")
|
||||
fmt.Print(string(jsIndent))
|
||||
os.Exit(0)
|
||||
}
|
||||
table := uitable.New()
|
||||
fmt.Printf("-------------------Node Information-----------------------\n")
|
||||
table.AddRow("uuid", v.ID)
|
||||
@ -210,8 +220,8 @@ func NewCmdNode() cli.Command {
|
||||
table.AddRow("external_ip", v.ExternalIP)
|
||||
table.AddRow("role", v.Role)
|
||||
table.AddRow("mode", v.Mode)
|
||||
table.AddRow("available_memory", v.AvailableMemory)
|
||||
table.AddRow("available_cpu", v.AvailableCPU)
|
||||
table.AddRow("available_memory", fmt.Sprintf("%d GB", v.AvailableMemory/1024/1024/1024))
|
||||
table.AddRow("available_cpu", fmt.Sprintf("%d Core", v.AvailableCPU))
|
||||
table.AddRow("status", v.Status)
|
||||
table.AddRow("health", v.NodeStatus.NodeHealth)
|
||||
table.AddRow("schedulable(set)", !v.Unschedulable)
|
||||
|
@ -90,7 +90,7 @@ func GetHTTPHealth(address string) map[string]string {
|
||||
resp, err := c.Get(addr.String())
|
||||
if err != nil {
|
||||
if isClientTimeout(err) {
|
||||
return map[string]string{"status": service.Stat_death, "info": "Request service is unreachable"}
|
||||
return map[string]string{"status": service.Stat_death, "info": "Request service timeout"}
|
||||
}
|
||||
logrus.Errorf("http probe request error %s", err.Error())
|
||||
return map[string]string{"status": service.Stat_unhealthy, "info": err.Error()}
|
||||
@ -99,6 +99,7 @@ func GetHTTPHealth(address string) map[string]string {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
if resp.StatusCode >= 500 {
|
||||
logrus.Debugf("http probe check address %s return code %d", address, resp.StatusCode)
|
||||
return map[string]string{"status": service.Stat_unhealthy, "info": "Service unhealthy"}
|
||||
}
|
||||
return map[string]string{"status": service.Stat_healthy, "info": "service health"}
|
||||
|
@ -186,17 +186,17 @@ func (n *NodeManager) heartbeat() {
|
||||
allHealth := true
|
||||
n.currentNode.NodeStatus.AdviceAction = nil
|
||||
for k, v := range allServiceHealth {
|
||||
if service := n.controller.GetService(k); service != nil {
|
||||
if service.ServiceHealth != nil {
|
||||
maxNum := service.ServiceHealth.MaxErrorsNum
|
||||
if ser := n.controller.GetService(k); ser != nil {
|
||||
if ser.ServiceHealth != nil {
|
||||
maxNum := ser.ServiceHealth.MaxErrorsNum
|
||||
if maxNum < 2 {
|
||||
maxNum = 2
|
||||
}
|
||||
if v.ErrorNumber > maxNum {
|
||||
if v.Status != service.Stat_healthy && v.ErrorNumber > maxNum {
|
||||
allHealth = false
|
||||
n.currentNode.UpdataCondition(
|
||||
client.NodeCondition{
|
||||
Type: client.NodeConditionType(service.Name),
|
||||
Type: client.NodeConditionType(ser.Name),
|
||||
Status: client.ConditionFalse,
|
||||
LastHeartbeatTime: time.Now(),
|
||||
LastTransitionTime: time.Now(),
|
||||
@ -204,6 +204,19 @@ func (n *NodeManager) heartbeat() {
|
||||
Reason: "NotHealth",
|
||||
})
|
||||
}
|
||||
if v.Status == service.Stat_healthy {
|
||||
old := n.currentNode.GetCondition(client.NodeConditionType(ser.Name))
|
||||
if old == nil || old.Status == client.ConditionFalse {
|
||||
n.currentNode.UpdataCondition(
|
||||
client.NodeCondition{
|
||||
Type: client.NodeConditionType(ser.Name),
|
||||
Status: client.ConditionTrue,
|
||||
LastHeartbeatTime: time.Now(),
|
||||
LastTransitionTime: time.Now(),
|
||||
Reason: "Health",
|
||||
})
|
||||
}
|
||||
}
|
||||
if n.cfg.AutoUnschedulerUnHealthDuration == 0 {
|
||||
continue
|
||||
}
|
||||
@ -211,11 +224,11 @@ func (n *NodeManager) heartbeat() {
|
||||
n.currentNode.NodeStatus.AdviceAction = []string{"unscheduler"}
|
||||
}
|
||||
} else {
|
||||
old := n.currentNode.GetCondition(client.NodeConditionType(service.Name))
|
||||
old := n.currentNode.GetCondition(client.NodeConditionType(ser.Name))
|
||||
if old == nil {
|
||||
n.currentNode.UpdataCondition(
|
||||
client.NodeCondition{
|
||||
Type: client.NodeConditionType(service.Name),
|
||||
Type: client.NodeConditionType(ser.Name),
|
||||
Status: client.ConditionTrue,
|
||||
LastHeartbeatTime: time.Now(),
|
||||
LastTransitionTime: time.Now(),
|
||||
|
Loading…
Reference in New Issue
Block a user