带阿里标识的版本
This commit is contained in:
@@ -10,8 +10,10 @@ 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 {
|
||||
@@ -41,13 +43,14 @@ func (this *ClusterSettingsAction) RunGet(params struct {
|
||||
}
|
||||
|
||||
settings := maps.Map{
|
||||
"name": cluster.GetString("name"),
|
||||
"gatewayDomain": cluster.GetString("gatewayDomain"),
|
||||
"cacheTtl": cluster.GetInt("defaultTTL"),
|
||||
"fallbackTimeout": cluster.GetInt("fallbackTimeout"),
|
||||
"installDir": cluster.GetString("installDir"),
|
||||
"isOn": cluster.GetBool("isOn"),
|
||||
"isDefaultCluster": cluster.GetBool("isDefault"),
|
||||
"name": cluster.GetString("name"),
|
||||
"gatewayDomain": cluster.GetString("gatewayDomain"),
|
||||
"cacheTtl": cluster.GetInt("defaultTTL"),
|
||||
"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
|
||||
@@ -59,6 +62,19 @@ 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,
|
||||
@@ -104,14 +120,15 @@ func (this *ClusterSettingsAction) RunGet(params struct {
|
||||
}
|
||||
|
||||
func (this *ClusterSettingsAction) RunPost(params struct {
|
||||
ClusterId int64
|
||||
Name string
|
||||
GatewayDomain string
|
||||
CacheTtl int32
|
||||
FallbackTimeout int32
|
||||
InstallDir string
|
||||
IsOn bool
|
||||
IsDefaultCluster bool
|
||||
ClusterId int64
|
||||
Name string
|
||||
GatewayDomain string
|
||||
CacheTtl int32
|
||||
FallbackTimeout int32
|
||||
InstallDir string
|
||||
IsOn bool
|
||||
IsDefaultCluster bool
|
||||
IsDefaultBackupCluster bool
|
||||
|
||||
Addresses []byte
|
||||
SslPolicyJSON []byte
|
||||
@@ -137,7 +154,15 @@ func (this *ClusterSettingsAction) RunPost(params struct {
|
||||
params.InstallDir = "/opt/edge-httpdns"
|
||||
}
|
||||
if params.IsDefaultCluster && !params.IsOn {
|
||||
this.Fail("默认集群必须保持启用状态")
|
||||
this.Fail("默认主集群必须保持启用状态")
|
||||
return
|
||||
}
|
||||
if params.IsDefaultBackupCluster && !params.IsOn {
|
||||
this.Fail("默认备用集群必须保持启用状态")
|
||||
return
|
||||
}
|
||||
if params.IsDefaultCluster && params.IsDefaultBackupCluster {
|
||||
this.Fail("默认主集群和默认备用集群不能是同一个集群")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -195,5 +220,33 @@ func (this *ClusterSettingsAction) RunPost(params struct {
|
||||
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)),
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user