| | |
| | | IsDelete bool `gorm:"column:isDelete;default:0" json:"isDelete"` |
| | | DeviceType string `gorm:"column:device_type" json:"device_type"` //设备型号` |
| | | DriftState string `gorm:"column:drift_state" json:"drift_state"` //漂移状态, master,backup |
| | | Online bool `gorm:"column:online;default:1" json:"online"` //在线状态 |
| | | } |
| | | |
| | | func (Node) TableName() string { |
| | |
| | | return node, nil |
| | | } |
| | | |
| | | func (n *Node) UpdateDriftStateByNodeId(driftState string, nodeId string) bool { |
| | | func (n *Node) FindNodeById(id string) (node Node, err error) { |
| | | if err = db.Raw("select * from cluster_node where id=?", id).Scan(&node).Error; err != nil { |
| | | return node, err |
| | | } |
| | | return node, nil |
| | | } |
| | | |
| | | func (n *Node) UpdateDriftStateByNodeId(driftState string, nodeId string, sync bool) bool { |
| | | var err error |
| | | tx := GetDB().Begin() |
| | | if !sync { |
| | | GetDB().LogMode(false) |
| | | defer db.LogMode(true) |
| | | } |
| | | |
| | | defer func() { |
| | | if err != nil && tx != nil { |
| | | logger.Error("updateDriftState err:", err) |