换成单集群模式
This commit is contained in:
@@ -10,10 +10,8 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
type ClusterSettingsAction struct {
|
||||
@@ -49,11 +47,9 @@ func (this *ClusterSettingsAction) RunGet(params struct {
|
||||
"fallbackTimeout": cluster.GetInt("fallbackTimeout"),
|
||||
"installDir": cluster.GetString("installDir"),
|
||||
"isOn": cluster.GetBool("isOn"),
|
||||
"isDefaultCluster": cluster.GetBool("isDefault"),
|
||||
"isDefaultBackupCluster": false,
|
||||
}
|
||||
if settings.GetInt("cacheTtl") <= 0 {
|
||||
settings["cacheTtl"] = 30
|
||||
settings["cacheTtl"] = 60
|
||||
}
|
||||
if settings.GetInt("fallbackTimeout") <= 0 {
|
||||
settings["fallbackTimeout"] = 300
|
||||
@@ -62,22 +58,9 @@ func (this *ClusterSettingsAction) RunGet(params struct {
|
||||
settings["installDir"] = "/opt/edge-httpdns"
|
||||
}
|
||||
|
||||
defaultBackupResp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{
|
||||
Code: string(systemconfigs.SettingCodeHTTPDNSDefaultBackupClusterId),
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
defaultBackupClusterId := int64(0)
|
||||
if defaultBackupResp != nil && len(defaultBackupResp.GetValueJSON()) > 0 {
|
||||
defaultBackupClusterId = types.Int64(string(defaultBackupResp.GetValueJSON()))
|
||||
}
|
||||
settings["isDefaultBackupCluster"] = defaultBackupClusterId == params.ClusterId
|
||||
|
||||
listenAddresses := []*serverconfigs.NetworkAddressConfig{
|
||||
{
|
||||
Protocol: serverconfigs.ProtocolHTTPS,
|
||||
Protocol: serverconfigs.ProtocolTLS,
|
||||
Host: "",
|
||||
PortRange: "443",
|
||||
},
|
||||
@@ -126,9 +109,7 @@ func (this *ClusterSettingsAction) RunPost(params struct {
|
||||
CacheTtl int32
|
||||
FallbackTimeout int32
|
||||
InstallDir string
|
||||
IsOn bool
|
||||
IsDefaultCluster bool
|
||||
IsDefaultBackupCluster bool
|
||||
IsOn bool
|
||||
|
||||
Addresses []byte
|
||||
SslPolicyJSON []byte
|
||||
@@ -145,7 +126,7 @@ func (this *ClusterSettingsAction) RunPost(params struct {
|
||||
params.Must.Field("gatewayDomain", params.GatewayDomain).Require("请输入服务域名")
|
||||
|
||||
if params.CacheTtl <= 0 {
|
||||
params.CacheTtl = 30
|
||||
params.CacheTtl = 60
|
||||
}
|
||||
if params.FallbackTimeout <= 0 {
|
||||
params.FallbackTimeout = 300
|
||||
@@ -153,18 +134,6 @@ func (this *ClusterSettingsAction) RunPost(params struct {
|
||||
if len(params.InstallDir) == 0 {
|
||||
params.InstallDir = "/opt/edge-httpdns"
|
||||
}
|
||||
if params.IsDefaultCluster && !params.IsOn {
|
||||
this.Fail("默认主集群必须保持启用状态")
|
||||
return
|
||||
}
|
||||
if params.IsDefaultBackupCluster && !params.IsOn {
|
||||
this.Fail("默认备用集群必须保持启用状态")
|
||||
return
|
||||
}
|
||||
if params.IsDefaultCluster && params.IsDefaultBackupCluster {
|
||||
this.Fail("默认主集群和默认备用集群不能是同一个集群")
|
||||
return
|
||||
}
|
||||
|
||||
cluster, err := findClusterMap(this.Parent(), params.ClusterId)
|
||||
if err != nil {
|
||||
@@ -213,35 +182,7 @@ func (this *ClusterSettingsAction) RunPost(params struct {
|
||||
InstallDir: params.InstallDir,
|
||||
TlsPolicyJSON: tlsPolicyJSON,
|
||||
IsOn: params.IsOn,
|
||||
IsDefault: params.IsDefaultCluster,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
backupClusterValue := int64(0)
|
||||
if params.IsDefaultBackupCluster {
|
||||
backupClusterValue = params.ClusterId
|
||||
} else {
|
||||
readResp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{
|
||||
Code: string(systemconfigs.SettingCodeHTTPDNSDefaultBackupClusterId),
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if readResp != nil && len(readResp.GetValueJSON()) > 0 {
|
||||
oldBackupClusterId := types.Int64(string(readResp.GetValueJSON()))
|
||||
if oldBackupClusterId != params.ClusterId {
|
||||
backupClusterValue = oldBackupClusterId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
|
||||
Code: string(systemconfigs.SettingCodeHTTPDNSDefaultBackupClusterId),
|
||||
ValueJSON: []byte(strconv.FormatInt(backupClusterValue, 10)),
|
||||
IsDefault: false,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
|
||||
Reference in New Issue
Block a user