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:
@@ -1,8 +1,6 @@
|
||||
package cloudmigration
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/apimachinery/errutil"
|
||||
@@ -45,8 +43,8 @@ type CloudMigrationSnapshot struct {
|
||||
Updated time.Time
|
||||
Finished time.Time
|
||||
|
||||
// []MigrateDataResponseItem
|
||||
Result []byte `xorm:"result"` //store raw gms response body
|
||||
// Stored in the cloud_migration_resource table
|
||||
Resources []CloudMigrationResource `xorm:"-"`
|
||||
}
|
||||
|
||||
type SnapshotStatus string
|
||||
@@ -63,14 +61,24 @@ const (
|
||||
SnapshotStatusUnknown = "unknown"
|
||||
)
|
||||
|
||||
type CloudMigrationResource struct {
|
||||
ID int64 `xorm:"pk autoincr 'id'"`
|
||||
UID string `xorm:"uid"`
|
||||
|
||||
Type MigrateDataType `xorm:"resource_type"`
|
||||
RefID string `xorm:"resource_uid"`
|
||||
Status ItemStatus `xorm:"status"`
|
||||
Error string `xorm:"error_string"`
|
||||
|
||||
SnapshotUID string `xorm:"snapshot_uid"`
|
||||
}
|
||||
|
||||
// Deprecated, use GetSnapshotResult for the async workflow
|
||||
func (s CloudMigrationSnapshot) GetResult() (*MigrateDataResponse, error) {
|
||||
var result MigrateDataResponse
|
||||
err := json.Unmarshal(s.Result, &result)
|
||||
if err != nil {
|
||||
return nil, errors.New("could not parse result of run")
|
||||
result := MigrateDataResponse{
|
||||
RunUID: s.UID,
|
||||
Items: s.Resources,
|
||||
}
|
||||
result.RunUID = s.UID
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
@@ -78,17 +86,6 @@ func (s CloudMigrationSnapshot) ShouldQueryGMS() bool {
|
||||
return s.Status == SnapshotStatusPendingProcessing || s.Status == SnapshotStatusProcessing
|
||||
}
|
||||
|
||||
func (s CloudMigrationSnapshot) GetSnapshotResult() ([]MigrateDataResponseItem, error) {
|
||||
var result []MigrateDataResponseItem
|
||||
if len(s.Result) > 0 {
|
||||
err := json.Unmarshal(s.Result, &result)
|
||||
if err != nil {
|
||||
return nil, errors.New("could not parse result of run")
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
type CloudMigrationRunList struct {
|
||||
Runs []MigrateDataResponseList
|
||||
}
|
||||
@@ -108,16 +105,23 @@ type CloudMigrationSessionListResponse struct {
|
||||
Sessions []CloudMigrationSessionResponse
|
||||
}
|
||||
|
||||
type GetSnapshotsQuery struct {
|
||||
SnapshotUID string
|
||||
SessionUID string
|
||||
ResultPage int
|
||||
ResultLimit int
|
||||
}
|
||||
|
||||
type ListSnapshotsQuery struct {
|
||||
SessionUID string
|
||||
Offset int
|
||||
Page int
|
||||
Limit int
|
||||
}
|
||||
|
||||
type UpdateSnapshotCmd struct {
|
||||
UID string
|
||||
Status SnapshotStatus
|
||||
Result []byte //store raw gms response body
|
||||
UID string
|
||||
Status SnapshotStatus
|
||||
Resources []CloudMigrationResource
|
||||
}
|
||||
|
||||
// access token
|
||||
@@ -172,26 +176,21 @@ type MigrateDataRequestItem struct {
|
||||
type ItemStatus string
|
||||
|
||||
const (
|
||||
ItemStatusOK ItemStatus = "OK"
|
||||
ItemStatusError ItemStatus = "ERROR"
|
||||
ItemStatusOK ItemStatus = "OK"
|
||||
ItemStatusError ItemStatus = "ERROR"
|
||||
ItemStatusPending ItemStatus = "PENDING"
|
||||
ItemStatusUnknown ItemStatus = "UNKNOWN"
|
||||
)
|
||||
|
||||
type MigrateDataResponse struct {
|
||||
RunUID string
|
||||
Items []MigrateDataResponseItem
|
||||
Items []CloudMigrationResource
|
||||
}
|
||||
|
||||
type MigrateDataResponseList struct {
|
||||
RunUID string
|
||||
}
|
||||
|
||||
type MigrateDataResponseItem struct {
|
||||
Type MigrateDataType
|
||||
RefID string
|
||||
Status ItemStatus
|
||||
Error string
|
||||
}
|
||||
|
||||
type CreateSessionResponse struct {
|
||||
SnapshotUid string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user