Skip to content

Commit

Permalink
fix(region): storage extra info (#17832)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito authored Aug 23, 2023
1 parent 6baad13 commit 4b5e211
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 27 deletions.
5 changes: 5 additions & 0 deletions pkg/apis/compute/cloudaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ type CloudaccountResourceInfo struct {
// 云账号名称
// example: google-account
Account string `json:"account,omitempty"`

// 云账号状态
AccountStatus string `json:"account_status,omitempty"`
// 云账号监控状态
AccountHealthStatus string `json:"account_health_status,omitempty"`
}

type CloudaccountCreateInput struct {
Expand Down
6 changes: 4 additions & 2 deletions pkg/apis/compute/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ type SStorageCapacityInfo struct {
}

type StorageHost struct {
Id string
Name string
Id string
Name string
Status string
HostStatus string
}

type StorageDetails struct {
Expand Down
2 changes: 2 additions & 0 deletions pkg/compute/models/managedresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ func (manager *SManagedResourceBaseManager) FetchCustomizeColumns(
for i := range rows {
if account, ok := accounts[rows[i].AccountId]; ok {
rows[i].Account = account.Name
rows[i].AccountStatus = account.Status
rows[i].AccountHealthStatus = account.HealthStatus
rows[i].Brand = account.Brand
rows[i].Provider = account.Provider
rows[i].CloudEnv = account.GetCloudEnv()
Expand Down
58 changes: 33 additions & 25 deletions pkg/compute/models/storages.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,37 +571,45 @@ func (manager *SStorageManager) FetchCustomizeColumns(
tagMap[tags[i].StorageId] = append(tagMap[tags[i].StorageId], desc)
}

q = HoststorageManager.Query("storage_id", "host_id").In("storage_id", storageIds)
hoststorages, err := q.Rows()
sq := HoststorageManager.Query().In("storage_id", storageIds).SubQuery()
hosts := HostManager.Query().SubQuery()
q = sq.Query(
sq.Field("storage_id"),
sq.Field("host_id"),
hosts.Field("name"),
hosts.Field("status"),
hosts.Field("host_status"),
).LeftJoin(hosts, sqlchemy.Equals(sq.Field("host_id"), hosts.Field("id")))

hs := []struct {
StorageId string
HostId string
Name string
Status string
HostStatus string
}{}
err = q.All(&hs)
if err != nil {
log.Errorf("query host error: %v", err)
return rows
}
defer hoststorages.Close()
hostIds := []string{}
storageMap := make(map[string][]string, len(objs))
for hoststorages.Next() {
var storageId, hostId string
hoststorages.Scan(&storageId, &hostId)
if _, ok := storageMap[storageId]; !ok {
storageMap[storageId] = []string{}

hoststorages := map[string][]api.StorageHost{}
for _, h := range hs {
_, ok := hoststorages[h.StorageId]
if !ok {
hoststorages[h.StorageId] = []api.StorageHost{}
}
storageMap[storageId] = append(storageMap[storageId], hostId)
hostIds = append(hostIds, hostId)
}
hostMap, err := db.FetchIdNameMap2(HostManager, hostIds)
if err != nil {
return rows
hoststorages[h.StorageId] = append(hoststorages[h.StorageId], api.StorageHost{
Id: h.HostId,
Name: h.Name,
Status: h.Status,
HostStatus: h.HostStatus,
})
}

for i := range rows {
hostIds, ok := storageMap[storageIds[i]]
if ok {
rows[i].Hosts = []api.StorageHost{}
for _, hostId := range hostIds {
if name, ok := hostMap[hostId]; ok {
rows[i].Hosts = append(rows[i].Hosts, api.StorageHost{Id: hostId, Name: name})
}
}
}
rows[i].Hosts, _ = hoststorages[storageIds[i]]
tags, ok := tagMap[storageIds[i]]
if ok {
rows[i].Schedtags = tags
Expand Down

0 comments on commit 4b5e211

Please sign in to comment.