Skip to content

Commit

Permalink
fix: 返回项目信息
Browse files Browse the repository at this point in the history
  • Loading branch information
Qu Xuan committed May 22, 2020
1 parent 575f1c2 commit 5cdeebb
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 3 deletions.
1 change: 1 addition & 0 deletions pkg/apis/compute/dbinstance_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type DBInstancePrivilege struct {

type DBInstanceAccountDetails struct {
apis.StatusStandaloneResourceDetails
apis.ProjectizedResourceInfo
DBInstanceResourceInfo

SDBInstanceAccount
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/compute/dbinstance_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type DBInstanceDatabaseCreateInput struct {

type DBInstancedatabaseDetails struct {
apis.StatusStandaloneResourceDetails
apis.ProjectizedResourceInfo
DBInstanceResourceInfo

SDBInstanceDatabase
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/compute/elasticcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ type ElasticcacheFilterListInput struct {

type ElasticcacheAccountDetails struct {
apis.StatusStandaloneResourceDetails
apis.ProjectizedResourceInfo
ElasticcacheResourceInfo

SElasticcacheAccount
}

type ElasticcacheAclDetails struct {
apis.StandaloneResourceDetails
apis.ProjectizedResourceInfo
ElasticcacheResourceInfo

SElasticcacheAcl
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/compute/elasticcachebackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import "yunion.io/x/onecloud/pkg/apis"

type ElasticcacheBackupDetails struct {
apis.StatusStandaloneResourceDetails
apis.ProjectizedResourceInfo
ElasticcacheResourceInfo

SElasticcacheBackup
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/compute/secgrouprule.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import "yunion.io/x/onecloud/pkg/apis"

type SecgroupRuleDetails struct {
apis.ResourceBaseDetails
apis.ProjectizedResourceInfo
SSecurityGroupRule
SecurityGroupResourceInfo
}
25 changes: 24 additions & 1 deletion pkg/compute/models/dbinstance_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,36 @@ func (manager *SDBInstanceAccountManager) FetchCustomizeColumns(
rows := make([]api.DBInstanceAccountDetails, len(objs))
stdRows := manager.SStatusStandaloneResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
dbRows := manager.SDBInstanceResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
dbinstanceIds := make([]string, len(objs))
for i := range rows {
rows[i] = api.DBInstanceAccountDetails{
StatusStandaloneResourceDetails: stdRows[i],
DBInstanceResourceInfo: dbRows[i],
}
rows[i], _ = objs[i].(*SDBInstanceAccount).getMoreDetails(ctx, userCred, rows[i])
account := objs[i].(*SDBInstanceAccount)
rows[i], _ = account.getMoreDetails(ctx, userCred, rows[i])
dbinstanceIds[i] = account.DBInstanceId
}

dbinstances := make(map[string]SDBInstance)
err := db.FetchStandaloneObjectsByIds(DBInstanceManager, dbinstanceIds, &dbinstances)
if err != nil {
log.Errorf("FetchStandaloneObjectsByIds fail: %v", err)
return rows
}

virObjs := make([]interface{}, len(objs))
for i := range rows {
if dbinstance, ok := dbinstances[dbinstanceIds[i]]; ok {
virObjs[i] = &dbinstance
}
}

projRows := DBInstanceManager.SProjectizedResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, virObjs, stringutils2.SSortedStrings{}, isList)
for i := range rows {
rows[i].ProjectizedResourceInfo = projRows[i]
}

return rows
}

Expand Down
25 changes: 24 additions & 1 deletion pkg/compute/models/dbinstance_databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,36 @@ func (manager *SDBInstanceDatabaseManager) FetchCustomizeColumns(
rows := make([]api.DBInstancedatabaseDetails, len(objs))
stdRows := manager.SStatusStandaloneResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
dbRows := manager.SDBInstanceResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
dbinstanceIds := make([]string, len(objs))
for i := range rows {
rows[i] = api.DBInstancedatabaseDetails{
StatusStandaloneResourceDetails: stdRows[i],
DBInstanceResourceInfo: dbRows[i],
}
rows[i], _ = objs[i].(*SDBInstanceDatabase).getMoreDetails(ctx, userCred, rows[i])
database := objs[i].(*SDBInstanceDatabase)
rows[i], _ = database.getMoreDetails(ctx, userCred, rows[i])
dbinstanceIds[i] = database.DBInstanceId
}

dbinstances := make(map[string]SDBInstance)
err := db.FetchStandaloneObjectsByIds(DBInstanceManager, dbinstanceIds, &dbinstances)
if err != nil {
log.Errorf("FetchStandaloneObjectsByIds fail: %v", err)
return rows
}

virObjs := make([]interface{}, len(objs))
for i := range rows {
if dbinstance, ok := dbinstances[dbinstanceIds[i]]; ok {
virObjs[i] = &dbinstance
}
}

projRows := DBInstanceManager.SProjectizedResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, virObjs, fields, isList)
for i := range rows {
rows[i].ProjectizedResourceInfo = projRows[i]
}

return rows
}

Expand Down
22 changes: 22 additions & 0 deletions pkg/compute/models/elasticcache_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,33 @@ func (manager *SElasticcacheAccountManager) FetchCustomizeColumns(
stdRows := manager.SStatusStandaloneResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
cacheRows := manager.SElasticcacheResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)

cacheIds := make([]string, len(objs))
for i := range rows {
rows[i] = api.ElasticcacheAccountDetails{
StatusStandaloneResourceDetails: stdRows[i],
ElasticcacheResourceInfo: cacheRows[i],
}
account := objs[i].(*SElasticcacheAccount)
cacheIds[i] = account.ElasticcacheId
}

caches := make(map[string]SElasticcache)
err := db.FetchStandaloneObjectsByIds(ElasticcacheManager, cacheIds, &caches)
if err != nil {
log.Errorf("FetchStandaloneObjectsByIds fail: %v", err)
return rows
}

virObjs := make([]interface{}, len(objs))
for i := range rows {
if cache, ok := caches[cacheIds[i]]; ok {
virObjs[i] = &cache
}
}

projRows := ElasticcacheManager.SProjectizedResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, virObjs, fields, isList)
for i := range rows {
rows[i].ProjectizedResourceInfo = projRows[i]
}

return rows
Expand Down
22 changes: 22 additions & 0 deletions pkg/compute/models/elasticcache_acls.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,33 @@ func (manager *SElasticcacheAclManager) FetchCustomizeColumns(
stdRows := manager.SStandaloneResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
elasticRows := manager.SElasticcacheResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)

cacheIds := make([]string, len(objs))
for i := range rows {
rows[i] = api.ElasticcacheAclDetails{
StandaloneResourceDetails: stdRows[i],
ElasticcacheResourceInfo: elasticRows[i],
}
acl := objs[i].(*SElasticcacheAcl)
cacheIds[i] = acl.ElasticcacheId
}

caches := make(map[string]SElasticcache)
err := db.FetchStandaloneObjectsByIds(ElasticcacheManager, cacheIds, &caches)
if err != nil {
log.Errorf("FetchStandaloneObjectsByIds fail: %v", err)
return rows
}

virObjs := make([]interface{}, len(objs))
for i := range rows {
if cache, ok := caches[cacheIds[i]]; ok {
virObjs[i] = &cache
}
}

projRows := ElasticcacheManager.SProjectizedResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, virObjs, fields, isList)
for i := range rows {
rows[i].ProjectizedResourceInfo = projRows[i]
}

return rows
Expand Down
23 changes: 22 additions & 1 deletion pkg/compute/models/elasticcache_backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,33 @@ func (manager *SElasticcacheBackupManager) FetchCustomizeColumns(

stdRows := manager.SStatusStandaloneResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
cacheRows := manager.SElasticcacheResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)

cacheIds := make([]string, len(objs))
for i := range rows {
rows[i] = api.ElasticcacheBackupDetails{
StatusStandaloneResourceDetails: stdRows[i],
ElasticcacheResourceInfo: cacheRows[i],
}
backup := objs[i].(*SElasticcacheBackup)
cacheIds[i] = backup.ElasticcacheId
}

caches := make(map[string]SElasticcache)
err := db.FetchStandaloneObjectsByIds(ElasticcacheManager, cacheIds, &caches)
if err != nil {
log.Errorf("FetchStandaloneObjectsByIds fail: %v", err)
return rows
}

virObjs := make([]interface{}, len(objs))
for i := range rows {
if cache, ok := caches[cacheIds[i]]; ok {
virObjs[i] = &cache
}
}

projRows := ElasticcacheManager.SProjectizedResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, virObjs, fields, isList)
for i := range rows {
rows[i].ProjectizedResourceInfo = projRows[i]
}

return rows
Expand Down
23 changes: 23 additions & 0 deletions pkg/compute/models/secgrouprules.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,35 @@ func (manager *SSecurityGroupRuleManager) FetchCustomizeColumns(
rows := make([]api.SecgroupRuleDetails, len(objs))
bRows := manager.SResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
secRows := manager.SSecurityGroupResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
secIds := make([]string, len(objs))
for i := range rows {
rows[i] = api.SecgroupRuleDetails{
ResourceBaseDetails: bRows[i],
SecurityGroupResourceInfo: secRows[i],
}
rule := objs[i].(*SSecurityGroupRule)
secIds[i] = rule.SecgroupId
}

secgroups := make(map[string]SSecurityGroup)
err := db.FetchStandaloneObjectsByIds(SecurityGroupManager, secIds, &secgroups)
if err != nil {
log.Errorf("FetchStandaloneObjectsByIds fail: %v", err)
return rows
}

virObjs := make([]interface{}, len(objs))
for i := range rows {
if secgroup, ok := secgroups[secIds[i]]; ok {
virObjs[i] = &secgroup
}
}

projRows := SecurityGroupManager.SProjectizedResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, virObjs, fields, isList)
for i := range rows {
rows[i].ProjectizedResourceInfo = projRows[i]
}

return rows
}

Expand Down

0 comments on commit 5cdeebb

Please sign in to comment.