mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-12 06:10:26 +08:00
删除集群的时候同时删除相关节点运行日志
This commit is contained in:
@@ -55,12 +55,16 @@ func (this *NodeClusterDAO) EnableNodeCluster(tx *dbs.Tx, id int64) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DisableNodeCluster 禁用条目
|
// DisableNodeCluster 禁用条目
|
||||||
func (this *NodeClusterDAO) DisableNodeCluster(tx *dbs.Tx, id int64) error {
|
func (this *NodeClusterDAO) DisableNodeCluster(tx *dbs.Tx, clusterId int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(clusterId).
|
||||||
Set("state", NodeClusterStateDisabled).
|
Set("state", NodeClusterStateDisabled).
|
||||||
Update()
|
Update()
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return SharedNodeLogDAO.DeleteNodeLogsWithCluster(tx, nodeconfigs.NodeRoleNode, clusterId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindEnabledNodeCluster 查找集群
|
// FindEnabledNodeCluster 查找集群
|
||||||
|
|||||||
@@ -2,4 +2,16 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestNodeClusterDAO_DisableNodeCluster(t *testing.T) {
|
||||||
|
dbs.NotifyReady()
|
||||||
|
|
||||||
|
err := SharedNodeClusterDAO.DisableNodeCluster(nil, 46)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log("ok")
|
||||||
|
}
|
||||||
|
|||||||
@@ -363,9 +363,35 @@ func (this *NodeLogDAO) UpdateAllNodeLogsRead(tx *dbs.Tx) error {
|
|||||||
|
|
||||||
// DeleteNodeLogs 删除某个节点上的日志
|
// DeleteNodeLogs 删除某个节点上的日志
|
||||||
func (this *NodeLogDAO) DeleteNodeLogs(tx *dbs.Tx, role nodeconfigs.NodeRole, nodeId int64) error {
|
func (this *NodeLogDAO) DeleteNodeLogs(tx *dbs.Tx, role nodeconfigs.NodeRole, nodeId int64) error {
|
||||||
|
if nodeId <= 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Attr("nodeId", nodeId).
|
Attr("nodeId", nodeId).
|
||||||
Attr("role", role).
|
Attr("role", role).
|
||||||
Delete()
|
Delete()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteNodeLogsWithCluster 删除某个集群下的所有日志
|
||||||
|
func (this *NodeLogDAO) DeleteNodeLogsWithCluster(tx *dbs.Tx, role nodeconfigs.NodeRole, clusterId int64) error {
|
||||||
|
if clusterId <= 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var query = this.Query(tx).
|
||||||
|
Attr("role", role)
|
||||||
|
|
||||||
|
switch role {
|
||||||
|
case nodeconfigs.NodeRoleNode:
|
||||||
|
query.Where("nodeId IN (SELECT id FROM " + SharedNodeDAO.Table + " WHERE clusterId=:clusterId)")
|
||||||
|
query.Param("clusterId", clusterId)
|
||||||
|
case nodeconfigs.NodeRoleDNS:
|
||||||
|
query.Where("nodeId IN (SELECT id FROM " + SharedNSNodeDAO.Table + " WHERE clusterId=:clusterId)")
|
||||||
|
query.Param("clusterId", clusterId)
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := query.Delete()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
@@ -46,12 +46,16 @@ func (this *NSClusterDAO) EnableNSCluster(tx *dbs.Tx, id int64) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DisableNSCluster 禁用条目
|
// DisableNSCluster 禁用条目
|
||||||
func (this *NSClusterDAO) DisableNSCluster(tx *dbs.Tx, id int64) error {
|
func (this *NSClusterDAO) DisableNSCluster(tx *dbs.Tx, clusterId int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(clusterId).
|
||||||
Set("state", NSClusterStateDisabled).
|
Set("state", NSClusterStateDisabled).
|
||||||
Update()
|
Update()
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return SharedNodeLogDAO.DeleteNodeLogsWithCluster(tx, nodeconfigs.NodeRoleDNS, clusterId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindEnabledNSCluster 查找启用中的条目
|
// FindEnabledNSCluster 查找启用中的条目
|
||||||
|
|||||||
@@ -3,4 +3,17 @@ package models
|
|||||||
import (
|
import (
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
_ "github.com/iwind/TeaGo/bootstrap"
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
func TestNSClusterDAO_DisableNodeCluster(t *testing.T) {
|
||||||
|
dbs.NotifyReady()
|
||||||
|
|
||||||
|
err := SharedNSClusterDAO.DisableNSCluster(nil, 7)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log("ok")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user