CloudMigration: Provide a stats rollup in the GetSnapshot response (#90252)
* order session list descending * add snapshot status method to store * query stats while retrieving snapshot * return stats in dto * swagger * fix tests * commit results of bingo get * fix swagger * minor improvement * fix typo * forgot a file
This commit is contained in:
@@ -442,6 +442,17 @@ func (cma *CloudMigrationAPI) GetSnapshot(c *contextmodel.ReqContext) response.R
|
||||
}
|
||||
}
|
||||
|
||||
dtoStats := SnapshotResourceStats{
|
||||
Types: make(map[MigrateDataType]int, len(snapshot.StatsRollup.CountsByStatus)),
|
||||
Statuses: make(map[ItemStatus]int, len(snapshot.StatsRollup.CountsByType)),
|
||||
}
|
||||
for s, c := range snapshot.StatsRollup.CountsByStatus {
|
||||
dtoStats.Statuses[ItemStatus(s)] = c
|
||||
}
|
||||
for s, c := range snapshot.StatsRollup.CountsByType {
|
||||
dtoStats.Types[MigrateDataType(s)] = c
|
||||
}
|
||||
|
||||
respDto := GetSnapshotResponseDTO{
|
||||
SnapshotDTO: SnapshotDTO{
|
||||
SnapshotUID: snapshot.UID,
|
||||
@@ -450,7 +461,8 @@ func (cma *CloudMigrationAPI) GetSnapshot(c *contextmodel.ReqContext) response.R
|
||||
Created: snapshot.Created,
|
||||
Finished: snapshot.Finished,
|
||||
},
|
||||
Results: dtoResults,
|
||||
Results: dtoResults,
|
||||
StatsRollup: dtoStats,
|
||||
}
|
||||
|
||||
return response.JSON(http.StatusOK, respDto)
|
||||
|
||||
@@ -471,7 +471,7 @@ func TestCloudMigrationAPI_GetSnapshot(t *testing.T) {
|
||||
requestUrl: "/api/cloudmigration/migration/1234/snapshot/1",
|
||||
basicRole: org.RoleAdmin,
|
||||
expectedHttpResult: http.StatusOK,
|
||||
expectedBody: `{"uid":"fake_uid","status":"UNKNOWN","sessionUid":"1234","created":"0001-01-01T00:00:00Z","finished":"0001-01-01T00:00:00Z","results":[]}`,
|
||||
expectedBody: `{"uid":"fake_uid","status":"UNKNOWN","sessionUid":"1234","created":"0001-01-01T00:00:00Z","finished":"0001-01-01T00:00:00Z","results":[],"stats":{"types":{},"statuses":{}}}`,
|
||||
},
|
||||
{
|
||||
desc: "should return 403 if no used is not admin",
|
||||
|
||||
@@ -299,7 +299,13 @@ type GetSnapshotResponse struct {
|
||||
|
||||
type GetSnapshotResponseDTO struct {
|
||||
SnapshotDTO
|
||||
Results []MigrateDataResponseItemDTO `json:"results"`
|
||||
Results []MigrateDataResponseItemDTO `json:"results"`
|
||||
StatsRollup SnapshotResourceStats `json:"stats"`
|
||||
}
|
||||
|
||||
type SnapshotResourceStats struct {
|
||||
Types map[MigrateDataType]int `json:"types"`
|
||||
Statuses map[ItemStatus]int `json:"statuses"`
|
||||
}
|
||||
|
||||
// swagger:parameters getShapshotList
|
||||
|
||||
Reference in New Issue
Block a user