mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-02 03:37:46 +08:00
Merge branch 'V5.0' of https://github.com/goodrain/rainbond into V5.0
This commit is contained in:
commit
efb808ab9e
@ -548,7 +548,11 @@ func NewCmdNode() cli.Command {
|
|||||||
node.ID = c.String("id")
|
node.ID = c.String("id")
|
||||||
err := clients.RegionClient.Nodes().Add(&node)
|
err := clients.RegionClient.Nodes().Add(&node)
|
||||||
handleErr(err)
|
handleErr(err)
|
||||||
fmt.Println("success add node")
|
if node.AutoInstall {
|
||||||
|
fmt.Printf("success add node, and it is installing,install log file /grdata/downloads/log/%s.log\n", node.HostName)
|
||||||
|
} else {
|
||||||
|
fmt.Println("success add node, you install it by running: grctl node install <nodeID>")
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -563,9 +567,11 @@ func NewCmdNode() cli.Command {
|
|||||||
if nodeID == "" {
|
if nodeID == "" {
|
||||||
showError("node id can not be empty")
|
showError("node id can not be empty")
|
||||||
}
|
}
|
||||||
err := clients.RegionClient.Nodes().Install(nodeID)
|
node, err := clients.RegionClient.Nodes().Get(nodeID)
|
||||||
handleErr(err)
|
handleErr(err)
|
||||||
fmt.Println("start install node")
|
err = clients.RegionClient.Nodes().Install(nodeID)
|
||||||
|
handleErr(err)
|
||||||
|
fmt.Printf("start install nodeinstall log file /grdata/downloads/log/%s.log\n", node.HostName)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -78,7 +78,6 @@ func AddNode(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
httputil.ReturnSuccess(r, w, rnode)
|
httputil.ReturnSuccess(r, w, rnode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,27 +36,6 @@ import (
|
|||||||
"github.com/twinj/uuid"
|
"github.com/twinj/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
//Running node running status
|
|
||||||
Running = "running"
|
|
||||||
//Offline node offline status
|
|
||||||
Offline = "offline"
|
|
||||||
//Unknown node unknown status
|
|
||||||
Unknown = "unknown"
|
|
||||||
//Error node error status
|
|
||||||
Error = "error"
|
|
||||||
//Init node init status
|
|
||||||
Init = "init"
|
|
||||||
//InstallSuccess node install success status
|
|
||||||
InstallSuccess = "install_success"
|
|
||||||
//InstallFailed node install failure status
|
|
||||||
InstallFailed = "install_failed"
|
|
||||||
//Installing node installing status
|
|
||||||
Installing = "installing"
|
|
||||||
//NotInstalled node not install status
|
|
||||||
NotInstalled = "not_installed"
|
|
||||||
)
|
|
||||||
|
|
||||||
//NodeService node service
|
//NodeService node service
|
||||||
type NodeService struct {
|
type NodeService struct {
|
||||||
c *option.Conf
|
c *option.Conf
|
||||||
@ -105,20 +84,14 @@ func (n *NodeService) AddNode(node *client.APIHostNode) (*client.HostNode, *util
|
|||||||
rbnode := node.Clone()
|
rbnode := node.Clone()
|
||||||
rbnode.CreateTime = time.Now()
|
rbnode.CreateTime = time.Now()
|
||||||
n.nodecluster.UpdateNode(rbnode)
|
n.nodecluster.UpdateNode(rbnode)
|
||||||
if _, err := rbnode.Update(); err != nil {
|
|
||||||
return nil, utils.CreateAPIHandleErrorFromDBError("save node", err)
|
|
||||||
}
|
|
||||||
return rbnode, nil
|
return rbnode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//InstallNode install node
|
//InstallNode install node
|
||||||
func (n *NodeService) InstallNode(node *client.HostNode) *utils.APIHandleError {
|
func (n *NodeService) InstallNode(node *client.HostNode) *utils.APIHandleError {
|
||||||
node.Status = Installing
|
node.Status = client.Installing
|
||||||
node.NodeStatus.Status = Installing
|
node.NodeStatus.Status = client.Installing
|
||||||
n.nodecluster.UpdateNode(node)
|
n.nodecluster.UpdateNode(node)
|
||||||
if _, err := node.Update(); err != nil {
|
|
||||||
return utils.CreateAPIHandleErrorFromDBError("save node", err)
|
|
||||||
}
|
|
||||||
go n.AsynchronousInstall(node)
|
go n.AsynchronousInstall(node)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -130,35 +103,28 @@ func (n *NodeService) AsynchronousInstall(node *client.HostNode) {
|
|||||||
linkModel = "key"
|
linkModel = "key"
|
||||||
}
|
}
|
||||||
// start add node script
|
// start add node script
|
||||||
logrus.Info("Begin add node, please don't exit")
|
logrus.Infof("Begin install node %s", node.ID)
|
||||||
line := fmt.Sprintf("cd /opt/rainbond/rainbond-ansible/scripts; ./%s.sh %s %s %s %s %s %s", node.Role[0], node.HostName,
|
line := fmt.Sprintf("./node.sh %s %s %s %s %s %s %s", node.Role[0], node.HostName,
|
||||||
node.InternalIP, linkModel, node.RootPass, node.KeyPath, node.ID)
|
node.InternalIP, linkModel, node.RootPass, node.KeyPath, node.ID)
|
||||||
|
|
||||||
fileName := node.HostName + ".log"
|
fileName := node.HostName + ".log"
|
||||||
cmd := exec.Command("bash", "-c", line)
|
cmd := exec.Command("bash", "-c", line)
|
||||||
f, _ := os.OpenFile("/grdata/downloads/log/"+fileName, os.O_WRONLY|os.O_CREATE|os.O_SYNC, 0755)
|
f, _ := os.OpenFile("/grdata/downloads/log/"+fileName, os.O_WRONLY|os.O_CREATE|os.O_SYNC, 0755)
|
||||||
cmd.Stdout = f
|
cmd.Stdout = f
|
||||||
|
cmd.Dir = "/opt/rainbond/rainbond-ansible/scripts"
|
||||||
cmd.Stderr = f
|
cmd.Stderr = f
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("Error executing shell script,View log file:/grdata/downloads/log/" + fileName)
|
logrus.Errorf("Error executing shell script,View log file:/grdata/downloads/log/" + fileName)
|
||||||
node.Status = InstallFailed
|
node.Status = client.InstallFailed
|
||||||
node.NodeStatus.Status = InstallFailed
|
node.NodeStatus.Status = client.InstallFailed
|
||||||
n.nodecluster.UpdateNode(node)
|
n.nodecluster.UpdateNode(node)
|
||||||
if _, err := node.Update(); err != nil {
|
|
||||||
logrus.Errorf(err.Error())
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logrus.Info("Add node successful")
|
logrus.Info("Add node successful")
|
||||||
logrus.Info("check cluster status: grctl node list")
|
logrus.Info("check cluster status: grctl node list")
|
||||||
node.Status = InstallSuccess
|
node.Status = client.InstallSuccess
|
||||||
node.NodeStatus.Status = InstallSuccess
|
node.NodeStatus.Status = client.InstallSuccess
|
||||||
n.nodecluster.UpdateNode(node)
|
n.nodecluster.UpdateNode(node)
|
||||||
if _, err := node.Update(); err != nil {
|
|
||||||
logrus.Errorf(err.Error())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//DeleteNode delete node
|
//DeleteNode delete node
|
||||||
@ -280,8 +246,8 @@ func (n *NodeService) DownNode(nodeID string) (*client.HostNode, *utils.APIHandl
|
|||||||
return nil, utils.CreateAPIHandleError(500, fmt.Errorf("k8s node down error,%s", err.Error()))
|
return nil, utils.CreateAPIHandleError(500, fmt.Errorf("k8s node down error,%s", err.Error()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hostNode.Status = Offline
|
hostNode.Status = client.Offline
|
||||||
hostNode.NodeStatus.Status = Offline
|
hostNode.NodeStatus.Status = client.Offline
|
||||||
n.nodecluster.UpdateNode(hostNode)
|
n.nodecluster.UpdateNode(hostNode)
|
||||||
return hostNode, nil
|
return hostNode, nil
|
||||||
}
|
}
|
||||||
@ -303,8 +269,8 @@ func (n *NodeService) UpNode(nodeID string) (*client.HostNode, *utils.APIHandleE
|
|||||||
hostNode.UpdateK8sNodeStatus(*node)
|
hostNode.UpdateK8sNodeStatus(*node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hostNode.Status = Running
|
hostNode.Status = client.Running
|
||||||
hostNode.NodeStatus.Status = Running
|
hostNode.NodeStatus.Status = client.Running
|
||||||
n.nodecluster.UpdateNode(hostNode)
|
n.nodecluster.UpdateNode(hostNode)
|
||||||
return hostNode, nil
|
return hostNode, nil
|
||||||
}
|
}
|
||||||
|
@ -45,18 +45,6 @@ import (
|
|||||||
"github.com/goodrain/rainbond/util"
|
"github.com/goodrain/rainbond/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
Running = "running"
|
|
||||||
Offline = "offline"
|
|
||||||
Unknown = "unknown"
|
|
||||||
Error = "error"
|
|
||||||
Init = "init"
|
|
||||||
InstallSuccess = "install_success"
|
|
||||||
InstallFailed = "install_failed"
|
|
||||||
Installing = "installing"
|
|
||||||
NotInstalled = "not_installed"
|
|
||||||
)
|
|
||||||
|
|
||||||
//Cluster node controller
|
//Cluster node controller
|
||||||
type Cluster struct {
|
type Cluster struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
@ -168,9 +156,12 @@ func (n *Cluster) GetNode(id string) *client.HostNode {
|
|||||||
|
|
||||||
//handleNodeStatus Master integrates node status and kube node status
|
//handleNodeStatus Master integrates node status and kube node status
|
||||||
func (n *Cluster) handleNodeStatus(v *client.HostNode) {
|
func (n *Cluster) handleNodeStatus(v *client.HostNode) {
|
||||||
|
if v.Status == client.NotInstalled || v.Status == client.Installing || v.Status == client.InstallFailed {
|
||||||
|
return
|
||||||
|
}
|
||||||
if time.Now().Sub(v.NodeStatus.NodeUpdateTime) > time.Minute*1 {
|
if time.Now().Sub(v.NodeStatus.NodeUpdateTime) > time.Minute*1 {
|
||||||
v.Status = Unknown
|
v.Status = client.Unknown
|
||||||
v.NodeStatus.Status = Unknown
|
v.NodeStatus.Status = client.Unknown
|
||||||
r := client.NodeCondition{
|
r := client.NodeCondition{
|
||||||
Type: client.NodeUp,
|
Type: client.NodeUp,
|
||||||
Status: client.ConditionFalse,
|
Status: client.ConditionFalse,
|
||||||
|
@ -179,6 +179,27 @@ type NodeSystemInfo struct {
|
|||||||
NumCPU int64 `json:"cpu_num"`
|
NumCPU int64 `json:"cpu_num"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
//Running node running status
|
||||||
|
Running = "running"
|
||||||
|
//Offline node offline status
|
||||||
|
Offline = "offline"
|
||||||
|
//Unknown node unknown status
|
||||||
|
Unknown = "unknown"
|
||||||
|
//Error node error status
|
||||||
|
Error = "error"
|
||||||
|
//Init node init status
|
||||||
|
Init = "init"
|
||||||
|
//InstallSuccess node install success status
|
||||||
|
InstallSuccess = "install_success"
|
||||||
|
//InstallFailed node install failure status
|
||||||
|
InstallFailed = "install_failed"
|
||||||
|
//Installing node installing status
|
||||||
|
Installing = "installing"
|
||||||
|
//NotInstalled node not install status
|
||||||
|
NotInstalled = "not_installed"
|
||||||
|
)
|
||||||
|
|
||||||
//Decode decode node info
|
//Decode decode node info
|
||||||
func (n *HostNode) Decode(data []byte) error {
|
func (n *HostNode) Decode(data []byte) error {
|
||||||
if err := ffjson.Unmarshal(data, n); err != nil {
|
if err := ffjson.Unmarshal(data, n); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user