CloudMigrations: Refactor API for async work (#89084)
* rename some stuff * more renaming * clean up api * rename more functions * rename cms -> gms * update comment * update swagger gen * update endpoints * overzealous * final touches * dont modify existing migrations * break structs into domain and dtos * add some conversion funcs * fix build * update frontend * try to make swagger happy
This commit is contained in:
@@ -11,37 +11,37 @@ import (
|
||||
var (
|
||||
ErrInternalNotImplementedError = errutil.Internal("cloudmigrations.notImplemented").Errorf("Internal server error")
|
||||
ErrFeatureDisabledError = errutil.Internal("cloudmigrations.disabled").Errorf("Cloud migrations are disabled on this instance")
|
||||
ErrMigrationNotFound = errutil.NotFound("cloudmigrations.migrationNotFound").Errorf("Migration not found")
|
||||
ErrMigrationNotFound = errutil.NotFound("cloudmigrations.sessionNotFound").Errorf("Session not found")
|
||||
ErrMigrationRunNotFound = errutil.NotFound("cloudmigrations.migrationRunNotFound").Errorf("Migration run not found")
|
||||
ErrMigrationNotDeleted = errutil.Internal("cloudmigrations.migrationNotDeleted").Errorf("Migration not deleted")
|
||||
ErrMigrationNotDeleted = errutil.Internal("cloudmigrations.sessionNotDeleted").Errorf("Session not deleted")
|
||||
ErrTokenNotFound = errutil.NotFound("cloudmigrations.tokenNotFound").Errorf("Token not found")
|
||||
)
|
||||
|
||||
// CloudMigration api dtos
|
||||
type CloudMigration struct {
|
||||
ID int64 `json:"id" xorm:"pk autoincr 'id'"`
|
||||
UID string `json:"uid" xorm:"uid"`
|
||||
AuthToken string `json:"-"`
|
||||
Stack string `json:"stack"`
|
||||
StackID int `json:"stackID" xorm:"stack_id"`
|
||||
RegionSlug string `json:"regionSlug"`
|
||||
ClusterSlug string `json:"clusterSlug"`
|
||||
Created time.Time `json:"created"`
|
||||
Updated time.Time `json:"updated"`
|
||||
// CloudMigration domain structs
|
||||
type CloudMigrationSession struct {
|
||||
ID int64 `xorm:"pk autoincr 'id'"`
|
||||
UID string `xorm:"uid"`
|
||||
AuthToken string
|
||||
Slug string
|
||||
StackID int `xorm:"stack_id"`
|
||||
RegionSlug string
|
||||
ClusterSlug string
|
||||
Created time.Time
|
||||
Updated time.Time
|
||||
}
|
||||
|
||||
type CloudMigrationRun struct {
|
||||
ID int64 `json:"id" xorm:"pk autoincr 'id'"`
|
||||
UID string `json:"uid" xorm:"uid"`
|
||||
CloudMigrationUID string `json:"migrationUid" xorm:"cloud_migration_uid"`
|
||||
Result []byte `json:"result"` //store raw cms response body
|
||||
Created time.Time `json:"created"`
|
||||
Updated time.Time `json:"updated"`
|
||||
Finished time.Time `json:"finished"`
|
||||
type CloudMigrationSnapshot struct {
|
||||
ID int64 `xorm:"pk autoincr 'id'"`
|
||||
UID string `xorm:"uid"`
|
||||
SessionUID string `xorm:"session_uid"`
|
||||
Result []byte //store raw gms response body
|
||||
Created time.Time
|
||||
Updated time.Time
|
||||
Finished time.Time
|
||||
}
|
||||
|
||||
func (r CloudMigrationRun) ToResponse() (*MigrateDataResponseDTO, error) {
|
||||
var result MigrateDataResponseDTO
|
||||
func (r CloudMigrationSnapshot) GetResult() (*MigrateDataResponse, error) {
|
||||
var result MigrateDataResponse
|
||||
err := json.Unmarshal(r.Result, &result)
|
||||
if err != nil {
|
||||
return nil, errors.New("could not parse result of run")
|
||||
@@ -50,23 +50,23 @@ func (r CloudMigrationRun) ToResponse() (*MigrateDataResponseDTO, error) {
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
type CloudMigrationRunList struct {
|
||||
Runs []MigrateDataResponseListDTO `json:"runs"`
|
||||
type SnapshotList struct {
|
||||
Runs []MigrateDataResponseList
|
||||
}
|
||||
|
||||
type CloudMigrationRequest struct {
|
||||
AuthToken string `json:"authToken"`
|
||||
type CloudMigrationSessionRequest struct {
|
||||
AuthToken string
|
||||
}
|
||||
|
||||
type CloudMigrationResponse struct {
|
||||
UID string `json:"uid"`
|
||||
Stack string `json:"stack"`
|
||||
Created time.Time `json:"created"`
|
||||
Updated time.Time `json:"updated"`
|
||||
type CloudMigrationSessionResponse struct {
|
||||
UID string
|
||||
Slug string
|
||||
Created time.Time
|
||||
Updated time.Time
|
||||
}
|
||||
|
||||
type CloudMigrationListResponse struct {
|
||||
Migrations []CloudMigrationResponse `json:"migrations"`
|
||||
type CloudMigrationSessionListResponse struct {
|
||||
Sessions []CloudMigrationSessionResponse
|
||||
}
|
||||
|
||||
// access token
|
||||
@@ -80,10 +80,10 @@ type Base64EncodedTokenPayload struct {
|
||||
Instance Base64HGInstance
|
||||
}
|
||||
|
||||
func (p Base64EncodedTokenPayload) ToMigration() CloudMigration {
|
||||
return CloudMigration{
|
||||
func (p Base64EncodedTokenPayload) ToMigration() CloudMigrationSession {
|
||||
return CloudMigrationSession{
|
||||
AuthToken: p.Token,
|
||||
Stack: p.Instance.Slug,
|
||||
Slug: p.Instance.Slug,
|
||||
StackID: p.Instance.StackID,
|
||||
RegionSlug: p.Instance.RegionSlug,
|
||||
ClusterSlug: p.Instance.ClusterSlug,
|
||||
@@ -97,9 +97,8 @@ type Base64HGInstance struct {
|
||||
ClusterSlug string
|
||||
}
|
||||
|
||||
// dtos for cms api
|
||||
// GMS domain structs
|
||||
|
||||
// swagger:enum MigrateDataType
|
||||
type MigrateDataType string
|
||||
|
||||
const (
|
||||
@@ -108,18 +107,17 @@ const (
|
||||
FolderDataType MigrateDataType = "FOLDER"
|
||||
)
|
||||
|
||||
type MigrateDataRequestDTO struct {
|
||||
Items []MigrateDataRequestItemDTO `json:"items"`
|
||||
type MigrateDataRequest struct {
|
||||
Items []MigrateDataRequestItem
|
||||
}
|
||||
|
||||
type MigrateDataRequestItemDTO struct {
|
||||
Type MigrateDataType `json:"type"`
|
||||
RefID string `json:"refId"`
|
||||
Name string `json:"name"`
|
||||
Data interface{} `json:"data"`
|
||||
type MigrateDataRequestItem struct {
|
||||
Type MigrateDataType
|
||||
RefID string
|
||||
Name string
|
||||
Data interface{}
|
||||
}
|
||||
|
||||
// swagger:enum ItemStatus
|
||||
type ItemStatus string
|
||||
|
||||
const (
|
||||
@@ -127,21 +125,18 @@ const (
|
||||
ItemStatusError ItemStatus = "ERROR"
|
||||
)
|
||||
|
||||
type MigrateDataResponseDTO struct {
|
||||
RunUID string `json:"uid"`
|
||||
Items []MigrateDataResponseItemDTO `json:"items"`
|
||||
type MigrateDataResponse struct {
|
||||
RunUID string
|
||||
Items []MigrateDataResponseItem
|
||||
}
|
||||
|
||||
type MigrateDataResponseListDTO struct {
|
||||
RunUID string `json:"uid"`
|
||||
type MigrateDataResponseList struct {
|
||||
RunUID string
|
||||
}
|
||||
|
||||
type MigrateDataResponseItemDTO struct {
|
||||
// required:true
|
||||
Type MigrateDataType `json:"type"`
|
||||
// required:true
|
||||
RefID string `json:"refId"`
|
||||
// required:true
|
||||
Status ItemStatus `json:"status"`
|
||||
Error string `json:"error,omitempty"`
|
||||
type MigrateDataResponseItem struct {
|
||||
Type MigrateDataType
|
||||
RefID string
|
||||
Status ItemStatus
|
||||
Error string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user