换成单集群模式
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package apps
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
@@ -57,24 +57,61 @@ func (this *AppSettingsAction) RunGet(params struct {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
clusterDomainMap := map[int64]string{}
|
||||
clusterApiAddressMap := map[int64]string{}
|
||||
clusterNameMap := map[int64]string{}
|
||||
for _, cluster := range clusterResp.GetClusters() {
|
||||
clusterDomainMap[cluster.GetId()] = cluster.GetServiceDomain()
|
||||
port := "443"
|
||||
if rawTLS := cluster.GetTlsPolicyJSON(); len(rawTLS) > 0 {
|
||||
var tlsConfig map[string]interface{}
|
||||
if err := json.Unmarshal(rawTLS, &tlsConfig); err == nil {
|
||||
if listenRaw, ok := tlsConfig["listen"]; ok && listenRaw != nil {
|
||||
if data, err := json.Marshal(listenRaw); err == nil {
|
||||
var listenAddresses []map[string]interface{}
|
||||
if err := json.Unmarshal(data, &listenAddresses); err == nil {
|
||||
if len(listenAddresses) > 0 {
|
||||
if portRange, ok := listenAddresses[0]["portRange"].(string); ok && len(portRange) > 0 {
|
||||
port = portRange
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
apiAddress := "https://" + cluster.GetServiceDomain() + ":" + port
|
||||
clusterApiAddressMap[cluster.GetId()] = apiAddress
|
||||
clusterNameMap[cluster.GetId()] = cluster.GetName()
|
||||
}
|
||||
|
||||
// 读取应用绑定的集群列表
|
||||
var clusterIds []int64
|
||||
if raw := app.Get("clusterIds"); raw != nil {
|
||||
if ids, ok := raw.([]int64); ok {
|
||||
clusterIds = ids
|
||||
}
|
||||
}
|
||||
|
||||
// 构建服务地址列表
|
||||
serviceAddresses := make([]maps.Map, 0)
|
||||
for _, cid := range clusterIds {
|
||||
addr := clusterApiAddressMap[cid]
|
||||
name := clusterNameMap[cid]
|
||||
if len(addr) > 0 {
|
||||
serviceAddresses = append(serviceAddresses, maps.Map{
|
||||
"address": addr,
|
||||
"clusterName": name,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
primaryClusterId := app.GetInt64("primaryClusterId")
|
||||
backupClusterId := app.GetInt64("backupClusterId")
|
||||
settings := maps.Map{
|
||||
"appId": app.GetString("appId"),
|
||||
"appStatus": app.GetBool("isOn"),
|
||||
"primaryClusterId": primaryClusterId,
|
||||
"backupClusterId": backupClusterId,
|
||||
"primaryServiceDomain": clusterDomainMap[primaryClusterId],
|
||||
"backupServiceDomain": clusterDomainMap[backupClusterId],
|
||||
"signEnabled": app.GetBool("signEnabled"),
|
||||
"signSecretPlain": app.GetString("signSecretPlain"),
|
||||
"signSecretMasked": app.GetString("signSecretMasked"),
|
||||
"signSecretUpdatedAt": app.GetString("signSecretUpdated"),
|
||||
"appId": app.GetString("appId"),
|
||||
"appStatus": app.GetBool("isOn"),
|
||||
"serviceAddresses": serviceAddresses,
|
||||
"signEnabled": app.GetBool("signEnabled"),
|
||||
"signSecretPlain": app.GetString("signSecretPlain"),
|
||||
"signSecretMasked": app.GetString("signSecretMasked"),
|
||||
"signSecretUpdatedAt": app.GetString("signSecretUpdated"),
|
||||
}
|
||||
this.Data["app"] = app
|
||||
this.Data["settings"] = settings
|
||||
@@ -104,12 +141,11 @@ func (this *AppSettingsAction) RunPost(params struct {
|
||||
}
|
||||
|
||||
_, err = this.RPC().HTTPDNSAppRPC().UpdateHTTPDNSApp(this.UserContext(), &pb.UpdateHTTPDNSAppRequest{
|
||||
AppDbId: params.AppId,
|
||||
Name: appResp.GetApp().GetName(),
|
||||
PrimaryClusterId: appResp.GetApp().GetPrimaryClusterId(),
|
||||
BackupClusterId: appResp.GetApp().GetBackupClusterId(),
|
||||
IsOn: params.AppStatus,
|
||||
UserId: appResp.GetApp().GetUserId(),
|
||||
AppDbId: params.AppId,
|
||||
Name: appResp.GetApp().GetName(),
|
||||
ClusterIdsJSON: appResp.GetApp().GetClusterIdsJSON(),
|
||||
IsOn: params.AppStatus,
|
||||
UserId: appResp.GetApp().GetUserId(),
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
|
||||
Reference in New Issue
Block a user