主分支代码
This commit is contained in:
98
EdgeAdmin/internal/web/actions/default/db/clickhouse.go
Normal file
98
EdgeAdmin/internal/web/actions/default/db/clickhouse.go
Normal file
@@ -0,0 +1,98 @@
|
||||
//go:build plus
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
const clickhouseConfigCode = "clickhouseConfig"
|
||||
|
||||
type ClickHouseAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ClickHouseAction) Init() {
|
||||
this.Nav("db", "db", "clickhouse")
|
||||
}
|
||||
|
||||
func (this *ClickHouseAction) RunGet(params struct{}) {
|
||||
this.Data["mainTab"] = "clickhouse"
|
||||
resp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: clickhouseConfigCode})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
cfg := &systemconfigs.ClickHouseSetting{Port: 8123, Database: "default"}
|
||||
if len(resp.ValueJSON) > 0 {
|
||||
_ = json.Unmarshal(resp.ValueJSON, cfg)
|
||||
}
|
||||
if cfg.Port <= 0 {
|
||||
cfg.Port = 8123
|
||||
}
|
||||
if cfg.Database == "" {
|
||||
cfg.Database = "default"
|
||||
}
|
||||
this.Data["config"] = map[string]interface{}{
|
||||
"host": cfg.Host,
|
||||
"port": cfg.Port,
|
||||
"user": cfg.User,
|
||||
"password": cfg.Password,
|
||||
"database": cfg.Database,
|
||||
}
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *ClickHouseAction) RunPost(params struct {
|
||||
Host string
|
||||
Port int
|
||||
User string
|
||||
Password string
|
||||
Database string
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.DBNode_LogUpdateDBNode, 0)
|
||||
if params.Port <= 0 {
|
||||
params.Port = 8123
|
||||
}
|
||||
if params.Database == "" {
|
||||
params.Database = "default"
|
||||
}
|
||||
password := params.Password
|
||||
if password == "" {
|
||||
resp, _ := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: clickhouseConfigCode})
|
||||
if len(resp.ValueJSON) > 0 {
|
||||
var old systemconfigs.ClickHouseSetting
|
||||
if json.Unmarshal(resp.ValueJSON, &old) == nil {
|
||||
password = old.Password
|
||||
}
|
||||
}
|
||||
}
|
||||
cfg := &systemconfigs.ClickHouseSetting{
|
||||
Host: params.Host,
|
||||
Port: params.Port,
|
||||
User: params.User,
|
||||
Password: password,
|
||||
Database: params.Database,
|
||||
}
|
||||
valueJSON, err := json.Marshal(cfg)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
|
||||
Code: clickhouseConfigCode,
|
||||
ValueJSON: valueJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Success()
|
||||
}
|
||||
33
EdgeAdmin/internal/web/actions/default/db/clickhouse_stub.go
Normal file
33
EdgeAdmin/internal/web/actions/default/db/clickhouse_stub.go
Normal file
@@ -0,0 +1,33 @@
|
||||
//go:build !plus
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
)
|
||||
|
||||
type ClickHouseAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ClickHouseAction) Init() {
|
||||
this.Nav("db", "db", "clickhouse")
|
||||
}
|
||||
|
||||
func (this *ClickHouseAction) RunGet(params struct{}) {
|
||||
this.Data["mainTab"] = "clickhouse"
|
||||
this.Data["config"] = map[string]interface{}{
|
||||
"host": "", "port": 8123, "user": "", "password": "", "database": "default",
|
||||
}
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *ClickHouseAction) RunPost(params struct {
|
||||
Host string
|
||||
Port int
|
||||
User string
|
||||
Password string
|
||||
Database string
|
||||
}) {
|
||||
this.Fail("请使用商业版以在页面上配置 ClickHouse")
|
||||
}
|
||||
@@ -23,5 +23,6 @@ func (this *Helper) BeforeAction(action *actions.ActionObject) {
|
||||
|
||||
var tabbar = actionutils.NewTabbar()
|
||||
tabbar.Add(this.Lang(action, codes.DBNode_TabNodes), "", "/db", "", selectedTabbar == "db")
|
||||
tabbar.Add(this.Lang(action, codes.DBNode_TabClickHouse), "", "/db/clickhouse", "", selectedTabbar == "clickhouse")
|
||||
actionutils.SetTabbar(action, tabbar)
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ func init() {
|
||||
Get("/node", new(NodeAction)).
|
||||
Get("/logs", new(LogsAction)).
|
||||
Post("/status", new(StatusAction)).
|
||||
GetPost("/clickhouse", new(ClickHouseAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user