mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-09 03:30:24 +08:00
阶段性提交
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/rands"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
@@ -37,15 +38,16 @@ func (this *ServerDAO) EnableServer(id uint32) (rowsAffected int64, err error) {
|
||||
}
|
||||
|
||||
// 禁用条目
|
||||
func (this *ServerDAO) DisableServer(id uint32) (rowsAffected int64, err error) {
|
||||
return this.Query().
|
||||
func (this *ServerDAO) DisableServer(id int64) (err error) {
|
||||
_, err = this.Query().
|
||||
Pk(id).
|
||||
Set("state", ServerStateDisabled).
|
||||
Update()
|
||||
return
|
||||
}
|
||||
|
||||
// 查找启用中的条目
|
||||
func (this *ServerDAO) FindEnabledServer(id uint32) (*Server, error) {
|
||||
func (this *ServerDAO) FindEnabledServer(id int64) (*Server, error) {
|
||||
result, err := this.Query().
|
||||
Pk(id).
|
||||
Attr("state", ServerStateEnabled).
|
||||
@@ -58,7 +60,13 @@ func (this *ServerDAO) FindEnabledServer(id uint32) (*Server, error) {
|
||||
|
||||
// 创建服务
|
||||
func (this *ServerDAO) CreateServer(adminId int64, userId int64, clusterId int64, configJSON string, includeNodesJSON string, excludeNodesJSON string) (serverId int64, err error) {
|
||||
uniqueId, err := this.genUniqueId()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
op := NewServerOperator()
|
||||
op.UniqueId = uniqueId
|
||||
op.UserId = userId
|
||||
op.AdminId = adminId
|
||||
op.ClusterId = clusterId
|
||||
@@ -119,3 +127,40 @@ func (this *ServerDAO) ListEnabledServers(offset int64, size int64) (result []*S
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
// 获取节点中的所有服务
|
||||
func (this *ServerDAO) FindAllEnabledServersWithNode(nodeId int64) (result []*Server, err error) {
|
||||
// 节点所在集群
|
||||
clusterId, err := SharedNodeDAO.FindNodeClusterId(nodeId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if clusterId <= 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
_, err = this.Query().
|
||||
Attr("clusterId", clusterId).
|
||||
State(ServerStateEnabled).
|
||||
AscPk().
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
// 生成唯一ID
|
||||
func (this *ServerDAO) genUniqueId() (string, error) {
|
||||
for {
|
||||
uniqueId := rands.HexString(32)
|
||||
ok, err := this.Query().
|
||||
Attr("uniqueId", uniqueId).
|
||||
Exist()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if ok {
|
||||
continue
|
||||
}
|
||||
return uniqueId, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user