mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-15 17:40:25 +08:00
单个服务切换集群时可以选择是否保留配置
This commit is contained in:
@@ -270,11 +270,21 @@ func (this *ServerDAO) CreateServer(tx *dbs.Tx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateServerBasic 修改服务基本信息
|
// UpdateServerBasic 修改服务基本信息
|
||||||
func (this *ServerDAO) UpdateServerBasic(tx *dbs.Tx, serverId int64, name string, description string, clusterId int64, isOn bool, groupIds []int64) error {
|
func (this *ServerDAO) UpdateServerBasic(tx *dbs.Tx, serverId int64, name string, description string, clusterId int64, keepOldChanges bool, isOn bool, groupIds []int64) error {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
return errors.New("serverId should not be smaller than 0")
|
return errors.New("serverId should not be smaller than 0")
|
||||||
}
|
}
|
||||||
op := NewServerOperator()
|
|
||||||
|
// 老的集群ID
|
||||||
|
oldClusterId, err := this.Query(tx).
|
||||||
|
Pk(serverId).
|
||||||
|
Result("clusterId").
|
||||||
|
FindInt64Col(0)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var op = NewServerOperator()
|
||||||
op.Id = serverId
|
op.Id = serverId
|
||||||
op.Name = name
|
op.Name = name
|
||||||
op.Description = description
|
op.Description = description
|
||||||
@@ -291,7 +301,7 @@ func (this *ServerDAO) UpdateServerBasic(tx *dbs.Tx, serverId int64, name string
|
|||||||
op.GroupIds = groupIdsJSON
|
op.GroupIds = groupIdsJSON
|
||||||
}
|
}
|
||||||
|
|
||||||
err := this.Save(tx, op)
|
err = this.Save(tx, op)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -303,7 +313,25 @@ func (this *ServerDAO) UpdateServerBasic(tx *dbs.Tx, serverId int64, name string
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 因为可能有isOn的原因,所以需要修改
|
// 因为可能有isOn的原因,所以需要修改
|
||||||
return this.NotifyDNSUpdate(tx, serverId)
|
err = this.NotifyDNSUpdate(tx, serverId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if clusterId != oldClusterId {
|
||||||
|
// 服务配置更新
|
||||||
|
if !keepOldChanges {
|
||||||
|
err = this.NotifyClusterUpdate(tx, oldClusterId, serverId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DNS更新
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUserServerBasic 设置用户相关的基本信息
|
// UpdateUserServerBasic 设置用户相关的基本信息
|
||||||
@@ -2418,7 +2446,7 @@ func (this *ServerDAO) FindServerUAM(tx *dbs.Tx, serverId int64) ([]byte, error)
|
|||||||
FindJSONCol()
|
FindJSONCol()
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotifyUpdate 同步集群
|
// NotifyUpdate 同步服务所在的集群
|
||||||
func (this *ServerDAO) NotifyUpdate(tx *dbs.Tx, serverId int64) error {
|
func (this *ServerDAO) NotifyUpdate(tx *dbs.Tx, serverId int64) error {
|
||||||
// 创建任务
|
// 创建任务
|
||||||
clusterId, err := this.FindServerClusterId(tx, serverId)
|
clusterId, err := this.FindServerClusterId(tx, serverId)
|
||||||
@@ -2431,6 +2459,14 @@ func (this *ServerDAO) NotifyUpdate(tx *dbs.Tx, serverId int64) error {
|
|||||||
return SharedNodeTaskDAO.CreateClusterTask(tx, nodeconfigs.NodeRoleNode, clusterId, serverId, NodeTaskTypeConfigChanged)
|
return SharedNodeTaskDAO.CreateClusterTask(tx, nodeconfigs.NodeRoleNode, clusterId, serverId, NodeTaskTypeConfigChanged)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NotifyClusterUpdate 同步指定的集群
|
||||||
|
func (this *ServerDAO) NotifyClusterUpdate(tx *dbs.Tx, clusterId, serverId int64) error {
|
||||||
|
if clusterId <= 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return SharedNodeTaskDAO.CreateClusterTask(tx, nodeconfigs.NodeRoleNode, clusterId, serverId, NodeTaskTypeConfigChanged)
|
||||||
|
}
|
||||||
|
|
||||||
// NotifyDNSUpdate 通知DNS更新
|
// NotifyDNSUpdate 通知DNS更新
|
||||||
func (this *ServerDAO) NotifyDNSUpdate(tx *dbs.Tx, serverId int64) error {
|
func (this *ServerDAO) NotifyDNSUpdate(tx *dbs.Tx, serverId int64) error {
|
||||||
clusterId, err := this.Query(tx).
|
clusterId, err := this.Query(tx).
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ func (this *ServerService) UpdateServerBasic(ctx context.Context, req *pb.Update
|
|||||||
return nil, errors.New("can not find server")
|
return nil, errors.New("can not find server")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = models.SharedServerDAO.UpdateServerBasic(tx, req.ServerId, req.Name, req.Description, req.NodeClusterId, req.IsOn, req.ServerGroupIds)
|
err = models.SharedServerDAO.UpdateServerBasic(tx, req.ServerId, req.Name, req.Description, req.NodeClusterId, req.KeepOldConfigs, req.IsOn, req.ServerGroupIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1965,12 +1965,30 @@ func (this *ServerService) FindServerUserPlan(ctx context.Context, req *pb.FindS
|
|||||||
|
|
||||||
// ComposeServerConfig 获取服务配置
|
// ComposeServerConfig 获取服务配置
|
||||||
func (this *ServerService) ComposeServerConfig(ctx context.Context, req *pb.ComposeServerConfigRequest) (*pb.ComposeServerConfigResponse, error) {
|
func (this *ServerService) ComposeServerConfig(ctx context.Context, req *pb.ComposeServerConfigRequest) (*pb.ComposeServerConfigResponse, error) {
|
||||||
_, err := this.ValidateNode(ctx)
|
nodeId, err := this.ValidateNode(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var tx = this.NullTx()
|
var tx = this.NullTx()
|
||||||
|
|
||||||
|
//读取节点的所有集群
|
||||||
|
clusterIds, err := models.SharedNodeDAO.FindEnabledNodeClusterIds(tx, nodeId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取服务所在集群
|
||||||
|
serverClusterId, err := models.SharedServerDAO.FindServerClusterId(tx, req.ServerId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果不在当前节点的集群中,则返回nil
|
||||||
|
if !lists.ContainsInt64(clusterIds, serverClusterId) {
|
||||||
|
return &pb.ComposeServerConfigResponse{ServerConfigJSON: nil}, nil
|
||||||
|
}
|
||||||
|
|
||||||
serverConfig, err := models.SharedServerDAO.ComposeServerConfigWithServerId(tx, req.ServerId, true)
|
serverConfig, err := models.SharedServerDAO.ComposeServerConfigWithServerId(tx, req.ServerId, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == models.ErrNotFound {
|
if err == models.ErrNotFound {
|
||||||
|
|||||||
Reference in New Issue
Block a user