CloudMigrations: Break snapshot resources out into their own table (#89575)
* create a new table for migration resources * remove raw result bytes from db * more snapshot resource management stuff * integrate new table with snapshots * pass in result limit and offset as params * combine create and update * set up xorm store test * add unit tests * save some cpu * remove unneeded arg * regen swagger * fix bug with result processing * fix update create logic so that uid isn't required for lookup * change offset to page * regen swagger * revert accidental changes to file * curl command page should be 1 indexed
This commit is contained in:
@@ -412,23 +412,32 @@ func (cma *CloudMigrationAPI) GetSnapshot(c *contextmodel.ReqContext) response.R
|
||||
return response.ErrOrFallback(http.StatusBadRequest, "invalid snapshot uid", err)
|
||||
}
|
||||
|
||||
snapshot, err := cma.cloudMigrationService.GetSnapshot(ctx, sessUid, snapshotUid)
|
||||
q := cloudmigration.GetSnapshotsQuery{
|
||||
SnapshotUID: snapshotUid,
|
||||
SessionUID: sessUid,
|
||||
ResultPage: c.QueryInt("resultPage"),
|
||||
ResultLimit: c.QueryInt("resultLimit"),
|
||||
}
|
||||
if q.ResultLimit == 0 {
|
||||
q.ResultLimit = 100
|
||||
}
|
||||
if q.ResultPage < 1 {
|
||||
q.ResultPage = 1
|
||||
}
|
||||
snapshot, err := cma.cloudMigrationService.GetSnapshot(ctx, q)
|
||||
if err != nil {
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "error retrieving snapshot", err)
|
||||
}
|
||||
|
||||
result, err := snapshot.GetSnapshotResult()
|
||||
if err != nil {
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "error snapshot reading snapshot results", err)
|
||||
}
|
||||
results := snapshot.Resources
|
||||
|
||||
dtoResults := make([]MigrateDataResponseItemDTO, len(result))
|
||||
for i := 0; i < len(result); i++ {
|
||||
dtoResults := make([]MigrateDataResponseItemDTO, len(results))
|
||||
for i := 0; i < len(results); i++ {
|
||||
dtoResults[i] = MigrateDataResponseItemDTO{
|
||||
Type: MigrateDataType(result[i].Type),
|
||||
RefID: result[i].RefID,
|
||||
Status: ItemStatus(result[i].Status),
|
||||
Error: result[i].Error,
|
||||
Type: MigrateDataType(results[i].Type),
|
||||
RefID: results[i].RefID,
|
||||
Status: ItemStatus(results[i].Status),
|
||||
Error: results[i].Error,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -467,11 +476,14 @@ func (cma *CloudMigrationAPI) GetSnapshotList(c *contextmodel.ReqContext) respon
|
||||
q := cloudmigration.ListSnapshotsQuery{
|
||||
SessionUID: uid,
|
||||
Limit: c.QueryInt("limit"),
|
||||
Offset: c.QueryInt("offset"),
|
||||
Page: c.QueryInt("page"),
|
||||
}
|
||||
if q.Limit == 0 {
|
||||
q.Limit = 100
|
||||
}
|
||||
if q.Page < 1 {
|
||||
q.Page = 1
|
||||
}
|
||||
|
||||
snapshotList, err := cma.cloudMigrationService.GetSnapshotList(ctx, q)
|
||||
if err != nil {
|
||||
|
||||
@@ -11,10 +11,10 @@ curl -X POST -H "Content-Type: application/json" \
|
||||
http://admin:admin@localhost:3000/api/cloudmigration/migration/{sessionUid}/snapshot
|
||||
|
||||
[get snapshot list]
|
||||
curl -X GET http://admin:admin@localhost:3000/api/cloudmigration/migration/{sessionUid}/snapshots?limit=100&offset=0
|
||||
curl -X GET http://admin:admin@localhost:3000/api/cloudmigration/migration/{sessionUid}/snapshots?limit=100&page=1
|
||||
|
||||
[get snapshot]
|
||||
curl -X GET http://admin:admin@localhost:3000/api/cloudmigration/migration/{sessionUid}/snapshot/{snapshotUid}
|
||||
curl -X GET http://admin:admin@localhost:3000/api/cloudmigration/migration/{sessionUid}/snapshot/{snapshotUid}?resultLimit=100&resultPage=1
|
||||
|
||||
[upload snapshot]
|
||||
curl -X POST -H "Content-Type: application/json" \
|
||||
|
||||
@@ -128,8 +128,10 @@ const (
|
||||
type ItemStatus string
|
||||
|
||||
const (
|
||||
ItemStatusOK ItemStatus = "OK"
|
||||
ItemStatusError ItemStatus = "ERROR"
|
||||
ItemStatusOK ItemStatus = "OK"
|
||||
ItemStatusError ItemStatus = "ERROR"
|
||||
ItemStatusPending ItemStatus = "PENDING"
|
||||
ItemStatusUnknown ItemStatus = "UNKNOWN"
|
||||
)
|
||||
|
||||
// swagger:parameters getCloudMigrationRun
|
||||
@@ -268,6 +270,18 @@ type CreateSnapshotResponseDTO struct {
|
||||
|
||||
// swagger:parameters getSnapshot
|
||||
type GetSnapshotParams struct {
|
||||
// ResultPage is used for pagination with ResultLimit
|
||||
// in:query
|
||||
// required:false
|
||||
// default: 1
|
||||
ResultPage int `json:"resultPage"`
|
||||
|
||||
// Max limit for snapshot results returned.
|
||||
// in:query
|
||||
// required:false
|
||||
// default: 100
|
||||
ResultLimit int `json:"resultLimit"`
|
||||
|
||||
// Session UID of a session
|
||||
// in: path
|
||||
UID string `json:"uid"`
|
||||
@@ -290,16 +304,18 @@ type GetSnapshotResponseDTO struct {
|
||||
|
||||
// swagger:parameters getShapshotList
|
||||
type GetSnapshotListParams struct {
|
||||
// Offset is used for pagination with limit
|
||||
// Page is used for pagination with limit
|
||||
// in:query
|
||||
// required:false
|
||||
// default: 0
|
||||
Offset int `json:"offset"`
|
||||
// default: 1
|
||||
Page int `json:"page"`
|
||||
|
||||
// Max limit for results returned.
|
||||
// in:query
|
||||
// required:false
|
||||
// default: 100
|
||||
Limit int `json:"limit"`
|
||||
|
||||
// Session UID of a session
|
||||
// in: path
|
||||
UID string `json:"uid"`
|
||||
|
||||
Reference in New Issue
Block a user