2020-09-06 16:19:34 +08:00
|
|
|
package settings
|
|
|
|
|
|
|
|
|
|
import (
|
2020-11-10 21:37:48 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
2020-09-06 16:19:34 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
2020-10-25 21:27:28 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
|
2021-10-12 11:43:53 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
2020-10-25 21:27:28 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
2020-09-06 16:19:34 +08:00
|
|
|
"github.com/iwind/TeaGo/actions"
|
|
|
|
|
"github.com/iwind/TeaGo/maps"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type IndexAction struct {
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) Init() {
|
|
|
|
|
this.Nav("", "setting", "")
|
|
|
|
|
this.SecondMenu("basic")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) RunGet(params struct {
|
|
|
|
|
ClusterId int64
|
|
|
|
|
}) {
|
2021-10-12 11:43:53 +08:00
|
|
|
// 基本信息
|
2020-12-17 15:50:44 +08:00
|
|
|
clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: params.ClusterId})
|
2020-09-06 16:19:34 +08:00
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2020-12-17 17:35:38 +08:00
|
|
|
cluster := clusterResp.NodeCluster
|
2020-09-06 16:19:34 +08:00
|
|
|
if cluster == nil {
|
|
|
|
|
this.WriteString("not found cluster")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 认证
|
|
|
|
|
var grantMap interface{} = nil
|
|
|
|
|
|
2021-05-25 17:48:51 +08:00
|
|
|
if cluster.NodeGrantId > 0 {
|
|
|
|
|
grantResp, err := this.RPC().NodeGrantRPC().FindEnabledNodeGrant(this.AdminContext(), &pb.FindEnabledNodeGrantRequest{NodeGrantId: cluster.NodeGrantId})
|
2020-09-06 16:19:34 +08:00
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-04-18 21:19:50 +08:00
|
|
|
grant := grantResp.NodeGrant
|
2020-09-06 16:19:34 +08:00
|
|
|
if grant != nil {
|
|
|
|
|
grantMap = maps.Map{
|
|
|
|
|
"id": grant.Id,
|
|
|
|
|
"name": grant.Name,
|
|
|
|
|
"method": grant.Method,
|
|
|
|
|
"methodName": grantutils.FindGrantMethodName(grant.Method),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.Data["grant"] = grantMap
|
|
|
|
|
|
2021-10-12 11:43:53 +08:00
|
|
|
// 时区
|
|
|
|
|
this.Data["timeZoneGroups"] = nodeconfigs.FindAllTimeZoneGroups()
|
|
|
|
|
this.Data["timeZoneLocations"] = nodeconfigs.FindAllTimeZoneLocations()
|
|
|
|
|
|
|
|
|
|
if len(cluster.TimeZone) == 0 {
|
|
|
|
|
cluster.TimeZone = nodeconfigs.DefaultTimeZoneLocation
|
|
|
|
|
}
|
|
|
|
|
this.Data["timeZoneLocation"] = nodeconfigs.FindTimeZoneLocation(cluster.TimeZone)
|
|
|
|
|
|
2020-09-06 16:19:34 +08:00
|
|
|
this.Data["cluster"] = maps.Map{
|
|
|
|
|
"id": cluster.Id,
|
|
|
|
|
"name": cluster.Name,
|
|
|
|
|
"installDir": cluster.InstallDir,
|
2021-10-12 11:43:53 +08:00
|
|
|
"timeZone": cluster.TimeZone,
|
2020-09-06 16:19:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Show()
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-18 21:19:50 +08:00
|
|
|
// RunPost 保存设置
|
2020-09-06 16:19:34 +08:00
|
|
|
func (this *IndexAction) RunPost(params struct {
|
|
|
|
|
ClusterId int64
|
|
|
|
|
Name string
|
|
|
|
|
GrantId int64
|
|
|
|
|
InstallDir string
|
2021-10-12 11:43:53 +08:00
|
|
|
TimeZone string
|
2020-09-06 16:19:34 +08:00
|
|
|
|
|
|
|
|
Must *actions.Must
|
|
|
|
|
}) {
|
2020-11-10 21:37:48 +08:00
|
|
|
// 创建日志
|
2020-11-20 15:32:42 +08:00
|
|
|
defer this.CreateLog(oplogs.LevelInfo, "修改集群基础设置 %d", params.ClusterId)
|
2020-11-10 21:37:48 +08:00
|
|
|
|
2020-09-06 16:19:34 +08:00
|
|
|
params.Must.
|
|
|
|
|
Field("name", params.Name).
|
|
|
|
|
Require("请输入集群名称")
|
|
|
|
|
|
|
|
|
|
_, err := this.RPC().NodeClusterRPC().UpdateNodeCluster(this.AdminContext(), &pb.UpdateNodeClusterRequest{
|
2020-12-17 15:50:44 +08:00
|
|
|
NodeClusterId: params.ClusterId,
|
|
|
|
|
Name: params.Name,
|
2021-05-25 17:48:51 +08:00
|
|
|
NodeGrantId: params.GrantId,
|
2020-12-17 15:50:44 +08:00
|
|
|
InstallDir: params.InstallDir,
|
2021-10-12 11:43:53 +08:00
|
|
|
TimeZone: params.TimeZone,
|
2020-09-06 16:19:34 +08:00
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Success()
|
|
|
|
|
}
|