2020-08-21 12:32:16 +08:00
|
|
|
package settings
|
|
|
|
|
|
2020-09-13 20:37:07 +08:00
|
|
|
import (
|
|
|
|
|
"errors"
|
2020-11-11 21:32:19 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
2020-09-13 20:37:07 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
|
|
|
|
"github.com/iwind/TeaGo/actions"
|
|
|
|
|
"github.com/iwind/TeaGo/maps"
|
|
|
|
|
)
|
2020-08-21 12:32:16 +08:00
|
|
|
|
2020-09-13 20:37:07 +08:00
|
|
|
// 服务基本信息设置
|
2020-08-21 12:32:16 +08:00
|
|
|
type IndexAction struct {
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) Init() {
|
|
|
|
|
this.Nav("", "setting", "")
|
|
|
|
|
this.SecondMenu("basic")
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-13 20:37:07 +08:00
|
|
|
func (this *IndexAction) RunGet(params struct {
|
|
|
|
|
ServerId int64
|
|
|
|
|
}) {
|
|
|
|
|
// 所有集群
|
|
|
|
|
resp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClusters(this.AdminContext(), &pb.FindAllEnabledNodeClustersRequest{})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
clusterMaps := []maps.Map{}
|
2020-12-17 17:35:38 +08:00
|
|
|
for _, cluster := range resp.NodeClusters {
|
2020-09-13 20:37:07 +08:00
|
|
|
clusterMaps = append(clusterMaps, maps.Map{
|
|
|
|
|
"id": cluster.Id,
|
|
|
|
|
"name": cluster.Name,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this.Data["clusters"] = clusterMaps
|
|
|
|
|
|
|
|
|
|
// 当前服务信息
|
|
|
|
|
serverResp, err := this.RPC().ServerRPC().FindEnabledServer(this.AdminContext(), &pb.FindEnabledServerRequest{ServerId: params.ServerId})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
server := serverResp.Server
|
|
|
|
|
if server == nil {
|
|
|
|
|
this.NotFound("Server", params.ServerId)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clusterId := int64(0)
|
2020-12-17 17:35:38 +08:00
|
|
|
if server.NodeCluster != nil {
|
|
|
|
|
clusterId = server.NodeCluster.Id
|
2020-09-13 20:37:07 +08:00
|
|
|
}
|
|
|
|
|
|
2020-10-29 21:37:48 +08:00
|
|
|
// 分组
|
|
|
|
|
groupMaps := []maps.Map{}
|
|
|
|
|
if len(server.Groups) > 0 {
|
|
|
|
|
for _, group := range server.Groups {
|
|
|
|
|
groupMaps = append(groupMaps, maps.Map{
|
|
|
|
|
"id": group.Id,
|
|
|
|
|
"name": group.Name,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-13 20:37:07 +08:00
|
|
|
this.Data["server"] = maps.Map{
|
|
|
|
|
"id": server.Id,
|
|
|
|
|
"clusterId": clusterId,
|
|
|
|
|
"type": server.Type,
|
|
|
|
|
"name": server.Name,
|
|
|
|
|
"description": server.Description,
|
2020-09-28 16:25:26 +08:00
|
|
|
"isOn": server.IsOn,
|
2020-10-29 21:37:48 +08:00
|
|
|
"groups": groupMaps,
|
2020-09-13 20:37:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serverType := serverconfigs.FindServerType(server.Type)
|
|
|
|
|
if serverType == nil {
|
|
|
|
|
this.ErrorPage(errors.New("invalid server type '" + server.Type + "'"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typeName := serverType.GetString("name")
|
|
|
|
|
this.Data["typeName"] = typeName
|
|
|
|
|
|
2020-08-21 12:32:16 +08:00
|
|
|
this.Show()
|
|
|
|
|
}
|
2020-09-13 20:37:07 +08:00
|
|
|
|
|
|
|
|
// 保存
|
|
|
|
|
func (this *IndexAction) RunPost(params struct {
|
|
|
|
|
ServerId int64
|
|
|
|
|
Name string
|
|
|
|
|
Description string
|
|
|
|
|
ClusterId int64
|
2020-10-29 21:37:48 +08:00
|
|
|
GroupIds []int64
|
2020-09-28 16:25:26 +08:00
|
|
|
IsOn bool
|
2020-09-13 20:37:07 +08:00
|
|
|
|
|
|
|
|
Must *actions.Must
|
|
|
|
|
}) {
|
2020-11-11 21:32:19 +08:00
|
|
|
// 记录日志
|
2020-11-20 15:32:42 +08:00
|
|
|
defer this.CreateLog(oplogs.LevelInfo, "修改代理服务 %d 基本信息", params.ServerId)
|
2020-11-11 21:32:19 +08:00
|
|
|
|
2020-09-13 20:37:07 +08:00
|
|
|
params.Must.
|
|
|
|
|
Field("name", params.Name).
|
|
|
|
|
Require("请输入服务名称")
|
|
|
|
|
|
|
|
|
|
if params.ClusterId <= 0 {
|
|
|
|
|
this.Fail("请选择部署的集群")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := this.RPC().ServerRPC().UpdateServerBasic(this.AdminContext(), &pb.UpdateServerBasicRequest{
|
2020-12-17 15:50:44 +08:00
|
|
|
ServerId: params.ServerId,
|
|
|
|
|
Name: params.Name,
|
|
|
|
|
Description: params.Description,
|
|
|
|
|
NodeClusterId: params.ClusterId,
|
|
|
|
|
IsOn: params.IsOn,
|
|
|
|
|
GroupIds: params.GroupIds,
|
2020-09-13 20:37:07 +08:00
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Success()
|
|
|
|
|
}
|