mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -40,14 +40,16 @@ func RegisterApi(
|
|||||||
// registerEndpoints Registers Endpoints on Grafana Router
|
// registerEndpoints Registers Endpoints on Grafana Router
|
||||||
func (cma *CloudMigrationAPI) registerEndpoints() {
|
func (cma *CloudMigrationAPI) registerEndpoints() {
|
||||||
cma.routeRegister.Group("/api/cloudmigration", func(cloudMigrationRoute routing.RouteRegister) {
|
cma.routeRegister.Group("/api/cloudmigration", func(cloudMigrationRoute routing.RouteRegister) {
|
||||||
// migration
|
cloudMigrationRoute.Get("/migration", routing.Wrap(cma.GetSessionList))
|
||||||
cloudMigrationRoute.Get("/migration", routing.Wrap(cma.GetMigrationList))
|
cloudMigrationRoute.Post("/migration", routing.Wrap(cma.CreateSession))
|
||||||
cloudMigrationRoute.Post("/migration", routing.Wrap(cma.CreateMigration))
|
cloudMigrationRoute.Get("/migration/:uid", routing.Wrap(cma.GetSession))
|
||||||
cloudMigrationRoute.Get("/migration/:uid", routing.Wrap(cma.GetMigration))
|
cloudMigrationRoute.Delete("/migration/:uid", routing.Wrap(cma.DeleteSession))
|
||||||
cloudMigrationRoute.Delete("/migration/:uid", routing.Wrap(cma.DeleteMigration))
|
|
||||||
|
// TODO new APIs for snapshot management to replace these
|
||||||
cloudMigrationRoute.Post("/migration/:uid/run", routing.Wrap(cma.RunMigration))
|
cloudMigrationRoute.Post("/migration/:uid/run", routing.Wrap(cma.RunMigration))
|
||||||
cloudMigrationRoute.Get("/migration/:uid/run", routing.Wrap(cma.GetMigrationRunList))
|
cloudMigrationRoute.Get("/migration/:uid/run", routing.Wrap(cma.GetMigrationRunList))
|
||||||
cloudMigrationRoute.Get("/migration/run/:runUID", routing.Wrap(cma.GetMigrationRun))
|
cloudMigrationRoute.Get("/migration/run/:runUID", routing.Wrap(cma.GetMigrationRun))
|
||||||
|
|
||||||
cloudMigrationRoute.Get("/token", routing.Wrap(cma.GetToken))
|
cloudMigrationRoute.Get("/token", routing.Wrap(cma.GetToken))
|
||||||
cloudMigrationRoute.Post("/token", routing.Wrap(cma.CreateToken))
|
cloudMigrationRoute.Post("/token", routing.Wrap(cma.CreateToken))
|
||||||
cloudMigrationRoute.Delete("/token/:uid", routing.Wrap(cma.DeleteToken))
|
cloudMigrationRoute.Delete("/token/:uid", routing.Wrap(cma.DeleteToken))
|
||||||
@@ -141,84 +143,88 @@ func (cma *CloudMigrationAPI) DeleteToken(c *contextmodel.ReqContext) response.R
|
|||||||
return response.Empty(http.StatusNoContent)
|
return response.Empty(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// swagger:route GET /cloudmigration/migration migrations getMigrationList
|
// swagger:route GET /cloudmigration/migration migrations getSessionList
|
||||||
//
|
//
|
||||||
// Get a list of all cloud migrations.
|
// Get a list of all cloud migration sessions that have been created.
|
||||||
//
|
//
|
||||||
// Responses:
|
// Responses:
|
||||||
// 200: cloudMigrationListResponse
|
// 200: cloudMigrationSessionListResponse
|
||||||
// 401: unauthorisedError
|
// 401: unauthorisedError
|
||||||
// 403: forbiddenError
|
// 403: forbiddenError
|
||||||
// 500: internalServerError
|
// 500: internalServerError
|
||||||
func (cma *CloudMigrationAPI) GetMigrationList(c *contextmodel.ReqContext) response.Response {
|
func (cma *CloudMigrationAPI) GetSessionList(c *contextmodel.ReqContext) response.Response {
|
||||||
ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.GetMigrationList")
|
ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.GetSessionList")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
cloudMigrations, err := cma.cloudMigrationService.GetMigrationList(ctx)
|
sl, err := cma.cloudMigrationService.GetSessionList(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response.ErrOrFallback(http.StatusInternalServerError, "migration list error", err)
|
return response.ErrOrFallback(http.StatusInternalServerError, "session list error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.JSON(http.StatusOK, cloudMigrations)
|
return response.JSON(http.StatusOK, convertSessionListToDTO(*sl))
|
||||||
}
|
}
|
||||||
|
|
||||||
// swagger:route GET /cloudmigration/migration/{uid} migrations getCloudMigration
|
// swagger:route GET /cloudmigration/migration/{uid} migrations getSession
|
||||||
//
|
//
|
||||||
// Get a cloud migration.
|
// Get a cloud migration session by its uid.
|
||||||
//
|
|
||||||
// It returns migrations that has been created.
|
|
||||||
//
|
//
|
||||||
// Responses:
|
// Responses:
|
||||||
// 200: cloudMigrationResponse
|
// 200: cloudMigrationSessionResponse
|
||||||
// 401: unauthorisedError
|
// 401: unauthorisedError
|
||||||
// 403: forbiddenError
|
// 403: forbiddenError
|
||||||
// 500: internalServerError
|
// 500: internalServerError
|
||||||
func (cma *CloudMigrationAPI) GetMigration(c *contextmodel.ReqContext) response.Response {
|
func (cma *CloudMigrationAPI) GetSession(c *contextmodel.ReqContext) response.Response {
|
||||||
ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.GetMigration")
|
ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.GetSession")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
uid := web.Params(c.Req)[":uid"]
|
uid := web.Params(c.Req)[":uid"]
|
||||||
if err := util.ValidateUID(uid); err != nil {
|
if err := util.ValidateUID(uid); err != nil {
|
||||||
return response.Error(http.StatusBadRequest, "invalid migration uid", err)
|
return response.Error(http.StatusBadRequest, "invalid session uid", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cloudMigration, err := cma.cloudMigrationService.GetMigration(ctx, uid)
|
s, err := cma.cloudMigrationService.GetSession(ctx, uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response.ErrOrFallback(http.StatusNotFound, "migration not found", err)
|
return response.ErrOrFallback(http.StatusNotFound, "session not found", err)
|
||||||
}
|
}
|
||||||
return response.JSON(http.StatusOK, cloudMigration)
|
|
||||||
|
return response.JSON(http.StatusOK, CloudMigrationSessionResponseDTO{
|
||||||
|
UID: s.UID,
|
||||||
|
Slug: s.Slug,
|
||||||
|
Created: s.Created,
|
||||||
|
Updated: s.Updated,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// swagger:parameters getCloudMigration
|
// swagger:route POST /cloudmigration/migration migrations createSession
|
||||||
type GetCloudMigrationRequest struct {
|
|
||||||
// UID of a migration
|
|
||||||
//
|
|
||||||
// in: path
|
|
||||||
UID string `json:"uid"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// swagger:route POST /cloudmigration/migration migrations createMigration
|
|
||||||
//
|
//
|
||||||
// Create a migration.
|
// Create a migration session.
|
||||||
//
|
//
|
||||||
// Responses:
|
// Responses:
|
||||||
// 200: cloudMigrationResponse
|
// 200: cloudMigrationSessionResponse
|
||||||
// 401: unauthorisedError
|
// 401: unauthorisedError
|
||||||
// 403: forbiddenError
|
// 403: forbiddenError
|
||||||
// 500: internalServerError
|
// 500: internalServerError
|
||||||
func (cma *CloudMigrationAPI) CreateMigration(c *contextmodel.ReqContext) response.Response {
|
func (cma *CloudMigrationAPI) CreateSession(c *contextmodel.ReqContext) response.Response {
|
||||||
ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.CreateMigration")
|
ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.CreateSession")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
cmd := cloudmigration.CloudMigrationRequest{}
|
cmd := CloudMigrationSessionRequestDTO{}
|
||||||
if err := web.Bind(c.Req, &cmd); err != nil {
|
if err := web.Bind(c.Req, &cmd); err != nil {
|
||||||
return response.ErrOrFallback(http.StatusBadRequest, "bad request data", err)
|
return response.ErrOrFallback(http.StatusBadRequest, "bad request data", err)
|
||||||
}
|
}
|
||||||
cloudMigration, err := cma.cloudMigrationService.CreateMigration(ctx, cmd)
|
s, err := cma.cloudMigrationService.CreateSession(ctx, cloudmigration.CloudMigrationSessionRequest{
|
||||||
|
AuthToken: cmd.AuthToken,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response.ErrOrFallback(http.StatusInternalServerError, "migration creation error", err)
|
return response.ErrOrFallback(http.StatusInternalServerError, "session creation error", err)
|
||||||
}
|
}
|
||||||
return response.JSON(http.StatusOK, cloudMigration)
|
|
||||||
|
return response.JSON(http.StatusOK, CloudMigrationSessionResponseDTO{
|
||||||
|
UID: s.UID,
|
||||||
|
Slug: s.Slug,
|
||||||
|
Created: s.Created,
|
||||||
|
Updated: s.Updated,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// swagger:route POST /cloudmigration/migration/{uid}/run migrations runCloudMigration
|
// swagger:route POST /cloudmigration/migration/{uid}/run migrations runCloudMigration
|
||||||
@@ -246,15 +252,7 @@ func (cma *CloudMigrationAPI) RunMigration(c *contextmodel.ReqContext) response.
|
|||||||
return response.ErrOrFallback(http.StatusInternalServerError, "migration run error", err)
|
return response.ErrOrFallback(http.StatusInternalServerError, "migration run error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.JSON(http.StatusOK, result)
|
return response.JSON(http.StatusOK, convertMigrateDataResponseToDTO(*result))
|
||||||
}
|
|
||||||
|
|
||||||
// swagger:parameters runCloudMigration
|
|
||||||
type RunCloudMigrationRequest struct {
|
|
||||||
// UID of a migration
|
|
||||||
//
|
|
||||||
// in: path
|
|
||||||
UID string `json:"uid"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// swagger:route GET /cloudmigration/migration/run/{runUID} migrations getCloudMigrationRun
|
// swagger:route GET /cloudmigration/migration/run/{runUID} migrations getCloudMigrationRun
|
||||||
@@ -280,21 +278,13 @@ func (cma *CloudMigrationAPI) GetMigrationRun(c *contextmodel.ReqContext) respon
|
|||||||
return response.ErrOrFallback(http.StatusInternalServerError, "migration status error", err)
|
return response.ErrOrFallback(http.StatusInternalServerError, "migration status error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
runResponse, err := migrationStatus.ToResponse()
|
result, err := migrationStatus.GetResult()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cma.log.Error("could not return migration run", "err", err)
|
cma.log.Error("could not return migration run", "err", err)
|
||||||
return response.Error(http.StatusInternalServerError, "migration run get error", err)
|
return response.Error(http.StatusInternalServerError, "migration run get error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.JSON(http.StatusOK, runResponse)
|
return response.JSON(http.StatusOK, convertMigrateDataResponseToDTO(*result))
|
||||||
}
|
|
||||||
|
|
||||||
// swagger:parameters getCloudMigrationRun
|
|
||||||
type GetMigrationRunParams struct {
|
|
||||||
// RunUID of a migration run
|
|
||||||
//
|
|
||||||
// in: path
|
|
||||||
RunUID string `json:"runUID"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// swagger:route GET /cloudmigration/migration/{uid}/run migrations getCloudMigrationRunList
|
// swagger:route GET /cloudmigration/migration/{uid}/run migrations getCloudMigrationRunList
|
||||||
@@ -320,118 +310,36 @@ func (cma *CloudMigrationAPI) GetMigrationRunList(c *contextmodel.ReqContext) re
|
|||||||
return response.ErrOrFallback(http.StatusInternalServerError, "list migration status error", err)
|
return response.ErrOrFallback(http.StatusInternalServerError, "list migration status error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.JSON(http.StatusOK, runList)
|
runs := make([]MigrateDataResponseListDTO, len(runList.Runs))
|
||||||
|
for i := 0; i < len(runList.Runs); i++ {
|
||||||
|
runs[i] = MigrateDataResponseListDTO{runList.Runs[i].RunUID}
|
||||||
|
}
|
||||||
|
return response.JSON(http.StatusOK, SnapshotListDTO{
|
||||||
|
Runs: runs,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// swagger:parameters getCloudMigrationRunList
|
// swagger:route DELETE /cloudmigration/migration/{uid} migrations deleteSession
|
||||||
type GetCloudMigrationRunList struct {
|
|
||||||
// UID of a migration
|
|
||||||
//
|
|
||||||
// in: path
|
|
||||||
UID string `json:"uid"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// swagger:route DELETE /cloudmigration/migration/{uid} migrations deleteCloudMigration
|
|
||||||
//
|
//
|
||||||
// Delete a migration.
|
// Delete a migration session by its uid.
|
||||||
//
|
//
|
||||||
// Responses:
|
// Responses:
|
||||||
// 200
|
// 200
|
||||||
// 401: unauthorisedError
|
// 401: unauthorisedError
|
||||||
// 403: forbiddenError
|
// 403: forbiddenError
|
||||||
// 500: internalServerError
|
// 500: internalServerError
|
||||||
func (cma *CloudMigrationAPI) DeleteMigration(c *contextmodel.ReqContext) response.Response {
|
func (cma *CloudMigrationAPI) DeleteSession(c *contextmodel.ReqContext) response.Response {
|
||||||
ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.DeleteMigration")
|
ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.DeleteSession")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
uid := web.Params(c.Req)[":uid"]
|
uid := web.Params(c.Req)[":uid"]
|
||||||
if err := util.ValidateUID(uid); err != nil {
|
if err := util.ValidateUID(uid); err != nil {
|
||||||
return response.ErrOrFallback(http.StatusBadRequest, "invalid migration uid", err)
|
return response.ErrOrFallback(http.StatusBadRequest, "invalid session uid", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := cma.cloudMigrationService.DeleteMigration(ctx, uid)
|
_, err := cma.cloudMigrationService.DeleteSession(ctx, uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response.ErrOrFallback(http.StatusInternalServerError, "migration delete error", err)
|
return response.ErrOrFallback(http.StatusInternalServerError, "session delete error", err)
|
||||||
}
|
}
|
||||||
return response.Empty(http.StatusOK)
|
return response.Empty(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
// swagger:parameters deleteCloudMigration
|
|
||||||
type DeleteMigrationRequest struct {
|
|
||||||
// UID of a migration
|
|
||||||
//
|
|
||||||
// in: path
|
|
||||||
UID string `json:"uid"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// swagger:response cloudMigrationRunResponse
|
|
||||||
type CloudMigrationRunResponse struct {
|
|
||||||
// in: body
|
|
||||||
Body cloudmigration.MigrateDataResponseDTO
|
|
||||||
}
|
|
||||||
|
|
||||||
// swagger:response cloudMigrationListResponse
|
|
||||||
type CloudMigrationListResponse struct {
|
|
||||||
// in: body
|
|
||||||
Body cloudmigration.CloudMigrationListResponse
|
|
||||||
}
|
|
||||||
|
|
||||||
// swagger:parameters createMigration
|
|
||||||
type CreateMigration struct {
|
|
||||||
// in:body
|
|
||||||
// required:true
|
|
||||||
Body cloudmigration.CloudMigrationRequest
|
|
||||||
}
|
|
||||||
|
|
||||||
// swagger:response cloudMigrationResponse
|
|
||||||
type CloudMigrationResponse struct {
|
|
||||||
// in: body
|
|
||||||
Body cloudmigration.CloudMigrationResponse
|
|
||||||
}
|
|
||||||
|
|
||||||
// swagger:response cloudMigrationRunListResponse
|
|
||||||
type CloudMigrationRunListResponse struct {
|
|
||||||
// in: body
|
|
||||||
Body cloudmigration.CloudMigrationRunList
|
|
||||||
}
|
|
||||||
|
|
||||||
// swagger:parameters getCloudMigrationToken
|
|
||||||
type GetCloudMigrationToken struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
// swagger:response cloudMigrationGetTokenResponse
|
|
||||||
type CloudMigrationGetTokenResponse struct {
|
|
||||||
// in: body
|
|
||||||
Body GetAccessTokenResponseDTO
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetAccessTokenResponseDTO struct {
|
|
||||||
ID string `json:"id"`
|
|
||||||
DisplayName string `json:"displayName"`
|
|
||||||
ExpiresAt string `json:"expiresAt"`
|
|
||||||
FirstUsedAt string `json:"firstUsedAt"`
|
|
||||||
LastUsedAt string `json:"lastUsedAt"`
|
|
||||||
CreatedAt string `json:"createdAt"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// swagger:response cloudMigrationCreateTokenResponse
|
|
||||||
type CloudMigrationCreateTokenResponse struct {
|
|
||||||
// in: body
|
|
||||||
Body CreateAccessTokenResponseDTO
|
|
||||||
}
|
|
||||||
|
|
||||||
type CreateAccessTokenResponseDTO struct {
|
|
||||||
Token string `json:"token"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// swagger:parameters deleteCloudMigrationToken
|
|
||||||
type DeleteCloudMigrationToken struct {
|
|
||||||
// UID of a cloud migration token
|
|
||||||
//
|
|
||||||
// in: path
|
|
||||||
UID string `json:"uid"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// swagger:response cloudMigrationDeleteTokenResponse
|
|
||||||
type CloudMigrationDeleteTokenResponse struct {
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ func TestCloudMigrationAPI_GetMigrationList(t *testing.T) {
|
|||||||
requestUrl: "/api/cloudmigration/migration",
|
requestUrl: "/api/cloudmigration/migration",
|
||||||
basicRole: org.RoleAdmin,
|
basicRole: org.RoleAdmin,
|
||||||
expectedHttpResult: http.StatusOK,
|
expectedHttpResult: http.StatusOK,
|
||||||
expectedBody: `{"migrations":[{"uid":"mock_uid_1","stack":"mock_stack_1","created":"2024-06-05T17:30:40Z","updated":"2024-06-05T17:30:40Z"},{"uid":"mock_uid_2","stack":"mock_stack_2","created":"2024-06-05T17:30:40Z","updated":"2024-06-05T17:30:40Z"}]}`,
|
expectedBody: `{"sessions":[{"uid":"mock_uid_1","slug":"mock_stack_1","created":"2024-06-05T17:30:40Z","updated":"2024-06-05T17:30:40Z"},{"uid":"mock_uid_2","slug":"mock_stack_2","created":"2024-06-05T17:30:40Z","updated":"2024-06-05T17:30:40Z"}]}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "should return 403 if no used is not admin",
|
desc: "should return 403 if no used is not admin",
|
||||||
@@ -216,7 +216,7 @@ func TestCloudMigrationAPI_CreateMigration(t *testing.T) {
|
|||||||
requestBody: `{"auth_token":"asdf"}`,
|
requestBody: `{"auth_token":"asdf"}`,
|
||||||
basicRole: org.RoleAdmin,
|
basicRole: org.RoleAdmin,
|
||||||
expectedHttpResult: http.StatusOK,
|
expectedHttpResult: http.StatusOK,
|
||||||
expectedBody: `{"uid":"fake_uid","stack":"fake_stack","created":"2024-06-05T17:30:40Z","updated":"2024-06-05T17:30:40Z"}`,
|
expectedBody: `{"uid":"fake_uid","slug":"fake_stack","created":"2024-06-05T17:30:40Z","updated":"2024-06-05T17:30:40Z"}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "should return 403 if no used is not admin",
|
desc: "should return 403 if no used is not admin",
|
||||||
|
|||||||
209
pkg/services/cloudmigration/api/dtos.go
Normal file
209
pkg/services/cloudmigration/api/dtos.go
Normal file
@@ -0,0 +1,209 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/services/cloudmigration"
|
||||||
|
)
|
||||||
|
|
||||||
|
// swagger:parameters getCloudMigrationToken
|
||||||
|
type GetCloudMigrationToken struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// swagger:response cloudMigrationGetTokenResponse
|
||||||
|
type CloudMigrationGetTokenResponse struct {
|
||||||
|
// in: body
|
||||||
|
Body GetAccessTokenResponseDTO
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetAccessTokenResponseDTO struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
DisplayName string `json:"displayName"`
|
||||||
|
ExpiresAt string `json:"expiresAt"`
|
||||||
|
FirstUsedAt string `json:"firstUsedAt"`
|
||||||
|
LastUsedAt string `json:"lastUsedAt"`
|
||||||
|
CreatedAt string `json:"createdAt"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// swagger:response cloudMigrationCreateTokenResponse
|
||||||
|
type CloudMigrationCreateTokenResponse struct {
|
||||||
|
// in: body
|
||||||
|
Body CreateAccessTokenResponseDTO
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateAccessTokenResponseDTO struct {
|
||||||
|
Token string `json:"token"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// swagger:parameters deleteCloudMigrationToken
|
||||||
|
type DeleteCloudMigrationToken struct {
|
||||||
|
// UID of a cloud migration token
|
||||||
|
//
|
||||||
|
// in: path
|
||||||
|
UID string `json:"uid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// swagger:response cloudMigrationDeleteTokenResponse
|
||||||
|
type CloudMigrationDeleteTokenResponse struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// swagger:response cloudMigrationSessionListResponse
|
||||||
|
type CloudMigrationSessionListResponse struct {
|
||||||
|
// in: body
|
||||||
|
Body CloudMigrationSessionListResponseDTO
|
||||||
|
}
|
||||||
|
|
||||||
|
type CloudMigrationSessionResponseDTO struct {
|
||||||
|
UID string `json:"uid"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
Created time.Time `json:"created"`
|
||||||
|
Updated time.Time `json:"updated"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CloudMigrationSessionListResponseDTO struct {
|
||||||
|
Sessions []CloudMigrationSessionResponseDTO `json:"sessions"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// swagger:parameters getSession
|
||||||
|
type GetCloudMigrationSessionRequest struct {
|
||||||
|
// UID of a migration session
|
||||||
|
//
|
||||||
|
// in: path
|
||||||
|
UID string `json:"uid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// swagger:response cloudMigrationSessionResponse
|
||||||
|
type CloudMigrationSessionResponse struct {
|
||||||
|
// in: body
|
||||||
|
Body CloudMigrationSessionResponseDTO
|
||||||
|
}
|
||||||
|
|
||||||
|
// swagger:parameters createSession
|
||||||
|
type CreateSession struct {
|
||||||
|
// in:body
|
||||||
|
// required:true
|
||||||
|
Body CloudMigrationSessionRequestDTO
|
||||||
|
}
|
||||||
|
|
||||||
|
type CloudMigrationSessionRequestDTO struct {
|
||||||
|
AuthToken string `json:"authToken"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// swagger:parameters runCloudMigration
|
||||||
|
type RunCloudMigrationRequest struct {
|
||||||
|
// UID of a migration
|
||||||
|
//
|
||||||
|
// in: path
|
||||||
|
UID string `json:"uid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// swagger:response cloudMigrationRunResponse
|
||||||
|
type CloudMigrationRunResponse struct {
|
||||||
|
// in: body
|
||||||
|
Body MigrateDataResponseDTO
|
||||||
|
}
|
||||||
|
|
||||||
|
type MigrateDataResponseDTO struct {
|
||||||
|
RunUID string `json:"uid"`
|
||||||
|
Items []MigrateDataResponseItemDTO `json:"items"`
|
||||||
|
}
|
||||||
|
|
||||||
|
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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// swagger:enum MigrateDataType
|
||||||
|
type MigrateDataType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
DashboardDataType MigrateDataType = "DASHBOARD"
|
||||||
|
DatasourceDataType MigrateDataType = "DATASOURCE"
|
||||||
|
FolderDataType MigrateDataType = "FOLDER"
|
||||||
|
)
|
||||||
|
|
||||||
|
// swagger:enum ItemStatus
|
||||||
|
type ItemStatus string
|
||||||
|
|
||||||
|
const (
|
||||||
|
ItemStatusOK ItemStatus = "OK"
|
||||||
|
ItemStatusError ItemStatus = "ERROR"
|
||||||
|
)
|
||||||
|
|
||||||
|
// swagger:parameters getCloudMigrationRun
|
||||||
|
type GetMigrationRunParams struct {
|
||||||
|
// RunUID of a migration run
|
||||||
|
//
|
||||||
|
// in: path
|
||||||
|
RunUID string `json:"runUID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// swagger:parameters getCloudMigrationRunList
|
||||||
|
type GetCloudMigrationRunList struct {
|
||||||
|
// UID of a migration
|
||||||
|
//
|
||||||
|
// in: path
|
||||||
|
UID string `json:"uid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// swagger:response cloudMigrationRunListResponse
|
||||||
|
type CloudMigrationRunListResponse struct {
|
||||||
|
// in: body
|
||||||
|
Body SnapshotListDTO
|
||||||
|
}
|
||||||
|
|
||||||
|
type SnapshotListDTO struct {
|
||||||
|
Runs []MigrateDataResponseListDTO `json:"runs"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MigrateDataResponseListDTO struct {
|
||||||
|
RunUID string `json:"uid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// swagger:parameters deleteSession
|
||||||
|
type DeleteMigrationSessionRequest struct {
|
||||||
|
// UID of a migration session
|
||||||
|
//
|
||||||
|
// in: path
|
||||||
|
UID string `json:"uid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// utility funcs for converting to/from DTO
|
||||||
|
|
||||||
|
func convertSessionListToDTO(sl cloudmigration.CloudMigrationSessionListResponse) CloudMigrationSessionListResponseDTO {
|
||||||
|
slDTOs := make([]CloudMigrationSessionResponseDTO, len(sl.Sessions))
|
||||||
|
for i := 0; i < len(slDTOs); i++ {
|
||||||
|
s := sl.Sessions[i]
|
||||||
|
slDTOs[i] = CloudMigrationSessionResponseDTO{
|
||||||
|
UID: s.UID,
|
||||||
|
Slug: s.Slug,
|
||||||
|
Created: s.Created,
|
||||||
|
Updated: s.Updated,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return CloudMigrationSessionListResponseDTO{
|
||||||
|
Sessions: slDTOs,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertMigrateDataResponseToDTO(r cloudmigration.MigrateDataResponse) MigrateDataResponseDTO {
|
||||||
|
items := make([]MigrateDataResponseItemDTO, len(r.Items))
|
||||||
|
for i := 0; i < len(r.Items); i++ {
|
||||||
|
item := r.Items[i]
|
||||||
|
items[i] = MigrateDataResponseItemDTO{
|
||||||
|
Type: MigrateDataType(item.Type),
|
||||||
|
RefID: item.RefID,
|
||||||
|
Status: ItemStatus(item.Status),
|
||||||
|
Error: item.Error,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return MigrateDataResponseDTO{
|
||||||
|
RunUID: r.RunUID,
|
||||||
|
Items: items,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,17 +11,16 @@ type Service interface {
|
|||||||
GetToken(ctx context.Context) (gcom.TokenView, error)
|
GetToken(ctx context.Context) (gcom.TokenView, error)
|
||||||
// CreateToken Creates a cloud migration token.
|
// CreateToken Creates a cloud migration token.
|
||||||
CreateToken(ctx context.Context) (CreateAccessTokenResponse, error)
|
CreateToken(ctx context.Context) (CreateAccessTokenResponse, error)
|
||||||
// ValidateToken Sends a request to CMS to test the token.
|
// ValidateToken Sends a request to GMS to test the token.
|
||||||
ValidateToken(ctx context.Context, mig CloudMigration) error
|
ValidateToken(ctx context.Context, mig CloudMigrationSession) error
|
||||||
DeleteToken(ctx context.Context, uid string) error
|
DeleteToken(ctx context.Context, uid string) error
|
||||||
|
|
||||||
CreateMigration(ctx context.Context, req CloudMigrationRequest) (*CloudMigrationResponse, error)
|
CreateSession(ctx context.Context, req CloudMigrationSessionRequest) (*CloudMigrationSessionResponse, error)
|
||||||
GetMigration(ctx context.Context, migUID string) (*CloudMigration, error)
|
GetSession(ctx context.Context, migUID string) (*CloudMigrationSession, error)
|
||||||
DeleteMigration(ctx context.Context, migUID string) (*CloudMigration, error)
|
DeleteSession(ctx context.Context, migUID string) (*CloudMigrationSession, error)
|
||||||
UpdateMigration(ctx context.Context, migUID string, request CloudMigrationRequest) (*CloudMigrationResponse, error)
|
GetSessionList(context.Context) (*CloudMigrationSessionListResponse, error)
|
||||||
GetMigrationList(context.Context) (*CloudMigrationListResponse, error)
|
|
||||||
|
|
||||||
RunMigration(ctx context.Context, migUID string) (*MigrateDataResponseDTO, error)
|
RunMigration(ctx context.Context, migUID string) (*MigrateDataResponse, error)
|
||||||
GetMigrationStatus(ctx context.Context, runUID string) (*CloudMigrationRun, error)
|
GetMigrationStatus(ctx context.Context, runUID string) (*CloudMigrationSnapshot, error)
|
||||||
GetMigrationRunList(ctx context.Context, migUID string) (*CloudMigrationRunList, error)
|
GetMigrationRunList(ctx context.Context, migUID string) (*SnapshotList, error)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||||
"github.com/grafana/grafana/pkg/services/cloudmigration"
|
"github.com/grafana/grafana/pkg/services/cloudmigration"
|
||||||
"github.com/grafana/grafana/pkg/services/cloudmigration/api"
|
"github.com/grafana/grafana/pkg/services/cloudmigration/api"
|
||||||
"github.com/grafana/grafana/pkg/services/cloudmigration/cmsclient"
|
"github.com/grafana/grafana/pkg/services/cloudmigration/gmsclient"
|
||||||
"github.com/grafana/grafana/pkg/services/contexthandler"
|
"github.com/grafana/grafana/pkg/services/contexthandler"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
"github.com/grafana/grafana/pkg/services/datasources"
|
"github.com/grafana/grafana/pkg/services/datasources"
|
||||||
@@ -38,7 +38,7 @@ type Service struct {
|
|||||||
cfg *setting.Cfg
|
cfg *setting.Cfg
|
||||||
|
|
||||||
features featuremgmt.FeatureToggles
|
features featuremgmt.FeatureToggles
|
||||||
cmsClient cmsclient.Client
|
gmsClient gmsclient.Client
|
||||||
|
|
||||||
dsService datasources.DataSourceService
|
dsService datasources.DataSourceService
|
||||||
gcomService gcom.Service
|
gcomService gcom.Service
|
||||||
@@ -95,16 +95,16 @@ func ProvideService(
|
|||||||
s.api = api.RegisterApi(routeRegister, s, tracer)
|
s.api = api.RegisterApi(routeRegister, s, tracer)
|
||||||
|
|
||||||
if !cfg.CloudMigration.IsDeveloperMode {
|
if !cfg.CloudMigration.IsDeveloperMode {
|
||||||
// get CMS path from the config
|
// get GMS path from the config
|
||||||
domain, err := s.parseCloudMigrationConfig()
|
domain, err := s.parseCloudMigrationConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("config parse error: %w", err)
|
return nil, fmt.Errorf("config parse error: %w", err)
|
||||||
}
|
}
|
||||||
s.cmsClient = cmsclient.NewCMSClient(domain)
|
s.gmsClient = gmsclient.NewGMSClient(domain)
|
||||||
|
|
||||||
s.gcomService = gcom.New(gcom.Config{ApiURL: cfg.GrafanaComAPIURL, Token: cfg.CloudMigration.GcomAPIToken})
|
s.gcomService = gcom.New(gcom.Config{ApiURL: cfg.GrafanaComAPIURL, Token: cfg.CloudMigration.GcomAPIToken})
|
||||||
} else {
|
} else {
|
||||||
s.cmsClient = cmsclient.NewInMemoryClient()
|
s.gmsClient = gmsclient.NewInMemoryClient()
|
||||||
s.gcomService = &gcomStub{policies: map[string]gcom.AccessPolicy{}, token: nil}
|
s.gcomService = &gcomStub{policies: map[string]gcom.AccessPolicy{}, token: nil}
|
||||||
s.cfg.StackID = "12345"
|
s.cfg.StackID = "12345"
|
||||||
}
|
}
|
||||||
@@ -242,7 +242,7 @@ func (s *Service) CreateToken(ctx context.Context) (cloudmigration.CreateAccessT
|
|||||||
Instance: cloudmigration.Base64HGInstance{
|
Instance: cloudmigration.Base64HGInstance{
|
||||||
StackID: instance.ID,
|
StackID: instance.ID,
|
||||||
RegionSlug: instance.RegionSlug,
|
RegionSlug: instance.RegionSlug,
|
||||||
ClusterSlug: instance.ClusterSlug, // This should be used for routing to CMS
|
ClusterSlug: instance.ClusterSlug, // This should be used for routing to GMS
|
||||||
Slug: instance.Slug,
|
Slug: instance.Slug,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -275,11 +275,11 @@ func (s *Service) findAccessPolicyByName(ctx context.Context, regionSlug, access
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) ValidateToken(ctx context.Context, cm cloudmigration.CloudMigration) error {
|
func (s *Service) ValidateToken(ctx context.Context, cm cloudmigration.CloudMigrationSession) error {
|
||||||
ctx, span := s.tracer.Start(ctx, "CloudMigrationService.ValidateToken")
|
ctx, span := s.tracer.Start(ctx, "CloudMigrationService.ValidateToken")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
if err := s.cmsClient.ValidateKey(ctx, cm); err != nil {
|
if err := s.gmsClient.ValidateKey(ctx, cm); err != nil {
|
||||||
return fmt.Errorf("validating key: %w", err)
|
return fmt.Errorf("validating key: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,10 +315,10 @@ func (s *Service) DeleteToken(ctx context.Context, tokenID string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) GetMigration(ctx context.Context, uid string) (*cloudmigration.CloudMigration, error) {
|
func (s *Service) GetSession(ctx context.Context, uid string) (*cloudmigration.CloudMigrationSession, error) {
|
||||||
ctx, span := s.tracer.Start(ctx, "CloudMigrationService.GetMigration")
|
ctx, span := s.tracer.Start(ctx, "CloudMigrationService.GetMigration")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
migration, err := s.store.GetMigrationByUID(ctx, uid)
|
migration, err := s.store.GetMigrationSessionByUID(ctx, uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -326,25 +326,25 @@ func (s *Service) GetMigration(ctx context.Context, uid string) (*cloudmigration
|
|||||||
return migration, nil
|
return migration, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) GetMigrationList(ctx context.Context) (*cloudmigration.CloudMigrationListResponse, error) {
|
func (s *Service) GetSessionList(ctx context.Context) (*cloudmigration.CloudMigrationSessionListResponse, error) {
|
||||||
values, err := s.store.GetAllCloudMigrations(ctx)
|
values, err := s.store.GetAllCloudMigrationSessions(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
migrations := make([]cloudmigration.CloudMigrationResponse, 0)
|
migrations := make([]cloudmigration.CloudMigrationSessionResponse, 0)
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
migrations = append(migrations, cloudmigration.CloudMigrationResponse{
|
migrations = append(migrations, cloudmigration.CloudMigrationSessionResponse{
|
||||||
UID: v.UID,
|
UID: v.UID,
|
||||||
Stack: v.Stack,
|
Slug: v.Slug,
|
||||||
Created: v.Created,
|
Created: v.Created,
|
||||||
Updated: v.Updated,
|
Updated: v.Updated,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return &cloudmigration.CloudMigrationListResponse{Migrations: migrations}, nil
|
return &cloudmigration.CloudMigrationSessionListResponse{Sessions: migrations}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) CreateMigration(ctx context.Context, cmd cloudmigration.CloudMigrationRequest) (*cloudmigration.CloudMigrationResponse, error) {
|
func (s *Service) CreateSession(ctx context.Context, cmd cloudmigration.CloudMigrationSessionRequest) (*cloudmigration.CloudMigrationSessionResponse, error) {
|
||||||
ctx, span := s.tracer.Start(ctx, "CloudMigrationService.createMigration")
|
ctx, span := s.tracer.Start(ctx, "CloudMigrationService.createMigration")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
@@ -359,32 +359,27 @@ func (s *Service) CreateMigration(ctx context.Context, cmd cloudmigration.CloudM
|
|||||||
}
|
}
|
||||||
|
|
||||||
migration := token.ToMigration()
|
migration := token.ToMigration()
|
||||||
// validate token against cms before saving
|
// validate token against GMS before saving
|
||||||
if err := s.ValidateToken(ctx, migration); err != nil {
|
if err := s.ValidateToken(ctx, migration); err != nil {
|
||||||
return nil, fmt.Errorf("token validation: %w", err)
|
return nil, fmt.Errorf("token validation: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cm, err := s.store.CreateMigration(ctx, migration)
|
cm, err := s.store.CreateMigrationSession(ctx, migration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error creating migration: %w", err)
|
return nil, fmt.Errorf("error creating migration: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &cloudmigration.CloudMigrationResponse{
|
return &cloudmigration.CloudMigrationSessionResponse{
|
||||||
UID: cm.UID,
|
UID: cm.UID,
|
||||||
Stack: token.Instance.Slug,
|
Slug: token.Instance.Slug,
|
||||||
Created: cm.Created,
|
Created: cm.Created,
|
||||||
Updated: cm.Updated,
|
Updated: cm.Updated,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) UpdateMigration(ctx context.Context, uid string, request cloudmigration.CloudMigrationRequest) (*cloudmigration.CloudMigrationResponse, error) {
|
func (s *Service) RunMigration(ctx context.Context, uid string) (*cloudmigration.MigrateDataResponse, error) {
|
||||||
// TODO: Implement method
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) RunMigration(ctx context.Context, uid string) (*cloudmigration.MigrateDataResponseDTO, error) {
|
|
||||||
// Get migration to read the auth token
|
// Get migration to read the auth token
|
||||||
migration, err := s.GetMigration(ctx, uid)
|
migration, err := s.GetSession(ctx, uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("migration get error: %w", err)
|
return nil, fmt.Errorf("migration get error: %w", err)
|
||||||
}
|
}
|
||||||
@@ -396,8 +391,8 @@ func (s *Service) RunMigration(ctx context.Context, uid string) (*cloudmigration
|
|||||||
return nil, fmt.Errorf("migration data get error: %w", err)
|
return nil, fmt.Errorf("migration data get error: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the cms service
|
// Call the gms service
|
||||||
resp, err := s.cmsClient.MigrateData(ctx, *migration, *request)
|
resp, err := s.gmsClient.MigrateData(ctx, *migration, *request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log.Error("error migrating data: %w", err)
|
s.log.Error("error migrating data: %w", err)
|
||||||
return nil, fmt.Errorf("migrate data error: %w", err)
|
return nil, fmt.Errorf("migrate data error: %w", err)
|
||||||
@@ -411,9 +406,9 @@ func (s *Service) RunMigration(ctx context.Context, uid string) (*cloudmigration
|
|||||||
}
|
}
|
||||||
|
|
||||||
// save the result of the migration
|
// save the result of the migration
|
||||||
runUID, err := s.createMigrationRun(ctx, cloudmigration.CloudMigrationRun{
|
runUID, err := s.createMigrationRun(ctx, cloudmigration.CloudMigrationSnapshot{
|
||||||
CloudMigrationUID: migration.UID,
|
SessionUID: migration.UID,
|
||||||
Result: respData,
|
Result: respData,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.Error(http.StatusInternalServerError, "migration run save error", err)
|
response.Error(http.StatusInternalServerError, "migration run save error", err)
|
||||||
@@ -424,8 +419,8 @@ func (s *Service) RunMigration(ctx context.Context, uid string) (*cloudmigration
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) getMigrationDataJSON(ctx context.Context) (*cloudmigration.MigrateDataRequestDTO, error) {
|
func (s *Service) getMigrationDataJSON(ctx context.Context) (*cloudmigration.MigrateDataRequest, error) {
|
||||||
var migrationDataSlice []cloudmigration.MigrateDataRequestItemDTO
|
var migrationDataSlice []cloudmigration.MigrateDataRequestItem
|
||||||
// Data sources
|
// Data sources
|
||||||
dataSources, err := s.getDataSources(ctx)
|
dataSources, err := s.getDataSources(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -433,7 +428,7 @@ func (s *Service) getMigrationDataJSON(ctx context.Context) (*cloudmigration.Mig
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, ds := range dataSources {
|
for _, ds := range dataSources {
|
||||||
migrationDataSlice = append(migrationDataSlice, cloudmigration.MigrateDataRequestItemDTO{
|
migrationDataSlice = append(migrationDataSlice, cloudmigration.MigrateDataRequestItem{
|
||||||
Type: cloudmigration.DatasourceDataType,
|
Type: cloudmigration.DatasourceDataType,
|
||||||
RefID: ds.UID,
|
RefID: ds.UID,
|
||||||
Name: ds.Name,
|
Name: ds.Name,
|
||||||
@@ -450,7 +445,7 @@ func (s *Service) getMigrationDataJSON(ctx context.Context) (*cloudmigration.Mig
|
|||||||
|
|
||||||
for _, dashboard := range dashboards {
|
for _, dashboard := range dashboards {
|
||||||
dashboard.Data.Del("id")
|
dashboard.Data.Del("id")
|
||||||
migrationDataSlice = append(migrationDataSlice, cloudmigration.MigrateDataRequestItemDTO{
|
migrationDataSlice = append(migrationDataSlice, cloudmigration.MigrateDataRequestItem{
|
||||||
Type: cloudmigration.DashboardDataType,
|
Type: cloudmigration.DashboardDataType,
|
||||||
RefID: dashboard.UID,
|
RefID: dashboard.UID,
|
||||||
Name: dashboard.Title,
|
Name: dashboard.Title,
|
||||||
@@ -466,14 +461,14 @@ func (s *Service) getMigrationDataJSON(ctx context.Context) (*cloudmigration.Mig
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range folders {
|
for _, f := range folders {
|
||||||
migrationDataSlice = append(migrationDataSlice, cloudmigration.MigrateDataRequestItemDTO{
|
migrationDataSlice = append(migrationDataSlice, cloudmigration.MigrateDataRequestItem{
|
||||||
Type: cloudmigration.FolderDataType,
|
Type: cloudmigration.FolderDataType,
|
||||||
RefID: f.UID,
|
RefID: f.UID,
|
||||||
Name: f.Title,
|
Name: f.Title,
|
||||||
Data: f,
|
Data: f,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
migrationData := &cloudmigration.MigrateDataRequestDTO{
|
migrationData := &cloudmigration.MigrateDataRequest{
|
||||||
Items: migrationDataSlice,
|
Items: migrationDataSlice,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,7 +542,7 @@ func (s *Service) getDashboards(ctx context.Context) ([]dashboards.Dashboard, er
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) createMigrationRun(ctx context.Context, cmr cloudmigration.CloudMigrationRun) (string, error) {
|
func (s *Service) createMigrationRun(ctx context.Context, cmr cloudmigration.CloudMigrationSnapshot) (string, error) {
|
||||||
uid, err := s.store.CreateMigrationRun(ctx, cmr)
|
uid, err := s.store.CreateMigrationRun(ctx, cmr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log.Error("Failed to save migration run", "err", err)
|
s.log.Error("Failed to save migration run", "err", err)
|
||||||
@@ -556,7 +551,7 @@ func (s *Service) createMigrationRun(ctx context.Context, cmr cloudmigration.Clo
|
|||||||
return uid, nil
|
return uid, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) GetMigrationStatus(ctx context.Context, runUID string) (*cloudmigration.CloudMigrationRun, error) {
|
func (s *Service) GetMigrationStatus(ctx context.Context, runUID string) (*cloudmigration.CloudMigrationSnapshot, error) {
|
||||||
cmr, err := s.store.GetMigrationStatus(ctx, runUID)
|
cmr, err := s.store.GetMigrationStatus(ctx, runUID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("retrieving migration status from db: %w", err)
|
return nil, fmt.Errorf("retrieving migration status from db: %w", err)
|
||||||
@@ -564,15 +559,15 @@ func (s *Service) GetMigrationStatus(ctx context.Context, runUID string) (*cloud
|
|||||||
return cmr, nil
|
return cmr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) GetMigrationRunList(ctx context.Context, migUID string) (*cloudmigration.CloudMigrationRunList, error) {
|
func (s *Service) GetMigrationRunList(ctx context.Context, migUID string) (*cloudmigration.SnapshotList, error) {
|
||||||
runs, err := s.store.GetMigrationStatusList(ctx, migUID)
|
runs, err := s.store.GetMigrationStatusList(ctx, migUID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("retrieving migration statuses from db: %w", err)
|
return nil, fmt.Errorf("retrieving migration statuses from db: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
runList := &cloudmigration.CloudMigrationRunList{Runs: []cloudmigration.MigrateDataResponseListDTO{}}
|
runList := &cloudmigration.SnapshotList{Runs: []cloudmigration.MigrateDataResponseList{}}
|
||||||
for _, s := range runs {
|
for _, s := range runs {
|
||||||
runList.Runs = append(runList.Runs, cloudmigration.MigrateDataResponseListDTO{
|
runList.Runs = append(runList.Runs, cloudmigration.MigrateDataResponseList{
|
||||||
RunUID: s.UID,
|
RunUID: s.UID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -580,8 +575,8 @@ func (s *Service) GetMigrationRunList(ctx context.Context, migUID string) (*clou
|
|||||||
return runList, nil
|
return runList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) DeleteMigration(ctx context.Context, uid string) (*cloudmigration.CloudMigration, error) {
|
func (s *Service) DeleteSession(ctx context.Context, uid string) (*cloudmigration.CloudMigrationSession, error) {
|
||||||
c, err := s.store.DeleteMigration(ctx, uid)
|
c, err := s.store.DeleteMigrationSessionByUID(ctx, uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c, fmt.Errorf("deleting migration from db: %w", err)
|
return c, fmt.Errorf("deleting migration from db: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,42 +24,38 @@ func (s *NoopServiceImpl) DeleteToken(ctx context.Context, uid string) error {
|
|||||||
return cloudmigration.ErrFeatureDisabledError
|
return cloudmigration.ErrFeatureDisabledError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *NoopServiceImpl) ValidateToken(ctx context.Context, cm cloudmigration.CloudMigration) error {
|
func (s *NoopServiceImpl) ValidateToken(ctx context.Context, cm cloudmigration.CloudMigrationSession) error {
|
||||||
return cloudmigration.ErrFeatureDisabledError
|
return cloudmigration.ErrFeatureDisabledError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *NoopServiceImpl) GetMigration(ctx context.Context, uid string) (*cloudmigration.CloudMigration, error) {
|
func (s *NoopServiceImpl) GetSession(ctx context.Context, uid string) (*cloudmigration.CloudMigrationSession, error) {
|
||||||
return nil, cloudmigration.ErrFeatureDisabledError
|
return nil, cloudmigration.ErrFeatureDisabledError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *NoopServiceImpl) GetMigrationList(ctx context.Context) (*cloudmigration.CloudMigrationListResponse, error) {
|
func (s *NoopServiceImpl) GetSessionList(ctx context.Context) (*cloudmigration.CloudMigrationSessionListResponse, error) {
|
||||||
return nil, cloudmigration.ErrFeatureDisabledError
|
return nil, cloudmigration.ErrFeatureDisabledError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *NoopServiceImpl) CreateMigration(ctx context.Context, cm cloudmigration.CloudMigrationRequest) (*cloudmigration.CloudMigrationResponse, error) {
|
func (s *NoopServiceImpl) CreateSession(ctx context.Context, cm cloudmigration.CloudMigrationSessionRequest) (*cloudmigration.CloudMigrationSessionResponse, error) {
|
||||||
return nil, cloudmigration.ErrFeatureDisabledError
|
return nil, cloudmigration.ErrFeatureDisabledError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *NoopServiceImpl) UpdateMigration(ctx context.Context, uid string, cm cloudmigration.CloudMigrationRequest) (*cloudmigration.CloudMigrationResponse, error) {
|
func (s *NoopServiceImpl) GetMigrationStatus(ctx context.Context, runUID string) (*cloudmigration.CloudMigrationSnapshot, error) {
|
||||||
return nil, cloudmigration.ErrFeatureDisabledError
|
return nil, cloudmigration.ErrFeatureDisabledError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *NoopServiceImpl) GetMigrationStatus(ctx context.Context, runUID string) (*cloudmigration.CloudMigrationRun, error) {
|
func (s *NoopServiceImpl) GetMigrationRunList(ctx context.Context, uid string) (*cloudmigration.SnapshotList, error) {
|
||||||
return nil, cloudmigration.ErrFeatureDisabledError
|
return nil, cloudmigration.ErrFeatureDisabledError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *NoopServiceImpl) GetMigrationRunList(ctx context.Context, uid string) (*cloudmigration.CloudMigrationRunList, error) {
|
func (s *NoopServiceImpl) DeleteSession(ctx context.Context, uid string) (*cloudmigration.CloudMigrationSession, error) {
|
||||||
return nil, cloudmigration.ErrFeatureDisabledError
|
return nil, cloudmigration.ErrFeatureDisabledError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *NoopServiceImpl) DeleteMigration(ctx context.Context, uid string) (*cloudmigration.CloudMigration, error) {
|
func (s *NoopServiceImpl) CreateMigrationRun(context.Context, cloudmigration.CloudMigrationSnapshot) (string, error) {
|
||||||
return nil, cloudmigration.ErrFeatureDisabledError
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *NoopServiceImpl) CreateMigrationRun(context.Context, cloudmigration.CloudMigrationRun) (string, error) {
|
|
||||||
return "", cloudmigration.ErrInternalNotImplementedError
|
return "", cloudmigration.ErrInternalNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *NoopServiceImpl) RunMigration(context.Context, string) (*cloudmigration.MigrateDataResponseDTO, error) {
|
func (s *NoopServiceImpl) RunMigration(context.Context, string) (*cloudmigration.MigrateDataResponse, error) {
|
||||||
return nil, cloudmigration.ErrFeatureDisabledError
|
return nil, cloudmigration.ErrFeatureDisabledError
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func Test_CreateGetAndDeleteToken(t *testing.T) {
|
|||||||
_, err = s.GetToken(context.Background())
|
_, err = s.GetToken(context.Background())
|
||||||
assert.ErrorIs(t, cloudmigration.ErrTokenNotFound, err)
|
assert.ErrorIs(t, cloudmigration.ErrTokenNotFound, err)
|
||||||
|
|
||||||
cm := cloudmigration.CloudMigration{}
|
cm := cloudmigration.CloudMigrationSession{}
|
||||||
err = s.ValidateToken(context.Background(), cm)
|
err = s.ValidateToken(context.Background(), cm)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
@@ -62,27 +62,27 @@ func Test_CreateGetRunMigrationsAndRuns(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotEmpty(t, createTokenResp.Token)
|
assert.NotEmpty(t, createTokenResp.Token)
|
||||||
|
|
||||||
cmd := cloudmigration.CloudMigrationRequest{
|
cmd := cloudmigration.CloudMigrationSessionRequest{
|
||||||
AuthToken: createTokenResp.Token,
|
AuthToken: createTokenResp.Token,
|
||||||
}
|
}
|
||||||
|
|
||||||
createResp, err := s.CreateMigration(context.Background(), cmd)
|
createResp, err := s.CreateSession(context.Background(), cmd)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotEmpty(t, createResp.UID)
|
require.NotEmpty(t, createResp.UID)
|
||||||
require.NotEmpty(t, createResp.Stack)
|
require.NotEmpty(t, createResp.Slug)
|
||||||
|
|
||||||
getMigResp, err := s.GetMigration(context.Background(), createResp.UID)
|
getMigResp, err := s.GetSession(context.Background(), createResp.UID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, getMigResp)
|
require.NotNil(t, getMigResp)
|
||||||
require.Equal(t, createResp.UID, getMigResp.UID)
|
require.Equal(t, createResp.UID, getMigResp.UID)
|
||||||
require.Equal(t, createResp.Stack, getMigResp.Stack)
|
require.Equal(t, createResp.Slug, getMigResp.Slug)
|
||||||
|
|
||||||
listResp, err := s.GetMigrationList(context.Background())
|
listResp, err := s.GetSessionList(context.Background())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, listResp)
|
require.NotNil(t, listResp)
|
||||||
require.Equal(t, 1, len(listResp.Migrations))
|
require.Equal(t, 1, len(listResp.Sessions))
|
||||||
require.Equal(t, createResp.UID, listResp.Migrations[0].UID)
|
require.Equal(t, createResp.UID, listResp.Sessions[0].UID)
|
||||||
require.Equal(t, createResp.Stack, listResp.Migrations[0].Stack)
|
require.Equal(t, createResp.Slug, listResp.Sessions[0].Slug)
|
||||||
|
|
||||||
runResp, err := s.RunMigration(ctxWithSignedInUser(), createResp.UID)
|
runResp, err := s.RunMigration(ctxWithSignedInUser(), createResp.UID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@@ -104,7 +104,7 @@ func Test_CreateGetRunMigrationsAndRuns(t *testing.T) {
|
|||||||
require.Equal(t, 1, len(listRunResp.Runs))
|
require.Equal(t, 1, len(listRunResp.Runs))
|
||||||
require.Equal(t, runResp.RunUID, listRunResp.Runs[0].RunUID)
|
require.Equal(t, runResp.RunUID, listRunResp.Runs[0].RunUID)
|
||||||
|
|
||||||
delMigResp, err := s.DeleteMigration(context.Background(), createResp.UID)
|
delMigResp, err := s.DeleteSession(context.Background(), createResp.UID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, createResp.UID, delMigResp.UID)
|
require.NotNil(t, createResp.UID, delMigResp.UID)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func (m FakeServiceImpl) CreateToken(_ context.Context) (cloudmigration.CreateAc
|
|||||||
return cloudmigration.CreateAccessTokenResponse{Token: "mock_token"}, nil
|
return cloudmigration.CreateAccessTokenResponse{Token: "mock_token"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m FakeServiceImpl) ValidateToken(ctx context.Context, migration cloudmigration.CloudMigration) error {
|
func (m FakeServiceImpl) ValidateToken(ctx context.Context, migration cloudmigration.CloudMigrationSession) error {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,49 +44,45 @@ func (m FakeServiceImpl) DeleteToken(_ context.Context, _ string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m FakeServiceImpl) CreateMigration(_ context.Context, _ cloudmigration.CloudMigrationRequest) (*cloudmigration.CloudMigrationResponse, error) {
|
func (m FakeServiceImpl) CreateSession(_ context.Context, _ cloudmigration.CloudMigrationSessionRequest) (*cloudmigration.CloudMigrationSessionResponse, error) {
|
||||||
if m.ReturnError {
|
if m.ReturnError {
|
||||||
return nil, fmt.Errorf("mock error")
|
return nil, fmt.Errorf("mock error")
|
||||||
}
|
}
|
||||||
return &cloudmigration.CloudMigrationResponse{
|
return &cloudmigration.CloudMigrationSessionResponse{
|
||||||
UID: "fake_uid",
|
UID: "fake_uid",
|
||||||
Stack: "fake_stack",
|
Slug: "fake_stack",
|
||||||
Created: fixedDate,
|
Created: fixedDate,
|
||||||
Updated: fixedDate,
|
Updated: fixedDate,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m FakeServiceImpl) GetMigration(_ context.Context, _ string) (*cloudmigration.CloudMigration, error) {
|
func (m FakeServiceImpl) GetSession(_ context.Context, _ string) (*cloudmigration.CloudMigrationSession, error) {
|
||||||
if m.ReturnError {
|
if m.ReturnError {
|
||||||
return nil, fmt.Errorf("mock error")
|
return nil, fmt.Errorf("mock error")
|
||||||
}
|
}
|
||||||
return &cloudmigration.CloudMigration{UID: "fake"}, nil
|
return &cloudmigration.CloudMigrationSession{UID: "fake"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m FakeServiceImpl) DeleteMigration(_ context.Context, _ string) (*cloudmigration.CloudMigration, error) {
|
func (m FakeServiceImpl) DeleteSession(_ context.Context, _ string) (*cloudmigration.CloudMigrationSession, error) {
|
||||||
if m.ReturnError {
|
if m.ReturnError {
|
||||||
return nil, fmt.Errorf("mock error")
|
return nil, fmt.Errorf("mock error")
|
||||||
}
|
}
|
||||||
return &cloudmigration.CloudMigration{UID: "fake"}, nil
|
return &cloudmigration.CloudMigrationSession{UID: "fake"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m FakeServiceImpl) UpdateMigration(ctx context.Context, uid string, request cloudmigration.CloudMigrationRequest) (*cloudmigration.CloudMigrationResponse, error) {
|
func (m FakeServiceImpl) GetSessionList(_ context.Context) (*cloudmigration.CloudMigrationSessionListResponse, error) {
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m FakeServiceImpl) GetMigrationList(_ context.Context) (*cloudmigration.CloudMigrationListResponse, error) {
|
|
||||||
if m.ReturnError {
|
if m.ReturnError {
|
||||||
return nil, fmt.Errorf("mock error")
|
return nil, fmt.Errorf("mock error")
|
||||||
}
|
}
|
||||||
return &cloudmigration.CloudMigrationListResponse{
|
return &cloudmigration.CloudMigrationSessionListResponse{
|
||||||
Migrations: []cloudmigration.CloudMigrationResponse{
|
Sessions: []cloudmigration.CloudMigrationSessionResponse{
|
||||||
{UID: "mock_uid_1", Stack: "mock_stack_1", Created: fixedDate, Updated: fixedDate},
|
{UID: "mock_uid_1", Slug: "mock_stack_1", Created: fixedDate, Updated: fixedDate},
|
||||||
{UID: "mock_uid_2", Stack: "mock_stack_2", Created: fixedDate, Updated: fixedDate},
|
{UID: "mock_uid_2", Slug: "mock_stack_2", Created: fixedDate, Updated: fixedDate},
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m FakeServiceImpl) RunMigration(_ context.Context, _ string) (*cloudmigration.MigrateDataResponseDTO, error) {
|
func (m FakeServiceImpl) RunMigration(_ context.Context, _ string) (*cloudmigration.MigrateDataResponse, error) {
|
||||||
if m.ReturnError {
|
if m.ReturnError {
|
||||||
return nil, fmt.Errorf("mock error")
|
return nil, fmt.Errorf("mock error")
|
||||||
}
|
}
|
||||||
@@ -94,20 +90,20 @@ func (m FakeServiceImpl) RunMigration(_ context.Context, _ string) (*cloudmigrat
|
|||||||
return &r, nil
|
return &r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func fakeMigrateDataResponseDTO() cloudmigration.MigrateDataResponseDTO {
|
func fakeMigrateDataResponseDTO() cloudmigration.MigrateDataResponse {
|
||||||
return cloudmigration.MigrateDataResponseDTO{
|
return cloudmigration.MigrateDataResponse{
|
||||||
RunUID: "fake_uid",
|
RunUID: "fake_uid",
|
||||||
Items: []cloudmigration.MigrateDataResponseItemDTO{
|
Items: []cloudmigration.MigrateDataResponseItem{
|
||||||
{Type: "type", RefID: "make_refid", Status: "ok", Error: "none"},
|
{Type: "type", RefID: "make_refid", Status: "ok", Error: "none"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m FakeServiceImpl) CreateMigrationRun(ctx context.Context, run cloudmigration.CloudMigrationRun) (string, error) {
|
func (m FakeServiceImpl) CreateMigrationRun(ctx context.Context, run cloudmigration.CloudMigrationSnapshot) (string, error) {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m FakeServiceImpl) GetMigrationStatus(_ context.Context, _ string) (*cloudmigration.CloudMigrationRun, error) {
|
func (m FakeServiceImpl) GetMigrationStatus(_ context.Context, _ string) (*cloudmigration.CloudMigrationSnapshot, error) {
|
||||||
if m.ReturnError {
|
if m.ReturnError {
|
||||||
return nil, fmt.Errorf("mock error")
|
return nil, fmt.Errorf("mock error")
|
||||||
}
|
}
|
||||||
@@ -115,23 +111,23 @@ func (m FakeServiceImpl) GetMigrationStatus(_ context.Context, _ string) (*cloud
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &cloudmigration.CloudMigrationRun{
|
return &cloudmigration.CloudMigrationSnapshot{
|
||||||
ID: 0,
|
ID: 0,
|
||||||
UID: "fake_uid",
|
UID: "fake_uid",
|
||||||
CloudMigrationUID: "fake_mig_uid",
|
SessionUID: "fake_mig_uid",
|
||||||
Result: result,
|
Result: result,
|
||||||
Created: fixedDate,
|
Created: fixedDate,
|
||||||
Updated: fixedDate,
|
Updated: fixedDate,
|
||||||
Finished: fixedDate,
|
Finished: fixedDate,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m FakeServiceImpl) GetMigrationRunList(_ context.Context, _ string) (*cloudmigration.CloudMigrationRunList, error) {
|
func (m FakeServiceImpl) GetMigrationRunList(_ context.Context, _ string) (*cloudmigration.SnapshotList, error) {
|
||||||
if m.ReturnError {
|
if m.ReturnError {
|
||||||
return nil, fmt.Errorf("mock error")
|
return nil, fmt.Errorf("mock error")
|
||||||
}
|
}
|
||||||
return &cloudmigration.CloudMigrationRunList{
|
return &cloudmigration.SnapshotList{
|
||||||
Runs: []cloudmigration.MigrateDataResponseListDTO{
|
Runs: []cloudmigration.MigrateDataResponseList{
|
||||||
{RunUID: "fake_run_uid_1"},
|
{RunUID: "fake_run_uid_1"},
|
||||||
{RunUID: "fake_run_uid_2"},
|
{RunUID: "fake_run_uid_2"},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type store interface {
|
type store interface {
|
||||||
CreateMigration(ctx context.Context, token cloudmigration.CloudMigration) (*cloudmigration.CloudMigration, error)
|
CreateMigrationSession(ctx context.Context, session cloudmigration.CloudMigrationSession) (*cloudmigration.CloudMigrationSession, error)
|
||||||
GetMigrationByUID(ctx context.Context, uid string) (*cloudmigration.CloudMigration, error)
|
GetMigrationSessionByUID(ctx context.Context, uid string) (*cloudmigration.CloudMigrationSession, error)
|
||||||
GetAllCloudMigrations(ctx context.Context) ([]*cloudmigration.CloudMigration, error)
|
GetAllCloudMigrationSessions(ctx context.Context) ([]*cloudmigration.CloudMigrationSession, error)
|
||||||
DeleteMigration(ctx context.Context, uid string) (*cloudmigration.CloudMigration, error)
|
DeleteMigrationSessionByUID(ctx context.Context, uid string) (*cloudmigration.CloudMigrationSession, error)
|
||||||
|
|
||||||
CreateMigrationRun(ctx context.Context, cmr cloudmigration.CloudMigrationRun) (string, error)
|
CreateMigrationRun(ctx context.Context, cmr cloudmigration.CloudMigrationSnapshot) (string, error)
|
||||||
GetMigrationStatus(ctx context.Context, cmrUID string) (*cloudmigration.CloudMigrationRun, error)
|
GetMigrationStatus(ctx context.Context, cmrUID string) (*cloudmigration.CloudMigrationSnapshot, error)
|
||||||
GetMigrationStatusList(ctx context.Context, migrationUID string) ([]*cloudmigration.CloudMigrationRun, error)
|
GetMigrationStatusList(ctx context.Context, migrationUID string) ([]*cloudmigration.CloudMigrationSnapshot, error)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ type sqlStore struct {
|
|||||||
secretsService secrets.Service
|
secretsService secrets.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *sqlStore) GetMigrationByUID(ctx context.Context, uid string) (*cloudmigration.CloudMigration, error) {
|
func (ss *sqlStore) GetMigrationSessionByUID(ctx context.Context, uid string) (*cloudmigration.CloudMigrationSession, error) {
|
||||||
var cm cloudmigration.CloudMigration
|
var cm cloudmigration.CloudMigrationSession
|
||||||
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
||||||
exist, err := sess.Where("uid=?", uid).Get(&cm)
|
exist, err := sess.Where("uid=?", uid).Get(&cm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -40,7 +40,7 @@ func (ss *sqlStore) GetMigrationByUID(ctx context.Context, uid string) (*cloudmi
|
|||||||
return &cm, err
|
return &cm, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *sqlStore) CreateMigrationRun(ctx context.Context, cmr cloudmigration.CloudMigrationRun) (string, error) {
|
func (ss *sqlStore) CreateMigrationRun(ctx context.Context, cmr cloudmigration.CloudMigrationSnapshot) (string, error) {
|
||||||
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
||||||
cmr.Created = time.Now()
|
cmr.Created = time.Now()
|
||||||
cmr.Updated = time.Now()
|
cmr.Updated = time.Now()
|
||||||
@@ -56,7 +56,7 @@ func (ss *sqlStore) CreateMigrationRun(ctx context.Context, cmr cloudmigration.C
|
|||||||
return cmr.UID, nil
|
return cmr.UID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *sqlStore) CreateMigration(ctx context.Context, migration cloudmigration.CloudMigration) (*cloudmigration.CloudMigration, error) {
|
func (ss *sqlStore) CreateMigrationSession(ctx context.Context, migration cloudmigration.CloudMigrationSession) (*cloudmigration.CloudMigrationSession, error) {
|
||||||
if err := ss.encryptToken(ctx, &migration); err != nil {
|
if err := ss.encryptToken(ctx, &migration); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -78,8 +78,8 @@ func (ss *sqlStore) CreateMigration(ctx context.Context, migration cloudmigratio
|
|||||||
return &migration, nil
|
return &migration, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *sqlStore) GetAllCloudMigrations(ctx context.Context) ([]*cloudmigration.CloudMigration, error) {
|
func (ss *sqlStore) GetAllCloudMigrationSessions(ctx context.Context) ([]*cloudmigration.CloudMigrationSession, error) {
|
||||||
var migrations = make([]*cloudmigration.CloudMigration, 0)
|
var migrations = make([]*cloudmigration.CloudMigrationSession, 0)
|
||||||
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error { return sess.Find(&migrations) })
|
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error { return sess.Find(&migrations) })
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -95,8 +95,8 @@ func (ss *sqlStore) GetAllCloudMigrations(ctx context.Context) ([]*cloudmigratio
|
|||||||
return migrations, nil
|
return migrations, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *sqlStore) DeleteMigration(ctx context.Context, uid string) (*cloudmigration.CloudMigration, error) {
|
func (ss *sqlStore) DeleteMigrationSessionByUID(ctx context.Context, uid string) (*cloudmigration.CloudMigrationSession, error) {
|
||||||
var c cloudmigration.CloudMigration
|
var c cloudmigration.CloudMigrationSession
|
||||||
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
||||||
exist, err := sess.Where("uid=?", uid).Get(&c)
|
exist, err := sess.Where("uid=?", uid).Get(&c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -106,7 +106,7 @@ func (ss *sqlStore) DeleteMigration(ctx context.Context, uid string) (*cloudmigr
|
|||||||
return cloudmigration.ErrMigrationNotFound
|
return cloudmigration.ErrMigrationNotFound
|
||||||
}
|
}
|
||||||
id := c.ID
|
id := c.ID
|
||||||
affected, err := sess.Delete(&cloudmigration.CloudMigration{
|
affected, err := sess.Delete(&cloudmigration.CloudMigrationSession{
|
||||||
ID: id,
|
ID: id,
|
||||||
})
|
})
|
||||||
if affected == 0 {
|
if affected == 0 {
|
||||||
@@ -118,8 +118,8 @@ func (ss *sqlStore) DeleteMigration(ctx context.Context, uid string) (*cloudmigr
|
|||||||
return &c, err
|
return &c, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *sqlStore) GetMigrationStatus(ctx context.Context, cmrUID string) (*cloudmigration.CloudMigrationRun, error) {
|
func (ss *sqlStore) GetMigrationStatus(ctx context.Context, cmrUID string) (*cloudmigration.CloudMigrationSnapshot, error) {
|
||||||
var c cloudmigration.CloudMigrationRun
|
var c cloudmigration.CloudMigrationSnapshot
|
||||||
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
||||||
exist, err := sess.Where("uid=?", cmrUID).Get(&c)
|
exist, err := sess.Where("uid=?", cmrUID).Get(&c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -133,11 +133,11 @@ func (ss *sqlStore) GetMigrationStatus(ctx context.Context, cmrUID string) (*clo
|
|||||||
return &c, err
|
return &c, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *sqlStore) GetMigrationStatusList(ctx context.Context, migrationUID string) ([]*cloudmigration.CloudMigrationRun, error) {
|
func (ss *sqlStore) GetMigrationStatusList(ctx context.Context, migrationUID string) ([]*cloudmigration.CloudMigrationSnapshot, error) {
|
||||||
var runs = make([]*cloudmigration.CloudMigrationRun, 0)
|
var runs = make([]*cloudmigration.CloudMigrationSnapshot, 0)
|
||||||
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
||||||
return sess.Find(&runs, &cloudmigration.CloudMigrationRun{
|
return sess.Find(&runs, &cloudmigration.CloudMigrationSnapshot{
|
||||||
CloudMigrationUID: migrationUID,
|
SessionUID: migrationUID,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -146,7 +146,7 @@ func (ss *sqlStore) GetMigrationStatusList(ctx context.Context, migrationUID str
|
|||||||
return runs, nil
|
return runs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *sqlStore) encryptToken(ctx context.Context, cm *cloudmigration.CloudMigration) error {
|
func (ss *sqlStore) encryptToken(ctx context.Context, cm *cloudmigration.CloudMigrationSession) error {
|
||||||
s, err := ss.secretsService.Encrypt(ctx, []byte(cm.AuthToken), secrets.WithoutScope())
|
s, err := ss.secretsService.Encrypt(ctx, []byte(cm.AuthToken), secrets.WithoutScope())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("encrypting auth token: %w", err)
|
return fmt.Errorf("encrypting auth token: %w", err)
|
||||||
@@ -157,7 +157,7 @@ func (ss *sqlStore) encryptToken(ctx context.Context, cm *cloudmigration.CloudMi
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *sqlStore) decryptToken(ctx context.Context, cm *cloudmigration.CloudMigration) error {
|
func (ss *sqlStore) decryptToken(ctx context.Context, cm *cloudmigration.CloudMigrationSession) error {
|
||||||
decoded, err := base64.StdEncoding.DecodeString(cm.AuthToken)
|
decoded, err := base64.StdEncoding.DecodeString(cm.AuthToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("token could not be decoded")
|
return fmt.Errorf("token could not be decoded")
|
||||||
|
|||||||
@@ -22,20 +22,20 @@ func Test_GetAllCloudMigrations(t *testing.T) {
|
|||||||
_, s := setUpTest(t)
|
_, s := setUpTest(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
t.Run("get all cloud_migrations", func(t *testing.T) {
|
t.Run("get all cloud_migration_session entries", func(t *testing.T) {
|
||||||
value, err := s.GetAllCloudMigrations(ctx)
|
value, err := s.GetAllCloudMigrationSessions(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, 3, len(value))
|
require.Equal(t, 3, len(value))
|
||||||
for _, m := range value {
|
for _, m := range value {
|
||||||
switch m.ID {
|
switch m.ID {
|
||||||
case 1:
|
case 1:
|
||||||
require.Equal(t, "11111", m.Stack)
|
require.Equal(t, "11111", m.Slug)
|
||||||
require.Equal(t, "12345", m.AuthToken)
|
require.Equal(t, "12345", m.AuthToken)
|
||||||
case 2:
|
case 2:
|
||||||
require.Equal(t, "22222", m.Stack)
|
require.Equal(t, "22222", m.Slug)
|
||||||
require.Equal(t, "6789", m.AuthToken)
|
require.Equal(t, "6789", m.AuthToken)
|
||||||
case 3:
|
case 3:
|
||||||
require.Equal(t, "33333", m.Stack)
|
require.Equal(t, "33333", m.Slug)
|
||||||
require.Equal(t, "777", m.AuthToken)
|
require.Equal(t, "777", m.AuthToken)
|
||||||
default:
|
default:
|
||||||
require.Fail(t, "ID value not expected: "+strconv.FormatInt(m.ID, 10))
|
require.Fail(t, "ID value not expected: "+strconv.FormatInt(m.ID, 10))
|
||||||
@@ -49,24 +49,24 @@ func Test_CreateMigration(t *testing.T) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
t.Run("creates migrations and reads it from the db", func(t *testing.T) {
|
t.Run("creates migrations and reads it from the db", func(t *testing.T) {
|
||||||
cm := cloudmigration.CloudMigration{
|
cm := cloudmigration.CloudMigrationSession{
|
||||||
AuthToken: encodeToken("token"),
|
AuthToken: encodeToken("token"),
|
||||||
Stack: "fake_stack",
|
Slug: "fake_stack",
|
||||||
StackID: 1234,
|
StackID: 1234,
|
||||||
RegionSlug: "fake_slug",
|
RegionSlug: "fake_slug",
|
||||||
ClusterSlug: "fake_cluster_slug",
|
ClusterSlug: "fake_cluster_slug",
|
||||||
}
|
}
|
||||||
mig, err := s.CreateMigration(ctx, cm)
|
mig, err := s.CreateMigrationSession(ctx, cm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotEmpty(t, mig.ID)
|
require.NotEmpty(t, mig.ID)
|
||||||
require.NotEmpty(t, mig.UID)
|
require.NotEmpty(t, mig.UID)
|
||||||
|
|
||||||
getRes, err := s.GetMigrationByUID(ctx, mig.UID)
|
getRes, err := s.GetMigrationSessionByUID(ctx, mig.UID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, mig.ID, getRes.ID)
|
require.Equal(t, mig.ID, getRes.ID)
|
||||||
require.Equal(t, mig.UID, getRes.UID)
|
require.Equal(t, mig.UID, getRes.UID)
|
||||||
require.Equal(t, cm.AuthToken, getRes.AuthToken)
|
require.Equal(t, cm.AuthToken, getRes.AuthToken)
|
||||||
require.Equal(t, cm.Stack, getRes.Stack)
|
require.Equal(t, cm.Slug, getRes.Slug)
|
||||||
require.Equal(t, cm.StackID, getRes.StackID)
|
require.Equal(t, cm.StackID, getRes.StackID)
|
||||||
require.Equal(t, cm.RegionSlug, getRes.RegionSlug)
|
require.Equal(t, cm.RegionSlug, getRes.RegionSlug)
|
||||||
require.Equal(t, cm.ClusterSlug, getRes.ClusterSlug)
|
require.Equal(t, cm.ClusterSlug, getRes.ClusterSlug)
|
||||||
@@ -76,15 +76,15 @@ func Test_CreateMigration(t *testing.T) {
|
|||||||
func Test_GetMigrationByUID(t *testing.T) {
|
func Test_GetMigrationByUID(t *testing.T) {
|
||||||
_, s := setUpTest(t)
|
_, s := setUpTest(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
t.Run("find migration by uid", func(t *testing.T) {
|
t.Run("find session by uid", func(t *testing.T) {
|
||||||
uid := "qwerty"
|
uid := "qwerty"
|
||||||
mig, err := s.GetMigrationByUID(ctx, uid)
|
mig, err := s.GetMigrationSessionByUID(ctx, uid)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, uid, mig.UID)
|
require.Equal(t, uid, mig.UID)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("returns error if migration is not found by uid", func(t *testing.T) {
|
t.Run("returns error if session is not found by uid", func(t *testing.T) {
|
||||||
_, err := s.GetMigrationByUID(ctx, "fake_uid_1234")
|
_, err := s.GetMigrationSessionByUID(ctx, "fake_uid_1234")
|
||||||
require.ErrorIs(t, cloudmigration.ErrMigrationNotFound, err)
|
require.ErrorIs(t, cloudmigration.ErrMigrationNotFound, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -93,14 +93,14 @@ func Test_DeleteMigration(t *testing.T) {
|
|||||||
_, s := setUpTest(t)
|
_, s := setUpTest(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
t.Run("deletes a migration from the db", func(t *testing.T) {
|
t.Run("deletes a session from the db", func(t *testing.T) {
|
||||||
uid := "qwerty"
|
uid := "qwerty"
|
||||||
delResp, err := s.DeleteMigration(ctx, uid)
|
delResp, err := s.DeleteMigrationSessionByUID(ctx, uid)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, uid, delResp.UID)
|
require.Equal(t, uid, delResp.UID)
|
||||||
|
|
||||||
// now we try to find it, should return an error
|
// now we try to find it, should return an error
|
||||||
_, err = s.GetMigrationByUID(ctx, uid)
|
_, err = s.GetMigrationSessionByUID(ctx, uid)
|
||||||
require.ErrorIs(t, cloudmigration.ErrMigrationNotFound, err)
|
require.ErrorIs(t, cloudmigration.ErrMigrationNotFound, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -109,11 +109,11 @@ func Test_CreateMigrationRun(t *testing.T) {
|
|||||||
_, s := setUpTest(t)
|
_, s := setUpTest(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
t.Run("creates a migration run and retrieves it from db", func(t *testing.T) {
|
t.Run("creates a session run and retrieves it from db", func(t *testing.T) {
|
||||||
result := []byte("OK")
|
result := []byte("OK")
|
||||||
cmr := cloudmigration.CloudMigrationRun{
|
cmr := cloudmigration.CloudMigrationSnapshot{
|
||||||
CloudMigrationUID: "asdfg",
|
SessionUID: "asdfg",
|
||||||
Result: result,
|
Result: result,
|
||||||
}
|
}
|
||||||
|
|
||||||
createResp, err := s.CreateMigrationRun(ctx, cmr)
|
createResp, err := s.CreateMigrationRun(ctx, cmr)
|
||||||
@@ -173,7 +173,7 @@ func setUpTest(t *testing.T) (*sqlstore.SQLStore, *sqlStore) {
|
|||||||
// insert cloud migration test data
|
// insert cloud migration test data
|
||||||
_, err := testDB.GetSqlxSession().Exec(ctx, `
|
_, err := testDB.GetSqlxSession().Exec(ctx, `
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
cloud_migration (id, uid, auth_token, stack, stack_id, region_slug, cluster_slug, created, updated)
|
cloud_migration_session (id, uid, auth_token, slug, stack_id, region_slug, cluster_slug, created, updated)
|
||||||
VALUES
|
VALUES
|
||||||
(1,'qwerty', ?, '11111', 11111, 'test', 'test', '2024-03-25 15:30:36.000', '2024-03-27 15:30:43.000'),
|
(1,'qwerty', ?, '11111', 11111, 'test', 'test', '2024-03-25 15:30:36.000', '2024-03-27 15:30:43.000'),
|
||||||
(2,'asdfgh', ?, '22222', 22222, 'test', 'test', '2024-03-25 15:30:36.000', '2024-03-27 15:30:43.000'),
|
(2,'asdfgh', ?, '22222', 22222, 'test', 'test', '2024-03-25 15:30:36.000', '2024-03-27 15:30:43.000'),
|
||||||
@@ -188,7 +188,7 @@ func setUpTest(t *testing.T) (*sqlstore.SQLStore, *sqlStore) {
|
|||||||
// insert cloud migration run test data
|
// insert cloud migration run test data
|
||||||
_, err = testDB.GetSqlxSession().Exec(ctx, `
|
_, err = testDB.GetSqlxSession().Exec(ctx, `
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
cloud_migration_run (cloud_migration_uid, uid, result, created, updated, finished)
|
cloud_migration_snapshot (session_uid, uid, result, created, updated, finished)
|
||||||
VALUES
|
VALUES
|
||||||
('qwerty', 'poiuy', ?, '2024-03-25 15:30:36.000', '2024-03-27 15:30:43.000', '2024-03-27 15:30:43.000'),
|
('qwerty', 'poiuy', ?, '2024-03-25 15:30:36.000', '2024-03-27 15:30:43.000', '2024-03-27 15:30:43.000'),
|
||||||
('qwerty', 'lkjhg', ?, '2024-03-25 15:30:36.000', '2024-03-27 15:30:43.000', '2024-03-27 15:30:43.000'),
|
('qwerty', 'lkjhg', ?, '2024-03-25 15:30:36.000', '2024-03-27 15:30:43.000', '2024-03-27 15:30:43.000'),
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
package cmsclient
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/apimachinery/errutil"
|
|
||||||
"github.com/grafana/grafana/pkg/services/cloudmigration"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Client interface {
|
|
||||||
ValidateKey(context.Context, cloudmigration.CloudMigration) error
|
|
||||||
MigrateData(context.Context, cloudmigration.CloudMigration, cloudmigration.MigrateDataRequestDTO) (*cloudmigration.MigrateDataResponseDTO, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
const logPrefix = "cloudmigration.cmsclient"
|
|
||||||
|
|
||||||
var ErrMigrationNotDeleted = errutil.Internal("cloudmigrations.developerModeEnabled", errutil.WithPublicMessage("Developer mode enabled"))
|
|
||||||
14
pkg/services/cloudmigration/gmsclient/client.go
Normal file
14
pkg/services/cloudmigration/gmsclient/client.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package gmsclient
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/services/cloudmigration"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Client interface {
|
||||||
|
ValidateKey(context.Context, cloudmigration.CloudMigrationSession) error
|
||||||
|
MigrateData(context.Context, cloudmigration.CloudMigrationSession, cloudmigration.MigrateDataRequest) (*cloudmigration.MigrateDataResponse, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
const logPrefix = "cloudmigration.gmsclient"
|
||||||
47
pkg/services/cloudmigration/gmsclient/dtos.go
Normal file
47
pkg/services/cloudmigration/gmsclient/dtos.go
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
// TODO: Move these to a shared library in common with GMS
|
||||||
|
package gmsclient
|
||||||
|
|
||||||
|
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 {
|
||||||
|
RunUID string `json:"uid"`
|
||||||
|
Items []MigrateDataResponseItemDTO `json:"items"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MigrateDataResponseListDTO struct {
|
||||||
|
RunUID string `json:"uid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
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"`
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package cmsclient
|
package gmsclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@@ -11,25 +11,26 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/cloudmigration"
|
"github.com/grafana/grafana/pkg/services/cloudmigration"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCMSClient returns an implementation of Client that queries CloudMigrationService
|
// NewGMSClient returns an implementation of Client that queries GrafanaMigrationService
|
||||||
func NewCMSClient(domain string) Client {
|
func NewGMSClient(domain string) Client {
|
||||||
return &cmsClientImpl{
|
return &gmsClientImpl{
|
||||||
domain: domain,
|
domain: domain,
|
||||||
log: log.New(logPrefix),
|
log: log.New(logPrefix),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type cmsClientImpl struct {
|
type gmsClientImpl struct {
|
||||||
domain string
|
domain string
|
||||||
log *log.ConcreteLogger
|
log *log.ConcreteLogger
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cmsClientImpl) ValidateKey(ctx context.Context, cm cloudmigration.CloudMigration) error {
|
func (c *gmsClientImpl) ValidateKey(ctx context.Context, cm cloudmigration.CloudMigrationSession) error {
|
||||||
logger := c.log.FromContext(ctx)
|
logger := c.log.FromContext(ctx)
|
||||||
|
|
||||||
|
// TODO update service url to gms
|
||||||
path := fmt.Sprintf("https://cms-%s.%s/cloud-migrations/api/v1/validate-key", cm.ClusterSlug, c.domain)
|
path := fmt.Sprintf("https://cms-%s.%s/cloud-migrations/api/v1/validate-key", cm.ClusterSlug, c.domain)
|
||||||
|
|
||||||
// validation is an empty POST to CMS with the authorization header included
|
// validation is an empty POST to GMS with the authorization header included
|
||||||
req, err := http.NewRequest("POST", path, bytes.NewReader(nil))
|
req, err := http.NewRequest("POST", path, bytes.NewReader(nil))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("error creating http request for token validation", "err", err.Error())
|
logger.Error("error creating http request for token validation", "err", err.Error())
|
||||||
@@ -63,17 +64,19 @@ func (c *cmsClientImpl) ValidateKey(ctx context.Context, cm cloudmigration.Cloud
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cmsClientImpl) MigrateData(ctx context.Context, cm cloudmigration.CloudMigration, request cloudmigration.MigrateDataRequestDTO) (*cloudmigration.MigrateDataResponseDTO, error) {
|
func (c *gmsClientImpl) MigrateData(ctx context.Context, cm cloudmigration.CloudMigrationSession, request cloudmigration.MigrateDataRequest) (*cloudmigration.MigrateDataResponse, error) {
|
||||||
logger := c.log.FromContext(ctx)
|
logger := c.log.FromContext(ctx)
|
||||||
|
|
||||||
|
// TODO update service url to gms
|
||||||
path := fmt.Sprintf("https://cms-%s.%s/cloud-migrations/api/v1/migrate-data", cm.ClusterSlug, c.domain)
|
path := fmt.Sprintf("https://cms-%s.%s/cloud-migrations/api/v1/migrate-data", cm.ClusterSlug, c.domain)
|
||||||
|
|
||||||
body, err := json.Marshal(request)
|
reqDTO := convertRequestToDTO(request)
|
||||||
|
body, err := json.Marshal(reqDTO)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error marshaling request: %w", err)
|
return nil, fmt.Errorf("error marshaling request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the request to cms with the associated auth token
|
// Send the request to GMS with the associated auth token
|
||||||
req, err := http.NewRequest(http.MethodPost, path, bytes.NewReader(body))
|
req, err := http.NewRequest(http.MethodPost, path, bytes.NewReader(body))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.log.Error("error creating http request for cloud migration run", "err", err.Error())
|
c.log.Error("error creating http request for cloud migration run", "err", err.Error())
|
||||||
@@ -98,11 +101,46 @@ func (c *cmsClientImpl) MigrateData(ctx context.Context, cm cloudmigration.Cloud
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var result cloudmigration.MigrateDataResponseDTO
|
var respDTO MigrateDataResponseDTO
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
if err := json.NewDecoder(resp.Body).Decode(&respDTO); err != nil {
|
||||||
logger.Error("unmarshalling response body: %w", err)
|
logger.Error("unmarshalling response body: %w", err)
|
||||||
return nil, fmt.Errorf("unmarshalling migration run response: %w", err)
|
return nil, fmt.Errorf("unmarshalling migration run response: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result := convertResponseFromDTO(respDTO)
|
||||||
return &result, nil
|
return &result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func convertRequestToDTO(request cloudmigration.MigrateDataRequest) MigrateDataRequestDTO {
|
||||||
|
items := make([]MigrateDataRequestItemDTO, len(request.Items))
|
||||||
|
for i := 0; i < len(request.Items); i++ {
|
||||||
|
item := request.Items[i]
|
||||||
|
items[i] = MigrateDataRequestItemDTO{
|
||||||
|
Type: MigrateDataType(item.Type),
|
||||||
|
RefID: item.RefID,
|
||||||
|
Name: item.Name,
|
||||||
|
Data: item.Data,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
r := MigrateDataRequestDTO{
|
||||||
|
Items: items,
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertResponseFromDTO(result MigrateDataResponseDTO) cloudmigration.MigrateDataResponse {
|
||||||
|
items := make([]cloudmigration.MigrateDataResponseItem, len(result.Items))
|
||||||
|
for i := 0; i < len(result.Items); i++ {
|
||||||
|
item := result.Items[i]
|
||||||
|
items[i] = cloudmigration.MigrateDataResponseItem{
|
||||||
|
Type: cloudmigration.MigrateDataType(item.Type),
|
||||||
|
RefID: item.RefID,
|
||||||
|
Status: cloudmigration.ItemStatus(item.Status),
|
||||||
|
Error: item.Error,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cloudmigration.MigrateDataResponse{
|
||||||
|
RunUID: result.RunUID,
|
||||||
|
Items: items,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package cmsclient
|
package gmsclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -14,24 +14,21 @@ func NewInMemoryClient() Client {
|
|||||||
|
|
||||||
type memoryClientImpl struct{}
|
type memoryClientImpl struct{}
|
||||||
|
|
||||||
func (c *memoryClientImpl) ValidateKey(ctx context.Context, cm cloudmigration.CloudMigration) error {
|
func (c *memoryClientImpl) ValidateKey(ctx context.Context, cm cloudmigration.CloudMigrationSession) error {
|
||||||
// return ErrMigrationNotDeleted
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *memoryClientImpl) MigrateData(
|
func (c *memoryClientImpl) MigrateData(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
cm cloudmigration.CloudMigration,
|
cm cloudmigration.CloudMigrationSession,
|
||||||
request cloudmigration.MigrateDataRequestDTO,
|
request cloudmigration.MigrateDataRequest,
|
||||||
) (*cloudmigration.MigrateDataResponseDTO, error) {
|
) (*cloudmigration.MigrateDataResponse, error) {
|
||||||
//return nil, ErrMigrationNotDeleted
|
result := cloudmigration.MigrateDataResponse{
|
||||||
|
Items: make([]cloudmigration.MigrateDataResponseItem, len(request.Items)),
|
||||||
result := cloudmigration.MigrateDataResponseDTO{
|
|
||||||
Items: make([]cloudmigration.MigrateDataResponseItemDTO, len(request.Items)),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, v := range request.Items {
|
for i, v := range request.Items {
|
||||||
result.Items[i] = cloudmigration.MigrateDataResponseItemDTO{
|
result.Items[i] = cloudmigration.MigrateDataResponseItem{
|
||||||
Type: v.Type,
|
Type: v.Type,
|
||||||
RefID: v.RefID,
|
RefID: v.RefID,
|
||||||
Status: cloudmigration.ItemStatusOK,
|
Status: cloudmigration.ItemStatusOK,
|
||||||
@@ -11,37 +11,37 @@ import (
|
|||||||
var (
|
var (
|
||||||
ErrInternalNotImplementedError = errutil.Internal("cloudmigrations.notImplemented").Errorf("Internal server error")
|
ErrInternalNotImplementedError = errutil.Internal("cloudmigrations.notImplemented").Errorf("Internal server error")
|
||||||
ErrFeatureDisabledError = errutil.Internal("cloudmigrations.disabled").Errorf("Cloud migrations are disabled on this instance")
|
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")
|
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")
|
ErrTokenNotFound = errutil.NotFound("cloudmigrations.tokenNotFound").Errorf("Token not found")
|
||||||
)
|
)
|
||||||
|
|
||||||
// CloudMigration api dtos
|
// CloudMigration domain structs
|
||||||
type CloudMigration struct {
|
type CloudMigrationSession struct {
|
||||||
ID int64 `json:"id" xorm:"pk autoincr 'id'"`
|
ID int64 `xorm:"pk autoincr 'id'"`
|
||||||
UID string `json:"uid" xorm:"uid"`
|
UID string `xorm:"uid"`
|
||||||
AuthToken string `json:"-"`
|
AuthToken string
|
||||||
Stack string `json:"stack"`
|
Slug string
|
||||||
StackID int `json:"stackID" xorm:"stack_id"`
|
StackID int `xorm:"stack_id"`
|
||||||
RegionSlug string `json:"regionSlug"`
|
RegionSlug string
|
||||||
ClusterSlug string `json:"clusterSlug"`
|
ClusterSlug string
|
||||||
Created time.Time `json:"created"`
|
Created time.Time
|
||||||
Updated time.Time `json:"updated"`
|
Updated time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type CloudMigrationRun struct {
|
type CloudMigrationSnapshot struct {
|
||||||
ID int64 `json:"id" xorm:"pk autoincr 'id'"`
|
ID int64 `xorm:"pk autoincr 'id'"`
|
||||||
UID string `json:"uid" xorm:"uid"`
|
UID string `xorm:"uid"`
|
||||||
CloudMigrationUID string `json:"migrationUid" xorm:"cloud_migration_uid"`
|
SessionUID string `xorm:"session_uid"`
|
||||||
Result []byte `json:"result"` //store raw cms response body
|
Result []byte //store raw gms response body
|
||||||
Created time.Time `json:"created"`
|
Created time.Time
|
||||||
Updated time.Time `json:"updated"`
|
Updated time.Time
|
||||||
Finished time.Time `json:"finished"`
|
Finished time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r CloudMigrationRun) ToResponse() (*MigrateDataResponseDTO, error) {
|
func (r CloudMigrationSnapshot) GetResult() (*MigrateDataResponse, error) {
|
||||||
var result MigrateDataResponseDTO
|
var result MigrateDataResponse
|
||||||
err := json.Unmarshal(r.Result, &result)
|
err := json.Unmarshal(r.Result, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("could not parse result of run")
|
return nil, errors.New("could not parse result of run")
|
||||||
@@ -50,23 +50,23 @@ func (r CloudMigrationRun) ToResponse() (*MigrateDataResponseDTO, error) {
|
|||||||
return &result, nil
|
return &result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type CloudMigrationRunList struct {
|
type SnapshotList struct {
|
||||||
Runs []MigrateDataResponseListDTO `json:"runs"`
|
Runs []MigrateDataResponseList
|
||||||
}
|
}
|
||||||
|
|
||||||
type CloudMigrationRequest struct {
|
type CloudMigrationSessionRequest struct {
|
||||||
AuthToken string `json:"authToken"`
|
AuthToken string
|
||||||
}
|
}
|
||||||
|
|
||||||
type CloudMigrationResponse struct {
|
type CloudMigrationSessionResponse struct {
|
||||||
UID string `json:"uid"`
|
UID string
|
||||||
Stack string `json:"stack"`
|
Slug string
|
||||||
Created time.Time `json:"created"`
|
Created time.Time
|
||||||
Updated time.Time `json:"updated"`
|
Updated time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type CloudMigrationListResponse struct {
|
type CloudMigrationSessionListResponse struct {
|
||||||
Migrations []CloudMigrationResponse `json:"migrations"`
|
Sessions []CloudMigrationSessionResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
// access token
|
// access token
|
||||||
@@ -80,10 +80,10 @@ type Base64EncodedTokenPayload struct {
|
|||||||
Instance Base64HGInstance
|
Instance Base64HGInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Base64EncodedTokenPayload) ToMigration() CloudMigration {
|
func (p Base64EncodedTokenPayload) ToMigration() CloudMigrationSession {
|
||||||
return CloudMigration{
|
return CloudMigrationSession{
|
||||||
AuthToken: p.Token,
|
AuthToken: p.Token,
|
||||||
Stack: p.Instance.Slug,
|
Slug: p.Instance.Slug,
|
||||||
StackID: p.Instance.StackID,
|
StackID: p.Instance.StackID,
|
||||||
RegionSlug: p.Instance.RegionSlug,
|
RegionSlug: p.Instance.RegionSlug,
|
||||||
ClusterSlug: p.Instance.ClusterSlug,
|
ClusterSlug: p.Instance.ClusterSlug,
|
||||||
@@ -97,9 +97,8 @@ type Base64HGInstance struct {
|
|||||||
ClusterSlug string
|
ClusterSlug string
|
||||||
}
|
}
|
||||||
|
|
||||||
// dtos for cms api
|
// GMS domain structs
|
||||||
|
|
||||||
// swagger:enum MigrateDataType
|
|
||||||
type MigrateDataType string
|
type MigrateDataType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -108,18 +107,17 @@ const (
|
|||||||
FolderDataType MigrateDataType = "FOLDER"
|
FolderDataType MigrateDataType = "FOLDER"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MigrateDataRequestDTO struct {
|
type MigrateDataRequest struct {
|
||||||
Items []MigrateDataRequestItemDTO `json:"items"`
|
Items []MigrateDataRequestItem
|
||||||
}
|
}
|
||||||
|
|
||||||
type MigrateDataRequestItemDTO struct {
|
type MigrateDataRequestItem struct {
|
||||||
Type MigrateDataType `json:"type"`
|
Type MigrateDataType
|
||||||
RefID string `json:"refId"`
|
RefID string
|
||||||
Name string `json:"name"`
|
Name string
|
||||||
Data interface{} `json:"data"`
|
Data interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// swagger:enum ItemStatus
|
|
||||||
type ItemStatus string
|
type ItemStatus string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -127,21 +125,18 @@ const (
|
|||||||
ItemStatusError ItemStatus = "ERROR"
|
ItemStatusError ItemStatus = "ERROR"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MigrateDataResponseDTO struct {
|
type MigrateDataResponse struct {
|
||||||
RunUID string `json:"uid"`
|
RunUID string
|
||||||
Items []MigrateDataResponseItemDTO `json:"items"`
|
Items []MigrateDataResponseItem
|
||||||
}
|
}
|
||||||
|
|
||||||
type MigrateDataResponseListDTO struct {
|
type MigrateDataResponseList struct {
|
||||||
RunUID string `json:"uid"`
|
RunUID string
|
||||||
}
|
}
|
||||||
|
|
||||||
type MigrateDataResponseItemDTO struct {
|
type MigrateDataResponseItem struct {
|
||||||
// required:true
|
Type MigrateDataType
|
||||||
Type MigrateDataType `json:"type"`
|
RefID string
|
||||||
// required:true
|
Status ItemStatus
|
||||||
RefID string `json:"refId"`
|
Error string
|
||||||
// required:true
|
|
||||||
Status ItemStatus `json:"status"`
|
|
||||||
Error string `json:"error,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func addCloudMigrationsMigrations(mg *Migrator) {
|
func addCloudMigrationsMigrations(mg *Migrator) {
|
||||||
|
// v1 - synchronous workflow
|
||||||
migrationTable := Table{
|
migrationTable := Table{
|
||||||
Name: "cloud_migration",
|
Name: "cloud_migration",
|
||||||
Columns: []*Column{
|
Columns: []*Column{
|
||||||
@@ -63,4 +64,61 @@ func addCloudMigrationsMigrations(mg *Migrator) {
|
|||||||
mg.AddMigration("Add unique index migration_run_uid", NewAddIndexMigration(migrationRunTable, &Index{
|
mg.AddMigration("Add unique index migration_run_uid", NewAddIndexMigration(migrationRunTable, &Index{
|
||||||
Cols: []string{"uid"}, Type: UniqueIndex,
|
Cols: []string{"uid"}, Type: UniqueIndex,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// v2 - asynchronous workflow refactor
|
||||||
|
sessionTable := Table{
|
||||||
|
Name: "cloud_migration_session",
|
||||||
|
Columns: []*Column{
|
||||||
|
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
|
||||||
|
{Name: "uid", Type: DB_NVarchar, Length: 40, Nullable: true},
|
||||||
|
{Name: "auth_token", Type: DB_Text, Nullable: true}, // encrypted
|
||||||
|
{Name: "slug", Type: DB_Text},
|
||||||
|
{Name: "stack_id", Type: DB_BigInt, Nullable: false},
|
||||||
|
{Name: "region_slug", Type: DB_Text, Nullable: false},
|
||||||
|
{Name: "cluster_slug", Type: DB_Text, Nullable: false},
|
||||||
|
{Name: "created", Type: DB_DateTime, Nullable: false},
|
||||||
|
{Name: "updated", Type: DB_DateTime, Nullable: false},
|
||||||
|
},
|
||||||
|
Indices: []*Index{
|
||||||
|
{Cols: []string{"uid"}, Type: UniqueIndex},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
migrationSnapshotTable := Table{
|
||||||
|
Name: "cloud_migration_snapshot",
|
||||||
|
Columns: []*Column{
|
||||||
|
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
|
||||||
|
{Name: "uid", Type: DB_NVarchar, Length: 40, Nullable: true},
|
||||||
|
{Name: "session_uid", Type: DB_NVarchar, Length: 40, Nullable: true}, // get from the cloud service
|
||||||
|
{Name: "result", Type: DB_Text, Nullable: false},
|
||||||
|
{Name: "created", Type: DB_DateTime, Nullable: false},
|
||||||
|
{Name: "updated", Type: DB_DateTime, Nullable: false},
|
||||||
|
{Name: "finished", Type: DB_DateTime, Nullable: true},
|
||||||
|
},
|
||||||
|
Indices: []*Index{
|
||||||
|
{Cols: []string{"uid"}, Type: UniqueIndex},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
addTableReplaceMigrations(mg, migrationTable, sessionTable, 2, map[string]string{
|
||||||
|
"id": "id",
|
||||||
|
"uid": "uid",
|
||||||
|
"auth_token": "auth_token",
|
||||||
|
"slug": "stack",
|
||||||
|
"stack_id": "stack_id",
|
||||||
|
"region_slug": "region_slug",
|
||||||
|
"cluster_slug": "cluster_slug",
|
||||||
|
"created": "created",
|
||||||
|
"updated": "updated",
|
||||||
|
})
|
||||||
|
|
||||||
|
addTableReplaceMigrations(mg, migrationRunTable, migrationSnapshotTable, 2, map[string]string{
|
||||||
|
"id": "id",
|
||||||
|
"uid": "uid",
|
||||||
|
"session_uid": "cloud_migration_uid",
|
||||||
|
"result": "result",
|
||||||
|
"created": "created",
|
||||||
|
"updated": "updated",
|
||||||
|
"finished": "finished",
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3116,18 +3116,18 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"CloudMigrationListResponse": {
|
"CloudMigrationSessionListResponseDTO": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"migrations": {
|
"sessions": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
"$ref": "#/definitions/CloudMigrationResponse"
|
"$ref": "#/definitions/CloudMigrationSessionResponseDTO"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"CloudMigrationRequest": {
|
"CloudMigrationSessionRequestDTO": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"authToken": {
|
"authToken": {
|
||||||
@@ -3135,14 +3135,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"CloudMigrationResponse": {
|
"CloudMigrationSessionResponseDTO": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"created": {
|
"created": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "date-time"
|
"format": "date-time"
|
||||||
},
|
},
|
||||||
"stack": {
|
"slug": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"uid": {
|
"uid": {
|
||||||
@@ -3154,17 +3154,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"CloudMigrationRunList": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"runs": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"$ref": "#/definitions/MigrateDataResponseListDTO"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"ConfFloat64": {
|
"ConfFloat64": {
|
||||||
"description": "ConfFloat64 is a float64. It Marshals float64 values of NaN of Inf\nto null.",
|
"description": "ConfFloat64 is a float64. It Marshals float64 values of NaN of Inf\nto null.",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
@@ -7048,6 +7037,17 @@
|
|||||||
"type": "integer",
|
"type": "integer",
|
||||||
"format": "int64"
|
"format": "int64"
|
||||||
},
|
},
|
||||||
|
"SnapshotListDTO": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"runs": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/MigrateDataResponseListDTO"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"State": {
|
"State": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
@@ -8342,22 +8342,10 @@
|
|||||||
"$ref": "#/definitions/GetAccessTokenResponseDTO"
|
"$ref": "#/definitions/GetAccessTokenResponseDTO"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cloudMigrationListResponse": {
|
|
||||||
"description": "",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/CloudMigrationListResponse"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"cloudMigrationResponse": {
|
|
||||||
"description": "",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/CloudMigrationResponse"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"cloudMigrationRunListResponse": {
|
"cloudMigrationRunListResponse": {
|
||||||
"description": "",
|
"description": "",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/CloudMigrationRunList"
|
"$ref": "#/definitions/SnapshotListDTO"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cloudMigrationRunResponse": {
|
"cloudMigrationRunResponse": {
|
||||||
@@ -8366,6 +8354,18 @@
|
|||||||
"$ref": "#/definitions/MigrateDataResponseDTO"
|
"$ref": "#/definitions/MigrateDataResponseDTO"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"cloudMigrationSessionListResponse": {
|
||||||
|
"description": "",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/CloudMigrationSessionListResponseDTO"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"cloudMigrationSessionResponse": {
|
||||||
|
"description": "",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/CloudMigrationSessionResponseDTO"
|
||||||
|
}
|
||||||
|
},
|
||||||
"conflictError": {
|
"conflictError": {
|
||||||
"description": "ConflictError",
|
"description": "ConflictError",
|
||||||
"schema": {
|
"schema": {
|
||||||
|
|||||||
@@ -2299,11 +2299,11 @@
|
|||||||
"tags": [
|
"tags": [
|
||||||
"migrations"
|
"migrations"
|
||||||
],
|
],
|
||||||
"summary": "Get a list of all cloud migrations.",
|
"summary": "Get a list of all cloud migration sessions that have been created.",
|
||||||
"operationId": "getMigrationList",
|
"operationId": "getSessionList",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"$ref": "#/responses/cloudMigrationListResponse"
|
"$ref": "#/responses/cloudMigrationSessionListResponse"
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"$ref": "#/responses/unauthorisedError"
|
"$ref": "#/responses/unauthorisedError"
|
||||||
@@ -2320,21 +2320,21 @@
|
|||||||
"tags": [
|
"tags": [
|
||||||
"migrations"
|
"migrations"
|
||||||
],
|
],
|
||||||
"summary": "Create a migration.",
|
"summary": "Create a migration session.",
|
||||||
"operationId": "createMigration",
|
"operationId": "createSession",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"name": "Body",
|
"name": "Body",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/CloudMigrationRequest"
|
"$ref": "#/definitions/CloudMigrationSessionRequestDTO"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"$ref": "#/responses/cloudMigrationResponse"
|
"$ref": "#/responses/cloudMigrationSessionResponse"
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"$ref": "#/responses/unauthorisedError"
|
"$ref": "#/responses/unauthorisedError"
|
||||||
@@ -2382,16 +2382,15 @@
|
|||||||
},
|
},
|
||||||
"/cloudmigration/migration/{uid}": {
|
"/cloudmigration/migration/{uid}": {
|
||||||
"get": {
|
"get": {
|
||||||
"description": "It returns migrations that has been created.",
|
|
||||||
"tags": [
|
"tags": [
|
||||||
"migrations"
|
"migrations"
|
||||||
],
|
],
|
||||||
"summary": "Get a cloud migration.",
|
"summary": "Get a cloud migration session by its uid.",
|
||||||
"operationId": "getCloudMigration",
|
"operationId": "getSession",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "UID of a migration",
|
"description": "UID of a migration session",
|
||||||
"name": "uid",
|
"name": "uid",
|
||||||
"in": "path",
|
"in": "path",
|
||||||
"required": true
|
"required": true
|
||||||
@@ -2399,7 +2398,7 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"$ref": "#/responses/cloudMigrationResponse"
|
"$ref": "#/responses/cloudMigrationSessionResponse"
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"$ref": "#/responses/unauthorisedError"
|
"$ref": "#/responses/unauthorisedError"
|
||||||
@@ -2416,12 +2415,12 @@
|
|||||||
"tags": [
|
"tags": [
|
||||||
"migrations"
|
"migrations"
|
||||||
],
|
],
|
||||||
"summary": "Delete a migration.",
|
"summary": "Delete a migration session by its uid.",
|
||||||
"operationId": "deleteCloudMigration",
|
"operationId": "deleteSession",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "UID of a migration",
|
"description": "UID of a migration session",
|
||||||
"name": "uid",
|
"name": "uid",
|
||||||
"in": "path",
|
"in": "path",
|
||||||
"required": true
|
"required": true
|
||||||
@@ -13294,18 +13293,18 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"CloudMigrationListResponse": {
|
"CloudMigrationSessionListResponseDTO": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"migrations": {
|
"sessions": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
"$ref": "#/definitions/CloudMigrationResponse"
|
"$ref": "#/definitions/CloudMigrationSessionResponseDTO"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"CloudMigrationRequest": {
|
"CloudMigrationSessionRequestDTO": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"authToken": {
|
"authToken": {
|
||||||
@@ -13313,14 +13312,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"CloudMigrationResponse": {
|
"CloudMigrationSessionResponseDTO": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"created": {
|
"created": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "date-time"
|
"format": "date-time"
|
||||||
},
|
},
|
||||||
"stack": {
|
"slug": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"uid": {
|
"uid": {
|
||||||
@@ -13332,17 +13331,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"CloudMigrationRunList": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"runs": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"$ref": "#/definitions/MigrateDataResponseListDTO"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"ConfFloat64": {
|
"ConfFloat64": {
|
||||||
"description": "ConfFloat64 is a float64. It Marshals float64 values of NaN of Inf\nto null.",
|
"description": "ConfFloat64 is a float64. It Marshals float64 values of NaN of Inf\nto null.",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
@@ -19950,6 +19938,17 @@
|
|||||||
"SmtpNotEnabled": {
|
"SmtpNotEnabled": {
|
||||||
"$ref": "#/definitions/ResponseDetails"
|
"$ref": "#/definitions/ResponseDetails"
|
||||||
},
|
},
|
||||||
|
"SnapshotListDTO": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"runs": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/MigrateDataResponseListDTO"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"Span": {
|
"Span": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"title": "A Span defines a continuous sequence of buckets.",
|
"title": "A Span defines a continuous sequence of buckets.",
|
||||||
@@ -22383,22 +22382,10 @@
|
|||||||
"$ref": "#/definitions/GetAccessTokenResponseDTO"
|
"$ref": "#/definitions/GetAccessTokenResponseDTO"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cloudMigrationListResponse": {
|
|
||||||
"description": "(empty)",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/CloudMigrationListResponse"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"cloudMigrationResponse": {
|
|
||||||
"description": "(empty)",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/CloudMigrationResponse"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"cloudMigrationRunListResponse": {
|
"cloudMigrationRunListResponse": {
|
||||||
"description": "(empty)",
|
"description": "(empty)",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/CloudMigrationRunList"
|
"$ref": "#/definitions/SnapshotListDTO"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cloudMigrationRunResponse": {
|
"cloudMigrationRunResponse": {
|
||||||
@@ -22407,6 +22394,18 @@
|
|||||||
"$ref": "#/definitions/MigrateDataResponseDTO"
|
"$ref": "#/definitions/MigrateDataResponseDTO"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"cloudMigrationSessionListResponse": {
|
||||||
|
"description": "(empty)",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/CloudMigrationSessionListResponseDTO"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"cloudMigrationSessionResponse": {
|
||||||
|
"description": "(empty)",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/CloudMigrationSessionResponseDTO"
|
||||||
|
}
|
||||||
|
},
|
||||||
"conflictError": {
|
"conflictError": {
|
||||||
"description": "ConflictError",
|
"description": "ConflictError",
|
||||||
"schema": {
|
"schema": {
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
import { baseAPI as api } from './baseAPI';
|
import { baseAPI as api } from './baseAPI';
|
||||||
const injectedRtkApi = api.injectEndpoints({
|
const injectedRtkApi = api.injectEndpoints({
|
||||||
endpoints: (build) => ({
|
endpoints: (build) => ({
|
||||||
getMigrationList: build.query<GetMigrationListApiResponse, GetMigrationListApiArg>({
|
getSessionList: build.query<GetSessionListApiResponse, GetSessionListApiArg>({
|
||||||
query: () => ({ url: `/cloudmigration/migration` }),
|
query: () => ({ url: `/cloudmigration/migration` }),
|
||||||
}),
|
}),
|
||||||
createMigration: build.mutation<CreateMigrationApiResponse, CreateMigrationApiArg>({
|
createSession: build.mutation<CreateSessionApiResponse, CreateSessionApiArg>({
|
||||||
query: (queryArg) => ({ url: `/cloudmigration/migration`, method: 'POST', body: queryArg.cloudMigrationRequest }),
|
query: (queryArg) => ({
|
||||||
|
url: `/cloudmigration/migration`,
|
||||||
|
method: 'POST',
|
||||||
|
body: queryArg.cloudMigrationSessionRequestDto,
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
getCloudMigrationRun: build.query<GetCloudMigrationRunApiResponse, GetCloudMigrationRunApiArg>({
|
getCloudMigrationRun: build.query<GetCloudMigrationRunApiResponse, GetCloudMigrationRunApiArg>({
|
||||||
query: (queryArg) => ({ url: `/cloudmigration/migration/run/${queryArg.runUid}` }),
|
query: (queryArg) => ({ url: `/cloudmigration/migration/run/${queryArg.runUid}` }),
|
||||||
}),
|
}),
|
||||||
deleteCloudMigration: build.mutation<DeleteCloudMigrationApiResponse, DeleteCloudMigrationApiArg>({
|
deleteSession: build.mutation<DeleteSessionApiResponse, DeleteSessionApiArg>({
|
||||||
query: (queryArg) => ({ url: `/cloudmigration/migration/${queryArg.uid}`, method: 'DELETE' }),
|
query: (queryArg) => ({ url: `/cloudmigration/migration/${queryArg.uid}`, method: 'DELETE' }),
|
||||||
}),
|
}),
|
||||||
getCloudMigration: build.query<GetCloudMigrationApiResponse, GetCloudMigrationApiArg>({
|
getSession: build.query<GetSessionApiResponse, GetSessionApiArg>({
|
||||||
query: (queryArg) => ({ url: `/cloudmigration/migration/${queryArg.uid}` }),
|
query: (queryArg) => ({ url: `/cloudmigration/migration/${queryArg.uid}` }),
|
||||||
}),
|
}),
|
||||||
getCloudMigrationRunList: build.query<GetCloudMigrationRunListApiResponse, GetCloudMigrationRunListApiArg>({
|
getCloudMigrationRunList: build.query<GetCloudMigrationRunListApiResponse, GetCloudMigrationRunListApiArg>({
|
||||||
@@ -32,28 +36,28 @@ const injectedRtkApi = api.injectEndpoints({
|
|||||||
overrideExisting: false,
|
overrideExisting: false,
|
||||||
});
|
});
|
||||||
export { injectedRtkApi as generatedAPI };
|
export { injectedRtkApi as generatedAPI };
|
||||||
export type GetMigrationListApiResponse = /** status 200 (empty) */ CloudMigrationListResponse;
|
export type GetSessionListApiResponse = /** status 200 (empty) */ CloudMigrationSessionListResponseDto;
|
||||||
export type GetMigrationListApiArg = void;
|
export type GetSessionListApiArg = void;
|
||||||
export type CreateMigrationApiResponse = /** status 200 (empty) */ CloudMigrationResponse;
|
export type CreateSessionApiResponse = /** status 200 (empty) */ CloudMigrationSessionResponseDto;
|
||||||
export type CreateMigrationApiArg = {
|
export type CreateSessionApiArg = {
|
||||||
cloudMigrationRequest: CloudMigrationRequest;
|
cloudMigrationSessionRequestDto: CloudMigrationSessionRequestDto;
|
||||||
};
|
};
|
||||||
export type GetCloudMigrationRunApiResponse = /** status 200 (empty) */ MigrateDataResponseDto;
|
export type GetCloudMigrationRunApiResponse = /** status 200 (empty) */ MigrateDataResponseDto;
|
||||||
export type GetCloudMigrationRunApiArg = {
|
export type GetCloudMigrationRunApiArg = {
|
||||||
/** RunUID of a migration run */
|
/** RunUID of a migration run */
|
||||||
runUid: string;
|
runUid: string;
|
||||||
};
|
};
|
||||||
export type DeleteCloudMigrationApiResponse = unknown;
|
export type DeleteSessionApiResponse = unknown;
|
||||||
export type DeleteCloudMigrationApiArg = {
|
export type DeleteSessionApiArg = {
|
||||||
/** UID of a migration */
|
/** UID of a migration session */
|
||||||
uid: string;
|
uid: string;
|
||||||
};
|
};
|
||||||
export type GetCloudMigrationApiResponse = /** status 200 (empty) */ CloudMigrationResponse;
|
export type GetSessionApiResponse = /** status 200 (empty) */ CloudMigrationSessionResponseDto;
|
||||||
export type GetCloudMigrationApiArg = {
|
export type GetSessionApiArg = {
|
||||||
/** UID of a migration */
|
/** UID of a migration session */
|
||||||
uid: string;
|
uid: string;
|
||||||
};
|
};
|
||||||
export type GetCloudMigrationRunListApiResponse = /** status 200 (empty) */ CloudMigrationRunList;
|
export type GetCloudMigrationRunListApiResponse = /** status 200 (empty) */ SnapshotListDto;
|
||||||
export type GetCloudMigrationRunListApiArg = {
|
export type GetCloudMigrationRunListApiArg = {
|
||||||
/** UID of a migration */
|
/** UID of a migration */
|
||||||
uid: string;
|
uid: string;
|
||||||
@@ -69,14 +73,14 @@ export type GetDashboardByUidApiResponse = /** status 200 (empty) */ DashboardFu
|
|||||||
export type GetDashboardByUidApiArg = {
|
export type GetDashboardByUidApiArg = {
|
||||||
uid: string;
|
uid: string;
|
||||||
};
|
};
|
||||||
export type CloudMigrationResponse = {
|
export type CloudMigrationSessionResponseDto = {
|
||||||
created?: string;
|
created?: string;
|
||||||
stack?: string;
|
slug?: string;
|
||||||
uid?: string;
|
uid?: string;
|
||||||
updated?: string;
|
updated?: string;
|
||||||
};
|
};
|
||||||
export type CloudMigrationListResponse = {
|
export type CloudMigrationSessionListResponseDto = {
|
||||||
migrations?: CloudMigrationResponse[];
|
sessions?: CloudMigrationSessionResponseDto[];
|
||||||
};
|
};
|
||||||
export type ErrorResponseBody = {
|
export type ErrorResponseBody = {
|
||||||
/** Error An optional detailed description of the actual error. Only included if running in developer mode. */
|
/** Error An optional detailed description of the actual error. Only included if running in developer mode. */
|
||||||
@@ -88,7 +92,7 @@ export type ErrorResponseBody = {
|
|||||||
For example, a 412 Precondition Failed error may include additional information of why that error happened. */
|
For example, a 412 Precondition Failed error may include additional information of why that error happened. */
|
||||||
status?: string;
|
status?: string;
|
||||||
};
|
};
|
||||||
export type CloudMigrationRequest = {
|
export type CloudMigrationSessionRequestDto = {
|
||||||
authToken?: string;
|
authToken?: string;
|
||||||
};
|
};
|
||||||
export type MigrateDataResponseItemDto = {
|
export type MigrateDataResponseItemDto = {
|
||||||
@@ -104,7 +108,7 @@ export type MigrateDataResponseDto = {
|
|||||||
export type MigrateDataResponseListDto = {
|
export type MigrateDataResponseListDto = {
|
||||||
uid?: string;
|
uid?: string;
|
||||||
};
|
};
|
||||||
export type CloudMigrationRunList = {
|
export type SnapshotListDto = {
|
||||||
runs?: MigrateDataResponseListDto[];
|
runs?: MigrateDataResponseListDto[];
|
||||||
};
|
};
|
||||||
export type CreateAccessTokenResponseDto = {
|
export type CreateAccessTokenResponseDto = {
|
||||||
@@ -154,11 +158,11 @@ export type DashboardFullWithMeta = {
|
|||||||
meta?: DashboardMeta;
|
meta?: DashboardMeta;
|
||||||
};
|
};
|
||||||
export const {
|
export const {
|
||||||
useGetMigrationListQuery,
|
useGetSessionListQuery,
|
||||||
useCreateMigrationMutation,
|
useCreateSessionMutation,
|
||||||
useGetCloudMigrationRunQuery,
|
useGetCloudMigrationRunQuery,
|
||||||
useDeleteCloudMigrationMutation,
|
useDeleteSessionMutation,
|
||||||
useGetCloudMigrationQuery,
|
useGetSessionQuery,
|
||||||
useGetCloudMigrationRunListQuery,
|
useGetCloudMigrationRunListQuery,
|
||||||
useRunCloudMigrationMutation,
|
useRunCloudMigrationMutation,
|
||||||
useCreateCloudMigrationTokenMutation,
|
useCreateCloudMigrationTokenMutation,
|
||||||
|
|||||||
@@ -10,23 +10,23 @@ export const cloudMigrationAPI = generatedAPI.enhanceEndpoints({
|
|||||||
createCloudMigrationToken: suppressErrorsOnQuery,
|
createCloudMigrationToken: suppressErrorsOnQuery,
|
||||||
|
|
||||||
// List Cloud Configs
|
// List Cloud Configs
|
||||||
getMigrationList: {
|
getSessionList: {
|
||||||
providesTags: ['cloud-migration-config'] /* should this be a -list? */,
|
providesTags: ['cloud-migration-config'] /* should this be a -list? */,
|
||||||
},
|
},
|
||||||
|
|
||||||
// Create Cloud Config
|
// Create Cloud Config
|
||||||
createMigration(endpoint) {
|
createSession(endpoint) {
|
||||||
suppressErrorsOnQuery(endpoint);
|
suppressErrorsOnQuery(endpoint);
|
||||||
endpoint.invalidatesTags = ['cloud-migration-config'];
|
endpoint.invalidatesTags = ['cloud-migration-config'];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Get one Cloud Config
|
// Get one Cloud Config
|
||||||
getCloudMigration: {
|
getSession: {
|
||||||
providesTags: ['cloud-migration-config'],
|
providesTags: ['cloud-migration-config'],
|
||||||
},
|
},
|
||||||
|
|
||||||
// Delete one Cloud Config
|
// Delete one Cloud Config
|
||||||
deleteCloudMigration: {
|
deleteSession: {
|
||||||
invalidatesTags: ['cloud-migration-config'],
|
invalidatesTags: ['cloud-migration-config'],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ import React, { useState } from 'react';
|
|||||||
import { Box, Button, Text } from '@grafana/ui';
|
import { Box, Button, Text } from '@grafana/ui';
|
||||||
import { Trans } from 'app/core/internationalization';
|
import { Trans } from 'app/core/internationalization';
|
||||||
|
|
||||||
import { useCreateMigrationMutation } from '../../../api';
|
import { useCreateSessionMutation } from '../../../api';
|
||||||
|
|
||||||
import { ConnectModal } from './ConnectModal';
|
import { ConnectModal } from './ConnectModal';
|
||||||
|
|
||||||
export const CallToAction = () => {
|
export const CallToAction = () => {
|
||||||
const [modalOpen, setModalOpen] = useState(false);
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
const [createMigration, createMigrationResponse] = useCreateMigrationMutation();
|
const [createMigration, createMigrationResponse] = useCreateSessionMutation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ import { GrafanaTheme2 } from '@grafana/data';
|
|||||||
import { Modal, Button, Stack, TextLink, Field, Input, Text, useStyles2, Alert } from '@grafana/ui';
|
import { Modal, Button, Stack, TextLink, Field, Input, Text, useStyles2, Alert } from '@grafana/ui';
|
||||||
import { Trans, t } from 'app/core/internationalization';
|
import { Trans, t } from 'app/core/internationalization';
|
||||||
|
|
||||||
import { CreateMigrationApiArg } from '../../../api';
|
import { CreateSessionApiArg } from '../../../api';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
isError: boolean;
|
isError: boolean;
|
||||||
hideModal: () => void;
|
hideModal: () => void;
|
||||||
onConfirm: (connectStackData: CreateMigrationApiArg) => Promise<unknown>;
|
onConfirm: (connectStackData: CreateSessionApiArg) => Promise<unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FormData {
|
interface FormData {
|
||||||
@@ -39,7 +39,7 @@ export const ConnectModal = ({ isOpen, isLoading, isError, hideModal, onConfirm
|
|||||||
|
|
||||||
const onConfirmConnect: SubmitHandler<FormData> = (formData) => {
|
const onConfirmConnect: SubmitHandler<FormData> = (formData) => {
|
||||||
onConfirm({
|
onConfirm({
|
||||||
cloudMigrationRequest: {
|
cloudMigrationSessionRequestDto: {
|
||||||
authToken: formData.token,
|
authToken: formData.token,
|
||||||
},
|
},
|
||||||
}).then((resp) => {
|
}).then((resp) => {
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import { Alert, Box, Button, Stack } from '@grafana/ui';
|
|||||||
import { Trans, t } from 'app/core/internationalization';
|
import { Trans, t } from 'app/core/internationalization';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
useDeleteCloudMigrationMutation,
|
useDeleteSessionMutation,
|
||||||
useGetCloudMigrationRunListQuery,
|
useGetCloudMigrationRunListQuery,
|
||||||
useGetCloudMigrationRunQuery,
|
useGetCloudMigrationRunQuery,
|
||||||
useGetMigrationListQuery,
|
useGetSessionListQuery,
|
||||||
useRunCloudMigrationMutation,
|
useRunCloudMigrationMutation,
|
||||||
} from '../api';
|
} from '../api';
|
||||||
|
|
||||||
@@ -33,8 +33,8 @@ import { ResourcesTable } from './ResourcesTable';
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function useGetLatestMigrationDestination() {
|
function useGetLatestMigrationDestination() {
|
||||||
const result = useGetMigrationListQuery();
|
const result = useGetSessionListQuery();
|
||||||
const latestMigration = result.data?.migrations?.at(-1);
|
const latestMigration = result.data?.sessions?.at(-1);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...result,
|
...result,
|
||||||
@@ -68,7 +68,7 @@ export const Page = () => {
|
|||||||
const migrationDestination = useGetLatestMigrationDestination();
|
const migrationDestination = useGetLatestMigrationDestination();
|
||||||
const lastMigrationRun = useGetLatestMigrationRun(migrationDestination.data?.uid);
|
const lastMigrationRun = useGetLatestMigrationRun(migrationDestination.data?.uid);
|
||||||
const [performRunMigration, runMigrationResult] = useRunCloudMigrationMutation();
|
const [performRunMigration, runMigrationResult] = useRunCloudMigrationMutation();
|
||||||
const [performDisconnect, disconnectResult] = useDeleteCloudMigrationMutation();
|
const [performDisconnect, disconnectResult] = useDeleteSessionMutation();
|
||||||
|
|
||||||
// isBusy is not a loading state, but indicates that the system is doing *something*
|
// isBusy is not a loading state, but indicates that the system is doing *something*
|
||||||
// and all buttons should be disabled
|
// and all buttons should be disabled
|
||||||
@@ -136,7 +136,7 @@ export const Page = () => {
|
|||||||
</Alert>
|
</Alert>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{migrationMeta.stack && (
|
{migrationMeta.slug && (
|
||||||
<Box
|
<Box
|
||||||
borderColor="weak"
|
borderColor="weak"
|
||||||
borderStyle="solid"
|
borderStyle="solid"
|
||||||
@@ -150,7 +150,7 @@ export const Page = () => {
|
|||||||
title={t('migrate-to-cloud.summary.target-stack-title', 'Uploading to')}
|
title={t('migrate-to-cloud.summary.target-stack-title', 'Uploading to')}
|
||||||
value={
|
value={
|
||||||
<>
|
<>
|
||||||
{migrationMeta.stack}{' '}
|
{migrationMeta.slug}{' '}
|
||||||
<Button
|
<Button
|
||||||
disabled={isBusy}
|
disabled={isBusy}
|
||||||
onClick={() => setDisconnectModalOpen(true)}
|
onClick={() => setDisconnectModalOpen(true)}
|
||||||
|
|||||||
@@ -196,31 +196,11 @@
|
|||||||
},
|
},
|
||||||
"description": "(empty)"
|
"description": "(empty)"
|
||||||
},
|
},
|
||||||
"cloudMigrationListResponse": {
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/components/schemas/CloudMigrationListResponse"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"description": "(empty)"
|
|
||||||
},
|
|
||||||
"cloudMigrationResponse": {
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/components/schemas/CloudMigrationResponse"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"description": "(empty)"
|
|
||||||
},
|
|
||||||
"cloudMigrationRunListResponse": {
|
"cloudMigrationRunListResponse": {
|
||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/components/schemas/CloudMigrationRunList"
|
"$ref": "#/components/schemas/SnapshotListDTO"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -236,6 +216,26 @@
|
|||||||
},
|
},
|
||||||
"description": "(empty)"
|
"description": "(empty)"
|
||||||
},
|
},
|
||||||
|
"cloudMigrationSessionListResponse": {
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/CloudMigrationSessionListResponseDTO"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"description": "(empty)"
|
||||||
|
},
|
||||||
|
"cloudMigrationSessionResponse": {
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/CloudMigrationSessionResponseDTO"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"description": "(empty)"
|
||||||
|
},
|
||||||
"conflictError": {
|
"conflictError": {
|
||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
@@ -3673,18 +3673,18 @@
|
|||||||
},
|
},
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"CloudMigrationListResponse": {
|
"CloudMigrationSessionListResponseDTO": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"migrations": {
|
"sessions": {
|
||||||
"items": {
|
"items": {
|
||||||
"$ref": "#/components/schemas/CloudMigrationResponse"
|
"$ref": "#/components/schemas/CloudMigrationSessionResponseDTO"
|
||||||
},
|
},
|
||||||
"type": "array"
|
"type": "array"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"CloudMigrationRequest": {
|
"CloudMigrationSessionRequestDTO": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"authToken": {
|
"authToken": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -3692,13 +3692,13 @@
|
|||||||
},
|
},
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"CloudMigrationResponse": {
|
"CloudMigrationSessionResponseDTO": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"created": {
|
"created": {
|
||||||
"format": "date-time",
|
"format": "date-time",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"stack": {
|
"slug": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"uid": {
|
"uid": {
|
||||||
@@ -3711,17 +3711,6 @@
|
|||||||
},
|
},
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"CloudMigrationRunList": {
|
|
||||||
"properties": {
|
|
||||||
"runs": {
|
|
||||||
"items": {
|
|
||||||
"$ref": "#/components/schemas/MigrateDataResponseListDTO"
|
|
||||||
},
|
|
||||||
"type": "array"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"type": "object"
|
|
||||||
},
|
|
||||||
"ConfFloat64": {
|
"ConfFloat64": {
|
||||||
"description": "ConfFloat64 is a float64. It Marshals float64 values of NaN of Inf\nto null.",
|
"description": "ConfFloat64 is a float64. It Marshals float64 values of NaN of Inf\nto null.",
|
||||||
"format": "double",
|
"format": "double",
|
||||||
@@ -10328,6 +10317,17 @@
|
|||||||
"SmtpNotEnabled": {
|
"SmtpNotEnabled": {
|
||||||
"$ref": "#/components/schemas/ResponseDetails"
|
"$ref": "#/components/schemas/ResponseDetails"
|
||||||
},
|
},
|
||||||
|
"SnapshotListDTO": {
|
||||||
|
"properties": {
|
||||||
|
"runs": {
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/components/schemas/MigrateDataResponseListDTO"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
"Span": {
|
"Span": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"Length": {
|
"Length": {
|
||||||
@@ -15112,10 +15112,10 @@
|
|||||||
},
|
},
|
||||||
"/cloudmigration/migration": {
|
"/cloudmigration/migration": {
|
||||||
"get": {
|
"get": {
|
||||||
"operationId": "getMigrationList",
|
"operationId": "getSessionList",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"$ref": "#/components/responses/cloudMigrationListResponse"
|
"$ref": "#/components/responses/cloudMigrationSessionListResponse"
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"$ref": "#/components/responses/unauthorisedError"
|
"$ref": "#/components/responses/unauthorisedError"
|
||||||
@@ -15127,18 +15127,18 @@
|
|||||||
"$ref": "#/components/responses/internalServerError"
|
"$ref": "#/components/responses/internalServerError"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"summary": "Get a list of all cloud migrations.",
|
"summary": "Get a list of all cloud migration sessions that have been created.",
|
||||||
"tags": [
|
"tags": [
|
||||||
"migrations"
|
"migrations"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"post": {
|
"post": {
|
||||||
"operationId": "createMigration",
|
"operationId": "createSession",
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/components/schemas/CloudMigrationRequest"
|
"$ref": "#/components/schemas/CloudMigrationSessionRequestDTO"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -15147,7 +15147,7 @@
|
|||||||
},
|
},
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"$ref": "#/components/responses/cloudMigrationResponse"
|
"$ref": "#/components/responses/cloudMigrationSessionResponse"
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"$ref": "#/components/responses/unauthorisedError"
|
"$ref": "#/components/responses/unauthorisedError"
|
||||||
@@ -15159,7 +15159,7 @@
|
|||||||
"$ref": "#/components/responses/internalServerError"
|
"$ref": "#/components/responses/internalServerError"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"summary": "Create a migration.",
|
"summary": "Create a migration session.",
|
||||||
"tags": [
|
"tags": [
|
||||||
"migrations"
|
"migrations"
|
||||||
]
|
]
|
||||||
@@ -15201,10 +15201,10 @@
|
|||||||
},
|
},
|
||||||
"/cloudmigration/migration/{uid}": {
|
"/cloudmigration/migration/{uid}": {
|
||||||
"delete": {
|
"delete": {
|
||||||
"operationId": "deleteCloudMigration",
|
"operationId": "deleteSession",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"description": "UID of a migration",
|
"description": "UID of a migration session",
|
||||||
"in": "path",
|
"in": "path",
|
||||||
"name": "uid",
|
"name": "uid",
|
||||||
"required": true,
|
"required": true,
|
||||||
@@ -15224,17 +15224,16 @@
|
|||||||
"$ref": "#/components/responses/internalServerError"
|
"$ref": "#/components/responses/internalServerError"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"summary": "Delete a migration.",
|
"summary": "Delete a migration session by its uid.",
|
||||||
"tags": [
|
"tags": [
|
||||||
"migrations"
|
"migrations"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"get": {
|
"get": {
|
||||||
"description": "It returns migrations that has been created.",
|
"operationId": "getSession",
|
||||||
"operationId": "getCloudMigration",
|
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"description": "UID of a migration",
|
"description": "UID of a migration session",
|
||||||
"in": "path",
|
"in": "path",
|
||||||
"name": "uid",
|
"name": "uid",
|
||||||
"required": true,
|
"required": true,
|
||||||
@@ -15245,7 +15244,7 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"$ref": "#/components/responses/cloudMigrationResponse"
|
"$ref": "#/components/responses/cloudMigrationSessionResponse"
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"$ref": "#/components/responses/unauthorisedError"
|
"$ref": "#/components/responses/unauthorisedError"
|
||||||
@@ -15257,7 +15256,7 @@
|
|||||||
"$ref": "#/components/responses/internalServerError"
|
"$ref": "#/components/responses/internalServerError"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"summary": "Get a cloud migration.",
|
"summary": "Get a cloud migration session by its uid.",
|
||||||
"tags": [
|
"tags": [
|
||||||
"migrations"
|
"migrations"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ const config: ConfigFile = {
|
|||||||
apiImport: 'baseAPI',
|
apiImport: 'baseAPI',
|
||||||
filterEndpoints: [
|
filterEndpoints: [
|
||||||
'createCloudMigrationToken',
|
'createCloudMigrationToken',
|
||||||
'getMigrationList',
|
'getSessionList',
|
||||||
'getCloudMigration',
|
'getSession',
|
||||||
'createMigration',
|
'createSession',
|
||||||
|
'deleteSession',
|
||||||
'runCloudMigration',
|
'runCloudMigration',
|
||||||
'getCloudMigrationRun',
|
'getCloudMigrationRun',
|
||||||
'getCloudMigrationRunList',
|
'getCloudMigrationRunList',
|
||||||
'deleteCloudMigration',
|
|
||||||
'getDashboardByUid',
|
'getDashboardByUid',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user