CloudMigrations: Implement migrations API (#85348)
* Implement run migration endpoint * Refactor RunMigration method into separate methods * Save migration runs fix lint * Minor changes * Refactor how to use cms endpoint * fix interface * complete merge * add individual items * adds tracing to getMigration * linter * updated swagger definition with the latest changes * CloudMigrations: Implement core API handlers for cloud migrations and migration runs (#85407) * implement delete * add auth token encryption * implement token validation * call token validation during migration creation * implement get migration status * implement list migration runs * fix bug * finish parse domain func * fix urls * fix typo * fix encoding and decoding * remove double decryption * add missing slash * fix id returned by create function * inject missing services * finish implementing (as far as I can tell right now) data migration and response handling * comment out broken test, needs a rewrite * add a few final touches * get dashboard migration to work properly * changed runMigration to a POST * swagger * swagger * swagger --------- Co-authored-by: Michael Mandrus <michael.mandrus@grafana.com> Co-authored-by: Leonard Gram <leo@xlson.com> Co-authored-by: Michael Mandrus <41969079+mmandrus@users.noreply.github.com>
This commit is contained in:
co-authored by
Michael Mandrus
Leonard Gram
Michael Mandrus
parent
89638238e5
commit
b885da09da
@@ -9,11 +9,15 @@ import (
|
||||
var (
|
||||
ErrInternalNotImplementedError = errutil.Internal("cloudmigrations.notImplemented", errutil.WithPublicMessage("Internal server error"))
|
||||
ErrFeatureDisabledError = errutil.Internal("cloudmigrations.disabled", errutil.WithPublicMessage("Cloud migrations are disabled on this instance"))
|
||||
ErrMigrationNotFound = errutil.NotFound("cloudmigrations.migrationNotFound", errutil.WithPublicMessage("Migration not found"))
|
||||
ErrMigrationRunNotFound = errutil.NotFound("cloudmigrations.migrationRunNotFound", errutil.WithPublicMessage("Migration run not found"))
|
||||
ErrMigrationNotDeleted = errutil.Internal("cloudmigrations.migrationNotDeleted", errutil.WithPublicMessage("Migration not deleted"))
|
||||
)
|
||||
|
||||
// cloud migration api dtos
|
||||
type CloudMigration struct {
|
||||
ID int64 `json:"id" xorm:"pk autoincr 'id'"`
|
||||
AuthToken string `json:"authToken"`
|
||||
AuthToken string `json:"-"`
|
||||
Stack string `json:"stack"`
|
||||
StackID int `json:"stackID" xorm:"stack_id"`
|
||||
RegionSlug string `json:"regionSlug"`
|
||||
@@ -41,17 +45,16 @@ type MigratedResource struct {
|
||||
}
|
||||
|
||||
type CloudMigrationRun struct {
|
||||
ID int64 `json:"id" xorm:"pk autoincr 'id'"`
|
||||
CloudMigrationUID string `json:"uid" xorm:"cloud_migration_uid"`
|
||||
Resources []MigratedResource `json:"items"`
|
||||
Result MigrationResult `json:"result"`
|
||||
Created time.Time `json:"created"`
|
||||
Updated time.Time `json:"updated"`
|
||||
Finished time.Time `json:"finished"`
|
||||
ID int64 `json:"id" xorm:"pk autoincr 'id'"`
|
||||
CloudMigrationUID string `json:"uid" 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 CloudMigrationRunList struct {
|
||||
Runs []CloudMigrationRun `json:"runs"`
|
||||
Runs []MigrateDataResponseDTO `json:"runs"`
|
||||
}
|
||||
|
||||
// swagger:parameters createMigration
|
||||
@@ -88,6 +91,8 @@ type MigrateDatasourcesResponseDTO struct {
|
||||
DatasourcesMigrated int `json:"datasourcesMigrated"`
|
||||
}
|
||||
|
||||
// access token
|
||||
|
||||
type CreateAccessTokenResponse struct {
|
||||
Token string
|
||||
}
|
||||
@@ -117,3 +122,42 @@ type Base64HGInstance struct {
|
||||
RegionSlug string
|
||||
ClusterSlug string
|
||||
}
|
||||
|
||||
// dtos for cms api
|
||||
|
||||
type MigrateDataType string
|
||||
|
||||
const (
|
||||
DashboardDataType MigrateDataType = "DASHBOARD"
|
||||
DatasourceDataType MigrateDataType = "DATASOURCE"
|
||||
FolderDataType MigrateDataType = "FOLDER"
|
||||
)
|
||||
|
||||
type MigrateDataRequestDTO struct {
|
||||
Items []MigrateDataRequestItemDTO `json:"items"`
|
||||
}
|
||||
|
||||
type MigrateDataRequestItemDTO struct {
|
||||
Type MigrateDataType `json:"type"`
|
||||
RefID string `json:"refId"`
|
||||
Name string `json:"name"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type ItemStatus string
|
||||
|
||||
const (
|
||||
ItemStatusOK ItemStatus = "OK"
|
||||
ItemStatusError ItemStatus = "ERROR"
|
||||
)
|
||||
|
||||
type MigrateDataResponseDTO struct {
|
||||
RunID int64 `json:"id"`
|
||||
Items []MigrateDataResponseItemDTO `json:"items"`
|
||||
}
|
||||
|
||||
type MigrateDataResponseItemDTO struct {
|
||||
RefID string `json:"refId"`
|
||||
Status ItemStatus `json:"status"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user